Skip to content

Commit

Permalink
Merge pull request #1 from emdgroup/feat/typescript-compat
Browse files Browse the repository at this point in the history
build cjs and esm files and upgrade to latest typescript version
  • Loading branch information
monken authored Sep 21, 2022
2 parents a0e9e66 + 7dad460 commit 0dc4cb9
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 171 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ docs/
dist/
node_modules/
*.tgz
.env
3 changes: 3 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"loader": "ts-node/esm"
}
58 changes: 22 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,7 @@ items after the end of the query is reached or the provided [`limit`](#limit) pa

| Name | Type |
| :------ | :------ |
| `T` | `AttributeMap` |

## Constructors

### constructor

**new PaginationResponse**<`T`\>(`args`)

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | `AttributeMap` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `args` | `PaginationResponseOptions`<`T`\> |
| `T` | extends `AttributeMap` = `AttributeMap` |

## Properties

Expand Down Expand Up @@ -514,34 +496,38 @@ token and can therefore contain sensitive data.

___

### from
### filter

`Optional` **from**: `string`
`Optional` **filter**: (`arg`: `AttributeMap`) => arg is T

Start returning results starting from `nextToken`
#### Type declaration

___
▸ (`arg`): arg is T

### limit
Filter results by a predicate function

`Optional` **limit**: `number`
##### Parameters

Limit the number of results to `limit`. Will return at least `limit` results even when using FilterExpressions.
| Name | Type |
| :------ | :------ |
| `arg` | `AttributeMap` |

## Methods
##### Returns

### filter
arg is T

`Optional` **filter**(`arg`): arg is T
___

Filter results by a predicate function
### from

#### Parameters
`Optional` **from**: `string`

| Name | Type |
| :------ | :------ |
| `arg` | `AttributeMap` |
Start returning results starting from `nextToken`

#### Returns
___

arg is T
### limit

`Optional` **limit**: `number`

Limit the number of results to `limit`. Will return at least `limit` results even when using FilterExpressions.
34 changes: 20 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"name": "@emdgroup/dynamodb-paginator",
"version": "2.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"version": "2.1.0",
"main": "dist/cjs/index.js",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"types": "dist/cjs/index.d.ts",
"type": "module",
"repository": "https://github.com/emdgroup/dynamodb-paginator.git",
"author": "Moritz Onken <[email protected]>",
"license": "Apache-2.0",
Expand All @@ -22,24 +27,25 @@
"@aws-sdk/util-dynamodb": "^3.0.0"
},
"devDependencies": {
"@tsconfig/node12": "^1.0.9",
"@types/mocha": "^9.0.0",
"@tsconfig/node14": "^1.0.0",
"@types/mocha": "^9.1.1",
"@types/node": "^16.3.1",
"mocha": "^9.0.2",
"ts-node": "^10.1.0",
"typedoc": "^0.22.0",
"typedoc-github-wiki-theme": "^1.0.0",
"typedoc-plugin-markdown": "^3.10.3",
"typescript": "^4.3.5"
"mocha": "^10.0.0",
"ts-node": "^10.9.0",
"typedoc": "^0.23.0",
"typedoc-github-wiki-theme": "^1.0.1",
"typedoc-plugin-markdown": "^3.13.0",
"typescript": "^4.8.0"
},
"engines": {
"node": ">= 12"
},
"scripts": {
"prepack": "yarn docs && rm -rf dist && tsc",
"prepack": "yarn docs && rm -rf dist && yarn build",
"build": "tsc && tsc --module commonjs --outDir dist/cjs",
"docs": "yarn --silent docs:build && yarn --silent docs:merge",
"docs:build": "rm -rf docs README.md && yarn --silent typedoc --hideInPageTOC --excludeNotDocumented --disableSources --theme github-wiki src/index.ts",
"docs:merge": "ts-node bin/merge-docs",
"test": "mocha --bail --watch-files '**/*.ts' --extension ts --require ts-node/register --timeout 60000 'src/**/*.spec.ts'"
"docs:merge": "node --loader=ts-node/esm bin/merge-docs.ts",
"test": "mocha --bail --watch-files '**/*.ts' --extension ts --timeout 60000 'src/**/*.spec.ts'"
}
}
7 changes: 3 additions & 4 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { strict as assert } from 'assert';
import { randomBytes } from 'crypto';
import { createTestTable } from './testing';
import { encodeKey, decodeKey, Paginator, AttributeMap } from '.';
import { docClient } from './testing';
import { b64uDecode } from './util';
import { createTestTable, docClient } from './testing.js';
import { encodeKey, decodeKey, Paginator, AttributeMap } from './index.js';
import { b64uDecode } from './util.js';

