@axi-engine/utils 0.2.5 → 0.2.6

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
@@ -171,45 +171,6 @@ declare const axiSettings: AxiEngineConfig;
171
171
  */
172
172
  declare function configure(newConfig: Partial<AxiEngineConfig>): void;
173
173
 
174
- /**
175
- * A generic registry for mapping string identifiers to class constructors.
176
- *
177
- * This utility is fundamental for building extensible systems like dependency injection containers,
178
- * factories, and serialization engines where types need to be dynamically resolved.
179
- *
180
- * @template T - A base type that all registered constructors must produce an instance of.
181
- */
182
- declare class ConstructorRegistry<T> {
183
- private readonly items;
184
- /**
185
- * Registers a constructor with a unique string identifier.
186
- *
187
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
188
- * @param ctor - The class constructor to register.
189
- * @returns The registry instance for chainable calls.
190
- * @throws If a constructor with the same `typeId` is already registered.
191
- */
192
- register(typeId: string, ctor: Constructor<T>): this;
193
- /**
194
- * Retrieves a constructor by its identifier.
195
- *
196
- * @param typeId - The identifier of the constructor to retrieve.
197
- * @returns The found class constructor.
198
- * @throws If no constructor is found for the given `typeId`.
199
- */
200
- get(typeId: string): Constructor<T>;
201
- /**
202
- * Checks if a constructor for a given identifier is registered.
203
- * @param typeId - The identifier to check.
204
- * @returns `true` if a constructor is registered, otherwise `false`.
205
- */
206
- has(typeId: string): boolean;
207
- /**
208
- * Clears all registered constructors from the registry.
209
- */
210
- clear(): void;
211
- }
212
-
213
174
  /**
214
175
  * A read-only contract for any system that can provide data by path.
215
176
  */
@@ -369,4 +330,46 @@ declare function randInt(min: number, max: number): number;
369
330
  */
370
331
  declare function randId(): string;
371
332
 
