@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
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamoDB,
|
|
1
|
+
import { BatchGetItemCommand, DynamoDB, GetItemCommand, PutItemCommand, ScanCommand } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { once } from '../../..';
|
|
3
3
|
import { resolveConfigValue } from '../../../config';
|
|
4
4
|
import { ifDefined } from '../../../guards';
|
|
@@ -10,10 +10,10 @@ export const dynamoUnversionedDocumentStore = (initializer) => () => (configProv
|
|
|
10
10
|
return {
|
|
11
11
|
loadAllDocumentsTheBadWay: async () => {
|
|
12
12
|
const loadAllResults = async (ExclusiveStartKey) => {
|
|
13
|
-
var _a;
|
|
13
|
+
var _a, _b;
|
|
14
14
|
const cmd = new ScanCommand({ TableName: await tableName(), ExclusiveStartKey });
|
|
15
15
|
const result = await dynamodb().send(cmd);
|
|
16
|
-
const resultItems = ((_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(decodeDynamoDocument))
|
|
16
|
+
const resultItems = (_b = (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map((item) => decodeDynamoDocument(item))) !== null && _b !== void 0 ? _b : [];
|
|
17
17
|
if (result.LastEvaluatedKey) {
|
|
18
18
|
return [...resultItems, ...await loadAllResults(result.LastEvaluatedKey)];
|
|
19
19
|
}
|
|
@@ -21,19 +21,26 @@ export const dynamoUnversionedDocumentStore = (initializer) => () => (configProv
|
|
|
21
21
|
};
|
|
22
22
|
return loadAllResults();
|
|
23
23
|
},
|
|
24
|
+
batchGetItem: async (ids) => {
|
|
25
|
+
const table = await tableName();
|
|
26
|
+
const key = hashKey.toString();
|
|
27
|
+
const getBatches = async (requestItems) => {
|
|
28
|
+
const cmd = new BatchGetItemCommand({
|
|
29
|
+
RequestItems: requestItems !== null && requestItems !== void 0 ? requestItems : { [table]: { Keys: ids.map((id) => ({ [key]: encodeDynamoAttribute(id) })) } },
|
|
30
|
+
});
|
|
31
|
+
const response = await dynamodb().send(cmd);
|
|
32
|
+
const currentResponses = response.Responses ?
|
|
33
|
+
response.Responses[table].map(response => decodeDynamoDocument(response)) : [];
|
|
34
|
+
return currentResponses.concat(response.UnprocessedKeys ? await getBatches(response.UnprocessedKeys) : []);
|
|
35
|
+
};
|
|
36
|
+
return getBatches();
|
|
37
|
+
},
|
|
24
38
|
getItem: async (id) => {
|
|
25
|
-
const cmd = new
|
|
39
|
+
const cmd = new GetItemCommand({
|
|
40
|
+
Key: { [hashKey.toString()]: encodeDynamoAttribute(id) },
|
|
26
41
|
TableName: await tableName(),
|
|
27
|
-
KeyConditionExpression: '#hk = :hkv',
|
|
28
|
-
ExpressionAttributeNames: { '#hk': hashKey.toString() },
|
|
29
|
-
ExpressionAttributeValues: { ':hkv': encodeDynamoAttribute(id) },
|
|
30
|
-
ScanIndexForward: false,
|
|
31
|
-
Limit: 1
|
|
32
|
-
});
|
|
33
|
-
return dynamodb().send(cmd).then(result => {
|
|
34
|
-
var _a;
|
|
35
|
-
return (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(decodeDynamoDocument)[0];
|
|
36
42
|
});
|
|
43
|
+
return dynamodb().send(cmd).then(result => result.Item ? decodeDynamoDocument(result.Item) : undefined);
|
|
37
44
|
},
|
|
38
45
|
/* saves a new version of a document with the given data */
|
|
39
46
|
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
|
};
|
|
@@ -39,6 +39,10 @@ export const fileSystemUnversionedDocumentStore = (initializer) => () => (config
|
|
|
39
39
|
Promise.all(files.map((file) => load(file)))
|
|
40
40
|
.then((allData) => resolve(allData.filter(isDefined)), (err) => reject(err))));
|
|
41
41
|
},
|
|
42
|
+
batchGetItem: async (ids) => {
|
|
43
|
+
const items = await Promise.all(ids.map((id) => load(hashFilename(id))));
|
|
44
|
+
return items.filter(isDefined);
|
|
45
|
+
},
|
|
42
46
|
getItem: (id) => load(hashFilename(id)),
|
|
43
47
|
putItem: async (item) => {
|
|
44
48
|
const path = await filePath(hashFilename(item[hashKey]));
|