@moicky/dynamodb 3.0.2 → 3.0.4
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/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export * from "./lib";
|
|
|
2
2
|
export * from "./operations";
|
|
3
3
|
export * from "./transactions";
|
|
4
4
|
export { createCustomReference, getDependencies, resolveReferences, } from "./transactions/references";
|
|
5
|
-
export type { DynamoDBItemKey, ItemWithKey, Prettify, DynamoDBSet, } from "./transactions/types";
|
|
6
5
|
export type { DynamoDBReference, ReferenceMetadata, ReferenceTo, ResolvedItem, WithoutReferences, } from "./transactions/references/types";
|
|
6
|
+
export type { DynamoDBItemKey, ItemWithKey, Prettify, } from "./transactions/types";
|
|
7
7
|
export type * from "./types";
|
package/dist/operations/get.js
CHANGED
|
@@ -41,12 +41,12 @@ async function getItem(key, args = {}) {
|
|
|
41
41
|
}
|
|
42
42
|
exports.getItem = getItem;
|
|
43
43
|
async function getItems(keys, args = {}, retry = 0) {
|
|
44
|
+
if (keys.length === 0)
|
|
45
|
+
return [];
|
|
44
46
|
args = (0, lib_1.withDefaults)(args, "getItems");
|
|
45
47
|
// creates batches of 100 items each and performs batchGet on every batch.
|
|
46
48
|
// also retries up to 3 times if there are unprocessed items (due to size limit of 16MB)
|
|
47
49
|
// returns items in same order as keys (not sorted by default when using batchGet)
|
|
48
|
-
if (retry > 3)
|
|
49
|
-
return [];
|
|
50
50
|
const batchReadLimit = 100;
|
|
51
51
|
// duplicate key entries would cause an error, so we remove them
|
|
52
52
|
const uniqueKeys = Object.values(keys.reduce((acc, key) => {
|
package/dist/operations/query.js
CHANGED
|
@@ -171,7 +171,7 @@ async function queryPaginatedItems(keyCondition, key, args) {
|
|
|
171
171
|
const queryArgs = {
|
|
172
172
|
...args,
|
|
173
173
|
Limit: pageSize,
|
|
174
|
-
ScanIndexForward: direction === "next",
|
|
174
|
+
ScanIndexForward: direction === (args.ScanIndexForward === false ? "previous" : "next"),
|
|
175
175
|
};
|
|
176
176
|
let newPageNumber;
|
|
177
177
|
switch (direction) {
|
|
@@ -219,7 +219,7 @@ async function queryPaginatedItems(keyCondition, key, args) {
|
|
|
219
219
|
ExclusiveStartKey: data.LastEvaluatedKey,
|
|
220
220
|
}).then(({ Count }) => Count > 0)));
|
|
221
221
|
let hasPreviousPage = newPageNumber > 1;
|
|
222
|
-
data.Items = data.Items || [];
|
|
222
|
+
data.Items = (data.Items || []).slice(0, pageSize);
|
|
223
223
|
direction === "previous" && data.Items.reverse();
|
|
224
224
|
const applySchema = (item) => {
|
|
225
225
|
return keyAttributes.reduce((acc, key) => ({ ...acc, [key]: item[key] }), {});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transaction } from ".";
|
|
2
2
|
import { DynamoDBItem } from "../types";
|
|
3
3
|
import { DynamoDBReference } from "./references/types";
|
|
4
|
-
import { ConditionOperation, CreateOperation,
|
|
4
|
+
import { ConditionOperation, CreateOperation, DeepSetUpdates, DynamoDBItemKey, ItemWithKey, NestedParams, Prettify, StrictDeepNumberUpdates, TypedParams, UpdateOperation, WithoutKey } from "./types";
|
|
5
5
|
export declare class CreateOperations<U extends ItemWithKey> {
|
|
6
6
|
private operation;
|
|
7
7
|
private transaction;
|
|
@@ -14,12 +14,10 @@ export declare class UpdateOperations<U extends DynamoDBItem> {
|
|
|
14
14
|
constructor(operation: UpdateOperation, transaction: Transaction);
|
|
15
15
|
setReferences(refs: SetReferencesParams<U>): void;
|
|
16
16
|
set(values: WithoutKey<Partial<U>> & NestedParams): this;
|
|
17
|
-
adjustNumber(values:
|
|
17
|
+
adjustNumber(values: Prettify<StrictDeepNumberUpdates<U>>): this;
|
|
18
18
|
removeAttributes(...attributes: string[]): this;
|
|
19
|
-
addItemsToSet(values:
|
|
20
|
-
|
|
21
|
-
} & NestedParams<Set<any> | any[]>): this;
|
|
22
|
-
deleteItemsFromSet(values: NestedTypedParams<U, Set<any>>): this;
|
|
19
|
+
addItemsToSet(values: Prettify<DeepSetUpdates<U>>): this;
|
|
20
|
+
deleteItemsFromSet(values: Prettify<DeepSetUpdates<U>>): this;
|
|
23
21
|
onCondition({ expression, values, }: {
|
|
24
22
|
expression: string;
|
|
25
23
|
values: Partial<U> & Record<string, any>;
|
|
@@ -69,7 +69,7 @@ class UpdateOperations {
|
|
|
69
69
|
adjustNumber(values) {
|
|
70
70
|
if (Object.keys(values).length === 0)
|
|
71
71
|
return this;
|
|
72
|
-
this.operation.actions.push({ _type: "add", values });
|
|
72
|
+
this.operation.actions.push({ _type: "add", values: values });
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
75
75
|
removeAttributes(...attributes) {
|
|
@@ -50,5 +50,29 @@ export type TypedParams<T extends DynamoDBItem, ValueType, ParamType = ValueType
|
|
|
50
50
|
};
|
|
51
51
|
export type NestedParams<T = any> = Record<`${string}.${string}`, T>;
|
|
52
52
|
export type NestedTypedParams<T extends DynamoDBItem, ValueType, ParamType = ValueType> = TypedParams<T, ValueType, ParamType> & NestedParams<ParamType>;
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
type Prev = [never, 0, 1, 2, 3];
|
|
54
|
+
type PathEntry = {
|
|
55
|
+
path: string;
|
|
56
|
+
type: any;
|
|
57
|
+
};
|
|
58
|
+
type DeepNumberPathEntries<T, Prefix extends string = "", D extends number = 3> = [D] extends [never] ? never : {
|
|
59
|
+
[K in keyof T & string]-?: NonNullable<T[K]> extends number ? {
|
|
60
|
+
path: `${Prefix}${K}`;
|
|
61
|
+
type: NonNullable<T[K]>;
|
|
62
|
+
} : NonNullable<T[K]> extends any[] | Set<any> | Date | Function | Uint8Array ? never : NonNullable<T[K]> extends object ? DeepNumberPathEntries<NonNullable<T[K]>, `${Prefix}${K}.`, Prev[D]> : never;
|
|
63
|
+
}[keyof T & string];
|
|
64
|
+
export type StrictDeepNumberUpdates<T> = {
|
|
65
|
+
[Entry in DeepNumberPathEntries<T> & PathEntry as Entry["path"]]?: Entry["type"];
|
|
66
|
+
};
|
|
67
|
+
type DeepSetPathEntries<T, Prefix extends string = "", D extends number = 3> = [
|
|
68
|
+
D
|
|
69
|
+
] extends [never] ? never : {
|
|
70
|
+
[K in keyof T & string]-?: NonNullable<T[K]> extends Set<infer E> | (infer E)[] ? {
|
|
71
|
+
path: `${Prefix}${K}`;
|
|
72
|
+
type: E;
|
|
73
|
+
} : NonNullable<T[K]> extends Date | Function | Uint8Array ? never : NonNullable<T[K]> extends object ? DeepSetPathEntries<NonNullable<T[K]>, `${Prefix}${K}.`, Prev[D]> : never;
|
|
74
|
+
}[keyof T & string];
|
|
75
|
+
export type DeepSetUpdates<T> = {
|
|
76
|
+
[Entry in DeepSetPathEntries<T> & PathEntry as Entry["path"]]?: Entry["type"][] | Set<Entry["type"]>;
|
|
77
|
+
};
|
|
78
|
+
export {};
|