electrodb 3.6.2 → 3.7.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/index.d.ts +7 -6
- package/package.json +1 -1
- package/src/clauses.js +90 -59
- package/src/entity.js +445 -154
- package/src/errors.js +24 -12
- package/src/operations.js +3 -3
- package/src/service.js +28 -24
- package/src/types.js +3 -0
- package/src/validations.js +4 -7
- package/dist/index.test-d.js +0 -4043
- package/dist/index.test-d.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export type DocumentClient =
|
|
|
30
30
|
scan: DocumentClientMethod;
|
|
31
31
|
transactGet: DocumentClientMethod;
|
|
32
32
|
transactWrite: DocumentClientMethod;
|
|
33
|
+
query: DocumentClientMethod;
|
|
33
34
|
}
|
|
34
35
|
| {
|
|
35
36
|
send: (command: any) => Promise<any>;
|
|
@@ -3957,7 +3958,7 @@ export type NestedAttributes =
|
|
|
3957
3958
|
|
|
3958
3959
|
export interface IndexWithSortKey {
|
|
3959
3960
|
readonly sk: {
|
|
3960
|
-
readonly field
|
|
3961
|
+
readonly field?: string;
|
|
3961
3962
|
readonly composite: ReadonlyArray<string>;
|
|
3962
3963
|
readonly template?: string;
|
|
3963
3964
|
};
|
|
@@ -3988,19 +3989,19 @@ export interface Schema<A extends string, F extends string, C extends string, P
|
|
|
3988
3989
|
readonly projection?: "all" | "keys_only" | ReadonlyArray<P>;
|
|
3989
3990
|
readonly index?: string;
|
|
3990
3991
|
readonly scope?: string;
|
|
3991
|
-
readonly type?: "clustered" | "isolated";
|
|
3992
|
+
readonly type?: "clustered" | "isolated" | "composite";
|
|
3992
3993
|
readonly collection?: AccessPatternCollection<C>;
|
|
3993
3994
|
readonly condition?: (composite: Record<string, unknown>) => boolean;
|
|
3994
3995
|
readonly pk: {
|
|
3995
3996
|
readonly casing?: KeyCasingOption;
|
|
3996
|
-
readonly field
|
|
3997
|
+
readonly field?: string;
|
|
3997
3998
|
readonly composite: ReadonlyArray<F>;
|
|
3998
3999
|
readonly template?: string;
|
|
3999
4000
|
readonly cast?: KeyCastOption;
|
|
4000
4001
|
};
|
|
4001
4002
|
readonly sk?: {
|
|
4002
4003
|
readonly casing?: KeyCasingOption;
|
|
4003
|
-
readonly field
|
|
4004
|
+
readonly field?: string;
|
|
4004
4005
|
readonly composite: ReadonlyArray<F>;
|
|
4005
4006
|
readonly template?: string;
|
|
4006
4007
|
readonly cast?: KeyCastOption;
|
|
@@ -4084,7 +4085,7 @@ type ClusteredIndexNameMap<
|
|
|
4084
4085
|
C extends string,
|
|
4085
4086
|
S extends Schema<A, F, C>,
|
|
4086
4087
|
> = {
|
|
4087
|
-
[I in keyof S["indexes"] as S["indexes"][I] extends { type: "clustered" }
|
|
4088
|
+
[I in keyof S["indexes"] as S["indexes"][I] extends { type: "clustered" | "composite" }
|
|
4088
4089
|
? I
|
|
4089
4090
|
: never]: S["indexes"][I]["collection"] extends AccessPatternCollection<
|
|
4090
4091
|
infer Name
|
|
@@ -4101,7 +4102,7 @@ type IsolatedIndexNameMap<
|
|
|
4101
4102
|
C extends string,
|
|
4102
4103
|
S extends Schema<A, F, C>,
|
|
4103
4104
|
> = {
|
|
4104
|
-
[I in keyof S["indexes"] as S["indexes"][I] extends { type: "clustered" }
|
|
4105
|
+
[I in keyof S["indexes"] as S["indexes"][I] extends { type: "clustered" | "composite" }
|
|
4105
4106
|
? never
|
|
4106
4107
|
: I]: S["indexes"][I]["collection"] extends AccessPatternCollection<
|
|
4107
4108
|
infer Name
|
package/package.json
CHANGED
package/src/clauses.js
CHANGED
|
@@ -22,6 +22,72 @@ const v = require("./validations");
|
|
|
22
22
|
const e = require("./errors");
|
|
23
23
|
const u = require("./util");
|
|
24
24
|
|
|
25
|
+
function handleNonIsolatedCollection(
|
|
26
|
+
entity,
|
|
27
|
+
state,
|
|
28
|
+
collection = "",
|
|
29
|
+
facets /* istanbul ignore next */ = {},
|
|
30
|
+
) {
|
|
31
|
+
if (state.getError() !== null) {
|
|
32
|
+
return state;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const { pk, sk } = state.getCompositeAttributes();
|
|
36
|
+
return state
|
|
37
|
+
.setMethod(MethodTypes.query)
|
|
38
|
+
.setCollection(collection)
|
|
39
|
+
.setPK(entity._expectFacets(facets, pk))
|
|
40
|
+
.ifSK(() => {
|
|
41
|
+
const { composites, unused } = state.identifyCompositeAttributes(
|
|
42
|
+
facets,
|
|
43
|
+
sk,
|
|
44
|
+
pk,
|
|
45
|
+
);
|
|
46
|
+
state.setSK(composites);
|
|
47
|
+
state.beforeBuildParams(({ options, state }) => {
|
|
48
|
+
const accessPattern =
|
|
49
|
+
entity.model.translations.indexes.fromIndexToAccessPattern[
|
|
50
|
+
state.query.index
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
options.compare === ComparisonTypes.attributes ||
|
|
55
|
+
options.compare === ComparisonTypes.v2
|
|
56
|
+
) {
|
|
57
|
+
if (
|
|
58
|
+
!entity.model.indexes[accessPattern].sk.isFieldRef &&
|
|
59
|
+
sk.length > 1
|
|
60
|
+
) {
|
|
61
|
+
state.filterProperties(FilterOperationNames.eq, {
|
|
62
|
+
...unused,
|
|
63
|
+
...composites,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
.whenOptions(({ options, state }) => {
|
|
70
|
+
if (!options.ignoreOwnership && !state.getParams()) {
|
|
71
|
+
state.query.options.expressions.names = {
|
|
72
|
+
...state.query.options.expressions.names,
|
|
73
|
+
...state.query.options.identifiers.names,
|
|
74
|
+
};
|
|
75
|
+
state.query.options.expressions.values = {
|
|
76
|
+
...state.query.options.expressions.values,
|
|
77
|
+
...state.query.options.identifiers.values,
|
|
78
|
+
};
|
|
79
|
+
state.query.options.expressions.expression =
|
|
80
|
+
state.query.options.expressions.expression.length > 1
|
|
81
|
+
? `(${state.query.options.expressions.expression}) AND ${state.query.options.identifiers.expression}`
|
|
82
|
+
: `${state.query.options.identifiers.expression}`;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
} catch (err) {
|
|
86
|
+
state.setError(err);
|
|
87
|
+
return state;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
25
91
|
const methodChildren = {
|
|
26
92
|
upsert: [
|
|
27
93
|
"upsertSet",
|
|
@@ -86,6 +152,7 @@ let clauses = {
|
|
|
86
152
|
"scan",
|
|
87
153
|
"collection",
|
|
88
154
|
"clusteredCollection",
|
|
155
|
+
"compositeCollection",
|
|
89
156
|
"create",
|
|
90
157
|
"remove",
|
|
91
158
|
"patch",
|
|
@@ -94,6 +161,23 @@ let clauses = {
|
|
|
94
161
|
"batchGet",
|
|
95
162
|
],
|
|
96
163
|
},
|
|
164
|
+
compositeCollection: {
|
|
165
|
+
name: "compositeCollection",
|
|
166
|
+
action(
|
|
167
|
+
entity,
|
|
168
|
+
state,
|
|
169
|
+
collection = "",
|
|
170
|
+
facets /* istanbul ignore next */ = {},
|
|
171
|
+
) {
|
|
172
|
+
return handleNonIsolatedCollection(
|
|
173
|
+
entity,
|
|
174
|
+
state.setType(QueryTypes.composite_collection),
|
|
175
|
+
collection,
|
|
176
|
+
facets,
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
children: ["between", "gte", "gt", "lte", "lt", "begins", "params", "go"],
|
|
180
|
+
},
|
|
97
181
|
clusteredCollection: {
|
|
98
182
|
name: "clusteredCollection",
|
|
99
183
|
action(
|
|
@@ -102,65 +186,12 @@ let clauses = {
|
|
|
102
186
|
collection = "",
|
|
103
187
|
facets /* istanbul ignore next */ = {},
|
|
104
188
|
) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.setType(QueryTypes.clustered_collection)
|
|
112
|
-
.setMethod(MethodTypes.query)
|
|
113
|
-
.setCollection(collection)
|
|
114
|
-
.setPK(entity._expectFacets(facets, pk))
|
|
115
|
-
.ifSK(() => {
|
|
116
|
-
const { composites, unused } = state.identifyCompositeAttributes(
|
|
117
|
-
facets,
|
|
118
|
-
sk,
|
|
119
|
-
pk,
|
|
120
|
-
);
|
|
121
|
-
state.setSK(composites);
|
|
122
|
-
state.beforeBuildParams(({ options, state }) => {
|
|
123
|
-
const accessPattern =
|
|
124
|
-
entity.model.translations.indexes.fromIndexToAccessPattern[
|
|
125
|
-
state.query.index
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
options.compare === ComparisonTypes.attributes ||
|
|
130
|
-
options.compare === ComparisonTypes.v2
|
|
131
|
-
) {
|
|
132
|
-
if (
|
|
133
|
-
!entity.model.indexes[accessPattern].sk.isFieldRef &&
|
|
134
|
-
sk.length > 1
|
|
135
|
-
) {
|
|
136
|
-
state.filterProperties(FilterOperationNames.eq, {
|
|
137
|
-
...unused,
|
|
138
|
-
...composites,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
})
|
|
144
|
-
.whenOptions(({ options, state }) => {
|
|
145
|
-
if (!options.ignoreOwnership && !state.getParams()) {
|
|
146
|
-
state.query.options.expressions.names = {
|
|
147
|
-
...state.query.options.expressions.names,
|
|
148
|
-
...state.query.options.identifiers.names,
|
|
149
|
-
};
|
|
150
|
-
state.query.options.expressions.values = {
|
|
151
|
-
...state.query.options.expressions.values,
|
|
152
|
-
...state.query.options.identifiers.values,
|
|
153
|
-
};
|
|
154
|
-
state.query.options.expressions.expression =
|
|
155
|
-
state.query.options.expressions.expression.length > 1
|
|
156
|
-
? `(${state.query.options.expressions.expression}) AND ${state.query.options.identifiers.expression}`
|
|
157
|
-
: `${state.query.options.identifiers.expression}`;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
} catch (err) {
|
|
161
|
-
state.setError(err);
|
|
162
|
-
return state;
|
|
163
|
-
}
|
|
189
|
+
return handleNonIsolatedCollection(
|
|
190
|
+
entity,
|
|
191
|
+
state.setType(QueryTypes.clustered_collection),
|
|
192
|
+
collection,
|
|
193
|
+
facets,
|
|
194
|
+
);
|
|
164
195
|
},
|
|
165
196
|
children: ["between", "gte", "gt", "lte", "lt", "begins", "params", "go"],
|
|
166
197
|
},
|