@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,87 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import type { QueryMap } from '@kravc/dos';
|
|
3
|
+
import { ExpressionKey } from './buildConditionExpression';
|
|
4
|
+
|
|
5
|
+
/** Ensures item matches condition expression built from a query. */
|
|
6
|
+
function filterConditionExpression<T>(item: T, query: QueryMap): T | undefined {
|
|
7
|
+
if (!item) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const conditionEntries = Object.entries(query);
|
|
12
|
+
|
|
13
|
+
for (const [key, value] of conditionEntries) {
|
|
14
|
+
const isNot = key.endsWith(`:${ExpressionKey.NOT}`);
|
|
15
|
+
const isContains = key.endsWith(`:${ExpressionKey.CONTAIN}`);
|
|
16
|
+
// const isLessThan = key.endsWith(':lt')
|
|
17
|
+
// const isGreaterThan = key.endsWith(':gt')
|
|
18
|
+
const isNotContains = key.endsWith(`:${ExpressionKey.EXCLUDE}`);
|
|
19
|
+
|
|
20
|
+
const isFilterValueArray = Array.isArray(value);
|
|
21
|
+
|
|
22
|
+
const isFilterValueNull = value === null;
|
|
23
|
+
|
|
24
|
+
let path = key;
|
|
25
|
+
/** Checks items are equal. */
|
|
26
|
+
let match = (a: unknown, b: unknown) => a === b;
|
|
27
|
+
|
|
28
|
+
if (isNot) {
|
|
29
|
+
path = key.replace(/:not/g, '');
|
|
30
|
+
|
|
31
|
+
/** Checks items are not equal. */
|
|
32
|
+
match = (a: unknown, b: unknown) => a !== b;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (isFilterValueNull) {
|
|
36
|
+
if (isNot) {
|
|
37
|
+
/** Checks item is not undefined. */
|
|
38
|
+
match = (a) => a !== undefined;
|
|
39
|
+
|
|
40
|
+
} else {
|
|
41
|
+
/** Checks item is undefined. */
|
|
42
|
+
match = (a) => a === undefined;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isContains) {
|
|
48
|
+
path = key.replace(/:contains/g, '');
|
|
49
|
+
|
|
50
|
+
/** Checks item includes value. */
|
|
51
|
+
match = (a: unknown, b: unknown) => (a as unknown[]).includes(b);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (isNotContains) {
|
|
55
|
+
path = key.replace(/:not_contains/g, '');
|
|
56
|
+
|
|
57
|
+
/** Checks item does not include value. */
|
|
58
|
+
match = (a: unknown, b: unknown) => !(a as unknown[]).includes(b);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (isFilterValueArray) {
|
|
62
|
+
/** Checks item is included in the array. */
|
|
63
|
+
match = (a: unknown, b: unknown) => (b as unknown[]).includes(a);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// if (isLessThan) {
|
|
67
|
+
// path = key.replace(/:lt/g, '')
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
// if (isGreaterThan) {
|
|
71
|
+
// path = key.replace(/:gt/g, '')
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
const itemValue = get(item, path);
|
|
75
|
+
const isMatched = match(itemValue, value);
|
|
76
|
+
|
|
77
|
+
if (isMatched) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return item;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default filterConditionExpression;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { homedir } from 'os';
|
|
2
|
+
import { fromIni } from '@aws-sdk/credential-providers';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { LOCAL_REGION } from './getTableOptions';
|
|
5
|
+
import { type DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
|
|
6
|
+
|
|
7
|
+
const HOME = homedir();
|
|
8
|
+
const hasAwsCredentials = existsSync(`${HOME}/.aws/credentials`);
|
|
9
|
+
|
|
10
|
+
const LOCAL_ENDPOINT = 'http://0.0.0.0:8000';
|
|
11
|
+
const DEFAULT_MAX_ATTEMPTS = 10;
|
|
12
|
+
|
|
13
|
+
/** Returns config for DynamoDB raw client. */
|
|
14
|
+
const getRawClientConfig = (region: string, profile: string): DynamoDBClientConfig => {
|
|
15
|
+
const config = {
|
|
16
|
+
maxAttempts: DEFAULT_MAX_ATTEMPTS,
|
|
17
|
+
region,
|
|
18
|
+
} as DynamoDBClientConfig;
|
|
19
|
+
|
|
20
|
+
const isLocal = region === LOCAL_REGION;
|
|
21
|
+
|
|
22
|
+
/* istanbul ignore else */
|
|
23
|
+
if (isLocal) {
|
|
24
|
+
config.endpoint = LOCAL_ENDPOINT;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* istanbul ignore else */
|
|
28
|
+
if (hasAwsCredentials) {
|
|
29
|
+
config.credentials = fromIni({ profile });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return config;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default getRawClientConfig;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import config from 'config';
|
|
2
|
+
import { got } from '@kravc/dos';
|
|
3
|
+
import { get } from 'lodash';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
|
|
7
|
+
export const LOCAL_REGION = 'local';
|
|
8
|
+
const PRIVATE_PROFILE = 'private';
|
|
9
|
+
|
|
10
|
+
export type LSI = {
|
|
11
|
+
name: string;
|
|
12
|
+
sortKey: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type GSI = {
|
|
16
|
+
name: string;
|
|
17
|
+
partitionKey: string;
|
|
18
|
+
sortKey: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type PrimaryKey = {
|
|
22
|
+
sortKey: string;
|
|
23
|
+
partitionKey: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type LocalIndexKeyComposer = { documentName: string, sk: string };
|
|
27
|
+
export type GlobalIndexKeyComposer = { pk: string, sk?: string };
|
|
28
|
+
|
|
29
|
+
type LocalIndexProps = {
|
|
30
|
+
indexName: string;
|
|
31
|
+
sortKeyName: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type GlobalIndexProps = {
|
|
35
|
+
indexName: string;
|
|
36
|
+
sortKeyName: string;
|
|
37
|
+
partitionKeyName: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type TableOptions = {
|
|
41
|
+
name: string;
|
|
42
|
+
region: string;
|
|
43
|
+
profile: string;
|
|
44
|
+
indexKeys: Record<string, LocalIndexKeyComposer | Record<string, GlobalIndexKeyComposer>>;
|
|
45
|
+
primaryKey: PrimaryKey;
|
|
46
|
+
isLocalhost: boolean;
|
|
47
|
+
localSecondaryIndexes: LSI[];
|
|
48
|
+
globalSecondaryIndexes: GSI[];
|
|
49
|
+
getLocalIndexSortKeyName: (indexName: string) => string;
|
|
50
|
+
getGlobalIndexPartitionKeyName: (indexName: string) => string;
|
|
51
|
+
getGlobalIndexSortKeyName: (indexName: string) => string;
|
|
52
|
+
isLocalSecondaryIndex: (indexName: string) => boolean;
|
|
53
|
+
getLocalIndexProps: (indexName: string) => LocalIndexProps;
|
|
54
|
+
getGlobalIndexProps: (indexName: string) => GlobalIndexProps;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Returns default table name. */
|
|
58
|
+
const getDefaultName = (): string => {
|
|
59
|
+
const ROOT_PATH = process.cwd();
|
|
60
|
+
const { NODE_APP_INSTANCE } = process.env;
|
|
61
|
+
|
|
62
|
+
const { name } = JSON.parse(
|
|
63
|
+
readFileSync(join(ROOT_PATH, 'package.json'), 'utf-8')
|
|
64
|
+
) as { name: string; };
|
|
65
|
+
|
|
66
|
+
const prefix = name.replace('@', '').replace('/', '-');
|
|
67
|
+
|
|
68
|
+
return [ prefix, NODE_APP_INSTANCE ].filter(value => !!value).join('-');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** Returns options for DynamoDB table creation. */
|
|
72
|
+
const getTableOptions = (partitionKey: string, sortKey: string): TableOptions => {
|
|
73
|
+
const tableConfig = config.get('dynamodb');
|
|
74
|
+
const tableOptions = JSON.parse(JSON.stringify(tableConfig)) as TableOptions;
|
|
75
|
+
|
|
76
|
+
const name = get(tableConfig, 'name', getDefaultName());
|
|
77
|
+
const indexKeys = get(tableConfig, 'indexKeys', {});
|
|
78
|
+
|
|
79
|
+
const region = get(config, 'aws.region', LOCAL_REGION);
|
|
80
|
+
const profile = get(config, 'aws.profile', PRIVATE_PROFILE);
|
|
81
|
+
|
|
82
|
+
const primaryKey = {
|
|
83
|
+
sortKey,
|
|
84
|
+
partitionKey,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
tableOptions.name = name;
|
|
88
|
+
tableOptions.region = region;
|
|
89
|
+
tableOptions.profile = profile;
|
|
90
|
+
tableOptions.indexKeys = indexKeys;
|
|
91
|
+
tableOptions.primaryKey = primaryKey;
|
|
92
|
+
tableOptions.isLocalhost = region === LOCAL_REGION;
|
|
93
|
+
|
|
94
|
+
tableOptions.localSecondaryIndexes = get(config, 'localSecondaryIndexes', [
|
|
95
|
+
{
|
|
96
|
+
name: 'lsi1',
|
|
97
|
+
sortKey: '_lsi1SortKey',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'lsi2',
|
|
101
|
+
sortKey: '_lsi2SortKey',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'lsi3',
|
|
105
|
+
sortKey: '_lsi3SortKey',
|
|
106
|
+
},
|
|
107
|
+
]) as LSI[];
|
|
108
|
+
|
|
109
|
+
tableOptions.globalSecondaryIndexes = get(config, 'globalSecondaryIndexes', [
|
|
110
|
+
{
|
|
111
|
+
name: 'gsi1',
|
|
112
|
+
partitionKey: '_gsi1PartitionKey',
|
|
113
|
+
sortKey: '_gsi1SortKey',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'gsi2',
|
|
117
|
+
partitionKey: '_gsi2PartitionKey',
|
|
118
|
+
sortKey: '_gsi2SortKey',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'gsi3',
|
|
122
|
+
partitionKey: '_gsi3PartitionKey',
|
|
123
|
+
sortKey: '_gsi3SortKey',
|
|
124
|
+
},
|
|
125
|
+
]) as GSI[];
|
|
126
|
+
|
|
127
|
+
/** Returns sort key name for a local secondary index. */
|
|
128
|
+
const getLocalIndexSortKeyName = (indexName: string): string => {
|
|
129
|
+
const { localSecondaryIndexes } = tableOptions;
|
|
130
|
+
|
|
131
|
+
const index = localSecondaryIndexes.find(({ name }) => name === indexName);
|
|
132
|
+
const indexesJson = JSON.stringify(localSecondaryIndexes, null, 2);
|
|
133
|
+
|
|
134
|
+
if (!index) {
|
|
135
|
+
throw new Error(`Local secondary index "${indexName}" is not defined, local indexes: ${indexesJson}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return got(index, 'sortKey') as string;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** Returns partition key name for a global secondary index. */
|
|
142
|
+
const getGlobalIndexPartitionKeyName = (indexName: string): string => {
|
|
143
|
+
const { globalSecondaryIndexes } = tableOptions;
|
|
144
|
+
|
|
145
|
+
const index = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
146
|
+
const indexesJson = JSON.stringify(globalSecondaryIndexes, null, 2);
|
|
147
|
+
|
|
148
|
+
if (!index) {
|
|
149
|
+
throw new Error(`Global secondary index "${indexName}" is not defined, global indexes: ${indexesJson}`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return got(index, 'partitionKey') as string;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/** Returns sort key name for a global secondary index. */
|
|
156
|
+
const getGlobalIndexSortKeyName = (indexName: string): string => {
|
|
157
|
+
const { globalSecondaryIndexes } = tableOptions;
|
|
158
|
+
|
|
159
|
+
const index = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
160
|
+
const indexesJson = JSON.stringify(globalSecondaryIndexes, null, 2);
|
|
161
|
+
|
|
162
|
+
if (!index) {
|
|
163
|
+
throw new Error(`Global secondary index "${indexName}" is not defined, global indexes: ${indexesJson}`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return got(index, 'sortKey') as string;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/** Returns true if local secondary index, false if global secondary index; throws if not found. */
|
|
170
|
+
const isLocalSecondaryIndex = (indexName: string): boolean => {
|
|
171
|
+
const {
|
|
172
|
+
localSecondaryIndexes,
|
|
173
|
+
globalSecondaryIndexes
|
|
174
|
+
} = tableOptions;
|
|
175
|
+
|
|
176
|
+
const lsi = localSecondaryIndexes.find(({ name }) => name === indexName);
|
|
177
|
+
|
|
178
|
+
if (lsi) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const gsi = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
183
|
+
|
|
184
|
+
if (gsi) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const indexesJson = JSON.stringify({ localSecondaryIndexes, globalSecondaryIndexes }, null, 2);
|
|
189
|
+
throw new Error(`Index "${indexName}" is not defined, indexes: ${indexesJson}`);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** Returns props for a local index by name. */
|
|
193
|
+
const getLocalIndexProps = (indexName: string): LocalIndexProps => {
|
|
194
|
+
isLocalSecondaryIndex(indexName);
|
|
195
|
+
|
|
196
|
+
const sortKeyName = getLocalIndexSortKeyName(indexName);
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
indexName,
|
|
200
|
+
sortKeyName,
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/** Returns props for a global index by name. */
|
|
205
|
+
const getGlobalIndexProps = (indexName: string): GlobalIndexProps => {
|
|
206
|
+
isLocalSecondaryIndex(indexName);
|
|
207
|
+
|
|
208
|
+
const sortKeyName = getGlobalIndexSortKeyName(indexName);
|
|
209
|
+
const partitionKeyName = getGlobalIndexPartitionKeyName(indexName);
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
indexName,
|
|
213
|
+
sortKeyName,
|
|
214
|
+
partitionKeyName,
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
tableOptions.getLocalIndexSortKeyName = getLocalIndexSortKeyName;
|
|
219
|
+
tableOptions.getGlobalIndexPartitionKeyName = getGlobalIndexPartitionKeyName;
|
|
220
|
+
tableOptions.getGlobalIndexSortKeyName = getGlobalIndexSortKeyName;
|
|
221
|
+
tableOptions.isLocalSecondaryIndex = isLocalSecondaryIndex;
|
|
222
|
+
tableOptions.getGlobalIndexProps = getGlobalIndexProps;
|
|
223
|
+
tableOptions.getLocalIndexProps = getLocalIndexProps;
|
|
224
|
+
|
|
225
|
+
return tableOptions;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export default getTableOptions;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
|
|
9
|
+
export {
|
|
10
|
+
getTableOptions,
|
|
11
|
+
buildTableSchema,
|
|
12
|
+
getRawClientConfig,
|
|
13
|
+
buildUpdateExpression,
|
|
14
|
+
buildQueryCommandInput,
|
|
15
|
+
buildConditionExpression,
|
|
16
|
+
filterConditionExpression,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type {
|
|
20
|
+
TableOptions,
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
6
|
+
export default Table;
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
ExpressionKey,
|
|
10
|
+
SortExpressionKey,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
TableOptions,
|
|
15
|
+
ItemAttributes,
|
|
16
|
+
LocalIndexKeyComposer,
|
|
17
|
+
GlobalIndexKeyComposer
|
|
18
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
|
|
6
|
+
export {
|
|
7
|
+
Document,
|
|
8
|
+
ExpressionKey,
|
|
9
|
+
SortExpressionKey,
|
|
10
|
+
DocumentWithHashId,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
DefaultAttributes,
|
|
15
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "./",
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"target": "esnext",
|
|
6
|
+
"module": "nodenext",
|
|
7
|
+
"isolatedModules": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"strictNullChecks": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"noUnusedParameters": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"declarationMap": true,
|
|
16
|
+
"sourceMap": true
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"dist",
|
|
24
|
+
"**/*.test.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|