@axi-engine/fields 0.3.1 → 0.3.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _axi_engine_utils from '@axi-engine/utils';
2
- import { Constructor, Subscribable, Emitter, PathType } from '@axi-engine/utils';
2
+ import { Constructor, Subscribable, ConstructorRegistry, Emitter, PathType } from '@axi-engine/utils';
3
3
 
4
4
  interface Policy<T> {
5
5
  readonly id: string;
@@ -218,45 +218,6 @@ declare class CoreNumericField extends CoreField<number> implements NumericField
218
218
  dec(amount?: number): void;
219
219
  }
220
220
 
221
- /**
222
- * A generic registry for mapping string identifiers to class constructors.
223
- *
224
- * This utility is fundamental for building extensible systems like dependency injection containers,
225
- * factories, and serialization engines where types need to be dynamically resolved.
226
- *
227
- * @template T - A base type that all registered constructors must produce an instance of.
228
- */
229
- declare class ConstructorRegistry<T> {
230
- private readonly items;
231
- /**
232
- * Registers a constructor with a unique string identifier.
233
- *
234
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
235
- * @param ctor - The class constructor to register.
236
- * @returns The registry instance for chainable calls.
237
- * @throws If a constructor with the same `typeId` is already registered.
238
- */
239
- register(typeId: string, ctor: Constructor<T>): this;
240
- /**
241
- * Retrieves a constructor by its identifier.
242
- *
243
- * @param typeId - The identifier of the constructor to retrieve.
244
- * @returns The found class constructor.
245
- * @throws If no constructor is found for the given `typeId`.
246
- */
247
- get(typeId: string): Constructor<T>;
248
- /**
249
- * Checks if a constructor for a given identifier is registered.
250
- * @param typeId - The identifier to check.
251
- * @returns `true` if a constructor is registered, otherwise `false`.
252
- */
253
- has(typeId: string): boolean;
254
- /**
255
- * Clears all registered constructors from the registry.
256
- */
257
- clear(): void;
258
- }
259
-
260
221
  declare class FieldRegistry extends ConstructorRegistry<Field<any>> {
261
222
  }
262
223
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _axi_engine_utils from '@axi-engine/utils';
2
- import { Constructor, Subscribable, Emitter, PathType } from '@axi-engine/utils';
2
+ import { Constructor, Subscribable, ConstructorRegistry, Emitter, PathType } from '@axi-engine/utils';
3
3
 
4
4
  interface Policy<T> {
5
5
  readonly id: string;
@@ -218,45 +218,6 @@ declare class CoreNumericField extends CoreField<number> implements NumericField
218
218
  dec(amount?: number): void;
219
219
  }
220
220
 
221
- /**
222
- * A generic registry for mapping string identifiers to class constructors.
223
- *
224
- * This utility is fundamental for building extensible systems like dependency injection containers,
225
- * factories, and serialization engines where types need to be dynamically resolved.
226
- *
227
- * @template T - A base type that all registered constructors must produce an instance of.
228
- */
229
- declare class ConstructorRegistry<T> {
230
- private readonly items;
231
- /**
232
- * Registers a constructor with a unique string identifier.
233
- *
234
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
235
- * @param ctor - The class constructor to register.
236
- * @returns The registry instance for chainable calls.
237
- * @throws If a constructor with the same `typeId` is already registered.
238
- */
239
- register(typeId: string, ctor: Constructor<T>): this;
240
- /**
241
- * Retrieves a constructor by its identifier.
242
- *
243
- * @param typeId - The identifier of the constructor to retrieve.
244
- * @returns The found class constructor.
245
- * @throws If no constructor is found for the given `typeId`.
246
- */
247
- get(typeId: string): Constructor<T>;
248
- /**
249
- * Checks if a constructor for a given identifier is registered.
250
- * @param typeId - The identifier to check.
251
- * @returns `true` if a constructor is registered, otherwise `false`.
252
- */
253
- has(typeId: string): boolean;
254
- /**
255
- * Clears all registered constructors from the registry.
256
- */
257
- clear(): void;
258
- }
259
-
260
221
  declare class FieldRegistry extends ConstructorRegistry<Field<any>> {
261
222
  }
