@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
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @kravc/dos-dynamodb
|
|
2
|
+
|
|
3
|
+
DynamoDB-backed CRUD layer for [@kravc/dos](https://github.com/alexkravets/dos). Exposes **Document** and **DocumentWithHashId** classes that plug into the dos service: define a schema and partition/sort keys, then use `create`, `get`, `update`, `delete`, and `index` (with GSI/LSI support) against a DynamoDB table.
|
|
4
|
+
|
|
5
|
+
**Examples** (see `example/`):
|
|
6
|
+
|
|
7
|
+
- **Asset** — `Document` with status filtering, archive/unarchive, and index queries (LSI/GSI).
|
|
8
|
+
- **Activity** — `Document` usage with activity-specific attributes and indexing.
|
|
9
|
+
- **Organization** — `DocumentWithHashId` with a fixed partition, list/disable/enable and `indexAll`.
|
|
10
|
+
|
|
11
|
+
Install:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i --save @kravc/dos-dynamodb
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
List supported DynamoDB table commands:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npx table
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
ISC
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
Revision: February 21, 2026<br/>
|
|
30
|
+
By: Oleksandr Kravets (@alexkravets)
|
package/bin/table.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
import Table from '../dist/src/Table';
|
|
6
|
+
import { exec } from 'child_process';
|
|
7
|
+
|
|
8
|
+
const command = process.argv[2];
|
|
9
|
+
const isInvalidCommand = ![ 'up', 'create', 'delete', 'reset' ].includes(command);
|
|
10
|
+
|
|
11
|
+
if (isInvalidCommand) {
|
|
12
|
+
console.info('table [create|delete|reset] [ENV=dev|stg|prd]\n');
|
|
13
|
+
console.info('Commands:');
|
|
14
|
+
console.info(' create Create tables defined in configuration');
|
|
15
|
+
console.info(' delete Delete tables defined in "/config/default.yaml"');
|
|
16
|
+
console.info(' reset Reset tables defined in "/config/default.yaml"');
|
|
17
|
+
console.info('\nDefault configuration file: "/config/default.yaml".');
|
|
18
|
+
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const env = process.argv[3];
|
|
23
|
+
|
|
24
|
+
if (env) {
|
|
25
|
+
process.env.NODE_ENV = 'serverless';
|
|
26
|
+
process.env.NODE_APP_INSTANCE = env;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Runs an action for a table. */
|
|
30
|
+
const _action = async (methodName) => {
|
|
31
|
+
const table = new Table({
|
|
32
|
+
sortKey: 'id',
|
|
33
|
+
partitionKey: 'partition',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const { name: tableName } = table.config;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await table[methodName]();
|
|
40
|
+
console.info(`Table "${tableName}" ${methodName}d`);
|
|
41
|
+
|
|
42
|
+
} catch (dynamoError) {
|
|
43
|
+
const { name: errorName } = dynamoError;
|
|
44
|
+
|
|
45
|
+
if (errorName === 'ResourceInUseException') {
|
|
46
|
+
console.info(`Table "${tableName}" skipped`);
|
|
47
|
+
|
|
48
|
+
} else if (errorName === 'ResourceNotFoundException') {
|
|
49
|
+
console.info(`Table "${tableName}" not found`);
|
|
50
|
+
|
|
51
|
+
} else {
|
|
52
|
+
console.error(dynamoError);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Creates a table. */
|
|
60
|
+
const _create = () => _action('create');
|
|
61
|
+
|
|
62
|
+
/** Deletes a table. */
|
|
63
|
+
const _delete = () => _action('delete');
|
|
64
|
+
|
|
65
|
+
/** Resets a table. */
|
|
66
|
+
const _reset = async () => {
|
|
67
|
+
await _delete();
|
|
68
|
+
await _create();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** Starts dynamodb in the Docker and runs a command. */
|
|
72
|
+
const run = async callback => {
|
|
73
|
+
if (env) {
|
|
74
|
+
return callback();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const command = exec('docker compose -f node_modules/@kravc/table/docker-compose.yaml up -d', callback);
|
|
78
|
+
command.stdout.on('data', data => console.log(data));
|
|
79
|
+
command.stderr.on('data', data => console.error(data));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const COMMANDS = {
|
|
83
|
+
reset: _reset,
|
|
84
|
+
create: _create,
|
|
85
|
+
delete: _delete,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
run(() => COMMANDS[command]());
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
dynamodb:
|
|
2
|
+
indexKeys:
|
|
3
|
+
lsi1:
|
|
4
|
+
documentName: 'Organization'
|
|
5
|
+
sk: '#createdAt'
|
|
6
|
+
|
|
7
|
+
lsi2:
|
|
8
|
+
documentName: 'Asset'
|
|
9
|
+
sk: '#status#createdAt'
|
|
10
|
+
|
|
11
|
+
lsi3:
|
|
12
|
+
documentName: 'Activity'
|
|
13
|
+
sk: '#createdAt'
|
|
14
|
+
|
|
15
|
+
gsi1:
|
|
16
|
+
Activity:
|
|
17
|
+
pk: '#partition#userId'
|
|
18
|
+
sk: '#createdAt'
|
|
19
|
+
|
|
20
|
+
Asset:
|
|
21
|
+
pk: '#partition#createdBy'
|
|
22
|
+
sk: '#status#createdAt'
|
|
23
|
+
|
|
24
|
+
Organization:
|
|
25
|
+
pk: 'PLATFORM'
|
|
26
|
+
sk: '#status#createdAt'
|
|
27
|
+
|
|
28
|
+
gsi2:
|
|
29
|
+
Activity:
|
|
30
|
+
pk: '#partition#operationId'
|
|
31
|
+
sk: '#createdAt'
|
|
32
|
+
|
|
33
|
+
idPrefixes:
|
|
34
|
+
Asset: 'AST'
|
|
35
|
+
Activity: 'ACT'
|
|
36
|
+
Organization: 'O'
|
package/config/test.yaml
ADDED
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Document } from '../src';
|
|
2
|
+
import { type ActivityAttributes } from './ActivityAttributes';
|
|
3
|
+
import { type Context, type IndexOptions } from '@kravc/dos';
|
|
4
|
+
/** Activity document class. */
|
|
5
|
+
declare class Activity extends Document<ActivityAttributes> {
|
|
6
|
+
/** Returns index query and index name for parameters. */
|
|
7
|
+
static _getIndexQueryProps(context: Context, query: {
|
|
8
|
+
userId?: string;
|
|
9
|
+
endDate?: string;
|
|
10
|
+
startDate?: string;
|
|
11
|
+
operationId?: string;
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
}): {
|
|
14
|
+
indexName: string;
|
|
15
|
+
indexQuery: {
|
|
16
|
+
[x: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** Returns activities. */
|
|
20
|
+
static indexWithDateRange(context: Context, query?: {
|
|
21
|
+
userId?: string;
|
|
22
|
+
endDate?: string;
|
|
23
|
+
startDate?: string;
|
|
24
|
+
operationId?: string;
|
|
25
|
+
[x: string]: unknown;
|
|
26
|
+
}, options?: IndexOptions): Promise<{
|
|
27
|
+
limit: number;
|
|
28
|
+
count: number;
|
|
29
|
+
objects: Activity[];
|
|
30
|
+
lastEvaluatedKey?: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export default Activity;
|
|
34
|
+
//# sourceMappingURL=Activity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../example/Activity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAU,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAO,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAElE,+BAA+B;AAC/B,cAAM,QAAS,SAAQ,QAAQ,CAAC,kBAAkB,CAAC;IACjD,yDAAyD;IACzD,MAAM,CAAC,mBAAmB,CACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;;;;;;IAiEH,0BAA0B;WACb,kBAAkB,CAC7B,OAAO,EAAE,OAAO,EAChB,KAAK,GAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACjB,EACN,OAAO,GAAE,YAAiB;;;;;;CA4B7B;AAID,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
const ActivityAttributes_1 = require("./ActivityAttributes");
|
|
5
|
+
const dos_1 = require("@kravc/dos");
|
|
6
|
+
/** Activity document class. */
|
|
7
|
+
class Activity extends src_1.Document {
|
|
8
|
+
/** Returns index query and index name for parameters. */
|
|
9
|
+
static _getIndexQueryProps(context, query) {
|
|
10
|
+
const { userId, endDate, startDate, operationId, ...filterQuery } = query;
|
|
11
|
+
/** Returns query for a global secondary index. */
|
|
12
|
+
const getGlobalIndexQuery = (indexName, partitionScope) => {
|
|
13
|
+
const { sortKeyName, partitionKeyName, } = this.getGlobalIndexProps(indexName);
|
|
14
|
+
const indexQuery = {};
|
|
15
|
+
const organizationId = (0, dos_1.got)(context.identity, 'organizationId');
|
|
16
|
+
indexQuery[partitionKeyName] = `${organizationId}#${partitionScope}`;
|
|
17
|
+
if (startDate) {
|
|
18
|
+
indexQuery[`${sortKeyName}:${src_1.SortExpressionKey.GE}`] = `#${startDate}T00:00:00.000Z`;
|
|
19
|
+
}
|
|
20
|
+
if (endDate) {
|
|
21
|
+
indexQuery[`${sortKeyName}:${src_1.SortExpressionKey.LE}`] = `#${endDate}T23:59:99.999Z`;
|
|
22
|
+
}
|
|
23
|
+
return indexQuery;
|
|
24
|
+
};
|
|
25
|
+
if (userId) {
|
|
26
|
+
const indexName = 'gsi1';
|
|
27
|
+
const indexQuery = getGlobalIndexQuery(indexName, userId);
|
|
28
|
+
return { indexName, indexQuery: { ...indexQuery, ...filterQuery } };
|
|
29
|
+
}
|
|
30
|
+
if (operationId) {
|
|
31
|
+
const indexName = 'gsi2';
|
|
32
|
+
const indexQuery = getGlobalIndexQuery(indexName, operationId);
|
|
33
|
+
return { indexName, indexQuery: { ...indexQuery, ...filterQuery } };
|
|
34
|
+
}
|
|
35
|
+
const { indexName, sortKeyName } = this.getLocalIndexProps('lsi3');
|
|
36
|
+
const indexQuery = {};
|
|
37
|
+
if (startDate) {
|
|
38
|
+
indexQuery[`${sortKeyName}:${src_1.SortExpressionKey.GE}`] = `#${startDate}T00:00:00.000Z`;
|
|
39
|
+
}
|
|
40
|
+
if (endDate) {
|
|
41
|
+
indexQuery[`${sortKeyName}:${src_1.SortExpressionKey.LE}`] = `#${endDate}T23:59:99.999Z`;
|
|
42
|
+
}
|
|
43
|
+
return { indexName, indexQuery: { ...indexQuery, ...filterQuery } };
|
|
44
|
+
}
|
|
45
|
+
/** Returns activities. */
|
|
46
|
+
static async indexWithDateRange(context, query = {}, options = {}) {
|
|
47
|
+
const { userId, endDate, startDate, operationId, } = query;
|
|
48
|
+
if (userId) {
|
|
49
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query);
|
|
50
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
51
|
+
}
|
|
52
|
+
if (operationId) {
|
|
53
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query);
|
|
54
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
55
|
+
}
|
|
56
|
+
const hasDateRange = !!startDate || !!endDate;
|
|
57
|
+
if (hasDateRange) {
|
|
58
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query);
|
|
59
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
60
|
+
}
|
|
61
|
+
return this.index(context, query, options);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
Activity.schema = ActivityAttributes_1.schema;
|
|
65
|
+
exports.default = Activity;
|
|
66
|
+
//# sourceMappingURL=Activity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC;QAE9C,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,QAAQ,CAAC,MAAM,GAAG,2BAAM,CAAC;AAEzB,kBAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema } from '@kravc/schema';
|
|
2
|
+
import { DefaultAttributes } from '../src';
|
|
3
|
+
type Identity = {
|
|
4
|
+
sub: string;
|
|
5
|
+
email: string;
|
|
6
|
+
firstName: string;
|
|
7
|
+
lastName: string;
|
|
8
|
+
permissions: string[];
|
|
9
|
+
};
|
|
10
|
+
export interface ActivityAttributes extends DefaultAttributes {
|
|
11
|
+
operationId: string;
|
|
12
|
+
summaryTemplate: string;
|
|
13
|
+
parametersJson?: string;
|
|
14
|
+
resultDocumentJson?: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
traceId: string;
|
|
17
|
+
userAgent: string;
|
|
18
|
+
ipAddress: string;
|
|
19
|
+
identity?: Identity;
|
|
20
|
+
}
|
|
21
|
+
export declare const schema: Schema;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=ActivityAttributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivityAttributes.d.ts","sourceRoot":"","sources":["../../example/ActivityAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAE3C,KAAK,QAAQ,GAAG;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB,CAAA;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED,eAAO,MAAM,MAAM,QAgDD,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = void 0;
|
|
4
|
+
const schema_1 = require("@kravc/schema");
|
|
5
|
+
exports.schema = new schema_1.Schema({
|
|
6
|
+
operationId: {
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
summaryTemplate: {
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
parametersJson: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
},
|
|
15
|
+
resultDocumentJson: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
},
|
|
18
|
+
userId: {
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
traceId: {
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
userAgent: {
|
|
25
|
+
required: true
|
|
26
|
+
},
|
|
27
|
+
ipAddress: {
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
identity: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
sub: {
|
|
34
|
+
required: true
|
|
35
|
+
},
|
|
36
|
+
email: {
|
|
37
|
+
required: true
|
|
38
|
+
},
|
|
39
|
+
firstName: {
|
|
40
|
+
required: true
|
|
41
|
+
},
|
|
42
|
+
lastName: {
|
|
43
|
+
required: true
|
|
44
|
+
},
|
|
45
|
+
permissions: {
|
|
46
|
+
required: true,
|
|
47
|
+
items: {
|
|
48
|
+
type: 'string'
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, 'ActivityBody');
|
|
54
|
+
//# sourceMappingURL=ActivityAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivityAttributes.js","sourceRoot":"","sources":["../../example/ActivityAttributes.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AAuB1B,QAAA,MAAM,GAAG,IAAI,eAAM,CAAC;IAC/B,WAAW,EAAE;QACX,QAAQ,EAAE,IAAI;KACf;IACD,eAAe,EAAE;QACf,QAAQ,EAAE,IAAI;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,QAAQ;KACf;IACD,kBAAkB,EAAE;QAClB,IAAI,EAAE,QAAQ;KACf;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,IAAI;KACf;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,GAAG,EAAE;gBACH,QAAQ,EAAE,IAAI;aACf;YACD,KAAK,EAAE;gBACL,QAAQ,EAAE,IAAI;aACf;YACD,SAAS,EAAE;gBACT,QAAQ,EAAE,IAAI;aACf;YACD,QAAQ,EAAE;gBACR,QAAQ,EAAE,IAAI;aACf;YACD,WAAW,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;iBACf;aACF;SACF;KACF;CACF,EAAE,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AssetAttributes, AssetStatus } from './AssetAttributes';
|
|
2
|
+
import { Document } from '../src';
|
|
3
|
+
import { type Context, type QueryMap, type IndexOptions } from '@kravc/dos';
|
|
4
|
+
/** Asset document class. */
|
|
5
|
+
declare class Asset extends Document<AssetAttributes> {
|
|
6
|
+
/** Returns props for an index query. */
|
|
7
|
+
static _getIndexQueryProps(context: Context, query: {
|
|
8
|
+
createdBy?: string;
|
|
9
|
+
[x: string]: unknown;
|
|
10
|
+
}, status: AssetStatus): {
|
|
11
|
+
indexQuery: {
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
indexName: string;
|
|
15
|
+
};
|
|
16
|
+
/** Returns active assets. */
|
|
17
|
+
static indexActiveAssets(context: Context, query?: QueryMap, options?: IndexOptions): Promise<{
|
|
18
|
+
limit: number;
|
|
19
|
+
count: number;
|
|
20
|
+
objects: Asset[];
|
|
21
|
+
lastEvaluatedKey?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** Returns archived assets. */
|
|
24
|
+
static indexArchivedAssets(context: Context, query?: QueryMap, options?: IndexOptions): Promise<{
|
|
25
|
+
limit: number;
|
|
26
|
+
count: number;
|
|
27
|
+
objects: Asset[];
|
|
28
|
+
lastEvaluatedKey?: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** Archives an asset. */
|
|
31
|
+
static archive(context: Context, query: QueryMap): Promise<Asset>;
|
|
32
|
+
/** Unarchives the asset. */
|
|
33
|
+
static unarchive(context: Context, query: QueryMap): Promise<Asset>;
|
|
34
|
+
}
|
|
35
|
+
export default Asset;
|
|
36
|
+
//# sourceMappingURL=Asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Asset.d.ts","sourceRoot":"","sources":["../../example/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,WAAW,EAAU,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAoC,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAO,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjF,4BAA4B;AAC5B,cAAM,KAAM,SAAQ,QAAQ,CAAC,eAAe,CAAC;IAC3C,wCAAwC;IACxC,MAAM,CAAC,mBAAmB,CACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE;QACL,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,EACD,MAAM,EAAE,WAAW;;;;;;IA2BrB,6BAA6B;WAChB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE,QAAa,EAAE,OAAO,GAAE,YAAiB;;;;;;IAKjG,+BAA+B;WAClB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE,QAAa,EAAE,OAAO,GAAE,YAAiB;;;;;;IAKnG,yBAAyB;WACZ,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ;IAUtD,4BAA4B;WACf,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ;CASzD;AAID,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const AssetAttributes_1 = require("./AssetAttributes");
|
|
4
|
+
const src_1 = require("../src");
|
|
5
|
+
const dos_1 = require("@kravc/dos");
|
|
6
|
+
/** Asset document class. */
|
|
7
|
+
class Asset extends src_1.Document {
|
|
8
|
+
/** Returns props for an index query. */
|
|
9
|
+
static _getIndexQueryProps(context, query, status) {
|
|
10
|
+
const indexQuery = {};
|
|
11
|
+
let indexName = 'lsi2';
|
|
12
|
+
let sortKeyName = this.getLocalIndexSortKeyName(indexName);
|
|
13
|
+
const { createdBy, ...filterQuery } = query;
|
|
14
|
+
if (createdBy) {
|
|
15
|
+
indexName = 'gsi1';
|
|
16
|
+
sortKeyName = this.getGlobalIndexSortKeyName(indexName);
|
|
17
|
+
const organizationId = (0, dos_1.got)(context.identity, 'organizationId');
|
|
18
|
+
const partitionKeyName = this.getGlobalIndexPartitionKeyName(indexName);
|
|
19
|
+
indexQuery[partitionKeyName] = `${organizationId}#${createdBy}`;
|
|
20
|
+
}
|
|
21
|
+
indexQuery[`${sortKeyName}:${src_1.SortExpressionKey.BW}`] = `#${status}`;
|
|
22
|
+
return {
|
|
23
|
+
indexQuery: { ...indexQuery, ...filterQuery },
|
|
24
|
+
indexName,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Returns active assets. */
|
|
28
|
+
static async indexActiveAssets(context, query = {}, options = {}) {
|
|
29
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query, AssetAttributes_1.AssetStatus.ACTIVE);
|
|
30
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
31
|
+
}
|
|
32
|
+
/** Returns archived assets. */
|
|
33
|
+
static async indexArchivedAssets(context, query = {}, options = {}) {
|
|
34
|
+
const { indexQuery, indexName } = this._getIndexQueryProps(context, query, AssetAttributes_1.AssetStatus.ARCHIVED);
|
|
35
|
+
return this.index(context, indexQuery, { ...options, indexName });
|
|
36
|
+
}
|
|
37
|
+
/** Archives an asset. */
|
|
38
|
+
static async archive(context, query) {
|
|
39
|
+
query[`status:${src_1.ExpressionKey.NOT}`] = AssetAttributes_1.AssetStatus.ARCHIVED;
|
|
40
|
+
const mutation = {
|
|
41
|
+
status: AssetAttributes_1.AssetStatus.ARCHIVED,
|
|
42
|
+
};
|
|
43
|
+
return this.update(context, query, mutation);
|
|
44
|
+
}
|
|
45
|
+
/** Unarchives the asset. */
|
|
46
|
+
static async unarchive(context, query) {
|
|
47
|
+
query[`status:${src_1.ExpressionKey.NOT}`] = AssetAttributes_1.AssetStatus.ACTIVE;
|
|
48
|
+
const mutation = {
|
|
49
|
+
status: AssetAttributes_1.AssetStatus.ACTIVE,
|
|
50
|
+
};
|
|
51
|
+
return this.update(context, query, mutation);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
Asset.schema = AssetAttributes_1.schema;
|
|
55
|
+
exports.default = Asset;
|
|
56
|
+
//# sourceMappingURL=Asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Asset.js","sourceRoot":"","sources":["../../example/Asset.ts"],"names":[],"mappings":";;AAAA,uDAA8E;AAC9E,gCAAoE;AACpE,oCAAiF;AAEjF,4BAA4B;AAC5B,MAAM,KAAM,SAAQ,cAAyB;IAC3C,wCAAwC;IACxC,MAAM,CAAC,mBAAmB,CACxB,OAAgB,EAChB,KAGC,EACD,MAAmB;QAEnB,MAAM,UAAU,GAAG,EAA4B,CAAC;QAEhD,IAAI,SAAS,GAAG,MAAM,CAAC;QACvB,IAAI,WAAW,GAAG,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAE3D,MAAM,EAAE,SAAS,EAAE,GAAG,WAAW,EAAE,GAAG,KAAK,CAAC;QAE5C,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,GAAG,MAAM,CAAC;YACnB,WAAW,GAAG,IAAI,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC;Y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,KAAe;QACpD,KAAK,CAAC,UAAU,mBAAa,CAAC,GAAG,EAAE,CAAC,GAAG,6BAAW,CAAC,QAAQ,CAAC;QAE5D,MAAM,QAAQ,GAAG;YACf,MAAM,EAAE,6BAAW,CAAC,QAAQ;SAC7B,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED,4BAA4B;IAC5B,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAgB,EAAE,KAAe;QACtD,KAAK,CAAC,UAAU,mBAAa,CAAC,GAAG,EAAE,CAAC,GAAG,6BAAW,CAAC,MAAM,CAAC;QAE1D,MAAM,QAAQ,GAAG;YACf,MAAM,EAAE,6BAAW,CAAC,MAAM;SAC3B,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;CACF;AAED,KAAK,CAAC,MAAM,GAAG,wBAAM,CAAC;AAEtB,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from '@kravc/schema';
|
|
2
|
+
import { DefaultAttributes } from '../src';
|
|
3
|
+
export declare enum AssetType {
|
|
4
|
+
FILE = "FILE",
|
|
5
|
+
CONTENT = "CONTENT"
|
|
6
|
+
}
|
|
7
|
+
export declare enum AssetStatus {
|
|
8
|
+
ACTIVE = "ACTIVE",
|
|
9
|
+
ARCHIVED = "ARCHIVED"
|
|
10
|
+
}
|
|
11
|
+
export interface AssetAttributes extends DefaultAttributes {
|
|
12
|
+
name: string;
|
|
13
|
+
tags: string[];
|
|
14
|
+
folderId?: string;
|
|
15
|
+
type: AssetType;
|
|
16
|
+
status: AssetStatus;
|
|
17
|
+
content?: string;
|
|
18
|
+
file?: {
|
|
19
|
+
url: string;
|
|
20
|
+
size: number;
|
|
21
|
+
name: string;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
lastModifiedAt: string;
|
|
24
|
+
thumbnailUrl?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare const schema: Schema;
|
|
28
|
+
//# sourceMappingURL=AssetAttributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetAttributes.d.ts","sourceRoot":"","sources":["../../example/AssetAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAE3C,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,oBAAY,WAAW;IACrB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAA;CACF;AAED,eAAO,MAAM,MAAM,QAwDJ,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = exports.AssetStatus = exports.AssetType = void 0;
|
|
4
|
+
const schema_1 = require("@kravc/schema");
|
|
5
|
+
var AssetType;
|
|
6
|
+
(function (AssetType) {
|
|
7
|
+
AssetType["FILE"] = "FILE";
|
|
8
|
+
AssetType["CONTENT"] = "CONTENT";
|
|
9
|
+
})(AssetType || (exports.AssetType = AssetType = {}));
|
|
10
|
+
var AssetStatus;
|
|
11
|
+
(function (AssetStatus) {
|
|
12
|
+
AssetStatus["ACTIVE"] = "ACTIVE";
|
|
13
|
+
AssetStatus["ARCHIVED"] = "ARCHIVED";
|
|
14
|
+
})(AssetStatus || (exports.AssetStatus = AssetStatus = {}));
|
|
15
|
+
exports.schema = new schema_1.Schema({
|
|
16
|
+
name: {
|
|
17
|
+
required: true
|
|
18
|
+
},
|
|
19
|
+
tags: {
|
|
20
|
+
items: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
},
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
folderId: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
},
|
|
28
|
+
thumbnailUrl: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
format: 'url',
|
|
31
|
+
},
|
|
32
|
+
type: {
|
|
33
|
+
enum: [AssetType.FILE, AssetType.CONTENT],
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
status: {
|
|
37
|
+
enum: [AssetStatus.ACTIVE, AssetStatus.ARCHIVED],
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
content: {
|
|
41
|
+
type: 'string'
|
|
42
|
+
},
|
|
43
|
+
file: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
url: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
format: 'url',
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
size: {
|
|
52
|
+
type: 'integer',
|
|
53
|
+
min: 0,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
name: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
mimeType: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
required: true,
|
|
63
|
+
},
|
|
64
|
+
lastModifiedAt: {
|
|
65
|
+
type: 'string',
|
|
66
|
+
format: 'date-time',
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, 'AssetBody');
|
|
72
|
+
//# sourceMappingURL=AssetAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetAttributes.js","sourceRoot":"","sources":["../../example/AssetAttributes.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AAGvC,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,0BAAa,CAAA;IACb,gCAAmB,CAAA;AACrB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;AACvB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAmBY,QAAA,MAAM,GAAG,IAAI,eAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,QAAQ,EAAE,IAAI;KACf;IACD,IAAI,EAAE;QACJ,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;SACf;QACD,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,QAAQ;KACf;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,KAAK;KACd;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,CAAE,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAE;QAC3C,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,CAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAE;QAClD,QAAQ,EAAE,IAAI;KACf;IACD,OAAO,EAAE;QACP,IAAI,EAAE,QAAQ;KACf;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,GAAG,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,IAAI;aACf;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,GAAG,EAAE,CAAC;gBACN,QAAQ,EAAE,IAAI;aACf;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,cAAc,EAAE;gBACd,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,WAAW;gBACnB,QAAQ,EAAE,IAAI;aACf;SACF;KACF;CACF,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DocumentWithHashId } from '../src';
|
|
2
|
+
import { type QueryMap, type Context, type IndexAllOptions } from '@kravc/dos';
|
|
3
|
+
import { type OrganizationAttributes } from './OrganizationAttributes';
|
|
4
|
+
/** Organization document class. */
|
|
5
|
+
declare class Organization extends DocumentWithHashId<OrganizationAttributes> {
|
|
6
|
+
/** Returns a PLATFORM partition to save a document. */
|
|
7
|
+
static getPartition(): string;
|
|
8
|
+
/** Returns active assets. */
|
|
9
|
+
static listActiveOrganizations(context: Context, query?: QueryMap, options?: IndexAllOptions): Promise<{
|
|
10
|
+
count: number;
|
|
11
|
+
objects: Organization[];
|
|
12
|
+
}>;
|
|
13
|
+
/** Disables an organization. */
|
|
14
|
+
static disable(context: Context, query: QueryMap): Promise<Organization>;
|
|
15
|
+
/** Enables an organization. */
|
|
16
|
+
static enable(context: Context, query: QueryMap): Promise<Organization>;
|
|
17
|
+
}
|
|
18
|
+
export default Organization;
|
|
19
|
+
//# sourceMappingURL=Organization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Organization.d.ts","sourceRoot":"","sources":["../../example/Organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAoC,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAA8B,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAInG,mCAAmC;AACnC,cAAM,YAAa,SAAQ,kBAAkB,CAAC,sBAAsB,CAAC;IACnE,uDAAuD;IACvD,MAAM,CAAC,YAAY,IAAI,MAAM;IAI7B,6BAA6B;WAChB,uBAAuB,CAClC,OAAO,EAAE,OAAO,EAChB,KAAK,GAAE,QAAa,EACpB,OAAO,GAAE,eAAoB;;;;IAkB/B,gCAAgC;WACnB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ;IAUtD,+BAA+B;WAClB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ;CAStD;AAID,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
const OrganizationAttributes_1 = require("./OrganizationAttributes");
|
|
5
|
+
const PLATFORM_PARTITION = 'PLATFORM';
|
|
6
|
+
/** Organization document class. */
|
|
7
|
+
class Organization extends src_1.DocumentWithHashId {
|
|
8
|
+
/** Returns a PLATFORM partition to save a document. */
|
|
9
|
+
static getPartition() {
|
|
10
|
+
return PLATFORM_PARTITION;
|
|
11
|
+
}
|
|
12
|
+
/** Returns active assets. */
|
|
13
|
+
static async listActiveOrganizations(context, query = {}, options = {}) {
|
|
14
|
+
const status = OrganizationAttributes_1.OrganizationStatus.ACTIVE;
|
|
15
|
+
const { indexName, sortKeyName, partitionKeyName, } = this.getGlobalIndexProps('gsi1');
|
|
16
|
+
const indexQuery = {
|
|
17
|
+
[partitionKeyName]: PLATFORM_PARTITION,
|
|
18
|
+
[`${sortKeyName}:${src_1.SortExpressionKey.BW}`]: `#${status}`,
|
|
19
|
+
};
|
|
20
|
+
return this.indexAll(context, { ...query, ...indexQuery }, { ...options, indexName });
|
|
21
|
+
}
|
|
22
|
+
/** Disables an organization. */
|
|
23
|
+
static async disable(context, query) {
|
|
24
|
+
query[`status:${src_1.ExpressionKey.NOT}`] = OrganizationAttributes_1.OrganizationStatus.DISABLED;
|
|
25
|
+
const mutation = {
|
|
26
|
+
status: OrganizationAttributes_1.OrganizationStatus.DISABLED,
|
|
27
|
+
};
|
|
28
|
+
return this.update(context, query, mutation);
|
|
29
|
+
}
|
|
30
|
+
/** Enables an organization. */
|
|
31
|
+
static async enable(context, query) {
|
|
32
|
+
query[`status:${src_1.ExpressionKey.NOT}`] = OrganizationAttributes_1.OrganizationStatus.ACTIVE;
|
|
33
|
+
const mutation = {
|
|
34
|
+
status: OrganizationAttributes_1.OrganizationStatus.ACTIVE,
|
|
35
|
+
};
|
|
36
|
+
return this.update(context, query, mutation);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
;
|
|
40
|
+
Organization.schema = OrganizationAttributes_1.schema;
|
|
41
|
+
exports.default = Organization;
|
|
42
|
+
//# sourceMappingURL=Organization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Organization.js","sourceRoot":"","sources":["../../example/Organization.ts"],"names":[],"mappings":";;AAAA,gCAA8E;AAE9E,qEAAmG;AAEnG,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAEtC,mCAAmC;AACnC,MAAM,YAAa,SAAQ,wBAA0C;IACnE,uDAAuD;IACvD,MAAM,CAAC,YAAY;QACjB,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,6BAA6B;IAC7B,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAClC,OAAgB,EAChB,QAAkB,EAAE,EACpB,UAA2B,EAAE;QAE7B,MAAM,MAAM,GAAG,2CAAkB,CAAC,MAAM,CAAC;QAEzC,MAAM,EACJ,SAAS,EACT,WAAW,EACX,gBAAgB,GACjB,GAAG,IAAI,CA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us {
|
|
4
|
+
ACTIVE = "ACTIVE",
|
|
5
|
+
DISABLED = "DISABLED"
|
|
6
|
+
}
|
|
7
|
+
export interface OrganizationAttributes extends DefaultAttributes {
|
|
8
|
+
name: string;
|
|
9
|
+
status: OrganizationStatus;
|
|
10
|
+
number: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const schema: Schema;
|
|
13
|
+
//# sourceMappingURL=OrganizationAttributes.d.ts.map
|