@openstax/ts-utils 1.7.0 → 1.9.0
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/{fetch.d.ts → fetch/index.d.ts} +1 -1
- package/dist/{esm/middleware.d.ts → cjs/middleware/index.d.ts} +2 -2
- package/dist/cjs/misc/hashValue.d.ts +2 -3
- package/dist/cjs/{pagination.d.ts → pagination/index.d.ts} +1 -1
- package/dist/cjs/{pagination.js → pagination/index.js} +3 -3
- package/dist/cjs/routing/index.d.ts +0 -3
- package/dist/cjs/routing/index.js +7 -9
- package/dist/cjs/services/authProvider/decryption.js +5 -5
- package/dist/cjs/services/authProvider/index.d.ts +0 -2
- package/dist/cjs/services/authProvider/subrequest.js +6 -6
- package/dist/cjs/services/documentStore/dynamoEncoding.d.ts +10 -0
- package/dist/cjs/services/documentStore/dynamoEncoding.js +52 -0
- package/dist/cjs/services/documentStore/index.d.ts +14 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +13 -0
- package/dist/cjs/services/documentStore/unversioned/dynamodb.js +51 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +15 -0
- package/dist/cjs/services/documentStore/unversioned/file-system.js +81 -0
- package/dist/cjs/services/documentStore/unversioned/index.d.ts +2 -0
- package/dist/cjs/services/documentStore/unversioned/index.js +2 -0
- package/dist/{esm/services/versionedDocumentStore → cjs/services/documentStore/versioned}/dynamodb.d.ts +6 -11
- package/dist/cjs/services/{versionedDocumentStore → documentStore/versioned}/dynamodb.js +27 -70
- package/dist/cjs/services/{versionedDocumentStore → documentStore/versioned}/file-system.d.ts +6 -11
- package/dist/cjs/services/{versionedDocumentStore → documentStore/versioned}/file-system.js +16 -16
- package/dist/cjs/services/{versionedDocumentStore → documentStore/versioned}/index.d.ts +2 -8
- package/dist/cjs/services/documentStore/versioned/index.js +2 -0
- package/dist/cjs/services/exercisesGateway/index.d.ts +3 -6
- package/dist/cjs/services/exercisesGateway/index.js +7 -7
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +4 -0
- package/dist/esm/{fetch.d.ts → fetch/index.d.ts} +1 -1
- package/dist/{cjs/middleware.d.ts → esm/middleware/index.d.ts} +2 -2
- package/dist/esm/misc/hashValue.d.ts +2 -3
- package/dist/esm/{pagination.d.ts → pagination/index.d.ts} +1 -1
- package/dist/esm/{pagination.js → pagination/index.js} +3 -3
- package/dist/esm/routing/index.d.ts +0 -3
- package/dist/esm/routing/index.js +7 -9
- package/dist/esm/services/authProvider/decryption.js +5 -5
- package/dist/esm/services/authProvider/index.d.ts +0 -2
- package/dist/esm/services/authProvider/subrequest.js +6 -6
- package/dist/esm/services/documentStore/dynamoEncoding.d.ts +10 -0
- package/dist/esm/services/documentStore/dynamoEncoding.js +45 -0
- package/dist/esm/services/documentStore/index.d.ts +14 -0
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +13 -0
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +47 -0
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +15 -0
- package/dist/esm/services/documentStore/unversioned/file-system.js +51 -0
- package/dist/esm/services/documentStore/unversioned/index.d.ts +2 -0
- package/dist/esm/services/documentStore/unversioned/index.js +1 -0
- package/dist/{cjs/services/versionedDocumentStore → esm/services/documentStore/versioned}/dynamodb.d.ts +6 -11
- package/dist/esm/services/{versionedDocumentStore → documentStore/versioned}/dynamodb.js +17 -60
- package/dist/esm/services/{versionedDocumentStore → documentStore/versioned}/file-system.d.ts +6 -11
- package/dist/esm/services/{versionedDocumentStore → documentStore/versioned}/file-system.js +16 -16
- package/dist/esm/services/{versionedDocumentStore → documentStore/versioned}/index.d.ts +2 -8
- package/dist/esm/services/documentStore/versioned/index.js +1 -0
- package/dist/esm/services/exercisesGateway/index.d.ts +3 -6
- package/dist/esm/services/exercisesGateway/index.js +7 -7
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +4 -0
- package/package.json +118 -13
- package/dist/cjs/profile.d.ts +0 -61
- package/dist/cjs/profile.js +0 -199
- package/dist/esm/profile.d.ts +0 -61
- package/dist/esm/profile.js +0 -191
- /package/dist/cjs/{assertions.d.ts → assertions/index.d.ts} +0 -0
- /package/dist/cjs/{assertions.js → assertions/index.js} +0 -0
- /package/dist/cjs/{errors.d.ts → errors/index.d.ts} +0 -0
- /package/dist/cjs/{errors.js → errors/index.js} +0 -0
- /package/dist/cjs/{fetch.js → fetch/index.js} +0 -0
- /package/dist/cjs/{guards.d.ts → guards/index.d.ts} +0 -0
- /package/dist/cjs/{guards.js → guards/index.js} +0 -0
- /package/dist/cjs/{middleware.js → middleware/index.js} +0 -0
- /package/dist/cjs/services/{versionedDocumentStore → documentStore}/index.js +0 -0
- /package/dist/esm/{assertions.d.ts → assertions/index.d.ts} +0 -0
- /package/dist/esm/{assertions.js → assertions/index.js} +0 -0
- /package/dist/esm/{errors.d.ts → errors/index.d.ts} +0 -0
- /package/dist/esm/{errors.js → errors/index.js} +0 -0
- /package/dist/esm/{fetch.js → fetch/index.js} +0 -0
- /package/dist/esm/{guards.d.ts → guards/index.d.ts} +0 -0
- /package/dist/esm/{guards.js → guards/index.js} +0 -0
- /package/dist/esm/{middleware.js → middleware/index.js} +0 -0
- /package/dist/esm/services/{versionedDocumentStore → documentStore}/index.js +0 -0
|
@@ -2,65 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dynamoVersionedDocumentStore = void 0;
|
|
4
4
|
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
5
|
-
const __1 = require("
|
|
6
|
-
const config_1 = require("
|
|
7
|
-
const guards_1 = require("
|
|
5
|
+
const __1 = require("../../..");
|
|
6
|
+
const config_1 = require("../../../config");
|
|
7
|
+
const guards_1 = require("../../../guards");
|
|
8
|
+
const dynamoEncoding_1 = require("../dynamoEncoding");
|
|
8
9
|
const dynamodb = (0, __1.once)(() => new client_dynamodb_1.DynamoDB({ apiVersion: '2012-08-10' }));
|
|
9
|
-
const encodeDynamoAttribute = (value) => {
|
|
10
|
-
if (typeof value === 'string') {
|
|
11
|
-
return { S: value };
|
|
12
|
-
}
|
|
13
|
-
if (typeof value === 'number') {
|
|
14
|
-
return { N: value.toString() };
|
|
15
|
-
}
|
|
16
|
-
if (typeof value === 'boolean') {
|
|
17
|
-
return { BOOL: value };
|
|
18
|
-
}
|
|
19
|
-
if (value === null) {
|
|
20
|
-
return { NULL: true };
|
|
21
|
-
}
|
|
22
|
-
if (value instanceof Array) {
|
|
23
|
-
return { L: value.map(encodeDynamoAttribute) };
|
|
24
|
-
}
|
|
25
|
-
if ((0, guards_1.isPlainObject)(value)) {
|
|
26
|
-
return { M: encodeDynamoDocument(value) };
|
|
27
|
-
}
|
|
28
|
-
throw new Error(`unknown attribute type ${typeof value} with value ${value}.`);
|
|
29
|
-
};
|
|
30
|
-
const encodeDynamoDocument = (base) => Object.fromEntries(Object.entries(base).map(([key, value]) => ([key, encodeDynamoAttribute(value)])));
|
|
31
|
-
const decodeDynamoAttribute = (value) => {
|
|
32
|
-
if (value.S !== undefined) {
|
|
33
|
-
return value.S;
|
|
34
|
-
}
|
|
35
|
-
if (value.N !== undefined) {
|
|
36
|
-
return parseFloat(value.N);
|
|
37
|
-
}
|
|
38
|
-
if (value.BOOL !== undefined) {
|
|
39
|
-
return value.BOOL;
|
|
40
|
-
}
|
|
41
|
-
if (value.NULL !== undefined) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
if (value.L !== undefined) {
|
|
45
|
-
return value.L.map(decodeDynamoAttribute);
|
|
46
|
-
}
|
|
47
|
-
if (value.M !== undefined) {
|
|
48
|
-
return decodeDynamoDocument(value.M);
|
|
49
|
-
}
|
|
50
|
-
throw new Error(`unknown attribute type: ${JSON.stringify(value)}.`);
|
|
51
|
-
};
|
|
52
|
-
const decodeDynamoDocument = (document) => Object.fromEntries(Object.entries(document).map(([key, value]) => ([key, decodeDynamoAttribute(value)])));
|
|
53
10
|
// i'm not really excited about getAuthor being required, but ts is getting confused about the type when unspecified
|
|
54
|
-
const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) => (
|
|
11
|
+
const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) => (_, hashKey, getAuthor) => {
|
|
55
12
|
const options = (0, guards_1.ifDefined)(initializer, {});
|
|
56
13
|
const tableName = (0, __1.once)(() => (0, config_1.resolveConfigValue)(configProvider[(0, guards_1.ifDefined)(options.configSpace, 'dynamodb')].tableName));
|
|
57
14
|
return {
|
|
58
|
-
loadAllDocumentsTheBadWay:
|
|
15
|
+
loadAllDocumentsTheBadWay: async () => {
|
|
59
16
|
const loadAllResults = async (ExclusiveStartKey) => {
|
|
60
17
|
var _a;
|
|
61
18
|
const cmd = new client_dynamodb_1.ScanCommand({ TableName: await tableName(), ExclusiveStartKey });
|
|
62
19
|
const result = await dynamodb().send(cmd);
|
|
63
|
-
const resultItems = ((_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(decodeDynamoDocument)) || [];
|
|
20
|
+
const resultItems = ((_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(dynamoEncoding_1.decodeDynamoDocument)) || [];
|
|
64
21
|
if (result.LastEvaluatedKey) {
|
|
65
22
|
return [...resultItems, ...await loadAllResults(result.LastEvaluatedKey)];
|
|
66
23
|
}
|
|
@@ -74,20 +31,20 @@ const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) =>
|
|
|
74
31
|
return result;
|
|
75
32
|
}, new Map()));
|
|
76
33
|
return Array.from(allResults.values());
|
|
77
|
-
}
|
|
78
|
-
getVersions:
|
|
34
|
+
},
|
|
35
|
+
getVersions: async (id, startVersion) => {
|
|
79
36
|
const cmd = new client_dynamodb_1.QueryCommand({
|
|
80
37
|
TableName: await tableName(),
|
|
81
38
|
KeyConditionExpression: '#hk = :hkv',
|
|
82
39
|
ExpressionAttributeValues: {
|
|
83
|
-
':hkv': encodeDynamoAttribute(id)
|
|
40
|
+
':hkv': (0, dynamoEncoding_1.encodeDynamoAttribute)(id)
|
|
84
41
|
},
|
|
85
42
|
ExpressionAttributeNames: {
|
|
86
43
|
'#hk': hashKey.toString()
|
|
87
44
|
},
|
|
88
45
|
...(startVersion
|
|
89
46
|
? { ExclusiveStartKey: {
|
|
90
|
-
[hashKey]: encodeDynamoAttribute(id),
|
|
47
|
+
[hashKey]: (0, dynamoEncoding_1.encodeDynamoAttribute)(id),
|
|
91
48
|
timestamp: { N: startVersion.toString() }
|
|
92
49
|
} }
|
|
93
50
|
: {}),
|
|
@@ -95,28 +52,28 @@ const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) =>
|
|
|
95
52
|
});
|
|
96
53
|
return dynamodb().send(cmd).then(result => {
|
|
97
54
|
var _a;
|
|
98
|
-
const items = (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(decodeDynamoDocument);
|
|
55
|
+
const items = (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(dynamoEncoding_1.decodeDynamoDocument);
|
|
99
56
|
if (!items || items.length === 0) {
|
|
100
57
|
return undefined;
|
|
101
58
|
}
|
|
102
59
|
return {
|
|
103
60
|
items,
|
|
104
|
-
nextPageToken: result.LastEvaluatedKey ? decodeDynamoDocument(result.LastEvaluatedKey).timestamp : undefined
|
|
61
|
+
nextPageToken: result.LastEvaluatedKey ? (0, dynamoEncoding_1.decodeDynamoDocument)(result.LastEvaluatedKey).timestamp : undefined
|
|
105
62
|
};
|
|
106
63
|
});
|
|
107
|
-
}
|
|
108
|
-
getItem:
|
|
64
|
+
},
|
|
65
|
+
getItem: async (id, timestamp) => {
|
|
109
66
|
let keyConditionExpression = '#hk = :hkv';
|
|
110
67
|
const expressionAttributeNames = {
|
|
111
68
|
'#hk': hashKey.toString()
|
|
112
69
|
};
|
|
113
70
|
const expressionAttributeValues = {
|
|
114
|
-
':hkv': encodeDynamoAttribute(id)
|
|
71
|
+
':hkv': (0, dynamoEncoding_1.encodeDynamoAttribute)(id)
|
|
115
72
|
};
|
|
116
73
|
if (timestamp) {
|
|
117
74
|
keyConditionExpression += ' and #ts = :tsv';
|
|
118
75
|
expressionAttributeNames['#ts'] = 'timestamp';
|
|
119
|
-
expressionAttributeValues[':tsv'] = encodeDynamoAttribute(timestamp);
|
|
76
|
+
expressionAttributeValues[':tsv'] = (0, dynamoEncoding_1.encodeDynamoAttribute)(timestamp);
|
|
120
77
|
}
|
|
121
78
|
const cmd = new client_dynamodb_1.QueryCommand({
|
|
122
79
|
TableName: await tableName(),
|
|
@@ -128,20 +85,20 @@ const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) =>
|
|
|
128
85
|
});
|
|
129
86
|
return dynamodb().send(cmd).then(result => {
|
|
130
87
|
var _a;
|
|
131
|
-
return (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(decodeDynamoDocument)[0];
|
|
88
|
+
return (_a = result.Items) === null || _a === void 0 ? void 0 : _a.map(dynamoEncoding_1.decodeDynamoDocument)[0];
|
|
132
89
|
});
|
|
133
|
-
}
|
|
90
|
+
},
|
|
134
91
|
/* prepares a new version of a document with the given data, then allows some additional
|
|
135
92
|
* changes to be input to a `save` function that actually saves it. useful for additional
|
|
136
93
|
* changes based on the new document version or author. the document version and author
|
|
137
94
|
* cannot be modified */
|
|
138
|
-
prepareItem:
|
|
95
|
+
prepareItem: async (item, ...authorArgs) => {
|
|
139
96
|
// this getAuthor type is terrible
|
|
140
97
|
const author = getAuthor ? await getAuthor(...authorArgs) : authorArgs[0];
|
|
141
98
|
const timestamp = new Date().getTime();
|
|
142
99
|
return {
|
|
143
100
|
document: { ...item, timestamp, author },
|
|
144
|
-
save:
|
|
101
|
+
save: async (changes) => {
|
|
145
102
|
const document = {
|
|
146
103
|
...item,
|
|
147
104
|
...changes,
|
|
@@ -150,15 +107,15 @@ const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) =>
|
|
|
150
107
|
};
|
|
151
108
|
const cmd = new client_dynamodb_1.PutItemCommand({
|
|
152
109
|
TableName: await tableName(),
|
|
153
|
-
Item: encodeDynamoDocument(document),
|
|
110
|
+
Item: (0, dynamoEncoding_1.encodeDynamoDocument)(document),
|
|
154
111
|
});
|
|
155
112
|
return dynamodb().send(cmd)
|
|
156
113
|
.then(() => document);
|
|
157
|
-
}
|
|
114
|
+
}
|
|
158
115
|
};
|
|
159
|
-
}
|
|
116
|
+
},
|
|
160
117
|
/* saves a new version of a document with the given data */
|
|
161
|
-
putItem:
|
|
118
|
+
putItem: async (item, ...authorArgs) => {
|
|
162
119
|
// this getAuthor type is terrible
|
|
163
120
|
const author = getAuthor ? await getAuthor(...authorArgs) : authorArgs[0];
|
|
164
121
|
const document = {
|
|
@@ -168,11 +125,11 @@ const dynamoVersionedDocumentStore = (initializer) => () => (configProvider) =>
|
|
|
168
125
|
};
|
|
169
126
|
const cmd = new client_dynamodb_1.PutItemCommand({
|
|
170
127
|
TableName: await tableName(),
|
|
171
|
-
Item: encodeDynamoDocument(document),
|
|
128
|
+
Item: (0, dynamoEncoding_1.encodeDynamoDocument)(document),
|
|
172
129
|
});
|
|
173
130
|
return dynamodb().send(cmd)
|
|
174
131
|
.then(() => document);
|
|
175
|
-
}
|
|
132
|
+
},
|
|
176
133
|
};
|
|
177
134
|
};
|
|
178
135
|
exports.dynamoVersionedDocumentStore = dynamoVersionedDocumentStore;
|
package/dist/cjs/services/{versionedDocumentStore → documentStore/versioned}/file-system.d.ts
RENAMED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
declare type Config = {
|
|
5
|
-
tableName: string;
|
|
6
|
-
};
|
|
1
|
+
import { Config } from '..';
|
|
2
|
+
import { ConfigProviderForConfig } from '../../../config';
|
|
3
|
+
import { VersionedDocumentAuthor, VersionedTDocument } from '.';
|
|
7
4
|
interface Initializer<C> {
|
|
8
5
|
dataDir: string;
|
|
9
6
|
fs?: Pick<typeof import('fs'), 'readFile' | 'writeFile'>;
|
|
10
7
|
configSpace?: C;
|
|
11
8
|
}
|
|
12
|
-
export declare const fileSystemVersionedDocumentStore: <C extends string = "fileSystem">(initializer: Initializer<C>) => <T extends
|
|
13
|
-
tableName: import("
|
|
14
|
-
}; }) => <K extends keyof T, A extends ((...a: any[]) => Promise<VersionedDocumentAuthor>) | undefined>({
|
|
15
|
-
profile: Track;
|
|
16
|
-
}, hashKey: K, getAuthor: A) => {
|
|
9
|
+
export declare const fileSystemVersionedDocumentStore: <C extends string = "fileSystem">(initializer: Initializer<C>) => <T extends VersionedTDocument<T>>() => (configProvider: { [key in C]: {
|
|
10
|
+
tableName: import("../../../config").ConfigValueProvider<string>;
|
|
11
|
+
}; }) => <K extends keyof T, A extends ((...a: any[]) => Promise<VersionedDocumentAuthor>) | undefined>(_: {}, hashKey: K, getAuthor: A) => {
|
|
17
12
|
loadAllDocumentsTheBadWay: () => Promise<T[]>;
|
|
18
13
|
getVersions: (id: T[K], startVersion?: number | undefined) => Promise<{
|
|
19
14
|
items: T[];
|
|
@@ -29,11 +29,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.fileSystemVersionedDocumentStore = void 0;
|
|
30
30
|
const fsModule = __importStar(require("fs"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
|
-
const __1 = require("
|
|
33
|
-
const config_1 = require("
|
|
34
|
-
const guards_1 = require("
|
|
32
|
+
const __1 = require("../../..");
|
|
33
|
+
const config_1 = require("../../../config");
|
|
34
|
+
const guards_1 = require("../../../guards");
|
|
35
35
|
const PAGE_LIMIT = 5;
|
|
36
|
-
const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider) => (
|
|
36
|
+
const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider) => (_, hashKey, getAuthor) => {
|
|
37
37
|
const tableName = (0, config_1.resolveConfigValue)(configProvider[initializer.configSpace || 'fileSystem'].tableName);
|
|
38
38
|
const filePath = tableName.then((table) => path_1.default.join(initializer.dataDir, table));
|
|
39
39
|
const { readFile, writeFile } = (0, guards_1.ifDefined)(initializer.fs, fsModule);
|
|
@@ -59,14 +59,14 @@ const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider)
|
|
|
59
59
|
}));
|
|
60
60
|
let previousSave;
|
|
61
61
|
return {
|
|
62
|
-
loadAllDocumentsTheBadWay:
|
|
62
|
+
loadAllDocumentsTheBadWay: async () => {
|
|
63
63
|
await load;
|
|
64
64
|
return Object.entries(data || []).map(([, versions]) => {
|
|
65
65
|
const versionsList = Object.values(versions);
|
|
66
66
|
return versionsList[versionsList.length - 1];
|
|
67
67
|
});
|
|
68
|
-
}
|
|
69
|
-
getVersions:
|
|
68
|
+
},
|
|
69
|
+
getVersions: async (id, startVersion) => {
|
|
70
70
|
await load;
|
|
71
71
|
const versions = data === null || data === void 0 ? void 0 : data[(0, __1.hashValue)(id)];
|
|
72
72
|
const versionsList = versions ? Object.values(versions).reverse() : undefined;
|
|
@@ -80,8 +80,8 @@ const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider)
|
|
|
80
80
|
items,
|
|
81
81
|
nextPageToken: hasMore ? items[items.length - 1].timestamp : undefined
|
|
82
82
|
};
|
|
83
|
-
}
|
|
84
|
-
getItem:
|
|
83
|
+
},
|
|
84
|
+
getItem: async (id, timestamp) => {
|
|
85
85
|
await load;
|
|
86
86
|
const versions = data === null || data === void 0 ? void 0 : data[(0, __1.hashValue)(id)];
|
|
87
87
|
if (timestamp) {
|
|
@@ -89,14 +89,14 @@ const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider)
|
|
|
89
89
|
}
|
|
90
90
|
const versionsList = versions ? Object.values(versions) : [];
|
|
91
91
|
return versionsList[versionsList.length - 1];
|
|
92
|
-
}
|
|
93
|
-
prepareItem:
|
|
92
|
+
},
|
|
93
|
+
prepareItem: async (item, ...authorArgs) => {
|
|
94
94
|
// this getAuthor type is terrible
|
|
95
95
|
const author = getAuthor ? await getAuthor(...authorArgs) : authorArgs[0];
|
|
96
96
|
const timestamp = new Date().getTime();
|
|
97
97
|
return {
|
|
98
98
|
document: { ...item, timestamp, author },
|
|
99
|
-
save:
|
|
99
|
+
save: async (changes) => {
|
|
100
100
|
await load;
|
|
101
101
|
await previousSave;
|
|
102
102
|
const save = previousSave = new Promise(resolve => (async () => {
|
|
@@ -109,10 +109,10 @@ const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider)
|
|
|
109
109
|
writeFile(path, JSON.stringify(data, null, 2), () => resolve(document));
|
|
110
110
|
})());
|
|
111
111
|
return await save;
|
|
112
|
-
}
|
|
112
|
+
}
|
|
113
113
|
};
|
|
114
|
-
}
|
|
115
|
-
putItem:
|
|
114
|
+
},
|
|
115
|
+
putItem: async (item, ...authorArgs) => {
|
|
116
116
|
await load;
|
|
117
117
|
await previousSave;
|
|
118
118
|
const save = previousSave = new Promise(resolve => (async () => {
|
|
@@ -127,7 +127,7 @@ const fileSystemVersionedDocumentStore = (initializer) => () => (configProvider)
|
|
|
127
127
|
writeFile(path, JSON.stringify(data, null, 2), () => resolve(document));
|
|
128
128
|
})());
|
|
129
129
|
return await save;
|
|
130
|
-
}
|
|
130
|
+
},
|
|
131
131
|
};
|
|
132
132
|
};
|
|
133
133
|
exports.fileSystemVersionedDocumentStore = fileSystemVersionedDocumentStore;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
+
import { TDocument } from '..';
|
|
1
2
|
import { dynamoVersionedDocumentStore } from './dynamodb';
|
|
2
|
-
export declare type DocumentBaseValueTypes = number | boolean | string | null | DocumentBaseMapType | DocumentBaseListType;
|
|
3
|
-
export declare type DocumentBaseMapType = {
|
|
4
|
-
[key: string]: DocumentBaseValueTypes;
|
|
5
|
-
};
|
|
6
|
-
export declare type DocumentBaseListType = DocumentBaseValueTypes[];
|
|
7
3
|
export declare type VersionedDocumentAuthor = {
|
|
8
4
|
type: 'user';
|
|
9
5
|
uuid: string;
|
|
@@ -17,7 +13,5 @@ export declare type VersionedDocumentRequiredFields = {
|
|
|
17
13
|
timestamp: number;
|
|
18
14
|
author: VersionedDocumentAuthor;
|
|
19
15
|
};
|
|
20
|
-
export declare type
|
|
21
|
-
[k in keyof T]: DocumentBaseValueTypes;
|
|
22
|
-
} & VersionedDocumentRequiredFields;
|
|
16
|
+
export declare type VersionedTDocument<T> = TDocument<T> & VersionedDocumentRequiredFields;
|
|
23
17
|
export declare type VersionedDocumentStoreCreator = typeof dynamoVersionedDocumentStore;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ConfigProviderForConfig } from '../../config';
|
|
2
2
|
import { GenericFetch } from '../../fetch';
|
|
3
|
-
import { Track } from '../../profile';
|
|
4
3
|
export declare type Config = {
|
|
5
4
|
defaultCorrectness?: string;
|
|
6
5
|
exercisesHost: string;
|
|
@@ -63,12 +62,10 @@ export declare const exercisesGateway: <C extends string = "exercises">(initiali
|
|
|
63
62
|
defaultCorrectness?: import("../../config").ConfigValueProvider<string> | undefined;
|
|
64
63
|
exercisesHost: import("../../config").ConfigValueProvider<string>;
|
|
65
64
|
exercisesAuthToken: import("../../config").ConfigValueProvider<string>;
|
|
66
|
-
}; }) => ({
|
|
67
|
-
|
|
68
|
-
}) => {
|
|
69
|
-
searchDigest: (query: string, page?: any, per_page?: any) => Promise<string>;
|
|
65
|
+
}; }) => (_: {}) => {
|
|
66
|
+
searchDigest: (query: string, page?: number, per_page?: number) => Promise<string>;
|
|
70
67
|
get: (uuid: string) => Promise<Exercise | undefined>;
|
|
71
|
-
search: (query: string, page?:
|
|
68
|
+
search: (query: string, page?: number, per_page?: number) => Promise<ExercisesSearchResultsWithDigest>;
|
|
72
69
|
};
|
|
73
70
|
export declare type ExercisesGateway = ReturnType<ReturnType<ReturnType<typeof exercisesGateway>>>;
|
|
74
71
|
export {};
|
|
@@ -58,7 +58,7 @@ const exercisesGateway = (initializer) => (configProvider) => {
|
|
|
58
58
|
}
|
|
59
59
|
return exercise;
|
|
60
60
|
};
|
|
61
|
-
return (
|
|
61
|
+
return (_) => {
|
|
62
62
|
const request = async (method, path, query = undefined) => {
|
|
63
63
|
const host = (await exercisesHost()).replace(/\/+$/, '');
|
|
64
64
|
const baseUrl = `${host}/api/${path}`;
|
|
@@ -70,22 +70,22 @@ const exercisesGateway = (initializer) => (configProvider) => {
|
|
|
70
70
|
method,
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
-
const searchDigest =
|
|
73
|
+
const searchDigest = async (query, page = 1, per_page = 100) => {
|
|
74
74
|
const response = await request(routing_1.METHOD.HEAD, 'exercises', { query, page, per_page });
|
|
75
75
|
return (0, assertions_1.assertString)(response.headers.get('X-Digest'), 'OpenStax Exercises search endpoint HEAD did not return an X-Digest header');
|
|
76
|
-
}
|
|
77
|
-
const search =
|
|
76
|
+
};
|
|
77
|
+
const search = async (query, page = 1, per_page = 100) => {
|
|
78
78
|
const response = await request(routing_1.METHOD.GET, 'exercises', { query, page, per_page });
|
|
79
79
|
const digest = (0, assertions_1.assertString)(response.headers.get('X-Digest'), 'OpenStax Exercises search endpoint GET did not return an X-Digest header');
|
|
80
80
|
const { items, total_count } = await response.json();
|
|
81
81
|
return { digest, items: await Promise.all(items.map(doDefaultCorrectness)), total_count };
|
|
82
|
-
}
|
|
83
|
-
const get =
|
|
82
|
+
};
|
|
83
|
+
const get = async (uuid) => {
|
|
84
84
|
const response = await request(routing_1.METHOD.GET, `exercises/${uuid}`);
|
|
85
85
|
return response.status === 404
|
|
86
86
|
? undefined
|
|
87
87
|
: response.json().then(doDefaultCorrectness);
|
|
88
|
-
}
|
|
88
|
+
};
|
|
89
89
|
return {
|
|
90
90
|
searchDigest,
|
|
91
91
|
get,
|