@gqloom/core 0.4.0 → 0.5.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/README.md CHANGED
@@ -18,14 +18,15 @@ The design of GQLoom is inspired by [tRPC](https://trpc.io/), [TypeGraphQL](http
18
18
  ## Hello World
19
19
 
20
20
  ```ts
21
- import { resolver, query, weave } from "@gqloom/valibot"
21
+ import { resolver, query, weave } from "@gqloom/core"
22
+ import { ValibotWeaver } from "@gqloom/valibot"
22
23
  import * as v from "valibot"
23
24
 
24
- const HelloResolver = resolver({
25
+ const helloResolver = resolver({
25
26
  hello: query(v.string(), () => "world"),
26
27
  })
27
28
 
28
- export const schema = weave(HelloResolver)
29
+ export const schema = weave(ValibotWeaver, helloResolver)
29
30
  ```
30
31
 
31
32
  Read [Introduction](https://gqloom.dev/guide/introduction.html) to learn more about GQLoom.
package/dist/index.cjs CHANGED
@@ -227,7 +227,9 @@ function collectName(name, schema) {
227
227
  }
228
228
 
229
229
  // src/resolver/silk.ts
230
- function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
230
+ function silk(type, validate = (value) => ({
231
+ value: value ?? void 0
232
+ })) {
231
233
  return {
232
234
  [GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
233
235
  "~standard": {
@@ -332,13 +334,17 @@ function getFieldOptions({
332
334
  }
333
335
 
334
336
  // src/utils/middleware.ts
335
- function applyMiddlewares(middlewares, resolveFunction, payload) {
337
+ function applyMiddlewares(middlewares, resolveFunction, options) {
336
338
  const next = (index) => {
337
339
  if (index >= middlewares.length) {
338
340
  return resolveFunction();
339
341
  }
340
342
  const middleware = middlewares[index];
341
- return middleware(() => next(index + 1), payload);
343
+ const callableOptions = Object.assign(() => next(index + 1), {
344
+ ...options,
345
+ next: () => next(index + 1)
346
+ });
347
+ return middleware(callableOptions);
342
348
  };
343
349
  return next(0);
344
350
  }
@@ -1073,7 +1079,7 @@ var SchemaWeaver = class _SchemaWeaver {
1073
1079
  if (query2 != null) this.query = query2;
1074
1080
  if (mutation2 != null) this.mutation = mutation2;
1075
1081
  if (subscription2 != null) this.subscription = subscription2;
1076
- if (types != null) this.types = types.slice();
1082
+ this.types = new Set(types ?? []);
1077
1083
  this.context = context ?? initWeaverContext();
1078
1084
  }
1079
1085
  use(...middlewares) {
@@ -1107,8 +1113,7 @@ var SchemaWeaver = class _SchemaWeaver {
1107
1113
  `${gqlType2?.name ?? gqlType2.toString()} is not a named type`
1108
1114
  );
1109
1115
  }, this.context);
1110
- this.types ??= [];
1111
- this.types.push(gqlType);
1116
+ this.types.add(gqlType);
1112
1117
  return this;
1113
1118
  }
1114
1119
  setConfig(config) {
@@ -1134,16 +1139,17 @@ var SchemaWeaver = class _SchemaWeaver {
1134
1139
  if (parent == null) return void 0;
1135
1140
  let gqlType = getGraphQLType(parent);
1136
1141
  if ((0, import_graphql6.isNonNullType)(gqlType)) gqlType = gqlType.ofType;
1137
- if ((0, import_graphql6.isObjectType)(gqlType)) {
1138
- const existing = this.context.loomObjectMap.get(gqlType);
1139
- if (existing != null) return existing;
1140
- const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
1141
- this.context.loomObjectMap.set(gqlType, extraObject);
1142
- return extraObject;
1142
+ if (!(0, import_graphql6.isObjectType)(gqlType)) {
1143
+ throw new Error(
1144
+ `${gqlType?.name ?? gqlType.toString()} is not an object type`
1145
+ );
1143
1146
  }
1144
- throw new Error(
1145
- `${gqlType?.name ?? gqlType.toString()} is not an object type`
1146
- );
1147
+ const existing = this.context.loomObjectMap.get(gqlType);
1148
+ if (existing != null) return existing;
1149
+ const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
1150
+ this.context.loomObjectMap.set(gqlType, extraObject);
1151
+ this.types.add(extraObject);
1152
+ return extraObject;
1147
1153
  })();
1148
1154
  if (resolverOptions?.extensions && parentObject)
1149
1155
  parentObject.mergeExtensions(resolverOptions.extensions);
package/dist/index.d.cts CHANGED
@@ -1,20 +1,20 @@
1
1
  import { GraphQLOutputType, GraphQLObjectTypeConfig, GraphQLFieldConfig, GraphQLResolveInfo, GraphQLScalarType, GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLSchemaConfig, GraphQLFieldMap, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
- declare namespace v1 {
4
+ /**
5
+ * The Standard Schema interface.
6
+ */
7
+ type StandardSchemaV1<Input = unknown, Output = Input> = {
5
8
  /**
6
- * The Standard Schema interface.
9
+ * The Standard Schema properties.
7
10
  */
8
- interface StandardSchema<Input = unknown, Output = Input> {
9
- /**
10
- * The Standard Schema properties.
11
- */
12
- readonly "~standard": StandardSchemaProps<Input, Output>;
13
- }
11
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
12
+ };
13
+ declare namespace StandardSchemaV1 {
14
14
  /**
15
15
  * The Standard Schema properties interface.
16
16
  */
17
- interface StandardSchemaProps<Input = unknown, Output = Input> {
17
+ export interface Props<Input = unknown, Output = Input> {
18
18
  /**
19
19
  * The version number of the standard.
20
20
  */
@@ -26,20 +26,20 @@ declare namespace v1 {
26
26
  /**
27
27
  * Validates unknown input values.
28
28
  */
29
- readonly validate: (value: unknown) => StandardResult<Output> | Promise<StandardResult<Output>>;
29
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
30
30
  /**
31
31
  * Inferred types associated with the schema.
32
32
  */
33
- readonly types?: StandardTypes<Input, Output> | undefined;
33
+ readonly types?: Types<Input, Output> | undefined;
34
34
  }
35
35
  /**
36
36
  * The result interface of the validate function.
37
37
  */
38
- type StandardResult<Output> = StandardSuccessResult<Output> | StandardFailureResult;
38
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
39
39
  /**
40
40
  * The result interface if validation succeeds.
41
41
  */
42
- interface StandardSuccessResult<Output> {
42
+ export interface SuccessResult<Output> {
43
43
  /**
44
44
  * The typed output value.
45
45
  */
@@ -52,16 +52,16 @@ declare namespace v1 {
52
52
  /**
53
53
  * The result interface if validation fails.
54
54
  */
55
- interface StandardFailureResult {
55
+ export interface FailureResult {
56
56
  /**
57
57
  * The issues of failed validation.
58
58
  */
59
- readonly issues: ReadonlyArray<StandardIssue>;
59
+ readonly issues: ReadonlyArray<Issue>;
60
60
  }
61
61
  /**
62
62
  * The issue interface of the failure output.
63
63
  */
64
- interface StandardIssue {
64
+ export interface Issue {
65
65
  /**
66
66
  * The error message of the issue.
67
67
  */
@@ -69,21 +69,21 @@ declare namespace v1 {
69
69
  /**
70
70
  * The path of the issue, if any.
71
71
  */
72
- readonly path?: ReadonlyArray<PropertyKey | StandardPathSegment> | undefined;
72
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
73
73
  }
74
74
  /**
75
75
  * The path segment interface of the issue.
76
76
  */
77
- interface StandardPathSegment {
77
+ export interface PathSegment {
78
78
  /**
79
79
  * The key representing a path segment.
80
80
  */
81
81
  readonly key: PropertyKey;
82
82
  }
83
83
  /**
84
- * The base types interface of Standard Schema.
84
+ * The Standard Schema types interface.
85
85
  */
86
- interface StandardTypes<Input, Output> {
86
+ export interface Types<Input = unknown, Output = Input> {
87
87
  /**
88
88
  * The input type of the schema.
89
89
  */
@@ -96,11 +96,12 @@ declare namespace v1 {
96
96
  /**
97
97
  * Infers the input type of a Standard Schema.
98
98
  */
99
- type InferInput<Schema extends StandardSchema> = NonNullable<Schema["~standard"]["types"]>["input"];
99
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
100
100
  /**
101
101
  * Infers the output type of a Standard Schema.
102
102
  */
103
- type InferOutput<Schema extends StandardSchema> = NonNullable<Schema["~standard"]["types"]>["output"];
103
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
104
+ export { };
104
105
  }
105
106
 
106
107
  type MayPromise<T> = T | Promise<T>;
@@ -182,19 +183,19 @@ interface CallableInputParser<TSchema extends InputSchema<GraphQLSilk>> {
182
183
  /**
183
184
  * Parse the input and return the
184
185
  */
185
- (): Promise<v1.StandardResult<InferInputO<TSchema, GraphQLSilkIO>>>;
186
+ (): Promise<StandardSchemaV1.Result<InferInputO<TSchema, GraphQLSilkIO>>>;
186
187
  /**
187
188
  * Result of parsing. Set it to `undefined` then the parser will run again.
188
189
  */
189
- result: v1.StandardResult<InferInputO<TSchema, GraphQLSilkIO>> | undefined;
190
+ result: StandardSchemaV1.Result<InferInputO<TSchema, GraphQLSilkIO>> | undefined;
190
191
  }
191
192
  declare function createInputParser<TSchema extends InputSchema<GraphQLSilk> | undefined>(schema: TSchema, value: InferInputI<TSchema, GraphQLSilkIO>): CallableInputParser<TSchema>;
192
- declare function parseInputValue<TSchema extends InputSchema<GraphQLSilk> | undefined>(inputSchema: TSchema, input: any): MayPromise<v1.StandardResult<InferInputO<TSchema, GraphQLSilkIO>>>;
193
- declare function getStandardValue<T>(result: v1.StandardResult<T>): T;
194
- declare function getStandardValue<T>(result?: v1.StandardResult<T>): T | undefined;
195
- declare function getStandardValue<T>(result: v1.StandardResult<T> | null): T | null;
193
+ declare function parseInputValue<TSchema extends InputSchema<GraphQLSilk> | undefined>(inputSchema: TSchema, input: any): MayPromise<StandardSchemaV1.Result<InferInputO<TSchema, GraphQLSilkIO>>>;
194
+ declare function getStandardValue<T>(result: StandardSchemaV1.Result<T>): T;
195
+ declare function getStandardValue<T>(result?: StandardSchemaV1.Result<T>): T | undefined;
196
+ declare function getStandardValue<T>(result: StandardSchemaV1.Result<T> | null): T | null;
196
197
 
197
- interface GraphQLSilk<TOutput = any, TInput = any> extends v1.StandardSchema<TInput, TOutput> {
198
+ interface GraphQLSilk<TOutput = any, TInput = any> extends StandardSchemaV1<TInput, TOutput> {
198
199
  /**
199
200
  * GraphQL type for schema
200
201
  */
@@ -234,7 +235,7 @@ interface FieldOrOperation<TParent extends undefined | GraphQLSilk, TOutput exte
234
235
  type: TType;
235
236
  input: TInput;
236
237
  output: TOutput;
237
- resolve: TType extends "field" ? (parent: v1.InferOutput<NonNullable<TParent>>, input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<v1.InferOutput<TOutput>> : TType extends "subscription" ? (value: any, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<v1.InferOutput<TOutput>> : (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<v1.InferOutput<TOutput>>;
238
+ resolve: TType extends "field" ? (parent: StandardSchemaV1.InferOutput<NonNullable<TParent>>, input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<StandardSchemaV1.InferOutput<TOutput>> : TType extends "subscription" ? (value: any, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<StandardSchemaV1.InferOutput<TOutput>> : (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<StandardSchemaV1.InferOutput<TOutput>>;
238
239
  subscribe?: TType extends "subscription" ? (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => MayPromise<AsyncIterator<any>> : undefined;
239
240
  }
240
241
  type GenericFieldOrOperation = FieldOrOperation<any, any, any, any>;
@@ -285,8 +286,8 @@ interface SubscriptionOptions<TSchemaIO extends AbstractSchemaIO, TOutput extend
285
286
  subscribe: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<AsyncIterator<TValue>>;
286
287
  resolve?: (value: TValue, input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>;
287
288
  }
288
- interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<GraphQLSilk> = undefined, TValue = v1.InferOutput<TOutput>> extends FieldOrOperation<undefined, TOutput, TInput, "subscription"> {
289
- resolve: (value: TValue, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<v1.InferOutput<TOutput>>;
289
+ interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<GraphQLSilk> = undefined, TValue = StandardSchemaV1.InferOutput<TOutput>> extends FieldOrOperation<undefined, TOutput, TInput, "subscription"> {
290
+ resolve: (value: TValue, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<StandardSchemaV1.InferOutput<TOutput>>;
290
291
  subscribe: (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => MayPromise<AsyncIterator<TValue>>;
291
292
  }
292
293
  /**
@@ -305,18 +306,24 @@ declare function getOperationOptions<T extends FieldOrOperationType = OperationT
305
306
  declare function getSubscriptionOptions(subscribeOrOptions: (() => any) | SubscriptionOptions<any, any, any, any>): SubscriptionOptions<any, any, any, any>;
306
307
  declare function getFieldOptions({ description, deprecationReason, extensions, }: GraphQLFieldOptions): GraphQLFieldOptions;
307
308
 
308
- interface MiddlewarePayload<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> {
309
+ interface MiddlewareOptions<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> {
309
310
  /** The Output Silk of the field */
310
- outputSilk: v1.InferOutput<InferFieldOutput<TField>>;
311
+ outputSilk: StandardSchemaV1.InferOutput<InferFieldOutput<TField>>;
311
312
  /** The previous object, which for a field on the root Query type is often not used. */
312
- parent: TField extends FieldOrOperation<infer TParent, any, any, any> ? TParent extends undefined ? undefined : v1.InferOutput<NonNullable<TParent>> : never;
313
+ parent: TField extends FieldOrOperation<infer TParent, any, any, any> ? TParent extends undefined ? undefined : StandardSchemaV1.InferOutput<NonNullable<TParent>> : never;
313
314
  /** A function to parse the input of the field */
314
315
  parseInput: TField extends FieldOrOperation<any, any, infer TInput, any> ? CallableInputParser<TInput> : undefined;
315
316
  /** The type of the field: `query`, `mutation`, `subscription` or `field` */
316
317
  type: FieldOrOperationType;
317
318
  }
318
- type Middleware<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> = (next: () => MayPromise<v1.InferOutput<InferFieldOutput<TField>>>, payload: MiddlewarePayload<TField>) => MayPromise<v1.InferOutput<InferFieldOutput<TField>>>;
319
- declare function applyMiddlewares<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>>(middlewares: Middleware[], resolveFunction: () => MayPromise<v1.InferOutput<InferFieldOutput<TField>>>, payload: MiddlewarePayload<TField>): Promise<v1.InferOutput<InferFieldOutput<TField>>>;
319
+ interface CallableMiddlewareOptions<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> extends MiddlewareOptions<TField> {
320
+ /** The function to call next in the middleware chain. */
321
+ next: () => MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
322
+ /** The function to call next in the middleware chain. */
323
+ (): MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
324
+ }
325
+ type Middleware<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> = (options: CallableMiddlewareOptions<TField>) => MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
326
+ declare function applyMiddlewares<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>>(middlewares: Middleware[], resolveFunction: () => MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>, options: MiddlewareOptions<TField>): Promise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
320
327
  declare function compose<T>(...lists: (T[] | undefined)[]): T[];
321
328
 
322
329
  /**
@@ -460,11 +467,11 @@ declare function markLocation(message: string, ...locations: string[]): string;
460
467
  /**
461
468
  * Create a Silk from Scalar.
462
469
  */
463
- declare function silk<TScalar extends GraphQLScalarType>(type: TScalar | (() => TScalar), parse?: (value: InferScalarExternal<TScalar>) => v1.StandardResult<InferScalarExternal<TScalar>> | Promise<v1.StandardResult<InferScalarInternal<TScalar>>>): GraphQLSilk<InferScalarInternal<TScalar> | undefined, InferScalarInternal<TScalar> | undefined>;
470
+ declare function silk<TScalar extends GraphQLScalarType>(type: TScalar | (() => TScalar), parse?: (value: InferScalarExternal<TScalar>) => StandardSchemaV1.Result<InferScalarExternal<TScalar>> | Promise<StandardSchemaV1.Result<InferScalarInternal<TScalar>>>): GraphQLSilk<InferScalarInternal<TScalar> | undefined, InferScalarInternal<TScalar> | undefined>;
464
471
  /**
465
472
  * Create a GraphQLSilk Object.
466
473
  */
467
- declare function silk<TOutput, TInput = TOutput>(type: GraphQLOutputType | (() => GraphQLOutputType), validate?: (value: TInput) => v1.StandardResult<TOutput> | Promise<v1.StandardResult<TOutput>>): GraphQLSilk<TOutput, TInput>;
474
+ declare function silk<TOutput, TInput = TOutput>(type: GraphQLOutputType | (() => GraphQLOutputType), validate?: (value: TInput) => StandardSchemaV1.Result<TOutput> | Promise<StandardSchemaV1.Result<TOutput>>): GraphQLSilk<TOutput, TInput>;
468
475
  declare namespace silk {
469
476
  var parse: typeof parseSilk;
470
477
  var getType: typeof getGraphQLType;
@@ -472,17 +479,17 @@ declare namespace silk {
472
479
  var list: typeof listSilk;
473
480
  var nullable: typeof nullableSilk;
474
481
  }
475
- type NonNullSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<NonNullable<v1.InferOutput<TSilk>>, NonNullable<v1.InferInput<TSilk>>>;
482
+ type NonNullSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<NonNullable<StandardSchemaV1.InferOutput<TSilk>>, NonNullable<StandardSchemaV1.InferInput<TSilk>>>;
476
483
  /**
477
484
  * Non-nullable Silk.
478
485
  */
479
486
  declare function nonNullSilk<TSilk extends GraphQLSilk<any, any>>(origin: TSilk): NonNullSilk<TSilk>;
480
- type ListSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<EnsureArray<v1.InferOutput<TSilk>>, EnsureArray<v1.InferOutput<TSilk>>>;
487
+ type ListSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<EnsureArray<StandardSchemaV1.InferOutput<TSilk>>, EnsureArray<StandardSchemaV1.InferOutput<TSilk>>>;
481
488
  /**
482
489
  * List Silk.
483
490
  */
484
491
  declare function listSilk<TSilk extends GraphQLSilk<any, any>>(origin: TSilk): ListSilk<TSilk>;
485
- type NullableSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<v1.InferOutput<TSilk> | null | undefined, v1.InferInput<TSilk>>;
492
+ type NullableSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<StandardSchemaV1.InferOutput<TSilk> | null | undefined, StandardSchemaV1.InferInput<TSilk>>;
486
493
  /**
487
494
  * Nullable Silk.
488
495
  */
@@ -499,7 +506,7 @@ declare function getGraphQLType(silk: GraphQLSilk): GraphQLOutputType;
499
506
  * @param input
500
507
  * @returns output
501
508
  */
502
- declare function parseSilk<TSilk extends GraphQLSilk>(silk: TSilk, input: v1.InferInput<TSilk>): MayPromise<v1.StandardResult<v1.InferOutput<TSilk>>>;
509
+ declare function parseSilk<TSilk extends GraphQLSilk>(silk: TSilk, input: StandardSchemaV1.InferInput<TSilk>): MayPromise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSilk>>>;
503
510
  declare function isSilk(target: any): target is GraphQLSilk;
504
511
  type InferScalarInternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<infer TInternal> ? TInternal : never;
505
512
  type InferScalarExternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<any, infer TExternal> ? TExternal : never;
@@ -640,7 +647,7 @@ declare class SchemaWeaver {
640
647
  query?: LoomObjectType;
641
648
  mutation?: LoomObjectType;
642
649
  subscription?: LoomObjectType;
643
- types?: GraphQLNamedType[] | null;
650
+ types: Set<GraphQLNamedType>;
644
651
  context: WeaverContext;
645
652
  resolverOptions?: ResolvingOptions;
646
653
  /**
@@ -704,4 +711,4 @@ interface GQLoomExtensionAttribute {
704
711
  directives?: string[];
705
712
  }
706
713
 
707
- export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewarePayload, type MutationFactory, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaVendorWeaver, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, v1, weave, weaverContext };
714
+ export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaVendorWeaver, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
package/dist/index.d.ts CHANGED
@@ -1,20 +1,20 @@
1
1
  import { GraphQLOutputType, GraphQLObjectTypeConfig, GraphQLFieldConfig, GraphQLResolveInfo, GraphQLScalarType, GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLSchemaConfig, GraphQLFieldMap, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
- declare namespace v1 {
4
+ /**
5
+ * The Standard Schema interface.
6
+ */
7
+ type StandardSchemaV1<Input = unknown, Output = Input> = {
5
8
  /**
6
- * The Standard Schema interface.
9
+ * The Standard Schema properties.
7
10
  */
8
- interface StandardSchema<Input = unknown, Output = Input> {
9
- /**
10
- * The Standard Schema properties.
11
- */
12
- readonly "~standard": StandardSchemaProps<Input, Output>;
13
- }
11
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
12
+ };
13
+ declare namespace StandardSchemaV1 {
14
14
  /**
15
15
  * The Standard Schema properties interface.
16
16
  */
17
- interface StandardSchemaProps<Input = unknown, Output = Input> {
17
+ export interface Props<Input = unknown, Output = Input> {
18
18
  /**
19
19
  * The version number of the standard.
20
20
  */
@@ -26,20 +26,20 @@ declare namespace v1 {
26
26
  /**
27
27
  * Validates unknown input values.
28
28
  */
29
- readonly validate: (value: unknown) => StandardResult<Output> | Promise<StandardResult<Output>>;
29
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
30
30
  /**
31
31
  * Inferred types associated with the schema.
32
32
  */
33
- readonly types?: StandardTypes<Input, Output> | undefined;
33
+ readonly types?: Types<Input, Output> | undefined;
34
34
  }
35
35
  /**
36
36
  * The result interface of the validate function.
37
37
  */
38
- type StandardResult<Output> = StandardSuccessResult<Output> | StandardFailureResult;
38
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
39
39
  /**
40
40
  * The result interface if validation succeeds.
41
41
  */
42
- interface StandardSuccessResult<Output> {
42
+ export interface SuccessResult<Output> {
43
43
  /**
44
44
  * The typed output value.
45
45
  */
@@ -52,16 +52,16 @@ declare namespace v1 {
52
52
  /**
53
53
  * The result interface if validation fails.
54
54
  */
55
- interface StandardFailureResult {
55
+ export interface FailureResult {
56
56
  /**
57
57
  * The issues of failed validation.
58
58
  */
59
- readonly issues: ReadonlyArray<StandardIssue>;
59
+ readonly issues: ReadonlyArray<Issue>;
60
60
  }
61
61
  /**
62
62
  * The issue interface of the failure output.
63
63
  */
64
- interface StandardIssue {
64
+ export interface Issue {
65
65
  /**
66
66
  * The error message of the issue.
67
67
  */
@@ -69,21 +69,21 @@ declare namespace v1 {
69
69
  /**
70
70
  * The path of the issue, if any.
71
71
  */
72
- readonly path?: ReadonlyArray<PropertyKey | StandardPathSegment> | undefined;
72
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
73
73
  }
74
74
  /**
75
75
  * The path segment interface of the issue.
76
76
  */
77
- interface StandardPathSegment {
77
+ export interface PathSegment {
78
78
  /**
79
79
  * The key representing a path segment.
80
80
  */
81
81
  readonly key: PropertyKey;
82
82
  }
83
83
  /**
84
- * The base types interface of Standard Schema.
84
+ * The Standard Schema types interface.
85
85
  */
86
- interface StandardTypes<Input, Output> {
86
+ export interface Types<Input = unknown, Output = Input> {
87
87
  /**
88
88
  * The input type of the schema.
89
89
  */
@@ -96,11 +96,12 @@ declare namespace v1 {
96
96
  /**
97
97
  * Infers the input type of a Standard Schema.
98
98
  */
99
- type InferInput<Schema extends StandardSchema> = NonNullable<Schema["~standard"]["types"]>["input"];
99
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
100
100
  /**
101
101
  * Infers the output type of a Standard Schema.
102
102
  */
103
- type InferOutput<Schema extends StandardSchema> = NonNullable<Schema["~standard"]["types"]>["output"];
103
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
104
+ export { };
104
105
  }
105
106
 
106
107
  type MayPromise<T> = T | Promise<T>;
@@ -182,19 +183,19 @@ interface CallableInputParser<TSchema extends InputSchema<GraphQLSilk>> {
182
183
  /**
183
184
  * Parse the input and return the
184
185
  */
185
- (): Promise<v1.StandardResult<InferInputO<TSchema, GraphQLSilkIO>>>;
186
+ (): Promise<StandardSchemaV1.Result<InferInputO<TSchema, GraphQLSilkIO>>>;
186
187
  /**
187
188
  * Result of parsing. Set it to `undefined` then the parser will run again.
188
189
  */
189
- result: v1.StandardResult<InferInputO<TSchema, GraphQLSilkIO>> | undefined;
190
+ result: StandardSchemaV1.Result<InferInputO<TSchema, GraphQLSilkIO>> | undefined;
190
191
  }
191
192
  declare function createInputParser<TSchema extends InputSchema<GraphQLSilk> | undefined>(schema: TSchema, value: InferInputI<TSchema, GraphQLSilkIO>): CallableInputParser<TSchema>;
192
- declare function parseInputValue<TSchema extends InputSchema<GraphQLSilk> | undefined>(inputSchema: TSchema, input: any): MayPromise<v1.StandardResult<InferInputO<TSchema, GraphQLSilkIO>>>;
193
- declare function getStandardValue<T>(result: v1.StandardResult<T>): T;
194
- declare function getStandardValue<T>(result?: v1.StandardResult<T>): T | undefined;
195
- declare function getStandardValue<T>(result: v1.StandardResult<T> | null): T | null;
193
+ declare function parseInputValue<TSchema extends InputSchema<GraphQLSilk> | undefined>(inputSchema: TSchema, input: any): MayPromise<StandardSchemaV1.Result<InferInputO<TSchema, GraphQLSilkIO>>>;
194
+ declare function getStandardValue<T>(result: StandardSchemaV1.Result<T>): T;
195
+ declare function getStandardValue<T>(result?: StandardSchemaV1.Result<T>): T | undefined;
196
+ declare function getStandardValue<T>(result: StandardSchemaV1.Result<T> | null): T | null;
196
197
 
197
- interface GraphQLSilk<TOutput = any, TInput = any> extends v1.StandardSchema<TInput, TOutput> {
198
+ interface GraphQLSilk<TOutput = any, TInput = any> extends StandardSchemaV1<TInput, TOutput> {
198
199
  /**
199
200
  * GraphQL type for schema
200
201
  */
@@ -234,7 +235,7 @@ interface FieldOrOperation<TParent extends undefined | GraphQLSilk, TOutput exte
234
235
  type: TType;
235
236
  input: TInput;
236
237
  output: TOutput;
237
- resolve: TType extends "field" ? (parent: v1.InferOutput<NonNullable<TParent>>, input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<v1.InferOutput<TOutput>> : TType extends "subscription" ? (value: any, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<v1.InferOutput<TOutput>> : (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<v1.InferOutput<TOutput>>;
238
+ resolve: TType extends "field" ? (parent: StandardSchemaV1.InferOutput<NonNullable<TParent>>, input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<StandardSchemaV1.InferOutput<TOutput>> : TType extends "subscription" ? (value: any, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<StandardSchemaV1.InferOutput<TOutput>> : (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => Promise<StandardSchemaV1.InferOutput<TOutput>>;
238
239
  subscribe?: TType extends "subscription" ? (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => MayPromise<AsyncIterator<any>> : undefined;
239
240
  }
240
241
  type GenericFieldOrOperation = FieldOrOperation<any, any, any, any>;
@@ -285,8 +286,8 @@ interface SubscriptionOptions<TSchemaIO extends AbstractSchemaIO, TOutput extend
285
286
  subscribe: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<AsyncIterator<TValue>>;
286
287
  resolve?: (value: TValue, input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>;
287
288
  }
288
- interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<GraphQLSilk> = undefined, TValue = v1.InferOutput<TOutput>> extends FieldOrOperation<undefined, TOutput, TInput, "subscription"> {
289
- resolve: (value: TValue, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<v1.InferOutput<TOutput>>;
289
+ interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<GraphQLSilk> = undefined, TValue = StandardSchemaV1.InferOutput<TOutput>> extends FieldOrOperation<undefined, TOutput, TInput, "subscription"> {
290
+ resolve: (value: TValue, input: InferInputI<TInput, GraphQLSilkIO>) => Promise<StandardSchemaV1.InferOutput<TOutput>>;
290
291
  subscribe: (input: InferInputI<TInput, GraphQLSilkIO>, options?: ResolvingOptions) => MayPromise<AsyncIterator<TValue>>;
291
292
  }
292
293
  /**
@@ -305,18 +306,24 @@ declare function getOperationOptions<T extends FieldOrOperationType = OperationT
305
306
  declare function getSubscriptionOptions(subscribeOrOptions: (() => any) | SubscriptionOptions<any, any, any, any>): SubscriptionOptions<any, any, any, any>;
306
307
  declare function getFieldOptions({ description, deprecationReason, extensions, }: GraphQLFieldOptions): GraphQLFieldOptions;
307
308
 
308
- interface MiddlewarePayload<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> {
309
+ interface MiddlewareOptions<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> {
309
310
  /** The Output Silk of the field */
310
- outputSilk: v1.InferOutput<InferFieldOutput<TField>>;
311
+ outputSilk: StandardSchemaV1.InferOutput<InferFieldOutput<TField>>;
311
312
  /** The previous object, which for a field on the root Query type is often not used. */
312
- parent: TField extends FieldOrOperation<infer TParent, any, any, any> ? TParent extends undefined ? undefined : v1.InferOutput<NonNullable<TParent>> : never;
313
+ parent: TField extends FieldOrOperation<infer TParent, any, any, any> ? TParent extends undefined ? undefined : StandardSchemaV1.InferOutput<NonNullable<TParent>> : never;
313
314
  /** A function to parse the input of the field */
314
315
  parseInput: TField extends FieldOrOperation<any, any, infer TInput, any> ? CallableInputParser<TInput> : undefined;
315
316
  /** The type of the field: `query`, `mutation`, `subscription` or `field` */
316
317
  type: FieldOrOperationType;
317
318
  }
318
- type Middleware<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> = (next: () => MayPromise<v1.InferOutput<InferFieldOutput<TField>>>, payload: MiddlewarePayload<TField>) => MayPromise<v1.InferOutput<InferFieldOutput<TField>>>;
319
- declare function applyMiddlewares<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>>(middlewares: Middleware[], resolveFunction: () => MayPromise<v1.InferOutput<InferFieldOutput<TField>>>, payload: MiddlewarePayload<TField>): Promise<v1.InferOutput<InferFieldOutput<TField>>>;
319
+ interface CallableMiddlewareOptions<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> extends MiddlewareOptions<TField> {
320
+ /** The function to call next in the middleware chain. */
321
+ next: () => MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
322
+ /** The function to call next in the middleware chain. */
323
+ (): MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
324
+ }
325
+ type Middleware<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>> = (options: CallableMiddlewareOptions<TField>) => MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
326
+ declare function applyMiddlewares<TField extends GenericFieldOrOperation = FieldOrOperation<any, any, any, any>>(middlewares: Middleware[], resolveFunction: () => MayPromise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>, options: MiddlewareOptions<TField>): Promise<StandardSchemaV1.InferOutput<InferFieldOutput<TField>>>;
320
327
  declare function compose<T>(...lists: (T[] | undefined)[]): T[];
321
328
 
322
329
  /**
@@ -460,11 +467,11 @@ declare function markLocation(message: string, ...locations: string[]): string;
460
467
  /**
461
468
  * Create a Silk from Scalar.
462
469
  */
463
- declare function silk<TScalar extends GraphQLScalarType>(type: TScalar | (() => TScalar), parse?: (value: InferScalarExternal<TScalar>) => v1.StandardResult<InferScalarExternal<TScalar>> | Promise<v1.StandardResult<InferScalarInternal<TScalar>>>): GraphQLSilk<InferScalarInternal<TScalar> | undefined, InferScalarInternal<TScalar> | undefined>;
470
+ declare function silk<TScalar extends GraphQLScalarType>(type: TScalar | (() => TScalar), parse?: (value: InferScalarExternal<TScalar>) => StandardSchemaV1.Result<InferScalarExternal<TScalar>> | Promise<StandardSchemaV1.Result<InferScalarInternal<TScalar>>>): GraphQLSilk<InferScalarInternal<TScalar> | undefined, InferScalarInternal<TScalar> | undefined>;
464
471
  /**
465
472
  * Create a GraphQLSilk Object.
466
473
  */
467
- declare function silk<TOutput, TInput = TOutput>(type: GraphQLOutputType | (() => GraphQLOutputType), validate?: (value: TInput) => v1.StandardResult<TOutput> | Promise<v1.StandardResult<TOutput>>): GraphQLSilk<TOutput, TInput>;
474
+ declare function silk<TOutput, TInput = TOutput>(type: GraphQLOutputType | (() => GraphQLOutputType), validate?: (value: TInput) => StandardSchemaV1.Result<TOutput> | Promise<StandardSchemaV1.Result<TOutput>>): GraphQLSilk<TOutput, TInput>;
468
475
  declare namespace silk {
469
476
  var parse: typeof parseSilk;
470
477
  var getType: typeof getGraphQLType;
@@ -472,17 +479,17 @@ declare namespace silk {
472
479
  var list: typeof listSilk;
473
480
  var nullable: typeof nullableSilk;
474
481
  }
475
- type NonNullSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<NonNullable<v1.InferOutput<TSilk>>, NonNullable<v1.InferInput<TSilk>>>;
482
+ type NonNullSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<NonNullable<StandardSchemaV1.InferOutput<TSilk>>, NonNullable<StandardSchemaV1.InferInput<TSilk>>>;
476
483
  /**
477
484
  * Non-nullable Silk.
478
485
  */
479
486
  declare function nonNullSilk<TSilk extends GraphQLSilk<any, any>>(origin: TSilk): NonNullSilk<TSilk>;
480
- type ListSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<EnsureArray<v1.InferOutput<TSilk>>, EnsureArray<v1.InferOutput<TSilk>>>;
487
+ type ListSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<EnsureArray<StandardSchemaV1.InferOutput<TSilk>>, EnsureArray<StandardSchemaV1.InferOutput<TSilk>>>;
481
488
  /**
482
489
  * List Silk.
483
490
  */
484
491
  declare function listSilk<TSilk extends GraphQLSilk<any, any>>(origin: TSilk): ListSilk<TSilk>;
485
- type NullableSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<v1.InferOutput<TSilk> | null | undefined, v1.InferInput<TSilk>>;
492
+ type NullableSilk<TSilk extends GraphQLSilk<any, any>> = GraphQLSilk<StandardSchemaV1.InferOutput<TSilk> | null | undefined, StandardSchemaV1.InferInput<TSilk>>;
486
493
  /**
487
494
  * Nullable Silk.
488
495
  */
@@ -499,7 +506,7 @@ declare function getGraphQLType(silk: GraphQLSilk): GraphQLOutputType;
499
506
  * @param input
500
507
  * @returns output
501
508
  */
502
- declare function parseSilk<TSilk extends GraphQLSilk>(silk: TSilk, input: v1.InferInput<TSilk>): MayPromise<v1.StandardResult<v1.InferOutput<TSilk>>>;
509
+ declare function parseSilk<TSilk extends GraphQLSilk>(silk: TSilk, input: StandardSchemaV1.InferInput<TSilk>): MayPromise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSilk>>>;
503
510
  declare function isSilk(target: any): target is GraphQLSilk;
504
511
  type InferScalarInternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<infer TInternal> ? TInternal : never;
505
512
  type InferScalarExternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<any, infer TExternal> ? TExternal : never;
@@ -640,7 +647,7 @@ declare class SchemaWeaver {
640
647
  query?: LoomObjectType;
641
648
  mutation?: LoomObjectType;
642
649
  subscription?: LoomObjectType;
643
- types?: GraphQLNamedType[] | null;
650
+ types: Set<GraphQLNamedType>;
644
651
  context: WeaverContext;
645
652
  resolverOptions?: ResolvingOptions;
646
653
  /**
@@ -704,4 +711,4 @@ interface GQLoomExtensionAttribute {
704
711
  directives?: string[];
705
712
  }
706
713
 
707
- export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewarePayload, type MutationFactory, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaVendorWeaver, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, v1, weave, weaverContext };
714
+ export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaVendorWeaver, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
package/dist/index.js CHANGED
@@ -156,7 +156,9 @@ function collectName(name, schema) {
156
156
  }
157
157
 
158
158
  // src/resolver/silk.ts
159
- function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
159
+ function silk(type, validate = (value) => ({
160
+ value: value ?? void 0
161
+ })) {
160
162
  return {
161
163
  [GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
162
164
  "~standard": {
@@ -261,13 +263,17 @@ function getFieldOptions({
261
263
  }
262
264
 
263
265
  // src/utils/middleware.ts
264
- function applyMiddlewares(middlewares, resolveFunction, payload) {
266
+ function applyMiddlewares(middlewares, resolveFunction, options) {
265
267
  const next = (index) => {
266
268
  if (index >= middlewares.length) {
267
269
  return resolveFunction();
268
270
  }
269
271
  const middleware = middlewares[index];
270
- return middleware(() => next(index + 1), payload);
272
+ const callableOptions = Object.assign(() => next(index + 1), {
273
+ ...options,
274
+ next: () => next(index + 1)
275
+ });
276
+ return middleware(callableOptions);
271
277
  };
272
278
  return next(0);
273
279
  }
@@ -1029,7 +1035,7 @@ var SchemaWeaver = class _SchemaWeaver {
1029
1035
  if (query2 != null) this.query = query2;
1030
1036
  if (mutation2 != null) this.mutation = mutation2;
1031
1037
  if (subscription2 != null) this.subscription = subscription2;
1032
- if (types != null) this.types = types.slice();
1038
+ this.types = new Set(types ?? []);
1033
1039
  this.context = context ?? initWeaverContext();
1034
1040
  }
1035
1041
  use(...middlewares) {
@@ -1063,8 +1069,7 @@ var SchemaWeaver = class _SchemaWeaver {
1063
1069
  `${gqlType2?.name ?? gqlType2.toString()} is not a named type`
1064
1070
  );
1065
1071
  }, this.context);
1066
- this.types ??= [];
1067
- this.types.push(gqlType);
1072
+ this.types.add(gqlType);
1068
1073
  return this;
1069
1074
  }
1070
1075
  setConfig(config) {
@@ -1090,16 +1095,17 @@ var SchemaWeaver = class _SchemaWeaver {
1090
1095
  if (parent == null) return void 0;
1091
1096
  let gqlType = getGraphQLType(parent);
1092
1097
  if (isNonNullType3(gqlType)) gqlType = gqlType.ofType;
1093
- if (isObjectType4(gqlType)) {
1094
- const existing = this.context.loomObjectMap.get(gqlType);
1095
- if (existing != null) return existing;
1096
- const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
1097
- this.context.loomObjectMap.set(gqlType, extraObject);
1098
- return extraObject;
1098
+ if (!isObjectType4(gqlType)) {
1099
+ throw new Error(
1100
+ `${gqlType?.name ?? gqlType.toString()} is not an object type`
1101
+ );
1099
1102
  }
1100
- throw new Error(
1101
- `${gqlType?.name ?? gqlType.toString()} is not an object type`
1102
- );
1103
+ const existing = this.context.loomObjectMap.get(gqlType);
1104
+ if (existing != null) return existing;
1105
+ const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
1106
+ this.context.loomObjectMap.set(gqlType, extraObject);
1107
+ this.types.add(extraObject);
1108
+ return extraObject;
1103
1109
  })();
1104
1110
  if (resolverOptions?.extensions && parentObject)
1105
1111
  parentObject.mergeExtensions(resolverOptions.extensions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gqloom/core",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Create GraphQL schema and resolvers with TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -46,6 +46,6 @@
46
46
  "access": "public"
47
47
  },
48
48
  "devDependencies": {
49
- "@standard-schema/spec": "1.0.0-beta.3"
49
+ "@standard-schema/spec": "1.0.0-beta.4"
50
50
  }
51
51
  }