262
223
 
package/dist/index.js CHANGED
@@ -346,53 +346,9 @@ var CoreNumericField = class _CoreNumericField extends CoreField {
346
346
  }
347
347
  };
348
348
 
349
- // src/utils/constructor-registry.ts
350
- var import_utils3 = require("@axi-engine/utils");
351
- var ConstructorRegistry = class {
352
- items = /* @__PURE__ */ new Map();
353
- /**
354
- * Registers a constructor with a unique string identifier.
355
- *
356
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
357
- * @param ctor - The class constructor to register.
358
- * @returns The registry instance for chainable calls.
359
- * @throws If a constructor with the same `typeId` is already registered.
360
- */
361
- register(typeId, ctor) {
362
- (0, import_utils3.throwIf)(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
363
- this.items.set(typeId, ctor);
364
- return this;
365
- }
366
- /**
367
- * Retrieves a constructor by its identifier.
368
- *
369
- * @param typeId - The identifier of the constructor to retrieve.
370
- * @returns The found class constructor.
371
- * @throws If no constructor is found for the given `typeId`.
372
- */
373
- get(typeId) {
374
- const Ctor = this.items.get(typeId);
375
- (0, import_utils3.throwIfEmpty)(Ctor, `No constructor found for typeId '${typeId}'`);
376
- return Ctor;
377
- }
378
- /**
379
- * Checks if a constructor for a given identifier is registered.
380
- * @param typeId - The identifier to check.
381
- * @returns `true` if a constructor is registered, otherwise `false`.
382
- */
383
- has(typeId) {
384
- return this.items.has(typeId);
385
- }
386
- /**
387
- * Clears all registered constructors from the registry.
388
- */
389
- clear() {
390
- this.items.clear();
391
- }
392
- };
393
-
394
349
  // src/field-registry.ts
395
- var FieldRegistry = class extends ConstructorRegistry {
350
+ var import_utils3 = require("@axi-engine/utils");
351
+ var FieldRegistry = class extends import_utils3.ConstructorRegistry {
396
352
  };
397
353
 
398
354
  // src/fields.ts
package/dist/index.mjs CHANGED
@@ -289,57 +289,13 @@ var CoreNumericField = class _CoreNumericField extends CoreField {
289
289
  }
290
290
  };
291
291
 
292
- // src/utils/constructor-registry.ts
293
- import { throwIf, throwIfEmpty } from "@axi-engine/utils";
294
- var ConstructorRegistry = class {
295
- items = /* @__PURE__ */ new Map();
296
- /**
297
- * Registers a constructor with a unique string identifier.
298
- *
299
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
300
- * @param ctor - The class constructor to register.
301
- * @returns The registry instance for chainable calls.
302
- * @throws If a constructor with the same `typeId` is already registered.
303
- */
304
- register(typeId, ctor) {
305
- throwIf(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
306
- this.items.set(typeId, ctor);
307
- return this;
308
- }
309
- /**
310
- * Retrieves a constructor by its identifier.
311
- *
312
- * @param typeId - The identifier of the constructor to retrieve.
313
- * @returns The found class constructor.
314
- * @throws If no constructor is found for the given `typeId`.
315
- */
316
- get(typeId) {
317
- const Ctor = this.items.get(typeId);
318
- throwIfEmpty(Ctor, `No constructor found for typeId '${typeId}'`);
319
- return Ctor;
320
- }
321
- /**
322
- * Checks if a constructor for a given identifier is registered.
323
- * @param typeId - The identifier to check.
324
- * @returns `true` if a constructor is registered, otherwise `false`.
325
- */
326
- has(typeId) {
327
- return this.items.has(typeId);
328
- }
329
- /**
330
- * Clears all registered constructors from the registry.
331
- */
332
- clear() {
333
- this.items.clear();
334
- }
335
- };
336
-
337
292
  // src/field-registry.ts
293
+ import { ConstructorRegistry } from "@axi-engine/utils";
338
294
  var FieldRegistry = class extends ConstructorRegistry {
339
295
  };
340
296
 
341
297
  // src/fields.ts
342
- import { Emitter as Emitter2, throwIf as throwIf2 } from "@axi-engine/utils";
298
+ import { Emitter as Emitter2, throwIf } from "@axi-engine/utils";
343
299
  var Fields = class _Fields {
344
300
  static typeName = "fields";
345
301
  typeName = _Fields.typeName;
@@ -390,7 +346,7 @@ var Fields = class _Fields {
390
346
  * @throws If a field with the same name already exists.
391
347
  */
392
348
  add(field) {
393
- throwIf2(this.has(field.name), `Field with name '${field.name}' already exists`);
349
+ throwIf(this.has(field.name), `Field with name '${field.name}' already exists`);
394
350
  this._fields.set(field.name, field);
395
351
  this.onAdd.emit({
396
352
  name: field.name,
@@ -439,7 +395,7 @@ var Fields = class _Fields {
439
395
  * @throws If the field does not exist.
440
396
  */
441
397
  get(name) {
442
- throwIf2(!this._fields.has(name), `Field with name '${name}' not exists`);
398
+ throwIf(!this._fields.has(name), `Field with name '${name}' not exists`);
443
399
  return this._fields.get(name);
444
400
  }
445
401
  /**
@@ -476,7 +432,7 @@ var Fields = class _Fields {
476
432
  };
477
433
 
478
434
  // src/field-tree.ts
479
- import { Emitter as Emitter3, ensurePathArray, ensurePathString, throwIf as throwIf3, throwIfEmpty as throwIfEmpty2 } from "@axi-engine/utils";
435
+ import { Emitter as Emitter3, ensurePathArray, ensurePathString, throwIf as throwIf2, throwIfEmpty } from "@axi-engine/utils";
480
436
  var FieldTree = class _FieldTree {
481
437
  static typeName = "fieldTree";
482
438
  typeName = _FieldTree.typeName;
@@ -545,7 +501,7 @@ var FieldTree = class _FieldTree {
545
501
  * @throws If a node with the same name already exists.
546
502
  */
547
503
  addNode(name, node) {
548
- throwIf3(this.has(name), `Can't add node with name: '${name}', node already exists`);
504
+ throwIf2(this.has(name), `Can't add node with name: '${name}', node already exists`);
549
505
  this._nodes.set(name, node);
550
506
  this.onAdd.emit({ name, node });
551
507
  return node;
@@ -558,7 +514,7 @@ var FieldTree = class _FieldTree {
558
514
  */
559
515
  getNode(name) {
560
516
  const node = this._nodes.get(name);
561
- throwIfEmpty2(node, `Can't find node with name '${name}'`);
517
+ throwIfEmpty(node, `Can't find node with name '${name}'`);
562
518
  return node;
563
519
  }
564
520
  /**
@@ -574,7 +530,7 @@ var FieldTree = class _FieldTree {
574
530
  removeNode(names) {
575
531
  const toRemoveNames = Array.isArray(names) ? names : [names];
576
532
  toRemoveNames.forEach((name) => {
577
- throwIf3(!this.has(name), `Can't remove node with name: '${name}', node doesn't exists`);
533
+ throwIf2(!this.has(name), `Can't remove node with name: '${name}', node doesn't exists`);
578
534
  });
579
535
  toRemoveNames.forEach((name) => {
580
536
  this._nodes.get(name).destroy();
@@ -615,7 +571,7 @@ var FieldTree = class _FieldTree {
615
571
  getFieldTree(path) {
616
572
  const traversedPath = this.traversePath(path);
617
573
  const node = traversedPath.branch.getNode(traversedPath.leafName);
618
- throwIf3(
574
+ throwIf2(
619
575
  !(node instanceof _FieldTree),
620
576
  `Node with name: ${traversedPath.leafName} by path: '${ensurePathString(path)}' should be instance of FieldTree`
621
577
  );
@@ -630,7 +586,7 @@ var FieldTree = class _FieldTree {
630
586
  getFields(path) {
631
587
  const traversedPath = this.traversePath(path);
632
588
  const node = traversedPath.branch.getNode(traversedPath.leafName);
633
- throwIf3(
589
+ throwIf2(
634
590
  !(node instanceof Fields),
635
591
  `Node with name: ${traversedPath.leafName} by path: '${ensurePathString(path)}' should be instance of Fields`
636
592
  );
@@ -695,7 +651,7 @@ var FieldTree = class _FieldTree {
695
651
  */
696
652
  traversePath(path, createPath) {
697
653
  const pathArr = ensurePathArray(path);
698
- throwIfEmpty2(pathArr, "The path is empty");
654
+ throwIfEmpty(pathArr, "The path is empty");
699
655
  const leafName = pathArr.pop();
700
656
  let currentNode = this;
701
657
  for (const pathPart of pathArr) {
@@ -707,8 +663,8 @@ var FieldTree = class _FieldTree {
707
663
  node = currentNode.createFieldTree(pathPart);
708
664
  }
709
665
  }
710
- throwIfEmpty2(node, `Can't find node with name ${pathPart} by path parsing: ${ensurePathString(path)}`);
711
- throwIf3(node instanceof Fields, `Node with name ${pathPart} should be instance of FieldTree`);
666
+ throwIfEmpty(node, `Can't find node with name ${pathPart} by path parsing: ${ensurePathString(path)}`);
667
+ throwIf2(node instanceof Fields, `Node with name ${pathPart} should be instance of FieldTree`);
712
668
  currentNode = node;
713
669
  }
714
670
  return { branch: currentNode, leafName };
@@ -802,11 +758,11 @@ var ClampMinPolicySerializerHandler = class {
802
758
  };
803
759
 
804
760
  // src/serializer/policy-serializer.ts
805
- import { throwIf as throwIf4, throwIfEmpty as throwIfEmpty3 } from "@axi-engine/utils";
761
+ import { throwIf as throwIf3, throwIfEmpty as throwIfEmpty2 } from "@axi-engine/utils";
806
762
  var PolicySerializer = class {
807
763
  handlers = /* @__PURE__ */ new Map();
808
764
  register(policyId, handler) {
809
- throwIf4(this.handlers.has(policyId), `A handler for policy ID '${policyId}' is already registered.`);
765
+ throwIf3(this.handlers.has(policyId), `A handler for policy ID '${policyId}' is already registered.`);
810
766
  this.handlers.set(policyId, handler);
811
767
  return this;
812
768
  }
@@ -822,7 +778,7 @@ var PolicySerializer = class {
822
778
  */
823
779
  snapshot(policy) {
824
780
  const handler = this.handlers.get(policy.id);
825
- throwIfEmpty3(handler, `No serializer handler registered for policy ID: '${policy.id}'`);
781
+ throwIfEmpty2(handler, `No serializer handler registered for policy ID: '${policy.id}'`);
826
782
  const data = handler.snapshot(policy);
827
783
  return {
828
784
  __type: policy.id,
@@ -837,16 +793,16 @@ var PolicySerializer = class {
837
793
  */
838
794
  hydrate(snapshot) {
839
795
  const typeId = snapshot?.__type;
840
- throwIfEmpty3(typeId, 'Invalid policy snapshot: missing "__type" identifier.');
796
+ throwIfEmpty2(typeId, 'Invalid policy snapshot: missing "__type" identifier.');
841
797
  const handler = this.handlers.get(typeId);
842
- throwIfEmpty3(handler, `No serializer handler registered for policy ID: '${typeId}'`);
798
+ throwIfEmpty2(handler, `No serializer handler registered for policy ID: '${typeId}'`);
843
799
  const { __type, ...data } = snapshot;
844
800
  return handler.hydrate(data);
845
801
  }
846
802
  };
847
803
 
848
804
  // src/serializer/field-serializer.ts
849
- import { isNullOrUndefined as isNullOrUndefined2, throwIfEmpty as throwIfEmpty4 } from "@axi-engine/utils";
805
+ import { isNullOrUndefined as isNullOrUndefined2, throwIfEmpty as throwIfEmpty3 } from "@axi-engine/utils";
850
806
  var FieldSerializer = class {
851
807
  /**
852
808
  * Creates an instance of FieldSerializer.
@@ -886,7 +842,7 @@ var FieldSerializer = class {
886
842
  */
887
843
  hydrate(snapshot) {
888
844
  const fieldType = snapshot.__type;
889
- throwIfEmpty4(fieldType, 'Invalid field snapshot: missing "__type" identifier.');
845
+ throwIfEmpty3(fieldType, 'Invalid field snapshot: missing "__type" identifier.');
890
846
  const Ctor = this.fieldRegistry.get(fieldType);
891
847
  let policies;
892
848
  if (!isNullOrUndefined2(snapshot.policies)) {
@@ -1011,7 +967,7 @@ var StringFieldResolver = class {
1011
967
  };
1012
968
 
1013
969
  // src/data-store.ts
1014
- import { ensurePathArray as ensurePathArray2, ensurePathString as ensurePathString2, throwIfEmpty as throwIfEmpty5 } from "@axi-engine/utils";
970
+ import { ensurePathArray as ensurePathArray2, ensurePathString as ensurePathString2, throwIfEmpty as throwIfEmpty4 } from "@axi-engine/utils";
1015
971
  var DataStore = class {
1016
972
  constructor(tree) {
1017
973
  this.tree = tree;
@@ -1096,7 +1052,7 @@ var DataStore = class {
1096
1052
  }
1097
1053
  getField(path) {
1098
1054
  const pathArr = ensurePathArray2(path);
1099
- throwIfEmpty5(pathArr, `Wrong path or path is empty: ${ensurePathString2(path)}, should contain at least one path segment`);
1055
+ throwIfEmpty4(pathArr, `Wrong path or path is empty: ${ensurePathString2(path)}, should contain at least one path segment`);
1100
1056
  if (this.isPathToRootFields(pathArr)) {
1101
1057
  return this.rootFields.get(pathArr[0]);
1102
1058
  }
@@ -1118,7 +1074,7 @@ var DataStore = class {
1118
1074
  }
1119
1075
  remove(path) {
1120
1076
  const pathArr = ensurePathArray2(path);
1121
- throwIfEmpty5(pathArr, `Wrong path or path is empty: ${ensurePathString2(path)}, should contain at least one path segment`);
1077
+ throwIfEmpty4(pathArr, `Wrong path or path is empty: ${ensurePathString2(path)}, should contain at least one path segment`);
1122
1078
  if (this.isPathToRootFields(pathArr)) {
1123
1079
  this.rootFields.remove(pathArr);
1124
1080
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/fields",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -31,9 +31,9 @@
31
31
  "dequal": "^2.0.3"
32
32
  },
33
33
  "devDependencies": {
34
- "@axi-engine/utils": "^0.1.6"
34
+ "@axi-engine/utils": "^0.1.7"
35
35
  },
36
36
  "peerDependencies": {
37
- "@axi-engine/utils": "^0.1.6"
37
+ "@axi-engine/utils": "^0.1.7"
38
38
  }
39
39
  }