electrodb 2.9.3 → 2.10.1
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/.prettierignore +112 -0
- package/.prettierrc +11 -0
- package/README.md +55 -47
- package/index.d.ts +5298 -2347
- package/index.js +24 -12
- package/package.json +20 -7
- package/src/clauses.js +1500 -1051
- package/src/client.js +255 -235
- package/src/entity.js +4518 -3730
- package/src/errors.js +39 -28
- package/src/events.js +26 -16
- package/src/filterOperations.js +124 -0
- package/src/filters.js +99 -101
- package/src/operations.js +347 -537
- package/src/schema.js +1825 -1473
- package/src/service.js +1081 -852
- package/src/set.js +22 -26
- package/src/transaction.js +179 -153
- package/src/types.js +263 -258
- package/src/update.js +94 -89
- package/src/updateOperations.js +197 -0
- package/src/util.js +45 -32
- package/src/validations.js +337 -325
- package/src/where.js +146 -124
- package/tsconfig.json +11 -11
package/src/set.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
const memberTypeToSetType = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
String: "String",
|
|
3
|
+
Number: "Number",
|
|
4
|
+
NumberValue: "Number",
|
|
5
|
+
Binary: "Binary",
|
|
6
|
+
string: "String",
|
|
7
|
+
number: "Number",
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
class DynamoDBSet {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
this.values = Array.from(new Set([].concat(list)));
|
|
11
|
+
constructor(list, type) {
|
|
12
|
+
this.wrapperName = "Set";
|
|
13
|
+
this.type = memberTypeToSetType[type];
|
|
14
|
+
if (this.type === undefined) {
|
|
15
|
+
new Error(`Invalid Set type: ${type}`);
|
|
18
16
|
}
|
|
17
|
+
this.values = Array.from(new Set([].concat(list)));
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
initialize(list, validate) {}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return memberTypeToSetType[typeof (this.values[0])];
|
|
26
|
-
}
|
|
22
|
+
detectType() {
|
|
23
|
+
return memberTypeToSetType[typeof this.values[0]];
|
|
24
|
+
}
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
validate() {}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return this.values;
|
|
34
|
-
}
|
|
28
|
+
toJSON() {
|
|
29
|
+
return this.values;
|
|
30
|
+
}
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
module.exports = {DynamoDBSet};
|
|
33
|
+
module.exports = { DynamoDBSet };
|
package/src/transaction.js
CHANGED
|
@@ -1,179 +1,205 @@
|
|
|
1
|
-
const { TableIndex, TransactionMethods } = require(
|
|
2
|
-
const { getEntityIdentifiers, matchToEntityAlias } = require(
|
|
3
|
-
|
|
4
|
-
function cleanseCanceledData(
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const { TableIndex, TransactionMethods } = require("./types");
|
|
2
|
+
const { getEntityIdentifiers, matchToEntityAlias } = require("./entity");
|
|
3
|
+
|
|
4
|
+
function cleanseCanceledData(
|
|
5
|
+
index = TableIndex,
|
|
6
|
+
entities,
|
|
7
|
+
data = {},
|
|
8
|
+
config = {},
|
|
9
|
+
) {
|
|
10
|
+
if (config.raw) {
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
const identifiers = getEntityIdentifiers(entities);
|
|
14
|
+
const canceled = data.canceled || [];
|
|
15
|
+
const paramItems = config._paramItems || [];
|
|
16
|
+
const results = [];
|
|
17
|
+
for (let i = 0; i < canceled.length; i++) {
|
|
18
|
+
const { Item, Code, Message } = canceled[i] || {};
|
|
19
|
+
const paramItem = paramItems[i];
|
|
20
|
+
const code = Code || "None";
|
|
21
|
+
const rejected = code !== "None";
|
|
22
|
+
const result = {
|
|
23
|
+
rejected,
|
|
24
|
+
code,
|
|
25
|
+
message: Message,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (Item) {
|
|
29
|
+
const entityAlias = matchToEntityAlias({
|
|
30
|
+
record: Item,
|
|
31
|
+
paramItem,
|
|
32
|
+
identifiers,
|
|
33
|
+
});
|
|
34
|
+
result.item = entities[entityAlias].formatResponse({ Item }, index, {
|
|
35
|
+
...config,
|
|
36
|
+
pager: false,
|
|
37
|
+
parse: undefined,
|
|
38
|
+
}).data;
|
|
39
|
+
} else {
|
|
40
|
+
result.item = null;
|
|
7
41
|
}
|
|
8
|
-
const identifiers = getEntityIdentifiers(entities);
|
|
9
|
-
const canceled = data.canceled || [];
|
|
10
|
-
const paramItems = config._paramItems || [];
|
|
11
|
-
const results = [];
|
|
12
|
-
for (let i = 0; i < canceled.length; i++) {
|
|
13
|
-
const { Item, Code, Message } = canceled[i] || {};
|
|
14
|
-
const paramItem = paramItems[i];
|
|
15
|
-
const code = Code || 'None';
|
|
16
|
-
const rejected = code !== 'None';
|
|
17
|
-
const result = {
|
|
18
|
-
rejected,
|
|
19
|
-
code,
|
|
20
|
-
message: Message,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (Item) {
|
|
24
|
-
const entityAlias = matchToEntityAlias({
|
|
25
|
-
record: Item,
|
|
26
|
-
paramItem,
|
|
27
|
-
identifiers
|
|
28
|
-
});
|
|
29
|
-
result.item = entities[entityAlias].formatResponse({Item}, index, {
|
|
30
|
-
...config,
|
|
31
|
-
pager: false,
|
|
32
|
-
parse: undefined,
|
|
33
|
-
}).data;
|
|
34
|
-
} else {
|
|
35
|
-
result.item = null;
|
|
36
|
-
}
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
results.push(result);
|
|
44
|
+
}
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
return results;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
|
-
function cleanseTransactionData(
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
function cleanseTransactionData(
|
|
50
|
+
index = TableIndex,
|
|
51
|
+
entities,
|
|
52
|
+
data = {},
|
|
53
|
+
config = {},
|
|
54
|
+
) {
|
|
55
|
+
if (config.raw) {
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
const identifiers = getEntityIdentifiers(entities);
|
|
59
|
+
data.Items = data.Items || [];
|
|
60
|
+
const paramItems = config._paramItems || [];
|
|
61
|
+
const results = [];
|
|
62
|
+
for (let i = 0; i < data.Items.length; i++) {
|
|
63
|
+
const record = data.Items[i];
|
|
64
|
+
if (!record) {
|
|
65
|
+
results.push(null);
|
|
66
|
+
continue;
|
|
47
67
|
}
|
|
48
|
-
const identifiers = getEntityIdentifiers(entities);
|
|
49
|
-
data.Items = data.Items || [];
|
|
50
|
-
const paramItems = config._paramItems || [];
|
|
51
|
-
const results = [];
|
|
52
|
-
for (let i = 0; i < data.Items.length; i++) {
|
|
53
|
-
const record = data.Items[i];
|
|
54
|
-
if (!record) {
|
|
55
|
-
results.push(null);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const paramItem = paramItems[i];
|
|
60
|
-
const entityAlias = matchToEntityAlias({paramItem, identifiers, record});
|
|
61
|
-
if (!entityAlias) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// pager=false because we don't want the entity trying to parse the lastEvaluatedKey
|
|
66
|
-
let formatted = entities[entityAlias].formatResponse({ Item: record }, index, {
|
|
67
|
-
...config,
|
|
68
|
-
pager: false,
|
|
69
|
-
parse: undefined
|
|
70
|
-
});
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
const paramItem = paramItems[i];
|
|
70
|
+
const entityAlias = matchToEntityAlias({ paramItem, identifiers, record });
|
|
71
|
+
if (!entityAlias) {
|
|
72
|
+
continue;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
// pager=false because we don't want the entity trying to parse the lastEvaluatedKey
|
|
76
|
+
let formatted = entities[entityAlias].formatResponse(
|
|
77
|
+
{ Item: record },
|
|
78
|
+
index,
|
|
79
|
+
{
|
|
80
|
+
...config,
|
|
81
|
+
pager: false,
|
|
82
|
+
parse: undefined,
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
results.push(formatted.data);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return results.map((item) => ({
|
|
90
|
+
rejected: false,
|
|
91
|
+
item,
|
|
92
|
+
}));
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
function createTransaction(options) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
96
|
+
const { fn, method, getEntities } = options;
|
|
97
|
+
const operations = {
|
|
98
|
+
params: (options = {}) => {
|
|
99
|
+
const paramItems = fn(getEntities());
|
|
100
|
+
const params = {
|
|
101
|
+
TransactItems: paramItems,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
if (typeof options.token === "string" && options.token.length) {
|
|
105
|
+
params["ClientRequestToken"] = options.token;
|
|
106
|
+
}
|
|
107
|
+
if (options._returnParamItems) {
|
|
108
|
+
return { params, paramItems };
|
|
109
|
+
}
|
|
110
|
+
return params;
|
|
111
|
+
},
|
|
112
|
+
go: async (options) => {
|
|
113
|
+
const driver = Object.values(getEntities())[0];
|
|
114
|
+
|
|
115
|
+
if (!driver) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
"At least one entity must exist to perform a transaction",
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const { params, paramItems } = operations.params({
|
|
122
|
+
...options,
|
|
123
|
+
_returnParamItems: true,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
let canceled = false;
|
|
127
|
+
if (paramItems.length === 0) {
|
|
128
|
+
return {
|
|
129
|
+
canceled,
|
|
130
|
+
data: [],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (options && options.logger) {
|
|
134
|
+
if (!options.listeners) {
|
|
135
|
+
options.listeners = [];
|
|
136
|
+
}
|
|
137
|
+
options.listeners.push(options.logger);
|
|
138
|
+
}
|
|
139
|
+
const response = await driver.go(method, params, {
|
|
140
|
+
...options,
|
|
141
|
+
parse: (options, data) => {
|
|
142
|
+
if (options.raw) {
|
|
143
|
+
return data;
|
|
144
|
+
} else if (data.canceled) {
|
|
145
|
+
canceled = true;
|
|
146
|
+
return cleanseCanceledData(TableIndex, getEntities(), data, {
|
|
147
|
+
...options,
|
|
148
|
+
_isTransaction: true,
|
|
149
|
+
_paramItems: paramItems,
|
|
108
150
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const response = await driver.go(method, params, {
|
|
151
|
+
} else if (data.Responses) {
|
|
152
|
+
return cleanseTransactionData(
|
|
153
|
+
TableIndex,
|
|
154
|
+
getEntities(),
|
|
155
|
+
{
|
|
156
|
+
Items: data.Responses.map((response) => response.Item),
|
|
157
|
+
},
|
|
158
|
+
{
|
|
119
159
|
...options,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
} else if (data.Responses) {
|
|
131
|
-
return cleanseTransactionData(TableIndex, getEntities(), {
|
|
132
|
-
Items: data.Responses.map(response => response.Item)
|
|
133
|
-
}, {
|
|
134
|
-
...options,
|
|
135
|
-
_isTransaction: true,
|
|
136
|
-
_paramItems: paramItems,
|
|
137
|
-
});
|
|
138
|
-
} else {
|
|
139
|
-
return new Array(paramItems ? paramItems.length : 0).fill({
|
|
140
|
-
item: null,
|
|
141
|
-
code: 'None',
|
|
142
|
-
rejected: false,
|
|
143
|
-
message: undefined,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
160
|
+
_isTransaction: true,
|
|
161
|
+
_paramItems: paramItems,
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
return new Array(paramItems ? paramItems.length : 0).fill({
|
|
166
|
+
item: null,
|
|
167
|
+
code: "None",
|
|
168
|
+
rejected: false,
|
|
169
|
+
message: undefined,
|
|
147
170
|
});
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
});
|
|
148
174
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
175
|
+
return {
|
|
176
|
+
...response,
|
|
177
|
+
canceled,
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
};
|
|
155
181
|
|
|
156
|
-
|
|
182
|
+
return operations;
|
|
157
183
|
}
|
|
158
184
|
|
|
159
185
|
function createWriteTransaction(entities, fn) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
186
|
+
return createTransaction({
|
|
187
|
+
fn,
|
|
188
|
+
method: TransactionMethods.transactWrite,
|
|
189
|
+
getEntities: () => entities,
|
|
190
|
+
});
|
|
165
191
|
}
|
|
166
192
|
|
|
167
193
|
function createGetTransaction(entities, fn) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
194
|
+
return createTransaction({
|
|
195
|
+
fn,
|
|
196
|
+
method: TransactionMethods.transactGet,
|
|
197
|
+
getEntities: () => entities,
|
|
198
|
+
});
|
|
173
199
|
}
|
|
174
200
|
|
|
175
201
|
module.exports = {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
202
|
+
createTransaction,
|
|
203
|
+
createWriteTransaction,
|
|
204
|
+
createGetTransaction,
|
|
205
|
+
};
|