@gqloom/core 0.9.2 → 0.9.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/context.cjs +8 -0
- package/dist/context.d.cts +37 -0
- package/dist/context.d.ts +37 -0
- package/dist/context.js +8 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/context.cjs
CHANGED
|
@@ -424,6 +424,14 @@ var asyncContextProvider = Object.assign(
|
|
|
424
424
|
],
|
|
425
425
|
with: (...keyValues) => {
|
|
426
426
|
return createProvider(...keyValues);
|
|
427
|
+
},
|
|
428
|
+
run: async (resolve, ...keyValues) => {
|
|
429
|
+
const store = onlyMemoization();
|
|
430
|
+
const map = getMemoizationMap(store);
|
|
431
|
+
for (const [key, value] of keyValues) {
|
|
432
|
+
map.set(key, value);
|
|
433
|
+
}
|
|
434
|
+
return resolverPayloadStorage.run(store, resolve);
|
|
427
435
|
}
|
|
428
436
|
}
|
|
429
437
|
);
|
package/dist/context.d.cts
CHANGED
|
@@ -119,7 +119,44 @@ interface CallableContextMemoization<T> extends ContextMemoization<T> {
|
|
|
119
119
|
*/
|
|
120
120
|
declare function createMemoization<T>(...args: ConstructorParameters<typeof ContextMemoization<T>>): CallableContextMemoization<T>;
|
|
121
121
|
interface AsyncContextProvider extends Middleware {
|
|
122
|
+
/**
|
|
123
|
+
* Creates a middleware that injects key-value pairs into the context during resolver execution.
|
|
124
|
+
* The injected values will be available throughout the entire resolver execution chain.
|
|
125
|
+
*
|
|
126
|
+
* @param keyValues - An array of tuples containing a WeakKey and its corresponding value
|
|
127
|
+
* @returns A middleware function that injects the provided key-value pairs into the context
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const executor = resolver.toExecutor(
|
|
132
|
+
* asyncContextProvider.with(
|
|
133
|
+
* useDefaultName.provide(() => "Default Name")
|
|
134
|
+
* )
|
|
135
|
+
* )
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
122
138
|
with: (...keyValues: [WeakKey, any][]) => Middleware;
|
|
139
|
+
/**
|
|
140
|
+
* Executes an async function with injected context values.
|
|
141
|
+
* The provided key-value pairs will be available in the context during the function execution.
|
|
142
|
+
*
|
|
143
|
+
* @template T - The return type of the async function
|
|
144
|
+
* @param resolve - The async function to execute
|
|
145
|
+
* @param keyValues - An array of tuples containing a WeakKey and its corresponding value
|
|
146
|
+
* @returns A Promise that resolves to the result of the async function
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const result = await asyncContextProvider.run(
|
|
151
|
+
* async () => {
|
|
152
|
+
* const name = useDefaultName()
|
|
153
|
+
* return `Hello, ${name}!`
|
|
154
|
+
* },
|
|
155
|
+
* useDefaultName.provide(() => "John")
|
|
156
|
+
* )
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
run: <T>(resolve: () => Promise<T>, ...keyValues: [WeakKey, any][]) => Promise<T>;
|
|
123
160
|
}
|
|
124
161
|
declare const asyncContextProvider: AsyncContextProvider;
|
|
125
162
|
|
package/dist/context.d.ts
CHANGED
|
@@ -119,7 +119,44 @@ interface CallableContextMemoization<T> extends ContextMemoization<T> {
|
|
|
119
119
|
*/
|
|
120
120
|
declare function createMemoization<T>(...args: ConstructorParameters<typeof ContextMemoization<T>>): CallableContextMemoization<T>;
|
|
121
121
|
interface AsyncContextProvider extends Middleware {
|
|
122
|
+
/**
|
|
123
|
+
* Creates a middleware that injects key-value pairs into the context during resolver execution.
|
|
124
|
+
* The injected values will be available throughout the entire resolver execution chain.
|
|
125
|
+
*
|
|
126
|
+
* @param keyValues - An array of tuples containing a WeakKey and its corresponding value
|
|
127
|
+
* @returns A middleware function that injects the provided key-value pairs into the context
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const executor = resolver.toExecutor(
|
|
132
|
+
* asyncContextProvider.with(
|
|
133
|
+
* useDefaultName.provide(() => "Default Name")
|
|
134
|
+
* )
|
|
135
|
+
* )
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
122
138
|
with: (...keyValues: [WeakKey, any][]) => Middleware;
|
|
139
|
+
/**
|
|
140
|
+
* Executes an async function with injected context values.
|
|
141
|
+
* The provided key-value pairs will be available in the context during the function execution.
|
|
142
|
+
*
|
|
143
|
+
* @template T - The return type of the async function
|
|
144
|
+
* @param resolve - The async function to execute
|
|
145
|
+
* @param keyValues - An array of tuples containing a WeakKey and its corresponding value
|
|
146
|
+
* @returns A Promise that resolves to the result of the async function
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const result = await asyncContextProvider.run(
|
|
151
|
+
* async () => {
|
|
152
|
+
* const name = useDefaultName()
|
|
153
|
+
* return `Hello, ${name}!`
|
|
154
|
+
* },
|
|
155
|
+
* useDefaultName.provide(() => "John")
|
|
156
|
+
* )
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
run: <T>(resolve: () => Promise<T>, ...keyValues: [WeakKey, any][]) => Promise<T>;
|
|
123
160
|
}
|
|
124
161
|
declare const asyncContextProvider: AsyncContextProvider;
|
|
125
162
|
|
package/dist/context.js
CHANGED
|
@@ -206,6 +206,14 @@ var asyncContextProvider = Object.assign(
|
|
|
206
206
|
],
|
|
207
207
|
with: (...keyValues) => {
|
|
208
208
|
return createProvider(...keyValues);
|
|
209
|
+
},
|
|
210
|
+
run: async (resolve, ...keyValues) => {
|
|
211
|
+
const store = onlyMemoization();
|
|
212
|
+
const map = getMemoizationMap(store);
|
|
213
|
+
for (const [key, value] of keyValues) {
|
|
214
|
+
map.set(key, value);
|
|
215
|
+
}
|
|
216
|
+
return resolverPayloadStorage.run(store, resolve);
|
|
209
217
|
}
|
|
210
218
|
}
|
|
211
219
|
);
|
package/dist/index.d.cts
CHANGED
|
@@ -467,4 +467,4 @@ interface GQLoomExtensionAttribute {
|
|
|
467
467
|
directives?: string[];
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
470
|
+
export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type Executor, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -467,4 +467,4 @@ interface GQLoomExtensionAttribute {
|
|
|
467
467
|
directives?: string[];
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
470
|
+
export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type Executor, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|