function createKey(pk: string[], sk: string[]): { PK: string, SK: string } {
return {
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { QueryCommand, ScanCommand } from '@aws-sdk/lib-dynamodb';
import type { DynamoDBDocumentClient as DynamoDBDocumentClientV3, QueryCommandInput, QueryCommandOutput, ScanCommandInput, ScanCommandOutput } from '@aws-sdk/lib-dynamodb';
import type { NativeAttributeValue } from '@aws-sdk/util-dynamodb';

import { b64uDecode, b64uEncode, uInt16Buffer } from './util';
import { b64uDecode, b64uEncode, uInt16Buffer } from './util.js';

export type AttributeMap = { [key: string]: NativeAttributeValue };

Expand All @@ -18,7 +18,7 @@ interface Keys {

/**
* @private
* A DynamoDB key { PK: abc, SK: cdef } is encoded as follows
* A DynamoDB key `{ PK: abc, SK: cdef }` is encoded as follows
* 'S' + 1 byte (length of "PK") + "PK" + 2 bytes (length of "abc") + "abc"
* 'S' + 1 byte (length of "SK") + "SK" + 2 bytes (length of "cdef") + "cdef"
*/
Expand Down Expand Up @@ -105,7 +105,7 @@ export interface PaginationResponseOptions<T extends AttributeMap> extends Pagin
*
*/

export class PaginationResponse<T = AttributeMap> {
export class PaginationResponse<T extends AttributeMap = AttributeMap> {
/** Number of items yielded */
count: number;
/** Number of items scanned by DynamoDB */
Expand Down Expand Up @@ -212,7 +212,7 @@ export class PaginationResponse<T = AttributeMap> {
return undefined;
}

private clone<K>(args: Partial<PaginationResponseOptions<K>>): PaginationResponse<K | T> {
private clone<K extends AttributeMap>(args: Partial<PaginationResponseOptions<K>>): PaginationResponse<K | T> {
const { _limit: limit, _from: from, _query: query, _filter: filter, client, key, method } = this;
return new PaginationResponse<K | T>({
client,
Expand Down Expand Up @@ -415,7 +415,7 @@ export interface PaginateQueryOptions<T extends AttributeMap> {
context?: Buffer | string;
}

type PredicateFor<T> = T extends (arg: AttributeMap) => arg is infer K ? K : never;
type PredicateFor<T> = T extends (arg: any) => arg is infer K ? K : never;

/**
* [![Apache License](https://img.shields.io/github/license/emdgroup/dynamodb-paginator.svg?style=flat-square)](https://github.com/emdgroup/dynamodb-paginator/blob/master/LICENSE)
Expand Down
2 changes: 1 addition & 1 deletion src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DynamoDB, CreateTableCommandInput } from '@aws-sdk/client-dynamodb';
import { ServiceException } from '@aws-sdk/smithy-client';
import { randomBytes } from 'crypto';
import { promises as fs } from 'fs';
import { sleep } from './util';
import { sleep } from './util.js';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';

export const ddb = new DynamoDB({});
Expand Down
5 changes: 0 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as https from 'https';
import { randomBytes } from 'crypto';

import { strict as assert } from 'assert';

export { assert };

const agent = new https.Agent({
keepAlive: true,
});

export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"extends": "@tsconfig/node12/tsconfig.json",
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"declaration": true
"outDir": "dist/esm",
"declaration": true,
"moduleResolution": "node",
"module": "esnext"
},
"include": ["src/index.ts", "src/util.ts"]
}
Loading

0 comments on commit 0dc4cb9

Please sign in to comment.