@dxos/plugin-script 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/DeploymentDialog-5TKNGPVR.mjs +14 -0
- package/dist/lib/browser/NotebookContainer-MHY3DXDE.mjs +817 -0
- package/dist/lib/browser/NotebookContainer-MHY3DXDE.mjs.map +7 -0
- package/dist/lib/browser/ScriptContainer-CW6YN3DQ.mjs +148 -0
- package/dist/lib/browser/ScriptContainer-CW6YN3DQ.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-IABOSTBK.mjs → app-graph-builder-2WR2ATTJ.mjs} +11 -9
- package/dist/lib/browser/app-graph-builder-2WR2ATTJ.mjs.map +7 -0
- package/dist/lib/browser/{blueprint-definition-AR7ITBCD.mjs → blueprint-definition-6PZWZM2Y.mjs} +5 -3
- package/dist/lib/{node-esm/blueprint-definition-TJY4TX6S.mjs.map → browser/blueprint-definition-6PZWZM2Y.mjs.map} +1 -1
- package/dist/lib/browser/chunk-2G2NA6DQ.mjs +88 -0
- package/dist/lib/browser/chunk-2G2NA6DQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-ALS6X4HU.mjs +304 -0
- package/dist/lib/browser/chunk-ALS6X4HU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-QYAREHGH.mjs → chunk-EB6AXFXO.mjs} +8 -5
- package/dist/lib/browser/chunk-EB6AXFXO.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-M6KJPUJK.mjs +111 -0
- package/dist/lib/browser/chunk-M6KJPUJK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-TH7GXPE3.mjs → chunk-N5EYLQOT.mjs} +150 -59
- package/dist/lib/browser/chunk-N5EYLQOT.mjs.map +7 -0
- package/dist/lib/browser/chunk-QIZ3BPRK.mjs +103 -0
- package/dist/lib/browser/chunk-QIZ3BPRK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-YCZPTTFO.mjs → chunk-SAN5Y7FI.mjs} +23 -21
- package/dist/lib/browser/chunk-SAN5Y7FI.mjs.map +7 -0
- package/dist/lib/browser/chunk-ULJFT73Q.mjs +513 -0
- package/dist/lib/browser/chunk-ULJFT73Q.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5TVBECWH.mjs → chunk-UOQ6NCH3.mjs} +2 -2
- package/dist/lib/browser/{compiler-2HJH34GM.mjs → compiler-4KHRSX7J.mjs} +13 -25
- package/dist/lib/browser/compiler-4KHRSX7J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +108 -50
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-YMK5SXVC.mjs → intent-resolver-TXTBWOVD.mjs} +38 -23
- package/dist/lib/browser/intent-resolver-TXTBWOVD.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-FEM5WWFH.mjs → react-surface-R245YN52.mjs} +45 -21
- package/dist/lib/browser/react-surface-R245YN52.mjs.map +7 -0
- package/dist/lib/browser/{settings-KCTBK5TY.mjs → settings-MHJXRGDF.mjs} +10 -8
- package/dist/lib/browser/settings-MHJXRGDF.mjs.map +7 -0
- package/dist/lib/browser/templates/index.mjs +2 -1
- package/dist/lib/browser/types/index.mjs +8 -4
- package/dist/lib/node-esm/DeploymentDialog-2ULNOZQH.mjs +15 -0
- package/dist/lib/node-esm/DeploymentDialog-2ULNOZQH.mjs.map +7 -0
- package/dist/lib/node-esm/NotebookContainer-U4C2HQ4T.mjs +818 -0
- package/dist/lib/node-esm/NotebookContainer-U4C2HQ4T.mjs.map +7 -0
- package/dist/lib/node-esm/ScriptContainer-VRPEKB4T.mjs +149 -0
- package/dist/lib/node-esm/ScriptContainer-VRPEKB4T.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-CQTTAYHP.mjs → app-graph-builder-NCVLUL5R.mjs} +11 -9
- package/dist/lib/node-esm/app-graph-builder-NCVLUL5R.mjs.map +7 -0
- package/dist/lib/node-esm/{blueprint-definition-TJY4TX6S.mjs → blueprint-definition-5R6YCSZZ.mjs} +4 -3
- package/dist/lib/{browser/blueprint-definition-AR7ITBCD.mjs.map → node-esm/blueprint-definition-5R6YCSZZ.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-35M3CHYE.mjs → chunk-55JZVM6K.mjs} +2 -2
- package/dist/lib/node-esm/chunk-57JA6XL5.mjs +90 -0
- package/dist/lib/node-esm/chunk-57JA6XL5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HDKR5WCD.mjs +113 -0
- package/dist/lib/node-esm/chunk-HDKR5WCD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-AHXJ6NQU.mjs → chunk-IBV2DR36.mjs} +8 -5
- package/dist/lib/node-esm/chunk-IBV2DR36.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZA36GO4T.mjs → chunk-ND4BPYPR.mjs} +23 -21
- package/dist/lib/node-esm/chunk-ND4BPYPR.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-6M2R2FQF.mjs → chunk-UEVZP5DN.mjs} +150 -59
- package/dist/lib/node-esm/chunk-UEVZP5DN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VJSRZRLI.mjs +514 -0
- package/dist/lib/node-esm/chunk-VJSRZRLI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VTRMJSQL.mjs +305 -0
- package/dist/lib/node-esm/chunk-VTRMJSQL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XYKKDWUR.mjs +104 -0
- package/dist/lib/node-esm/chunk-XYKKDWUR.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-7SP27RA6.mjs → compiler-DU5NQISX.mjs} +13 -25
- package/dist/lib/node-esm/compiler-DU5NQISX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +108 -50
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-SKRDYQCZ.mjs → intent-resolver-D6AVAQRA.mjs} +38 -23
- package/dist/lib/node-esm/intent-resolver-D6AVAQRA.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-AOKMDJR4.mjs → react-surface-MHT3PJ6C.mjs} +45 -21
- package/dist/lib/node-esm/react-surface-MHT3PJ6C.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-DXZ334A3.mjs → settings-BVJORMMJ.mjs} +10 -8
- package/dist/lib/node-esm/settings-BVJORMMJ.mjs.map +7 -0
- package/dist/lib/node-esm/templates/index.mjs +2 -1
- package/dist/lib/node-esm/types/index.mjs +8 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -1
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +3 -3
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +113 -7
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/NotebookContainer.d.ts +10 -0
- package/dist/types/src/components/NotebookContainer.d.ts.map +1 -0
- package/dist/types/src/components/NotebookContainer.stories.d.ts +254 -0
- package/dist/types/src/components/NotebookContainer.stories.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +15 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts +9 -0
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +14 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +248 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/index.d.ts +3 -0
- package/dist/types/src/components/NotebookStack/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptContainer.d.ts +4 -4
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +5 -6
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +240 -2
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts +2 -2
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts +2 -2
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestContainer.d.ts +2 -2
- package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +3 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +14 -12
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +2 -2
- package/dist/types/src/hooks/format.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts +4 -14
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/notebook/compute-graph.d.ts +45 -0
- package/dist/types/src/notebook/compute-graph.d.ts.map +1 -0
- package/dist/types/src/notebook/compute-graph.test.d.ts +2 -0
- package/dist/types/src/notebook/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/notebook/eval.d.ts +13 -0
- package/dist/types/src/notebook/eval.d.ts.map +1 -0
- package/dist/types/src/notebook/index.d.ts +2 -0
- package/dist/types/src/notebook/index.d.ts.map +1 -0
- package/dist/types/src/notebook/vfs-parser.d.ts +74 -0
- package/dist/types/src/notebook/vfs-parser.d.ts.map +1 -0
- package/dist/types/src/notebook/vfs-parser.test.d.ts +2 -0
- package/dist/types/src/notebook/vfs-parser.test.d.ts.map +1 -0
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/data-generator.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/templates/gmail.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +43 -1
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/templates/{echo.d.ts → ping.d.ts} +1 -1
- package/dist/types/src/templates/ping.d.ts.map +1 -0
- package/dist/types/src/testing/data.d.ts +3 -0
- package/dist/types/src/testing/data.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +31 -5
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Notebook.d.ts +31 -0
- package/dist/types/src/types/Notebook.d.ts.map +1 -0
- package/dist/types/src/types/actions.d.ts +54 -0
- package/dist/types/src/types/actions.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +6 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/util/deploy.d.ts +4 -4
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts +6 -3
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +79 -69
- package/src/ScriptPlugin.tsx +79 -73
- package/src/capabilities/app-graph-builder.ts +10 -9
- package/src/capabilities/artifact-definition.ts +2 -3
- package/src/capabilities/compiler.ts +1 -1
- package/src/capabilities/intent-resolver.ts +20 -11
- package/src/capabilities/react-surface.tsx +30 -17
- package/src/capabilities/settings.ts +3 -3
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +13 -6
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +41 -30
- package/src/components/FrameContainer/FrameContainer.tsx +2 -2
- package/src/components/NotebookContainer.stories.tsx +83 -0
- package/src/components/NotebookContainer.tsx +260 -0
- package/src/components/NotebookStack/NotebookCell.tsx +216 -0
- package/src/components/NotebookStack/NotebookMenu.tsx +47 -0
- package/src/components/NotebookStack/NotebookStack.stories.tsx +54 -0
- package/src/components/NotebookStack/NotebookStack.tsx +86 -0
- package/src/components/NotebookStack/index.ts +6 -0
- package/src/components/ScriptContainer.tsx +8 -7
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +22 -10
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +30 -33
- package/src/components/Settings/ScriptObjectSettings.tsx +115 -19
- package/src/components/Settings/ScriptPluginSettings.tsx +4 -19
- package/src/components/TestPanel/TestContainer.tsx +2 -2
- package/src/components/TestPanel/TestPanel.tsx +42 -19
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +71 -16
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +36 -35
- package/src/components/index.ts +3 -0
- package/src/events.ts +2 -2
- package/src/hooks/deploy.ts +17 -17
- package/src/hooks/format.ts +4 -4
- package/src/hooks/template.ts +6 -15
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +10 -6
- package/src/index.ts +1 -0
- package/src/meta.ts +7 -5
- package/src/notebook/compute-graph.test.ts +70 -0
- package/src/notebook/compute-graph.ts +206 -0
- package/src/notebook/eval.ts +105 -0
- package/src/notebook/index.ts +5 -0
- package/src/notebook/vfs-parser.test.ts +149 -0
- package/src/notebook/vfs-parser.ts +451 -0
- package/src/templates/chess.ts +2 -0
- package/src/templates/data-generator.ts +2 -0
- package/src/templates/discord.ts +9 -1
- package/src/templates/forex-effect.ts +5 -1
- package/src/templates/forex.ts +2 -0
- package/src/templates/gmail.ts +22 -11
- package/src/templates/index.ts +6 -6
- package/src/testing/data.ts +72 -0
- package/src/testing/index.ts +5 -0
- package/src/translations.ts +34 -7
- package/src/types/Notebook.ts +42 -0
- package/src/types/actions.ts +53 -0
- package/src/types/index.ts +3 -1
- package/src/types/types.ts +15 -0
- package/src/util/deploy.ts +14 -18
- package/src/util/functions.ts +37 -6
- package/dist/lib/browser/DeploymentDialog-QZSTVNIS.mjs +0 -12
- package/dist/lib/browser/ScriptContainer-JUPCBUCP.mjs +0 -263
- package/dist/lib/browser/ScriptContainer-JUPCBUCP.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-IABOSTBK.mjs.map +0 -7
- package/dist/lib/browser/chunk-6CAH7VIE.mjs +0 -283
- package/dist/lib/browser/chunk-6CAH7VIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-IS4OG2UW.mjs +0 -39
- package/dist/lib/browser/chunk-IS4OG2UW.mjs.map +0 -7
- package/dist/lib/browser/chunk-NXKU3BNX.mjs +0 -222
- package/dist/lib/browser/chunk-NXKU3BNX.mjs.map +0 -7
- package/dist/lib/browser/chunk-QYAREHGH.mjs.map +0 -7
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs +0 -88
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-TH7GXPE3.mjs.map +0 -7
- package/dist/lib/browser/chunk-YCZPTTFO.mjs.map +0 -7
- package/dist/lib/browser/compiler-2HJH34GM.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YMK5SXVC.mjs.map +0 -7
- package/dist/lib/browser/react-surface-FEM5WWFH.mjs.map +0 -7
- package/dist/lib/browser/settings-KCTBK5TY.mjs.map +0 -7
- package/dist/lib/node-esm/DeploymentDialog-G6EHEPXN.mjs +0 -13
- package/dist/lib/node-esm/ScriptContainer-UXZUDQF6.mjs +0 -264
- package/dist/lib/node-esm/ScriptContainer-UXZUDQF6.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-CQTTAYHP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2GBESIHU.mjs +0 -284
- package/dist/lib/node-esm/chunk-2GBESIHU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6M2R2FQF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AHXJ6NQU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs +0 -90
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs +0 -40
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-M642JUOZ.mjs +0 -223
- package/dist/lib/node-esm/chunk-M642JUOZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZA36GO4T.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-7SP27RA6.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-SKRDYQCZ.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-AOKMDJR4.mjs.map +0 -7
- package/dist/lib/node-esm/settings-DXZ334A3.mjs.map +0 -7
- package/dist/types/src/templates/echo.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -38
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/types/schema.ts +0 -37
- /package/dist/lib/browser/{DeploymentDialog-QZSTVNIS.mjs.map → DeploymentDialog-5TKNGPVR.mjs.map} +0 -0
- /package/dist/lib/{node-esm/DeploymentDialog-G6EHEPXN.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-5TVBECWH.mjs.map → chunk-UOQ6NCH3.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-35M3CHYE.mjs.map → chunk-55JZVM6K.mjs.map} +0 -0
- /package/src/templates/{echo.ts → ping.ts} +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { NotebookVirtualParser, VirtualTypeScriptParser } from './vfs-parser';
|
|
8
|
+
|
|
9
|
+
describe('vfs-parser', () => {
|
|
10
|
+
test('parse simple assignments', () => {
|
|
11
|
+
const parser = new VirtualTypeScriptParser();
|
|
12
|
+
|
|
13
|
+
const tests = [
|
|
14
|
+
{
|
|
15
|
+
input: 'const a = 1',
|
|
16
|
+
expected: {
|
|
17
|
+
name: 'a',
|
|
18
|
+
type: 'variable',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
input: 'a = 1',
|
|
23
|
+
expected: {
|
|
24
|
+
name: 'a',
|
|
25
|
+
type: 'variable',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
tests.forEach(({ input, expected }) => {
|
|
31
|
+
const result = parser.parseExpression(input);
|
|
32
|
+
expect(result, input).toMatchObject(expected);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('parse variable with references', () => {
|
|
37
|
+
const parser = new VirtualTypeScriptParser();
|
|
38
|
+
|
|
39
|
+
const tests = [
|
|
40
|
+
{
|
|
41
|
+
input: 'const y = x * 2',
|
|
42
|
+
expected: {
|
|
43
|
+
name: 'y',
|
|
44
|
+
type: 'variable',
|
|
45
|
+
references: ['x'],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
input: 'y = x * 2',
|
|
50
|
+
expected: {
|
|
51
|
+
name: 'y',
|
|
52
|
+
type: 'variable',
|
|
53
|
+
references: ['x'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
tests.forEach(({ input, expected }) => {
|
|
59
|
+
const result = parser.parseExpression(input);
|
|
60
|
+
expect(result, input).toMatchObject(expected);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('parse simple expression with references', () => {
|
|
65
|
+
const parser = new VirtualTypeScriptParser();
|
|
66
|
+
|
|
67
|
+
const result = parser.parseExpression('(a + b) * c');
|
|
68
|
+
expect(result).toMatchObject({
|
|
69
|
+
references: ['a', 'b', 'c'],
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('parse single expression', () => {
|
|
74
|
+
const parser = new VirtualTypeScriptParser();
|
|
75
|
+
|
|
76
|
+
const result = parser.parseExpression('const add = (a: number, b: number): number => a + b;');
|
|
77
|
+
expect(result).toMatchObject({
|
|
78
|
+
name: 'add',
|
|
79
|
+
type: 'function',
|
|
80
|
+
valueType: expect.stringContaining('(a: number, b: number) => number'),
|
|
81
|
+
returnType: 'number',
|
|
82
|
+
parameters: [
|
|
83
|
+
{ name: 'a', type: 'number' },
|
|
84
|
+
{ name: 'b', type: 'number' },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('analyze multiple files', () => {
|
|
90
|
+
const parser = new VirtualTypeScriptParser();
|
|
91
|
+
|
|
92
|
+
const files = [
|
|
93
|
+
{
|
|
94
|
+
filename: '/test.ts',
|
|
95
|
+
content: 'export const PI = 3.14159;\nexport function square(x: number): number { return x * x; }',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
const results = parser.analyzeFiles(files);
|
|
100
|
+
expect(results).toHaveLength(2);
|
|
101
|
+
expect(results[0]).toMatchObject({
|
|
102
|
+
name: 'PI',
|
|
103
|
+
type: 'variable',
|
|
104
|
+
valueType: '3.14159',
|
|
105
|
+
});
|
|
106
|
+
expect(results[1]).toMatchObject({
|
|
107
|
+
name: 'square',
|
|
108
|
+
type: 'function',
|
|
109
|
+
returnType: 'number',
|
|
110
|
+
parameters: [{ name: 'x', type: 'number' }],
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('notebook cell analysis', () => {
|
|
115
|
+
const parser = new NotebookVirtualParser();
|
|
116
|
+
|
|
117
|
+
const cells = [
|
|
118
|
+
{ id: 'cell1', code: 'const x: number = 10;' },
|
|
119
|
+
{ id: 'cell2', code: 'const y = x * 2;' },
|
|
120
|
+
{ id: 'cell3', code: 'console.log(y);' },
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
const analysis = parser.analyzeNotebook(cells);
|
|
124
|
+
|
|
125
|
+
// Cell 1 exports x.
|
|
126
|
+
const cell1 = analysis.get('cell1');
|
|
127
|
+
expect(cell1?.exports).toHaveLength(1);
|
|
128
|
+
expect(cell1?.exports[0]).toMatchObject({
|
|
129
|
+
name: 'x',
|
|
130
|
+
type: 'variable',
|
|
131
|
+
valueType: 'number',
|
|
132
|
+
});
|
|
133
|
+
expect(cell1?.imports).toHaveLength(0);
|
|
134
|
+
|
|
135
|
+
// Cell 2 imports x and exports y.
|
|
136
|
+
const cell2 = analysis.get('cell2');
|
|
137
|
+
expect(cell2?.exports).toHaveLength(1);
|
|
138
|
+
expect(cell2?.exports[0]).toMatchObject({
|
|
139
|
+
name: 'y',
|
|
140
|
+
type: 'variable',
|
|
141
|
+
});
|
|
142
|
+
expect(cell2?.imports).toContain('x');
|
|
143
|
+
|
|
144
|
+
// Cell 3 imports y.
|
|
145
|
+
const cell3 = analysis.get('cell3');
|
|
146
|
+
expect(cell3?.exports).toHaveLength(0);
|
|
147
|
+
expect(cell3?.imports).toContain('y');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
|
|
10
|
+
import { builtIns, systemDefinitions } from './eval';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default system definitions.
|
|
14
|
+
*/
|
|
15
|
+
const systemFiles: VirtualFile[] = [
|
|
16
|
+
{
|
|
17
|
+
filename: '/lib.d.ts',
|
|
18
|
+
content: systemDefinitions,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export type ParsedExpression = {
|
|
23
|
+
name?: string;
|
|
24
|
+
type?: 'function' | 'variable' | 'class' | 'interface';
|
|
25
|
+
value?: any;
|
|
26
|
+
valueType?: string;
|
|
27
|
+
parameters?: Array<{ name: string; type: string }>;
|
|
28
|
+
returnType?: string;
|
|
29
|
+
references?: string[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type VirtualFile = {
|
|
33
|
+
filename: string;
|
|
34
|
+
content: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* TypeScript parser using Virtual File System for browser compatibility.
|
|
39
|
+
* This provides full TypeScript analysis including type information.
|
|
40
|
+
*/
|
|
41
|
+
export class VirtualTypeScriptParser {
|
|
42
|
+
protected compilerOptions: ts.CompilerOptions = {
|
|
43
|
+
target: ts.ScriptTarget.ES2020,
|
|
44
|
+
module: ts.ModuleKind.ESNext,
|
|
45
|
+
strict: true,
|
|
46
|
+
esModuleInterop: true,
|
|
47
|
+
skipLibCheck: true,
|
|
48
|
+
forceConsistentCasingInfilenames: true,
|
|
49
|
+
jsx: ts.JsxEmit.React,
|
|
50
|
+
noLib: true, // Don't automatically include default lib files.
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Parse a single expression or statement.
|
|
55
|
+
*/
|
|
56
|
+
parseExpression(input: string): ParsedExpression {
|
|
57
|
+
invariant(input.trim() !== '', 'input must not be empty');
|
|
58
|
+
const files: VirtualFile[] = [{ filename: '/temp.ts', content: input }];
|
|
59
|
+
const analysis = this.analyzeFiles(files);
|
|
60
|
+
|
|
61
|
+
// If no declarations found, check for standalone expression references.
|
|
62
|
+
if (analysis.length === 0) {
|
|
63
|
+
const sourcefilename = '/temp.ts';
|
|
64
|
+
const env = this.createEnvironment([{ filename: sourcefilename, content: input }]);
|
|
65
|
+
const sourceFile = env.getSourceFile(sourcefilename);
|
|
66
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
67
|
+
|
|
68
|
+
if (sourceFile && typeChecker) {
|
|
69
|
+
// Check for assignment expressions.
|
|
70
|
+
const assignmentInfo = this.findAssignmentExpression(sourceFile, typeChecker);
|
|
71
|
+
if (assignmentInfo) {
|
|
72
|
+
return assignmentInfo;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const references = this.findAllReferences(sourceFile, typeChecker);
|
|
76
|
+
return { references };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return analysis[0];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Analyze multiple files with full type information.
|
|
85
|
+
*/
|
|
86
|
+
analyzeFiles(files: VirtualFile[]): ParsedExpression[] {
|
|
87
|
+
const env = this.createEnvironment(files);
|
|
88
|
+
const results: ParsedExpression[] = [];
|
|
89
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
90
|
+
|
|
91
|
+
// Analyze each file.
|
|
92
|
+
files.forEach((file) => {
|
|
93
|
+
const sourceFile = env.getSourceFile(file.filename);
|
|
94
|
+
if (!sourceFile || !typeChecker) return;
|
|
95
|
+
|
|
96
|
+
const fileResults = this.analyzeSourceFile(sourceFile, typeChecker);
|
|
97
|
+
results.push(...fileResults);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return results;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Analyze a source file with type information.
|
|
105
|
+
*/
|
|
106
|
+
protected analyzeSourceFile(sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker): ParsedExpression[] {
|
|
107
|
+
const results: ParsedExpression[] = [];
|
|
108
|
+
|
|
109
|
+
const visit = (node: ts.Node) => {
|
|
110
|
+
// Function declarations.
|
|
111
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
112
|
+
const symbol = typeChecker.getSymbolAtLocation(node.name);
|
|
113
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, node);
|
|
114
|
+
const signature = type && typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
|
|
115
|
+
|
|
116
|
+
results.push({
|
|
117
|
+
name: node.name.text,
|
|
118
|
+
type: 'function',
|
|
119
|
+
parameters: this.extractParameters(signature, typeChecker),
|
|
120
|
+
returnType: signature ? typeChecker.typeToString(signature.getReturnType()) : 'any',
|
|
121
|
+
references: this.findReferences(node, sourceFile, typeChecker),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Variable declarations.
|
|
126
|
+
else if (ts.isVariableStatement(node)) {
|
|
127
|
+
node.declarationList.declarations.forEach((declaration) => {
|
|
128
|
+
if (ts.isIdentifier(declaration.name)) {
|
|
129
|
+
const symbol = typeChecker.getSymbolAtLocation(declaration.name);
|
|
130
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
131
|
+
|
|
132
|
+
let kind: 'function' | 'variable' = 'variable';
|
|
133
|
+
let parameters: Array<{ name: string; type: string }> | undefined;
|
|
134
|
+
let returnType: string | undefined;
|
|
135
|
+
let value: any;
|
|
136
|
+
|
|
137
|
+
// Get the type string.
|
|
138
|
+
const typeString = type ? typeChecker.typeToString(type) : 'any';
|
|
139
|
+
|
|
140
|
+
// Check if it's a function.
|
|
141
|
+
if (declaration.initializer) {
|
|
142
|
+
if (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)) {
|
|
143
|
+
kind = 'function';
|
|
144
|
+
const funcType = typeChecker.getTypeAtLocation(declaration.initializer);
|
|
145
|
+
const signature = typeChecker.getSignaturesOfType(funcType, ts.SignatureKind.Call)[0];
|
|
146
|
+
if (signature) {
|
|
147
|
+
parameters = this.extractParameters(signature, typeChecker);
|
|
148
|
+
returnType = typeChecker.typeToString(signature.getReturnType());
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
// Extract literal values
|
|
152
|
+
if (ts.isNumericLiteral(declaration.initializer)) {
|
|
153
|
+
value = Number(declaration.initializer.text);
|
|
154
|
+
} else if (ts.isStringLiteral(declaration.initializer)) {
|
|
155
|
+
value = declaration.initializer.text;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Find references in the initializer only.
|
|
161
|
+
const refs = declaration.initializer
|
|
162
|
+
? this.findReferences(declaration.initializer, sourceFile, typeChecker)
|
|
163
|
+
: [];
|
|
164
|
+
|
|
165
|
+
results.push({
|
|
166
|
+
name: declaration.name.text,
|
|
167
|
+
type: kind,
|
|
168
|
+
valueType: typeString,
|
|
169
|
+
value,
|
|
170
|
+
parameters,
|
|
171
|
+
returnType,
|
|
172
|
+
references: refs,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Class declarations.
|
|
179
|
+
else if (ts.isClassDeclaration(node) && node.name) {
|
|
180
|
+
results.push({
|
|
181
|
+
name: node.name.text,
|
|
182
|
+
type: 'class',
|
|
183
|
+
references: this.findReferences(node, sourceFile, typeChecker),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Interface declarations.
|
|
188
|
+
else if (ts.isInterfaceDeclaration(node)) {
|
|
189
|
+
results.push({
|
|
190
|
+
name: node.name.text,
|
|
191
|
+
type: 'interface',
|
|
192
|
+
references: this.findReferences(node, sourceFile, typeChecker),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
ts.forEachChild(node, visit);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
visit(sourceFile);
|
|
200
|
+
return results;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Extract parameter information from a signature.
|
|
205
|
+
*/
|
|
206
|
+
private extractParameters(
|
|
207
|
+
signature: ts.Signature | undefined,
|
|
208
|
+
typeChecker: ts.TypeChecker,
|
|
209
|
+
): Array<{ name: string; type: string }> {
|
|
210
|
+
if (!signature) return [];
|
|
211
|
+
|
|
212
|
+
return signature.parameters.map((param) => ({
|
|
213
|
+
name: param.getName(),
|
|
214
|
+
type: typeChecker.typeToString(typeChecker.getTypeOfSymbolAtLocation(param, param.valueDeclaration!)),
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Find all references to variables used in a node.
|
|
220
|
+
*/
|
|
221
|
+
private findReferences(node: ts.Node, _sourceFile: ts.SourceFile, _typeChecker: ts.TypeChecker): string[] {
|
|
222
|
+
const references = new Set<string>();
|
|
223
|
+
const localSymbols = new Set<string>();
|
|
224
|
+
|
|
225
|
+
// First, collect local symbols (parameters, local variables).
|
|
226
|
+
const collectLocalSymbols = (node: ts.Node) => {
|
|
227
|
+
if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
228
|
+
node.parameters.forEach((param) => {
|
|
229
|
+
if (ts.isIdentifier(param.name)) {
|
|
230
|
+
localSymbols.add(param.name.text);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
236
|
+
localSymbols.add(node.name.text);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
ts.forEachChild(node, collectLocalSymbols);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
collectLocalSymbols(node);
|
|
243
|
+
|
|
244
|
+
// Then find all identifier references.
|
|
245
|
+
const findRefs = (node: ts.Node) => {
|
|
246
|
+
if (ts.isIdentifier(node)) {
|
|
247
|
+
// Skip if it's a local symbol.
|
|
248
|
+
if (!localSymbols.has(node.text)) {
|
|
249
|
+
// Check if it's a reference (not a declaration).
|
|
250
|
+
const parent = node.parent;
|
|
251
|
+
const isDeclaration =
|
|
252
|
+
(ts.isVariableDeclaration(parent) && parent.name === node) ||
|
|
253
|
+
(ts.isFunctionDeclaration(parent) && parent.name === node) ||
|
|
254
|
+
(ts.isParameter(parent) && parent.name === node);
|
|
255
|
+
|
|
256
|
+
if (!isDeclaration && !this.isBuiltIn(node.text)) {
|
|
257
|
+
references.add(node.text);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
ts.forEachChild(node, findRefs);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
findRefs(node);
|
|
265
|
+
return Array.from(references);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Check if a name is a built-in global.
|
|
270
|
+
*/
|
|
271
|
+
protected isBuiltIn(name: string): boolean {
|
|
272
|
+
return builtIns.has(name);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Find assignment expressions in a source file.
|
|
277
|
+
*/
|
|
278
|
+
private findAssignmentExpression(sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker): ParsedExpression | null {
|
|
279
|
+
let result: ParsedExpression | null = null;
|
|
280
|
+
|
|
281
|
+
const visit = (node: ts.Node) => {
|
|
282
|
+
if (ts.isExpressionStatement(node) && ts.isBinaryExpression(node.expression)) {
|
|
283
|
+
const expr = node.expression;
|
|
284
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(expr.left)) {
|
|
285
|
+
const type = typeChecker.getTypeAtLocation(expr.right);
|
|
286
|
+
const typeString = typeChecker.typeToString(type);
|
|
287
|
+
|
|
288
|
+
// Get the literal value if it's a literal.
|
|
289
|
+
let value: any;
|
|
290
|
+
if (ts.isNumericLiteral(expr.right)) {
|
|
291
|
+
value = Number(expr.right.text);
|
|
292
|
+
} else if (ts.isStringLiteral(expr.right)) {
|
|
293
|
+
value = expr.right.text;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Find references in the right-hand side.
|
|
297
|
+
const references = this.findReferences(expr.right, sourceFile, typeChecker);
|
|
298
|
+
|
|
299
|
+
result = {
|
|
300
|
+
name: expr.left.text,
|
|
301
|
+
type: 'variable',
|
|
302
|
+
valueType: typeString,
|
|
303
|
+
value,
|
|
304
|
+
references,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (!result) {
|
|
309
|
+
ts.forEachChild(node, visit);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
visit(sourceFile);
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Find all identifier references in a source file.
|
|
319
|
+
*/
|
|
320
|
+
protected findAllReferences(sourceFile: ts.SourceFile, _typeChecker: ts.TypeChecker): string[] {
|
|
321
|
+
const references = new Set<string>();
|
|
322
|
+
|
|
323
|
+
const visit = (node: ts.Node) => {
|
|
324
|
+
if (ts.isIdentifier(node)) {
|
|
325
|
+
// Skip if it's a declaration.
|
|
326
|
+
const parent = node.parent;
|
|
327
|
+
const isDeclaration =
|
|
328
|
+
(ts.isVariableDeclaration(parent) && parent.name === node) ||
|
|
329
|
+
(ts.isFunctionDeclaration(parent) && parent.name === node) ||
|
|
330
|
+
(ts.isParameter(parent) && parent.name === node);
|
|
331
|
+
|
|
332
|
+
// Skip if it's the left-hand side of an assignment.
|
|
333
|
+
const isAssignmentTarget =
|
|
334
|
+
ts.isBinaryExpression(parent) &&
|
|
335
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
336
|
+
parent.left === node;
|
|
337
|
+
|
|
338
|
+
if (!isDeclaration && !isAssignmentTarget && !this.isBuiltIn(node.text)) {
|
|
339
|
+
references.add(node.text);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
ts.forEachChild(node, visit);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
visit(sourceFile);
|
|
346
|
+
return Array.from(references);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
protected createEnvironment(files: VirtualFile[]) {
|
|
350
|
+
const allFiles = [...systemFiles, ...files];
|
|
351
|
+
|
|
352
|
+
const fileMap = new Map<string, string>();
|
|
353
|
+
allFiles.forEach(({ filename, content }) => {
|
|
354
|
+
fileMap.set(filename, content);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const system = createSystem(fileMap);
|
|
358
|
+
return createVirtualTypeScriptEnvironment(
|
|
359
|
+
system,
|
|
360
|
+
allFiles.map(({ filename }) => filename),
|
|
361
|
+
ts,
|
|
362
|
+
this.compilerOptions,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Notebook-specific parser with dependency analysis.
|
|
369
|
+
*/
|
|
370
|
+
export class NotebookVirtualParser extends VirtualTypeScriptParser {
|
|
371
|
+
/**
|
|
372
|
+
* Analyze notebook cells with full type checking.
|
|
373
|
+
*/
|
|
374
|
+
analyzeNotebook(cells: Array<{ id: string; code: string }>) {
|
|
375
|
+
// Create cumulative environment where each cell can see previous cells.
|
|
376
|
+
const cumulativeCode: string[] = [];
|
|
377
|
+
const cellAnalysis: Map<
|
|
378
|
+
string,
|
|
379
|
+
{
|
|
380
|
+
exports: ParsedExpression[];
|
|
381
|
+
imports: string[];
|
|
382
|
+
errors: ts.Diagnostic[];
|
|
383
|
+
}
|
|
384
|
+
> = new Map();
|
|
385
|
+
|
|
386
|
+
cells.forEach((cell) => {
|
|
387
|
+
// Create files for all cells up to current.
|
|
388
|
+
const files: VirtualFile[] = [];
|
|
389
|
+
|
|
390
|
+
// Add previous cells as context.
|
|
391
|
+
if (cumulativeCode.length > 0) {
|
|
392
|
+
files.push({
|
|
393
|
+
filename: '/context.ts',
|
|
394
|
+
content: cumulativeCode.join('\n'),
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Add current cell.
|
|
399
|
+
const filename = `/cell/${cell.id}.ts`;
|
|
400
|
+
files.push({
|
|
401
|
+
filename,
|
|
402
|
+
content: cell.code,
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// Create environment.
|
|
406
|
+
const env = this.createEnvironment(files);
|
|
407
|
+
|
|
408
|
+
// Get diagnostics (errors).
|
|
409
|
+
const diagnostics = env.languageService.getSemanticDiagnostics(filename);
|
|
410
|
+
|
|
411
|
+
// Analyze current cell.
|
|
412
|
+
const sourceFile = env.getSourceFile(filename);
|
|
413
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
414
|
+
|
|
415
|
+
if (sourceFile && typeChecker) {
|
|
416
|
+
const exports = this.analyzeSourceFile(sourceFile, typeChecker);
|
|
417
|
+
|
|
418
|
+
// Find all references in the current cell.
|
|
419
|
+
const allRefs = new Set<string>();
|
|
420
|
+
exports.forEach((exp) => {
|
|
421
|
+
exp.references?.forEach((ref) => allRefs.add(ref));
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// Also check for references not in exports (e.g., console.log(y)).
|
|
425
|
+
const additionalRefs = this.findAllReferences(sourceFile, typeChecker);
|
|
426
|
+
additionalRefs.forEach((ref) => allRefs.add(ref));
|
|
427
|
+
|
|
428
|
+
// Determine which references are imports from previous cells.
|
|
429
|
+
const previousExports = new Set<string>();
|
|
430
|
+
for (const [_prevCellId, prevAnalysis] of cellAnalysis) {
|
|
431
|
+
prevAnalysis.exports.forEach((exp) => {
|
|
432
|
+
if (exp.name) previousExports.add(exp.name);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const imports = Array.from(allRefs).filter((ref) => previousExports.has(ref));
|
|
437
|
+
|
|
438
|
+
cellAnalysis.set(cell.id, {
|
|
439
|
+
exports,
|
|
440
|
+
imports,
|
|
441
|
+
errors: diagnostics,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Add current cell code to cumulative.
|
|
446
|
+
cumulativeCode.push(cell.code);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
return cellAnalysis;
|
|
450
|
+
}
|
|
451
|
+
}
|
package/src/templates/chess.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { S, defineFunction } from 'dxos:functions';
|
|
|
8
8
|
import { Chess } from 'https://esm.sh/chess.js@0.13.1?bundle=false';
|
|
9
9
|
|
|
10
10
|
export default defineFunction({
|
|
11
|
+
key: 'dxos.org/script/chess',
|
|
12
|
+
name: 'Chess',
|
|
11
13
|
description: 'Plays a random move in a chess game.',
|
|
12
14
|
|
|
13
15
|
inputSchema: S.Struct({
|
|
@@ -8,6 +8,8 @@ import { Expando, S, create, defineFunction } from 'dxos:functions';
|
|
|
8
8
|
import { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';
|
|
9
9
|
|
|
10
10
|
export default defineFunction({
|
|
11
|
+
key: 'dxos.org/script/data-generator',
|
|
12
|
+
name: 'Data Generator',
|
|
11
13
|
inputSchema: S.Struct({
|
|
12
14
|
documentAmount: S.optional(S.Number),
|
|
13
15
|
textSize: S.optional(S.Number),
|
package/src/templates/discord.ts
CHANGED
|
@@ -13,7 +13,13 @@ import {
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.17.0&bundle=false';
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
import
|
|
16
|
+
import * as Config from 'https://esm.sh/effect@3.17.0/Config?bundle=false';
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
import * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import * as Redacted from 'https://esm.sh/effect@3.17.0/Redacted?bundle=false';
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
import * as Ref from 'https://esm.sh/effect@3.17.0/Ref?bundle=false';
|
|
17
23
|
|
|
18
24
|
const MessageSchema = S.Struct({
|
|
19
25
|
id: ObjectId,
|
|
@@ -36,6 +42,8 @@ const generateSnowflake = (unixTimestamp: number): bigint => {
|
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
export default defineFunction({
|
|
45
|
+
key: 'dxos.org/script/discord',
|
|
46
|
+
name: 'Discord',
|
|
39
47
|
inputSchema: S.Struct({
|
|
40
48
|
// TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
|
|
41
49
|
tick: S.optional(S.String),
|
|
@@ -11,9 +11,13 @@ import {
|
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
} from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
import
|
|
14
|
+
import * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import * as Schedule from 'https://esm.sh/effect@3.17.0/Schedule?bundle=false';
|
|
15
17
|
|
|
16
18
|
export default defineFunction({
|
|
19
|
+
key: 'dxos.org/script/forex-effect',
|
|
20
|
+
name: 'Forex Effect',
|
|
17
21
|
description: 'Returns the exchange rate between two currencies.',
|
|
18
22
|
|
|
19
23
|
inputSchema: S.Struct({
|
package/src/templates/forex.ts
CHANGED