@dxos/plugin-sheet 0.7.4 → 0.7.5-labs.5f04cf6
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/SheetContainer-CM4CO3DC.mjs +370 -0
- package/dist/lib/browser/SheetContainer-CM4CO3DC.mjs.map +7 -0
- package/dist/lib/browser/chunk-FOO6NGBM.mjs +229 -0
- package/dist/lib/browser/chunk-FOO6NGBM.mjs.map +7 -0
- package/dist/lib/browser/chunk-H23JW3DX.mjs +800 -0
- package/dist/lib/browser/chunk-H23JW3DX.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RABELMEQ.mjs → chunk-K6EUYKWT.mjs} +3 -3
- package/dist/lib/browser/chunk-K6EUYKWT.mjs.map +7 -0
- package/dist/lib/browser/chunk-PW25VUP6.mjs +15 -0
- package/dist/lib/browser/chunk-PW25VUP6.mjs.map +7 -0
- package/dist/lib/browser/chunk-T3IVPMRX.mjs +900 -0
- package/dist/lib/browser/chunk-T3IVPMRX.mjs.map +7 -0
- package/dist/lib/browser/compute-graph-registry-XH6B2SWG.mjs +27 -0
- package/dist/lib/browser/compute-graph-registry-XH6B2SWG.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +86 -324
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-Q7DTHAM5.mjs +47 -0
- package/dist/lib/browser/intent-resolver-Q7DTHAM5.mjs.map +7 -0
- package/dist/lib/browser/markdown-IKG5FNCA.mjs +26 -0
- package/dist/lib/browser/markdown-IKG5FNCA.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-context-JG43577H.mjs +28 -0
- package/dist/lib/browser/react-context-JG43577H.mjs.map +7 -0
- package/dist/lib/browser/react-surface-URRC3AFC.mjs +43 -0
- package/dist/lib/browser/react-surface-URRC3AFC.mjs.map +7 -0
- package/dist/lib/browser/thread-YX6KBQNQ.mjs +17 -0
- package/dist/lib/browser/thread-YX6KBQNQ.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +62 -0
- package/dist/lib/node/SheetContainer-TJ3JQLWM.cjs +364 -0
- package/dist/lib/node/SheetContainer-TJ3JQLWM.cjs.map +7 -0
- package/dist/lib/node/chunk-E3RXOEL6.cjs +935 -0
- package/dist/lib/node/chunk-E3RXOEL6.cjs.map +7 -0
- package/dist/lib/node/{types.cjs → chunk-FU5K66DS.cjs} +12 -16
- package/dist/lib/node/chunk-FU5K66DS.cjs.map +7 -0
- package/dist/lib/node/{chunk-2ZVZI2KJ.cjs → chunk-NLDXUFDG.cjs} +7 -7
- package/dist/lib/node/chunk-NLDXUFDG.cjs.map +7 -0
- package/dist/lib/node/chunk-P4KSGZSS.cjs +251 -0
- package/dist/lib/node/chunk-P4KSGZSS.cjs.map +7 -0
- package/dist/lib/node/chunk-ZPWW4LPY.cjs +807 -0
- package/dist/lib/node/chunk-ZPWW4LPY.cjs.map +7 -0
- package/dist/lib/node/compute-graph-registry-ORGTIE5M.cjs +53 -0
- package/dist/lib/node/compute-graph-registry-ORGTIE5M.cjs.map +7 -0
- package/dist/lib/node/index.cjs +87 -318
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-ZUDJJUFG.cjs +60 -0
- package/dist/lib/node/intent-resolver-ZUDJJUFG.cjs.map +7 -0
- package/dist/lib/node/markdown-EUUL3Q36.cjs +40 -0
- package/dist/lib/node/markdown-EUUL3Q36.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-context-OOH5QFE2.cjs +50 -0
- package/dist/lib/node/react-context-OOH5QFE2.cjs.map +7 -0
- package/dist/lib/node/react-surface-IQN5JKSS.cjs +64 -0
- package/dist/lib/node/react-surface-IQN5JKSS.cjs.map +7 -0
- package/dist/lib/node/{meta.cjs → thread-VBPS23P2.cjs} +12 -10
- package/dist/lib/node/thread-VBPS23P2.cjs.map +7 -0
- package/dist/lib/node/types/index.cjs +84 -0
- package/dist/lib/node/types/index.cjs.map +7 -0
- package/dist/lib/node-esm/SheetContainer-QEEFORIC.mjs +371 -0
- package/dist/lib/node-esm/SheetContainer-QEEFORIC.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BM2Q3FFC.mjs → chunk-FMOVRTS4.mjs} +3 -3
- package/dist/lib/node-esm/chunk-FMOVRTS4.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KCXK5UM6.mjs +16 -0
- package/dist/lib/node-esm/chunk-KCXK5UM6.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NSVUOAI6.mjs +901 -0
- package/dist/lib/node-esm/chunk-NSVUOAI6.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OXD6RBFF.mjs +801 -0
- package/dist/lib/node-esm/chunk-OXD6RBFF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PTOI45NK.mjs +231 -0
- package/dist/lib/node-esm/chunk-PTOI45NK.mjs.map +7 -0
- package/dist/lib/node-esm/compute-graph-registry-JH2FRHLD.mjs +28 -0
- package/dist/lib/node-esm/compute-graph-registry-JH2FRHLD.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +86 -324
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-IF64RN7B.mjs +48 -0
- package/dist/lib/node-esm/intent-resolver-IF64RN7B.mjs.map +7 -0
- package/dist/lib/node-esm/markdown-D2ZMN7LR.mjs +27 -0
- package/dist/lib/node-esm/markdown-D2ZMN7LR.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-context-CJVSLO74.mjs +29 -0
- package/dist/lib/node-esm/react-context-CJVSLO74.mjs.map +7 -0
- package/dist/lib/node-esm/react-surface-XJIX5G3I.mjs +44 -0
- package/dist/lib/node-esm/react-surface-XJIX5G3I.mjs.map +7 -0
- package/dist/lib/node-esm/thread-HSJD3SR6.mjs +18 -0
- package/dist/lib/node-esm/thread-HSJD3SR6.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +63 -0
- package/dist/types/src/SheetPlugin.d.ts +1 -3
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts +5 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-graph-registry.d.ts +4 -0
- package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +17 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/markdown.d.ts +6 -0
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-context.d.ts +8 -0
- package/dist/types/src/capabilities/react-context.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/thread.d.ts +6 -0
- package/dist/types/src/capabilities/thread.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +1 -1
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
- package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +1 -2
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +7 -0
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +6 -0
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/align.d.ts +28 -0
- package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/comment.d.ts +23 -0
- package/dist/types/src/components/SheetToolbar/comment.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/index.d.ts +2 -0
- package/dist/types/src/components/SheetToolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/style.d.ts +26 -0
- package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/useToolbarAction.d.ts +8 -0
- package/dist/types/src/components/SheetToolbar/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts +6 -0
- package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.d.ts +1 -1
- package/dist/types/src/extensions/compute.d.ts.map +1 -1
- package/dist/types/src/extensions/editor/extension.d.ts +1 -1
- package/dist/types/src/extensions/editor/extension.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/integrations/thread-ranges.d.ts +1 -1
- package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts +6 -8
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/model/testing.d.ts +1 -1
- package/dist/types/src/model/testing.d.ts.map +1 -1
- package/dist/types/src/model/useSheetModel.d.ts +1 -1
- package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +1 -1
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/{defs → types}/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +105 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/{defs → types}/sheet-range-types.d.ts +1 -1
- package/dist/types/src/types/sheet-range-types.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +71 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/{defs → types}/util.d.ts +5 -1
- package/dist/types/src/types/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +47 -61
- package/src/SheetPlugin.tsx +70 -176
- package/src/capabilities/capabilities.ts +14 -0
- package/src/capabilities/compute-graph-registry.ts +25 -0
- package/src/capabilities/index.ts +14 -0
- package/src/capabilities/intent-resolver.ts +29 -0
- package/src/capabilities/markdown.ts +22 -0
- package/src/capabilities/react-context.tsx +20 -0
- package/src/capabilities/react-surface.tsx +30 -0
- package/src/capabilities/thread.ts +14 -0
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +1 -2
- package/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.tsx +6 -7
- package/src/components/FunctionEditor/FunctionEditor.tsx +2 -1
- package/src/components/GridSheet/GridSheet.stories.tsx +2 -0
- package/src/components/GridSheet/GridSheet.tsx +15 -18
- package/src/components/GridSheet/SheetCellEditor.stories.tsx +6 -7
- package/src/components/GridSheet/util.ts +3 -2
- package/src/components/RangeList/RangeList.tsx +2 -1
- package/src/components/SheetContainer/SheetContainer.stories.tsx +25 -23
- package/src/components/SheetContainer/SheetContainer.tsx +3 -8
- package/src/components/SheetContext/SheetContext.tsx +1 -2
- package/src/components/{Toolbar/Toolbar.stories.tsx → SheetToolbar/SheetToolbar.stories.tsx} +4 -8
- package/src/components/SheetToolbar/SheetToolbar.tsx +48 -0
- package/src/components/SheetToolbar/align.ts +68 -0
- package/src/components/SheetToolbar/comment.ts +56 -0
- package/src/components/{Toolbar → SheetToolbar}/index.ts +1 -1
- package/src/components/SheetToolbar/style.ts +72 -0
- package/src/components/SheetToolbar/useToolbarAction.ts +87 -0
- package/src/components/SheetToolbar/useToolbarState.ts +17 -0
- package/src/components/index.ts +0 -1
- package/src/extensions/compute.ts +7 -4
- package/src/extensions/editor/extension.test.ts +2 -1
- package/src/extensions/editor/extension.ts +2 -3
- package/src/index.ts +2 -7
- package/src/integrations/thread-ranges.ts +28 -24
- package/src/meta.ts +1 -1
- package/src/model/sheet-model.test.ts +4 -10
- package/src/model/sheet-model.ts +30 -22
- package/src/model/testing.ts +3 -2
- package/src/model/useSheetModel.ts +2 -1
- package/src/sanity.test.ts +1 -1
- package/src/testing/testing.tsx +2 -3
- package/src/{defs → types}/index.ts +1 -0
- package/src/types/schema.ts +56 -0
- package/src/{defs → types}/sheet-range-types.ts +1 -1
- package/src/types/types.ts +67 -0
- package/src/{defs → types}/util.ts +13 -13
- package/dist/lib/browser/SheetContainer-KCLT6PEO.mjs +0 -296
- package/dist/lib/browser/SheetContainer-KCLT6PEO.mjs.map +0 -7
- package/dist/lib/browser/chunk-E5WQ7U7G.mjs +0 -1675
- package/dist/lib/browser/chunk-E5WQ7U7G.mjs.map +0 -7
- package/dist/lib/browser/chunk-F3HE6D3J.mjs +0 -3269
- package/dist/lib/browser/chunk-F3HE6D3J.mjs.map +0 -7
- package/dist/lib/browser/chunk-JXFPOYNA.mjs +0 -67
- package/dist/lib/browser/chunk-JXFPOYNA.mjs.map +0 -7
- package/dist/lib/browser/chunk-RABELMEQ.mjs.map +0 -7
- package/dist/lib/browser/compute-graph-SNUS7HOH.mjs +0 -35
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/types.mjs +0 -16
- package/dist/lib/browser/types.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-VVVRYTQG.cjs +0 -298
- package/dist/lib/node/SheetContainer-VVVRYTQG.cjs.map +0 -7
- package/dist/lib/node/chunk-2ZVZI2KJ.cjs.map +0 -7
- package/dist/lib/node/chunk-45YW2DX2.cjs +0 -1656
- package/dist/lib/node/chunk-45YW2DX2.cjs.map +0 -7
- package/dist/lib/node/chunk-KSEEI5VC.cjs +0 -3323
- package/dist/lib/node/chunk-KSEEI5VC.cjs.map +0 -7
- package/dist/lib/node/chunk-OWH2EUHZ.cjs +0 -90
- package/dist/lib/node/chunk-OWH2EUHZ.cjs.map +0 -7
- package/dist/lib/node/compute-graph-WILPHO4A.cjs +0 -57
- package/dist/lib/node/compute-graph-WILPHO4A.cjs.map +0 -7
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node/types.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-LSBE6Q4X.mjs +0 -297
- package/dist/lib/node-esm/SheetContainer-LSBE6Q4X.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6JF2AHKO.mjs +0 -3270
- package/dist/lib/node-esm/chunk-6JF2AHKO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BVS2IQRO.mjs +0 -68
- package/dist/lib/node-esm/chunk-BVS2IQRO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NYDNXI7L.mjs +0 -1676
- package/dist/lib/node-esm/chunk-NYDNXI7L.mjs.map +0 -7
- package/dist/lib/node-esm/compute-graph-S6CVN7RS.mjs +0 -36
- package/dist/lib/node-esm/compute-graph-S6CVN7RS.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/lib/node-esm/types.mjs +0 -17
- package/dist/lib/node-esm/types.mjs.map +0 -7
- package/dist/types/src/components/SheetObjectSettings.d.ts +0 -7
- package/dist/types/src/components/SheetObjectSettings.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -48
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +0 -7
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts +0 -34
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph.d.ts +0 -64
- package/dist/types/src/compute-graph/compute-graph.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph.test.d.ts +0 -2
- package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-node.d.ts +0 -26
- package/dist/types/src/compute-graph/compute-node.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/async-function.d.ts +0 -66
- package/dist/types/src/compute-graph/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/edge-function.d.ts +0 -21
- package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/function-defs.d.ts +0 -11
- package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/index.d.ts +0 -4
- package/dist/types/src/compute-graph/functions/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/hyperformula.test.d.ts +0 -2
- package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph/index.d.ts +0 -5
- package/dist/types/src/compute-graph/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/testing/index.d.ts +0 -3
- package/dist/types/src/compute-graph/testing/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/testing/test-builder.d.ts +0 -15
- package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts +0 -36
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/compute-graph/util.d.ts +0 -2
- package/dist/types/src/compute-graph/util.d.ts.map +0 -1
- package/dist/types/src/defs/index.d.ts.map +0 -1
- package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
- package/dist/types/src/defs/types.d.ts +0 -26
- package/dist/types/src/defs/types.d.ts.map +0 -1
- package/dist/types/src/defs/types.test.d.ts +0 -2
- package/dist/types/src/defs/types.test.d.ts.map +0 -1
- package/dist/types/src/defs/util.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -182
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/vendor/hyperformula.mjs +0 -37145
- package/src/components/SheetObjectSettings.tsx +0 -38
- package/src/components/Toolbar/Toolbar.tsx +0 -346
- package/src/compute-graph/compute-graph-registry.ts +0 -90
- package/src/compute-graph/compute-graph.test.ts +0 -87
- package/src/compute-graph/compute-graph.ts +0 -260
- package/src/compute-graph/compute-node.ts +0 -62
- package/src/compute-graph/functions/async-function.ts +0 -179
- package/src/compute-graph/functions/edge-function.ts +0 -102
- package/src/compute-graph/functions/function-defs.ts +0 -2427
- package/src/compute-graph/functions/index.ts +0 -7
- package/src/compute-graph/hyperformula.test.ts +0 -14
- package/src/compute-graph/index.ts +0 -8
- package/src/compute-graph/testing/index.ts +0 -6
- package/src/compute-graph/testing/test-builder.ts +0 -54
- package/src/compute-graph/testing/test-plugin.ts +0 -100
- package/src/compute-graph/util.ts +0 -8
- package/src/defs/types.test.ts +0 -91
- package/src/defs/types.ts +0 -88
- package/src/types.ts +0 -125
- /package/dist/lib/browser/{compute-graph-SNUS7HOH.mjs.map → types/index.mjs.map} +0 -0
- /package/dist/lib/{browser/meta.mjs.map → node-esm/types/index.mjs.map} +0 -0
- /package/dist/types/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.d.ts +0 -0
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
6
|
-
|
|
7
|
-
import { Event } from '@dxos/async';
|
|
8
|
-
import { type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
|
|
9
|
-
import { FQ_ID_LENGTH } from '@dxos/client/echo';
|
|
10
|
-
import { Resource } from '@dxos/context';
|
|
11
|
-
import { getTypename } from '@dxos/echo-schema';
|
|
12
|
-
import { invariant } from '@dxos/invariant';
|
|
13
|
-
import { PublicKey } from '@dxos/keys';
|
|
14
|
-
import { log } from '@dxos/log';
|
|
15
|
-
import { FunctionType } from '@dxos/plugin-script/types';
|
|
16
|
-
import { nonNullable } from '@dxos/util';
|
|
17
|
-
|
|
18
|
-
import { ExportedCellChange, type HyperFormula } from '#hyperformula';
|
|
19
|
-
import { ComputeNode } from './compute-node';
|
|
20
|
-
import {
|
|
21
|
-
defaultFunctions,
|
|
22
|
-
FunctionContext,
|
|
23
|
-
type FunctionContextOptions,
|
|
24
|
-
type FunctionDefinition,
|
|
25
|
-
EDGE_FUNCTION_NAME,
|
|
26
|
-
} from './functions';
|
|
27
|
-
|
|
28
|
-
// TODO(burdon): Factor out compute-graph.
|
|
29
|
-
|
|
30
|
-
const UNKNOWN_BINDING = '__UNKNOWN__';
|
|
31
|
-
|
|
32
|
-
// TODO(burdon): Factory.
|
|
33
|
-
// export type ComputeNodeGenerator = <T>(obj: T) => ComputeNode;
|
|
34
|
-
|
|
35
|
-
type ObjectRef = { type: string; id: string };
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Marker for sheets that are managed by an ECHO object.
|
|
39
|
-
* Sheet ID: `dxos.org/type/SheetType@1234`
|
|
40
|
-
*/
|
|
41
|
-
export const createSheetName = ({ type, id }: ObjectRef) => `${type}@${id}`;
|
|
42
|
-
export const parseSheetName = (name: string): Partial<ObjectRef> => {
|
|
43
|
-
const [type, id] = name.split('@');
|
|
44
|
-
return id ? { type, id } : { id: type };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type ComputeGraphEvent = 'functionsUpdated' | 'valuesUpdated';
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Per-space compute and dependency graph.
|
|
51
|
-
* Consists of multiple ComputeNode (corresponding to a HyperFormula sheet).
|
|
52
|
-
* Manages the set of custom functions.
|
|
53
|
-
* HyperFormula manages the dependency graph.
|
|
54
|
-
*/
|
|
55
|
-
export class ComputeGraph extends Resource {
|
|
56
|
-
public readonly id = `graph-${PublicKey.random().truncate()}`;
|
|
57
|
-
|
|
58
|
-
// Map of nodes indexed by sheet number.
|
|
59
|
-
private readonly _nodes = new Map<number, ComputeNode>();
|
|
60
|
-
|
|
61
|
-
// Cached function objects.
|
|
62
|
-
private _remoteFunctions: FunctionType[] = [];
|
|
63
|
-
|
|
64
|
-
public readonly update = new Event<{ type: ComputeGraphEvent }>();
|
|
65
|
-
|
|
66
|
-
// The context is passed to all functions.
|
|
67
|
-
public readonly context: FunctionContext;
|
|
68
|
-
|
|
69
|
-
constructor(
|
|
70
|
-
private readonly _hf: HyperFormula,
|
|
71
|
-
private readonly _space?: Space,
|
|
72
|
-
private readonly _options?: Partial<FunctionContextOptions>,
|
|
73
|
-
) {
|
|
74
|
-
super();
|
|
75
|
-
|
|
76
|
-
const contextOptions = {
|
|
77
|
-
...this._options,
|
|
78
|
-
onUpdate: (update) => {
|
|
79
|
-
this._options?.onUpdate?.(update);
|
|
80
|
-
this.update.emit({ type: 'valuesUpdated' });
|
|
81
|
-
},
|
|
82
|
-
} satisfies Partial<FunctionContextOptions>;
|
|
83
|
-
this.context = new FunctionContext(this._hf, this._space, contextOptions);
|
|
84
|
-
this._hf.updateConfig({ context: this.context });
|
|
85
|
-
|
|
86
|
-
// TODO(burdon): If debounce then aggregate changes.
|
|
87
|
-
const onValuesUpdate: Listeners['valuesUpdated'] = (changes) => {
|
|
88
|
-
for (const change of changes) {
|
|
89
|
-
if (change instanceof ExportedCellChange) {
|
|
90
|
-
const { sheet } = change;
|
|
91
|
-
const node = this._nodes.get(sheet);
|
|
92
|
-
if (node) {
|
|
93
|
-
node.update.emit({ type: 'valuesUpdated', change });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
this._hf.on('valuesUpdated', onValuesUpdate);
|
|
100
|
-
this._ctx.onDispose(() => this._hf.off('valuesUpdated', onValuesUpdate));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get hf() {
|
|
104
|
-
return this._hf;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getFunctions(
|
|
108
|
-
{ standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
|
|
109
|
-
): FunctionDefinition[] {
|
|
110
|
-
return [
|
|
111
|
-
...(standard
|
|
112
|
-
? this._hf
|
|
113
|
-
.getRegisteredFunctionNames()
|
|
114
|
-
.map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name })
|
|
115
|
-
: []),
|
|
116
|
-
...(echo ? this._remoteFunctions.map((fn) => ({ name: fn.binding! })) : []),
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Get or create cell representing a sheet.
|
|
122
|
-
*/
|
|
123
|
-
// TODO(burdon): Async (open node).
|
|
124
|
-
// The graph should be an extensible factory that plugins extend with model constructors.
|
|
125
|
-
// This would enable on-the-fly instantiation of new models when then are referenced.
|
|
126
|
-
// E.g., Cross-object reference would be stored as "ObjectId!A1"
|
|
127
|
-
// The graph would then load the object and create a ComputeNode (model) of the appropriate type.
|
|
128
|
-
getOrCreateNode(name: string): ComputeNode {
|
|
129
|
-
invariant(name.length);
|
|
130
|
-
if (!this._hf.doesSheetExist(name)) {
|
|
131
|
-
log('created node', { space: this._space?.id, sheet: name });
|
|
132
|
-
this._hf.addSheet(name);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const sheetId = this._hf.getSheetId(name);
|
|
136
|
-
invariant(sheetId !== undefined);
|
|
137
|
-
|
|
138
|
-
const node = new ComputeNode(this, sheetId);
|
|
139
|
-
this._nodes.set(sheetId, node);
|
|
140
|
-
return node;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Map bound value to custom function invocation.
|
|
145
|
-
* E.g., "HELLO(...args)" => "DX("HELLO", ...args)".
|
|
146
|
-
*/
|
|
147
|
-
mapFormulaToNative(formula: string): string {
|
|
148
|
-
return (
|
|
149
|
-
formula
|
|
150
|
-
//
|
|
151
|
-
// Map cross-sheet references by name onto sheet stored by ECHO object/model.
|
|
152
|
-
// Example: "Test Sheet"!A0 => "dxos.org/type/SheetType@1234"!A0
|
|
153
|
-
// https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
|
|
154
|
-
//
|
|
155
|
-
.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
|
|
156
|
-
if (name) {
|
|
157
|
-
// TODO(burdon): Cache map.
|
|
158
|
-
const objects = this._hf
|
|
159
|
-
.getSheetNames()
|
|
160
|
-
.map((name) => {
|
|
161
|
-
const { type, id } = parseSheetName(name);
|
|
162
|
-
return type && id ? this._space?.db.getObjectById(id) : undefined;
|
|
163
|
-
})
|
|
164
|
-
.filter(nonNullable);
|
|
165
|
-
|
|
166
|
-
for (const obj of objects) {
|
|
167
|
-
if (obj.name === name) {
|
|
168
|
-
const type = getTypename(obj)!;
|
|
169
|
-
// NOTE: Names must be single quoted.
|
|
170
|
-
return `'${createSheetName({ type, id: obj.id })}'!`;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return `${name}!`;
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
//
|
|
179
|
-
// Map remote function references (i.e., to remote DX function invocation).
|
|
180
|
-
//
|
|
181
|
-
.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
182
|
-
const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
|
|
183
|
-
if (!fn) {
|
|
184
|
-
return match;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (args.trim() === '') {
|
|
188
|
-
return `${EDGE_FUNCTION_NAME}("${binding}")`;
|
|
189
|
-
} else {
|
|
190
|
-
return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Map from binding to fully qualified ECHO ID (to store).
|
|
198
|
-
* E.g., HELLO() => spaceId:objectId()
|
|
199
|
-
*/
|
|
200
|
-
mapFunctionBindingToId(formula: string) {
|
|
201
|
-
return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
202
|
-
if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn) => fn.name === binding)) {
|
|
203
|
-
return match;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
|
|
207
|
-
if (fn) {
|
|
208
|
-
const id = fullyQualifiedId(fn);
|
|
209
|
-
return `${id}(${args})`;
|
|
210
|
-
} else {
|
|
211
|
-
return match;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Map from fully qualified ECHO ID to binding (from store).
|
|
218
|
-
* E.g., spaceId:objectId() => HELLO()
|
|
219
|
-
*/
|
|
220
|
-
mapFunctionBindingFromId(formula: string) {
|
|
221
|
-
const binding = formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
|
|
222
|
-
const id = `${spaceId}:${objectId}`;
|
|
223
|
-
if (id.length !== FQ_ID_LENGTH) {
|
|
224
|
-
return match;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const fn = this._remoteFunctions.find((fn) => fullyQualifiedId(fn) === id);
|
|
228
|
-
if (fn?.binding) {
|
|
229
|
-
return `${fn.binding}(${args})`;
|
|
230
|
-
} else {
|
|
231
|
-
return UNKNOWN_BINDING;
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
if (binding.startsWith(`=${UNKNOWN_BINDING}`)) {
|
|
236
|
-
return undefined;
|
|
237
|
-
} else {
|
|
238
|
-
return binding;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
protected override async _open() {
|
|
243
|
-
if (this._space) {
|
|
244
|
-
// Subscribe to remote function definitions.
|
|
245
|
-
const query = this._space.db.query(Filter.schema(FunctionType));
|
|
246
|
-
const unsubscribe = query.subscribe(({ objects }) => {
|
|
247
|
-
this._remoteFunctions = objects.filter(({ binding }) => binding);
|
|
248
|
-
this.update.emit({ type: 'functionsUpdated' });
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
this._ctx.onDispose(unsubscribe);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
protected override async _close() {
|
|
256
|
-
for (const node of this._nodes.values()) {
|
|
257
|
-
await node.close();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
6
|
-
import { type ExportedCellChange } from 'hyperformula/typings/Exporter';
|
|
7
|
-
|
|
8
|
-
import { Event } from '@dxos/async';
|
|
9
|
-
import { Resource } from '@dxos/context';
|
|
10
|
-
|
|
11
|
-
import { DetailedCellError } from '#hyperformula';
|
|
12
|
-
import { type ComputeGraph } from './compute-graph';
|
|
13
|
-
import { type CellAddress, isFormula } from '../defs';
|
|
14
|
-
import { type CellScalarValue } from '../types';
|
|
15
|
-
|
|
16
|
-
export type ComputeNodeEvent = {
|
|
17
|
-
type: keyof Listeners;
|
|
18
|
-
change?: ExportedCellChange;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Individual "sheet" (typically corresponds to an ECHO object).
|
|
23
|
-
*/
|
|
24
|
-
// TODO(burdon): Factor out common HF wrapper from from SheetModel.
|
|
25
|
-
export class ComputeNode extends Resource {
|
|
26
|
-
public readonly update = new Event<ComputeNodeEvent>();
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
private readonly _graph: ComputeGraph,
|
|
30
|
-
public readonly sheetId: number,
|
|
31
|
-
) {
|
|
32
|
-
super();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get graph() {
|
|
36
|
-
return this._graph;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
clear() {
|
|
40
|
-
this._graph.hf.clearSheet(this.sheetId);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getValue(cell: CellAddress): CellScalarValue {
|
|
44
|
-
const value = this._graph.hf.getCellValue({ sheet: this.sheetId, row: cell.row, col: cell.col });
|
|
45
|
-
if (value instanceof DetailedCellError) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setValue(cell: CellAddress, value: CellScalarValue) {
|
|
53
|
-
const mappedValue = isFormula(value) ? this._graph.mapFormulaToNative(value) : value;
|
|
54
|
-
this._graph.hf.setCellContents({ sheet: this.sheetId, row: cell.row, col: cell.col }, [[mappedValue]]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// TODO(burdon): Load data into sheet.
|
|
58
|
-
protected override async _open() {
|
|
59
|
-
// const unsubscribe = this._graph.update.on(this.update.emit);
|
|
60
|
-
// this._ctx.onDispose(unsubscribe);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
|
|
6
|
-
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
7
|
-
import { type InterpreterValue } from 'hyperformula/typings/interpreter/InterpreterValue';
|
|
8
|
-
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
9
|
-
import defaultsDeep from 'lodash.defaultsdeep';
|
|
10
|
-
|
|
11
|
-
import { debounce, type UnsubscribeCallback } from '@dxos/async';
|
|
12
|
-
import { type Space } from '@dxos/client/echo';
|
|
13
|
-
import { log } from '@dxos/log';
|
|
14
|
-
|
|
15
|
-
import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from '#hyperformula';
|
|
16
|
-
|
|
17
|
-
// TODO(burdon): Create API gateways:
|
|
18
|
-
// https://publicapis.io
|
|
19
|
-
// https://api-ninjas.com/api/cryptoprice
|
|
20
|
-
// https://developers.google.com/apis-explorer
|
|
21
|
-
// https://publicapis.io/coin-desk-api
|
|
22
|
-
|
|
23
|
-
export type AsyncFunction = (...args: any) => Promise<InterpreterValue>;
|
|
24
|
-
|
|
25
|
-
export type FunctionUpdateEvent = {
|
|
26
|
-
name: string;
|
|
27
|
-
cell: SimpleCellAddress;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type FunctionOptions = {
|
|
31
|
-
ttl?: number;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type FunctionContextOptions = {
|
|
35
|
-
defaultTtl: number;
|
|
36
|
-
debounceDelay: number;
|
|
37
|
-
remoteFunctionUrl: string;
|
|
38
|
-
onUpdate?: (update: FunctionUpdateEvent) => void;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const defaultFunctionContextOptions: FunctionContextOptions = {
|
|
42
|
-
defaultTtl: 5_000,
|
|
43
|
-
debounceDelay: 200,
|
|
44
|
-
remoteFunctionUrl: 'https://edge.dxos.workers.dev/functions', // TODO(burdon): Config.
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The context singleton for the model is passed into custom functions.
|
|
49
|
-
*
|
|
50
|
-
* HyperFormula does not support async functions.
|
|
51
|
-
* - https://hyperformula.handsontable.com/guide/custom-functions.html
|
|
52
|
-
* - https://hyperformula.handsontable.com/guide/known-limitations.html#known-limitations
|
|
53
|
-
* - https://github.com/handsontable/hyperformula/issues/892
|
|
54
|
-
*/
|
|
55
|
-
export class FunctionContext {
|
|
56
|
-
// Mangle name with params.
|
|
57
|
-
static createInvocationKey(name: string, ...args: any) {
|
|
58
|
-
return JSON.stringify({ name, ...args });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// TODO(wittjosiah): Persist cached values.
|
|
62
|
-
// Cached values for cell.
|
|
63
|
-
private readonly _cache = new Map<string, { value: InterpreterValue; ts: number }>();
|
|
64
|
-
|
|
65
|
-
// Active requests.
|
|
66
|
-
private readonly _pending = new Map<string, number>();
|
|
67
|
-
|
|
68
|
-
// Query subscriptions.
|
|
69
|
-
private readonly _subscriptions = new Map<string, UnsubscribeCallback>();
|
|
70
|
-
|
|
71
|
-
// Invocation count.
|
|
72
|
-
private _invocations: Record<string, number> = {};
|
|
73
|
-
|
|
74
|
-
private readonly _options: FunctionContextOptions;
|
|
75
|
-
|
|
76
|
-
// Debounced update handler.
|
|
77
|
-
private readonly _onUpdate: (update: FunctionUpdateEvent) => void;
|
|
78
|
-
|
|
79
|
-
constructor(
|
|
80
|
-
private readonly _hf: HyperFormula,
|
|
81
|
-
private readonly _space: Space | undefined,
|
|
82
|
-
_options?: Partial<FunctionContextOptions>,
|
|
83
|
-
) {
|
|
84
|
-
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
85
|
-
this._onUpdate = debounce((update) => {
|
|
86
|
-
log('update', update);
|
|
87
|
-
// TODO(burdon): Better way to trigger recalculation? (NOTE: rebuildAndRecalculate resets the undo history.)
|
|
88
|
-
this._hf.resumeEvaluation();
|
|
89
|
-
this._options.onUpdate?.(update);
|
|
90
|
-
}, this._options.debounceDelay);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get space() {
|
|
94
|
-
return this._space;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get remoteFunctionUrl() {
|
|
98
|
-
return this._options.remoteFunctionUrl;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get info() {
|
|
102
|
-
return { cache: this._cache.size, invocations: this._invocations };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
flush() {
|
|
106
|
-
this._cache.clear();
|
|
107
|
-
this._invocations = {};
|
|
108
|
-
this._subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
109
|
-
this._subscriptions.clear();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
createSubscription(name: string, unsubscribe: UnsubscribeCallback) {
|
|
113
|
-
this._subscriptions.get(name)?.();
|
|
114
|
-
this._subscriptions.set(name, unsubscribe);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Exec the function if TTL has expired.
|
|
119
|
-
* Return the cached value.
|
|
120
|
-
*/
|
|
121
|
-
invokeFunction(
|
|
122
|
-
name: string,
|
|
123
|
-
state: InterpreterState,
|
|
124
|
-
args: any[],
|
|
125
|
-
cb: AsyncFunction,
|
|
126
|
-
options?: FunctionOptions,
|
|
127
|
-
): InterpreterValue | undefined {
|
|
128
|
-
const ttl = options?.ttl ?? this._options.defaultTtl;
|
|
129
|
-
|
|
130
|
-
const { formulaAddress: cell } = state;
|
|
131
|
-
const invocationKey = FunctionContext.createInvocationKey(name, ...args);
|
|
132
|
-
const { value = undefined, ts = 0 } = this._cache.get(invocationKey) ?? {};
|
|
133
|
-
|
|
134
|
-
const now = Date.now();
|
|
135
|
-
const delta = now - ts;
|
|
136
|
-
if ((!ts || delta > ttl) && !this._pending.has(invocationKey)) {
|
|
137
|
-
this._pending.set(invocationKey, now);
|
|
138
|
-
setTimeout(async () => {
|
|
139
|
-
this._invocations[name] = (this._invocations[name] ?? 0) + 1;
|
|
140
|
-
try {
|
|
141
|
-
// Exec function.
|
|
142
|
-
const value = await cb(...args);
|
|
143
|
-
this._cache.set(invocationKey, { value, ts: Date.now() });
|
|
144
|
-
log('set', { cell, value });
|
|
145
|
-
this._onUpdate({ name, cell });
|
|
146
|
-
} catch (err) {
|
|
147
|
-
// TODO(burdon): Show error to user.
|
|
148
|
-
log.warn('failed', { cell, err });
|
|
149
|
-
this._cache.set(invocationKey, { value: new CellError(ErrorType.ERROR, 'Function failed.'), ts: Date.now() });
|
|
150
|
-
} finally {
|
|
151
|
-
this._pending.delete(invocationKey);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
log('invoke', { cell, name, args, cache: value });
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Base class for async functions.
|
|
163
|
-
*/
|
|
164
|
-
export class AsyncFunctionPlugin extends FunctionPlugin {
|
|
165
|
-
get context() {
|
|
166
|
-
return this.config.context as FunctionContext;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Immediately returns cached value then runs the async function.
|
|
171
|
-
*/
|
|
172
|
-
protected runAsyncFunction(ast: ProcedureAst, state: InterpreterState, cb: AsyncFunction, options?: FunctionOptions) {
|
|
173
|
-
const { procedureName } = ast;
|
|
174
|
-
const metadata = this.metadata(procedureName);
|
|
175
|
-
return this.runFunction(ast.args, state, metadata, (...args: any) => {
|
|
176
|
-
return this.context.invokeFunction(procedureName, state, args, cb, options) ?? EmptyValue;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { effect } from '@preact/signals-core';
|
|
6
|
-
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
7
|
-
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
8
|
-
|
|
9
|
-
import { Filter, getMeta } from '@dxos/client/echo';
|
|
10
|
-
import { log } from '@dxos/log';
|
|
11
|
-
import { getUserFunctionUrlInMetadata } from '@dxos/plugin-script/edge';
|
|
12
|
-
import { FunctionType } from '@dxos/plugin-script/types';
|
|
13
|
-
import { nonNullable } from '@dxos/util';
|
|
14
|
-
|
|
15
|
-
import { CellError, ErrorType, FunctionArgumentType } from '#hyperformula';
|
|
16
|
-
import { type AsyncFunction, AsyncFunctionPlugin } from './async-function';
|
|
17
|
-
|
|
18
|
-
export const EDGE_FUNCTION_NAME = 'DX';
|
|
19
|
-
|
|
20
|
-
const FUNCTION_TTL = 10_000;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A hyperformula function plugin for calling remote (EDGE) functions.
|
|
24
|
-
*
|
|
25
|
-
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
26
|
-
*/
|
|
27
|
-
export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
28
|
-
dx(ast: ProcedureAst, state: InterpreterState) {
|
|
29
|
-
const handler =
|
|
30
|
-
(subscribe = false): AsyncFunction =>
|
|
31
|
-
async (binding: string, ...args: any) => {
|
|
32
|
-
const space = this.context.space;
|
|
33
|
-
if (!space) {
|
|
34
|
-
return new CellError(ErrorType.REF, 'Missing space');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const {
|
|
38
|
-
objects: [fn],
|
|
39
|
-
} = await space.db.query(Filter.schema(FunctionType, { binding })).run();
|
|
40
|
-
if (!fn) {
|
|
41
|
-
log.info('Function not found', { binding });
|
|
42
|
-
return new CellError(ErrorType.REF, 'Function not found');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (subscribe) {
|
|
46
|
-
const unsubscribe = effect(() => {
|
|
47
|
-
log('function changed', { fn });
|
|
48
|
-
const _ = fn?.version;
|
|
49
|
-
|
|
50
|
-
// TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
|
|
51
|
-
// This needs a ttl to prevent a binding change from causing the function not to be found.
|
|
52
|
-
this.runAsyncFunction(ast, state, handler(false), { ttl: FUNCTION_TTL });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const path = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
59
|
-
const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: { 'Content-Type': 'application/json' },
|
|
62
|
-
body: JSON.stringify({ args: args.filter(nonNullable) }),
|
|
63
|
-
});
|
|
64
|
-
const result = await response.text();
|
|
65
|
-
log('function executed', { result });
|
|
66
|
-
|
|
67
|
-
return result;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
EdgeFunctionPlugin.implementedFunctions = {
|
|
75
|
-
[EDGE_FUNCTION_NAME]: {
|
|
76
|
-
method: 'dx',
|
|
77
|
-
parameters: [
|
|
78
|
-
// Binding
|
|
79
|
-
{ argumentType: FunctionArgumentType.STRING },
|
|
80
|
-
|
|
81
|
-
// Remote function arguments (currently supporting up to 8).
|
|
82
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
83
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
84
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
85
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
86
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
87
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
88
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
89
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
90
|
-
],
|
|
91
|
-
isVolatile: true,
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const EdgeFunctionPluginTranslations = {
|
|
96
|
-
enGB: {
|
|
97
|
-
[EDGE_FUNCTION_NAME]: 'Remote function',
|
|
98
|
-
},
|
|
99
|
-
enUS: {
|
|
100
|
-
[EDGE_FUNCTION_NAME]: 'Remote function',
|
|
101
|
-
},
|
|
102
|
-
};
|