electrodb 1.10.2 → 1.12.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/README.md +97 -35
- package/index.d.ts +351 -100
- package/index.js +2 -1
- package/notes +45 -0
- package/output +106 -0
- package/package.json +8 -10
- package/src/clauses.js +20 -4
- package/src/client.js +2 -2
- package/src/entity.js +159 -9
- package/src/operations.js +7 -1
- package/src/schema.js +53 -14
- package/src/types.js +9 -0
- package/src/util.js +8 -0
- package/taskdata.json +1 -0
- package/typez.ts +1736 -0
- package/src/parse.js +0 -45
package/README.md
CHANGED
|
@@ -94,7 +94,6 @@ tasks
|
|
|
94
94
|
|
|
95
95
|
------------
|
|
96
96
|
|
|
97
|
-
## Table of Contents
|
|
98
97
|
- [ElectroDB](#electrodb)
|
|
99
98
|
* [Features](#features)
|
|
100
99
|
* [Table of Contents](#table-of-contents)
|
|
@@ -208,10 +207,10 @@ tasks
|
|
|
208
207
|
- [AWS DynamoDB Client](#aws-dynamodb-client)
|
|
209
208
|
* [V2 Client](#v2-client)
|
|
210
209
|
* [V3 Client](#v3-client)
|
|
210
|
+
- [Logging](#logging)
|
|
211
211
|
- [Events](#events)
|
|
212
212
|
* [Query Event](#query-event)
|
|
213
213
|
* [Results Event](#results-event)
|
|
214
|
-
- [Logging](#logging)
|
|
215
214
|
- [Listeners](#listeners)
|
|
216
215
|
- [Errors:](#errors-)
|
|
217
216
|
+ [No Client Defined On Model](#no-client-defined-on-model)
|
|
@@ -273,17 +272,19 @@ tasks
|
|
|
273
272
|
- [Stores will renewals for Q4](#stores-will-renewals-for-q4)
|
|
274
273
|
- [Spite-stores with release renewals this year](#spite-stores-with-release-renewals-this-year)
|
|
275
274
|
- [All Latte Larrys in a particular mall building](#all-latte-larrys-in-a-particular-mall-building)
|
|
276
|
-
- [
|
|
277
|
-
* [
|
|
278
|
-
* [
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
275
|
+
- [TypeScript](#typescript)
|
|
276
|
+
* [Custom Attributes](#custom-attributes)
|
|
277
|
+
* [Exported Types](#exported-types)
|
|
278
|
+
+ [EntityRecord Type](#entityrecord-type)
|
|
279
|
+
+ [EntityItem Type](#entityitem-type)
|
|
280
|
+
+ [CollectionItem Type](#collectionitem-type)
|
|
281
|
+
+ [CreateEntityItem Type](#createentityitem-type)
|
|
282
|
+
+ [UpdateEntityItem Type](#updateentityitem-type)
|
|
283
|
+
+ [UpdateAddEntityItem Type](#updateaddentityitem-type)
|
|
284
|
+
+ [UpdateSubtractEntityItem Type](#updatesubtractentityitem-type)
|
|
285
|
+
+ [UpdateAppendEntityItem Type](#updateappendentityitem-type)
|
|
286
|
+
+ [UpdateRemoveEntityItem Type](#updateremoveentityitem-type)
|
|
287
|
+
+ [UpdateDeleteEntityItem Type](#updatedeleteentityitem-type)
|
|
287
288
|
- [Using ElectroDB With Existing Data](#using-electrodb-with-existing-data)
|
|
288
289
|
- [Electro CLI](#electro-cli)
|
|
289
290
|
- [Version 1 Migration](#version-1-migration)
|
|
@@ -776,7 +777,7 @@ attributes: {
|
|
|
776
777
|
|
|
777
778
|
#### Set Attributes
|
|
778
779
|
|
|
779
|
-
The Set attribute is arguably DynamoDB's most powerful type. ElectroDB supports String and Number Sets using the `items` property set as either `"string"
|
|
780
|
+
The Set attribute is arguably DynamoDB's most powerful type. ElectroDB supports String and Number Sets using the `items` property set as either `"string"`, `"number"`, or an array of strings or numbers. When a ReadonlyArray is provided, ElectroDB will enforce those values as a finite list of acceptable values, similar to an [Enum Attribute](#enum-attributes)
|
|
780
781
|
|
|
781
782
|
In addition to having the same modeling benefits you get with other attributes, ElectroDB also simplifies the use of Sets by removing the need to use DynamoDB's special `createSet` class to work with Sets. ElectroDB Set Attributes accept Arrays, JavaScript native Sets, and objects from `createSet` as values. ElectroDB will manage the casting of values to a DynamoDB Set value prior to saving and ElectroDB will also convert Sets back to JavaScript arrays on retrieval.
|
|
782
783
|
|
|
@@ -791,6 +792,14 @@ attributes: {
|
|
|
791
792
|
myNumberSet: {
|
|
792
793
|
type: "set",
|
|
793
794
|
items: "number"
|
|
795
|
+
},
|
|
796
|
+
myEnumStringSet: {
|
|
797
|
+
type: "set",
|
|
798
|
+
items: ["RED", "GREEN", "BLUE"] as const // electrodb will only accept the included values "RED", "GREEN", and/or "BLUE"
|
|
799
|
+
},
|
|
800
|
+
myEnumNumberSet: {
|
|
801
|
+
type: "set",
|
|
802
|
+
items: [1, 2, 3] as const // electrodb will only accept the included values 1, 2, and/or 3
|
|
794
803
|
}
|
|
795
804
|
}
|
|
796
805
|
```
|
|
@@ -1097,17 +1106,17 @@ indexes: {
|
|
|
1097
1106
|
| Property | Type | Required | Description |
|
|
1098
1107
|
| -------------- | :------------------------------------: | :------: | ----------- |
|
|
1099
1108
|
| `pk` | `object` | yes | Configuration for the pk of that index or table
|
|
1100
|
-
| `pk.composite` | `string
|
|
1109
|
+
| `pk.composite` | `string[]` | yes | An array that represents the order in which attributes are concatenated to composite attributes the key (see [Composite Attributes](#composite-attributes) below for more on this functionality).
|
|
1101
1110
|
| `pk.template` | `string` | no | A string that represents the template in which attributes composed to form a key (see [Composite Attribute Templates](#composite-attribute-templates) below for more on this functionality).
|
|
1102
1111
|
| `pk.field` | `string` | yes | The name of the attribute as it exists in DynamoDB, if named differently in the schema attributes.
|
|
1103
|
-
| `pk.casing` | `default
|
|
1112
|
+
| `pk.casing` | `default`, `upper`, `lower`, `none` | no | Choose a case for ElectroDB to convert your keys to, to avoid casing pitfalls when querying data. Default: `lower`.
|
|
1104
1113
|
| `sk` | `object` | no | Configuration for the sk of that index or table
|
|
1105
|
-
| `sk.composite` | `string
|
|
1114
|
+
| `sk.composite` | `string[]` | no | Either an Array that represents the order in which attributes are concatenated to composite attributes the key, or a String for a composite attribute template. (see [Composite Attributes](#composite-attributes) below for more on this functionality).
|
|
1106
1115
|
| `sk.template` | `string` | no | A string that represents the template in which attributes composed to form a key (see [Composite Attribute Templates](#composite-attribute-templates) below for more on this functionality).
|
|
1107
1116
|
| `sk.field` | `string` | yes | The name of the attribute as it exists in DynamoDB, if named differently in the schema attributes.
|
|
1108
|
-
| `pk.casing` | `default
|
|
1117
|
+
| `pk.casing` | `default`, `upper`, `lower`, `none`, | no | Choose a case for ElectroDB to convert your keys to, to avoid casing pitfalls when querying data. Default: `lower`.
|
|
1109
1118
|
| `index` | `string` | no | Required when the `Index` defined is a *Secondary Index*; but is left blank for the table's primary index.
|
|
1110
|
-
| `collection` | `string
|
|
1119
|
+
| `collection` | `string`, `string[]` | no | Used when models are joined to a `Service`. When two entities share a `collection` on the same `index`, they can be queried with one request to DynamoDB. The name of the collection should represent what the query would return as a pseudo `Entity`. (see [Collections](#collections) below for more on this functionality).
|
|
1111
1120
|
|
|
1112
1121
|
### Indexes Without Sort Keys
|
|
1113
1122
|
When using indexes without Sort Keys, that should be expressed as an index *without* an `sk` property at all. Indexes without an `sk` cannot have a collection, see [Collections](#collections) for more detail.
|
|
@@ -1465,7 +1474,7 @@ When your attribute's name, or [`field` property](#expanded-syntax) on an attrib
|
|
|
1465
1474
|
}
|
|
1466
1475
|
```
|
|
1467
1476
|
|
|
1468
|
-
[](
|
|
1477
|
+
[](https://electrodb.fun/?#code/JYWwDg9gTgLgBAbwKIDsbBgTwL5wGZQQhwDkApgDZkDGMhAJgEYkDcAUG9RCgM7zAoAbmTTRMcALxwUZAO5xU6LAAoEbOHBAR6lAFyJ1GuCKWZ9AIkwQArlAD6JjJjsoAhiDLmANIY08yUILA1GQWVrZ2-oHBZC7unj5GcMJQPMDcFgCM5obYiXCuMHTAjNYwZDz6akmu1FzWaACS9FW+RlhgoXDmfFACAOY5SXltYAzWtABy1iCMAa1JGh1d5igzc1BDRti5+QI6AB4VC0Zj2hMwlQaLcGAA1ic3eMCULd219U303m1JXOAQNLlfQAbXMHxsX3MAF1fnARjceA9rjd8C8KG9zGd6BdprMAj9UXB-pAgV0wdjcesCbCbjthrk2HlEDBXIwqPoSCBMAAVNlUEjYACU7E43D4BTqkJgzUk7zqMAAtAAWACsAGYAAzmdhcXjwSlTalQOUAJk1msyooEwlEUEwhgAdGAyqpJZ8ZfQvLdxkb8SbhU7+hBlCKODaTGJHQBHawBB1JZ2+y6qCENT2BxPB0PsIA)
|
|
1469
1478
|
|
|
1470
1479
|
**Using `template`**
|
|
1471
1480
|
|
|
@@ -2607,9 +2616,10 @@ const formattedQueryResults = myEntity.parse(formattedQueryResults);
|
|
|
2607
2616
|
|
|
2608
2617
|
Parse also accepts an optional `options` object as a second argument (see the section [Query Options](#query-options) to learn more). Currently, the following query options are relevant to the `parse()` method:
|
|
2609
2618
|
|
|
2610
|
-
Option | Default
|
|
2611
|
-
----------------- :
|
|
2612
|
-
|
|
2619
|
+
Option | Type | Default | Notes
|
|
2620
|
+
----------------- : -------- : ------------------ | -----
|
|
2621
|
+
ignoreOwnership | boolean | `true` | This property defaults to `true` here, unlike elsewhere in the application when it defaults to `false`. You can overwrite the default here with your own preference.
|
|
2622
|
+
attributes | string[] | _(all attributes)_ | The `attributes` option allows you to specify a subset of attributes to return
|
|
2613
2623
|
|
|
2614
2624
|
# Building Queries
|
|
2615
2625
|
> For hands-on learners: the following example can be followed along with **and** executed on runkit: https://runkit.com/tywalch/electrodb-building-queries
|
|
@@ -4300,6 +4310,7 @@ By default, **ElectroDB** enables you to work with records as the names and prop
|
|
|
4300
4310
|
logger?: (event) => void;
|
|
4301
4311
|
listeners Array<(event) => void>;
|
|
4302
4312
|
preserveBatchOrder?: boolean;
|
|
4313
|
+
attributes?: string[];
|
|
4303
4314
|
};
|
|
4304
4315
|
```
|
|
4305
4316
|
|
|
@@ -4307,6 +4318,7 @@ Option | Default | Description
|
|
|
4307
4318
|
------------------ | :------------------: | -----------
|
|
4308
4319
|
params | `{}` | Properties added to this object will be merged onto the params sent to the document client. Any conflicts with **ElectroDB** will favor the params specified here.
|
|
4309
4320
|
table | _(from constructor)_ | Use a different table than the one defined in the [Service Options](#service-options)
|
|
4321
|
+
attributes | _(all attributes)_ | The `attributes` query option allows you to specify ProjectionExpression Attributes for your `get` or `query` operation. As of `1.11.0` only root attributes are allowed to be specified.
|
|
4310
4322
|
raw | `false` | Returns query results as they were returned by the docClient.
|
|
4311
4323
|
includeKeys | `false` | By default, **ElectroDB** does not return partition, sort, or global keys in its response.
|
|
4312
4324
|
pager | `"named"` | Used in with pagination (`.pages()`) calls to override ElectroDBs default behaviour to break apart `LastEvaluatedKeys` records into composite attributes. See more detail about this in the sections for [Pager Query Options](#pager-query-options).
|
|
@@ -5613,11 +5625,62 @@ let storeId = "LatteLarrys";
|
|
|
5613
5625
|
let stores = await StoreLocations.malls({mallId}).query({buildingId, storeId}).go();
|
|
5614
5626
|
```
|
|
5615
5627
|
|
|
5616
|
-
#
|
|
5628
|
+
# TypeScript
|
|
5629
|
+
ElectroDB using advanced dynamic typing techniques to automatically create types based on the configurations in your model. Changes to your model will automatically change the types returned by ElectroDB.
|
|
5630
|
+
|
|
5631
|
+
## Custom Attributes
|
|
5632
|
+
If you have a need for a custom attribute type (beyond those supported by ElectroDB) you can use the the export function `createCustomAttribute`. This function takes an attribute definition and allows you to specify a custom typed attribute with ElectroDB:
|
|
5633
|
+
|
|
5634
|
+
> _NOTE: creating a custom type, ElectroDB will enforce attribute constraints based on the attribute definition provided, but will yield typing control to the user. This may result in some mismatches between your typing and the constraints enforced by ElectroDB._
|
|
5635
|
+
|
|
5636
|
+
```typescript
|
|
5637
|
+
import { Entity, createCustomAttribute } from 'electrodb';
|
|
5638
|
+
|
|
5639
|
+
type PersonnelRole = {
|
|
5640
|
+
type: 'employee';
|
|
5641
|
+
startDate: string;
|
|
5642
|
+
endDate?: string;
|
|
5643
|
+
} | {
|
|
5644
|
+
type: 'contractor';
|
|
5645
|
+
contractStartDate: string;
|
|
5646
|
+
contractEndDate: string;
|
|
5647
|
+
};
|
|
5648
|
+
|
|
5649
|
+
const table = 'workplace_table';
|
|
5650
|
+
const person = new Entity({
|
|
5651
|
+
model: {
|
|
5652
|
+
entity: 'personnel',
|
|
5653
|
+
service: 'workplace',
|
|
5654
|
+
version: '1'
|
|
5655
|
+
},
|
|
5656
|
+
attributes: {
|
|
5657
|
+
id: {
|
|
5658
|
+
type: 'string'
|
|
5659
|
+
},
|
|
5660
|
+
role: createCustomAttribute<PersonnelRole>({
|
|
5661
|
+
required: true,
|
|
5662
|
+
}),
|
|
5663
|
+
},
|
|
5664
|
+
indexes: {
|
|
5665
|
+
record: {
|
|
5666
|
+
pk: {
|
|
5667
|
+
field: 'pk',
|
|
5668
|
+
compose: ['id']
|
|
5669
|
+
},
|
|
5670
|
+
sk: {
|
|
5671
|
+
field: 'sk',
|
|
5672
|
+
compose: [],
|
|
5673
|
+
}
|
|
5674
|
+
}
|
|
5675
|
+
}
|
|
5676
|
+
}, { table });
|
|
5677
|
+
```
|
|
5678
|
+
|
|
5679
|
+
## Exported Types
|
|
5617
5680
|
|
|
5618
5681
|
The following types are exported for easier use while using ElectroDB with TypeScript:
|
|
5619
5682
|
|
|
5620
|
-
|
|
5683
|
+
### EntityRecord Type
|
|
5621
5684
|
|
|
5622
5685
|
The EntityRecord type is an object containing every attribute an Entity's model.
|
|
5623
5686
|
|
|
@@ -5635,7 +5698,7 @@ _Use:_
|
|
|
5635
5698
|
type EntiySchema = EntityRecord<typeof MyEntity>
|
|
5636
5699
|
```
|
|
5637
5700
|
|
|
5638
|
-
|
|
5701
|
+
### EntityItem Type
|
|
5639
5702
|
|
|
5640
5703
|
This type represents an item as it is returned from a query. This is different from the `EntityRecord` in that this type reflects the `required`, `hidden`, `default`, etc properties defined on the attribute.
|
|
5641
5704
|
|
|
@@ -5654,7 +5717,7 @@ _Use:_
|
|
|
5654
5717
|
type Thing = EntityItem<typeof MyEntityInstance>;
|
|
5655
5718
|
```
|
|
5656
5719
|
|
|
5657
|
-
|
|
5720
|
+
### CollectionItem Type
|
|
5658
5721
|
|
|
5659
5722
|
This type represents the value returned from a collection query, and is similar to EntityItem.
|
|
5660
5723
|
|
|
@@ -5664,7 +5727,7 @@ _Use:_
|
|
|
5664
5727
|
type CollectionResults = CollectionItem<typeof MyServiceInstance, "collectionName">
|
|
5665
5728
|
```
|
|
5666
5729
|
|
|
5667
|
-
|
|
5730
|
+
### CreateEntityItem Type
|
|
5668
5731
|
|
|
5669
5732
|
This type represents an item that you would pass your entity's `put` or `create` method
|
|
5670
5733
|
|
|
@@ -5683,7 +5746,7 @@ _Use:_
|
|
|
5683
5746
|
type NewThing = CreateEntityItem<typeof MyEntityInstance>;
|
|
5684
5747
|
```
|
|
5685
5748
|
|
|
5686
|
-
|
|
5749
|
+
### UpdateEntityItem Type
|
|
5687
5750
|
|
|
5688
5751
|
This type represents an item that you would pass your entity's `set` method when using `create` or `update`.
|
|
5689
5752
|
|
|
@@ -5702,8 +5765,7 @@ _Use:_
|
|
|
5702
5765
|
type UpdateProperties = UpdateEntityItem<typeof MyEntityInstance>;
|
|
5703
5766
|
```
|
|
5704
5767
|
|
|
5705
|
-
|
|
5706
|
-
## UpdateAddEntityItem Type
|
|
5768
|
+
### UpdateAddEntityItem Type
|
|
5707
5769
|
|
|
5708
5770
|
This type represents an item that you would pass your entity's `add` method when using `create` or `update`.
|
|
5709
5771
|
|
|
@@ -5716,7 +5778,7 @@ export type UpdateAddEntityItem<E extends Entity<any, any, any, any>> =
|
|
|
5716
5778
|
|
|
5717
5779
|
`````
|
|
5718
5780
|
|
|
5719
|
-
|
|
5781
|
+
### UpdateSubtractEntityItem Type
|
|
5720
5782
|
|
|
5721
5783
|
This type represents an item that you would pass your entity's `subtract` method when using `create` or `update`.
|
|
5722
5784
|
|
|
@@ -5728,7 +5790,7 @@ export type UpdateSubtractEntityItem<E extends Entity<any, any, any, any>> =
|
|
|
5728
5790
|
: never;
|
|
5729
5791
|
```
|
|
5730
5792
|
|
|
5731
|
-
|
|
5793
|
+
### UpdateAppendEntityItem Type
|
|
5732
5794
|
|
|
5733
5795
|
This type represents an item that you would pass your entity's `append` method when using `create` or `update`.
|
|
5734
5796
|
|
|
@@ -5740,7 +5802,7 @@ export type UpdateAppendEntityItem<E extends Entity<any, any, any, any>> =
|
|
|
5740
5802
|
: never;
|
|
5741
5803
|
```
|
|
5742
5804
|
|
|
5743
|
-
|
|
5805
|
+
### UpdateRemoveEntityItem Type
|
|
5744
5806
|
|
|
5745
5807
|
This type represents an item that you would pass your entity's `remove` method when using `create` or `update`.
|
|
5746
5808
|
|
|
@@ -5752,7 +5814,7 @@ export type UpdateRemoveEntityItem<E extends Entity<any, any, any, any>> =
|
|
|
5752
5814
|
: never;
|
|
5753
5815
|
```
|
|
5754
5816
|
|
|
5755
|
-
|
|
5817
|
+
### UpdateDeleteEntityItem Type
|
|
5756
5818
|
|
|
5757
5819
|
This type represents an item that you would pass your entity's `delete` method when using `create` or `update`.
|
|
5758
5820
|
|