dyno-table 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +324 -55
- package/dist/builders/condition-check-builder.d.cts +1 -1
- package/dist/builders/condition-check-builder.d.ts +1 -1
- package/dist/builders/delete-builder.d.cts +1 -1
- package/dist/builders/delete-builder.d.ts +1 -1
- package/dist/builders/put-builder.d.cts +1 -1
- package/dist/builders/put-builder.d.ts +1 -1
- package/dist/builders/query-builder.d.cts +2 -2
- package/dist/builders/query-builder.d.ts +2 -2
- package/dist/builders/transaction-builder.d.cts +1 -1
- package/dist/builders/transaction-builder.d.ts +1 -1
- package/dist/builders/update-builder.d.cts +1 -1
- package/dist/builders/update-builder.d.ts +1 -1
- package/dist/{conditions-x6kGWMR7.d.cts → conditions-3ae5znV_.d.cts} +1 -1
- package/dist/{conditions-BIpBkh4m.d.ts → conditions-BtynAviC.d.ts} +1 -1
- package/dist/conditions.d.cts +1 -1
- package/dist/conditions.d.ts +1 -1
- package/dist/entity.cjs +93 -49
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +14 -10
- package/dist/entity.d.ts +14 -10
- package/dist/entity.js +93 -49
- package/dist/entity.js.map +1 -1
- package/dist/index.cjs +3701 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +3674 -0
- package/dist/index.js.map +1 -0
- package/dist/{query-builder-H9Dn0qaS.d.ts → query-builder-BhrR31oO.d.ts} +2 -2
- package/dist/{query-builder-Dg9Loeco.d.cts → query-builder-CbHvimBk.d.cts} +2 -2
- package/dist/{table-CmIQe-jD.d.cts → table-CY9byPEg.d.cts} +2 -2
- package/dist/{table-TI4ULfra.d.ts → table-Des8C2od.d.ts} +2 -2
- package/dist/table.d.cts +3 -3
- package/dist/table.d.ts +3 -3
- package/dist/utils.cjs +34 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{utils/sort-key-template.d.cts → utils.d.cts} +32 -1
- package/dist/{utils/sort-key-template.d.ts → utils.d.ts} +32 -1
- package/dist/utils.js +31 -0
- package/dist/utils.js.map +1 -0
- package/package.json +114 -49
- package/dist/utils/partition-key-template.cjs +0 -19
- package/dist/utils/partition-key-template.cjs.map +0 -1
- package/dist/utils/partition-key-template.d.cts +0 -32
- package/dist/utils/partition-key-template.d.ts +0 -32
- package/dist/utils/partition-key-template.js +0 -17
- package/dist/utils/partition-key-template.js.map +0 -1
- package/dist/utils/sort-key-template.cjs +0 -19
- package/dist/utils/sort-key-template.cjs.map +0 -1
- package/dist/utils/sort-key-template.js +0 -17
- package/dist/utils/sort-key-template.js.map +0 -1
package/dist/entity.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { DeleteBuilder } from './builders/delete-builder.cjs';
|
|
2
|
-
import { S as ScanBuilder, G as GetBuilder, T as Table } from './table-
|
|
2
|
+
import { S as ScanBuilder, G as GetBuilder, T as Table } from './table-CY9byPEg.cjs';
|
|
3
3
|
import { PutBuilder } from './builders/put-builder.cjs';
|
|
4
4
|
import { UpdateBuilder } from './builders/update-builder.cjs';
|
|
5
5
|
import { StandardSchemaV1 } from './standard-schema.cjs';
|
|
6
6
|
import { DynamoItem, TableConfig, Index } from './types.cjs';
|
|
7
|
-
import {
|
|
8
|
-
import { Q as QueryBuilder } from './query-builder-
|
|
7
|
+
import { r as PrimaryKeyWithoutExpression, P as PrimaryKey } from './conditions-3ae5znV_.cjs';
|
|
8
|
+
import { Q as QueryBuilder } from './query-builder-CbHvimBk.cjs';
|
|
9
9
|
import './builders/transaction-builder.cjs';
|
|
10
10
|
import '@aws-sdk/lib-dynamodb';
|
|
11
11
|
import './builder-types-DlaUSc-b.cjs';
|
|
@@ -72,9 +72,9 @@ interface Settings {
|
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
interface EntityConfig<T extends DynamoItem, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
75
|
+
interface EntityConfig<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
76
76
|
name: string;
|
|
77
|
-
schema: StandardSchemaV1<T>;
|
|
77
|
+
schema: StandardSchemaV1<TInput, T>;
|
|
78
78
|
primaryKey: IndexDefinition<I>;
|
|
79
79
|
indexes?: Record<string, Index>;
|
|
80
80
|
queries: Q;
|
|
@@ -82,9 +82,13 @@ interface EntityConfig<T extends DynamoItem, I extends DynamoItem = T, Q extends
|
|
|
82
82
|
}
|
|
83
83
|
interface EntityRepository<
|
|
84
84
|
/**
|
|
85
|
-
* The Entity Type
|
|
85
|
+
* The Entity Type (output type)
|
|
86
86
|
*/
|
|
87
87
|
T extends DynamoItem,
|
|
88
|
+
/**
|
|
89
|
+
* The Input Type (for create operations)
|
|
90
|
+
*/
|
|
91
|
+
TInput extends DynamoItem = T,
|
|
88
92
|
/**
|
|
89
93
|
* The Primary Index (Partition index) Type
|
|
90
94
|
*/
|
|
@@ -93,8 +97,8 @@ I extends DynamoItem = T,
|
|
|
93
97
|
* The Queries object
|
|
94
98
|
*/
|
|
95
99
|
Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
96
|
-
create: (data:
|
|
97
|
-
upsert: (data:
|
|
100
|
+
create: (data: TInput) => PutBuilder<T>;
|
|
101
|
+
upsert: (data: TInput & I) => PutBuilder<T>;
|
|
98
102
|
get: (key: I) => GetBuilder<T>;
|
|
99
103
|
update: (key: I, data: Partial<T>) => UpdateBuilder<T>;
|
|
100
104
|
delete: (key: I) => DeleteBuilder;
|
|
@@ -118,9 +122,9 @@ Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
|
118
122
|
* });
|
|
119
123
|
* ```
|
|
120
124
|
*/
|
|
121
|
-
declare function defineEntity<T extends DynamoItem, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, I, Q>): {
|
|
125
|
+
declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, TInput, I, Q>): {
|
|
122
126
|
name: string;
|
|
123
|
-
createRepository: (table: Table) => EntityRepository<T, I, Q>;
|
|
127
|
+
createRepository: (table: Table) => EntityRepository<T, TInput, I, Q>;
|
|
124
128
|
};
|
|
125
129
|
declare function createQueries<T extends DynamoItem>(): {
|
|
126
130
|
input: <I>(schema: StandardSchemaV1<I>) => {
|
package/dist/entity.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { DeleteBuilder } from './builders/delete-builder.js';
|
|
2
|
-
import { S as ScanBuilder, G as GetBuilder, T as Table } from './table-
|
|
2
|
+
import { S as ScanBuilder, G as GetBuilder, T as Table } from './table-Des8C2od.js';
|
|
3
3
|
import { PutBuilder } from './builders/put-builder.js';
|
|
4
4
|
import { UpdateBuilder } from './builders/update-builder.js';
|
|
5
5
|
import { StandardSchemaV1 } from './standard-schema.js';
|
|
6
6
|
import { DynamoItem, TableConfig, Index } from './types.js';
|
|
7
|
-
import {
|
|
8
|
-
import { Q as QueryBuilder } from './query-builder-
|
|
7
|
+
import { r as PrimaryKeyWithoutExpression, P as PrimaryKey } from './conditions-BtynAviC.js';
|
|
8
|
+
import { Q as QueryBuilder } from './query-builder-BhrR31oO.js';
|
|
9
9
|
import './builders/transaction-builder.js';
|
|
10
10
|
import '@aws-sdk/lib-dynamodb';
|
|
11
11
|
import './builder-types-B_tCpn9F.js';
|
|
@@ -72,9 +72,9 @@ interface Settings {
|
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
interface EntityConfig<T extends DynamoItem, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
75
|
+
interface EntityConfig<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
76
76
|
name: string;
|
|
77
|
-
schema: StandardSchemaV1<T>;
|
|
77
|
+
schema: StandardSchemaV1<TInput, T>;
|
|
78
78
|
primaryKey: IndexDefinition<I>;
|
|
79
79
|
indexes?: Record<string, Index>;
|
|
80
80
|
queries: Q;
|
|
@@ -82,9 +82,13 @@ interface EntityConfig<T extends DynamoItem, I extends DynamoItem = T, Q extends
|
|
|
82
82
|
}
|
|
83
83
|
interface EntityRepository<
|
|
84
84
|
/**
|
|
85
|
-
* The Entity Type
|
|
85
|
+
* The Entity Type (output type)
|
|
86
86
|
*/
|
|
87
87
|
T extends DynamoItem,
|
|
88
|
+
/**
|
|
89
|
+
* The Input Type (for create operations)
|
|
90
|
+
*/
|
|
91
|
+
TInput extends DynamoItem = T,
|
|
88
92
|
/**
|
|
89
93
|
* The Primary Index (Partition index) Type
|
|
90
94
|
*/
|
|
@@ -93,8 +97,8 @@ I extends DynamoItem = T,
|
|
|
93
97
|
* The Queries object
|
|
94
98
|
*/
|
|
95
99
|
Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
96
|
-
create: (data:
|
|
97
|
-
upsert: (data:
|
|
100
|
+
create: (data: TInput) => PutBuilder<T>;
|
|
101
|
+
upsert: (data: TInput & I) => PutBuilder<T>;
|
|
98
102
|
get: (key: I) => GetBuilder<T>;
|
|
99
103
|
update: (key: I, data: Partial<T>) => UpdateBuilder<T>;
|
|
100
104
|
delete: (key: I) => DeleteBuilder;
|
|
@@ -118,9 +122,9 @@ Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
|
118
122
|
* });
|
|
119
123
|
* ```
|
|
120
124
|
*/
|
|
121
|
-
declare function defineEntity<T extends DynamoItem, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, I, Q>): {
|
|
125
|
+
declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, TInput, I, Q>): {
|
|
122
126
|
name: string;
|
|
123
|
-
createRepository: (table: Table) => EntityRepository<T, I, Q>;
|
|
127
|
+
createRepository: (table: Table) => EntityRepository<T, TInput, I, Q>;
|
|
124
128
|
};
|
|
125
129
|
declare function createQueries<T extends DynamoItem>(): {
|
|
126
130
|
input: <I>(schema: StandardSchemaV1<I>) => {
|
package/dist/entity.js
CHANGED
|
@@ -31,39 +31,33 @@ function defineEntity(config) {
|
|
|
31
31
|
createRepository: (table) => {
|
|
32
32
|
const repository = {
|
|
33
33
|
create: (data) => {
|
|
34
|
-
const
|
|
35
|
-
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
36
|
-
(acc, [indexName, index]) => {
|
|
37
|
-
const key = index.generateKey(data);
|
|
38
|
-
const gsiConfig = table.gsis[indexName];
|
|
39
|
-
if (!gsiConfig) {
|
|
40
|
-
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
41
|
-
}
|
|
42
|
-
if (key.pk) {
|
|
43
|
-
acc[gsiConfig.partitionKey] = key.pk;
|
|
44
|
-
}
|
|
45
|
-
if (key.sk && gsiConfig.sortKey) {
|
|
46
|
-
acc[gsiConfig.sortKey] = key.sk;
|
|
47
|
-
}
|
|
48
|
-
return acc;
|
|
49
|
-
},
|
|
50
|
-
{}
|
|
51
|
-
);
|
|
52
|
-
const builder = table.create({
|
|
53
|
-
...data,
|
|
54
|
-
[entityTypeAttributeName]: config.name,
|
|
55
|
-
[table.partitionKey]: primaryKey.pk,
|
|
56
|
-
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
57
|
-
...indexes,
|
|
58
|
-
...generateTimestamps(["createdAt", "updatedAt"])
|
|
59
|
-
});
|
|
34
|
+
const builder = table.create({});
|
|
60
35
|
const prepareValidatedItemAsync = async () => {
|
|
61
|
-
const validationResult =
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
const validationResult = config.schema["~standard"].validate(data);
|
|
37
|
+
const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;
|
|
38
|
+
if ("issues" in validatedData && validatedData.issues) {
|
|
39
|
+
throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(", ")}`);
|
|
64
40
|
}
|
|
41
|
+
const primaryKey = config.primaryKey.generateKey(validatedData.value);
|
|
42
|
+
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
43
|
+
(acc, [indexName, index]) => {
|
|
44
|
+
const key = index.generateKey(validatedData.value);
|
|
45
|
+
const gsiConfig = table.gsis[indexName];
|
|
46
|
+
if (!gsiConfig) {
|
|
47
|
+
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
48
|
+
}
|
|
49
|
+
if (key.pk) {
|
|
50
|
+
acc[gsiConfig.partitionKey] = key.pk;
|
|
51
|
+
}
|
|
52
|
+
if (key.sk && gsiConfig.sortKey) {
|
|
53
|
+
acc[gsiConfig.sortKey] = key.sk;
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
},
|
|
57
|
+
{}
|
|
58
|
+
);
|
|
65
59
|
const validatedItem = {
|
|
66
|
-
...
|
|
60
|
+
...validatedData.value,
|
|
67
61
|
[entityTypeAttributeName]: config.name,
|
|
68
62
|
[table.partitionKey]: primaryKey.pk,
|
|
69
63
|
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
@@ -76,11 +70,31 @@ function defineEntity(config) {
|
|
|
76
70
|
const prepareValidatedItemSync = () => {
|
|
77
71
|
const validationResult = config.schema["~standard"].validate(data);
|
|
78
72
|
if (validationResult instanceof Promise) {
|
|
79
|
-
throw new Error(
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Async validation is not supported in create method. The schema must support synchronous validation for transaction compatibility."
|
|
75
|
+
);
|
|
80
76
|
}
|
|
81
77
|
if ("issues" in validationResult && validationResult.issues) {
|
|
82
78
|
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
83
79
|
}
|
|
80
|
+
const primaryKey = config.primaryKey.generateKey(validationResult.value);
|
|
81
|
+
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
82
|
+
(acc, [indexName, index]) => {
|
|
83
|
+
const key = index.generateKey(validationResult.value);
|
|
84
|
+
const gsiConfig = table.gsis[indexName];
|
|
85
|
+
if (!gsiConfig) {
|
|
86
|
+
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
87
|
+
}
|
|
88
|
+
if (key.pk) {
|
|
89
|
+
acc[gsiConfig.partitionKey] = key.pk;
|
|
90
|
+
}
|
|
91
|
+
if (key.sk && gsiConfig.sortKey) {
|
|
92
|
+
acc[gsiConfig.sortKey] = key.sk;
|
|
93
|
+
}
|
|
94
|
+
return acc;
|
|
95
|
+
},
|
|
96
|
+
{}
|
|
97
|
+
);
|
|
84
98
|
const validatedItem = {
|
|
85
99
|
...validationResult.value,
|
|
86
100
|
[entityTypeAttributeName]: config.name,
|
|
@@ -119,25 +133,37 @@ function defineEntity(config) {
|
|
|
119
133
|
return builder;
|
|
120
134
|
},
|
|
121
135
|
upsert: (data) => {
|
|
122
|
-
const
|
|
123
|
-
const builder = table.put({
|
|
124
|
-
[table.partitionKey]: primaryKey.pk,
|
|
125
|
-
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
126
|
-
...data,
|
|
127
|
-
[entityTypeAttributeName]: config.name,
|
|
128
|
-
...generateTimestamps(["createdAt", "updatedAt"])
|
|
129
|
-
});
|
|
136
|
+
const builder = table.put({});
|
|
130
137
|
const prepareValidatedItemAsync = async () => {
|
|
131
|
-
const validationResult =
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
const validationResult = config.schema["~standard"].validate(data);
|
|
139
|
+
const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;
|
|
140
|
+
if ("issues" in validatedData && validatedData.issues) {
|
|
141
|
+
throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(", ")}`);
|
|
134
142
|
}
|
|
135
|
-
const
|
|
143
|
+
const primaryKey = config.primaryKey.generateKey(validatedData.value);
|
|
144
|
+
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
145
|
+
(acc, [indexName, index]) => {
|
|
146
|
+
const key = index.generateKey(validatedData.value);
|
|
147
|
+
const gsiConfig = table.gsis[indexName];
|
|
148
|
+
if (!gsiConfig) {
|
|
149
|
+
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
150
|
+
}
|
|
151
|
+
if (key.pk) {
|
|
152
|
+
acc[gsiConfig.partitionKey] = key.pk;
|
|
153
|
+
}
|
|
154
|
+
if (key.sk && gsiConfig.sortKey) {
|
|
155
|
+
acc[gsiConfig.sortKey] = key.sk;
|
|
156
|
+
}
|
|
157
|
+
return acc;
|
|
158
|
+
},
|
|
159
|
+
{}
|
|
160
|
+
);
|
|
136
161
|
const validatedItem = {
|
|
137
|
-
[table.partitionKey]:
|
|
138
|
-
...table.sortKey ? { [table.sortKey]:
|
|
139
|
-
...
|
|
162
|
+
[table.partitionKey]: primaryKey.pk,
|
|
163
|
+
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
164
|
+
...validatedData.value,
|
|
140
165
|
[entityTypeAttributeName]: config.name,
|
|
166
|
+
...indexes,
|
|
141
167
|
...generateTimestamps(["createdAt", "updatedAt"])
|
|
142
168
|
};
|
|
143
169
|
Object.assign(builder, { item: validatedItem });
|
|
@@ -151,12 +177,30 @@ function defineEntity(config) {
|
|
|
151
177
|
if ("issues" in validationResult && validationResult.issues) {
|
|
152
178
|
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
153
179
|
}
|
|
154
|
-
const
|
|
180
|
+
const primaryKey = config.primaryKey.generateKey(validationResult.value);
|
|
181
|
+
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
182
|
+
(acc, [indexName, index]) => {
|
|
183
|
+
const key = index.generateKey(validationResult.value);
|
|
184
|
+
const gsiConfig = table.gsis[indexName];
|
|
185
|
+
if (!gsiConfig) {
|
|
186
|
+
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
187
|
+
}
|
|
188
|
+
if (key.pk) {
|
|
189
|
+
acc[gsiConfig.partitionKey] = key.pk;
|
|
190
|
+
}
|
|
191
|
+
if (key.sk && gsiConfig.sortKey) {
|
|
192
|
+
acc[gsiConfig.sortKey] = key.sk;
|
|
193
|
+
}
|
|
194
|
+
return acc;
|
|
195
|
+
},
|
|
196
|
+
{}
|
|
197
|
+
);
|
|
155
198
|
const validatedItem = {
|
|
156
|
-
[table.partitionKey]:
|
|
157
|
-
...table.sortKey ? { [table.sortKey]:
|
|
199
|
+
[table.partitionKey]: primaryKey.pk,
|
|
200
|
+
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
158
201
|
...validationResult.value,
|
|
159
202
|
[entityTypeAttributeName]: config.name,
|
|
203
|
+
...indexes,
|
|
160
204
|
...generateTimestamps(["createdAt", "updatedAt"])
|
|
161
205
|
};
|
|
162
206
|
Object.assign(builder, { item: validatedItem });
|