electrodb 2.2.0 → 2.2.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 +5 -1
- package/index.d.ts +11 -7
- package/package.json +1 -1
- package/src/entity.js +1 -1
- package/src/schema.js +45 -17
package/README.md
CHANGED
|
@@ -132,6 +132,9 @@ tasks
|
|
|
132
132
|
- [CreatedAt and UpdatedAt Attributes](#createdat-and-updatedat-attributes)
|
|
133
133
|
- [Attribute Validation](#attribute-validation)
|
|
134
134
|
* [Indexes](#indexes)
|
|
135
|
+
+ [Index Types](#index-types)
|
|
136
|
+
- [Isolated Indexes](#isolated-indexes)
|
|
137
|
+
- [Clustered Indexes](#clustered-indexes)
|
|
135
138
|
+ [Indexes Without Sort Keys](#indexes-without-sort-keys)
|
|
136
139
|
+ [Indexes With Sort Keys](#indexes-with-sort-keys)
|
|
137
140
|
+ [Numeric Keys](#numeric-keys)
|
|
@@ -287,7 +290,8 @@ tasks
|
|
|
287
290
|
- [Electro CLI](#electro-cli)
|
|
288
291
|
- [Version 2 Migration](#version-2-migration)
|
|
289
292
|
* [New response format for all query methods.](#new-response-format-for-all-query-methods)
|
|
290
|
-
* [Unified
|
|
293
|
+
* [Unified pagination APIs](#unified-pagination-apis)
|
|
294
|
+
* [Pagination with a string cursor](#pagination-with-a-string-cursor)
|
|
291
295
|
- [Version 1 Migration](#version-1-migration)
|
|
292
296
|
* [New schema format/breaking key format change](#new-schema-format-breaking-key-format-change)
|
|
293
297
|
* [The renaming of index property Facets to Composite and Template](#the-renaming-of-index-property-facets-to-composite-and-template)
|
package/index.d.ts
CHANGED
|
@@ -723,7 +723,7 @@ export interface BatchWriteOperationOptions<A extends string, F extends string,
|
|
|
723
723
|
}
|
|
724
724
|
|
|
725
725
|
export interface SetRecordActionOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> {
|
|
726
|
-
go: UpdateRecordGo<
|
|
726
|
+
go: UpdateRecordGo<TableItem>;
|
|
727
727
|
params: ParamRecord<UpdateQueryParams>;
|
|
728
728
|
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
|
|
729
729
|
remove: SetRecord<A,F,C,S, Array<keyof SetItem<A,F,C,S>>,IndexCompositeAttributes,TableItem>;
|
|
@@ -987,7 +987,16 @@ export type ServiceQueryRecordsGo<ResponseType, Options = QueryOptions> = <T = R
|
|
|
987
987
|
|
|
988
988
|
export type QueryRecordsGo<ResponseType, Options = QueryOptions> = <T = ResponseType>(options?: Options) => Promise<{ data: T, cursor: string | null }>;
|
|
989
989
|
|
|
990
|
-
export type UpdateRecordGo<ResponseType
|
|
990
|
+
export type UpdateRecordGo<ResponseType> = <T = ResponseType, Options extends UpdateQueryOptions = UpdateQueryOptions>(options?: Options) =>
|
|
991
|
+
Options extends infer O
|
|
992
|
+
? 'response' extends keyof O
|
|
993
|
+
? O['response'] extends 'all_new'
|
|
994
|
+
? Promise<{data: T}>
|
|
995
|
+
: O['response'] extends 'all_old'
|
|
996
|
+
? Promise<{data: T}>
|
|
997
|
+
: Promise<{data: Partial<T>}>
|
|
998
|
+
: Promise<{data: Partial<T>}>
|
|
999
|
+
: never;
|
|
991
1000
|
|
|
992
1001
|
export type PutRecordGo<ResponseType, Options = QueryOptions> = <T = ResponseType>(options?: Options) => Promise<{ data: T }>;
|
|
993
1002
|
|
|
@@ -996,11 +1005,6 @@ export type DeleteRecordOperationGo<ResponseType, Options = QueryOptions> = <T =
|
|
|
996
1005
|
export type BatchWriteGo<ResponseType> = <O extends BulkOptions>(options?: O) =>
|
|
997
1006
|
Promise<{ unprocessed: ResponseType }>
|
|
998
1007
|
|
|
999
|
-
// export type PageRecord<ResponseType, CompositeAttributes> = (page?: (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null, options?: PaginationOptions) => Promise<[
|
|
1000
|
-
// (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
|
|
1001
|
-
// ResponseType
|
|
1002
|
-
// ]>;
|
|
1003
|
-
|
|
1004
1008
|
export type ParamRecord<Options = ParamOptions> = <P>(options?: Options) => P;
|
|
1005
1009
|
|
|
1006
1010
|
export class ElectroError extends Error {
|
package/package.json
CHANGED
package/src/entity.js
CHANGED
|
@@ -3037,7 +3037,7 @@ class Entity {
|
|
|
3037
3037
|
indexAccessPattern,
|
|
3038
3038
|
indexHasSubCollections,
|
|
3039
3039
|
} = this._normalizeIndexes(model.indexes);
|
|
3040
|
-
let schema = new Schema(model.attributes, facets, {client});
|
|
3040
|
+
let schema = new Schema(model.attributes, facets, {client, isRoot: true});
|
|
3041
3041
|
let filters = this._normalizeFilters(model.filters);
|
|
3042
3042
|
// todo: consider a rename
|
|
3043
3043
|
let prefixes = this._normalizeKeyFixings({service, entity, version, indexes, modelVersion, clusteredIndexes});
|
package/src/schema.js
CHANGED
|
@@ -524,15 +524,22 @@ class MapAttribute extends Attribute {
|
|
|
524
524
|
traverser: this.traverser
|
|
525
525
|
});
|
|
526
526
|
this.properties = properties;
|
|
527
|
+
this.isRoot = !!definition.isRoot;
|
|
527
528
|
this.get = this._makeGet(definition.get, properties);
|
|
528
529
|
this.set = this._makeSet(definition.set, properties);
|
|
529
530
|
}
|
|
530
531
|
|
|
531
532
|
_makeGet(get, properties) {
|
|
532
533
|
this._checkGetSet(get, "get");
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
534
|
+
const getter = get || ((val) => {
|
|
535
|
+
const isEmpty = !val || Object.keys(val).length === 0;
|
|
536
|
+
const isNotRequired = !this.required;
|
|
537
|
+
const isRoot = this.isRoot;
|
|
538
|
+
if (isEmpty && isRoot && !isNotRequired) {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
return val;
|
|
542
|
+
});
|
|
536
543
|
return (values, siblings) => {
|
|
537
544
|
const data = {};
|
|
538
545
|
|
|
@@ -541,6 +548,9 @@ class MapAttribute extends Attribute {
|
|
|
541
548
|
}
|
|
542
549
|
|
|
543
550
|
if (values === undefined) {
|
|
551
|
+
if (!get) {
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
544
554
|
return getter(data, siblings);
|
|
545
555
|
}
|
|
546
556
|
|
|
@@ -561,11 +571,23 @@ class MapAttribute extends Attribute {
|
|
|
561
571
|
|
|
562
572
|
_makeSet(set, properties) {
|
|
563
573
|
this._checkGetSet(set, "set");
|
|
564
|
-
const setter = set || ((
|
|
574
|
+
const setter = set || ((val) => {
|
|
575
|
+
const isEmpty = !val || Object.keys(val).length === 0;
|
|
576
|
+
const isNotRequired = !this.required;
|
|
577
|
+
const isRoot = this.isRoot;
|
|
578
|
+
if (isEmpty && isRoot && !isNotRequired) {
|
|
579
|
+
return undefined;
|
|
580
|
+
}
|
|
581
|
+
return val;
|
|
582
|
+
});
|
|
583
|
+
|
|
565
584
|
return (values, siblings) => {
|
|
566
585
|
const data = {};
|
|
567
586
|
if (values === undefined) {
|
|
568
|
-
|
|
587
|
+
if (!set) {
|
|
588
|
+
return undefined;
|
|
589
|
+
}
|
|
590
|
+
return setter(values, siblings);
|
|
569
591
|
}
|
|
570
592
|
for (const name of Object.keys(properties.attributes)) {
|
|
571
593
|
const attribute = properties.attributes[name];
|
|
@@ -624,18 +646,18 @@ class MapAttribute extends Attribute {
|
|
|
624
646
|
}
|
|
625
647
|
|
|
626
648
|
val(value) {
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
649
|
+
const incomingIsEmpty = value === undefined;
|
|
650
|
+
let fromDefault = false;
|
|
651
|
+
let data;
|
|
652
|
+
if (value === undefined) {
|
|
653
|
+
data = this.default();
|
|
654
|
+
if (data !== undefined) {
|
|
655
|
+
fromDefault = true;
|
|
631
656
|
}
|
|
632
|
-
|
|
657
|
+
} else {
|
|
658
|
+
data = value;
|
|
633
659
|
}
|
|
634
660
|
|
|
635
|
-
let data = value === undefined
|
|
636
|
-
? getValue(value)
|
|
637
|
-
: value;
|
|
638
|
-
|
|
639
661
|
const valueType = getValueType(data);
|
|
640
662
|
|
|
641
663
|
if (data === undefined) {
|
|
@@ -654,6 +676,10 @@ class MapAttribute extends Attribute {
|
|
|
654
676
|
}
|
|
655
677
|
}
|
|
656
678
|
|
|
679
|
+
if (Object.keys(response).length === 0 && !fromDefault && this.isRoot && !this.required && incomingIsEmpty) {
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
|
|
657
683
|
return response;
|
|
658
684
|
}
|
|
659
685
|
}
|
|
@@ -959,9 +985,9 @@ class SetAttribute extends Attribute {
|
|
|
959
985
|
}
|
|
960
986
|
|
|
961
987
|
class Schema {
|
|
962
|
-
constructor(properties = {}, facets = {}, {traverser = new AttributeTraverser(), client, parent} = {}) {
|
|
988
|
+
constructor(properties = {}, facets = {}, {traverser = new AttributeTraverser(), client, parent, isRoot} = {}) {
|
|
963
989
|
this._validateProperties(properties, parent);
|
|
964
|
-
let schema = Schema.normalizeAttributes(properties, facets, {traverser, client, parent});
|
|
990
|
+
let schema = Schema.normalizeAttributes(properties, facets, {traverser, client, parent, isRoot});
|
|
965
991
|
this.client = client;
|
|
966
992
|
this.attributes = schema.attributes;
|
|
967
993
|
this.enums = schema.enums;
|
|
@@ -972,9 +998,10 @@ class Schema {
|
|
|
972
998
|
this.requiredAttributes = schema.requiredAttributes;
|
|
973
999
|
this.translationForWatching = this._formatWatchTranslations(this.attributes);
|
|
974
1000
|
this.traverser = traverser;
|
|
1001
|
+
this.isRoot = !!isRoot;
|
|
975
1002
|
}
|
|
976
1003
|
|
|
977
|
-
static normalizeAttributes(attributes = {}, facets = {}, {traverser, client, parent} = {}) {
|
|
1004
|
+
static normalizeAttributes(attributes = {}, facets = {}, {traverser, client, parent, isRoot} = {}) {
|
|
978
1005
|
const attributeHasParent = !!parent;
|
|
979
1006
|
let invalidProperties = [];
|
|
980
1007
|
let normalized = {};
|
|
@@ -1073,6 +1100,7 @@ class Schema {
|
|
|
1073
1100
|
postfix,
|
|
1074
1101
|
traverser,
|
|
1075
1102
|
isKeyField,
|
|
1103
|
+
isRoot: !!isRoot,
|
|
1076
1104
|
label: attribute.label,
|
|
1077
1105
|
required: !!attribute.required,
|
|
1078
1106
|
default: attribute.default,
|