@openstax/ts-utils 1.15.2 → 1.15.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/cjs/services/documentStore/unversioned/dynamodb.js +9 -2
- package/dist/cjs/services/documentStore/unversioned/file-system.js +2 -1
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +9 -2
- package/dist/esm/services/documentStore/unversioned/file-system.js +2 -1
- package/dist/esm/services/documentStore/versioned/file-system.js +1 -1
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BatchGetItemCommand, DynamoDB, GetItemCommand, PutItemCommand, ScanCommand, UpdateItemCommand } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { once } from '../../..';
|
|
3
3
|
import { resolveConfigValue } from '../../../config';
|
|
4
|
+
import { NotFoundError } from '../../../errors';
|
|
4
5
|
import { ifDefined } from '../../../guards';
|
|
5
6
|
import { decodeDynamoDocument, encodeDynamoAttribute, encodeDynamoDocument } from '../dynamoEncoding';
|
|
6
7
|
const dynamodb = once(() => new DynamoDB({ apiVersion: '2012-08-10' }));
|
|
@@ -59,9 +60,12 @@ export const dynamoUnversionedDocumentStore = (initializer) => () => (configProv
|
|
|
59
60
|
var _a;
|
|
60
61
|
const result = (_a = item.Attributes) === null || _a === void 0 ? void 0 : _a[field]['N'];
|
|
61
62
|
if (!result) {
|
|
62
|
-
throw new
|
|
63
|
+
throw new NotFoundError(`Item with ${key} "${id}" does not exist`);
|
|
63
64
|
}
|
|
64
65
|
return parseFloat(result);
|
|
66
|
+
}).catch((error) => {
|
|
67
|
+
throw error.name === 'ConditionalCheckFailedException' ?
|
|
68
|
+
new NotFoundError(`Item with ${key} "${id}" does not exist`) : error;
|
|
65
69
|
});
|
|
66
70
|
},
|
|
67
71
|
/* replaces only specified attributes with the given data */
|
|
@@ -94,9 +98,12 @@ export const dynamoUnversionedDocumentStore = (initializer) => () => (configProv
|
|
|
94
98
|
});
|
|
95
99
|
return dynamodb().send(cmd).then((item) => {
|
|
96
100
|
if (!item.Attributes) {
|
|
97
|
-
throw new
|
|
101
|
+
throw new NotFoundError(`Item with ${key} "${id}" does not exist`);
|
|
98
102
|
}
|
|
99
103
|
return decodeDynamoDocument(item.Attributes);
|
|
104
|
+
}).catch((error) => {
|
|
105
|
+
throw error.name === 'ConditionalCheckFailedException' ?
|
|
106
|
+
new NotFoundError(`Item with ${key} "${id}" does not exist`) : error;
|
|
100
107
|
});
|
|
101
108
|
},
|
|
102
109
|
/* replaces the entire document with the given data */
|
|
@@ -2,6 +2,7 @@ import * as fsModule from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { hashValue } from '../../..';
|
|
4
4
|
import { resolveConfigValue } from '../../../config';
|
|
5
|
+
import { NotFoundError } from '../../../errors';
|
|
5
6
|
import { ifDefined, isDefined } from '../../../guards';
|
|
6
7
|
export const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvider) => (_, hashKey) => {
|
|
7
8
|
const tableName = resolveConfigValue(configProvider[initializer.configSpace || 'fileSystem'].tableName);
|
|
@@ -72,7 +73,7 @@ export const fileSystemUnversionedDocumentStore = (initializer) => () => (config
|
|
|
72
73
|
await mkTableDir;
|
|
73
74
|
const data = await load(filename);
|
|
74
75
|
if (!data) {
|
|
75
|
-
throw new
|
|
76
|
+
throw new NotFoundError(`Item with ${hashKey.toString()} "${id}" does not exist`);
|
|
76
77
|
}
|
|
77
78
|
const newItem = { ...data, ...item };
|
|
78
79
|
return new Promise((resolve, reject) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fileSystemUnversionedDocumentStore } from
|
|
1
|
+
import { fileSystemUnversionedDocumentStore } from '../unversioned/file-system';
|
|
2
2
|
const PAGE_LIMIT = 5;
|
|
3
3
|
export const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider) => (_, hashKey, getAuthor) => {
|
|
4
4
|
const unversionedDocuments = fileSystemUnversionedDocumentStore(initializer)()(configProvider)({}, 'id');
|