@gqloom/core 0.10.1 → 0.11.1

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.
@@ -1,11 +1,12 @@
1
- import { P as OnlyMemoizationPayload, R as ResolverPayload, B as BaseField, v as Middleware, K as ResolvingFields } from './context-ljWuL8VA.cjs';
2
- import { AsyncLocalStorage } from 'node:async_hooks';
3
- import 'graphql';
1
+ import { BaseField, Middleware, OnlyMemoizationPayload, ResolverPayload, ResolvingFields } from "./index-DXUAbzqx.cjs";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+
4
+ //#region src/context/context.d.ts
4
5
 
5
6
  /**
6
7
  * the AsyncLocalStorage instance to store the resolver payload
7
8
  */
8
- declare const resolverPayloadStorage: AsyncLocalStorage<OnlyMemoizationPayload | ResolverPayload<object, BaseField>>;
9
+ declare const resolverPayloadStorage: AsyncLocalStorage<ResolverPayload<object, BaseField> | OnlyMemoizationPayload>;
9
10
  /**
10
11
  * use detailed payload of the current resolver
11
12
  * @returns the resolver payload
@@ -21,8 +22,8 @@ declare function useContext<TContextType = object>(): TContextType;
21
22
  */
22
23
  declare function useMemoizationMap(): WeakMap<WeakKey, any> | undefined;
23
24
  interface ContextOptions {
24
- getContextMap: () => WeakMap<WeakKey, any> | undefined;
25
- key: WeakKey;
25
+ getContextMap: () => WeakMap<WeakKey, any> | undefined;
26
+ key: WeakKey;
26
27
  }
27
28
  /**
28
29
  * A class that provides dependency injection and context sharing capabilities.
@@ -32,75 +33,75 @@ interface ContextOptions {
32
33
  *
33
34
  */
34
35
  declare class InjectableContext<T> implements ContextOptions {
35
- readonly getter: () => T;
36
- /**
37
- * Creates a new instance of InjectableContext.
38
- *
39
- * @param getter - A function that returns the default value when no custom implementation is provided
40
- * @param options - Optional configuration for the context
41
- * @param options.getContextMap - A function that returns the WeakMap used to store context values. Defaults to useMemoizationMap
42
- * @param options.key - A unique key used to identify this context in the WeakMap. Defaults to the getter function
43
- */
44
- constructor(getter: () => T, options?: Partial<ContextOptions>);
45
- /**
46
- * A function that returns the WeakMap used to store context values.
47
- * This can be customized to use different storage mechanisms.
48
- */
49
- getContextMap: () => WeakMap<WeakKey, any> | undefined;
50
- /**
51
- * A unique key used to identify this context in the WeakMap.
52
- * This is used to store and retrieve values from the context map.
53
- */
54
- readonly key: WeakKey;
55
- /**
56
- * Retrieves the value from the context.
57
- * If a custom implementation is provided, it will be used.
58
- * Otherwise, the default getter function will be called.
59
- *
60
- * @returns The value of type T
61
- */
62
- get(): T;
63
- /**
64
- * Provides a new implementation for this context.
65
- *
66
- * @param getter - A function that returns the new value
67
- * @returns A tuple containing the key and the new getter function
68
- */
69
- provide(getter: () => T): [WeakKey, () => T];
36
+ readonly getter: () => T;
37
+ /**
38
+ * Creates a new instance of InjectableContext.
39
+ *
40
+ * @param getter - A function that returns the default value when no custom implementation is provided
41
+ * @param options - Optional configuration for the context
42
+ * @param options.getContextMap - A function that returns the WeakMap used to store context values. Defaults to useMemoizationMap
43
+ * @param options.key - A unique key used to identify this context in the WeakMap. Defaults to the getter function
44
+ */
45
+ constructor(getter: () => T, options?: Partial<ContextOptions>);
46
+ /**
47
+ * A function that returns the WeakMap used to store context values.
48
+ * This can be customized to use different storage mechanisms.
49
+ */
50
+ getContextMap: () => WeakMap<WeakKey, any> | undefined;
51
+ /**
52
+ * A unique key used to identify this context in the WeakMap.
53
+ * This is used to store and retrieve values from the context map.
54
+ */
55
+ readonly key: WeakKey;
56
+ /**
57
+ * Retrieves the value from the context.
58
+ * If a custom implementation is provided, it will be used.
59
+ * Otherwise, the default getter function will be called.
60
+ *
61
+ * @returns The value of type T
62
+ */
63
+ get(): T;
64
+ /**
65
+ * Provides a new implementation for this context.
66
+ *
67
+ * @param getter - A function that returns the new value
68
+ * @returns A tuple containing the key and the new getter function
69
+ */
70
+ provide(getter: () => T): [WeakKey, () => T];
70
71
  }
