@axi-engine/fields 0.2.2 → 0.2.3

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _axi_engine_utils from '@axi-engine/utils';
2
- import { Subscribable, Constructor, Emitter, PathType } from '@axi-engine/utils';
2
+ import { Constructor, Subscribable, Emitter, PathType } from '@axi-engine/utils';
3
3
 
4
4
  interface Policy<T> {
5
5
  readonly id: string;
@@ -75,6 +75,31 @@ declare class Policies<T> {
75
75
  apply(val: T): T;
76
76
  }
77
77
 
78
+ /**
79
+ * extract field type
80
+ */
81
+ type GetValueType<TField extends Field<any>> = TField extends Field<infer U> ? U : any;
82
+ /**
83
+ * A mapped type that creates the method signatures for a typed mixin.
84
+ * e.g., createBoolean, upsetBoolean, getBoolean
85
+ */
86
+ type TypedMethods<TCtor extends Constructor<Field<any>>, TBaseName extends string> = {
87
+ [K in `create${TBaseName}`]: (name: string, initialValue: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
88
+ } & {
89
+ [K in `upset${TBaseName}`]: (name: string, value: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
90
+ } & {
91
+ [K in `get${TBaseName}`]: (name: string) => InstanceType<TCtor>;
92
+ };
93
+ /**
94
+ * A higher-order function that generates a mixin for a specific Field type.
95
+ * This factory removes the need to write boilerplate mixin code for every new field type.
96
+ *
97
+ * @param typeName The `typeName` of the Field to create (e.g., 'boolean', 'my-signal-field').
98
+ * @param baseMethodName The base name for the generated methods (e.g., 'Boolean', 'MySignal').
99
+ * @returns A fully functional, typed mixin.
100
+ */
101
+ 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>>;
102
+
78
103
  interface FieldOptions<T> {
79
104
  policies?: Policy<T>[];
80
105
  }
@@ -333,107 +358,48 @@ declare class Fields {
333
358
  destroy(): void;
334
359
  }
335
360
 
336
- declare const DefaultFields_base: {
337
- new (...args: any[]): {
338
- createBoolean(name: string, initialValue: boolean, options?: DefaultBooleanFieldOptions): DefaultBooleanField;
339
- upsetBoolean(name: string, value: boolean, options?: DefaultBooleanFieldOptions): DefaultBooleanField;
340
- getBoolean(name: string): DefaultBooleanField;
341
- readonly typeName: "fields";
342
- readonly _fields: Map<string, Field<any>>;
343
- readonly _fieldRegistry: FieldRegistry;
344
- onAdd: _axi_engine_utils.Emitter<[event: {
345
- name: string;
346
- field: Field<any>;
347
- }]>;
348
- onRemove: _axi_engine_utils.Emitter<[event: {
349
- names: string[];
350
- }]>;
351
- get fields(): Map<string, Field<any>>;
352
- has(name: string): boolean;
353
- add<T extends Field<any>>(field: Field<any>): T;
354
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
355
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
356
- get<T extends Field<any>>(name: string): T;
357
- remove(names: string | string[]): void;
358
- clear(): void;
359
- destroy(): void;
360
- };
361
+ declare const DefaultFields_base: _axi_engine_utils.Constructor<{
362
+ createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
363
+ upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
364
+ getGeneric<T>(name: string): DefaultField<T>;
365
+ readonly typeName: "fields";
366
+ readonly _fields: Map<string, Field<any>>;
367
+ readonly _fieldRegistry: FieldRegistry;
368
+ onAdd: _axi_engine_utils.Emitter<[event: {
369
+ name: string;
370
+ field: Field<any>;
371
+ }]>;
372
+ onRemove: _axi_engine_utils.Emitter<[event: {
373
+ names: string[];
374
+ }]>;
375
+ get fields(): Map<string, Field<any>>;
376
+ has(name: string): boolean;
377
+ add<T extends Field<any>>(field: Field<any>): T;
378
+ create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
379
+ upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
380
+ get<T extends Field<any>>(name: string): T;
381
+ remove(names: string | string[]): void;
382
+ clear(): void;
383
+ destroy(): void;
384
+ } & Fields & {
385
+ createNumeric: (name: string, initialValue: number, options?: DefaultNumericFieldOptions | undefined) => DefaultNumericField;
361
386
  } & {
362
- new (...args: any[]): {
363
- createString(name: string, initialValue: string, options?: DefaultStringFieldOptions): DefaultStringField;
364
- upsetString(name: string, value: string, options?: DefaultStringFieldOptions): DefaultStringField;
365
- getString(name: string): DefaultStringField;
366
- readonly typeName: "fields";
367
- readonly _fields: Map<string, Field<any>>;
368
- readonly _fieldRegistry: FieldRegistry;
369
- onAdd: _axi_engine_utils.Emitter<[event: {
370
- name: string;
371
- field: Field<any>;
372
- }]>;
373
- onRemove: _axi_engine_utils.Emitter<[event: {
374
- names: string[];
375
- }]>;
376
- get fields(): Map<string, Field<any>>;
377
- has(name: string): boolean;
378
- add<T extends Field<any>>(field: Field<any>): T;
379
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
380
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
381
- get<T extends Field<any>>(name: string): T;
382
- remove(names: string | string[]): void;
383
- clear(): void;
384
- destroy(): void;
385
- };
387
+ upsetNumeric: (name: string, value: number, options?: DefaultNumericFieldOptions | undefined) => DefaultNumericField;
386
388
  } & {
387
- new (...args: any[]): {
388
- createNumeric(name: string, initialValue: number, options?: DefaultNumericFieldOptions): DefaultNumericField;
389
- upsetNumeric(name: string, value: number, options?: DefaultNumericFieldOptions): DefaultNumericField;
390
- getNumeric(name: string): DefaultNumericField;
391
- readonly typeName: "fields";
392
- readonly _fields: Map<string, Field<any>>;
393
- readonly _fieldRegistry: FieldRegistry;
394
- onAdd: _axi_engine_utils.Emitter<[event: {
395
- name: string;
396
- field: Field<any>;
397
- }]>;
398
- onRemove: _axi_engine_utils.Emitter<[event: {
399
- names: string[];
400
- }]>;
401
- get fields(): Map<string, Field<any>>;
402
- has(name: string): boolean;
403
- add<T extends Field<any>>(field: Field<any>): T;
404
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
405
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
406
- get<T extends Field<any>>(name: string): T;
407
- remove(names: string | string[]): void;
408
- clear(): void;
409
- destroy(): void;
410
- };
389
+ getNumeric: (name: string) => DefaultNumericField;
411
390
  } & {
412
- new (...args: any[]): {
413
- createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
414
- upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
415
- getGeneric<T>(name: string): DefaultField<T>;
416
- readonly typeName: "fields";
417
- readonly _fields: Map<string, Field<any>>;
418
- readonly _fieldRegistry: FieldRegistry;
419
- onAdd: _axi_engine_utils.Emitter<[event: {
420
- name: string;
421
- field: Field<any>;
422
- }]>;
423
- onRemove: _axi_engine_utils.Emitter<[event: {
424
- names: string[];
425
- }]>;
426
- get fields(): Map<string, Field<any>>;
427
- has(name: string): boolean;
428
- add<T extends Field<any>>(field: Field<any>): T;
429
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
430
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
431
- get<T extends Field<any>>(name: string): T;
432
- remove(names: string | string[]): void;
433
- clear(): void;
434
- destroy(): void;
435
- };
436
- } & typeof Fields;
391
+ createString: (name: string, initialValue: string, options?: DefaultStringFieldOptions | undefined) => DefaultStringField;
392
+ } & {
393
+ upsetString: (name: string, value: string, options?: DefaultStringFieldOptions | undefined) => DefaultStringField;
394
+ } & {
395
+ getString: (name: string) => DefaultStringField;
396
+ } & {
397
+ createBoolean: (name: string, initialValue: boolean, options?: DefaultBooleanFieldOptions | undefined) => DefaultBooleanField;
398
+ } & {
399
+ upsetBoolean: (name: string, value: boolean, options?: DefaultBooleanFieldOptions | undefined) => DefaultBooleanField;
400
+ } & {
401
+ getBoolean: (name: string) => DefaultBooleanField;
402
+ }>;
437
403
  declare class DefaultFields extends DefaultFields_base {
438
404
  }
439
405
 
@@ -839,4 +805,4 @@ declare class FieldTreeSerializer<TFields extends Fields> {
839
805
  hydrate(snapshot: FieldTreeSnapshot): FieldTree<TFields>;
840
806
  }
841
807
 
842
- export { type BooleanField, ClampMaxPolicy, ClampMaxPolicySerializerHandler, ClampMinPolicy, ClampMinPolicySerializerHandler, ClampPolicy, ClampPolicySerializerHandler, DefaultBooleanField, type DefaultBooleanFieldOptions, DefaultField, DefaultFields, DefaultFieldsFactory, DefaultNumericField, type DefaultNumericFieldOptions, DefaultStringField, type DefaultStringFieldOptions, DefaultTreeNodeFactory, type Field, type FieldOptions, FieldRegistry, FieldSerializer, type FieldSnapshot, FieldTree, FieldTreeSerializer, type FieldTreeSnapshot, Fields, type FieldsFactory, FieldsSerializer, type FieldsSnapshot, type NumericField, Policies, type Policy, PolicySerializer, type PolicySerializerHandler, type StringField, type TreeNode, type TreeNodeFactory, clampMaxPolicy, clampMinPolicy, clampPolicy };
808
+ export { type BooleanField, ClampMaxPolicy, ClampMaxPolicySerializerHandler, ClampMinPolicy, ClampMinPolicySerializerHandler, ClampPolicy, ClampPolicySerializerHandler, DefaultBooleanField, type DefaultBooleanFieldOptions, DefaultField, DefaultFields, DefaultFieldsFactory, DefaultNumericField, type DefaultNumericFieldOptions, DefaultStringField, type DefaultStringFieldOptions, DefaultTreeNodeFactory, type Field, type FieldOptions, FieldRegistry, FieldSerializer, type FieldSnapshot, FieldTree, FieldTreeSerializer, type FieldTreeSnapshot, Fields, type FieldsFactory, FieldsSerializer, type FieldsSnapshot, type NumericField, Policies, type Policy, PolicySerializer, type PolicySerializerHandler, type StringField, type TreeNode, type TreeNodeFactory, clampMaxPolicy, clampMinPolicy, clampPolicy, createTypedMethodsMixin };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _axi_engine_utils from '@axi-engine/utils';
2
- import { Subscribable, Constructor, Emitter, PathType } from '@axi-engine/utils';
2
+ import { Constructor, Subscribable, Emitter, PathType } from '@axi-engine/utils';
3
3
 
4
4
  interface Policy<T> {
5
5
  readonly id: string;
@@ -75,6 +75,31 @@ declare class Policies<T> {
75
75
  apply(val: T): T;
76
76
  }
77
77
 
78
+ /**
79
+ * extract field type
80
+ */
81
+ type GetValueType<TField extends Field<any>> = TField extends Field<infer U> ? U : any;
82
+ /**
83
+ * A mapped type that creates the method signatures for a typed mixin.
84
+ * e.g., createBoolean, upsetBoolean, getBoolean
85
+ */
86
+ type TypedMethods<TCtor extends Constructor<Field<any>>, TBaseName extends string> = {
87
+ [K in `create${TBaseName}`]: (name: string, initialValue: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
88
+ } & {
89
+ [K in `upset${TBaseName}`]: (name: string, value: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
90
+ } & {
91
+ [K in `get${TBaseName}`]: (name: string) => InstanceType<TCtor>;
92
+ };
93
+ /**
94
+ * A higher-order function that generates a mixin for a specific Field type.
95
+ * This factory removes the need to write boilerplate mixin code for every new field type.
96
+ *
97
+ * @param typeName The `typeName` of the Field to create (e.g., 'boolean', 'my-signal-field').
98
+ * @param baseMethodName The base name for the generated methods (e.g., 'Boolean', 'MySignal').
99
+ * @returns A fully functional, typed mixin.
100
+ */
101
+ 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>>;
102
+
78
103
  interface FieldOptions<T> {
79
104
  policies?: Policy<T>[];
80
105
  }
@@ -333,107 +358,48 @@ declare class Fields {
333
358
  destroy(): void;
334
359
  }
335
360
 
336
- declare const DefaultFields_base: {
337
- new (...args: any[]): {
338
- createBoolean(name: string, initialValue: boolean, options?: DefaultBooleanFieldOptions): DefaultBooleanField;
339
- upsetBoolean(name: string, value: boolean, options?: DefaultBooleanFieldOptions): DefaultBooleanField;
340
- getBoolean(name: string): DefaultBooleanField;
341
- readonly typeName: "fields";
342
- readonly _fields: Map<string, Field<any>>;
343
- readonly _fieldRegistry: FieldRegistry;
344
- onAdd: _axi_engine_utils.Emitter<[event: {
345
- name: string;
346
- field: Field<any>;
347
- }]>;
348
- onRemove: _axi_engine_utils.Emitter<[event: {
349
- names: string[];
350
- }]>;
351
- get fields(): Map<string, Field<any>>;
352
- has(name: string): boolean;
353
- add<T extends Field<any>>(field: Field<any>): T;
354
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
355
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
356
- get<T extends Field<any>>(name: string): T;
357
- remove(names: string | string[]): void;
358
- clear(): void;
359
- destroy(): void;
360
- };
361
+ declare const DefaultFields_base: _axi_engine_utils.Constructor<{
362
+ createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
363
+ upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
364
+ getGeneric<T>(name: string): DefaultField<T>;
365
+ readonly typeName: "fields";
366
+ readonly _fields: Map<string, Field<any>>;
367
+ readonly _fieldRegistry: FieldRegistry;
368
+ onAdd: _axi_engine_utils.Emitter<[event: {
369
+ name: string;
370
+ field: Field<any>;
371
+ }]>;
372
+ onRemove: _axi_engine_utils.Emitter<[event: {
373
+ names: string[];
374
+ }]>;
375
+ get fields(): Map<string, Field<any>>;
376
+ has(name: string): boolean;
377
+ add<T extends Field<any>>(field: Field<any>): T;
378
+ create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
379
+ upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
380
+ get<T extends Field<any>>(name: string): T;
381
+ remove(names: string | string[]): void;
382
+ clear(): void;
383
+ destroy(): void;
384
+ } & Fields & {
385
+ createNumeric: (name: string, initialValue: number, options?: DefaultNumericFieldOptions | undefined) => DefaultNumericField;
361
386
  } & {
362
- new (...args: any[]): {
363
- createString(name: string, initialValue: string, options?: DefaultStringFieldOptions): DefaultStringField;
364
- upsetString(name: string, value: string, options?: DefaultStringFieldOptions): DefaultStringField;
365
- getString(name: string): DefaultStringField;
366
- readonly typeName: "fields";
367
- readonly _fields: Map<string, Field<any>>;
368
- readonly _fieldRegistry: FieldRegistry;
369
- onAdd: _axi_engine_utils.Emitter<[event: {
370
- name: string;
371
- field: Field<any>;
372
- }]>;
373
- onRemove: _axi_engine_utils.Emitter<[event: {
374
- names: string[];
375
- }]>;
376
- get fields(): Map<string, Field<any>>;
377
- has(name: string): boolean;
378
- add<T extends Field<any>>(field: Field<any>): T;
379
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
380
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
381
- get<T extends Field<any>>(name: string): T;
382
- remove(names: string | string[]): void;
383
- clear(): void;
384
- destroy(): void;
385
- };
387
+ upsetNumeric: (name: string, value: number, options?: DefaultNumericFieldOptions | undefined) => DefaultNumericField;
386
388
  } & {
387
- new (...args: any[]): {
388
- createNumeric(name: string, initialValue: number, options?: DefaultNumericFieldOptions): DefaultNumericField;
389
- upsetNumeric(name: string, value: number, options?: DefaultNumericFieldOptions): DefaultNumericField;
390
- getNumeric(name: string): DefaultNumericField;
391
- readonly typeName: "fields";
392
- readonly _fields: Map<string, Field<any>>;
393
- readonly _fieldRegistry: FieldRegistry;
394
- onAdd: _axi_engine_utils.Emitter<[event: {
395
- name: string;
396
- field: Field<any>;
397
- }]>;
398
- onRemove: _axi_engine_utils.Emitter<[event: {
399
- names: string[];
400
- }]>;
401
- get fields(): Map<string, Field<any>>;
402
- has(name: string): boolean;
403
- add<T extends Field<any>>(field: Field<any>): T;
404
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
405
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
406
- get<T extends Field<any>>(name: string): T;
407
- remove(names: string | string[]): void;
408
- clear(): void;
409
- destroy(): void;
410
- };
389
+ getNumeric: (name: string) => DefaultNumericField;
411
390
  } & {
412
- new (...args: any[]): {
413
- createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
414
- upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
415
- getGeneric<T>(name: string): DefaultField<T>;
416
- readonly typeName: "fields";
417
- readonly _fields: Map<string, Field<any>>;
418
- readonly _fieldRegistry: FieldRegistry;
419
- onAdd: _axi_engine_utils.Emitter<[event: {
420
- name: string;
421
- field: Field<any>;
422
- }]>;
423
- onRemove: _axi_engine_utils.Emitter<[event: {
424
- names: string[];
425
- }]>;
426
- get fields(): Map<string, Field<any>>;
427
- has(name: string): boolean;
428
- add<T extends Field<any>>(field: Field<any>): T;
429
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
430
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
431
- get<T extends Field<any>>(name: string): T;
432
- remove(names: string | string[]): void;
433
- clear(): void;
434
- destroy(): void;
435
- };
436
- } & typeof Fields;
391
+ createString: (name: string, initialValue: string, options?: DefaultStringFieldOptions | undefined) => DefaultStringField;
392
+ } & {
393
+ upsetString: (name: string, value: string, options?: DefaultStringFieldOptions | undefined) => DefaultStringField;
394
+ } & {
395
+ getString: (name: string) => DefaultStringField;
396
+ } & {
397
+ createBoolean: (name: string, initialValue: boolean, options?: DefaultBooleanFieldOptions | undefined) => DefaultBooleanField;
398
+ } & {
399
+ upsetBoolean: (name: string, value: boolean, options?: DefaultBooleanFieldOptions | undefined) => DefaultBooleanField;
400
+ } & {
401
+ getBoolean: (name: string) => DefaultBooleanField;
402
+ }>;
437
403
  declare class DefaultFields extends DefaultFields_base {
438
404
  }
439
405
 
@@ -839,4 +805,4 @@ declare class FieldTreeSerializer<TFields extends Fields> {
839
805
  hydrate(snapshot: FieldTreeSnapshot): FieldTree<TFields>;
840
806
  }
841
807
 
842
- export { type BooleanField, ClampMaxPolicy, ClampMaxPolicySerializerHandler, ClampMinPolicy, ClampMinPolicySerializerHandler, ClampPolicy, ClampPolicySerializerHandler, DefaultBooleanField, type DefaultBooleanFieldOptions, DefaultField, DefaultFields, DefaultFieldsFactory, DefaultNumericField, type DefaultNumericFieldOptions, DefaultStringField, type DefaultStringFieldOptions, DefaultTreeNodeFactory, type Field, type FieldOptions, FieldRegistry, FieldSerializer, type FieldSnapshot, FieldTree, FieldTreeSerializer, type FieldTreeSnapshot, Fields, type FieldsFactory, FieldsSerializer, type FieldsSnapshot, type NumericField, Policies, type Policy, PolicySerializer, type PolicySerializerHandler, type StringField, type TreeNode, type TreeNodeFactory, clampMaxPolicy, clampMinPolicy, clampPolicy };
808
+ export { type BooleanField, ClampMaxPolicy, ClampMaxPolicySerializerHandler, ClampMinPolicy, ClampMinPolicySerializerHandler, ClampPolicy, ClampPolicySerializerHandler, DefaultBooleanField, type DefaultBooleanFieldOptions, DefaultField, DefaultFields, DefaultFieldsFactory, DefaultNumericField, type DefaultNumericFieldOptions, DefaultStringField, type DefaultStringFieldOptions, DefaultTreeNodeFactory, type Field, type FieldOptions, FieldRegistry, FieldSerializer, type FieldSnapshot, FieldTree, FieldTreeSerializer, type FieldTreeSnapshot, Fields, type FieldsFactory, FieldsSerializer, type FieldsSnapshot, type NumericField, Policies, type Policy, PolicySerializer, type PolicySerializerHandler, type StringField, type TreeNode, type TreeNodeFactory, clampMaxPolicy, clampMinPolicy, clampPolicy, createTypedMethodsMixin };
package/dist/index.js CHANGED
@@ -43,7 +43,8 @@ __export(index_exports, {
43
43
  PolicySerializer: () => PolicySerializer,
44
44
  clampMaxPolicy: () => clampMaxPolicy,
45
45
  clampMinPolicy: () => clampMinPolicy,
46
- clampPolicy: () => clampPolicy
46
+ clampPolicy: () => clampPolicy,
47
+ createTypedMethodsMixin: () => createTypedMethodsMixin
47
48
  });
48
49
  module.exports = __toCommonJS(index_exports);
49
50
 
@@ -166,6 +167,31 @@ var Policies = class {
166
167
  }
167
168
  };
168
169
 
170
+ // src/mixins/mixin-factory.ts
171
+ function createTypedMethodsMixin(typeName, baseMethodName) {
172
+ const methodNames = {
173
+ create: `create${baseMethodName}`,
174
+ upset: `upset${baseMethodName}`,
175
+ get: `get${baseMethodName}`
176
+ };
177
+ return function(Base) {
178
+ return class FieldsWith extends Base {
179
+ // createBoolean, createMySignal, etc.
180
+ [methodNames.create](name, initialValue, options) {
181
+ return this.create(typeName, name, initialValue, options);
182
+ }
183
+ // upsetBoolean, upsetMySignal, etc.
184
+ [methodNames.upset](name, value, options) {
185
+ return this.upset(typeName, name, value, options);
186
+ }
187
+ // getBoolean, getMySignal, etc.
188
+ [methodNames.get](name) {
189
+ return this.get(name);
190
+ }
191
+ };
192
+ };
193
+ }
194
+
169
195
  // src/field-definitions/default-field.ts
170
196
  var import_utils = require("@axi-engine/utils");
171
197
  var import_dequal = require("dequal");
@@ -500,49 +526,13 @@ var Fields = class _Fields {
500
526
  };
501
527
 
502
528
  // src/mixins/with-boolean-fields.mixin.ts
503
- function WithBooleanFields(Base) {
504
- return class FieldsWithBoolean extends Base {
505
- createBoolean(name, initialValue, options) {
506
- return this.create(DefaultBooleanField.typeName, name, initialValue, options);
507
- }
508
- upsetBoolean(name, value, options) {
509
- return this.upset(DefaultBooleanField.typeName, name, value, options);
510
- }
511
- getBoolean(name) {
512
- return this.get(name);
513
- }
514
- };
515
- }
529
+ var WithBooleanFields = createTypedMethodsMixin(DefaultBooleanField.typeName, "Boolean");
516
530
 
517
531
  // src/mixins/with-string-fields.mixin.ts
518
- function WithStringFields(Base) {
519
- return class FieldsWithString extends Base {
520
- createString(name, initialValue, options) {
521
- return this.create(DefaultStringField.typeName, name, initialValue, options);
522
- }
523
- upsetString(name, value, options) {
524
- return this.upset(DefaultStringField.typeName, name, value, options);
525
- }
526
- getString(name) {
527
- return this.get(name);
528
- }
529
- };
530
- }
532
+ var WithStringFields = createTypedMethodsMixin(DefaultBooleanField.typeName, "String");
531
533
 
532
534
  // src/mixins/with-numeric-fields.mixin.ts
533
- function WithNumericFields(Base) {
534
- return class FieldsWithNumeric extends Base {
535
- createNumeric(name, initialValue, options) {
536
- return this.create(DefaultNumericField.typeName, name, initialValue, options);
537
- }
538
- upsetNumeric(name, value, options) {
539
- return this.upset(DefaultNumericField.typeName, name, value, options);
540
- }
541
- getNumeric(name) {
542
- return this.get(name);
543
- }
544
- };
545
- }
535
+ var WithNumericFields = createTypedMethodsMixin(DefaultBooleanField.typeName, "Numeric");
546
536
 
547
537
  // src/mixins/with-default-generic-fields.mixin.ts
548
538
  function WithDefaultGenericFields(Base) {
@@ -1053,5 +1043,6 @@ var FieldTreeSerializer = class {
1053
1043
  PolicySerializer,
1054
1044
  clampMaxPolicy,
1055
1045
  clampMinPolicy,
1056
- clampPolicy
1046
+ clampPolicy,
1047
+ createTypedMethodsMixin
1057
1048
  });
package/dist/index.mjs CHANGED
@@ -117,6 +117,31 @@ var Policies = class {
117
117
  }
118
118
  };
119
119
 
120
+ // src/mixins/mixin-factory.ts
121
+ function createTypedMethodsMixin(typeName, baseMethodName) {
122
+ const methodNames = {
123
+ create: `create${baseMethodName}`,
124
+ upset: `upset${baseMethodName}`,
125
+ get: `get${baseMethodName}`
126
+ };
127
+ return function(Base) {
128
+ return class FieldsWith extends Base {
129
+ // createBoolean, createMySignal, etc.
130
+ [methodNames.create](name, initialValue, options) {
131
+ return this.create(typeName, name, initialValue, options);
132
+ }
133
+ // upsetBoolean, upsetMySignal, etc.
134
+ [methodNames.upset](name, value, options) {
135
+ return this.upset(typeName, name, value, options);
136
+ }
137
+ // getBoolean, getMySignal, etc.
138
+ [methodNames.get](name) {
139
+ return this.get(name);
140
+ }
141
+ };
142
+ };
143
+ }
144
+
120
145
  // src/field-definitions/default-field.ts
121
146
  import { Emitter } from "@axi-engine/utils";
122
147
  import { dequal } from "dequal";
@@ -451,49 +476,13 @@ var Fields = class _Fields {
451
476
  };
452
477
 
453
478
  // src/mixins/with-boolean-fields.mixin.ts
454
- function WithBooleanFields(Base) {
455
- return class FieldsWithBoolean extends Base {
456
- createBoolean(name, initialValue, options) {
457
- return this.create(DefaultBooleanField.typeName, name, initialValue, options);
458
- }
459
- upsetBoolean(name, value, options) {
460
- return this.upset(DefaultBooleanField.typeName, name, value, options);
461
- }
462
- getBoolean(name) {
463
- return this.get(name);
464
- }
465
- };
466
- }
479
+ var WithBooleanFields = createTypedMethodsMixin(DefaultBooleanField.typeName, "Boolean");
467
480
 
468
481
  // src/mixins/with-string-fields.mixin.ts
469
- function WithStringFields(Base) {
470
- return class FieldsWithString extends Base {
471
- createString(name, initialValue, options) {
472
- return this.create(DefaultStringField.typeName, name, initialValue, options);
473
- }
474
- upsetString(name, value, options) {
475
- return this.upset(DefaultStringField.typeName, name, value, options);
476
- }
477
- getString(name) {
478
- return this.get(name);
479
- }
480
- };
481
- }
482
+ var WithStringFields = createTypedMethodsMixin(DefaultBooleanField.typeName, "String");
482
483
 
483
484
  // src/mixins/with-numeric-fields.mixin.ts
484
- function WithNumericFields(Base) {
485
- return class FieldsWithNumeric extends Base {
486
- createNumeric(name, initialValue, options) {
487
- return this.create(DefaultNumericField.typeName, name, initialValue, options);
488
- }
489
- upsetNumeric(name, value, options) {
490
- return this.upset(DefaultNumericField.typeName, name, value, options);
491
- }
492
- getNumeric(name) {
493
- return this.get(name);
494
- }
495
- };
496
- }
485
+ var WithNumericFields = createTypedMethodsMixin(DefaultBooleanField.typeName, "Numeric");
497
486
 
498
487
  // src/mixins/with-default-generic-fields.mixin.ts
499
488
  function WithDefaultGenericFields(Base) {
@@ -1003,5 +992,6 @@ export {
1003
992
  PolicySerializer,
1004
993
  clampMaxPolicy,
1005
994
  clampMinPolicy,
1006
- clampPolicy
995
+ clampPolicy,
996
+ createTypedMethodsMixin
1007
997
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/fields",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "keywords": [