372
- export { type AxiEngineConfig, type Constructor, ConstructorRegistry, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNull, isNullOrUndefined, isNumber, isPercentageString, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
333
+ /**
334
+ * A generic, type-safe wrapper around a Map for managing collections of items by key.
335
+ * This class provides a consistent API for registering, retrieving, and checking for
336
+ * the existence of items.
337
+ *
338
+ * @template K - The type of the key (must be a string).
339
+ * @template V - The type of the value being stored.
340
+ */
341
+ declare class Registry<K extends string, V> {
342
+ protected readonly items: Map<K, V>;
343
+ /**
344
+ * Registers an item with a specific key.
345
+ * Warns if an item with the same key is already registered.
346
+ * @param key The key to associate with the item.
347
+ * @param value The item to register.
348
+ */
349
+ register(key: K, value: V): void;
350
+ /**
351
+ * Checks if an item with the given key is registered.
352
+ * @param key The key to check.
353
+ */
354
+ has(key: K): boolean;
355
+ /**
356
+ * Retrieves an item by its key.
357
+ * @param key The key of the item to retrieve.
358
+ * @returns The item, or `undefined` if not found.
359
+ */
360
+ get(key: K): V | undefined;
361
+ /**
362
+ * Retrieves an item by its key, throwing an error if it's not found.
363
+ * @param key The key of the item to retrieve.
364
+ * @returns The item.
365
+ * @throws {Error} if no item is found for the given key.
366
+ */
367
+ getOrThrow(key: K): V;
368
+ delete(key: K): boolean;
369
+ /**
370
+ * Clears all registered items from the registry.
371
+ */
372
+ clear(): void;
373
+ }
374
+
375
+ export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNull, isNullOrUndefined, isNumber, isPercentageString, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
package/dist/index.d.ts CHANGED
@@ -171,45 +171,6 @@ declare const axiSettings: AxiEngineConfig;
171
171
  */
172
172
  declare function configure(newConfig: Partial<AxiEngineConfig>): void;
173
173
 
174
- /**
175
- * A generic registry for mapping string identifiers to class constructors.
176
- *
177
- * This utility is fundamental for building extensible systems like dependency injection containers,
178
- * factories, and serialization engines where types need to be dynamically resolved.
179
- *
180
- * @template T - A base type that all registered constructors must produce an instance of.
181
- */
182
- declare class ConstructorRegistry<T> {
183
- private readonly items;
184
- /**
185
- * Registers a constructor with a unique string identifier.
186
- *
187
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
188
- * @param ctor - The class constructor to register.
189
- * @returns The registry instance for chainable calls.
190
- * @throws If a constructor with the same `typeId` is already registered.
191
- */
192
- register(typeId: string, ctor: Constructor<T>): this;
193
- /**
194
- * Retrieves a constructor by its identifier.
195
- *
196
- * @param typeId - The identifier of the constructor to retrieve.
197
- * @returns The found class constructor.
198
- * @throws If no constructor is found for the given `typeId`.
199
- */
200
- get(typeId: string): Constructor<T>;
201
- /**
202
- * Checks if a constructor for a given identifier is registered.
203
- * @param typeId - The identifier to check.
204
- * @returns `true` if a constructor is registered, otherwise `false`.
205
- */
206
- has(typeId: string): boolean;
207
- /**
208
- * Clears all registered constructors from the registry.
209
- */
210
- clear(): void;
211
- }
212
-
213
174
  /**
214
175
  * A read-only contract for any system that can provide data by path.
215
176
  */
@@ -369,4 +330,46 @@ declare function randInt(min: number, max: number): number;
369
330
  */
370
331
  declare function randId(): string;
371
332
 
372
- export { type AxiEngineConfig, type Constructor, ConstructorRegistry, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNull, isNullOrUndefined, isNumber, isPercentageString, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
333
+ /**
334
+ * A generic, type-safe wrapper around a Map for managing collections of items by key.
335
+ * This class provides a consistent API for registering, retrieving, and checking for
336
+ * the existence of items.
337
+ *
338
+ * @template K - The type of the key (must be a string).
339
+ * @template V - The type of the value being stored.
340
+ */
341
+ declare class Registry<K extends string, V> {
342
+ protected readonly items: Map<K, V>;
343
+ /**
344
+ * Registers an item with a specific key.
345
+ * Warns if an item with the same key is already registered.
346
+ * @param key The key to associate with the item.
347
+ * @param value The item to register.
348
+ */
349
+ register(key: K, value: V): void;
350
+ /**
351
+ * Checks if an item with the given key is registered.
352
+ * @param key The key to check.
353
+ */
354
+ has(key: K): boolean;
355
+ /**
356
+ * Retrieves an item by its key.
357
+ * @param key The key of the item to retrieve.
358
+ * @returns The item, or `undefined` if not found.
359
+ */
360
+ get(key: K): V | undefined;
361
+ /**
362
+ * Retrieves an item by its key, throwing an error if it's not found.
363
+ * @param key The key of the item to retrieve.
364
+ * @returns The item.
365
+ * @throws {Error} if no item is found for the given key.
366
+ */
367
+ getOrThrow(key: K): V;
368
+ delete(key: K): boolean;
369
+ /**
370
+ * Clears all registered items from the registry.
371
+ */
372
+ clear(): void;
373
+ }
374
+
375
+ export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNull, isNullOrUndefined, isNumber, isPercentageString, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
package/dist/index.js CHANGED
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- ConstructorRegistry: () => ConstructorRegistry,
24
23
  Emitter: () => Emitter,
24
+ Registry: () => Registry,
25
25
  areArraysEqual: () => areArraysEqual,
26
26
  axiSettings: () => axiSettings,
27
27
  clampNumber: () => clampNumber,
@@ -151,50 +151,6 @@ function configure(newConfig) {
151
151
  Object.assign(axiSettings, newConfig);
152
152
  }
153
153
 
154
- // src/constructor-registry.ts
155
- var ConstructorRegistry = class {
156
- items = /* @__PURE__ */ new Map();
157
- /**
158
- * Registers a constructor with a unique string identifier.
159
- *
160
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
161
- * @param ctor - The class constructor to register.
162
- * @returns The registry instance for chainable calls.
163
- * @throws If a constructor with the same `typeId` is already registered.
164
- */
165
- register(typeId, ctor) {
166
- throwIf(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
167
- this.items.set(typeId, ctor);
168
- return this;
169
- }
170
- /**
171
- * Retrieves a constructor by its identifier.
172
- *
173
- * @param typeId - The identifier of the constructor to retrieve.
174
- * @returns The found class constructor.
175
- * @throws If no constructor is found for the given `typeId`.
176
- */
177
- get(typeId) {
178
- const Ctor = this.items.get(typeId);
179
- throwIfEmpty(Ctor, `No constructor found for typeId '${typeId}'`);
180
- return Ctor;
181
- }
182
- /**
183
- * Checks if a constructor for a given identifier is registered.
184
- * @param typeId - The identifier to check.
185
- * @returns `true` if a constructor is registered, otherwise `false`.
186
- */
187
- has(typeId) {
188
- return this.items.has(typeId);
189
- }
190
- /**
191
- * Clears all registered constructors from the registry.
192
- */
193
- clear() {
194
- this.items.clear();
195
- }
196
- };
197
-
198
154
  // src/emitter.ts
199
155
  var Emitter = class {
200
156
  listeners = /* @__PURE__ */ new Set();
@@ -266,10 +222,60 @@ function randInt(min, max) {
266
222
  function randId() {
267
223
  return (0, import_uuid.v4)();
268
224
  }
225
+
226
+ // src/registry.ts
227
+ var Registry = class {
228
+ items = /* @__PURE__ */ new Map();
229
+ /**
230
+ * Registers an item with a specific key.
231
+ * Warns if an item with the same key is already registered.
232
+ * @param key The key to associate with the item.
233
+ * @param value The item to register.
234
+ */
235
+ register(key, value) {
236
+ throwIf(this.items.has(key), `An item with the key '${key}' is already registered and will be overwritten.`);
237
+ this.items.set(key, value);
238
+ }
239
+ /**
240
+ * Checks if an item with the given key is registered.
241
+ * @param key The key to check.
242
+ */
243
+ has(key) {
244
+ return this.items.has(key);
245
+ }
246
+ /**
247
+ * Retrieves an item by its key.
248
+ * @param key The key of the item to retrieve.
249
+ * @returns The item, or `undefined` if not found.
250
+ */
251
+ get(key) {
252
+ return this.items.get(key);
253
+ }
254
+ /**
255
+ * Retrieves an item by its key, throwing an error if it's not found.
256
+ * @param key The key of the item to retrieve.
257
+ * @returns The item.
258
+ * @throws {Error} if no item is found for the given key.
259
+ */
260
+ getOrThrow(key) {
261
+ const item = this.get(key);
262
+ throwIfEmpty(item, `No item registered for the key '${key}'.`);
263
+ return item;
264
+ }
265
+ delete(key) {
266
+ return this.items.delete(key);
267
+ }
268
+ /**
269
+ * Clears all registered items from the registry.
270
+ */
271
+ clear() {
272
+ this.items.clear();
273
+ }
274
+ };
269
275
  // Annotate the CommonJS export names for ESM import in node:
270
276
  0 && (module.exports = {
271
- ConstructorRegistry,
272
277
  Emitter,
278
+ Registry,
273
279
  areArraysEqual,
274
280
  axiSettings,
275
281
  clampNumber,
package/dist/index.mjs CHANGED
@@ -96,50 +96,6 @@ function configure(newConfig) {
96
96
  Object.assign(axiSettings, newConfig);
97
97
  }
98
98
 
99
- // src/constructor-registry.ts
100
- var ConstructorRegistry = class {
101
- items = /* @__PURE__ */ new Map();
102
- /**
103
- * Registers a constructor with a unique string identifier.
104
- *
105
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
106
- * @param ctor - The class constructor to register.
107
- * @returns The registry instance for chainable calls.
108
- * @throws If a constructor with the same `typeId` is already registered.
109
- */
110
- register(typeId, ctor) {
111
- throwIf(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
112
- this.items.set(typeId, ctor);
113
- return this;
114
- }
115
- /**
116
- * Retrieves a constructor by its identifier.
117
- *
118
- * @param typeId - The identifier of the constructor to retrieve.
119
- * @returns The found class constructor.
120
- * @throws If no constructor is found for the given `typeId`.
121
- */
122
- get(typeId) {
123
- const Ctor = this.items.get(typeId);
124
- throwIfEmpty(Ctor, `No constructor found for typeId '${typeId}'`);
125
- return Ctor;
126
- }
127
- /**
128
- * Checks if a constructor for a given identifier is registered.
129
- * @param typeId - The identifier to check.
130
- * @returns `true` if a constructor is registered, otherwise `false`.
131
- */
132
- has(typeId) {
133
- return this.items.has(typeId);
134
- }
135
- /**
136
- * Clears all registered constructors from the registry.
137
- */
138
- clear() {
139
- this.items.clear();
140
- }
141
- };
142
-
143
99
  // src/emitter.ts
144
100
  var Emitter = class {
145
101
  listeners = /* @__PURE__ */ new Set();
@@ -211,9 +167,59 @@ function randInt(min, max) {
211
167
  function randId() {
212
168
  return uuidv4();
213
169
  }
170
+
171
+ // src/registry.ts
172
+ var Registry = class {
173
+ items = /* @__PURE__ */ new Map();
174
+ /**
175
+ * Registers an item with a specific key.
176
+ * Warns if an item with the same key is already registered.
177
+ * @param key The key to associate with the item.
178
+ * @param value The item to register.
179
+ */
180
+ register(key, value) {
181
+ throwIf(this.items.has(key), `An item with the key '${key}' is already registered and will be overwritten.`);
182
+ this.items.set(key, value);
183
+ }
184
+ /**
185
+ * Checks if an item with the given key is registered.
186
+ * @param key The key to check.
187
+ */
188
+ has(key) {
189
+ return this.items.has(key);
190
+ }
191
+ /**
192
+ * Retrieves an item by its key.
193
+ * @param key The key of the item to retrieve.
194
+ * @returns The item, or `undefined` if not found.
195
+ */
196
+ get(key) {
197
+ return this.items.get(key);
198
+ }
199
+ /**
200
+ * Retrieves an item by its key, throwing an error if it's not found.
201
+ * @param key The key of the item to retrieve.
202
+ * @returns The item.
203
+ * @throws {Error} if no item is found for the given key.
204
+ */
205
+ getOrThrow(key) {
206
+ const item = this.get(key);
207
+ throwIfEmpty(item, `No item registered for the key '${key}'.`);
208
+ return item;
209
+ }
210
+ delete(key) {
211
+ return this.items.delete(key);
212
+ }
213
+ /**
214
+ * Clears all registered items from the registry.
215
+ */
216
+ clear() {
217
+ this.items.clear();
218
+ }
219
+ };
214
220
  export {
215
- ConstructorRegistry,
216
221
  Emitter,
222
+ Registry,
217
223
  areArraysEqual,
218
224
  axiSettings,
219
225
  clampNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/utils",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Core utility library for Axi Engine, providing common functions for arrays, math, type guards, and more.",
5
5
  "license": "MIT",
6
6
  "repository": {