electrodb 2.12.0 → 2.12.2

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 CHANGED
@@ -46,10 +46,10 @@ _Please submit issues/feedback or reach out on Twitter [@tinkertamper](https://t
46
46
  - [**Easily Query Across Entities**](https://electrodb.dev/en/core-concepts/single-table-relationships) - Define "collections" to create powerful/idiomatic queries that return multiple entities in a single request.
47
47
  - [**Automatic Index Selection**](https://electrodb.dev/en/queries/find/) - Use `.find()` or `.match()` methods to dynamically and efficiently query based on defined sort key structures.
48
48
  - [**Simplified Pagination API**](https://electrodb.dev/en/queries/pagination/) - ElectroDB generates url safe cursors for pagination, allows for fine grain automated pagination, and supports async iteration.
49
- - [**TypeScript Support**](https://electrodb.dev/en/reference/typscript/) - Strong **TypeScript** support for both Entities and Services now in Beta.
49
+ - [**Strong TypeScript Inference**](https://electrodb.dev/en/reference/typescript/) - Strong **TypeScript** support for both Entities and Services now in Beta.
50
50
  - [**Query Directly via the Terminal**](https://github.com/tywalch/electrocli#query-taskapp) - Execute queries against your `Entities`, `Services`, `Models` directly from the command line.
51
51
  - [**Stand Up Rest Server for Entities**](https://github.com/tywalch/electrocli#query-taskapp) - Stand up a REST Server to interact with your `Entities`, `Services`, `Models` for easier prototyping.
52
- - [**Use with your existing tables**](https://electrodb.dev/en/core-concepts/use-electrodb-with-existing-table/) - ElectroDB simplifies building DocumentClient parameters, so you can use it with existing tables/data.
52
+ - [**Use with your existing tables**](https://electrodb.dev/en/recipes/use-electrodb-with-existing-table/) - ElectroDB simplifies building DocumentClient parameters, so you can use it with existing tables/data.
53
53
 
54
54
  ---
55
55
 
package/index.d.ts CHANGED
@@ -3914,51 +3914,53 @@ type PartialDefinedKeys<T> = {
3914
3914
  };
3915
3915
 
3916
3916
  export type ItemAttribute<A extends Attribute> =
3917
- A["type"] extends OpaquePrimitiveTypeName<infer T>
3918
- ? T
3919
- : A["type"] extends CustomAttributeTypeName<infer T>
3920
- ? T
3921
- : A["type"] extends infer R
3922
- ? R extends "string"
3923
- ? string
3924
- : R extends "number"
3925
- ? number
3926
- : R extends "boolean"
3927
- ? boolean
3928
- : R extends ReadonlyArray<infer E>
3929
- ? E
3930
- : R extends "map"
3931
- ? "properties" extends keyof A
3932
- ? {
3933
- [P in keyof A["properties"]]: A["properties"][P] extends infer M
3934
- ? M extends Attribute
3935
- ? ItemAttribute<M>
3936
- : never
3937
- : never;
3938
- }
3939
- : never
3940
- : R extends "list"
3941
- ? "items" extends keyof A
3942
- ? A["items"] extends infer I
3943
- ? I extends Attribute
3944
- ? Array<ItemAttribute<I>>
3917
+ A["type"] extends infer T
3918
+ ? T extends OpaquePrimitiveTypeName<infer OP>
3919
+ ? OP
3920
+ : T extends CustomAttributeTypeName<infer CA>
3921
+ ? CA
3922
+ : T extends infer R
3923
+ ? R extends "string"
3924
+ ? string
3925
+ : R extends "number"
3926
+ ? number
3927
+ : R extends "boolean"
3928
+ ? boolean
3929
+ : R extends ReadonlyArray<infer E>
3930
+ ? E
3931
+ : R extends "map"
3932
+ ? "properties" extends keyof A
3933
+ ? {
3934
+ [P in keyof A["properties"]]: A["properties"][P] extends infer M
3935
+ ? M extends Attribute
3936
+ ? ItemAttribute<M>
3937
+ : never
3938
+ : never;
3939
+ }
3940
+ : never
3941
+ : R extends "list"
3942
+ ? "items" extends keyof A
3943
+ ? A["items"] extends infer I
3944
+ ? I extends Attribute
3945
+ ? Array<ItemAttribute<I>>
3946
+ : never
3945
3947
  : never
3946
3948
  : never
3947
- : never
3948
- : R extends "set"
3949
- ? "items" extends keyof A
3950
- ? A["items"] extends infer I
3951
- ? I extends "string"
3952
- ? string[]
3953
- : I extends "number"
3954
- ? number[]
3955
- : I extends ReadonlyArray<infer ENUM>
3956
- ? ENUM[]
3949
+ : R extends "set"
3950
+ ? "items" extends keyof A
3951
+ ? A["items"] extends infer I
3952
+ ? I extends "string"
3953
+ ? string[]
3954
+ : I extends "number"
3955
+ ? number[]
3956
+ : I extends ReadonlyArray<infer ENUM>
3957
+ ? ENUM[]
3958
+ : never
3957
3959
  : never
3958
3960
  : never
3961
+ : R extends "any"
3962
+ ? any
3959
3963
  : never
3960
- : R extends "any"
3961
- ? any
3962
3964
  : never
3963
3965
  : never;
3964
3966
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrodb",
3
- "version": "2.12.0",
3
+ "version": "2.12.2",
4
4
  "description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/entity.js CHANGED
@@ -2211,30 +2211,61 @@ class Entity {
2211
2211
  let { pk, sk } = this._makeIndexKeys({
2212
2212
  index: indexBase,
2213
2213
  });
2214
+
2214
2215
  let keys = this._makeParameterKey(indexBase, pk, ...sk);
2216
+ // trim empty key values (this can occur when keys are defined by users)
2217
+ for (let key in keys) {
2218
+ if (keys[key] === undefined || keys[key] === '') {
2219
+ delete keys[key];
2220
+ }
2221
+ }
2222
+
2215
2223
  let keyExpressions = this._expressionAttributeBuilder(keys);
2216
- let params = {
2217
- TableName: this.getTableName(),
2218
- ExpressionAttributeNames: this._mergeExpressionsAttributes(
2224
+
2225
+ const expressionAttributeNames = this._mergeExpressionsAttributes(
2219
2226
  filter.getNames(),
2220
2227
  keyExpressions.ExpressionAttributeNames,
2221
- ),
2222
- ExpressionAttributeValues: this._mergeExpressionsAttributes(
2228
+ );
2229
+
2230
+ const expressionAttributeValues = this._mergeExpressionsAttributes(
2223
2231
  filter.getValues(),
2224
2232
  keyExpressions.ExpressionAttributeValues,
2225
- ),
2226
- FilterExpression: `begins_with(#${pkField}, :${pkField})`,
2233
+ );
2234
+
2235
+
2236
+ let params = {
2237
+ TableName: this.getTableName(),
2227
2238
  };
2228
2239
 
2240
+ if (Object.keys(expressionAttributeNames).length) {
2241
+ params['ExpressionAttributeNames'] = expressionAttributeNames;
2242
+ }
2243
+
2244
+ if (Object.keys(expressionAttributeValues).length) {
2245
+ params['ExpressionAttributeValues'] = expressionAttributeValues;
2246
+ }
2247
+
2248
+ let filterExpressions = [];
2249
+
2250
+ if (keys[pkField]) {
2251
+ filterExpressions.push(`begins_with(#${pkField}, :${pkField})`);
2252
+ }
2253
+
2229
2254
  if (hasSortKey) {
2230
2255
  let skField = this.model.indexes[accessPattern].sk.field;
2231
- params.FilterExpression = `${params.FilterExpression} AND begins_with(#${skField}, :${skField})`;
2256
+ if (keys[skField]) {
2257
+ filterExpressions.push(`begins_with(#${skField}, :${skField})`);
2258
+ }
2232
2259
  }
2260
+
2233
2261
  if (filter.build()) {
2234
- params.FilterExpression = `${
2235
- params.FilterExpression
2236
- } AND ${filter.build()}`;
2262
+ filterExpressions.push(filter.build());
2237
2263
  }
2264
+
2265
+ if (filterExpressions.length) {
2266
+ params.FilterExpression = filterExpressions.join(' AND ');
2267
+ }
2268
+
2238
2269
  return params;
2239
2270
  }
2240
2271
 
package/test.csv ADDED
@@ -0,0 +1,117 @@
1
+
2
+ > electrodb@2.12.1 local:exec
3
+ > LOCAL_DYNAMO_ENDPOINT='http://localhost:8000' ts-node ./test/debug.ts
4
+
5
+ kind, op, value, region, plan, datetime
6
+ item, value, $test_1#region_central-1#plan_base#datetime_1989-07-01, central-1, Base, 1989-07-01
7
+ item, value, $test_1#region_central-1#plan_base#datetime_2023-12-01, central-1, Base, 2023-12-01
8
+ item, value, $test_1#region_central-1#plan_base#datetime_2024-12-01, central-1, Base, 2024-12-01
9
+ item, value, $test_1#region_central-1#plan_pro#datetime_1989-07-01, central-1, Pro, 1989-07-01
10
+ item, value, $test_1#region_central-1#plan_pro#datetime_2023-12-01, central-1, Pro, 2023-12-01
11
+ item, value, $test_1#region_central-1#plan_pro#datetime_2024-12-01, central-1, Pro, 2024-12-01
12
+ item, value, $test_1#region_central-1#plan_proplus#datetime_1989-07-01, central-1, ProPlus, 1989-07-01
13
+ item, value, $test_1#region_central-1#plan_proplus#datetime_2023-12-01, central-1, ProPlus, 2023-12-01
14
+ item, value, $test_1#region_central-1#plan_proplus#datetime_2024-12-01, central-1, ProPlus, 2024-12-01
15
+ item, value, $test_1#region_central-1#plan_special#datetime_1989-07-01, central-1, Special, 1989-07-01
16
+ item, value, $test_1#region_central-1#plan_special#datetime_2023-12-01, central-1, Special, 2023-12-01
17
+ item, value, $test_1#region_central-1#plan_special#datetime_2024-12-01, central-1, Special, 2024-12-01
18
+ item, value, $test_1#region_east-1#plan_base#datetime_1989-07-01, east-1, Base, 1989-07-01
19
+ item, value, $test_1#region_east-1#plan_base#datetime_2023-12-01, east-1, Base, 2023-12-01
20
+ item, value, $test_1#region_east-1#plan_base#datetime_2024-12-01, east-1, Base, 2024-12-01
21
+ item, value, $test_1#region_east-1#plan_pro#datetime_1989-07-01, east-1, Pro, 1989-07-01
22
+ item, value, $test_1#region_east-1#plan_pro#datetime_2023-12-01, east-1, Pro, 2023-12-01
23
+ item, value, $test_1#region_east-1#plan_pro#datetime_2024-12-01, east-1, Pro, 2024-12-01
24
+ item, value, $test_1#region_east-1#plan_proplus#datetime_1989-07-01, east-1, ProPlus, 1989-07-01
25
+ item, value, $test_1#region_east-1#plan_proplus#datetime_2023-12-01, east-1, ProPlus, 2023-12-01
26
+ item, value, $test_1#region_east-1#plan_proplus#datetime_2024-12-01, east-1, ProPlus, 2024-12-01
27
+ item, value, $test_1#region_east-1#plan_special#datetime_1989-07-01, east-1, Special, 1989-07-01
28
+ item, value, $test_1#region_east-1#plan_special#datetime_2023-12-01, east-1, Special, 2023-12-01
29
+ item, value, $test_1#region_east-1#plan_special#datetime_2024-12-01, east-1, Special, 2024-12-01
30
+ item, value, $test_1#region_east-2#plan_base#datetime_1989-07-01, east-2, Base, 1989-07-01
31
+ item, value, $test_1#region_east-2#plan_base#datetime_2023-12-01, east-2, Base, 2023-12-01
32
+ item, value, $test_1#region_east-2#plan_base#datetime_2024-12-01, east-2, Base, 2024-12-01
33
+ item, value, $test_1#region_east-2#plan_pro#datetime_1989-07-01, east-2, Pro, 1989-07-01
34
+ item, value, $test_1#region_east-2#plan_pro#datetime_2023-12-01, east-2, Pro, 2023-12-01
35
+ item, value, $test_1#region_east-2#plan_pro#datetime_2024-12-01, east-2, Pro, 2024-12-01
36
+ item, value, $test_1#region_east-2#plan_proplus#datetime_1989-07-01, east-2, ProPlus, 1989-07-01
37
+ item, value, $test_1#region_east-2#plan_proplus#datetime_2023-12-01, east-2, ProPlus, 2023-12-01
38
+ item, value, $test_1#region_east-2#plan_proplus#datetime_2024-12-01, east-2, ProPlus, 2024-12-01
39
+ item, value, $test_1#region_east-2#plan_special#datetime_1989-07-01, east-2, Special, 1989-07-01
40
+ item, value, $test_1#region_east-2#plan_special#datetime_2023-12-01, east-2, Special, 2023-12-01
41
+ item, value, $test_1#region_east-2#plan_special#datetime_2024-12-01, east-2, Special, 2024-12-01
42
+ item, value, $test_1#region_west-1#plan_base#datetime_1989-07-01, west-1, Base, 1989-07-01
43
+ item, value, $test_1#region_west-1#plan_base#datetime_2023-12-01, west-1, Base, 2023-12-01
44
+ item, value, $test_1#region_west-1#plan_base#datetime_2024-12-01, west-1, Base, 2024-12-01
45
+ item, value, $test_1#region_west-1#plan_pro#datetime_1989-07-01, west-1, Pro, 1989-07-01
46
+ item, value, $test_1#region_west-1#plan_pro#datetime_2023-12-01, west-1, Pro, 2023-12-01
47
+ item, value, $test_1#region_west-1#plan_pro#datetime_2024-12-01, west-1, Pro, 2024-12-01
48
+ item, value, $test_1#region_west-1#plan_proplus#datetime_1989-07-01, west-1, ProPlus, 1989-07-01
49
+ item, value, $test_1#region_west-1#plan_proplus#datetime_2023-12-01, west-1, ProPlus, 2023-12-01
50
+ item, value, $test_1#region_west-1#plan_proplus#datetime_2024-12-01, west-1, ProPlus, 2024-12-01
51
+ item, value, $test_1#region_west-1#plan_special#datetime_1989-07-01, west-1, Special, 1989-07-01
52
+ item, value, $test_1#region_west-1#plan_special#datetime_2023-12-01, west-1, Special, 2023-12-01
53
+ item, value, $test_1#region_west-1#plan_special#datetime_2024-12-01, west-1, Special, 2024-12-01
54
+ partials, all, $test_1#region_, , ,
55
+ partials, begins, $test_1, , ,
56
+ partials, gt, $test_2, , ,
57
+ partials, gte, $test_1, , ,
58
+ partials, lt, $test_1, , ,
59
+ partials, lte, $test_2, , ,
60
+ partials, between_start, $test_1, , ,
61
+ partials, between_end, $test_2, , ,
62
+ partials, all, $test_1#region_east#plan_, east, ,
63
+ partials, begins, $test_1#region_east, east, ,
64
+ partials, gt, $test_1#region_easu, east, ,
65
+ partials, gte, $test_1#region_east, east, ,
66
+ partials, lt, $test_1#region_east, east, ,
67
+ partials, lte, $test_1#region_easu, east, ,
68
+ partials, between_start, $test_1#region_east, east, ,
69
+ partials, between_end, $test_1#region_easu, east, ,
70
+ partials, all, $test_1#region_east#plan_pro#datetime_, east, Pro,
71
+ partials, begins, $test_1#region_east#plan_pro, east, Pro,
72
+ partials, gt, $test_1#region_east#plan_prp, east, Pro,
73
+ partials, gte, $test_1#region_east#plan_pro, east, Pro,
74
+ partials, lt, $test_1#region_east#plan_pro, east, Pro,
75
+ partials, lte, $test_1#region_east#plan_prp, east, Pro,
76
+ partials, between_start, $test_1#region_east#plan_pro, east, Pro,
77
+ partials, between_end, $test_1#region_east#plan_prp, east, Pro,
78
+ partials, all, $test_1#region_east#plan_pro#datetime_2023-12-00, east, Pro, 2023-12-00
79
+ partials, begins, $test_1#region_east#plan_pro#datetime_2023-12-00, east, Pro, 2023-12-00
80
+ partials, gt, $test_1#region_east#plan_pro#datetime_2023-12-01, east, Pro, 2023-12-00
81
+ partials, gte, $test_1#region_east#plan_pro#datetime_2023-12-00, east, Pro, 2023-12-00
82
+ partials, lt, $test_1#region_east#plan_pro#datetime_2023-12-00, east, Pro, 2023-12-00
83
+ partials, lte, $test_1#region_east#plan_pro#datetime_2023-12-01, east, Pro, 2023-12-00
84
+ partials, between_start, $test_1#region_east#plan_pro#datetime_2023-12-00, east, Pro, 2023-12-00
85
+ partials, between_end, $test_1#region_east#plan_pro#datetime_2023-12-01, east, Pro, 2023-12-00
86
+ complete, all, $test_1#region_, , ,
87
+ complete, begins, $test_1, , ,
88
+ complete, gt, $test_2, , ,
89
+ complete, gte, $test_1, , ,
90
+ complete, lt, $test_1, , ,
91
+ complete, lte, $test_2, , ,
92
+ complete, between_start, $test_1, , ,
93
+ complete, between_end, $test_2, , ,
94
+ complete, all, $test_1#region_east-1#plan_, east-1, ,
95
+ complete, begins, $test_1#region_east-1, east-1, ,
96
+ complete, gt, $test_1#region_east-2, east-1, ,
97
+ complete, gte, $test_1#region_east-1, east-1, ,
98
+ complete, lt, $test_1#region_east-1, east-1, ,
99
+ complete, lte, $test_1#region_east-2, east-1, ,
100
+ complete, between_start, $test_1#region_east-1, east-1, ,
101
+ complete, between_end, $test_1#region_east-2, east-1, ,
102
+ complete, all, $test_1#region_east-1#plan_proplus#datetime_, east-1, ProPlus,
103
+ complete, begins, $test_1#region_east-1#plan_proplus, east-1, ProPlus,
104
+ complete, gt, $test_1#region_east-1#plan_proplut, east-1, ProPlus,
105
+ complete, gte, $test_1#region_east-1#plan_proplus, east-1, ProPlus,
106
+ complete, lt, $test_1#region_east-1#plan_proplus, east-1, ProPlus,
107
+ complete, lte, $test_1#region_east-1#plan_proplut, east-1, ProPlus,
108
+ complete, between_start, $test_1#region_east-1#plan_proplus, east-1, ProPlus,
109
+ complete, between_end, $test_1#region_east-1#plan_proplut, east-1, ProPlus,
110
+ complete, all, $test_1#region_east-1#plan_proplus#datetime_2023-12-01, east-1, ProPlus, 2023-12-01
111
+ complete, begins, $test_1#region_east-1#plan_proplus#datetime_2023-12-01, east-1, ProPlus, 2023-12-01
112
+ complete, gt, $test_1#region_east-1#plan_proplus#datetime_2023-12-02, east-1, ProPlus, 2023-12-01
113
+ complete, gte, $test_1#region_east-1#plan_proplus#datetime_2023-12-01, east-1, ProPlus, 2023-12-01
114
+ complete, lt, $test_1#region_east-1#plan_proplus#datetime_2023-12-01, east-1, ProPlus, 2023-12-01
115
+ complete, lte, $test_1#region_east-1#plan_proplus#datetime_2023-12-02, east-1, ProPlus, 2023-12-01
116
+ complete, between_start, $test_1#region_east-1#plan_proplus#datetime_2023-12-01, east-1, ProPlus, 2023-12-01
117
+ complete, between_end, $test_1#region_east-1#plan_proplus#datetime_2023-12-02, east-1, ProPlus, 2023-12-01