@declaro/core 2.0.0-beta.99 → 2.1.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/browser/index.js +21 -27
- package/dist/browser/index.js.map +37 -27
- package/dist/browser/scope/index.js +1 -2
- package/dist/browser/scope/index.js.map +1 -1
- package/dist/bun/index.js +19011 -0
- package/dist/bun/index.js.map +132 -0
- package/dist/bun/scope/index.js +4 -0
- package/dist/bun/scope/index.js.map +9 -0
- package/dist/node/index.cjs +2581 -874
- package/dist/node/index.cjs.map +36 -27
- package/dist/node/index.js +2572 -868
- package/dist/node/index.js.map +36 -27
- package/dist/node/scope/index.cjs +31 -10
- package/dist/node/scope/index.cjs.map +1 -1
- package/dist/node/scope/index.js +1 -27
- package/dist/node/scope/index.js.map +1 -1
- package/dist/ts/context/async-context.d.ts +54 -0
- package/dist/ts/context/async-context.d.ts.map +1 -0
- package/dist/ts/context/async-context.test.d.ts +2 -0
- package/dist/ts/context/async-context.test.d.ts.map +1 -0
- package/dist/ts/context/context.circular-deps.test.d.ts +2 -0
- package/dist/ts/context/context.circular-deps.test.d.ts.map +1 -0
- package/dist/ts/context/context.d.ts +297 -38
- package/dist/ts/context/context.d.ts.map +1 -1
- package/dist/ts/http/request-context.d.ts.map +1 -1
- package/dist/ts/index.d.ts +2 -0
- package/dist/ts/index.d.ts.map +1 -1
- package/dist/ts/schema/json-schema.d.ts +9 -1
- package/dist/ts/schema/json-schema.d.ts.map +1 -1
- package/dist/ts/schema/model.d.ts +6 -1
- package/dist/ts/schema/model.d.ts.map +1 -1
- package/dist/ts/schema/test/mock-model.d.ts +2 -2
- package/dist/ts/schema/test/mock-model.d.ts.map +1 -1
- package/dist/ts/shared/utils/schema-utils.d.ts +3 -0
- package/dist/ts/shared/utils/schema-utils.d.ts.map +1 -0
- package/dist/ts/shared/utils/schema-utils.test.d.ts +2 -0
- package/dist/ts/shared/utils/schema-utils.test.d.ts.map +1 -0
- package/dist/ts/shims/async-local-storage.d.ts +36 -0
- package/dist/ts/shims/async-local-storage.d.ts.map +1 -0
- package/dist/ts/shims/async-local-storage.test.d.ts +2 -0
- package/dist/ts/shims/async-local-storage.test.d.ts.map +1 -0
- package/package.json +17 -9
- package/src/context/async-context.test.ts +348 -0
- package/src/context/async-context.ts +129 -0
- package/src/context/context.circular-deps.test.ts +1047 -0
- package/src/context/context.test.ts +150 -0
- package/src/context/context.ts +493 -55
- package/src/http/request-context.ts +1 -3
- package/src/index.ts +2 -0
- package/src/schema/json-schema.ts +14 -1
- package/src/schema/model-schema.test.ts +155 -1
- package/src/schema/model.ts +34 -3
- package/src/schema/test/mock-model.ts +6 -2
- package/src/shared/utils/schema-utils.test.ts +33 -0
- package/src/shared/utils/schema-utils.ts +17 -0
- package/src/shims/async-local-storage.test.ts +258 -0
- package/src/shims/async-local-storage.ts +82 -0
- package/dist/ts/schema/entity-schema.test.d.ts +0 -1
- package/dist/ts/schema/entity-schema.test.d.ts.map +0 -1
- package/src/schema/entity-schema.test.ts +0 -0
|
@@ -5,78 +5,245 @@ import type { AllNodeMiddleware } from '../http/request-context';
|
|
|
5
5
|
import type { Class, PromiseOrValue, UnwrapPromise } from '../typescript';
|
|
6
6
|
import { type Validator } from '../validation';
|
|
7
7
|
import { ContextConsumer } from './context-consumer';
|
|
8
|
+
/**
|
|
9
|
+
* Global interface for declaring dependencies available across all contexts.
|
|
10
|
+
* Extend this interface using declaration merging to add type-safe dependencies.
|
|
11
|
+
*/
|
|
8
12
|
export interface DeclaroDependencies {
|
|
9
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Base scope interface for contexts with request and node middleware.
|
|
16
|
+
*/
|
|
10
17
|
export interface DeclaroScope {
|
|
18
|
+
/** Middleware that runs on request contexts */
|
|
11
19
|
requestMiddleware: ContextMiddleware<Context>[];
|
|
20
|
+
/** Node.js-compatible middleware */
|
|
12
21
|
nodeMiddleware: AllNodeMiddleware[];
|
|
13
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Scope interface for request-specific contexts, extending the base scope with request data.
|
|
25
|
+
*/
|
|
14
26
|
export interface DeclaroRequestScope extends DeclaroScope {
|
|
27
|
+
/** The HTTP request object */
|
|
15
28
|
request: Request;
|
|
29
|
+
/** Incoming HTTP headers */
|
|
16
30
|
headers: IncomingHttpHeaders;
|
|
31
|
+
/** Helper function to retrieve a specific header value */
|
|
17
32
|
header: <K extends keyof IncomingHttpHeaders>(header: K) => IncomingHttpHeaders[K] | undefined;
|
|
18
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the scope type from a Context type.
|
|
36
|
+
*/
|
|
19
37
|
export type ExtractScope<T extends Context<any>> = T extends Context<infer S> ? S : never;
|
|
20
38
|
/**
|
|
21
39
|
* Creates a context type that narrows the scope to a subset.
|
|
22
40
|
* This allows using a context with more dependencies where fewer are expected.
|
|
23
41
|
*/
|
|
24
42
|
export type NarrowContext<TContext extends Context<any>, TNarrowScope extends object> = TContext extends Context<infer TFullScope> ? TNarrowScope extends Partial<TFullScope> ? Context<TNarrowScope> : never : never;
|
|
43
|
+
/**
|
|
44
|
+
* Middleware function that can modify or extend a context.
|
|
45
|
+
*/
|
|
25
46
|
export type ContextMiddleware<C extends Context = Context> = (context: Context<ExtractScope<C>>) => any | Promise<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Represents the state storage for a context, mapping keys to their attributes.
|
|
49
|
+
*/
|
|
26
50
|
export type ContextState<TContext extends Context> = Record<PropertyKey, ContextAttribute<TContext, StateValue<any>>>;
|
|
51
|
+
/**
|
|
52
|
+
* Function that resolves a value from a context.
|
|
53
|
+
*/
|
|
27
54
|
export type ContextResolver<T> = (context: Context) => StateValue<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Wrapper type for state values.
|
|
57
|
+
*/
|
|
28
58
|
export type StateValue<T> = T;
|
|
59
|
+
/**
|
|
60
|
+
* Types of dependencies that can be registered in a context.
|
|
61
|
+
*/
|
|
29
62
|
export declare enum DependencyType {
|
|
63
|
+
/** A literal value dependency */
|
|
30
64
|
VALUE = "VALUE",
|
|
65
|
+
/** A factory function that creates the dependency */
|
|
31
66
|
FACTORY = "FACTORY",
|
|
67
|
+
/** A class constructor that instantiates the dependency */
|
|
32
68
|
CLASS = "CLASS"
|
|
33
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Factory function type that takes arguments and returns a value.
|
|
72
|
+
*/
|
|
34
73
|
export type FactoryFn<T, A extends any[]> = (...args: A) => T;
|
|
35
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Function that loads a value from a context with optional resolution options.
|
|
76
|
+
*/
|
|
77
|
+
export type ValueLoader<C extends Context, T> = (context: C, resolutionOptions?: ResolveOptions) => T;
|
|
78
|
+
/**
|
|
79
|
+
* Filters object keys to only those whose values match a specific type.
|
|
80
|
+
*/
|
|
36
81
|
export type FilterKeysByType<TScope, TValue> = {
|
|
37
82
|
[Key in keyof TScope]: TScope[Key] extends TValue ? Key : never;
|
|
38
83
|
}[keyof TScope];
|
|
84
|
+
/**
|
|
85
|
+
* Filters object keys to only those whose values match a specific type or Promise of that type.
|
|
86
|
+
*/
|
|
39
87
|
export type FilterKeysByAsyncType<TScope, TValue> = {
|
|
40
88
|
[Key in keyof TScope]: TScope[Key] extends PromiseOrValue<TValue> ? Key : never;
|
|
41
89
|
}[keyof TScope];
|
|
90
|
+
/**
|
|
91
|
+
* Maps an array of argument types to their corresponding scope keys.
|
|
92
|
+
*/
|
|
42
93
|
export type FilterArgsByType<TScope, TArgs extends any[]> = {
|
|
43
94
|
[Key in keyof TArgs]: FilterKeysByType<TScope, TArgs[Key]>;
|
|
44
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Maps an array of argument types to their corresponding scope keys for async values.
|
|
98
|
+
*/
|
|
45
99
|
export type FilterAsyncArgsByType<TScope, TArgs extends any[]> = {
|
|
46
100
|
[Key in keyof TArgs]: FilterKeysByAsyncType<TScope, TArgs[Key]>;
|
|
47
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* Metadata describing how a dependency is registered and resolved in a context.
|
|
104
|
+
*/
|
|
48
105
|
export type ContextAttribute<TContext extends Context<any>, TValue> = {
|
|
106
|
+
/** The key under which this dependency is registered */
|
|
49
107
|
key: PropertyKey;
|
|
108
|
+
/** Function that loads the value from the context */
|
|
50
109
|
value?: ValueLoader<TContext, TValue>;
|
|
110
|
+
/** The type of dependency (value, factory, or class) */
|
|
51
111
|
type: DependencyType;
|
|
112
|
+
/** Options controlling how this dependency is resolved */
|
|
52
113
|
resolveOptions?: ResolveOptions;
|
|
114
|
+
/** Cached value for singleton or eager dependencies */
|
|
53
115
|
cachedValue?: TValue;
|
|
116
|
+
/** Keys of other dependencies that this dependency requires */
|
|
54
117
|
inject: PropertyKey[];
|
|
55
118
|
};
|
|
119
|
+
/**
|
|
120
|
+
* Type-safe scope key extraction.
|
|
121
|
+
*/
|
|
56
122
|
export type ScopeKey<S extends object> = keyof S;
|
|
123
|
+
/**
|
|
124
|
+
* Listener function that responds to events in a context.
|
|
125
|
+
*/
|
|
57
126
|
export type ContextListener<C extends Context, E extends IEvent> = (context: C, event: E) => any;
|
|
58
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Interface for circular dependency proxies that defer to a real target once resolved.
|
|
129
|
+
* These proxies are created during circular dependency resolution to allow references
|
|
130
|
+
* to objects that haven't been fully constructed yet.
|
|
131
|
+
*/
|
|
132
|
+
export interface ResolveProxy<T = any> {
|
|
133
|
+
/**
|
|
134
|
+
* Identifies this object as a circular proxy.
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
readonly __isProxy: true;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the real target object that this proxy should delegate to.
|
|
140
|
+
* Called internally once the circular dependency is resolved.
|
|
141
|
+
* @internal
|
|
142
|
+
*/
|
|
143
|
+
readonly __resolve: (target: T) => void;
|
|
144
|
+
/** Indicates whether the proxy has been resolved to a real target. */
|
|
145
|
+
readonly __isResolved: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the real target object if resolved, otherwise returns the proxy itself.
|
|
148
|
+
* This allows using the proxy transparently before and after resolution.
|
|
149
|
+
*/
|
|
150
|
+
readonly valueOf: () => T;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Type guard to check if a value is a circular dependency proxy.
|
|
154
|
+
*
|
|
155
|
+
* @param value - The value to check
|
|
156
|
+
* @returns True if the value is a ResolveProxy
|
|
157
|
+
*/
|
|
158
|
+
export declare function isProxy(value: any): value is ResolveProxy;
|
|
159
|
+
export interface ResolveOptions {
|
|
160
|
+
/**
|
|
161
|
+
* If true, an error will be thrown if the dependency is not found. If false, undefined will be returned if the dependency is not found.
|
|
162
|
+
* @default false
|
|
163
|
+
*/
|
|
59
164
|
strict?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* If true, the dependency will be resolved immediately when the context is initialized. This is useful for dependencies that need to perform setup work.
|
|
167
|
+
* @default false
|
|
168
|
+
*/
|
|
60
169
|
eager?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* If true, the dependency will be a singleton, and the same instance will be returned for every request. If false, a new instance will be created each time the dependency is resolved.
|
|
172
|
+
* @default false
|
|
173
|
+
*/
|
|
61
174
|
singleton?: boolean;
|
|
62
|
-
|
|
175
|
+
/**
|
|
176
|
+
* An optional resolution context that can be used to track resolution state across multiple `resolve` calls. This is primarily used internally to track circular dependencies, but can be useful for advanced use cases.
|
|
177
|
+
*/
|
|
178
|
+
resolutionContext?: Map<PropertyKey, any>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Extracts nested resolution options, preserving resolution state across calls.
|
|
182
|
+
*
|
|
183
|
+
* @param options - The resolve options to extract from
|
|
184
|
+
* @returns Internal resolution options with resolution stack and context
|
|
185
|
+
*/
|
|
186
|
+
export declare function getNestedResolveOptions(options?: ResolveOptions | InternalResolveOptions): InternalResolveOptions;
|
|
187
|
+
/**
|
|
188
|
+
* Internal interface extending ResolveOptions with resolution tracking.
|
|
189
|
+
*/
|
|
190
|
+
export interface InternalResolveOptions extends ResolveOptions {
|
|
191
|
+
/** Stack tracking the current resolution chain to detect circular dependencies */
|
|
192
|
+
resolutionStack: Set<PropertyKey>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Returns the default resolution options for dependencies.
|
|
196
|
+
*
|
|
197
|
+
* @returns Default resolve options with strict, eager, and singleton all set to false
|
|
198
|
+
*/
|
|
63
199
|
export declare function defaultResolveOptions(): ResolveOptions;
|
|
200
|
+
/**
|
|
201
|
+
* Helper function to define type-safe context middleware.
|
|
202
|
+
*
|
|
203
|
+
* @param middleware - The middleware function to define
|
|
204
|
+
* @returns The same middleware function with proper typing
|
|
205
|
+
*/
|
|
206
|
+
export declare function defineContextMiddleware<C extends Context>(middleware: ContextMiddleware<C>): ContextMiddleware<C>;
|
|
207
|
+
/**
|
|
208
|
+
* Configuration options for creating a context.
|
|
209
|
+
*/
|
|
64
210
|
export type ContextOptions = {
|
|
211
|
+
/** Default options to use when resolving dependencies */
|
|
65
212
|
defaultResolveOptions?: ResolveOptions;
|
|
66
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* Core dependency injection container that manages application dependencies and their lifecycle.
|
|
216
|
+
* Supports values, factories, and classes with automatic dependency resolution and circular dependency handling.
|
|
217
|
+
*/
|
|
67
218
|
export declare class Context<Scope extends object = any> {
|
|
68
219
|
private readonly state;
|
|
69
220
|
private readonly emitter;
|
|
221
|
+
/** The scope object providing typed access to all registered dependencies */
|
|
70
222
|
readonly scope: Scope;
|
|
223
|
+
/** Default options used when resolving dependencies if not overridden */
|
|
71
224
|
protected readonly defaultResolveOptions: ResolveOptions;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a new context instance.
|
|
227
|
+
*
|
|
228
|
+
* @param options - Configuration options for the context
|
|
229
|
+
*/
|
|
72
230
|
constructor(options?: ContextOptions);
|
|
231
|
+
/**
|
|
232
|
+
* Gets the event manager for this context.
|
|
233
|
+
*
|
|
234
|
+
* @returns The event manager instance
|
|
235
|
+
*/
|
|
73
236
|
get events(): EventManager<IEvent>;
|
|
237
|
+
/**
|
|
238
|
+
* Initializes all dependencies marked as eager.
|
|
239
|
+
* Should be called after all dependencies are registered to trigger eager initialization.
|
|
240
|
+
*/
|
|
74
241
|
initializeEagerDependencies(): Promise<void>;
|
|
75
242
|
/**
|
|
76
243
|
* Set a value in context, to be injected later.
|
|
77
244
|
*
|
|
78
|
-
* @param key
|
|
79
|
-
* @param payload
|
|
245
|
+
* @param key - The scope key to register the value under
|
|
246
|
+
* @param payload - The value to register
|
|
80
247
|
* @deprecated Use `provideValue` instead, or you can register the same dependency as a factory with `provideFactory` or class with `provideClass`.
|
|
81
248
|
*/
|
|
82
249
|
provide<K extends ScopeKey<Scope>>(key: K, payload: Scope[K]): void;
|
|
@@ -89,97 +256,189 @@ export declare class Context<Scope extends object = any> {
|
|
|
89
256
|
register<K extends ScopeKey<Scope>>(key: K, dep: ContextAttribute<this, Scope[K]>): void;
|
|
90
257
|
/**
|
|
91
258
|
* Add a dependency to the context.
|
|
259
|
+
*
|
|
260
|
+
* @param key - The scope key to register under
|
|
261
|
+
* @param dep - The dependency attribute to add
|
|
262
|
+
* @returns The registered dependency attribute
|
|
92
263
|
*/
|
|
93
264
|
protected addDep<K extends ScopeKey<Scope>>(key: K, dep: ContextAttribute<this, Scope[K]>): ContextAttribute<this, Scope[K]>;
|
|
94
265
|
/**
|
|
95
266
|
* Register a value in context scope.
|
|
96
267
|
*
|
|
97
|
-
* @param key The key to register the dependency under
|
|
98
|
-
* @param value The value to register
|
|
268
|
+
* @param key - The key to register the dependency under
|
|
269
|
+
* @param value - The value to register
|
|
270
|
+
* @param defaultResolveOptions - Optional resolution options
|
|
271
|
+
* @returns The context instance for chaining
|
|
99
272
|
*/
|
|
100
273
|
registerValue<K extends ScopeKey<Scope>>(key: K, value: Scope[K], defaultResolveOptions?: ResolveOptions): this;
|
|
101
274
|
/**
|
|
102
275
|
* Register a dependency as a factory in context scope.
|
|
103
276
|
*
|
|
104
|
-
* @param key The key to register the dependency under
|
|
105
|
-
* @param factory A factory function that will be called to generate the value when it is requested
|
|
106
|
-
* @param inject An array of keys to use when injecting factory args
|
|
277
|
+
* @param key - The key to register the dependency under
|
|
278
|
+
* @param factory - A factory function that will be called to generate the value when it is requested
|
|
279
|
+
* @param inject - An array of keys to use when injecting factory args
|
|
280
|
+
* @param defaultResolveOptions - Optional resolution options
|
|
107
281
|
* @returns A chainable instance of context
|
|
108
282
|
*/
|
|
109
283
|
registerFactory<K extends ScopeKey<Scope>, A extends any[]>(key: K, factory: FactoryFn<Scope[K], A>, inject?: FilterArgsByType<Scope, A>, defaultResolveOptions?: ResolveOptions): this;
|
|
284
|
+
/**
|
|
285
|
+
* Register an async factory in context scope.
|
|
286
|
+
* The factory function and its dependencies can be asynchronous.
|
|
287
|
+
*
|
|
288
|
+
* @param key - The key to register the dependency under
|
|
289
|
+
* @param factory - An async factory function that will be called to generate the value
|
|
290
|
+
* @param inject - An array of keys to use when injecting factory args
|
|
291
|
+
* @param defaultResolveOptions - Optional resolution options
|
|
292
|
+
* @returns A chainable instance of context
|
|
293
|
+
*/
|
|
110
294
|
registerAsyncFactory<K extends FilterKeysByType<Scope, Promise<any>>, A extends any[]>(key: K, factory: FactoryFn<Scope[K], A>, inject?: FilterAsyncArgsByType<Scope, A>, defaultResolveOptions?: ResolveOptions): this;
|
|
295
|
+
/**
|
|
296
|
+
* Register a class constructor in context scope.
|
|
297
|
+
* The class will be instantiated with the specified dependencies.
|
|
298
|
+
*
|
|
299
|
+
* @param key - The key to register the dependency under
|
|
300
|
+
* @param Class - The class constructor
|
|
301
|
+
* @param inject - An array of keys to use when injecting constructor arguments
|
|
302
|
+
* @param defaultResolveOptions - Optional resolution options
|
|
303
|
+
* @returns A chainable instance of context
|
|
304
|
+
*/
|
|
111
305
|
registerClass<K extends FilterKeysByType<Scope, InstanceType<T>>, T extends Class<Scope[K] extends {} ? Scope[K] : never>>(key: K, Class: T, inject?: FilterArgsByType<Scope, ConstructorParameters<T>>, defaultResolveOptions?: ResolveOptions): this;
|
|
306
|
+
/**
|
|
307
|
+
* Register an async class constructor in context scope.
|
|
308
|
+
* The class constructor can have async dependencies.
|
|
309
|
+
*
|
|
310
|
+
* @param key - The key to register the dependency under
|
|
311
|
+
* @param Class - The class constructor
|
|
312
|
+
* @param inject - An array of keys to use when injecting constructor arguments
|
|
313
|
+
* @param defaultResolveOptions - Optional resolution options
|
|
314
|
+
* @returns A chainable instance of context
|
|
315
|
+
*/
|
|
112
316
|
registerAsyncClass<K extends FilterKeysByType<Scope, InstanceType<any>>, T extends Class<UnwrapPromise<Scope[K]> extends {} ? UnwrapPromise<Scope[K]> : never>>(key: K, Class: T, inject?: FilterAsyncArgsByType<Scope, ConstructorParameters<T>>, defaultResolveOptions?: ResolveOptions): this;
|
|
317
|
+
/**
|
|
318
|
+
* Gets all dependencies required by a specific dependency.
|
|
319
|
+
*
|
|
320
|
+
* @param key - The key of the dependency to inspect
|
|
321
|
+
* @returns Array of all direct and transitive dependencies
|
|
322
|
+
*/
|
|
113
323
|
getAllDependencies<K extends ScopeKey<Scope>>(key: K): ContextAttribute<this, any>[];
|
|
114
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Gets all dependencies that depend on a specific dependency.
|
|
326
|
+
* Useful for cache invalidation when a dependency changes.
|
|
327
|
+
*
|
|
328
|
+
* @param key - The key of the dependency to inspect
|
|
329
|
+
* @param visited - Internal tracking set to prevent infinite recursion
|
|
330
|
+
* @returns Array of all direct and transitive dependents
|
|
331
|
+
*/
|
|
332
|
+
getAllDependents<K extends ScopeKey<Scope>>(key: K, visited?: Set<any>): ContextAttribute<this, any>[];
|
|
333
|
+
/**
|
|
334
|
+
* Introspects a dependency to get its metadata.
|
|
335
|
+
*
|
|
336
|
+
* @param key - The key of the dependency to inspect
|
|
337
|
+
* @returns The context attribute for the dependency, or undefined if not found
|
|
338
|
+
*/
|
|
115
339
|
introspect<K extends ScopeKey<Scope>>(key: K): ContextState<this>[K];
|
|
116
|
-
|
|
117
|
-
|
|
340
|
+
/**
|
|
341
|
+
* Checks if a cached value is still valid for a dependency.
|
|
342
|
+
* A cache is invalid if the dependency or any of its transitive dependencies have been invalidated.
|
|
343
|
+
*
|
|
344
|
+
* @param key - The key of the dependency to check
|
|
345
|
+
* @param visited - Internal tracking set to prevent infinite recursion in circular dependencies
|
|
346
|
+
* @returns True if the cache is valid, false otherwise
|
|
347
|
+
*/
|
|
348
|
+
protected _cacheIsValid<K extends ScopeKey<Scope>>(key: K, visited?: Set<PropertyKey>): boolean;
|
|
349
|
+
/**
|
|
350
|
+
* Creates a proxy object for handling circular dependencies.
|
|
351
|
+
* The proxy initially acts as a placeholder and is later resolved to the real target.
|
|
352
|
+
*
|
|
353
|
+
* @returns A proxy that can be resolved later
|
|
354
|
+
*/
|
|
355
|
+
protected createProxy<T>(): ResolveProxy<T>;
|
|
356
|
+
/**
|
|
357
|
+
* Internal method to resolve a dependency value with circular dependency handling.
|
|
358
|
+
* This is the core resolution logic that handles caching, proxies, and dependency injection.
|
|
359
|
+
*
|
|
360
|
+
* @param key - The key of the dependency to resolve
|
|
361
|
+
* @param resolveOptions - Options controlling the resolution behavior
|
|
362
|
+
* @returns The resolved dependency value
|
|
363
|
+
*/
|
|
364
|
+
protected _resolveValue<K extends ScopeKey<Scope>>(key: K, resolveOptions?: InternalResolveOptions): Scope[K];
|
|
118
365
|
/**
|
|
119
366
|
* Extract a value from context.
|
|
120
367
|
*
|
|
121
|
-
* @param key
|
|
122
|
-
* @returns
|
|
368
|
+
* @param key - The scope key to resolve
|
|
369
|
+
* @returns The resolved value or undefined if not found
|
|
123
370
|
* @deprecated Use `resolve` instead
|
|
124
371
|
*/
|
|
125
372
|
inject<T = any>(key: ScopeKey<Scope>): T | undefined;
|
|
373
|
+
/**
|
|
374
|
+
* Resolves a dependency from the context.
|
|
375
|
+
* This is the primary method for retrieving registered dependencies.
|
|
376
|
+
*
|
|
377
|
+
* @param key - The scope key to resolve
|
|
378
|
+
* @param resolveOptions - Options controlling resolution behavior
|
|
379
|
+
* @returns The resolved dependency value
|
|
380
|
+
*/
|
|
126
381
|
resolve<K extends ScopeKey<Scope>>(key: K, resolveOptions?: ResolveOptions): Scope[K];
|
|
127
382
|
/**
|
|
128
383
|
* Ensure that only one copy of this instance exists in this context. Provides the instance if it doesn't exist yet, otherwise inject the cached instance.
|
|
129
384
|
*
|
|
130
|
-
* @param key
|
|
131
|
-
* @param instance
|
|
385
|
+
* @param key - The scope key to register under
|
|
386
|
+
* @param instance - The instance to register as a singleton
|
|
387
|
+
* @returns The singleton instance (either the provided one or the existing one)
|
|
132
388
|
*/
|
|
133
389
|
singleton<T = any>(key: ScopeKey<Scope>, instance: T): T;
|
|
134
390
|
/**
|
|
135
|
-
* Instantiate a ContextConsumer class
|
|
391
|
+
* Instantiate a ContextConsumer class.
|
|
392
|
+
* ContextConsumer classes have automatic access to the context instance.
|
|
136
393
|
*
|
|
137
|
-
* @param Consumer
|
|
138
|
-
* @
|
|
394
|
+
* @param Consumer - The ContextConsumer class to instantiate
|
|
395
|
+
* @param args - Additional arguments to pass to the constructor
|
|
396
|
+
* @returns A new instance of the ContextConsumer
|
|
139
397
|
*/
|
|
140
398
|
hydrate<T extends ContextConsumer<this, any[]>, A extends any[]>(Consumer: new (context: this, ...args: A) => T, ...args: A): T;
|
|
141
399
|
/**
|
|
142
|
-
* Create a new context from other instance(s) of Context
|
|
400
|
+
* Create a new context from other instance(s) of Context.
|
|
401
|
+
* Dependencies and event listeners from the provided contexts will be merged into this context.
|
|
143
402
|
*
|
|
144
|
-
* @param contexts
|
|
145
|
-
* @returns
|
|
403
|
+
* @param contexts - One or more contexts to extend from
|
|
404
|
+
* @returns The current context instance for chaining
|
|
146
405
|
*/
|
|
147
406
|
extend(...contexts: Context[]): this;
|
|
148
407
|
/**
|
|
149
|
-
* Modify context with middleware
|
|
408
|
+
* Modify context with middleware.
|
|
409
|
+
* Middleware can register dependencies, modify configuration, or perform other setup tasks.
|
|
150
410
|
*
|
|
151
|
-
* @param middleware
|
|
152
|
-
* @returns
|
|
411
|
+
* @param middleware - One or more middleware functions to apply
|
|
153
412
|
*/
|
|
154
413
|
use<TNarrowScope extends Partial<Scope>>(...middleware: ContextMiddleware<Context<TNarrowScope>>[]): Promise<void>;
|
|
155
414
|
use(...middleware: ContextMiddleware[]): Promise<void>;
|
|
156
415
|
/**
|
|
157
416
|
* Validate context ensuring all validators are valid.
|
|
158
417
|
*
|
|
159
|
-
* @param validators
|
|
160
|
-
* @returns
|
|
418
|
+
* @param validators - One or more validator functions to run
|
|
419
|
+
* @returns The validation result
|
|
161
420
|
*/
|
|
162
421
|
validate(...validators: Validator<Context>[]): import("..").Validation<this>;
|
|
163
422
|
/**
|
|
164
|
-
* Validate context ensuring at least one validator is valid
|
|
165
|
-
*
|
|
166
|
-
* @
|
|
423
|
+
* Validate context ensuring at least one validator is valid.
|
|
424
|
+
*
|
|
425
|
+
* @param validators - One or more validator functions to run
|
|
426
|
+
* @returns The validation result
|
|
167
427
|
*/
|
|
168
428
|
validateAny(...validators: Validator<Context>[]): import("..").Validation<any>;
|
|
169
429
|
/**
|
|
170
430
|
* Add a callback to listen for an event in this context.
|
|
171
431
|
*
|
|
172
|
-
* @param event
|
|
173
|
-
* @param listener
|
|
174
|
-
* @returns
|
|
432
|
+
* @param type - The event type to listen for
|
|
433
|
+
* @param listener - The callback function to invoke when the event is emitted
|
|
434
|
+
* @returns A function to unregister the listener
|
|
175
435
|
*/
|
|
176
436
|
on<E extends IEvent = IEvent>(type: IEvent['type'], listener: ContextListener<this, E>): () => void;
|
|
177
437
|
/**
|
|
178
|
-
* Emit an event in this context
|
|
438
|
+
* Emit an event in this context.
|
|
179
439
|
*
|
|
180
|
-
* @param event
|
|
181
|
-
* @
|
|
182
|
-
* @returns
|
|
440
|
+
* @param event - The event type string or event object to emit
|
|
441
|
+
* @returns A promise that resolves when all event listeners have completed
|
|
183
442
|
*/
|
|
184
443
|
emit(event: string | IEvent): Promise<void>;
|
|
185
444
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGpD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;CAAG;AAEvC;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,+CAA+C;IAC/C,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAA;IAC/C,oCAAoC;IACpC,cAAc,EAAE,iBAAi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V,GAAG,CAAC,GAAG,UAAU,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5D;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,UAAU,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE;IAI5C;;;;;OAKG;IACH,WAAW,CAAC,GAAG,UAAU,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE;IAI/C;;;;;;OAMG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IAMtF;;;;;OAKG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAMjC;;;;;OAKG;IACH,MAAM,CAAC,YAAY,SAAS,OAAO,CAAC,KAAK,CAAC,KAAK,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC;CAGnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../../src/http/request-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../../src/http/request-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEvF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,0BAM/E;AAED,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,YAAY,EAC3D,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,GAAG,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAAE,qCAS9C;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAA;AAC9E,MAAM,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAChG,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,GAAG,KAAK,GAAG,CAAA;AAC3G,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,sBAAsB,GAAG,cAAc,CAAA;AAEtF,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,uBAM5E;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,iBAAiB,EAAE,uBAQpH"}
|
package/dist/ts/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './application/use-declaro';
|
|
|
23
23
|
export * from './context/context';
|
|
24
24
|
export * from './context/context-consumer';
|
|
25
25
|
export * from './context/validators';
|
|
26
|
+
export * from './context/async-context';
|
|
26
27
|
export * from './dataflow';
|
|
27
28
|
export * from './events';
|
|
28
29
|
export * from './validation';
|
|
@@ -42,4 +43,5 @@ export * from './schema/model-schema';
|
|
|
42
43
|
export * from './schema/schema-mixin';
|
|
43
44
|
export * from './schema/test/mock-model';
|
|
44
45
|
export * from './shared/utils/action-descriptor';
|
|
46
|
+
export * from './shared/utils/schema-utils';
|
|
45
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACR;;;;;;GAMG;AACH,QAAQ;AACR;;;;;;GAMG;AACH,YAAY,GACf,MAAM,QAAQ,CAAA;AAEf,cAAc,uBAAuB,CAAA;AAErC,cAAc,cAAc,CAAA;AAC5B,cAAc,OAAO,CAAA;AACrB,cAAc,sCAAsC,CAAA;AACpD,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AAExC,cAAc,kCAAkC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACR;;;;;;GAMG;AACH,QAAQ;AACR;;;;;;GAMG;AACH,YAAY,GACf,MAAM,QAAQ,CAAA;AAEf,cAAc,uBAAuB,CAAA;AAErC,cAAc,cAAc,CAAA;AAC5B,cAAc,OAAO,CAAA;AACrB,cAAc,sCAAsC,CAAA;AACpD,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AAExC,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { type JSONSchema7 } from 'json-schema';
|
|
2
|
-
export
|
|
2
|
+
export type JSONSchemaDefinition = JSONSchema | boolean;
|
|
3
|
+
export interface JSONMeta {
|
|
4
|
+
hidden?: boolean;
|
|
5
|
+
private?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface JSONSchema extends JSONSchema7, JSONMeta {
|
|
8
|
+
properties?: {
|
|
9
|
+
[key: string]: JSONSchemaDefinition;
|
|
10
|
+
} | undefined;
|
|
3
11
|
}
|
|
4
12
|
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../../src/schema/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,WAAW,UAAW,SAAQ,WAAW;
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../../src/schema/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,OAAO,CAAA;AAEvD,MAAM,WAAW,QAAQ;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,UAAW,SAAQ,WAAW,EAAE,QAAQ;IACrD,UAAU,CAAC,EACL;QACI,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAAA;KACtC,GACD,SAAS,CAAA;CAClB"}
|
|
@@ -4,6 +4,10 @@ import { type ModelLabels } from './labels';
|
|
|
4
4
|
export interface ModelValidationOptions {
|
|
5
5
|
strict?: boolean;
|
|
6
6
|
}
|
|
7
|
+
export interface ModelSchemaOptions {
|
|
8
|
+
includePrivateFields?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function getDefaultModelSchemaOptions(): ModelSchemaOptions;
|
|
7
11
|
export declare abstract class Model<TName extends Readonly<string>, TSchema extends StandardSchemaV1> implements StandardSchemaV1<StandardSchemaV1.InferInput<TSchema>, StandardSchemaV1.InferOutput<TSchema>> {
|
|
8
12
|
readonly name: TName;
|
|
9
13
|
/**
|
|
@@ -13,9 +17,10 @@ export declare abstract class Model<TName extends Readonly<string>, TSchema exte
|
|
|
13
17
|
*/
|
|
14
18
|
readonly schema: TSchema;
|
|
15
19
|
constructor(name: TName, schema: TSchema);
|
|
20
|
+
stripExcludedFields(value: StandardSchemaV1.InferInput<TSchema>): StandardSchemaV1.InferInput<TSchema>;
|
|
16
21
|
validate(value: StandardSchemaV1.InferInput<TSchema>, options?: ModelValidationOptions): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
17
22
|
get labels(): ModelLabels;
|
|
18
|
-
abstract toJSONSchema(): JSONSchema;
|
|
23
|
+
abstract toJSONSchema(options?: ModelSchemaOptions): JSONSchema;
|
|
19
24
|
get version(): number;
|
|
20
25
|
get '~standard'(): StandardSchemaV1['~standard'];
|
|
21
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/schema/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtD,MAAM,WAAW,sBAAsB;IACnC,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,8BAAsB,KAAK,CAAC,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,SAAS,gBAAgB,CACxF,YAAW,gBAAgB,CAAC,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAExG,SAAgB,IAAI,EAAE,KAAK,CAAA;IAC3B;;;;OAIG;IACH,SAAgB,MAAM,EAAE,OAAO,CAAA;gBAEnB,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/schema/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtD,MAAM,WAAW,sBAAsB;IACnC,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,kBAAkB;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAA;CACjC;AAED,wBAAgB,4BAA4B,IAAI,kBAAkB,CAIjE;AAED,8BAAsB,KAAK,CAAC,KAAK,SAA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AC,IAAI,gBAAgB,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;AAE1G,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAA;AAEjE,MAAM,WAAW,YAAY,CAAC,mBAAmB,SAAS,QAAQ,CAAC,MAAM,CAAC;IACtE,IAAI,EAAE,mBAAmB,CAAA;CAC5B;AAED,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,SAAS,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { $ZodType } from 'zod/v4/core';
|
|
2
2
|
import type { JSONSchema } from '../json-schema';
|
|
3
|
-
import { Model } from '../model';
|
|
3
|
+
import { Model, type ModelSchemaOptions } from '../model';
|
|
4
4
|
export declare class MockModel<TName extends Readonly<string>, TSchema extends $ZodType<any>> extends Model<TName, TSchema> {
|
|
5
5
|
constructor(name: TName, schema: TSchema);
|
|
6
|
-
toJSONSchema(): JSONSchema;
|
|
6
|
+
toJSONSchema(options?: ModelSchemaOptions): JSONSchema;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=mock-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-model.d.ts","sourceRoot":"","sources":["../../../../src/schema/test/mock-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"mock-model.d.ts","sourceRoot":"","sources":["../../../../src/schema/test/mock-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGzD,qBAAa,SAAS,CAAC,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,SAAS,QAAQ,CAAC,GAAG,CAAC,CAAE,SAAQ,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC;gBACnG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO;IAIxC,YAAY,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,UAAU;CAOzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../../../src/shared/utils/schema-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAc3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.test.d.ts","sourceRoot":"","sources":["../../../../src/shared/utils/schema-utils.test.ts"],"names":[],"mappings":""}
|