@bluelibs/runner 4.5.1 → 4.5.3
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.cjs +13 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +33 -5
- package/dist/index.d.ts +33 -5
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,6 +59,12 @@ type HasInputContracts<TItems extends readonly unknown[]> = [
|
|
|
59
59
|
type HasOutputContracts<TItems extends readonly unknown[]> = [
|
|
60
60
|
ContractsUnionOutputs<TItems>
|
|
61
61
|
] extends [never] ? false : true;
|
|
62
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
63
|
+
type KeysWithNever<T> = T extends object ? {
|
|
64
|
+
[K in keyof T]-?: [T[K]] extends [never] ? K : never;
|
|
65
|
+
}[keyof T] : never;
|
|
66
|
+
type HasNeverProperty<T> = KeysWithNever<T> extends never ? false : true;
|
|
67
|
+
type IsImpossibleIntersection<T> = IsNever<T> extends true ? true : HasNeverProperty<T> extends true ? true : false;
|
|
62
68
|
type InputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
63
69
|
message: "Value does not satisfy all input contracts";
|
|
64
70
|
expected: Simplify<ContractsIntersectionInputs<TItems>>;
|
|
@@ -71,6 +77,7 @@ type OutputContractViolationError<TItems extends readonly unknown[], TActual> =
|
|
|
71
77
|
};
|
|
72
78
|
type EnsureInputSatisfiesContracts<TItems extends readonly unknown[], TValue> = [ContractsUnionInputs<TItems>] extends [never] ? TValue : TValue extends Promise<infer U> ? Promise<U extends ContractsIntersectionInputs<TItems> ? U : InputContractViolationError<TItems, U>> : TValue extends ContractsIntersectionInputs<TItems> ? TValue : InputContractViolationError<TItems, TValue>;
|
|
73
79
|
type EnsureOutputSatisfiesContracts<TItems extends readonly unknown[], TResponse> = [ContractsUnionOutputs<TItems>] extends [never] ? TResponse : TResponse extends Promise<infer U> ? Promise<U extends ContractsIntersectionOutputs<TItems> ? U : OutputContractViolationError<TItems, U>> : TResponse extends ContractsIntersectionOutputs<TItems> ? TResponse : OutputContractViolationError<TItems, TResponse>;
|
|
80
|
+
type InferInputOrViolationFromContracts<TItems extends readonly unknown[]> = HasInputContracts<TItems> extends false ? void : ContractsIntersectionInputs<TItems> extends infer I ? IsImpossibleIntersection<I> extends true ? InputContractViolationError<TItems, Simplify<I extends never ? never : I>> : Simplify<I> : never;
|
|
74
81
|
|
|
75
82
|
/**
|
|
76
83
|
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
@@ -165,6 +172,8 @@ declare const symbolStore: unique symbol;
|
|
|
165
172
|
/** @internal Brand used by index() resources */
|
|
166
173
|
declare const symbolIndexResource: unique symbol;
|
|
167
174
|
|
|
175
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
176
|
+
type IsUnspecified<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : IsAny<T> extends true ? true : false;
|
|
168
177
|
interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> {
|
|
169
178
|
/** Stable identifier. */
|
|
170
179
|
id: string;
|
|
@@ -178,7 +187,10 @@ interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promi
|
|
|
178
187
|
/**
|
|
179
188
|
* Initialize and return the resource value. Called once during boot.
|
|
180
189
|
*/
|
|
181
|
-
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ?
|
|
190
|
+
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? (IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[
|
|
191
|
+
...TTags,
|
|
192
|
+
...TMiddleware
|
|
193
|
+
], TConfig>) : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
|
|
182
194
|
/**
|
|
183
195
|
* Optional validation schema for the resource's resolved value.
|
|
184
196
|
* When provided, the value will be validated immediately after `init` resolves,
|
|
@@ -224,7 +236,7 @@ interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promi
|
|
|
224
236
|
}
|
|
225
237
|
interface IResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext, any, any, TMeta, TTags, TMiddleware> {
|
|
226
238
|
id: string;
|
|
227
|
-
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
239
|
+
with(config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? (IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : TConfig) : TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
228
240
|
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
229
241
|
overrides: Array<OverridableElements>;
|
|
230
242
|
middleware: TMiddleware;
|
|
@@ -267,7 +279,10 @@ interface ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any
|
|
|
267
279
|
* `run` resolves, without considering middleware.
|
|
268
280
|
*/
|
|
269
281
|
resultSchema?: IValidationSchema<TOutput extends Promise<infer U> ? U : never>;
|
|
270
|
-
run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ?
|
|
282
|
+
run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? ([TInput] extends [undefined] ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[
|
|
283
|
+
...TTags,
|
|
284
|
+
...TMiddleware
|
|
285
|
+
], TInput>) : TInput, dependencies: DependencyValuesType<TDependencies>) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
|
|
271
286
|
/**
|
|
272
287
|
* Tags applied to the task that might define its behvaiour or impact the systems.
|
|
273
288
|
*/
|
|
@@ -1380,15 +1395,28 @@ declare class Store {
|
|
|
1380
1395
|
validateEventEmissionGraph(): void;
|
|
1381
1396
|
initializeStore(root: IResource<any, any, any, any, any>, config: any): void;
|
|
1382
1397
|
dispose(): Promise<void>;
|
|
1398
|
+
/**
|
|
1399
|
+
* Internal, avoid using this method directly.
|
|
1400
|
+
*/
|
|
1383
1401
|
processOverrides(): void;
|
|
1402
|
+
/**
|
|
1403
|
+
* Internal, avoid using this method directly.
|
|
1404
|
+
* @param item
|
|
1405
|
+
* @returns
|
|
1406
|
+
*/
|
|
1384
1407
|
storeGenericItem<C>(item: RegisterableItems): void;
|
|
1385
1408
|
/**
|
|
1386
1409
|
* Returns all tasks with the given tag.
|
|
1387
1410
|
* @param tag - The tag to filter by.
|
|
1388
1411
|
* @returns The tasks with the given tag.
|
|
1389
1412
|
*/
|
|
1390
|
-
getTasksWithTag(tag: string | ITag): ITask<any, any, any, any, TagType[], TaskMiddlewareAttachmentType[]>[];
|
|
1391
|
-
|
|
1413
|
+
getTasksWithTag(tag: string | ITag<any, any, any>): ITask<any, any, any, any, TagType[], TaskMiddlewareAttachmentType[]>[];
|
|
1414
|
+
/**
|
|
1415
|
+
* Returns all resources with the given tag.
|
|
1416
|
+
* @param tag - The tag to filter by.
|
|
1417
|
+
* @returns The resources with the given tag.
|
|
1418
|
+
*/
|
|
1419
|
+
getResourcesWithTag(tag: string | ITag<any, any, any>): IResource<any, any, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>[];
|
|
1392
1420
|
}
|
|
1393
1421
|
|
|
1394
1422
|
declare class ResourceInitializer {
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,12 @@ type HasInputContracts<TItems extends readonly unknown[]> = [
|
|
|
59
59
|
type HasOutputContracts<TItems extends readonly unknown[]> = [
|
|
60
60
|
ContractsUnionOutputs<TItems>
|
|
61
61
|
] extends [never] ? false : true;
|
|
62
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
63
|
+
type KeysWithNever<T> = T extends object ? {
|
|
64
|
+
[K in keyof T]-?: [T[K]] extends [never] ? K : never;
|
|
65
|
+
}[keyof T] : never;
|
|
66
|
+
type HasNeverProperty<T> = KeysWithNever<T> extends never ? false : true;
|
|
67
|
+
type IsImpossibleIntersection<T> = IsNever<T> extends true ? true : HasNeverProperty<T> extends true ? true : false;
|
|
62
68
|
type InputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
63
69
|
message: "Value does not satisfy all input contracts";
|
|
64
70
|
expected: Simplify<ContractsIntersectionInputs<TItems>>;
|
|
@@ -71,6 +77,7 @@ type OutputContractViolationError<TItems extends readonly unknown[], TActual> =
|
|
|
71
77
|
};
|
|
72
78
|
type EnsureInputSatisfiesContracts<TItems extends readonly unknown[], TValue> = [ContractsUnionInputs<TItems>] extends [never] ? TValue : TValue extends Promise<infer U> ? Promise<U extends ContractsIntersectionInputs<TItems> ? U : InputContractViolationError<TItems, U>> : TValue extends ContractsIntersectionInputs<TItems> ? TValue : InputContractViolationError<TItems, TValue>;
|
|
73
79
|
type EnsureOutputSatisfiesContracts<TItems extends readonly unknown[], TResponse> = [ContractsUnionOutputs<TItems>] extends [never] ? TResponse : TResponse extends Promise<infer U> ? Promise<U extends ContractsIntersectionOutputs<TItems> ? U : OutputContractViolationError<TItems, U>> : TResponse extends ContractsIntersectionOutputs<TItems> ? TResponse : OutputContractViolationError<TItems, TResponse>;
|
|
80
|
+
type InferInputOrViolationFromContracts<TItems extends readonly unknown[]> = HasInputContracts<TItems> extends false ? void : ContractsIntersectionInputs<TItems> extends infer I ? IsImpossibleIntersection<I> extends true ? InputContractViolationError<TItems, Simplify<I extends never ? never : I>> : Simplify<I> : never;
|
|
74
81
|
|
|
75
82
|
/**
|
|
76
83
|
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
@@ -165,6 +172,8 @@ declare const symbolStore: unique symbol;
|
|
|
165
172
|
/** @internal Brand used by index() resources */
|
|
166
173
|
declare const symbolIndexResource: unique symbol;
|
|
167
174
|
|
|
175
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
176
|
+
type IsUnspecified<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : IsAny<T> extends true ? true : false;
|
|
168
177
|
interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> {
|
|
169
178
|
/** Stable identifier. */
|
|
170
179
|
id: string;
|
|
@@ -178,7 +187,10 @@ interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promi
|
|
|
178
187
|
/**
|
|
179
188
|
* Initialize and return the resource value. Called once during boot.
|
|
180
189
|
*/
|
|
181
|
-
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ?
|
|
190
|
+
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? (IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[
|
|
191
|
+
...TTags,
|
|
192
|
+
...TMiddleware
|
|
193
|
+
], TConfig>) : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
|
|
182
194
|
/**
|
|
183
195
|
* Optional validation schema for the resource's resolved value.
|
|
184
196
|
* When provided, the value will be validated immediately after `init` resolves,
|
|
@@ -224,7 +236,7 @@ interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promi
|
|
|
224
236
|
}
|
|
225
237
|
interface IResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext, any, any, TMeta, TTags, TMiddleware> {
|
|
226
238
|
id: string;
|
|
227
|
-
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
239
|
+
with(config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? (IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : TConfig) : TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
228
240
|
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
229
241
|
overrides: Array<OverridableElements>;
|
|
230
242
|
middleware: TMiddleware;
|
|
@@ -267,7 +279,10 @@ interface ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any
|
|
|
267
279
|
* `run` resolves, without considering middleware.
|
|
268
280
|
*/
|
|
269
281
|
resultSchema?: IValidationSchema<TOutput extends Promise<infer U> ? U : never>;
|
|
270
|
-
run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ?
|
|
282
|
+
run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? ([TInput] extends [undefined] ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[
|
|
283
|
+
...TTags,
|
|
284
|
+
...TMiddleware
|
|
285
|
+
], TInput>) : TInput, dependencies: DependencyValuesType<TDependencies>) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
|
|
271
286
|
/**
|
|
272
287
|
* Tags applied to the task that might define its behvaiour or impact the systems.
|
|
273
288
|
*/
|
|
@@ -1380,15 +1395,28 @@ declare class Store {
|
|
|
1380
1395
|
validateEventEmissionGraph(): void;
|
|
1381
1396
|
initializeStore(root: IResource<any, any, any, any, any>, config: any): void;
|
|
1382
1397
|
dispose(): Promise<void>;
|
|
1398
|
+
/**
|
|
1399
|
+
* Internal, avoid using this method directly.
|
|
1400
|
+
*/
|
|
1383
1401
|
processOverrides(): void;
|
|
1402
|
+
/**
|
|
1403
|
+
* Internal, avoid using this method directly.
|
|
1404
|
+
* @param item
|
|
1405
|
+
* @returns
|
|
1406
|
+
*/
|
|
1384
1407
|
storeGenericItem<C>(item: RegisterableItems): void;
|
|
1385
1408
|
/**
|
|
1386
1409
|
* Returns all tasks with the given tag.
|
|
1387
1410
|
* @param tag - The tag to filter by.
|
|
1388
1411
|
* @returns The tasks with the given tag.
|
|
1389
1412
|
*/
|
|
1390
|
-
getTasksWithTag(tag: string | ITag): ITask<any, any, any, any, TagType[], TaskMiddlewareAttachmentType[]>[];
|
|
1391
|
-
|
|
1413
|
+
getTasksWithTag(tag: string | ITag<any, any, any>): ITask<any, any, any, any, TagType[], TaskMiddlewareAttachmentType[]>[];
|
|
1414
|
+
/**
|
|
1415
|
+
* Returns all resources with the given tag.
|
|
1416
|
+
* @param tag - The tag to filter by.
|
|
1417
|
+
* @returns The resources with the given tag.
|
|
1418
|
+
*/
|
|
1419
|
+
getResourcesWithTag(tag: string | ITag<any, any, any>): IResource<any, any, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>[];
|
|
1392
1420
|
}
|
|
1393
1421
|
|
|
1394
1422
|
declare class ResourceInitializer {
|
package/dist/index.mjs
CHANGED
|
@@ -3490,9 +3490,17 @@ var _Store = class _Store {
|
|
|
3490
3490
|
}
|
|
3491
3491
|
}
|
|
3492
3492
|
}
|
|
3493
|
+
/**
|
|
3494
|
+
* Internal, avoid using this method directly.
|
|
3495
|
+
*/
|
|
3493
3496
|
processOverrides() {
|
|
3494
3497
|
this.overrideManager.processOverrides();
|
|
3495
3498
|
}
|
|
3499
|
+
/**
|
|
3500
|
+
* Internal, avoid using this method directly.
|
|
3501
|
+
* @param item
|
|
3502
|
+
* @returns
|
|
3503
|
+
*/
|
|
3496
3504
|
storeGenericItem(item) {
|
|
3497
3505
|
return this.registry.storeGenericItem(item);
|
|
3498
3506
|
}
|
|
@@ -3504,6 +3512,11 @@ var _Store = class _Store {
|
|
|
3504
3512
|
getTasksWithTag(tag) {
|
|
3505
3513
|
return this.registry.getTasksWithTag(tag);
|
|
3506
3514
|
}
|
|
3515
|
+
/**
|
|
3516
|
+
* Returns all resources with the given tag.
|
|
3517
|
+
* @param tag - The tag to filter by.
|
|
3518
|
+
* @returns The resources with the given tag.
|
|
3519
|
+
*/
|
|
3507
3520
|
getResourcesWithTag(tag) {
|
|
3508
3521
|
return this.registry.getResourcesWithTag(tag);
|
|
3509
3522
|
}
|