From c5f1cda979e012ce1491b4c8efbbe809e994c5ac Mon Sep 17 00:00:00 2001 From: Chris Barbour Date: Tue, 24 Dec 2024 10:38:07 +0000 Subject: [PATCH] updating types for latest version of ts --- package-lock.json | 30 ++++++++++++++++------- package.json | 4 +-- src/comparison.ts | 8 +++--- src/dynamo-jest-setup.ts | 2 +- src/projector.ts | 2 +- src/table-builder/single-table-builder.ts | 12 ++++----- src/table-builder/table-definition.ts | 28 ++++++++++++--------- src/table-client.ts | 4 +-- test/dynamo-querier.spec.ts | 17 ++++++++----- test/tables.ts | 2 +- 10 files changed, 65 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index 829d90c..666d8bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@aws-sdk/client-dynamodb": "^3.348.0", "@shelf/jest-dynamodb": "^3.4.2", "@types/jest": "^29.5.2", - "@types/node": "^18.16.16", + "@types/node": "^20.17.10", "@types/uuid": "^9.0.7", "@typescript-eslint/eslint-plugin": "^6.15.0", "@typescript-eslint/parser": "^6.15.0", @@ -27,7 +27,7 @@ "prettier": "^2.5.1", "terser": "^5.14.2", "ts-jest": "^29.1.1", - "typescript": "^5.1.3" + "typescript": "^5.7.2" }, "peerDependencies": { "@aws-sdk/client-dynamodb": "^3.49.0" @@ -2856,10 +2856,14 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.16.16", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.16.tgz", - "integrity": "sha512-NpaM49IGQQAUlBhHMF82QH80J08os4ZmyF9MkpCzWAGuOHqE4gTEbhzd7L3l5LmWuZ6E0OiC1FweQ4tsiW35+g==", - "dev": true + "version": "20.17.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.10.tgz", + "integrity": "sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.19.2" + } }, "node_modules/@types/prettier": { "version": "2.7.3", @@ -7962,10 +7966,11 @@ "dev": true }, "node_modules/typescript": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", - "integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -7974,6 +7979,13 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true, + "license": "MIT" + }, "node_modules/unified": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/unified/-/unified-9.2.2.tgz", diff --git a/package.json b/package.json index c78b1dc..e377b62 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "@aws-sdk/client-dynamodb": "^3.348.0", "@shelf/jest-dynamodb": "^3.4.2", "@types/jest": "^29.5.2", - "@types/node": "^18.16.16", + "@types/node": "^20.17.10", "@types/uuid": "^9.0.7", "@typescript-eslint/eslint-plugin": "^6.15.0", "@typescript-eslint/parser": "^6.15.0", @@ -98,6 +98,6 @@ "prettier": "^2.5.1", "terser": "^5.14.2", "ts-jest": "^29.1.1", - "typescript": "^5.1.3" + "typescript": "^5.7.2" } } diff --git a/src/comparison.ts b/src/comparison.ts index 7d4d5eb..ddc6174 100644 --- a/src/comparison.ts +++ b/src/comparison.ts @@ -29,9 +29,9 @@ type NestedComparisonBuilder = { }; type Digger = Required<{ - [K in keyof T]: Operation & - Digger & - NestedComparisonBuilder; + [K in keyof Required]-?: Operation, Required[K]>> & + Digger[K]>, Original> & + NestedComparisonBuilder[K]>>; }>; export type ComparisonBuilderFrom = { @@ -135,7 +135,7 @@ class ComparisonBuilderType { } empty(): Wrapper { - this.wrapper.expression = ""; + this.wrapper.expression = ''; return this.wrapper; } diff --git a/src/dynamo-jest-setup.ts b/src/dynamo-jest-setup.ts index 0908d94..b519c98 100644 --- a/src/dynamo-jest-setup.ts +++ b/src/dynamo-jest-setup.ts @@ -14,7 +14,7 @@ export function tableDefinition(definitions: Record): { } export function writeJestDynamoConfig( - definitions: Record, + definitions: Record>, name = 'jest-dynamodb-config.js', rest = {}, ): void { diff --git a/src/projector.ts b/src/projector.ts index 140b22b..7893531 100644 --- a/src/projector.ts +++ b/src/projector.ts @@ -15,7 +15,7 @@ type FromKeys = KEYS extends [infer K, ...infer KS] ? { [KEY in K3 extends string ? K3 : never]: V } : V; interface Projector { - project>( + project>( path: PATH, ): Projector< T, diff --git a/src/table-builder/single-table-builder.ts b/src/table-builder/single-table-builder.ts index e9a6173..ac33960 100644 --- a/src/table-builder/single-table-builder.ts +++ b/src/table-builder/single-table-builder.ts @@ -20,8 +20,8 @@ import { DynamoConfig } from '../types/index.js'; import { TableDefinition, ValidKeys } from './table-definition.js'; type TablePart = { - partitions: (keyof T)[]; - sorts: (keyof T)[]; + partitions: (keyof T & string)[]; + sorts: (keyof T & string)[]; }; type SortKeys< @@ -171,9 +171,9 @@ export class TablePartClient< partition: { [K in T['partitions'][number]]: string }, keys: (keys: SortKeys) => { [K in T['sorts'][number]]?: string; - } = () => { + } = (() => { return {}; - }, + }) as any, options: QuerierInput = {}, ): Promise> { const keyResult: any = {}; @@ -441,8 +441,8 @@ export class TablePartInfo< static from(): { withKeys< - K extends ValidKeys, - K2 extends Exclude, K>, + K extends ValidKeys & string, + K2 extends Exclude, K> & string, >( partitionKey: K, sortKey: K2, diff --git a/src/table-builder/table-definition.ts b/src/table-builder/table-definition.ts index 867ab17..3032f09 100644 --- a/src/table-builder/table-definition.ts +++ b/src/table-builder/table-definition.ts @@ -17,12 +17,13 @@ export type SimpleDynamoType = type ValidKeyTypes = string | number | Buffer; -export type ValidKeys = T extends Record +export type ValidKeys = (T extends Record ? { [K in keyof T]: T[K] extends ValidKeyTypes ? K : never }[keyof T] - : never; + : never) & + keyof T; class TableDefinitionBuilder { - withPartitionKey>( + withPartitionKey>( partitionKey: K, ): TableDefinition { return new TableDefinition({ partitionKey }, {}); @@ -31,9 +32,12 @@ class TableDefinitionBuilder { class IndexDefinitionBuilder< T, - KEYS extends DynamoTableKeyConfig, - INDEXES extends Record>, - K extends keyof INDEXES, + const KEYS extends DynamoTableKeyConfig, + const INDEXES extends Record< + string, + { global: boolean } & DynamoTableKeyConfig + >, + const K extends keyof INDEXES, > { constructor( private readonly tableDefinition: TableDefinition, @@ -44,7 +48,7 @@ class IndexDefinitionBuilder< return this.tableDefinition; } - withSortKey( + withSortKey( sortKey: SK, ): TableDefinition< T, @@ -62,13 +66,13 @@ type PartitionAndSort> = KEYS extends { sortKey: infer S; partitionKey: infer K; } - ? K | S - : KEYS['partitionKey']; + ? (K | S) & keyof T + : KEYS['partitionKey'] & keyof T; export class TableDefinition< T = any, - KEYS extends DynamoTableKeyConfig = any, - INDEXES extends Record< + const KEYS extends DynamoTableKeyConfig = any, + const INDEXES extends Record< string, { global: boolean } & DynamoTableKeyConfig > = {}, @@ -86,7 +90,7 @@ export class TableDefinition< return new TableDefinition(this.indexes[index], {}); } - withSortKey, KEYS['partitionKey']>>( + withSortKey, KEYS['partitionKey']>>( sortKey: K, ): TableDefinition< T, diff --git a/src/table-client.ts b/src/table-client.ts index c1bb5b1..8544815 100644 --- a/src/table-client.ts +++ b/src/table-client.ts @@ -45,7 +45,7 @@ import IndexClient from './index-client.js'; import { TableDefinition } from './table-builder/table-definition.js'; import { DynamoConfig, JsonPath } from './types/index.js'; -export class TableClient { +export class TableClient> { constructor( public readonly tableConfig: TableConfig, private readonly clientConfig: DynamoConfig, @@ -232,7 +232,7 @@ export class TableClient { ); } - static build( + static build>( tableConfig: TableConfig, clientConfig: DynamoConfig, ): TableClient { diff --git a/test/dynamo-querier.spec.ts b/test/dynamo-querier.spec.ts index 295ccaf..61f3140 100644 --- a/test/dynamo-querier.spec.ts +++ b/test/dynamo-querier.spec.ts @@ -378,19 +378,24 @@ describe('Dynamo Querier', () => { it('should filter nothing', async () => { const result = await testTable2.query( - { identifier }, - { - filter: compare => compare().empty() - }, + { identifier }, + { + filter: (compare) => compare().empty(), + }, ); expect(result).toEqual({ - member: [preInserts2[0], preInserts2[1], preInserts2[2], preInserts2[3]], + member: [ + preInserts2[0], + preInserts2[1], + preInserts2[2], + preInserts2[3], + ], count: 4, scannedCount: 4, consumedCapacity: undefined, next: undefined, }); - }) + }); }); describe('Scan Index Forward', () => { diff --git a/test/tables.ts b/test/tables.ts index 7725b4b..df377af 100644 --- a/test/tables.ts +++ b/test/tables.ts @@ -59,7 +59,7 @@ export type NestedTable = { export type ComplexTable = { hash: string; text?: string; - obj?: { abc: string; def?: number }; + obj?: { abc: string; def?: number; qvc?: { a: string } }; arr?: { ghi?: number }[]; jkl?: number; };