@ftschopp/dynatable-core 1.0.0 → 1.2.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/CHANGELOG.md +19 -0
- package/README.md +528 -2
- package/dist/builders/delete/types.d.ts +6 -1
- package/dist/builders/delete/types.d.ts.map +1 -1
- package/dist/builders/get/types.d.ts +6 -1
- package/dist/builders/get/types.d.ts.map +1 -1
- package/dist/builders/put/types.d.ts +6 -1
- package/dist/builders/put/types.d.ts.map +1 -1
- package/dist/builders/query/create-query-builder.d.ts +1 -1
- package/dist/builders/query/create-query-builder.d.ts.map +1 -1
- package/dist/builders/query/types.d.ts +9 -10
- package/dist/builders/query/types.d.ts.map +1 -1
- package/dist/builders/transact-write/create-transact-write-builder.d.ts.map +1 -1
- package/dist/builders/transact-write/create-transact-write-builder.js +1 -1
- package/dist/builders/transact-write/types.d.ts +33 -6
- package/dist/builders/transact-write/types.d.ts.map +1 -1
- package/dist/builders/update/create-update-builder.d.ts.map +1 -1
- package/dist/builders/update/create-update-builder.js +30 -9
- package/dist/builders/update/types.d.ts +8 -2
- package/dist/builders/update/types.d.ts.map +1 -1
- package/dist/core/types.d.ts +96 -11
- package/dist/core/types.d.ts.map +1 -1
- package/dist/entity/create-entity-api.d.ts +15 -0
- package/dist/entity/create-entity-api.d.ts.map +1 -0
- package/dist/entity/create-entity-api.js +124 -0
- package/dist/entity/index.d.ts +12 -0
- package/dist/entity/index.d.ts.map +1 -0
- package/dist/entity/index.js +18 -0
- package/dist/entity/middleware/factories.d.ts +6 -0
- package/dist/entity/middleware/factories.d.ts.map +1 -0
- package/dist/entity/middleware/factories.js +15 -0
- package/dist/entity/middleware/types.d.ts +8 -0
- package/dist/entity/middleware/types.d.ts.map +1 -0
- package/dist/entity/middleware/types.js +2 -0
- package/dist/entity/middleware/with-middleware.d.ts +8 -0
- package/dist/entity/middleware/with-middleware.d.ts.map +1 -0
- package/dist/entity/middleware/with-middleware.js +29 -0
- package/dist/{entity.d.ts → entity/types.d.ts} +6 -17
- package/dist/entity/types.d.ts.map +1 -0
- package/dist/entity/types.js +2 -0
- package/dist/entity/validation/key-validation.d.ts +7 -0
- package/dist/entity/validation/key-validation.d.ts.map +1 -0
- package/dist/entity/validation/key-validation.js +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/table.d.ts +8 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +1 -0
- package/dist/utils/model-utils.d.ts +7 -1
- package/dist/utils/model-utils.d.ts.map +1 -1
- package/dist/utils/model-utils.js +32 -3
- package/dist/utils/zod-utils.d.ts +3 -2
- package/dist/utils/zod-utils.d.ts.map +1 -1
- package/dist/utils/zod-utils.js +33 -11
- package/package.json +3 -2
- package/src/builders/README.md +68 -1
- package/src/builders/delete/types.ts +7 -1
- package/src/builders/get/types.ts +7 -1
- package/src/builders/put/types.ts +7 -1
- package/src/builders/query/create-query-builder.ts +4 -6
- package/src/builders/query/types.ts +9 -12
- package/src/builders/transact-write/README.md +37 -1
- package/src/builders/transact-write/create-transact-write-builder.ts +20 -14
- package/src/builders/transact-write/types.ts +44 -6
- package/src/builders/update/create-update-builder.test.ts +43 -0
- package/src/builders/update/create-update-builder.ts +47 -9
- package/src/builders/update/types.ts +9 -2
- package/src/core/types.test.ts +137 -0
- package/src/core/types.ts +97 -20
- package/src/entity/create-entity-api.ts +212 -0
- package/src/entity/index.ts +19 -0
- package/src/entity/middleware/factories.ts +15 -0
- package/src/entity/middleware/types.ts +7 -0
- package/src/entity/middleware/with-middleware.ts +37 -0
- package/src/entity/types.ts +79 -0
- package/src/entity/validation/key-validation.ts +34 -0
- package/src/index.ts +1 -0
- package/src/table.ts +10 -3
- package/src/utils/model-utils.test.ts +131 -1
- package/src/utils/model-utils.ts +35 -2
- package/src/utils/zod-utils.test.ts +97 -2
- package/src/utils/zod-utils.ts +31 -12
- package/dist/entity.d.ts.map +0 -1
- package/dist/entity.js +0 -161
- package/src/entity.ts +0 -337
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ExecutableBuilder, AttrBuilder, OpBuilder, Condition } from '../shared';
|
|
2
|
-
import { ModelDefinition } from '../../core/types';
|
|
3
2
|
/**
|
|
4
3
|
* Query result with pagination support
|
|
5
4
|
*/
|
|
@@ -24,31 +23,31 @@ export interface QueryResult<Model> {
|
|
|
24
23
|
/**
|
|
25
24
|
* Query executor with additional query-specific options
|
|
26
25
|
*/
|
|
27
|
-
export interface QueryExecutor<Model
|
|
26
|
+
export interface QueryExecutor<Model> extends ExecutableBuilder<Model[]> {
|
|
28
27
|
/**
|
|
29
28
|
* Limit the number of items to return
|
|
30
29
|
*/
|
|
31
|
-
limit(count: number): QueryExecutor<Model
|
|
30
|
+
limit(count: number): QueryExecutor<Model>;
|
|
32
31
|
/**
|
|
33
32
|
* Scan index forward (ascending) or backward (descending)
|
|
34
33
|
*/
|
|
35
|
-
scanIndexForward(forward: boolean): QueryExecutor<Model
|
|
34
|
+
scanIndexForward(forward: boolean): QueryExecutor<Model>;
|
|
36
35
|
/**
|
|
37
36
|
* Use a secondary index
|
|
38
37
|
*/
|
|
39
|
-
useIndex(indexName: string): QueryExecutor<Model
|
|
38
|
+
useIndex(indexName: string): QueryExecutor<Model>;
|
|
40
39
|
/**
|
|
41
40
|
* Select specific attributes to return
|
|
42
41
|
*/
|
|
43
|
-
select(attrs: (keyof Model)[]): QueryExecutor<Model
|
|
42
|
+
select(attrs: (keyof Model)[]): QueryExecutor<Model>;
|
|
44
43
|
/**
|
|
45
44
|
* Use consistent read
|
|
46
45
|
*/
|
|
47
|
-
consistentRead(): QueryExecutor<Model
|
|
46
|
+
consistentRead(): QueryExecutor<Model>;
|
|
48
47
|
/**
|
|
49
48
|
* Start query from a specific key (for pagination)
|
|
50
49
|
*/
|
|
51
|
-
startFrom(key: Record<string, any>): QueryExecutor<Model
|
|
50
|
+
startFrom(key: Record<string, any>): QueryExecutor<Model>;
|
|
52
51
|
/**
|
|
53
52
|
* Returns the raw DynamoDB query parameters
|
|
54
53
|
*/
|
|
@@ -65,7 +64,7 @@ export interface QueryExecutor<Model, M extends ModelDefinition = any> extends E
|
|
|
65
64
|
/**
|
|
66
65
|
* Main Query Builder interface with type-safe where clause
|
|
67
66
|
*/
|
|
68
|
-
export interface QueryBuilder<Model
|
|
67
|
+
export interface QueryBuilder<Model> {
|
|
69
68
|
/**
|
|
70
69
|
* Build a condition expression using attributes and operators
|
|
71
70
|
* Usage: .where((attr, op) => op.eq(attr.username, 'juanca'))
|
|
@@ -74,6 +73,6 @@ export interface QueryBuilder<Model, M extends ModelDefinition = any> {
|
|
|
74
73
|
* op.gt(attr.age, 18)
|
|
75
74
|
* ))
|
|
76
75
|
*/
|
|
77
|
-
where(fn: (attr: AttrBuilder<Model>, op: OpBuilder) => Condition): QueryExecutor<Model
|
|
76
|
+
where(fn: (attr: AttrBuilder<Model>, op: OpBuilder) => Condition): QueryExecutor<Model>;
|
|
78
77
|
}
|
|
79
78
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/query/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/query/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC;;OAEG;IACH,KAAK,EAAE,KAAK,EAAE,CAAC;IAEf;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEvC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,iBAAiB,CAAC,KAAK,EAAE,CAAC;IACtE;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAE3C;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEzD;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAElD;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAErD;;OAEG;IACH,cAAc,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IAEvC;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1D;;OAEG;IACH,QAAQ,IAAI,GAAG,CAAC;IAEhB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAE5B;;OAEG;IACH,qBAAqB,IAAI,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,KAAK;IACjC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,SAAS,KAAK,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;CACzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-transact-write-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/transact-write/create-transact-write-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-transact-write-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/transact-write/create-transact-write-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,oBAAoB,EAMrB,MAAM,SAAS,CAAC;AAiGjB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,cAAc,KAAG,oBAGnE,CAAC"}
|
|
@@ -49,7 +49,7 @@ const setClientRequestToken = (state) => (token) => ({
|
|
|
49
49
|
*/
|
|
50
50
|
const toDbParams = (state) => {
|
|
51
51
|
const params = {
|
|
52
|
-
TransactItems: state.items,
|
|
52
|
+
TransactItems: [...state.items],
|
|
53
53
|
};
|
|
54
54
|
if (state.clientRequestToken) {
|
|
55
55
|
params.ClientRequestToken = state.clientRequestToken;
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
import type { TransactWriteCommandInput, TransactWriteCommandOutput, PutCommandInput, UpdateCommandInput, DeleteCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
3
|
+
type TransactWriteItems = NonNullable<TransactWriteCommandInput['TransactItems']>;
|
|
4
|
+
type StrictTransactPut = NonNullable<TransactWriteItems[number]['Put']>;
|
|
5
|
+
type StrictTransactUpdate = NonNullable<TransactWriteItems[number]['Update']>;
|
|
6
|
+
type StrictTransactDelete = NonNullable<TransactWriteItems[number]['Delete']>;
|
|
7
|
+
type StrictTransactConditionCheck = NonNullable<TransactWriteItems[number]['ConditionCheck']>;
|
|
8
|
+
/**
|
|
9
|
+
* Parameters for a Put operation within a transaction
|
|
10
|
+
* Accepts both regular PutCommandInput and strict transaction Put params
|
|
11
|
+
*/
|
|
12
|
+
export type TransactPutParams = PutCommandInput | StrictTransactPut;
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for an Update operation within a transaction
|
|
15
|
+
* Accepts both regular UpdateCommandInput and strict transaction Update params
|
|
16
|
+
*/
|
|
17
|
+
export type TransactUpdateParams = UpdateCommandInput | StrictTransactUpdate;
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for a Delete operation within a transaction
|
|
20
|
+
* Accepts both regular DeleteCommandInput and strict transaction Delete params
|
|
21
|
+
*/
|
|
22
|
+
export type TransactDeleteParams = DeleteCommandInput | StrictTransactDelete;
|
|
23
|
+
/**
|
|
24
|
+
* Parameters for a ConditionCheck operation within a transaction
|
|
25
|
+
*/
|
|
26
|
+
export type TransactConditionCheckParams = StrictTransactConditionCheck;
|
|
2
27
|
/**
|
|
3
28
|
* Represents a single item in a TransactWrite operation
|
|
29
|
+
* Using any internally to allow flexibility between CommandInput and strict transaction types
|
|
4
30
|
*/
|
|
5
31
|
export type TransactWriteItem = {
|
|
6
32
|
Put: any;
|
|
@@ -23,12 +49,13 @@ export type TransactWriteState = {
|
|
|
23
49
|
* TransactWrite builder interface
|
|
24
50
|
*/
|
|
25
51
|
export type TransactWriteBuilder = {
|
|
26
|
-
readonly addPut: (params:
|
|
27
|
-
readonly addUpdate: (params:
|
|
28
|
-
readonly addDelete: (params:
|
|
29
|
-
readonly addConditionCheck: (params:
|
|
52
|
+
readonly addPut: (params: TransactPutParams) => TransactWriteBuilder;
|
|
53
|
+
readonly addUpdate: (params: TransactUpdateParams) => TransactWriteBuilder;
|
|
54
|
+
readonly addDelete: (params: TransactDeleteParams) => TransactWriteBuilder;
|
|
55
|
+
readonly addConditionCheck: (params: TransactConditionCheckParams) => TransactWriteBuilder;
|
|
30
56
|
readonly withClientRequestToken: (token: string) => TransactWriteBuilder;
|
|
31
|
-
readonly dbParams: () =>
|
|
32
|
-
readonly execute: () => Promise<
|
|
57
|
+
readonly dbParams: () => TransactWriteCommandInput;
|
|
58
|
+
readonly execute: () => Promise<TransactWriteCommandOutput>;
|
|
33
59
|
};
|
|
60
|
+
export {};
|
|
34
61
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/transact-write/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/transact-write/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAG/B,KAAK,kBAAkB,GAAG,WAAW,CAAC,yBAAyB,CAAC,eAAe,CAAC,CAAC,CAAC;AAClF,KAAK,iBAAiB,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACxE,KAAK,oBAAoB,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9E,KAAK,oBAAoB,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9E,KAAK,4BAA4B,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAE9F;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG,iBAAiB,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AAE7E;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,4BAA4B,CAAC;AAExE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE,GACZ;IAAE,MAAM,EAA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7D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EACvC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,EACnB,MAAM,EAAE,cAAc,EACtB,cAAc,GAAE,SAAS,EAAO,EAChC,aAAa,GAAE;IACb,GAAG,EAAE,YAAY,EAAE,CAAC;IACpB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,GAAG,EAAE,YAAY,EAAE,CAAC;IACpB,MAAM,EAAE,YAAY,EAAE,CAAC;CACuB,EAChD,UAAU,GAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,aAAsB,EACnF,YAAY,SAAI,EAChB,gBAAgB,UAAQ,EACxB,MAAM,CAAC,EAAE,cAAc,GACtB,aAAa,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"create-update-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/update/create-update-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAgC,SAAS,EAA4B,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EACvC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,EACnB,MAAM,EAAE,cAAc,EACtB,cAAc,GAAE,SAAS,EAAO,EAChC,aAAa,GAAE;IACb,GAAG,EAAE,YAAY,EAAE,CAAC;IACpB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,GAAG,EAAE,YAAY,EAAE,CAAC;IACpB,MAAM,EAAE,YAAY,EAAE,CAAC;CACuB,EAChD,UAAU,GAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,aAAsB,EACnF,YAAY,SAAI,EAChB,gBAAgB,UAAQ,EACxB,MAAM,CAAC,EAAE,cAAc,GACtB,aAAa,CAAC,KAAK,CAAC,CAwStB"}
|
|
@@ -28,8 +28,32 @@ function createUpdateBuilder(tableName, key, client, prevConditions = [], update
|
|
|
28
28
|
const condition = fn(attrs, opBuilder);
|
|
29
29
|
return createUpdateBuilder(tableName, key, client, [...conditions, condition], updateActions, returnMode, valueCounter, enableTimestamps, logger);
|
|
30
30
|
},
|
|
31
|
-
set(
|
|
32
|
-
|
|
31
|
+
set(attrOrUpdates, value) {
|
|
32
|
+
// Check if this is a multiple updates object
|
|
33
|
+
// An AttrRef has only 'name' property and is a string value
|
|
34
|
+
// Multiple updates is an object with no value parameter
|
|
35
|
+
if (value === undefined &&
|
|
36
|
+
typeof attrOrUpdates === 'object' &&
|
|
37
|
+
attrOrUpdates !== null &&
|
|
38
|
+
!(Object.keys(attrOrUpdates).length === 1 &&
|
|
39
|
+
'name' in attrOrUpdates &&
|
|
40
|
+
typeof attrOrUpdates.name === 'string')) {
|
|
41
|
+
// Multiple updates case
|
|
42
|
+
const updates = attrOrUpdates;
|
|
43
|
+
const newActions = [];
|
|
44
|
+
for (const [attr, val] of Object.entries(updates)) {
|
|
45
|
+
const attrName = attr;
|
|
46
|
+
const valueName = getUniqueValueName(attrName);
|
|
47
|
+
newActions.push({
|
|
48
|
+
expression: `#${attrName} = :${valueName}`,
|
|
49
|
+
names: { [`#${attrName}`]: attrName },
|
|
50
|
+
values: { [`:${valueName}`]: val },
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return createUpdateBuilder(tableName, key, client, conditions, { ...updateActions, set: [...updateActions.set, ...newActions] }, returnMode, valueCounter, enableTimestamps, logger);
|
|
54
|
+
}
|
|
55
|
+
// Single update case
|
|
56
|
+
const attrName = normalizeAttr(attrOrUpdates);
|
|
33
57
|
const valueName = getUniqueValueName(attrName);
|
|
34
58
|
const action = {
|
|
35
59
|
expression: `#${attrName} = :${valueName}`,
|
|
@@ -165,15 +189,12 @@ function createUpdateBuilder(tableName, key, client, prevConditions = [], update
|
|
|
165
189
|
const params = build().dbParams();
|
|
166
190
|
const response = await client.send(new lib_dynamodb_1.UpdateCommand(params));
|
|
167
191
|
logger?.log('UpdateCommand', params, response);
|
|
168
|
-
// Return the
|
|
169
|
-
if (
|
|
170
|
-
return response.Attributes;
|
|
171
|
-
}
|
|
172
|
-
if (returnMode === 'UPDATED_NEW' && response.Attributes) {
|
|
192
|
+
// Return the item based on returnMode
|
|
193
|
+
if (response.Attributes) {
|
|
173
194
|
return response.Attributes;
|
|
174
195
|
}
|
|
175
|
-
//
|
|
176
|
-
return
|
|
196
|
+
// If no attributes returned (NONE mode), return undefined
|
|
197
|
+
return undefined;
|
|
177
198
|
},
|
|
178
199
|
});
|
|
179
200
|
return build();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
1
2
|
import { OperationBuilder, AttrRef } from '../shared';
|
|
2
3
|
/**
|
|
3
4
|
* Update actions that can be performed on attributes
|
|
@@ -10,11 +11,12 @@ export type UpdateAction = {
|
|
|
10
11
|
/**
|
|
11
12
|
* Builder interface for DynamoDB UpdateItem operations
|
|
12
13
|
*/
|
|
13
|
-
export interface UpdateBuilder<Model> extends OperationBuilder<Model> {
|
|
14
|
+
export interface UpdateBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams'> {
|
|
14
15
|
/**
|
|
15
|
-
* Sets an attribute to a specific value
|
|
16
|
+
* Sets an attribute to a specific value, or sets multiple attributes at once
|
|
16
17
|
*/
|
|
17
18
|
set(attr: keyof Model | AttrRef, value: any): UpdateBuilder<Model>;
|
|
19
|
+
set(updates: Partial<Model>): UpdateBuilder<Model>;
|
|
18
20
|
/**
|
|
19
21
|
* Removes an attribute from the item
|
|
20
22
|
*/
|
|
@@ -31,5 +33,9 @@ export interface UpdateBuilder<Model> extends OperationBuilder<Model> {
|
|
|
31
33
|
* Configures what values should be returned after the update operation
|
|
32
34
|
*/
|
|
33
35
|
returning(mode: 'NONE' | 'ALL_OLD' | 'ALL_NEW' | 'UPDATED_OLD' | 'UPDATED_NEW'): UpdateBuilder<Model>;
|
|
36
|
+
/**
|
|
37
|
+
* Converts the builder state to DynamoDB UpdateItem parameters
|
|
38
|
+
*/
|
|
39
|
+
dbParams(): UpdateCommandInput;
|
|
34
40
|
}
|
|
35
41
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/update/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/update/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IACrF;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACnE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEnD;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1D;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEnE;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEtE;;OAEG;IACH,SAAS,CACP,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,aAAa,GACnE,aAAa,CAAC,KAAK,CAAC,CAAC;IAExB;;OAEG;IACH,QAAQ,IAAI,kBAAkB,CAAC;CAChC"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -23,19 +23,61 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @property type - The JavaScript constructor for the attribute type
|
|
29
|
-
* @property [required] - Whether the attribute is required
|
|
30
|
-
* @property [generate] - Auto-generation strategy ('ulid', 'uuid')
|
|
31
|
-
* @property [default] - Default value or generator function
|
|
26
|
+
* Scalar attribute definition (String, Number, Boolean, Date)
|
|
32
27
|
*/
|
|
33
|
-
export type
|
|
28
|
+
export type ScalarAttributeDefinition = {
|
|
34
29
|
type: StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;
|
|
35
30
|
required?: boolean;
|
|
36
31
|
generate?: 'ulid' | 'uuid';
|
|
37
32
|
default?: any;
|
|
33
|
+
nulls?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Object attribute definition with a nested schema
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* address: {
|
|
40
|
+
* type: Object,
|
|
41
|
+
* schema: {
|
|
42
|
+
* street: { type: String },
|
|
43
|
+
* city: { type: String, required: true },
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
export type ObjectAttributeDefinition = {
|
|
48
|
+
type: ObjectConstructor;
|
|
49
|
+
schema: Record<string, AttributeDefinition>;
|
|
50
|
+
required?: boolean;
|
|
51
|
+
default?: any;
|
|
52
|
+
nulls?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Array attribute definition with a typed items schema
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* history: {
|
|
59
|
+
* type: Array,
|
|
60
|
+
* default: [],
|
|
61
|
+
* items: {
|
|
62
|
+
* type: Object,
|
|
63
|
+
* schema: {
|
|
64
|
+
* date: { type: String },
|
|
65
|
+
* status: { type: String },
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
*/
|
|
70
|
+
export type ArrayAttributeDefinition = {
|
|
71
|
+
type: ArrayConstructor;
|
|
72
|
+
items: AttributeDefinition;
|
|
73
|
+
required?: boolean;
|
|
74
|
+
default?: any;
|
|
75
|
+
nulls?: boolean;
|
|
38
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Attribute definition for model attributes — supports scalars, nested objects, and arrays
|
|
79
|
+
*/
|
|
80
|
+
export type AttributeDefinition = ScalarAttributeDefinition | ObjectAttributeDefinition | ArrayAttributeDefinition;
|
|
39
81
|
/**
|
|
40
82
|
* Key definition for primary and secondary indexes
|
|
41
83
|
*
|
|
@@ -84,6 +126,7 @@ export type ModelDefinition = {
|
|
|
84
126
|
export type SchemaParams = {
|
|
85
127
|
isoDates?: boolean;
|
|
86
128
|
timestamps?: boolean;
|
|
129
|
+
cleanInternalKeys?: boolean;
|
|
87
130
|
};
|
|
88
131
|
/**
|
|
89
132
|
* Complete schema definition for a DynamoDB table
|
|
@@ -100,7 +143,39 @@ export type SchemaDefinition = {
|
|
|
100
143
|
models: Record<string, ModelDefinition>;
|
|
101
144
|
params?: SchemaParams;
|
|
102
145
|
};
|
|
103
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Recursively infers the TypeScript type from an AttributeDefinition.
|
|
148
|
+
* - Object → infers the nested schema shape
|
|
149
|
+
* - Array → infers an array of the items type
|
|
150
|
+
* - Scalars → maps to the corresponding primitive
|
|
151
|
+
*/
|
|
152
|
+
type InferAttr<A> = A extends {
|
|
153
|
+
type: ObjectConstructor;
|
|
154
|
+
schema: infer S;
|
|
155
|
+
} ? InferObjectSchema<S> : A extends {
|
|
156
|
+
type: ArrayConstructor;
|
|
157
|
+
items: infer I;
|
|
158
|
+
} ? Array<InferAttr<I>> : A extends {
|
|
159
|
+
type: StringConstructor;
|
|
160
|
+
} ? string : A extends {
|
|
161
|
+
type: NumberConstructor;
|
|
162
|
+
} ? number : A extends {
|
|
163
|
+
type: BooleanConstructor;
|
|
164
|
+
} ? boolean : A extends {
|
|
165
|
+
type: DateConstructor;
|
|
166
|
+
} ? Date : unknown;
|
|
167
|
+
/**
|
|
168
|
+
* Infers the shape of a nested object schema, respecting required/optional fields.
|
|
169
|
+
*/
|
|
170
|
+
type InferObjectSchema<S> = {
|
|
171
|
+
[K in keyof S as S[K] extends {
|
|
172
|
+
required: true;
|
|
173
|
+
} ? K : never]: InferAttr<S[K]>;
|
|
174
|
+
} & {
|
|
175
|
+
[K in keyof S as S[K] extends {
|
|
176
|
+
required: true;
|
|
177
|
+
} ? never : K]?: InferAttr<S[K]>;
|
|
178
|
+
};
|
|
104
179
|
/**
|
|
105
180
|
* Non-generated attributes for input
|
|
106
181
|
* Splits into required and optional based on the 'required' field
|
|
@@ -110,7 +185,7 @@ type NonGeneratedAttributes<M extends ModelDefinition> = {
|
|
|
110
185
|
generate: string;
|
|
111
186
|
} ? never : M['attributes'][K] extends {
|
|
112
187
|
required: true;
|
|
113
|
-
} ? K : never]: InferAttr<M['attributes'][K]
|
|
188
|
+
} ? K : never]: InferAttr<M['attributes'][K]>;
|
|
114
189
|
} & {
|
|
115
190
|
[K in keyof M['attributes'] as M['attributes'][K] extends {
|
|
116
191
|
generate: string;
|
|
@@ -118,7 +193,7 @@ type NonGeneratedAttributes<M extends ModelDefinition> = {
|
|
|
118
193
|
required: false;
|
|
119
194
|
} ? K : M['attributes'][K] extends {
|
|
120
195
|
required: true;
|
|
121
|
-
} ? never : K]?: InferAttr<M['attributes'][K]
|
|
196
|
+
} ? never : K]?: InferAttr<M['attributes'][K]>;
|
|
122
197
|
};
|
|
123
198
|
/**
|
|
124
199
|
* Generated-only attributes for internal use
|
|
@@ -126,7 +201,7 @@ type NonGeneratedAttributes<M extends ModelDefinition> = {
|
|
|
126
201
|
type GeneratedAttributes<M extends ModelDefinition> = {
|
|
127
202
|
[K in keyof M['attributes'] as M['attributes'][K] extends {
|
|
128
203
|
generate: string;
|
|
129
|
-
} ? K : never]: InferAttr<M['attributes'][K]
|
|
204
|
+
} ? K : never]: InferAttr<M['attributes'][K]>;
|
|
130
205
|
};
|
|
131
206
|
/**
|
|
132
207
|
* Template string variable extraction
|
|
@@ -220,5 +295,15 @@ type KeyTemplateVars<M extends ModelDefinition> = PrimaryKeyVars<M>;
|
|
|
220
295
|
export type InferKeyInput<M extends ModelDefinition> = {
|
|
221
296
|
[K in KeyTemplateVars<M>]: string;
|
|
222
297
|
};
|
|
298
|
+
/**
|
|
299
|
+
* Extracts the item type from an array attribute.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* type StoryFrame = ArrayItem<StoryEntity['frames']>;
|
|
303
|
+
* // → { url: string; duration?: number; mediaType?: string }
|
|
304
|
+
*
|
|
305
|
+
* type HistoryEntry = ArrayItem<TransactionEntity['history']>;
|
|
306
|
+
*/
|
|
307
|
+
export type ArrayItem<T extends readonly unknown[] | undefined> = NonNullable<T>[number];
|
|
223
308
|
export {};
|
|
224
309
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,eAAe,CAAC;IACnF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,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yInput, InferModel, ModelDefinition } from '../core/types';
|
|
3
|
+
import { EntityAPI, EntityAPIOptions } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an entity API instance with validation, key resolution, and builder creation.
|
|
6
|
+
*
|
|
7
|
+
* @param tableName - The name of the DynamoDB table
|
|
8
|
+
* @param modelName - The name of the model/entity
|
|
9
|
+
* @param model - The model definition
|
|
10
|
+
* @param client - DynamoDB client instance
|
|
11
|
+
* @param options - Optional configuration (logger, timestamps, cleanInternalKeys)
|
|
12
|
+
* @returns EntityAPI with get, put, query, scan, update, delete, batchGet, and batchWrite methods
|
|
13
|
+
*/
|
|
14
|
+
export declare const createEntityAPI: <Model extends ModelDefinition>(tableName: string, modelName: string, model: Model, client: DynamoDBClient, options?: EntityAPIOptions) => EntityAPI<InferModel<Model>, InferInput<Model>, InferKeyInput<Model>>;
|
|
15
|
+
//# sourceMappingURL=create-entity-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-entity-api.d.ts","sourceRoot":"","sources":["../../src/entity/create-entity-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AActF,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAKtD;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,SAAS,eAAe,EAC3D,WAAW,MAAM,EACjB,WAAW,MAAM,EACjB,OAAO,KAAK,EACZ,QAAQ,cAAc,EACtB,UAAS,gBAAqB,KAC7B,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,CA8KtE,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEntityAPI = void 0;
|
|
4
|
+
const model_utils_1 = require("../utils/model-utils");
|
|
5
|
+
const zod_utils_1 = require("../utils/zod-utils");
|
|
6
|
+
const builders_1 = require("../builders");
|
|
7
|
+
const with_middleware_1 = require("./middleware/with-middleware");
|
|
8
|
+
const factories_1 = require("./middleware/factories");
|
|
9
|
+
const key_validation_1 = require("./validation/key-validation");
|
|
10
|
+
/**
|
|
11
|
+
* Creates an entity API instance with validation, key resolution, and builder creation.
|
|
12
|
+
*
|
|
13
|
+
* @param tableName - The name of the DynamoDB table
|
|
14
|
+
* @param modelName - The name of the model/entity
|
|
15
|
+
* @param model - The model definition
|
|
16
|
+
* @param client - DynamoDB client instance
|
|
17
|
+
* @param options - Optional configuration (logger, timestamps, cleanInternalKeys)
|
|
18
|
+
* @returns EntityAPI with get, put, query, scan, update, delete, batchGet, and batchWrite methods
|
|
19
|
+
*/
|
|
20
|
+
const createEntityAPI = (tableName, modelName, model, client, options = {}) => {
|
|
21
|
+
const { logger, timestamps = false, cleanInternalKeys = false } = options;
|
|
22
|
+
// Build a Zod schema from the model
|
|
23
|
+
const zodSchema = (0, zod_utils_1.modelToZod)(model);
|
|
24
|
+
return {
|
|
25
|
+
get(key) {
|
|
26
|
+
// Validate key fields
|
|
27
|
+
(0, key_validation_1.validateKeyFields)(modelName, model, key, 'get()');
|
|
28
|
+
// Resolve any key defaults or computed keys
|
|
29
|
+
const fullKey = (0, model_utils_1.resolveKeys)(model, key);
|
|
30
|
+
const builder = (0, builders_1.createGetBuilder)(tableName, fullKey, client, undefined, logger);
|
|
31
|
+
return (0, with_middleware_1.withMiddleware)(builder, (0, factories_1.createCleanKeysMiddleware)(cleanInternalKeys));
|
|
32
|
+
},
|
|
33
|
+
put(item) {
|
|
34
|
+
// Validate full input data
|
|
35
|
+
const parsed = zodSchema.parse(item);
|
|
36
|
+
// Apply post-processing defaults from the model (including timestamps for new items)
|
|
37
|
+
const withDefaults = (0, model_utils_1.applyPostDefaults)(model, parsed, {
|
|
38
|
+
isUpdate: false,
|
|
39
|
+
timestamps,
|
|
40
|
+
});
|
|
41
|
+
// Resolve keys again with defaults
|
|
42
|
+
const fullKey = (0, model_utils_1.resolveKeys)(model, withDefaults);
|
|
43
|
+
// Combine keys and data into full item, adding _type field
|
|
44
|
+
const fullItem = {
|
|
45
|
+
...withDefaults,
|
|
46
|
+
...fullKey,
|
|
47
|
+
_type: modelName, // Add entity type identifier
|
|
48
|
+
};
|
|
49
|
+
return (0, builders_1.createPutBuilder)(tableName, fullItem, client, [], false, 'NONE', false, logger);
|
|
50
|
+
},
|
|
51
|
+
query() {
|
|
52
|
+
// Query builder doesn't have execute() until after .where() is called
|
|
53
|
+
// The cleanInternalKeys will be handled in the builder itself
|
|
54
|
+
return (0, builders_1.createQueryBuilder)(tableName, client, model, logger);
|
|
55
|
+
},
|
|
56
|
+
scan() {
|
|
57
|
+
const builder = (0, builders_1.createScanBuilder)(tableName, client, [], [], undefined, false, undefined, undefined, undefined, logger);
|
|
58
|
+
return (0, with_middleware_1.withMiddleware)(builder, (0, factories_1.createCleanKeysMiddleware)(cleanInternalKeys));
|
|
59
|
+
},
|
|
60
|
+
update(key) {
|
|
61
|
+
// Validate key fields
|
|
62
|
+
(0, key_validation_1.validateKeyFields)(modelName, model, key, 'update()');
|
|
63
|
+
// Resolve any key defaults or computed keys
|
|
64
|
+
const fullKey = (0, model_utils_1.resolveKeys)(model, key);
|
|
65
|
+
const builder = (0, builders_1.createUpdateBuilder)(tableName, fullKey, client, [], { set: [], remove: [], add: [], delete: [] }, 'NONE', 0, timestamps, logger);
|
|
66
|
+
return (0, with_middleware_1.withMiddleware)(builder, (0, factories_1.createCleanKeysMiddleware)(cleanInternalKeys));
|
|
67
|
+
},
|
|
68
|
+
delete(key) {
|
|
69
|
+
// Validate key fields
|
|
70
|
+
(0, key_validation_1.validateKeyFields)(modelName, model, key, 'delete()');
|
|
71
|
+
// Resolve any key defaults or computed keys
|
|
72
|
+
const fullKey = (0, model_utils_1.resolveKeys)(model, key);
|
|
73
|
+
const builder = (0, builders_1.createDeleteBuilder)(tableName, fullKey, client, [], 'NONE', logger);
|
|
74
|
+
return (0, with_middleware_1.withMiddleware)(builder, (0, factories_1.createCleanKeysMiddleware)(cleanInternalKeys));
|
|
75
|
+
},
|
|
76
|
+
batchGet(keys) {
|
|
77
|
+
// Process all keys and validate them
|
|
78
|
+
const resolvedKeys = keys.map((key) => {
|
|
79
|
+
// Validate key fields
|
|
80
|
+
(0, key_validation_1.validateKeyFields)(modelName, model, key, 'batchGet()');
|
|
81
|
+
// Resolve any key defaults or computed keys
|
|
82
|
+
return (0, model_utils_1.resolveKeys)(model, key);
|
|
83
|
+
});
|
|
84
|
+
// Create the request items in the format expected by BatchGetItem
|
|
85
|
+
const requestItems = {
|
|
86
|
+
[tableName]: {
|
|
87
|
+
Keys: resolvedKeys,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const builder = (0, builders_1.createBatchGetBuilder)(requestItems, client, undefined, logger);
|
|
91
|
+
return (0, with_middleware_1.withMiddleware)(builder, (0, factories_1.createCleanKeysMiddleware)(cleanInternalKeys));
|
|
92
|
+
},
|
|
93
|
+
batchWrite(items) {
|
|
94
|
+
// Validate and process all items
|
|
95
|
+
const processedItems = items.map((item) => {
|
|
96
|
+
// Validate full input data
|
|
97
|
+
const parsed = zodSchema.parse(item);
|
|
98
|
+
// Apply post-processing defaults from the model (including timestamps for new items)
|
|
99
|
+
const withDefaults = (0, model_utils_1.applyPostDefaults)(model, parsed, {
|
|
100
|
+
isUpdate: false,
|
|
101
|
+
timestamps,
|
|
102
|
+
});
|
|
103
|
+
// Resolve keys again with defaults
|
|
104
|
+
const fullKey = (0, model_utils_1.resolveKeys)(model, withDefaults);
|
|
105
|
+
// Combine keys and data into full item, adding _type field
|
|
106
|
+
return {
|
|
107
|
+
...withDefaults,
|
|
108
|
+
...fullKey,
|
|
109
|
+
_type: modelName, // Add entity type identifier
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
// Create the request items in the format expected by BatchWriteItem
|
|
113
|
+
const requestItems = {
|
|
114
|
+
[tableName]: processedItems.map((item) => ({
|
|
115
|
+
PutRequest: {
|
|
116
|
+
Item: item,
|
|
117
|
+
},
|
|
118
|
+
})),
|
|
119
|
+
};
|
|
120
|
+
return (0, builders_1.createBatchWriteBuilder)(requestItems, client, logger);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
exports.createEntityAPI = createEntityAPI;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity API module
|
|
3
|
+
*
|
|
4
|
+
* Provides high-level entity management with validation, key resolution, and builder creation.
|
|
5
|
+
*/
|
|
6
|
+
export type { EntityAPI, EntityAPIOptions } from './types';
|
|
7
|
+
export type { ExecutionMiddleware } from './middleware/types';
|
|
8
|
+
export { withMiddleware } from './middleware/with-middleware';
|
|
9
|
+
export { createCleanKeysMiddleware } from './middleware/factories';
|
|
10
|
+
export { validateKeyFields } from './validation/key-validation';
|
|
11
|
+
export { createEntityAPI } from './create-entity-api';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Entity API module
|
|
4
|
+
*
|
|
5
|
+
* Provides high-level entity management with validation, key resolution, and builder creation.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createEntityAPI = exports.validateKeyFields = exports.createCleanKeysMiddleware = exports.withMiddleware = void 0;
|
|
9
|
+
var with_middleware_1 = require("./middleware/with-middleware");
|
|
10
|
+
Object.defineProperty(exports, "withMiddleware", { enumerable: true, get: function () { return with_middleware_1.withMiddleware; } });
|
|
11
|
+
var factories_1 = require("./middleware/factories");
|
|
12
|
+
Object.defineProperty(exports, "createCleanKeysMiddleware", { enumerable: true, get: function () { return factories_1.createCleanKeysMiddleware; } });
|
|
13
|
+
// Validation utilities
|
|
14
|
+
var key_validation_1 = require("./validation/key-validation");
|
|
15
|
+
Object.defineProperty(exports, "validateKeyFields", { enumerable: true, get: function () { return key_validation_1.validateKeyFields; } });
|
|
16
|
+
// Main entity API factory
|
|
17
|
+
var create_entity_api_1 = require("./create-entity-api");
|
|
18
|
+
Object.defineProperty(exports, "createEntityAPI", { enumerable: true, get: function () { return create_entity_api_1.createEntityAPI; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../../../src/entity/middleware/factories.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,OAAO,GAAG,mBAAmB,CAQnF"}
|