@sqlrooms/cells 0.29.0-rc.2 → 0.29.0-rc.3
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 +8 -8
- package/dist/cellsSlice.d.ts.map +1 -1
- package/dist/cellsSlice.js +121 -198
- package/dist/cellsSlice.js.map +1 -1
- package/dist/components/CellSourceSelector.d.ts +1 -0
- package/dist/components/CellSourceSelector.d.ts.map +1 -1
- package/dist/components/CellSourceSelector.js +8 -9
- package/dist/components/CellSourceSelector.js.map +1 -1
- package/dist/components/SqlCellContent.js +3 -3
- package/dist/components/SqlCellContent.js.map +1 -1
- package/dist/components/SqlCellDependentsMenu.d.ts +3 -3
- package/dist/components/SqlCellDependentsMenu.d.ts.map +1 -1
- package/dist/components/SqlCellDependentsMenu.js +4 -4
- package/dist/components/SqlCellDependentsMenu.js.map +1 -1
- package/dist/components/VegaCellHeader.d.ts.map +1 -1
- package/dist/components/VegaCellHeader.js +2 -1
- package/dist/components/VegaCellHeader.js.map +1 -1
- package/dist/dagUtils.d.ts +9 -9
- package/dist/dagUtils.d.ts.map +1 -1
- package/dist/dagUtils.js +44 -42
- package/dist/dagUtils.js.map +1 -1
- package/dist/defaultCellRegistry.d.ts.map +1 -1
- package/dist/defaultCellRegistry.js +16 -12
- package/dist/defaultCellRegistry.js.map +1 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +22 -16
- package/dist/execution.js.map +1 -1
- package/dist/helpers.d.ts +9 -17
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +24 -43
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/sqlHelpers.d.ts +5 -5
- package/dist/sqlHelpers.d.ts.map +1 -1
- package/dist/sqlHelpers.js +7 -7
- package/dist/sqlHelpers.js.map +1 -1
- package/dist/types.d.ts +19 -47
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -12
- package/dist/types.js.map +1 -1
- package/dist/useValidateResultName.js +5 -5
- package/dist/useValidateResultName.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +4 -4
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/dist/components/DeleteSheetModal.d.ts +0 -9
- package/dist/components/DeleteSheetModal.d.ts.map +0 -1
- package/dist/components/DeleteSheetModal.js +0 -6
- package/dist/components/DeleteSheetModal.js.map +0 -1
- package/dist/components/SheetsTabBar.d.ts +0 -6
- package/dist/components/SheetsTabBar.d.ts.map +0 -1
- package/dist/components/SheetsTabBar.js +0 -58
- package/dist/components/SheetsTabBar.js.map +0 -1
- package/dist/components/SqlCellBody.d.ts +0 -6
- package/dist/components/SqlCellBody.d.ts.map +0 -1
- package/dist/components/SqlCellBody.js +0 -12
- package/dist/components/SqlCellBody.js.map +0 -1
- package/dist/crdt.d.ts +0 -61
- package/dist/crdt.d.ts.map +0 -1
- package/dist/crdt.js +0 -82
- package/dist/crdt.js.map +0 -1
- package/dist/dagSlice.d.ts +0 -3
- package/dist/dagSlice.d.ts.map +0 -1
- package/dist/dagSlice.js +0 -51
- package/dist/dagSlice.js.map +0 -1
- package/dist/typeGuards.d.ts +0 -2
- package/dist/typeGuards.d.ts.map +0 -1
- package/dist/typeGuards.js +0 -4
- package/dist/typeGuards.js.map +0 -1
- package/dist/validation.d.ts +0 -16
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -40
- package/dist/validation.js.map +0 -1
|
@@ -7,6 +7,7 @@ import { CellSourceSelector } from './CellSourceSelector';
|
|
|
7
7
|
import { useCellsStore } from '../hooks';
|
|
8
8
|
export const VegaCellHeader = ({ cellId, selectValue, onEditToggle, hasDataSource, crossFilterEnabled, brushField, crossFilterPredicate, }) => {
|
|
9
9
|
const updateCell = useCellsStore((s) => s.cells.updateCell);
|
|
10
|
+
const artifactId = useCellsStore((s) => s.cells.getArtifactIdForCell(cellId));
|
|
10
11
|
const handleDataSourceChange = (value) => {
|
|
11
12
|
updateCell(cellId, (c) => produce(c, (draft) => {
|
|
12
13
|
if (draft.type !== 'vega') {
|
|
@@ -24,7 +25,7 @@ export const VegaCellHeader = ({ cellId, selectValue, onEditToggle, hasDataSourc
|
|
|
24
25
|
}
|
|
25
26
|
}));
|
|
26
27
|
};
|
|
27
|
-
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CellSourceSelector, { value: selectValue, onValueChange: handleDataSourceChange }), _jsx(Button, { size: "xs", variant: "secondary", className: "h-6", onClick: onEditToggle, disabled: !hasDataSource, children: _jsx(Settings, { className: "h-4 w-4" }) }), crossFilterEnabled && brushField && (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("div", { className: "flex items-center", children: _jsx(Filter, { className: `h-3.5 w-3.5 ${crossFilterPredicate ? 'text-blue-500' : 'text-gray-400'}` }) }) }), _jsx(TooltipContent, { side: "bottom", children: _jsx("p", { className: "text-xs", children: crossFilterPredicate
|
|
28
|
+
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CellSourceSelector, { artifactId: artifactId ?? '', value: selectValue, onValueChange: handleDataSourceChange }), _jsx(Button, { size: "xs", variant: "secondary", className: "h-6", onClick: onEditToggle, disabled: !hasDataSource, children: _jsx(Settings, { className: "h-4 w-4" }) }), crossFilterEnabled && brushField && (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("div", { className: "flex items-center", children: _jsx(Filter, { className: `h-3.5 w-3.5 ${crossFilterPredicate ? 'text-blue-500' : 'text-gray-400'}` }) }) }), _jsx(TooltipContent, { side: "bottom", children: _jsx("p", { className: "text-xs", children: crossFilterPredicate
|
|
28
29
|
? `Filtered: ${crossFilterPredicate}`
|
|
29
30
|
: `Cross-filter on ${brushField}` }) })] }))] }));
|
|
30
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VegaCellHeader.js","sourceRoot":"","sources":["../../src/components/VegaCellHeader.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,kBAAkB,EAAE,mBAAmB,EAAC,MAAM,YAAY,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AAYvC,MAAM,CAAC,MAAM,cAAc,GAAkC,CAAC,EAC5D,MAAM,EACN,WAAW,EACX,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,oBAAoB,GACrB,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"VegaCellHeader.js","sourceRoot":"","sources":["../../src/components/VegaCellHeader.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,kBAAkB,EAAE,mBAAmB,EAAC,MAAM,YAAY,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AAYvC,MAAM,CAAC,MAAM,cAAc,GAAkC,CAAC,EAC5D,MAAM,EACN,WAAW,EACX,YAAY,EACZ,aAAa,E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C,KAAK,EACf,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,CAAC,aAAa,YAExB,KAAC,QAAQ,IAAC,SAAS,EAAC,SAAS,GAAG,GACzB,EACR,kBAAkB,IAAI,UAAU,IAAI,CACnC,MAAC,OAAO,eACN,KAAC,cAAc,IAAC,OAAO,kBACrB,cAAK,SAAS,EAAC,mBAAmB,YAChC,KAAC,MAAM,IACL,SAAS,EAAE,eAAe,oBAAoB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,EAAE,GACpF,GACE,GACS,EACjB,KAAC,cAAc,IAAC,IAAI,EAAC,QAAQ,YAC3B,YAAG,SAAS,EAAC,SAAS,YACnB,oBAAoB;gCACnB,CAAC,CAAC,aAAa,oBAAoB,EAAE;gCACrC,CAAC,CAAC,mBAAmB,UAAU,EAAE,GACjC,GACW,IACT,CACX,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {Button, Tooltip, TooltipContent, TooltipTrigger} from '@sqlrooms/ui';\nimport {produce} from 'immer';\nimport {Filter, Settings} from 'lucide-react';\nimport {fromDataSourceCell, fromDataSourceTable} from '../helpers';\nimport {CellSourceSelector} from './CellSourceSelector';\nimport {useCellsStore} from '../hooks';\n\nexport type VegaCellHeaderProps = {\n cellId: string;\n selectValue: string | undefined;\n onEditToggle: () => void;\n hasDataSource: boolean;\n crossFilterEnabled: boolean;\n brushField: string | undefined;\n crossFilterPredicate: string | null;\n};\n\nexport const VegaCellHeader: React.FC<VegaCellHeaderProps> = ({\n cellId,\n selectValue,\n onEditToggle,\n hasDataSource,\n crossFilterEnabled,\n brushField,\n crossFilterPredicate,\n}) => {\n const updateCell = useCellsStore((s) => s.cells.updateCell);\n const artifactId = useCellsStore((s) => s.cells.getArtifactIdForCell(cellId));\n\n const handleDataSourceChange = (value: string) => {\n updateCell(cellId, (c) =>\n produce(c, (draft) => {\n if (draft.type !== 'vega') {\n return;\n }\n\n const cellIdFromValue = fromDataSourceCell(value);\n const tableRef = fromDataSourceTable(value);\n\n if (cellIdFromValue) {\n draft.data.sqlId = cellIdFromValue;\n delete draft.data.tableRef;\n } else if (tableRef) {\n draft.data.tableRef = tableRef;\n delete draft.data.sqlId;\n }\n }),\n );\n };\n\n return (\n <div className=\"flex items-center gap-2\">\n <CellSourceSelector\n artifactId={artifactId ?? ''}\n value={selectValue}\n onValueChange={handleDataSourceChange}\n />\n <Button\n size=\"xs\"\n variant=\"secondary\"\n className=\"h-6\"\n onClick={onEditToggle}\n disabled={!hasDataSource}\n >\n <Settings className=\"h-4 w-4\" />\n </Button>\n {crossFilterEnabled && brushField && (\n <Tooltip>\n <TooltipTrigger asChild>\n <div className=\"flex items-center\">\n <Filter\n className={`h-3.5 w-3.5 ${crossFilterPredicate ? 'text-blue-500' : 'text-gray-400'}`}\n />\n </div>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n <p className=\"text-xs\">\n {crossFilterPredicate\n ? `Filtered: ${crossFilterPredicate}`\n : `Cross-filter on ${brushField}`}\n </p>\n </TooltipContent>\n </Tooltip>\n )}\n </div>\n );\n};\n"]}
|
package/dist/dagUtils.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type { CellsRootState,
|
|
1
|
+
import type { CellsRootState, CellArtifactRuntime, CellArtifactGraphCache, Edge, SqlSelectToJsonFn } from './types';
|
|
2
2
|
export type DependencyGraph = {
|
|
3
3
|
dependencies: Record<string, string[]>;
|
|
4
4
|
dependents: Record<string, string[]>;
|
|
5
5
|
tableDependencies?: Record<string, string[]>;
|
|
6
6
|
};
|
|
7
|
-
export declare function buildGraphCacheFromEdges(
|
|
8
|
-
export declare function dependencyEdgesFromGraphCache(
|
|
9
|
-
export declare function getRenderableDependencyEdges(
|
|
10
|
-
export declare function ensureGraphCache(
|
|
11
|
-
export declare function replaceCellDependenciesInCache(
|
|
12
|
-
export declare function removeCellFromCache(
|
|
13
|
-
export declare function buildDependencyGraph(
|
|
7
|
+
export declare function buildGraphCacheFromEdges(artifact: CellArtifactRuntime): CellArtifactGraphCache;
|
|
8
|
+
export declare function dependencyEdgesFromGraphCache(artifact: CellArtifactRuntime): Edge[];
|
|
9
|
+
export declare function getRenderableDependencyEdges(artifact: CellArtifactRuntime): Edge[];
|
|
10
|
+
export declare function ensureGraphCache(artifact: CellArtifactRuntime): CellArtifactGraphCache;
|
|
11
|
+
export declare function replaceCellDependenciesInCache(artifact: CellArtifactRuntime, cellId: string, deps: string[], tableNames?: string[]): void;
|
|
12
|
+
export declare function removeCellFromCache(artifact: CellArtifactRuntime, cellId: string): void;
|
|
13
|
+
export declare function buildDependencyGraph(artifactId: string, state: CellsRootState): DependencyGraph;
|
|
14
14
|
export declare function topologicalOrder(roots: string[], dependencies: Record<string, string[]>, dependents: Record<string, string[]>, scope?: Set<string>): string[];
|
|
15
15
|
export declare function collectReachable(startId: string, dependents: Record<string, string[]>): Set<string>;
|
|
16
16
|
/**
|
|
17
17
|
* Async version of dependency graph build that always uses AST-enabled
|
|
18
18
|
* registry dependency derivation.
|
|
19
19
|
*/
|
|
20
|
-
export declare function buildDependencyGraphAsync(
|
|
20
|
+
export declare function buildDependencyGraphAsync(artifactId: string, state: CellsRootState, sqlSelectToJson: SqlSelectToJsonFn): Promise<DependencyGraph>;
|
|
21
21
|
//# sourceMappingURL=dagUtils.d.ts.map
|
package/dist/dagUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dagUtils.d.ts","sourceRoot":"","sources":["../src/dagUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"dagUtils.d.ts","sourceRoot":"","sources":["../src/dagUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,IAAI,EAEJ,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAIjB,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,M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sB,yBAAyB,CAC7C,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,cAAc,EACrB,eAAe,EAAE,iBAAiB,GACjC,OAAO,CAAC,eAAe,CAAC,CA+E1B"}
|
package/dist/dagUtils.js
CHANGED
|
@@ -6,19 +6,19 @@ function dedupe(values) {
|
|
|
6
6
|
function getEdgeKind(edge) {
|
|
7
7
|
return edge.kind ?? 'dependency';
|
|
8
8
|
}
|
|
9
|
-
function isGraphCacheComplete(cache,
|
|
9
|
+
function isGraphCacheComplete(cache, artifact) {
|
|
10
10
|
if (!cache)
|
|
11
11
|
return false;
|
|
12
|
-
return
|
|
12
|
+
return artifact.cellIds.every((cellId) => Array.isArray(cache.dependencies[cellId]));
|
|
13
13
|
}
|
|
14
|
-
export function buildGraphCacheFromEdges(
|
|
14
|
+
export function buildGraphCacheFromEdges(artifact) {
|
|
15
15
|
const dependencies = {};
|
|
16
16
|
const dependents = {};
|
|
17
|
-
const localCellIds = new Set(
|
|
18
|
-
for (const cellId of
|
|
17
|
+
const localCellIds = new Set(artifact.cellIds);
|
|
18
|
+
for (const cellId of artifact.cellIds) {
|
|
19
19
|
dependencies[cellId] = [];
|
|
20
20
|
}
|
|
21
|
-
for (const edge of
|
|
21
|
+
for (const edge of artifact.edges) {
|
|
22
22
|
// Cascades only consume dependency edges.
|
|
23
23
|
if (getEdgeKind(edge) !== 'dependency')
|
|
24
24
|
continue;
|
|
@@ -34,17 +34,17 @@ export function buildGraphCacheFromEdges(sheet) {
|
|
|
34
34
|
return {
|
|
35
35
|
dependencies,
|
|
36
36
|
dependents,
|
|
37
|
-
contentHashByCell:
|
|
38
|
-
tableDependencies:
|
|
37
|
+
contentHashByCell: artifact.graphCache?.contentHashByCell || {},
|
|
38
|
+
tableDependencies: artifact.graphCache?.tableDependencies || {},
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
export function dependencyEdgesFromGraphCache(
|
|
42
|
-
if (!isGraphCacheComplete(
|
|
41
|
+
export function dependencyEdgesFromGraphCache(artifact) {
|
|
42
|
+
if (!isGraphCacheComplete(artifact.graphCache, artifact))
|
|
43
43
|
return [];
|
|
44
|
-
const cache =
|
|
45
|
-
const localCellIds = new Set(
|
|
44
|
+
const cache = artifact.graphCache;
|
|
45
|
+
const localCellIds = new Set(artifact.cellIds);
|
|
46
46
|
const edges = [];
|
|
47
|
-
for (const target of
|
|
47
|
+
for (const target of artifact.cellIds) {
|
|
48
48
|
const deps = dedupe(cache.dependencies[target] || []);
|
|
49
49
|
for (const source of deps) {
|
|
50
50
|
if (!localCellIds.has(source) || source === target)
|
|
@@ -59,24 +59,26 @@ export function dependencyEdgesFromGraphCache(sheet) {
|
|
|
59
59
|
}
|
|
60
60
|
return edges;
|
|
61
61
|
}
|
|
62
|
-
export function getRenderableDependencyEdges(
|
|
63
|
-
const cacheEdges = dependencyEdgesFromGraphCache(
|
|
64
|
-
if (cacheEdges.length > 0 ||
|
|
62
|
+
export function getRenderableDependencyEdges(artifact) {
|
|
63
|
+
const cacheEdges = dependencyEdgesFromGraphCache(artifact);
|
|
64
|
+
if (cacheEdges.length > 0 ||
|
|
65
|
+
isGraphCacheComplete(artifact.graphCache, artifact)) {
|
|
65
66
|
return cacheEdges;
|
|
66
67
|
}
|
|
67
68
|
// Compatibility fallback while legacy edge persistence still exists.
|
|
68
69
|
// TODO(edge-kinds): merge sheet-local manual edges here once manual editing is enabled.
|
|
69
|
-
return
|
|
70
|
+
return artifact.edges.filter((edge) => getEdgeKind(edge) === 'dependency');
|
|
70
71
|
}
|
|
71
|
-
export function ensureGraphCache(
|
|
72
|
-
if (!
|
|
73
|
-
|
|
72
|
+
export function ensureGraphCache(artifact) {
|
|
73
|
+
if (!artifact.graphCache ||
|
|
74
|
+
!isGraphCacheComplete(artifact.graphCache, artifact)) {
|
|
75
|
+
artifact.graphCache = buildGraphCacheFromEdges(artifact);
|
|
74
76
|
}
|
|
75
|
-
return
|
|
77
|
+
return artifact.graphCache;
|
|
76
78
|
}
|
|
77
|
-
export function replaceCellDependenciesInCache(
|
|
78
|
-
const cache = ensureGraphCache(
|
|
79
|
-
const localCellIds = new Set(
|
|
79
|
+
export function replaceCellDependenciesInCache(artifact, cellId, deps, tableNames) {
|
|
80
|
+
const cache = ensureGraphCache(artifact);
|
|
81
|
+
const localCellIds = new Set(artifact.cellIds);
|
|
80
82
|
const nextDeps = dedupe(deps).filter((depId) => localCellIds.has(depId) && depId !== cellId);
|
|
81
83
|
const previousDeps = cache.dependencies[cellId] || [];
|
|
82
84
|
for (const oldDep of previousDeps) {
|
|
@@ -96,8 +98,8 @@ export function replaceCellDependenciesInCache(sheet, cellId, deps, tableNames)
|
|
|
96
98
|
cache.tableDependencies[cellId] = tableNames;
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
export function removeCellFromCache(
|
|
100
|
-
const cache = ensureGraphCache(
|
|
101
|
+
export function removeCellFromCache(artifact, cellId) {
|
|
102
|
+
const cache = ensureGraphCache(artifact);
|
|
101
103
|
const previousDeps = cache.dependencies[cellId] || [];
|
|
102
104
|
for (const depId of previousDeps) {
|
|
103
105
|
const children = cache.dependents[depId] || [];
|
|
@@ -117,13 +119,13 @@ export function removeCellFromCache(sheet, cellId) {
|
|
|
117
119
|
delete cache.tableDependencies[cellId];
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
|
-
export function buildDependencyGraph(
|
|
121
|
-
const
|
|
122
|
-
if (!
|
|
122
|
+
export function buildDependencyGraph(artifactId, state) {
|
|
123
|
+
const artifact = state.cells.config.artifacts[artifactId];
|
|
124
|
+
if (!artifact)
|
|
123
125
|
return { dependencies: {}, dependents: {} };
|
|
124
|
-
const cache = isGraphCacheComplete(
|
|
125
|
-
?
|
|
126
|
-
: buildGraphCacheFromEdges(
|
|
126
|
+
const cache = isGraphCacheComplete(artifact.graphCache, artifact)
|
|
127
|
+
? artifact.graphCache
|
|
128
|
+
: buildGraphCacheFromEdges(artifact);
|
|
127
129
|
return {
|
|
128
130
|
dependencies: { ...cache.dependencies },
|
|
129
131
|
dependents: { ...cache.dependents },
|
|
@@ -188,14 +190,14 @@ export function collectReachable(startId, dependents) {
|
|
|
188
190
|
* Async version of dependency graph build that always uses AST-enabled
|
|
189
191
|
* registry dependency derivation.
|
|
190
192
|
*/
|
|
191
|
-
export async function buildDependencyGraphAsync(
|
|
192
|
-
const
|
|
193
|
+
export async function buildDependencyGraphAsync(artifactId, state, sqlSelectToJson) {
|
|
194
|
+
const artifact = state.cells.config.artifacts[artifactId];
|
|
193
195
|
const registry = state.cells.cellRegistry;
|
|
194
|
-
if (!
|
|
196
|
+
if (!artifact) {
|
|
195
197
|
return { dependencies: {}, dependents: {} };
|
|
196
198
|
}
|
|
197
|
-
if (isGraphCacheComplete(
|
|
198
|
-
const cache =
|
|
199
|
+
if (isGraphCacheComplete(artifact.graphCache, artifact)) {
|
|
200
|
+
const cache = artifact.graphCache;
|
|
199
201
|
return {
|
|
200
202
|
dependencies: { ...cache.dependencies },
|
|
201
203
|
dependents: { ...cache.dependents },
|
|
@@ -207,12 +209,12 @@ export async function buildDependencyGraphAsync(sheetId, state, sqlSelectToJson)
|
|
|
207
209
|
const dependencies = {};
|
|
208
210
|
const dependents = {};
|
|
209
211
|
const tableDependencies = {};
|
|
210
|
-
const
|
|
211
|
-
const scopedCells = Object.fromEntries(
|
|
212
|
+
const artifactCellIds = new Set(artifact.cellIds);
|
|
213
|
+
const scopedCells = Object.fromEntries(artifact.cellIds
|
|
212
214
|
.map((id) => state.cells.config.data[id])
|
|
213
215
|
.filter(isDefined)
|
|
214
216
|
.map((cell) => [cell.id, cell]));
|
|
215
|
-
const cellDeps = await Promise.all(
|
|
217
|
+
const cellDeps = await Promise.all(artifact.cellIds.map(async (cellId) => {
|
|
216
218
|
const cell = state.cells.config.data[cellId];
|
|
217
219
|
if (!cell)
|
|
218
220
|
return {
|
|
@@ -230,13 +232,13 @@ export async function buildDependencyGraphAsync(sheetId, state, sqlSelectToJson)
|
|
|
230
232
|
const raw = await registryItem.findDependencies({
|
|
231
233
|
cell,
|
|
232
234
|
cells: scopedCells,
|
|
233
|
-
|
|
235
|
+
artifactId,
|
|
234
236
|
sqlSelectToJson,
|
|
235
237
|
});
|
|
236
238
|
const normalized = normalizeCellDependencies(raw);
|
|
237
239
|
return {
|
|
238
240
|
cellId,
|
|
239
|
-
cellIds: Array.from(new Set(normalized.cellIds)).filter((depId) =>
|
|
241
|
+
cellIds: Array.from(new Set(normalized.cellIds)).filter((depId) => artifactCellIds.has(depId)),
|
|
240
242
|
tableNames: normalized.tableNames,
|
|
241
243
|
};
|
|
242
244
|
}));
|
package/dist/dagUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dagUtils.js","sourceRoot":"","sources":["../src/dagUtils.ts"],"names":[],"mappings":"AAUA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAClC,OAAO,EAAC,yBAAyB,EAAC,MAAM,WAAW,CAAC;AAQpD,SAAS,MAAM,CAAC,MAAgB;IAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,WAAW,CAAC,IAAU;IAC7B,OAAO,IAAI,CAAC,IAAI,IAAI,YAAY,CAAC;AACnC,CAAC;AAED,SAAS,oBAAoB,CAC3B,KAAkC,EAClC,KAAY;IAEZ,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CACpC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAY;IACnD,MAAM,YAAY,GAA6B,EAAE,CAAC;IAClD,MAAM,UAAU,GAA6B,EAAE,CAAC;IAChD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC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AAK,EAAE,WAAW;YAClB,OAAO;YACP,eAAe;SAChB,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;QAElD,OAAO;YACL,MAAM;YACN,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAChE,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CACxB;YACD,UAAU,EAAE,UAAU,CAAC,UAAU;SAClC,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAC,IAAI,QAAQ,EAAE,CAAC;QACrD,YAAY,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;YACvD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QACD,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxC,iBAAiB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;QACzC,CAAC;IACH,CAAC;IAED,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAC,CAAC;AACvD,CAAC","sourcesContent":["import type {\n Cell,\n CellDependencies,\n CellsRootState,\n Edge,\n EdgeKind,\n Sheet,\n SheetGraphCache,\n SqlSelectToJsonFn,\n} from './types';\nimport {isDefined} from './utils';\nimport {normalizeCellDependencies} from './helpers';\n\nexport type DependencyGraph = {\n dependencies: Record<string, string[]>;\n dependents: Record<string, string[]>;\n tableDependencies?: Record<string, string[]>;\n};\n\nfunction dedupe(values: string[]): string[] {\n return Array.from(new Set(values));\n}\n\nfunction getEdgeKind(edge: Edge): EdgeKind {\n return edge.kind ?? 'dependency';\n}\n\nfunction isGraphCacheComplete(\n cache: SheetGraphCache | undefined,\n sheet: Sheet,\n): boolean {\n if (!cache) return false;\n return sheet.cellIds.every((cellId) =>\n Array.isArray(cache.dependencies[cellId]),\n );\n}\n\nexport function buildGraphCacheFromEdges(sheet: Sheet): SheetGraphCache {\n const dependencies: Record<string, string[]> = {};\n const dependents: Record<string, string[]> = {};\n const localCellIds = new Set(sheet.cellIds);\n\n for (const cellId of sheet.cellIds) {\n dependencies[cellId] = [];\n }\n\n for (const edge of sheet.edges) {\n // Cascades only consume dependency edges.\n if (getEdgeKind(edge) !== 'dependency') continue;\n if (!localCellIds.has(edge.source) || !localCellIds.has(edge.target))\n continue;\n\n const deps = dependencies[edge.target] || (dependencies[edge.target] = []);\n if (!deps.includes(edge.source)) deps.push(edge.source);\n\n const children = dependents[edge.source] || (dependents[edge.source] = []);\n if (!children.includes(edge.target)) children.push(edge.target);\n }\n\n return {\n dependencies,\n dependents,\n contentHashByCell: sheet.graphCache?.contentHashByCell || {},\n tableDependencies: sheet.graphCache?.tableDependencies || {},\n };\n}\n\nexport function dependencyEdgesFromGraphCache(sheet: Sheet): Edge[] {\n if (!isGraphCacheComplete(sheet.graphCache, sheet)) return [];\n\n const cache = sheet.graphCache as SheetGraphCache;\n const localCellIds = new Set(sheet.cellIds);\n const edges: Edge[] = [];\n\n for (const target of sheet.cellIds) {\n const deps = dedupe(cache.dependencies[target] || []);\n for (const source of deps) {\n if (!localCellIds.has(source) || source === target) continue;\n edges.push({\n id: `${source}-${target}`,\n source,\n target,\n kind: 'dependency',\n });\n }\n }\n\n return edges;\n}\n\nexport function getRenderableDependencyEdges(sheet: Sheet): Edge[] {\n const cacheEdges = dependencyEdgesFromGraphCache(sheet);\n if (cacheEdges.length > 0 || isGraphCacheComplete(sheet.graphCache, sheet)) {\n return cacheEdges;\n }\n\n // Compatibility fallback while legacy edge persistence still exists.\n // TODO(edge-kinds): merge sheet-local manual edges here once manual editing is enabled.\n return sheet.edges.filter((edge) => getEdgeKind(edge) === 'dependency');\n}\n\nexport function ensureGraphCache(sheet: Sheet): SheetGraphCache {\n if (!sheet.graphCache || !isGraphCacheComplete(sheet.graphCache, sheet)) {\n sheet.graphCache = buildGraphCacheFromEdges(sheet);\n }\n return sheet.graphCache;\n}\n\nexport function replaceCellDependenciesInCache(\n sheet: Sheet,\n cellId: string,\n deps: string[],\n tableNames?: string[],\n) {\n const cache = ensureGraphCache(sheet);\n const localCellIds = new Set(sheet.cellIds);\n const nextDeps = dedupe(deps).filter(\n (depId) => localCellIds.has(depId) && depId !== cellId,\n );\n const previousDeps = cache.dependencies[cellId] || [];\n\n for (const oldDep of previousDeps) {\n if (nextDeps.includes(oldDep)) continue;\n const currentDependents = cache.dependents[oldDep] || [];\n cache.dependents[oldDep] = currentDependents.filter((id) => id !== cellId);\n }\n\n cache.dependencies[cellId] = nextDeps;\n\n for (const depId of nextDeps) {\n const children = cache.dependents[depId] || (cache.dependents[depId] = []);\n if (!children.includes(cellId)) children.push(cellId);\n }\n\n if (tableNames !== undefined) {\n cache.tableDependencies = cache.tableDependencies || {};\n cache.tableDependencies[cellId] = tableNames;\n }\n}\n\nexport function removeCellFromCache(sheet: Sheet, cellId: string) {\n const cache = ensureGraphCache(sheet);\n const previousDeps = cache.dependencies[cellId] || [];\n\n for (const depId of previousDeps) {\n const children = cache.dependents[depId] || [];\n cache.dependents[depId] = children.filter((id) => id !== cellId);\n }\n\n const downstream = cache.dependents[cellId] || [];\n for (const dependentId of downstream) {\n const deps = cache.dependencies[dependentId] || [];\n cache.dependencies[dependentId] = deps.filter((id) => id !== cellId);\n }\n\n delete cache.dependencies[cellId];\n delete cache.dependents[cellId];\n if (cache.contentHashByCell) {\n delete cache.contentHashByCell[cellId];\n }\n if (cache.tableDependencies) {\n delete cache.tableDependencies[cellId];\n }\n}\n\nexport function buildDependencyGraph(\n sheetId: string,\n state: CellsRootState,\n): DependencyGraph {\n const sheet = state.cells.config.sheets[sheetId];\n if (!sheet) return {dependencies: {}, dependents: {}};\n\n const cache = isGraphCacheComplete(sheet.graphCache, sheet)\n ? (sheet.graphCache as SheetGraphCache)\n : buildGraphCacheFromEdges(sheet);\n\n return {\n dependencies: {...cache.dependencies},\n dependents: {...cache.dependents},\n };\n}\n\nexport function topologicalOrder(\n roots: string[],\n dependencies: Record<string, string[]>,\n dependents: Record<string, string[]>,\n scope?: Set<string>,\n): string[] {\n const inDegree: Record<string, number> = {};\n const queue: string[] = [];\n\n const addNode = (id: string) => {\n if (scope && !scope.has(id)) return;\n if (!(id in inDegree)) inDegree[id] = 0;\n };\n\n for (const [cellId, deps] of Object.entries(dependencies)) {\n addNode(cellId);\n if (scope && !scope.has(cellId)) continue;\n for (const dep of deps) {\n if (scope && !scope.has(dep)) continue;\n inDegree[cellId] = (inDegree[cellId] ?? 0) + 1;\n addNode(dep);\n }\n }\n\n for (const root of roots) {\n if (scope && !scope.has(root)) continue;\n queue.push(root);\n }\n\n const order: string[] = [];\n while (queue.length) {\n const current = queue.shift() as string;\n if (scope && !scope.has(current)) continue;\n order.push(current);\n for (const child of dependents[current] || []) {\n if (scope && !scope.has(child)) continue;\n inDegree[child] = (inDegree[child] ?? 0) - 1;\n if (inDegree[child] === 0) queue.push(child);\n }\n }\n return order;\n}\n\nexport function collectReachable(\n startId: string,\n dependents: Record<string, string[]>,\n): Set<string> {\n const reachable = new Set<string>();\n const queue = [...(dependents[startId] || [])];\n while (queue.length) {\n const next = queue.shift() as string;\n if (reachable.has(next)) continue;\n reachable.add(next);\n for (const child of dependents[next] || []) {\n queue.push(child);\n }\n }\n return reachable;\n}\n\n/**\n * Async version of dependency graph build that always uses AST-enabled\n * registry dependency derivation.\n */\nexport async function buildDependencyGraphAsync(\n sheetId: string,\n state: CellsRootState,\n sqlSelectToJson: SqlSelectToJsonFn,\n): Promise<DependencyGraph> {\n const sheet = state.cells.config.sheets[sheetId];\n const registry = state.cells.cellRegistry;\n if (!sheet) {\n return {dependencies: {}, dependents: {}};\n }\n\n if (isGraphCacheComplete(sheet.graphCache, sheet)) {\n const cache = sheet.graphCache as SheetGraphCache;\n return {\n dependencies: {...cache.dependencies},\n dependents: {...cache.dependents},\n tableDependencies: cache.tableDependencies\n ? {...cache.tableDependencies}\n : undefined,\n };\n }\n\n const dependencies: Record<string, string[]> = {};\n const dependents: Record<string, string[]> = {};\n const tableDependencies: Record<string, string[]> = {};\n const sheetCellIds = new Set(sheet.cellIds);\n const scopedCells = Object.fromEntries(\n sheet.cellIds\n .map((id) => state.cells.config.data[id])\n .filter(isDefined)\n .map((cell) => [cell.id, cell]),\n ) as Record<string, Cell>;\n\n const cellDeps = await Promise.all(\n sheet.cellIds.map(async (cellId) => {\n const cell = state.cells.config.data[cellId];\n if (!cell)\n return {\n cellId,\n cellIds: [] as string[],\n tableNames: undefined as string[] | undefined,\n };\n\n const registryItem = registry[cell.type];\n if (!registryItem)\n return {\n cellId,\n cellIds: [] as string[],\n tableNames: undefined as string[] | undefined,\n };\n\n const raw = await registryItem.findDependencies({\n cell,\n cells: scopedCells,\n sheetId,\n sqlSelectToJson,\n });\n const normalized = normalizeCellDependencies(raw);\n\n return {\n cellId,\n cellIds: Array.from(new Set(normalized.cellIds)).filter((depId) =>\n sheetCellIds.has(depId),\n ),\n tableNames: normalized.tableNames,\n };\n }),\n );\n\n for (const {cellId, cellIds, tableNames} of cellDeps) {\n dependencies[cellId] = cellIds;\n for (const dep of cellIds) {\n const list = dependents[dep] || (dependents[dep] = []);\n if (!list.includes(cellId)) {\n list.push(cellId);\n }\n }\n if (tableNames && tableNames.length > 0) {\n tableDependencies[cellId] = tableNames;\n }\n }\n\n return {dependencies, dependents, tableDependencies};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dagUtils.js","sourceRoot":"","sources":["../src/dagUtils.ts"],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KAAK,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAC,IAAI,QAAQ,EAAE,CAAC;QACrD,YAAY,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;YACvD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QACD,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxC,iBAAiB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;QACzC,CAAC;IACH,CAAC;IAED,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAC,CAAC;AACvD,CAAC","sourcesContent":["import type {\n Cell,\n CellDependencies,\n CellsRootState,\n CellArtifactRuntime,\n CellArtifactGraphCache,\n Edge,\n EdgeKind,\n SqlSelectToJsonFn,\n} from './types';\nimport {isDefined} from './utils';\nimport {normalizeCellDependencies} from './helpers';\n\nexport type DependencyGraph = {\n dependencies: Record<string, string[]>;\n dependents: Record<string, string[]>;\n tableDependencies?: Record<string, string[]>;\n};\n\nfunction dedupe(values: string[]): string[] {\n return Array.from(new Set(values));\n}\n\nfunction getEdgeKind(edge: Edge): EdgeKind {\n return edge.kind ?? 'dependency';\n}\n\nfunction isGraphCacheComplete(\n cache: CellArtifactGraphCache | undefined,\n artifact: CellArtifactRuntime,\n): boolean {\n if (!cache) return false;\n return artifact.cellIds.every((cellId) =>\n Array.isArray(cache.dependencies[cellId]),\n );\n}\n\nexport function buildGraphCacheFromEdges(\n artifact: CellArtifactRuntime,\n): CellArtifactGraphCache {\n const dependencies: Record<string, string[]> = {};\n const dependents: Record<string, string[]> = {};\n const localCellIds = new Set(artifact.cellIds);\n\n for (const cellId of artifact.cellIds) {\n dependencies[cellId] = [];\n }\n\n for (const edge of artifact.edges) {\n // Cascades only consume dependency edges.\n if (getEdgeKind(edge) !== 'dependency') continue;\n if (!localCellIds.has(edge.source) || !localCellIds.has(edge.target))\n continue;\n\n const deps = dependencies[edge.target] || (dependencies[edge.target] = []);\n if (!deps.includes(edge.source)) deps.push(edge.source);\n\n const children = dependents[edge.source] || (dependents[edge.source] = []);\n if (!children.includes(edge.target)) children.push(edge.target);\n }\n\n return {\n dependencies,\n dependents,\n contentHashByCell: artifact.graphCache?.contentHashByCell || {},\n tableDependencies: artifact.graphCache?.tableDependencies || {},\n };\n}\n\nexport function dependencyEdgesFromGraphCache(\n artifact: CellArtifactRuntime,\n): Edge[] {\n if (!isGraphCacheComplete(artifact.graphCache, artifact)) return [];\n\n const cache = artifact.graphCache as CellArtifactGraphCache;\n const localCellIds = new Set(artifact.cellIds);\n const edges: Edge[] = [];\n\n for (const target of artifact.cellIds) {\n const deps = dedupe(cache.dependencies[target] || []);\n for (const source of deps) {\n if (!localCellIds.has(source) || source === target) continue;\n edges.push({\n id: `${source}-${target}`,\n source,\n target,\n kind: 'dependency',\n });\n }\n }\n\n return edges;\n}\n\nexport function getRenderableDependencyEdges(\n artifact: CellArtifactRuntime,\n): Edge[] {\n const cacheEdges = dependencyEdgesFromGraphCache(artifact);\n if (\n cacheEdges.length > 0 ||\n isGraphCacheComplete(artifact.graphCache, artifact)\n ) {\n return cacheEdges;\n }\n\n // Compatibility fallback while legacy edge persistence still exists.\n // TODO(edge-kinds): merge sheet-local manual edges here once manual editing is enabled.\n return artifact.edges.filter((edge) => getEdgeKind(edge) === 'dependency');\n}\n\nexport function ensureGraphCache(\n artifact: CellArtifactRuntime,\n): CellArtifactGraphCache {\n if (\n !artifact.graphCache ||\n !isGraphCacheComplete(artifact.graphCache, artifact)\n ) {\n artifact.graphCache = buildGraphCacheFromEdges(artifact);\n }\n return artifact.graphCache;\n}\n\nexport function replaceCellDependenciesInCache(\n artifact: CellArtifactRuntime,\n cellId: string,\n deps: string[],\n tableNames?: string[],\n) {\n const cache = ensureGraphCache(artifact);\n const localCellIds = new Set(artifact.cellIds);\n const nextDeps = dedupe(deps).filter(\n (depId) => localCellIds.has(depId) && depId !== cellId,\n );\n const previousDeps = cache.dependencies[cellId] || [];\n\n for (const oldDep of previousDeps) {\n if (nextDeps.includes(oldDep)) continue;\n const currentDependents = cache.dependents[oldDep] || [];\n cache.dependents[oldDep] = currentDependents.filter((id) => id !== cellId);\n }\n\n cache.dependencies[cellId] = nextDeps;\n\n for (const depId of nextDeps) {\n const children = cache.dependents[depId] || (cache.dependents[depId] = []);\n if (!children.includes(cellId)) children.push(cellId);\n }\n\n if (tableNames !== undefined) {\n cache.tableDependencies = cache.tableDependencies || {};\n cache.tableDependencies[cellId] = tableNames;\n }\n}\n\nexport function removeCellFromCache(\n artifact: CellArtifactRuntime,\n cellId: string,\n) {\n const cache = ensureGraphCache(artifact);\n const previousDeps = cache.dependencies[cellId] || [];\n\n for (const depId of previousDeps) {\n const children = cache.dependents[depId] || [];\n cache.dependents[depId] = children.filter((id) => id !== cellId);\n }\n\n const downstream = cache.dependents[cellId] || [];\n for (const dependentId of downstream) {\n const deps = cache.dependencies[dependentId] || [];\n cache.dependencies[dependentId] = deps.filter((id) => id !== cellId);\n }\n\n delete cache.dependencies[cellId];\n delete cache.dependents[cellId];\n if (cache.contentHashByCell) {\n delete cache.contentHashByCell[cellId];\n }\n if (cache.tableDependencies) {\n delete cache.tableDependencies[cellId];\n }\n}\n\nexport function buildDependencyGraph(\n artifactId: string,\n state: CellsRootState,\n): DependencyGraph {\n const artifact = state.cells.config.artifacts[artifactId];\n if (!artifact) return {dependencies: {}, dependents: {}};\n\n const cache = isGraphCacheComplete(artifact.graphCache, artifact)\n ? (artifact.graphCache as CellArtifactGraphCache)\n : buildGraphCacheFromEdges(artifact);\n\n return {\n dependencies: {...cache.dependencies},\n dependents: {...cache.dependents},\n };\n}\n\nexport function topologicalOrder(\n roots: string[],\n dependencies: Record<string, string[]>,\n dependents: Record<string, string[]>,\n scope?: Set<string>,\n): string[] {\n const inDegree: Record<string, number> = {};\n const queue: string[] = [];\n\n const addNode = (id: string) => {\n if (scope && !scope.has(id)) return;\n if (!(id in inDegree)) inDegree[id] = 0;\n };\n\n for (const [cellId, deps] of Object.entries(dependencies)) {\n addNode(cellId);\n if (scope && !scope.has(cellId)) continue;\n for (const dep of deps) {\n if (scope && !scope.has(dep)) continue;\n inDegree[cellId] = (inDegree[cellId] ?? 0) + 1;\n addNode(dep);\n }\n }\n\n for (const root of roots) {\n if (scope && !scope.has(root)) continue;\n queue.push(root);\n }\n\n const order: string[] = [];\n while (queue.length) {\n const current = queue.shift() as string;\n if (scope && !scope.has(current)) continue;\n order.push(current);\n for (const child of dependents[current] || []) {\n if (scope && !scope.has(child)) continue;\n inDegree[child] = (inDegree[child] ?? 0) - 1;\n if (inDegree[child] === 0) queue.push(child);\n }\n }\n return order;\n}\n\nexport function collectReachable(\n startId: string,\n dependents: Record<string, string[]>,\n): Set<string> {\n const reachable = new Set<string>();\n const queue = [...(dependents[startId] || [])];\n while (queue.length) {\n const next = queue.shift() as string;\n if (reachable.has(next)) continue;\n reachable.add(next);\n for (const child of dependents[next] || []) {\n queue.push(child);\n }\n }\n return reachable;\n}\n\n/**\n * Async version of dependency graph build that always uses AST-enabled\n * registry dependency derivation.\n */\nexport async function buildDependencyGraphAsync(\n artifactId: string,\n state: CellsRootState,\n sqlSelectToJson: SqlSelectToJsonFn,\n): Promise<DependencyGraph> {\n const artifact = state.cells.config.artifacts[artifactId];\n const registry = state.cells.cellRegistry;\n if (!artifact) {\n return {dependencies: {}, dependents: {}};\n }\n\n if (isGraphCacheComplete(artifact.graphCache, artifact)) {\n const cache = artifact.graphCache as CellArtifactGraphCache;\n return {\n dependencies: {...cache.dependencies},\n dependents: {...cache.dependents},\n tableDependencies: cache.tableDependencies\n ? {...cache.tableDependencies}\n : undefined,\n };\n }\n\n const dependencies: Record<string, string[]> = {};\n const dependents: Record<string, string[]> = {};\n const tableDependencies: Record<string, string[]> = {};\n const artifactCellIds = new Set(artifact.cellIds);\n const scopedCells = Object.fromEntries(\n artifact.cellIds\n .map((id) => state.cells.config.data[id])\n .filter(isDefined)\n .map((cell) => [cell.id, cell]),\n ) as Record<string, Cell>;\n\n const cellDeps = await Promise.all(\n artifact.cellIds.map(async (cellId) => {\n const cell = state.cells.config.data[cellId];\n if (!cell)\n return {\n cellId,\n cellIds: [] as string[],\n tableNames: undefined as string[] | undefined,\n };\n\n const registryItem = registry[cell.type];\n if (!registryItem)\n return {\n cellId,\n cellIds: [] as string[],\n tableNames: undefined as string[] | undefined,\n };\n\n const raw = await registryItem.findDependencies({\n cell,\n cells: scopedCells,\n artifactId,\n sqlSelectToJson,\n });\n const normalized = normalizeCellDependencies(raw);\n\n return {\n cellId,\n cellIds: Array.from(new Set(normalized.cellIds)).filter((depId) =>\n artifactCellIds.has(depId),\n ),\n tableNames: normalized.tableNames,\n };\n }),\n );\n\n for (const {cellId, cellIds, tableNames} of cellDeps) {\n dependencies[cellId] = cellIds;\n for (const dep of cellIds) {\n const list = dependents[dep] || (dependents[dep] = []);\n if (!list.includes(cellId)) {\n list.push(cellId);\n }\n }\n if (tableNames && tableNames.length > 0) {\n tableDependencies[cellId] = tableNames;\n }\n }\n\n return {dependencies, dependents, tableDependencies};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultCellRegistry.d.ts","sourceRoot":"","sources":["../src/defaultCellRegistry.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,YAAY,EAQb,MAAM,SAAS,CAAC;AAIjB,wBAAgB,yBAAyB,IAAI,YAAY,
|
|
1
|
+
{"version":3,"file":"defaultCellRegistry.d.ts","sourceRoot":"","sources":["../src/defaultCellRegistry.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,YAAY,EAQb,MAAM,SAAS,CAAC;AAIjB,wBAAgB,yBAAyB,IAAI,YAAY,CA4PxD"}
|
|
@@ -7,9 +7,9 @@ import { SqlCellContent } from './components/SqlCellContent';
|
|
|
7
7
|
import { TextCellContent } from './components/TextCellContent';
|
|
8
8
|
import { VegaCellContent } from './components/VegaCellContent';
|
|
9
9
|
import { executeSqlCell } from './execution';
|
|
10
|
-
import {
|
|
10
|
+
import { findArtifactIdForCell, resolveArtifactSchemaName } from './helpers';
|
|
11
11
|
import { dropResultRelation, renameResultRelation } from './resultRelationPolicy';
|
|
12
|
-
import { findSqlDependenciesFromAst,
|
|
12
|
+
import { findSqlDependenciesFromAst, qualifyArtifactLocalResultNames, renderSqlWithInputs, } from './sqlHelpers';
|
|
13
13
|
import { isInputCell, isSqlCell } from './types';
|
|
14
14
|
import { getEffectiveResultName, isDefined } from './utils';
|
|
15
15
|
export function createDefaultCellRegistry() {
|
|
@@ -73,9 +73,9 @@ export function createDefaultCellRegistry() {
|
|
|
73
73
|
return sqlStatus.resultView;
|
|
74
74
|
},
|
|
75
75
|
runCell: async ({ id, opts, get, set }) => {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
await get().cells.updateEdgesFromSql(
|
|
76
|
+
const ownerArtifactId = findArtifactIdForCell(get(), id);
|
|
77
|
+
if (ownerArtifactId) {
|
|
78
|
+
await get().cells.updateEdgesFromSql(ownerArtifactId, id);
|
|
79
79
|
}
|
|
80
80
|
const controller = new AbortController();
|
|
81
81
|
set((s) => produce(s, (draft) => {
|
|
@@ -98,9 +98,13 @@ export function createDefaultCellRegistry() {
|
|
|
98
98
|
const previousRelationType = (status?.type === 'sql'
|
|
99
99
|
? status.resultRelationType
|
|
100
100
|
: undefined) ?? 'view';
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
101
|
+
const artifactId = findArtifactIdForCell(state, id);
|
|
102
|
+
const artifact = artifactId
|
|
103
|
+
? state.cells.config.artifacts[artifactId]
|
|
104
|
+
: undefined;
|
|
105
|
+
const schemaName = artifact
|
|
106
|
+
? resolveArtifactSchemaName(artifact)
|
|
107
|
+
: 'main';
|
|
104
108
|
const effectiveResultName = getEffectiveResultName(cell.data, convertToValidColumnOrTableName);
|
|
105
109
|
const newTableName = makeQualifiedTableName({
|
|
106
110
|
table: effectiveResultName,
|
|
@@ -112,7 +116,7 @@ export function createDefaultCellRegistry() {
|
|
|
112
116
|
}
|
|
113
117
|
const connector = await state.db.getConnector();
|
|
114
118
|
const sql = cell.data.sql;
|
|
115
|
-
const scopedCellIds =
|
|
119
|
+
const scopedCellIds = artifact?.cellIds ?? Object.keys(state.cells.config.data);
|
|
116
120
|
const scopedCells = Object.fromEntries(scopedCellIds
|
|
117
121
|
.map((cellId) => state.cells.config.data[cellId])
|
|
118
122
|
.filter(isDefined)
|
|
@@ -124,10 +128,10 @@ export function createDefaultCellRegistry() {
|
|
|
124
128
|
value: c.data.input.value,
|
|
125
129
|
}));
|
|
126
130
|
const renderedSql = renderSqlWithInputs(sql, inputs);
|
|
127
|
-
const rewrittenSql =
|
|
131
|
+
const rewrittenSql = qualifyArtifactLocalResultNames({
|
|
128
132
|
sql: renderedSql,
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
artifactSchema: schemaName,
|
|
134
|
+
artifactCellIds: scopedCellIds,
|
|
131
135
|
cells: state.cells.config.data,
|
|
132
136
|
getSqlResultName: (cellId) => {
|
|
133
137
|
const c = state.cells.config.data[cellId];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultCellRegistry.js","sourceRoot":"","sources":["../src/defaultCellRegistry.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAC,+BAA+B,EAAC,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,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AC1B,UAAU,EAAE,CAAC,EAAC,EAAE,EAAC,EAAa,EAAE,CAAC,CAAC;gBAChC,EAAE;gBACF,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE;oBACJ,KAAK,EAAE,OAAO;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;wBAClC,KAAK,EAAE,EAAE;qBACV;iBACF;aACF,CAAC;YACF,UAAU,EAAE,CAAC,EAAC,EAAE,EAAE,IAAI,EAAE,eAAe,EAAC,EAAE,EAAE,CAAC,CAC3C,KAAC,gBAAgB,IACf,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAiB,EACvB,eAAe,EAAE,eAAe,GAChC,CACH;YACD,gBAAgB,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE;SACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {makeQualifiedTableName} from '@sqlrooms/duckdb';\nimport {convertToValidColumnOrTableName} from '@sqlrooms/utils';\nimport {produce} from 'immer';\nimport {InputCellContent} from './components/InputCellContent';\nimport {SqlCellContent} from './components/SqlCellContent';\nimport {TextCellContent} from './components/TextCellContent';\nimport {VegaCellContent} from './components/VegaCellContent';\nimport {executeSqlCell} from './execution';\nimport {findSheetIdForCell, resolveSheetSchemaName} from './helpers';\nimport {dropResultRelation, renameResultRelation} from './resultRelationPolicy';\nimport {\n findSqlDependenciesFromAst,\n qualifySheetLocalResultNames,\n renderSqlWithInputs,\n} from './sqlHelpers';\nimport type {\n Cell,\n CellRegistry,\n CellStatus,\n InputCell,\n SqlCell,\n SqlCellData,\n SqlCellStatus,\n TextCell,\n VegaCell,\n} from './types';\nimport {isInputCell, isSqlCell} from './types';\nimport {getEffectiveResultName, isDefined} from './utils';\n\nexport function createDefaultCellRegistry(): CellRegistry {\n return {\n sql: {\n type: 'sql',\n title: 'SQL Query',\n createCell: ({id}): SqlCell => ({\n id,\n type: 'sql',\n data: {title: 'Untitled Query', sql: ''},\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <SqlCellContent\n id={id}\n cell={cell as SqlCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async ({cell, cells, sqlSelectToJson}) => {\n return findSqlDependenciesFromAst({\n sql: (cell as SqlCell).data.sql,\n cells,\n sqlSelectToJson,\n });\n },\n createStatus: (): CellStatus => ({\n type: 'sql',\n status: 'idle',\n referencedTables: [],\n }),\n onRemove: async ({status, get}) => {\n if (status?.type === 'sql' && (status as SqlCellStatus).resultView) {\n try {\n const connector = await get().db.getConnector();\n await dropResultRelation({\n connector,\n relationName: (status as SqlCellStatus).resultView,\n });\n } catch {\n // best-effort\n }\n }\n },\n hasSemanticChange: (oldCell, newCell) => {\n const oldSql = isSqlCell(oldCell) ? oldCell.data.sql : undefined;\n const newSql = isSqlCell(newCell) ? newCell.data.sql : undefined;\n return oldSql !== newSql;\n },\n invalidateStatus: (currentStatus): CellStatus => ({\n type: 'sql',\n status: 'idle',\n referencedTables:\n (currentStatus as SqlCellStatus).referencedTables || [],\n }),\n getRelationsToDrop: (status): string[] => {\n const sqlStatus = status as SqlCellStatus;\n return sqlStatus.resultView ? [sqlStatus.resultView] : [];\n },\n recordError: (currentStatus, message): CellStatus => ({\n ...currentStatus,\n status: 'error',\n lastError: message,\n }),\n getResultRelation: (status): string | undefined => {\n const sqlStatus = status as SqlCellStatus;\n return sqlStatus.resultView;\n },\n runCell: async ({id, opts, get, set}) => {\n const ownerSheetId = findSheetIdForCell(get(), id);\n if (ownerSheetId) {\n await get().cells.updateEdgesFromSql(ownerSheetId, id);\n }\n\n const controller = new AbortController();\n set((s) =>\n produce(s, (draft) => {\n draft.cells.activeAbortControllers[id] = controller;\n }),\n );\n\n await executeSqlCell(id, get, set, {\n schemaName: opts?.schemaName || 'main',\n cascade: opts?.cascade,\n signal: controller.signal,\n setCellResult: get().cells.setCellResult,\n });\n\n void get().db.refreshTableSchemas();\n },\n renameResult: async ({id, oldResultView, get, set}) => {\n const state = get();\n const cell = state.cells.config.data[id];\n if (!cell || cell.type !== 'sql') return;\n const status = state.cells.status[id];\n const previousRelationType =\n (status?.type === 'sql'\n ? (status as SqlCellStatus).resultRelationType\n : undefined) ?? 'view';\n\n const sheetId = findSheetIdForCell(state, id);\n const sheet = sheetId ? state.cells.config.sheets[sheetId] : undefined;\n const schemaName = sheet ? resolveSheetSchemaName(sheet) : 'main';\n\n const effectiveResultName = getEffectiveResultName(\n cell.data as SqlCellData,\n convertToValidColumnOrTableName,\n );\n const newTableName = makeQualifiedTableName({\n table: effectiveResultName,\n schema: schemaName,\n database: state.db.currentDatabase,\n }).toString();\n\n if (newTableName === oldResultView) {\n return;\n }\n\n const connector = await state.db.getConnector();\n const sql = (cell.data as SqlCellData).sql;\n const scopedCellIds =\n sheet?.cellIds ?? Object.keys(state.cells.config.data);\n const scopedCells = Object.fromEntries(\n scopedCellIds\n .map((cellId) => state.cells.config.data[cellId])\n .filter(isDefined)\n .map((candidate) => [candidate.id, candidate]),\n ) as Record<string, Cell>;\n\n const inputs = Object.values(scopedCells)\n .filter((c) => isInputCell(c))\n .map((c) => ({\n varName: c.data.input.varName,\n value: c.data.input.value as string | number,\n }));\n const renderedSql = renderSqlWithInputs(sql, inputs);\n const rewrittenSql = qualifySheetLocalResultNames({\n sql: renderedSql,\n sheetSchema: schemaName,\n sheetCellIds: scopedCellIds,\n cells: state.cells.config.data,\n getSqlResultName: (cellId) => {\n const c = state.cells.config.data[cellId];\n if (c?.type === 'sql') {\n return getEffectiveResultName(\n c.data as SqlCellData,\n convertToValidColumnOrTableName,\n );\n }\n return undefined;\n },\n });\n\n await renameResultRelation({\n connector,\n oldRelationName: oldResultView,\n newRelationName: newTableName,\n relationType: previousRelationType,\n viewSql: rewrittenSql,\n });\n\n set((s) =>\n produce(s, (draft) => {\n const draftStatus = draft.cells.status[id];\n if (draftStatus?.type === 'sql') {\n (draftStatus as SqlCellStatus).resultName = newTableName;\n (draftStatus as SqlCellStatus).resultView = newTableName;\n (draftStatus as SqlCellStatus).resultRelationType =\n previousRelationType;\n }\n }),\n );\n\n void get().db.refreshTableSchemas();\n },\n },\n text: {\n type: 'text',\n title: 'Text / Markdown',\n createCell: ({id}): TextCell => ({\n id,\n type: 'text',\n data: {title: 'Text', text: ''},\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <TextCellContent\n id={id}\n cell={cell as TextCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async () => [],\n },\n vega: {\n type: 'vega',\n title: 'Visualization',\n createCell: ({id}): VegaCell => ({\n id,\n type: 'vega',\n data: {\n title: 'Chart',\n crossFilter: {enabled: true},\n vegaSpec: {\n data: {name: 'queryResult'},\n mark: 'bar',\n padding: 20,\n },\n },\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <VegaCellContent\n id={id}\n cell={cell as VegaCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async ({cell}) => {\n const sqlId = (cell as VegaCell).data.sqlId;\n const tableRef = (cell as VegaCell).data.tableRef;\n return {\n cellIds: sqlId ? [sqlId] : [],\n tableNames: tableRef ? [tableRef] : [],\n };\n },\n },\n input: {\n type: 'input',\n title: 'Input / Parameter',\n createCell: ({id}): InputCell => ({\n id,\n type: 'input',\n data: {\n title: 'Input',\n input: {\n kind: 'text',\n varName: `param_${id.slice(0, 4)}`,\n value: '',\n },\n },\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <InputCellContent\n id={id}\n cell={cell as InputCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async () => [],\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"defaultCellRegistry.js","sourceRoot":"","sources":["../src/defaultCellRegistry.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAC,+BAA+B,EAAC,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,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;QACD,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,mBAAmB;YAC1B,UAAU,EAAE,CAAC,EAAC,EAAE,EAAC,EAAa,EAAE,CAAC,CAAC;gBAChC,EAAE;gBACF,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE;oBACJ,KAAK,EAAE,OAAO;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;wBAClC,KAAK,EAAE,EAAE;qBACV;iBACF;aACF,CAAC;YACF,UAAU,EAAE,CAAC,EAAC,EAAE,EAAE,IAAI,EAAE,eAAe,EAAC,EAAE,EAAE,CAAC,CAC3C,KAAC,gBAAgB,IACf,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAiB,EACvB,eAAe,EAAE,eAAe,GAChC,CACH;YACD,gBAAgB,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE;SACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {makeQualifiedTableName} from '@sqlrooms/duckdb';\nimport {convertToValidColumnOrTableName} from '@sqlrooms/utils';\nimport {produce} from 'immer';\nimport {InputCellContent} from './components/InputCellContent';\nimport {SqlCellContent} from './components/SqlCellContent';\nimport {TextCellContent} from './components/TextCellContent';\nimport {VegaCellContent} from './components/VegaCellContent';\nimport {executeSqlCell} from './execution';\nimport {findArtifactIdForCell, resolveArtifactSchemaName} from './helpers';\nimport {dropResultRelation, renameResultRelation} from './resultRelationPolicy';\nimport {\n findSqlDependenciesFromAst,\n qualifyArtifactLocalResultNames,\n renderSqlWithInputs,\n} from './sqlHelpers';\nimport type {\n Cell,\n CellRegistry,\n CellStatus,\n InputCell,\n SqlCell,\n SqlCellData,\n SqlCellStatus,\n TextCell,\n VegaCell,\n} from './types';\nimport {isInputCell, isSqlCell} from './types';\nimport {getEffectiveResultName, isDefined} from './utils';\n\nexport function createDefaultCellRegistry(): CellRegistry {\n return {\n sql: {\n type: 'sql',\n title: 'SQL Query',\n createCell: ({id}): SqlCell => ({\n id,\n type: 'sql',\n data: {title: 'Untitled Query', sql: ''},\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <SqlCellContent\n id={id}\n cell={cell as SqlCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async ({cell, cells, sqlSelectToJson}) => {\n return findSqlDependenciesFromAst({\n sql: (cell as SqlCell).data.sql,\n cells,\n sqlSelectToJson,\n });\n },\n createStatus: (): CellStatus => ({\n type: 'sql',\n status: 'idle',\n referencedTables: [],\n }),\n onRemove: async ({status, get}) => {\n if (status?.type === 'sql' && (status as SqlCellStatus).resultView) {\n try {\n const connector = await get().db.getConnector();\n await dropResultRelation({\n connector,\n relationName: (status as SqlCellStatus).resultView,\n });\n } catch {\n // best-effort\n }\n }\n },\n hasSemanticChange: (oldCell, newCell) => {\n const oldSql = isSqlCell(oldCell) ? oldCell.data.sql : undefined;\n const newSql = isSqlCell(newCell) ? newCell.data.sql : undefined;\n return oldSql !== newSql;\n },\n invalidateStatus: (currentStatus): CellStatus => ({\n type: 'sql',\n status: 'idle',\n referencedTables:\n (currentStatus as SqlCellStatus).referencedTables || [],\n }),\n getRelationsToDrop: (status): string[] => {\n const sqlStatus = status as SqlCellStatus;\n return sqlStatus.resultView ? [sqlStatus.resultView] : [];\n },\n recordError: (currentStatus, message): CellStatus => ({\n ...currentStatus,\n status: 'error',\n lastError: message,\n }),\n getResultRelation: (status): string | undefined => {\n const sqlStatus = status as SqlCellStatus;\n return sqlStatus.resultView;\n },\n runCell: async ({id, opts, get, set}) => {\n const ownerArtifactId = findArtifactIdForCell(get(), id);\n if (ownerArtifactId) {\n await get().cells.updateEdgesFromSql(ownerArtifactId, id);\n }\n\n const controller = new AbortController();\n set((s) =>\n produce(s, (draft) => {\n draft.cells.activeAbortControllers[id] = controller;\n }),\n );\n\n await executeSqlCell(id, get, set, {\n schemaName: opts?.schemaName || 'main',\n cascade: opts?.cascade,\n signal: controller.signal,\n setCellResult: get().cells.setCellResult,\n });\n\n void get().db.refreshTableSchemas();\n },\n renameResult: async ({id, oldResultView, get, set}) => {\n const state = get();\n const cell = state.cells.config.data[id];\n if (!cell || cell.type !== 'sql') return;\n const status = state.cells.status[id];\n const previousRelationType =\n (status?.type === 'sql'\n ? (status as SqlCellStatus).resultRelationType\n : undefined) ?? 'view';\n\n const artifactId = findArtifactIdForCell(state, id);\n const artifact = artifactId\n ? state.cells.config.artifacts[artifactId]\n : undefined;\n const schemaName = artifact\n ? resolveArtifactSchemaName(artifact)\n : 'main';\n\n const effectiveResultName = getEffectiveResultName(\n cell.data as SqlCellData,\n convertToValidColumnOrTableName,\n );\n const newTableName = makeQualifiedTableName({\n table: effectiveResultName,\n schema: schemaName,\n database: state.db.currentDatabase,\n }).toString();\n\n if (newTableName === oldResultView) {\n return;\n }\n\n const connector = await state.db.getConnector();\n const sql = (cell.data as SqlCellData).sql;\n const scopedCellIds =\n artifact?.cellIds ?? Object.keys(state.cells.config.data);\n const scopedCells = Object.fromEntries(\n scopedCellIds\n .map((cellId) => state.cells.config.data[cellId])\n .filter(isDefined)\n .map((candidate) => [candidate.id, candidate]),\n ) as Record<string, Cell>;\n\n const inputs = Object.values(scopedCells)\n .filter((c) => isInputCell(c))\n .map((c) => ({\n varName: c.data.input.varName,\n value: c.data.input.value as string | number,\n }));\n const renderedSql = renderSqlWithInputs(sql, inputs);\n const rewrittenSql = qualifyArtifactLocalResultNames({\n sql: renderedSql,\n artifactSchema: schemaName,\n artifactCellIds: scopedCellIds,\n cells: state.cells.config.data,\n getSqlResultName: (cellId) => {\n const c = state.cells.config.data[cellId];\n if (c?.type === 'sql') {\n return getEffectiveResultName(\n c.data as SqlCellData,\n convertToValidColumnOrTableName,\n );\n }\n return undefined;\n },\n });\n\n await renameResultRelation({\n connector,\n oldRelationName: oldResultView,\n newRelationName: newTableName,\n relationType: previousRelationType,\n viewSql: rewrittenSql,\n });\n\n set((s) =>\n produce(s, (draft) => {\n const draftStatus = draft.cells.status[id];\n if (draftStatus?.type === 'sql') {\n (draftStatus as SqlCellStatus).resultName = newTableName;\n (draftStatus as SqlCellStatus).resultView = newTableName;\n (draftStatus as SqlCellStatus).resultRelationType =\n previousRelationType;\n }\n }),\n );\n\n void get().db.refreshTableSchemas();\n },\n },\n text: {\n type: 'text',\n title: 'Text / Markdown',\n createCell: ({id}): TextCell => ({\n id,\n type: 'text',\n data: {title: 'Text', text: ''},\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <TextCellContent\n id={id}\n cell={cell as TextCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async () => [],\n },\n vega: {\n type: 'vega',\n title: 'Visualization',\n createCell: ({id}): VegaCell => ({\n id,\n type: 'vega',\n data: {\n title: 'Chart',\n crossFilter: {enabled: true},\n vegaSpec: {\n data: {name: 'queryResult'},\n mark: 'bar',\n padding: 20,\n },\n },\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <VegaCellContent\n id={id}\n cell={cell as VegaCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async ({cell}) => {\n const sqlId = (cell as VegaCell).data.sqlId;\n const tableRef = (cell as VegaCell).data.tableRef;\n return {\n cellIds: sqlId ? [sqlId] : [],\n tableNames: tableRef ? [tableRef] : [],\n };\n },\n },\n input: {\n type: 'input',\n title: 'Input / Parameter',\n createCell: ({id}): InputCell => ({\n id,\n type: 'input',\n data: {\n title: 'Input',\n input: {\n kind: 'text',\n varName: `param_${id.slice(0, 4)}`,\n value: '',\n },\n },\n }),\n renderCell: ({id, cell, renderContainer}) => (\n <InputCellContent\n id={id}\n cell={cell as InputCell}\n renderContainer={renderContainer}\n />\n ),\n findDependencies: async () => [],\n },\n };\n}\n"]}
|
package/dist/execution.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAkBA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EAGpB,MAAM,SAAS,CAAC;AAKjB,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5D,CAAC;AAEF,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,cAAc,EAC9B,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,cAAc,KAAK,IAAI,EACjE,OAAO,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAkBA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EAGpB,MAAM,SAAS,CAAC;AAKjB,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5D,CAAC;AAEF,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,cAAc,EAC9B,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,cAAc,KAAK,IAAI,EACjE,OAAO,EAAE,qBAAqB,iBA0O/B"}
|
package/dist/execution.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { escapeId, makeQualifiedTableName } from '@sqlrooms/duckdb';
|
|
2
2
|
import { convertToValidColumnOrTableName } from '@sqlrooms/utils';
|
|
3
3
|
import { produce } from 'immer';
|
|
4
|
-
import {
|
|
5
|
-
import { findSqlDependencies,
|
|
4
|
+
import { findArtifactIdForCell, getUnqualifiedSqlIdentifier, resolveArtifactSchemaName, } from './helpers';
|
|
5
|
+
import { findSqlDependencies, qualifyArtifactLocalResultNames, renderSqlWithInputs, } from './sqlHelpers';
|
|
6
6
|
import { chooseAdaptiveRelationType, createOrReplaceResultRelation, } from './resultRelationPolicy';
|
|
7
7
|
import { isInputCell, isSqlCell, } from './types';
|
|
8
8
|
import { getEffectiveResultName, isDefined } from './utils';
|
|
@@ -20,15 +20,21 @@ export async function executeSqlCell(cellId, getState, set, options) {
|
|
|
20
20
|
: undefined;
|
|
21
21
|
const { schemaName, cascade = true, signal, setCellResult } = options;
|
|
22
22
|
const sqlRaw = cell.data.sql || '';
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
const artifactId = findArtifactIdForCell(state, cellId);
|
|
24
|
+
const artifact = artifactId
|
|
25
|
+
? state.cells.config.artifacts[artifactId]
|
|
26
|
+
: undefined;
|
|
27
|
+
const finalSchemaName = artifact
|
|
28
|
+
? resolveArtifactSchemaName(artifact)
|
|
29
|
+
: schemaName;
|
|
26
30
|
const finalDatabaseName = state.db.config.coreMaterialization.strategy === 'attached_ephemeral'
|
|
27
31
|
? state.db.config.coreMaterialization.attachedDatabaseName
|
|
28
32
|
: undefined;
|
|
29
|
-
const
|
|
33
|
+
const artifactCellIds = artifact?.cellIds ?? [];
|
|
30
34
|
// 1. Gather inputs for SQL rendering
|
|
31
|
-
const cellsInScope = (
|
|
35
|
+
const cellsInScope = (artifactCellIds.length
|
|
36
|
+
? artifactCellIds
|
|
37
|
+
: Object.keys(state.cells.config.data))
|
|
32
38
|
.map((id) => state.cells.config.data[id])
|
|
33
39
|
.filter(isDefined);
|
|
34
40
|
const inputs = cellsInScope
|
|
@@ -38,11 +44,11 @@ export async function executeSqlCell(cellId, getState, set, options) {
|
|
|
38
44
|
value: c.data.input.value,
|
|
39
45
|
}));
|
|
40
46
|
const renderedSql = renderSqlWithInputs(sqlRaw, inputs);
|
|
41
|
-
const sql =
|
|
47
|
+
const sql = qualifyArtifactLocalResultNames({
|
|
42
48
|
sql: renderedSql,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
artifactSchema: finalSchemaName,
|
|
50
|
+
artifactDatabase: finalDatabaseName,
|
|
51
|
+
artifactCellIds,
|
|
46
52
|
cells: state.cells.config.data,
|
|
47
53
|
getSqlResultName: (id) => {
|
|
48
54
|
const target = state.cells.config.data[id];
|
|
@@ -110,8 +116,8 @@ export async function executeSqlCell(cellId, getState, set, options) {
|
|
|
110
116
|
// - first run: choose table when there are downstream dependents,
|
|
111
117
|
// otherwise keep a lightweight view.
|
|
112
118
|
// - subsequent runs: preserve the previously selected relation type.
|
|
113
|
-
const hasDownstream = Boolean(
|
|
114
|
-
getState().cells.getDownstream(
|
|
119
|
+
const hasDownstream = Boolean(artifactId) &&
|
|
120
|
+
getState().cells.getDownstream(artifactId, cellId).length > 0;
|
|
115
121
|
relationType = chooseAdaptiveRelationType({
|
|
116
122
|
previousRelationType: previousStatus?.resultRelationType,
|
|
117
123
|
hasDownstream,
|
|
@@ -171,9 +177,9 @@ export async function executeSqlCell(cellId, getState, set, options) {
|
|
|
171
177
|
}
|
|
172
178
|
// 5. Cascade if needed
|
|
173
179
|
if (cascade) {
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
176
|
-
await state.cells.runDownstreamCascade(
|
|
180
|
+
const ownerArtifactId = findArtifactIdForCell(getState(), cellId);
|
|
181
|
+
if (ownerArtifactId) {
|
|
182
|
+
await state.cells.runDownstreamCascade(ownerArtifactId, cellId);
|
|
177
183
|
}
|
|
178
184
|
}
|
|
179
185
|
}
|