Comparing version 3.0.0-alpha-24f11bbe.0 to 3.0.0-alpha-2b305512.0
@@ -16,3 +16,3 @@ 'use strict'; | ||
const resolve = (accessor, selection, __type) => { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
const meta$1 = meta.$meta(accessor); | ||
@@ -64,8 +64,11 @@ if (!meta$1) | ||
if (cache.expiresAt === -Infinity) { | ||
data = (_a = context.cache.get(selection.cacheKeys.join("."))) == null ? void 0 : _a.data; | ||
data = (_a = context.cache.get( | ||
selection.cacheKeys.join("."), | ||
context.cacheOptions | ||
)) == null ? void 0 : _a.data; | ||
} | ||
(_b = context.onSelect) == null ? void 0 : _b.call(context, selection, { ...cache, data }); | ||
context.select(selection, { ...cache, data }); | ||
return isArray ? Array.isArray(data) ? data : [void 0] : data; | ||
} | ||
const unions = (_c = context.schema[types.SchemaUnionsKey]) == null ? void 0 : _c[pureType.slice(1)]; | ||
const unions = (_b = context.schema[types.SchemaUnionsKey]) == null ? void 0 : _b[pureType.slice(1)]; | ||
if (unions == null ? void 0 : unions.length) { | ||
@@ -186,3 +189,3 @@ return createUnionAccessor({ | ||
set(_, key, value, proxy) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c; | ||
const meta$1 = meta.$meta(proxy); | ||
@@ -196,3 +199,3 @@ if (typeof key !== "string" || !meta$1) | ||
if (field) { | ||
const data = (_c = (_b = context.cache.get(`${type}.${field}`)) == null ? void 0 : _b.data) != null ? _c : {}; | ||
const data = (_c = (_b = context.cache.get(`${type}.${field}`, context.cacheOptions)) == null ? void 0 : _b.data) != null ? _c : {}; | ||
if (!object.isPlainObject(data)) | ||
@@ -215,3 +218,3 @@ return false; | ||
} | ||
(_d = context.onSelect) == null ? void 0 : _d.call(context, currentSelection, { ...cache, data: scalar }); | ||
context.select(currentSelection, { ...cache, data: scalar }); | ||
} | ||
@@ -371,3 +374,3 @@ return result; | ||
console.warn( | ||
"Received invalid cache data for array accessor.", | ||
"Invalid cache for an array accessor, monkey-patch by wrapping it with an array.", | ||
meta$1, | ||
@@ -377,3 +380,3 @@ meta$1.context.cache.toJSON() | ||
} | ||
throw new index.GQtyError(`Cache data must be an array.`); | ||
meta$1.cache.data = [meta$1.cache.data]; | ||
} | ||
@@ -380,0 +383,0 @@ const proxy = new Proxy(meta$1.cache.data, arrayProxyHandler); |
export declare const isSkeleton: (object: any) => boolean; | ||
/** Create data skeleton array/objects. */ | ||
export declare const createSkeleton: <T extends object>(fn: () => T) => T; |
@@ -1,2 +0,1 @@ | ||
import { FrailMap } from '../Helpers/FrailMap'; | ||
/** | ||
@@ -6,5 +5,2 @@ * Stack-based deep crawl, avoiding recursions. | ||
export declare const crawl: (data: any, fn: (it: any, key: string | number, parent: Record<string, any> | any[]) => [any, any, any] | void, maxIterations?: number) => any; | ||
export declare class InfiniteFrailMap<K extends object, V> extends FrailMap<K, V | InfiniteFrailMap<K, V | InfiniteFrailMap<K, V>>> { | ||
get(key: K): V | InfiniteFrailMap<K, V | InfiniteFrailMap<K, V>>; | ||
} | ||
export declare const flattenObject: (obj: Record<string, unknown>, maxIterations?: number) => [string[], string | number | boolean | null][]; |
@@ -5,6 +5,6 @@ 'use strict'; | ||
const FrailMap = require('../Helpers/FrailMap.js'); | ||
const InfiniteFrailMap = require('../Helpers/InfiniteFrailMap.js'); | ||
const crawl = (data, fn, maxIterations = 1e5) => { | ||
const seen = new InfiniteFrailMap(); | ||
const seen = new InfiniteFrailMap.InfiniteFrailMap(); | ||
const stack = /* @__PURE__ */ new Set([[data, 0, []]]); | ||
@@ -34,10 +34,2 @@ for (const [it, key, obj] of stack) { | ||
}; | ||
class InfiniteFrailMap extends FrailMap.FrailMap { | ||
get(key) { | ||
var _a; | ||
const value = (_a = super.get(key)) != null ? _a : new InfiniteFrailMap(); | ||
super.set(key, value); | ||
return value; | ||
} | ||
} | ||
const flattenObject = (obj, maxIterations = 1e5) => { | ||
@@ -71,4 +63,3 @@ const result = []; | ||
exports.InfiniteFrailMap = InfiniteFrailMap; | ||
exports.crawl = crawl; | ||
exports.flattenObject = flattenObject; |
@@ -36,7 +36,3 @@ import type { GeneratedSchemaObject } from '../Schema'; | ||
swrBefore?: number; | ||
/** | ||
* Internal reference of cache eviction timeout, subject to change in the | ||
* future. | ||
*/ | ||
timeout?: ReturnType<typeof setTimeout>; | ||
unref?: () => void; | ||
}; | ||
@@ -67,3 +63,3 @@ export type CacheListener = <TData extends CacheNode = CacheNode>(value: TData) => void; | ||
*/ | ||
get(path: string, { includeExpired }?: CacheGetOptions): CacheDataContainer | undefined; | ||
get(path: string, options?: CacheGetOptions): CacheDataContainer | undefined; | ||
/** | ||
@@ -70,0 +66,0 @@ * Merge objects into the current cache, recursively normalize incoming values |
@@ -43,3 +43,3 @@ 'use strict'; | ||
}; | ||
var _maxAge, _staleWhileRevalidate, _normalizationOptions, _data, _normalizedObjects, _subscriptions, _normalizedSubscriptions, _subscribeNormalized, subscribeNormalized_fn, _notifySubscribers, _selectionAccessors; | ||
var _maxAge, _staleWhileRevalidate, _normalizationOptions, _data, _normalizedObjects, _dataRefs, _subscriptions, _normalizedSubscriptions, _subscribeNormalized, subscribeNormalized_fn, _notifySubscribers, _selectionAccessors; | ||
class Cache { | ||
@@ -64,2 +64,4 @@ constructor(data, { | ||
__privateAdd(this, _normalizedObjects, /* @__PURE__ */ new Map()); | ||
/** Temporary strong references in parallel with the WeakRef in FrailMap. */ | ||
__privateAdd(this, _dataRefs, /* @__PURE__ */ new Map()); | ||
/** Subscription paths and it's listener function. */ | ||
@@ -191,3 +193,3 @@ __privateAdd(this, _subscriptions, /* @__PURE__ */ new Map()); | ||
*/ | ||
get(path, { includeExpired } = {}) { | ||
get(path, options) { | ||
var _a; | ||
@@ -202,9 +204,13 @@ const [, type, key, subpath] = (_a = path.match(/^([a-z]+(?:\w*))\.(?:__)?([a-z]+(?:\w*))(.*[^\.])?$/i)) != null ? _a : []; | ||
let dataContainer = __privateGet(this, _data).get(cacheKey); | ||
if (dataContainer === void 0) { | ||
if (dataContainer === void 0) | ||
return; | ||
} | ||
const { expiresAt, swrBefore } = dataContainer; | ||
let { data } = dataContainer; | ||
if (expiresAt < Date.now() && !(options == null ? void 0 : options.includeExpired)) { | ||
data = void 0; | ||
} else if (subpath) { | ||
data = select.select(data, subpath.slice(1).split(".")); | ||
} | ||
return { | ||
data: expiresAt < Date.now() && !includeExpired ? void 0 : subpath ? select.select(data, subpath.slice(1).split(".")) : data, | ||
data, | ||
expiresAt, | ||
@@ -221,3 +227,3 @@ swrBefore | ||
set(values, { skipNotify = false } = {}) { | ||
var _a; | ||
var _a, _b; | ||
const age = this.maxAge; | ||
@@ -234,4 +240,9 @@ const swr = this.staleWhileRevalidate; | ||
for (const [field, data] of Object.entries(cacheObjects)) { | ||
const __ref = Symbol(); | ||
let unrefTimer; | ||
const unref = () => { | ||
clearTimeout(unrefTimer); | ||
__privateGet(this, _dataRefs).delete(__ref); | ||
}; | ||
const cacheKey = `${type}.${field}`; | ||
clearTimeout((_a = __privateGet(this, _data).get(cacheKey)) == null ? void 0 : _a.timeout); | ||
const dataContainer = ( | ||
@@ -246,19 +257,18 @@ // Mutation and subscription results should be returned right away for | ||
expiresAt: now + 100, | ||
swrBefore: now | ||
swrBefore: now, | ||
unref | ||
} : { | ||
data, | ||
expiresAt: age + now, | ||
swrBefore: age + swr + now | ||
swrBefore: age + swr + now, | ||
unref | ||
} | ||
); | ||
(_b = (_a = __privateGet(this, _data).get(cacheKey)) == null ? void 0 : _a.unref) == null ? void 0 : _b.call(_a); | ||
if (isFinite(age + swr)) { | ||
const timeout = setTimeout( | ||
// Hold on to lexical scope reference, preventing GC from WeakRef. | ||
() => dataContainer, | ||
age + swr | ||
); | ||
if (typeof timeout === "object") { | ||
timeout.unref(); | ||
unrefTimer = setTimeout(unref, age + swr); | ||
if (typeof unrefTimer === "object") { | ||
unrefTimer.unref(); | ||
} | ||
dataContainer.timeout = timeout; | ||
__privateGet(this, _dataRefs).set(__ref, dataContainer); | ||
} | ||
@@ -299,2 +309,3 @@ __privateGet(this, _data).set(cacheKey, dataContainer, { strong: !isFinite(age) }); | ||
_normalizedObjects = new WeakMap(); | ||
_dataRefs = new WeakMap(); | ||
_subscriptions = new WeakMap(); | ||
@@ -313,9 +324,13 @@ _normalizedSubscriptions = new WeakMap(); | ||
const [type, field, ...parts] = path.split("."); | ||
select.select((_b = this.get(`${type}.${field}`)) == null ? void 0 : _b.data, parts, (node) => { | ||
const id = getId(node); | ||
if (id && store.has(id) && utils.isCacheObject(node)) { | ||
nsubs.set(node, fn); | ||
select.select( | ||
(_b = this.get(`${type}.${field}`, { includeExpired: true })) == null ? void 0 : _b.data, | ||
parts, | ||
(node) => { | ||
const id = getId(node); | ||
if (id && store.has(id) && utils.isCacheObject(node)) { | ||
nsubs.set(node, fn); | ||
} | ||
return node; | ||
} | ||
return node; | ||
}); | ||
); | ||
} | ||
@@ -322,0 +337,0 @@ }; |
@@ -1,6 +0,7 @@ | ||
import type { BaseGeneratedSchema, FetchOptions, SchemaContext } from '../..'; | ||
import type { Cache } from '../../Cache'; | ||
import type { ScalarsEnumsHash, Schema } from '../../Schema'; | ||
import type { createDebugger } from '../debugger'; | ||
import type { Resolvers } from '../resolvers'; | ||
import { type BaseGeneratedSchema, type FetchOptions, type SchemaContext } from '../..'; | ||
import { type Cache } from '../../Cache'; | ||
import { type ScalarsEnumsHash, type Schema } from '../../Schema'; | ||
import { type Selectable } from '../../Selectable'; | ||
import { type createDebugger } from '../debugger'; | ||
import { type Resolvers } from '../resolvers'; | ||
import { LegacyHydrateCache } from './hydrateCache'; | ||
@@ -11,6 +12,6 @@ import { LegacyInlineResolved } from './inlineResolved'; | ||
import { LegacyPrepareRender } from './prepareRender'; | ||
import type { LegacyQueryFetcher } from './queryFetcher'; | ||
import { type LegacyQueryFetcher } from './queryFetcher'; | ||
import { LegacyRefetch } from './refetch'; | ||
import { LegacyResolved } from './resolved'; | ||
import type { LegacySubscriptionsClient } from './subscriptionsClient'; | ||
import { type LegacySubscriptionsClient } from './subscriptionsClient'; | ||
import { LegacyTrack } from './track'; | ||
@@ -47,3 +48,3 @@ export type { LegacyHydrateCache, LegacyHydrateCacheOptions, } from './hydrateCache'; | ||
*/ | ||
export type SelectionSubscriber = (fn: NonNullable<SchemaContext['onSelect']>) => () => void; | ||
export type SelectionSubscriber = (fn: Selectable['select']) => () => void; | ||
export type LegacyClient<TSchema extends BaseGeneratedSchema> = { | ||
@@ -75,4 +76,4 @@ /** | ||
/** | ||
* @deprecated It does not include selections from scoped queries such as | ||
* `resolve()` and `subscribe()`, do not mix usage if you are using SSR. | ||
* Captures selections made with a fake render, fetches them and returns the | ||
* result. | ||
*/ | ||
@@ -79,0 +80,0 @@ prepareRender: LegacyPrepareRender; |
@@ -14,19 +14,17 @@ 'use strict'; | ||
let deprecationWarningMessage = !process.env.NODE_ENV || process.env.NODE_ENV === "development" ? "[GQty] global query, mutation and subscription is deprecated, use `schema` instead." : void 0; | ||
const createLegacyClient = (options) => { | ||
const selectionHistory = /* @__PURE__ */ new Set(); | ||
const selectionSubscriptions = /* @__PURE__ */ new Set(); | ||
const prevOnSelect = options.context.onSelect; | ||
options.context.onSelect = (selection, cache) => { | ||
if (selectionSubscriptions.size > 0) { | ||
selectionHistory.add(selection); | ||
} | ||
selectionSubscriptions.forEach((fn) => fn(selection, cache)); | ||
prevOnSelect == null ? void 0 : prevOnSelect.call(options.context, selection, cache); | ||
}; | ||
options.context.subscribeSelect((select) => { | ||
selectionHistory.add(select); | ||
}); | ||
const methodOptions = { | ||
...options, | ||
subscribeLegacySelections(fn) { | ||
selectionSubscriptions.add(fn); | ||
return () => selectionSubscriptions.delete(fn); | ||
const { context } = options; | ||
const unsubscribeSelect = context.subscribeSelect(fn); | ||
const unsubscribeDispose = context.subscribeDispose(unsubscribeSelect); | ||
return () => { | ||
unsubscribeDispose(); | ||
unsubscribeSelect(); | ||
}; | ||
} | ||
@@ -36,17 +34,5 @@ }; | ||
return { | ||
get query() { | ||
deprecationWarningMessage && console.warn(deprecationWarningMessage); | ||
deprecationWarningMessage = void 0; | ||
return options.accessor.query; | ||
}, | ||
get mutation() { | ||
deprecationWarningMessage && console.warn(deprecationWarningMessage); | ||
deprecationWarningMessage = void 0; | ||
return options.accessor.mutation; | ||
}, | ||
get subscription() { | ||
deprecationWarningMessage && console.warn(deprecationWarningMessage); | ||
deprecationWarningMessage = void 0; | ||
return options.accessor.subscription; | ||
}, | ||
query: options.accessor.query, | ||
mutation: options.accessor.mutation, | ||
subscription: options.accessor.subscription, | ||
resolved: resolved.createLegacyResolved(methodOptions), | ||
@@ -53,0 +39,0 @@ inlineResolved: inlineResolved$1, |
@@ -23,4 +23,3 @@ 'use strict'; | ||
const unsubscribe = subscribeLegacySelections((selection$1, cache) => { | ||
var _a; | ||
(_a = context.onSelect) == null ? void 0 : _a.call(context, selection$1, cache); | ||
context.select(selection$1, cache); | ||
onSelection == null ? void 0 : onSelection(selection.convertSelection(selection$1)); | ||
@@ -27,0 +26,0 @@ }); |
@@ -15,4 +15,3 @@ 'use strict'; | ||
const unsubscribe = subscribeLegacySelections((selection, cache) => { | ||
var _a; | ||
(_a = context.onSelect) == null ? void 0 : _a.call(context, selection, cache); | ||
context.select(selection, cache); | ||
}); | ||
@@ -19,0 +18,0 @@ const data = fn(query); |
@@ -39,4 +39,3 @@ 'use strict'; | ||
const unsubscribe = subscribeLegacySelections((selection$1, cache2) => { | ||
var _a; | ||
(_a = context.onSelect) == null ? void 0 : _a.call(context, selection$1, cache2); | ||
context.select(selection$1, cache2); | ||
onSelection == null ? void 0 : onSelection(selection.convertSelection(selection$1)); | ||
@@ -43,0 +42,0 @@ }); |
@@ -28,4 +28,3 @@ 'use strict'; | ||
const unsubscribe = subscribeLegacySelections((selection, cache2) => { | ||
var _a; | ||
(_a = context.onSelect) == null ? void 0 : _a.call(context, selection, cache2); | ||
context.select(selection, cache2); | ||
}); | ||
@@ -32,0 +31,0 @@ const data = { current: dataFn({ type: "initial" }) }; |
@@ -1,5 +0,6 @@ | ||
import { Cache, CacheDataContainer, CacheGetOptions } from '../Cache'; | ||
import { Cache, CacheGetOptions } from '../Cache'; | ||
import { type Disposable } from '../Disposable'; | ||
import type { ScalarsEnumsHash, Schema } from '../Schema'; | ||
import type { Selection } from '../Selection'; | ||
export type SchemaContext<T extends Record<string, unknown> = Record<string, unknown>> = T & { | ||
import { type Selectable } from '../Selectable'; | ||
export type SchemaContext<T extends Record<string, unknown> = Record<string, unknown>> = T & Disposable & Selectable & { | ||
cache: Cache; | ||
@@ -13,3 +14,2 @@ readonly cacheOptions?: CacheGetOptions; | ||
readonly typeKeys?: Record<string, string[]>; | ||
onSelect: (selection: Selection, cache?: CacheDataContainer) => void; | ||
notifyCacheUpdate: boolean; | ||
@@ -24,3 +24,2 @@ shouldFetch: boolean; | ||
cachePolicy: RequestCache; | ||
onSelect?: NonNullable<SchemaContext['onSelect']>; | ||
scalars: ScalarsEnumsHash; | ||
@@ -30,2 +29,2 @@ schema: Readonly<Schema>; | ||
}; | ||
export declare const createContext: ({ cache, cachePolicy, depthLimit, onSelect, scalars, schema, typeKeys, }: CreateContextOptions) => SchemaContext; | ||
export declare const createContext: ({ cache, cachePolicy, depthLimit, scalars, schema, typeKeys, }: CreateContextOptions) => SchemaContext; |
@@ -11,29 +11,49 @@ 'use strict'; | ||
depthLimit, | ||
onSelect, | ||
scalars, | ||
schema, | ||
typeKeys | ||
}) => ({ | ||
cache: cachePolicy === "no-cache" || cachePolicy === "no-store" || cachePolicy === "reload" ? new index.Cache(void 0, { maxAge: Infinity }) : cache, | ||
cacheOptions: { | ||
includeExpired: cachePolicy === "default" || cachePolicy === "force-cache" || cachePolicy === "only-if-cached" | ||
}, | ||
scalars, | ||
schema, | ||
depthLimit, | ||
hasCacheHit: false, | ||
hasCacheMiss: false, | ||
shouldFetch: false, | ||
notifyCacheUpdate: cachePolicy !== "default", | ||
onSelect(selection, cacheNode) { | ||
const now = Date.now(); | ||
const { data, expiresAt: age = Infinity } = cacheNode != null ? cacheNode : {}; | ||
this.shouldFetch || (this.shouldFetch = data === void 0 || age < now - 100); | ||
this.hasCacheHit || (this.hasCacheHit = data !== void 0); | ||
this.notifyCacheUpdate || (this.notifyCacheUpdate = data === void 0); | ||
onSelect == null ? void 0 : onSelect(selection, cacheNode); | ||
}, | ||
typeKeys | ||
}); | ||
}) => { | ||
const disposeSubscriptions = /* @__PURE__ */ new Set(); | ||
const selectSubscriptions = /* @__PURE__ */ new Set(); | ||
return { | ||
cache: cachePolicy === "no-cache" || cachePolicy === "no-store" || cachePolicy === "reload" ? new index.Cache(void 0, { maxAge: Infinity }) : cache, | ||
cacheOptions: { | ||
includeExpired: cachePolicy === "default" || cachePolicy === "force-cache" || cachePolicy === "only-if-cached" | ||
}, | ||
scalars, | ||
schema, | ||
depthLimit, | ||
hasCacheHit: false, | ||
hasCacheMiss: false, | ||
shouldFetch: false, | ||
notifyCacheUpdate: cachePolicy !== "default", | ||
select(selection, cacheNode) { | ||
const now = Date.now(); | ||
const { data, expiresAt: age = Infinity } = cacheNode != null ? cacheNode : {}; | ||
this.shouldFetch || (this.shouldFetch = data === void 0 || age < now - 100); | ||
this.hasCacheHit || (this.hasCacheHit = data !== void 0); | ||
this.notifyCacheUpdate || (this.notifyCacheUpdate = data === void 0); | ||
selectSubscriptions.forEach((fn) => fn(selection, cacheNode)); | ||
}, | ||
subscribeSelect(callback) { | ||
selectSubscriptions.add(callback); | ||
return () => { | ||
selectSubscriptions.delete(callback); | ||
}; | ||
}, | ||
dispose() { | ||
disposeSubscriptions.forEach((fn) => fn()); | ||
disposeSubscriptions.clear(); | ||
selectSubscriptions.clear(); | ||
}, | ||
subscribeDispose(callback) { | ||
disposeSubscriptions.add(callback); | ||
return () => { | ||
disposeSubscriptions.delete(callback); | ||
}; | ||
}, | ||
typeKeys | ||
}; | ||
}; | ||
exports.createContext = createContext; |
@@ -25,4 +25,6 @@ 'use strict'; | ||
const createClient = ({ | ||
// Legacy clients don't have this. | ||
cache = new index$1.Cache(), | ||
// This default cache on a required option is for legacy clients, which does | ||
// not provide a `cache` option. | ||
// TODO: compat: remove in v4 | ||
cache = new index$1.Cache(void 0, { normalization: true }), | ||
fetchOptions: { | ||
@@ -29,0 +31,0 @@ fetcher, |
@@ -51,3 +51,3 @@ import type { BaseGeneratedSchema, FetchOptions } from '.'; | ||
}; | ||
export type CreateResolverFn<TSchema extends BaseGeneratedSchema> = (options?: ResolveOptions) => { | ||
export type ResolverParts<TSchema extends BaseGeneratedSchema> = { | ||
accessor: TSchema; | ||
@@ -63,2 +63,3 @@ context: SchemaContext; | ||
}; | ||
export type CreateResolverFn<TSchema extends BaseGeneratedSchema> = (options?: ResolveOptions) => ResolverParts<TSchema>; | ||
export type ResolveFn<TSchema extends BaseGeneratedSchema> = <TData extends Record<string, unknown> = Record<string, unknown>>(fn: DataFn<TSchema>, options?: ResolveOptions) => Promise<TData>; | ||
@@ -103,3 +104,3 @@ export type SubscribeFn<TSchema extends BaseGeneratedSchema> = <TData extends Record<string, unknown> = Record<string, unknown>>(fn: DataFn<TSchema>, options?: SubscribeOptions) => AsyncGenerator<TData, void, unknown> & { | ||
onFetch?: (fetchPromise: Promise<unknown>) => void; | ||
onSelect?: NonNullable<SchemaContext['onSelect']>; | ||
onSelect?: SchemaContext['select']; | ||
operationName?: string; | ||
@@ -139,3 +140,3 @@ }; | ||
onError?: (error: unknown) => void; | ||
onSelect?: NonNullable<SchemaContext['onSelect']>; | ||
onSelect?: SchemaContext['select']; | ||
/** | ||
@@ -142,0 +143,0 @@ * Called when a subscription is established, receives an unsubscribe |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const pick = require('../Utils/pick.js'); | ||
const batching = require('./batching.js'); | ||
const context = require('./context.js'); | ||
@@ -13,2 +14,3 @@ const resolveSelections = require('./resolveSelections.js'); | ||
const asyncItDoneMessage = { done: true }; | ||
const pendingQueries = /* @__PURE__ */ new WeakMap(); | ||
const createResolvers = ({ | ||
@@ -39,12 +41,12 @@ cache: clientCache, | ||
cachePolicy, | ||
onSelect(selection, cache) { | ||
if (!selections.has(selection)) { | ||
selections.add(selection); | ||
parentContext == null ? void 0 : parentContext.onSelect(selection, cache); | ||
} | ||
onSelect == null ? void 0 : onSelect(selection, cache); | ||
}, | ||
scalars, | ||
schema | ||
}); | ||
context$1.subscribeSelect((selection, cache) => { | ||
if (!selections.has(selection)) { | ||
selections.add(selection); | ||
parentContext == null ? void 0 : parentContext.select(selection, cache); | ||
} | ||
onSelect == null ? void 0 : onSelect(selection, cache); | ||
}); | ||
const accessor = index.createSchemaAccessor(context$1); | ||
@@ -57,19 +59,43 @@ const resolve = async () => { | ||
} | ||
return resolveSelections.fetchSelections(selections, { | ||
cache: context$1.cache, | ||
debugger: debug, | ||
fetchOptions: { | ||
...fetchOptions, | ||
cachePolicy, | ||
retryPolicy | ||
}, | ||
operationName | ||
}).then((results) => { | ||
updateCaches.updateCaches( | ||
results, | ||
cachePolicy !== "no-store" && context$1.cache !== clientCache ? [context$1.cache, clientCache] : [context$1.cache], | ||
{ skipNotify: !context$1.notifyCacheUpdate } | ||
const selectionsCacheKey = `${cachePolicy}/${operationName != null ? operationName : ""}`; | ||
const pendingSelections = batching.addSelections( | ||
clientCache, | ||
selectionsCacheKey, | ||
selections | ||
); | ||
if (!pendingQueries.has(pendingSelections)) { | ||
pendingQueries.set( | ||
pendingSelections, | ||
new Promise((resolve2, reject) => { | ||
queueMicrotask(() => { | ||
var _a; | ||
const selections2 = new Set( | ||
[ | ||
...(_a = batching.getSelectionsSet(clientCache, selectionsCacheKey)) != null ? _a : [] | ||
].flatMap((selections3) => [...selections3]) | ||
); | ||
pendingQueries.delete(pendingSelections); | ||
batching.delSelectionsSet(clientCache, selectionsCacheKey); | ||
resolveSelections.fetchSelections(selections2, { | ||
cache: context$1.cache, | ||
debugger: debug, | ||
fetchOptions: { | ||
...fetchOptions, | ||
cachePolicy, | ||
retryPolicy | ||
}, | ||
operationName | ||
}).then((results) => { | ||
updateCaches.updateCaches( | ||
results, | ||
cachePolicy !== "no-store" && context$1.cache !== clientCache ? [context$1.cache, clientCache] : [context$1.cache], | ||
{ skipNotify: !context$1.notifyCacheUpdate } | ||
); | ||
return results; | ||
}).then(resolve2, reject); | ||
}); | ||
}) | ||
); | ||
return results; | ||
}); | ||
} | ||
return pendingQueries.get(pendingSelections); | ||
}; | ||
@@ -76,0 +102,0 @@ const subscribe = ({ |
@@ -0,1 +1,2 @@ | ||
import { Selection } from '../Selection'; | ||
export interface PrepassObjKey { | ||
@@ -6,1 +7,2 @@ field: string; | ||
export declare function prepass<T extends object | null | undefined>(v: T, ...keys: Array<string | Array<string | PrepassObjKey>>): T; | ||
export declare function prepass<T extends object | null | undefined>(v: T, selections: Set<Selection>): T; |
@@ -16,2 +16,10 @@ 'use strict'; | ||
return v; | ||
keys = keys[0] instanceof Set ? keys = [...keys[0]].map((selection) => { | ||
return selection.ancestry.map( | ||
(s) => s.input ? { | ||
field: `${s.key}`, | ||
variables: s.input.values | ||
} : `${s.key}` | ||
); | ||
}) : keys; | ||
for (const composedKeys of keys) { | ||
@@ -18,0 +26,0 @@ const separatedKeys = typeof composedKeys === "string" ? composedKeys.split(".") : composedKeys; |
{ | ||
"name": "gqty", | ||
"version": "3.0.0-alpha-24f11bbe.0", | ||
"version": "3.0.0-alpha-2b305512.0", | ||
"description": "gqty client without queries", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -13,3 +13,3 @@ 'use strict'; | ||
const stringifySelectionTree = (tree) => Object.entries(tree).reduce((prev, [key, value]) => { | ||
const stringifySelectionTree = (tree) => Object.entries(tree).sort(([a], [b]) => a.localeCompare(b)).reduce((prev, [key, value]) => { | ||
const query = typeof value === "object" ? `${key}{${stringifySelectionTree(value)}}` : key; | ||
@@ -16,0 +16,0 @@ if (!prev || prev.endsWith("}") || prev.endsWith("{")) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
273548
162
7846
14