71
72
  /**
72
73
  * Create a memoization in context to store the result of a getter function
73
74
  */
74
75
  declare class ContextMemoization<T> implements ContextOptions {
75
- readonly getter: () => T;
76
- constructor(getter: () => T, options?: Partial<ContextOptions>);
77
- getContextMap: () => WeakMap<WeakKey, any> | undefined;
78
- readonly key: WeakKey;
79
- /**
80
- * Get the value in memoization or call the getter function
81
- * @returns the value of the getter function
82
- */
83
- get(): T;
84
- /**
85
- * Clear the memoization
86
- * @returns true if the memoization is cleared, undefined if the context is not found
87
- */
88
- clear(): boolean | undefined;
89
- /**
90
- * Check if the memoization exists
91
- * @returns true if the memoization exists, undefined if the context is not found
92
- */
93
- exists(): boolean | undefined;
94
- /**
95
- * Set a new value to the memoization
96
- * @param value the new value to set
97
- * @returns the memoization map or undefined if the context is not found
98
- */
99
- set(value: T): WeakMap<WeakKey, any> | undefined;
100
- provide(value: T): [WeakKey, T];
76
+ readonly getter: () => T;
77
+ constructor(getter: () => T, options?: Partial<ContextOptions>);
78
+ getContextMap: () => WeakMap<WeakKey, any> | undefined;
79
+ readonly key: WeakKey;
80
+ /**
81
+ * Get the value in memoization or call the getter function
82
+ * @returns the value of the getter function
83
+ */
84
+ get(): T;
85
+ /**
86
+ * Clear the memoization
87
+ * @returns true if the memoization is cleared, undefined if the context is not found
88
+ */
89
+ clear(): boolean | undefined;
90
+ /**
91
+ * Check if the memoization exists
92
+ * @returns true if the memoization exists, undefined if the context is not found
93
+ */
94
+ exists(): boolean | undefined;
95
+ /**
96
+ * Set a new value to the memoization
97
+ * @param value the new value to set
98
+ * @returns the memoization map or undefined if the context is not found
99
+ */
100
+ set(value: T): WeakMap<WeakKey, any> | undefined;
101
+ provide(value: T): [WeakKey, T];
101
102
  }
102
103
  interface CallableContext<T> extends InjectableContext<T> {
103
- (): T;
104
+ (): T;
104
105
  }
105
106
  /**
106
107
  * Create a callable context
@@ -112,54 +113,55 @@ declare function createContext<T>(...args: ConstructorParameters<typeof Injectab
112
113
  * Async Memoization with a callable function
113
114
  */
114
115
  interface CallableContextMemoization<T> extends ContextMemoization<T> {
115
- (): T;
116
+ (): T;
116
117
  }
117
118
  /**
118
119
  * Create a memoization in context to store the result of a getter function
119
120
  */
120
121
  declare function createMemoization<T>(...args: ConstructorParameters<typeof ContextMemoization<T>>): CallableContextMemoization<T>;
121
122
  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
- */
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
+ /**
124
+ * Creates a middleware that injects key-value pairs into the context during resolver execution.
125
+ * The injected values will be available throughout the entire resolver execution chain.
126
+ *
127
+ * @param keyValues - An array of tuples containing a WeakKey and its corresponding value
128
+ * @returns A middleware function that injects the provided key-value pairs into the context
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const executor = resolver.toExecutor(
133
+ * asyncContextProvider.with(
134
+ * useDefaultName.provide(() => "Default Name")
135
+ * )
136
+ * )
137
+ * ```
138
+ */
139
+ with: (...keyValues: [WeakKey, any][]) => Middleware;
140
+ /**
141
+ * Executes an async function with injected context values.
142
+ * The provided key-value pairs will be available in the context during the function execution.
143
+ *
144
+ * @template T - The return type of the async function
145
+ * @param resolve - The async function to execute
146
+ * @param keyValues - An array of tuples containing a WeakKey and its corresponding value
147
+ * @returns A Promise that resolves to the result of the async function
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const result = await asyncContextProvider.run(
152
+ * async () => {
153
+ * const name = useDefaultName()
154
+ * return `Hello, ${name}!`
155
+ * },
156
+ * useDefaultName.provide(() => "John")
157
+ * )
158
+ * ```
159
+ */
160
+ run: <T>(resolve: () => Promise<T>, ...keyValues: [WeakKey, any][]) => Promise<T>;
160
161
  }
