dyno-table 2.3.1 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/dist/{chunk-NTA6GDPP.cjs → chunk-3J5DY7KG.cjs} +40 -37
- package/dist/{chunk-2EWNZOUK.js → chunk-M5Y6JQJN.js} +40 -37
- package/dist/entity.cjs +4 -4
- package/dist/entity.d.cts +8 -5
- package/dist/entity.d.ts +8 -5
- package/dist/entity.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -273,9 +273,3 @@ const largeDinos = await dinoRepo.batchGet([
|
|
|
273
273
|
- **[Issues](https://github.com/Kysumi/dyno-table/issues)** - Report bugs or request features
|
|
274
274
|
- **[Discussions](https://github.com/Kysumi/dyno-table/discussions)** - Ask questions and share ideas
|
|
275
275
|
- **[NPM](https://www.npmjs.com/package/dyno-table)** - Package information
|
|
276
|
-
|
|
277
|
-
---
|
|
278
|
-
|
|
279
|
-
<div align="center">
|
|
280
|
-
<em>Built by developers who believe working with DynamoDB should be intuitive and type-safe</em>
|
|
281
|
-
</div>
|
|
@@ -500,46 +500,49 @@ function defineEntity(config) {
|
|
|
500
500
|
builder.condition(chunk7UJJ7JXM_cjs.eq(entityTypeAttributeName, config.name));
|
|
501
501
|
return createEntityAwareDeleteBuilder(builder, config.name);
|
|
502
502
|
},
|
|
503
|
-
query: Object.entries(config.queries || {}).reduce(
|
|
504
|
-
acc[key]
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
503
|
+
query: Object.entries(config.queries || {}).reduce(
|
|
504
|
+
(acc, [key, inputCallback]) => {
|
|
505
|
+
acc[key] = (input) => {
|
|
506
|
+
const queryEntity = {
|
|
507
|
+
scan: repository.scan,
|
|
508
|
+
get: (key2) => createEntityAwareGetBuilder(table.get(key2), config.name),
|
|
509
|
+
query: (keyCondition) => {
|
|
510
|
+
return table.query(keyCondition);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
const queryBuilderCallback = inputCallback(input);
|
|
514
|
+
const builder = queryBuilderCallback(queryEntity);
|
|
515
|
+
if (builder && typeof builder === "object" && "filter" in builder && typeof builder.filter === "function") {
|
|
516
|
+
builder.filter(chunk7UJJ7JXM_cjs.eq(entityTypeAttributeName, config.name));
|
|
510
517
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
const validationResult = schema["~standard"].validate(input);
|
|
525
|
-
if ("issues" in validationResult && validationResult.issues) {
|
|
526
|
-
throw new Error(
|
|
527
|
-
`Validation failed: ${validationResult.issues.map((issue) => issue.message).join(", ")}`
|
|
528
|
-
);
|
|
518
|
+
if (builder && typeof builder === "object" && "execute" in builder) {
|
|
519
|
+
const originalExecute = builder.execute;
|
|
520
|
+
builder.execute = async () => {
|
|
521
|
+
const queryFn = config.queries[key];
|
|
522
|
+
if (queryFn && typeof queryFn === "function") {
|
|
523
|
+
const schema = queryFn.schema;
|
|
524
|
+
if (schema?.["~standard"]?.validate && typeof schema["~standard"].validate === "function") {
|
|
525
|
+
const validationResult = schema["~standard"].validate(input);
|
|
526
|
+
if ("issues" in validationResult && validationResult.issues) {
|
|
527
|
+
throw new Error(
|
|
528
|
+
`Validation failed: ${validationResult.issues.map((issue) => issue.message).join(", ")}`
|
|
529
|
+
);
|
|
530
|
+
}
|
|
529
531
|
}
|
|
530
532
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
533
|
+
const result = await originalExecute.call(builder);
|
|
534
|
+
if (!result) {
|
|
535
|
+
throw new Error("Failed to execute query");
|
|
536
|
+
}
|
|
537
|
+
return result;
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
return builder;
|
|
541
|
+
};
|
|
542
|
+
return acc;
|
|
543
|
+
},
|
|
544
|
+
{}
|
|
545
|
+
),
|
|
543
546
|
scan: () => {
|
|
544
547
|
const builder = table.scan();
|
|
545
548
|
builder.filter(chunk7UJJ7JXM_cjs.eq(entityTypeAttributeName, config.name));
|
|
@@ -498,46 +498,49 @@ function defineEntity(config) {
|
|
|
498
498
|
builder.condition(eq(entityTypeAttributeName, config.name));
|
|
499
499
|
return createEntityAwareDeleteBuilder(builder, config.name);
|
|
500
500
|
},
|
|
501
|
-
query: Object.entries(config.queries || {}).reduce(
|
|
502
|
-
acc[key]
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
501
|
+
query: Object.entries(config.queries || {}).reduce(
|
|
502
|
+
(acc, [key, inputCallback]) => {
|
|
503
|
+
acc[key] = (input) => {
|
|
504
|
+
const queryEntity = {
|
|
505
|
+
scan: repository.scan,
|
|
506
|
+
get: (key2) => createEntityAwareGetBuilder(table.get(key2), config.name),
|
|
507
|
+
query: (keyCondition) => {
|
|
508
|
+
return table.query(keyCondition);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const queryBuilderCallback = inputCallback(input);
|
|
512
|
+
const builder = queryBuilderCallback(queryEntity);
|
|
513
|
+
if (builder && typeof builder === "object" && "filter" in builder && typeof builder.filter === "function") {
|
|
514
|
+
builder.filter(eq(entityTypeAttributeName, config.name));
|
|
508
515
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const validationResult = schema["~standard"].validate(input);
|
|
523
|
-
if ("issues" in validationResult && validationResult.issues) {
|
|
524
|
-
throw new Error(
|
|
525
|
-
`Validation failed: ${validationResult.issues.map((issue) => issue.message).join(", ")}`
|
|
526
|
-
);
|
|
516
|
+
if (builder && typeof builder === "object" && "execute" in builder) {
|
|
517
|
+
const originalExecute = builder.execute;
|
|
518
|
+
builder.execute = async () => {
|
|
519
|
+
const queryFn = config.queries[key];
|
|
520
|
+
if (queryFn && typeof queryFn === "function") {
|
|
521
|
+
const schema = queryFn.schema;
|
|
522
|
+
if (schema?.["~standard"]?.validate && typeof schema["~standard"].validate === "function") {
|
|
523
|
+
const validationResult = schema["~standard"].validate(input);
|
|
524
|
+
if ("issues" in validationResult && validationResult.issues) {
|
|
525
|
+
throw new Error(
|
|
526
|
+
`Validation failed: ${validationResult.issues.map((issue) => issue.message).join(", ")}`
|
|
527
|
+
);
|
|
528
|
+
}
|
|
527
529
|
}
|
|
528
530
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
531
|
+
const result = await originalExecute.call(builder);
|
|
532
|
+
if (!result) {
|
|
533
|
+
throw new Error("Failed to execute query");
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
return builder;
|
|
539
|
+
};
|
|
540
|
+
return acc;
|
|
541
|
+
},
|
|
542
|
+
{}
|
|
543
|
+
),
|
|
541
544
|
scan: () => {
|
|
542
545
|
const builder = table.scan();
|
|
543
546
|
builder.filter(eq(entityTypeAttributeName, config.name));
|
package/dist/entity.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk3J5DY7KG_cjs = require('./chunk-3J5DY7KG.cjs');
|
|
4
4
|
require('./chunk-7UJJ7JXM.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "createIndex", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunk3J5DY7KG_cjs.createIndex; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "createQueries", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk3J5DY7KG_cjs.createQueries; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "defineEntity", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunk3J5DY7KG_cjs.defineEntity; }
|
|
19
19
|
});
|
package/dist/entity.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { s as Path, t as PathType, a as Condition, b as ConditionOperator, c as
|
|
|
2
2
|
import { P as PutBuilder, G as GetBuilder, U as UpdateBuilder, i as UpdateCommandParams, T as TransactionBuilder, D as DeleteBuilder, S as ScanBuilder, Q as QueryBuilder } from './index-DlN8G9hd.cjs';
|
|
3
3
|
import { StandardSchemaV1 } from './standard-schema.cjs';
|
|
4
4
|
import { Table } from './table.cjs';
|
|
5
|
-
import { DynamoItem,
|
|
5
|
+
import { DynamoItem, Index, TableConfig } from './types.cjs';
|
|
6
6
|
import '@aws-sdk/lib-dynamodb';
|
|
7
7
|
|
|
8
8
|
type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
|
|
@@ -110,7 +110,10 @@ type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R
|
|
|
110
110
|
schema?: StandardSchemaV1<I>;
|
|
111
111
|
};
|
|
112
112
|
type QueryRecord<T extends DynamoItem> = {
|
|
113
|
-
[K: string]: QueryFunctionWithSchema<T, any,
|
|
113
|
+
[K: string]: QueryFunctionWithSchema<T, any, any>;
|
|
114
|
+
};
|
|
115
|
+
type MappedQueries<T extends DynamoItem, Q extends QueryRecord<T>> = {
|
|
116
|
+
[K in keyof Q]: Q[K] extends QueryFunctionWithSchema<T, infer I, infer R> ? (input: I) => R : never;
|
|
114
117
|
};
|
|
115
118
|
type QueryEntity<T extends DynamoItem> = {
|
|
116
119
|
scan: () => ScanBuilder<T>;
|
|
@@ -195,7 +198,7 @@ Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
|
195
198
|
get: (key: I) => EntityAwareGetBuilder<T>;
|
|
196
199
|
update: (key: I, data: Partial<T>) => EntityAwareUpdateBuilder<T>;
|
|
197
200
|
delete: (key: I) => EntityAwareDeleteBuilder;
|
|
198
|
-
query: Q
|
|
201
|
+
query: MappedQueries<T, Q>;
|
|
199
202
|
scan: () => ScanBuilder<T>;
|
|
200
203
|
}
|
|
201
204
|
/**
|
|
@@ -221,7 +224,7 @@ declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem =
|
|
|
221
224
|
};
|
|
222
225
|
declare function createQueries<T extends DynamoItem>(): {
|
|
223
226
|
input: <I>(schema: StandardSchemaV1<I>) => {
|
|
224
|
-
query: <
|
|
227
|
+
query: <R extends ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>(handler: (params: {
|
|
225
228
|
input: I;
|
|
226
229
|
entity: QueryEntity<T>;
|
|
227
230
|
}) => R) => QueryFunctionWithSchema<T, I, R>;
|
|
@@ -255,4 +258,4 @@ declare function createIndex(): {
|
|
|
255
258
|
};
|
|
256
259
|
};
|
|
257
260
|
|
|
258
|
-
export { type EntityConfig, type EntityRepository, type IndexDefinition, type QueryEntity, type QueryFunction, type QueryFunctionWithSchema, type QueryRecord, createIndex, createQueries, defineEntity };
|
|
261
|
+
export { type EntityConfig, type EntityRepository, type IndexDefinition, type MappedQueries, type QueryEntity, type QueryFunction, type QueryFunctionWithSchema, type QueryRecord, createIndex, createQueries, defineEntity };
|
package/dist/entity.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { s as Path, t as PathType, a as Condition, b as ConditionOperator, c as
|
|
|
2
2
|
import { P as PutBuilder, G as GetBuilder, U as UpdateBuilder, i as UpdateCommandParams, T as TransactionBuilder, D as DeleteBuilder, S as ScanBuilder, Q as QueryBuilder } from './index-2cbm07Bi.js';
|
|
3
3
|
import { StandardSchemaV1 } from './standard-schema.js';
|
|
4
4
|
import { Table } from './table.js';
|
|
5
|
-
import { DynamoItem,
|
|
5
|
+
import { DynamoItem, Index, TableConfig } from './types.js';
|
|
6
6
|
import '@aws-sdk/lib-dynamodb';
|
|
7
7
|
|
|
8
8
|
type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
|
|
@@ -110,7 +110,10 @@ type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R
|
|
|
110
110
|
schema?: StandardSchemaV1<I>;
|
|
111
111
|
};
|
|
112
112
|
type QueryRecord<T extends DynamoItem> = {
|
|
113
|
-
[K: string]: QueryFunctionWithSchema<T, any,
|
|
113
|
+
[K: string]: QueryFunctionWithSchema<T, any, any>;
|
|
114
|
+
};
|
|
115
|
+
type MappedQueries<T extends DynamoItem, Q extends QueryRecord<T>> = {
|
|
116
|
+
[K in keyof Q]: Q[K] extends QueryFunctionWithSchema<T, infer I, infer R> ? (input: I) => R : never;
|
|
114
117
|
};
|
|
115
118
|
type QueryEntity<T extends DynamoItem> = {
|
|
116
119
|
scan: () => ScanBuilder<T>;
|
|
@@ -195,7 +198,7 @@ Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
|
195
198
|
get: (key: I) => EntityAwareGetBuilder<T>;
|
|
196
199
|
update: (key: I, data: Partial<T>) => EntityAwareUpdateBuilder<T>;
|
|
197
200
|
delete: (key: I) => EntityAwareDeleteBuilder;
|
|
198
|
-
query: Q
|
|
201
|
+
query: MappedQueries<T, Q>;
|
|
199
202
|
scan: () => ScanBuilder<T>;
|
|
200
203
|
}
|
|
201
204
|
/**
|
|
@@ -221,7 +224,7 @@ declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem =
|
|
|
221
224
|
};
|
|
222
225
|
declare function createQueries<T extends DynamoItem>(): {
|
|
223
226
|
input: <I>(schema: StandardSchemaV1<I>) => {
|
|
224
|
-
query: <
|
|
227
|
+
query: <R extends ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>(handler: (params: {
|
|
225
228
|
input: I;
|
|
226
229
|
entity: QueryEntity<T>;
|
|
227
230
|
}) => R) => QueryFunctionWithSchema<T, I, R>;
|
|
@@ -255,4 +258,4 @@ declare function createIndex(): {
|
|
|
255
258
|
};
|
|
256
259
|
};
|
|
257
260
|
|
|
258
|
-
export { type EntityConfig, type EntityRepository, type IndexDefinition, type QueryEntity, type QueryFunction, type QueryFunctionWithSchema, type QueryRecord, createIndex, createQueries, defineEntity };
|
|
261
|
+
export { type EntityConfig, type EntityRepository, type IndexDefinition, type MappedQueries, type QueryEntity, type QueryFunction, type QueryFunctionWithSchema, type QueryRecord, createIndex, createQueries, defineEntity };
|
package/dist/entity.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createIndex, createQueries, defineEntity } from './chunk-
|
|
1
|
+
export { createIndex, createQueries, defineEntity } from './chunk-M5Y6JQJN.js';
|
|
2
2
|
import './chunk-2WIBY7PZ.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkKA3VPIPS_cjs = require('./chunk-KA3VPIPS.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunk3J5DY7KG_cjs = require('./chunk-3J5DY7KG.cjs');
|
|
5
5
|
var chunkPB7BBCZO_cjs = require('./chunk-PB7BBCZO.cjs');
|
|
6
6
|
var chunkXYL43FDX_cjs = require('./chunk-XYL43FDX.cjs');
|
|
7
7
|
var chunk7UJJ7JXM_cjs = require('./chunk-7UJJ7JXM.cjs');
|
|
@@ -14,15 +14,15 @@ Object.defineProperty(exports, "Table", {
|
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "createIndex", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunk3J5DY7KG_cjs.createIndex; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "createQueries", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunk3J5DY7KG_cjs.createQueries; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "defineEntity", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunk3J5DY7KG_cjs.defineEntity; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "partitionKey", {
|
|
28
28
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Table } from './chunk-EODPMYPE.js';
|
|
2
|
-
export { createIndex, createQueries, defineEntity } from './chunk-
|
|
2
|
+
export { createIndex, createQueries, defineEntity } from './chunk-M5Y6JQJN.js';
|
|
3
3
|
export { partitionKey, sortKey } from './chunk-QVRMYGC4.js';
|
|
4
4
|
export { BatchBuilder, BatchError, DeleteBuilder, PutBuilder, QueryBuilder, TransactionBuilder, UpdateBuilder } from './chunk-DTFJJASK.js';
|
|
5
5
|
export { and, attributeExists, attributeNotExists, beginsWith, between, contains, eq, gt, gte, inArray, lt, lte, ne, not, or } from './chunk-2WIBY7PZ.js';
|