@ftschopp/dynatable-core 1.6.0 → 2.0.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 +50 -0
- package/README.md +28 -22
- package/dist/builders/batch-write/create-batch-write-builder.d.ts.map +1 -1
- package/dist/builders/batch-write/types.d.ts +8 -11
- package/dist/builders/batch-write/types.d.ts.map +1 -1
- package/dist/builders/delete/types.d.ts +12 -2
- package/dist/builders/delete/types.d.ts.map +1 -1
- package/dist/builders/get/create-get-builder.d.ts +7 -5
- package/dist/builders/get/create-get-builder.d.ts.map +1 -1
- package/dist/builders/get/create-get-builder.js +8 -15
- package/dist/builders/put/types.d.ts +12 -2
- package/dist/builders/put/types.d.ts.map +1 -1
- package/dist/builders/query/create-query-builder.d.ts.map +1 -1
- package/dist/builders/query/create-query-builder.js +13 -17
- package/dist/builders/scan/create-scan-builder.d.ts.map +1 -1
- package/dist/builders/scan/create-scan-builder.js +31 -62
- package/dist/builders/shared/operators.d.ts.map +1 -1
- package/dist/builders/shared/operators.js +2 -7
- package/dist/builders/shared/projection.d.ts.map +1 -1
- package/dist/builders/shared/projection.js +2 -9
- package/dist/builders/transact-write/create-transact-write-builder.d.ts.map +1 -1
- package/dist/builders/transact-write/types.d.ts +5 -11
- 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 +26 -65
- package/dist/builders/update/types.d.ts +12 -2
- package/dist/builders/update/types.d.ts.map +1 -1
- package/dist/core/types.d.ts +18 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/entity/types.d.ts +9 -2
- package/dist/entity/types.d.ts.map +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +4 -3
- package/dist/utils/model-utils.d.ts.map +1 -1
- package/dist/utils/model-utils.js +5 -13
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
+
# @ftschopp/dynatable-core [2.0.0](https://github.com/ftschopp/dynatable/compare/@ftschopp/dynatable-core@1.6.1...@ftschopp/dynatable-core@2.0.0) (2026-05-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Code Refactoring
|
|
5
|
+
|
|
6
|
+
* adopt functional style across core, migrations, and docs ([#53](https://github.com/ftschopp/dynatable/issues/53)) ([de6a6c4](https://github.com/ftschopp/dynatable/commit/de6a6c46aad452be51d08d7ac5886b6c4406ddea))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* (migrations): convert class-based public APIs to factory
|
|
12
|
+
functions to remove gratuitous OO ceremony — no behavior changes.
|
|
13
|
+
|
|
14
|
+
- MigrationRunner / DynamoDBMigrationTracker / MigrationLoader / ConfigLoader
|
|
15
|
+
→ createMigrationRunner / createMigrationTracker / createMigrationLoader
|
|
16
|
+
→ loadConfig / createDefaultConfig (free functions)
|
|
17
|
+
- Centralize CLI try/catch in a single runCommand helper; replace `error: any`
|
|
18
|
+
with `unknown` + narrowing throughout migrations.
|
|
19
|
+
- Group migration statuses with a single reduce instead of four .filter passes.
|
|
20
|
+
|
|
21
|
+
Core (no behavior changes):
|
|
22
|
+
- buildProjectionExpression, operators.in, resolveKeys: replace forEach/for-of
|
|
23
|
+
+ mutation with Object.fromEntries / map composition.
|
|
24
|
+
- scan.dbParams / query.dbParams / update.dbParams: replace `let params: any` +
|
|
25
|
+
imperative assignments with a single object literal using conditional spread;
|
|
26
|
+
replace `Object.assign(allNames, …)` loops with a buildSection helper that
|
|
27
|
+
reduces actions into { part, names, values }.
|
|
28
|
+
|
|
29
|
+
Docs: replace `let query = …; if (cond) query = query.set(…)` with
|
|
30
|
+
`.set(filteredFields)` or conditional `startFrom`; switch a mutating `.sort()`
|
|
31
|
+
on a feed array to `.toSorted()`.
|
|
32
|
+
|
|
33
|
+
* chore: switch to createRequire in migrations CLI/loader and pin Node 22
|
|
34
|
+
|
|
35
|
+
- Replace top-level `require()` calls with `createRequire(__filename)` in
|
|
36
|
+
cli.ts and loader.ts so the package compiles cleanly without falling back
|
|
37
|
+
on bundler-specific shims; switch `require('ts-node')` to `await import`
|
|
38
|
+
for ESM compatibility (registerTsNode is now async).
|
|
39
|
+
- Simplify update examples in blog-system.md: pass the partial `updates`
|
|
40
|
+
object directly to `.set(...)` — Dynatable already ignores undefined
|
|
41
|
+
fields, so the manual filter was redundant.
|
|
42
|
+
- Add .nvmrc pinning to Node 22 (matches engines field in package.json).
|
|
43
|
+
|
|
44
|
+
## @ftschopp/dynatable-core [1.6.1](https://github.com/ftschopp/dynatable/compare/@ftschopp/dynatable-core@1.6.0...@ftschopp/dynatable-core@1.6.1) (2026-05-10)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Bug Fixes
|
|
48
|
+
|
|
49
|
+
* **core:** preserve concrete builder type through where(), unblock IDE typecheck on tests ([#45](https://github.com/ftschopp/dynatable/issues/45)) ([fb98553](https://github.com/ftschopp/dynatable/commit/fb98553684943291f6d500200bb4b7d32e2fa613))
|
|
50
|
+
|
|
1
51
|
# @ftschopp/dynatable-core [1.6.0](https://github.com/ftschopp/dynatable/compare/@ftschopp/dynatable-core@1.5.2...@ftschopp/dynatable-core@1.6.0) (2026-05-10)
|
|
2
52
|
|
|
3
53
|
|
package/README.md
CHANGED
|
@@ -30,7 +30,6 @@ pnpm add @ftschopp/dynatable-core
|
|
|
30
30
|
```typescript
|
|
31
31
|
import { Table } from '@ftschopp/dynatable-core';
|
|
32
32
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
33
|
-
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
34
33
|
|
|
35
34
|
// Define your schema
|
|
36
35
|
const schema = {
|
|
@@ -57,14 +56,12 @@ const schema = {
|
|
|
57
56
|
},
|
|
58
57
|
} as const;
|
|
59
58
|
|
|
60
|
-
// Create
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// Create table instance
|
|
59
|
+
// Create table instance — pass the raw DynamoDBClient.
|
|
60
|
+
// Internally Dynatable uses lib-dynamodb commands which marshal/unmarshal
|
|
61
|
+
// JS values automatically; you do NOT need to wrap with DynamoDBDocumentClient.
|
|
65
62
|
const table = new Table({
|
|
66
63
|
name: 'MyTable',
|
|
67
|
-
client,
|
|
64
|
+
client: new DynamoDBClient({ region: 'us-east-1' }),
|
|
68
65
|
schema,
|
|
69
66
|
});
|
|
70
67
|
|
|
@@ -218,11 +215,14 @@ type User = InferModelFromSchema<typeof schema, 'User'>;
|
|
|
218
215
|
type UserInput = InferInputFromSchema<typeof schema, 'User'>;
|
|
219
216
|
// { username: string; name: string; email?: string; followerCount?: number }
|
|
220
217
|
|
|
221
|
-
//
|
|
222
|
-
|
|
218
|
+
// Low-level: infer directly from a ModelDefinition.
|
|
219
|
+
// Prefer InferModelFromSchema in user code; use this when you only have
|
|
220
|
+
// the model in hand (e.g. utilities that take a ModelDefinition).
|
|
221
|
+
// Note: does not honor schema-level `params.timestamps`.
|
|
222
|
+
type UserModel = InferModel<typeof schema.models.User>;
|
|
223
223
|
|
|
224
|
-
//
|
|
225
|
-
type
|
|
224
|
+
// Low-level input variant. Prefer InferInputFromSchema in user code.
|
|
225
|
+
type UserInputRaw = InferInput<typeof schema.models.User>;
|
|
226
226
|
|
|
227
227
|
// Key input type (only key template variables)
|
|
228
228
|
type UserKey = InferKeyInput<typeof schema.models.User>;
|
|
@@ -279,7 +279,7 @@ const photos = await table.entities.Photo.query()
|
|
|
279
279
|
|
|
280
280
|
// SCAN - Full table scan with filter
|
|
281
281
|
const activeUsers = await table.entities.User.scan()
|
|
282
|
-
.
|
|
282
|
+
.filter((attr, op) => op.gt(attr.followerCount, 1000))
|
|
283
283
|
.limit(50)
|
|
284
284
|
.execute();
|
|
285
285
|
|
|
@@ -291,6 +291,13 @@ const users = await table.entities.User.batchGet([
|
|
|
291
291
|
]).execute();
|
|
292
292
|
|
|
293
293
|
// BATCH WRITE - Write multiple items
|
|
294
|
+
//
|
|
295
|
+
// `batchWrite` accepts any number of items. Internally `execute()` chunks
|
|
296
|
+
// them into sub-requests of at most 25 items (DynamoDB's hard
|
|
297
|
+
// `BatchWriteItem` limit) and retries UnprocessedItems with exponential
|
|
298
|
+
// backoff (default 3 retries; configurable via `.maxRetries(n)` and
|
|
299
|
+
// `.retryBackoffMs(ms)`). If items remain unprocessed after the retry
|
|
300
|
+
// budget, `BatchUnprocessedError` is thrown.
|
|
294
301
|
await table.entities.User.batchWrite([
|
|
295
302
|
{ username: 'alice', name: 'Alice', email: 'alice@example.com' },
|
|
296
303
|
{ username: 'bob', name: 'Bob', email: 'bob@example.com' },
|
|
@@ -316,14 +323,13 @@ await table
|
|
|
316
323
|
.addUpdate(table.entities.Photo.update({ photoId: 'photo1' }).add('likesCount', 1).dbParams())
|
|
317
324
|
.execute();
|
|
318
325
|
|
|
319
|
-
// TransactGet - Atomic reads
|
|
320
|
-
|
|
326
|
+
// TransactGet - Atomic reads. execute() resolves to a flat array of
|
|
327
|
+
// items in the same order as the addGet() calls.
|
|
328
|
+
const [user, photo] = await table
|
|
321
329
|
.transactGet()
|
|
322
330
|
.addGet(table.entities.User.get({ username: 'alice' }).dbParams())
|
|
323
331
|
.addGet(table.entities.Photo.get({ photoId: 'photo1' }).dbParams())
|
|
324
332
|
.execute();
|
|
325
|
-
|
|
326
|
-
const [user, photo] = result.items;
|
|
327
333
|
```
|
|
328
334
|
|
|
329
335
|
## Available Operators
|
|
@@ -378,7 +384,7 @@ const users = await table.entities.User.query()
|
|
|
378
384
|
|
|
379
385
|
// IN operator
|
|
380
386
|
const activeUsers = await table.entities.User.scan()
|
|
381
|
-
.
|
|
387
|
+
.filter((attr, op) => op.in(attr.status, ['active', 'pending']))
|
|
382
388
|
.execute();
|
|
383
389
|
|
|
384
390
|
// Size function
|
|
@@ -462,11 +468,11 @@ export {
|
|
|
462
468
|
type IndexDefinition, // Index (hash + optional sort)
|
|
463
469
|
type IndexesDefinition, // All table indexes
|
|
464
470
|
type SchemaParams, // Global schema params
|
|
465
|
-
type InferModel, // Infer model type (
|
|
466
|
-
type InferInput, // Infer input type (
|
|
471
|
+
type InferModel, // Infer model type from a ModelDefinition (low-level)
|
|
472
|
+
type InferInput, // Infer input type from a ModelDefinition (low-level)
|
|
467
473
|
type InferKeyInput, // Infer key type
|
|
468
|
-
type InferModelFromSchema, // Infer from full schema (preferred)
|
|
469
|
-
type InferInputFromSchema, // Infer input from full schema (preferred)
|
|
474
|
+
type InferModelFromSchema, // Infer from full schema (preferred for user code)
|
|
475
|
+
type InferInputFromSchema, // Infer input from full schema (preferred for user code)
|
|
470
476
|
type TimestampFields, // createdAt/updatedAt fields type
|
|
471
477
|
type ArrayItem, // Extract item type from array attribute
|
|
472
478
|
createDynamoDBLogger, // Logger factory
|
|
@@ -487,7 +493,7 @@ Each builder type is exported for advanced use cases:
|
|
|
487
493
|
|
|
488
494
|
## Requirements
|
|
489
495
|
|
|
490
|
-
- Node.js >=
|
|
496
|
+
- Node.js >= 22
|
|
491
497
|
- TypeScript >= 5.0 (recommended)
|
|
492
498
|
- AWS SDK v3 (`@aws-sdk/client-dynamodb`, `@aws-sdk/lib-dynamodb`)
|
|
493
499
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-batch-write-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/batch-write/create-batch-write-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-batch-write-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/batch-write/create-batch-write-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAgB1D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAC5C,MAAM,EAAE,cAAc,EACtB,MAAM,CAAC,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GACA,iBAAiB,CAkEnB"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BatchWriteCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
2
|
/**
|
|
3
|
-
* A single write request
|
|
3
|
+
* A single write request — either a PutRequest or a DeleteRequest. Sourced
|
|
4
|
+
* from the SDK's `BatchWriteCommandInput.RequestItems` value type so the
|
|
5
|
+
* builder's accumulated requests are assignable to the SDK input without
|
|
6
|
+
* casts. `Item` and `Key` are `Record<string, NativeAttributeValue> | undefined`
|
|
7
|
+
* because the doc-client marshalls native JS values automatically.
|
|
4
8
|
*/
|
|
5
|
-
export type WriteRequest =
|
|
6
|
-
PutRequest?: {
|
|
7
|
-
Item: any;
|
|
8
|
-
};
|
|
9
|
-
DeleteRequest?: {
|
|
10
|
-
Key: any;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
9
|
+
export type WriteRequest = NonNullable<BatchWriteCommandInput['RequestItems']>[string][number];
|
|
13
10
|
/**
|
|
14
11
|
* BatchWriteBuilder allows you to put or delete multiple items from one or more tables
|
|
15
12
|
* in a single logical operation.
|
|
@@ -38,7 +35,7 @@ export type BatchWriteBuilder = {
|
|
|
38
35
|
* this directly to the SDK will fail at runtime — `execute()` is what
|
|
39
36
|
* applies the chunking and retry logic.
|
|
40
37
|
*/
|
|
41
|
-
dbParams():
|
|
38
|
+
dbParams(): BatchWriteCommandInput;
|
|
42
39
|
/**
|
|
43
40
|
* Execute the BatchWriteItem operation.
|
|
44
41
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/batch-write/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/batch-write/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/F;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC;IAEzC;;;OAGG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,CAAC;IAE9C;;;;;;;OAOG;IACH,QAAQ,IAAI,sBAAsB,CAAC;IAEnC;;;;;;;;;;;OAWG;IACH,OAAO,IAAI,OAAO,CAAC;QACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;KACnD,CAAC,CAAC;CACJ,CAAC"}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { DeleteCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
|
-
import { OperationBuilder } from '../shared';
|
|
2
|
+
import { OperationBuilder, AttrBuilder, OpBuilder, Condition } from '../shared';
|
|
3
3
|
/**
|
|
4
4
|
* Builder interface for DynamoDB DeleteItem operations
|
|
5
5
|
*/
|
|
6
|
-
export interface DeleteBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams'> {
|
|
6
|
+
export interface DeleteBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams' | 'where'> {
|
|
7
|
+
/**
|
|
8
|
+
* Adds a condition expression to the delete operation. Returns a new
|
|
9
|
+
* immutable builder.
|
|
10
|
+
*
|
|
11
|
+
* Override of `OperationBuilder.where(): this` because `Omit<>` doesn't
|
|
12
|
+
* preserve `this`-polymorphism — chains like `.where(...).returning(...)`
|
|
13
|
+
* would otherwise widen to `OperationBuilder<Model>` and lose the
|
|
14
|
+
* delete-specific methods.
|
|
15
|
+
*/
|
|
16
|
+
where(fn: (attr: AttrBuilder<Model>, op: OpBuilder) => Condition): DeleteBuilder<Model>;
|
|
7
17
|
/**
|
|
8
18
|
* Configures what values should be returned after the delete operation
|
|
9
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/delete/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/delete/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAC/F;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,SAAS,KAAK,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAExF;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1D;;;;;;;OAOG;IACH,sBAAsB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEjF;;OAEG;IACH,QAAQ,IAAI,kBAAkB,CAAC;CAChC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { GetBuilder } from './types';
|
|
3
3
|
import { DynamoDBLogger } from '../../utils/dynamodb-logger';
|
|
4
|
-
|
|
5
|
-
* Creates a GetBuilder to retrieve an item by its key.
|
|
6
|
-
*/
|
|
7
|
-
export declare function createGetBuilder<KeyInput, Model>(tableName: string, key: Record<string, any>, client: DynamoDBClient, options?: {
|
|
4
|
+
type GetBuilderOptions<Model> = {
|
|
8
5
|
projection?: (keyof Model)[];
|
|
9
6
|
consistentRead?: boolean;
|
|
10
7
|
returnConsumedCapacity?: 'INDEXES' | 'TOTAL' | 'NONE';
|
|
11
|
-
}
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates a GetBuilder to retrieve an item by its key.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createGetBuilder<KeyInput, Model>(tableName: string, key: Record<string, any>, client: DynamoDBClient, options?: GetBuilderOptions<Model>, logger?: DynamoDBLogger): GetBuilder<KeyInput, Model>;
|
|
13
|
+
export {};
|
|
12
14
|
//# sourceMappingURL=create-get-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-get-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/get/create-get-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D
|
|
1
|
+
{"version":3,"file":"create-get-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/get/create-get-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,KAAK,iBAAiB,CAAC,KAAK,IAAI;IAC9B,UAAU,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sBAAsB,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAC9C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAClC,MAAM,CAAC,EAAE,cAAc,GACtB,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAoF7B"}
|
|
@@ -10,36 +10,29 @@ function createGetBuilder(tableName, key, client, options, logger) {
|
|
|
10
10
|
const projection = options?.projection ?? [];
|
|
11
11
|
const isConsistent = options?.consistentRead ?? false;
|
|
12
12
|
const consumedCapacity = options?.returnConsumedCapacity;
|
|
13
|
+
const buildOpts = (overrides) => ({
|
|
14
|
+
projection: overrides.projection ?? projection,
|
|
15
|
+
consistentRead: overrides.consistentRead ?? isConsistent,
|
|
16
|
+
returnConsumedCapacity: overrides.returnConsumedCapacity ?? consumedCapacity,
|
|
17
|
+
});
|
|
13
18
|
return {
|
|
14
19
|
/**
|
|
15
20
|
* Select only specific attributes to retrieve.
|
|
16
21
|
*/
|
|
17
22
|
select(attrs) {
|
|
18
|
-
return createGetBuilder(tableName, key, client, {
|
|
19
|
-
projection: attrs,
|
|
20
|
-
consistentRead: isConsistent,
|
|
21
|
-
returnConsumedCapacity: consumedCapacity,
|
|
22
|
-
}, logger);
|
|
23
|
+
return createGetBuilder(tableName, key, client, buildOpts({ projection: attrs }), logger);
|
|
23
24
|
},
|
|
24
25
|
/**
|
|
25
26
|
* Enable strongly consistent read.
|
|
26
27
|
*/
|
|
27
28
|
consistentRead() {
|
|
28
|
-
return createGetBuilder(tableName, key, client, {
|
|
29
|
-
projection,
|
|
30
|
-
consistentRead: true,
|
|
31
|
-
returnConsumedCapacity: consumedCapacity,
|
|
32
|
-
}, logger);
|
|
29
|
+
return createGetBuilder(tableName, key, client, buildOpts({ consistentRead: true }), logger);
|
|
33
30
|
},
|
|
34
31
|
/**
|
|
35
32
|
* Configure ReturnConsumedCapacity parameter.
|
|
36
33
|
*/
|
|
37
34
|
returnConsumedCapacity(mode) {
|
|
38
|
-
return createGetBuilder(tableName, key, client, {
|
|
39
|
-
projection,
|
|
40
|
-
consistentRead: isConsistent,
|
|
41
|
-
returnConsumedCapacity: mode,
|
|
42
|
-
}, logger);
|
|
35
|
+
return createGetBuilder(tableName, key, client, buildOpts({ returnConsumedCapacity: mode }), logger);
|
|
43
36
|
},
|
|
44
37
|
/**
|
|
45
38
|
* Build the underlying DynamoDB input parameters.
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { PutCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
|
-
import { OperationBuilder } from '../shared';
|
|
2
|
+
import { OperationBuilder, AttrBuilder, OpBuilder, Condition } from '../shared';
|
|
3
3
|
/**
|
|
4
4
|
* Builder interface for DynamoDB PutItem operations
|
|
5
5
|
*/
|
|
6
|
-
export interface PutBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams'> {
|
|
6
|
+
export interface PutBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams' | 'where'> {
|
|
7
|
+
/**
|
|
8
|
+
* Adds a condition expression to the put operation. Returns a new
|
|
9
|
+
* immutable builder.
|
|
10
|
+
*
|
|
11
|
+
* Override of `OperationBuilder.where(): this` because `Omit<>` doesn't
|
|
12
|
+
* preserve `this`-polymorphism — chains like `.where(...).ifNotExists()`
|
|
13
|
+
* would otherwise widen to `OperationBuilder<Model>` and lose the
|
|
14
|
+
* put-specific methods.
|
|
15
|
+
*/
|
|
16
|
+
where(fn: (attr: AttrBuilder<Model>, op: OpBuilder) => Condition): PutBuilder<Model>;
|
|
7
17
|
/**
|
|
8
18
|
* Adds a condition that the item must not exist (checks pk and sk)
|
|
9
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/put/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/put/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,KAAK,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAC5F;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,SAAS,KAAK,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAErF;;OAEG;IACH,WAAW,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAEjC;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAEvD;;;;;;;;OAQG;IACH,sBAAsB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAE9E;;OAEG;IACH,QAAQ,IAAI,eAAe,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-query-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/query/create-query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAM1D,OAAO,EAAE,YAAY,EAA8B,MAAM,SAAS,CAAC;AACnE,OAAO,EAAiB,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"create-query-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/query/create-query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAM1D,OAAO,EAAE,YAAY,EAA8B,MAAM,SAAS,CAAC;AACnE,OAAO,EAAiB,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAid7D;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EACtC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,cAAc,EACtB,KAAK,CAAC,EAAE,eAAe,EACvB,MAAM,CAAC,EAAE,cAAc,EACvB,UAAU,CAAC,EAAE,MAAM,GAClB,YAAY,CAAC,KAAK,CAAC,CA0BrB"}
|
|
@@ -284,24 +284,22 @@ function createQueryExecutor(state) {
|
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
// Merge attribute names and values from both expressions
|
|
287
|
+
// Build ProjectionExpression with placeholders so reserved words
|
|
288
|
+
// (name, date, status, type, …) don't blow up at DynamoDB.
|
|
289
|
+
// Idempotent merge: filter/key and projection placeholders both map
|
|
290
|
+
// `#name → name`, so collisions resolve to the same value.
|
|
291
|
+
const projection = state.projection && state.projection.length > 0
|
|
292
|
+
? (0, projection_1.buildProjectionExpression)(state.projection.map((a) => String(a)))
|
|
293
|
+
: undefined;
|
|
287
294
|
const allNames = {
|
|
288
295
|
...(keyExpr.names ?? {}),
|
|
289
296
|
...(filterExpr.names ?? {}),
|
|
297
|
+
...(projection?.ExpressionAttributeNames ?? {}),
|
|
290
298
|
};
|
|
291
299
|
const allValues = {
|
|
292
300
|
...(keyExpr.values ?? {}),
|
|
293
301
|
...(filterExpr.values ?? {}),
|
|
294
302
|
};
|
|
295
|
-
// Build ProjectionExpression with placeholders so reserved words
|
|
296
|
-
// (name, date, status, type, …) don't blow up at DynamoDB.
|
|
297
|
-
// Idempotent merge: filter/key and projection placeholders both map
|
|
298
|
-
// `#name → name`, so collisions resolve to the same value.
|
|
299
|
-
let projectionExpression;
|
|
300
|
-
if (state.projection && state.projection.length > 0) {
|
|
301
|
-
const proj = (0, projection_1.buildProjectionExpression)(state.projection.map((a) => String(a)));
|
|
302
|
-
projectionExpression = proj.ProjectionExpression;
|
|
303
|
-
Object.assign(allNames, proj.ExpressionAttributeNames);
|
|
304
|
-
}
|
|
305
303
|
return {
|
|
306
304
|
TableName: state.tableName,
|
|
307
305
|
...(keyExpr.expression && {
|
|
@@ -321,8 +319,8 @@ function createQueryExecutor(state) {
|
|
|
321
319
|
...(state.scanForward !== undefined && {
|
|
322
320
|
ScanIndexForward: state.scanForward,
|
|
323
321
|
}),
|
|
324
|
-
...(
|
|
325
|
-
ProjectionExpression:
|
|
322
|
+
...(projection && {
|
|
323
|
+
ProjectionExpression: projection.ProjectionExpression,
|
|
326
324
|
}),
|
|
327
325
|
...(state.consistentReadEnabled && { ConsistentRead: true }),
|
|
328
326
|
...(state.exclusiveStartKey && {
|
|
@@ -389,16 +387,14 @@ function createQueryBuilder(tableName, client, model, logger, entityType) {
|
|
|
389
387
|
const opBuilder = (0, operators_1.createOpBuilder)();
|
|
390
388
|
// Call the user's function to get the condition tree
|
|
391
389
|
const condition = fn(attrProxy, opBuilder);
|
|
392
|
-
|
|
393
|
-
const initialState = {
|
|
390
|
+
return createQueryExecutor({
|
|
394
391
|
tableName,
|
|
395
392
|
client,
|
|
396
|
-
model,
|
|
397
393
|
condition,
|
|
394
|
+
model,
|
|
398
395
|
logger,
|
|
399
396
|
entityType,
|
|
400
|
-
};
|
|
401
|
-
return createQueryExecutor(initialState);
|
|
397
|
+
});
|
|
402
398
|
},
|
|
403
399
|
};
|
|
404
400
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-scan-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/scan/create-scan-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAGL,SAAS,EAGV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,SAAS,EAAO,EACzB,eAAe,GAAE,CAAC,MAAM,KAAK,CAAC,EAAO,EACrC,UAAU,CAAC,EAAE,MAAM,EACnB,gBAAgB,UAAQ,EACxB,SAAS,CAAC,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACvC,aAAa,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,EAC1D,MAAM,CAAC,EAAE,cAAc,EACvB,gBAAgB,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAC9C,WAAW,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"create-scan-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/scan/create-scan-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAGL,SAAS,EAGV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,SAAS,EAAO,EACzB,eAAe,GAAE,CAAC,MAAM,KAAK,CAAC,EAAO,EACrC,UAAU,CAAC,EAAE,MAAM,EACnB,gBAAgB,UAAQ,EACxB,SAAS,CAAC,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACvC,aAAa,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,EAC1D,MAAM,CAAC,EAAE,cAAc,EACvB,gBAAgB,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAC9C,WAAW,CAAC,KAAK,CAAC,CAgOpB"}
|
|
@@ -40,71 +40,40 @@ function createScanBuilder(tableName, client, filters = [], projectionAttrs = []
|
|
|
40
40
|
return createScanBuilder(tableName, client, filters, projectionAttrs, limitValue, isConsistentRead, indexName, exclusiveStartKey, segmentConfig, logger, mode);
|
|
41
41
|
},
|
|
42
42
|
dbParams() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let expressionAttributeValues = {};
|
|
46
|
-
// Build FilterExpression from filters
|
|
47
|
-
if (filters.length > 0) {
|
|
48
|
-
const combinedFilter = filters.length === 1 && filters[0]
|
|
43
|
+
const filterResult = filters.length > 0
|
|
44
|
+
? (0, shared_1.buildExpression)(filters.length === 1 && filters[0]
|
|
49
45
|
? filters[0]
|
|
50
|
-
: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let projectionExpression = '';
|
|
63
|
-
if (projectionAttrs.length > 0) {
|
|
64
|
-
const proj = (0, shared_1.buildProjectionExpression)(projectionAttrs.map((attr) => String(attr)));
|
|
65
|
-
projectionExpression = proj.ProjectionExpression;
|
|
66
|
-
// Idempotent merge: filter and projection placeholders both map
|
|
67
|
-
// `#name → name`, so collisions resolve to the same value.
|
|
68
|
-
expressionAttributeNames = {
|
|
69
|
-
...proj.ExpressionAttributeNames,
|
|
70
|
-
...expressionAttributeNames,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const params = {
|
|
46
|
+
: { expression: '', operator: 'AND', children: filters })
|
|
47
|
+
: { expression: '', names: {}, values: {} };
|
|
48
|
+
// Idempotent merge: filter and projection placeholders both map
|
|
49
|
+
// `#name → name`, so collisions resolve to the same value.
|
|
50
|
+
const projection = projectionAttrs.length > 0
|
|
51
|
+
? (0, shared_1.buildProjectionExpression)(projectionAttrs.map((attr) => String(attr)))
|
|
52
|
+
: undefined;
|
|
53
|
+
const expressionAttributeNames = {
|
|
54
|
+
...(projection?.ExpressionAttributeNames ?? {}),
|
|
55
|
+
...filterResult.names,
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
74
58
|
TableName: tableName,
|
|
59
|
+
...(filterResult.expression && { FilterExpression: filterResult.expression }),
|
|
60
|
+
...(Object.keys(expressionAttributeNames).length > 0 && {
|
|
61
|
+
ExpressionAttributeNames: expressionAttributeNames,
|
|
62
|
+
}),
|
|
63
|
+
...(Object.keys(filterResult.values).length > 0 && {
|
|
64
|
+
ExpressionAttributeValues: filterResult.values,
|
|
65
|
+
}),
|
|
66
|
+
...(projection && { ProjectionExpression: projection.ProjectionExpression }),
|
|
67
|
+
...(limitValue !== undefined && { Limit: limitValue }),
|
|
68
|
+
...(isConsistentRead && { ConsistentRead: true }),
|
|
69
|
+
...(indexName && { IndexName: indexName }),
|
|
70
|
+
...(exclusiveStartKey && { ExclusiveStartKey: exclusiveStartKey }),
|
|
71
|
+
...(segmentConfig && {
|
|
72
|
+
Segment: segmentConfig.segment,
|
|
73
|
+
TotalSegments: segmentConfig.totalSegments,
|
|
74
|
+
}),
|
|
75
|
+
...(consumedCapacity && { ReturnConsumedCapacity: consumedCapacity }),
|
|
75
76
|
};
|
|
76
|
-
if (filterExpression) {
|
|
77
|
-
params.FilterExpression = filterExpression;
|
|
78
|
-
}
|
|
79
|
-
if (Object.keys(expressionAttributeNames).length > 0) {
|
|
80
|
-
params.ExpressionAttributeNames = expressionAttributeNames;
|
|
81
|
-
}
|
|
82
|
-
if (Object.keys(expressionAttributeValues).length > 0) {
|
|
83
|
-
params.ExpressionAttributeValues = expressionAttributeValues;
|
|
84
|
-
}
|
|
85
|
-
if (projectionExpression) {
|
|
86
|
-
params.ProjectionExpression = projectionExpression;
|
|
87
|
-
}
|
|
88
|
-
if (limitValue !== undefined) {
|
|
89
|
-
params.Limit = limitValue;
|
|
90
|
-
}
|
|
91
|
-
if (isConsistentRead) {
|
|
92
|
-
params.ConsistentRead = true;
|
|
93
|
-
}
|
|
94
|
-
if (indexName) {
|
|
95
|
-
params.IndexName = indexName;
|
|
96
|
-
}
|
|
97
|
-
if (exclusiveStartKey) {
|
|
98
|
-
params.ExclusiveStartKey = exclusiveStartKey;
|
|
99
|
-
}
|
|
100
|
-
if (segmentConfig) {
|
|
101
|
-
params.Segment = segmentConfig.segment;
|
|
102
|
-
params.TotalSegments = segmentConfig.totalSegments;
|
|
103
|
-
}
|
|
104
|
-
if (consumedCapacity) {
|
|
105
|
-
params.ReturnConsumedCapacity = consumedCapacity;
|
|
106
|
-
}
|
|
107
|
-
return params;
|
|
108
77
|
},
|
|
109
78
|
/**
|
|
110
79
|
* ⚠️ Returns only the FIRST page of results. DynamoDB caps each Scan
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../../src/builders/shared/operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,eAAe,IAAI,SAAS,
|
|
1
|
+
{"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../../src/builders/shared/operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,eAAe,IAAI,SAAS,CA6L3C;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,SAA6B,CAAC"}
|
|
@@ -117,15 +117,10 @@ function createOpBuilder() {
|
|
|
117
117
|
},
|
|
118
118
|
in: (attr, values) => {
|
|
119
119
|
const valueNames = values.map((_, i) => getUniqueValueName(`${attr.name}_in${i}`));
|
|
120
|
-
const placeholders = valueNames.map((name) => `:${name}`).join(', ');
|
|
121
|
-
const valuesObj = {};
|
|
122
|
-
valueNames.forEach((name, i) => {
|
|
123
|
-
valuesObj[`:${name}`] = values[i];
|
|
124
|
-
});
|
|
125
120
|
return {
|
|
126
|
-
expression: `#${attr.name} IN (${
|
|
121
|
+
expression: `#${attr.name} IN (${valueNames.map((name) => `:${name}`).join(', ')})`,
|
|
127
122
|
names: { [`#${attr.name}`]: attr.name },
|
|
128
|
-
values:
|
|
123
|
+
values: Object.fromEntries(valueNames.map((name, i) => [`:${name}`, values[i]])),
|
|
129
124
|
};
|
|
130
125
|
},
|
|
131
126
|
size: (attr) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/builders/shared/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;IAC1D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD,
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/builders/shared/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;IAC1D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD,CAKA"}
|
|
@@ -12,15 +12,8 @@ exports.buildProjectionExpression = buildProjectionExpression;
|
|
|
12
12
|
* `ValidationException: Attribute name is a reserved keyword`.
|
|
13
13
|
*/
|
|
14
14
|
function buildProjectionExpression(attrs) {
|
|
15
|
-
const names = {};
|
|
16
|
-
const projectionParts = [];
|
|
17
|
-
attrs.forEach((attr) => {
|
|
18
|
-
const placeholder = `#${attr}`;
|
|
19
|
-
names[placeholder] = attr;
|
|
20
|
-
projectionParts.push(placeholder);
|
|
21
|
-
});
|
|
22
15
|
return {
|
|
23
|
-
ProjectionExpression:
|
|
24
|
-
ExpressionAttributeNames:
|
|
16
|
+
ProjectionExpression: attrs.map((attr) => `#${attr}`).join(', '),
|
|
17
|
+
ExpressionAttributeNames: Object.fromEntries(attrs.map((attr) => [`#${attr}`, attr])),
|
|
25
18
|
};
|
|
26
19
|
}
|
|
@@ -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":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,oBAAoB,
|
|
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,EAOrB,MAAM,SAAS,CAAC;AA6GjB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,cAAc,KAAG,oBAGnE,CAAC"}
|
|
@@ -25,18 +25,12 @@ export type TransactDeleteParams = DeleteCommandInput | StrictTransactDelete;
|
|
|
25
25
|
*/
|
|
26
26
|
export type TransactConditionCheckParams = StrictTransactConditionCheck;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Single item in a TransactWrite operation. Mirrors the SDK's
|
|
29
|
+
* `TransactWriteCommandInput['TransactItems']` element shape (all four
|
|
30
|
+
* fields optional) so the builder's accumulated items are assignable to
|
|
31
|
+
* the SDK input without unsafe casts.
|
|
30
32
|
*/
|
|
31
|
-
export type TransactWriteItem =
|
|
32
|
-
Put: any;
|
|
33
|
-
} | {
|
|
34
|
-
Update: any;
|
|
35
|
-
} | {
|
|
36
|
-
Delete: any;
|
|
37
|
-
} | {
|
|
38
|
-
ConditionCheck: any;
|
|
39
|
-
};
|
|
33
|
+
export type TransactWriteItem = TransactWriteItems[number];
|
|
40
34
|
/**
|
|
41
35
|
* State for the TransactWrite builder
|
|
42
36
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/transact-write/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/transact-write/types.ts"],"names":[],"mappings":"AAAA,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,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nD,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,0BAA0B,CAAC,CAAC;CAC7D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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,YAAY,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAyB7D;;;;;;;;GAQG;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,EACvB,YAAY,CAAC,EAAE,YAAY,EAC3B,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACnC,gBAAgB,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAC9C,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,YAAY,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAyB7D;;;;;;;;GAQG;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,EACvB,YAAY,CAAC,EAAE,YAAY,EAC3B,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACnC,gBAAgB,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAC9C,aAAa,CAAC,KAAK,CAAC,CAubtB"}
|
|
@@ -124,10 +124,6 @@ function createUpdateBuilder(tableName, key, client, prevConditions = [], update
|
|
|
124
124
|
return createUpdateBuilder(tableName, key, client, conditions, updateActions, returnMode, valueCounter, enableTimestamps, logger, indexContext, setInputs, mode);
|
|
125
125
|
},
|
|
126
126
|
dbParams() {
|
|
127
|
-
// Build UpdateExpression from actions
|
|
128
|
-
const updateParts = [];
|
|
129
|
-
const allNames = {};
|
|
130
|
-
const allValues = {};
|
|
131
127
|
// Clone updateActions to avoid mutation
|
|
132
128
|
const actionsToProcess = { ...updateActions, set: [...updateActions.set] };
|
|
133
129
|
// Auto-recompute secondary-index keys whose templates depend on any
|
|
@@ -241,38 +237,24 @@ function createUpdateBuilder(tableName, key, client, prevConditions = [], update
|
|
|
241
237
|
};
|
|
242
238
|
actionsToProcess.set = [...actionsToProcess.set, timestampAction];
|
|
243
239
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
Object.assign(allValues, action.values || {});
|
|
263
|
-
return action.expression;
|
|
264
|
-
});
|
|
265
|
-
updateParts.push(`ADD ${addExpressions.join(', ')}`);
|
|
266
|
-
}
|
|
267
|
-
if (updateActions.delete.length > 0) {
|
|
268
|
-
const deleteExpressions = updateActions.delete.map((action) => {
|
|
269
|
-
Object.assign(allNames, action.names || {});
|
|
270
|
-
Object.assign(allValues, action.values || {});
|
|
271
|
-
return action.expression;
|
|
272
|
-
});
|
|
273
|
-
updateParts.push(`DELETE ${deleteExpressions.join(', ')}`);
|
|
274
|
-
}
|
|
275
|
-
const updateExpression = updateParts.join(' ');
|
|
240
|
+
const buildSection = (label, actions, includeValues) => actions.length === 0
|
|
241
|
+
? null
|
|
242
|
+
: {
|
|
243
|
+
part: `${label} ${actions.map((a) => a.expression).join(', ')}`,
|
|
244
|
+
names: Object.assign({}, ...actions.map((a) => a.names ?? {})),
|
|
245
|
+
values: includeValues
|
|
246
|
+
? Object.assign({}, ...actions.map((a) => a.values ?? {}))
|
|
247
|
+
: {},
|
|
248
|
+
};
|
|
249
|
+
const sections = [
|
|
250
|
+
buildSection('SET', actionsToProcess.set, true),
|
|
251
|
+
buildSection('REMOVE', updateActions.remove, false),
|
|
252
|
+
buildSection('ADD', updateActions.add, true),
|
|
253
|
+
buildSection('DELETE', updateActions.delete, true),
|
|
254
|
+
].filter((s) => s !== null);
|
|
255
|
+
const updateExpression = sections.map((s) => s.part).join(' ');
|
|
256
|
+
const allNames = Object.assign({}, ...sections.map((s) => s.names));
|
|
257
|
+
const allValues = Object.assign({}, ...sections.map((s) => s.values));
|
|
276
258
|
// DynamoDB rejects an UpdateCommand without an UpdateExpression
|
|
277
259
|
// ("ValidationException: ExpressionAttributeNames must not be empty"
|
|
278
260
|
// or worse, "Member must not be null"). Throw a clearer error
|
|
@@ -284,39 +266,18 @@ function createUpdateBuilder(tableName, key, client, prevConditions = [], update
|
|
|
284
266
|
'modifying anything, use a get() instead.');
|
|
285
267
|
}
|
|
286
268
|
// Build ConditionExpression from conditions
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
let conditionValues = {};
|
|
290
|
-
if (conditions.length > 0) {
|
|
291
|
-
const combinedCondition = conditions.length === 1 && conditions[0]
|
|
269
|
+
const conditionResult = conditions.length > 0
|
|
270
|
+
? (0, shared_1.buildExpression)(conditions.length === 1 && conditions[0]
|
|
292
271
|
? conditions[0]
|
|
293
|
-
: {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
};
|
|
298
|
-
const result = (0, shared_1.buildExpression)(combinedCondition);
|
|
299
|
-
conditionExpression = result.expression;
|
|
300
|
-
conditionNames = result.names;
|
|
301
|
-
conditionValues = result.values;
|
|
302
|
-
}
|
|
303
|
-
// Merge names and values
|
|
304
|
-
const expressionAttributeNames = {
|
|
305
|
-
...allNames,
|
|
306
|
-
...conditionNames,
|
|
307
|
-
};
|
|
308
|
-
const expressionAttributeValues = {
|
|
309
|
-
...allValues,
|
|
310
|
-
...conditionValues,
|
|
311
|
-
};
|
|
312
|
-
const extra = returnMode !== 'NONE' ? { ReturnValues: returnMode } : {};
|
|
272
|
+
: { expression: '', operator: 'AND', children: conditions })
|
|
273
|
+
: { expression: '', names: {}, values: {} };
|
|
274
|
+
const expressionAttributeNames = { ...allNames, ...conditionResult.names };
|
|
275
|
+
const expressionAttributeValues = { ...allValues, ...conditionResult.values };
|
|
313
276
|
return {
|
|
314
277
|
TableName: tableName,
|
|
315
278
|
Key: key,
|
|
316
279
|
...(updateExpression && { UpdateExpression: updateExpression }),
|
|
317
|
-
...(
|
|
318
|
-
ConditionExpression: conditionExpression,
|
|
319
|
-
}),
|
|
280
|
+
...(conditionResult.expression && { ConditionExpression: conditionResult.expression }),
|
|
320
281
|
...(Object.keys(expressionAttributeNames).length && {
|
|
321
282
|
ExpressionAttributeNames: expressionAttributeNames,
|
|
322
283
|
}),
|
|
@@ -324,7 +285,7 @@ function createUpdateBuilder(tableName, key, client, prevConditions = [], update
|
|
|
324
285
|
ExpressionAttributeValues: expressionAttributeValues,
|
|
325
286
|
}),
|
|
326
287
|
...(consumedCapacity && { ReturnConsumedCapacity: consumedCapacity }),
|
|
327
|
-
...
|
|
288
|
+
...(returnMode !== 'NONE' && { ReturnValues: returnMode }),
|
|
328
289
|
};
|
|
329
290
|
},
|
|
330
291
|
async execute() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
2
|
import { ModelDefinition } from '../../core/types';
|
|
3
|
-
import { OperationBuilder, AttrRef } from '../shared';
|
|
3
|
+
import { OperationBuilder, AttrRef, AttrBuilder, OpBuilder, Condition } from '../shared';
|
|
4
4
|
/**
|
|
5
5
|
* Update actions that can be performed on attributes
|
|
6
6
|
*/
|
|
@@ -24,7 +24,17 @@ export type IndexContext = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Builder interface for DynamoDB UpdateItem operations
|
|
26
26
|
*/
|
|
27
|
-
export interface UpdateBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams'> {
|
|
27
|
+
export interface UpdateBuilder<Model> extends Omit<OperationBuilder<Model>, 'dbParams' | 'where'> {
|
|
28
|
+
/**
|
|
29
|
+
* Adds a condition expression to the update operation. Returns a new
|
|
30
|
+
* immutable builder.
|
|
31
|
+
*
|
|
32
|
+
* Override of `OperationBuilder.where(): this` because `Omit<>` doesn't
|
|
33
|
+
* preserve `this`-polymorphism — chains like `.where(...).set(...)` or
|
|
34
|
+
* `.where(...).returning(...)` would otherwise widen to
|
|
35
|
+
* `OperationBuilder<Model>` and lose the update-specific methods.
|
|
36
|
+
*/
|
|
37
|
+
where(fn: (attr: AttrBuilder<Model>, op: OpBuilder) => Condition): UpdateBuilder<Model>;
|
|
28
38
|
/**
|
|
29
39
|
* Sets an attribute to a specific value, or sets multiple attributes at once
|
|
30
40
|
*/
|
|
@@ -1 +1 @@
|
|
|
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,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,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,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEzF;;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;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC;AA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M extends ModelDefinition> = {
|
|
|
238
238
|
} ? K : never;
|
|
239
239
|
}[keyof NonGeneratedAttributes<M>];
|
|
240
240
|
/**
|
|
241
|
-
* Input type used for put/update
|
|
241
|
+
* Input type used for put/update.
|
|
242
242
|
*
|
|
243
|
-
*
|
|
243
|
+
* Low-level primitive: takes a `ModelDefinition` directly. Most user code
|
|
244
|
+
* should prefer `InferInputFromSchema`, the schema-driven entry point that
|
|
245
|
+
* stays consistent with `InferModelFromSchema`. Use `InferInput` when you
|
|
246
|
+
* only have a `ModelDefinition` in hand — for example, when authoring
|
|
247
|
+
* utilities that consume models directly without the surrounding schema.
|
|
248
|
+
*
|
|
249
|
+
* Note: `createdAt`/`updatedAt` are never part of the input shape, even
|
|
250
|
+
* when `params.timestamps` is enabled — they are generated automatically
|
|
251
|
+
* on put/update.
|
|
244
252
|
*/
|
|
245
253
|
export type InferInput<M extends ModelDefinition> = {
|
|
246
254
|
[K in keyof NonGeneratedAttributes<M> as K extends RequiredKeys<M> ? K : never]: NonGeneratedAttributes<M>[K];
|
|
@@ -267,9 +275,15 @@ export type TimestampFields = {
|
|
|
267
275
|
};
|
|
268
276
|
/**
|
|
269
277
|
* Infers the model type without exposing internal DynamoDB keys (PK, SK, GSI1PK, etc.)
|
|
270
|
-
* Only includes business attributes and generated fields
|
|
278
|
+
* Only includes business attributes and generated fields.
|
|
271
279
|
*
|
|
272
|
-
*
|
|
280
|
+
* Low-level primitive: takes a `ModelDefinition` directly and therefore has
|
|
281
|
+
* no access to schema-level params (e.g. `params.timestamps`). Most user code
|
|
282
|
+
* should prefer `InferModelFromSchema`, which honors `params.timestamps` and
|
|
283
|
+
* automatically includes `createdAt`/`updatedAt` when enabled. Use
|
|
284
|
+
* `InferModel` when you only have a `ModelDefinition` in hand — for example,
|
|
285
|
+
* when authoring utilities that consume models directly without the
|
|
286
|
+
* surrounding schema.
|
|
273
287
|
*/
|
|
274
288
|
export type InferModel<M extends ModelDefinition> = ModelAttributes<M>;
|
|
275
289
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Ae,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG;KAC9E,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,MAAM;CAC9B,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAC/C;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,MAAM;CAChC,GACD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAE7B;;GAEG;AACH,KAAK,eAAe,CAAC,CAAC,SAAS,eAAe,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,eAAe,IAAI;KACpD,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,MAAM;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,SAAS,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/entity/types.d.ts
CHANGED
|
@@ -61,8 +61,15 @@ export type EntityAPI<Model, Input, KeyInput> = {
|
|
|
61
61
|
*/
|
|
62
62
|
batchGet: (keys: KeyInput[]) => BatchGetBuilder<Model>;
|
|
63
63
|
/**
|
|
64
|
-
* Writes multiple items in a single batch operation
|
|
65
|
-
*
|
|
64
|
+
* Writes multiple items in a single batch operation.
|
|
65
|
+
*
|
|
66
|
+
* Accepts any number of items: `execute()` chunks the request into
|
|
67
|
+
* sub-requests of at most 25 items (DynamoDB's hard `BatchWriteItem`
|
|
68
|
+
* limit) and retries any UnprocessedItems with exponential backoff.
|
|
69
|
+
* If items remain unprocessed after the retry budget, a
|
|
70
|
+
* `BatchUnprocessedError` is thrown.
|
|
71
|
+
*
|
|
72
|
+
* @param items - Items to put. No upper bound — chunking is transparent.
|
|
66
73
|
* @returns BatchWriteBuilder configured for the items
|
|
67
74
|
*/
|
|
68
75
|
batchWrite: (items: Input[]) => BatchWriteBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/entity/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACL,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,WAAW,EACX,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,IAAI;IAC9C;;;;OAIG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEpD;;;;OAIG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC;IAExC;;;OAGG;IACH,KAAK,EAAE,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;IAEjC;;;OAGG;IACH,IAAI,EAAE,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;IAE/B;;;;OAIG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;IAEhD;;;;OAIG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;IAEhD;;;;OAIG;IACH,QAAQ,EAAE,CAAC,IAAI,E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AAe,CAAC,KAAK,CAAC,CAAC;IAEvD;;;;;;;;;;;OAWG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,iBAAiB,CAAC;CACnD,CAAC"}
|
package/dist/table.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAmB,SAAS,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAmB,SAAS,EAAoB,MAAM,UAAU,CAAC;AACxE,OAAO,EAA8B,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAA4B,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,gBAAgB,IAAI;IACpD,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,MAAM,EAAE,cAAc,CAAC;IACvB,uDAAuD;IACvD,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,wDAAwD;IACxD,MAAM,EAAE,CAAC,CAAC;CACX,CAAC;AAEF;;;GAGG;AACH,KAAK,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC;AAEjD;;GAEG;AACH,KAAK,SAAS,CAAC,CAAC,SAAS,gBAAgB,IAAI;KAC1C,CAAC,IAAI,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,SAAS,CACjC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EACpC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EACpC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACxC;CACF,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,KAAK,CAAC,CAAC,SAAS,gBAAgB;IAC3C,4BAA4B;IAC5B,SAAgB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAEvC,sBAAsB;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;gBAE5B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAgClC;;;;;;;;;;;;;OAaG;IACH,aAAa,IAAI,oBAAoB;IAIrC;;;;;;;;;;;;;OAaG;IACH,WAAW,IAAI,kBAAkB;CAGlC"}
|
package/dist/table.js
CHANGED
|
@@ -31,12 +31,13 @@ class Table {
|
|
|
31
31
|
if (!model) {
|
|
32
32
|
throw new Error(`Model '${modelName}' is missing in schema`);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
logger,
|
|
34
|
+
const entityOpts = {
|
|
36
35
|
timestamps: schema.params?.timestamps ?? false,
|
|
37
36
|
cleanInternalKeys: schema.params?.cleanInternalKeys ?? false,
|
|
38
37
|
internalKeys,
|
|
39
|
-
|
|
38
|
+
logger,
|
|
39
|
+
};
|
|
40
|
+
rawEntities[modelName] = (0, entity_1.createEntityAPI)(tableName, modelName, model, client, entityOpts);
|
|
40
41
|
}
|
|
41
42
|
this.entities = rawEntities;
|
|
42
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/utils/model-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAiB,eAAe,EAAE,MAAM,cAAc,CAAC;AAG7F;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,MAAM,EAG5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAoB7E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EACnD,OAAO,CAAC,EACR,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,OAAM,KAAK,GAAG,OAAO,GAAG,MAAc,KACrC,MAAM,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/utils/model-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAiB,eAAe,EAAE,MAAM,cAAc,CAAC;AAG7F;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,MAAM,EAG5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAoB7E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EACnD,OAAO,CAAC,EACR,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,OAAM,KAAK,GAAG,OAAO,GAAG,MAAc,KACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAQvB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CACnE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,eAAe,EAC3D,OAAO,CAAC,EACR,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC3B,mBAwBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,eAAe,EACzD,OAAO,CAAC,EACR,eAAe,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClC,UAAU;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,KACrD,UAAU,CAAC,CAAC,CAiCd,CAAC;AAWF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GACpC,SAAS,iBAAiB,GAAG,SAAS,KACrC,MAAM,EAUR,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EACjC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,EACzB,eAAc,SAAS,MAAM,EAA0B,KACtD,CAAC,GAAG,CAAC,EAAE,GAAG,SAqBZ,CAAC"}
|
|
@@ -38,19 +38,11 @@ exports.resolveTemplate = resolveTemplate;
|
|
|
38
38
|
* Resolves all keys or indexes for a model
|
|
39
39
|
*/
|
|
40
40
|
const resolveKeys = (model, input, type = 'key') => {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
out[k] = (0, exports.resolveTemplate)(def.value, input);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
if (type === 'key' || type === 'both')
|
|
50
|
-
process(model.key);
|
|
51
|
-
if (type === 'index' || type === 'both')
|
|
52
|
-
process(model.index);
|
|
53
|
-
return out;
|
|
41
|
+
const resolve = (keys) => keys ? Object.entries(keys).map(([k, def]) => [k, (0, exports.resolveTemplate)(def.value, input)]) : [];
|
|
42
|
+
return Object.fromEntries([
|
|
43
|
+
...(type === 'key' || type === 'both' ? resolve(model.key) : []),
|
|
44
|
+
...(type === 'index' || type === 'both' ? resolve(model.index) : []),
|
|
45
|
+
]);
|
|
54
46
|
};
|
|
55
47
|
exports.resolveKeys = resolveKeys;
|
|
56
48
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftschopp/dynatable-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Core library for DynamoDB single table design",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"build": "tsc && tsc-alias",
|
|
23
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
24
24
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
25
25
|
"lint": "eslint src",
|
|
26
26
|
"test": "jest",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
27
28
|
"prepublishOnly": "yarn build"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|