161
162
  declare const asyncContextProvider: AsyncContextProvider;
162
-
163
+ //#endregion
164
+ //#region src/context/use-resolving-fields.d.ts
163
165
  /**
164
166
  * A hook that analyzes and processes field resolution in a GraphQL query.
165
167
  *
@@ -167,8 +169,9 @@ declare const asyncContextProvider: AsyncContextProvider;
167
169
  * or undefined if no resolver payload is available
168
170
  */
169
171
  declare const useResolvingFields: CallableContext<ResolvingFields | undefined>;
170
-
172
+ //#endregion
173
+ //#region src/context/async-iterator.d.ts
171
174
  declare function bindAsyncIterator<TAsyncLocalStorage extends AsyncLocalStorage<unknown>, TAsyncIterator extends AsyncIterator<unknown, unknown, unknown>>(storage: TAsyncLocalStorage, generator: TAsyncIterator): TAsyncIterator;
172
175
  declare function isAsyncIterator(value: unknown): value is AsyncIterator<unknown, unknown, unknown>;
173
-
174
- export { type AsyncContextProvider, type CallableContext, type CallableContextMemoization, ContextMemoization, InjectableContext, asyncContextProvider, bindAsyncIterator, createContext, createMemoization, isAsyncIterator, resolverPayloadStorage, useContext, useMemoizationMap, useResolverPayload, useResolvingFields };
176
+ //#endregion
177
+ export { AsyncContextProvider, CallableContext, CallableContextMemoization, ContextMemoization, InjectableContext, asyncContextProvider, bindAsyncIterator, createContext, createMemoization, isAsyncIterator, resolverPayloadStorage, useContext, useMemoizationMap, useResolverPayload, useResolvingFields };
package/dist/context.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { P as OnlyMemoizationPayload, R as ResolverPayload, B as BaseField, v as Middleware, K as ResolvingFields } from './context-ljWuL8VA.js';
2
- import { AsyncLocalStorage } from 'node:async_hooks';
3
- import 'graphql';
1
+ import { BaseField, Middleware, OnlyMemoizationPayload, ResolverPayload, ResolvingFields } from "./index-t3pO8DK2.js";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+
4
+ //#region src/context/context.d.ts
4
5
 
5
6
  /**
6
7
  * the AsyncLocalStorage instance to store the resolver payload
7
8
  */
8
- declare const resolverPayloadStorage: AsyncLocalStorage<OnlyMemoizationPayload | ResolverPayload<object, BaseField>>;
9
+ declare const resolverPayloadStorage: AsyncLocalStorage<ResolverPayload<object, BaseField> | OnlyMemoizationPayload>;
9
10
  /**
10
11
  * use detailed payload of the current resolver
11
12
  * @returns the resolver payload
@@ -21,8 +22,8 @@ declare function useContext<TContextType = object>(): TContextType;
21
22
  */
22
23
  declare function useMemoizationMap(): WeakMap<WeakKey, any> | undefined;
23
24
  interface ContextOptions {
24
- getContextMap: () => WeakMap<WeakKey, any> | undefined;
25
- key: WeakKey;
25
+ getContextMap: () => WeakMap<WeakKey, any> | undefined;
26
+ key: WeakKey;
26
27
  }
27
28
  /**
28
29
  * A class that provides dependency injection and context sharing capabilities.
@@ -32,75 +33,75 @@ interface ContextOptions {
32
33
  *
33
34
  */
