@kravc/dos-dynamodb 1.0.0-alpha.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/README.md +30 -0
- package/bin/table.js +88 -0
- package/config/default.yaml +36 -0
- package/config/test.yaml +0 -0
- package/dist/example/Activity.d.ts +34 -0
- package/dist/example/Activity.d.ts.map +1 -0
- package/dist/example/Activity.js +66 -0
- package/dist/example/Activity.js.map +1 -0
- package/dist/example/ActivityAttributes.d.ts +23 -0
- package/dist/example/ActivityAttributes.d.ts.map +1 -0
- package/dist/example/ActivityAttributes.js +54 -0
- package/dist/example/ActivityAttributes.js.map +1 -0
- package/dist/example/Asset.d.ts +36 -0
- package/dist/example/Asset.d.ts.map +1 -0
- package/dist/example/Asset.js +56 -0
- package/dist/example/Asset.js.map +1 -0
- package/dist/example/AssetAttributes.d.ts +28 -0
- package/dist/example/AssetAttributes.d.ts.map +1 -0
- package/dist/example/AssetAttributes.js +72 -0
- package/dist/example/AssetAttributes.js.map +1 -0
- package/dist/example/Organization.d.ts +19 -0
- package/dist/example/Organization.d.ts.map +1 -0
- package/dist/example/Organization.js +42 -0
- package/dist/example/Organization.js.map +1 -0
- package/dist/example/OrganizationAttributes.d.ts +13 -0
- package/dist/example/OrganizationAttributes.d.ts.map +1 -0
- package/dist/example/OrganizationAttributes.js +24 -0
- package/dist/example/OrganizationAttributes.js.map +1 -0
- package/dist/example/index.d.ts +5 -0
- package/dist/example/index.d.ts.map +1 -0
- package/dist/example/index.js +13 -0
- package/dist/example/index.js.map +1 -0
- package/dist/src/Document/Document.d.ts +67 -0
- package/dist/src/Document/Document.d.ts.map +1 -0
- package/dist/src/Document/Document.js +216 -0
- package/dist/src/Document/Document.js.map +1 -0
- package/dist/src/Document/DocumentWithHashId.d.ts +22 -0
- package/dist/src/Document/DocumentWithHashId.d.ts.map +1 -0
- package/dist/src/Document/DocumentWithHashId.js +73 -0
- package/dist/src/Document/DocumentWithHashId.js.map +1 -0
- package/dist/src/Document/__tests__/__helpers.d.ts +21 -0
- package/dist/src/Document/__tests__/__helpers.d.ts.map +1 -0
- package/dist/src/Document/__tests__/__helpers.js +92 -0
- package/dist/src/Document/__tests__/__helpers.js.map +1 -0
- package/dist/src/Document/helpers/composeIndexKeys.d.ts +11 -0
- package/dist/src/Document/helpers/composeIndexKeys.d.ts.map +1 -0
- package/dist/src/Document/helpers/composeIndexKeys.js +81 -0
- package/dist/src/Document/helpers/composeIndexKeys.js.map +1 -0
- package/dist/src/Document/helpers/index.d.ts +3 -0
- package/dist/src/Document/helpers/index.d.ts.map +1 -0
- package/dist/src/Document/helpers/index.js +9 -0
- package/dist/src/Document/helpers/index.js.map +1 -0
- package/dist/src/Table/Table.d.ts +56 -0
- package/dist/src/Table/Table.d.ts.map +1 -0
- package/dist/src/Table/Table.js +228 -0
- package/dist/src/Table/Table.js.map +1 -0
- package/dist/src/Table/helpers/buildConditionExpression.d.ts +22 -0
- package/dist/src/Table/helpers/buildConditionExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildConditionExpression.js +128 -0
- package/dist/src/Table/helpers/buildConditionExpression.js.map +1 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.d.ts +12 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.js +60 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.js.map +1 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.d.ts +17 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.js +77 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.js.map +1 -0
- package/dist/src/Table/helpers/buildTableSchema.d.ts +6 -0
- package/dist/src/Table/helpers/buildTableSchema.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildTableSchema.js +100 -0
- package/dist/src/Table/helpers/buildTableSchema.js.map +1 -0
- package/dist/src/Table/helpers/buildUpdateExpression.d.ts +10 -0
- package/dist/src/Table/helpers/buildUpdateExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildUpdateExpression.js +69 -0
- package/dist/src/Table/helpers/buildUpdateExpression.js.map +1 -0
- package/dist/src/Table/helpers/filterConditionExpression.d.ts +5 -0
- package/dist/src/Table/helpers/filterConditionExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/filterConditionExpression.js +68 -0
- package/dist/src/Table/helpers/filterConditionExpression.js.map +1 -0
- package/dist/src/Table/helpers/getRawClientConfig.d.ts +5 -0
- package/dist/src/Table/helpers/getRawClientConfig.d.ts.map +1 -0
- package/dist/src/Table/helpers/getRawClientConfig.js +29 -0
- package/dist/src/Table/helpers/getRawClientConfig.js.map +1 -0
- package/dist/src/Table/helpers/getTableOptions.d.ts +51 -0
- package/dist/src/Table/helpers/getTableOptions.d.ts.map +1 -0
- package/dist/src/Table/helpers/getTableOptions.js +144 -0
- package/dist/src/Table/helpers/getTableOptions.js.map +1 -0
- package/dist/src/Table/helpers/index.d.ts +10 -0
- package/dist/src/Table/helpers/index.d.ts.map +1 -0
- package/dist/src/Table/helpers/index.js +21 -0
- package/dist/src/Table/helpers/index.js.map +1 -0
- package/dist/src/Table/index.d.ts +8 -0
- package/dist/src/Table/index.d.ts.map +1 -0
- package/dist/src/Table/index.js +13 -0
- package/dist/src/Table/index.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +14 -0
- package/dist/src/index.js.map +1 -0
- package/docker-compose.yaml +10 -0
- package/eslint.config.mjs +35 -0
- package/example/Activity.ts +123 -0
- package/example/ActivityAttributes.ts +72 -0
- package/example/Asset.ts +78 -0
- package/example/AssetAttributes.ts +87 -0
- package/example/Organization.ts +61 -0
- package/example/OrganizationAttributes.ts +28 -0
- package/example/index.ts +9 -0
- package/jest.config.mjs +10 -0
- package/package.json +50 -0
- package/src/Document/DefaultAttributes.d.ts +16 -0
- package/src/Document/Document.ts +257 -0
- package/src/Document/DocumentWithHashId.ts +85 -0
- package/src/Document/__tests__/Document.test.ts +596 -0
- package/src/Document/__tests__/DocumentWithHashId.test.ts +81 -0
- package/src/Document/__tests__/__helpers.ts +115 -0
- package/src/Document/helpers/__tests__/composeIndexKeys.test.ts +40 -0
- package/src/Document/helpers/composeIndexKeys.ts +137 -0
- package/src/Document/helpers/index.ts +5 -0
- package/src/Table/Table.ts +354 -0
- package/src/Table/__tests__/Table.test.ts +64 -0
- package/src/Table/helpers/__tests__/buildQueryCommandInput.test.ts +14 -0
- package/src/Table/helpers/__tests__/buildTableSchema.test.ts +19 -0
- package/src/Table/helpers/buildConditionExpression.ts +151 -0
- package/src/Table/helpers/buildQueryCommandInput.ts +113 -0
- package/src/Table/helpers/buildQueryConditionExpression.ts +109 -0
- package/src/Table/helpers/buildTableSchema.ts +151 -0
- package/src/Table/helpers/buildUpdateExpression.ts +95 -0
- package/src/Table/helpers/filterConditionExpression.ts +87 -0
- package/src/Table/helpers/getRawClientConfig.ts +35 -0
- package/src/Table/helpers/getTableOptions.ts +228 -0
- package/src/Table/helpers/index.ts +21 -0
- package/src/Table/index.ts +18 -0
- package/src/index.ts +15 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LOCAL_REGION = void 0;
|
|
7
|
+
const config_1 = __importDefault(require("config"));
|
|
8
|
+
const dos_1 = require("@kravc/dos");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
exports.LOCAL_REGION = 'local';
|
|
13
|
+
const PRIVATE_PROFILE = 'private';
|
|
14
|
+
/** Returns default table name. */
|
|
15
|
+
const getDefaultName = () => {
|
|
16
|
+
const ROOT_PATH = process.cwd();
|
|
17
|
+
const { NODE_APP_INSTANCE } = process.env;
|
|
18
|
+
const { name } = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(ROOT_PATH, 'package.json'), 'utf-8'));
|
|
19
|
+
const prefix = name.replace('@', '').replace('/', '-');
|
|
20
|
+
return [prefix, NODE_APP_INSTANCE].filter(value => !!value).join('-');
|
|
21
|
+
};
|
|
22
|
+
/** Returns options for DynamoDB table creation. */
|
|
23
|
+
const getTableOptions = (partitionKey, sortKey) => {
|
|
24
|
+
const tableConfig = config_1.default.get('dynamodb');
|
|
25
|
+
const tableOptions = JSON.parse(JSON.stringify(tableConfig));
|
|
26
|
+
const name = (0, lodash_1.get)(tableConfig, 'name', getDefaultName());
|
|
27
|
+
const indexKeys = (0, lodash_1.get)(tableConfig, 'indexKeys', {});
|
|
28
|
+
const region = (0, lodash_1.get)(config_1.default, 'aws.region', exports.LOCAL_REGION);
|
|
29
|
+
const profile = (0, lodash_1.get)(config_1.default, 'aws.profile', PRIVATE_PROFILE);
|
|
30
|
+
const primaryKey = {
|
|
31
|
+
sortKey,
|
|
32
|
+
partitionKey,
|
|
33
|
+
};
|
|
34
|
+
tableOptions.name = name;
|
|
35
|
+
tableOptions.region = region;
|
|
36
|
+
tableOptions.profile = profile;
|
|
37
|
+
tableOptions.indexKeys = indexKeys;
|
|
38
|
+
tableOptions.primaryKey = primaryKey;
|
|
39
|
+
tableOptions.isLocalhost = region === exports.LOCAL_REGION;
|
|
40
|
+
tableOptions.localSecondaryIndexes = (0, lodash_1.get)(config_1.default, 'localSecondaryIndexes', [
|
|
41
|
+
{
|
|
42
|
+
name: 'lsi1',
|
|
43
|
+
sortKey: '_lsi1SortKey',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'lsi2',
|
|
47
|
+
sortKey: '_lsi2SortKey',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'lsi3',
|
|
51
|
+
sortKey: '_lsi3SortKey',
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
tableOptions.globalSecondaryIndexes = (0, lodash_1.get)(config_1.default, 'globalSecondaryIndexes', [
|
|
55
|
+
{
|
|
56
|
+
name: 'gsi1',
|
|
57
|
+
partitionKey: '_gsi1PartitionKey',
|
|
58
|
+
sortKey: '_gsi1SortKey',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'gsi2',
|
|
62
|
+
partitionKey: '_gsi2PartitionKey',
|
|
63
|
+
sortKey: '_gsi2SortKey',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'gsi3',
|
|
67
|
+
partitionKey: '_gsi3PartitionKey',
|
|
68
|
+
sortKey: '_gsi3SortKey',
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
/** Returns sort key name for a local secondary index. */
|
|
72
|
+
const getLocalIndexSortKeyName = (indexName) => {
|
|
73
|
+
const { localSecondaryIndexes } = tableOptions;
|
|
74
|
+
const index = localSecondaryIndexes.find(({ name }) => name === indexName);
|
|
75
|
+
const indexesJson = JSON.stringify(localSecondaryIndexes, null, 2);
|
|
76
|
+
if (!index) {
|
|
77
|
+
throw new Error(`Local secondary index "${indexName}" is not defined, local indexes: ${indexesJson}`);
|
|
78
|
+
}
|
|
79
|
+
return (0, dos_1.got)(index, 'sortKey');
|
|
80
|
+
};
|
|
81
|
+
/** Returns partition key name for a global secondary index. */
|
|
82
|
+
const getGlobalIndexPartitionKeyName = (indexName) => {
|
|
83
|
+
const { globalSecondaryIndexes } = tableOptions;
|
|
84
|
+
const index = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
85
|
+
const indexesJson = JSON.stringify(globalSecondaryIndexes, null, 2);
|
|
86
|
+
if (!index) {
|
|
87
|
+
throw new Error(`Global secondary index "${indexName}" is not defined, global indexes: ${indexesJson}`);
|
|
88
|
+
}
|
|
89
|
+
return (0, dos_1.got)(index, 'partitionKey');
|
|
90
|
+
};
|
|
91
|
+
/** Returns sort key name for a global secondary index. */
|
|
92
|
+
const getGlobalIndexSortKeyName = (indexName) => {
|
|
93
|
+
const { globalSecondaryIndexes } = tableOptions;
|
|
94
|
+
const index = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
95
|
+
const indexesJson = JSON.stringify(globalSecondaryIndexes, null, 2);
|
|
96
|
+
if (!index) {
|
|
97
|
+
throw new Error(`Global secondary index "${indexName}" is not defined, global indexes: ${indexesJson}`);
|
|
98
|
+
}
|
|
99
|
+
return (0, dos_1.got)(index, 'sortKey');
|
|
100
|
+
};
|
|
101
|
+
/** Returns true if local secondary index, false if global secondary index; throws if not found. */
|
|
102
|
+
const isLocalSecondaryIndex = (indexName) => {
|
|
103
|
+
const { localSecondaryIndexes, globalSecondaryIndexes } = tableOptions;
|
|
104
|
+
const lsi = localSecondaryIndexes.find(({ name }) => name === indexName);
|
|
105
|
+
if (lsi) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
const gsi = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
109
|
+
if (gsi) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const indexesJson = JSON.stringify({ localSecondaryIndexes, globalSecondaryIndexes }, null, 2);
|
|
113
|
+
throw new Error(`Index "${indexName}" is not defined, indexes: ${indexesJson}`);
|
|
114
|
+
};
|
|
115
|
+
/** Returns props for a local index by name. */
|
|
116
|
+
const getLocalIndexProps = (indexName) => {
|
|
117
|
+
isLocalSecondaryIndex(indexName);
|
|
118
|
+
const sortKeyName = getLocalIndexSortKeyName(indexName);
|
|
119
|
+
return {
|
|
120
|
+
indexName,
|
|
121
|
+
sortKeyName,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/** Returns props for a global index by name. */
|
|
125
|
+
const getGlobalIndexProps = (indexName) => {
|
|
126
|
+
isLocalSecondaryIndex(indexName);
|
|
127
|
+
const sortKeyName = getGlobalIndexSortKeyName(indexName);
|
|
128
|
+
const partitionKeyName = getGlobalIndexPartitionKeyName(indexName);
|
|
129
|
+
return {
|
|
130
|
+
indexName,
|
|
131
|
+
sortKeyName,
|
|
132
|
+
partitionKeyName,
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
tableOptions.getLocalIndexSortKeyName = getLocalIndexSortKeyName;
|
|
136
|
+
tableOptions.getGlobalIndexPartitionKeyName = getGlobalIndexPartitionKeyName;
|
|
137
|
+
tableOptions.getGlobalIndexSortKeyName = getGlobalIndexSortKeyName;
|
|
138
|
+
tableOptions.isLocalSecondaryIndex = isLocalSecondaryIndex;
|
|
139
|
+
tableOptions.getGlobalIndexProps = getGlobalIndexProps;
|
|
140
|
+
tableOptions.getLocalIndexProps = getLocalIndexProps;
|
|
141
|
+
return tableOptions;
|
|
142
|
+
};
|
|
143
|
+
exports.default = getTableOptions;
|
|
144
|
+
//# sourceMappingURL=getTableOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTableOptions.js","sourceRoot":"","sources":["../../../../src/Table/helpers/getTableOptions.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oCAAiC;AACjC,mCAA6B;AAC7B,yCAAiC;AACjC,qCAAuC;AAE1B,QAAA,YAAY,GAAG,OAAO,CAAC;AACpC,MAAM,eAAe,GAAG,SAAS,CAAC;AAiDlC,kCAAkC;AAClC,MAAM,cAAc,GAAG,GAAW,EAAE;IAClC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAE1C,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CACzB,IAAA,sBAAY,EAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAClC,CAAC;IAEvB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAA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D,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import buildTableSchema from './buildTableSchema';
|
|
2
|
+
import getRawClientConfig from './getRawClientConfig';
|
|
3
|
+
import buildUpdateExpression from './buildUpdateExpression';
|
|
4
|
+
import buildQueryCommandInput from './buildQueryCommandInput';
|
|
5
|
+
import buildConditionExpression from './buildConditionExpression';
|
|
6
|
+
import filterConditionExpression from './filterConditionExpression';
|
|
7
|
+
import getTableOptions, { type TableOptions } from './getTableOptions';
|
|
8
|
+
export { getTableOptions, buildTableSchema, getRawClientConfig, buildUpdateExpression, buildQueryCommandInput, buildConditionExpression, filterConditionExpression, };
|
|
9
|
+
export type { TableOptions, };
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAC9D,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,eAAe,EAAE,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,GAC1B,CAAC;AAEF,YAAY,EACV,YAAY,GACb,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.filterConditionExpression = exports.buildConditionExpression = exports.buildQueryCommandInput = exports.buildUpdateExpression = exports.getRawClientConfig = exports.buildTableSchema = exports.getTableOptions = void 0;
|
|
7
|
+
const buildTableSchema_1 = __importDefault(require("./buildTableSchema"));
|
|
8
|
+
exports.buildTableSchema = buildTableSchema_1.default;
|
|
9
|
+
const getRawClientConfig_1 = __importDefault(require("./getRawClientConfig"));
|
|
10
|
+
exports.getRawClientConfig = getRawClientConfig_1.default;
|
|
11
|
+
const buildUpdateExpression_1 = __importDefault(require("./buildUpdateExpression"));
|
|
12
|
+
exports.buildUpdateExpression = buildUpdateExpression_1.default;
|
|
13
|
+
const buildQueryCommandInput_1 = __importDefault(require("./buildQueryCommandInput"));
|
|
14
|
+
exports.buildQueryCommandInput = buildQueryCommandInput_1.default;
|
|
15
|
+
const buildConditionExpression_1 = __importDefault(require("./buildConditionExpression"));
|
|
16
|
+
exports.buildConditionExpression = buildConditionExpression_1.default;
|
|
17
|
+
const filterConditionExpression_1 = __importDefault(require("./filterConditionExpression"));
|
|
18
|
+
exports.filterConditionExpression = filterConditionExpression_1.default;
|
|
19
|
+
const getTableOptions_1 = __importDefault(require("./getTableOptions"));
|
|
20
|
+
exports.getTableOptions = getTableOptions_1.default;
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Table/helpers/index.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAkD;AAUhD,2BAVK,0BAAgB,CAUL;AATlB,8EAAsD;AAUpD,6BAVK,4BAAkB,CAUL;AATpB,oFAA4D;AAU1D,gCAVK,+BAAqB,CAUL;AATvB,sFAA8D;AAU5D,iCAVK,gCAAsB,CAUL;AATxB,0FAAkE;AAUhE,mCAVK,kCAAwB,CAUL;AAT1B,4FAAoE;AAUlE,oCAVK,mCAAyB,CAUL;AAT3B,wEAAuE;AAGrE,0BAHK,yBAAe,CAGL"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExpressionKey } from './helpers/buildConditionExpression';
|
|
2
|
+
import { SortExpressionKey } from './helpers/buildQueryConditionExpression';
|
|
3
|
+
import Table, { type ItemAttributes } from './Table';
|
|
4
|
+
import type { TableOptions, LocalIndexKeyComposer, GlobalIndexKeyComposer } from './helpers/getTableOptions';
|
|
5
|
+
export default Table;
|
|
6
|
+
export { ExpressionKey, SortExpressionKey, };
|
|
7
|
+
export type { TableOptions, ItemAttributes, LocalIndexKeyComposer, GlobalIndexKeyComposer };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Table/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,KAAK,EAAE,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAE7G,eAAe,KAAK,CAAC;AAErB,OAAO,EACL,aAAa,EACb,iBAAiB,GAClB,CAAC;AAEF,YAAY,EACV,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACvB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SortExpressionKey = exports.ExpressionKey = void 0;
|
|
7
|
+
const buildConditionExpression_1 = require("./helpers/buildConditionExpression");
|
|
8
|
+
Object.defineProperty(exports, "ExpressionKey", { enumerable: true, get: function () { return buildConditionExpression_1.ExpressionKey; } });
|
|
9
|
+
const buildQueryConditionExpression_1 = require("./helpers/buildQueryConditionExpression");
|
|
10
|
+
Object.defineProperty(exports, "SortExpressionKey", { enumerable: true, get: function () { return buildQueryConditionExpression_1.SortExpressionKey; } });
|
|
11
|
+
const Table_1 = __importDefault(require("./Table"));
|
|
12
|
+
exports.default = Table_1.default;
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Table/index.ts"],"names":[],"mappings":";;;;;;AAAA,iFAAmE;AAQjE,8FARO,wCAAa,OAQP;AAPf,2FAA4E;AAQ1E,kGARO,iDAAiB,OAQP;AAPnB,oDAAqD;AAGrD,kBAAe,eAAK,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Document from './Document/Document';
|
|
2
|
+
import DocumentWithHashId from './Document/DocumentWithHashId';
|
|
3
|
+
import type { DefaultAttributes } from './Document/DefaultAttributes';
|
|
4
|
+
import { ExpressionKey, SortExpressionKey } from './Table';
|
|
5
|
+
export { Document, ExpressionKey, SortExpressionKey, DocumentWithHashId, };
|
|
6
|
+
export type { DefaultAttributes, };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,kBAAkB,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,EACL,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,CAAC;AAEF,YAAY,EACV,iBAAiB,GAClB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DocumentWithHashId = exports.SortExpressionKey = exports.ExpressionKey = exports.Document = void 0;
|
|
7
|
+
const Document_1 = __importDefault(require("./Document/Document"));
|
|
8
|
+
exports.Document = Document_1.default;
|
|
9
|
+
const DocumentWithHashId_1 = __importDefault(require("./Document/DocumentWithHashId"));
|
|
10
|
+
exports.DocumentWithHashId = DocumentWithHashId_1.default;
|
|
11
|
+
const Table_1 = require("./Table");
|
|
12
|
+
Object.defineProperty(exports, "ExpressionKey", { enumerable: true, get: function () { return Table_1.ExpressionKey; } });
|
|
13
|
+
Object.defineProperty(exports, "SortExpressionKey", { enumerable: true, get: function () { return Table_1.SortExpressionKey; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mEAA2C;AAMzC,mBANK,kBAAQ,CAML;AALV,uFAA+D;AAQ7D,6BARK,4BAAkB,CAQL;AANpB,mCAA2D;AAIzD,8FAJO,qBAAa,OAIP;AACb,kGALsB,yBAAiB,OAKtB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import jsdoc from 'eslint-plugin-jsdoc';
|
|
2
|
+
import eslint from '@eslint/js';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
import tseslint from 'typescript-eslint';
|
|
5
|
+
import { globalIgnores } from 'eslint/config';
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
globalIgnores([ '**/dist/', '**/coverage/' ]),
|
|
9
|
+
{
|
|
10
|
+
languageOptions: {
|
|
11
|
+
globals: {
|
|
12
|
+
...globals.node,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
plugins: {
|
|
16
|
+
jsdoc,
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
semi: ['error', 'always'],
|
|
20
|
+
quotes: ['error', 'single'],
|
|
21
|
+
'jsdoc/require-jsdoc': ['error', {
|
|
22
|
+
require: {
|
|
23
|
+
ArrowFunctionExpression: true,
|
|
24
|
+
ClassDeclaration: true,
|
|
25
|
+
ClassExpression: true,
|
|
26
|
+
FunctionDeclaration: true,
|
|
27
|
+
FunctionExpression: true,
|
|
28
|
+
MethodDefinition: true,
|
|
29
|
+
},
|
|
30
|
+
}],
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
eslint.configs.recommended,
|
|
34
|
+
tseslint.configs.recommended
|
|
35
|
+
);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Document, SortExpressionKey } from '../src';
|
|
2
|
+
import { schema, type ActivityAttributes } from './ActivityAttributes';
|
|
3
|
+
import { got, type Context, type IndexOptions } from '@kravc/dos';
|
|
4
|
+
|
|
5
|
+
/** Activity document class. */
|
|
6
|
+
class Activity extends Document<ActivityAttributes> {
|
|
7
|
+
/** Returns index query and index name for parameters. */
|
|
8
|
+
static _getIndexQueryProps(
|
|
9
|
+
context: Context,
|
|
10
|
+
query: {
|
|
11
|
+
userId?: string;
|
|
12
|
+
endDate?: string;
|
|
13
|
+
startDate?: string;
|
|
14
|
+
operationId?: string;
|
|
15
|
+
[x: string]: unknown;
|
|
16
|
+
},
|
|
17
|
+
) {
|
|
18
|
+
const {
|
|
19
|
+
userId,
|
|
20
|
+
endDate,
|
|
21
|
+
startDate,
|
|
22
|
+
operationId,
|
|
23
|
+
...filterQuery
|
|
24
|
+
} = query;
|
|
25
|
+
|
|
26
|
+
/** Returns query for a global secondary index. */
|
|
27
|
+
const getGlobalIndexQuery = (indexName: string, partitionScope: string) => {
|
|
28
|
+
const {
|
|
29
|
+
sortKeyName,
|
|
30
|
+
partitionKeyName,
|
|
31
|
+
} = this.getGlobalIndexProps(indexName);
|
|
32
|
+
|
|
33
|
+
const indexQuery = {} as Record<string, string>;
|
|
34
|
+
|
|
35
|
+
const organizationId = got(context.identity, 'organizationId');
|
|
36
|
+
indexQuery[partitionKeyName] = `${organizationId}#${partitionScope}`;
|
|
37
|
+
|
|
38
|
+
if (startDate) {
|
|
39
|
+
indexQuery[`${sortKeyName}:${SortExpressionKey.GE}`] = `#${startDate}T00:00:00.000Z`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (endDate) {
|
|
43
|
+
indexQuery[`${sortKeyName}:${SortExpressionKey.LE}`] = `#${endDate}T23:59:99.999Z`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return indexQuery;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (userId) {
|
|
50
|
+
const indexName = 'gsi1';
|
|
51
|
+
const indexQuery = getGlobalIndexQuery(indexName, userId);
|
|
52
|
+
|
|
53
|
+
return { indexName, indexQuery: { ...indexQuery, ...filterQuery } };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (operationId) {
|
|
57
|
+
const indexName = 'gsi2';
|
|
58
|
+
const indexQuery = getGlobalIndexQuery(indexName, operationId);
|
|
59
|
+
|
|
60
|
+
return { indexName, indexQuery: { ...indexQuery, ...filterQuery } };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
indexName,
|
|
65
|
+
sortKeyName
|
|
66
|
+
} = this.getLocalIndexProps('lsi3');
|
|
67
|
+
|
|
68
|
+
const indexQuery = {} as Record<string, string>;
|
|
69
|
+
|
|
70
|
+
if (startDate) {
|
|
71
|
+
indexQuery[`${sortKeyName}:${SortExpressionKey.GE}`] = `#${startDate}T00:00:00.000Z`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (endDate) {
|
|
75
|
+
indexQuery[`${sortKeyName}:${SortExpressionKey.LE}`] = `#${endDate}T23:59:99.999Z`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { indexName, indexQuery: { ...indexQuery, ...filterQuery } };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Returns activities. */
|
|
82
|
+
static async indexWithDateRange(
|
|
83
|
+
context: Context,
|
|
84
|
+
query: {
|
|
85
|
+
userId?: string;
|
|
86
|
+
endDate?: string;
|
|
87
|
+
startDate?: string;
|
|
88
|
+
operationId?: string;
|
|
89
|
+
[x: string]: unknown;
|
|
90
|
+
} = {},
|
|
91
|
+
options: IndexOptions = {}
|
|
92
|
+
) {
|
|
93
|
+
const {
|
|
94
|
+
userId,
|
|
95
|
+
endDate,
|
|
96
|
+
startDate,
|
|
97
|
+
operationId,
|
|
98
|
+
} = query;
|
|
99
|
+
|
|
100
|
+
if (userId) {
|
|
101
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query);
|
|
102
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (operationId) {
|
|
106
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query);
|
|
107
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const hasDateRange = !!startDate || !!endDate;
|
|
111
|
+
|
|
112
|
+
if (hasDateRange) {
|
|
113
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query);
|
|
114
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return this.index(context, query, options);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Activity.schema = schema;
|
|
122
|
+
|
|
123
|
+
export default Activity;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Schema } from '@kravc/schema';
|
|
2
|
+
import { DefaultAttributes } from '../src';
|
|
3
|
+
|
|
4
|
+
type Identity = {
|
|
5
|
+
sub: string;
|
|
6
|
+
email: string;
|
|
7
|
+
firstName: string;
|
|
8
|
+
lastName: string;
|
|
9
|
+
permissions: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ActivityAttributes extends DefaultAttributes {
|
|
13
|
+
operationId: string;
|
|
14
|
+
summaryTemplate: string;
|
|
15
|
+
parametersJson?: string;
|
|
16
|
+
resultDocumentJson?: string;
|
|
17
|
+
userId: string;
|
|
18
|
+
traceId: string;
|
|
19
|
+
userAgent: string;
|
|
20
|
+
ipAddress: string;
|
|
21
|
+
identity?: Identity
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const schema = new Schema({
|
|
25
|
+
operationId: {
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
summaryTemplate: {
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
parametersJson: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
},
|
|
34
|
+
resultDocumentJson: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
},
|
|
37
|
+
userId: {
|
|
38
|
+
required: true
|
|
39
|
+
},
|
|
40
|
+
traceId: {
|
|
41
|
+
required: true
|
|
42
|
+
},
|
|
43
|
+
userAgent: {
|
|
44
|
+
required: true
|
|
45
|
+
},
|
|
46
|
+
ipAddress: {
|
|
47
|
+
required: true
|
|
48
|
+
},
|
|
49
|
+
identity: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
sub: {
|
|
53
|
+
required: true
|
|
54
|
+
},
|
|
55
|
+
email: {
|
|
56
|
+
required: true
|
|
57
|
+
},
|
|
58
|
+
firstName: {
|
|
59
|
+
required: true
|
|
60
|
+
},
|
|
61
|
+
lastName: {
|
|
62
|
+
required: true
|
|
63
|
+
},
|
|
64
|
+
permissions: {
|
|
65
|
+
required: true,
|
|
66
|
+
items: {
|
|
67
|
+
type: 'string'
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, 'ActivityBody');
|
package/example/Asset.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type AssetAttributes, AssetStatus, schema } from './AssetAttributes';
|
|
2
|
+
import { Document, ExpressionKey, SortExpressionKey } from '../src';
|
|
3
|
+
import { got, type Context, type QueryMap, type IndexOptions } from '@kravc/dos';
|
|
4
|
+
|
|
5
|
+
/** Asset document class. */
|
|
6
|
+
class Asset extends Document<AssetAttributes> {
|
|
7
|
+
/** Returns props for an index query. */
|
|
8
|
+
static _getIndexQueryProps(
|
|
9
|
+
context: Context,
|
|
10
|
+
query: {
|
|
11
|
+
createdBy?: string;
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
},
|
|
14
|
+
status: AssetStatus
|
|
15
|
+
) {
|
|
16
|
+
const indexQuery = {} as Record<string, string>;
|
|
17
|
+
|
|
18
|
+
let indexName = 'lsi2';
|
|
19
|
+
let sortKeyName = this.getLocalIndexSortKeyName(indexName);
|
|
20
|
+
|
|
21
|
+
const { createdBy, ...filterQuery } = query;
|
|
22
|
+
|
|
23
|
+
if (createdBy) {
|
|
24
|
+
indexName = 'gsi1';
|
|
25
|
+
sortKeyName = this.getGlobalIndexSortKeyName(indexName);
|
|
26
|
+
|
|
27
|
+
const organizationId = got(context.identity, 'organizationId');
|
|
28
|
+
const partitionKeyName = this.getGlobalIndexPartitionKeyName(indexName);
|
|
29
|
+
|
|
30
|
+
indexQuery[partitionKeyName] = `${organizationId}#${createdBy}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
indexQuery[`${sortKeyName}:${SortExpressionKey.BW}`] = `#${status}`;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
indexQuery: { ...indexQuery, ...filterQuery },
|
|
37
|
+
indexName,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Returns active assets. */
|
|
42
|
+
static async indexActiveAssets(context: Context, query: QueryMap = {}, options: IndexOptions = {}) {
|
|
43
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query, AssetStatus.ACTIVE);
|
|
44
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Returns archived assets. */
|
|
48
|
+
static async indexArchivedAssets(context: Context, query: QueryMap = {}, options: IndexOptions = {}) {
|
|
49
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query, AssetStatus.ARCHIVED);
|
|
50
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Archives an asset. */
|
|
54
|
+
static async archive(context: Context, query: QueryMap) {
|
|
55
|
+
query[`status:${ExpressionKey.NOT}`] = AssetStatus.ARCHIVED;
|
|
56
|
+
|
|
57
|
+
const mutation = {
|
|
58
|
+
status: AssetStatus.ARCHIVED,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return this.update(context, query, mutation);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Unarchives the asset. */
|
|
65
|
+
static async unarchive(context: Context, query: QueryMap) {
|
|
66
|
+
query[`status:${ExpressionKey.NOT}`] = AssetStatus.ACTIVE;
|
|
67
|
+
|
|
68
|
+
const mutation = {
|
|
69
|
+
status: AssetStatus.ACTIVE,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return this.update(context, query, mutation);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Asset.schema = schema;
|
|
77
|
+
|
|
78
|
+
export default Asset;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Schema } from '@kravc/schema';
|
|
2
|
+
import { DefaultAttributes } from '../src';
|
|
3
|
+
|
|
4
|
+
export enum AssetType {
|
|
5
|
+
FILE = 'FILE',
|
|
6
|
+
CONTENT = 'CONTENT'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export enum AssetStatus {
|
|
10
|
+
ACTIVE = 'ACTIVE',
|
|
11
|
+
ARCHIVED = 'ARCHIVED'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AssetAttributes extends DefaultAttributes {
|
|
15
|
+
name: string;
|
|
16
|
+
tags: string[];
|
|
17
|
+
folderId?: string;
|
|
18
|
+
type: AssetType;
|
|
19
|
+
status: AssetStatus;
|
|
20
|
+
content?: string;
|
|
21
|
+
file?: {
|
|
22
|
+
url: string;
|
|
23
|
+
size: number;
|
|
24
|
+
name: string;
|
|
25
|
+
mimeType: string;
|
|
26
|
+
lastModifiedAt: string;
|
|
27
|
+
thumbnailUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const schema = new Schema({
|
|
32
|
+
name: {
|
|
33
|
+
required: true
|
|
34
|
+
},
|
|
35
|
+
tags: {
|
|
36
|
+
items: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
},
|
|
39
|
+
required: true
|
|
40
|
+
},
|
|
41
|
+
folderId: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
},
|
|
44
|
+
thumbnailUrl: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
format: 'url',
|
|
47
|
+
},
|
|
48
|
+
type: {
|
|
49
|
+
enum: [ AssetType.FILE, AssetType.CONTENT ],
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
status: {
|
|
53
|
+
enum: [ AssetStatus.ACTIVE, AssetStatus.ARCHIVED ],
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
content: {
|
|
57
|
+
type: 'string'
|
|
58
|
+
},
|
|
59
|
+
file: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
url: {
|
|
63
|
+
type: 'string',
|
|
64
|
+
format: 'url',
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
size: {
|
|
68
|
+
type: 'integer',
|
|
69
|
+
min: 0,
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
name: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
mimeType: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
required: true,
|
|
79
|
+
},
|
|
80
|
+
lastModifiedAt: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
format: 'date-time',
|
|
83
|
+
required: true,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, 'AssetBody');
|