@moicky/dynamodb 3.0.3 → 3.0.5
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) => {
|
|
@@ -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,33 @@ 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 DeepNumberPathEntries<T, Prefix extends string = "", D extends number = 3> = [D] extends [never] ? never : {
|
|
55
|
+
[K in keyof T & string]-?: NonNullable<T[K]> extends number ? {
|
|
56
|
+
path: `${Prefix}${K}`;
|
|
57
|
+
type: NonNullable<T[K]>;
|
|
58
|
+
} : 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;
|
|
59
|
+
}[keyof T & string];
|
|
60
|
+
export type StrictDeepNumberUpdates<T> = {
|
|
61
|
+
[E in DeepNumberPathEntries<T> as E extends {
|
|
62
|
+
path: string;
|
|
63
|
+
} ? E["path"] : never]?: E extends {
|
|
64
|
+
type: infer V;
|
|
65
|
+
} ? V : never;
|
|
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
|
+
[E in DeepSetPathEntries<T> as E extends {
|
|
77
|
+
path: string;
|
|
78
|
+
} ? E["path"] : never]?: E extends {
|
|
79
|
+
type: infer V;
|
|
80
|
+
} ? V[] | Set<V> : never;
|
|
81
|
+
};
|
|
82
|
+
export {};
|