34
35
  declare class InjectableContext<T> implements ContextOptions {
35
- readonly getter: () => T;
36
- /**
37
- * Creates a new instance of InjectableContext.
38
- *
39
- * @param getter - A function that returns the default value when no custom implementation is provided
40
- * @param options - Optional configuration for the context
41
- * @param options.getContextMap - A function that returns the WeakMap used to store context values. Defaults to useMemoizationMap
42
- * @param options.key - A unique key used to identify this context in the WeakMap. Defaults to the getter function
43
- */
44
- constructor(getter: () => T, options?: Partial<ContextOptions>);
45
- /**
46
- * A function that returns the WeakMap used to store context values.
47
- * This can be customized to use different storage mechanisms.
48
- */
49
- getContextMap: () => WeakMap<WeakKey, any> | undefined;
50
- /**
51
- * A unique key used to identify this context in the WeakMap.
52
- * This is used to store and retrieve values from the context map.
53
- */
54
- readonly key: WeakKey;
55
- /**
56
- * Retrieves the value from the context.
57
- * If a custom implementation is provided, it will be used.
58
- * Otherwise, the default getter function will be called.
59
- *
60
- * @returns The value of type T
61
- */
62
- get(): T;
63
- /**
64
- * Provides a new implementation for this context.
65
- *
66
- * @param getter - A function that returns the new value
67
- * @returns A tuple containing the key and the new getter function
68
- */
69
- provide(getter: () => T): [WeakKey, () => T];
36
+ readonly getter: () => T;
37
+ /**
38
+ * Creates a new instance of InjectableContext.
39
+ *
40
+ * @param getter - A function that returns the default value when no custom implementation is provided
41
+ * @param options - Optional configuration for the context
42
+ * @param options.getContextMap - A function that returns the WeakMap used to store context values. Defaults to useMemoizationMap
43
+ * @param options.key - A unique key used to identify this context in the WeakMap. Defaults to the getter function
44
+ */
45
+ constructor(getter: () => T, options?: Partial<ContextOptions>);
46
+ /**
47
+ * A function that returns the WeakMap used to store context values.
48
+ * This can be customized to use different storage mechanisms.
49
+ */
50
+ getContextMap: () => WeakMap<WeakKey, any> | undefined;
51
+ /**
52
+ * A unique key used to identify this context in the WeakMap.
53
+ * This is used to store and retrieve values from the context map.
54
+ */
55
+ readonly key: WeakKey;
56
+ /**
57
+ * Retrieves the value from the context.
58
+ * If a custom implementation is provided, it will be used.
59
+ * Otherwise, the default getter function will be called.
60
+ *
61
+ * @returns The value of type T
62
+ */
63
+ get(): T;
64
+ /**
65
+ * Provides a new implementation for this context.
66
+ *
67
+ * @param getter - A function that returns the new value
68
+ * @returns A tuple containing the key and the new getter function
69
+ */
70
+ provide(getter: () => T): [WeakKey, () => T];
70
71
  }
71
72
  /**
72
73
  * Create a memoization in context to store the result of a getter function
73
74
  */
74
75
  declare class ContextMemoization<T> implements ContextOptions {
75
- readonly getter: () => T;
76
- constructor(getter: () => T, options?: Partial<ContextOptions>);
77
- getContextMap: () => WeakMap<WeakKey, any> | undefined;
78
- readonly key: WeakKey;
79
- /**
80
- * Get the value in memoization or call the getter function
81
- * @returns the value of the getter function
82
- */
83
- get(): T;
84
- /**
85
- * Clear the memoization
86
- * @returns true if the memoization is cleared, undefined if the context is not found
87
- */
88
- clear(): boolean | undefined;
89
- /**
90
- * Check if the memoization exists
91
- * @returns true if the memoization exists, undefined if the context is not found
92
- */
93
- exists(): boolean | undefined;
94
- /**
95
- * Set a new value to the memoization
96
- * @param value the new value to set
97
- * @returns the memoization map or undefined if the context is not found
98
- */
99
- set(value: T): WeakMap<WeakKey, any> | undefined;
100
- provide(value: T): [WeakKey, T];
76
+ readonly getter: () => T;
77
+ constructor(getter: () => T, options?: Partial<ContextOptions>);
78
+ getContextMap: () => WeakMap<WeakKey, any> | undefined;
79
+ readonly key: WeakKey;
80
+ /**
81
+ * Get the value in memoization or call the getter function
82
+ * @returns the value of the getter function
83
+ */
84
+ get(): T;
85
+ /**
86
+ * Clear the memoization
87
+ * @returns true if the memoization is cleared, undefined if the context is not found
88
+ */
89
+ clear(): boolean | undefined;
90
+ /**
91
+ * Check if the memoization exists
92
+ * @returns true if the memoization exists, undefined if the context is not found
93
+ */
94
+ exists(): boolean | undefined;
95
+ /**
96
+ * Set a new value to the memoization
97
+ * @param value the new value to set
98
+ * @returns the memoization map or undefined if the context is not found
99
+ */
100
+ set(value: T): WeakMap<WeakKey, any> | undefined;
101
+ provide(value: T): [WeakKey, T];
101
102
  }
