@xylabs/object-model 5.0.84 → 5.0.86

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.
Files changed (2) hide show
  1. package/README.md +148 -186
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
+
19
+
18
20
  ## Reference
19
21
 
20
22
  **@xylabs/object-model**
@@ -23,19 +25,23 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
23
25
 
24
26
  ## Interfaces
25
27
 
26
- - [TypeCheckConfig](#interfaces/TypeCheckConfig)
27
- - [TypeCheckRequiredConfig](#interfaces/TypeCheckRequiredConfig)
28
- - [TypeCheckOptionalConfig](#interfaces/TypeCheckOptionalConfig)
28
+ | Interface | Description |
29
+ | ------ | ------ |
30
+ | [TypeCheckConfig](#interfaces/TypeCheckConfig) | Configuration options for type check functions, with optional logging. |
31
+ | [TypeCheckRequiredConfig](#interfaces/TypeCheckRequiredConfig) | Type check configuration that marks the value as required, causing assertions on failure. |
32
+ | [TypeCheckOptionalConfig](#interfaces/TypeCheckOptionalConfig) | Type check configuration that marks the value as optional, returning undefined on failure. |
29
33
 
30
34
  ## Type Aliases
31
35
 
32
- - [AnyObject](#type-aliases/AnyObject)
33
- - [AsTypeFunction](#type-aliases/AsTypeFunction)
34
- - [AsOptionalTypeFunction](#type-aliases/AsOptionalTypeFunction)
35
- - [Compare](#type-aliases/Compare)
36
- - [EmptyObject](#type-aliases/EmptyObject)
37
- - [StringOrAlertFunction](#type-aliases/StringOrAlertFunction)
38
- - [TypeCheck](#type-aliases/TypeCheck)
36
+ | Type Alias | Description |
37
+ | ------ | ------ |
38
+ | [AnyObject](#type-aliases/AnyObject) | Any object, which means that it does not enforce the set of fields that it has. Extending from AnyObject will result in a type that includes the universal set of field names |
39
+ | [AsTypeFunction](#type-aliases/AsTypeFunction) | A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. |
40
+ | [AsOptionalTypeFunction](#type-aliases/AsOptionalTypeFunction) | A simplified type-narrowing function that returns T or undefined, without assertion support. |
41
+ | [Compare](#type-aliases/Compare) | A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. |
42
+ | [EmptyObject](#type-aliases/EmptyObject) | An empty object, which means that it does enforce the set of field names, defaulting to an empty set until extended from, which then adds only those additional fields |
43
+ | [StringOrAlertFunction](#type-aliases/StringOrAlertFunction) | A string message or function that produces an assertion error message for a failed type check. |
44
+ | [TypeCheck](#type-aliases/TypeCheck) | A type guard function that checks whether a value conforms to type T, with optional configuration. |
39
45
 
40
46
  ### interfaces
41
47
 
@@ -54,11 +60,9 @@ Configuration options for type check functions, with optional logging.
54
60
 
55
61
  ## Properties
56
62
 
57
- ### log?
58
-
59
- ```ts
60
- optional log: boolean | Logger;
61
- ```
63
+ | Property | Type |
64
+ | ------ | ------ |
65
+ | <a id="log"></a> `log?` | `boolean` \| `Logger` |
62
66
 
63
67
  ### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig
64
68
 
@@ -74,23 +78,10 @@ Type check configuration that marks the value as optional, returning undefined o
74
78
 
75
79
  ## Properties
76
80
 
77
- ### log?
78
-
79
- ```ts
80
- optional log: boolean | Logger;
81
- ```
82
-
83
- ### Inherited from
84
-
85
- [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
86
-
87
- ***
88
-
89
- ### required
90
-
91
- ```ts
92
- required: false;
93
- ```
81
+ | Property | Type | Inherited from |
82
+ | ------ | ------ | ------ |
83
+ | <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
84
+ | <a id="required"></a> `required` | `false` | - |
94
85
 
95
86
  ### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig
96
87
 
@@ -106,23 +97,10 @@ Type check configuration that marks the value as required, causing assertions on
106
97
 
107
98
  ## Properties
108
99
 
109
- ### log?
110
-
111
- ```ts
112
- optional log: boolean | Logger;
113
- ```
114
-
115
- ### Inherited from
116
-
117
- [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
118
-
119
- ***
120
-
121
- ### required
122
-
123
- ```ts
124
- required: true;
125
- ```
100
+ | Property | Type | Inherited from |
101
+ | ------ | ------ | ------ |
102
+ | <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
103
+ | <a id="required"></a> `required` | `true` | - |
126
104
 
127
105
  ### type-aliases
128
106
 
@@ -146,28 +124,28 @@ will result in a type that includes the universal set of field names
146
124
  ***
147
125
 
148
126
  ```ts
149
- type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
127
+ type AsOptionalTypeFunction<T> = <TType>(value: AnyNonPromise) => TType | undefined;
150
128
  ```
151
129
 
152
130
  A simplified type-narrowing function that returns T or undefined, without assertion support.
153
131
 
154
132
  ## Type Parameters
155
133
 
156
- ### T
157
-
158
- `T` *extends* `AnyNonPromise` = `AnyNonPromise`
134
+ | Type Parameter | Default type |
135
+ | ------ | ------ |
136
+ | `T` *extends* `AnyNonPromise` | `AnyNonPromise` |
159
137
 
160
138
  ## Type Parameters
161
139
 
162
- ### TType
163
-
164
- `TType` *extends* `AnyNonPromise`
140
+ | Type Parameter |
141
+ | ------ |
142
+ | `TType` *extends* `AnyNonPromise` |
165
143
 
166
144
  ## Parameters
167
145
 
168
- ### value
169
-
170
- `AnyNonPromise`
146
+ | Parameter | Type |
147
+ | ------ | ------ |
148
+ | `value` | `AnyNonPromise` |
171
149
 
172
150
  ## Returns
173
151
 
@@ -181,12 +159,16 @@ A simplified type-narrowing function that returns T or undefined, without assert
181
159
 
182
160
  ```ts
183
161
  type AsTypeFunction<T> = {
184
- <TType> (value): TType | undefined;
185
- <TType> (value, config): TType;
186
- <TType> (value, config): TType | undefined;
187
- <TType> (value, assert): TType | undefined;
188
- <TType> (value, assert, config): TType;
189
- <TType> (value, assert, config): TType | undefined;
162
+ <TType> (value: AnyNonPromise): TType | undefined;
163
+ <TType> (value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
164
+ <TType> (value: AnyNonPromise, config:
165
+ | TypeCheckConfig
166
+ | TypeCheckOptionalConfig): TType | undefined;
167
+ <TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
168
+ <TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckRequiredConfig): TType;
169
+ <TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config:
170
+ | TypeCheckConfig
171
+ | TypeCheckOptionalConfig): TType | undefined;
190
172
  };
191
173
  ```
192
174
 
@@ -194,27 +176,27 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
194
176
 
195
177
  ## Type Parameters
196
178
 
197
- ### T
198
-
199
- `T` *extends* `AnyNonPromise` = `AnyNonPromise`
179
+ | Type Parameter | Default type |
180
+ | ------ | ------ |
181
+ | `T` *extends* `AnyNonPromise` | `AnyNonPromise` |
200
182
 
201
183
  ## Call Signature
202
184
 
203
185
  ```ts
204
- <TType>(value): TType | undefined;
186
+ <TType>(value: AnyNonPromise): TType | undefined;
205
187
  ```
206
188
 
207
189
  ### Type Parameters
208
190
 
209
- ### TType
210
-
211
- `TType` *extends* `AnyNonPromise`
191
+ | Type Parameter |
192
+ | ------ |
193
+ | `TType` *extends* `AnyNonPromise` |
212
194
 
213
195
  ### Parameters
214
196
 
215
- ### value
216
-
217
- `AnyNonPromise`
197
+ | Parameter | Type |
198
+ | ------ | ------ |
199
+ | `value` | `AnyNonPromise` |
218
200
 
219
201
  ### Returns
220
202
 
@@ -223,24 +205,21 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
223
205
  ## Call Signature
224
206
 
225
207
  ```ts
226
- <TType>(value, config): TType;
208
+ <TType>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
227
209
  ```
228
210
 
229
211
  ### Type Parameters
230
212
 
231
- ### TType
232
-
233
- `TType` *extends* `AnyNonPromise`
213
+ | Type Parameter |
214
+ | ------ |
215
+ | `TType` *extends* `AnyNonPromise` |
234
216
 
235
217
  ### Parameters
236
218
 
237
- ### value
238
-
239
- `AnyNonPromise`
240
-
241
- ### config
242
-
243
- [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig)
219
+ | Parameter | Type |
220
+ | ------ | ------ |
221
+ | `value` | `AnyNonPromise` |
222
+ | `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) |
244
223
 
245
224
  ### Returns
246
225
 
@@ -249,24 +228,23 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
249
228
  ## Call Signature
250
229
 
251
230
  ```ts
252
- <TType>(value, config): TType | undefined;
231
+ <TType>(value: AnyNonPromise, config:
232
+ | TypeCheckConfig
233
+ | TypeCheckOptionalConfig): TType | undefined;
253
234
  ```
254
235
 
255
236
  ### Type Parameters
256
237
 
257
- ### TType
258
-
259
- `TType` *extends* `AnyNonPromise`
238
+ | Type Parameter |
239
+ | ------ |
240
+ | `TType` *extends* `AnyNonPromise` |
260
241
 
261
242
  ### Parameters
262
243
 
263
- ### value
264
-
265
- `AnyNonPromise`
266
-
267
- ### config
268
-
269
- [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig)
244
+ | Parameter | Type |
245
+ | ------ | ------ |
246
+ | `value` | `AnyNonPromise` |
247
+ | `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) |
270
248
 
271
249
  ### Returns
272
250
 
@@ -275,24 +253,21 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
275
253
  ## Call Signature
276
254
 
277
255
  ```ts
278
- <TType>(value, assert): TType | undefined;
256
+ <TType>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
279
257
  ```
280
258
 
281
259
  ### Type Parameters
282
260
 
283
- ### TType
284
-
285
- `TType` *extends* `AnyNonPromise`
261
+ | Type Parameter |
262
+ | ------ |
263
+ | `TType` *extends* `AnyNonPromise` |
286
264
 
287
265
  ### Parameters
288
266
 
289
- ### value
290
-
291
- `AnyNonPromise`
292
-
293
- ### assert
294
-
295
- [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
267
+ | Parameter | Type |
268
+ | ------ | ------ |
269
+ | `value` | `AnyNonPromise` |
270
+ | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
296
271
 
297
272
  ### Returns
298
273
 
@@ -302,30 +277,24 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
302
277
 
303
278
  ```ts
304
279
  <TType>(
305
- value,
306
- assert,
307
- config): TType;
280
+ value: AnyNonPromise,
281
+ assert: StringOrAlertFunction<TType>,
282
+ config: TypeCheckRequiredConfig): TType;
308
283
  ```
309
284
 
310
285
  ### Type Parameters
311
286
 
312
- ### TType
313
-
314
- `TType` *extends* `AnyNonPromise`
287
+ | Type Parameter |
288
+ | ------ |
289
+ | `TType` *extends* `AnyNonPromise` |
315
290
 
316
291
  ### Parameters
317
292
 
318
- ### value
319
-
320
- `AnyNonPromise`
321
-
322
- ### assert
323
-
324
- [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
325
-
326
- ### config
327
-
328
- [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig)
293
+ | Parameter | Type |
294
+ | ------ | ------ |
295
+ | `value` | `AnyNonPromise` |
296
+ | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
297
+ | `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) |
329
298
 
330
299
  ### Returns
331
300
 
@@ -335,30 +304,26 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
335
304
 
336
305
  ```ts
337
306
  <TType>(
338
- value,
339
- assert,
340
- config): TType | undefined;
307
+ value: AnyNonPromise,
308
+ assert: StringOrAlertFunction<TType>,
309
+ config:
310
+ | TypeCheckConfig
311
+ | TypeCheckOptionalConfig): TType | undefined;
341
312
  ```
342
313
 
343
314
  ### Type Parameters
344
315
 
345
- ### TType
346
-
347
- `TType` *extends* `AnyNonPromise`
316
+ | Type Parameter |
317
+ | ------ |
318
+ | `TType` *extends* `AnyNonPromise` |
348
319
 
349
320
  ### Parameters
350
321
 
351
- ### value
352
-
353
- `AnyNonPromise`
354
-
355
- ### assert
356
-
357
- [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
358
-
359
- ### config
360
-
361
- [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig)
322
+ | Parameter | Type |
323
+ | ------ | ------ |
324
+ | `value` | `AnyNonPromise` |
325
+ | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
326
+ | `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) |
362
327
 
363
328
  ### Returns
364
329
 
@@ -371,26 +336,23 @@ A type-narrowing function that attempts to cast a value to T, with optional asse
371
336
  ***
372
337
 
373
338
  ```ts
374
- type Compare<T> = (a, b) => number;
339
+ type Compare<T> = (a: T, b: T) => number;
375
340
  ```
376
341
 
377
342
  A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
378
343
 
379
344
  ## Type Parameters
380
345
 
381
- ### T
382
-
383
- `T`
346
+ | Type Parameter |
347
+ | ------ |
348
+ | `T` |
384
349
 
385
350
  ## Parameters
386
351
 
387
- ### a
388
-
389
- `T`
390
-
391
- ### b
392
-
393
- `T`
352
+ | Parameter | Type |
353
+ | ------ | ------ |
354
+ | `a` | `T` |
355
+ | `b` | `T` |
394
356
 
395
357
  ## Returns
396
358
 
@@ -403,7 +365,7 @@ A comparator function that returns a negative number if a < b, zero if a == b, a
403
365
  ***
404
366
 
405
367
  ```ts
406
- type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args) => unknown | null>;
368
+ type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args: unknown[]) => unknown | null>;
407
369
  ```
408
370
 
409
371
  An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
@@ -411,9 +373,9 @@ extended from, which then adds only those additional fields
411
373
 
412
374
  ## Type Parameters
413
375
 
414
- ### T
415
-
416
- `T` *extends* `object` = `object`
376
+ | Type Parameter | Default type |
377
+ | ------ | ------ |
378
+ | `T` *extends* `object` | `object` |
417
379
 
418
380
  ### <a id="StringOrAlertFunction"></a>StringOrAlertFunction
419
381
 
@@ -429,9 +391,9 @@ A string message or function that produces an assertion error message for a fail
429
391
 
430
392
  ## Type Parameters
431
393
 
432
- ### T
433
-
434
- `T` *extends* `AnyNonPromise`
394
+ | Type Parameter |
395
+ | ------ |
396
+ | `T` *extends* `AnyNonPromise` |
435
397
 
436
398
  ### <a id="TypeCheck"></a>TypeCheck
437
399
 
@@ -441,9 +403,12 @@ A string message or function that produces an assertion error message for a fail
441
403
 
442
404
  ```ts
443
405
  type TypeCheck<T> = {
444
- (obj): obj is T;
445
- (obj, config): obj is T;
446
- (obj, config): obj is T;
406
+ (obj: AnyNonPromise): obj is T;
407
+ (obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
408
+ (obj: AnyNonPromise, config:
409
+ | number
410
+ | TypeCheckConfig
411
+ | undefined): obj is T;
447
412
  };
448
413
  ```
449
414
 
@@ -451,21 +416,21 @@ A type guard function that checks whether a value conforms to type T, with optio
451
416
 
452
417
  ## Type Parameters
453
418
 
454
- ### T
455
-
456
- `T` *extends* `TypedValue`
419
+ | Type Parameter |
420
+ | ------ |
421
+ | `T` *extends* `TypedValue` |
457
422
 
458
423
  ## Call Signature
459
424
 
460
425
  ```ts
461
- (obj): obj is T;
426
+ (obj: AnyNonPromise): obj is T;
462
427
  ```
463
428
 
464
429
  ### Parameters
465
430
 
466
- ### obj
467
-
468
- `AnyNonPromise`
431
+ | Parameter | Type |
432
+ | ------ | ------ |
433
+ | `obj` | `AnyNonPromise` |
469
434
 
470
435
  ### Returns
471
436
 
@@ -474,18 +439,15 @@ A type guard function that checks whether a value conforms to type T, with optio
474
439
  ## Call Signature
475
440
 
476
441
  ```ts
477
- (obj, config): obj is T;
442
+ (obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
478
443
  ```
479
444
 
480
445
  ### Parameters
481
446
 
482
- ### obj
483
-
484
- `AnyNonPromise`
485
-
486
- ### config
487
-
488
- [`TypeCheckConfig`](#../interfaces/TypeCheckConfig)
447
+ | Parameter | Type |
448
+ | ------ | ------ |
449
+ | `obj` | `AnyNonPromise` |
450
+ | `config` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) |
489
451
 
490
452
  ### Returns
491
453
 
@@ -494,18 +456,18 @@ A type guard function that checks whether a value conforms to type T, with optio
494
456
  ## Call Signature
495
457
 
496
458
  ```ts
497
- (obj, config): obj is T;
459
+ (obj: AnyNonPromise, config:
460
+ | number
461
+ | TypeCheckConfig
462
+ | undefined): obj is T;
498
463
  ```
499
464
 
500
465
  ### Parameters
501
466
 
502
- ### obj
503
-
504
- `AnyNonPromise`
505
-
506
- ### config
507
-
508
- `number` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | `undefined`
467
+ | Parameter | Type |
468
+ | ------ | ------ |
469
+ | `obj` | `AnyNonPromise` |
470
+ | `config` | \| `number` \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| `undefined` |
509
471
 
510
472
  ### Returns
511
473
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/object-model",
3
- "version": "5.0.84",
3
+ "version": "5.0.86",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -35,14 +35,14 @@
35
35
  "!**/*.test.*"
36
36
  ],
37
37
  "dependencies": {
38
- "@xylabs/assert": "~5.0.84",
39
- "@xylabs/logger": "~5.0.84",
40
- "@xylabs/promise": "~5.0.84",
41
- "@xylabs/typeof": "~5.0.84"
38
+ "@xylabs/assert": "~5.0.86",
39
+ "@xylabs/logger": "~5.0.86",
40
+ "@xylabs/promise": "~5.0.86",
41
+ "@xylabs/typeof": "~5.0.86"
42
42
  },
43
43
  "devDependencies": {
44
- "@xylabs/ts-scripts-yarn3": "~7.4.13",
45
- "@xylabs/tsconfig": "~7.4.13",
44
+ "@xylabs/ts-scripts-yarn3": "~7.4.16",
45
+ "@xylabs/tsconfig": "~7.4.16",
46
46
  "typescript": "~5.9.3",
47
47
  "vitest": "~4.0.18"
48
48
  },