@sqlrooms/mosaic 0.28.0 → 0.29.0-rc.0
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/MosaicSlice.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DuckDbSliceState } from '@sqlrooms/duckdb';
|
|
2
|
+
import { type SliceFunctions } from '@sqlrooms/room-store';
|
|
2
3
|
import { Connector, Coordinator, makeClient, Selection } from '@uwdata/mosaic-core';
|
|
3
4
|
import { Query } from '@uwdata/mosaic-sql';
|
|
4
5
|
import { z } from 'zod';
|
|
5
|
-
import { SliceFunctions } from '../../room-store/dist/BaseRoomStore';
|
|
6
6
|
export declare const MosaicSliceConfig: z.ZodObject<{}, z.core.$strip>;
|
|
7
7
|
export type MosaicSliceConfig = z.infer<typeof MosaicSliceConfig>;
|
|
8
8
|
export type MosaicClientOptions<T = unknown> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MosaicSlice.d.ts","sourceRoot":"","sources":["../src/MosaicSlice.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MosaicSlice.d.ts","sourceRoot":"","sources":["../src/MosaicSlice.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAwB,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,WAAW,EAEX,UAAU,EACV,SAAS,EAEV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,eAAO,MAAM,iBAAiB,gCAAe,CAAC;AAC9C,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAGlE,MAAM,MAAM,mBAAmB,CAAC,CAA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AS,CAAC,CAAC;QACtC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,0DAA0D;QAC1D,YAAY,EAAE,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,KACtC,SAAS,CAAC;QACf,6CAA6C;QAC7C,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;QAC7D,4FAA4F;QAC5F,YAAY,EAAE,CAAC,CAAC,EACd,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG;YAChC,EAAE,EAAE,MAAM,CAAC;YACX,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;SACrC,KACE,IAAI,CAAC;QACV,2CAA2C;QAC3C,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;QACpC,kDAAkD;QAClD,iBAAiB,EAAE,MAAM,IAAI,CAAC;KAC/B,CAAC;CACH,CAAC;AAEF,wBAAgB,yBAAyB,CACvC,KAAK,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACjC,iBAAiB,CAInB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrC,oDAoPA;AAED,MAAM,MAAM,0BAA0B,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAE7E,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,QAAQ,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,CAAC,GACjD,CAAC,CAIH"}
|
package/dist/MosaicSlice.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { createId } from '@paralleldrive/cuid2';
|
|
1
2
|
import { isWasmDuckDbConnector } from '@sqlrooms/duckdb';
|
|
2
|
-
import { createSlice, useBaseRoomStore, } from '@sqlrooms/room-
|
|
3
|
+
import { createSlice, useBaseRoomStore, } from '@sqlrooms/room-store';
|
|
3
4
|
import { coordinator, makeClient, Selection, wasmConnector, } from '@uwdata/mosaic-core';
|
|
4
|
-
import { createId } from '@paralleldrive/cuid2';
|
|
5
5
|
import { produce } from 'immer';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
export const MosaicSliceConfig = z.object({});
|
package/dist/MosaicSlice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MosaicSlice.js","sourceRoot":"","sources":["../src/MosaicSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAEL,WAAW,EACX,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,WAAW,EACX,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AA6D9C,MAAM,UAAU,yBAAyB,CACvC,KAAkC;IAElC,OAAO;QACL,GAAG,KAAK;KACY,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAEjC;IACC,OAAO,WAAW,CAGhB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACtB,MAAM,EAAE;YACN,MAAM,EAAE,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC;YAChD,UAAU,EAAE;gBACV,MAAM,EAAE,MAAM;gBACd,SAAS,EAAE,SAAS;aACrB;YACD,OAAO,EAAE,EAAE;YACX,UAAU,EAAE,EAAE;YAEd,K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,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAClC,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;YAED,iBAAiB;gBACf,MAAM,EAAC,UAAU,EAAE,OAAO,EAAC,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;gBAE3C,IAAI,UAAU,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;oBAClC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;wBACzC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpD,CAAC,CAAC,CAAC;gBACL,CAAC;gBAED,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,KAAK,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;gBAC5B,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAID,MAAM,UAAU,kBAAkB,CAChC,QAAkD;IAElD,OAAO,gBAAgB,CAAwB,CAAC,KAAK,EAAE,EAAE,CACvD,QAAQ,CAAC,KAA8C,CAAC,CACzD,CAAC;AACJ,CAAC","sourcesContent":["import {DuckDbSliceState, isWasmDuckDbConnector} from '@sqlrooms/duckdb';\nimport {\n BaseRoomStoreState,\n createSlice,\n useBaseRoomStore,\n} from '@sqlrooms/room-shell';\nimport {\n Connector,\n Coordinator,\n coordinator,\n makeClient,\n Selection,\n wasmConnector,\n} from '@uwdata/mosaic-core';\nimport {Query} from '@uwdata/mosaic-sql';\nimport {createId} from '@paralleldrive/cuid2';\nimport {produce} from 'immer';\nimport {z} from 'zod';\nimport {SliceFunctions} from '../../room-store/dist/BaseRoomStore';\n\nexport const MosaicSliceConfig = z.object({});\nexport type MosaicSliceConfig = z.infer<typeof MosaicSliceConfig>;\n\n// Client configuration options\nexport type MosaicClientOptions<T = unknown> = {\n /** Unique identifier for this client */\n id?: string;\n /** Selection name for cross-filtering (will create if doesn't exist) */\n selectionName?: string;\n /** The selection to subscribe to for cross-filtering */\n selection?: Selection;\n /** Query builder function that receives the current filter */\n query: (filter: unknown) => ReturnType<typeof Query.from>;\n /** Callback when query results are received */\n queryResult?: (result: T) => void;\n};\n\n// Tracked client info\nexport type TrackedClient<T = unknown> = {\n id: string;\n client: ReturnType<typeof makeClient>;\n createdAt: number;\n isLoading: boolean;\n data: T | null;\n selection?: Selection; // Track for change detection\n queryResultCallback?: (result: T) => void; // External callback\n};\n\nexport type MosaicSliceState = {\n mosaic: SliceFunctions & {\n connection:\n | {status: 'idle' | 'loading'}\n | {status: 'ready'; connector: Connector; coordinator: Coordinator}\n | {status: 'error'; error: unknown};\n config: MosaicSliceConfig;\n /** Record of registered clients by id */\n clients: Record<string, TrackedClient<unknown>>;\n /** Named selections for cross-filtering (e.g., 'brush', 'hover') */\n selections: Record<string, Selection>;\n initialize: () => Promise<void>;\n /** Get or create a named selection for cross-filtering */\n getSelection: (\n name: string,\n type?: 'crossfilter' | 'single' | 'union',\n ) => Selection;\n /** Create a mosaic client and register it */\n createClient: <T>(options: MosaicClientOptions<T>) => string;\n /** Ensure a client exists with given options (idempotent - creates or updates as needed) */\n ensureClient: <T>(\n options: MosaicClientOptions<T> & {\n id: string;\n onQueryResult?: (result: T) => void;\n },\n ) => void;\n /** Disconnect and remove a client by id */\n destroyClient: (id: string) => void;\n /** Disconnect all clients (useful for cleanup) */\n destroyAllClients: () => void;\n };\n};\n\nexport function createDefaultMosaicConfig(\n props?: Partial<MosaicSliceConfig>,\n): MosaicSliceConfig {\n return {\n ...props,\n } as MosaicSliceConfig;\n}\n\nexport function createMosaicSlice(props?: {\n config?: Partial<MosaicSliceConfig>;\n}) {\n return createSlice<\n MosaicSliceState,\n BaseRoomStoreState & DuckDbSliceState & MosaicSliceState\n >((set, get, store) => ({\n mosaic: {\n config: createDefaultMosaicConfig(props?.config),\n connection: {\n status: 'idle',\n connector: undefined,\n },\n clients: {},\n selections: {},\n\n async initialize() {\n let mosaicConnector: Connector | undefined;\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.connection = {status: 'loading'};\n }),\n );\n try {\n const dbConnector = await get().db.getConnector();\n if (!isWasmDuckDbConnector(dbConnector)) {\n throw new Error('Only WasmDuckDbConnector is currently supported');\n }\n mosaicConnector = await coordinator().databaseConnector(\n wasmConnector({\n // @ts-expect-error - We install a different version of duckdb-wasm\n duckDb: dbConnector.getDb(),\n connection: dbConnector.getConnection(),\n }),\n );\n } catch (error) {\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.connection = {status: 'error', error};\n }),\n );\n throw error;\n } finally {\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.connection = {\n status: 'ready',\n connector: mosaicConnector!,\n coordinator: coordinator(),\n };\n }),\n );\n }\n },\n\n async destroy() {\n get().mosaic.destroyAllClients();\n },\n\n getSelection(\n name: string,\n type: 'crossfilter' | 'single' | 'union' = 'crossfilter',\n ) {\n const existing = get().mosaic.selections[name];\n if (existing) return existing;\n\n const selection =\n type === 'crossfilter'\n ? Selection.crossfilter()\n : type === 'single'\n ? Selection.single()\n : Selection.union();\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.selections[name] = selection;\n }),\n );\n return selection;\n },\n\n createClient<T>(options: MosaicClientOptions<T>) {\n const {connection} = get().mosaic;\n if (connection.status !== 'ready') {\n throw new Error('Mosaic connection not ready');\n }\n\n const id = options.id ?? createId();\n\n // Determine which selection to use\n const selection =\n options.selection ??\n (options.selectionName\n ? get().mosaic.getSelection(options.selectionName)\n : undefined);\n\n // Wrap queryResult to update store state AND call external callback\n const wrappedQueryResult = (data: unknown) => {\n const typedData = data as T;\n set((state) =>\n produce(state, (draft) => {\n const tracked = draft.mosaic.clients[id];\n if (tracked) {\n tracked.data = typedData;\n tracked.isLoading = false;\n }\n }),\n );\n // Call external callback if provided\n options.queryResult?.(typedData);\n };\n\n const client = makeClient({\n coordinator: connection.coordinator,\n selection,\n query: options.query,\n queryResult: wrappedQueryResult,\n });\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.clients[id] = {\n id,\n client,\n createdAt: Date.now(),\n isLoading: true,\n data: null,\n selection,\n queryResultCallback: options.queryResult\n ? (result: unknown) => options.queryResult!(result as T)\n : undefined,\n };\n }),\n );\n\n return id;\n },\n\n ensureClient<T>(\n options: MosaicClientOptions<T> & {\n id: string;\n onQueryResult?: (result: T) => void;\n },\n ) {\n const {connection, clients} = get().mosaic;\n if (connection.status !== 'ready') {\n return; // Silently return if not ready - hook will handle retry\n }\n\n const existing = clients[options.id];\n\n // Determine which selection to use\n const selection =\n options.selection ??\n (options.selectionName\n ? get().mosaic.getSelection(options.selectionName)\n : undefined);\n\n // Check if client exists and selection matches\n // Note: If query or callback changes, we recreate the client to ensure\n // the latest versions are used. This is simpler than trying to update\n // the bound queryResult callback in makeClient.\n if (existing && existing.selection === selection) {\n return; // No-op - client already exists with same selection\n }\n\n // If exists but selection changed, destroy it first\n if (existing) {\n get().mosaic.destroyClient(options.id);\n }\n\n // Create new client with wrapped queryResult that calls both store update and external callback\n const wrappedQueryResult = (data: unknown) => {\n const typedData = data as T;\n set((state) =>\n produce(state, (draft) => {\n const tracked = draft.mosaic.clients[options.id];\n if (tracked) {\n tracked.data = typedData;\n tracked.isLoading = false;\n }\n }),\n );\n // Call external callback if provided\n options.onQueryResult?.(typedData);\n // Also call original queryResult if provided\n options.queryResult?.(typedData);\n };\n\n const client = makeClient({\n coordinator: connection.coordinator,\n selection,\n query: options.query,\n queryResult: wrappedQueryResult,\n });\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.clients[options.id] = {\n id: options.id,\n client,\n createdAt: Date.now(),\n isLoading: true,\n data: null,\n selection,\n queryResultCallback: options.onQueryResult as\n | ((result: unknown) => void)\n | undefined,\n };\n }),\n );\n },\n\n destroyClient(id: string) {\n const {connection, clients} = get().mosaic;\n const tracked = clients[id];\n if (!tracked) return;\n\n if (connection.status === 'ready') {\n connection.coordinator.disconnect(tracked.client);\n }\n\n set((state) =>\n produce(state, (draft) => {\n delete draft.mosaic.clients[id];\n }),\n );\n },\n\n destroyAllClients() {\n const {connection, clients} = get().mosaic;\n\n if (connection.status === 'ready') {\n Object.values(clients).forEach((tracked) => {\n connection.coordinator.disconnect(tracked.client);\n });\n }\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.clients = {};\n }),\n );\n },\n },\n }));\n}\n\nexport type DuckDbSliceStateWithMosaic = DuckDbSliceState & MosaicSliceState;\n\nexport function useStoreWithMosaic<T>(\n selector: (state: DuckDbSliceStateWithMosaic) => T,\n): T {\n return useBaseRoomStore<BaseRoomStoreState, T>((state) =>\n selector(state as unknown as DuckDbSliceStateWithMosaic),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MosaicSlice.js","sourceRoot":"","sources":["../src/MosaicSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAmB,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAEL,WAAW,EACX,gBAAgB,GAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,WAAW,EACX,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AA6D9C,MAAM,UAAU,yBAAyB,CACvC,KAAkC;IAElC,OAAO;QACL,GAAG,KAAK;KACY,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAEjC;IACC,OAAO,WAAW,CAGhB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,E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K,OAAO,EAAE,CAAC;oBAClC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpD,CAAC;gBAED,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAClC,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;YAED,iBAAiB;gBACf,MAAM,EAAC,UAAU,EAAE,OAAO,EAAC,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC;gBAE3C,IAAI,UAAU,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;oBAClC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;wBACzC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpD,CAAC,CAAC,CAAC;gBACL,CAAC;gBAED,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,KAAK,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;gBAC5B,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAID,MAAM,UAAU,kBAAkB,CAChC,QAAkD;IAElD,OAAO,gBAAgB,CAAwB,CAAC,KAAK,EAAE,EAAE,CACvD,QAAQ,CAAC,KAA8C,CAAC,CACzD,CAAC;AACJ,CAAC","sourcesContent":["import {createId} from '@paralleldrive/cuid2';\nimport {DuckDbSliceState, isWasmDuckDbConnector} from '@sqlrooms/duckdb';\nimport {\n BaseRoomStoreState,\n createSlice,\n useBaseRoomStore,\n type SliceFunctions,\n} from '@sqlrooms/room-store';\nimport {\n Connector,\n Coordinator,\n coordinator,\n makeClient,\n Selection,\n wasmConnector,\n} from '@uwdata/mosaic-core';\nimport {Query} from '@uwdata/mosaic-sql';\nimport {produce} from 'immer';\nimport {z} from 'zod';\n\nexport const MosaicSliceConfig = z.object({});\nexport type MosaicSliceConfig = z.infer<typeof MosaicSliceConfig>;\n\n// Client configuration options\nexport type MosaicClientOptions<T = unknown> = {\n /** Unique identifier for this client */\n id?: string;\n /** Selection name for cross-filtering (will create if doesn't exist) */\n selectionName?: string;\n /** The selection to subscribe to for cross-filtering */\n selection?: Selection;\n /** Query builder function that receives the current filter */\n query: (filter: unknown) => ReturnType<typeof Query.from>;\n /** Callback when query results are received */\n queryResult?: (result: T) => void;\n};\n\n// Tracked client info\nexport type TrackedClient<T = unknown> = {\n id: string;\n client: ReturnType<typeof makeClient>;\n createdAt: number;\n isLoading: boolean;\n data: T | null;\n selection?: Selection; // Track for change detection\n queryResultCallback?: (result: T) => void; // External callback\n};\n\nexport type MosaicSliceState = {\n mosaic: SliceFunctions & {\n connection:\n | {status: 'idle' | 'loading'}\n | {status: 'ready'; connector: Connector; coordinator: Coordinator}\n | {status: 'error'; error: unknown};\n config: MosaicSliceConfig;\n /** Record of registered clients by id */\n clients: Record<string, TrackedClient<unknown>>;\n /** Named selections for cross-filtering (e.g., 'brush', 'hover') */\n selections: Record<string, Selection>;\n initialize: () => Promise<void>;\n /** Get or create a named selection for cross-filtering */\n getSelection: (\n name: string,\n type?: 'crossfilter' | 'single' | 'union',\n ) => Selection;\n /** Create a mosaic client and register it */\n createClient: <T>(options: MosaicClientOptions<T>) => string;\n /** Ensure a client exists with given options (idempotent - creates or updates as needed) */\n ensureClient: <T>(\n options: MosaicClientOptions<T> & {\n id: string;\n onQueryResult?: (result: T) => void;\n },\n ) => void;\n /** Disconnect and remove a client by id */\n destroyClient: (id: string) => void;\n /** Disconnect all clients (useful for cleanup) */\n destroyAllClients: () => void;\n };\n};\n\nexport function createDefaultMosaicConfig(\n props?: Partial<MosaicSliceConfig>,\n): MosaicSliceConfig {\n return {\n ...props,\n } as MosaicSliceConfig;\n}\n\nexport function createMosaicSlice(props?: {\n config?: Partial<MosaicSliceConfig>;\n}) {\n return createSlice<\n MosaicSliceState,\n BaseRoomStoreState & DuckDbSliceState & MosaicSliceState\n >((set, get, store) => ({\n mosaic: {\n config: createDefaultMosaicConfig(props?.config),\n connection: {\n status: 'idle',\n connector: undefined,\n },\n clients: {},\n selections: {},\n\n async initialize() {\n let mosaicConnector: Connector | undefined;\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.connection = {status: 'loading'};\n }),\n );\n try {\n const dbConnector = await get().db.getConnector();\n if (!isWasmDuckDbConnector(dbConnector)) {\n throw new Error('Only WasmDuckDbConnector is currently supported');\n }\n mosaicConnector = await coordinator().databaseConnector(\n wasmConnector({\n // @ts-expect-error - We install a different version of duckdb-wasm\n duckDb: dbConnector.getDb(),\n connection: dbConnector.getConnection(),\n }),\n );\n } catch (error) {\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.connection = {status: 'error', error};\n }),\n );\n throw error;\n } finally {\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.connection = {\n status: 'ready',\n connector: mosaicConnector!,\n coordinator: coordinator(),\n };\n }),\n );\n }\n },\n\n async destroy() {\n get().mosaic.destroyAllClients();\n },\n\n getSelection(\n name: string,\n type: 'crossfilter' | 'single' | 'union' = 'crossfilter',\n ) {\n const existing = get().mosaic.selections[name];\n if (existing) return existing;\n\n const selection =\n type === 'crossfilter'\n ? Selection.crossfilter()\n : type === 'single'\n ? Selection.single()\n : Selection.union();\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.selections[name] = selection;\n }),\n );\n return selection;\n },\n\n createClient<T>(options: MosaicClientOptions<T>) {\n const {connection} = get().mosaic;\n if (connection.status !== 'ready') {\n throw new Error('Mosaic connection not ready');\n }\n\n const id = options.id ?? createId();\n\n // Determine which selection to use\n const selection =\n options.selection ??\n (options.selectionName\n ? get().mosaic.getSelection(options.selectionName)\n : undefined);\n\n // Wrap queryResult to update store state AND call external callback\n const wrappedQueryResult = (data: unknown) => {\n const typedData = data as T;\n set((state) =>\n produce(state, (draft) => {\n const tracked = draft.mosaic.clients[id];\n if (tracked) {\n tracked.data = typedData;\n tracked.isLoading = false;\n }\n }),\n );\n // Call external callback if provided\n options.queryResult?.(typedData);\n };\n\n const client = makeClient({\n coordinator: connection.coordinator,\n selection,\n query: options.query,\n queryResult: wrappedQueryResult,\n });\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.clients[id] = {\n id,\n client,\n createdAt: Date.now(),\n isLoading: true,\n data: null,\n selection,\n queryResultCallback: options.queryResult\n ? (result: unknown) => options.queryResult!(result as T)\n : undefined,\n };\n }),\n );\n\n return id;\n },\n\n ensureClient<T>(\n options: MosaicClientOptions<T> & {\n id: string;\n onQueryResult?: (result: T) => void;\n },\n ) {\n const {connection, clients} = get().mosaic;\n if (connection.status !== 'ready') {\n return; // Silently return if not ready - hook will handle retry\n }\n\n const existing = clients[options.id];\n\n // Determine which selection to use\n const selection =\n options.selection ??\n (options.selectionName\n ? get().mosaic.getSelection(options.selectionName)\n : undefined);\n\n // Check if client exists and selection matches\n // Note: If query or callback changes, we recreate the client to ensure\n // the latest versions are used. This is simpler than trying to update\n // the bound queryResult callback in makeClient.\n if (existing && existing.selection === selection) {\n return; // No-op - client already exists with same selection\n }\n\n // If exists but selection changed, destroy it first\n if (existing) {\n get().mosaic.destroyClient(options.id);\n }\n\n // Create new client with wrapped queryResult that calls both store update and external callback\n const wrappedQueryResult = (data: unknown) => {\n const typedData = data as T;\n set((state) =>\n produce(state, (draft) => {\n const tracked = draft.mosaic.clients[options.id];\n if (tracked) {\n tracked.data = typedData;\n tracked.isLoading = false;\n }\n }),\n );\n // Call external callback if provided\n options.onQueryResult?.(typedData);\n // Also call original queryResult if provided\n options.queryResult?.(typedData);\n };\n\n const client = makeClient({\n coordinator: connection.coordinator,\n selection,\n query: options.query,\n queryResult: wrappedQueryResult,\n });\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.clients[options.id] = {\n id: options.id,\n client,\n createdAt: Date.now(),\n isLoading: true,\n data: null,\n selection,\n queryResultCallback: options.onQueryResult as\n | ((result: unknown) => void)\n | undefined,\n };\n }),\n );\n },\n\n destroyClient(id: string) {\n const {connection, clients} = get().mosaic;\n const tracked = clients[id];\n if (!tracked) return;\n\n if (connection.status === 'ready') {\n connection.coordinator.disconnect(tracked.client);\n }\n\n set((state) =>\n produce(state, (draft) => {\n delete draft.mosaic.clients[id];\n }),\n );\n },\n\n destroyAllClients() {\n const {connection, clients} = get().mosaic;\n\n if (connection.status === 'ready') {\n Object.values(clients).forEach((tracked) => {\n connection.coordinator.disconnect(tracked.client);\n });\n }\n\n set((state) =>\n produce(state, (draft) => {\n draft.mosaic.clients = {};\n }),\n );\n },\n },\n }));\n}\n\nexport type DuckDbSliceStateWithMosaic = DuckDbSliceState & MosaicSliceState;\n\nexport function useStoreWithMosaic<T>(\n selector: (state: DuckDbSliceStateWithMosaic) => T,\n): T {\n return useBaseRoomStore<BaseRoomStoreState, T>((state) =>\n selector(state as unknown as DuckDbSliceStateWithMosaic),\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/mosaic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0-rc.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@paralleldrive/cuid2": "^3.0.0",
|
|
23
|
-
"@sqlrooms/duckdb": "0.
|
|
24
|
-
"@sqlrooms/room-
|
|
23
|
+
"@sqlrooms/duckdb": "0.29.0-rc.0",
|
|
24
|
+
"@sqlrooms/room-store": "0.29.0-rc.0",
|
|
25
25
|
"@uwdata/mosaic-core": "^0.21.0",
|
|
26
26
|
"@uwdata/mosaic-spec": "^0.21.0",
|
|
27
27
|
"@uwdata/mosaic-sql": "^0.21.0",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"typecheck": "tsc --noEmit",
|
|
41
41
|
"typedoc": "typedoc"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "afdb949c9601b4cdeaae966157a25a54aea2ae54"
|
|
44
44
|
}
|