syncorejs 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_vendor/cli/app.d.mts.map +1 -1
- package/dist/_vendor/cli/app.mjs +8 -5
- package/dist/_vendor/cli/app.mjs.map +1 -1
- package/dist/_vendor/cli/context.mjs.map +1 -1
- package/dist/_vendor/cli/dev-session.mjs.map +1 -1
- package/dist/_vendor/cli/doctor.mjs.map +1 -1
- package/dist/_vendor/cli/errors.mjs.map +1 -1
- package/dist/_vendor/cli/help.mjs.map +1 -1
- package/dist/_vendor/cli/index.mjs +9 -2
- package/dist/_vendor/cli/index.mjs.map +1 -1
- package/dist/_vendor/cli/messages.mjs.map +1 -1
- package/dist/_vendor/cli/preflight.mjs.map +1 -1
- package/dist/_vendor/cli/project.mjs +20 -20
- package/dist/_vendor/cli/project.mjs.map +1 -1
- package/dist/_vendor/cli/render.mjs.map +1 -1
- package/dist/_vendor/cli/targets.mjs.map +1 -1
- package/dist/_vendor/core/cli.d.mts +8 -2
- package/dist/_vendor/core/cli.d.mts.map +1 -1
- package/dist/_vendor/core/cli.mjs +510 -71
- package/dist/_vendor/core/cli.mjs.map +1 -1
- package/dist/_vendor/core/devtools-auth.mjs.map +1 -1
- package/dist/_vendor/core/index.d.mts +3 -3
- package/dist/_vendor/core/runtime/components.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/components.mjs.map +1 -1
- package/dist/_vendor/core/runtime/devtools.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/devtools.mjs +261 -23
- package/dist/_vendor/core/runtime/devtools.mjs.map +1 -1
- package/dist/_vendor/core/runtime/functions.d.mts +388 -6
- package/dist/_vendor/core/runtime/functions.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/functions.mjs +72 -1
- package/dist/_vendor/core/runtime/functions.mjs.map +1 -1
- package/dist/_vendor/core/runtime/id.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/id.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs +12 -6
- package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs +123 -20
- package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs +56 -8
- package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs +49 -14
- package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs +4 -7
- package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/shared.mjs +81 -2
- package/dist/_vendor/core/runtime/internal/engines/shared.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs +100 -13
- package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs +42 -7
- package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/runtimeStatus.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/systemMeta.mjs.map +1 -1
- package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs +4 -0
- package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs.map +1 -1
- package/dist/_vendor/core/runtime/runtime.d.mts +1100 -12
- package/dist/_vendor/core/runtime/runtime.d.mts.map +1 -1
- package/dist/_vendor/core/runtime/runtime.mjs +63 -0
- package/dist/_vendor/core/runtime/runtime.mjs.map +1 -1
- package/dist/_vendor/core/transport.d.mts +2 -0
- package/dist/_vendor/core/transport.d.mts.map +1 -1
- package/dist/_vendor/core/transport.mjs +61 -27
- package/dist/_vendor/core/transport.mjs.map +1 -1
- package/dist/_vendor/devtools-protocol/index.d.ts +223 -4
- package/dist/_vendor/devtools-protocol/index.d.ts.map +1 -1
- package/dist/_vendor/devtools-protocol/index.js.map +1 -1
- package/dist/_vendor/next/config.d.ts +3 -4
- package/dist/_vendor/next/config.d.ts.map +1 -1
- package/dist/_vendor/next/config.js +37 -19
- package/dist/_vendor/next/config.js.map +1 -1
- package/dist/_vendor/next/index.d.ts +109 -29
- package/dist/_vendor/next/index.d.ts.map +1 -1
- package/dist/_vendor/next/index.js +86 -18
- package/dist/_vendor/next/index.js.map +1 -1
- package/dist/_vendor/platform-expo/index.d.ts +146 -27
- package/dist/_vendor/platform-expo/index.d.ts.map +1 -1
- package/dist/_vendor/platform-expo/index.js +81 -10
- package/dist/_vendor/platform-expo/index.js.map +1 -1
- package/dist/_vendor/platform-expo/react.js.map +1 -1
- package/dist/_vendor/platform-expo/web-sqljs-wasm.js +16 -0
- package/dist/_vendor/platform-expo/web-sqljs-wasm.js.map +1 -0
- package/dist/_vendor/platform-node/index.d.mts +174 -9
- package/dist/_vendor/platform-node/index.d.mts.map +1 -1
- package/dist/_vendor/platform-node/index.mjs +251 -95
- package/dist/_vendor/platform-node/index.mjs.map +1 -1
- package/dist/_vendor/platform-node/ipc-react.mjs +4 -0
- package/dist/_vendor/platform-node/ipc-react.mjs.map +1 -1
- package/dist/_vendor/platform-node/ipc.d.mts.map +1 -1
- package/dist/_vendor/platform-node/ipc.mjs.map +1 -1
- package/dist/_vendor/platform-web/external-change.d.ts +41 -0
- package/dist/_vendor/platform-web/external-change.d.ts.map +1 -1
- package/dist/_vendor/platform-web/external-change.js +30 -0
- package/dist/_vendor/platform-web/external-change.js.map +1 -1
- package/dist/_vendor/platform-web/index.d.ts +312 -37
- package/dist/_vendor/platform-web/index.d.ts.map +1 -1
- package/dist/_vendor/platform-web/index.js +247 -25
- package/dist/_vendor/platform-web/index.js.map +1 -1
- package/dist/_vendor/platform-web/indexeddb.d.ts +12 -0
- package/dist/_vendor/platform-web/indexeddb.d.ts.map +1 -1
- package/dist/_vendor/platform-web/indexeddb.js +10 -0
- package/dist/_vendor/platform-web/indexeddb.js.map +1 -1
- package/dist/_vendor/platform-web/opfs.d.ts +16 -1
- package/dist/_vendor/platform-web/opfs.d.ts.map +1 -1
- package/dist/_vendor/platform-web/opfs.js +41 -3
- package/dist/_vendor/platform-web/opfs.js.map +1 -1
- package/dist/_vendor/platform-web/persistence.d.ts +85 -1
- package/dist/_vendor/platform-web/persistence.d.ts.map +1 -1
- package/dist/_vendor/platform-web/persistence.js +15 -0
- package/dist/_vendor/platform-web/persistence.js.map +1 -1
- package/dist/_vendor/platform-web/react.d.ts +1 -2
- package/dist/_vendor/platform-web/react.d.ts.map +1 -1
- package/dist/_vendor/platform-web/react.js +11 -5
- package/dist/_vendor/platform-web/react.js.map +1 -1
- package/dist/_vendor/platform-web/sqljs.js +10 -1
- package/dist/_vendor/platform-web/sqljs.js.map +1 -1
- package/dist/_vendor/platform-web/web-sqljs-wasm.js +8 -0
- package/dist/_vendor/platform-web/web-sqljs-wasm.js.map +1 -0
- package/dist/_vendor/platform-web/worker.d.ts +60 -9
- package/dist/_vendor/platform-web/worker.d.ts.map +1 -1
- package/dist/_vendor/platform-web/worker.js +37 -4
- package/dist/_vendor/platform-web/worker.js.map +1 -1
- package/dist/_vendor/react/index.d.ts +197 -13
- package/dist/_vendor/react/index.d.ts.map +1 -1
- package/dist/_vendor/react/index.js +209 -17
- package/dist/_vendor/react/index.js.map +1 -1
- package/dist/_vendor/schema/definition.d.ts +129 -0
- package/dist/_vendor/schema/definition.d.ts.map +1 -1
- package/dist/_vendor/schema/definition.js +99 -0
- package/dist/_vendor/schema/definition.js.map +1 -1
- package/dist/_vendor/schema/planner.d.ts.map +1 -1
- package/dist/_vendor/schema/planner.js.map +1 -1
- package/dist/_vendor/schema/validators.d.ts +180 -4
- package/dist/_vendor/schema/validators.d.ts.map +1 -1
- package/dist/_vendor/schema/validators.js +35 -1
- package/dist/_vendor/schema/validators.js.map +1 -1
- package/dist/_vendor/svelte/index.d.ts +207 -7
- package/dist/_vendor/svelte/index.d.ts.map +1 -1
- package/dist/_vendor/svelte/index.js +201 -6
- package/dist/_vendor/svelte/index.js.map +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +24 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n derived,\n type Readable,\n readable,\n type StartStopNotifier\n} from \"svelte/store\";\nimport { getContext, setContext } from \"svelte\";\nimport type {\n FunctionArgs,\n FunctionReference,\n FunctionResult,\n PaginationOptions,\n PaginationResult,\n SyncoreClient,\n SyncoreQueryState,\n SyncoreRuntimeStatus,\n SyncoreWatch,\n UsePaginatedQueryResult\n} from \"@syncore/core\";\n\nexport type OptionalArgsTuple<TArgs> =\n Record<never, never> extends TArgs ? [args?: TArgs] : [args: TArgs];\n\ntype ManagedSyncoreWatch<TResult> = SyncoreWatch<TResult> & {\n dispose?: () => void;\n};\n\ntype QueryRequestInput<\n TReference extends FunctionReference<\"query\"> = FunctionReference<\"query\">\n> = Record<never, never> extends FunctionArgs<TReference>\n ? {\n query: TReference;\n args?: FunctionArgs<TReference> | Skip;\n }\n : {\n query: TReference;\n args: FunctionArgs<TReference> | Skip;\n };\n\ntype QueriesRequestInput = Record<string, QueryRequestInput>;\n\ntype QueryStateForEntry<TEntry> = TEntry extends QueryRequestInput<\n infer TReference\n>\n ? SyncoreQueryState<FunctionResult<TReference>>\n : never;\n\nexport type CreateQueriesStoreResult<TEntries extends QueriesRequestInput> = {\n [TKey in keyof TEntries]: QueryStateForEntry<TEntries[TKey]>;\n};\n\ntype PaginatedQueryReference = FunctionReference<\n \"query\",\n Record<string, unknown>,\n PaginationResult<unknown>\n>;\n\ntype PaginatedQueryArgs<TReference extends FunctionReference<\"query\">> =\n FunctionArgs<TReference> extends { paginationOpts: PaginationOptions }\n ? Omit<FunctionArgs<TReference>, \"paginationOpts\">\n : never;\n\ntype PaginatedQueryItem<TReference extends FunctionReference<\"query\">> =\n FunctionResult<TReference> extends PaginationResult<infer TItem>\n ? TItem\n : never;\n\ntype PaginatedQueryInternalState = {\n nextPageKey: number;\n pages: Array<{\n key: string;\n cursor: string | null;\n numItems: number;\n }>;\n};\n\n/**\n * The reactive query state shape exposed by Syncore's Svelte stores.\n */\nexport interface SyncoreQueryStoreState<TResult>\n extends SyncoreQueryState<TResult> {}\n\nexport const skip = \"skip\" as const;\ntype Skip = typeof skip;\n\nconst defaultRuntimeStatus: SyncoreRuntimeStatus = {\n kind: \"starting\",\n reason: \"booting\"\n};\n\nconst SYNCORE_CLIENT_CONTEXT = Symbol(\"syncore.client\");\n\n/**\n * Stores a Syncore client in Svelte component context and returns it.\n */\nexport function setSyncoreClient(client: SyncoreClient): SyncoreClient {\n setContext(SYNCORE_CLIENT_CONTEXT, client);\n return client;\n}\n\n/**\n * Reads the Syncore client previously stored in Svelte component context.\n */\nexport function getSyncoreClient(): SyncoreClient {\n const client = getContext<SyncoreClient | undefined>(SYNCORE_CLIENT_CONTEXT);\n if (!client) {\n throw new Error(\n \"Syncore client is missing from the Svelte component context.\"\n );\n }\n return client;\n}\n\nexport function createSyncoreStatusStore(): Readable<SyncoreRuntimeStatus> {\n return createClientSyncoreStatusStore(getSyncoreClient());\n}\n\nexport function createClientSyncoreStatusStore(\n client: SyncoreClient\n): Readable<SyncoreRuntimeStatus> {\n return readable<SyncoreRuntimeStatus>(\n defaultRuntimeStatus,\n createStatusStoreStart(client)\n );\n}\n\n/**\n * Creates a reactive store for a Syncore query result using the contextual client.\n */\nexport function createQueryValueStore<\n TReference extends FunctionReference<\"query\">\n>(\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<FunctionResult<TReference> | undefined> {\n return createClientQueryValueStore(getSyncoreClient(), reference, ...args);\n}\n\n/**\n * Creates a reactive store for a Syncore query result using an explicit client.\n */\nexport function createClientQueryValueStore<\n TReference extends FunctionReference<\"query\">\n>(\n client: SyncoreClient,\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<FunctionResult<TReference> | undefined> {\n return derived(\n createClientQueryStore(client, reference, ...(args as OptionalArgsTuple<\n FunctionArgs<TReference>\n > | [Skip])),\n ($state) => $state.data\n );\n}\n\n/**\n * Creates a reactive store with the full Syncore query state.\n */\nexport function createQueryStore<TReference extends FunctionReference<\"query\">>(\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n return createClientQueryStore(getSyncoreClient(), reference, ...args);\n}\n\n/**\n * Creates a reactive store with the full Syncore query state for an explicit client.\n */\nexport function createClientQueryStore<\n TReference extends FunctionReference<\"query\">\n>(\n client: SyncoreClient,\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n const isSkipped = args[0] === skip;\n const normalizedArgs = isSkipped\n ? undefined\n : normalizeOptionalArgs(args as OptionalArgsTuple<FunctionArgs<TReference>>);\n return readable<SyncoreQueryStoreState<FunctionResult<TReference>>>(\n toQueryState<FunctionResult<TReference>>(\n {\n data: undefined,\n error: undefined\n },\n defaultRuntimeStatus,\n isSkipped\n ),\n createQueryStoreStart(client, reference, normalizedArgs, isSkipped)\n );\n}\n\nexport function createQueriesStore<TEntries extends QueriesRequestInput>(\n entries: TEntries\n): Readable<CreateQueriesStoreResult<TEntries>> {\n return createClientQueriesStore(getSyncoreClient(), entries);\n}\n\nexport function createClientQueriesStore<TEntries extends QueriesRequestInput>(\n client: SyncoreClient,\n entries: TEntries\n): Readable<CreateQueriesStoreResult<TEntries>> {\n const normalizedEntries = Object.entries(entries)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => ({\n key,\n query: entry.query,\n skipped: entry.args === skip,\n args:\n entry.args === skip\n ? {}\n : normalizeOptionalArgs([entry.args ?? {}] as [] | [unknown])\n }));\n\n return readable<CreateQueriesStoreResult<TEntries>>(\n {} as CreateQueriesStoreResult<TEntries>,\n (set) => {\n const runtimeWatch = client.watchRuntimeStatus();\n const watches = normalizedEntries.map((entry) => ({\n key: entry.key,\n skipped: entry.skipped,\n watch: entry.skipped\n ? (noOpWatch as ManagedSyncoreWatch<unknown>)\n : (client.watchQuery(entry.query, entry.args) as ManagedSyncoreWatch<\n unknown\n >)\n }));\n const publish = () => {\n const runtimeStatus = readRuntimeStatus(runtimeWatch);\n set(\n Object.fromEntries(\n watches.map((entry) => [\n entry.key,\n toQueryState(\n entry.skipped\n ? {\n data: undefined,\n error: undefined\n }\n : readWatchSnapshot(entry.watch),\n runtimeStatus,\n entry.skipped\n )\n ])\n ) as CreateQueriesStoreResult<TEntries>\n );\n };\n\n publish();\n const cleanups = [\n runtimeWatch.onUpdate(publish),\n ...watches.map((entry) => entry.watch.onUpdate(publish))\n ];\n\n return () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n runtimeWatch.dispose?.();\n for (const entry of watches) {\n if (!entry.skipped) {\n entry.watch.dispose?.();\n }\n }\n };\n }\n );\n}\n\nexport function createPaginatedQueryStore<\n TReference extends PaginatedQueryReference\n>(\n reference: TReference,\n args: PaginatedQueryArgs<TReference> | Skip,\n options: {\n initialNumItems: number;\n }\n): Readable<UsePaginatedQueryResult<PaginatedQueryItem<TReference>>> {\n return createClientPaginatedQueryStore(\n getSyncoreClient(),\n reference,\n args,\n options\n );\n}\n\nexport function createClientPaginatedQueryStore<\n TReference extends PaginatedQueryReference\n>(\n client: SyncoreClient,\n reference: TReference,\n args: PaginatedQueryArgs<TReference> | Skip,\n options: {\n initialNumItems: number;\n }\n): Readable<UsePaginatedQueryResult<PaginatedQueryItem<TReference>>> {\n if (\n typeof options.initialNumItems !== \"number\" ||\n options.initialNumItems <= 0\n ) {\n throw new Error(\n `options.initialNumItems must be a positive number. Received ${String(\n options.initialNumItems\n )}.`\n );\n }\n\n const isSkipped = args === skip;\n const baseArgs = isSkipped ? {} : (args ?? {});\n\n return readable<UsePaginatedQueryResult<PaginatedQueryItem<TReference>>>(\n createEmptyPaginatedResult(defaultRuntimeStatus),\n (set) => {\n const runtimeWatch = client.watchRuntimeStatus();\n let state: PaginatedQueryInternalState = {\n nextPageKey: 1,\n pages: isSkipped\n ? []\n : [\n {\n key: \"0\",\n cursor: null,\n numItems: options.initialNumItems\n }\n ]\n };\n const pageEntries = new Map<\n string,\n {\n cursor: string | null;\n numItems: number;\n watch: ManagedSyncoreWatch<PaginationResult<PaginatedQueryItem<TReference>>>;\n unsubscribe: () => void;\n }\n >();\n\n const disposePage = (key: string) => {\n const entry = pageEntries.get(key);\n if (!entry) {\n return;\n }\n entry.unsubscribe();\n entry.watch.dispose?.();\n pageEntries.delete(key);\n };\n\n const ensurePages = () => {\n const activeKeys = new Set(state.pages.map((page) => page.key));\n for (const page of state.pages) {\n if (pageEntries.has(page.key)) {\n continue;\n }\n const watch = client.watchQuery(reference, {\n ...(baseArgs as Record<string, unknown>),\n paginationOpts: {\n cursor: page.cursor,\n numItems: page.numItems\n }\n }) as ManagedSyncoreWatch<PaginationResult<PaginatedQueryItem<TReference>>>;\n const unsubscribe = watch.onUpdate(publish);\n pageEntries.set(page.key, {\n cursor: page.cursor,\n numItems: page.numItems,\n watch,\n unsubscribe\n });\n }\n for (const key of [...pageEntries.keys()]) {\n if (!activeKeys.has(key)) {\n disposePage(key);\n }\n }\n };\n\n const deriveResult = (\n runtimeStatus: SyncoreRuntimeStatus\n ): UsePaginatedQueryResult<PaginatedQueryItem<TReference>> => {\n if (isSkipped) {\n return createEmptyPaginatedResult(runtimeStatus);\n }\n\n const pages: Array<PaginationResult<PaginatedQueryItem<TReference>>> = [];\n let error: Error | undefined;\n\n for (const page of state.pages) {\n const entry = pageEntries.get(page.key);\n if (!entry) {\n break;\n }\n const pageError = entry.watch.localQueryError();\n if (pageError) {\n error = pageError;\n break;\n }\n const value = entry.watch.localQueryResult();\n if (!value) {\n break;\n }\n pages.push(value);\n }\n\n const results = pages.flatMap((page) => page.page);\n const lastLoadedPage = pages.at(-1);\n const lastRequestedPage = state.pages.at(-1);\n const lastRequestedEntry = lastRequestedPage\n ? pageEntries.get(lastRequestedPage.key)\n : undefined;\n const lastRequestedResult = lastRequestedEntry?.watch.localQueryResult();\n const isLoading = pages.length === 0 && !error;\n const isLoadingMore =\n state.pages.length > pages.length ||\n (!!lastRequestedEntry && !lastRequestedResult && pages.length > 0);\n const hasMore = !!lastLoadedPage && !lastLoadedPage.isDone;\n const status = error\n ? \"error\"\n : isLoading\n ? \"loading\"\n : isLoadingMore\n ? \"loadingMore\"\n : hasMore\n ? \"ready\"\n : \"exhausted\";\n\n return {\n results,\n pages,\n status,\n error,\n isLoading,\n isLoadingMore,\n hasMore,\n cursor: lastLoadedPage?.cursor ?? null,\n runtimeStatus,\n loadMore(numItems = options.initialNumItems) {\n if (\n error ||\n isLoadingMore ||\n !hasMore ||\n !lastLoadedPage?.cursor\n ) {\n return;\n }\n state = {\n nextPageKey: state.nextPageKey + 1,\n pages: [\n ...state.pages,\n {\n key: String(state.nextPageKey),\n cursor: lastLoadedPage.cursor,\n numItems\n }\n ]\n };\n ensurePages();\n publish();\n }\n };\n };\n\n function publish() {\n set(deriveResult(readRuntimeStatus(runtimeWatch)));\n }\n\n ensurePages();\n publish();\n const detachRuntime = runtimeWatch.onUpdate(publish);\n\n return () => {\n detachRuntime();\n runtimeWatch.dispose?.();\n for (const key of [...pageEntries.keys()]) {\n disposePage(key);\n }\n };\n }\n );\n}\n\n/**\n * Creates a callable wrapper for a Syncore mutation using the contextual client.\n */\nexport function createMutation<\n TReference extends FunctionReference<\"mutation\">\n>(\n reference: TReference\n): (\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n) => Promise<FunctionResult<TReference>> {\n const client = getSyncoreClient();\n return (...args) =>\n client.mutation(reference, normalizeOptionalArgs(args)) as Promise<\n FunctionResult<TReference>\n >;\n}\n\n/**\n * Creates a callable wrapper for a Syncore action using the contextual client.\n */\nexport function createAction<TReference extends FunctionReference<\"action\">>(\n reference: TReference\n): (\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n) => Promise<FunctionResult<TReference>> {\n const client = getSyncoreClient();\n return (...args) =>\n client.action(reference, normalizeOptionalArgs(args)) as Promise<\n FunctionResult<TReference>\n >;\n}\n\nfunction createStatusStoreStart(\n client: SyncoreClient\n): StartStopNotifier<SyncoreRuntimeStatus> {\n return (set) => {\n const watch = client.watchRuntimeStatus();\n const sync = () => {\n set(readRuntimeStatus(watch));\n };\n sync();\n const unsubscribe = watch.onUpdate(sync);\n return () => {\n unsubscribe();\n watch.dispose?.();\n };\n };\n}\n\nfunction createQueryStoreStart<TReference extends FunctionReference<\"query\">>(\n client: SyncoreClient,\n reference: TReference,\n args: FunctionArgs<TReference> | undefined,\n isSkipped: boolean\n): StartStopNotifier<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n return (\n set: (value: SyncoreQueryStoreState<FunctionResult<TReference>>) => void\n ) => {\n const runtimeWatch = client.watchRuntimeStatus();\n const watch = isSkipped\n ? (noOpWatch as ManagedSyncoreWatch<FunctionResult<TReference>>)\n : (client.watchQuery(reference, args ?? {}) as ManagedSyncoreWatch<\n FunctionResult<TReference>\n >);\n const sync = () => {\n set(\n toQueryState(\n isSkipped\n ? {\n data: undefined,\n error: undefined\n }\n : readWatchSnapshot(watch),\n readRuntimeStatus(runtimeWatch),\n isSkipped\n )\n );\n };\n sync();\n const unsubscribeWatch = watch.onUpdate(sync);\n const unsubscribeRuntime = runtimeWatch.onUpdate(sync);\n return () => {\n unsubscribeWatch();\n unsubscribeRuntime();\n runtimeWatch.dispose?.();\n if (!isSkipped) {\n watch.dispose?.();\n }\n };\n };\n}\n\nfunction normalizeOptionalArgs<TArgs>(\n args: [] | [TArgs] | readonly unknown[]\n): TArgs {\n return (args[0] ?? {}) as TArgs;\n}\n\nfunction readWatchSnapshot<TResult>(watch: SyncoreWatch<TResult>): {\n data: TResult | undefined;\n error: Error | undefined;\n} {\n return {\n data: watch.localQueryResult(),\n error: watch.localQueryError()\n };\n}\n\nfunction readRuntimeStatus(\n watch: SyncoreWatch<SyncoreRuntimeStatus>\n): SyncoreRuntimeStatus {\n return watch.localQueryResult() ?? defaultRuntimeStatus;\n}\n\nfunction toQueryState<TResult>(\n snapshot: {\n data: TResult | undefined;\n error: Error | undefined;\n },\n runtimeStatus: SyncoreRuntimeStatus,\n isSkipped: boolean\n): SyncoreQueryState<TResult> {\n if (isSkipped) {\n return {\n data: undefined,\n error: undefined,\n status: \"skipped\",\n runtimeStatus,\n isLoading: false,\n isError: false,\n isReady: false\n };\n }\n\n const status =\n snapshot.error !== undefined\n ? \"error\"\n : snapshot.data === undefined\n ? \"loading\"\n : \"success\";\n\n return {\n data: snapshot.data,\n error: snapshot.error,\n status,\n runtimeStatus,\n isLoading: status === \"loading\",\n isError: status === \"error\",\n isReady: status === \"success\"\n };\n}\n\nfunction createEmptyPaginatedResult<TItem>(\n runtimeStatus: SyncoreRuntimeStatus\n): UsePaginatedQueryResult<TItem> {\n return {\n results: [],\n pages: [],\n status: \"ready\",\n error: undefined,\n isLoading: false,\n isLoadingMore: false,\n hasMore: false,\n cursor: null,\n runtimeStatus,\n loadMore() {\n return;\n }\n };\n}\n\nconst noOpWatch: ManagedSyncoreWatch<never> = {\n onUpdate: () => () => undefined,\n localQueryResult: () => undefined,\n localQueryError: () => undefined\n};\n"],"mappings":";;;AAkFA,MAAa,OAAO;AAGpB,MAAM,uBAA6C;CACjD,MAAM;CACN,QAAQ;CACT;AAED,MAAM,yBAAyB,OAAO,iBAAiB;;;;AAKvD,SAAgB,iBAAiB,QAAsC;AACrE,YAAW,wBAAwB,OAAO;AAC1C,QAAO;;;;;AAMT,SAAgB,mBAAkC;CAChD,MAAM,SAAS,WAAsC,uBAAuB;AAC5E,KAAI,CAAC,OACH,OAAM,IAAI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EAGZ;;AAGH,MAAM,YAAwC;CAC5C,sBAAsB,KAAA;CACtB,wBAAwB,KAAA;CACxB,uBAAuB,KAAA;CACxB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n derived,\n type Readable,\n readable,\n type StartStopNotifier\n} from \"svelte/store\";\nimport { getContext, setContext } from \"svelte\";\nimport type {\n FunctionArgs,\n FunctionReference,\n FunctionResult,\n PaginationOptions,\n PaginationResult,\n SyncoreClient,\n SyncoreQueryState,\n SyncoreRuntimeStatus,\n SyncoreWatch,\n UsePaginatedQueryResult\n} from \"@syncore/core\";\n\nexport type OptionalArgsTuple<TArgs> =\n Record<never, never> extends TArgs ? [args?: TArgs] : [args: TArgs];\n\ntype ManagedSyncoreWatch<TResult> = SyncoreWatch<TResult> & {\n dispose?: () => void;\n};\n\ntype QueryRequestInput<\n TReference extends FunctionReference<\"query\"> = FunctionReference<\"query\">\n> = Record<never, never> extends FunctionArgs<TReference>\n ? {\n query: TReference;\n args?: FunctionArgs<TReference> | Skip;\n }\n : {\n query: TReference;\n args: FunctionArgs<TReference> | Skip;\n };\n\ntype QueriesRequestInput = Record<string, QueryRequestInput>;\n\ntype QueryStateForEntry<TEntry> = TEntry extends QueryRequestInput<\n infer TReference\n>\n ? SyncoreQueryState<FunctionResult<TReference>>\n : never;\n\nexport type CreateQueriesStoreResult<TEntries extends QueriesRequestInput> = {\n [TKey in keyof TEntries]: QueryStateForEntry<TEntries[TKey]>;\n};\n\ntype PaginatedQueryReference = FunctionReference<\n \"query\",\n Record<string, unknown>,\n PaginationResult<unknown>\n>;\n\ntype PaginatedQueryArgs<TReference extends FunctionReference<\"query\">> =\n FunctionArgs<TReference> extends { paginationOpts: PaginationOptions }\n ? Omit<FunctionArgs<TReference>, \"paginationOpts\">\n : never;\n\ntype PaginatedQueryItem<TReference extends FunctionReference<\"query\">> =\n FunctionResult<TReference> extends PaginationResult<infer TItem>\n ? TItem\n : never;\n\ntype PaginatedQueryInternalState = {\n nextPageKey: number;\n pages: Array<{\n key: string;\n cursor: string | null;\n numItems: number;\n }>;\n};\n\n/**\n * The reactive query state shape emitted by Syncore's Svelte store factories.\n *\n * Extends SyncoreQueryState with the same fields (`data`, `error`,\n * `status`, `runtimeStatus`, `isLoading`, `isError`, `isReady`). Returned as\n * the value of stores created by {@link createQueryStore} and\n * {@link createClientQueryStore}.\n */\nexport interface SyncoreQueryStoreState<TResult>\n extends SyncoreQueryState<TResult> {}\n\n/**\n * A sentinel value that tells Syncore store factories to skip the query.\n *\n * Use `skip` in place of a query’s `args` argument to avoid firing the query\n * while some required data is not yet available (e.g. a user ID that loads\n * asynchronously). The store will remain in a `\"loading\"` / skipped state\n * until a non-skip value is provided.\n *\n * ```svelte\n * <script>\n * import { createQueryValueStore, skip } from \"syncorejs/svelte\";\n * import { api } from \"../syncore/_generated/api\";\n *\n * export let userId: string | undefined;\n *\n * $: profile = createQueryValueStore(\n * api.users.get,\n * userId ? { id: userId } : skip\n * );\n * </script>\n * ```\n */\nexport const skip = \"skip\" as const;\ntype Skip = typeof skip;\n\nconst defaultRuntimeStatus: SyncoreRuntimeStatus = {\n kind: \"starting\",\n reason: \"booting\"\n};\n\nconst SYNCORE_CLIENT_CONTEXT = Symbol(\"syncore.client\");\n\n/**\n * Store the Syncore client in Svelte’s component context.\n *\n * Call this once at the root of your component tree (e.g. in a layout or\n * root `+layout.svelte`) so that the context-aware store factories\n * (`createQueryStore`, `createQueriesStore`, etc.) can retrieve it\n * automatically without prop-drilling.\n *\n * ```svelte\n * <!-- +layout.svelte -->\n * <script>\n * import { setSyncoreClient } from \"syncorejs/svelte\";\n * export let data; // { client } from +layout.ts\n * setSyncoreClient(data.client);\n * </script>\n * <slot />\n * ```\n *\n * @param client - The ready Syncore client to store in context.\n * @returns The same `client` for convenience.\n */\nexport function setSyncoreClient(client: SyncoreClient): SyncoreClient {\n setContext(SYNCORE_CLIENT_CONTEXT, client);\n return client;\n}\n\n/**\n * Retrieve the Syncore client from Svelte’s component context.\n *\n * Throws if {@link setSyncoreClient} has not been called by an ancestor\n * component. Only use this inside Svelte components; for standalone scripts\n * keep an explicit reference to the client instead.\n *\n * @throws `Error` when no client is found in the component context.\n */\nexport function getSyncoreClient(): SyncoreClient {\n const client = getContext<SyncoreClient | undefined>(SYNCORE_CLIENT_CONTEXT);\n if (!client) {\n throw new Error(\n \"Syncore client is missing from the Svelte component context.\"\n );\n }\n return client;\n}\n\n/**\n * Create a reactive Svelte store that tracks the Syncore runtime status.\n *\n * Uses the client from Svelte context (set via {@link setSyncoreClient}).\n * Subscribe to gate your UI on `\"ready\"` before rendering data-dependent\n * components.\n *\n * ```svelte\n * <script>\n * import { createSyncoreStatusStore } from \"syncorejs/svelte\";\n * const status = createSyncoreStatusStore();\n * </script>\n *\n * {#if $status.kind === \"ready\"}\n * <App />\n * {:else}\n * <Loading />\n * {/if}\n * ```\n */\nexport function createSyncoreStatusStore(): Readable<SyncoreRuntimeStatus> {\n return createClientSyncoreStatusStore(getSyncoreClient());\n}\n\n/**\n * Create a reactive Svelte store that tracks the Syncore runtime status.\n *\n * Accepts an explicit `client` rather than reading from Svelte context,\n * making it usable outside component trees (e.g. in module-level code or\n * SvelteKit `load` functions).\n *\n * @param client - The Syncore client to observe.\n */\nexport function createClientSyncoreStatusStore(\n client: SyncoreClient\n): Readable<SyncoreRuntimeStatus> {\n return readable<SyncoreRuntimeStatus>(\n defaultRuntimeStatus,\n createStatusStoreStart(client)\n );\n}\n\n/**\n * Create a reactive Svelte store that emits the current value of a Syncore\n * query, or `undefined` while loading.\n *\n * Uses the client from Svelte context (set via {@link setSyncoreClient}).\n * Pass `skip` as `args` to pause the query.\n *\n * ```svelte\n * <script>\n * import { createQueryValueStore } from \"syncorejs/svelte\";\n * import { api } from \"../syncore/_generated/api\";\n *\n * const todos = createQueryValueStore(api.todos.list);\n * </script>\n *\n * {#each $todos ?? [] as todo}\n * <p>{todo.text}</p>\n * {/each}\n * ```\n */\nexport function createQueryValueStore<\n TReference extends FunctionReference<\"query\">\n>(\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<FunctionResult<TReference> | undefined> {\n return createClientQueryValueStore(getSyncoreClient(), reference, ...args);\n}\n\n/**\n * Create a reactive Svelte store that emits the current value of a Syncore\n * query, or `undefined` while loading.\n *\n * Accepts an explicit `client` instead of reading from Svelte context.\n *\n * @param client - The Syncore client to query against.\n */\nexport function createClientQueryValueStore<\n TReference extends FunctionReference<\"query\">\n>(\n client: SyncoreClient,\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<FunctionResult<TReference> | undefined> {\n return derived(\n createClientQueryStore(client, reference, ...(args as OptionalArgsTuple<\n FunctionArgs<TReference>\n > | [Skip])),\n ($state) => $state.data\n );\n}\n\n/**\n * Create a reactive Svelte store that emits the full SyncoreQueryState\n * for a query, including `data`, `error`, `status`, and `isPending`.\n *\n * Uses the client from Svelte context (set via {@link setSyncoreClient}).\n *\n * ```svelte\n * <script>\n * import { createQueryStore } from \"syncorejs/svelte\";\n * import { api } from \"../syncore/_generated/api\";\n *\n * const state = createQueryStore(api.todos.list);\n * </script>\n *\n * {#if $state.isPending}\n * <Spinner />\n * {:else if $state.error}\n * <Error message={$state.error.message} />\n * {:else}\n * {#each $state.data as todo}<p>{todo.text}</p>{/each}\n * {/if}\n * ```\n */\nexport function createQueryStore<TReference extends FunctionReference<\"query\">>(\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n return createClientQueryStore(getSyncoreClient(), reference, ...args);\n}\n\n/**\n * Create a reactive Svelte store that emits the full SyncoreQueryState\n * for a query, including `data`, `error`, `status`, and `isPending`.\n *\n * Accepts an explicit `client` instead of reading from Svelte context.\n *\n * @param client - The Syncore client to query against.\n */\nexport function createClientQueryStore<\n TReference extends FunctionReference<\"query\">\n>(\n client: SyncoreClient,\n reference: TReference,\n ...args: OptionalArgsTuple<FunctionArgs<TReference>> | [Skip]\n): Readable<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n const isSkipped = args[0] === skip;\n const normalizedArgs = isSkipped\n ? undefined\n : normalizeOptionalArgs(args as OptionalArgsTuple<FunctionArgs<TReference>>);\n return readable<SyncoreQueryStoreState<FunctionResult<TReference>>>(\n toQueryState<FunctionResult<TReference>>(\n {\n data: undefined,\n error: undefined\n },\n defaultRuntimeStatus,\n isSkipped\n ),\n createQueryStoreStart(client, reference, normalizedArgs, isSkipped)\n );\n}\n\n/**\n * Create a reactive Svelte store that simultaneously observes multiple\n * Syncore queries.\n *\n * Uses the client from Svelte context (set via {@link setSyncoreClient}).\n * Each key in `entries` corresponds to a key in the emitted result object.\n *\n * ```svelte\n * <script>\n * import { createQueriesStore } from \"syncorejs/svelte\";\n * import { api } from \"../syncore/_generated/api\";\n *\n * const stores = createQueriesStore({\n * todos: { query: api.todos.list },\n * user: { query: api.users.me },\n * });\n * </script>\n *\n * <p>{$stores.user.data?.name} has {$stores.todos.data?.length} todos</p>\n * ```\n */\nexport function createQueriesStore<TEntries extends QueriesRequestInput>(\n entries: TEntries\n): Readable<CreateQueriesStoreResult<TEntries>> {\n return createClientQueriesStore(getSyncoreClient(), entries);\n}\n\n/**\n * Create a reactive Svelte store that simultaneously observes multiple\n * Syncore queries.\n *\n * Accepts an explicit `client` instead of reading from Svelte context.\n *\n * @param client - The Syncore client to query against.\n */\nexport function createClientQueriesStore<TEntries extends QueriesRequestInput>(\n client: SyncoreClient,\n entries: TEntries\n): Readable<CreateQueriesStoreResult<TEntries>> {\n const normalizedEntries = Object.entries(entries)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => ({\n key,\n query: entry.query,\n skipped: entry.args === skip,\n args:\n entry.args === skip\n ? {}\n : normalizeOptionalArgs([entry.args ?? {}] as [] | [unknown])\n }));\n\n return readable<CreateQueriesStoreResult<TEntries>>(\n {} as CreateQueriesStoreResult<TEntries>,\n (set) => {\n const runtimeWatch = client.watchRuntimeStatus();\n const watches = normalizedEntries.map((entry) => ({\n key: entry.key,\n skipped: entry.skipped,\n watch: entry.skipped\n ? (noOpWatch as ManagedSyncoreWatch<unknown>)\n : (client.watchQuery(entry.query, entry.args) as ManagedSyncoreWatch<\n unknown\n >)\n }));\n const publish = () => {\n const runtimeStatus = readRuntimeStatus(runtimeWatch);\n set(\n Object.fromEntries(\n watches.map((entry) => [\n entry.key,\n toQueryState(\n entry.skipped\n ? {\n data: undefined,\n error: undefined\n }\n : readWatchSnapshot(entry.watch),\n runtimeStatus,\n entry.skipped\n )\n ])\n ) as CreateQueriesStoreResult<TEntries>\n );\n };\n\n publish();\n const cleanups = [\n runtimeWatch.onUpdate(publish),\n ...watches.map((entry) => entry.watch.onUpdate(publish))\n ];\n\n return () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n runtimeWatch.dispose?.();\n for (const entry of watches) {\n if (!entry.skipped) {\n entry.watch.dispose?.();\n }\n }\n };\n }\n );\n}\n\n/**\n * Create a reactive Svelte store for cursor-based paginated Syncore queries.\n *\n * Uses the client from Svelte context (set via {@link setSyncoreClient}).\n * The store handles page tracking and exposes a `loadMore()` function so you\n * can implement “Load More” UIs without manual cursor management.\n *\n * The query referenced by `reference` must accept a `paginationOpts`\n * argument and return a PaginationResult.\n *\n * ```svelte\n * <script>\n * import { createPaginatedQueryStore } from \"syncorejs/svelte\";\n * import { api } from \"../syncore/_generated/api\";\n *\n * const result = createPaginatedQueryStore(\n * api.todos.listPaginated,\n * {},\n * { initialNumItems: 10 }\n * );\n * </script>\n *\n * {#each $result.results as todo}<p>{todo.text}</p>{/each}\n * {#if $result.canLoadMore}\n * <button on:click={() => $result.loadMore(10)}>Load more</button>\n * {/if}\n * ```\n *\n * @param reference - A paginated query function reference.\n * @param args - Query arguments excluding `paginationOpts`, or `skip`.\n * @param options - Pagination options. `initialNumItems` controls the number\n * of items to fetch on the first page.\n */\nexport function createPaginatedQueryStore<\n TReference extends PaginatedQueryReference\n>(\n reference: TReference,\n args: PaginatedQueryArgs<TReference> | Skip,\n options: {\n initialNumItems: number;\n }\n): Readable<UsePaginatedQueryResult<PaginatedQueryItem<TReference>>> {\n return createClientPaginatedQueryStore(\n getSyncoreClient(),\n reference,\n args,\n options\n );\n}\n\n/**\n * Create a reactive Svelte store for cursor-based paginated Syncore queries.\n *\n * Accepts an explicit `client` instead of reading from Svelte context.\n *\n * @param client - The Syncore client to query against.\n * @param reference - A paginated query function reference.\n * @param args - Query arguments excluding `paginationOpts`, or `skip`.\n * @param options - Pagination options. `initialNumItems` controls the number\n * of items to fetch on the first page.\n */\nexport function createClientPaginatedQueryStore<\n TReference extends PaginatedQueryReference\n>(\n client: SyncoreClient,\n reference: TReference,\n args: PaginatedQueryArgs<TReference> | Skip,\n options: {\n initialNumItems: number;\n }\n): Readable<UsePaginatedQueryResult<PaginatedQueryItem<TReference>>> {\n if (\n typeof options.initialNumItems !== \"number\" ||\n options.initialNumItems <= 0\n ) {\n throw new Error(\n `options.initialNumItems must be a positive number. Received ${String(\n options.initialNumItems\n )}.`\n );\n }\n\n const isSkipped = args === skip;\n const baseArgs = isSkipped ? {} : (args ?? {});\n\n return readable<UsePaginatedQueryResult<PaginatedQueryItem<TReference>>>(\n createEmptyPaginatedResult(defaultRuntimeStatus),\n (set) => {\n const runtimeWatch = client.watchRuntimeStatus();\n let state: PaginatedQueryInternalState = {\n nextPageKey: 1,\n pages: isSkipped\n ? []\n : [\n {\n key: \"0\",\n cursor: null,\n numItems: options.initialNumItems\n }\n ]\n };\n const pageEntries = new Map<\n string,\n {\n cursor: string | null;\n numItems: number;\n watch: ManagedSyncoreWatch<PaginationResult<PaginatedQueryItem<TReference>>>;\n unsubscribe: () => void;\n }\n >();\n\n const disposePage = (key: string) => {\n const entry = pageEntries.get(key);\n if (!entry) {\n return;\n }\n entry.unsubscribe();\n entry.watch.dispose?.();\n pageEntries.delete(key);\n };\n\n const ensurePages = () => {\n const activeKeys = new Set(state.pages.map((page) => page.key));\n for (const page of state.pages) {\n if (pageEntries.has(page.key)) {\n continue;\n }\n const watch = client.watchQuery(reference, {\n ...(baseArgs as Record<string, unknown>),\n paginationOpts: {\n cursor: page.cursor,\n numItems: page.numItems\n }\n }) as ManagedSyncoreWatch<PaginationResult<PaginatedQueryItem<TReference>>>;\n const unsubscribe = watch.onUpdate(publish);\n pageEntries.set(page.key, {\n cursor: page.cursor,\n numItems: page.numItems,\n watch,\n unsubscribe\n });\n }\n for (const key of [...pageEntries.keys()]) {\n if (!activeKeys.has(key)) {\n disposePage(key);\n }\n }\n };\n\n const deriveResult = (\n runtimeStatus: SyncoreRuntimeStatus\n ): UsePaginatedQueryResult<PaginatedQueryItem<TReference>> => {\n if (isSkipped) {\n return createEmptyPaginatedResult(runtimeStatus);\n }\n\n const pages: Array<PaginationResult<PaginatedQueryItem<TReference>>> = [];\n let error: Error | undefined;\n\n for (const page of state.pages) {\n const entry = pageEntries.get(page.key);\n if (!entry) {\n break;\n }\n const pageError = entry.watch.localQueryError();\n if (pageError) {\n error = pageError;\n break;\n }\n const value = entry.watch.localQueryResult();\n if (!value) {\n break;\n }\n pages.push(value);\n }\n\n const results = pages.flatMap((page) => page.page);\n const lastLoadedPage = pages.at(-1);\n const lastRequestedPage = state.pages.at(-1);\n const lastRequestedEntry = lastRequestedPage\n ? pageEntries.get(lastRequestedPage.key)\n : undefined;\n const lastRequestedResult = lastRequestedEntry?.watch.localQueryResult();\n const isLoading = pages.length === 0 && !error;\n const isLoadingMore =\n state.pages.length > pages.length ||\n (!!lastRequestedEntry && !lastRequestedResult && pages.length > 0);\n const hasMore = !!lastLoadedPage && !lastLoadedPage.isDone;\n const status = error\n ? \"error\"\n : isLoading\n ? \"loading\"\n : isLoadingMore\n ? \"loadingMore\"\n : hasMore\n ? \"ready\"\n : \"exhausted\";\n\n return {\n results,\n pages,\n status,\n error,\n isLoading,\n isLoadingMore,\n hasMore,\n cursor: lastLoadedPage?.cursor ?? null,\n runtimeStatus,\n loadMore(numItems = options.initialNumItems) {\n if (\n error ||\n isLoadingMore ||\n !hasMore ||\n !lastLoadedPage?.cursor\n ) {\n return;\n }\n state = {\n nextPageKey: state.nextPageKey + 1,\n pages: [\n ...state.pages,\n {\n key: String(state.nextPageKey),\n cursor: lastLoadedPage.cursor,\n numItems\n }\n ]\n };\n ensurePages();\n publish();\n }\n };\n };\n\n function publish() {\n set(deriveResult(readRuntimeStatus(runtimeWatch)));\n }\n\n ensurePages();\n publish();\n const detachRuntime = runtimeWatch.onUpdate(publish);\n\n return () => {\n detachRuntime();\n runtimeWatch.dispose?.();\n for (const key of [...pageEntries.keys()]) {\n disposePage(key);\n }\n };\n }\n );\n}\n\n/**\n * Creates a callable wrapper for a Syncore mutation using the contextual client.\n */\nexport function createMutation<\n TReference extends FunctionReference<\"mutation\">\n>(\n reference: TReference\n): (\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n) => Promise<FunctionResult<TReference>> {\n const client = getSyncoreClient();\n return (...args) =>\n client.mutation(reference, normalizeOptionalArgs(args)) as Promise<\n FunctionResult<TReference>\n >;\n}\n\n/**\n * Creates a callable wrapper for a Syncore action using the contextual client.\n */\nexport function createAction<TReference extends FunctionReference<\"action\">>(\n reference: TReference\n): (\n ...args: OptionalArgsTuple<FunctionArgs<TReference>>\n) => Promise<FunctionResult<TReference>> {\n const client = getSyncoreClient();\n return (...args) =>\n client.action(reference, normalizeOptionalArgs(args)) as Promise<\n FunctionResult<TReference>\n >;\n}\n\nfunction createStatusStoreStart(\n client: SyncoreClient\n): StartStopNotifier<SyncoreRuntimeStatus> {\n return (set) => {\n const watch = client.watchRuntimeStatus();\n const sync = () => {\n set(readRuntimeStatus(watch));\n };\n sync();\n const unsubscribe = watch.onUpdate(sync);\n return () => {\n unsubscribe();\n watch.dispose?.();\n };\n };\n}\n\nfunction createQueryStoreStart<TReference extends FunctionReference<\"query\">>(\n client: SyncoreClient,\n reference: TReference,\n args: FunctionArgs<TReference> | undefined,\n isSkipped: boolean\n): StartStopNotifier<SyncoreQueryStoreState<FunctionResult<TReference>>> {\n return (\n set: (value: SyncoreQueryStoreState<FunctionResult<TReference>>) => void\n ) => {\n const runtimeWatch = client.watchRuntimeStatus();\n const watch = isSkipped\n ? (noOpWatch as ManagedSyncoreWatch<FunctionResult<TReference>>)\n : (client.watchQuery(reference, args ?? {}) as ManagedSyncoreWatch<\n FunctionResult<TReference>\n >);\n const sync = () => {\n set(\n toQueryState(\n isSkipped\n ? {\n data: undefined,\n error: undefined\n }\n : readWatchSnapshot(watch),\n readRuntimeStatus(runtimeWatch),\n isSkipped\n )\n );\n };\n sync();\n const unsubscribeWatch = watch.onUpdate(sync);\n const unsubscribeRuntime = runtimeWatch.onUpdate(sync);\n return () => {\n unsubscribeWatch();\n unsubscribeRuntime();\n runtimeWatch.dispose?.();\n if (!isSkipped) {\n watch.dispose?.();\n }\n };\n };\n}\n\nfunction normalizeOptionalArgs<TArgs>(\n args: [] | [TArgs] | readonly unknown[]\n): TArgs {\n return (args[0] ?? {}) as TArgs;\n}\n\nfunction readWatchSnapshot<TResult>(watch: SyncoreWatch<TResult>): {\n data: TResult | undefined;\n error: Error | undefined;\n} {\n return {\n data: watch.localQueryResult(),\n error: watch.localQueryError()\n };\n}\n\nfunction readRuntimeStatus(\n watch: SyncoreWatch<SyncoreRuntimeStatus>\n): SyncoreRuntimeStatus {\n return watch.localQueryResult() ?? defaultRuntimeStatus;\n}\n\nfunction toQueryState<TResult>(\n snapshot: {\n data: TResult | undefined;\n error: Error | undefined;\n },\n runtimeStatus: SyncoreRuntimeStatus,\n isSkipped: boolean\n): SyncoreQueryState<TResult> {\n if (isSkipped) {\n return {\n data: undefined,\n error: undefined,\n status: \"skipped\",\n runtimeStatus,\n isLoading: false,\n isError: false,\n isReady: false\n };\n }\n\n const status =\n snapshot.error !== undefined\n ? \"error\"\n : snapshot.data === undefined\n ? \"loading\"\n : \"success\";\n\n return {\n data: snapshot.data,\n error: snapshot.error,\n status,\n runtimeStatus,\n isLoading: status === \"loading\",\n isError: status === \"error\",\n isReady: status === \"success\"\n };\n}\n\nfunction createEmptyPaginatedResult<TItem>(\n runtimeStatus: SyncoreRuntimeStatus\n): UsePaginatedQueryResult<TItem> {\n return {\n results: [],\n pages: [],\n status: \"ready\",\n error: undefined,\n isLoading: false,\n isLoadingMore: false,\n hasMore: false,\n cursor: null,\n runtimeStatus,\n loadMore() {\n return;\n }\n };\n}\n\nconst noOpWatch: ManagedSyncoreWatch<never> = {\n onUpdate: () => () => undefined,\n localQueryResult: () => undefined,\n localQueryError: () => undefined\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6GA,MAAa,OAAO;AAGpB,MAAM,uBAA6C;CACjD,MAAM;CACN,QAAQ;AACV;AAEA,MAAM,yBAAyB,OAAO,gBAAgB;;;;;;;;;;;;;;;;;;;;;;AAuBtD,SAAgB,iBAAiB,QAAsC;CACrE,WAAW,wBAAwB,MAAM;CACzC,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,mBAAkC;CAChD,MAAM,SAAS,WAAsC,sBAAsB;CAC3E,IAAI,CAAC,QACH,MAAM,IAAI,MACR,8DACF;CAEF,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,2BAA2D;CACzE,OAAO,+BAA+B,iBAAiB,CAAC;AAC1D;;;;;;;;;;AAWA,SAAgB,+BACd,QACgC;CAChC,OAAO,SACL,sBACA,uBAAuB,MAAM,CAC/B;AACF;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,sBAGd,WACA,GAAG,MAC+C;CAClD,OAAO,4BAA4B,iBAAiB,GAAG,WAAW,GAAG,IAAI;AAC3E;;;;;;;;;AAUA,SAAgB,4BAGd,QACA,WACA,GAAG,MAC+C;CAClD,OAAO,QACL,uBAAuB,QAAQ,WAAW,GAAI,IAEnC,IACV,WAAW,OAAO,IACrB;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,iBACd,WACA,GAAG,MAC2D;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ACE,YACI;IACE,MAAM,KAAA;IACN,OAAO,KAAA;GACT,IACA,kBAAkB,KAAK,GAC3B,kBAAkB,YAAY,GAC9B,SACF,CACF;EACF;EACA,KAAK;EACL,MAAM,mBAAmB,MAAM,SAAS,IAAI;EAC5C,MAAM,qBAAqB,aAAa,SAAS,IAAI;EACrD,aAAa;GACX,iBAAiB;GACjB,mBAAmB;GACnB,aAAa,UAAU;GACvB,IAAI,CAAC,WACH,MAAM,UAAU;EAEpB;CACF;AACF;AAEA,SAAS,sBACP,MACO;CACP,OAAQ,KAAK,MAAM,CAAC;AACtB;AAEA,SAAS,kBAA2B,OAGlC;CACA,OAAO;EACL,MAAM,MAAM,iBAAiB;EAC7B,OAAO,MAAM,gBAAgB;CAC/B;AACF;AAEA,SAAS,kBACP,OACsB;CACtB,OAAO,MAAM,iBAAiB,KAAK;AACrC;AAEA,SAAS,aACP,UAIA,eACA,WAC4B;CAC5B,IAAI,WACF,OAAO;EACL,MAAM,KAAA;EACN,OAAO,KAAA;EACP,QAAQ;EACR;EACA,WAAW;EACX,SAAS;EACT,SAAS;CACX;CAGF,MAAM,SACJ,SAAS,UAAU,KAAA,IACf,UACA,SAAS,SAAS,KAAA,IAChB,YACA;CAER,OAAO;EACL,MAAM,SAAS;EACf,OAAO,SAAS;EAChB;EACA;EACA,WAAW,WAAW;EACtB,SAAS,WAAW;EACpB,SAAS,WAAW;CACtB;AACF;AAEA,SAAS,2BACP,eACgC;CAChC,OAAO;EACL,SAAS,CAAC;EACV,OAAO,CAAC;EACR,QAAQ;EACR,OAAO,KAAA;EACP,WAAW;EACX,eAAe;EACf,SAAS;EACT,QAAQ;EACR;EACA,WAAW,CAEX;CACF;AACF;AAEA,MAAM,YAAwC;CAC5C,sBAAsB,KAAA;CACtB,wBAAwB,KAAA;CACxB,uBAAuB,KAAA;AACzB"}
|
package/dist/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","names":[],"sources":["../src/browser.ts"],"mappings":";;;KAsCY,gCAAA,GACV,
|
|
1
|
+
{"version":3,"file":"browser.d.ts","names":[],"sources":["../src/browser.ts"],"mappings":";;;KAsCY,gCAAA,GACV,sCAAoC;AAAA,KAC1B,0BAAA,GAA6B,wBAAsB;AAAA,cAElD,0BAAA,SAA0B,wBAAyB;AAAA,cACnD,yBAAA,SAAyB,8BAA+B;AAAA,cACxD,gCAAA,SAAgC,8BAA+B"}
|
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,9 @@ function isDirectInvocation(moduleUrl) {
|
|
|
9
9
|
if (invokedPath === void 0) return false;
|
|
10
10
|
return realpathSync(path.resolve(invokedPath)) === realpathSync(path.resolve(fileURLToPath(moduleUrl)));
|
|
11
11
|
}
|
|
12
|
-
if (isDirectInvocation(import.meta.url)) runSyncoreCli().
|
|
12
|
+
if (isDirectInvocation(import.meta.url)) runSyncoreCli().then(() => {
|
|
13
|
+
process.exit(process.exitCode ?? 0);
|
|
14
|
+
}).catch((error) => {
|
|
13
15
|
process.nextTick(() => {
|
|
14
16
|
throw error;
|
|
15
17
|
});
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { runSyncoreCli } from \"@syncore/cli\";\nimport { realpathSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport { runSyncoreCli };\n\nfunction isDirectInvocation(moduleUrl: string): boolean {\n const invokedPath = process.argv[1];\n if (invokedPath === undefined) {\n return false;\n }\n\n return (\n realpathSync(path.resolve(invokedPath)) ===\n realpathSync(path.resolve(fileURLToPath(moduleUrl)))\n );\n}\n\nif (isDirectInvocation(import.meta.url)) {\n void runSyncoreCli().catch((error) => {\n
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { runSyncoreCli } from \"@syncore/cli\";\nimport { realpathSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport { runSyncoreCli };\n\nfunction isDirectInvocation(moduleUrl: string): boolean {\n const invokedPath = process.argv[1];\n if (invokedPath === undefined) {\n return false;\n }\n\n return (\n realpathSync(path.resolve(invokedPath)) ===\n realpathSync(path.resolve(fileURLToPath(moduleUrl)))\n );\n}\n\nif (isDirectInvocation(import.meta.url)) {\n void runSyncoreCli()\n .then(() => {\n process.exit(process.exitCode ?? 0);\n })\n .catch((error) => {\n process.nextTick(() => {\n throw error;\n });\n });\n}\n"],"mappings":";;;;;AAOA,SAAS,mBAAmB,WAA4B;CACtD,MAAM,cAAc,QAAQ,KAAK;CACjC,IAAI,gBAAgB,KAAA,GAClB,OAAO;CAGT,OACE,aAAa,KAAK,QAAQ,WAAW,CAAC,MACtC,aAAa,KAAK,QAAQ,cAAc,SAAS,CAAC,CAAC;AAEvD;AAEA,IAAI,mBAAmB,OAAO,KAAK,GAAG,GACpC,cAAmB,EAChB,WAAW;CACV,QAAQ,KAAK,QAAQ,YAAY,CAAC;AACpC,CAAC,EACA,OAAO,UAAU;CAChB,QAAQ,eAAe;EACrB,MAAM;CACR,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ComponentPath, FunctionReferencesForTree, InstalledComponentApi, InstalledComponentsApi, ResolvedSyncoreComponent, SyncoreComponent, SyncoreComponentFunctionMetadata, SyncoreComponentHookContext, SyncoreComponentInstall, SyncoreComponentsManifest, SyncoreCoreCapability, SyncoreFunctionTree, SyncoreHostServiceName, SyncoreRequestedCapability, composeProjectFunctionRegistry, composeProjectSchema, createBindingFunctionReference, createComponentPhysicalTableName, createInstalledComponentsApi, defineComponent, defineComponents, installComponent, resolveComponentsManifest, toCanonicalComponentFunctionName } from "./components.js";
|
|
2
2
|
import { ActionCtx, ComparisonOperator, CronJobs, DevtoolsSink, DocumentForTable, EmptyArgs, FilterBuilder, FunctionArgs, FunctionArgsFromDefinition, FunctionConfig, FunctionKindFromDefinition, FunctionReference, FunctionReferenceFor, FunctionResult, FunctionResultFromDefinition, IndexRangeBuilder, InferArgs, InsertValueForTable, JsonObject, MisfirePolicy, MutationCtx, PaginationOptions, PaginationResult, QueryBuilder, QueryCondition, QueryCtx, QueryExpression, RecurringDailySchedule, RecurringIntervalSchedule, RecurringJobDefinition, RecurringSchedule, RecurringWeeklySchedule, RegisteredSyncoreFunction, RegisteredSyncoreHandler, RunResult, SchedulerApi, SchedulerOptions, SearchIndexBuilder, SearchQuery, StorageObject, StorageWriteInput, SyncoreCapabilities, SyncoreClient, SyncoreDatabaseReader, SyncoreDatabaseWriter, SyncoreFunctionDefinition, SyncoreFunctionKind, SyncoreFunctionRegistry, SyncoreResolvedComponents, SyncoreRuntime, SyncoreRuntimeOptions, SyncoreSqlDriver, SyncoreStorageAdapter, SyncoreStorageApi, SyncoreWatch, TableNames, action, createFunctionReference, createFunctionReferenceFor, cronJobs, generateId, mutation, query } from "./_vendor/core/index.d.mts";
|
|
3
3
|
export * from "./_vendor/schema/index.d.ts";
|
|
4
|
-
export { type ActionCtx, type ComparisonOperator, ComponentPath, type CronJobs, type DevtoolsSink, type DocumentForTable, type EmptyArgs, type FilterBuilder, type FunctionArgs, type FunctionArgsFromDefinition, type FunctionConfig, type FunctionKindFromDefinition, type FunctionReference, type FunctionReferenceFor, FunctionReferencesForTree, type FunctionResult, type FunctionResultFromDefinition, type IndexRangeBuilder, type InferArgs, type InsertValueForTable, InstalledComponentApi, InstalledComponentsApi, type JsonObject, type MisfirePolicy, type MutationCtx, type PaginationOptions, type PaginationResult, type QueryBuilder, type QueryCondition, type QueryCtx, type QueryExpression, type RecurringDailySchedule, type RecurringIntervalSchedule, type RecurringJobDefinition, type RecurringSchedule, type RecurringWeeklySchedule, type RegisteredSyncoreFunction, type RegisteredSyncoreHandler, ResolvedSyncoreComponent, type RunResult, type SchedulerApi, type SchedulerOptions, type SearchIndexBuilder, type SearchQuery, type StorageObject, type StorageWriteInput, type SyncoreCapabilities, type SyncoreClient, SyncoreComponent, SyncoreComponentFunctionMetadata, SyncoreComponentHookContext, SyncoreComponentInstall, SyncoreComponentsManifest, SyncoreCoreCapability, type SyncoreDatabaseReader, type SyncoreDatabaseWriter, type SyncoreFunctionDefinition, type SyncoreFunctionKind, type SyncoreFunctionRegistry, SyncoreFunctionTree, SyncoreHostServiceName, SyncoreRequestedCapability, type SyncoreResolvedComponents, SyncoreRuntime, type SyncoreRuntimeOptions, type SyncoreSqlDriver, type SyncoreStorageAdapter, type SyncoreStorageApi, type SyncoreWatch, type TableNames, action, composeProjectFunctionRegistry, composeProjectSchema, createBindingFunctionReference, createComponentPhysicalTableName, createFunctionReference, createFunctionReferenceFor, createInstalledComponentsApi, cronJobs, defineComponent, defineComponents, generateId, installComponent, mutation, query, resolveComponentsManifest, toCanonicalComponentFunctionName };
|
|
4
|
+
export { type ActionCtx, type ComparisonOperator, type ComponentPath, type CronJobs, type DevtoolsSink, type DocumentForTable, type EmptyArgs, type FilterBuilder, type FunctionArgs, type FunctionArgsFromDefinition, type FunctionConfig, type FunctionKindFromDefinition, type FunctionReference, type FunctionReferenceFor, type FunctionReferencesForTree, type FunctionResult, type FunctionResultFromDefinition, type IndexRangeBuilder, type InferArgs, type InsertValueForTable, type InstalledComponentApi, type InstalledComponentsApi, type JsonObject, type MisfirePolicy, type MutationCtx, type PaginationOptions, type PaginationResult, type QueryBuilder, type QueryCondition, type QueryCtx, type QueryExpression, type RecurringDailySchedule, type RecurringIntervalSchedule, type RecurringJobDefinition, type RecurringSchedule, type RecurringWeeklySchedule, type RegisteredSyncoreFunction, type RegisteredSyncoreHandler, type ResolvedSyncoreComponent, type RunResult, type SchedulerApi, type SchedulerOptions, type SearchIndexBuilder, type SearchQuery, type StorageObject, type StorageWriteInput, type SyncoreCapabilities, type SyncoreClient, type SyncoreComponent, type SyncoreComponentFunctionMetadata, type SyncoreComponentHookContext, type SyncoreComponentInstall, type SyncoreComponentsManifest, type SyncoreCoreCapability, type SyncoreDatabaseReader, type SyncoreDatabaseWriter, type SyncoreFunctionDefinition, type SyncoreFunctionKind, type SyncoreFunctionRegistry, type SyncoreFunctionTree, type SyncoreHostServiceName, type SyncoreRequestedCapability, type SyncoreResolvedComponents, SyncoreRuntime, type SyncoreRuntimeOptions, type SyncoreSqlDriver, type SyncoreStorageAdapter, type SyncoreStorageApi, type SyncoreWatch, type TableNames, action, composeProjectFunctionRegistry, composeProjectSchema, createBindingFunctionReference, createComponentPhysicalTableName, createFunctionReference, createFunctionReferenceFor, createInstalledComponentsApi, cronJobs, defineComponent, defineComponents, generateId, installComponent, mutation, query, resolveComponentsManifest, toCanonicalComponentFunctionName };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "syncorejs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Local-first reactive backend toolkit for offline apps",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -100,27 +100,27 @@
|
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
|
-
"build": "
|
|
104
|
-
"build:deps": "
|
|
105
|
-
"build:standalone": "
|
|
103
|
+
"build": "npm run build:deps && tsdown --config tsdown.config.ts && tsx ../../scripts/vendor-syncore-internals.ts",
|
|
104
|
+
"build:deps": "npm run build --workspace @syncore/core && npm run build --workspace @syncore/schema && npm run build --workspace @syncore/devtools-protocol && npm run build --workspace @syncore/cli && npm run build --workspace @syncore/react && npm run build --workspace @syncore/platform-web && npm run build --workspace @syncore/platform-node && npm run build --workspace @syncore/platform-expo && npm run build --workspace @syncore/next && npm run build --workspace @syncore/svelte",
|
|
105
|
+
"build:standalone": "npm run build",
|
|
106
106
|
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
107
107
|
"lint": "eslint src --ext .ts,.tsx",
|
|
108
108
|
"test": "vitest run --passWithNoTests",
|
|
109
109
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"adm-zip": "^0.5.
|
|
113
|
-
"commander": "^
|
|
112
|
+
"adm-zip": "^0.5.17",
|
|
113
|
+
"commander": "^14.0.3",
|
|
114
114
|
"date-fns-tz": "^3.2.0",
|
|
115
115
|
"node-sql-parser": "^5.4.0",
|
|
116
116
|
"sql.js": "^1.14.1",
|
|
117
|
-
"tsx": "^4.
|
|
118
|
-
"ws": "^8.
|
|
117
|
+
"tsx": "^4.22.3",
|
|
118
|
+
"ws": "^8.21.0"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
|
-
"expo-file-system": "^
|
|
122
|
-
"expo-sqlite": "^
|
|
123
|
-
"next": "^15.0.0",
|
|
121
|
+
"expo-file-system": "^56.0.7",
|
|
122
|
+
"expo-sqlite": "^56.0.4",
|
|
123
|
+
"next": "^15.0.0 || ^16.0.0",
|
|
124
124
|
"react": "^18.3.0 || ^19.0.0",
|
|
125
125
|
"react-dom": "^18.3.0 || ^19.0.0",
|
|
126
126
|
"svelte": "^5.0.0"
|
|
@@ -146,15 +146,18 @@
|
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
|
-
"@syncore/cli": "
|
|
150
|
-
"@syncore/core": "
|
|
151
|
-
"@syncore/devtools-protocol": "
|
|
152
|
-
"@syncore/next": "
|
|
153
|
-
"@syncore/platform-expo": "
|
|
154
|
-
"@syncore/platform-node": "
|
|
155
|
-
"@syncore/platform-web": "
|
|
156
|
-
"@syncore/react": "
|
|
157
|
-
"@syncore/schema": "
|
|
158
|
-
"@syncore/svelte": "
|
|
149
|
+
"@syncore/cli": "^0.1.0",
|
|
150
|
+
"@syncore/core": "^0.1.0",
|
|
151
|
+
"@syncore/devtools-protocol": "^0.1.0",
|
|
152
|
+
"@syncore/next": "^0.1.0",
|
|
153
|
+
"@syncore/platform-expo": "^0.1.0",
|
|
154
|
+
"@syncore/platform-node": "^0.1.0",
|
|
155
|
+
"@syncore/platform-web": "^0.1.0",
|
|
156
|
+
"@syncore/react": "^0.1.0",
|
|
157
|
+
"@syncore/schema": "^0.1.0",
|
|
158
|
+
"@syncore/svelte": "^0.1.0",
|
|
159
|
+
"expo-file-system": "^56.0.7",
|
|
160
|
+
"expo-sqlite": "^56.0.4",
|
|
161
|
+
"next": "16.3.0-canary.27"
|
|
159
162
|
}
|
|
160
163
|
}
|