Comparing version 3.0.0-alpha-455c7aa1.0 to 3.0.0-alpha-4c58a180.0
@@ -8,3 +8,3 @@ import type { BaseGeneratedSchema, SchemaContext } from '../Client'; | ||
*/ | ||
export declare const setCache: <TData extends GeneratedSchemaObject<Record<string, any>>>(accessor: TData, data: Partial<TData>) => void; | ||
export declare const setCache: <TData extends GeneratedSchemaObject>(accessor: TData, data: Partial<TData>) => void; | ||
/** | ||
@@ -16,2 +16,2 @@ * Use another accessor like a fragment, this function takes all children from | ||
*/ | ||
export declare const assignSelections: <TData extends GeneratedSchemaObject<Record<string, any>>>(source: TData | null, target: TData | null) => void; | ||
export declare const assignSelections: <TData extends GeneratedSchemaObject>(source: TData | null, target: TData | null) => void; |
import type { CacheNode } from '../Cache'; | ||
import { GeneratedSchemaObject, Type } from '../Schema'; | ||
import { type GeneratedSchemaObject, type Type } from '../Schema'; | ||
import type { Selection } from '../Selection'; | ||
@@ -9,5 +9,5 @@ import type { Meta } from './meta'; | ||
*/ | ||
export declare const resolve: (accessor: GeneratedSchemaObject, selection: Selection, __type: Type['__type']) => string | number | boolean | CacheNode[] | GeneratedSchemaObject<Record<string, any>> | { | ||
export declare const resolve: (accessor: GeneratedSchemaObject, selection: Selection, __type: Type['__type']) => string | number | boolean | CacheNode[] | GeneratedSchemaObject | { | ||
[k: string]: boolean; | ||
} | GeneratedSchemaObject<Record<string, any>>[] | null | undefined; | ||
} | GeneratedSchemaObject[] | null | undefined; | ||
export declare const createUnionAccessor: ({ context, cache, possibleTypes, selection, }: Omit<Meta, "type"> & { | ||
@@ -21,5 +21,5 @@ possibleTypes: readonly string[]; | ||
}; | ||
export declare const createObjectAccessor: <TSchemaType extends GeneratedSchemaObject<Record<string, any>>>(meta: Meta) => GeneratedSchemaObject<Record<string, any>>; | ||
export declare const createObjectAccessor: <TSchemaType extends GeneratedSchemaObject>(meta: Meta) => GeneratedSchemaObject; | ||
/** Recursively replace proxy accessors with its actual cached value. */ | ||
export declare const deepMetadata: (input: any) => any; | ||
export declare const createArrayAccessor: <TSchemaType extends GeneratedSchemaObject<Record<string, any>>[]>(meta: Meta) => TSchemaType; | ||
export declare const createArrayAccessor: <TSchemaType extends GeneratedSchemaObject[]>(meta: Meta) => TSchemaType; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
const types = require('../Schema/types.js'); | ||
require('../Utils/hash.js'); | ||
const object = require('../Utils/object.js'); | ||
@@ -11,0 +12,0 @@ require('just-safe-set'); |
@@ -1,5 +0,5 @@ | ||
import type { GeneratedSchemaObject } from '../Schema'; | ||
import type { Selection } from '../Selection'; | ||
import { CacheNormalizationHandler } from './normalization'; | ||
import { CacheSnapshot } from './persistence'; | ||
import { type GeneratedSchemaObject } from '../Schema'; | ||
import { type Selection } from '../Selection'; | ||
import { type CacheNormalizationHandler } from './normalization'; | ||
import { type CacheSnapshot } from './persistence'; | ||
export type CacheRoot = { | ||
@@ -6,0 +6,0 @@ query?: CacheObject; |
@@ -10,2 +10,3 @@ 'use strict'; | ||
const FrailMap = require('../Helpers/FrailMap.js'); | ||
require('../Utils/hash.js'); | ||
const select = require('../Helpers/select.js'); | ||
@@ -12,0 +13,0 @@ require('just-safe-get'); |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const index = require('../Error/index.js'); | ||
require('../Utils/hash.js'); | ||
const object = require('../Utils/object.js'); | ||
@@ -8,0 +9,0 @@ require('just-safe-set'); |
import type { Cache, CacheLeaf, CacheNode, CacheObject, CacheRoot } from '.'; | ||
import { FrailMap } from '../Helpers/FrailMap'; | ||
import { CacheNormalizationHandler, NormalizedObjectShell } from './normalization'; | ||
import { type CacheNormalizationHandler, type NormalizedObjectShell } from './normalization'; | ||
export type Persistors = { | ||
@@ -5,0 +5,0 @@ persist(version?: string): CacheSnapshot; |
@@ -7,4 +7,5 @@ 'use strict'; | ||
const index = require('../Error/index.js'); | ||
const FrailMap = require('../Helpers/FrailMap.js'); | ||
const deepCopy = require('../Helpers/deepCopy.js'); | ||
const FrailMap = require('../Helpers/FrailMap.js'); | ||
require('../Utils/hash.js'); | ||
const object = require('../Utils/object.js'); | ||
@@ -11,0 +12,0 @@ require('just-safe-set'); |
@@ -7,22 +7,22 @@ import { type BaseGeneratedSchema, type FetchOptions, type SchemaContext } from '../..'; | ||
import { type Resolvers } from '../resolvers'; | ||
import { LegacyHydrateCache } from './hydrateCache'; | ||
import { LegacyInlineResolved } from './inlineResolved'; | ||
import { LegacyMutate } from './mutate'; | ||
import { LegacyPrefetch } from './prefetch'; | ||
import { LegacyPrepareRender } from './prepareRender'; | ||
import { type LegacyHydrateCache } from './hydrateCache'; | ||
import { type LegacyInlineResolved } from './inlineResolved'; | ||
import { type LegacyMutate } from './mutate'; | ||
import { type LegacyPrefetch } from './prefetch'; | ||
import { type LegacyPrepareRender } from './prepareRender'; | ||
import { type LegacyQueryFetcher } from './queryFetcher'; | ||
import { LegacyRefetch } from './refetch'; | ||
import { LegacyResolved } from './resolved'; | ||
import { type LegacyRefetch } from './refetch'; | ||
import { type LegacyResolved } from './resolved'; | ||
import { type LegacySubscriptionsClient } from './subscriptionsClient'; | ||
import { LegacyTrack } from './track'; | ||
export type { LegacyHydrateCache, LegacyHydrateCacheOptions, } from './hydrateCache'; | ||
export type { LegacyInlineResolved, LegacyInlineResolveOptions, } from './inlineResolved'; | ||
export type { LegacyMutate, LegacyMutateHelpers } from './mutate'; | ||
export type { LegacyPrefetch } from './prefetch'; | ||
export type { LegacyQueryFetcher } from './queryFetcher'; | ||
export type { LegacyRefetch } from './refetch'; | ||
export type { LegacyResolved, LegacyResolveOptions } from './resolved'; | ||
export type { LegacySelection } from './selection'; | ||
export type { LegacySubscribeEvents, LegacySubscriptionsClient, } from './subscriptionsClient'; | ||
export type { LegacyTrack, LegacyTrackCallInfo, LegacyTrackCallType, LegacyTrackOptions, } from './track'; | ||
import { type LegacyTrack } from './track'; | ||
export { type LegacyHydrateCache, type LegacyHydrateCacheOptions, } from './hydrateCache'; | ||
export { type LegacyInlineResolveOptions, type LegacyInlineResolved, } from './inlineResolved'; | ||
export { type LegacyMutate, type LegacyMutateHelpers } from './mutate'; | ||
export { type LegacyPrefetch } from './prefetch'; | ||
export { type LegacyQueryFetcher } from './queryFetcher'; | ||
export { type LegacyRefetch } from './refetch'; | ||
export { type LegacyResolveOptions, type LegacyResolved } from './resolved'; | ||
export { type LegacySelection } from './selection'; | ||
export { type LegacySubscribeEvents, type LegacySubscriptionsClient, } from './subscriptionsClient'; | ||
export { type LegacyTrack, type LegacyTrackCallInfo, type LegacyTrackCallType, type LegacyTrackOptions, } from './track'; | ||
export type CreateLegacyClientOptions<TSchema extends BaseGeneratedSchema> = { | ||
@@ -29,0 +29,0 @@ accessor: TSchema; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
const index = require('../../Error/index.js'); | ||
require('../../Selection/index.js'); | ||
require('../../Utils/hash.js'); | ||
const meta = require('../../Accessor/meta.js'); | ||
@@ -10,0 +10,0 @@ require('../../Accessor/resolve.js'); |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const index = require('../../Cache/index.js'); | ||
require('../../Utils/hash.js'); | ||
const object = require('../../Utils/object.js'); | ||
@@ -31,3 +32,3 @@ require('just-safe-set'); | ||
return false; | ||
if (it[1] && (!object.isPlainObject(it[1]) || !object.isPlainObject(it[1].input) || typeof it[1].isUnion !== "boolean")) | ||
if (it[1] && (!object.isPlainObject(it[1]) || !object.isPlainObject(it[1].input) || it[1].isUnion !== void 0 && it[1].isUnion !== true)) | ||
return false; | ||
@@ -34,0 +35,0 @@ return true; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
require('../../Selection/index.js'); | ||
require('../../Utils/hash.js'); | ||
const meta = require('../../Accessor/meta.js'); | ||
@@ -8,0 +8,0 @@ require('../../Accessor/resolve.js'); |
@@ -1,4 +0,4 @@ | ||
import type { BaseGeneratedSchema } from '..'; | ||
import { GQtyError, RetryOptions } from '../../Error'; | ||
import type { CreateLegacyMethodOptions } from './client'; | ||
import { type BaseGeneratedSchema } from '..'; | ||
import { GQtyError, type RetryOptions } from '../../Error'; | ||
import { type CreateLegacyMethodOptions } from './client'; | ||
import { type LegacySelection } from './selection'; | ||
@@ -5,0 +5,0 @@ export interface LegacyFetchOptions extends Omit<RequestInit, 'body'> { |
@@ -1,5 +0,5 @@ | ||
import { Client } from 'graphql-ws'; | ||
import type { Promisable } from 'type-fest'; | ||
import type { Client } from 'graphql-ws'; | ||
import { GQtyError } from '../../Error'; | ||
import type { LegacySelection as Selection } from './selection'; | ||
type Promisable<T> = T | Promise<T>; | ||
export type LegacySubscriptionsClient<TData extends Record<string, unknown> = Record<string, unknown>> = { | ||
@@ -35,1 +35,2 @@ subscribe(opts: { | ||
export declare const createLegacySubscriptionsClient: (subscriptionsClient: LegacySubscriptionsClient) => Client; | ||
export {}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
const graphqlWs = require('graphql-ws'); | ||
const index = require('../../Error/index.js'); | ||
@@ -29,3 +28,3 @@ | ||
dispatchEvent("message", { | ||
type: graphqlWs.MessageType.ConnectionAck | ||
type: "connection_ack" | ||
}); | ||
@@ -60,3 +59,3 @@ }, | ||
id: operationId, | ||
type: graphqlWs.MessageType.Subscribe, | ||
type: "subscribe", | ||
payload | ||
@@ -70,3 +69,3 @@ }); | ||
id: sub.operationId, | ||
type: graphqlWs.MessageType.Subscribe, | ||
type: "subscribe", | ||
payload | ||
@@ -73,0 +72,0 @@ }); |
@@ -1,4 +0,4 @@ | ||
import { Cache, CacheGetOptions } from '../Cache'; | ||
import { Cache, type CacheGetOptions } from '../Cache'; | ||
import { type Disposable } from '../Disposable'; | ||
import type { ScalarsEnumsHash, Schema } from '../Schema'; | ||
import { type ScalarsEnumsHash, type Schema } from '../Schema'; | ||
import { type Selectable } from '../Selectable'; | ||
@@ -5,0 +5,0 @@ export type SchemaContext<T extends Record<string, unknown> = Record<string, unknown>> = T & Disposable & Selectable & { |
@@ -1,10 +0,10 @@ | ||
import type { Client as SseClient } from 'graphql-sse'; | ||
import type { Client as WsClient } from 'graphql-ws'; | ||
import { type Client as SseClient } from 'graphql-sse'; | ||
import { type Client as WsClient } from 'graphql-ws'; | ||
import { Cache } from '../Cache'; | ||
import { Persistors } from '../Cache/persistence'; | ||
import { type Persistors } from '../Cache/persistence'; | ||
import type { RetryOptions } from '../Error'; | ||
import type { GeneratedSchemaObject, QueryFetcher, ScalarsEnumsHash, Schema } from '../Schema'; | ||
import { LegacyClient, LegacyClientOptions } from './compat/client'; | ||
import { type LegacyClient, type LegacyClientOptions } from './compat/client'; | ||
import { createDebugger } from './debugger'; | ||
import { Resolvers } from './resolvers'; | ||
import { type Resolvers } from './resolvers'; | ||
export { $meta } from '../Accessor'; | ||
@@ -11,0 +11,0 @@ export { getFields, prepass, selectFields } from '../Helpers'; |
@@ -20,2 +20,3 @@ 'use strict'; | ||
const useMetaStateHack = require('../Helpers/useMetaStateHack.js'); | ||
require('../Utils/hash.js'); | ||
const pick = require('../Utils/pick.js'); | ||
@@ -22,0 +23,0 @@ const resolveSelections = require('./resolveSelections.js'); |
@@ -1,9 +0,9 @@ | ||
import type { BaseGeneratedSchema, FetchOptions } from '.'; | ||
import type { Cache } from '../Cache'; | ||
import type { GQtyError, RetryOptions } from '../Error'; | ||
import type { ScalarsEnumsHash, Schema } from '../Schema'; | ||
import type { Selection } from '../Selection'; | ||
import { SchemaContext } from './context'; | ||
import type { Debugger } from './debugger'; | ||
import { Unsubscribe } from './resolveSelections'; | ||
import { type BaseGeneratedSchema, type FetchOptions } from '.'; | ||
import { type Cache } from '../Cache'; | ||
import { type GQtyError, type RetryOptions } from '../Error'; | ||
import { type ScalarsEnumsHash, type Schema } from '../Schema'; | ||
import { type Selection } from '../Selection'; | ||
import { type SchemaContext } from './context'; | ||
import { type Debugger } from './debugger'; | ||
import { type Unsubscribe } from './resolveSelections'; | ||
export type CreateResolversOptions = { | ||
@@ -69,12 +69,4 @@ cache: Cache; | ||
export type DataResult<TData = unknown> = TData extends undefined ? TData : TData extends void ? unknown : TData; | ||
export type ResolveOptions = { | ||
export type CreateResolverOptions = { | ||
/** | ||
* Awaits resolution it the query results in a fetch. Specify `false` to | ||
* immediately return the current cache, placeholder data will be returned on | ||
* a partial or complete cache miss. | ||
* | ||
* @default true | ||
*/ | ||
awaitsFetch?: boolean; | ||
/** | ||
* Defines how a query should fetch from the cache and network. | ||
@@ -89,5 +81,3 @@ * | ||
* GQty creates a temporary cache at query-level which immediately expires. | ||
* - `reload`: Always fetch, updates on response. | ||
* - `no-cache`: Same as `reload`, for GraphQL does not support conditional | ||
* requests. | ||
* - `no-cache`: Always fetch, updates on response. | ||
* - `force-cache`: Serves the cached contents regardless of staleness. It | ||
@@ -103,30 +93,20 @@ * fetches on cache miss or a stale cache, updates cache on response. | ||
cachePolicy?: RequestCache; | ||
/** Custom GraphQL extensions to be exposed to the query fetcher. */ | ||
extensions?: Record<string, unknown>; | ||
retryPolicy?: RetryOptions; | ||
onFetch?: (fetchPromise: Promise<unknown>) => void; | ||
onSelect?: SchemaContext['select']; | ||
operationName?: string; | ||
}; | ||
export type SubscribeOptions = { | ||
export type ResolveOptions = CreateResolverOptions & { | ||
/** | ||
* Defines how a query should fetch from the cache and network. | ||
* Awaits resolution it the query results in a fetch. Specify `false` to | ||
* immediately return the current cache, placeholder data will be returned on | ||
* a partial or complete cache miss. | ||
* | ||
* - `default`: Serves the cached contents when it is fresh, and if they are | ||
* stale within `staleWhileRevalidate` window, fetches in the background and | ||
* updates the cache. Or simply fetches on cache stale or cache miss. During | ||
* SWR, a successful fetch will not notify cache updates. New contents are | ||
* served on next query. | ||
* - `no-store`: Always fetch and does not update on response. | ||
* GQty creates a temporary cache at query-level which immediately expires. | ||
* - `no-cache`: Always fetch, updates on response. | ||
* - `force-cache`: Serves the cached contents regardless of staleness. It | ||
* fetches on cache miss or a stale cache, updates cache on response. | ||
* - `only-if-cached`: Serves the cached contents regardless of staleness, | ||
* throws a network error on cache miss. | ||
* | ||
* _It takes effort to make sure the above stays true for all supported | ||
* frameworks, please consider sponsoring so we can dedicate even more time on | ||
* this._ | ||
* @default true | ||
*/ | ||
cachePolicy?: RequestCache; | ||
retryPolicy?: RetryOptions; | ||
awaitsFetch?: boolean; | ||
onFetch?: (fetchPromise: Promise<unknown>) => void; | ||
}; | ||
export type SubscribeOptions = CreateResolverOptions & { | ||
/** | ||
@@ -141,3 +121,2 @@ * Intercept errors thrown from the underlying subscription client or query | ||
onError?: (error: unknown) => void; | ||
onSelect?: SchemaContext['select']; | ||
/** | ||
@@ -149,4 +128,3 @@ * Called when a subscription is established, receives an unsubscribe | ||
onSubscribe?: (unsubscribe: Unsubscribe) => void; | ||
operationName?: string; | ||
}; | ||
export declare const createResolvers: <TSchema extends BaseGeneratedSchema>({ cache: clientCache, debugger: debug, depthLimit, fetchOptions, fetchOptions: { cachePolicy: defaultCachePolicy, retryPolicy: defaultRetryPoliy, }, scalars, schema, parentContext, }: CreateResolversOptions) => Resolvers<TSchema>; |
@@ -29,2 +29,3 @@ 'use strict'; | ||
cachePolicy = defaultCachePolicy, | ||
extensions, | ||
onSelect, | ||
@@ -52,2 +53,10 @@ onSubscribe, | ||
const resolve = async () => { | ||
if (selections.size === 0) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.warn( | ||
"[GQty] No selections found. If you are reading from the global accessors, try using the first argument instead." | ||
); | ||
} | ||
return; | ||
} | ||
if (!context$1.shouldFetch) | ||
@@ -67,29 +76,28 @@ return; | ||
pendingSelections, | ||
new Promise((resolve2, reject) => { | ||
queueMicrotask(() => { | ||
var _a; | ||
const selections2 = new Set( | ||
[ | ||
...(_a = batching.getSelectionsSet(clientCache, selectionsCacheKey)) != null ? _a : [] | ||
].flatMap((selections3) => [...selections3]) | ||
Promise.resolve().then(() => { | ||
var _a; | ||
const selections2 = new Set( | ||
[ | ||
...(_a = batching.getSelectionsSet(clientCache, selectionsCacheKey)) != null ? _a : [] | ||
].flatMap((selections3) => [...selections3]) | ||
); | ||
pendingQueries.delete(pendingSelections); | ||
batching.delSelectionsSet(clientCache, selectionsCacheKey); | ||
return resolveSelections.fetchSelections(selections2, { | ||
cache: context$1.cache, | ||
debugger: debug, | ||
extensions, | ||
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 } | ||
); | ||
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; | ||
}); | ||
@@ -106,2 +114,11 @@ }) | ||
} = {}) => { | ||
if (selections.size === 0) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.warn( | ||
"[GQty] No selections found. If you are reading from the global accessors, try using the first argument instead." | ||
); | ||
} | ||
return () => { | ||
}; | ||
} | ||
const unsubscibers = /* @__PURE__ */ new Set(); | ||
@@ -129,3 +146,5 @@ const unsubscribe = () => { | ||
} | ||
promises.push(resolve()); | ||
if (selections.size > 0) { | ||
promises.push(resolve()); | ||
} | ||
} | ||
@@ -139,3 +158,3 @@ for (const selection of subscriptionSelections) { | ||
subscriptionSelections, | ||
({ data, error, extensions }) => { | ||
({ data, error, extensions: extensions2 }) => { | ||
if (error) { | ||
@@ -146,3 +165,3 @@ onError == null ? void 0 : onError(error); | ||
updateCaches.updateCaches( | ||
[{ data, error, extensions }], | ||
[{ data, error, extensions: extensions2 }], | ||
cachePolicy !== "no-store" && context$1.cache !== clientCache ? [context$1.cache, clientCache] : [context$1.cache], | ||
@@ -156,2 +175,3 @@ { skipNotify: !context$1.notifyCacheUpdate } | ||
debugger: debug, | ||
extensions, | ||
fetchOptions: { | ||
@@ -158,0 +178,0 @@ ...fetchOptions, |
@@ -1,11 +0,12 @@ | ||
import type { ExecutionResult } from 'graphql'; | ||
import { CloseEvent } from 'ws'; | ||
import type { FetchOptions } from '.'; | ||
import type { Cache } from '../Cache'; | ||
import { type ExecutionResult } from 'graphql'; | ||
import { type CloseEvent } from 'ws'; | ||
import { type FetchOptions } from '.'; | ||
import { type Cache } from '../Cache'; | ||
import { GQtyError } from '../Error'; | ||
import type { Selection } from '../Selection'; | ||
import type { Debugger } from './debugger'; | ||
import { type Selection } from '../Selection'; | ||
import { type Debugger } from './debugger'; | ||
export type FetchSelectionsOptions = { | ||
cache?: Cache; | ||
debugger?: Debugger; | ||
extensions?: Record<string, unknown>; | ||
fetchOptions: FetchOptions; | ||
@@ -21,3 +22,3 @@ operationName?: string; | ||
}; | ||
export declare const fetchSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, { cache, debugger: debug, fetchOptions, operationName, }: FetchSelectionsOptions) => Promise<FetchResult<TData>[]>; | ||
export declare const fetchSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, { cache, debugger: debug, extensions: customExtensions, fetchOptions, operationName, }: FetchSelectionsOptions) => Promise<FetchResult<TData>[]>; | ||
export type SubscribeSelectionOptions = FetchSelectionsOptions & { | ||
@@ -29,3 +30,3 @@ onComplete?: () => void; | ||
export type Unsubscribe = () => void; | ||
export declare const subscribeSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, fn: SubscriptionCallback<TData>, { cache, debugger: debug, fetchOptions: { subscriber }, operationName, onSubscribe, onComplete, }: SubscribeSelectionOptions) => Unsubscribe; | ||
export declare const subscribeSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, fn: SubscriptionCallback<TData>, { cache, debugger: debug, extensions: customExtensions, fetchOptions: { subscriber }, operationName, onSubscribe, onComplete, }: SubscribeSelectionOptions) => Unsubscribe; | ||
export declare const isCloseEvent: (input: unknown) => input is CloseEvent; |
@@ -5,4 +5,2 @@ 'use strict'; | ||
const graphqlWs = require('graphql-ws'); | ||
const ws = require('ws'); | ||
const query = require('../Cache/query.js'); | ||
@@ -17,2 +15,3 @@ const index$1 = require('../Error/index.js'); | ||
debugger: debug, | ||
extensions: customExtensions, | ||
fetchOptions, | ||
@@ -36,3 +35,3 @@ operationName | ||
operationName: operationName2, | ||
extensions: { type, hash } | ||
extensions: { ...customExtensions, type, hash } | ||
}; | ||
@@ -65,2 +64,3 @@ const { data, errors, extensions } = await query.dedupePromise( | ||
debugger: debug, | ||
extensions: customExtensions, | ||
fetchOptions: { subscriber }, | ||
@@ -74,3 +74,3 @@ operationName, | ||
index.buildQuery(selections, operationName).map( | ||
({ | ||
async ({ | ||
query: query$1, | ||
@@ -92,3 +92,3 @@ variables, | ||
operationName: operationName2, | ||
extensions: { type, hash } | ||
extensions: { ...customExtensions, type, hash } | ||
}; | ||
@@ -100,3 +100,3 @@ let subscriptionId; | ||
switch (message.type) { | ||
case graphqlWs.MessageType.ConnectionAck: { | ||
case "connection_ack": { | ||
unsub == null ? void 0 : unsub(); | ||
@@ -113,6 +113,6 @@ onSubscribe == null ? void 0 : onSubscribe(); | ||
switch (message.type) { | ||
case graphqlWs.MessageType.ConnectionAck: { | ||
case "connection_ack": { | ||
break; | ||
} | ||
case graphqlWs.MessageType.Subscribe: { | ||
case "subscribe": { | ||
if (((_a = message.payload.extensions) == null ? void 0 : _a.hash) !== hash) | ||
@@ -294,4 +294,7 @@ return; | ||
const isCloseEvent = (input) => { | ||
var _a, _b; | ||
const error = input; | ||
return error.type === "close" && error.target instanceof ws.WebSocket || typeof error.code === "number" && [ | ||
if (!error || typeof error !== "object") | ||
return false; | ||
return error.type === "close" && ((_b = (_a = error.target) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "WebSocket" || typeof error.code === "number" && [ | ||
4004, | ||
@@ -298,0 +301,0 @@ 4005, |
@@ -5,2 +5,3 @@ 'use strict'; | ||
require('../Utils/hash.js'); | ||
const object = require('../Utils/object.js'); | ||
@@ -7,0 +8,0 @@ require('just-safe-set'); |
@@ -5,2 +5,3 @@ 'use strict'; | ||
require('../Utils/hash.js'); | ||
const object = require('../Utils/object.js'); | ||
@@ -7,0 +8,0 @@ require('just-safe-set'); |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const set = require('just-safe-set'); | ||
require('../Utils/hash.js'); | ||
const object = require('../Utils/object.js'); | ||
@@ -9,0 +10,0 @@ |
{ | ||
"name": "gqty", | ||
"version": "3.0.0-alpha-455c7aa1.0", | ||
"version": "3.0.0-alpha-4c58a180.0", | ||
"description": "gqty client without queries", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -6,3 +6,3 @@ 'use strict'; | ||
const set = require('just-safe-set'); | ||
const hash = require('object-hash'); | ||
const hash = require('../Utils/hash.js'); | ||
@@ -12,3 +12,2 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
const set__default = /*#__PURE__*/_interopDefault(set); | ||
const hash__default = /*#__PURE__*/_interopDefault(hash); | ||
@@ -42,5 +41,12 @@ const stringifySelectionTree = (tree) => Object.entries(tree).sort(([a], [b]) => a.localeCompare(b)).reduce((prev, [key, value]) => { | ||
const queryInputs = Object.entries(input.values).map(([key2, value]) => { | ||
const index = variables.size + 1; | ||
variables.set(`v${index}`, { value, type: input.types[key2] }); | ||
return `${key2}:$v${index}`; | ||
var _a; | ||
const variableName = hash.hash(((_a = s.alias) != null ? _a : s.key) + "_" + key2).slice( | ||
0, | ||
6 | ||
); | ||
variables.set(`${variableName}`, { | ||
value, | ||
type: input.types[key2] | ||
}); | ||
return `${key2}:$${variableName}`; | ||
}).join(" "); | ||
@@ -76,3 +82,3 @@ inputDedupe.set(input, `${key}(${queryInputs})`); | ||
rootKey, | ||
`${rootKey}(${[...variables.entries()].map(([, { type }], index) => `$v${index + 1}:${type}`).join("")})` | ||
`${rootKey}(${[...variables.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([name, { type }]) => `$${name}:${type}`).join("")})` | ||
); | ||
@@ -92,3 +98,3 @@ } | ||
type: rootKey, | ||
hash: hash__default["default"]({ query, variables }) | ||
hash: hash.hash({ query, variables }) | ||
// For query dedupe and cache keys | ||
@@ -95,0 +101,0 @@ } |
@@ -5,11 +5,5 @@ 'use strict'; | ||
const memoize = require('just-memoize'); | ||
const hash = require('object-hash'); | ||
const index = require('../Error/index.js'); | ||
const hash = require('../Utils/hash.js'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
const memoize__default = /*#__PURE__*/_interopDefault(memoize); | ||
const hash__default = /*#__PURE__*/_interopDefault(hash); | ||
const createSymbol = Symbol(); | ||
@@ -19,3 +13,3 @@ const aliasGenerator = { | ||
map: /* @__PURE__ */ new WeakMap(), | ||
hash: memoize__default["default"]((...args) => hash__default["default"](args).replace(/^\d+/, "")), | ||
hash: hash.hash, | ||
get(key, input) { | ||
@@ -22,0 +16,0 @@ var _a; |
@@ -1,4 +0,4 @@ | ||
export declare const isInteger: (v: any) => v is number; | ||
export declare function isEmptyObject(obj: object): boolean; | ||
export * from './hash'; | ||
export * from './object'; | ||
export * from './pick'; | ||
export declare const isInteger: (v: any) => v is number; |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const hash = require('./hash.js'); | ||
const object = require('./object.js'); | ||
@@ -10,9 +11,6 @@ const pick = require('./pick.js'); | ||
const isInteger = (v) => Number.isInteger(v); | ||
function isEmptyObject(obj) { | ||
for (var _i in obj) | ||
return false; | ||
return true; | ||
} | ||
exports.hash = hash.hash; | ||
exports.deepAssign = object.deepAssign; | ||
exports.isEmptyObject = object.isEmptyObject; | ||
exports.isObject = object.isObject; | ||
@@ -22,3 +20,2 @@ exports.isObjectWithType = object.isObjectWithType; | ||
exports.pick = pick.pick; | ||
exports.isEmptyObject = isEmptyObject; | ||
exports.isInteger = isInteger; |
export type PlainObject = Record<string | number | symbol, unknown>; | ||
export declare const isObject: (v: unknown) => v is object; | ||
export declare const isPlainObject: (v: unknown) => v is PlainObject; | ||
export declare function isEmptyObject(obj: object): boolean; | ||
export interface ObjectWithType<Typename extends string = string> extends Record<string, unknown> { | ||
@@ -5,0 +6,0 @@ __typename: Typename; |
@@ -7,2 +7,7 @@ 'use strict'; | ||
const isPlainObject = (v) => isObject(v) && !Array.isArray(v); | ||
function isEmptyObject(obj) { | ||
for (var _i in obj) | ||
return false; | ||
return true; | ||
} | ||
const isObjectWithType = (v) => isPlainObject(v) && typeof v.__typename === "string"; | ||
@@ -37,4 +42,5 @@ function deepAssign(target, sources, onConflict) { | ||
exports.deepAssign = deepAssign; | ||
exports.isEmptyObject = isEmptyObject; | ||
exports.isObject = isObject; | ||
exports.isObjectWithType = isObjectWithType; | ||
exports.isPlainObject = isPlainObject; |
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
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
275526
165
7923
18