@danielsimonjr/mathts-core 0.14.3 → 0.15.0
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/arithmetic/scalar.d.ts +56 -0
- package/dist/arithmetic/scalar.d.ts.map +1 -0
- package/dist/array.d.ts +253 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/bignumber-formatter.d.ts +135 -0
- package/dist/bignumber-formatter.d.ts.map +1 -0
- package/dist/collection.d.ts +67 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/customs.d.ts +44 -0
- package/dist/customs.d.ts.map +1 -0
- package/dist/error/DimensionError.d.ts +26 -0
- package/dist/error/DimensionError.d.ts.map +1 -0
- package/dist/error/IndexError.d.ts +33 -0
- package/dist/error/IndexError.d.ts.map +1 -0
- package/dist/error/MathjsError.d.ts +13 -0
- package/dist/error/MathjsError.d.ts.map +1 -0
- package/dist/factory/factory.d.ts +154 -0
- package/dist/factory/factory.d.ts.map +1 -0
- package/dist/factory/index.d.ts +6 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory.d.ts +112 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/index.d.ts +24 -2593
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -13
- package/dist/internal.d.ts +33 -1344
- package/dist/internal.d.ts.map +1 -0
- package/dist/is.d.ts +102 -0
- package/dist/is.d.ts.map +1 -0
- package/dist/map.d.ts +113 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/number.d.ts +314 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/numeric/stable.d.ts +130 -0
- package/dist/numeric/stable.d.ts.map +1 -0
- package/dist/object.d.ts +119 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/shared.d.ts +41 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/string.d.ts +70 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/switch.d.ts +9 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/typed/index.d.ts +7 -0
- package/dist/typed/index.d.ts.map +1 -0
- package/dist/typed/mathts-typed.d.ts +246 -0
- package/dist/typed/mathts-typed.d.ts.map +1 -0
- package/dist/typed/type-bridge.d.ts +2 -0
- package/dist/typed/type-bridge.d.ts.map +1 -0
- package/dist/types/bignumber.d.ts +367 -0
- package/dist/types/bignumber.d.ts.map +1 -0
- package/dist/types/complex.d.ts +284 -0
- package/dist/types/complex.d.ts.map +1 -0
- package/dist/types/dual-rules.d.ts +129 -0
- package/dist/types/dual-rules.d.ts.map +1 -0
- package/dist/types/dual.d.ts +36 -0
- package/dist/types/dual.d.ts.map +1 -0
- package/dist/types/fraction.d.ts +215 -0
- package/dist/types/fraction.d.ts.map +1 -0
- package/dist/types/interfaces.d.ts +143 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/matrix/Range.d.ts +767 -0
- package/dist/types/matrix/Range.d.ts.map +1 -0
- package/dist/types/unit/Unit.d.ts +3 -0
- package/dist/types/unit/Unit.d.ts.map +1 -0
- package/dist/types/unit/dependencies.d.ts +4 -0
- package/dist/types/unit/dependencies.d.ts.map +1 -0
- package/dist/types/unit/errors.d.ts +18 -0
- package/dist/types/unit/errors.d.ts.map +1 -0
- package/dist/types/unit/index.d.ts +7 -0
- package/dist/types/unit/index.d.ts.map +1 -0
- package/dist/types/unit/unit-types.d.ts +231 -0
- package/dist/types/unit/unit-types.d.ts.map +1 -0
- package/dist/types/unit-definitions.d.ts +79 -0
- package/dist/types/unit-definitions.d.ts.map +1 -0
- package/dist/types/unit-prefixes.d.ts +29 -0
- package/dist/types/unit-prefixes.d.ts.map +1 -0
- package/dist/types/unit.d.ts +28 -0
- package/dist/types/unit.d.ts.map +1 -0
- package/dist/types/wasm-loader.d.ts +35 -0
- package/dist/types/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.d.ts +97 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/index-B4LIOfHN.d.ts +0 -449
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a range error with the message:
|
|
3
|
+
* 'Dimension mismatch (<actual size> != <expected size>)'
|
|
4
|
+
* Or with a custom message when called with a single string argument.
|
|
5
|
+
*
|
|
6
|
+
* The single canonical `DimensionError` for the whole monorepo (Bucket B, commit 1),
|
|
7
|
+
* exposed via the `@danielsimonjr/mathts-core/internal` subpath. `expression/src/error/
|
|
8
|
+
* DimensionError.ts` and `functions/src/error/DimensionError.ts` are now thin
|
|
9
|
+
* re-export shims of this class — a `DimensionError` thrown in one package is
|
|
10
|
+
* `instanceof DimensionError` in any other, since there is only ever one class
|
|
11
|
+
* identity. `core/src/array.ts` (and the ~20 other call sites across matrix algos,
|
|
12
|
+
* subset, resize, concat, reshape, ...) all throw this same class.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DimensionError extends RangeError {
|
|
15
|
+
actual?: number | number[];
|
|
16
|
+
expected?: number | number[];
|
|
17
|
+
relation?: string;
|
|
18
|
+
isDimensionError: true;
|
|
19
|
+
/**
|
|
20
|
+
* @param actual - The actual size or custom error message
|
|
21
|
+
* @param expected - The expected size (optional if actual is a custom message)
|
|
22
|
+
* @param relation - Optional relation between actual and expected size: '!=', '<', etc.
|
|
23
|
+
*/
|
|
24
|
+
constructor(actual: number | number[] | string, expected?: number | number[], relation?: string);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=DimensionError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DimensionError.d.ts","sourceRoot":"","sources":["../../src/error/DimensionError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,OAAiB;IAEjC;;;;OAIG;IACH,YAAY,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,EAwC9F;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error type for index out of range errors.
|
|
3
|
+
*
|
|
4
|
+
* The single canonical `IndexError` for the whole monorepo (Bucket B, commit 1),
|
|
5
|
+
* exposed via the `@danielsimonjr/mathts-core/internal` subpath. `expression/src/error/
|
|
6
|
+
* IndexError.ts` and `functions/src/error/IndexError.ts` are now thin re-export shims
|
|
7
|
+
* of this class — an `IndexError` thrown in one package is `instanceof IndexError`
|
|
8
|
+
* in any other, since there is only ever one class identity. `core/src/array.ts` /
|
|
9
|
+
* `core/src/collection.ts` (and the many other call sites across concat, subset,
|
|
10
|
+
* cumsum, mapSlices, ...) all throw this same class.
|
|
11
|
+
*
|
|
12
|
+
* @extends RangeError
|
|
13
|
+
*/
|
|
14
|
+
export declare class IndexError extends RangeError {
|
|
15
|
+
index: number;
|
|
16
|
+
min: number | undefined;
|
|
17
|
+
max: number | undefined;
|
|
18
|
+
isIndexError: true;
|
|
19
|
+
/**
|
|
20
|
+
* Create an IndexError
|
|
21
|
+
*
|
|
22
|
+
* Can be called in two ways:
|
|
23
|
+
* - IndexError(index, max) - assumes min=0
|
|
24
|
+
* - IndexError(index, min, max)
|
|
25
|
+
*
|
|
26
|
+
* @param index The actual index
|
|
27
|
+
* @param min Minimum index (included), or max if only 2 args provided
|
|
28
|
+
* @param max Maximum index (excluded)
|
|
29
|
+
*/
|
|
30
|
+
constructor(index: number, min?: number, max?: number);
|
|
31
|
+
}
|
|
32
|
+
export declare function createIndexError(index: number, min?: number, max?: number): IndexError;
|
|
33
|
+
//# sourceMappingURL=IndexError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexError.d.ts","sourceRoot":"","sources":["../../src/error/IndexError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,OAAiB;IAE7B;;;;;;;;;;OAUG;IACH,YAAY,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAqCpD;CACF;AAID,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,UAAU,CAEtF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error type for Mathjs errors
|
|
3
|
+
* @extends Error
|
|
4
|
+
*/
|
|
5
|
+
export declare class MathjsError extends Error {
|
|
6
|
+
isMathjsError: true;
|
|
7
|
+
/**
|
|
8
|
+
* Create a MathjsError
|
|
9
|
+
* @param message Error message
|
|
10
|
+
*/
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=MathjsError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MathjsError.d.ts","sourceRoot":"","sources":["../../src/error/MathjsError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,aAAa,OAAiB;IAE9B;;;OAGG;IACH,YAAY,OAAO,EAAE,MAAM,EAgB1B;CACF"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MathTS Function Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides a factory pattern for creating MathTS functions with:
|
|
5
|
+
* - Typed function dispatch via typed-function
|
|
6
|
+
* - Dependency injection for inter-function references
|
|
7
|
+
* - Backend selection integration
|
|
8
|
+
* - Lazy loading support
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import type { TypedFunction, TypedInstance, SignatureFunction, ReferTo, ReferToSelf } from '../typed/mathts-typed.js';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for MathTS instance
|
|
15
|
+
*/
|
|
16
|
+
export interface MathTSConfig {
|
|
17
|
+
/** Numeric precision (for BigNumber) */
|
|
18
|
+
precision: number;
|
|
19
|
+
/** Default matrix type */
|
|
20
|
+
matrix: 'Matrix' | 'Array';
|
|
21
|
+
/** Number type for parsing */
|
|
22
|
+
number: 'number' | 'BigNumber' | 'Fraction';
|
|
23
|
+
/** Enable predictable randomness */
|
|
24
|
+
randomSeed: string | null;
|
|
25
|
+
/** Epsilon for floating point comparison */
|
|
26
|
+
epsilon: number;
|
|
27
|
+
/** Preferred backend for matrix operations */
|
|
28
|
+
preferredBackend: 'auto' | 'js' | 'wasm' | 'gpu';
|
|
29
|
+
/** Minimum elements to use WASM backend */
|
|
30
|
+
wasmThreshold: number;
|
|
31
|
+
/** Minimum elements to use GPU backend */
|
|
32
|
+
gpuThreshold: number;
|
|
33
|
+
/** Enable parallel processing */
|
|
34
|
+
parallelEnabled: boolean;
|
|
35
|
+
/** Minimum elements to parallelize */
|
|
36
|
+
parallelThreshold: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Default MathTS configuration
|
|
40
|
+
*/
|
|
41
|
+
export declare const DEFAULT_CONFIG: MathTSConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Factory function definition
|
|
44
|
+
*/
|
|
45
|
+
export interface FactoryFunction<T = TypedFunction> {
|
|
46
|
+
/** Name of the function */
|
|
47
|
+
name: string;
|
|
48
|
+
/** Dependencies required by this function */
|
|
49
|
+
dependencies: string[];
|
|
50
|
+
/** Factory that creates the function given dependencies */
|
|
51
|
+
factory: (deps: FactoryDependencies) => T;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Dependencies passed to factory functions
|
|
55
|
+
*/
|
|
56
|
+
export interface FactoryDependencies {
|
|
57
|
+
/** MathTS configuration */
|
|
58
|
+
config: MathTSConfig;
|
|
59
|
+
/** typed-function instance */
|
|
60
|
+
typed: TypedInstance;
|
|
61
|
+
/** Registered functions (for cross-references) */
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Import definition for a factory function
|
|
66
|
+
*/
|
|
67
|
+
export type FactoryImport = FactoryFunction | (() => Promise<FactoryFunction>);
|
|
68
|
+
/**
|
|
69
|
+
* MathTS function registry
|
|
70
|
+
*/
|
|
71
|
+
export declare class FunctionRegistry {
|
|
72
|
+
private factories;
|
|
73
|
+
private instances;
|
|
74
|
+
private dependencies;
|
|
75
|
+
private creating;
|
|
76
|
+
constructor(config?: Partial<MathTSConfig>, typed?: TypedInstance);
|
|
77
|
+
/**
|
|
78
|
+
* Register a factory function
|
|
79
|
+
*/
|
|
80
|
+
register(factory: FactoryFunction): void;
|
|
81
|
+
/**
|
|
82
|
+
* Register multiple factory functions
|
|
83
|
+
*/
|
|
84
|
+
registerAll(factories: FactoryFunction[]): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get or create a function by name
|
|
87
|
+
*/
|
|
88
|
+
get(name: string): TypedFunction;
|
|
89
|
+
/**
|
|
90
|
+
* Check if a function is registered
|
|
91
|
+
*/
|
|
92
|
+
has(name: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Get all registered function names
|
|
95
|
+
*/
|
|
96
|
+
names(): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Update configuration
|
|
99
|
+
*/
|
|
100
|
+
updateConfig(config: Partial<MathTSConfig>): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get current configuration
|
|
103
|
+
*/
|
|
104
|
+
getConfig(): MathTSConfig;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create a factory function definition
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* export const addFactory = createFactory('add', ['typed'], ({ typed }) =>
|
|
112
|
+
* typed('add', {
|
|
113
|
+
* 'number, number': (a, b) => a + b,
|
|
114
|
+
* 'Complex, Complex': (a, b) => ({ re: a.re + b.re, im: a.im + b.im }),
|
|
115
|
+
* })
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function createFactory<T = TypedFunction>(name: string, dependencies: string[], factory: (deps: FactoryDependencies) => T): FactoryFunction<T>;
|
|
120
|
+
/**
|
|
121
|
+
* Create a typed function using the factory pattern
|
|
122
|
+
*
|
|
123
|
+
* This is a convenience wrapper that creates a factory and immediately
|
|
124
|
+
* invokes it with the default dependencies.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* export const add = createTypedFunction('add', {
|
|
129
|
+
* 'number, number': (a, b) => a + b,
|
|
130
|
+
* 'string, string': (a, b) => a + b,
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function createTypedFunction(name: string, signatures: Record<string, SignatureFunction | ReferTo | ReferToSelf>): TypedFunction;
|
|
135
|
+
export declare const registry: FunctionRegistry;
|
|
136
|
+
export declare const math: {
|
|
137
|
+
/**
|
|
138
|
+
* Get a registered function
|
|
139
|
+
*/
|
|
140
|
+
get: (name: string) => TypedFunction;
|
|
141
|
+
/**
|
|
142
|
+
* Register a factory function
|
|
143
|
+
*/
|
|
144
|
+
register: (factory: FactoryFunction) => void;
|
|
145
|
+
/**
|
|
146
|
+
* Get configuration
|
|
147
|
+
*/
|
|
148
|
+
config: () => MathTSConfig;
|
|
149
|
+
/**
|
|
150
|
+
* Update configuration
|
|
151
|
+
*/
|
|
152
|
+
configure: (config: Partial<MathTSConfig>) => void;
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/factory/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAGlC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3B,8BAA8B;IAC9B,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;IAC5C,oCAAoC;IACpC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;IACjD,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,sCAAsC;IACtC,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,YAW5B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,aAAa;IAChD,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,2DAA2D;IAC3D,OAAO,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,2B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AM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,GAAG,WAAW,CAAC,GACpE,aAAa,CAEf;AAGD,eAAO,MAAM,QAAQ,kBAAyB,CAAC;AAG/C,eAAO,MAAM,IAAI;IACf;;OAEG;IACH,GAAG,SAAS,MAAM;IAElB;;OAEG;IACH,QAAQ,YAAY,eAAe;IAEnC;;OAEG;IACH,MAAM;IAEN;;OAEG;IACH,SAAS,WAAW,OAAO,CAAC,YAAY,CAAC;CAC1C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory pattern exports
|
|
3
|
+
*/
|
|
4
|
+
export { FunctionRegistry, createFactory, createTypedFunction, registry, math, DEFAULT_CONFIG, } from './factory.js';
|
|
5
|
+
export type { MathTSConfig, FactoryFunction, FactoryDependencies, FactoryImport, } from './factory.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,IAAI,EACJ,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,aAAa,GACd,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type for a factory function that creates instances
|
|
3
|
+
*/
|
|
4
|
+
export interface FactoryFunction<TResult = unknown> {
|
|
5
|
+
(scope: Record<string, unknown>): TResult;
|
|
6
|
+
isFactory: true;
|
|
7
|
+
fn: string;
|
|
8
|
+
dependencies: string[];
|
|
9
|
+
meta?: FactoryMeta;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Type for legacy factory objects (old-style factories)
|
|
13
|
+
*/
|
|
14
|
+
export interface LegacyFactory {
|
|
15
|
+
type?: string;
|
|
16
|
+
name: string;
|
|
17
|
+
factory: (...args: unknown[]) => unknown;
|
|
18
|
+
math?: boolean;
|
|
19
|
+
dependencies?: string[];
|
|
20
|
+
meta?: FactoryMeta;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Meta information that can be attached to a factory
|
|
24
|
+
*/
|
|
25
|
+
export interface FactoryMeta {
|
|
26
|
+
/**
|
|
27
|
+
* If true, the factory will be recreated when config changes
|
|
28
|
+
*/
|
|
29
|
+
recreateOnConfigChange?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* If true, this is a lazy factory that should only be created when needed
|
|
32
|
+
*/
|
|
33
|
+
lazy?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Additional custom metadata
|
|
36
|
+
*/
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Type for dependency names, which can be optional (prefixed with '?')
|
|
41
|
+
*/
|
|
42
|
+
export type DependencyName = string;
|
|
43
|
+
/**
|
|
44
|
+
* Type for the create callback function
|
|
45
|
+
*/
|
|
46
|
+
export type CreateFunction<TDeps extends Record<string, unknown>, TResult> = (dependencies: TDeps) => TResult;
|
|
47
|
+
/**
|
|
48
|
+
* Create a factory function, which can be used to inject dependencies.
|
|
49
|
+
*
|
|
50
|
+
* The created functions are memoized, a consecutive call of the factory
|
|
51
|
+
* with the exact same inputs will return the same function instance.
|
|
52
|
+
* The memoized cache is exposed on `factory.cache` and can be cleared
|
|
53
|
+
* if needed.
|
|
54
|
+
*
|
|
55
|
+
* Example:
|
|
56
|
+
*
|
|
57
|
+
* const name = 'log'
|
|
58
|
+
* const dependencies = ['config', 'typed', 'divideScalar', 'Complex']
|
|
59
|
+
*
|
|
60
|
+
* export const createLog = factory(name, dependencies, ({ typed, config, divideScalar, Complex }) => {
|
|
61
|
+
* // ... create the function log here and return it
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* @param name Name of the function to be created
|
|
65
|
+
* @param dependencies The names of all required dependencies
|
|
66
|
+
* @param create Callback function called with an object with all dependencies
|
|
67
|
+
* @param meta Optional object with meta information that will be attached
|
|
68
|
+
* to the created factory function as property `meta`. For explanation
|
|
69
|
+
* of what meta properties can be specified and what they mean, see
|
|
70
|
+
* docs/core/extension.md.
|
|
71
|
+
* @returns The factory function
|
|
72
|
+
*/
|
|
73
|
+
export declare function factory<TDeps extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>(name: string, dependencies: DependencyName[], create: CreateFunction<TDeps, TResult>, meta?: FactoryMeta): FactoryFunction<TResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Sort all factories such that when loading in order, the dependencies are resolved.
|
|
76
|
+
*
|
|
77
|
+
* @param factories Array of factory functions or legacy factories
|
|
78
|
+
* @returns Returns a new array with the sorted factories
|
|
79
|
+
*/
|
|
80
|
+
export declare function sortFactories(factories: Array<FactoryFunction | LegacyFactory>): Array<FactoryFunction | LegacyFactory>;
|
|
81
|
+
export declare function create(factories: Array<FactoryFunction | LegacyFactory>, scope?: Record<string, unknown>): Record<string, unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Test whether an object is a factory. This is the case when it has
|
|
84
|
+
* properties name, dependencies, and a function create.
|
|
85
|
+
* @param obj Any value to test
|
|
86
|
+
* @returns true if obj is a factory function
|
|
87
|
+
*/
|
|
88
|
+
export declare function isFactory(obj: unknown): obj is FactoryFunction;
|
|
89
|
+
/**
|
|
90
|
+
* Assert that all dependencies of a list with dependencies are available in the provided scope.
|
|
91
|
+
*
|
|
92
|
+
* Will throw an exception when there are dependencies missing.
|
|
93
|
+
*
|
|
94
|
+
* @param name Name for the function to be created. Used to generate a useful error message
|
|
95
|
+
* @param dependencies Array of dependency names
|
|
96
|
+
* @param scope Object containing the available dependencies
|
|
97
|
+
* @throws Error if required dependencies are missing
|
|
98
|
+
*/
|
|
99
|
+
export declare function assertDependencies(name: string, dependencies: DependencyName[], scope: Record<string, unknown>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Check if a dependency is optional (starts with '?')
|
|
102
|
+
* @param dependency The dependency name to check
|
|
103
|
+
* @returns true if the dependency is optional
|
|
104
|
+
*/
|
|
105
|
+
export declare function isOptionalDependency(dependency: DependencyName): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Remove the optional notation '?' from a dependency name
|
|
108
|
+
* @param dependency The dependency name
|
|
109
|
+
* @returns The dependency name without optional notation
|
|
110
|
+
*/
|
|
111
|
+
export declare function stripOptionalNotation(dependency: DependencyName): string;
|
|
112
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,GAAG,OAAO;IAChD,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAC1C,SAAS,EAAE,IAAI,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,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