@sqlrooms/deck 0.29.0-rc.5 → 0.29.0-rc.7
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/README.md +24 -2
- package/dist/DeckJsonMap.d.ts +1 -1
- package/dist/DeckJsonMap.d.ts.map +1 -1
- package/dist/DeckJsonMap.js +16 -11
- package/dist/DeckJsonMap.js.map +1 -1
- package/dist/LatitudeSelector.d.ts +11 -0
- package/dist/LatitudeSelector.d.ts.map +1 -0
- package/dist/LatitudeSelector.js +25 -0
- package/dist/LatitudeSelector.js.map +1 -0
- package/dist/LongitudeSelector.d.ts +11 -0
- package/dist/LongitudeSelector.d.ts.map +1 -0
- package/dist/LongitudeSelector.js +27 -0
- package/dist/LongitudeSelector.js.map +1 -0
- package/dist/MapSettings.d.ts +10 -0
- package/dist/MapSettings.d.ts.map +1 -0
- package/dist/MapSettings.js +94 -0
- package/dist/MapSettings.js.map +1 -0
- package/dist/ai.d.ts +168 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +232 -0
- package/dist/ai.js.map +1 -0
- package/dist/dashboard.d.ts.map +1 -1
- package/dist/dashboard.js +72 -105
- package/dist/dashboard.js.map +1 -1
- package/dist/dashboardConfig.d.ts +22 -6
- package/dist/dashboardConfig.d.ts.map +1 -1
- package/dist/dashboardConfig.js +2 -5
- package/dist/dashboardConfig.js.map +1 -1
- package/dist/dashboardIntegration.d.ts +3 -0
- package/dist/dashboardIntegration.d.ts.map +1 -0
- package/dist/dashboardIntegration.js +16 -0
- package/dist/dashboardIntegration.js.map +1 -0
- package/dist/datasets/PreparedDatasetStore.js +2 -1
- package/dist/datasets/PreparedDatasetStore.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/json/colorScaleFunction.d.ts +1 -1
- package/dist/json/colorScaleFunction.d.ts.map +1 -1
- package/dist/json/colorScaleFunction.js +7 -1
- package/dist/json/colorScaleFunction.js.map +1 -1
- package/dist/json/extractColorScaleLegends.d.ts.map +1 -1
- package/dist/json/extractColorScaleLegends.js +0 -1
- package/dist/json/extractColorScaleLegends.js.map +1 -1
- package/dist/json/layerCompatibility.d.ts.map +1 -1
- package/dist/json/layerCompatibility.js +2 -0
- package/dist/json/layerCompatibility.js.map +1 -1
- package/dist/mapConfigUtils.d.ts +62 -0
- package/dist/mapConfigUtils.d.ts.map +1 -0
- package/dist/mapConfigUtils.js +233 -0
- package/dist/mapConfigUtils.js.map +1 -0
- package/dist/mapDataPolicy.d.ts +4 -0
- package/dist/mapDataPolicy.d.ts.map +1 -0
- package/dist/mapDataPolicy.js +25 -0
- package/dist/mapDataPolicy.js.map +1 -0
- package/dist/mapLayerConfigUtils.d.ts +38 -0
- package/dist/mapLayerConfigUtils.d.ts.map +1 -0
- package/dist/mapLayerConfigUtils.js +185 -0
- package/dist/mapLayerConfigUtils.js.map +1 -0
- package/dist/prepare/wkbDecoder.d.ts.map +1 -1
- package/dist/prepare/wkbDecoder.js +266 -67
- package/dist/prepare/wkbDecoder.js.map +1 -1
- package/dist/prepare/wkbParser.d.ts +19 -0
- package/dist/prepare/wkbParser.d.ts.map +1 -0
- package/dist/prepare/wkbParser.js +115 -0
- package/dist/prepare/wkbParser.js.map +1 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -6
- package/dist/useDeckLayersReadyRedraw.d.ts +0 -13
- package/dist/useDeckLayersReadyRedraw.d.ts.map +0 -1
- package/dist/useDeckLayersReadyRedraw.js +0 -35
- package/dist/useDeckLayersReadyRedraw.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreparedDatasetStore.js","sourceRoot":"","sources":["../../src/datasets/PreparedDatasetStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAA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MAAM,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,EAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC,CAAC;IAC/C,CAAC;IAED,OAAO;QACL,MAAM,EAAE,OAAO;QACf,QAAQ,EACN,KAAK,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS;YACpC,CAAC,CAAC,KAAK,CAAC,QAAQ;YAChB,CAAC,CAAC;gBACE,GAAG,KAAK,CAAC,QAAQ;gBACjB,SAAS;aACV;KACR,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAAC,OAIhD;IACC,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAC,GAAG,OAAO,CAAC;IAEvD,OAAO,MAAM,CAAC,WAAW,CACvB,iCAAiC,CAAC,EAAC,QAAQ,EAAE,iBAAiB,EAAC,CAAC,CAAC,GAAG,CAClE,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC;QACzB,SAAS;QACT,+BAA+B,CAAC;YAC9B,SAAS;YACT,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;SAChD,CAAC;KACH,CACF,CACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,EAAE,CAAC","sourcesContent":["import type {QueryHandle} from '@sqlrooms/duckdb';\nimport {createStore} from 'zustand/vanilla';\nimport {prepareDeckDataset} from '../prepare/prepareDeckDataset';\nimport {\n isSqlDatasetInput,\n type DeckDatasetInput,\n type PreparedDeckDatasetState,\n} from '../types';\nimport {\n DEFAULT_MAX_PREPARED_DATASET_ENTRIES,\n cloneEntryWithConsumers,\n evictLruEntries,\n nextAccessTimestamp,\n resolvePreparedDatasetCacheKey,\n touchEntry,\n} from './helpers';\nimport {resolveArrowTable} from './normalizeDatasets';\nimport type {\n PreparedDatasetCacheEntry,\n PreparedDatasetStoreOptions,\n} from './types';\n\n/**\n * Internal store state for the prepared-dataset cache.\n *\n * `DeckJsonMap` never talks to this shape directly; `usePreparedDatasetStates`\n * uses it as the backing state machine for preparation, reuse, and eviction.\n */\ntype PreparedDatasetStoreState = {\n /**\n * Cache keys currently referenced by each hook consumer.\n *\n * This lets the store update consumer memberships incrementally when a map's\n * dataset registry changes, instead of resetting all cache state.\n */\n consumerKeys: Record<string, string[]>;\n /**\n * Prepared entries keyed by resolved dataset identity.\n *\n * Keys are based on query/table identity plus geometry options, not dataset\n * id, so the same prepared result can be reused across multiple maps or\n * differently named datasets that point at the same underlying data.\n */\n entries: Record<string, PreparedDatasetCacheEntry>;\n /**\n * Ensure a cache entry exists for the given dataset key.\n *\n * If an entry already exists, this is a no-op other than touching its LRU\n * metadata. Otherwise the store creates a `loading` entry, resolves the\n * source table through DuckDB if needed, runs `prepareDeckDataset(...)`, and\n * stores the resulting `ready` or `error` state.\n */\n ensureEntry: (options: {\n cacheKey: string;\n datasetId: string;\n executeSql: (\n query: string,\n version?: number,\n ) => Promise<QueryHandle | null>;\n input: DeckDatasetInput;\n }) => void;\n /**\n * Remove all subscriptions for one hook consumer.\n *\n * This is called when a `DeckJsonMap` instance unmounts so the store can\n * release the consumer's references and allow now-unreferenced entries to be\n * evicted later.\n */\n removeConsumer: (consumerId: string) => void;\n /**\n * Reconcile the set of cache keys referenced by one hook consumer.\n *\n * This adds the consumer to newly needed entries, removes it from entries no\n * longer needed, and preserves existing entries in place so unrelated dataset\n * states do not get reset during prop changes.\n */\n syncConsumer: (consumerId: string, keys: string[]) => void;\n /**\n * Reconcile and ensure all prepared entries needed by one dataset registry.\n *\n * This is the store-level orchestration entrypoint used by\n * `usePreparedDatasetStates`. It computes cache keys for the current dataset\n * registry, syncs consumer memberships, and eagerly ensures any resolvable\n * entries exist.\n */\n syncDatasetsForConsumer: (options: {\n consumerId: string;\n datasets: Record<string, DeckDatasetInput>;\n executeSql: (\n query: string,\n version?: number,\n ) => Promise<QueryHandle | null>;\n sqlSourceIdentity: object;\n }) => void;\n};\n\ntype PreparedDatasetDescriptor = {\n datasetId: string;\n input: DeckDatasetInput;\n cacheKey: string | undefined;\n};\n\nfunction resolvePreparedDatasetDescriptors(options: {\n datasets: Record<string, DeckDatasetInput>;\n sqlSourceIdentity: object;\n}): PreparedDatasetDescriptor[] {\n const {datasets, sqlSourceIdentity} = options;\n\n return Object.entries(datasets).map(([datasetId, input]) => ({\n datasetId,\n input,\n cacheKey: resolvePreparedDatasetCacheKey({\n input,\n sqlSourceIdentity,\n }),\n }));\n}\n\n/**\n * Create a feature-local cache store for prepared deck datasets.\n *\n * The store is intentionally scoped to deck's preparation layer. It reuses the\n * expensive result of `prepareDeckDataset(...)` across consumers while leaving\n * raw query/result caching to the upstream data provider:\n *\n * - Mosaic handles cached query results through its coordinator/query manager\n * - DuckDB-backed SQL datasets still use the DuckDB slice execution path\n *\n * This keeps `@sqlrooms/deck` independent from either provider while still\n * avoiding repeated geometry decoding and GeoArrow/GeoJSON shaping work.\n */\nexport function createPreparedDatasetStore(\n options: PreparedDatasetStoreOptions = {},\n) {\n const {\n maxEntries = DEFAULT_MAX_PREPARED_DATASET_ENTRIES,\n prepareDataset = prepareDeckDataset,\n } = options;\n\n return createStore<PreparedDatasetStoreState>((set, get) => ({\n consumerKeys: {},\n entries: {},\n\n ensureEntry({cacheKey, datasetId, executeSql, input}) {\n const existing = get().entries[cacheKey];\n if (existing) {\n if (existing.status !== 'loading') {\n set((state) => ({\n ...state,\n entries: {\n ...state.entries,\n [cacheKey]: touchEntry(existing),\n },\n }));\n }\n return;\n }\n\n const promise = Promise.resolve().then(async () => {\n try {\n let table = resolveArrowTable(input);\n if (!table && isSqlDatasetInput(input)) {\n const queryHandle = await executeSql(input.sqlQuery);\n if (!queryHandle) {\n throw new Error(\n `Query for dataset \"${datasetId}\" was cancelled.`,\n );\n }\n\n table = await queryHandle;\n }\n\n if (!table) {\n return;\n }\n\n const prepared = prepareDataset({\n datasetId,\n table,\n geometryColumn: input.geometryColumn,\n geometryEncodingHint: input.geometryEncodingHint,\n });\n\n set((state) => ({\n ...state,\n entries: evictLruEntries(\n {\n ...state.entries,\n [cacheKey]: {\n status: 'ready',\n prepared,\n consumers:\n state.entries[cacheKey]?.consumers ?? new Set<string>(),\n lastAccessedAt: nextAccessTimestamp(),\n },\n },\n maxEntries,\n ),\n }));\n } catch (error) {\n set((state) => ({\n ...state,\n entries: evictLruEntries(\n {\n ...state.entries,\n [cacheKey]: {\n status: 'error',\n error:\n error instanceof Error ? error : new Error(String(error)),\n consumers:\n state.entries[cacheKey]?.consumers ?? new Set<string>(),\n lastAccessedAt: nextAccessTimestamp(),\n },\n },\n maxEntries,\n ),\n }));\n }\n });\n\n set((state) => ({\n ...state,\n entries: {\n ...state.entries,\n [cacheKey]: {\n status: 'loading',\n promise,\n consumers: state.entries[cacheKey]?.consumers ?? new Set<string>(),\n lastAccessedAt: nextAccessTimestamp(),\n },\n },\n }));\n },\n\n syncConsumer(consumerId, keys) {\n const previousKeys = new Set(get().consumerKeys[consumerId] ?? []);\n const nextKeys = new Set(keys);\n\n set((state) => {\n let didChangeEntries = false;\n let nextEntries = state.entries;\n\n const updateEntry = (\n cacheKey: string,\n updater: (\n entry: PreparedDatasetCacheEntry,\n ) => PreparedDatasetCacheEntry,\n ) => {\n const currentEntry = nextEntries[cacheKey];\n if (!currentEntry) {\n return;\n }\n\n if (!didChangeEntries) {\n nextEntries = {...nextEntries};\n didChangeEntries = true;\n }\n\n nextEntries[cacheKey] = updater(currentEntry);\n };\n\n for (const cacheKey of previousKeys) {\n if (nextKeys.has(cacheKey)) {\n continue;\n }\n\n updateEntry(cacheKey, (entry) => {\n const consumers = new Set(entry.consumers);\n consumers.delete(consumerId);\n return cloneEntryWithConsumers(entry, consumers);\n });\n }\n\n for (const cacheKey of nextKeys) {\n updateEntry(cacheKey, (entry) => {\n const consumers = new Set(entry.consumers);\n consumers.add(consumerId);\n return cloneEntryWithConsumers(entry, consumers);\n });\n }\n\n return {\n ...state,\n consumerKeys: {\n ...state.consumerKeys,\n [consumerId]: [...nextKeys],\n },\n entries: didChangeEntries\n ? evictLruEntries(nextEntries, maxEntries)\n : state.entries,\n };\n });\n },\n\n removeConsumer(consumerId) {\n const previousKeys = get().consumerKeys[consumerId];\n if (!previousKeys) {\n return;\n }\n\n set((state) => {\n let didChangeEntries = false;\n let nextEntries = state.entries;\n\n for (const cacheKey of previousKeys) {\n const entry = nextEntries[cacheKey];\n if (!entry) {\n continue;\n }\n\n const consumers = new Set(entry.consumers);\n consumers.delete(consumerId);\n\n if (!didChangeEntries) {\n nextEntries = {...nextEntries};\n didChangeEntries = true;\n }\n\n nextEntries[cacheKey] = cloneEntryWithConsumers(entry, consumers);\n }\n\n const {[consumerId]: _removedConsumer, ...nextConsumerKeys} =\n state.consumerKeys;\n\n return {\n ...state,\n consumerKeys: nextConsumerKeys,\n entries: didChangeEntries\n ? evictLruEntries(nextEntries, maxEntries)\n : state.entries,\n };\n });\n },\n\n syncDatasetsForConsumer({\n consumerId,\n datasets,\n executeSql,\n sqlSourceIdentity,\n }) {\n const descriptors = resolvePreparedDatasetDescriptors({\n datasets,\n sqlSourceIdentity,\n });\n const cacheKeys = descriptors\n .map((descriptor) => descriptor.cacheKey)\n .filter((cacheKey): cacheKey is string => Boolean(cacheKey));\n\n for (const descriptor of descriptors) {\n if (!descriptor.cacheKey) {\n continue;\n }\n\n get().ensureEntry({\n cacheKey: descriptor.cacheKey,\n datasetId: descriptor.datasetId,\n executeSql,\n input: descriptor.input,\n });\n }\n\n get().syncConsumer(consumerId, cacheKeys);\n },\n }));\n}\n\n/**\n * Resolve a shared prepared-store entry back into the dataset-state shape\n * consumed by `DeckJsonMap`.\n *\n * Prepared entries are shared by cache key, while `datasetId` stays a\n * view-level label used by layer binding and user-facing errors. When a shared\n * prepared entry is reused for a different dataset id, this helper remaps the\n * prepared payload so downstream callers still see the dataset id they asked\n * for.\n */\nexport function resolvePreparedDeckDatasetState(options: {\n datasetId: string;\n entry?: PreparedDatasetCacheEntry;\n}): PreparedDeckDatasetState {\n const {datasetId, entry} = options;\n\n if (!entry || entry.status === 'loading') {\n return {status: 'loading'};\n }\n\n if (entry.status === 'error') {\n return {status: 'error', error: entry.error};\n }\n\n return {\n status: 'ready',\n prepared:\n entry.prepared.datasetId === datasetId\n ? entry.prepared\n : {\n ...entry.prepared,\n datasetId,\n },\n };\n}\n\n/**\n * Resolve the full `datasetId -> state` map for a dataset registry.\n *\n * This mirrors the lookup logic used by `DeckJsonMap`: unresolved Arrow\n * datasets remain `loading`, while resolvable datasets reuse shared prepared\n * entries keyed by data identity rather than by dataset id.\n */\nexport function resolvePreparedDeckDatasetStates(options: {\n datasets: Record<string, DeckDatasetInput>;\n entries: Record<string, PreparedDatasetCacheEntry>;\n sqlSourceIdentity: object;\n}): Record<string, PreparedDeckDatasetState> {\n const {datasets, entries, sqlSourceIdentity} = options;\n\n return Object.fromEntries(\n resolvePreparedDatasetDescriptors({datasets, sqlSourceIdentity}).map(\n ({datasetId, cacheKey}) => [\n datasetId,\n resolvePreparedDeckDatasetState({\n datasetId,\n entry: cacheKey ? entries[cacheKey] : undefined,\n }),\n ],\n ),\n );\n}\n\n/**\n * Module-global prepared dataset cache shared by all `DeckJsonMap` instances.\n *\n * The cache stores only deck-specific prepared payloads, not raw query\n * results, and applies a small internal LRU policy so settled entries do not\n * grow without bound.\n */\nexport const preparedDatasetStore = createPreparedDatasetStore();\n"]}
|
|
1
|
+
{"version":3,"file":"PreparedDatasetStore.js","sourceRoot":"","sources":["../../src/datasets/PreparedDatasetStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EACL,iBAAiB,GAGlB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oCAAoC,EACpC,uBAAuB,EACv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CAAC;IAED,OAAO;QACL,MAAM,EAAE,OAAO;QACf,QAAQ,EACN,KAAK,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS;YACpC,CAAC,CAAC,KAAK,CAAC,QAAQ;YAChB,CAAC,CAAC;gBACE,GAAG,KAAK,CAAC,QAAQ;gBACjB,SAAS;aACV;KACR,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAAC,OAIhD;IACC,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAC,GAAG,OAAO,CAAC;IAEvD,OAAO,MAAM,CAAC,WAAW,CACvB,iCAAiC,CAAC,EAAC,QAAQ,EAAE,iBAAiB,EAAC,CAAC,CAAC,GAAG,CAClE,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC;QACzB,SAAS;QACT,+BAA+B,CAAC;YAC9B,SAAS;YACT,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;SAChD,CAAC;KACH,CACF,CACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,EAAE,CAAC","sourcesContent":["import type {QueryHandle} from '@sqlrooms/duckdb';\nimport {createStore} from 'zustand/vanilla';\nimport {prepareDeckDataset} from '../prepare/prepareDeckDataset';\nimport {\n isSqlDatasetInput,\n type DeckDatasetInput,\n type PreparedDeckDatasetState,\n} from '../types';\nimport {\n DEFAULT_MAX_PREPARED_DATASET_ENTRIES,\n cloneEntryWithConsumers,\n evictLruEntries,\n nextAccessTimestamp,\n resolvePreparedDatasetCacheKey,\n touchEntry,\n} from './helpers';\nimport {resolveArrowTable} from './normalizeDatasets';\nimport type {\n PreparedDatasetCacheEntry,\n PreparedDatasetStoreOptions,\n} from './types';\n\n/**\n * Internal store state for the prepared-dataset cache.\n *\n * `DeckJsonMap` never talks to this shape directly; `usePreparedDatasetStates`\n * uses it as the backing state machine for preparation, reuse, and eviction.\n */\ntype PreparedDatasetStoreState = {\n /**\n * Cache keys currently referenced by each hook consumer.\n *\n * This lets the store update consumer memberships incrementally when a map's\n * dataset registry changes, instead of resetting all cache state.\n */\n consumerKeys: Record<string, string[]>;\n /**\n * Prepared entries keyed by resolved dataset identity.\n *\n * Keys are based on query/table identity plus geometry options, not dataset\n * id, so the same prepared result can be reused across multiple maps or\n * differently named datasets that point at the same underlying data.\n */\n entries: Record<string, PreparedDatasetCacheEntry>;\n /**\n * Ensure a cache entry exists for the given dataset key.\n *\n * If an entry already exists, this is a no-op other than touching its LRU\n * metadata. Otherwise the store creates a `loading` entry, resolves the\n * source table through DuckDB if needed, runs `prepareDeckDataset(...)`, and\n * stores the resulting `ready` or `error` state.\n */\n ensureEntry: (options: {\n cacheKey: string;\n datasetId: string;\n executeSql: (\n query: string,\n version?: number,\n ) => Promise<QueryHandle | null>;\n input: DeckDatasetInput;\n }) => void;\n /**\n * Remove all subscriptions for one hook consumer.\n *\n * This is called when a `DeckJsonMap` instance unmounts so the store can\n * release the consumer's references and allow now-unreferenced entries to be\n * evicted later.\n */\n removeConsumer: (consumerId: string) => void;\n /**\n * Reconcile the set of cache keys referenced by one hook consumer.\n *\n * This adds the consumer to newly needed entries, removes it from entries no\n * longer needed, and preserves existing entries in place so unrelated dataset\n * states do not get reset during prop changes.\n */\n syncConsumer: (consumerId: string, keys: string[]) => void;\n /**\n * Reconcile and ensure all prepared entries needed by one dataset registry.\n *\n * This is the store-level orchestration entrypoint used by\n * `usePreparedDatasetStates`. It computes cache keys for the current dataset\n * registry, syncs consumer memberships, and eagerly ensures any resolvable\n * entries exist.\n */\n syncDatasetsForConsumer: (options: {\n consumerId: string;\n datasets: Record<string, DeckDatasetInput>;\n executeSql: (\n query: string,\n version?: number,\n ) => Promise<QueryHandle | null>;\n sqlSourceIdentity: object;\n }) => void;\n};\n\ntype PreparedDatasetDescriptor = {\n datasetId: string;\n input: DeckDatasetInput;\n cacheKey: string | undefined;\n};\n\nfunction resolvePreparedDatasetDescriptors(options: {\n datasets: Record<string, DeckDatasetInput>;\n sqlSourceIdentity: object;\n}): PreparedDatasetDescriptor[] {\n const {datasets, sqlSourceIdentity} = options;\n\n return Object.entries(datasets).map(([datasetId, input]) => ({\n datasetId,\n input,\n cacheKey: resolvePreparedDatasetCacheKey({\n input,\n sqlSourceIdentity,\n }),\n }));\n}\n\n/**\n * Create a feature-local cache store for prepared deck datasets.\n *\n * The store is intentionally scoped to deck's preparation layer. It reuses the\n * expensive result of `prepareDeckDataset(...)` across consumers while leaving\n * raw query/result caching to the upstream data provider:\n *\n * - Mosaic handles cached query results through its coordinator/query manager\n * - DuckDB-backed SQL datasets still use the DuckDB slice execution path\n *\n * This keeps `@sqlrooms/deck` independent from either provider while still\n * avoiding repeated geometry decoding and GeoArrow/GeoJSON shaping work.\n */\nexport function createPreparedDatasetStore(\n options: PreparedDatasetStoreOptions = {},\n) {\n const {\n maxEntries = DEFAULT_MAX_PREPARED_DATASET_ENTRIES,\n prepareDataset = prepareDeckDataset,\n } = options;\n\n return createStore<PreparedDatasetStoreState>((set, get) => ({\n consumerKeys: {},\n entries: {},\n\n ensureEntry({cacheKey, datasetId, executeSql, input}) {\n const existing = get().entries[cacheKey];\n if (existing) {\n if (existing.status !== 'loading') {\n set((state) => ({\n ...state,\n entries: {\n ...state.entries,\n [cacheKey]: touchEntry(existing),\n },\n }));\n }\n return;\n }\n\n const promise = Promise.resolve().then(async () => {\n try {\n let table = resolveArrowTable(input);\n if (!table && isSqlDatasetInput(input)) {\n const queryHandle = await executeSql(input.sqlQuery);\n if (!queryHandle) {\n throw new Error(\n `Query for dataset \"${datasetId}\" was cancelled.`,\n );\n }\n\n table = await queryHandle;\n }\n\n if (!table) {\n return;\n }\n\n const prepared = prepareDataset({\n datasetId,\n table,\n geometryColumn: input.geometryColumn,\n geometryEncodingHint: input.geometryEncodingHint,\n });\n\n set((state) => ({\n ...state,\n entries: evictLruEntries(\n {\n ...state.entries,\n [cacheKey]: {\n status: 'ready',\n prepared,\n consumers:\n state.entries[cacheKey]?.consumers ?? new Set<string>(),\n lastAccessedAt: nextAccessTimestamp(),\n },\n },\n maxEntries,\n ),\n }));\n } catch (error) {\n set((state) => ({\n ...state,\n entries: evictLruEntries(\n {\n ...state.entries,\n [cacheKey]: {\n status: 'error',\n error:\n error instanceof Error ? error : new Error(String(error)),\n consumers:\n state.entries[cacheKey]?.consumers ?? new Set<string>(),\n lastAccessedAt: nextAccessTimestamp(),\n },\n },\n maxEntries,\n ),\n }));\n }\n });\n\n set((state) => ({\n ...state,\n entries: {\n ...state.entries,\n [cacheKey]: {\n status: 'loading',\n promise,\n consumers: state.entries[cacheKey]?.consumers ?? new Set<string>(),\n lastAccessedAt: nextAccessTimestamp(),\n },\n },\n }));\n },\n\n syncConsumer(consumerId, keys) {\n const previousKeys = new Set(get().consumerKeys[consumerId] ?? []);\n const nextKeys = new Set(keys);\n\n set((state) => {\n let didChangeEntries = false;\n let nextEntries = state.entries;\n\n const updateEntry = (\n cacheKey: string,\n updater: (\n entry: PreparedDatasetCacheEntry,\n ) => PreparedDatasetCacheEntry,\n ) => {\n const currentEntry = nextEntries[cacheKey];\n if (!currentEntry) {\n return;\n }\n\n if (!didChangeEntries) {\n nextEntries = {...nextEntries};\n didChangeEntries = true;\n }\n\n nextEntries[cacheKey] = updater(currentEntry);\n };\n\n for (const cacheKey of previousKeys) {\n if (nextKeys.has(cacheKey)) {\n continue;\n }\n\n updateEntry(cacheKey, (entry) => {\n const consumers = new Set(entry.consumers);\n consumers.delete(consumerId);\n return cloneEntryWithConsumers(entry, consumers);\n });\n }\n\n for (const cacheKey of nextKeys) {\n updateEntry(cacheKey, (entry) => {\n const consumers = new Set(entry.consumers);\n consumers.add(consumerId);\n return cloneEntryWithConsumers(entry, consumers);\n });\n }\n\n return {\n ...state,\n consumerKeys: {\n ...state.consumerKeys,\n [consumerId]: [...nextKeys],\n },\n entries: didChangeEntries\n ? evictLruEntries(nextEntries, maxEntries)\n : state.entries,\n };\n });\n },\n\n removeConsumer(consumerId) {\n const previousKeys = get().consumerKeys[consumerId];\n if (!previousKeys) {\n return;\n }\n\n set((state) => {\n let didChangeEntries = false;\n let nextEntries = state.entries;\n\n for (const cacheKey of previousKeys) {\n const entry = nextEntries[cacheKey];\n if (!entry) {\n continue;\n }\n\n const consumers = new Set(entry.consumers);\n consumers.delete(consumerId);\n\n if (!didChangeEntries) {\n nextEntries = {...nextEntries};\n didChangeEntries = true;\n }\n\n nextEntries[cacheKey] = cloneEntryWithConsumers(entry, consumers);\n }\n\n const nextConsumerKeys = {...state.consumerKeys};\n delete nextConsumerKeys[consumerId];\n\n return {\n ...state,\n consumerKeys: nextConsumerKeys,\n entries: didChangeEntries\n ? evictLruEntries(nextEntries, maxEntries)\n : state.entries,\n };\n });\n },\n\n syncDatasetsForConsumer({\n consumerId,\n datasets,\n executeSql,\n sqlSourceIdentity,\n }) {\n const descriptors = resolvePreparedDatasetDescriptors({\n datasets,\n sqlSourceIdentity,\n });\n const cacheKeys = descriptors\n .map((descriptor) => descriptor.cacheKey)\n .filter((cacheKey): cacheKey is string => Boolean(cacheKey));\n\n for (const descriptor of descriptors) {\n if (!descriptor.cacheKey) {\n continue;\n }\n\n get().ensureEntry({\n cacheKey: descriptor.cacheKey,\n datasetId: descriptor.datasetId,\n executeSql,\n input: descriptor.input,\n });\n }\n\n get().syncConsumer(consumerId, cacheKeys);\n },\n }));\n}\n\n/**\n * Resolve a shared prepared-store entry back into the dataset-state shape\n * consumed by `DeckJsonMap`.\n *\n * Prepared entries are shared by cache key, while `datasetId` stays a\n * view-level label used by layer binding and user-facing errors. When a shared\n * prepared entry is reused for a different dataset id, this helper remaps the\n * prepared payload so downstream callers still see the dataset id they asked\n * for.\n */\nexport function resolvePreparedDeckDatasetState(options: {\n datasetId: string;\n entry?: PreparedDatasetCacheEntry;\n}): PreparedDeckDatasetState {\n const {datasetId, entry} = options;\n\n if (!entry || entry.status === 'loading') {\n return {status: 'loading'};\n }\n\n if (entry.status === 'error') {\n return {status: 'error', error: entry.error};\n }\n\n return {\n status: 'ready',\n prepared:\n entry.prepared.datasetId === datasetId\n ? entry.prepared\n : {\n ...entry.prepared,\n datasetId,\n },\n };\n}\n\n/**\n * Resolve the full `datasetId -> state` map for a dataset registry.\n *\n * This mirrors the lookup logic used by `DeckJsonMap`: unresolved Arrow\n * datasets remain `loading`, while resolvable datasets reuse shared prepared\n * entries keyed by data identity rather than by dataset id.\n */\nexport function resolvePreparedDeckDatasetStates(options: {\n datasets: Record<string, DeckDatasetInput>;\n entries: Record<string, PreparedDatasetCacheEntry>;\n sqlSourceIdentity: object;\n}): Record<string, PreparedDeckDatasetState> {\n const {datasets, entries, sqlSourceIdentity} = options;\n\n return Object.fromEntries(\n resolvePreparedDatasetDescriptors({datasets, sqlSourceIdentity}).map(\n ({datasetId, cacheKey}) => [\n datasetId,\n resolvePreparedDeckDatasetState({\n datasetId,\n entry: cacheKey ? entries[cacheKey] : undefined,\n }),\n ],\n ),\n );\n}\n\n/**\n * Module-global prepared dataset cache shared by all `DeckJsonMap` instances.\n *\n * The cache stores only deck-specific prepared payloads, not raw query\n * results, and applies a small internal LRU policy so settled entries do not\n * grow without bound.\n */\nexport const preparedDatasetStore = createPreparedDatasetStore();\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { ColorScaleLegend } from '@sqlrooms/color-scales';
|
|
6
6
|
export { createDeckJsonSpecFromDatasets } from './createDeckJsonSpecFromDatasets';
|
|
7
|
+
export { DECK_MAP_AI_INSTRUCTIONS, createDashboardAgentToolWithDeckMaps, createDashboardWithDeckMapAiTools, createDeckMapAiTools, createDeckMapDashboardAiTools, createDeckMapDashboardTool, createDeckMapConfigTool, DeckMapDashboardConfigParameter, DeckMapConfigToolParameters, DeckMapDashboardToolParameters, getDashboardWithDeckMapAiInstructions, } from './ai';
|
|
8
|
+
export type { DeckMapConfigToolParams, DeckMapDashboardConfigToolConfig, DeckMapDashboardToolParams, } from './ai';
|
|
7
9
|
export { deckMapDashboardAddPanelAction, deckMapDashboardPanelRenderer, } from './dashboard';
|
|
8
|
-
export {
|
|
9
|
-
export
|
|
10
|
+
export { createDeckMapDashboardSliceOptions } from './dashboardIntegration';
|
|
11
|
+
export { asDeckJsonMapConfig, createDeckMapDashboardDatasetQuery, createDeckMapDashboardDatasets, createDeckMapDashboardPanelConfig, DEFAULT_DECK_MAP_MAX_DATA_POINTS, DECK_MAP_DASHBOARD_PANEL_TYPE, resolveDeckMapDashboardDatasetSource, } from './dashboardConfig';
|
|
12
|
+
export { getDeckMapDataPolicy } from './mapDataPolicy';
|
|
13
|
+
export { createDeckMapDashboardConfigForTable, createDeckMapDashboardPanelConfigForTable, findDeckMapLongitudeLatitudeColumns, findLongitudeLatitudeColumns, normalizeDeckMapFillColor, quoteDeckMapSqlIdentifier, quoteDeckMapSqlTableReference, regenerateMapConfigForTable, } from './mapConfigUtils';
|
|
14
|
+
export type { DeckMapConfigColumn, DeckMapFillColor, DeckMapTableReference, } from './mapConfigUtils';
|
|
15
|
+
export type { DeckMapDashboardFitToDataConfig, CreateDeckMapDashboardPanelConfigOptions, DeckMapDashboardDatasetClientState, DeckMapDashboardDatasetConfig, DeckMapDataPolicyOverride, DeckMapDashboardInteractionConfig, DeckMapDashboardPanelConfig, } from './dashboardConfig';
|
|
10
16
|
export { DeckJsonMap } from './DeckJsonMap';
|
|
11
17
|
export { ColorScaleFunction, GeometryEncodingHint as DeckGeometryEncodingHint, DeckJsonMapLayerSpec, DeckJsonMapSpec, LayerBindingConfig, LayerBindingProps, } from './DeckJsonMapSpec';
|
|
12
18
|
export { createDeckJsonConfiguration } from './json/createDeckJsonConfiguration';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;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,mBAAmB,CAAC;AAC3B,OAAO,EAAC,2BAA2B,EAAC,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAEhE,YAAY,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAChF,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,wBAAwB,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAC;AACpE,YAAY,EACV,qCAAqC,EACrC,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,SAAS,EACT,wBAAwB,GACzB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { ColorScaleLegend } from '@sqlrooms/color-scales';
|
|
6
6
|
export { createDeckJsonSpecFromDatasets } from './createDeckJsonSpecFromDatasets';
|
|
7
|
+
export { DECK_MAP_AI_INSTRUCTIONS, createDashboardAgentToolWithDeckMaps, createDashboardWithDeckMapAiTools, createDeckMapAiTools, createDeckMapDashboardAiTools, createDeckMapDashboardTool, createDeckMapConfigTool, DeckMapDashboardConfigParameter, DeckMapConfigToolParameters, DeckMapDashboardToolParameters, getDashboardWithDeckMapAiInstructions, } from './ai';
|
|
7
8
|
export { deckMapDashboardAddPanelAction, deckMapDashboardPanelRenderer, } from './dashboard';
|
|
8
|
-
export {
|
|
9
|
+
export { createDeckMapDashboardSliceOptions } from './dashboardIntegration';
|
|
10
|
+
export { asDeckJsonMapConfig, createDeckMapDashboardDatasetQuery, createDeckMapDashboardDatasets, createDeckMapDashboardPanelConfig, DEFAULT_DECK_MAP_MAX_DATA_POINTS, DECK_MAP_DASHBOARD_PANEL_TYPE, resolveDeckMapDashboardDatasetSource, } from './dashboardConfig';
|
|
11
|
+
export { getDeckMapDataPolicy } from './mapDataPolicy';
|
|
12
|
+
export { createDeckMapDashboardConfigForTable, createDeckMapDashboardPanelConfigForTable, findDeckMapLongitudeLatitudeColumns, findLongitudeLatitudeColumns, normalizeDeckMapFillColor, quoteDeckMapSqlIdentifier, quoteDeckMapSqlTableReference, regenerateMapConfigForTable, } from './mapConfigUtils';
|
|
9
13
|
export { DeckJsonMap } from './DeckJsonMap';
|
|
10
14
|
export { ColorScaleFunction, GeometryEncodingHint as DeckGeometryEncodingHint, DeckJsonMapLayerSpec, DeckJsonMapSpec, LayerBindingConfig, LayerBindingProps, } from './DeckJsonMapSpec';
|
|
11
15
|
export { createDeckJsonConfiguration } from './json/createDeckJsonConfiguration';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAC,8BAA8B,EAAC,MAAM,kCAAkC,CAAC;AAChF,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,kCAAkC,EAClC,8BAA8B,EAC9B,iCAAiC,EACjC,6BAA6B,EAC7B,oCAAoC,GACrC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAC,8BAA8B,EAAC,MAAM,kCAAkC,CAAC;AAChF,OAAO,EACL,wBAAwB,EACxB,oCAAoC,EACpC,iCAAiC,EACjC,oBAAoB,EACpB,6BAA6B,EAC7B,0BAA0B,EAC1B,uBAAuB,EACvB,+BAA+B,EAC/B,2BAA2B,EAC3B,8BAA8B,EAC9B,qCAAqC,GACtC,MAAM,MAAM,CAAC;AAMd,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,kCAAkC,EAAC,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,kCAAkC,EAClC,8BAA8B,EAC9B,iCAAiC,EACjC,gCAAgC,EAChC,6BAA6B,EAC7B,oCAAoC,GACrC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AACrD,OAAO,EACL,oCAAoC,EACpC,yCAAyC,EACzC,mCAAmC,EACnC,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,EACzB,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAe1B,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EACL,kBAAkB,EAClB,oBAAoB,IAAI,wBAAwB,EAChD,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,2BAA2B,EAAC,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAUhE,OAAO,EAAC,wBAAwB,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nexport {ColorScaleLegend} from '@sqlrooms/color-scales';\nexport {createDeckJsonSpecFromDatasets} from './createDeckJsonSpecFromDatasets';\nexport {\n DECK_MAP_AI_INSTRUCTIONS,\n createDashboardAgentToolWithDeckMaps,\n createDashboardWithDeckMapAiTools,\n createDeckMapAiTools,\n createDeckMapDashboardAiTools,\n createDeckMapDashboardTool,\n createDeckMapConfigTool,\n DeckMapDashboardConfigParameter,\n DeckMapConfigToolParameters,\n DeckMapDashboardToolParameters,\n getDashboardWithDeckMapAiInstructions,\n} from './ai';\nexport type {\n DeckMapConfigToolParams,\n DeckMapDashboardConfigToolConfig,\n DeckMapDashboardToolParams,\n} from './ai';\nexport {\n deckMapDashboardAddPanelAction,\n deckMapDashboardPanelRenderer,\n} from './dashboard';\nexport {createDeckMapDashboardSliceOptions} from './dashboardIntegration';\nexport {\n asDeckJsonMapConfig,\n createDeckMapDashboardDatasetQuery,\n createDeckMapDashboardDatasets,\n createDeckMapDashboardPanelConfig,\n DEFAULT_DECK_MAP_MAX_DATA_POINTS,\n DECK_MAP_DASHBOARD_PANEL_TYPE,\n resolveDeckMapDashboardDatasetSource,\n} from './dashboardConfig';\nexport {getDeckMapDataPolicy} from './mapDataPolicy';\nexport {\n createDeckMapDashboardConfigForTable,\n createDeckMapDashboardPanelConfigForTable,\n findDeckMapLongitudeLatitudeColumns,\n findLongitudeLatitudeColumns,\n normalizeDeckMapFillColor,\n quoteDeckMapSqlIdentifier,\n quoteDeckMapSqlTableReference,\n regenerateMapConfigForTable,\n} from './mapConfigUtils';\nexport type {\n DeckMapConfigColumn,\n DeckMapFillColor,\n DeckMapTableReference,\n} from './mapConfigUtils';\nexport type {\n DeckMapDashboardFitToDataConfig,\n CreateDeckMapDashboardPanelConfigOptions,\n DeckMapDashboardDatasetClientState,\n DeckMapDashboardDatasetConfig,\n DeckMapDataPolicyOverride,\n DeckMapDashboardInteractionConfig,\n DeckMapDashboardPanelConfig,\n} from './dashboardConfig';\nexport {DeckJsonMap} from './DeckJsonMap';\nexport {\n ColorScaleFunction,\n GeometryEncodingHint as DeckGeometryEncodingHint,\n DeckJsonMapLayerSpec,\n DeckJsonMapSpec,\n LayerBindingConfig,\n LayerBindingProps,\n} from './DeckJsonMapSpec';\nexport {createDeckJsonConfiguration} from './json/createDeckJsonConfiguration';\nexport {prepareDeckDataset} from './prepare/prepareDeckDataset';\n\nexport type {ColorLegendConfig, ColorScaleConfig} from '@sqlrooms/color-scales';\nexport type {\n GeometryEncodingHint,\n PreparedDeckDataset,\n PreparedGeoArrowLayerData,\n ResolvedGeometryColumn,\n ResolvedGeometryEncoding,\n} from './prepare/types';\nexport {isArrowTableDatasetInput, isSqlDatasetInput} from './types';\nexport type {\n CreateDeckJsonSpecFromDatasetsOptions,\n DeckArrowTableDatasetInput,\n DeckAutoLayerType,\n DeckDatasetInput,\n DeckJsonMapProps,\n DeckJsonSpecDatasetHint,\n DeckSqlDatasetInput,\n DeckTable,\n PreparedDeckDatasetState,\n} from './types';\n"]}
|
|
@@ -7,7 +7,7 @@ export type ColorScaleMarker = {
|
|
|
7
7
|
export declare function createColorScaleMarker(value: ColorScaleConfig): ColorScaleMarker;
|
|
8
8
|
export declare function isColorScaleMarker(value: unknown): value is ColorScaleMarker;
|
|
9
9
|
export declare function getColorScale(props: Record<string, unknown>): {
|
|
10
|
-
propName: 'getFillColor' | 'getLineColor';
|
|
10
|
+
propName: 'getFillColor' | 'getLineColor' | 'getColor' | 'getSourceColor' | 'getTargetColor';
|
|
11
11
|
colorScale: ColorScaleConfig;
|
|
12
12
|
} | undefined;
|
|
13
13
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colorScaleFunction.d.ts","sourceRoot":"","sources":["../../src/json/colorScaleFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAG7D,QAAA,MAAM,2BAA2B,eAEhC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,CAAC,2BAA2B,CAAC,EAAE,IAAI,CAAC;CACrC,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,CAKlB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAU5E;AAED,wBAAgB,aAAa,
|
|
1
|
+
{"version":3,"file":"colorScaleFunction.d.ts","sourceRoot":"","sources":["../../src/json/colorScaleFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAG7D,QAAA,MAAM,2BAA2B,eAEhC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,CAAC,2BAA2B,CAAC,EAAE,IAAI,CAAC;CACrC,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,CAKlB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAU5E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxD;IACE,QAAQ,EACJ,cAAc,GACd,cAAc,GACd,UAAU,GACV,gBAAgB,GAChB,gBAAgB,CAAC;IACrB,UAAU,EAAE,gBAAgB,CAAC;CAC9B,GACD,SAAS,CAwBZ"}
|
|
@@ -14,7 +14,13 @@ export function isColorScaleMarker(value) {
|
|
|
14
14
|
value.colorScale != null);
|
|
15
15
|
}
|
|
16
16
|
export function getColorScale(props) {
|
|
17
|
-
for (const propName of [
|
|
17
|
+
for (const propName of [
|
|
18
|
+
'getFillColor',
|
|
19
|
+
'getLineColor',
|
|
20
|
+
'getColor',
|
|
21
|
+
'getSourceColor',
|
|
22
|
+
'getTargetColor',
|
|
23
|
+
]) {
|
|
18
24
|
const value = props[propName];
|
|
19
25
|
if (isColorScaleMarker(value)) {
|
|
20
26
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colorScaleFunction.js","sourceRoot":"","sources":["../../src/json/colorScaleFunction.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAEnD,MAAM,2BAA2B,GAAG,MAAM,CAAC,GAAG,CAC5C,qCAAqC,CACtC,CAAC;AAOF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AE,CAAC;YAC9B,OAAO;gBACL,QAAQ;gBACR,UAAU,EAAE,KAAK,CAAC,UAAU;aAC7B,CAAC;QACJ,CAAC;QACD,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,QAAQ;gBACR,UAAU,EAAE,KAAK;aAClB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type {ColorScaleConfig} from '@sqlrooms/color-scales';\nimport {isColorScaleFunction} from './layerConfig';\n\nconst SQLROOMS_COLOR_SCALE_MARKER = Symbol.for(\n '@sqlrooms/deck/sqlrooms-color-scale',\n);\n\nexport type ColorScaleMarker = {\n colorScale: ColorScaleConfig;\n [SQLROOMS_COLOR_SCALE_MARKER]: true;\n};\n\nexport function createColorScaleMarker(\n value: ColorScaleConfig,\n): ColorScaleMarker {\n return {\n colorScale: value,\n [SQLROOMS_COLOR_SCALE_MARKER]: true,\n };\n}\n\nexport function isColorScaleMarker(value: unknown): value is ColorScaleMarker {\n return Boolean(\n value &&\n typeof value === 'object' &&\n (value as {[SQLROOMS_COLOR_SCALE_MARKER]?: boolean})[\n SQLROOMS_COLOR_SCALE_MARKER\n ] &&\n typeof (value as {colorScale?: unknown}).colorScale === 'object' &&\n (value as {colorScale?: unknown}).colorScale != null,\n );\n}\n\nexport function getColorScale(props: Record<string, unknown>):\n | {\n propName:\n | 'getFillColor'\n | 'getLineColor'\n | 'getColor'\n | 'getSourceColor'\n | 'getTargetColor';\n colorScale: ColorScaleConfig;\n }\n | undefined {\n for (const propName of [\n 'getFillColor',\n 'getLineColor',\n 'getColor',\n 'getSourceColor',\n 'getTargetColor',\n ] as const) {\n const value = props[propName];\n if (isColorScaleMarker(value)) {\n return {\n propName,\n colorScale: value.colorScale,\n };\n }\n if (isColorScaleFunction(value)) {\n return {\n propName,\n colorScale: value,\n };\n }\n }\n\n return undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractColorScaleLegends.d.ts","sourceRoot":"","sources":["../../src/json/extractColorScaleLegends.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"extractColorScaleLegends.d.ts","sourceRoot":"","sources":["../../src/json/extractColorScaleLegends.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,UAAU,CAAC;AAuBvD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAChD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;CACzD,yBA0CA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractColorScaleLegends.js","sourceRoot":"","sources":["../../src/json/extractColorScaleLegends.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAEnE,SAAS,kBAAkB,CACzB,UAAmC,EACnC,aAAqB;IAErB,MAAM,MAAM,GACV,kBAAkB,CAAC,UAAU,EAAE,cAAc,CAAC;QAC9C,kBAAkB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACjD,IACE,MAAM;QACN,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAChC,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,aAAa,CAAC;AACvB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AAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACzC,OAAO,EAA2B,CAAC;IACrC,CAAC;IAED,MAAM,OAAO,GAA0B,EAAE,CAAC;IAE1C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxC,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,KAAgC,CAAC;QACpD,MAAM,kBAAkB,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxB,SAAS;QACX,CAAC;QACD,MAAM,EAAC,UAAU,EAAC,GAAG,kBAAkB,CAAC;QAExC,MAAM,SAAS,GAAG,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS;QACX,CAAC;QAED,MAAM,YAAY,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YACrD,SAAS;QACX,CAAC;QAED,MAAM,cAAc,GAAG,qBAAqB,CAAC;YAC3C,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,KAAK;YAClC,UAAU;YACV,KAAK,EAAE,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;SACxD,CAAC,CAAC;QAEH,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {ResolvedColorLegend} from '@sqlrooms/color-scales';\nimport type {PreparedDeckDatasetState} from '../types';\nimport {getColorScale} from './colorScaleFunction';\nimport {buildColorScaleLegend} from './compileColorScale';\nimport {resolveColorLegend, resolveDatasetId} from './layerConfig';\n\nfunction resolveLegendTitle(\n layerProps: Record<string, unknown>,\n fallbackField: string,\n) {\n const legend =\n resolveColorLegend(layerProps, 'getFillColor') ??\n resolveColorLegend(layerProps, 'getLineColor');\n if (\n legend &&\n typeof legend === 'object' &&\n typeof legend.title === 'string'\n ) {\n return legend.title;\n }\n\n return fallbackField;\n}\n\nexport function extractColorScaleLegends(options: {\n spec: Record<string, unknown> | null;\n datasetIds: string[];\n datasetStates: Record<string, PreparedDeckDatasetState>;\n}) {\n const {spec, datasetIds, datasetStates} = options;\n if (!spec || !Array.isArray(spec.layers)) {\n return [] as ResolvedColorLegend[];\n }\n\n const legends: ResolvedColorLegend[] = [];\n\n for (const layer of spec.layers) {\n if (!layer || typeof layer !== 'object') {\n continue;\n }\n\n const layerProps = layer as Record<string, unknown>;\n const resolvedColorScale = getColorScale(layerProps);\n if (!resolvedColorScale) {\n continue;\n }\n const {colorScale} = resolvedColorScale;\n\n const datasetId = resolveDatasetId(layerProps, datasetIds);\n if (!datasetId) {\n continue;\n }\n\n const datasetState = datasetStates[datasetId];\n if (!datasetState || datasetState.status !== 'ready') {\n continue;\n }\n\n const resolvedLegend = buildColorScaleLegend({\n table: datasetState.prepared.table,\n colorScale,\n title: resolveLegendTitle(layerProps, colorScale.field),\n });\n\n if (resolvedLegend) {\n legends.push(resolvedLegend);\n }\n }\n\n return legends;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layerCompatibility.d.ts","sourceRoot":"","sources":["../../src/json/layerCompatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAExD,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,SAAS,CAAC;IAC1B,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC5B,SAAS,EAAE,oBAAoB,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,cAAc,EAAE,UAAU,CAAC;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,KAAK,kBAAkB,GAAG,oBAAoB,GAAG,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"layerCompatibility.d.ts","sourceRoot":"","sources":["../../src/json/layerCompatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAExD,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,SAAS,CAAC;IAC1B,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC5B,SAAS,EAAE,oBAAoB,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,cAAc,EAAE,UAAU,CAAC;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,KAAK,kBAAkB,GAAG,oBAAoB,GAAG,qBAAqB,CAAC;AAmKvE,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,kCAEtD"}
|
|
@@ -95,6 +95,7 @@ const LAYER_COMPATIBILITY = {
|
|
|
95
95
|
'getLineWidth',
|
|
96
96
|
'getElevation',
|
|
97
97
|
],
|
|
98
|
+
allowGeoArrowPromotion: true,
|
|
98
99
|
},
|
|
99
100
|
GeoArrowSolidPolygonLayer: {
|
|
100
101
|
representation: 'geoarrow',
|
|
@@ -111,6 +112,7 @@ const LAYER_COMPATIBILITY = {
|
|
|
111
112
|
'getFillColor',
|
|
112
113
|
'getLineColor',
|
|
113
114
|
],
|
|
115
|
+
allowGeoArrowPromotion: true,
|
|
114
116
|
},
|
|
115
117
|
GeoArrowArcLayer: {
|
|
116
118
|
representation: 'geoarrow',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layerCompatibility.js","sourceRoot":"","sources":["../../src/json/layerCompatibility.ts"],"names":[],"mappings":"AAuBA,MAAM,mBAAmB,GAAuC;IAC9D,YAAY,EAAE;QACZ,cAAc,EAAE,SAAS;QACzB,mBAAmB,EAAE,EAAE;KACxB;IACD,wBAAwB,EAAE;QACxB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;SACF;QACD,mBAAmB,EAAE;YACnB,aAAa;YACb,WAAW;YACX,cAAc;YACd,cAAc;YACd,cAAc;SACf;QACD,sBAAsB,EAAE,IAAI;KAC7B;IACD,oBAAoB,EAAE;QACpB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;SACF;QACD,mBAAmB,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC;QACjD,sBAAsB,EAAE,IAAI;KAC7B;IACD,mBAAmB,EAAE;QACnB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;SACF;QACD,mBAAmB,EAAE;YACnB,aAAa;YACb,cAAc;YACd,cAAc;YACd,cAAc;YACd,cAAc;SACf;QACD,sBAAsB,EAAE,IAAI;KAC7B;IACD,iBAAiB,EAAE;QACjB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;SACF;QACD,mBAAmB,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC;KACzD;IACD,kBAAkB,EAAE;QAClB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,iBAAiB;gBAC5B,QAAQ,EAAE,IAAI;aACf;SACF;QACD,mBAAmB,EAAE,CAAC,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,CAAC;KAC1E;IACD,oBAAoB,EAAE;QACpB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;SACF;QACD,mBAAmB,EAAE;YACnB,YAAY;YACZ,cAAc;YACd,cAAc;YACd,cAAc;YACd,cAAc;SACf;
|
|
1
|
+
{"version":3,"file":"layerCompatibility.js","sourceRoot":"","sources":["../../src/json/layerCompatibility.ts"],"names":[],"mappings":"AAuBA,MAAM,mBAAmB,GAAuC;IAC9D,YAAY,EAAE;QACZ,cAAc,EAAE,SAAS;QACzB,mBAAmB,EAAE,EAAE;KACxB;IACD,wBAAwB,EAAE;QACxB,cAAc,EAAE,UAAU;QAC1B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,gBAAgB;aAC5B;SACF;QACD,mBAAmB,EAAE;YACnB,a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,CAAC;AACxC,CAAC","sourcesContent":["import type {LayerConfigColumnKey} from './layerConfig';\n\ntype GeoJsonCompatibility = {\n representation: 'geojson';\n vectorAccessorProps: string[];\n};\n\ntype GeoArrowBinding = {\n prop: string;\n kind: 'geometry' | 'column';\n configKey: LayerConfigColumnKey;\n required?: boolean;\n};\n\ntype GeoArrowCompatibility = {\n representation: 'geoarrow';\n bindings: GeoArrowBinding[];\n vectorAccessorProps: string[];\n allowGeoArrowPromotion?: boolean;\n};\n\ntype LayerCompatibility = GeoJsonCompatibility | GeoArrowCompatibility;\n\nconst LAYER_COMPATIBILITY: Record<string, LayerCompatibility> = {\n GeoJsonLayer: {\n representation: 'geojson',\n vectorAccessorProps: [],\n },\n GeoArrowScatterplotLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPosition',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n ],\n vectorAccessorProps: [\n 'getPosition',\n 'getRadius',\n 'getFillColor',\n 'getLineColor',\n 'getLineWidth',\n ],\n allowGeoArrowPromotion: true,\n },\n GeoArrowHeatmapLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPosition',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n ],\n vectorAccessorProps: ['getPosition', 'getWeight'],\n allowGeoArrowPromotion: true,\n },\n GeoArrowColumnLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPosition',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n ],\n vectorAccessorProps: [\n 'getPosition',\n 'getFillColor',\n 'getLineColor',\n 'getLineWidth',\n 'getElevation',\n ],\n allowGeoArrowPromotion: true,\n },\n GeoArrowPathLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPath',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n ],\n vectorAccessorProps: ['getPath', 'getColor', 'getWidth'],\n },\n GeoArrowTripsLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPath',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n {\n prop: 'getTimestamps',\n kind: 'column',\n configKey: 'timestampColumn',\n required: true,\n },\n ],\n vectorAccessorProps: ['getPath', 'getTimestamps', 'getColor', 'getWidth'],\n },\n GeoArrowPolygonLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPolygon',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n ],\n vectorAccessorProps: [\n 'getPolygon',\n 'getFillColor',\n 'getLineColor',\n 'getLineWidth',\n 'getElevation',\n ],\n allowGeoArrowPromotion: true,\n },\n GeoArrowSolidPolygonLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getPolygon',\n kind: 'geometry',\n configKey: 'geometryColumn',\n },\n ],\n vectorAccessorProps: [\n 'getPolygon',\n 'getElevation',\n 'getFillColor',\n 'getLineColor',\n ],\n allowGeoArrowPromotion: true,\n },\n GeoArrowArcLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getSourcePosition',\n kind: 'geometry',\n configKey: 'sourceGeometryColumn',\n required: true,\n },\n {\n prop: 'getTargetPosition',\n kind: 'geometry',\n configKey: 'targetGeometryColumn',\n required: true,\n },\n ],\n vectorAccessorProps: [\n 'getSourcePosition',\n 'getTargetPosition',\n 'getSourceColor',\n 'getTargetColor',\n 'getWidth',\n 'getHeight',\n 'getTilt',\n ],\n },\n GeoArrowH3HexagonLayer: {\n representation: 'geoarrow',\n bindings: [\n {\n prop: 'getHexagon',\n kind: 'column',\n configKey: 'hexagonColumn',\n required: true,\n },\n ],\n vectorAccessorProps: [\n 'getHexagon',\n 'getFillColor',\n 'getLineColor',\n 'getElevation',\n ],\n },\n};\n\nexport function getLayerCompatibility(layerName: string) {\n return LAYER_COMPATIBILITY[layerName];\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { MosaicDashboardPanelConfigType } from '@sqlrooms/mosaic';
|
|
2
|
+
import type { DataTable } from '@sqlrooms/duckdb';
|
|
3
|
+
import { type DeckMapDashboardPanelConfig } from './dashboardConfig';
|
|
4
|
+
import type { GeometryEncodingHint } from './prepare/types';
|
|
5
|
+
export type DeckMapConfigColumn = {
|
|
6
|
+
name: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
};
|
|
9
|
+
export type DeckMapTableReference = string | {
|
|
10
|
+
database?: string;
|
|
11
|
+
schema?: string;
|
|
12
|
+
table?: string;
|
|
13
|
+
};
|
|
14
|
+
export type DeckMapFillColor = [number, number, number] | [number, number, number, number];
|
|
15
|
+
export declare function findDeckMapLongitudeLatitudeColumns(columns?: DeckMapConfigColumn[]): {
|
|
16
|
+
longitudeColumn: string;
|
|
17
|
+
latitudeColumn: string;
|
|
18
|
+
} | null;
|
|
19
|
+
export declare function findLongitudeLatitudeColumns(table?: DataTable): {
|
|
20
|
+
longitudeColumn: string;
|
|
21
|
+
latitudeColumn: string;
|
|
22
|
+
} | null;
|
|
23
|
+
export declare function findDeckMapGeometryColumn(columns?: DeckMapConfigColumn[]): {
|
|
24
|
+
geometryColumn: string;
|
|
25
|
+
geometryEncodingHint: GeometryEncodingHint | undefined;
|
|
26
|
+
} | null;
|
|
27
|
+
export declare function findGeometryColumn(table?: DataTable): {
|
|
28
|
+
geometryColumn: string;
|
|
29
|
+
geometryEncodingHint: GeometryEncodingHint | undefined;
|
|
30
|
+
} | null;
|
|
31
|
+
export declare function quoteDeckMapSqlIdentifier(identifier: string): string;
|
|
32
|
+
export declare function quoteDeckMapSqlTableReference(tableReference: DeckMapTableReference): string;
|
|
33
|
+
export declare function normalizeDeckMapFillColor(fillColor?: number[]): DeckMapFillColor;
|
|
34
|
+
export declare function createDeckMapDashboardConfigForTable(options: {
|
|
35
|
+
tableName: string;
|
|
36
|
+
columns: DeckMapConfigColumn[];
|
|
37
|
+
tableReference?: DeckMapTableReference;
|
|
38
|
+
sourceSqlQuery?: string;
|
|
39
|
+
longitudeColumn?: string;
|
|
40
|
+
latitudeColumn?: string;
|
|
41
|
+
geometryColumn?: string;
|
|
42
|
+
geometryEncodingHint?: GeometryEncodingHint;
|
|
43
|
+
pointRadius?: number;
|
|
44
|
+
fillColor?: DeckMapFillColor;
|
|
45
|
+
mapStyle?: string;
|
|
46
|
+
}): DeckMapDashboardPanelConfig;
|
|
47
|
+
export declare function createDeckMapDashboardPanelConfigForTable(options: {
|
|
48
|
+
title?: string;
|
|
49
|
+
tableName: string;
|
|
50
|
+
columns: DeckMapConfigColumn[];
|
|
51
|
+
tableReference?: DeckMapTableReference;
|
|
52
|
+
sourceSqlQuery?: string;
|
|
53
|
+
longitudeColumn?: string;
|
|
54
|
+
latitudeColumn?: string;
|
|
55
|
+
geometryColumn?: string;
|
|
56
|
+
geometryEncodingHint?: GeometryEncodingHint;
|
|
57
|
+
pointRadius?: number;
|
|
58
|
+
fillColor?: DeckMapFillColor;
|
|
59
|
+
mapStyle?: string;
|
|
60
|
+
}): any;
|
|
61
|
+
export declare function regenerateMapConfigForTable(panel: MosaicDashboardPanelConfigType, table: DataTable, longitudeColumn?: string, latitudeColumn?: string): any;
|
|
62
|
+
//# sourceMappingURL=mapConfigUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapConfigUtils.d.ts","sourceRoot":"","sources":["../src/mapConfigUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAQ1D,MAAM,MAAM,mBAAmB,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AAChE,MAAM,MAAM,qBAAqB,GAC7B,MAAM,GACN;IACE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,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S,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,OAKA;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,8BAA8B,EACrC,KAAK,EAAE,SAAS,EAChB,eAAe,CAAC,EAAE,MAAM,EACxB,cAAc,CAAC,EAAE,MAAM,OAuBxB"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { createDeckMapDashboardPanelConfig, } from './dashboardConfig';
|
|
2
|
+
const LONGITUDE_COLUMN_NAMES = ['longitude', 'lon', 'lng', 'long', 'x'];
|
|
3
|
+
const LATITUDE_COLUMN_NAMES = ['latitude', 'lat', 'y'];
|
|
4
|
+
const GEOMETRY_COLUMN_NAMES = ['geometry', 'geom'];
|
|
5
|
+
const DEFAULT_GEOMETRY_COLUMN = '__sqlrooms_geom';
|
|
6
|
+
const DEFAULT_FILL_COLOR = [56, 189, 248, 180];
|
|
7
|
+
function findColumnByName(columns, candidates) {
|
|
8
|
+
const candidateSet = new Set(candidates);
|
|
9
|
+
return columns.find((column) => candidateSet.has(column.name.toLowerCase()))
|
|
10
|
+
?.name;
|
|
11
|
+
}
|
|
12
|
+
export function findDeckMapLongitudeLatitudeColumns(columns) {
|
|
13
|
+
if (!columns)
|
|
14
|
+
return null;
|
|
15
|
+
const longitudeColumn = findColumnByName(columns, LONGITUDE_COLUMN_NAMES);
|
|
16
|
+
const latitudeColumn = findColumnByName(columns, LATITUDE_COLUMN_NAMES);
|
|
17
|
+
return longitudeColumn && latitudeColumn
|
|
18
|
+
? { longitudeColumn, latitudeColumn }
|
|
19
|
+
: null;
|
|
20
|
+
}
|
|
21
|
+
export function findLongitudeLatitudeColumns(table) {
|
|
22
|
+
if (!table)
|
|
23
|
+
return null;
|
|
24
|
+
return findDeckMapLongitudeLatitudeColumns(table.columns);
|
|
25
|
+
}
|
|
26
|
+
function inferGeometryEncodingHint(column) {
|
|
27
|
+
const type = column.type?.toLowerCase();
|
|
28
|
+
if (!type)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (type.includes('wkb') ||
|
|
31
|
+
type.includes('blob') ||
|
|
32
|
+
type.includes('binary')) {
|
|
33
|
+
return 'wkb';
|
|
34
|
+
}
|
|
35
|
+
if (type.includes('wkt') ||
|
|
36
|
+
type.includes('varchar') ||
|
|
37
|
+
type.includes('text')) {
|
|
38
|
+
return 'wkt';
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
export function findDeckMapGeometryColumn(columns) {
|
|
43
|
+
if (!columns)
|
|
44
|
+
return null;
|
|
45
|
+
const namedGeometryColumn = findColumnByName(columns, GEOMETRY_COLUMN_NAMES);
|
|
46
|
+
const geometryColumn = (namedGeometryColumn
|
|
47
|
+
? columns.find((column) => column.name === namedGeometryColumn)
|
|
48
|
+
: undefined) ??
|
|
49
|
+
columns.find((column) => {
|
|
50
|
+
const type = column.type?.toLowerCase() ?? '';
|
|
51
|
+
return type.includes('geometry') || type.includes('geoarrow');
|
|
52
|
+
});
|
|
53
|
+
if (!geometryColumn)
|
|
54
|
+
return null;
|
|
55
|
+
return {
|
|
56
|
+
geometryColumn: geometryColumn.name,
|
|
57
|
+
geometryEncodingHint: inferGeometryEncodingHint(geometryColumn),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function findGeometryColumn(table) {
|
|
61
|
+
if (!table)
|
|
62
|
+
return null;
|
|
63
|
+
return findDeckMapGeometryColumn(table.columns);
|
|
64
|
+
}
|
|
65
|
+
export function quoteDeckMapSqlIdentifier(identifier) {
|
|
66
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
67
|
+
}
|
|
68
|
+
export function quoteDeckMapSqlTableReference(tableReference) {
|
|
69
|
+
if (typeof tableReference === 'string') {
|
|
70
|
+
return tableReference
|
|
71
|
+
.split('.')
|
|
72
|
+
.map((part) => quoteDeckMapSqlIdentifier(part))
|
|
73
|
+
.join('.');
|
|
74
|
+
}
|
|
75
|
+
return [tableReference.database, tableReference.schema, tableReference.table]
|
|
76
|
+
.filter((part) => Boolean(part))
|
|
77
|
+
.map(quoteDeckMapSqlIdentifier)
|
|
78
|
+
.join('.');
|
|
79
|
+
}
|
|
80
|
+
function ensureDeckMapColumnExists(columns, columnName, role) {
|
|
81
|
+
if (!columns.some((column) => column.name === columnName)) {
|
|
82
|
+
throw new Error(`Unknown ${role} column "${columnName}". Available columns: ${columns
|
|
83
|
+
.map((column) => column.name)
|
|
84
|
+
.join(', ')}.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function resolveDeckMapCoordinateColumns(options) {
|
|
88
|
+
const coordinates = options.longitudeColumn && options.latitudeColumn
|
|
89
|
+
? {
|
|
90
|
+
longitudeColumn: options.longitudeColumn,
|
|
91
|
+
latitudeColumn: options.latitudeColumn,
|
|
92
|
+
}
|
|
93
|
+
: findDeckMapLongitudeLatitudeColumns(options.columns);
|
|
94
|
+
if (!coordinates) {
|
|
95
|
+
throw new Error('Could not find longitude/latitude columns. Pass longitudeColumn and latitudeColumn explicitly, or provide geometryColumn.');
|
|
96
|
+
}
|
|
97
|
+
ensureDeckMapColumnExists(options.columns, coordinates.longitudeColumn, 'longitude');
|
|
98
|
+
ensureDeckMapColumnExists(options.columns, coordinates.latitudeColumn, 'latitude');
|
|
99
|
+
return coordinates;
|
|
100
|
+
}
|
|
101
|
+
function createDeckMapPointSourceSql(options) {
|
|
102
|
+
const quotedLongitude = quoteDeckMapSqlIdentifier(options.longitudeColumn);
|
|
103
|
+
const quotedLatitude = quoteDeckMapSqlIdentifier(options.latitudeColumn);
|
|
104
|
+
const cleanedSourceSqlQuery = options.sourceSqlQuery
|
|
105
|
+
?.trim()
|
|
106
|
+
.replace(/(?:\s*;+\s*)+$/, '');
|
|
107
|
+
const baseSource = cleanedSourceSqlQuery
|
|
108
|
+
? `(${cleanedSourceSqlQuery}) AS "__sqlrooms_dashboard_map_source"`
|
|
109
|
+
: quoteDeckMapSqlTableReference(options.tableReference);
|
|
110
|
+
return [
|
|
111
|
+
`SELECT *, ST_AsWKB(ST_Point(${quotedLongitude}, ${quotedLatitude})) AS ${quoteDeckMapSqlIdentifier(options.geometryColumn)}`,
|
|
112
|
+
`FROM ${baseSource}`,
|
|
113
|
+
`WHERE ${quotedLongitude} IS NOT NULL AND ${quotedLatitude} IS NOT NULL`,
|
|
114
|
+
].join(' ');
|
|
115
|
+
}
|
|
116
|
+
export function normalizeDeckMapFillColor(fillColor) {
|
|
117
|
+
if (fillColor?.length === 3) {
|
|
118
|
+
return [fillColor[0], fillColor[1], fillColor[2]];
|
|
119
|
+
}
|
|
120
|
+
if (fillColor?.length === 4) {
|
|
121
|
+
return [fillColor[0], fillColor[1], fillColor[2], fillColor[3]];
|
|
122
|
+
}
|
|
123
|
+
return [...DEFAULT_FILL_COLOR];
|
|
124
|
+
}
|
|
125
|
+
export function createDeckMapDashboardConfigForTable(options) {
|
|
126
|
+
const datasetId = options.tableName;
|
|
127
|
+
const explicitGeometryColumn = options.geometryColumn?.trim() || undefined;
|
|
128
|
+
const detectedCoordinates = options.longitudeColumn && options.latitudeColumn
|
|
129
|
+
? {
|
|
130
|
+
longitudeColumn: options.longitudeColumn,
|
|
131
|
+
latitudeColumn: options.latitudeColumn,
|
|
132
|
+
}
|
|
133
|
+
: findDeckMapLongitudeLatitudeColumns(options.columns);
|
|
134
|
+
const detectedGeometryColumn = explicitGeometryColumn
|
|
135
|
+
? {
|
|
136
|
+
geometryColumn: explicitGeometryColumn,
|
|
137
|
+
geometryEncodingHint: options.geometryEncodingHint,
|
|
138
|
+
}
|
|
139
|
+
: detectedCoordinates
|
|
140
|
+
? null
|
|
141
|
+
: findDeckMapGeometryColumn(options.columns);
|
|
142
|
+
const coordinates = detectedGeometryColumn
|
|
143
|
+
? undefined
|
|
144
|
+
: resolveDeckMapCoordinateColumns({
|
|
145
|
+
columns: options.columns,
|
|
146
|
+
longitudeColumn: options.longitudeColumn,
|
|
147
|
+
latitudeColumn: options.latitudeColumn,
|
|
148
|
+
});
|
|
149
|
+
const geometryColumn = detectedGeometryColumn?.geometryColumn ?? DEFAULT_GEOMETRY_COLUMN;
|
|
150
|
+
const geometryEncodingHint = options.geometryEncodingHint ??
|
|
151
|
+
detectedGeometryColumn?.geometryEncodingHint;
|
|
152
|
+
const source = coordinates
|
|
153
|
+
? {
|
|
154
|
+
sqlQuery: createDeckMapPointSourceSql({
|
|
155
|
+
sourceSqlQuery: options.sourceSqlQuery,
|
|
156
|
+
tableReference: options.tableReference ?? options.tableName,
|
|
157
|
+
longitudeColumn: coordinates.longitudeColumn,
|
|
158
|
+
latitudeColumn: coordinates.latitudeColumn,
|
|
159
|
+
geometryColumn,
|
|
160
|
+
}),
|
|
161
|
+
}
|
|
162
|
+
: options.sourceSqlQuery
|
|
163
|
+
? { sqlQuery: options.sourceSqlQuery }
|
|
164
|
+
: { tableName: options.tableName };
|
|
165
|
+
if (detectedGeometryColumn) {
|
|
166
|
+
ensureDeckMapColumnExists(options.columns, detectedGeometryColumn.geometryColumn, 'geometry');
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
spec: {
|
|
170
|
+
initialViewState: { longitude: 0, latitude: 20, zoom: 1.5 },
|
|
171
|
+
layers: [
|
|
172
|
+
{
|
|
173
|
+
'@@type': coordinates
|
|
174
|
+
? 'GeoArrowScatterplotLayer'
|
|
175
|
+
: 'GeoArrowPolygonLayer',
|
|
176
|
+
id: datasetId,
|
|
177
|
+
_sqlroomsBinding: { dataset: datasetId },
|
|
178
|
+
filled: true,
|
|
179
|
+
stroked: false,
|
|
180
|
+
pickable: true,
|
|
181
|
+
radiusUnits: 'pixels',
|
|
182
|
+
getRadius: options.pointRadius ?? 4,
|
|
183
|
+
getFillColor: options.fillColor ?? [...DEFAULT_FILL_COLOR],
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
datasets: {
|
|
188
|
+
[datasetId]: {
|
|
189
|
+
source,
|
|
190
|
+
geometryColumn,
|
|
191
|
+
geometryEncodingHint: coordinates ? 'wkb' : geometryEncodingHint,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
...(coordinates
|
|
195
|
+
? {
|
|
196
|
+
fitToData: {
|
|
197
|
+
dataset: datasetId,
|
|
198
|
+
longitudeColumn: coordinates.longitudeColumn,
|
|
199
|
+
latitudeColumn: coordinates.latitudeColumn,
|
|
200
|
+
padding: 40,
|
|
201
|
+
maxZoom: 12,
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
: {}),
|
|
205
|
+
...(options.mapStyle ? { mapStyle: options.mapStyle } : {}),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
export function createDeckMapDashboardPanelConfigForTable(options) {
|
|
209
|
+
return createDeckMapDashboardPanelConfig({
|
|
210
|
+
title: options.title,
|
|
211
|
+
...createDeckMapDashboardConfigForTable(options),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
export function regenerateMapConfigForTable(panel, table, longitudeColumn, latitudeColumn) {
|
|
215
|
+
if (!(longitudeColumn && latitudeColumn) &&
|
|
216
|
+
!findLongitudeLatitudeColumns(table) &&
|
|
217
|
+
!findGeometryColumn(table)) {
|
|
218
|
+
return panel.config;
|
|
219
|
+
}
|
|
220
|
+
const existingConfig = panel.config;
|
|
221
|
+
const nextConfig = createDeckMapDashboardConfigForTable({
|
|
222
|
+
tableName: table.tableName,
|
|
223
|
+
columns: table.columns,
|
|
224
|
+
tableReference: table.table,
|
|
225
|
+
longitudeColumn,
|
|
226
|
+
latitudeColumn,
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
...existingConfig,
|
|
230
|
+
...nextConfig,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=mapConfigUtils.js.map
|