@rocicorp/zero 0.24.2025090402 → 0.24.2025091100
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/out/{chunk-4NLQ25GZ.js → chunk-FH5Q72JS.js} +3 -3
- package/out/{chunk-G442PJSB.js → chunk-MLYQCVBG.js} +23 -13
- package/out/{chunk-G442PJSB.js.map → chunk-MLYQCVBG.js.map} +2 -2
- package/out/{chunk-P6JME3HC.js → chunk-V2KPKXLX.js} +20 -6
- package/out/chunk-V2KPKXLX.js.map +7 -0
- package/out/{inspector-4ALIZXAU.js → inspector-NC6TPMRA.js} +2 -2
- package/out/react.js +87 -12
- package/out/react.js.map +2 -2
- package/out/replicache/src/connection-loop.d.ts.map +1 -1
- package/out/solid.js +64 -19
- package/out/solid.js.map +3 -3
- package/out/zero/package.json +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +8 -0
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +18 -0
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.js +4 -0
- package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.d.ts +1 -0
- package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.js +41 -2
- package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
- package/out/zero-cache/src/server/otel-diag-logger.d.ts +16 -0
- package/out/zero-cache/src/server/otel-diag-logger.d.ts.map +1 -0
- package/out/zero-cache/src/server/otel-diag-logger.js +76 -0
- package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -0
- package/out/zero-cache/src/server/otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/otel-start.js +13 -13
- package/out/zero-cache/src/server/otel-start.js.map +1 -1
- package/out/zero-cache/src/server/reaper.js +5 -1
- package/out/zero-cache/src/server/reaper.js.map +1 -1
- package/out/zero-cache/src/server/syncer.js +1 -1
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts +4 -4
- package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts +7 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js +17 -8
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +0 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +6 -19
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts +0 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +19 -8
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +1 -6
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-client/src/client/query-manager.d.ts +2 -0
- package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
- package/out/zero-react/src/use-query.d.ts +20 -3
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +24 -5
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/use-query.d.ts.map +1 -1
- package/out/zero.js +3 -3
- package/out/zql/src/ivm/array-view.d.ts +2 -1
- package/out/zql/src/ivm/array-view.d.ts.map +1 -1
- package/out/zql/src/ivm/array-view.js +16 -5
- package/out/zql/src/ivm/array-view.js.map +1 -1
- package/out/zql/src/ivm/view.d.ts +2 -1
- package/out/zql/src/ivm/view.d.ts.map +1 -1
- package/out/zql/src/query/query-delegate.d.ts +2 -1
- package/out/zql/src/query/query-delegate.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js +17 -5
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/typed-view.d.ts +3 -2
- package/out/zql/src/query/typed-view.d.ts.map +1 -1
- package/out/{zero-cache/src/services/view-syncer → zqlite/src}/database-storage.d.ts +2 -2
- package/out/zqlite/src/database-storage.d.ts.map +1 -0
- package/out/{zero-cache/src/services/view-syncer → zqlite/src}/database-storage.js +1 -1
- package/out/zqlite/src/database-storage.js.map +1 -0
- package/package.json +1 -1
- package/out/chunk-P6JME3HC.js.map +0 -7
- package/out/zero-cache/src/services/view-syncer/database-storage.d.ts.map +0 -1
- package/out/zero-cache/src/services/view-syncer/database-storage.js.map +0 -1
- /package/out/{chunk-4NLQ25GZ.js.map → chunk-FH5Q72JS.js.map} +0 -0
- /package/out/{inspector-4ALIZXAU.js.map → inspector-NC6TPMRA.js.map} +0 -0
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
test,
|
|
18
18
|
valita_exports,
|
|
19
19
|
withRead
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-MLYQCVBG.js";
|
|
21
21
|
import {
|
|
22
22
|
assert,
|
|
23
23
|
unreachable
|
|
@@ -485,4 +485,4 @@ function convertServerMetrics(metrics) {
|
|
|
485
485
|
export {
|
|
486
486
|
newInspector
|
|
487
487
|
};
|
|
488
|
-
//# sourceMappingURL=inspector-
|
|
488
|
+
//# sourceMappingURL=inspector-NC6TPMRA.js.map
|
package/out/react.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Zero
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V2KPKXLX.js";
|
|
4
4
|
import "./chunk-MKB4RXL3.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_TTL_MS
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MLYQCVBG.js";
|
|
8
8
|
import {
|
|
9
9
|
hasOwn
|
|
10
10
|
} from "./chunk-SGW2EIVJ.js";
|
|
@@ -203,24 +203,84 @@ var disabledSubscriber = () => () => {
|
|
|
203
203
|
};
|
|
204
204
|
var resultTypeUnknown = { type: "unknown" };
|
|
205
205
|
var resultTypeComplete = { type: "complete" };
|
|
206
|
+
var resultTypeError = { type: "error" };
|
|
206
207
|
var emptySnapshotSingularUnknown = [void 0, resultTypeUnknown];
|
|
207
208
|
var emptySnapshotSingularComplete = [void 0, resultTypeComplete];
|
|
209
|
+
var emptySnapshotSingularErrorUnknown = [void 0, resultTypeError];
|
|
208
210
|
var emptySnapshotPluralUnknown = [emptyArray, resultTypeUnknown];
|
|
209
211
|
var emptySnapshotPluralComplete = [emptyArray, resultTypeComplete];
|
|
212
|
+
var emptySnapshotErrorUnknown = [emptyArray, resultTypeError];
|
|
210
213
|
function getDefaultSnapshot(singular) {
|
|
211
214
|
return singular ? emptySnapshotSingularUnknown : emptySnapshotPluralUnknown;
|
|
212
215
|
}
|
|
213
|
-
function getSnapshot(singular, data, resultType) {
|
|
216
|
+
function getSnapshot(singular, data, resultType, refetchFn, error) {
|
|
214
217
|
if (singular && data === void 0) {
|
|
215
|
-
|
|
218
|
+
switch (resultType) {
|
|
219
|
+
case "error":
|
|
220
|
+
if (error) {
|
|
221
|
+
return [
|
|
222
|
+
void 0,
|
|
223
|
+
makeError(refetchFn, error)
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
return emptySnapshotSingularErrorUnknown;
|
|
227
|
+
case "complete":
|
|
228
|
+
return emptySnapshotSingularComplete;
|
|
229
|
+
case "unknown":
|
|
230
|
+
return emptySnapshotSingularUnknown;
|
|
231
|
+
}
|
|
216
232
|
}
|
|
217
233
|
if (!singular && data.length === 0) {
|
|
218
|
-
|
|
234
|
+
switch (resultType) {
|
|
235
|
+
case "error":
|
|
236
|
+
if (error) {
|
|
237
|
+
return [
|
|
238
|
+
emptyArray,
|
|
239
|
+
makeError(refetchFn, error)
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
return emptySnapshotErrorUnknown;
|
|
243
|
+
case "complete":
|
|
244
|
+
return emptySnapshotPluralComplete;
|
|
245
|
+
case "unknown":
|
|
246
|
+
return emptySnapshotPluralUnknown;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
switch (resultType) {
|
|
250
|
+
case "error":
|
|
251
|
+
if (error) {
|
|
252
|
+
return [data, makeError(refetchFn, error)];
|
|
253
|
+
}
|
|
254
|
+
return [
|
|
255
|
+
data,
|
|
256
|
+
makeError(refetchFn, {
|
|
257
|
+
error: "app",
|
|
258
|
+
id: "unknown",
|
|
259
|
+
name: "unknown",
|
|
260
|
+
details: "An unknown error occurred"
|
|
261
|
+
})
|
|
262
|
+
];
|
|
263
|
+
case "complete":
|
|
264
|
+
return [data, resultTypeComplete];
|
|
265
|
+
case "unknown":
|
|
266
|
+
return [data, resultTypeUnknown];
|
|
219
267
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
268
|
+
}
|
|
269
|
+
function makeError(refetch, error) {
|
|
270
|
+
return {
|
|
271
|
+
type: "error",
|
|
272
|
+
refetch,
|
|
273
|
+
error: error.error === "app" || error.error === "zero" ? {
|
|
274
|
+
type: "app",
|
|
275
|
+
queryName: error.name,
|
|
276
|
+
details: error.details
|
|
277
|
+
} : {
|
|
278
|
+
type: "http",
|
|
279
|
+
queryName: error.name,
|
|
280
|
+
status: error.status,
|
|
281
|
+
details: error.details
|
|
282
|
+
}
|
|
283
|
+
};
|
|
224
284
|
}
|
|
225
285
|
var ViewStore = class {
|
|
226
286
|
#views = /* @__PURE__ */ new Map();
|
|
@@ -295,10 +355,16 @@ var ViewWrapper = class {
|
|
|
295
355
|
this.#reactInternals = /* @__PURE__ */ new Set();
|
|
296
356
|
this.#materializeIfNeeded();
|
|
297
357
|
}
|
|
298
|
-
#onData = (snap, resultType) => {
|
|
358
|
+
#onData = (snap, resultType, error) => {
|
|
299
359
|
const data = snap === void 0 ? snap : deepClone(snap);
|
|
300
|
-
this.#snapshot = getSnapshot(
|
|
301
|
-
|
|
360
|
+
this.#snapshot = getSnapshot(
|
|
361
|
+
this.#format.singular,
|
|
362
|
+
data,
|
|
363
|
+
resultType,
|
|
364
|
+
this.#refetch,
|
|
365
|
+
error
|
|
366
|
+
);
|
|
367
|
+
if (resultType === "complete" || resultType === "error") {
|
|
302
368
|
this.#complete = true;
|
|
303
369
|
this.#completeResolver.resolve();
|
|
304
370
|
this.#nonEmpty = true;
|
|
@@ -312,6 +378,15 @@ var ViewWrapper = class {
|
|
|
312
378
|
internals();
|
|
313
379
|
}
|
|
314
380
|
};
|
|
381
|
+
/**
|
|
382
|
+
* Called by the user to force a refetch of the query
|
|
383
|
+
* in the case the query errored.
|
|
384
|
+
*/
|
|
385
|
+
#refetch = () => {
|
|
386
|
+
this.#view?.destroy();
|
|
387
|
+
this.#view = void 0;
|
|
388
|
+
this.#materializeIfNeeded();
|
|
389
|
+
};
|
|
315
390
|
#materializeIfNeeded = () => {
|
|
316
391
|
if (this.#view) {
|
|
317
392
|
return;
|
package/out/react.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../zero-react/src/components/zero-inspector.tsx", "../../zero-react/src/use-query.tsx", "../../shared/src/deep-clone.ts", "../../zero-react/src/zero-provider.tsx", "../../zero-react/src/use-zero-online.tsx"],
|
|
4
|
-
"sourcesContent": ["import {lazy, Suspense, useState} from 'react';\nimport type {CustomMutatorDefs} from '../../../zero-client/src/client/custom.ts';\nimport type {Zero} from '../../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../../zero-schema/src/builder/schema-builder.ts';\nimport {MarkIcon} from './mark-icon.tsx';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst Inspector = lazy(() => import('./inspector.tsx'));\n\nexport function ZeroInspector<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>({zero}: {zero: Zero<S, MD>}): JSX.Element {\n const [show, setShow] = useState(false);\n return show ? (\n <Suspense fallback={<div>Loading Inspector...</div>}>\n <Inspector\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n zero={zero as any}\n onClose={() => setShow(false)}\n />\n </Suspense>\n ) : (\n <button\n onClick={() => setShow(!show)}\n style={{\n position: 'fixed',\n bottom: 0,\n right: 0,\n zIndex: 1000,\n padding: '5px',\n color: 'white',\n backgroundColor: '#333',\n borderTopLeftRadius: '8px',\n opacity: 0.95,\n }}\n >\n <MarkIcon\n style={{\n width: '20px',\n height: '20px',\n fill: 'currentColor',\n }}\n />\n </button>\n );\n}\n", "import React, {useSyncExternalStore} from 'react';\nimport {resolver} from '@rocicorp/resolver';\nimport {deepClone} from '../../shared/src/deep-clone.ts';\nimport type {Immutable} from '../../shared/src/immutable.ts';\nimport type {ReadonlyJSONValue} from '../../shared/src/json.ts';\nimport {Zero} from '../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\nimport type {Format} from '../../zql/src/ivm/view.ts';\nimport {AbstractQuery} from '../../zql/src/query/query-impl.ts';\nimport {type HumanReadable, type Query} from '../../zql/src/query/query.ts';\nimport {DEFAULT_TTL_MS, type TTL} from '../../zql/src/query/ttl.ts';\nimport type {ResultType, TypedView} from '../../zql/src/query/typed-view.ts';\nimport {useZero} from './zero-provider.tsx';\n\nexport type QueryResultDetails = Readonly<{\n type: ResultType;\n}>;\n\nexport type QueryResult<TReturn> = readonly [\n HumanReadable<TReturn>,\n QueryResultDetails,\n];\n\nexport type UseQueryOptions = {\n enabled?: boolean | undefined;\n /**\n * Time to live (TTL) in seconds. Controls how long query results are cached\n * after the query is removed. During this time, Zero continues to sync the query.\n * Default is 'never'.\n */\n ttl?: TTL | undefined;\n};\n\nexport type UseSuspenseQueryOptions = UseQueryOptions & {\n /**\n * Whether to suspend until:\n * - 'partial': the query has partial results (partial array or defined\n * value for singular results) which may be of result type 'unknown',\n * or the query result type is 'complete' (in which case results may be\n * empty). This is useful for suspending until there are partial\n * optimistic local results, or the query has completed loading from the\n * server.\n * - 'complete': the query result type is 'complete'.\n *\n * Default is 'partial'.\n */\n suspendUntil?: 'complete' | 'partial';\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\nconst reactUse = (React as unknown as {use?: (p: Promise<unknown>) => void})\n .use;\nconst suspend: (p: Promise<unknown>) => void = reactUse\n ? reactUse\n : p => {\n throw p;\n };\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n query: Query<TSchema, TTable, TReturn>,\n options?: UseQueryOptions | boolean,\n): QueryResult<TReturn> {\n let enabled = true;\n let ttl: TTL = DEFAULT_TTL_MS;\n if (typeof options === 'boolean') {\n enabled = options;\n } else if (options) {\n ({enabled = true, ttl = DEFAULT_TTL_MS} = options);\n }\n\n const view = viewStore.getView(\n useZero(),\n query as AbstractQuery<TSchema, TTable, TReturn>,\n enabled,\n ttl,\n );\n // https://react.dev/reference/react/useSyncExternalStore\n return useSyncExternalStore(\n view.subscribeReactInternals,\n view.getSnapshot,\n view.getSnapshot,\n );\n}\n\nexport function useSuspenseQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n query: Query<TSchema, TTable, TReturn>,\n options?: UseSuspenseQueryOptions | boolean,\n): QueryResult<TReturn> {\n let enabled = true;\n let ttl: TTL = DEFAULT_TTL_MS;\n let suspendUntil: 'complete' | 'partial' = 'partial';\n if (typeof options === 'boolean') {\n enabled = options;\n } else if (options) {\n ({\n enabled = true,\n ttl = DEFAULT_TTL_MS,\n suspendUntil = 'complete',\n } = options);\n }\n\n const view = viewStore.getView(\n useZero(),\n query as AbstractQuery<TSchema, TTable, TReturn>,\n enabled,\n ttl,\n );\n // https://react.dev/reference/react/useSyncExternalStore\n const snapshot = useSyncExternalStore(\n view.subscribeReactInternals,\n view.getSnapshot,\n view.getSnapshot,\n );\n\n if (enabled) {\n if (suspendUntil === 'complete' && !view.complete) {\n suspend(view.waitForComplete());\n }\n\n if (suspendUntil === 'partial' && !view.nonEmpty) {\n suspend(view.waitForNonEmpty());\n }\n }\n\n return snapshot;\n}\n\nconst emptyArray: unknown[] = [];\nconst disabledSubscriber = () => () => {};\n\nconst resultTypeUnknown = {type: 'unknown'} as const;\nconst resultTypeComplete = {type: 'complete'} as const;\n\nconst emptySnapshotSingularUnknown = [undefined, resultTypeUnknown] as const;\nconst emptySnapshotSingularComplete = [undefined, resultTypeComplete] as const;\nconst emptySnapshotPluralUnknown = [emptyArray, resultTypeUnknown] as const;\nconst emptySnapshotPluralComplete = [emptyArray, resultTypeComplete] as const;\n\nfunction getDefaultSnapshot<TReturn>(singular: boolean): QueryResult<TReturn> {\n return (\n singular ? emptySnapshotSingularUnknown : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n}\n\n/**\n * Returns a new snapshot or one of the empty predefined ones. Returning the\n * predefined ones is important to prevent unnecessary re-renders in React.\n */\nfunction getSnapshot<TReturn>(\n singular: boolean,\n data: HumanReadable<TReturn>,\n resultType: string,\n): QueryResult<TReturn> {\n if (singular && data === undefined) {\n return (resultType === 'complete'\n ? emptySnapshotSingularComplete\n : emptySnapshotSingularUnknown) as unknown as QueryResult<TReturn>;\n }\n\n if (!singular && (data as unknown[]).length === 0) {\n return (\n resultType === 'complete'\n ? emptySnapshotPluralComplete\n : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n }\n\n return [\n data,\n resultType === 'complete' ? resultTypeComplete : resultTypeUnknown,\n ];\n}\n\ndeclare const TESTING: boolean;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ViewWrapperAny = ViewWrapper<any, any, any>;\n\nconst allViews = new WeakMap<ViewStore, Map<string, ViewWrapperAny>>();\n\nexport function getAllViewsSizeForTesting(store: ViewStore): number {\n if (TESTING) {\n return allViews.get(store)?.size ?? 0;\n }\n return 0;\n}\n\n/**\n * A global store of all active views.\n *\n * React subscribes and unsubscribes to these views\n * via `useSyncExternalStore`.\n *\n * Managing views through `useEffect` or `useLayoutEffect` causes\n * inconsistencies because effects run after render.\n *\n * For example, if useQuery used use*Effect in the component below:\n * ```ts\n * function Foo({issueID}) {\n * const issue = useQuery(z.query.issue.where('id', issueID).one());\n * if (issue?.id !== undefined && issue.id !== issueID) {\n * console.log('MISMATCH!', issue.id, issueID);\n * }\n * }\n * ```\n *\n * `MISMATCH` will be printed whenever the `issueID` prop changes.\n *\n * This is because the component will render once with\n * the old state returned from `useQuery`. Then the effect inside\n * `useQuery` will run. The component will render again with the new\n * state. This inconsistent transition can cause unexpected results.\n *\n * Emulating `useEffect` via `useState` and `if` causes resource leaks.\n * That is:\n *\n * ```ts\n * function useQuery(q) {\n * const [oldHash, setOldHash] = useState();\n * if (hash(q) !== oldHash) {\n * // make new view\n * }\n *\n * useEffect(() => {\n * return () => view.destroy();\n * }, []);\n * }\n * ```\n *\n * I'm not sure why but in strict mode the cleanup function\n * fails to be called for the first instance of the view and only\n * cleans up later instances.\n *\n * Swapping `useState` to `useRef` has similar problems.\n */\nexport class ViewStore {\n #views = new Map<string, ViewWrapperAny>();\n\n constructor() {\n if (TESTING) {\n allViews.set(this, this.#views);\n }\n }\n\n getView<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n >(\n zero: Zero<TSchema>,\n query: Query<TSchema, TTable, TReturn>,\n enabled: boolean,\n ttl: TTL,\n ): {\n getSnapshot: () => QueryResult<TReturn>;\n subscribeReactInternals: (internals: () => void) => () => void;\n updateTTL: (ttl: TTL) => void;\n waitForComplete: () => Promise<void>;\n waitForNonEmpty: () => Promise<void>;\n complete: boolean;\n nonEmpty: boolean;\n } {\n const {format} = query;\n if (!enabled) {\n return {\n getSnapshot: () => getDefaultSnapshot(format.singular),\n subscribeReactInternals: disabledSubscriber,\n updateTTL: () => {},\n waitForComplete: () => Promise.resolve(),\n waitForNonEmpty: () => Promise.resolve(),\n complete: false,\n nonEmpty: false,\n };\n }\n\n const hash = query.hash() + zero.clientID;\n let existing = this.#views.get(hash);\n if (!existing) {\n existing = new ViewWrapper(\n zero,\n query,\n format,\n ttl,\n view => {\n const lastView = this.#views.get(hash);\n // I don't think this can happen\n // but lets guard against it so we don't\n // leak resources.\n if (lastView && lastView !== view) {\n throw new Error('View already exists');\n }\n this.#views.set(hash, view);\n },\n () => {\n this.#views.delete(hash);\n },\n );\n this.#views.set(hash, existing);\n } else {\n existing.updateTTL(ttl);\n }\n return existing as ViewWrapper<TSchema, TTable, TReturn>;\n }\n}\n\nconst viewStore = new ViewStore();\n\n/**\n * This wraps and ref counts a view.\n *\n * The only signal we have from React as to whether or not it is\n * done with a view is when it calls `unsubscribe`.\n *\n * In non-strict-mode we can clean up the view as soon\n * as the listener count goes to 0.\n *\n * In strict-mode, the listener count will go to 0 then a\n * new listener for the same view is immediately added back.\n *\n * This is why the `onMaterialized` and `onDematerialized` callbacks exist --\n * they allow a view which React is still referencing to be added\n * back into the store when React re-subscribes to it.\n *\n * This wrapper also exists to deal with the various\n * `useSyncExternalStore` caveats that cause excessive\n * re-renders and materializations.\n *\n * See: https://react.dev/reference/react/useSyncExternalStore#caveats\n * Especially:\n * 1. The store snapshot returned by getSnapshot must be immutable. If the underlying store has mutable data, return a new immutable snapshot if the data has changed. Otherwise, return a cached last snapshot.\n * 2. If a different subscribe function is passed during a re-render, React will re-subscribe to the store using the newly passed subscribe function. You can prevent this by declaring subscribe outside the component.\n */\nclass ViewWrapper<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n> {\n #zero: Zero<TSchema>;\n #view: TypedView<HumanReadable<TReturn>> | undefined;\n readonly #onDematerialized;\n readonly #onMaterialized;\n readonly #query: Query<TSchema, TTable, TReturn>;\n readonly #format: Format;\n #snapshot: QueryResult<TReturn>;\n #reactInternals: Set<() => void>;\n #ttl: TTL;\n #complete = false;\n #completeResolver = resolver<void>();\n #nonEmpty = false;\n #nonEmptyResolver = resolver<void>();\n\n constructor(\n zero: Zero<TSchema>,\n query: Query<TSchema, TTable, TReturn>,\n format: Format,\n ttl: TTL,\n onMaterialized: (view: ViewWrapper<TSchema, TTable, TReturn>) => void,\n onDematerialized: () => void,\n ) {\n this.#zero = zero;\n this.#query = query;\n this.#format = format;\n this.#ttl = ttl;\n this.#onMaterialized = onMaterialized;\n this.#onDematerialized = onDematerialized;\n this.#snapshot = getDefaultSnapshot(format.singular);\n this.#reactInternals = new Set();\n this.#materializeIfNeeded();\n }\n\n #onData = (\n snap: Immutable<HumanReadable<TReturn>>,\n resultType: ResultType,\n ) => {\n const data =\n snap === undefined\n ? snap\n : (deepClone(snap as ReadonlyJSONValue) as HumanReadable<TReturn>);\n this.#snapshot = getSnapshot(this.#format.singular, data, resultType);\n if (resultType === 'complete') {\n this.#complete = true;\n this.#completeResolver.resolve();\n this.#nonEmpty = true;\n this.#nonEmptyResolver.resolve();\n }\n\n if (\n this.#format.singular\n ? this.#snapshot[0] !== undefined\n : (this.#snapshot[0] as unknown[]).length !== 0\n ) {\n this.#nonEmpty = true;\n this.#nonEmptyResolver.resolve();\n }\n\n for (const internals of this.#reactInternals) {\n internals();\n }\n };\n\n #materializeIfNeeded = () => {\n if (this.#view) {\n return;\n }\n\n this.#view = this.#zero.materialize(this.#query, {ttl: this.#ttl});\n this.#view.addListener(this.#onData);\n\n this.#onMaterialized(this);\n };\n\n getSnapshot = () => this.#snapshot;\n\n subscribeReactInternals = (internals: () => void): (() => void) => {\n this.#reactInternals.add(internals);\n this.#materializeIfNeeded();\n return () => {\n this.#reactInternals.delete(internals);\n\n // only schedule a cleanup task if we have no listeners left\n if (this.#reactInternals.size === 0) {\n setTimeout(() => {\n // Someone re-registered a listener on this view before the timeout elapsed.\n // This happens often in strict-mode which forces a component\n // to mount, unmount, remount.\n if (this.#reactInternals.size > 0) {\n return;\n }\n // We already destroyed the view\n if (this.#view === undefined) {\n return;\n }\n this.#view.destroy();\n this.#view = undefined;\n this.#complete = false;\n this.#completeResolver = resolver();\n this.#nonEmpty = false;\n this.#nonEmptyResolver = resolver();\n this.#onDematerialized();\n }, 10);\n }\n };\n };\n\n updateTTL(ttl: TTL): void {\n this.#ttl = ttl;\n this.#view?.updateTTL(ttl);\n }\n\n get complete() {\n return this.#complete;\n }\n\n waitForComplete(): Promise<void> {\n return this.#completeResolver.promise;\n }\n\n get nonEmpty() {\n return this.#nonEmpty;\n }\n\n waitForNonEmpty(): Promise<void> {\n return this.#nonEmptyResolver.promise;\n }\n}\n", "import {hasOwn} from './has-own.ts';\nimport type {JSONValue, ReadonlyJSONValue} from './json.ts';\n\nexport function deepClone(value: ReadonlyJSONValue): JSONValue {\n const seen: Array<ReadonlyJSONValue> = [];\n return internalDeepClone(value, seen);\n}\n\nexport function internalDeepClone(\n value: ReadonlyJSONValue,\n seen: Array<ReadonlyJSONValue>,\n): JSONValue {\n switch (typeof value) {\n case 'boolean':\n case 'number':\n case 'string':\n case 'undefined':\n return value;\n case 'object': {\n if (value === null) {\n return null;\n }\n if (seen.includes(value)) {\n throw new Error('Cyclic object');\n }\n seen.push(value);\n if (Array.isArray(value)) {\n const rv = value.map(v => internalDeepClone(v, seen));\n seen.pop();\n return rv;\n }\n\n const obj: JSONValue = {};\n\n for (const k in value) {\n if (hasOwn(value, k)) {\n const v = (value as Record<string, ReadonlyJSONValue>)[k];\n if (v !== undefined) {\n obj[k] = internalDeepClone(v, seen);\n }\n }\n }\n seen.pop();\n return obj;\n }\n\n default:\n throw new Error(`Invalid type: ${typeof value}`);\n }\n}\n", "import {\n createContext,\n useContext,\n useEffect,\n useState,\n type ReactNode,\n} from 'react';\nimport {Zero} from '../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\nimport type {CustomMutatorDefs} from '../../zero-client/src/client/custom.ts';\nimport type {ZeroOptions} from '../../zero-client/src/client/options.ts';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst ZeroContext = createContext<unknown | undefined>(undefined);\n\nexport function useZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>(): Zero<S, MD> {\n const zero = useContext(ZeroContext);\n if (zero === undefined) {\n throw new Error('useZero must be used within a ZeroProvider');\n }\n return zero as Zero<S, MD>;\n}\n\nexport function createUseZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>() {\n return () => useZero<S, MD>();\n}\n\nexport type ZeroProviderProps<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n> = (ZeroOptions<S, MD> | {zero: Zero<S, MD>}) & {\n init?: (zero: Zero<S, MD>) => void;\n children: ReactNode;\n};\n\nexport function ZeroProvider<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>({children, init, ...props}: ZeroProviderProps<S, MD>) {\n const [zero, setZero] = useState<Zero<S, MD> | undefined>(\n 'zero' in props ? props.zero : undefined,\n );\n\n // If Zero is not passed in, we construct it, but only client-side.\n // Zero doesn't really work SSR today so this is usually the right thing.\n // When we support Zero SSR this will either become a breaking change or\n // more likely server support will be opt-in with a new prop on this\n // component.\n useEffect(() => {\n if ('zero' in props) {\n setZero(props.zero);\n return;\n }\n\n const z = new Zero(props);\n init?.(z);\n setZero(z);\n\n return () => {\n void z.close();\n setZero(undefined);\n };\n }, [init, ...Object.values(props)]);\n\n return (\n zero && <ZeroContext.Provider value={zero}>{children}</ZeroContext.Provider>\n );\n}\n", "import {useSyncExternalStore} from 'react';\nimport {useZero} from './zero-provider.tsx';\n\n/**\n * Hook to subscribe to the online status of the Zero instance.\n *\n * This is useful when you want to update state based on the online status.\n *\n * @returns The online status of the Zero instance.\n */\nexport function useZeroOnline(): boolean {\n const zero = useZero();\n return useSyncExternalStore(\n zero.onOnline,\n () => zero.online,\n () => zero.online,\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;AAAA,SAAQ,MAAM,UAAU,gBAAe;AAef;AARxB,IAAM,YAAY,KAAK,MAAM,OAAO,yBAAiB,CAAC;AAE/C,SAAS,cAGd,EAAC,KAAI,GAAqC;AAC1C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,SAAO,OACL,oBAAC,YAAS,UAAU,oBAAC,SAAI,kCAAoB,GAC3C;AAAA,IAAC;AAAA;AAAA,MAEC;AAAA,MACA,SAAS,MAAM,QAAQ,KAAK;AAAA;AAAA,EAC9B,GACF,IAEA;AAAA,IAAC;AAAA;AAAA,MACC,SAAS,MAAM,QAAQ,CAAC,IAAI;AAAA,MAC5B,OAAO;AAAA,QACL,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,OAAO;AAAA,QACP,iBAAiB;AAAA,QACjB,qBAAqB;AAAA,QACrB,SAAS;AAAA,MACX;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;;;AC9CA,OAAO,SAAQ,4BAA2B;AAC1C,SAAQ,gBAAe;;;ACEhB,SAAS,UAAU,OAAqC;AAC7D,QAAM,OAAiC,CAAC;AACxC,SAAO,kBAAkB,OAAO,IAAI;AACtC;AAEO,SAAS,kBACd,OACA,MACW;AACX,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,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AAQ,CAAC;AAET,WAAO,MAAM;AACX,WAAK,EAAE,MAAM;AACb,cAAQ,MAAS;AAAA,IACnB;AAAA,EACF,GAAG,CAAC,MAAM,GAAG,OAAO,OAAO,KAAK,CAAC,CAAC;AAElC,SACE,QAAQ,gBAAAD,KAAC,YAAY,UAAZ,EAAqB,OAAO,MAAO,UAAS;AAEzD;;;
|
|
4
|
+
"sourcesContent": ["import {lazy, Suspense, useState} from 'react';\nimport type {CustomMutatorDefs} from '../../../zero-client/src/client/custom.ts';\nimport type {Zero} from '../../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../../zero-schema/src/builder/schema-builder.ts';\nimport {MarkIcon} from './mark-icon.tsx';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst Inspector = lazy(() => import('./inspector.tsx'));\n\nexport function ZeroInspector<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>({zero}: {zero: Zero<S, MD>}): JSX.Element {\n const [show, setShow] = useState(false);\n return show ? (\n <Suspense fallback={<div>Loading Inspector...</div>}>\n <Inspector\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n zero={zero as any}\n onClose={() => setShow(false)}\n />\n </Suspense>\n ) : (\n <button\n onClick={() => setShow(!show)}\n style={{\n position: 'fixed',\n bottom: 0,\n right: 0,\n zIndex: 1000,\n padding: '5px',\n color: 'white',\n backgroundColor: '#333',\n borderTopLeftRadius: '8px',\n opacity: 0.95,\n }}\n >\n <MarkIcon\n style={{\n width: '20px',\n height: '20px',\n fill: 'currentColor',\n }}\n />\n </button>\n );\n}\n", "import React, {useSyncExternalStore} from 'react';\nimport {resolver} from '@rocicorp/resolver';\nimport {deepClone} from '../../shared/src/deep-clone.ts';\nimport type {Immutable} from '../../shared/src/immutable.ts';\nimport type {ReadonlyJSONValue} from '../../shared/src/json.ts';\nimport {Zero} from '../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\nimport type {Format} from '../../zql/src/ivm/view.ts';\nimport {AbstractQuery} from '../../zql/src/query/query-impl.ts';\nimport {type HumanReadable, type Query} from '../../zql/src/query/query.ts';\nimport {DEFAULT_TTL_MS, type TTL} from '../../zql/src/query/ttl.ts';\nimport type {ResultType, TypedView} from '../../zql/src/query/typed-view.ts';\nimport {useZero} from './zero-provider.tsx';\nimport type {ErroredQuery} from '../../zero-protocol/src/custom-queries.ts';\n\nexport type QueryResultDetails = Readonly<\n | {\n type: 'complete';\n }\n | {\n type: 'unknown';\n }\n | QueryErrorDetails\n>;\n\ntype QueryErrorDetails = {\n type: 'error';\n refetch: (() => void) | undefined;\n error:\n | {\n type: 'app';\n queryName: string;\n details: ReadonlyJSONValue;\n }\n | {\n type: 'http';\n queryName: string;\n status: number;\n details: ReadonlyJSONValue;\n };\n};\n\nexport type QueryResult<TReturn> = readonly [\n HumanReadable<TReturn>,\n QueryResultDetails,\n];\n\nexport type UseQueryOptions = {\n enabled?: boolean | undefined;\n /**\n * Time to live (TTL) in seconds. Controls how long query results are cached\n * after the query is removed. During this time, Zero continues to sync the query.\n * Default is 'never'.\n */\n ttl?: TTL | undefined;\n};\n\nexport type UseSuspenseQueryOptions = UseQueryOptions & {\n /**\n * Whether to suspend until:\n * - 'partial': the query has partial results (partial array or defined\n * value for singular results) which may be of result type 'unknown',\n * or the query result type is 'complete' (in which case results may be\n * empty). This is useful for suspending until there are partial\n * optimistic local results, or the query has completed loading from the\n * server.\n * - 'complete': the query result type is 'complete'.\n *\n * Default is 'partial'.\n */\n suspendUntil?: 'complete' | 'partial';\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\nconst reactUse = (React as unknown as {use?: (p: Promise<unknown>) => void})\n .use;\nconst suspend: (p: Promise<unknown>) => void = reactUse\n ? reactUse\n : p => {\n throw p;\n };\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n query: Query<TSchema, TTable, TReturn>,\n options?: UseQueryOptions | boolean,\n): QueryResult<TReturn> {\n let enabled = true;\n let ttl: TTL = DEFAULT_TTL_MS;\n if (typeof options === 'boolean') {\n enabled = options;\n } else if (options) {\n ({enabled = true, ttl = DEFAULT_TTL_MS} = options);\n }\n\n const view = viewStore.getView(\n useZero(),\n query as AbstractQuery<TSchema, TTable, TReturn>,\n enabled,\n ttl,\n );\n // https://react.dev/reference/react/useSyncExternalStore\n return useSyncExternalStore(\n view.subscribeReactInternals,\n view.getSnapshot,\n view.getSnapshot,\n );\n}\n\nexport function useSuspenseQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n query: Query<TSchema, TTable, TReturn>,\n options?: UseSuspenseQueryOptions | boolean,\n): QueryResult<TReturn> {\n let enabled = true;\n let ttl: TTL = DEFAULT_TTL_MS;\n let suspendUntil: 'complete' | 'partial' = 'partial';\n if (typeof options === 'boolean') {\n enabled = options;\n } else if (options) {\n ({\n enabled = true,\n ttl = DEFAULT_TTL_MS,\n suspendUntil = 'complete',\n } = options);\n }\n\n const view = viewStore.getView(\n useZero(),\n query as AbstractQuery<TSchema, TTable, TReturn>,\n enabled,\n ttl,\n );\n // https://react.dev/reference/react/useSyncExternalStore\n const snapshot = useSyncExternalStore(\n view.subscribeReactInternals,\n view.getSnapshot,\n view.getSnapshot,\n );\n\n if (enabled) {\n if (suspendUntil === 'complete' && !view.complete) {\n suspend(view.waitForComplete());\n }\n\n if (suspendUntil === 'partial' && !view.nonEmpty) {\n suspend(view.waitForNonEmpty());\n }\n }\n\n return snapshot;\n}\n\nconst emptyArray: unknown[] = [];\nconst disabledSubscriber = () => () => {};\n\nconst resultTypeUnknown = {type: 'unknown'} as const;\nconst resultTypeComplete = {type: 'complete'} as const;\nconst resultTypeError = {type: 'error'} as const;\n\nconst emptySnapshotSingularUnknown = [undefined, resultTypeUnknown] as const;\nconst emptySnapshotSingularComplete = [undefined, resultTypeComplete] as const;\nconst emptySnapshotSingularErrorUnknown = [undefined, resultTypeError] as const;\nconst emptySnapshotPluralUnknown = [emptyArray, resultTypeUnknown] as const;\nconst emptySnapshotPluralComplete = [emptyArray, resultTypeComplete] as const;\nconst emptySnapshotErrorUnknown = [emptyArray, resultTypeError] as const;\n\nfunction getDefaultSnapshot<TReturn>(singular: boolean): QueryResult<TReturn> {\n return (\n singular ? emptySnapshotSingularUnknown : emptySnapshotPluralUnknown\n ) as QueryResult<TReturn>;\n}\n\n/**\n * Returns a new snapshot or one of the empty predefined ones. Returning the\n * predefined ones is important to prevent unnecessary re-renders in React.\n */\nfunction getSnapshot<TReturn>(\n singular: boolean,\n data: HumanReadable<TReturn>,\n resultType: ResultType,\n refetchFn: () => void,\n error?: ErroredQuery | undefined,\n): QueryResult<TReturn> {\n if (singular && data === undefined) {\n switch (resultType) {\n case 'error':\n if (error) {\n return [\n undefined,\n makeError(refetchFn, error),\n ] as unknown as QueryResult<TReturn>;\n }\n return emptySnapshotSingularErrorUnknown as unknown as QueryResult<TReturn>;\n case 'complete':\n return emptySnapshotSingularComplete as unknown as QueryResult<TReturn>;\n case 'unknown':\n return emptySnapshotSingularUnknown as unknown as QueryResult<TReturn>;\n }\n }\n\n if (!singular && (data as unknown[]).length === 0) {\n switch (resultType) {\n case 'error':\n if (error) {\n return [\n emptyArray,\n makeError(refetchFn, error),\n ] as unknown as QueryResult<TReturn>;\n }\n return emptySnapshotErrorUnknown as unknown as QueryResult<TReturn>;\n case 'complete':\n return emptySnapshotPluralComplete as unknown as QueryResult<TReturn>;\n case 'unknown':\n return emptySnapshotPluralUnknown as unknown as QueryResult<TReturn>;\n }\n }\n\n switch (resultType) {\n case 'error':\n if (error) {\n return [data, makeError(refetchFn, error)];\n }\n return [\n data,\n makeError(refetchFn, {\n error: 'app',\n id: 'unknown',\n name: 'unknown',\n details: 'An unknown error occurred',\n }),\n ];\n case 'complete':\n return [data, resultTypeComplete];\n case 'unknown':\n return [data, resultTypeUnknown];\n }\n}\n\nfunction makeError(\n refetch: () => void,\n error: ErroredQuery,\n): QueryErrorDetails {\n return {\n type: 'error',\n refetch,\n error:\n error.error === 'app' || error.error === 'zero'\n ? {\n type: 'app',\n queryName: error.name,\n details: error.details,\n }\n : {\n type: 'http',\n queryName: error.name,\n status: error.status,\n details: error.details,\n },\n };\n}\n\ndeclare const TESTING: boolean;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ViewWrapperAny = ViewWrapper<any, any, any>;\n\nconst allViews = new WeakMap<ViewStore, Map<string, ViewWrapperAny>>();\n\nexport function getAllViewsSizeForTesting(store: ViewStore): number {\n if (TESTING) {\n return allViews.get(store)?.size ?? 0;\n }\n return 0;\n}\n\n/**\n * A global store of all active views.\n *\n * React subscribes and unsubscribes to these views\n * via `useSyncExternalStore`.\n *\n * Managing views through `useEffect` or `useLayoutEffect` causes\n * inconsistencies because effects run after render.\n *\n * For example, if useQuery used use*Effect in the component below:\n * ```ts\n * function Foo({issueID}) {\n * const issue = useQuery(z.query.issue.where('id', issueID).one());\n * if (issue?.id !== undefined && issue.id !== issueID) {\n * console.log('MISMATCH!', issue.id, issueID);\n * }\n * }\n * ```\n *\n * `MISMATCH` will be printed whenever the `issueID` prop changes.\n *\n * This is because the component will render once with\n * the old state returned from `useQuery`. Then the effect inside\n * `useQuery` will run. The component will render again with the new\n * state. This inconsistent transition can cause unexpected results.\n *\n * Emulating `useEffect` via `useState` and `if` causes resource leaks.\n * That is:\n *\n * ```ts\n * function useQuery(q) {\n * const [oldHash, setOldHash] = useState();\n * if (hash(q) !== oldHash) {\n * // make new view\n * }\n *\n * useEffect(() => {\n * return () => view.destroy();\n * }, []);\n * }\n * ```\n *\n * I'm not sure why but in strict mode the cleanup function\n * fails to be called for the first instance of the view and only\n * cleans up later instances.\n *\n * Swapping `useState` to `useRef` has similar problems.\n */\nexport class ViewStore {\n #views = new Map<string, ViewWrapperAny>();\n\n constructor() {\n if (TESTING) {\n allViews.set(this, this.#views);\n }\n }\n\n getView<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n >(\n zero: Zero<TSchema>,\n query: Query<TSchema, TTable, TReturn>,\n enabled: boolean,\n ttl: TTL,\n ): {\n getSnapshot: () => QueryResult<TReturn>;\n subscribeReactInternals: (internals: () => void) => () => void;\n updateTTL: (ttl: TTL) => void;\n waitForComplete: () => Promise<void>;\n waitForNonEmpty: () => Promise<void>;\n complete: boolean;\n nonEmpty: boolean;\n } {\n const {format} = query;\n if (!enabled) {\n return {\n getSnapshot: () => getDefaultSnapshot(format.singular),\n subscribeReactInternals: disabledSubscriber,\n updateTTL: () => {},\n waitForComplete: () => Promise.resolve(),\n waitForNonEmpty: () => Promise.resolve(),\n complete: false,\n nonEmpty: false,\n };\n }\n\n const hash = query.hash() + zero.clientID;\n let existing = this.#views.get(hash);\n if (!existing) {\n existing = new ViewWrapper(\n zero,\n query,\n format,\n ttl,\n view => {\n const lastView = this.#views.get(hash);\n // I don't think this can happen\n // but lets guard against it so we don't\n // leak resources.\n if (lastView && lastView !== view) {\n throw new Error('View already exists');\n }\n this.#views.set(hash, view);\n },\n () => {\n this.#views.delete(hash);\n },\n );\n this.#views.set(hash, existing);\n } else {\n existing.updateTTL(ttl);\n }\n return existing as ViewWrapper<TSchema, TTable, TReturn>;\n }\n}\n\nconst viewStore = new ViewStore();\n\n/**\n * This wraps and ref counts a view.\n *\n * The only signal we have from React as to whether or not it is\n * done with a view is when it calls `unsubscribe`.\n *\n * In non-strict-mode we can clean up the view as soon\n * as the listener count goes to 0.\n *\n * In strict-mode, the listener count will go to 0 then a\n * new listener for the same view is immediately added back.\n *\n * This is why the `onMaterialized` and `onDematerialized` callbacks exist --\n * they allow a view which React is still referencing to be added\n * back into the store when React re-subscribes to it.\n *\n * This wrapper also exists to deal with the various\n * `useSyncExternalStore` caveats that cause excessive\n * re-renders and materializations.\n *\n * See: https://react.dev/reference/react/useSyncExternalStore#caveats\n * Especially:\n * 1. The store snapshot returned by getSnapshot must be immutable. If the underlying store has mutable data, return a new immutable snapshot if the data has changed. Otherwise, return a cached last snapshot.\n * 2. If a different subscribe function is passed during a re-render, React will re-subscribe to the store using the newly passed subscribe function. You can prevent this by declaring subscribe outside the component.\n */\nclass ViewWrapper<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n> {\n #zero: Zero<TSchema>;\n #view: TypedView<HumanReadable<TReturn>> | undefined;\n readonly #onDematerialized;\n readonly #onMaterialized;\n readonly #query: Query<TSchema, TTable, TReturn>;\n readonly #format: Format;\n #snapshot: QueryResult<TReturn>;\n #reactInternals: Set<() => void>;\n #ttl: TTL;\n #complete = false;\n #completeResolver = resolver<void>();\n #nonEmpty = false;\n #nonEmptyResolver = resolver<void>();\n\n constructor(\n zero: Zero<TSchema>,\n query: Query<TSchema, TTable, TReturn>,\n format: Format,\n ttl: TTL,\n onMaterialized: (view: ViewWrapper<TSchema, TTable, TReturn>) => void,\n onDematerialized: () => void,\n ) {\n this.#zero = zero;\n this.#query = query;\n this.#format = format;\n this.#ttl = ttl;\n this.#onMaterialized = onMaterialized;\n this.#onDematerialized = onDematerialized;\n this.#snapshot = getDefaultSnapshot(format.singular);\n this.#reactInternals = new Set();\n this.#materializeIfNeeded();\n }\n\n #onData = (\n snap: Immutable<HumanReadable<TReturn>>,\n resultType: ResultType,\n error?: ErroredQuery | undefined,\n ) => {\n const data =\n snap === undefined\n ? snap\n : (deepClone(snap as ReadonlyJSONValue) as HumanReadable<TReturn>);\n this.#snapshot = getSnapshot(\n this.#format.singular,\n data,\n resultType,\n this.#refetch,\n error,\n );\n if (resultType === 'complete' || resultType === 'error') {\n this.#complete = true;\n this.#completeResolver.resolve();\n this.#nonEmpty = true;\n this.#nonEmptyResolver.resolve();\n }\n\n if (\n this.#format.singular\n ? this.#snapshot[0] !== undefined\n : (this.#snapshot[0] as unknown[]).length !== 0\n ) {\n this.#nonEmpty = true;\n this.#nonEmptyResolver.resolve();\n }\n\n for (const internals of this.#reactInternals) {\n internals();\n }\n };\n\n /**\n * Called by the user to force a refetch of the query\n * in the case the query errored.\n */\n #refetch = () => {\n this.#view?.destroy();\n this.#view = undefined;\n this.#materializeIfNeeded();\n };\n\n #materializeIfNeeded = () => {\n if (this.#view) {\n return;\n }\n\n this.#view = this.#zero.materialize(this.#query, {ttl: this.#ttl});\n this.#view.addListener(this.#onData);\n\n this.#onMaterialized(this);\n };\n\n getSnapshot = () => this.#snapshot;\n\n subscribeReactInternals = (internals: () => void): (() => void) => {\n this.#reactInternals.add(internals);\n this.#materializeIfNeeded();\n return () => {\n this.#reactInternals.delete(internals);\n\n // only schedule a cleanup task if we have no listeners left\n if (this.#reactInternals.size === 0) {\n setTimeout(() => {\n // Someone re-registered a listener on this view before the timeout elapsed.\n // This happens often in strict-mode which forces a component\n // to mount, unmount, remount.\n if (this.#reactInternals.size > 0) {\n return;\n }\n // We already destroyed the view\n if (this.#view === undefined) {\n return;\n }\n this.#view.destroy();\n this.#view = undefined;\n this.#complete = false;\n this.#completeResolver = resolver();\n this.#nonEmpty = false;\n this.#nonEmptyResolver = resolver();\n this.#onDematerialized();\n }, 10);\n }\n };\n };\n\n updateTTL(ttl: TTL): void {\n this.#ttl = ttl;\n this.#view?.updateTTL(ttl);\n }\n\n get complete() {\n return this.#complete;\n }\n\n waitForComplete(): Promise<void> {\n return this.#completeResolver.promise;\n }\n\n get nonEmpty() {\n return this.#nonEmpty;\n }\n\n waitForNonEmpty(): Promise<void> {\n return this.#nonEmptyResolver.promise;\n }\n}\n", "import {hasOwn} from './has-own.ts';\nimport type {JSONValue, ReadonlyJSONValue} from './json.ts';\n\nexport function deepClone(value: ReadonlyJSONValue): JSONValue {\n const seen: Array<ReadonlyJSONValue> = [];\n return internalDeepClone(value, seen);\n}\n\nexport function internalDeepClone(\n value: ReadonlyJSONValue,\n seen: Array<ReadonlyJSONValue>,\n): JSONValue {\n switch (typeof value) {\n case 'boolean':\n case 'number':\n case 'string':\n case 'undefined':\n return value;\n case 'object': {\n if (value === null) {\n return null;\n }\n if (seen.includes(value)) {\n throw new Error('Cyclic object');\n }\n seen.push(value);\n if (Array.isArray(value)) {\n const rv = value.map(v => internalDeepClone(v, seen));\n seen.pop();\n return rv;\n }\n\n const obj: JSONValue = {};\n\n for (const k in value) {\n if (hasOwn(value, k)) {\n const v = (value as Record<string, ReadonlyJSONValue>)[k];\n if (v !== undefined) {\n obj[k] = internalDeepClone(v, seen);\n }\n }\n }\n seen.pop();\n return obj;\n }\n\n default:\n throw new Error(`Invalid type: ${typeof value}`);\n }\n}\n", "import {\n createContext,\n useContext,\n useEffect,\n useState,\n type ReactNode,\n} from 'react';\nimport {Zero} from '../../zero-client/src/client/zero.ts';\nimport type {Schema} from '../../zero-schema/src/builder/schema-builder.ts';\nimport type {CustomMutatorDefs} from '../../zero-client/src/client/custom.ts';\nimport type {ZeroOptions} from '../../zero-client/src/client/options.ts';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst ZeroContext = createContext<unknown | undefined>(undefined);\n\nexport function useZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>(): Zero<S, MD> {\n const zero = useContext(ZeroContext);\n if (zero === undefined) {\n throw new Error('useZero must be used within a ZeroProvider');\n }\n return zero as Zero<S, MD>;\n}\n\nexport function createUseZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>() {\n return () => useZero<S, MD>();\n}\n\nexport type ZeroProviderProps<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n> = (ZeroOptions<S, MD> | {zero: Zero<S, MD>}) & {\n init?: (zero: Zero<S, MD>) => void;\n children: ReactNode;\n};\n\nexport function ZeroProvider<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>({children, init, ...props}: ZeroProviderProps<S, MD>) {\n const [zero, setZero] = useState<Zero<S, MD> | undefined>(\n 'zero' in props ? props.zero : undefined,\n );\n\n // If Zero is not passed in, we construct it, but only client-side.\n // Zero doesn't really work SSR today so this is usually the right thing.\n // When we support Zero SSR this will either become a breaking change or\n // more likely server support will be opt-in with a new prop on this\n // component.\n useEffect(() => {\n if ('zero' in props) {\n setZero(props.zero);\n return;\n }\n\n const z = new Zero(props);\n init?.(z);\n setZero(z);\n\n return () => {\n void z.close();\n setZero(undefined);\n };\n }, [init, ...Object.values(props)]);\n\n return (\n zero && <ZeroContext.Provider value={zero}>{children}</ZeroContext.Provider>\n );\n}\n", "import {useSyncExternalStore} from 'react';\nimport {useZero} from './zero-provider.tsx';\n\n/**\n * Hook to subscribe to the online status of the Zero instance.\n *\n * This is useful when you want to update state based on the online status.\n *\n * @returns The online status of the Zero instance.\n */\nexport function useZeroOnline(): boolean {\n const zero = useZero();\n return useSyncExternalStore(\n zero.onOnline,\n () => zero.online,\n () => zero.online,\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA,SAAQ,MAAM,UAAU,gBAAe;AAef;AARxB,IAAM,YAAY,KAAK,MAAM,OAAO,yBAAiB,CAAC;AAE/C,SAAS,cAGd,EAAC,KAAI,GAAqC;AAC1C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,SAAO,OACL,oBAAC,YAAS,UAAU,oBAAC,SAAI,kCAAoB,GAC3C;AAAA,IAAC;AAAA;AAAA,MAEC;AAAA,MACA,SAAS,MAAM,QAAQ,KAAK;AAAA;AAAA,EAC9B,GACF,IAEA;AAAA,IAAC;AAAA;AAAA,MACC,SAAS,MAAM,QAAQ,CAAC,IAAI;AAAA,MAC5B,OAAO;AAAA,QACL,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,OAAO;AAAA,QACP,iBAAiB;AAAA,QACjB,qBAAqB;AAAA,QACrB,SAAS;AAAA,MACX;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;;;AC9CA,OAAO,SAAQ,4B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B,eAAK,oBAAoB,SAAS;AAClC,eAAK,kBAAkB;AAAA,QACzB,GAAG,EAAE;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAAA,EAEA,UAAU,KAAgB;AACxB,SAAK,OAAO;AACZ,SAAK,OAAO,UAAU,GAAG;AAAA,EAC3B;AAAA,EAEA,IAAI,WAAW;AACb,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,kBAAiC;AAC/B,WAAO,KAAK,kBAAkB;AAAA,EAChC;AAAA,EAEA,IAAI,WAAW;AACb,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,kBAAiC;AAC/B,WAAO,KAAK,kBAAkB;AAAA,EAChC;AACF;;;AGhkBA,SAAQ,wBAAAE,6BAA2B;AAU5B,SAAS,gBAAyB;AACvC,QAAM,OAAO,QAAQ;AACrB,SAAOC;AAAA,IACL,KAAK;AAAA,IACL,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,EACb;AACF;",
|
|
6
6
|
"names": ["useState", "jsx", "useState", "useSyncExternalStore", "useSyncExternalStore"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-loop.d.ts","sourceRoot":"","sources":["../../../../replicache/src/connection-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sCAAsC,CAAC;AAGpF,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,YAAY,QAAS,CAAC;AAInC,MAAM,WAAW,sBAAsB;IACrC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IAEtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,cAAc;;
|
|
1
|
+
{"version":3,"file":"connection-loop.d.ts","sourceRoot":"","sources":["../../../../replicache/src/connection-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sCAAsC,CAAC;AAGpF,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,YAAY,QAAS,CAAC;AAInC,MAAM,WAAW,sBAAsB;IACrC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IAEtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,cAAc;;gBA2DvB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,sBAAsB,EAChC,iBAAiB,CAAC,EAAE,yBAAyB;IAQ/C,KAAK,IAAI,IAAI;IAQb;;;;OAIG;IACG,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG;QAAC,KAAK,EAAE,OAAO,CAAA;KAAC,CAAC;IAmBzD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAgJ3B"}
|
package/out/solid.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-FH5Q72JS.js";
|
|
2
2
|
import {
|
|
3
3
|
Zero
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-V2KPKXLX.js";
|
|
5
5
|
import "./chunk-MKB4RXL3.js";
|
|
6
6
|
import {
|
|
7
7
|
DEFAULT_TTL_MS,
|
|
8
8
|
applyChange,
|
|
9
9
|
idSymbol
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-MLYQCVBG.js";
|
|
11
11
|
import "./chunk-SGW2EIVJ.js";
|
|
12
12
|
import "./chunk-424PT5DM.js";
|
|
13
13
|
|
|
14
14
|
// ../zero-solid/src/use-query.ts
|
|
15
|
-
import { createComputed, onCleanup as onCleanup2 } from "solid-js";
|
|
15
|
+
import { createComputed, createSignal, onCleanup as onCleanup2 } from "solid-js";
|
|
16
16
|
import { createStore } from "solid-js/store";
|
|
17
17
|
|
|
18
18
|
// ../zero-solid/src/solid-view.ts
|
|
@@ -23,6 +23,7 @@ var SolidView = class {
|
|
|
23
23
|
#input;
|
|
24
24
|
#format;
|
|
25
25
|
#onDestroy;
|
|
26
|
+
#refetch;
|
|
26
27
|
#setState;
|
|
27
28
|
// Optimization: if the store is currently empty we build up
|
|
28
29
|
// the view on a plain old JS object stored at #builderRoot, and return
|
|
@@ -35,12 +36,13 @@ var SolidView = class {
|
|
|
35
36
|
#builderRoot;
|
|
36
37
|
#pendingChanges = [];
|
|
37
38
|
#updateTTL;
|
|
38
|
-
constructor(input, onTransactionCommit, format, onDestroy, queryComplete, updateTTL, setState) {
|
|
39
|
+
constructor(input, onTransactionCommit, format, onDestroy, queryComplete, updateTTL, setState, refetch) {
|
|
39
40
|
this.#input = input;
|
|
40
41
|
onTransactionCommit(this.#onTransactionCommit);
|
|
41
42
|
this.#format = format;
|
|
42
43
|
this.#onDestroy = onDestroy;
|
|
43
44
|
this.#updateTTL = updateTTL;
|
|
45
|
+
this.#refetch = refetch;
|
|
44
46
|
input.setOutput(this);
|
|
45
47
|
const initialRoot = this.#createEmptyRoot();
|
|
46
48
|
this.#applyChangesToRoot(
|
|
@@ -50,20 +52,44 @@ var SolidView = class {
|
|
|
50
52
|
);
|
|
51
53
|
this.#setState = setState;
|
|
52
54
|
this.#setState(
|
|
53
|
-
reconcile(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
reconcile(
|
|
56
|
+
[
|
|
57
|
+
initialRoot,
|
|
58
|
+
queryComplete === true ? COMPLETE : "error" in queryComplete ? this.#makeError(queryComplete) : UNKNOWN
|
|
59
|
+
],
|
|
60
|
+
{
|
|
61
|
+
// solidjs's types want a string, but a symbol works
|
|
62
|
+
key: idSymbol
|
|
63
|
+
}
|
|
64
|
+
)
|
|
57
65
|
);
|
|
58
66
|
if (isEmptyRoot(initialRoot)) {
|
|
59
67
|
this.#builderRoot = this.#createEmptyRoot();
|
|
60
68
|
}
|
|
61
|
-
if (queryComplete !== true) {
|
|
69
|
+
if (queryComplete !== true && !("error" in queryComplete)) {
|
|
62
70
|
void queryComplete.then(() => {
|
|
63
71
|
this.#setState((prev) => [prev[0], COMPLETE]);
|
|
72
|
+
}).catch((error) => {
|
|
73
|
+
this.#setState((prev) => [prev[0], this.#makeError(error)]);
|
|
64
74
|
});
|
|
65
75
|
}
|
|
66
76
|
}
|
|
77
|
+
#makeError(error) {
|
|
78
|
+
return {
|
|
79
|
+
type: "error",
|
|
80
|
+
refetch: this.#refetch,
|
|
81
|
+
error: error.error === "app" || error.error === "zero" ? {
|
|
82
|
+
type: "app",
|
|
83
|
+
queryName: error.name,
|
|
84
|
+
details: error.details
|
|
85
|
+
} : {
|
|
86
|
+
type: "http",
|
|
87
|
+
queryName: error.name,
|
|
88
|
+
status: error.status,
|
|
89
|
+
details: error.details
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
67
93
|
destroy() {
|
|
68
94
|
this.#onDestroy();
|
|
69
95
|
}
|
|
@@ -171,7 +197,7 @@ function isEmptyRoot(entry) {
|
|
|
171
197
|
const data = entry[""];
|
|
172
198
|
return data === void 0 || Array.isArray(data) && data.length === 0;
|
|
173
199
|
}
|
|
174
|
-
function createSolidViewFactory(setState) {
|
|
200
|
+
function createSolidViewFactory(setState, refetch) {
|
|
175
201
|
function solidViewFactory(_query, input, format, onDestroy, onTransactionCommit, queryComplete, updateTTL) {
|
|
176
202
|
return new SolidView(
|
|
177
203
|
input,
|
|
@@ -180,7 +206,9 @@ function createSolidViewFactory(setState) {
|
|
|
180
206
|
onDestroy,
|
|
181
207
|
queryComplete,
|
|
182
208
|
updateTTL,
|
|
183
|
-
setState
|
|
209
|
+
setState,
|
|
210
|
+
refetch || (() => {
|
|
211
|
+
})
|
|
184
212
|
);
|
|
185
213
|
}
|
|
186
214
|
solidViewFactory;
|
|
@@ -248,28 +276,45 @@ function useQuery(querySignal, options) {
|
|
|
248
276
|
},
|
|
249
277
|
UNKNOWN
|
|
250
278
|
]);
|
|
279
|
+
const initialRefetchKey = 0;
|
|
280
|
+
const [refetchKey, setRefetchKey] = createSignal(initialRefetchKey);
|
|
281
|
+
const refetch = () => {
|
|
282
|
+
setRefetchKey((k) => k + 1);
|
|
283
|
+
};
|
|
251
284
|
let view = void 0;
|
|
252
285
|
createComputed(
|
|
253
|
-
([
|
|
286
|
+
([
|
|
287
|
+
prevView,
|
|
288
|
+
prevClientID,
|
|
289
|
+
prevQuery,
|
|
290
|
+
prevQueryHash,
|
|
291
|
+
prevTtl,
|
|
292
|
+
prevRefetchKey
|
|
293
|
+
]) => {
|
|
254
294
|
const zero = useZero()();
|
|
295
|
+
const currentRefetchKey = refetchKey();
|
|
255
296
|
const { clientID } = zero;
|
|
256
297
|
const query = querySignal();
|
|
257
298
|
const queryHash = query.hash();
|
|
258
299
|
const ttl = normalize(options)?.ttl ?? DEFAULT_TTL_MS;
|
|
259
|
-
if (!prevView || clientID !== prevClientID || query !== prevQuery && (clientID === void 0 || query.hash() !== prevQueryHash)) {
|
|
300
|
+
if (!prevView || clientID !== prevClientID || prevRefetchKey !== currentRefetchKey || query !== prevQuery && (clientID === void 0 || query.hash() !== prevQueryHash)) {
|
|
260
301
|
if (prevView) {
|
|
261
302
|
prevView.destroy();
|
|
262
303
|
}
|
|
263
|
-
view = zero.materialize(
|
|
304
|
+
view = zero.materialize(
|
|
305
|
+
query,
|
|
306
|
+
createSolidViewFactory(setState, refetch),
|
|
307
|
+
{ ttl }
|
|
308
|
+
);
|
|
264
309
|
} else {
|
|
265
310
|
view = prevView;
|
|
266
311
|
if (ttl !== prevTtl) {
|
|
267
312
|
view.updateTTL(ttl);
|
|
268
313
|
}
|
|
269
314
|
}
|
|
270
|
-
return [view, clientID, query, queryHash, ttl];
|
|
315
|
+
return [view, clientID, query, queryHash, ttl, currentRefetchKey];
|
|
271
316
|
},
|
|
272
|
-
[void 0, void 0, void 0, void 0, void 0]
|
|
317
|
+
[void 0, void 0, void 0, void 0, void 0, initialRefetchKey]
|
|
273
318
|
);
|
|
274
319
|
onCleanup2(() => {
|
|
275
320
|
view?.destroy();
|
|
@@ -281,10 +326,10 @@ function normalize(options) {
|
|
|
281
326
|
}
|
|
282
327
|
|
|
283
328
|
// ../zero-solid/src/use-zero-online.ts
|
|
284
|
-
import { createSignal, onCleanup as onCleanup3 } from "solid-js";
|
|
329
|
+
import { createSignal as createSignal2, onCleanup as onCleanup3 } from "solid-js";
|
|
285
330
|
function useZeroOnline() {
|
|
286
331
|
const zero = useZero()();
|
|
287
|
-
const [online, setOnline] =
|
|
332
|
+
const [online, setOnline] = createSignal2(zero.online);
|
|
288
333
|
const unsubscribe = zero.onOnline(setOnline);
|
|
289
334
|
onCleanup3(unsubscribe);
|
|
290
335
|
return online;
|
package/out/solid.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../zero-solid/src/use-query.ts", "../../zero-solid/src/solid-view.ts", "../../zero-solid/src/use-zero.ts", "../../zero-solid/src/use-zero-online.ts"],
|
|
4
|
-
"sourcesContent": ["import {createComputed, onCleanup, type Accessor} from 'solid-js';\nimport {createStore} from 'solid-js/store';\nimport {\n type ClientID,\n type HumanReadable,\n type Query,\n type Schema,\n type TTL,\n} from '../../zero/src/zero.ts';\nimport {DEFAULT_TTL_MS} from '../../zql/src/query/ttl.ts';\nimport {\n createSolidViewFactory,\n UNKNOWN,\n type QueryResultDetails,\n type SolidView,\n type State,\n} from './solid-view.ts';\nimport {useZero} from './use-zero.ts';\n\nexport type QueryResult<TReturn> = readonly [\n Accessor<HumanReadable<TReturn>>,\n Accessor<QueryResultDetails>,\n];\n\n// Deprecated in 0.22\n/**\n * @deprecated Use {@linkcode UseQueryOptions} instead.\n */\nexport type CreateQueryOptions = {\n ttl?: TTL | undefined;\n};\n\nexport type UseQueryOptions = {\n ttl?: TTL | undefined;\n};\n\n// Deprecated in 0.22\n/**\n * @deprecated Use {@linkcode useQuery} instead.\n */\nexport function createQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n querySignal: Accessor<Query<TSchema, TTable, TReturn>>,\n options?: CreateQueryOptions | Accessor<CreateQueryOptions>,\n): QueryResult<TReturn> {\n return useQuery(querySignal, options);\n}\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n querySignal: Accessor<Query<TSchema, TTable, TReturn>>,\n options?: UseQueryOptions | Accessor<UseQueryOptions>,\n): QueryResult<TReturn> {\n const [state, setState] = createStore<State>([\n {\n '': undefined,\n },\n UNKNOWN,\n ]);\n\n let view: SolidView | undefined = undefined;\n // Wrap in in createComputed to ensure a new view is created if the querySignal changes.\n createComputed<\n [\n SolidView | undefined,\n ClientID | undefined,\n Query<TSchema, TTable, TReturn> | undefined,\n string | undefined,\n TTL | undefined,\n ]\n >(\n ([prevView, prevClientID, prevQuery, prevQueryHash, prevTtl]) => {\n const zero = useZero()();\n const {clientID} = zero;\n const query = querySignal();\n const queryHash = query.hash();\n const ttl = normalize(options)?.ttl ?? DEFAULT_TTL_MS;\n if (\n !prevView ||\n clientID !== prevClientID ||\n (query !== prevQuery &&\n (clientID === undefined || query.hash() !== prevQueryHash))\n ) {\n if (prevView) {\n prevView.destroy();\n }\n view = zero.materialize(query, createSolidViewFactory(setState), {ttl});\n } else {\n view = prevView;\n if (ttl !== prevTtl) {\n view.updateTTL(ttl);\n }\n }\n\n return [view, clientID, query, queryHash, ttl];\n },\n [undefined, undefined, undefined, undefined, undefined],\n );\n\n onCleanup(() => {\n view?.destroy();\n });\n\n return [() => state[0][''] as HumanReadable<TReturn>, () => state[1]];\n}\n\nfunction normalize<T>(\n options?: T | Accessor<T | undefined> | undefined,\n): T | undefined {\n return typeof options === 'function' ? (options as Accessor<T>)() : options;\n}\n", "import {produce, reconcile, type SetStoreFunction} from 'solid-js/store';\nimport {\n applyChange,\n type Change,\n type Entry,\n type Format,\n type Input,\n type Node,\n type Output,\n type Query,\n type ResultType,\n type Schema,\n type Stream,\n type TTL,\n type ViewChange,\n type ViewFactory,\n} from '../../zero-client/src/mod.js';\nimport {idSymbol} from '../../zql/src/ivm/view-apply-change.ts';\n\nexport type QueryResultDetails = {\n readonly type: ResultType;\n};\n\nexport type State = [Entry, QueryResultDetails];\n\nexport const COMPLETE: QueryResultDetails = Object.freeze({type: 'complete'});\nexport const UNKNOWN: QueryResultDetails = Object.freeze({type: 'unknown'});\n\nexport class SolidView implements Output {\n readonly #input: Input;\n readonly #format: Format;\n readonly #onDestroy: () => void;\n\n #setState: SetStoreFunction<State>;\n\n // Optimization: if the store is currently empty we build up\n // the view on a plain old JS object stored at #builderRoot, and return\n // that for the new state on transaction commit. This avoids building up\n // large views from scratch via solid produce. The proxy object used by\n // solid produce is slow and in this case we don't care about solid tracking\n // the fine grained changes (everything has changed, it's all new). For a\n // test case with a view with 3000 rows, each row having 2 children, this\n // optimization reduced #applyChanges time from 743ms to 133ms.\n #builderRoot: Entry | undefined;\n #pendingChanges: ViewChange[] = [];\n readonly #updateTTL: (ttl: TTL) => void;\n\n constructor(\n input: Input,\n onTransactionCommit: (cb: () => void) => void,\n format: Format,\n onDestroy: () => void,\n queryComplete: true | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n setState: SetStoreFunction<State>,\n ) {\n this.#input = input;\n onTransactionCommit(this.#onTransactionCommit);\n this.#format = format;\n this.#onDestroy = onDestroy;\n this.#updateTTL = updateTTL;\n\n input.setOutput(this);\n\n const initialRoot = this.#createEmptyRoot();\n this.#applyChangesToRoot(\n input.fetch({}),\n node => ({type: 'add', node}),\n initialRoot,\n );\n\n this.#setState = setState;\n this.#setState(\n reconcile([initialRoot, queryComplete === true ? COMPLETE : UNKNOWN], {\n // solidjs's types want a string, but a symbol works\n key: idSymbol as unknown as string,\n }),\n );\n\n if (isEmptyRoot(initialRoot)) {\n this.#builderRoot = this.#createEmptyRoot();\n }\n\n if (queryComplete !== true) {\n void queryComplete.then(() => {\n this.#setState(prev => [prev[0], COMPLETE]);\n });\n }\n }\n\n destroy(): void {\n this.#onDestroy();\n }\n\n #onTransactionCommit = () => {\n const builderRoot = this.#builderRoot;\n if (builderRoot) {\n if (!isEmptyRoot(builderRoot)) {\n this.#setState(\n 0,\n reconcile(builderRoot, {\n // solidjs's types want a string, but a symbol works\n key: idSymbol as unknown as string,\n }),\n );\n this.#setState(prev => [builderRoot, prev[1]]);\n this.#builderRoot = undefined;\n }\n } else {\n try {\n this.#applyChanges(this.#pendingChanges, c => c);\n } finally {\n this.#pendingChanges = [];\n }\n }\n };\n\n push(change: Change): void {\n // Delay updating the solid store state until the transaction commit\n // (because each update of the solid store is quite expensive). If\n // this.#builderRoot is defined apply the changes to it (we are building\n // from an empty root), otherwise queue the changes to be applied\n // using produce at the end of the transaction but read the relationships\n // now as they are only valid to read when the push is received.\n if (this.#builderRoot) {\n this.#applyChangeToRoot(change, this.#builderRoot);\n } else {\n this.#pendingChanges.push(materializeRelationships(change));\n }\n }\n\n #applyChanges<T>(changes: Iterable<T>, mapper: (v: T) => ViewChange): void {\n this.#setState(\n produce((draftState: State) => {\n this.#applyChangesToRoot<T>(changes, mapper, draftState[0]);\n if (isEmptyRoot(draftState[0])) {\n this.#builderRoot = this.#createEmptyRoot();\n }\n }),\n );\n }\n\n #applyChangesToRoot<T>(\n changes: Iterable<T>,\n mapper: (v: T) => ViewChange,\n root: Entry,\n ) {\n for (const change of changes) {\n this.#applyChangeToRoot(mapper(change), root);\n }\n }\n\n #applyChangeToRoot(change: ViewChange, root: Entry) {\n applyChange(\n root,\n change,\n this.#input.getSchema(),\n '',\n this.#format,\n true /* withIDs */,\n );\n }\n\n #createEmptyRoot(): Entry {\n return {\n '': this.#format.singular ? undefined : [],\n };\n }\n\n updateTTL(ttl: TTL): void {\n this.#updateTTL(ttl);\n }\n}\n\nfunction materializeRelationships(change: Change): ViewChange {\n switch (change.type) {\n case 'add':\n return {type: 'add', node: materializeNodeRelationships(change.node)};\n case 'remove':\n return {type: 'remove', node: materializeNodeRelationships(change.node)};\n case 'child':\n return {\n type: 'child',\n node: {row: change.node.row},\n child: {\n relationshipName: change.child.relationshipName,\n change: materializeRelationships(change.child.change),\n },\n };\n case 'edit':\n return {\n type: 'edit',\n node: {row: change.node.row},\n oldNode: {row: change.oldNode.row},\n };\n }\n}\n\nfunction materializeNodeRelationships(node: Node): Node {\n const relationships: Record<string, () => Stream<Node>> = {};\n for (const relationship in node.relationships) {\n const materialized: Node[] = [];\n for (const n of node.relationships[relationship]()) {\n materialized.push(materializeNodeRelationships(n));\n }\n relationships[relationship] = () => materialized;\n }\n return {\n row: node.row,\n relationships,\n };\n}\n\nfunction isEmptyRoot(entry: Entry) {\n const data = entry[''];\n return data === undefined || (Array.isArray(data) && data.length === 0);\n}\n\nexport function createSolidViewFactory(setState: SetStoreFunction<State>) {\n function solidViewFactory<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n >(\n _query: Query<TSchema, TTable, TReturn>,\n input: Input,\n format: Format,\n onDestroy: () => void,\n onTransactionCommit: (cb: () => void) => void,\n queryComplete: true | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n ) {\n return new SolidView(\n input,\n onTransactionCommit,\n format,\n onDestroy,\n queryComplete,\n updateTTL,\n setState,\n );\n }\n\n solidViewFactory satisfies ViewFactory<Schema, string, unknown, unknown>;\n\n return solidViewFactory;\n}\n", "import {\n batch,\n createContext,\n createMemo,\n onCleanup,\n splitProps,\n useContext,\n type Accessor,\n type JSX,\n} from 'solid-js';\nimport {\n Zero,\n type CustomMutatorDefs,\n type Schema,\n type ZeroOptions,\n} from '../../zero/src/zero.ts';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any\nconst ZeroContext = createContext<Accessor<Zero<any, any>> | undefined>(\n undefined,\n);\n\nexport function createZero<S extends Schema, MD extends CustomMutatorDefs>(\n options: ZeroOptions<S, MD>,\n): Zero<S, MD> {\n const opts = {\n ...options,\n batchViewUpdates: batch,\n };\n return new Zero(opts);\n}\n\nexport function useZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>(): () => Zero<S, MD> {\n const zero = useContext(ZeroContext);\n\n if (zero === undefined) {\n throw new Error('useZero must be used within a ZeroProvider');\n }\n return zero;\n}\n\nexport function createUseZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>() {\n return () => useZero<S, MD>();\n}\n\nexport function ZeroProvider<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>(\n props: {children: JSX.Element} & (\n | {\n zero: Zero<S, MD>;\n }\n | ZeroOptions<S, MD>\n ),\n) {\n const zero = createMemo(() => {\n if ('zero' in props) {\n return props.zero;\n }\n const [, options] = splitProps(props, ['children']);\n const createdZero = new Zero({\n ...options,\n batchViewUpdates: batch,\n });\n onCleanup(() => createdZero.close());\n return createdZero;\n });\n\n return ZeroContext.Provider({\n value: zero,\n get children() {\n return props.children;\n },\n });\n}\n", "import {createSignal, onCleanup, type Accessor} from 'solid-js';\nimport {useZero} from './use-zero.ts';\n\n/**\n * Tracks the online status of the current Zero instance.\n *\n * @returns An accessor \u2014 call `online()` to get a reactive `boolean`.\n *\n * @example\n * const online = useZeroOnline();\n *\n * <span>\n * {online() ? 'Online' : 'Offline'}\n * </span>\n */\nexport function useZeroOnline(): Accessor<boolean> {\n const zero = useZero()();\n\n const [online, setOnline] = createSignal<boolean>(zero.online);\n\n const unsubscribe = zero.onOnline(setOnline);\n\n onCleanup(unsubscribe);\n\n return online;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAAA,SAAQ,gBAAgB,aAAAA,kBAA+B;
|
|
6
|
-
"names": ["onCleanup", "onCleanup", "onCleanup", "onCleanup"]
|
|
4
|
+
"sourcesContent": ["import {createComputed, createSignal, onCleanup, type Accessor} from 'solid-js';\nimport {createStore} from 'solid-js/store';\nimport {\n type ClientID,\n type HumanReadable,\n type Query,\n type Schema,\n type TTL,\n} from '../../zero/src/zero.ts';\nimport {DEFAULT_TTL_MS} from '../../zql/src/query/ttl.ts';\nimport {\n createSolidViewFactory,\n UNKNOWN,\n type QueryResultDetails,\n type SolidView,\n type State,\n} from './solid-view.ts';\nimport {useZero} from './use-zero.ts';\n\nexport type QueryResult<TReturn> = readonly [\n Accessor<HumanReadable<TReturn>>,\n Accessor<QueryResultDetails>,\n];\n\n// Deprecated in 0.22\n/**\n * @deprecated Use {@linkcode UseQueryOptions} instead.\n */\nexport type CreateQueryOptions = {\n ttl?: TTL | undefined;\n};\n\nexport type UseQueryOptions = {\n ttl?: TTL | undefined;\n};\n\n// Deprecated in 0.22\n/**\n * @deprecated Use {@linkcode useQuery} instead.\n */\nexport function createQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n querySignal: Accessor<Query<TSchema, TTable, TReturn>>,\n options?: CreateQueryOptions | Accessor<CreateQueryOptions>,\n): QueryResult<TReturn> {\n return useQuery(querySignal, options);\n}\n\nexport function useQuery<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n>(\n querySignal: Accessor<Query<TSchema, TTable, TReturn>>,\n options?: UseQueryOptions | Accessor<UseQueryOptions>,\n): QueryResult<TReturn> {\n const [state, setState] = createStore<State>([\n {\n '': undefined,\n },\n UNKNOWN,\n ]);\n const initialRefetchKey = 0;\n const [refetchKey, setRefetchKey] = createSignal(initialRefetchKey);\n\n const refetch = () => {\n setRefetchKey(k => k + 1);\n };\n\n let view: SolidView | undefined = undefined;\n\n // Wrap in in createComputed to ensure a new view is created if the querySignal changes.\n createComputed<\n [\n SolidView | undefined,\n ClientID | undefined,\n Query<TSchema, TTable, TReturn> | undefined,\n string | undefined,\n TTL | undefined,\n number,\n ]\n >(\n ([\n prevView,\n prevClientID,\n prevQuery,\n prevQueryHash,\n prevTtl,\n prevRefetchKey,\n ]) => {\n const zero = useZero()();\n const currentRefetchKey = refetchKey(); // depend on refetchKey to force re-evaluation\n const {clientID} = zero;\n const query = querySignal();\n const queryHash = query.hash();\n const ttl = normalize(options)?.ttl ?? DEFAULT_TTL_MS;\n if (\n !prevView ||\n clientID !== prevClientID ||\n prevRefetchKey !== currentRefetchKey ||\n (query !== prevQuery &&\n (clientID === undefined || query.hash() !== prevQueryHash))\n ) {\n if (prevView) {\n prevView.destroy();\n }\n view = zero.materialize(\n query,\n createSolidViewFactory(setState, refetch),\n {ttl},\n );\n } else {\n view = prevView;\n if (ttl !== prevTtl) {\n view.updateTTL(ttl);\n }\n }\n\n return [view, clientID, query, queryHash, ttl, currentRefetchKey];\n },\n [undefined, undefined, undefined, undefined, undefined, initialRefetchKey],\n );\n\n onCleanup(() => {\n view?.destroy();\n });\n\n return [() => state[0][''] as HumanReadable<TReturn>, () => state[1]];\n}\n\nfunction normalize<T>(\n options?: T | Accessor<T | undefined> | undefined,\n): T | undefined {\n return typeof options === 'function' ? (options as Accessor<T>)() : options;\n}\n", "import {produce, reconcile, type SetStoreFunction} from 'solid-js/store';\nimport {\n applyChange,\n type Change,\n type Entry,\n type Format,\n type Input,\n type Node,\n type Output,\n type Query,\n type Schema,\n type Stream,\n type TTL,\n type ViewChange,\n type ViewFactory,\n} from '../../zero-client/src/mod.js';\nimport {idSymbol} from '../../zql/src/ivm/view-apply-change.ts';\nimport type {ReadonlyJSONValue} from '../../shared/src/json.ts';\nimport type {ErroredQuery} from '../../zero-protocol/src/custom-queries.ts';\n\nexport type QueryResultDetails = Readonly<\n | {\n type: 'complete';\n }\n | {\n type: 'unknown';\n }\n | QueryErrorDetails\n>;\n\ntype QueryErrorDetails = {\n type: 'error';\n refetch: () => void;\n error:\n | {\n type: 'app';\n queryName: string;\n details: ReadonlyJSONValue;\n }\n | {\n type: 'http';\n queryName: string;\n status: number;\n details: ReadonlyJSONValue;\n };\n};\n\nexport type State = [Entry, QueryResultDetails];\n\nexport const COMPLETE: QueryResultDetails = Object.freeze({type: 'complete'});\nexport const UNKNOWN: QueryResultDetails = Object.freeze({type: 'unknown'});\n\nexport class SolidView implements Output {\n readonly #input: Input;\n readonly #format: Format;\n readonly #onDestroy: () => void;\n readonly #refetch: () => void;\n\n #setState: SetStoreFunction<State>;\n\n // Optimization: if the store is currently empty we build up\n // the view on a plain old JS object stored at #builderRoot, and return\n // that for the new state on transaction commit. This avoids building up\n // large views from scratch via solid produce. The proxy object used by\n // solid produce is slow and in this case we don't care about solid tracking\n // the fine grained changes (everything has changed, it's all new). For a\n // test case with a view with 3000 rows, each row having 2 children, this\n // optimization reduced #applyChanges time from 743ms to 133ms.\n #builderRoot: Entry | undefined;\n #pendingChanges: ViewChange[] = [];\n readonly #updateTTL: (ttl: TTL) => void;\n\n constructor(\n input: Input,\n onTransactionCommit: (cb: () => void) => void,\n format: Format,\n onDestroy: () => void,\n queryComplete: true | ErroredQuery | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n setState: SetStoreFunction<State>,\n refetch: () => void,\n ) {\n this.#input = input;\n onTransactionCommit(this.#onTransactionCommit);\n this.#format = format;\n this.#onDestroy = onDestroy;\n this.#updateTTL = updateTTL;\n this.#refetch = refetch;\n\n input.setOutput(this);\n\n const initialRoot = this.#createEmptyRoot();\n this.#applyChangesToRoot(\n input.fetch({}),\n node => ({type: 'add', node}),\n initialRoot,\n );\n\n this.#setState = setState;\n this.#setState(\n reconcile(\n [\n initialRoot,\n queryComplete === true\n ? COMPLETE\n : 'error' in queryComplete\n ? this.#makeError(queryComplete)\n : UNKNOWN,\n ],\n {\n // solidjs's types want a string, but a symbol works\n key: idSymbol as unknown as string,\n },\n ),\n );\n\n if (isEmptyRoot(initialRoot)) {\n this.#builderRoot = this.#createEmptyRoot();\n }\n\n if (queryComplete !== true && !('error' in queryComplete)) {\n void queryComplete\n .then(() => {\n this.#setState(prev => [prev[0], COMPLETE]);\n })\n .catch((error: ErroredQuery) => {\n this.#setState(prev => [prev[0], this.#makeError(error)]);\n });\n }\n }\n\n #makeError(error: ErroredQuery): QueryErrorDetails {\n return {\n type: 'error',\n refetch: this.#refetch,\n error:\n error.error === 'app' || error.error === 'zero'\n ? {\n type: 'app',\n queryName: error.name,\n details: error.details,\n }\n : {\n type: 'http',\n queryName: error.name,\n status: error.status,\n details: error.details,\n },\n };\n }\n\n destroy(): void {\n this.#onDestroy();\n }\n\n #onTransactionCommit = () => {\n const builderRoot = this.#builderRoot;\n if (builderRoot) {\n if (!isEmptyRoot(builderRoot)) {\n this.#setState(\n 0,\n reconcile(builderRoot, {\n // solidjs's types want a string, but a symbol works\n key: idSymbol as unknown as string,\n }),\n );\n this.#setState(prev => [builderRoot, prev[1]]);\n this.#builderRoot = undefined;\n }\n } else {\n try {\n this.#applyChanges(this.#pendingChanges, c => c);\n } finally {\n this.#pendingChanges = [];\n }\n }\n };\n\n push(change: Change): void {\n // Delay updating the solid store state until the transaction commit\n // (because each update of the solid store is quite expensive). If\n // this.#builderRoot is defined apply the changes to it (we are building\n // from an empty root), otherwise queue the changes to be applied\n // using produce at the end of the transaction but read the relationships\n // now as they are only valid to read when the push is received.\n if (this.#builderRoot) {\n this.#applyChangeToRoot(change, this.#builderRoot);\n } else {\n this.#pendingChanges.push(materializeRelationships(change));\n }\n }\n\n #applyChanges<T>(changes: Iterable<T>, mapper: (v: T) => ViewChange): void {\n this.#setState(\n produce((draftState: State) => {\n this.#applyChangesToRoot<T>(changes, mapper, draftState[0]);\n if (isEmptyRoot(draftState[0])) {\n this.#builderRoot = this.#createEmptyRoot();\n }\n }),\n );\n }\n\n #applyChangesToRoot<T>(\n changes: Iterable<T>,\n mapper: (v: T) => ViewChange,\n root: Entry,\n ) {\n for (const change of changes) {\n this.#applyChangeToRoot(mapper(change), root);\n }\n }\n\n #applyChangeToRoot(change: ViewChange, root: Entry) {\n applyChange(\n root,\n change,\n this.#input.getSchema(),\n '',\n this.#format,\n true /* withIDs */,\n );\n }\n\n #createEmptyRoot(): Entry {\n return {\n '': this.#format.singular ? undefined : [],\n };\n }\n\n updateTTL(ttl: TTL): void {\n this.#updateTTL(ttl);\n }\n}\n\nfunction materializeRelationships(change: Change): ViewChange {\n switch (change.type) {\n case 'add':\n return {type: 'add', node: materializeNodeRelationships(change.node)};\n case 'remove':\n return {type: 'remove', node: materializeNodeRelationships(change.node)};\n case 'child':\n return {\n type: 'child',\n node: {row: change.node.row},\n child: {\n relationshipName: change.child.relationshipName,\n change: materializeRelationships(change.child.change),\n },\n };\n case 'edit':\n return {\n type: 'edit',\n node: {row: change.node.row},\n oldNode: {row: change.oldNode.row},\n };\n }\n}\n\nfunction materializeNodeRelationships(node: Node): Node {\n const relationships: Record<string, () => Stream<Node>> = {};\n for (const relationship in node.relationships) {\n const materialized: Node[] = [];\n for (const n of node.relationships[relationship]()) {\n materialized.push(materializeNodeRelationships(n));\n }\n relationships[relationship] = () => materialized;\n }\n return {\n row: node.row,\n relationships,\n };\n}\n\nfunction isEmptyRoot(entry: Entry) {\n const data = entry[''];\n return data === undefined || (Array.isArray(data) && data.length === 0);\n}\n\nexport function createSolidViewFactory(\n setState: SetStoreFunction<State>,\n refetch?: () => void,\n) {\n function solidViewFactory<\n TSchema extends Schema,\n TTable extends keyof TSchema['tables'] & string,\n TReturn,\n >(\n _query: Query<TSchema, TTable, TReturn>,\n input: Input,\n format: Format,\n onDestroy: () => void,\n onTransactionCommit: (cb: () => void) => void,\n queryComplete: true | ErroredQuery | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n ) {\n return new SolidView(\n input,\n onTransactionCommit,\n format,\n onDestroy,\n queryComplete,\n updateTTL,\n setState,\n refetch || (() => {}),\n );\n }\n\n solidViewFactory satisfies ViewFactory<Schema, string, unknown, unknown>;\n\n return solidViewFactory;\n}\n", "import {\n batch,\n createContext,\n createMemo,\n onCleanup,\n splitProps,\n useContext,\n type Accessor,\n type JSX,\n} from 'solid-js';\nimport {\n Zero,\n type CustomMutatorDefs,\n type Schema,\n type ZeroOptions,\n} from '../../zero/src/zero.ts';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any\nconst ZeroContext = createContext<Accessor<Zero<any, any>> | undefined>(\n undefined,\n);\n\nexport function createZero<S extends Schema, MD extends CustomMutatorDefs>(\n options: ZeroOptions<S, MD>,\n): Zero<S, MD> {\n const opts = {\n ...options,\n batchViewUpdates: batch,\n };\n return new Zero(opts);\n}\n\nexport function useZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>(): () => Zero<S, MD> {\n const zero = useContext(ZeroContext);\n\n if (zero === undefined) {\n throw new Error('useZero must be used within a ZeroProvider');\n }\n return zero;\n}\n\nexport function createUseZero<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>() {\n return () => useZero<S, MD>();\n}\n\nexport function ZeroProvider<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined = undefined,\n>(\n props: {children: JSX.Element} & (\n | {\n zero: Zero<S, MD>;\n }\n | ZeroOptions<S, MD>\n ),\n) {\n const zero = createMemo(() => {\n if ('zero' in props) {\n return props.zero;\n }\n const [, options] = splitProps(props, ['children']);\n const createdZero = new Zero({\n ...options,\n batchViewUpdates: batch,\n });\n onCleanup(() => createdZero.close());\n return createdZero;\n });\n\n return ZeroContext.Provider({\n value: zero,\n get children() {\n return props.children;\n },\n });\n}\n", "import {createSignal, onCleanup, type Accessor} from 'solid-js';\nimport {useZero} from './use-zero.ts';\n\n/**\n * Tracks the online status of the current Zero instance.\n *\n * @returns An accessor \u2014 call `online()` to get a reactive `boolean`.\n *\n * @example\n * const online = useZeroOnline();\n *\n * <span>\n * {online() ? 'Online' : 'Offline'}\n * </span>\n */\nexport function useZeroOnline(): Accessor<boolean> {\n const zero = useZero()();\n\n const [online, setOnline] = createSignal<boolean>(zero.online);\n\n const unsubscribe = zero.onOnline(setOnline);\n\n onCleanup(unsubscribe);\n\n return online;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA,SAAQ,gBAAgB,cAAc,aAAAA,kBAA+B;AACrE,SAAQ,mBAAkB;;;ACD1B,SAAQ,SAAS,iBAAuC;AAiDjD,IAAM,WAA+B,OAAO,OAAO,EAAC,MAAM,WAAU,CAAC;AACrE,IAAM,UAA8B,OAAO,OAAO,EAAC,MAAM,UAAS,CAAC;AAEnE,IAAM,YAAN,MAAkC;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA,EACA,kBAAgC,CAAC;AAAA,EACxB;AAAA,EAET,YACE,OACA,qBACA,QACA,WACA,eACA,WACA,UACA,SACA;AACA,SAAK,SAAS;AACd,wBAAoB,KAAK,oBAAoB;AAC7C,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,aAAa;AAClB,SAAK,WAAW;AAEhB,UAAM,UAAU,IAAI;AAEpB,UAAM,cAAc,KAAK,iBAAiB;AAC1C,SAAK;AAAA,MACH,MAAM,MAAM,CAAC,CAAC;AAAA,MACd,WAAS,EAAC,MAAM,OAAO,KAAI;AAAA,MAC3B;AAAA,IACF;AAEA,SAAK,YAAY;AACjB,SAAK;AAAA,MACH;AAAA,QACE;AAAA,UACE;AAAA,UACA,kBAAkB,OACd,WACA,WAAW,gBACT,KAAK,WAAW,aAAa,IAC7B;AAAA,QACR;AAAA,QACA;AAAA;AAAA,UAEE,KAAK;AAAA,QACP;AAAA,MACF;AAAA,IACF;AAEA,QAAI,YAAY,WAAW,GAAG;AAC5B,WAAK,eAAe,KAAK,i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AAK,MAAM,gBAC9C;AACA,YAAI,UAAU;AACZ,mBAAS,QAAQ;AAAA,QACnB;AACA,eAAO,KAAK;AAAA,UACV;AAAA,UACA,uBAAuB,UAAU,OAAO;AAAA,UACxC,EAAC,IAAG;AAAA,QACN;AAAA,MACF,OAAO;AACL,eAAO;AACP,YAAI,QAAQ,SAAS;AACnB,eAAK,UAAU,GAAG;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,CAAC,MAAM,UAAU,OAAO,WAAW,KAAK,iBAAiB;AAAA,IAClE;AAAA,IACA,CAAC,QAAW,QAAW,QAAW,QAAW,QAAW,iBAAiB;AAAA,EAC3E;AAEA,EAAAC,WAAU,MAAM;AACd,UAAM,QAAQ;AAAA,EAChB,CAAC;AAED,SAAO,CAAC,MAAM,MAAM,CAAC,EAAE,EAAE,GAA6B,MAAM,MAAM,CAAC,CAAC;AACtE;AAEA,SAAS,UACP,SACe;AACf,SAAO,OAAO,YAAY,aAAc,QAAwB,IAAI;AACtE;;;AGzIA,SAAQ,gBAAAC,eAAc,aAAAC,kBAA+B;AAe9C,SAAS,gBAAmC;AACjD,QAAM,OAAO,QAAQ,EAAE;AAEvB,QAAM,CAAC,QAAQ,SAAS,IAAIC,cAAsB,KAAK,MAAM;AAE7D,QAAM,cAAc,KAAK,SAAS,SAAS;AAE3C,EAAAC,WAAU,WAAW;AAErB,SAAO;AACT;",
|
|
6
|
+
"names": ["onCleanup", "onCleanup", "createSignal", "onCleanup", "createSignal", "onCleanup"]
|
|
7
7
|
}
|
package/out/zero/package.json
CHANGED
|
@@ -15,7 +15,7 @@ import { compile, sql } from "../../../zqlite/src/internal/sql.js";
|
|
|
15
15
|
import { fromSQLiteTypes, TableSource, } from "../../../zqlite/src/table-source.js";
|
|
16
16
|
import { computeZqlSpecs } from "../db/lite-tables.js";
|
|
17
17
|
import { StatementRunner } from "../db/statements.js";
|
|
18
|
-
import { DatabaseStorage, } from "
|
|
18
|
+
import { DatabaseStorage, } from "../../../zqlite/src/database-storage.js";
|
|
19
19
|
import { mapLiteDataTypeToZqlSchemaValue } from "../types/lite.js";
|
|
20
20
|
import { getSchema, reloadPermissionsIfChanged, } from "./load-permissions.js";
|
|
21
21
|
export class WriteAuthorizerImpl {
|