@parcae/sdk
Advanced tools
@@ -36,2 +36,4 @@ import React from 'react'; | ||
| refetch: () => void; | ||
| /** Total matching records on the server (before limit/offset). */ | ||
| total: number; | ||
| } | ||
@@ -38,0 +40,0 @@ declare function useQuery<T>(chain: QueryChain<T> | null | undefined, options?: UseQueryOptions): UseQueryResult<T>; |
+62
-31
@@ -90,3 +90,3 @@ import { __export, createClient, log } from '../chunk-B47IBEFK.js'; | ||
| // ../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.mjs | ||
| // ../../../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.mjs | ||
| var core_exports = {}; | ||
@@ -105,3 +105,3 @@ __export(core_exports, { | ||
| // ../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/helpers.mjs | ||
| // ../../../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/helpers.mjs | ||
| var __extends = /* @__PURE__ */ (function() { | ||
@@ -233,3 +233,3 @@ var extendStatics = function(d, b) { | ||
| // ../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.mjs | ||
| // ../../../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.mjs | ||
| var JsonPatchError = PatchError; | ||
@@ -554,3 +554,3 @@ var deepClone = _deepClone; | ||
| // ../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/duplex.mjs | ||
| // ../../../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/duplex.mjs | ||
| var duplex_exports = {}; | ||
@@ -722,3 +722,3 @@ __export(duplex_exports, { | ||
| // ../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/index.mjs | ||
| // ../../../../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/index.mjs | ||
| Object.assign({}, core_exports, duplex_exports, { | ||
@@ -798,2 +798,3 @@ JsonPatchError: PatchError, | ||
| queryHash: null, | ||
| totalCount: 0, | ||
| chain: null, | ||
@@ -815,2 +816,16 @@ client: null, | ||
| } | ||
| function ensureIntermediates(doc, patches) { | ||
| for (const { path } of patches) { | ||
| const segments = path.split("/").filter(Boolean); | ||
| let cursor = doc; | ||
| for (let i = 0; i < segments.length - 1; i++) { | ||
| const seg = segments[i]; | ||
| const val = cursor[seg]; | ||
| if (val === null || val === void 0 || typeof val !== "object") { | ||
| cursor[seg] = {}; | ||
| } | ||
| cursor = cursor[seg]; | ||
| } | ||
| } | ||
| } | ||
| function applyOps(items, ops, modelClass, adapter) { | ||
@@ -850,2 +865,3 @@ if (ops.length === 0) return { items, changed: false }; | ||
| const snapshot = JSON.parse(JSON.stringify(existing.__data ?? {})); | ||
| ensureIntermediates(snapshot, patches); | ||
| applyPatch(snapshot, patches, false, true); | ||
@@ -913,3 +929,5 @@ const serverMerge = existing[SYM_SERVER_MERGE]; | ||
| const delay = RETRY_DELAYS[Math.min(entry.retryCount, RETRY_DELAYS.length - 1)]; | ||
| log.debug(`useQuery: scheduling retry ${entry.retryCount + 1}/${MAX_RETRIES} in ${delay}ms`); | ||
| log.debug( | ||
| `useQuery: scheduling retry ${entry.retryCount + 1}/${MAX_RETRIES} in ${delay}ms` | ||
| ); | ||
| entry.retryTimer = setTimeout(() => { | ||
@@ -936,2 +954,5 @@ entry.retryTimer = null; | ||
| entry.retryCount = 0; | ||
| if (typeof result.__totalCount === "number") { | ||
| entry.totalCount = result.__totalCount; | ||
| } | ||
| if (entry.retryTimer) { | ||
@@ -948,3 +969,8 @@ clearTimeout(entry.retryTimer); | ||
| if (!Array.isArray(ops) || ops.length === 0) return; | ||
| const result2 = applyOps(entry.items, ops, chain.__modelClass, adapter); | ||
| const result2 = applyOps( | ||
| entry.items, | ||
| ops, | ||
| chain.__modelClass, | ||
| adapter | ||
| ); | ||
| if (!result2.changed) return; | ||
@@ -981,27 +1007,30 @@ entry.items = result2.items; | ||
| keyRef.current = key; | ||
| const subscribe = useCallback((onChange) => { | ||
| if (!key) return () => { | ||
| }; | ||
| const e = getOrCreate(key); | ||
| e.refs++; | ||
| e.listeners.add(onChange); | ||
| if (e.gcTimer) { | ||
| clearTimeout(e.gcTimer); | ||
| e.gcTimer = null; | ||
| } | ||
| return () => { | ||
| e.listeners.delete(onChange); | ||
| e.refs--; | ||
| if (e.refs <= 0) { | ||
| if (e.retryTimer) { | ||
| clearTimeout(e.retryTimer); | ||
| e.retryTimer = null; | ||
| const subscribe = useCallback( | ||
| (onChange) => { | ||
| if (!key) return () => { | ||
| }; | ||
| const e = getOrCreate(key); | ||
| e.refs++; | ||
| e.listeners.add(onChange); | ||
| if (e.gcTimer) { | ||
| clearTimeout(e.gcTimer); | ||
| e.gcTimer = null; | ||
| } | ||
| return () => { | ||
| e.listeners.delete(onChange); | ||
| e.refs--; | ||
| if (e.refs <= 0) { | ||
| if (e.retryTimer) { | ||
| clearTimeout(e.retryTimer); | ||
| e.retryTimer = null; | ||
| } | ||
| e.gcTimer = setTimeout(() => { | ||
| e.dispose?.(); | ||
| cache.delete(key); | ||
| }, GC_DELAY); | ||
| } | ||
| e.gcTimer = setTimeout(() => { | ||
| e.dispose?.(); | ||
| cache.delete(key); | ||
| }, GC_DELAY); | ||
| } | ||
| }; | ||
| }, [key]); | ||
| }; | ||
| }, | ||
| [key] | ||
| ); | ||
| const getSnapshot = useCallback(() => { | ||
@@ -1064,2 +1093,3 @@ if (!key) return INITIAL_HASH; | ||
| error: null, | ||
| total: 0, | ||
| refetch: () => { | ||
@@ -1073,2 +1103,3 @@ } | ||
| error: entry?.error ?? null, | ||
| total: entry?.totalCount ?? 0, | ||
| refetch | ||
@@ -1075,0 +1106,0 @@ }; |
+12
-12
| { | ||
| "name": "@parcae/sdk", | ||
| "version": "0.8.0", | ||
| "version": "0.8.1", | ||
| "description": "Parcae SDK — client transport and React hooks for Parcae backends", | ||
@@ -24,3 +24,11 @@ "type": "module", | ||
| ], | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "typecheck": "tsc --noEmit", | ||
| "clean": "rm -rf dist", | ||
| "test": "vitest run", | ||
| "test:watch": "vitest" | ||
| }, | ||
| "dependencies": { | ||
| "@parcae/model": "workspace:*", | ||
| "compress-json": "^3.1.0", | ||
@@ -32,4 +40,3 @@ "eventemitter3": "^5.0.1", | ||
| "socket.io-client": "^4.8.0", | ||
| "valtio": "^2.1.0", | ||
| "@parcae/model": "0.8.0" | ||
| "valtio": "^2.1.0" | ||
| }, | ||
@@ -52,10 +59,3 @@ "devDependencies": { | ||
| }, | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "typecheck": "tsc --noEmit", | ||
| "clean": "rm -rf dist", | ||
| "test": "vitest run", | ||
| "test:watch": "vitest" | ||
| } | ||
| } | ||
| "license": "MIT" | ||
| } |
Sorry, the diff of this file is too big to display
215958
1.7%1821
1.85%- Removed
Updated