Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
8 changes: 4 additions & 4 deletions src/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type NestedComparisonBuilder<Original, Type> = {
};

type Digger<T, Original = T> = Required<{
[K in keyof T]: Operation<T, T[K]> &
Digger<T[K], Original> &
NestedComparisonBuilder<Original, T[K]>;
[K in keyof Required<T>]-?: Operation<Required<T>, Required<Required<T>[K]>> &
Digger<Required<Required<T>[K]>, Original> &
NestedComparisonBuilder<Original, Required<Required<T>[K]>>;
}>;

export type ComparisonBuilderFrom<TableType> = {
Expand Down Expand Up @@ -135,7 +135,7 @@ class ComparisonBuilderType<T> {
}

empty(): Wrapper {
this.wrapper.expression = "";
this.wrapper.expression = '';
return this.wrapper;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dynamo-jest-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function tableDefinition(definitions: Record<string, TableDefinition>): {
}

export function writeJestDynamoConfig(
definitions: Record<string, TableDefinition>,
definitions: Record<string, TableDefinition<any>>,
name = 'jest-dynamodb-config.js',
rest = {},
): void {
Expand Down
2 changes: 1 addition & 1 deletion src/projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FromKeys<KEYS extends any[], V> = KEYS extends [infer K, ...infer KS]
? { [KEY in K3 extends string ? K3 : never]: V }
: V;
interface Projector<T, PROJECTED = {}> {
project<PATH extends JsonPath<T>>(
project<const PATH extends JsonPath<T>>(
path: PATH,
): Projector<
T,
Expand Down
12 changes: 6 additions & 6 deletions src/table-builder/single-table-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { DynamoConfig } from '../types/index.js';
import { TableDefinition, ValidKeys } from './table-definition.js';

type TablePart<T> = {
partitions: (keyof T)[];
sorts: (keyof T)[];
partitions: (keyof T & string)[];
sorts: (keyof T & string)[];
};

type SortKeys<
Expand Down Expand Up @@ -171,9 +171,9 @@ export class TablePartClient<
partition: { [K in T['partitions'][number]]: string },
keys: (keys: SortKeys<T['sorts']>) => {
[K in T['sorts'][number]]?: string;
} = () => {
} = (() => {
return {};
},
}) as any,
options: QuerierInput<TableType, PROJECTION> = {},
): Promise<QuerierReturn<TableType, PROJECTION>> {
const keyResult: any = {};
Expand Down Expand Up @@ -441,8 +441,8 @@ export class TablePartInfo<

static from<TableType>(): {
withKeys<
K extends ValidKeys<TableType>,
K2 extends Exclude<ValidKeys<TableType>, K>,
K extends ValidKeys<TableType> & string,
K2 extends Exclude<ValidKeys<TableType>, K> & string,
>(
partitionKey: K,
sortKey: K2,
Expand Down
28 changes: 16 additions & 12 deletions src/table-builder/table-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export type SimpleDynamoType =

type ValidKeyTypes = string | number | Buffer;

export type ValidKeys<T> = T extends Record<string, any>
export type ValidKeys<T> = (T extends Record<string, any>
? { [K in keyof T]: T[K] extends ValidKeyTypes ? K : never }[keyof T]
: never;
: never) &
keyof T;

class TableDefinitionBuilder<T> {
withPartitionKey<K extends ValidKeys<T>>(
withPartitionKey<const K extends ValidKeys<T>>(
partitionKey: K,
): TableDefinition<T, { partitionKey: K }> {
return new TableDefinition<T, { partitionKey: K }>({ partitionKey }, {});
Expand All @@ -31,9 +32,12 @@ class TableDefinitionBuilder<T> {

class IndexDefinitionBuilder<
T,
KEYS extends DynamoTableKeyConfig<T>,
INDEXES extends Record<string, { global: boolean } & DynamoTableKeyConfig<T>>,
K extends keyof INDEXES,
const KEYS extends DynamoTableKeyConfig<T>,
const INDEXES extends Record<
string,
{ global: boolean } & DynamoTableKeyConfig<T>
>,
const K extends keyof INDEXES,
> {
constructor(
private readonly tableDefinition: TableDefinition<T, KEYS, INDEXES>,
Expand All @@ -44,7 +48,7 @@ class IndexDefinitionBuilder<
return this.tableDefinition;
}

withSortKey<SK extends keyof T>(
withSortKey<const SK extends keyof T>(
sortKey: SK,
): TableDefinition<
T,
Expand All @@ -62,13 +66,13 @@ type PartitionAndSort<T, KEYS extends DynamoTableKeyConfig<T>> = 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<T> = any,
INDEXES extends Record<
const KEYS extends DynamoTableKeyConfig<T> = any,
const INDEXES extends Record<
string,
{ global: boolean } & DynamoTableKeyConfig<T>
> = {},
Expand All @@ -86,7 +90,7 @@ export class TableDefinition<
return new TableDefinition<T, INDEXES[I]>(this.indexes[index], {});
}

withSortKey<K extends Exclude<ValidKeys<T>, KEYS['partitionKey']>>(
withSortKey<const K extends Exclude<ValidKeys<T>, KEYS['partitionKey']>>(
sortKey: K,
): TableDefinition<
T,
Expand Down
4 changes: 2 additions & 2 deletions src/table-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableConfig extends TableDefinition> {
export class TableClient<TableConfig extends TableDefinition<any, any, any>> {
constructor(
public readonly tableConfig: TableConfig,
private readonly clientConfig: DynamoConfig,
Expand Down Expand Up @@ -232,7 +232,7 @@ export class TableClient<TableConfig extends TableDefinition> {
);
}

static build<TableConfig extends TableDefinition>(
static build<TableConfig extends TableDefinition<any, any, any>>(
tableConfig: TableConfig,
clientConfig: DynamoConfig,
): TableClient<TableConfig> {
Expand Down
17 changes: 11 additions & 6 deletions test/dynamo-querier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading