@axi-engine/fields 0.3.3 → 0.3.4
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/core-field-tree-factory.d.ts +13 -0
- package/dist/core-field-tree-factory.d.ts.map +1 -0
- package/dist/core-field-tree-factory.js +14 -0
- package/dist/core-field-tree-factory.js.map +1 -0
- package/dist/core-field-tree.d.ts +5 -0
- package/dist/core-field-tree.d.ts.map +1 -0
- package/dist/core-field-tree.js +4 -0
- package/dist/core-field-tree.js.map +1 -0
- package/dist/core-fields-factory.d.ts +10 -0
- package/dist/core-fields-factory.d.ts.map +1 -0
- package/dist/core-fields-factory.js +14 -0
- package/dist/core-fields-factory.js.map +1 -0
- package/dist/core-fields.d.ts +47 -0
- package/dist/core-fields.d.ts.map +1 -0
- package/dist/core-fields.js +8 -0
- package/dist/core-fields.js.map +1 -0
- package/dist/data-store-field-resolver.d.ts +26 -0
- package/dist/data-store-field-resolver.d.ts.map +1 -0
- package/dist/data-store-field-resolver.js +21 -0
- package/dist/data-store-field-resolver.js.map +1 -0
- package/dist/data-store.d.ts +38 -0
- package/dist/data-store.d.ts.map +1 -0
- package/dist/data-store.js +141 -0
- package/dist/data-store.js.map +1 -0
- package/dist/field-definitions/core-boolean-field.d.ts +11 -0
- package/dist/field-definitions/core-boolean-field.d.ts.map +1 -0
- package/dist/field-definitions/core-boolean-field.js +13 -0
- package/dist/field-definitions/core-boolean-field.js.map +1 -0
- package/dist/field-definitions/core-field.d.ts +51 -0
- package/dist/field-definitions/core-field.d.ts.map +1 -0
- package/dist/field-definitions/core-field.js +74 -0
- package/dist/field-definitions/core-field.js.map +1 -0
- package/dist/field-definitions/core-numeric-field.d.ts +18 -0
- package/dist/field-definitions/core-numeric-field.d.ts.map +1 -0
- package/dist/field-definitions/core-numeric-field.js +45 -0
- package/dist/field-definitions/core-numeric-field.js.map +1 -0
- package/dist/field-definitions/core-string-field.d.ts +15 -0
- package/dist/field-definitions/core-string-field.d.ts.map +1 -0
- package/dist/field-definitions/core-string-field.js +27 -0
- package/dist/field-definitions/core-string-field.js.map +1 -0
- package/dist/field-definitions/index.d.ts +5 -0
- package/dist/field-definitions/index.d.ts.map +1 -0
- package/dist/field-definitions/index.js +5 -0
- package/dist/field-definitions/index.js.map +1 -0
- package/dist/field-registry.d.ts +5 -0
- package/dist/field-registry.d.ts.map +1 -0
- package/dist/field-registry.js +4 -0
- package/dist/field-registry.js.map +1 -0
- package/dist/field-tree-factory.d.ts +12 -0
- package/dist/field-tree-factory.d.ts.map +1 -0
- package/dist/field-tree-factory.js +2 -0
- package/dist/field-tree-factory.js.map +1 -0
- package/dist/field-tree.d.ts +171 -0
- package/dist/field-tree.d.ts.map +1 -0
- package/dist/field-tree.js +248 -0
- package/dist/field-tree.js.map +1 -0
- package/dist/field.d.ts +34 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +2 -0
- package/dist/field.js.map +1 -0
- package/dist/fields-factory.d.ts +5 -0
- package/dist/fields-factory.d.ts.map +1 -0
- package/dist/fields-factory.js +2 -0
- package/dist/fields-factory.js.map +1 -0
- package/dist/fields.d.ts +101 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +143 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.d.mts +794 -815
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1084 -1116
- package/dist/mixins/mixin-factory.d.ts +29 -0
- package/dist/mixins/mixin-factory.d.ts.map +1 -0
- package/dist/mixins/mixin-factory.js +32 -0
- package/dist/mixins/mixin-factory.js.map +1 -0
- package/dist/mixins/with-boolean-fields.mixin.d.ts +9 -0
- package/dist/mixins/with-boolean-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-boolean-fields.mixin.js +4 -0
- package/dist/mixins/with-boolean-fields.mixin.js.map +1 -0
- package/dist/mixins/with-default-generic-fields.mixin.d.ts +31 -0
- package/dist/mixins/with-default-generic-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-default-generic-fields.mixin.js +15 -0
- package/dist/mixins/with-default-generic-fields.mixin.js.map +1 -0
- package/dist/mixins/with-numeric-fields.mixin.d.ts +9 -0
- package/dist/mixins/with-numeric-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-numeric-fields.mixin.js +4 -0
- package/dist/mixins/with-numeric-fields.mixin.js.map +1 -0
- package/dist/mixins/with-string-fields.mixin.d.ts +9 -0
- package/dist/mixins/with-string-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-string-fields.mixin.js +4 -0
- package/dist/mixins/with-string-fields.mixin.js.map +1 -0
- package/dist/policies/clamp-max-policy.d.ts +11 -0
- package/dist/policies/clamp-max-policy.d.ts.map +1 -0
- package/dist/policies/clamp-max-policy.js +18 -0
- package/dist/policies/clamp-max-policy.js.map +1 -0
- package/dist/policies/clamp-min-policy.d.ts +11 -0
- package/dist/policies/clamp-min-policy.d.ts.map +1 -0
- package/dist/policies/clamp-min-policy.js +18 -0
- package/dist/policies/clamp-min-policy.js.map +1 -0
- package/dist/policies/clamp-policy.d.ts +12 -0
- package/dist/policies/clamp-policy.d.ts.map +1 -0
- package/dist/policies/clamp-policy.js +21 -0
- package/dist/policies/clamp-policy.js.map +1 -0
- package/dist/policies/index.d.ts +6 -0
- package/dist/policies/index.d.ts.map +1 -0
- package/dist/policies/index.js +6 -0
- package/dist/policies/index.js.map +1 -0
- package/dist/policies/policies.d.ts +38 -0
- package/dist/policies/policies.d.ts.map +1 -0
- package/dist/policies/policies.js +62 -0
- package/dist/policies/policies.js.map +1 -0
- package/dist/policies/policy.d.ts +6 -0
- package/dist/policies/policy.d.ts.map +1 -0
- package/dist/policies/policy.js +2 -0
- package/dist/policies/policy.js.map +1 -0
- package/dist/serializer/field-serializer.d.ts +52 -0
- package/dist/serializer/field-serializer.d.ts.map +1 -0
- package/dist/serializer/field-serializer.js +66 -0
- package/dist/serializer/field-serializer.js.map +1 -0
- package/dist/serializer/field-tree-serializer.d.ts +50 -0
- package/dist/serializer/field-tree-serializer.d.ts.map +1 -0
- package/dist/serializer/field-tree-serializer.js +68 -0
- package/dist/serializer/field-tree-serializer.js.map +1 -0
- package/dist/serializer/fields-serializer.d.ts +49 -0
- package/dist/serializer/fields-serializer.d.ts.map +1 -0
- package/dist/serializer/fields-serializer.js +57 -0
- package/dist/serializer/fields-serializer.js.map +1 -0
- package/dist/serializer/index.d.ts +8 -0
- package/dist/serializer/index.d.ts.map +1 -0
- package/dist/serializer/index.js +8 -0
- package/dist/serializer/index.js.map +1 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts +13 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts.map +1 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.js +10 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.js.map +1 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts +13 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts.map +1 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.js +10 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.js.map +1 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts +16 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts.map +1 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.js +10 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.js.map +1 -0
- package/dist/serializer/policy-serializer.d.ts +41 -0
- package/dist/serializer/policy-serializer.d.ts.map +1 -0
- package/dist/serializer/policy-serializer.js +43 -0
- package/dist/serializer/policy-serializer.js.map +1 -0
- package/dist/setup.d.ts +41 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +57 -0
- package/dist/setup.js.map +1 -0
- package/dist/store.d.ts +137 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +2 -0
- package/dist/store.js.map +1 -0
- package/package.json +44 -44
- package/dist/index.cjs +0 -1232
- package/dist/index.d.cts +0 -1018
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Constructor } from '@axi-engine/utils';
|
|
2
|
+
import { Field } from '../field';
|
|
3
|
+
import { Fields } from '../fields';
|
|
4
|
+
/**
|
|
5
|
+
* extract field type
|
|
6
|
+
*/
|
|
7
|
+
type GetValueType<TField extends Field<any>> = TField extends Field<infer U> ? U : any;
|
|
8
|
+
/**
|
|
9
|
+
* A mapped type that creates the method signatures for a typed mixin.
|
|
10
|
+
* e.g., createBoolean, upsetBoolean, getBoolean
|
|
11
|
+
*/
|
|
12
|
+
type TypedMethods<TCtor extends Constructor<Field<any>>, TBaseName extends string> = {
|
|
13
|
+
[K in `create${TBaseName}`]: (name: string, initialValue: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
|
|
14
|
+
} & {
|
|
15
|
+
[K in `upset${TBaseName}`]: (name: string, value: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
|
|
16
|
+
} & {
|
|
17
|
+
[K in `get${TBaseName}`]: (name: string) => InstanceType<TCtor>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A higher-order function that generates a mixin for a specific Field type.
|
|
21
|
+
* This factory removes the need to write boilerplate mixin code for every new field type.
|
|
22
|
+
*
|
|
23
|
+
* @param typeName The `typeName` of the Field to create (e.g., 'boolean', 'my-signal-field').
|
|
24
|
+
* @param baseMethodName The base name for the generated methods (e.g., 'Boolean', 'MySignal').
|
|
25
|
+
* @returns A fully functional, typed mixin.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createTypedMethodsMixin<TCtor extends Constructor<Field<any>>, TBaseName extends string>(typeName: string, baseMethodName: TBaseName): <TBase extends Constructor<Fields>>(Base: TBase) => Constructor<InstanceType<TBase> & TypedMethods<TCtor, TBaseName>>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=mixin-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin-factory.d.ts","sourceRoot":"","sources":["../../src/mixins/mixin-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AAEjC;;GAEG;AACH,KAAK,YAAY,CAAC,MAAM,SAAS,KAAK,CAAC,GAAG,CAAC,IAAI,MAAM,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAEvF;;;GAGG;AACH,KAAK,YAAY,CACf,KAAK,SAAS,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EACrC,SAAS,SAAS,MAAM,IACtB;KACD,CAAC,IAAI,SAAS,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,KAAK,CAAC;CAC/J,GAAG;KACD,CAAC,IAAI,QAAQ,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,KAAK,CAAC;CACvJ,GAAG;KACD,CAAC,IAAI,MAAM,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,YAAY,CAAC,KAAK,CAAC;CAChE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,SAAS,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EACrC,SAAS,SAAS,MAAM,EAExB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,SAAS,IAQR,KAAK,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,KAC7D,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAmBpE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A higher-order function that generates a mixin for a specific Field type.
|
|
3
|
+
* This factory removes the need to write boilerplate mixin code for every new field type.
|
|
4
|
+
*
|
|
5
|
+
* @param typeName The `typeName` of the Field to create (e.g., 'boolean', 'my-signal-field').
|
|
6
|
+
* @param baseMethodName The base name for the generated methods (e.g., 'Boolean', 'MySignal').
|
|
7
|
+
* @returns A fully functional, typed mixin.
|
|
8
|
+
*/
|
|
9
|
+
export function createTypedMethodsMixin(typeName, baseMethodName) {
|
|
10
|
+
const methodNames = {
|
|
11
|
+
create: `create${baseMethodName}`,
|
|
12
|
+
upset: `upset${baseMethodName}`,
|
|
13
|
+
get: `get${baseMethodName}`,
|
|
14
|
+
};
|
|
15
|
+
return function (Base) {
|
|
16
|
+
return class FieldsWith extends Base {
|
|
17
|
+
// createBoolean, createMySignal, etc.
|
|
18
|
+
[methodNames.create](name, initialValue, options) {
|
|
19
|
+
return this.create(typeName, name, initialValue, options);
|
|
20
|
+
}
|
|
21
|
+
// upsetBoolean, upsetMySignal, etc.
|
|
22
|
+
[methodNames.upset](name, value, options) {
|
|
23
|
+
return this.upset(typeName, name, value, options);
|
|
24
|
+
}
|
|
25
|
+
// getBoolean, getMySignal, etc.
|
|
26
|
+
[methodNames.get](name) {
|
|
27
|
+
return this.get(name);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=mixin-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin-factory.js","sourceRoot":"","sources":["../../src/mixins/mixin-factory.ts"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAIrC,QAAgB,EAChB,cAAyB;IAEzB,MAAM,WAAW,GAAG;QAClB,MAAM,EAAE,SAAS,cAAc,EAAE;QACjC,KAAK,EAAE,QAAQ,cAAc,EAAE;QAC/B,GAAG,EAAE,MAAM,cAAc,EAAE;KAC5B,CAAC;IAEF,OAAO,UAA6C,IAAW;QAG7D,OAAO,MAAM,UAAW,SAAQ,IAAI;YAClC,sCAAsC;YACtC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAY,EAAE,YAAiB,EAAE,OAAyC;gBAC7F,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,CAAwB,CAAC;YACnF,CAAC;YAED,oCAAoC;YACpC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAY,EAAE,KAAU,EAAE,OAAyC;gBACrF,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAwB,CAAC;YAC3E,CAAC;YAED,gCAAgC;YAChC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAY;gBAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;SACK,CAAC;IACX,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoreBooleanField } from '../field-definitions';
|
|
2
|
+
export declare const WithBooleanFields: <TBase extends import("@axi-engine/utils").Constructor<import("..").Fields>>(Base: TBase) => import("@axi-engine/utils").Constructor<InstanceType<TBase> & {
|
|
3
|
+
createBoolean: (name: string, initialValue: boolean, options?: import("../field-definitions").CoreBooleanFieldOptions | undefined) => CoreBooleanField;
|
|
4
|
+
} & {
|
|
5
|
+
upsetBoolean: (name: string, value: boolean, options?: import("../field-definitions").CoreBooleanFieldOptions | undefined) => CoreBooleanField;
|
|
6
|
+
} & {
|
|
7
|
+
getBoolean: (name: string) => CoreBooleanField;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=with-boolean-fields.mixin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-boolean-fields.mixin.d.ts","sourceRoot":"","sources":["../../src/mixins/with-boolean-fields.mixin.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD,eAAO,MAAM,iBAAiB;;;;;;EAGS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-boolean-fields.mixin.js","sourceRoot":"","sources":["../../src/mixins/with-boolean-fields.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAGtD,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Constructor } from '@axi-engine/utils';
|
|
2
|
+
import { Fields } from '../fields';
|
|
3
|
+
import { CoreField } from '../field-definitions';
|
|
4
|
+
import { FieldOptions } from '../field';
|
|
5
|
+
export declare function WithDefaultGenericFields<TBase extends Constructor<Fields>>(Base: TBase): {
|
|
6
|
+
new (...args: any[]): {
|
|
7
|
+
createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T>): CoreField<T>;
|
|
8
|
+
upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T>): CoreField<T>;
|
|
9
|
+
getGeneric<T>(name: string): CoreField<T>;
|
|
10
|
+
readonly typeName: "fields";
|
|
11
|
+
readonly _fields: Map<string, import("../field").Field<any>>;
|
|
12
|
+
readonly _fieldRegistry: import("..").FieldRegistry;
|
|
13
|
+
onAdd: import("@axi-engine/utils").Emitter<[event: {
|
|
14
|
+
name: string;
|
|
15
|
+
field: import("../field").Field<any>;
|
|
16
|
+
}]>;
|
|
17
|
+
onRemove: import("@axi-engine/utils").Emitter<[event: {
|
|
18
|
+
names: string[];
|
|
19
|
+
}]>;
|
|
20
|
+
get fields(): Map<string, import("../field").Field<any>>;
|
|
21
|
+
has(name: string): boolean;
|
|
22
|
+
add<T extends import("../field").Field<any>>(field: import("../field").Field<any>): T;
|
|
23
|
+
create<T extends import("../field").Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
|
|
24
|
+
upset<T extends import("../field").Field<any>>(typeName: string, name: string, value: any, options?: any): T;
|
|
25
|
+
get<TField extends import("../field").Field<any>>(name: string): TField;
|
|
26
|
+
remove(names: string | string[]): void;
|
|
27
|
+
clear(): void;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
};
|
|
30
|
+
} & TBase;
|
|
31
|
+
//# sourceMappingURL=with-default-generic-fields.mixin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-default-generic-fields.mixin.d.ts","sourceRoot":"","sources":["../../src/mixins/with-default-generic-fields.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACjC,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAGtC,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK;;sBAGrE,CAAC,QAAQ,MAAM,gBAAgB,CAAC,YAAY,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;qBAI3E,CAAC,QAAQ,MAAM,SAAS,CAAC,YAAY,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;mBAIrE,CAAC,QAAQ,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;UAI5C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CoreField } from '../field-definitions';
|
|
2
|
+
export function WithDefaultGenericFields(Base) {
|
|
3
|
+
return class FieldsWithDefaultGeneric extends Base {
|
|
4
|
+
createGeneric(name, initialValue, options) {
|
|
5
|
+
return this.create(CoreField.typeName, name, initialValue, options);
|
|
6
|
+
}
|
|
7
|
+
upsetGeneric(name, value, options) {
|
|
8
|
+
return this.upset(CoreField.typeName, name, value, options);
|
|
9
|
+
}
|
|
10
|
+
getGeneric(name) {
|
|
11
|
+
return this.get(name);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=with-default-generic-fields.mixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-default-generic-fields.mixin.js","sourceRoot":"","sources":["../../src/mixins/with-default-generic-fields.mixin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAI/C,MAAM,UAAU,wBAAwB,CAAoC,IAAW;IAErF,OAAO,MAAM,wBAAyB,SAAQ,IAAI;QAChD,aAAa,CAAI,IAAY,EAAE,YAAe,EAAE,OAAyB;YACvE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QACtE,CAAC;QAED,YAAY,CAAI,IAAY,EAAE,KAAQ,EAAE,OAAyB;YAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC9D,CAAC;QAED,UAAU,CAAI,IAAY;YACxB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoreNumericField } from '../field-definitions';
|
|
2
|
+
export declare const WithNumericFields: <TBase extends import("@axi-engine/utils").Constructor<import("..").Fields>>(Base: TBase) => import("@axi-engine/utils").Constructor<InstanceType<TBase> & {
|
|
3
|
+
createNumeric: (name: string, initialValue: number, options?: import("../field-definitions").CoreNumericFieldOptions | undefined) => CoreNumericField;
|
|
4
|
+
} & {
|
|
5
|
+
upsetNumeric: (name: string, value: number, options?: import("../field-definitions").CoreNumericFieldOptions | undefined) => CoreNumericField;
|
|
6
|
+
} & {
|
|
7
|
+
getNumeric: (name: string) => CoreNumericField;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=with-numeric-fields.mixin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-numeric-fields.mixin.d.ts","sourceRoot":"","sources":["../../src/mixins/with-numeric-fields.mixin.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAGtD,eAAO,MAAM,iBAAiB;;;;;;EAGS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-numeric-fields.mixin.js","sourceRoot":"","sources":["../../src/mixins/with-numeric-fields.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAGtD,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAGtD,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoreStringField } from '../field-definitions';
|
|
2
|
+
export declare const WithStringFields: <TBase extends import("@axi-engine/utils").Constructor<import("..").Fields>>(Base: TBase) => import("@axi-engine/utils").Constructor<InstanceType<TBase> & {
|
|
3
|
+
createString: (name: string, initialValue: string, options?: import("../field-definitions").CoreStringFieldOptions | undefined) => CoreStringField;
|
|
4
|
+
} & {
|
|
5
|
+
upsetString: (name: string, value: string, options?: import("../field-definitions").CoreStringFieldOptions | undefined) => CoreStringField;
|
|
6
|
+
} & {
|
|
7
|
+
getString: (name: string) => CoreStringField;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=with-string-fields.mixin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-string-fields.mixin.d.ts","sourceRoot":"","sources":["../../src/mixins/with-string-fields.mixin.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,gBAAgB;;;;;;EAGQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-string-fields.mixin.js","sourceRoot":"","sources":["../../src/mixins/with-string-fields.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAErD,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAGrD,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Policy } from './policy';
|
|
2
|
+
export declare class ClampMaxPolicy implements Policy<number> {
|
|
3
|
+
max: number;
|
|
4
|
+
static readonly id = "clampMax";
|
|
5
|
+
readonly id = "clampMax";
|
|
6
|
+
constructor(max: number);
|
|
7
|
+
apply(val: number): number;
|
|
8
|
+
updateBounds(max: number): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function clampMaxPolicy(max: number): ClampMaxPolicy;
|
|
11
|
+
//# sourceMappingURL=clamp-max-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp-max-policy.d.ts","sourceRoot":"","sources":["../../src/policies/clamp-max-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,qBAAa,cAAe,YAAW,MAAM,CAAC,MAAM,CAAC;IAIhC,GAAG,EAAE,MAAM;IAH9B,MAAM,CAAC,QAAQ,CAAC,EAAE,cAAc;IAChC,QAAQ,CAAC,EAAE,cAAqB;gBAEb,GAAG,EAAE,MAAM;IAG9B,KAAK,CAAC,GAAG,EAAE,MAAM;IAIjB,YAAY,CAAC,GAAG,EAAE,MAAM;CAGzB;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,kBAEzC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class ClampMaxPolicy {
|
|
2
|
+
max;
|
|
3
|
+
static id = 'clampMax';
|
|
4
|
+
id = ClampMaxPolicy.id;
|
|
5
|
+
constructor(max) {
|
|
6
|
+
this.max = max;
|
|
7
|
+
}
|
|
8
|
+
apply(val) {
|
|
9
|
+
return Math.min(this.max, val);
|
|
10
|
+
}
|
|
11
|
+
updateBounds(max) {
|
|
12
|
+
this.max = max;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function clampMaxPolicy(max) {
|
|
16
|
+
return new ClampMaxPolicy(max);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=clamp-max-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp-max-policy.js","sourceRoot":"","sources":["../../src/policies/clamp-max-policy.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAc;IAIN;IAHnB,MAAM,CAAU,EAAE,GAAG,UAAU,CAAC;IACvB,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC;IAEhC,YAAmB,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAC9B,CAAC;IAED,KAAK,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,YAAY,CAAC,GAAW;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;;AAGH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,IAAI,cAAc,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Policy } from './policy';
|
|
2
|
+
export declare class ClampMinPolicy implements Policy<number> {
|
|
3
|
+
min: number;
|
|
4
|
+
static readonly id = "clampMin";
|
|
5
|
+
readonly id = "clampMin";
|
|
6
|
+
constructor(min: number);
|
|
7
|
+
apply(val: number): number;
|
|
8
|
+
updateBounds(min: number): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function clampMinPolicy(min: number): ClampMinPolicy;
|
|
11
|
+
//# sourceMappingURL=clamp-min-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp-min-policy.d.ts","sourceRoot":"","sources":["../../src/policies/clamp-min-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,qBAAa,cAAe,YAAW,MAAM,CAAC,MAAM,CAAC;IAIhC,GAAG,EAAE,MAAM;IAH9B,MAAM,CAAC,QAAQ,CAAC,EAAE,cAAc;IAChC,QAAQ,CAAC,EAAE,cAAqB;gBAEb,GAAG,EAAE,MAAM;IAG9B,KAAK,CAAC,GAAG,EAAE,MAAM;IAIjB,YAAY,CAAC,GAAG,EAAE,MAAM;CAGzB;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,kBAEzC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class ClampMinPolicy {
|
|
2
|
+
min;
|
|
3
|
+
static id = 'clampMin';
|
|
4
|
+
id = ClampMinPolicy.id;
|
|
5
|
+
constructor(min) {
|
|
6
|
+
this.min = min;
|
|
7
|
+
}
|
|
8
|
+
apply(val) {
|
|
9
|
+
return Math.max(this.min, val);
|
|
10
|
+
}
|
|
11
|
+
updateBounds(min) {
|
|
12
|
+
this.min = min;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function clampMinPolicy(min) {
|
|
16
|
+
return new ClampMinPolicy(min);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=clamp-min-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp-min-policy.js","sourceRoot":"","sources":["../../src/policies/clamp-min-policy.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAc;IAIN;IAHnB,MAAM,CAAU,EAAE,GAAG,UAAU,CAAC;IACvB,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC;IAEhC,YAAmB,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAC9B,CAAC;IAED,KAAK,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,YAAY,CAAC,GAAW;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;;AAGH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,IAAI,cAAc,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Policy } from './policy';
|
|
2
|
+
export declare class ClampPolicy implements Policy<number> {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
static readonly id = "clamp";
|
|
6
|
+
readonly id = "clamp";
|
|
7
|
+
constructor(min: number, max: number);
|
|
8
|
+
apply(val: number): number;
|
|
9
|
+
updateBounds(min: number, max: number): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function clampPolicy(min: number, max: number): ClampPolicy;
|
|
12
|
+
//# sourceMappingURL=clamp-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp-policy.d.ts","sourceRoot":"","sources":["../../src/policies/clamp-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,qBAAa,WAAY,YAAW,MAAM,CAAC,MAAM,CAAC;IAI7B,GAAG,EAAE,MAAM;IAAS,GAAG,EAAE,MAAM;IAHlD,MAAM,CAAC,QAAQ,CAAC,EAAE,WAAW;IAC7B,QAAQ,CAAC,EAAE,WAAkB;gBAEV,GAAG,EAAE,MAAM,EAAS,GAAG,EAAE,MAAM;IAGlD,KAAK,CAAC,GAAG,EAAE,MAAM;IAIjB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CAItC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,eAEnD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class ClampPolicy {
|
|
2
|
+
min;
|
|
3
|
+
max;
|
|
4
|
+
static id = 'clamp';
|
|
5
|
+
id = ClampPolicy.id;
|
|
6
|
+
constructor(min, max) {
|
|
7
|
+
this.min = min;
|
|
8
|
+
this.max = max;
|
|
9
|
+
}
|
|
10
|
+
apply(val) {
|
|
11
|
+
return Math.max(this.min, Math.min(this.max, val));
|
|
12
|
+
}
|
|
13
|
+
updateBounds(min, max) {
|
|
14
|
+
this.min = min;
|
|
15
|
+
this.max = max;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function clampPolicy(min, max) {
|
|
19
|
+
return new ClampPolicy(min, max);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=clamp-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp-policy.js","sourceRoot":"","sources":["../../src/policies/clamp-policy.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IAIH;IAAoB;IAHvC,MAAM,CAAU,EAAE,GAAG,OAAO,CAAC;IACpB,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC;IAE7B,YAAmB,GAAW,EAAS,GAAW;QAA/B,QAAG,GAAH,GAAG,CAAQ;QAAS,QAAG,GAAH,GAAG,CAAQ;IAClD,CAAC;IAED,KAAK,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,GAAW;QACnC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;;AAGH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAClD,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AAEzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AAEzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Policy } from './policy';
|
|
2
|
+
export declare class Policies<T> {
|
|
3
|
+
private readonly policies;
|
|
4
|
+
get items(): Map<string, Policy<T>>;
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a specific policy instance by its ID.
|
|
7
|
+
* Useful for accessing a policy's internal state or methods.
|
|
8
|
+
* @template P The expected type of the policy.
|
|
9
|
+
* @param id The unique ID of the policy to retrieve.
|
|
10
|
+
* @returns The policy instance, or `undefined` if not found.
|
|
11
|
+
*/
|
|
12
|
+
get<P extends Policy<T>>(id: string): P | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Adds a new policy to the field or replaces an existing one with the same ID.
|
|
15
|
+
* The new policy will be applied on the next `set()` operation.
|
|
16
|
+
* If a policy with the same ID already exists, its `destroy` method will be called before it is replaced.
|
|
17
|
+
* @param policy The policy instance to add.
|
|
18
|
+
*/
|
|
19
|
+
add(policy: Policy<T>): this;
|
|
20
|
+
/**
|
|
21
|
+
* Removes a policy from the field by its ID and call `destroy` method.
|
|
22
|
+
* @param policyId The unique ID of the policy to remove.
|
|
23
|
+
* @returns `true` if the policy was found and removed, otherwise `false`.
|
|
24
|
+
*/
|
|
25
|
+
remove(policyId: string): boolean;
|
|
26
|
+
isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Removes all policies from the field.
|
|
29
|
+
* After this, `set()` will no longer apply any transformations to the value until new policies are added.
|
|
30
|
+
*/
|
|
31
|
+
clear(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Forces the current value to be re-processed by all policies.
|
|
34
|
+
* Useful if a policy's logic has changed and you need to re-evaluate the current state.
|
|
35
|
+
*/
|
|
36
|
+
apply(val: T): T;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=policies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/policies/policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAGhC,qBAAa,QAAQ,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IAEzD,IAAI,KAAK,2BAER;IAED;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAInD;;;;;OAKG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAQrB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IASjC,OAAO;IAIP;;;OAGG;IACH,KAAK,IAAI,IAAI;IAKb;;;OAGG;IACH,KAAK,CAAC,GAAG,EAAE,CAAC;CAKb"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export class Policies {
|
|
2
|
+
policies = new Map();
|
|
3
|
+
get items() {
|
|
4
|
+
return this.policies;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a specific policy instance by its ID.
|
|
8
|
+
* Useful for accessing a policy's internal state or methods.
|
|
9
|
+
* @template P The expected type of the policy.
|
|
10
|
+
* @param id The unique ID of the policy to retrieve.
|
|
11
|
+
* @returns The policy instance, or `undefined` if not found.
|
|
12
|
+
*/
|
|
13
|
+
get(id) {
|
|
14
|
+
return this.policies.get(id);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Adds a new policy to the field or replaces an existing one with the same ID.
|
|
18
|
+
* The new policy will be applied on the next `set()` operation.
|
|
19
|
+
* If a policy with the same ID already exists, its `destroy` method will be called before it is replaced.
|
|
20
|
+
* @param policy The policy instance to add.
|
|
21
|
+
*/
|
|
22
|
+
add(policy) {
|
|
23
|
+
const existed = this.policies.get(policy.id);
|
|
24
|
+
existed?.destroy?.();
|
|
25
|
+
this.policies.set(policy.id, policy);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Removes a policy from the field by its ID and call `destroy` method.
|
|
30
|
+
* @param policyId The unique ID of the policy to remove.
|
|
31
|
+
* @returns `true` if the policy was found and removed, otherwise `false`.
|
|
32
|
+
*/
|
|
33
|
+
remove(policyId) {
|
|
34
|
+
const policyToRemove = this.policies.get(policyId);
|
|
35
|
+
if (!policyToRemove) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
policyToRemove.destroy?.();
|
|
39
|
+
return this.policies.delete(policyId);
|
|
40
|
+
}
|
|
41
|
+
isEmpty() {
|
|
42
|
+
return this.policies.size === 0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Removes all policies from the field.
|
|
46
|
+
* After this, `set()` will no longer apply any transformations to the value until new policies are added.
|
|
47
|
+
*/
|
|
48
|
+
clear() {
|
|
49
|
+
this.policies.forEach(policy => policy.destroy?.());
|
|
50
|
+
this.policies.clear();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Forces the current value to be re-processed by all policies.
|
|
54
|
+
* Useful if a policy's logic has changed and you need to re-evaluate the current state.
|
|
55
|
+
*/
|
|
56
|
+
apply(val) {
|
|
57
|
+
let finalVal = val;
|
|
58
|
+
this.policies.forEach(policy => finalVal = policy.apply(finalVal));
|
|
59
|
+
return finalVal;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies.js","sourceRoot":"","sources":["../../src/policies/policies.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,QAAQ;IACF,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;IAEzD,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAsB,EAAU;QACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAM,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,MAAiB;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC7C,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAErC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAgB;QACrB,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAM;QACV,IAAI,QAAQ,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnE,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/policies/policy.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/policies/policy.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PolicySerializer } from './policy-serializer';
|
|
2
|
+
import { FieldRegistry } from '../field-registry';
|
|
3
|
+
import { Field } from '../field';
|
|
4
|
+
/**
|
|
5
|
+
* A plain object representation of a Field's state for serialization.
|
|
6
|
+
*/
|
|
7
|
+
export interface FieldSnapshot {
|
|
8
|
+
__type: string;
|
|
9
|
+
name: string;
|
|
10
|
+
value: any;
|
|
11
|
+
policies?: object[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Orchestrates the serialization and deserialization of Field instances.
|
|
15
|
+
*
|
|
16
|
+
* This class acts as a central point for converting complex Field objects into
|
|
17
|
+
* plain, storable data (snapshots) and vice-versa. It uses a `FieldRegistry`
|
|
18
|
+
* to resolve class constructors and a `PolicySerializer` to handle the state
|
|
19
|
+
* of any attached policies.
|
|
20
|
+
*
|
|
21
|
+
* @todo Implement a `patch(field, snapshot)` method.
|
|
22
|
+
* Unlike `hydrate`, which creates a new
|
|
23
|
+
* instance, `patch` should update the state of an *existing* field instance
|
|
24
|
+
* without breaking external references to it.
|
|
25
|
+
*/
|
|
26
|
+
export declare class FieldSerializer {
|
|
27
|
+
private readonly fieldRegistry;
|
|
28
|
+
private readonly policySerializer;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of FieldSerializer.
|
|
31
|
+
* @param {FieldRegistry} fieldRegistry - A registry that maps string type names to Field constructors.
|
|
32
|
+
* @param {PolicySerializer} policySerializer - A serializer dedicated to handling Policy instances.
|
|
33
|
+
*/
|
|
34
|
+
constructor(fieldRegistry: FieldRegistry, policySerializer: PolicySerializer);
|
|
35
|
+
/**
|
|
36
|
+
* Creates a serializable snapshot of a Field instance.
|
|
37
|
+
* The snapshot includes the field's type, name, current value, and the state of all its policies.
|
|
38
|
+
* @param {Field<any>} field - The Field instance to serialize.
|
|
39
|
+
* @returns {FieldSnapshot} A plain object ready for JSON serialization.
|
|
40
|
+
*/
|
|
41
|
+
snapshot(field: Field<any>): FieldSnapshot;
|
|
42
|
+
/**
|
|
43
|
+
* Restores a Field instance from its snapshot representation.
|
|
44
|
+
* It uses the `__type` property to find the correct constructor and hydrates
|
|
45
|
+
* the field with its value and all its policies.
|
|
46
|
+
* @param {FieldSnapshot} snapshot - The plain object snapshot to deserialize.
|
|
47
|
+
* @returns {Field<any>} A new, fully functional Field instance.
|
|
48
|
+
* @throws If the snapshot is invalid, missing a `__type`, or if the type is not registered.
|
|
49
|
+
*/
|
|
50
|
+
hydrate(snapshot: FieldSnapshot): Field<any>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=field-serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-serializer.d.ts","sourceRoot":"","sources":["../../src/serializer/field-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAI/B;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAe;IAQxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAPnC;;;;OAIG;gBAEgB,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,gBAAgB;IAIrD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,aAAa;IAgB1C;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC;CAa7C"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { isNullOrUndefined, throwIfEmpty } from '@axi-engine/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Orchestrates the serialization and deserialization of Field instances.
|
|
4
|
+
*
|
|
5
|
+
* This class acts as a central point for converting complex Field objects into
|
|
6
|
+
* plain, storable data (snapshots) and vice-versa. It uses a `FieldRegistry`
|
|
7
|
+
* to resolve class constructors and a `PolicySerializer` to handle the state
|
|
8
|
+
* of any attached policies.
|
|
9
|
+
*
|
|
10
|
+
* @todo Implement a `patch(field, snapshot)` method.
|
|
11
|
+
* Unlike `hydrate`, which creates a new
|
|
12
|
+
* instance, `patch` should update the state of an *existing* field instance
|
|
13
|
+
* without breaking external references to it.
|
|
14
|
+
*/
|
|
15
|
+
export class FieldSerializer {
|
|
16
|
+
fieldRegistry;
|
|
17
|
+
policySerializer;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of FieldSerializer.
|
|
20
|
+
* @param {FieldRegistry} fieldRegistry - A registry that maps string type names to Field constructors.
|
|
21
|
+
* @param {PolicySerializer} policySerializer - A serializer dedicated to handling Policy instances.
|
|
22
|
+
*/
|
|
23
|
+
constructor(fieldRegistry, policySerializer) {
|
|
24
|
+
this.fieldRegistry = fieldRegistry;
|
|
25
|
+
this.policySerializer = policySerializer;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a serializable snapshot of a Field instance.
|
|
29
|
+
* The snapshot includes the field's type, name, current value, and the state of all its policies.
|
|
30
|
+
* @param {Field<any>} field - The Field instance to serialize.
|
|
31
|
+
* @returns {FieldSnapshot} A plain object ready for JSON serialization.
|
|
32
|
+
*/
|
|
33
|
+
snapshot(field) {
|
|
34
|
+
let snapshot = {
|
|
35
|
+
__type: field.typeName,
|
|
36
|
+
name: field.name,
|
|
37
|
+
value: field.value,
|
|
38
|
+
};
|
|
39
|
+
if (!field.policies.isEmpty()) {
|
|
40
|
+
const serializedPolicies = [];
|
|
41
|
+
field.policies.items.forEach(policy => serializedPolicies.push(this.policySerializer.snapshot(policy)));
|
|
42
|
+
snapshot.policies = serializedPolicies;
|
|
43
|
+
}
|
|
44
|
+
return snapshot;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Restores a Field instance from its snapshot representation.
|
|
48
|
+
* It uses the `__type` property to find the correct constructor and hydrates
|
|
49
|
+
* the field with its value and all its policies.
|
|
50
|
+
* @param {FieldSnapshot} snapshot - The plain object snapshot to deserialize.
|
|
51
|
+
* @returns {Field<any>} A new, fully functional Field instance.
|
|
52
|
+
* @throws If the snapshot is invalid, missing a `__type`, or if the type is not registered.
|
|
53
|
+
*/
|
|
54
|
+
hydrate(snapshot) {
|
|
55
|
+
const fieldType = snapshot.__type;
|
|
56
|
+
throwIfEmpty(fieldType, 'Invalid field snapshot: missing "__type" identifier.');
|
|
57
|
+
const Ctor = this.fieldRegistry.get(fieldType);
|
|
58
|
+
let policies;
|
|
59
|
+
if (!isNullOrUndefined(snapshot.policies)) {
|
|
60
|
+
policies = [];
|
|
61
|
+
snapshot.policies.forEach((p) => policies.push(this.policySerializer.hydrate(p)));
|
|
62
|
+
}
|
|
63
|
+
return new Ctor(snapshot.name, snapshot.value, { policies });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=field-serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-serializer.js","sourceRoot":"","sources":["../../src/serializer/field-serializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAgBlE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,eAAe;IAQP;IACA;IAPnB;;;;OAIG;IACH,YACmB,aAA4B,EAC5B,gBAAkC;QADlC,kBAAa,GAAb,aAAa,CAAe;QAC5B,qBAAgB,GAAhB,gBAAgB,CAAkB;IAErD,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,KAAiB;QACxB,IAAI,QAAQ,GAAQ;YAClB,MAAM,EAAE,KAAK,CAAC,QAAQ;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAA;QAED,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9B,MAAM,kBAAkB,GAAa,EAAE,CAAC;YACxC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxG,QAAQ,CAAC,QAAQ,GAAG,kBAAkB,CAAC;QACzC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,QAAuB;QAC7B,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC;QAClC,YAAY,CAAC,SAAS,EAAE,sDAAsD,CAAC,CAAC;QAChF,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAE/C,IAAI,QAAmC,CAAC;QACxC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1C,QAAQ,GAAG,EAAE,CAAC;YACd,QAAQ,CAAC,QAAS,CAAC,OAAO,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,QAAS,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3F,CAAC;QAED,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAC,QAAQ,EAAC,CAAe,CAAC;IAC3E,CAAC;CACF"}
|