@axi-engine/fields 0.3.7 → 0.3.8
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/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +7 -14
- package/dist/index.mjs +9 -16
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _axi_engine_utils from '@axi-engine/utils';
|
|
2
|
-
import { Subscribable,
|
|
2
|
+
import { Subscribable, Registry, Constructor, Emitter, PathType, DataStorage } from '@axi-engine/utils';
|
|
3
3
|
|
|
4
4
|
interface Policy<T> {
|
|
5
5
|
readonly id: string;
|
|
@@ -107,7 +107,7 @@ interface StringField extends Field<string> {
|
|
|
107
107
|
clear(): void;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
declare class FieldRegistry extends
|
|
110
|
+
declare class FieldRegistry extends Registry<string, Constructor<Field<any>>> {
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
@@ -583,9 +583,8 @@ interface PolicySerializerHandler<T extends Policy<any>, S extends object> {
|
|
|
583
583
|
hydrate(snapshotData: S): T;
|
|
584
584
|
}
|
|
585
585
|
declare class PolicySerializer {
|
|
586
|
-
|
|
587
|
-
register(policyId: string, handler: PolicySerializerHandler<any, any>):
|
|
588
|
-
clearHandlers(): void;
|
|
586
|
+
handlers: Registry<string, PolicySerializerHandler<any, any>>;
|
|
587
|
+
register(policyId: string, handler: PolicySerializerHandler<any, any>): void;
|
|
589
588
|
/**
|
|
590
589
|
* Creates a serializable snapshot of a policy instance.
|
|
591
590
|
* The snapshot includes the policy's state and a `__type` identifier.
|
|
@@ -648,6 +647,7 @@ interface FieldSnapshot {
|
|
|
648
647
|
value: any;
|
|
649
648
|
policies?: object[];
|
|
650
649
|
}
|
|
650
|
+
|
|
651
651
|
/**
|
|
652
652
|
* Orchestrates the serialization and deserialization of Field instances.
|
|
653
653
|
*
|
|
@@ -695,6 +695,7 @@ interface FieldsSnapshot {
|
|
|
695
695
|
__type: string;
|
|
696
696
|
[fieldName: string]: FieldSnapshot | string;
|
|
697
697
|
}
|
|
698
|
+
|
|
698
699
|
/**
|
|
699
700
|
* Orchestrates the serialization and deserialization of `Fields` container instances.
|
|
700
701
|
*
|
|
@@ -747,6 +748,7 @@ interface FieldTreeSnapshot {
|
|
|
747
748
|
__type: string;
|
|
748
749
|
[fieldName: string]: FieldsSnapshot | FieldTreeSnapshot | string;
|
|
749
750
|
}
|
|
751
|
+
|
|
750
752
|
/**
|
|
751
753
|
* Orchestrates the recursive serialization and deserialization of `FieldTree` instances.
|
|
752
754
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _axi_engine_utils from '@axi-engine/utils';
|
|
2
|
-
import { Subscribable,
|
|
2
|
+
import { Subscribable, Registry, Constructor, Emitter, PathType, DataStorage } from '@axi-engine/utils';
|
|
3
3
|
|
|
4
4
|
interface Policy<T> {
|
|
5
5
|
readonly id: string;
|
|
@@ -107,7 +107,7 @@ interface StringField extends Field<string> {
|
|
|
107
107
|
clear(): void;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
declare class FieldRegistry extends
|
|
110
|
+
declare class FieldRegistry extends Registry<string, Constructor<Field<any>>> {
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
@@ -583,9 +583,8 @@ interface PolicySerializerHandler<T extends Policy<any>, S extends object> {
|
|
|
583
583
|
hydrate(snapshotData: S): T;
|
|
584
584
|
}
|
|
585
585
|
declare class PolicySerializer {
|
|
586
|
-
|
|
587
|
-
register(policyId: string, handler: PolicySerializerHandler<any, any>):
|
|
588
|
-
clearHandlers(): void;
|
|
586
|
+
handlers: Registry<string, PolicySerializerHandler<any, any>>;
|
|
587
|
+
register(policyId: string, handler: PolicySerializerHandler<any, any>): void;
|
|
589
588
|
/**
|
|
590
589
|
* Creates a serializable snapshot of a policy instance.
|
|
591
590
|
* The snapshot includes the policy's state and a `__type` identifier.
|
|
@@ -648,6 +647,7 @@ interface FieldSnapshot {
|
|
|
648
647
|
value: any;
|
|
649
648
|
policies?: object[];
|
|
650
649
|
}
|
|
650
|
+
|
|
651
651
|
/**
|
|
652
652
|
* Orchestrates the serialization and deserialization of Field instances.
|
|
653
653
|
*
|
|
@@ -695,6 +695,7 @@ interface FieldsSnapshot {
|
|
|
695
695
|
__type: string;
|
|
696
696
|
[fieldName: string]: FieldSnapshot | string;
|
|
697
697
|
}
|
|
698
|
+
|
|
698
699
|
/**
|
|
699
700
|
* Orchestrates the serialization and deserialization of `Fields` container instances.
|
|
700
701
|
*
|
|
@@ -747,6 +748,7 @@ interface FieldTreeSnapshot {
|
|
|
747
748
|
__type: string;
|
|
748
749
|
[fieldName: string]: FieldsSnapshot | FieldTreeSnapshot | string;
|
|
749
750
|
}
|
|
751
|
+
|
|
750
752
|
/**
|
|
751
753
|
* Orchestrates the recursive serialization and deserialization of `FieldTree` instances.
|
|
752
754
|
*
|
package/dist/index.js
CHANGED
|
@@ -351,7 +351,7 @@ var CoreNumericField = class _CoreNumericField extends CoreField {
|
|
|
351
351
|
|
|
352
352
|
// src/field-registry.ts
|
|
353
353
|
var import_utils3 = require("@axi-engine/utils");
|
|
354
|
-
var FieldRegistry = class extends import_utils3.
|
|
354
|
+
var FieldRegistry = class extends import_utils3.Registry {
|
|
355
355
|
};
|
|
356
356
|
|
|
357
357
|
// src/fields.ts
|
|
@@ -425,7 +425,7 @@ var Fields = class _Fields {
|
|
|
425
425
|
* @returns {T} The newly created `Field` instance.
|
|
426
426
|
*/
|
|
427
427
|
create(typeName, name, initialValue, options) {
|
|
428
|
-
const Ctor = this._fieldRegistry.
|
|
428
|
+
const Ctor = this._fieldRegistry.getOrThrow(typeName);
|
|
429
429
|
const field = new Ctor(name, initialValue, options);
|
|
430
430
|
this.add(field);
|
|
431
431
|
return field;
|
|
@@ -820,14 +820,9 @@ var ClampMinPolicySerializerHandler = class {
|
|
|
820
820
|
// src/serializer/policy-serializer.ts
|
|
821
821
|
var import_utils6 = require("@axi-engine/utils");
|
|
822
822
|
var PolicySerializer = class {
|
|
823
|
-
handlers =
|
|
823
|
+
handlers = new import_utils6.Registry();
|
|
824
824
|
register(policyId, handler) {
|
|
825
|
-
|
|
826
|
-
this.handlers.set(policyId, handler);
|
|
827
|
-
return this;
|
|
828
|
-
}
|
|
829
|
-
clearHandlers() {
|
|
830
|
-
this.handlers.clear();
|
|
825
|
+
this.handlers.register(policyId, handler);
|
|
831
826
|
}
|
|
832
827
|
/**
|
|
833
828
|
* Creates a serializable snapshot of a policy instance.
|
|
@@ -837,8 +832,7 @@ var PolicySerializer = class {
|
|
|
837
832
|
* @throws If no handler is registered for the policy's ID.
|
|
838
833
|
*/
|
|
839
834
|
snapshot(policy) {
|
|
840
|
-
const handler = this.handlers.
|
|
841
|
-
(0, import_utils6.throwIfEmpty)(handler, `No serializer handler registered for policy ID: '${policy.id}'`);
|
|
835
|
+
const handler = this.handlers.getOrThrow(policy.id);
|
|
842
836
|
const data = handler.snapshot(policy);
|
|
843
837
|
return {
|
|
844
838
|
__type: policy.id,
|
|
@@ -854,8 +848,7 @@ var PolicySerializer = class {
|
|
|
854
848
|
hydrate(snapshot) {
|
|
855
849
|
const typeId = snapshot?.__type;
|
|
856
850
|
(0, import_utils6.throwIfEmpty)(typeId, 'Invalid policy snapshot: missing "__type" identifier.');
|
|
857
|
-
const handler = this.handlers.
|
|
858
|
-
(0, import_utils6.throwIfEmpty)(handler, `No serializer handler registered for policy ID: '${typeId}'`);
|
|
851
|
+
const handler = this.handlers.getOrThrow(typeId);
|
|
859
852
|
const { __type, ...data } = snapshot;
|
|
860
853
|
return handler.hydrate(data);
|
|
861
854
|
}
|
|
@@ -903,7 +896,7 @@ var FieldSerializer = class {
|
|
|
903
896
|
hydrate(snapshot) {
|
|
904
897
|
const fieldType = snapshot.__type;
|
|
905
898
|
(0, import_utils7.throwIfEmpty)(fieldType, 'Invalid field snapshot: missing "__type" identifier.');
|
|
906
|
-
const Ctor = this.fieldRegistry.
|
|
899
|
+
const Ctor = this.fieldRegistry.getOrThrow(fieldType);
|
|
907
900
|
let policies;
|
|
908
901
|
if (!(0, import_utils7.isNullOrUndefined)(snapshot.policies)) {
|
|
909
902
|
policies = [];
|
package/dist/index.mjs
CHANGED
|
@@ -290,8 +290,8 @@ var CoreNumericField = class _CoreNumericField extends CoreField {
|
|
|
290
290
|
};
|
|
291
291
|
|
|
292
292
|
// src/field-registry.ts
|
|
293
|
-
import {
|
|
294
|
-
var FieldRegistry = class extends
|
|
293
|
+
import { Registry } from "@axi-engine/utils";
|
|
294
|
+
var FieldRegistry = class extends Registry {
|
|
295
295
|
};
|
|
296
296
|
|
|
297
297
|
// src/fields.ts
|
|
@@ -365,7 +365,7 @@ var Fields = class _Fields {
|
|
|
365
365
|
* @returns {T} The newly created `Field` instance.
|
|
366
366
|
*/
|
|
367
367
|
create(typeName, name, initialValue, options) {
|
|
368
|
-
const Ctor = this._fieldRegistry.
|
|
368
|
+
const Ctor = this._fieldRegistry.getOrThrow(typeName);
|
|
369
369
|
const field = new Ctor(name, initialValue, options);
|
|
370
370
|
this.add(field);
|
|
371
371
|
return field;
|
|
@@ -758,16 +758,11 @@ var ClampMinPolicySerializerHandler = class {
|
|
|
758
758
|
};
|
|
759
759
|
|
|
760
760
|
// src/serializer/policy-serializer.ts
|
|
761
|
-
import {
|
|
761
|
+
import { Registry as Registry2, throwIfEmpty as throwIfEmpty2 } from "@axi-engine/utils";
|
|
762
762
|
var PolicySerializer = class {
|
|
763
|
-
handlers =
|
|
763
|
+
handlers = new Registry2();
|
|
764
764
|
register(policyId, handler) {
|
|
765
|
-
|
|
766
|
-
this.handlers.set(policyId, handler);
|
|
767
|
-
return this;
|
|
768
|
-
}
|
|
769
|
-
clearHandlers() {
|
|
770
|
-
this.handlers.clear();
|
|
765
|
+
this.handlers.register(policyId, handler);
|
|
771
766
|
}
|
|
772
767
|
/**
|
|
773
768
|
* Creates a serializable snapshot of a policy instance.
|
|
@@ -777,8 +772,7 @@ var PolicySerializer = class {
|
|
|
777
772
|
* @throws If no handler is registered for the policy's ID.
|
|
778
773
|
*/
|
|
779
774
|
snapshot(policy) {
|
|
780
|
-
const handler = this.handlers.
|
|
781
|
-
throwIfEmpty2(handler, `No serializer handler registered for policy ID: '${policy.id}'`);
|
|
775
|
+
const handler = this.handlers.getOrThrow(policy.id);
|
|
782
776
|
const data = handler.snapshot(policy);
|
|
783
777
|
return {
|
|
784
778
|
__type: policy.id,
|
|
@@ -794,8 +788,7 @@ var PolicySerializer = class {
|
|
|
794
788
|
hydrate(snapshot) {
|
|
795
789
|
const typeId = snapshot?.__type;
|
|
796
790
|
throwIfEmpty2(typeId, 'Invalid policy snapshot: missing "__type" identifier.');
|
|
797
|
-
const handler = this.handlers.
|
|
798
|
-
throwIfEmpty2(handler, `No serializer handler registered for policy ID: '${typeId}'`);
|
|
791
|
+
const handler = this.handlers.getOrThrow(typeId);
|
|
799
792
|
const { __type, ...data } = snapshot;
|
|
800
793
|
return handler.hydrate(data);
|
|
801
794
|
}
|
|
@@ -843,7 +836,7 @@ var FieldSerializer = class {
|
|
|
843
836
|
hydrate(snapshot) {
|
|
844
837
|
const fieldType = snapshot.__type;
|
|
845
838
|
throwIfEmpty3(fieldType, 'Invalid field snapshot: missing "__type" identifier.');
|
|
846
|
-
const Ctor = this.fieldRegistry.
|
|
839
|
+
const Ctor = this.fieldRegistry.getOrThrow(fieldType);
|
|
847
840
|
let policies;
|
|
848
841
|
if (!isNullOrUndefined2(snapshot.policies)) {
|
|
849
842
|
policies = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axi-engine/fields",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "A compact, reactive state management library based on a tree of observable fields.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"dequal": "^2.0.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@axi-engine/utils": "^0.2.
|
|
39
|
+
"@axi-engine/utils": "^0.2.6"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@axi-engine/utils": "^0.2.
|
|
42
|
+
"@axi-engine/utils": "^0.2.6"
|
|
43
43
|
}
|
|
44
44
|
}
|