@xylabs/object-model 5.0.82 → 5.0.84
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/README.md
CHANGED
|
@@ -45,6 +45,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
45
45
|
|
|
46
46
|
***
|
|
47
47
|
|
|
48
|
+
Configuration options for type check functions, with optional logging.
|
|
49
|
+
|
|
48
50
|
## Extended by
|
|
49
51
|
|
|
50
52
|
- [`TypeCheckRequiredConfig`](#TypeCheckRequiredConfig)
|
|
@@ -64,6 +66,8 @@ optional log: boolean | Logger;
|
|
|
64
66
|
|
|
65
67
|
***
|
|
66
68
|
|
|
69
|
+
Type check configuration that marks the value as optional, returning undefined on failure.
|
|
70
|
+
|
|
67
71
|
## Extends
|
|
68
72
|
|
|
69
73
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
@@ -94,6 +98,8 @@ required: false;
|
|
|
94
98
|
|
|
95
99
|
***
|
|
96
100
|
|
|
101
|
+
Type check configuration that marks the value as required, causing assertions on failure.
|
|
102
|
+
|
|
97
103
|
## Extends
|
|
98
104
|
|
|
99
105
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
@@ -143,6 +149,8 @@ will result in a type that includes the universal set of field names
|
|
|
143
149
|
type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
|
|
144
150
|
```
|
|
145
151
|
|
|
152
|
+
A simplified type-narrowing function that returns T or undefined, without assertion support.
|
|
153
|
+
|
|
146
154
|
## Type Parameters
|
|
147
155
|
|
|
148
156
|
### T
|
|
@@ -182,6 +190,8 @@ type AsTypeFunction<T> = {
|
|
|
182
190
|
};
|
|
183
191
|
```
|
|
184
192
|
|
|
193
|
+
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
|
|
194
|
+
|
|
185
195
|
## Type Parameters
|
|
186
196
|
|
|
187
197
|
### T
|
|
@@ -364,6 +374,8 @@ type AsTypeFunction<T> = {
|
|
|
364
374
|
type Compare<T> = (a, b) => number;
|
|
365
375
|
```
|
|
366
376
|
|
|
377
|
+
A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
|
|
378
|
+
|
|
367
379
|
## Type Parameters
|
|
368
380
|
|
|
369
381
|
### T
|
|
@@ -413,6 +425,8 @@ extended from, which then adds only those additional fields
|
|
|
413
425
|
type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
|
|
414
426
|
```
|
|
415
427
|
|
|
428
|
+
A string message or function that produces an assertion error message for a failed type check.
|
|
429
|
+
|
|
416
430
|
## Type Parameters
|
|
417
431
|
|
|
418
432
|
### T
|
|
@@ -433,6 +447,8 @@ type TypeCheck<T> = {
|
|
|
433
447
|
};
|
|
434
448
|
```
|
|
435
449
|
|
|
450
|
+
A type guard function that checks whether a value conforms to type T, with optional configuration.
|
|
451
|
+
|
|
436
452
|
## Type Parameters
|
|
437
453
|
|
|
438
454
|
### T
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { AnyNonPromise } from '@xylabs/promise';
|
|
2
2
|
import type { AsTypeFunction } from './AsTypeFunction.ts';
|
|
3
3
|
import type { TypeCheck } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.
|
|
6
|
+
* Supports optional assertion messages and configuration for required/optional behavior.
|
|
7
|
+
*/
|
|
4
8
|
export declare const AsTypeFactory: {
|
|
5
9
|
create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
|
|
6
10
|
createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AnyNonPromise } from '@xylabs/promise';
|
|
2
2
|
import type { StringOrAlertFunction, TypeCheckConfig, TypeCheckOptionalConfig, TypeCheckRequiredConfig } from './types.ts';
|
|
3
|
+
/** A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. */
|
|
3
4
|
export type AsTypeFunction<T extends AnyNonPromise = AnyNonPromise> = {
|
|
4
5
|
<TType extends T>(value: AnyNonPromise): TType | undefined;
|
|
5
6
|
<TType extends T>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
|
|
@@ -8,6 +9,7 @@ export type AsTypeFunction<T extends AnyNonPromise = AnyNonPromise> = {
|
|
|
8
9
|
<TType extends T>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckRequiredConfig): TType;
|
|
9
10
|
<TType extends T>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckConfig | TypeCheckOptionalConfig): TType | undefined;
|
|
10
11
|
};
|
|
12
|
+
/** A simplified type-narrowing function that returns T or undefined, without assertion support. */
|
|
11
13
|
export type AsOptionalTypeFunction<T extends AnyNonPromise = AnyNonPromise> = {
|
|
12
14
|
<TType extends T>(value: AnyNonPromise): TType | undefined;
|
|
13
15
|
};
|
package/dist/neutral/types.d.ts
CHANGED
|
@@ -2,16 +2,21 @@ import type { AssertExMessageFunc } from '@xylabs/assert';
|
|
|
2
2
|
import type { Logger } from '@xylabs/logger';
|
|
3
3
|
import type { AnyNonPromise } from '@xylabs/promise';
|
|
4
4
|
import type { TypedValue } from '@xylabs/typeof';
|
|
5
|
+
/** Configuration options for type check functions, with optional logging. */
|
|
5
6
|
export interface TypeCheckConfig {
|
|
6
7
|
log?: boolean | Logger;
|
|
7
8
|
}
|
|
9
|
+
/** Type check configuration that marks the value as required, causing assertions on failure. */
|
|
8
10
|
export interface TypeCheckRequiredConfig extends TypeCheckConfig {
|
|
9
11
|
required: true;
|
|
10
12
|
}
|
|
13
|
+
/** Type check configuration that marks the value as optional, returning undefined on failure. */
|
|
11
14
|
export interface TypeCheckOptionalConfig extends TypeCheckConfig {
|
|
12
15
|
required: false;
|
|
13
16
|
}
|
|
17
|
+
/** A string message or function that produces an assertion error message for a failed type check. */
|
|
14
18
|
export type StringOrAlertFunction<T extends AnyNonPromise> = string | AssertExMessageFunc<T>;
|
|
19
|
+
/** A type guard function that checks whether a value conforms to type T, with optional configuration. */
|
|
15
20
|
export type TypeCheck<T extends TypedValue> = {
|
|
16
21
|
(obj: AnyNonPromise): obj is T;
|
|
17
22
|
(obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/object-model",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
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.
|
|
39
|
-
"@xylabs/logger": "~5.0.
|
|
40
|
-
"@xylabs/promise": "~5.0.
|
|
41
|
-
"@xylabs/typeof": "~5.0.
|
|
38
|
+
"@xylabs/assert": "~5.0.84",
|
|
39
|
+
"@xylabs/logger": "~5.0.84",
|
|
40
|
+
"@xylabs/promise": "~5.0.84",
|
|
41
|
+
"@xylabs/typeof": "~5.0.84"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
45
|
-
"@xylabs/tsconfig": "~7.4.
|
|
44
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
45
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
46
46
|
"typescript": "~5.9.3",
|
|
47
47
|
"vitest": "~4.0.18"
|
|
48
48
|
},
|