@bluelibs/runner 4.5.2 → 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.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 ? EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TConfig> : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
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 ? EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TInput> : TInput, dependencies: DependencyValuesType<TDependencies>) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
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
  */
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 ? EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TConfig> : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
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 ? EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TInput> : TInput, dependencies: DependencyValuesType<TDependencies>) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluelibs/runner",
3
- "version": "4.5.2",
3
+ "version": "4.5.3",
4
4
  "description": "BlueLibs Runner",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.cjs",