@axi-engine/utils 0.2.3 → 0.2.5

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
@@ -155,6 +155,11 @@ declare function throwIf(condition: boolean, exceptionMessage: string): asserts
155
155
  * console.log('First item:', items[0]);
156
156
  */
157
157
  declare function throwIfEmpty<T>(value: T, exceptionMessage: string): asserts value is NonNullable<T>;
158
+ /**
159
+ * Throws an error unconditionally.
160
+ * @param message The message for the error.
161
+ */
162
+ declare function throwError(message: string): never;
158
163
 
159
164
  interface AxiEngineConfig {
160
165
  pathSeparator: string;
@@ -210,14 +215,54 @@ declare class ConstructorRegistry<T> {
210
215
  */
211
216
  interface DataSource {
212
217
  get(path: PathType): unknown;
218
+ /**
219
+ * Checks if a path valid.
220
+ * @param {PathType} path The path to the node.
221
+ * @returns {boolean} `true` if the node exists, otherwise `false`.
222
+ */
213
223
  has(path: PathType): boolean;
214
224
  }
215
225
  /**
216
- * A write-only contract for any system that can accept data by path.
226
+ * A write-only contract for any system that can accept or mutate data by path.
227
+ *
228
+ * This interface is the counterpart to `DataSource` and represents the "write" side
229
+ * of a complete data storage system. It provides a standard set of methods for
230
+ * creating, updating, and deleting data, abstracting away the underlying
231
+ * implementation details.
232
+ *
233
+ * @interface
217
234
  */
218
235
  interface DataSink {
236
+ /**
237
+ * Strictly updates the value at an *existing* path.
238
+ * This operation should typically fail or throw an error if no value exists at the path.
239
+ *
240
+ * @param path The path to the value to be updated.
241
+ * @param value The new value to set.
242
+ */
219
243
  set(path: PathType, value: unknown): void;
244
+ /**
245
+ * Strictly creates a new value at the specified path.
246
+ * This operation should typically fail or throw an error if a value already exists
247
+ * at the path.
248
+ *
249
+ * @param path The full path where the new value will be created.
250
+ * @param value The initial value to create.
251
+ */
220
252
  create(path: PathType, value: unknown): void;
253
+ /**
254
+ * Updates a value at a specified path if it exists, or creates it if it does not.
255
+ * This is a convenient and non-strict combination of the `set` and `create` operations.
256
+ *
257
+ * @param path The path to the value to be created or updated.
258
+ * @param value The value to set.
259
+ */
260
+ upset(path: PathType, value: unknown): void;
261
+ /**
262
+ * Deletes the value at the specified path.
263
+ *
264
+ * @param path The path to the value to be deleted.
265
+ */
221
266
  delete(path: PathType): void;
222
267
  }
223
268
  /**
@@ -324,4 +369,4 @@ declare function randInt(min: number, max: number): number;
324
369
  */
325
370
  declare function randId(): string;
326
371
 
327
- 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, throwIf, throwIfEmpty, unique };
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 };
package/dist/index.d.ts CHANGED
@@ -155,6 +155,11 @@ declare function throwIf(condition: boolean, exceptionMessage: string): asserts
155
155
  * console.log('First item:', items[0]);
156
156
  */
157
157
  declare function throwIfEmpty<T>(value: T, exceptionMessage: string): asserts value is NonNullable<T>;
158
+ /**
159
+ * Throws an error unconditionally.
160
+ * @param message The message for the error.
161
+ */
162
+ declare function throwError(message: string): never;
158
163
 
159
164
  interface AxiEngineConfig {
160
165
  pathSeparator: string;
@@ -210,14 +215,54 @@ declare class ConstructorRegistry<T> {
210
215
  */
211
216
  interface DataSource {
212
217
  get(path: PathType): unknown;
218
+ /**
219
+ * Checks if a path valid.
220
+ * @param {PathType} path The path to the node.
221
+ * @returns {boolean} `true` if the node exists, otherwise `false`.
222
+ */
213
223
  has(path: PathType): boolean;
214
224
  }
215
225
  /**
216
- * A write-only contract for any system that can accept data by path.
226
+ * A write-only contract for any system that can accept or mutate data by path.
227
+ *
228
+ * This interface is the counterpart to `DataSource` and represents the "write" side
229
+ * of a complete data storage system. It provides a standard set of methods for
230
+ * creating, updating, and deleting data, abstracting away the underlying
231
+ * implementation details.
232
+ *
233
+ * @interface
217
234
  */
218
235
  interface DataSink {
236
+ /**
237
+ * Strictly updates the value at an *existing* path.
238
+ * This operation should typically fail or throw an error if no value exists at the path.
239
+ *
240
+ * @param path The path to the value to be updated.
241
+ * @param value The new value to set.
242
+ */
219
243
  set(path: PathType, value: unknown): void;
244
+ /**
245
+ * Strictly creates a new value at the specified path.
246
+ * This operation should typically fail or throw an error if a value already exists
247
+ * at the path.
248
+ *
249
+ * @param path The full path where the new value will be created.
250
+ * @param value The initial value to create.
251
+ */
220
252
  create(path: PathType, value: unknown): void;
253
+ /**
254
+ * Updates a value at a specified path if it exists, or creates it if it does not.
255
+ * This is a convenient and non-strict combination of the `set` and `create` operations.
256
+ *
257
+ * @param path The path to the value to be created or updated.
258
+ * @param value The value to set.
259
+ */
260
+ upset(path: PathType, value: unknown): void;
261
+ /**
262
+ * Deletes the value at the specified path.
263
+ *
264
+ * @param path The path to the value to be deleted.
265
+ */
221
266
  delete(path: PathType): void;
222
267
  }
223
268
  /**
@@ -324,4 +369,4 @@ declare function randInt(min: number, max: number): number;
324
369
  */
325
370
  declare function randId(): string;
326
371
 
327
- 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, throwIf, throwIfEmpty, unique };
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 };
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ __export(index_exports, {
46
46
  randId: () => randId,
47
47
  randInt: () => randInt,
48
48
  shuffleArray: () => shuffleArray,
49
+ throwError: () => throwError,
49
50
  throwIf: () => throwIf,
50
51
  throwIfEmpty: () => throwIfEmpty,
51
52
  unique: () => unique
@@ -137,6 +138,9 @@ function throwIfEmpty(value, exceptionMessage) {
137
138
  throw new Error(exceptionMessage);
138
139
  }
139
140
  }
141
+ function throwError(message) {
142
+ throw new Error(message);
143
+ }
140
144
 
141
145
  // src/config.ts
142
146
  var defaultConfig = {
@@ -290,6 +294,7 @@ function randId() {
290
294
  randId,
291
295
  randInt,
292
296
  shuffleArray,
297
+ throwError,
293
298
  throwIf,
294
299
  throwIfEmpty,
295
300
  unique
package/dist/index.mjs CHANGED
@@ -83,6 +83,9 @@ function throwIfEmpty(value, exceptionMessage) {
83
83
  throw new Error(exceptionMessage);
84
84
  }
85
85
  }
86
+ function throwError(message) {
87
+ throw new Error(message);
88
+ }
86
89
 
87
90
  // src/config.ts
88
91
  var defaultConfig = {
@@ -235,6 +238,7 @@ export {
235
238
  randId,
236
239
  randInt,
237
240
  shuffleArray,
241
+ throwError,
238
242
  throwIf,
239
243
  throwIfEmpty,
240
244
  unique
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/utils",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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": {