@nano_kit/query 1.0.0-alpha.1 → 1.0.0-alpha.10
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/CacheStorage.d.ts +2 -2
- package/dist/CacheStorage.d.ts.map +1 -1
- package/dist/CacheStorage.types.d.ts +5 -0
- package/dist/CacheStorage.types.d.ts.map +1 -1
- package/dist/ClientContext.d.ts +7 -5
- package/dist/ClientContext.d.ts.map +1 -1
- package/dist/RequestContext.d.ts.map +1 -1
- package/dist/cache.d.ts +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.types.d.ts.map +1 -1
- package/dist/client.d.ts +7 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.mock.d.ts.map +1 -1
- package/dist/client.types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +929 -840
- package/dist/index.js.map +1 -1
- package/dist/map.d.ts +5 -0
- package/dist/map.d.ts.map +1 -1
- package/dist/queries/base.d.ts +9 -9
- package/dist/queries/base.d.ts.map +1 -1
- package/dist/queries/index.d.ts.map +1 -1
- package/dist/queries/infinite.d.ts.map +1 -1
- package/dist/queries/mutation.d.ts.map +1 -1
- package/dist/queries/operation.d.ts.map +1 -1
- package/dist/queries/query.d.ts.map +1 -1
- package/dist/settings/abortable.d.ts.map +1 -1
- package/dist/settings/codec.d.ts +16 -0
- package/dist/settings/codec.d.ts.map +1 -0
- package/dist/settings/entities.d.ts.map +1 -1
- package/dist/settings/hydratable.d.ts +11 -0
- package/dist/settings/hydratable.d.ts.map +1 -0
- package/dist/settings/index.d.ts +5 -3
- package/dist/settings/index.d.ts.map +1 -1
- package/dist/settings/indexedDbStorage.d.ts +5 -7
- package/dist/settings/indexedDbStorage.d.ts.map +1 -1
- package/dist/settings/persistence.d.ts +16 -0
- package/dist/settings/persistence.d.ts.map +1 -0
- package/dist/settings/retryOnError.d.ts.map +1 -1
- package/dist/settings/revalidateOn.d.ts +9 -0
- package/dist/settings/revalidateOn.d.ts.map +1 -0
- package/dist/settings/ssr.d.ts +9 -0
- package/dist/settings/ssr.d.ts.map +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/settings/revalidateOnFocus.d.ts +0 -12
- package/dist/settings/revalidateOnFocus.d.ts.map +0 -1
- package/dist/settings/revalidateOnInterval.d.ts +0 -9
- package/dist/settings/revalidateOnInterval.d.ts.map +0 -1
- package/dist/settings/revalidateOnReconnect.d.ts +0 -12
- package/dist/settings/revalidateOnReconnect.d.ts.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AnyCodec } from '@nano_kit/store';
|
|
2
|
+
import type { ClientSetting } from '../client.types.js';
|
|
3
|
+
import type { CacheEntry, EncodedCacheEntry } from '../CacheStorage.types.js';
|
|
4
|
+
export declare function encodeEntryData<T extends CacheEntry | EncodedCacheEntry>(entry: T, codec: AnyCodec): T;
|
|
5
|
+
export declare function decodeEntryData<T extends CacheEntry | EncodedCacheEntry>(entry: T, codec: AnyCodec): T;
|
|
6
|
+
export declare function encodeEntryDetails(entry: CacheEntry): EncodedCacheEntry;
|
|
7
|
+
export declare function decodeEntryDetails(entry: EncodedCacheEntry): CacheEntry;
|
|
8
|
+
export declare function encodeEntry(entry: CacheEntry, codec: AnyCodec): EncodedCacheEntry;
|
|
9
|
+
export declare function decodeEntry(entry: EncodedCacheEntry, codec: AnyCodec): CacheEntry;
|
|
10
|
+
/**
|
|
11
|
+
* Set cache entry data codec for query client.
|
|
12
|
+
* @param codec - Codec used to encode and decode cached data.
|
|
13
|
+
* @returns The client setting function.
|
|
14
|
+
*/
|
|
15
|
+
export declare function codec(codec: AnyCodec): ClientSetting;
|
|
16
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/settings/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAEd,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EAClB,MAAM,0BAA0B,CAAA;AAgBjC,wBAAgB,eAAe,CAAC,CAAC,SAAS,UAAU,GAAG,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAC/C,CAAC,CACpD;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,UAAU,GAAG,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAC/C,CAAC,CACpD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GACN,iBAAiB,CAC9D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GACb,UAAU,CACvD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GACZ,iBAAiB,CAClE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,QAAQ,GACnB,UAAU,CAC3D;AAED;;;;GAIG;AAEH,wBAAgB,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,aAAa,CAIpD","sourcesContent":["import {\n type AnyCodec,\n identity\n} from '@nano_kit/store'\nimport type { ClientSetting } from '../client.types.js'\nimport type {\n CacheEntry,\n EncodedCacheEntry\n} from '../CacheStorage.types.js'\n\nfunction mapEntry(\n entry: CacheEntry | EncodedCacheEntry,\n mapDetail: (data: number | string) => number | string,\n mapData: (data: unknown) => unknown\n) {\n return {\n ...entry,\n data: mapData(entry.data),\n rev: mapDetail(entry.rev),\n dedupes: mapDetail(entry.dedupes),\n expires: mapDetail(entry.expires)\n }\n}\n\nexport function encodeEntryData<T extends CacheEntry | EncodedCacheEntry>(entry: T, codec: AnyCodec) {\n return mapEntry(entry, identity, codec.encode) as T\n}\n\nexport function decodeEntryData<T extends CacheEntry | EncodedCacheEntry>(entry: T, codec: AnyCodec) {\n return mapEntry(entry, identity, codec.decode) as T\n}\n\nexport function encodeEntryDetails(entry: CacheEntry) {\n return mapEntry(entry, String, identity) as EncodedCacheEntry\n}\n\nexport function decodeEntryDetails(entry: EncodedCacheEntry) {\n return mapEntry(entry, Number, identity) as CacheEntry\n}\n\nexport function encodeEntry(entry: CacheEntry, codec: AnyCodec) {\n return mapEntry(entry, String, codec.encode) as EncodedCacheEntry\n}\n\nexport function decodeEntry(entry: EncodedCacheEntry, codec: AnyCodec) {\n return mapEntry(entry, Number, codec.decode) as CacheEntry\n}\n\n/**\n * Set cache entry data codec for query client.\n * @param codec - Codec used to encode and decode cached data.\n * @returns The client setting function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function codec(codec: AnyCodec): ClientSetting {\n return (ctx) => {\n ctx.codec = codec\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/settings/entities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,qBAAqB,CAAA;AAG5B,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,EAAE;IAClC;;OAEG;IACH,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;IAChE;;OAEG;IACH,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;CACf;AAqBD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACtD,IAAI,EAAE,MAAM,GACX,MAAM,CAAC,CAAC,CAAC,CAAA;AAEZ;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,EAAE,EACjC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GACjC,MAAM,CAAC,CAAC,CAAC,CAAA;AAkCZ;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC7E,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC7E,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/settings/entities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,qBAAqB,CAAA;AAG5B,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,EAAE;IAClC;;OAEG;IACH,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;IAChE;;OAEG;IACH,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;CACf;AAqBD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACtD,IAAI,EAAE,MAAM,GACX,MAAM,CAAC,CAAC,CAAC,CAAA;AAEZ;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,EAAE,EACjC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GACjC,MAAM,CAAC,CAAC,CAAC,CAAA;AAkCZ;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC7E,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC7E,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAA","sourcesContent":["import type { PickNonEmptyValue } from '@nano_kit/store'\nimport type { ClientSetting } from '../client.types.js'\nimport type { CacheKey } from '../CacheStorage.types.js'\nimport type {\n ClientContext,\n MutationClientContext,\n QueryClientContext\n} from '../ClientContext.js'\nimport { queryKey } from '../cache.js'\n\nexport interface Entity<T extends {}> {\n /**\n * Get the cache key for the entity by its identifier.\n */\n (id: number | string): CacheKey<[id: number | string], T | null>\n /**\n * Get or upsert the entity in the cache.\n */\n (entity: T): T\n}\n\nconst ENTITY_KEY = '#entity'\nconst EntityKey = queryKey(ENTITY_KEY)\n\ninterface EntityRef {\n [ENTITY_KEY]: CacheKey\n}\n\nfunction isIdentifier(value: unknown): value is number | string {\n const type = typeof value\n\n return type === 'number' || type === 'string'\n}\n\nfunction isEntityRef<T extends {}>(value: T): value is T & EntityRef {\n return ENTITY_KEY in value\n}\n\nlet currentCtx: ClientContext | null = null\n\n/**\n * Create an entity manager for a specific entity type.\n * @param name - The name of the entity type.\n * @returns The entity manager.\n */\nexport function entity<T extends { id: number | string }>(\n name: string\n): Entity<T>\n\n/**\n * Create an entity manager for a specific entity type.\n * @param name - The name of the entity type.\n * @param id - A function to extract the identifier from the entity.\n * @returns The entity manager.\n */\nexport function entity<T extends {}>(\n name: string,\n id: (entity: T) => number | string\n): Entity<T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function entity<T extends { id: number | string }>(\n name: string,\n id = (entity: T) => entity.id\n) {\n return (idOrRefOrEntity: number | string | null | undefined | T) => {\n if (isIdentifier(idOrRefOrEntity)) {\n return EntityKey(name, idOrRefOrEntity)\n }\n\n if (!idOrRefOrEntity || !currentCtx) {\n return idOrRefOrEntity\n }\n\n if (isEntityRef(idOrRefOrEntity)) {\n return currentCtx.$get(idOrRefOrEntity[ENTITY_KEY]).data\n }\n\n const key = EntityKey(name, id(idOrRefOrEntity))\n\n currentCtx.set(key, {\n ...currentCtx.initial(),\n data: idOrRefOrEntity\n })\n\n return {\n ...idOrRefOrEntity,\n [ENTITY_KEY]: key\n }\n }\n}\n\n/**\n * Map entities from the fetched data.\n * @param mapper - A function to map entities from the fetched data.\n * @returns The client setting function.\n */\nexport function entities<T>(\n mapper: (data: NoInfer<PickNonEmptyValue<T>>) => NoInfer<PickNonEmptyValue<T>>\n): ClientSetting<QueryClientContext<T>>\n\n/**\n * Map entities from the fetched data.\n * @param mapper - A function to map entities from the fetched data.\n * @returns The client setting function.\n */\nexport function entities<T>(\n mapper: (data: NoInfer<PickNonEmptyValue<T>>) => NoInfer<PickNonEmptyValue<T>>\n): ClientSetting<MutationClientContext<T>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function entities(mapper: (data: unknown) => unknown) {\n return (ctx: ClientContext) => {\n const safeMapper = (data: unknown) => {\n if (data) {\n try {\n currentCtx = ctx\n\n return mapper(data)\n } finally {\n currentCtx = null\n }\n }\n\n return data\n }\n\n ctx.mapComputedData = ctx.mapData = safeMapper\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AnyAccessor, type Hydrator } from '@nano_kit/store';
|
|
2
|
+
import type { ClientSetting } from '../client.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Make client cache hydratable.
|
|
5
|
+
* Without arguments, it will try to resolve {@link Hydrator$} and {@link Hydratables$} from the injection context.
|
|
6
|
+
* @param hydrator - Optional hydrator to use for rehydrating the cache. Pass `null` to skip hydration and only register for dehydration.
|
|
7
|
+
* @param hydratables - Optional map to register the cache collector for dehydration.
|
|
8
|
+
* @returns The client setting function.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hydratable(hydrator?: Hydrator | null, hydratables?: Map<string, AnyAccessor> | null): ClientSetting;
|
|
11
|
+
//# sourceMappingURL=hydratable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydratable.d.ts","sourceRoot":"","sources":["../../src/settings/hydratable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,QAAQ,EAId,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAiDvD;;;;;;GAMG;AAEH,wBAAgB,UAAU,CACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,EAC1B,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,GAC5C,aAAa,CAsBf","sourcesContent":["import {\n type AnyAccessor,\n type Hydrator,\n Hydrator$,\n Hydratables$,\n inject\n} from '@nano_kit/store'\nimport type { ClientSetting } from '../client.types.js'\nimport type { ClientContext } from '../ClientContext.js'\nimport type { EncodedCacheEntry } from '../CacheStorage.types.js'\nimport { setShardedMapKey } from '../map.js'\nimport {\n encodeEntry,\n decodeEntry\n} from './codec.js'\n\ninterface HydratableContext extends ClientContext {\n hydratable?: boolean\n}\n\ntype EncodedShardedMap = [string, string, EncodedCacheEntry][]\n\nconst id = '@nano_kit/query'\n\nfunction encode({\n cache,\n codec\n}: HydratableContext) {\n const encoded: EncodedShardedMap = []\n\n cache.forEach((shard, shardKey) => {\n shard.forEach(($signal, key) => {\n const value = $signal?.()\n\n if (value !== undefined) {\n encoded.push([shardKey, key, encodeEntry(value, codec)])\n }\n })\n })\n\n return encoded\n}\n\nfunction decode(\n {\n cache,\n codec\n }: HydratableContext,\n encoded: EncodedShardedMap\n) {\n encoded.forEach(([shard, key, value]) => setShardedMapKey(cache, {\n shard,\n key\n }, decodeEntry(value, codec)))\n}\n\n/**\n * Make client cache hydratable.\n * Without arguments, it will try to resolve {@link Hydrator$} and {@link Hydratables$} from the injection context.\n * @param hydrator - Optional hydrator to use for rehydrating the cache. Pass `null` to skip hydration and only register for dehydration.\n * @param hydratables - Optional map to register the cache collector for dehydration.\n * @returns The client setting function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function hydratable(\n hydrator?: Hydrator | null,\n hydratables?: Map<string, AnyAccessor> | null\n): ClientSetting {\n return (ctx: HydratableContext) => {\n if (!ctx.hydratable) {\n const finalHydrator = hydrator === undefined\n ? inject(Hydrator$)\n : hydrator\n\n if (finalHydrator) {\n finalHydrator.pull(id, value => decode(ctx, value as EncodedShardedMap))\n } else {\n const finalHydratables = hydratables === undefined\n ? inject(Hydratables$)\n : hydratables\n\n if (finalHydratables) {\n finalHydratables.set(id, () => encode(ctx))\n }\n }\n }\n\n ctx.hydratable = true\n }\n}\n"]}
|
package/dist/settings/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './abortable.js';
|
|
2
2
|
export * from './entities.js';
|
|
3
|
+
export * from './persistence.js';
|
|
3
4
|
export { indexedDbStorage } from './indexedDbStorage.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './revalidateOnInterval.js';
|
|
6
|
-
export * from './revalidateOnReconnect.js';
|
|
5
|
+
export * from './revalidateOn.js';
|
|
7
6
|
export * from './retryOnError.js';
|
|
7
|
+
export * from './codec.js';
|
|
8
|
+
export * from './hydratable.js';
|
|
9
|
+
export * from './ssr.js';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA","sourcesContent":["export * from './abortable.js'\nexport * from './entities.js'\nexport * from './persistence.js'\nexport { indexedDbStorage } from './indexedDbStorage.js'\nexport * from './revalidateOn.js'\nexport * from './retryOnError.js'\nexport * from './codec.js'\nexport * from './hydratable.js'\nexport * from './ssr.js'\n"]}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import type { ClientSetting } from '../client.types.js';
|
|
2
1
|
import type { CacheKey, CacheShardKey, CacheEntry } from '../CacheStorage.types.js';
|
|
3
|
-
import type {
|
|
2
|
+
import type { Storage } from './persistence.js';
|
|
4
3
|
export declare const DB_NAME = "nano_kit";
|
|
5
4
|
export declare const STORE_NAME = "query";
|
|
6
5
|
export declare const DB_VERSION = 1;
|
|
7
6
|
export declare function connect(): Promise<IDBDatabase | null>;
|
|
8
7
|
export declare function SELECT(connection: Promise<IDBDatabase | null>, key: CacheKey): Promise<CacheEntry | null>;
|
|
9
8
|
export declare function SET(connection: Promise<IDBDatabase | null>, cacheKey: CacheKey, entry: CacheEntry, lifetime: number): Promise<void>;
|
|
10
|
-
export declare function DELETE(connection: Promise<IDBDatabase | null>, cacheKey
|
|
9
|
+
export declare function DELETE(connection: Promise<IDBDatabase | null>, cacheKey?: CacheShardKey | CacheKey): Promise<void>;
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @returns The client setting function.
|
|
11
|
+
* IndexedDB adapter for persistent storage.
|
|
12
|
+
* @returns IndexedDB storage implementation or null if IndexedDB is not supported.
|
|
15
13
|
*/
|
|
16
|
-
export declare function indexedDbStorage(
|
|
14
|
+
export declare function indexedDbStorage(): Storage | null;
|
|
17
15
|
//# sourceMappingURL=indexedDbStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexedDbStorage.d.ts","sourceRoot":"","sources":["../../src/settings/indexedDbStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"indexedDbStorage.d.ts","sourceRoot":"","sources":["../../src/settings/indexedDbStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,UAAU,EACX,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE/C,eAAO,MAAM,OAAO,aAAa,CAAA;AACjC,eAAO,MAAM,UAAU,UAAU,CAAA;AACjC,eAAO,MAAM,UAAU,IAAI,CAAA;AAS3B,wBAAgB,OAAO,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAsBrD;AAED,wBAAsB,MAAM,CAC1B,UAAU,EAAE,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvC,GAAG,EAAE,QAAQ,GACZ,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAiC5B;AAED,wBAAsB,GAAG,CACvB,UAAU,EAAE,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED,wBAAsB,MAAM,CAC1B,UAAU,EAAE,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvC,QAAQ,CAAC,EAAE,aAAa,GAAG,QAAQ,GAClC,OAAO,CAAC,IAAI,CAAC,CA+Cf;AAED;;;GAGG;AAEH,wBAAgB,gBAAgB,IAAI,OAAO,GAAG,IAAI,CAkBjD","sourcesContent":["import type {\n CacheKey,\n CacheShardKey,\n CacheEntry\n} from '../CacheStorage.types.js'\nimport type { Storage } from './persistence.js'\n\nexport const DB_NAME = 'nano_kit'\nexport const STORE_NAME = 'query'\nexport const DB_VERSION = 1\n\ninterface StoredEntry {\n shard: string\n key: string\n data: CacheEntry\n expires: number\n}\n\nexport function connect(): Promise<IDBDatabase | null> {\n return new Promise((resolve) => {\n const request = indexedDB.open(DB_NAME, DB_VERSION)\n\n request.onerror = () => resolve(null)\n\n request.onsuccess = () => resolve(request.result)\n\n request.onupgradeneeded = () => {\n const db = request.result\n\n if (!db.objectStoreNames.contains(STORE_NAME)) {\n const store = db.createObjectStore(STORE_NAME, {\n keyPath: ['shard', 'key']\n })\n\n store.createIndex('shard', 'shard', {\n unique: false\n })\n }\n }\n })\n}\n\nexport async function SELECT(\n connection: Promise<IDBDatabase | null>,\n key: CacheKey\n): Promise<CacheEntry | null> {\n const db = await connection\n\n if (!db) {\n return null\n }\n\n return new Promise((resolve) => {\n const transaction = db.transaction(STORE_NAME, 'readonly')\n const store = transaction.objectStore(STORE_NAME)\n const request = store.get([key.shard, key.key])\n\n request.onerror = () => resolve(null)\n\n request.onsuccess = () => {\n const result = request.result as StoredEntry | undefined\n\n if (!result) {\n resolve(null)\n return\n }\n\n const now = Date.now()\n\n if (result.expires < now || result.data.expires < now) {\n void DELETE(connection, key)\n resolve(null)\n return\n }\n\n resolve(result.data)\n }\n })\n}\n\nexport async function SET(\n connection: Promise<IDBDatabase | null>,\n cacheKey: CacheKey,\n entry: CacheEntry,\n lifetime: number\n): Promise<void> {\n const db = await connection\n\n if (!db) {\n return\n }\n\n return new Promise((resolve) => {\n const {\n shard,\n key\n } = cacheKey\n const transaction = db.transaction(STORE_NAME, 'readwrite')\n const store = transaction.objectStore(STORE_NAME)\n const storedEntry: StoredEntry = {\n shard,\n key,\n data: entry,\n expires: Date.now() + lifetime\n }\n const request = store.put(storedEntry)\n\n request.onerror = () => resolve()\n request.onsuccess = () => resolve()\n })\n}\n\nexport async function DELETE(\n connection: Promise<IDBDatabase | null>,\n cacheKey?: CacheShardKey | CacheKey\n): Promise<void> {\n const db = await connection\n\n if (!db) {\n return\n }\n\n return new Promise((resolve) => {\n const transaction = db.transaction(STORE_NAME, 'readwrite')\n const store = transaction.objectStore(STORE_NAME)\n\n if (!cacheKey) {\n const request = store.clear()\n\n request.onerror = () => resolve()\n request.onsuccess = () => resolve()\n } else {\n const {\n shard,\n key\n } = cacheKey\n\n if (key === undefined) {\n const index = store.index('shard')\n const range = IDBKeyRange.only(shard)\n const request = index.openCursor(range)\n\n request.onerror = () => resolve()\n\n request.onsuccess = () => {\n const cursor = request.result\n\n if (cursor) {\n cursor.delete()\n cursor.continue()\n } else {\n resolve()\n }\n }\n } else {\n const request = store.delete([shard, key])\n\n request.onerror = () => resolve()\n request.onsuccess = () => resolve()\n }\n }\n })\n}\n\n/**\n * IndexedDB adapter for persistent storage.\n * @returns IndexedDB storage implementation or null if IndexedDB is not supported.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function indexedDbStorage(): Storage | null {\n if (typeof indexedDB === 'undefined') {\n return null\n }\n\n const db = connect()\n\n return {\n get(key: CacheKey) {\n return SELECT(db, key)\n },\n set(cacheKey: CacheKey, entry: CacheEntry, lifetime: number) {\n return SET(db, cacheKey, entry, lifetime)\n },\n delete(cacheKey?: CacheShardKey | CacheKey) {\n return DELETE(db, cacheKey)\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ClientSetting } from '../client.types.js';
|
|
2
|
+
import type { CacheKey, CacheShardKey, CacheEntry } from '../CacheStorage.types.js';
|
|
3
|
+
import type { QueryClientContext } from '../ClientContext.js';
|
|
4
|
+
export interface Storage {
|
|
5
|
+
get(key: CacheKey): Promise<CacheEntry | null>;
|
|
6
|
+
set(key: CacheKey, entry: CacheEntry, lifetime: number): Promise<void>;
|
|
7
|
+
delete(key?: CacheShardKey | CacheKey): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generic persistent storage client setting.
|
|
11
|
+
* @param storage - The storage implementation to use for persistence.
|
|
12
|
+
* @param lifetime - How long to keep entries in storage in milliseconds.
|
|
13
|
+
* @returns The client setting function.
|
|
14
|
+
*/
|
|
15
|
+
export declare function persistence(storage: Storage | null, lifetime: number): ClientSetting<QueryClientContext>;
|
|
16
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/settings/persistence.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,UAAU,EACX,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAgB7D,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;IAC9C,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtE,MAAM,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACtD;AAED;;;;;GAKG;AAEH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAmFxG","sourcesContent":["import { untracked } from '@nano_kit/store'\nimport type { ClientSetting } from '../client.types.js'\nimport type {\n CacheKey,\n CacheShardKey,\n CacheEntry\n} from '../CacheStorage.types.js'\nimport type { QueryClientContext } from '../ClientContext.js'\nimport {\n UNSET_REV,\n revLock,\n revLocked\n} from '../CacheStorage.js'\nimport { hasShardedMapKey } from '../map.js'\nimport {\n encodeEntryData,\n decodeEntryData\n} from './codec.js'\n\ninterface PersistenceContext extends QueryClientContext {\n persistenceLifetime?: number\n}\n\nexport interface Storage {\n get(key: CacheKey): Promise<CacheEntry | null>\n set(key: CacheKey, entry: CacheEntry, lifetime: number): Promise<void>\n delete(key?: CacheShardKey | CacheKey): Promise<void>\n}\n\n/**\n * Generic persistent storage client setting.\n * @param storage - The storage implementation to use for persistence.\n * @param lifetime - How long to keep entries in storage in milliseconds.\n * @returns The client setting function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function persistence(storage: Storage | null, lifetime: number): ClientSetting<QueryClientContext> {\n return (ctx: PersistenceContext) => {\n if (!storage) {\n return\n }\n\n if (ctx.persistenceLifetime === undefined) {\n const superGet = ctx.$get\n const superSet = ctx.set\n const superInvalidate = ctx.invalidate\n\n ctx.$get = function (key) {\n const cache = this.cache\n const hasKey = hasShardedMapKey(cache, key)\n const entry = superGet.call(this, key)\n\n if (hasKey) {\n return entry\n }\n\n superSet.call(this, key, {\n ...entry,\n rev: revLock(entry.rev)\n })\n\n void this.task(storage.get(key).then(storedEntry => superSet.call(this, key, {\n ...entry,\n ...storedEntry && decodeEntryData(storedEntry, this.codec),\n rev: UNSET_REV\n })))\n\n return superGet.call(this, key)\n }\n\n function saveSingleEntry(\n this: PersistenceContext,\n key: CacheKey\n ) {\n const entry = untracked(superGet.bind(this, key))\n\n if (entry && !entry.loading && !entry.error && !revLocked(entry.rev)) {\n void this.task(\n storage!.set(\n key,\n encodeEntryData(entry, this.codec),\n this.persistenceLifetime!\n )\n )\n }\n }\n\n ctx.set = function (cacheKey, entry) {\n superSet.call(this, cacheKey, entry)\n\n const {\n shard,\n key\n } = cacheKey\n\n if (key !== undefined) {\n saveSingleEntry.call(this, cacheKey)\n } else {\n const shardMap = this.cache.get(shard)\n\n if (shardMap) {\n for (const key of shardMap.keys()) {\n saveSingleEntry.call(this, {\n shard,\n key\n } as CacheKey)\n }\n }\n }\n }\n\n ctx.invalidate = function (key) {\n superInvalidate.call(this, key)\n void this.task(storage.delete(key))\n }\n }\n\n ctx.persistenceLifetime = lifetime\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnError.d.ts","sourceRoot":"","sources":["../../src/settings/retryOnError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAG7D,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;AAS3E,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,UAKvD;AAcD;;;;GAIG;AAEH,wBAAgB,YAAY,CAC1B,cAAc,GAAE,cAAsC,GACrD,aAAa,CAAC,kBAAkB,CAAC,CA4CnC"}
|
|
1
|
+
{"version":3,"file":"retryOnError.d.ts","sourceRoot":"","sources":["../../src/settings/retryOnError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAG7D,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;AAS3E,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,UAKvD;AAcD;;;;GAIG;AAEH,wBAAgB,YAAY,CAC1B,cAAc,GAAE,cAAsC,GACrD,aAAa,CAAC,kBAAkB,CAAC,CA4CnC","sourcesContent":["import type { ClientSetting } from '../client.types.js'\nimport type { CacheKey } from '../CacheStorage.types.js'\nimport type { QueryClientContext } from '../ClientContext.js'\nimport type { QueryContext } from '../RequestContext.js'\n\nexport type CalcRetryDelay = (retryCount: number, error: unknown) => number\n\ninterface RetryContext extends QueryClientContext {\n retryCounts?: Map<string, number>\n retryTimeoutId?: ReturnType<typeof setTimeout>\n calcRetryDelay?: CalcRetryDelay\n}\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function defaultCalcRetryDelay(retryCount: number) {\n return (\n // oxlint-disable-next-line eslint/no-magic-numbers\n ~~((Math.random() + 0.5) * (1 << (retryCount < 8 ? retryCount : 8))) * 2000\n )\n}\n\nfunction getRetryCount(ctx: RetryContext, key: CacheKey) {\n return ctx.retryCounts?.get(key.key) || 0\n}\n\nfunction setRetryCount(ctx: RetryContext, key: CacheKey, count: number) {\n (ctx.retryCounts ??= new Map()).set(key.key, count)\n}\n\nfunction clearRetryCount(ctx: RetryContext, key: CacheKey) {\n ctx.retryCounts?.delete(key.key)\n}\n\n/**\n * Retry the query on error with exponential backoff.\n * @param calcRetryDelay - Function to calculate the delay before retrying.\n * @returns The client setting function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function retryOnError(\n calcRetryDelay: CalcRetryDelay = defaultCalcRetryDelay\n): ClientSetting<QueryClientContext> {\n return (ctx: RetryContext) => {\n if (ctx.calcRetryDelay === undefined) {\n const superRun = ctx.run\n\n ctx.run = function (\n this: RetryContext,\n queryCtx: QueryContext<unknown[], unknown>,\n start,\n onSettled: (data: unknown, error: string | null) => void,\n interrupt\n ) {\n clearTimeout(this.retryTimeoutId)\n\n const promise = superRun.call(this, queryCtx, start, onSettled, interrupt)\n\n if (!('shard' in queryCtx)) {\n return promise\n }\n\n void this.task(promise.then(\n (result) => {\n const error = result?.[1]\n\n if (!error) {\n clearRetryCount(this, queryCtx)\n } else {\n const retryCount = getRetryCount(this, queryCtx) + 1\n const delay = this.calcRetryDelay!(retryCount, error)\n\n this.retryTimeoutId = setTimeout(() => {\n this.invalidate(queryCtx)\n setRetryCount(this, queryCtx, retryCount)\n }, delay)\n }\n }\n ))\n\n return promise\n } as typeof superRun\n }\n\n ctx.calcRetryDelay = calcRetryDelay\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AnyAccessor } from '@nano_kit/store';
|
|
2
|
+
import type { ClientSetting } from '../client.types.js';
|
|
3
|
+
import type { QueryClientContext } from '../ClientContext.js';
|
|
4
|
+
/**
|
|
5
|
+
* Revalidate the query when the reactive condition becomes true.
|
|
6
|
+
* @returns The client setting function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function revalidateOn(...conditions: AnyAccessor[]): ClientSetting<QueryClientContext>;
|
|
9
|
+
//# sourceMappingURL=revalidateOn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidateOn.d.ts","sourceRoot":"","sources":["../../src/settings/revalidateOn.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAEjB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAO7D;;;GAGG;AAEH,wBAAgB,YAAY,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAoB5F","sourcesContent":["import {\n type AnyAccessor,\n listen\n} from '@nano_kit/store'\nimport type { ClientSetting } from '../client.types.js'\nimport type { QueryClientContext } from '../ClientContext.js'\nimport { addFn } from '../utils.js'\n\ninterface RevalidateOnContext extends QueryClientContext {\n revalidateOn?: Set<AnyAccessor>\n}\n\n/**\n * Revalidate the query when the reactive condition becomes true.\n * @returns The client setting function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function revalidateOn(...conditions: AnyAccessor[]): ClientSetting<QueryClientContext> {\n return (ctx: RevalidateOnContext) => {\n if (ctx.revalidateOn === undefined) {\n ctx.revalidateOn = new Set()\n }\n\n conditions.forEach(($condition) => {\n if (!ctx.revalidateOn!.has($condition)) {\n ctx.mounted = addFn(ctx.mounted, function (this: RevalidateOnContext) {\n listen($condition, (visible) => {\n if (visible) {\n this.revalidate(this.$key())\n }\n })\n })\n\n ctx.revalidateOn!.add($condition)\n }\n })\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ClientSetting } from '../client.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Client setting for enabling SSR support.
|
|
4
|
+
* It combines tasks management and cache hydration to ensure that queries can be executed on the server and their results can be sent to the client for hydration.
|
|
5
|
+
* Should be called inside injection context.
|
|
6
|
+
* @returns The client setting function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ssr(): ClientSetting;
|
|
9
|
+
//# sourceMappingURL=ssr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../../src/settings/ssr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAIvD;;;;;GAKG;AACH,wBAAgB,GAAG,IAAI,aAAa,CAQnC","sourcesContent":["import type { ClientSetting } from '../client.types.js'\nimport { tasks } from '../ClientContext.js'\nimport { hydratable } from './hydratable.js'\n\n/**\n * Client setting for enabling SSR support.\n * It combines tasks management and cache hydration to ensure that queries can be executed on the server and their results can be sent to the client for hydration.\n * Should be called inside injection context.\n * @returns The client setting function.\n */\nexport function ssr(): ClientSetting {\n const tasksSetting = tasks()\n const hydratableSetting = hydratable()\n\n return (ctx) => {\n tasksSetting(ctx)\n hydratableSetting(ctx)\n }\n}\n"]}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,KAAK,CAEnB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAClC,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CASjC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC,cAMvD"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,KAAK,CAEnB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAClC,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CASjC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC,cAMvD","sourcesContent":["/* @__NO_SIDE_EFFECTS__ */\nexport function addFn<\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends (...args: any[]) => void\n>(prevFn: T | undefined, fn: T): T {\n if (prevFn === undefined) {\n return fn\n }\n\n return function (this: unknown, ...args: Parameters<T>) {\n prevFn.apply(this, args)\n fn.apply(this, args)\n } as T\n}\n\nexport function settle<T, R>(\n promise: Promise<T>,\n onSettled: (data: T | undefined, error?: unknown) => R\n) {\n return promise.then(\n onSettled,\n error => onSettled(undefined, error)\n )\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nano_kit/query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
5
|
-
"description": "A small and powerful remote data
|
|
4
|
+
"version": "1.0.0-alpha.10",
|
|
5
|
+
"description": "A small and powerful remote data management library for @nano_kit/store.",
|
|
6
6
|
"author": "dangreen",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://nano-kit.js.org/query",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"nano_kit"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=20"
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"exports": {
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@nano_kit/store": "^1.0.0-
|
|
43
|
+
"@nano_kit/store": "^1.0.0-beta.8"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ClientSetting } from '../client.types.js';
|
|
2
|
-
import type { QueryClientContext } from '../ClientContext.js';
|
|
3
|
-
/**
|
|
4
|
-
* @todo Move to common extras package
|
|
5
|
-
*/
|
|
6
|
-
export declare const $windowVisible: import("@nano_kit/store").WritableSignal<boolean>;
|
|
7
|
-
/**
|
|
8
|
-
* Revalidate the query when the window gains focus.
|
|
9
|
-
* @returns The client setting function.
|
|
10
|
-
*/
|
|
11
|
-
export declare function revalidateOnFocus(): ClientSetting<QueryClientContext>;
|
|
12
|
-
//# sourceMappingURL=revalidateOnFocus.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"revalidateOnFocus.d.ts","sourceRoot":"","sources":["../../src/settings/revalidateOnFocus.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAO7D;;GAEG;AACH,eAAO,MAAM,cAAc,mDAiBzB,CAAA;AAEF;;;GAGG;AAEH,wBAAgB,iBAAiB,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAcrE"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ClientSetting } from '../client.types.js';
|
|
2
|
-
import type { QueryClientContext } from '../ClientContext.js';
|
|
3
|
-
/**
|
|
4
|
-
* Revalidate the query on a specified interval.
|
|
5
|
-
* @param interval - The interval in milliseconds.
|
|
6
|
-
* @returns The client setting function.
|
|
7
|
-
*/
|
|
8
|
-
export declare function revalidateOnInterval(interval: number): ClientSetting<QueryClientContext>;
|
|
9
|
-
//# sourceMappingURL=revalidateOnInterval.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"revalidateOnInterval.d.ts","sourceRoot":"","sources":["../../src/settings/revalidateOnInterval.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAO7D;;;;GAIG;AAEH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAgBxF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ClientSetting } from '../client.types.js';
|
|
2
|
-
import type { QueryClientContext } from '../ClientContext.js';
|
|
3
|
-
/**
|
|
4
|
-
* @todo Move to common extras package
|
|
5
|
-
*/
|
|
6
|
-
export declare const $networkOnline: import("@nano_kit/store").WritableSignal<boolean>;
|
|
7
|
-
/**
|
|
8
|
-
* Revalidate the query when the network reconnects.
|
|
9
|
-
* @returns The client setting function.
|
|
10
|
-
*/
|
|
11
|
-
export declare function revalidateOnReconnect(): ClientSetting<QueryClientContext>;
|
|
12
|
-
//# sourceMappingURL=revalidateOnReconnect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"revalidateOnReconnect.d.ts","sourceRoot":"","sources":["../../src/settings/revalidateOnReconnect.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAO7D;;GAEG;AACH,eAAO,MAAM,cAAc,mDAmBzB,CAAA;AAEF;;;GAGG;AAEH,wBAAgB,qBAAqB,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAczE"}
|