@openstax/ts-utils 1.9.0 → 1.9.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/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +1 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.js +19 -12
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +1 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.js +4 -0
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +1 -0
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +20 -13
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +1 -0
- package/dist/esm/services/documentStore/unversioned/file-system.js +4 -0
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ export declare const dynamoUnversionedDocumentStore: <C extends string = "dynamo
|
|
|
7
7
|
tableName: import("../../../config").ConfigValueProvider<string>;
|
|
8
8
|
}; }) => <K extends keyof T>(_: {}, hashKey: K) => {
|
|
9
9
|
loadAllDocumentsTheBadWay: () => Promise<T[]>;
|
|
10
|
+
batchGetItem: (ids: T[K][]) => Promise<T[]>;
|
|
10
11
|
getItem: (id: T[K]) => Promise<T | undefined>;
|
|
11
12
|
putItem: (item: T) => Promise<T>;
|
|
12
13
|
};
|
|
@@ -13,10 +13,10 @@ const dynamoUnversionedDocumentStore = (initializer) => () => (configProvider) =
|
|
|
13
13
|
return {
|
|
14
14
|
loadAllDocumentsTheBadWay: async () => {
|
|
15
15
|
const loadAllResults = async (ExclusiveStartKey) => {
|
|
16
|
-
var _a;
|
|
16
|
+
var _a, _b;
|
|
17
17
|
const cmd = new client_dynamodb_1.ScanCommand({ TableName: await tableName(), ExclusiveStartKey });
|
|
18
18
|
const result = await dynamodb().send(cmd);
|
|
19
|
-
const resultItems = ((_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(dynamoEncoding_1.decodeDynamoDocument))
|
|
19
|
+
const resultItems = (_b = (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map((item) => (0, dynamoEncoding_1.decodeDynamoDocument)(item))) !== null && _b !== void 0 ? _b : [];
|
|
20
20
|
if (result.LastEvaluatedKey) {
|
|
21
21
|
return [...resultItems, ...await loadAllResults(result.LastEvaluatedKey)];
|
|
22
22
|
}
|
|
@@ -24,19 +24,26 @@ const dynamoUnversionedDocumentStore = (initializer) => () => (configProvider) =
|
|
|
24
24
|
};
|
|
25
25
|
return loadAllResults();
|
|
26
26
|
},
|
|
27
|
+
batchGetItem: async (ids) => {
|
|
28
|
+
const table = await tableName();
|
|
29
|
+
const key = hashKey.toString();
|
|
30
|
+
const getBatches = async (requestItems) => {
|
|
31
|
+
const cmd = new client_dynamodb_1.BatchGetItemCommand({
|
|
32
|
+
RequestItems: requestItems !== null && requestItems !== void 0 ? requestItems : { [table]: { Keys: ids.map((id) => ({ [key]: (0, dynamoEncoding_1.encodeDynamoAttribute)(id) })) } },
|
|
33
|
+
});
|
|
34
|
+
const response = await dynamodb().send(cmd);
|
|
35
|
+
const currentResponses = response.Responses ?
|
|
36
|
+
response.Responses[table].map(response => (0, dynamoEncoding_1.decodeDynamoDocument)(response)) : [];
|
|
37
|
+
return currentResponses.concat(response.UnprocessedKeys ? await getBatches(response.UnprocessedKeys) : []);
|
|
38
|
+
};
|
|
39
|
+
return getBatches();
|
|
40
|
+
},
|
|
27
41
|
getItem: async (id) => {
|
|
28
|
-
const cmd = new client_dynamodb_1.
|
|
42
|
+
const cmd = new client_dynamodb_1.GetItemCommand({
|
|
43
|
+
Key: { [hashKey.toString()]: (0, dynamoEncoding_1.encodeDynamoAttribute)(id) },
|
|
29
44
|
TableName: await tableName(),
|
|
30
|
-
KeyConditionExpression: '#hk = :hkv',
|
|
31
|
-
ExpressionAttributeNames: { '#hk': hashKey.toString() },
|
|
32
|
-
ExpressionAttributeValues: { ':hkv': (0, dynamoEncoding_1.encodeDynamoAttribute)(id) },
|
|
33
|
-
ScanIndexForward: false,
|
|
34
|
-
Limit: 1
|
|
35
|
-
});
|
|
36
|
-
return dynamodb().send(cmd).then(result => {
|
|
37
|
-
var _a;
|
|
38
|
-
return (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(dynamoEncoding_1.decodeDynamoDocument)[0];
|
|
39
45
|
});
|
|
46
|
+
return dynamodb().send(cmd).then(result => result.Item ? (0, dynamoEncoding_1.decodeDynamoDocument)(result.Item) : undefined);
|
|
40
47
|
},
|
|
41
48
|
/* saves a new version of a document with the given data */
|
|
42
49
|
putItem: async (item) => {
|
|
@@ -9,6 +9,7 @@ export declare const fileSystemUnversionedDocumentStore: <C extends string = "fi
|
|
|
9
9
|
tableName: import("../../../config").ConfigValueProvider<string>;
|
|
10
10
|
}; }) => <K extends keyof T>(_: {}, hashKey: K) => {
|
|
11
11
|
loadAllDocumentsTheBadWay: () => Promise<T[]>;
|
|
12
|
+
batchGetItem: (ids: T[K][]) => Promise<Exclude<Awaited<T>, undefined>[]>;
|
|
12
13
|
getItem: (id: T[K]) => Promise<T | undefined>;
|
|
13
14
|
putItem: (item: T) => Promise<T>;
|
|
14
15
|
};
|
|
@@ -68,6 +68,10 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
68
68
|
Promise.all(files.map((file) => load(file)))
|
|
69
69
|
.then((allData) => resolve(allData.filter(guards_1.isDefined)), (err) => reject(err))));
|
|
70
70
|
},
|
|
71
|
+
batchGetItem: async (ids) => {
|
|
72
|
+
const items = await Promise.all(ids.map((id) => load(hashFilename(id))));
|
|
73
|
+
return items.filter(guards_1.isDefined);
|
|
74
|
+
},
|
|
71
75
|
getItem: (id) => load(hashFilename(id)),
|
|
72
76
|
putItem: async (item) => {
|
|
73
77
|
const path = await filePath(hashFilename(item[hashKey]));
|