@webiny/db-dynamodb 6.0.0-beta.0 → 6.0.0-rc.1
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/DynamoDbDriver.d.ts +14 -12
- package/DynamoDbDriver.js +214 -22
- package/DynamoDbDriver.js.map +1 -1
- package/README.md +6 -62
- package/index.d.ts +4 -3
- package/index.js +4 -36
- package/index.js.map +1 -1
- package/package.json +19 -26
- package/plugins/definitions/AttributePlugin.d.ts +1 -1
- package/plugins/definitions/AttributePlugin.js +4 -12
- package/plugins/definitions/AttributePlugin.js.map +1 -1
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/DateTimeTransformPlugin.js +6 -14
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPathPlugin.js +6 -14
- package/plugins/definitions/FieldPathPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.d.ts +2 -2
- package/plugins/definitions/FieldPlugin.js +2 -9
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/TimeTransformPlugin.js +12 -19
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueFilterPlugin.d.ts +2 -2
- package/plugins/definitions/ValueFilterPlugin.js +5 -13
- package/plugins/definitions/ValueFilterPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.js +6 -14
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +4 -12
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/filters/andIn.d.ts +2 -2
- package/plugins/filters/andIn.js +5 -12
- package/plugins/filters/andIn.js.map +1 -1
- package/plugins/filters/between.d.ts +2 -2
- package/plugins/filters/between.js +5 -12
- package/plugins/filters/between.js.map +1 -1
- package/plugins/filters/contains.d.ts +2 -2
- package/plugins/filters/contains.js +24 -11
- package/plugins/filters/contains.js.map +1 -1
- package/plugins/filters/eq.d.ts +2 -2
- package/plugins/filters/eq.js +5 -11
- package/plugins/filters/eq.js.map +1 -1
- package/plugins/filters/fuzzy.d.ts +2 -2
- package/plugins/filters/fuzzy.js +5 -12
- package/plugins/filters/fuzzy.js.map +1 -1
- package/plugins/filters/gt.d.ts +2 -2
- package/plugins/filters/gt.js +3 -9
- package/plugins/filters/gt.js.map +1 -1
- package/plugins/filters/gte.d.ts +2 -2
- package/plugins/filters/gte.js +3 -9
- package/plugins/filters/gte.js.map +1 -1
- package/plugins/filters/in.d.ts +2 -2
- package/plugins/filters/in.js +5 -12
- package/plugins/filters/in.js.map +1 -1
- package/plugins/filters/index.d.ts +1 -1
- package/plugins/filters/index.js +12 -20
- package/plugins/filters/index.js.map +1 -1
- package/plugins/filters/lt.d.ts +2 -2
- package/plugins/filters/lt.js +3 -9
- package/plugins/filters/lt.js.map +1 -1
- package/plugins/filters/lte.d.ts +2 -2
- package/plugins/filters/lte.js +3 -9
- package/plugins/filters/lte.js.map +1 -1
- package/plugins/filters/startsWith.d.ts +2 -2
- package/plugins/filters/startsWith.js +3 -9
- package/plugins/filters/startsWith.js.map +1 -1
- package/plugins/index.d.ts +9 -1
- package/plugins/index.js +11 -11
- package/plugins/index.js.map +1 -1
- package/store/entity.d.ts +6 -0
- package/store/entity.js +11 -0
- package/store/entity.js.map +1 -0
- package/store/keys.d.ts +6 -0
- package/store/keys.js +16 -0
- package/store/keys.js.map +1 -0
- package/store/types.d.ts +6 -0
- package/store/types.js +3 -0
- package/store/types.js.map +1 -0
- package/toolbox.d.ts +7 -2
- package/toolbox.js +2 -17
- package/toolbox.js.map +1 -1
- package/types.d.ts +3 -24
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/attributes.d.ts +3 -3
- package/utils/attributes.js +4 -12
- package/utils/attributes.js.map +1 -1
- package/utils/{batchRead.d.ts → batch/batchRead.d.ts} +3 -2
- package/utils/{batchRead.js → batch/batchRead.js} +5 -13
- package/utils/batch/batchRead.js.map +1 -0
- package/utils/batch/batchWrite.d.ts +13 -0
- package/utils/{batchWrite.js → batch/batchWrite.js} +3 -11
- package/utils/batch/batchWrite.js.map +1 -0
- package/utils/batch/index.d.ts +3 -0
- package/utils/batch/index.js +5 -0
- package/utils/batch/index.js.map +1 -0
- package/utils/batch/types.d.ts +30 -0
- package/utils/batch/types.js +3 -0
- package/utils/batch/types.js.map +1 -0
- package/utils/cleanup.d.ts +3 -3
- package/utils/cleanup.js +3 -10
- package/utils/cleanup.js.map +1 -1
- package/utils/count.d.ts +1 -1
- package/utils/count.js +1 -8
- package/utils/count.js.map +1 -1
- package/utils/createEntity.d.ts +36 -53
- package/utils/createEntity.js +75 -51
- package/utils/createEntity.js.map +1 -1
- package/utils/createTable.d.ts +10 -6
- package/utils/createTable.js +25 -15
- package/utils/createTable.js.map +1 -1
- package/utils/cursor.js +2 -10
- package/utils/cursor.js.map +1 -1
- package/utils/delete.d.ts +8 -8
- package/utils/delete.js +1 -8
- package/utils/delete.js.map +1 -1
- package/utils/entity/Entity.d.ts +28 -0
- package/utils/entity/Entity.js +99 -0
- package/utils/entity/Entity.js.map +1 -0
- package/utils/entity/EntityReadBatch.d.ts +18 -0
- package/utils/entity/EntityReadBatch.js +39 -0
- package/utils/entity/EntityReadBatch.js.map +1 -0
- package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
- package/utils/entity/EntityReadBatchBuilder.js +21 -0
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
- package/utils/entity/EntityWriteBatch.d.ts +23 -0
- package/utils/entity/EntityWriteBatch.js +51 -0
- package/utils/entity/EntityWriteBatch.js.map +1 -0
- package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
- package/utils/entity/EntityWriteBatchBuilder.js +20 -0
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
- package/utils/entity/getEntity.d.ts +4 -0
- package/utils/entity/getEntity.js +12 -0
- package/utils/entity/getEntity.js.map +1 -0
- package/utils/entity/index.d.ts +7 -0
- package/utils/entity/index.js +9 -0
- package/utils/entity/index.js.map +1 -0
- package/utils/entity/types.d.ts +75 -0
- package/utils/entity/types.js +4 -0
- package/utils/entity/types.js.map +1 -0
- package/utils/filter.d.ts +2 -2
- package/utils/filter.js +7 -14
- package/utils/filter.js.map +1 -1
- package/utils/get.d.ts +6 -5
- package/utils/get.js +4 -12
- package/utils/get.js.map +1 -1
- package/utils/index.d.ts +17 -17
- package/utils/index.js +17 -192
- package/utils/index.js.map +1 -1
- package/utils/listResponse.js +4 -10
- package/utils/listResponse.js.map +1 -1
- package/utils/put.d.ts +10 -9
- package/utils/put.js +3 -9
- package/utils/put.js.map +1 -1
- package/utils/query.d.ts +11 -12
- package/utils/query.js +30 -22
- package/utils/query.js.map +1 -1
- package/utils/scan.d.ts +11 -7
- package/utils/scan.js +22 -12
- package/utils/scan.js.map +1 -1
- package/utils/sort.d.ts +1 -1
- package/utils/sort.js +7 -14
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.d.ts +10 -0
- package/utils/table/Table.js +27 -0
- package/utils/table/Table.js.map +1 -0
- package/utils/table/TableReadBatch.d.ts +19 -0
- package/utils/table/TableReadBatch.js +54 -0
- package/utils/table/TableReadBatch.js.map +1 -0
- package/utils/table/TableWriteBatch.d.ts +21 -0
- package/utils/table/TableWriteBatch.js +61 -0
- package/utils/table/TableWriteBatch.js.map +1 -0
- package/utils/table/index.d.ts +4 -0
- package/utils/table/index.js +6 -0
- package/utils/table/index.js.map +1 -0
- package/utils/table/types.d.ts +39 -0
- package/utils/table/types.js +3 -0
- package/utils/table/types.js.map +1 -0
- package/utils/update.d.ts +2 -1
- package/utils/update.js +3 -9
- package/utils/update.js.map +1 -1
- package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
- package/plugins/definitions/NumberTransformPlugin.js +0 -36
- package/plugins/definitions/NumberTransformPlugin.js.map +0 -1
- package/utils/batchRead.js.map +0 -1
- package/utils/batchWrite.d.ts +0 -29
- package/utils/batchWrite.js.map +0 -1
- package/utils/table.d.ts +0 -7
- package/utils/table.js +0 -24
- package/utils/table.js.map +0 -1
package/DynamoDbDriver.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
-
import { DbDriver,
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { DbDriver, GetValueResult, GetValuesResult, IListValuesParams, ListValuesResult, RemoveValueResult, RemoveValuesResult, StorageKey, StoreValueResult, StoreValuesResult } from "@webiny/db";
|
|
3
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
4
|
interface ConstructorArgs {
|
|
4
5
|
documentClient: DynamoDBDocument;
|
|
5
6
|
}
|
|
6
|
-
declare class DynamoDbDriver implements DbDriver {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
declare class DynamoDbDriver implements DbDriver<DynamoDBDocument> {
|
|
8
|
+
readonly documentClient: DynamoDBDocument;
|
|
9
|
+
readonly table: import("./utils").ITable<string, "PK", "SK">;
|
|
10
|
+
readonly entity: import("./store/types").IStoreEntity;
|
|
9
11
|
constructor({ documentClient }: ConstructorArgs);
|
|
10
12
|
getClient(): DynamoDBDocument;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
storeValue<V>(key: string, input: V): Promise<StoreValueResult<V>>;
|
|
14
|
+
storeValues<V extends GenericRecord<StorageKey>>(values: V): Promise<StoreValuesResult<V>>;
|
|
15
|
+
getValue<V>(key: StorageKey): Promise<GetValueResult<V>>;
|
|
16
|
+
getValues<V extends GenericRecord<StorageKey>>(input: (keyof V)[]): Promise<GetValuesResult<V>>;
|
|
17
|
+
listValues<V extends GenericRecord<StorageKey>>(params?: IListValuesParams): Promise<ListValuesResult<V>>;
|
|
18
|
+
removeValue<V>(key: StorageKey): Promise<RemoveValueResult<V>>;
|
|
19
|
+
removeValues<V extends GenericRecord<StorageKey>>(input: (keyof V)[]): Promise<RemoveValuesResult<V>>;
|
|
18
20
|
}
|
|
19
21
|
export default DynamoDbDriver;
|
package/DynamoDbDriver.js
CHANGED
|
@@ -1,41 +1,233 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
1
|
+
import { createTable } from "./utils/createTable.js";
|
|
2
|
+
import { createEntity } from "./store/entity.js";
|
|
3
|
+
import { createPartitionKey, createSortKey, createType } from "./store/keys.js";
|
|
7
4
|
class DynamoDbDriver {
|
|
8
5
|
constructor({
|
|
9
6
|
documentClient
|
|
10
7
|
}) {
|
|
11
|
-
this.batchProcesses = {};
|
|
12
8
|
this.documentClient = documentClient;
|
|
9
|
+
this.table = createTable({
|
|
10
|
+
name: process.env.DB_TABLE,
|
|
11
|
+
documentClient
|
|
12
|
+
});
|
|
13
|
+
this.entity = createEntity({
|
|
14
|
+
table: this.table
|
|
15
|
+
});
|
|
13
16
|
}
|
|
14
17
|
getClient() {
|
|
15
18
|
return this.documentClient;
|
|
16
19
|
}
|
|
17
|
-
async
|
|
18
|
-
|
|
20
|
+
async storeValue(key, input) {
|
|
21
|
+
let value;
|
|
22
|
+
try {
|
|
23
|
+
value = JSON.stringify(input);
|
|
24
|
+
} catch (ex) {
|
|
25
|
+
return {
|
|
26
|
+
key,
|
|
27
|
+
error: ex
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await this.entity.put({
|
|
32
|
+
PK: createPartitionKey(),
|
|
33
|
+
SK: createSortKey({
|
|
34
|
+
key
|
|
35
|
+
}),
|
|
36
|
+
TYPE: createType(),
|
|
37
|
+
data: {
|
|
38
|
+
key,
|
|
39
|
+
value
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
key,
|
|
44
|
+
data: input
|
|
45
|
+
};
|
|
46
|
+
} catch (ex) {
|
|
47
|
+
return {
|
|
48
|
+
key,
|
|
49
|
+
error: ex
|
|
50
|
+
};
|
|
51
|
+
}
|
|
19
52
|
}
|
|
20
|
-
async
|
|
21
|
-
|
|
53
|
+
async storeValues(values) {
|
|
54
|
+
const keys = Object.keys(values);
|
|
55
|
+
const batchWrite = this.entity.createEntityWriter();
|
|
56
|
+
try {
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
const input = values[key];
|
|
59
|
+
let value;
|
|
60
|
+
try {
|
|
61
|
+
value = JSON.stringify(input);
|
|
62
|
+
} catch (ex) {
|
|
63
|
+
throw ex;
|
|
64
|
+
}
|
|
65
|
+
batchWrite.put({
|
|
66
|
+
PK: createPartitionKey(),
|
|
67
|
+
SK: createSortKey({
|
|
68
|
+
key
|
|
69
|
+
}),
|
|
70
|
+
TYPE: createType(),
|
|
71
|
+
data: {
|
|
72
|
+
key,
|
|
73
|
+
value
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
await batchWrite.execute();
|
|
78
|
+
return {
|
|
79
|
+
keys,
|
|
80
|
+
data: values
|
|
81
|
+
};
|
|
82
|
+
} catch (ex) {
|
|
83
|
+
return {
|
|
84
|
+
keys,
|
|
85
|
+
error: ex
|
|
86
|
+
};
|
|
87
|
+
}
|
|
22
88
|
}
|
|
23
|
-
async
|
|
24
|
-
|
|
89
|
+
async getValue(key) {
|
|
90
|
+
try {
|
|
91
|
+
const result = await this.entity.get({
|
|
92
|
+
PK: createPartitionKey(),
|
|
93
|
+
SK: createSortKey({
|
|
94
|
+
key
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
key,
|
|
99
|
+
data: result?.data?.value ? JSON.parse(result.data.value) : null
|
|
100
|
+
};
|
|
101
|
+
} catch (ex) {
|
|
102
|
+
return {
|
|
103
|
+
key,
|
|
104
|
+
error: ex
|
|
105
|
+
};
|
|
106
|
+
}
|
|
25
107
|
}
|
|
26
|
-
async
|
|
27
|
-
|
|
108
|
+
async getValues(input) {
|
|
109
|
+
const keys = [...input];
|
|
110
|
+
const batchRead = this.entity.createEntityReader({
|
|
111
|
+
read: keys.map(key => {
|
|
112
|
+
return {
|
|
113
|
+
PK: createPartitionKey(),
|
|
114
|
+
SK: createSortKey({
|
|
115
|
+
key
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
try {
|
|
121
|
+
const results = await batchRead.execute();
|
|
122
|
+
const data = keys.reduce((collection, initialKey) => {
|
|
123
|
+
const key = initialKey;
|
|
124
|
+
const result = results.find(item => {
|
|
125
|
+
return item.PK === createPartitionKey() && item.SK === createSortKey({
|
|
126
|
+
key
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
if (!result?.data?.value) {
|
|
130
|
+
collection[key] = null;
|
|
131
|
+
return collection;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
collection[key] = JSON.parse(result.data.value);
|
|
135
|
+
} catch {
|
|
136
|
+
collection[key] = null;
|
|
137
|
+
}
|
|
138
|
+
return collection;
|
|
139
|
+
}, {});
|
|
140
|
+
return {
|
|
141
|
+
keys,
|
|
142
|
+
data
|
|
143
|
+
};
|
|
144
|
+
} catch (ex) {
|
|
145
|
+
return {
|
|
146
|
+
keys,
|
|
147
|
+
error: ex
|
|
148
|
+
};
|
|
149
|
+
}
|
|
28
150
|
}
|
|
29
|
-
async
|
|
30
|
-
|
|
151
|
+
async listValues(params) {
|
|
152
|
+
try {
|
|
153
|
+
const partitionKey = createPartitionKey();
|
|
154
|
+
const options = {
|
|
155
|
+
...params
|
|
156
|
+
};
|
|
157
|
+
const results = await this.entity.queryAll({
|
|
158
|
+
partitionKey,
|
|
159
|
+
options
|
|
160
|
+
});
|
|
161
|
+
const data = results.reduce((collection, item) => {
|
|
162
|
+
const key = item.data.key;
|
|
163
|
+
try {
|
|
164
|
+
collection[key] = JSON.parse(item.data.value);
|
|
165
|
+
} catch {
|
|
166
|
+
collection[key] = null;
|
|
167
|
+
}
|
|
168
|
+
return collection;
|
|
169
|
+
}, {});
|
|
170
|
+
return {
|
|
171
|
+
keys: Object.keys(data),
|
|
172
|
+
data
|
|
173
|
+
};
|
|
174
|
+
} catch (ex) {
|
|
175
|
+
return {
|
|
176
|
+
error: ex
|
|
177
|
+
};
|
|
178
|
+
}
|
|
31
179
|
}
|
|
32
|
-
async
|
|
33
|
-
|
|
180
|
+
async removeValue(key) {
|
|
181
|
+
const result = await this.getValue(key);
|
|
182
|
+
if (result.error) {
|
|
183
|
+
return {
|
|
184
|
+
key,
|
|
185
|
+
error: result.error
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
await this.entity.delete({
|
|
190
|
+
PK: createPartitionKey(),
|
|
191
|
+
SK: createSortKey({
|
|
192
|
+
key
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
key,
|
|
197
|
+
data: result.data
|
|
198
|
+
};
|
|
199
|
+
} catch (ex) {
|
|
200
|
+
return {
|
|
201
|
+
key,
|
|
202
|
+
error: ex
|
|
203
|
+
};
|
|
204
|
+
}
|
|
34
205
|
}
|
|
35
|
-
|
|
36
|
-
|
|
206
|
+
async removeValues(input) {
|
|
207
|
+
const keys = [...input];
|
|
208
|
+
const batchDelete = this.entity.createEntityWriter({
|
|
209
|
+
delete: keys.map(key => {
|
|
210
|
+
return {
|
|
211
|
+
PK: createPartitionKey(),
|
|
212
|
+
SK: createSortKey({
|
|
213
|
+
key
|
|
214
|
+
})
|
|
215
|
+
};
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
try {
|
|
219
|
+
await batchDelete.execute();
|
|
220
|
+
return {
|
|
221
|
+
keys
|
|
222
|
+
};
|
|
223
|
+
} catch (ex) {
|
|
224
|
+
return {
|
|
225
|
+
keys,
|
|
226
|
+
error: ex
|
|
227
|
+
};
|
|
228
|
+
}
|
|
37
229
|
}
|
|
38
230
|
}
|
|
39
|
-
|
|
231
|
+
export default DynamoDbDriver;
|
|
40
232
|
|
|
41
233
|
//# sourceMappingURL=DynamoDbDriver.js.map
|
package/DynamoDbDriver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DynamoDbDriver","constructor","documentClient","batchProcesses","getClient","create","update","delete","read","createLog","readLogs","getBatchProcess","_default","exports","default"],"sources":["DynamoDbDriver.ts"],"sourcesContent":["import { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { DbDriver, Result } from \"@webiny/db\";\n\ninterface ConstructorArgs {\n documentClient: DynamoDBDocument;\n}\n\nclass DynamoDbDriver implements DbDriver {\n batchProcesses: Record<string, any>;\n documentClient: DynamoDBDocument;\n constructor({ documentClient }: ConstructorArgs) {\n this.batchProcesses = {};\n this.documentClient = documentClient;\n }\n\n getClient() {\n return this.documentClient;\n }\n async create(): Promise<Result> {\n return [true, {}];\n }\n\n async update(): Promise<Result> {\n return [true, {}];\n }\n\n async delete(): Promise<Result> {\n return [true, {}];\n }\n\n async read<T>(): Promise<Result<T[]>> {\n return [[], {}];\n }\n\n async createLog(): Promise<Result> {\n return [true, {}];\n }\n\n async readLogs<T>() {\n return this.read<T>();\n }\n\n getBatchProcess() {\n // not empty\n }\n}\n\nexport default DynamoDbDriver;\n"],"mappings":";;;;;;AAOA,MAAMA,cAAc,CAAqB;EAGrCC,WAAWA,CAAC;IAAEC;EAAgC,CAAC,EAAE;IAC7C,IAAI,CAACC,cAAc,GAAG,CAAC,CAAC;IACxB,IAAI,CAACD,cAAc,GAAGA,cAAc;EACxC;EAEAE,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACF,cAAc;EAC9B;EACA,MAAMG,MAAMA,CAAA,EAAoB;IAC5B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;EACrB;EAEA,MAAMC,MAAMA,CAAA,EAAoB;IAC5B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;EACrB;EAEA,MAAMC,MAAMA,CAAA,EAAoB;IAC5B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;EACrB;EAEA,MAAMC,IAAIA,CAAA,EAA4B;IAClC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;EACnB;EAEA,MAAMC,SAASA,CAAA,EAAoB;IAC/B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;EACrB;EAEA,MAAMC,QAAQA,CAAA,EAAM;IAChB,OAAO,IAAI,CAACF,IAAI,CAAI,CAAC;EACzB;EAEAG,eAAeA,CAAA,EAAG;IACd;EAAA;AAER;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcd,cAAc","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createTable","createEntity","createPartitionKey","createSortKey","createType","DynamoDbDriver","constructor","documentClient","table","name","process","env","DB_TABLE","entity","getClient","storeValue","key","input","value","JSON","stringify","ex","error","put","PK","SK","TYPE","data","storeValues","values","keys","Object","batchWrite","createEntityWriter","execute","getValue","result","get","parse","getValues","batchRead","createEntityReader","read","map","results","reduce","collection","initialKey","find","item","listValues","params","partitionKey","options","queryAll","removeValue","delete","removeValues","batchDelete"],"sources":["DynamoDbDriver.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type {\n DbDriver,\n GetValueResult,\n GetValuesResult,\n IListValuesParams,\n ListValuesResult,\n RemoveValueResult,\n RemoveValuesResult,\n StorageKey,\n StoreValueResult,\n StoreValuesResult\n} from \"@webiny/db\";\nimport { createTable } from \"~/utils/createTable.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { createEntity } from \"~/store/entity.js\";\nimport { createPartitionKey, createSortKey, createType } from \"~/store/keys.js\";\n\ninterface ConstructorArgs {\n documentClient: DynamoDBDocument;\n}\n\nclass DynamoDbDriver implements DbDriver<DynamoDBDocument> {\n public readonly documentClient;\n\n public readonly table;\n public readonly entity;\n\n constructor({ documentClient }: ConstructorArgs) {\n this.documentClient = documentClient;\n this.table = createTable({\n name: process.env.DB_TABLE as string,\n documentClient\n });\n this.entity = createEntity({\n table: this.table\n });\n }\n\n public getClient() {\n return this.documentClient;\n }\n\n public async storeValue<V>(key: string, input: V): Promise<StoreValueResult<V>> {\n let value: string | undefined;\n try {\n value = JSON.stringify(input);\n } catch (ex) {\n return {\n key,\n error: ex\n };\n }\n\n try {\n await this.entity.put({\n PK: createPartitionKey(),\n SK: createSortKey({ key }),\n TYPE: createType(),\n data: {\n key,\n value\n }\n });\n\n return {\n key,\n data: input\n };\n } catch (ex) {\n return {\n key,\n error: ex\n };\n }\n }\n public async storeValues<V extends GenericRecord<StorageKey>>(\n values: V\n ): Promise<StoreValuesResult<V>> {\n const keys = Object.keys(values);\n\n const batchWrite = this.entity.createEntityWriter();\n try {\n for (const key of keys) {\n const input = values[key];\n let value: string | undefined;\n try {\n value = JSON.stringify(input);\n } catch (ex) {\n throw ex;\n }\n batchWrite.put({\n PK: createPartitionKey(),\n SK: createSortKey({ key }),\n TYPE: createType(),\n data: {\n key,\n value\n }\n });\n }\n\n await batchWrite.execute();\n return {\n keys,\n data: values\n };\n } catch (ex) {\n return {\n keys,\n error: ex\n };\n }\n }\n public async getValue<V>(key: StorageKey): Promise<GetValueResult<V>> {\n try {\n const result = await this.entity.get({\n PK: createPartitionKey(),\n SK: createSortKey({ key })\n });\n return {\n key,\n data: result?.data?.value ? JSON.parse(result.data.value) : null\n };\n } catch (ex) {\n return {\n key,\n error: ex\n };\n }\n }\n public async getValues<V extends GenericRecord<StorageKey>>(\n input: (keyof V)[]\n ): Promise<GetValuesResult<V>> {\n const keys = [...input] as string[];\n\n const batchRead = this.entity.createEntityReader({\n read: keys.map(key => {\n return {\n PK: createPartitionKey(),\n SK: createSortKey({ key })\n };\n })\n });\n\n try {\n const results = await batchRead.execute();\n const data = keys.reduce((collection, initialKey) => {\n const key = initialKey as keyof V;\n const result = results.find(item => {\n return item.PK === createPartitionKey() && item.SK === createSortKey({ key });\n });\n if (!result?.data?.value) {\n collection[key] = null;\n return collection;\n }\n try {\n collection[key] = JSON.parse(result.data.value);\n } catch {\n collection[key] = null;\n }\n\n return collection;\n }, {} as GenericRecord);\n return {\n keys,\n data\n };\n } catch (ex) {\n return {\n keys,\n error: ex\n };\n }\n }\n public async listValues<V extends GenericRecord<StorageKey>>(\n params?: IListValuesParams\n ): Promise<ListValuesResult<V>> {\n try {\n const partitionKey = createPartitionKey();\n const options = {\n ...params\n };\n const results = await this.entity.queryAll({\n partitionKey,\n options\n });\n\n const data = results.reduce((collection, item) => {\n const key = item.data.key as keyof V;\n try {\n collection[key] = JSON.parse(item.data.value);\n } catch {\n collection[key] = null;\n }\n\n return collection;\n }, {} as GenericRecord);\n\n return {\n keys: Object.keys(data),\n data\n };\n } catch (ex) {\n return {\n error: ex\n };\n }\n }\n\n public async removeValue<V>(key: StorageKey): Promise<RemoveValueResult<V>> {\n const result = await this.getValue<V>(key);\n if (result.error) {\n return {\n key,\n error: result.error\n };\n }\n try {\n await this.entity.delete({\n PK: createPartitionKey(),\n SK: createSortKey({ key })\n });\n return {\n key,\n data: result.data\n };\n } catch (ex) {\n return {\n key,\n error: ex\n };\n }\n }\n\n public async removeValues<V extends GenericRecord<StorageKey>>(\n input: (keyof V)[]\n ): Promise<RemoveValuesResult<V>> {\n const keys = [...input] as string[];\n\n const batchDelete = this.entity.createEntityWriter({\n delete: keys.map(key => {\n return {\n PK: createPartitionKey(),\n SK: createSortKey({ key })\n };\n })\n });\n\n try {\n await batchDelete.execute();\n return {\n keys\n };\n } catch (ex) {\n return {\n keys,\n error: ex\n };\n }\n }\n}\n\nexport default DynamoDbDriver;\n"],"mappings":"AAaA,SAASA,WAAW;AAEpB,SAASC,YAAY;AACrB,SAASC,kBAAkB,EAAEC,aAAa,EAAEC,UAAU;AAMtD,MAAMC,cAAc,CAAuC;EAMvDC,WAAWA,CAAC;IAAEC;EAAgC,CAAC,E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jB,CAAC;IACL,CAAC,CAAC,OAAON,EAAE,EAAE;MACT,OAAO;QACHL,GAAG;QACHM,KAAK,EAAED;MACX,CAAC;IACL;EACJ;EAEA,MAAaoC,YAAYA,CACrBxC,KAAkB,EACY;IAC9B,MAAMa,IAAI,GAAG,CAAC,GAAGb,KAAK,CAAa;IAEnC,MAAMyC,WAAW,GAAG,IAAI,CAAC7C,MAAM,CAACoB,kBAAkB,CAAC;MAC/CuB,MAAM,EAAE1B,IAAI,CAACa,GAAG,CAAC3B,GAAG,IAAI;QACpB,OAAO;UACHQ,EAAE,EAAEtB,kBAAkB,CAAC,CAAC;UACxBuB,EAAE,EAAEtB,aAAa,CAAC;YAAEa;UAAI,CAAC;QAC7B,CAAC;MACL,CAAC;IACL,CAAC,CAAC;IAEF,IAAI;MACA,MAAM0C,WAAW,CAACxB,OAAO,CAAC,CAAC;MAC3B,OAAO;QACHJ;MACJ,CAAC;IACL,CAAC,CAAC,OAAOT,EAAE,EAAE;MACT,OAAO;QACHS,IAAI;QACJR,KAAK,EAAED;MACX,CAAC;IACL;EACJ;AACJ;AAEA,eAAehB,cAAc","ignoreList":[]}
|
package/README.md
CHANGED
|
@@ -1,67 +1,11 @@
|
|
|
1
1
|
# @webiny/db-dynamodb
|
|
2
|
-
[](https://www.npmjs.com/package/webiny-data-dynamodb)
|
|
3
|
-
[](https://www.npmjs.com/package/webiny-data-dynamodb)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
[the official docs](https://github.com/doitadrian/data-dynamodb).
|
|
11
|
-
|
|
12
|
-
## Install
|
|
13
|
-
```
|
|
14
|
-
yarn add @webiny/db-dynamodb
|
|
15
|
-
```
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
16
8
|
|
|
9
|
+
---
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
We have a number [helper](./src/utils) functions that ease the use of either dynamodb-toolbox, filtering, sorting or just creating proper response.
|
|
20
|
-
|
|
21
|
-
#### [batchRead](./src/utils/batchRead.ts)
|
|
22
|
-
Read a batch of records from the DynamoDB table.
|
|
23
|
-
|
|
24
|
-
This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.getBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L313).
|
|
25
|
-
|
|
26
|
-
Internally it reads records until there are no more to read and returns a list of read records.
|
|
27
|
-
|
|
28
|
-
#### [batchWrite](./src/utils/batchWrite.ts)
|
|
29
|
-
Write a batch of records to the DynamoDB table.
|
|
30
|
-
|
|
31
|
-
This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.putBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L989).
|
|
32
|
-
It also accepts a number which defines a number of items to be written in one request. DO NOT put that number over the official DynamoDB maximum.
|
|
33
|
-
|
|
34
|
-
Internally it loops through the items received (in chunks of `maxChunks` parameter) and does not return anything.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#### [cleanupItem and cleanupItems](./src/utils/cleanup.ts)
|
|
38
|
-
Clean up records received from the DynamoDB table.
|
|
39
|
-
|
|
40
|
-
This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and item to be cleaned up, in case of the cleanupItem.
|
|
41
|
-
In case of `cleanupItems` it accepts an array of items to clean up.
|
|
42
|
-
|
|
43
|
-
We use this to remove the properties that dynamodb-toolbox puts on the record automatically.
|
|
44
|
-
|
|
45
|
-
#### [get](./src/utils/get.ts)
|
|
46
|
-
Get a single record from the DynamoDB table with given keys.
|
|
47
|
-
|
|
48
|
-
This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and keys to fetch the record by.
|
|
49
|
-
|
|
50
|
-
It returns either record or null. By default, [entity.get()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L281) returns a object with some meta data and `Item` property, which contains the record (or null if no record).
|
|
51
|
-
|
|
52
|
-
#### [queryOne and queryAll](./src/utils/query.ts)
|
|
53
|
-
Query the DynamoDB table for record(s) by given partition key and query options.
|
|
54
|
-
|
|
55
|
-
This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) to perform the query on, `partitionKey` to query by and [options](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts#L65) to define the query parameters with.
|
|
56
|
-
|
|
57
|
-
The `queryAll` method accepts `limit`, a number with which you can load only a certain amount of records. The `queryOne` method does not have that property.
|
|
58
|
-
|
|
59
|
-
#### [filter](./src/utils/filter.ts)
|
|
60
|
-
Filter the DynamoDB records by given where condition.
|
|
61
|
-
|
|
62
|
-
This function accepts items (records) to be filtered, a definition of fields to filter by (not required by default if no field modification is required), where conditions (eg. `{published: true, date_gte: "2021-01-01"}`) and filtering plugins.
|
|
63
|
-
|
|
64
|
-
#### [sort](./src/utils/sort.ts)
|
|
65
|
-
Sort the DynamoDB records by given sort condition.
|
|
66
|
-
|
|
67
|
-
This function accepts items (records) to be sorted, sort options (eg. createdBy_ASC, id_DESC, etc.) and a definitions of fields to sort by (not required by default if no field modification is required).
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { default as DynamoDbDriver } from "./DynamoDbDriver";
|
|
2
|
-
export * from "./utils";
|
|
3
|
-
export
|
|
1
|
+
import { default as DynamoDbDriver } from "./DynamoDbDriver.js";
|
|
2
|
+
export * from "./utils/index.js";
|
|
3
|
+
export * from "./plugins/index.js";
|
|
4
|
+
export type { DbItem } from "./types.js";
|
|
4
5
|
export { DynamoDbDriver };
|
package/index.js
CHANGED
|
@@ -1,38 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
var _exportNames = {
|
|
8
|
-
DynamoDbDriver: true,
|
|
9
|
-
DbItem: true
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "DbItem", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return _types.DbItem;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "DynamoDbDriver", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _DynamoDbDriver.default;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
var _DynamoDbDriver = _interopRequireDefault(require("./DynamoDbDriver"));
|
|
24
|
-
var _utils = require("./utils");
|
|
25
|
-
Object.keys(_utils).forEach(function (key) {
|
|
26
|
-
if (key === "default" || key === "__esModule") return;
|
|
27
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
-
if (key in exports && exports[key] === _utils[key]) return;
|
|
29
|
-
Object.defineProperty(exports, key, {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return _utils[key];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
var _types = require("./types");
|
|
1
|
+
import { default as DynamoDbDriver } from "./DynamoDbDriver.js";
|
|
2
|
+
export * from "./utils/index.js";
|
|
3
|
+
export * from "./plugins/index.js";
|
|
4
|
+
export { DynamoDbDriver };
|
|
37
5
|
|
|
38
6
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["default","DynamoDbDriver"],"sources":["index.ts"],"sourcesContent":["import { default as DynamoDbDriver } from \"./DynamoDbDriver.js\";\n\nexport * from \"./utils/index.js\";\nexport * from \"./plugins/index.js\";\nexport type { DbItem } from \"./types.js\";\n\nexport { DynamoDbDriver };\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAAc;AAElC;AACA;AAGA,SAASA,cAAc","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/db-dynamodb",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -10,38 +11,30 @@
|
|
|
10
11
|
"author": "Webiny Ltd",
|
|
11
12
|
"license": "MIT",
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"@webiny/api": "6.0.0-
|
|
14
|
-
"@webiny/aws-sdk": "6.0.0-
|
|
15
|
-
"@webiny/db": "6.0.0-
|
|
16
|
-
"@webiny/error": "6.0.0-
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/
|
|
19
|
-
"date-fns": "2.
|
|
14
|
+
"@webiny/api": "6.0.0-rc.1",
|
|
15
|
+
"@webiny/aws-sdk": "6.0.0-rc.1",
|
|
16
|
+
"@webiny/db": "6.0.0-rc.1",
|
|
17
|
+
"@webiny/error": "6.0.0-rc.1",
|
|
18
|
+
"@webiny/plugins": "6.0.0-rc.1",
|
|
19
|
+
"@webiny/utils": "6.0.0-rc.1",
|
|
20
|
+
"date-fns": "2.30.0",
|
|
20
21
|
"dot-prop": "6.0.1",
|
|
21
|
-
"dynamodb-toolbox": "0.9.
|
|
22
|
-
"fuse.js": "7.
|
|
23
|
-
"
|
|
24
|
-
"lodash": "4.17.21"
|
|
22
|
+
"dynamodb-toolbox": "0.9.5",
|
|
23
|
+
"fuse.js": "7.1.0",
|
|
24
|
+
"lodash": "4.17.23"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@webiny/cli": "6.0.0-beta.0",
|
|
31
|
-
"@webiny/project-utils": "6.0.0-beta.0",
|
|
32
|
-
"jest": "29.7.0",
|
|
27
|
+
"@types/is-number": "7.0.5",
|
|
28
|
+
"@webiny/build-tools": "6.0.0-rc.1",
|
|
29
|
+
"@webiny/project-utils": "6.0.0-rc.1",
|
|
33
30
|
"jest-dynalite": "3.6.1",
|
|
34
|
-
"rimraf": "
|
|
35
|
-
"
|
|
36
|
-
"
|
|
31
|
+
"rimraf": "6.1.3",
|
|
32
|
+
"typescript": "5.9.3",
|
|
33
|
+
"vitest": "4.0.18"
|
|
37
34
|
},
|
|
38
35
|
"publishConfig": {
|
|
39
36
|
"access": "public",
|
|
40
37
|
"directory": "dist"
|
|
41
38
|
},
|
|
42
|
-
"
|
|
43
|
-
"build": "yarn webiny run build",
|
|
44
|
-
"watch": "yarn webiny run watch"
|
|
45
|
-
},
|
|
46
|
-
"gitHead": "aa8dbfbbd5ad13ec271adba6f2431e02991a300f"
|
|
39
|
+
"gitHead": "36d702721ff9ed39fb21d6f5fe7922a2a8716e63"
|
|
47
40
|
}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.AttributePlugin = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _plugins = require("@webiny/plugins");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { Plugin } from "@webiny/plugins";
|
|
10
3
|
const reservedFields = ["PK", "SK", "index", "data"];
|
|
11
|
-
class AttributePlugin extends
|
|
4
|
+
export class AttributePlugin extends Plugin {
|
|
12
5
|
static type = "db.dynamodb.attribute";
|
|
13
6
|
get entity() {
|
|
14
7
|
return this._entity;
|
|
@@ -36,11 +29,10 @@ class AttributePlugin extends _plugins.Plugin {
|
|
|
36
29
|
if (reservedFields.includes(attribute) === false) {
|
|
37
30
|
return;
|
|
38
31
|
}
|
|
39
|
-
throw new
|
|
32
|
+
throw new WebinyError(`Attribute name "${attribute}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
|
|
40
33
|
attribute
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
}
|
|
44
|
-
exports.AttributePlugin = AttributePlugin;
|
|
45
37
|
|
|
46
38
|
//# sourceMappingURL=AttributePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","Plugin","reservedFields","AttributePlugin","type","entity","_entity","attribute","_attribute","constructor","params","validateReserved","_params","getDefinition","includes"],"sources":["AttributePlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { AttributeDefinition } from \"~/toolbox.js\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\"];\n\nexport interface AttributePluginParams {\n entity: string;\n attribute: string;\n params: AttributeDefinition;\n}\n\nexport abstract class AttributePlugin extends Plugin {\n public static override readonly type: string = \"db.dynamodb.attribute\";\n private readonly _entity: string;\n private readonly _attribute: string;\n private readonly _params: AttributeDefinition;\n\n public get entity(): string {\n return this._entity;\n }\n\n public get attribute(): string {\n return this._attribute;\n }\n\n public constructor({ entity, attribute, params }: AttributePluginParams) {\n super();\n\n this.validateReserved(attribute);\n\n this._entity = entity;\n this._attribute = attribute;\n this._params = params;\n }\n\n public getDefinition(): Record<string, AttributeDefinition> {\n return {\n [this.attribute]: this._params\n };\n }\n\n private validateReserved(attribute: string): void {\n if (reservedFields.includes(attribute) === false) {\n return;\n }\n throw new WebinyError(\n `Attribute name \"${attribute}\" is not allowed.`,\n \"ATTRIBUTE_NOT_ALLOWED\",\n {\n attribute\n }\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,MAAM,QAAQ,iBAAiB;AAGxC,MAAMC,cAAc,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC;AAQpD,OAAO,MAAeC,eAAe,SAASF,MAAM,CAAC;EACjD,OAAgCG,IAAI,GAAW,uBAAuB;EAKtE,IAAWC,MAAMA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,OAAO;EACvB;EAEA,IAAWC,SAASA,CAAA,EAAW;IAC3B,OAAO,IAAI,CAACC,UAAU;EAC1B;EAEOC,WAAWA,CAAC;IAAEJ,MAAM;IAAEE,SAAS;IAAEG;EAA8B,CAAC,EAAE;IACrE,KAAK,CAAC,CAAC;IAEP,IAAI,CAACC,gBAAgB,CAACJ,SAAS,CAAC;IAEhC,IAAI,CAACD,OAAO,GAAGD,MAAM;IACrB,IAAI,CAACG,UAAU,GAAGD,SAAS;IAC3B,IAAI,CAACK,OAAO,GAAGF,MAAM;EACzB;EAEOG,aAAaA,CAAA,EAAwC;IACxD,OAAO;MACH,CAAC,IAAI,CAACN,SAAS,GAAG,IAAI,CAACK;IAC3B,CAAC;EACL;EAEQD,gBAAgBA,CAACJ,SAAiB,EAAQ;IAC9C,IAAIL,cAAc,CAACY,QAAQ,CAACP,SAAS,CAAC,KAAK,KAAK,EAAE;MAC9C;IACJ;IACA,MAAM,IAAIP,WAAW,CACjB,mBAAmBO,SAAS,mBAAmB,EAC/C,uBAAuB,EACvB;MACIA;IACJ,CACJ,CAAC;EACL;AACJ","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ValueTransformPluginParams } from "./ValueTransformPlugin.js";
|
|
2
|
+
import { ValueTransformPlugin } from "./ValueTransformPlugin.js";
|
|
2
3
|
export declare class DateTimeTransformPlugin extends ValueTransformPlugin {
|
|
3
4
|
constructor(params: Omit<ValueTransformPluginParams, "transform">);
|
|
4
5
|
}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.DateTimeTransformPlugin = void 0;
|
|
8
|
-
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _dateFns = require("date-fns");
|
|
1
|
+
import { ValueTransformPlugin } from "./ValueTransformPlugin.js";
|
|
2
|
+
import WebinyError from "@webiny/error";
|
|
3
|
+
import { parseISO } from "date-fns";
|
|
11
4
|
const transformDateTime = params => {
|
|
12
5
|
const {
|
|
13
6
|
value
|
|
@@ -15,7 +8,7 @@ const transformDateTime = params => {
|
|
|
15
8
|
if (value === null || value === undefined) {
|
|
16
9
|
return null;
|
|
17
10
|
} else if (typeof value === "string") {
|
|
18
|
-
const parsedDateTime =
|
|
11
|
+
const parsedDateTime = parseISO(value).getTime();
|
|
19
12
|
if (isNaN(parsedDateTime) === false) {
|
|
20
13
|
return parsedDateTime;
|
|
21
14
|
}
|
|
@@ -25,11 +18,11 @@ const transformDateTime = params => {
|
|
|
25
18
|
*/
|
|
26
19
|
return value.getTime();
|
|
27
20
|
}
|
|
28
|
-
throw new
|
|
21
|
+
throw new WebinyError("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
|
|
29
22
|
value
|
|
30
23
|
});
|
|
31
24
|
};
|
|
32
|
-
class DateTimeTransformPlugin extends
|
|
25
|
+
export class DateTimeTransformPlugin extends ValueTransformPlugin {
|
|
33
26
|
constructor(params) {
|
|
34
27
|
super({
|
|
35
28
|
transform: transformDateTime,
|
|
@@ -37,6 +30,5 @@ class DateTimeTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin
|
|
|
37
30
|
});
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
|
-
exports.DateTimeTransformPlugin = DateTimeTransformPlugin;
|
|
41
33
|
|
|
42
34
|
//# sourceMappingURL=DateTimeTransformPlugin.js.map
|