102
103
  interface CallableContext<T> extends InjectableContext<T> {
103
- (): T;
104
+ (): T;
104
105
  }
105
106
  /**
106
107
  * Create a callable context
@@ -112,54 +113,55 @@ declare function createContext<T>(...args: ConstructorParameters<typeof Injectab
112
113
  * Async Memoization with a callable function
113
114
  */
114
115
  interface CallableContextMemoization<T> extends ContextMemoization<T> {
115
- (): T;
116
+ (): T;
116
117
  }
117
118
  /**
118
119
  * Create a memoization in context to store the result of a getter function
119
120
  */
120
121
  declare function createMemoization<T>(...args: ConstructorParameters<typeof ContextMemoization<T>>): CallableContextMemoization<T>;
121
122
  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
- */
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
+ /**
124
+ * Creates a middleware that injects key-value pairs into the context during resolver execution.
125
+ * The injected values will be available throughout the entire resolver execution chain.
126
+ *
127
+ * @param keyValues - An array of tuples containing a WeakKey and its corresponding value
128
+ * @returns A middleware function that injects the provided key-value pairs into the context
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const executor = resolver.toExecutor(
133
+ * asyncContextProvider.with(
134
+ * useDefaultName.provide(() => "Default Name")
135
+ * )
136
+ * )
137
+ * ```
138
+ */
139
+ with: (...keyValues: [WeakKey, any][]) => Middleware;
140
+ /**
141
+ * Executes an async function with injected context values.
142
+ * The provided key-value pairs will be available in the context during the function execution.
143
+ *
144
+ * @template T - The return type of the async function
145
+ * @param resolve - The async function to execute
146
+ * @param keyValues - An array of tuples containing a WeakKey and its corresponding value
147
+ * @returns A Promise that resolves to the result of the async function
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const result = await asyncContextProvider.run(
152
+ * async () => {
153
+ * const name = useDefaultName()
154
+ * return `Hello, ${name}!`
155
+ * },
156
+ * useDefaultName.provide(() => "John")
157
+ * )
158
+ * ```
159
+ */
160
+ run: <T>(resolve: () => Promise<T>, ...keyValues: [WeakKey, any][]) => Promise<T>;
160
161
  }
161
162
  declare const asyncContextProvider: AsyncContextProvider;
162
-
163
+ //#endregion
164
+ //#region src/context/use-resolving-fields.d.ts
163
165
  /**
164
166
  * A hook that analyzes and processes field resolution in a GraphQL query.
165
167
  *
@@ -167,8 +169,9 @@ declare const asyncContextProvider: AsyncContextProvider;
167
169
  * or undefined if no resolver payload is available
168
170
  */
169
171
  declare const useResolvingFields: CallableContext<ResolvingFields | undefined>;
170
-
172
+ //#endregion
173
+ //#region src/context/async-iterator.d.ts
171
174
  declare function bindAsyncIterator<TAsyncLocalStorage extends AsyncLocalStorage<unknown>, TAsyncIterator extends AsyncIterator<unknown, unknown, unknown>>(storage: TAsyncLocalStorage, generator: TAsyncIterator): TAsyncIterator;
172
175
  declare function isAsyncIterator(value: unknown): value is AsyncIterator<unknown, unknown, unknown>;
173
-
174
- export { type AsyncContextProvider, type CallableContext, type CallableContextMemoization, ContextMemoization, InjectableContext, asyncContextProvider, bindAsyncIterator, createContext, createMemoization, isAsyncIterator, resolverPayloadStorage, useContext, useMemoizationMap, useResolverPayload, useResolvingFields };
176
+ //#endregion
177
+ export { AsyncContextProvider, CallableContext, CallableContextMemoization, ContextMemoization, InjectableContext, asyncContextProvider, bindAsyncIterator, createContext, createMemoization, isAsyncIterator, resolverPayloadStorage, useContext, useMemoizationMap, useResolverPayload, useResolvingFields };