@kravc/dos-dynamodb 1.0.0-alpha.4 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Table/helpers/buildTableSchema.d.ts.map +1 -1
- package/dist/src/Table/helpers/buildTableSchema.js +12 -10
- package/dist/src/Table/helpers/buildTableSchema.js.map +1 -1
- package/package.json +1 -1
- package/src/Table/helpers/__tests__/buildTableSchema.test.ts +28 -8
- package/src/Table/helpers/buildTableSchema.ts +16 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTableSchema.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/buildTableSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"buildTableSchema.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/buildTableSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,0BAA0B,CAAC;AAmGlC,qDAAqD;AACrD,QAAA,MAAM,gBAAgB,GAAI,8FAMvB,YAAY,KAAG,gBAwCjB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -19,9 +19,7 @@ const getAttributeDefinitions = (primaryKey, localSecondaryIndexes, globalSecond
|
|
|
19
19
|
for (const globalIndexKey in globalSecondaryIndexes) {
|
|
20
20
|
const { partitionKey, sortKey } = globalSecondaryIndexes[globalIndexKey];
|
|
21
21
|
attributes.push(partitionKey);
|
|
22
|
-
|
|
23
|
-
attributes.push(sortKey);
|
|
24
|
-
}
|
|
22
|
+
attributes.push(sortKey);
|
|
25
23
|
}
|
|
26
24
|
attributes = (0, lodash_1.uniq)(attributes);
|
|
27
25
|
const AttributeDefinitions = attributes
|
|
@@ -39,13 +37,11 @@ const getSecondaryIndex = (IndexName, partitionKey, sortKey) => {
|
|
|
39
37
|
KeyType: 'HASH',
|
|
40
38
|
AttributeName: partitionKey
|
|
41
39
|
},
|
|
42
|
-
|
|
43
|
-
if (sortKey) {
|
|
44
|
-
KeySchema.push({
|
|
40
|
+
{
|
|
45
41
|
KeyType: 'RANGE',
|
|
46
42
|
AttributeName: sortKey
|
|
47
|
-
}
|
|
48
|
-
|
|
43
|
+
},
|
|
44
|
+
];
|
|
49
45
|
const index = {
|
|
50
46
|
IndexName,
|
|
51
47
|
KeySchema,
|
|
@@ -84,9 +80,15 @@ const buildTableSchema = ({ name: TableName, primaryKey, isLocalhost, localSecon
|
|
|
84
80
|
TableName,
|
|
85
81
|
KeySchema,
|
|
86
82
|
AttributeDefinitions,
|
|
87
|
-
LocalSecondaryIndexes,
|
|
88
|
-
GlobalSecondaryIndexes,
|
|
89
83
|
};
|
|
84
|
+
const hasLocalSecondaryIndexes = LocalSecondaryIndexes.length > 0;
|
|
85
|
+
if (hasLocalSecondaryIndexes) {
|
|
86
|
+
schema.LocalSecondaryIndexes = LocalSecondaryIndexes;
|
|
87
|
+
}
|
|
88
|
+
const hasGlobalSecondaryIndexes = GlobalSecondaryIndexes.length > 0;
|
|
89
|
+
if (hasGlobalSecondaryIndexes) {
|
|
90
|
+
schema.GlobalSecondaryIndexes = GlobalSecondaryIndexes;
|
|
91
|
+
}
|
|
90
92
|
/* istanbul ignore else */
|
|
91
93
|
if (isLocalhost) {
|
|
92
94
|
schema.ProvisionedThroughput = ProvisionedThroughput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTableSchema.js","sourceRoot":"","sources":["../../../../src/Table/helpers/buildTableSchema.ts"],"names":[],"mappings":";;AAAA,mCAA8B;AAQ9B,MAAM,qBAAqB,GAAG;IAC5B,iBAAiB,EAAE,CAAC;IACpB,kBAAkB,EAAE,CAAC;CACtB,C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AwB,EAAE,CAAC;QAC7B,MAAM,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACvD,CAAC;IAED,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAEpE,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;IACzD,CAAC;IAED,0BAA0B;IAC1B,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IAEvD,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAAC;IAEzC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,18 +2,38 @@ import getTableOptions from '../getTableOptions';
|
|
|
2
2
|
import buildTableSchema from '../buildTableSchema';
|
|
3
3
|
|
|
4
4
|
describe('buildTableSchema(tableOptions)', () => {
|
|
5
|
-
it('supports global secondary indexes without a sort key', () => {
|
|
5
|
+
// it('supports global secondary indexes without a sort key', () => {
|
|
6
|
+
// const tableOptions = getTableOptions('partition', 'id');
|
|
7
|
+
|
|
8
|
+
// tableOptions.globalSecondaryIndexes = [
|
|
9
|
+
// {
|
|
10
|
+
// name: 'gsiTest',
|
|
11
|
+
// partitionKey: 'gsiPartitionKey',
|
|
12
|
+
// }
|
|
13
|
+
// ];
|
|
14
|
+
|
|
15
|
+
// const tableSchema = buildTableSchema(tableOptions);
|
|
16
|
+
|
|
17
|
+
// expect(tableSchema.GlobalSecondaryIndexes).toHaveLength(1);
|
|
18
|
+
// });
|
|
19
|
+
|
|
20
|
+
it('supports no global secondary indexes', () => {
|
|
21
|
+
const tableOptions = getTableOptions('partition', 'id');
|
|
22
|
+
|
|
23
|
+
tableOptions.globalSecondaryIndexes = [];
|
|
24
|
+
|
|
25
|
+
const tableSchema = buildTableSchema(tableOptions);
|
|
26
|
+
|
|
27
|
+
expect(tableSchema.GlobalSecondaryIndexes).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('supports no local secondary indexes', () => {
|
|
6
31
|
const tableOptions = getTableOptions('partition', 'id');
|
|
7
32
|
|
|
8
|
-
tableOptions.
|
|
9
|
-
{
|
|
10
|
-
name: 'gsiTest',
|
|
11
|
-
partitionKey: 'gsiPartitionKey',
|
|
12
|
-
}
|
|
13
|
-
];
|
|
33
|
+
tableOptions.localSecondaryIndexes = [];
|
|
14
34
|
|
|
15
35
|
const tableSchema = buildTableSchema(tableOptions);
|
|
16
36
|
|
|
17
|
-
expect(tableSchema.
|
|
37
|
+
expect(tableSchema.LocalSecondaryIndexes).toBeUndefined();
|
|
18
38
|
});
|
|
19
39
|
});
|
|
@@ -35,10 +35,7 @@ const getAttributeDefinitions = (
|
|
|
35
35
|
const { partitionKey, sortKey } = globalSecondaryIndexes[globalIndexKey];
|
|
36
36
|
|
|
37
37
|
attributes.push(partitionKey);
|
|
38
|
-
|
|
39
|
-
if (sortKey) {
|
|
40
|
-
attributes.push(sortKey);
|
|
41
|
-
}
|
|
38
|
+
attributes.push(sortKey);
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
attributes = uniq(attributes);
|
|
@@ -64,14 +61,11 @@ const getSecondaryIndex = (
|
|
|
64
61
|
KeyType: 'HASH',
|
|
65
62
|
AttributeName: partitionKey
|
|
66
63
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (sortKey) {
|
|
70
|
-
KeySchema.push({
|
|
64
|
+
{
|
|
71
65
|
KeyType: 'RANGE',
|
|
72
66
|
AttributeName: sortKey
|
|
73
|
-
}
|
|
74
|
-
|
|
67
|
+
},
|
|
68
|
+
];
|
|
75
69
|
|
|
76
70
|
const index = {
|
|
77
71
|
IndexName,
|
|
@@ -132,10 +126,20 @@ const buildTableSchema = ({
|
|
|
132
126
|
TableName,
|
|
133
127
|
KeySchema,
|
|
134
128
|
AttributeDefinitions,
|
|
135
|
-
LocalSecondaryIndexes,
|
|
136
|
-
GlobalSecondaryIndexes,
|
|
137
129
|
} as CreateTableInput;
|
|
138
130
|
|
|
131
|
+
const hasLocalSecondaryIndexes = LocalSecondaryIndexes.length > 0;
|
|
132
|
+
|
|
133
|
+
if (hasLocalSecondaryIndexes) {
|
|
134
|
+
schema.LocalSecondaryIndexes = LocalSecondaryIndexes;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const hasGlobalSecondaryIndexes = GlobalSecondaryIndexes.length > 0;
|
|
138
|
+
|
|
139
|
+
if (hasGlobalSecondaryIndexes) {
|
|
140
|
+
schema.GlobalSecondaryIndexes = GlobalSecondaryIndexes;
|
|
141
|
+
}
|
|
142
|
+
|
|
139
143
|
/* istanbul ignore else */
|
|
140
144
|
if (isLocalhost) {
|
|
141
145
|
schema.ProvisionedThroughput = ProvisionedThroughput;
|