@dxos/plugin-automation 0.8.4-main.67995b8 → 0.8.4-main.69d29f4
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/AutomationPanel-FAS6ADCW.mjs +11 -0
- package/dist/lib/browser/AutomationSettings-XN2OIYWL.mjs +56 -0
- package/dist/lib/browser/AutomationSettings-XN2OIYWL.mjs.map +7 -0
- package/dist/lib/browser/FunctionsContainer-6QLC7JP4.mjs +129 -0
- package/dist/lib/browser/FunctionsContainer-6QLC7JP4.mjs.map +7 -0
- package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs → FunctionsPanel-ZX4J75UM.mjs} +3 -3
- package/dist/lib/browser/app-graph-builder-LAQMEBMH.mjs +84 -0
- package/dist/lib/browser/app-graph-builder-LAQMEBMH.mjs.map +7 -0
- package/dist/lib/browser/chunk-54PANILA.mjs +14 -0
- package/dist/lib/browser/chunk-54PANILA.mjs.map +7 -0
- package/dist/lib/browser/chunk-BFUIVUQH.mjs +102 -0
- package/dist/lib/browser/chunk-BFUIVUQH.mjs.map +7 -0
- package/dist/lib/browser/chunk-BKFQBKYO.mjs +8 -0
- package/dist/lib/browser/chunk-BKFQBKYO.mjs.map +7 -0
- package/dist/lib/browser/chunk-JOXPQ27I.mjs +83 -0
- package/dist/lib/browser/chunk-JOXPQ27I.mjs.map +7 -0
- package/dist/lib/browser/chunk-PZNBEKO5.mjs +17 -0
- package/dist/lib/browser/chunk-PZNBEKO5.mjs.map +7 -0
- package/dist/lib/browser/chunk-QW3EM35H.mjs +248 -0
- package/dist/lib/browser/chunk-QW3EM35H.mjs.map +7 -0
- package/dist/lib/browser/chunk-RAF2FJST.mjs +86 -0
- package/dist/lib/browser/chunk-RAF2FJST.mjs.map +7 -0
- package/dist/lib/browser/chunk-YWLEY2FD.mjs +200 -0
- package/dist/lib/browser/chunk-YWLEY2FD.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +1107 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/compute-runtime-WTWLQ67J.mjs +114 -0
- package/dist/lib/browser/compute-runtime-WTWLQ67J.mjs.map +7 -0
- package/dist/lib/browser/hooks/index.mjs +13 -0
- package/dist/lib/browser/index.mjs +67 -46
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-Q3MWOR7K.mjs +82 -0
- package/dist/lib/browser/operation-resolver-Q3MWOR7K.mjs.map +7 -0
- package/dist/lib/browser/{react-surface-4DFSM7OX.mjs → react-surface-EV3AC62F.mjs} +25 -24
- package/dist/lib/browser/react-surface-EV3AC62F.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +10 -4
- package/dist/lib/node-esm/{AutomationPanel-YYUMSK2W.mjs → AutomationPanel-B7NAGDFA.mjs} +4 -4
- package/dist/lib/node-esm/AutomationSettings-M5PMZJ6P.mjs +57 -0
- package/dist/lib/node-esm/AutomationSettings-M5PMZJ6P.mjs.map +7 -0
- package/dist/lib/node-esm/FunctionsContainer-J4O2ULWR.mjs +130 -0
- package/dist/lib/node-esm/FunctionsContainer-J4O2ULWR.mjs.map +7 -0
- package/dist/lib/node-esm/{FunctionsPanel-KGIOZSPZ.mjs → FunctionsPanel-SS6GIVNU.mjs} +3 -3
- package/dist/lib/node-esm/FunctionsPanel-SS6GIVNU.mjs.map +7 -0
- package/dist/lib/node-esm/app-graph-builder-4UCMXHYY.mjs +85 -0
- package/dist/lib/node-esm/app-graph-builder-4UCMXHYY.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2CKVH7JC.mjs +201 -0
- package/dist/lib/node-esm/chunk-2CKVH7JC.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5FXNN3MV.mjs +19 -0
- package/dist/lib/node-esm/chunk-5FXNN3MV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-7QRUPEHH.mjs +16 -0
- package/dist/lib/node-esm/chunk-7QRUPEHH.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HQLVREIX.mjs +87 -0
- package/dist/lib/node-esm/chunk-HQLVREIX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-K7GCM342.mjs +10 -0
- package/dist/lib/node-esm/chunk-K7GCM342.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KWKWOGS5.mjs +103 -0
- package/dist/lib/node-esm/chunk-KWKWOGS5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LJAXQ6CX.mjs +249 -0
- package/dist/lib/node-esm/chunk-LJAXQ6CX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-RX52VKI2.mjs +84 -0
- package/dist/lib/node-esm/chunk-RX52VKI2.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +1108 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/compute-runtime-ZHROOBLY.mjs +115 -0
- package/dist/lib/node-esm/compute-runtime-ZHROOBLY.mjs.map +7 -0
- package/dist/lib/node-esm/hooks/index.mjs +14 -0
- package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +67 -46
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/operation-resolver-R5GA4YNO.mjs +83 -0
- package/dist/lib/node-esm/operation-resolver-R5GA4YNO.mjs.map +7 -0
- package/dist/lib/node-esm/{react-surface-3PNW7NDW.mjs → react-surface-S6VZJCEZ.mjs} +25 -24
- package/dist/lib/node-esm/react-surface-S6VZJCEZ.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +10 -4
- package/dist/types/src/AutomationPlugin.d.ts +2 -1
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-runtime/compute-runtime.d.ts +6 -0
- package/dist/types/src/capabilities/compute-runtime/compute-runtime.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-runtime/index.d.ts +3 -0
- package/dist/types/src/capabilities/compute-runtime/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +4 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/cli/commands/index.d.ts +2 -0
- package/dist/types/src/cli/commands/index.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/create/index.d.ts +25 -0
- package/dist/types/src/cli/commands/trigger/create/index.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/create/queue.d.ts +13 -0
- package/dist/types/src/cli/commands/trigger/create/queue.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/create/subscription.d.ts +15 -0
- package/dist/types/src/cli/commands/trigger/create/subscription.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/create/timer.d.ts +13 -0
- package/dist/types/src/cli/commands/trigger/create/timer.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/index.d.ts +57 -0
- package/dist/types/src/cli/commands/trigger/index.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/list.d.ts +7 -0
- package/dist/types/src/cli/commands/trigger/list.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/options.d.ts +11 -0
- package/dist/types/src/cli/commands/trigger/options.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/remove.d.ts +8 -0
- package/dist/types/src/cli/commands/trigger/remove.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/update/index.d.ts +28 -0
- package/dist/types/src/cli/commands/trigger/update/index.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/update/queue.d.ts +12 -0
- package/dist/types/src/cli/commands/trigger/update/queue.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/update/subscription.d.ts +13 -0
- package/dist/types/src/cli/commands/trigger/update/subscription.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/update/timer.d.ts +11 -0
- package/dist/types/src/cli/commands/trigger/update/timer.d.ts.map +1 -0
- package/dist/types/src/cli/commands/trigger/util.d.ts +46 -0
- package/dist/types/src/cli/commands/trigger/util.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +2 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/plugin.d.ts +3 -0
- package/dist/types/src/cli/plugin.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +7 -6
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +49 -4
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -1
- package/dist/types/src/components/AutomationSettings.d.ts +5 -0
- package/dist/types/src/components/AutomationSettings.d.ts.map +1 -0
- package/dist/types/src/components/FunctionsContainer.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsPanel/FunctionsPanel.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts +8 -0
- package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts.map +1 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts +2 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts.map +1 -0
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts +12 -9
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts +6 -3
- package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +11 -8
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +117 -4
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TriggerSettings.d.ts +6 -0
- package/dist/types/src/components/TriggerSettings.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts +12 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts.map +1 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts +11 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/testing/test-functions.d.ts +202 -3
- package/dist/types/src/testing/test-functions.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +22 -0
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/events.d.ts +5 -0
- package/dist/types/src/types/events.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +31 -2
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +80 -45
- package/src/AutomationPlugin.tsx +18 -32
- package/src/capabilities/app-graph-builder/app-graph-builder.ts +71 -0
- package/src/capabilities/app-graph-builder/index.ts +7 -0
- package/src/capabilities/compute-runtime/compute-runtime.ts +133 -0
- package/src/capabilities/compute-runtime/index.ts +7 -0
- package/src/capabilities/index.ts +4 -5
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +79 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +60 -0
- package/src/cli/commands/index.ts +5 -0
- package/src/cli/commands/trigger/create/index.ts +14 -0
- package/src/cli/commands/trigger/create/queue.ts +89 -0
- package/src/cli/commands/trigger/create/subscription.ts +128 -0
- package/src/cli/commands/trigger/create/timer.ts +93 -0
- package/src/cli/commands/trigger/index.ts +16 -0
- package/src/cli/commands/trigger/list.ts +67 -0
- package/src/cli/commands/trigger/options.ts +59 -0
- package/src/cli/commands/trigger/remove.ts +45 -0
- package/src/cli/commands/trigger/update/index.ts +14 -0
- package/src/cli/commands/trigger/update/queue.ts +195 -0
- package/src/cli/commands/trigger/update/subscription.ts +278 -0
- package/src/cli/commands/trigger/update/timer.ts +193 -0
- package/src/cli/commands/trigger/util.ts +395 -0
- package/src/cli/index.ts +5 -0
- package/src/cli/plugin.ts +23 -0
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +16 -17
- package/src/components/AutomationPanel/AutomationPanel.tsx +139 -59
- package/src/components/AutomationSettings.tsx +30 -0
- package/src/components/FunctionsContainer.tsx +18 -13
- package/src/components/FunctionsPanel/FunctionsPanel.tsx +33 -19
- package/src/components/FunctionsRegistry/FunctionsRegistry.tsx +111 -0
- package/src/components/FunctionsRegistry/index.ts +5 -0
- package/src/components/TriggerEditor/FunctionInputEditor.tsx +33 -35
- package/src/components/TriggerEditor/SpecSelector.tsx +29 -21
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +78 -32
- package/src/components/TriggerEditor/TriggerEditor.tsx +81 -48
- package/src/components/TriggerSettings.tsx +25 -0
- package/src/components/index.ts +1 -1
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useComputeRuntimeCallback.ts +67 -0
- package/src/hooks/useTriggerRuntimeControls.ts +53 -0
- package/src/index.ts +2 -0
- package/src/meta.ts +8 -7
- package/src/testing/test-functions.ts +3 -3
- package/src/translations.ts +9 -0
- package/src/types/capabilities.ts +42 -0
- package/src/types/events.ts +11 -0
- package/src/types/index.ts +2 -0
- package/src/types/schema.ts +24 -3
- package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs +0 -38
- package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs.map +0 -7
- package/dist/lib/browser/AutomationPanel-ZWA6GOFY.mjs +0 -11
- package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs +0 -39
- package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-ZTAUTFI4.mjs +0 -80
- package/dist/lib/browser/app-graph-builder-ZTAUTFI4.mjs.map +0 -7
- package/dist/lib/browser/chunk-ECSTS2UI.mjs +0 -14
- package/dist/lib/browser/chunk-ECSTS2UI.mjs.map +0 -7
- package/dist/lib/browser/chunk-ERTIGJYE.mjs +0 -147
- package/dist/lib/browser/chunk-ERTIGJYE.mjs.map +0 -7
- package/dist/lib/browser/chunk-FSJZXTS2.mjs +0 -230
- package/dist/lib/browser/chunk-FSJZXTS2.mjs.map +0 -7
- package/dist/lib/browser/chunk-GW5U2DGT.mjs +0 -15
- package/dist/lib/browser/chunk-GW5U2DGT.mjs.map +0 -7
- package/dist/lib/browser/chunk-HN7OHFCB.mjs +0 -38
- package/dist/lib/browser/chunk-HN7OHFCB.mjs.map +0 -7
- package/dist/lib/browser/chunk-LYJVTIVD.mjs +0 -94
- package/dist/lib/browser/chunk-LYJVTIVD.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-U3ZAQEFW.mjs +0 -76
- package/dist/lib/browser/intent-resolver-U3ZAQEFW.mjs.map +0 -7
- package/dist/lib/browser/react-surface-4DFSM7OX.mjs.map +0 -7
- package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs +0 -39
- package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs.map +0 -7
- package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs +0 -40
- package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-3FP63ZSG.mjs +0 -81
- package/dist/lib/node-esm/app-graph-builder-3FP63ZSG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AZH66CED.mjs +0 -231
- package/dist/lib/node-esm/chunk-AZH66CED.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HIMYPGHF.mjs +0 -148
- package/dist/lib/node-esm/chunk-HIMYPGHF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NK5N3QKD.mjs +0 -17
- package/dist/lib/node-esm/chunk-NK5N3QKD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OEZNHUL2.mjs +0 -39
- package/dist/lib/node-esm/chunk-OEZNHUL2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SGZPTJ47.mjs +0 -16
- package/dist/lib/node-esm/chunk-SGZPTJ47.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZGPUV5VS.mjs +0 -95
- package/dist/lib/node-esm/chunk-ZGPUV5VS.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-3QWXEBPX.mjs +0 -77
- package/dist/lib/node-esm/intent-resolver-3QWXEBPX.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-3PNW7NDW.mjs.map +0 -7
- package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/AutomationContainer.d.ts +0 -5
- package/dist/types/src/components/AutomationContainer.d.ts.map +0 -1
- package/src/capabilities/app-graph-builder.ts +0 -86
- package/src/capabilities/intent-resolver.ts +0 -72
- package/src/capabilities/react-surface.tsx +0 -56
- package/src/components/AutomationContainer.tsx +0 -30
- /package/dist/lib/browser/{AutomationPanel-ZWA6GOFY.mjs.map → AutomationPanel-FAS6ADCW.mjs.map} +0 -0
- /package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs.map → FunctionsPanel-ZX4J75UM.mjs.map} +0 -0
- /package/dist/lib/{node-esm/AutomationPanel-YYUMSK2W.mjs.map → browser/hooks/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{FunctionsPanel-KGIOZSPZ.mjs.map → AutomationPanel-B7NAGDFA.mjs.map} +0 -0
|
@@ -2,60 +2,71 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
TriggerKind,
|
|
16
|
-
} from '@dxos/functions';
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as EFn from 'effect/Function';
|
|
7
|
+
import * as Match from 'effect/Match';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
9
|
+
import React, { useMemo, useState } from 'react';
|
|
10
|
+
|
|
11
|
+
import { Filter, Obj, Tag } from '@dxos/echo';
|
|
12
|
+
import { Function, Script, Trigger } from '@dxos/functions';
|
|
13
|
+
import { FunctionsServiceClient } from '@dxos/functions-runtime/edge';
|
|
14
|
+
import { useTypeOptions } from '@dxos/plugin-space';
|
|
17
15
|
import { type Client, useClient } from '@dxos/react-client';
|
|
18
|
-
import {
|
|
19
|
-
import { Clipboard, IconButton, Input, Separator, useTranslation } from '@dxos/react-ui';
|
|
16
|
+
import { type Space, useQuery } from '@dxos/react-client/echo';
|
|
17
|
+
import { Clipboard, IconButton, Input, Separator, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
20
18
|
import { ControlItem, controlItemClasses } from '@dxos/react-ui-form';
|
|
21
19
|
import { List } from '@dxos/react-ui-list';
|
|
22
|
-
import {
|
|
20
|
+
import { Project } from '@dxos/types';
|
|
21
|
+
import { ghostHover, mx } from '@dxos/ui-theme';
|
|
22
|
+
import { isNonNullable } from '@dxos/util';
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { meta } from '../../meta';
|
|
25
25
|
import { TriggerEditor, type TriggerEditorProps } from '../TriggerEditor';
|
|
26
26
|
|
|
27
|
-
const grid = 'grid grid-cols-[
|
|
27
|
+
const grid = 'grid grid-cols-[40px_1fr_32px_32px] min-bs-[2.5rem]';
|
|
28
28
|
|
|
29
|
-
export type AutomationPanelProps = {
|
|
29
|
+
export type AutomationPanelProps = ThemedClassName<{
|
|
30
30
|
space: Space;
|
|
31
|
-
object?: Obj.
|
|
32
|
-
initialTrigger?:
|
|
31
|
+
object?: Obj.Unknown;
|
|
32
|
+
initialTrigger?: Trigger.Trigger;
|
|
33
33
|
onDone?: () => void;
|
|
34
|
-
}
|
|
34
|
+
}>;
|
|
35
35
|
|
|
36
36
|
// TODO(burdon): Factor out common layout with ViewEditor.
|
|
37
|
-
export const AutomationPanel = ({ space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
38
|
-
const { t } = useTranslation(
|
|
37
|
+
export const AutomationPanel = ({ classNames, space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
38
|
+
const { t } = useTranslation(meta.id);
|
|
39
39
|
const client = useClient();
|
|
40
|
-
const
|
|
41
|
-
const functions = useQuery(space, Filter.type(
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const functionsServiceClient = useMemo(() => FunctionsServiceClient.fromClient(client), [client]);
|
|
41
|
+
const functions = useQuery(space.db, Filter.type(Function.Function));
|
|
42
|
+
const triggers = useQuery(space.db, Filter.type(Trigger.Trigger));
|
|
43
|
+
const filteredTriggers = useMemo(() => {
|
|
44
|
+
return object ? triggers.filter(triggerMatch(object)) : triggers;
|
|
45
|
+
}, [object, triggers]);
|
|
46
|
+
const tags = useQuery(space.db, Filter.type(Tag.Tag));
|
|
47
|
+
const types = useTypeOptions({
|
|
48
|
+
space,
|
|
49
|
+
annotation: {
|
|
50
|
+
location: ['database', 'runtime'],
|
|
51
|
+
kind: ['user'],
|
|
52
|
+
registered: ['registered'],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const [trigger, setTrigger] = useState<Trigger.Trigger | undefined>(initialTrigger);
|
|
57
|
+
const [selected, setSelected] = useState<Trigger.Trigger>();
|
|
58
|
+
|
|
59
|
+
const handleSelect = (trigger: Trigger.Trigger) => {
|
|
60
|
+
setTrigger(trigger);
|
|
50
61
|
setSelected(trigger);
|
|
51
62
|
};
|
|
52
63
|
|
|
53
64
|
const handleAdd = () => {
|
|
54
|
-
setTrigger(
|
|
65
|
+
setTrigger(Trigger.make({}));
|
|
55
66
|
setSelected(undefined);
|
|
56
67
|
};
|
|
57
68
|
|
|
58
|
-
const handleDelete = (trigger:
|
|
69
|
+
const handleDelete = (trigger: Trigger.Trigger) => {
|
|
59
70
|
space.db.remove(trigger);
|
|
60
71
|
setTrigger(undefined);
|
|
61
72
|
setSelected(undefined);
|
|
@@ -65,7 +76,7 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
65
76
|
if (selected) {
|
|
66
77
|
Object.assign(selected, trigger);
|
|
67
78
|
} else {
|
|
68
|
-
space.db.add(
|
|
79
|
+
space.db.add(Trigger.make(trigger));
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
setTrigger(undefined);
|
|
@@ -78,41 +89,61 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
78
89
|
onDone?.();
|
|
79
90
|
};
|
|
80
91
|
|
|
92
|
+
const handleForceRunTrigger = async (trigger: Trigger.Trigger) => {
|
|
93
|
+
await functionsServiceClient.forceRunCronTrigger(space.id, trigger.id);
|
|
94
|
+
};
|
|
95
|
+
|
|
81
96
|
if (trigger) {
|
|
82
97
|
return (
|
|
83
98
|
<ControlItem title={t('trigger editor title')}>
|
|
84
|
-
<TriggerEditor
|
|
99
|
+
<TriggerEditor
|
|
100
|
+
db={space.db}
|
|
101
|
+
trigger={trigger}
|
|
102
|
+
readonlySpec={Boolean(object)}
|
|
103
|
+
tags={tags}
|
|
104
|
+
types={types}
|
|
105
|
+
onSave={handleSave}
|
|
106
|
+
onCancel={handleCancel}
|
|
107
|
+
/>
|
|
85
108
|
</ControlItem>
|
|
86
109
|
);
|
|
87
110
|
}
|
|
88
111
|
|
|
89
112
|
return (
|
|
90
|
-
<div className={controlItemClasses}>
|
|
91
|
-
{
|
|
92
|
-
<List.Root<
|
|
93
|
-
{
|
|
94
|
-
|
|
95
|
-
|
|
113
|
+
<div className={mx(controlItemClasses, classNames)}>
|
|
114
|
+
{filteredTriggers.length > 0 && (
|
|
115
|
+
<List.Root<Trigger.Trigger>
|
|
116
|
+
items={filteredTriggers}
|
|
117
|
+
isItem={Schema.is(Trigger.Trigger)}
|
|
118
|
+
getId={(field) => field.id}
|
|
119
|
+
>
|
|
120
|
+
{({ items: filteredTriggers }) => (
|
|
121
|
+
<div role='list' className='flex flex-col is-full'>
|
|
122
|
+
{filteredTriggers?.map((trigger) => {
|
|
96
123
|
const copyAction = getCopyAction(client, trigger);
|
|
97
124
|
return (
|
|
98
|
-
<List.Item<
|
|
125
|
+
<List.Item<Trigger.Trigger>
|
|
99
126
|
key={trigger.id}
|
|
100
127
|
item={trigger}
|
|
101
|
-
classNames={mx(grid, ghostHover, 'items-center', '
|
|
128
|
+
classNames={mx(grid, ghostHover, 'items-center', 'pli-2')}
|
|
102
129
|
>
|
|
103
130
|
<Input.Root>
|
|
104
131
|
<Input.Switch
|
|
105
132
|
checked={trigger.enabled}
|
|
106
|
-
onCheckedChange={(checked) =>
|
|
133
|
+
onCheckedChange={(checked) =>
|
|
134
|
+
Obj.change(trigger, (t) => {
|
|
135
|
+
t.enabled = checked;
|
|
136
|
+
})
|
|
137
|
+
}
|
|
107
138
|
/>
|
|
108
139
|
</Input.Root>
|
|
109
140
|
|
|
110
141
|
<div className={'flex'}>
|
|
111
142
|
<List.ItemTitle
|
|
112
|
-
classNames='
|
|
143
|
+
classNames='pli-1 cursor-pointer is-0 shrink truncate'
|
|
113
144
|
onClick={() => handleSelect(trigger)}
|
|
114
145
|
>
|
|
115
|
-
{getFunctionName(
|
|
146
|
+
{getFunctionName(functions, trigger) ?? '∅'}
|
|
116
147
|
</List.ItemTitle>
|
|
117
148
|
|
|
118
149
|
{/* TODO: a better way to expose copy action */}
|
|
@@ -124,6 +155,14 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
124
155
|
)}
|
|
125
156
|
</div>
|
|
126
157
|
|
|
158
|
+
<List.ItemButton
|
|
159
|
+
autoHide={false}
|
|
160
|
+
disabled={!trigger.enabled || trigger.spec?.kind !== 'timer'}
|
|
161
|
+
icon='ph--play--regular'
|
|
162
|
+
label='Force run'
|
|
163
|
+
onClick={() => handleForceRunTrigger(trigger)}
|
|
164
|
+
/>
|
|
165
|
+
|
|
127
166
|
<List.ItemDeleteButton onClick={() => handleDelete(trigger)} />
|
|
128
167
|
</List.Item>
|
|
129
168
|
);
|
|
@@ -132,40 +171,81 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
132
171
|
)}
|
|
133
172
|
</List.Root>
|
|
134
173
|
)}
|
|
135
|
-
{
|
|
174
|
+
{filteredTriggers.length > 0 && <Separator classNames='mlb-4' />}
|
|
136
175
|
<IconButton icon='ph--plus--regular' label={t('new trigger label')} onClick={handleAdd} />
|
|
137
176
|
</div>
|
|
138
177
|
);
|
|
139
178
|
};
|
|
140
179
|
|
|
141
|
-
const getCopyAction = (client: Client, trigger:
|
|
142
|
-
if (trigger?.spec?.kind ===
|
|
143
|
-
return {
|
|
180
|
+
const getCopyAction = (client: Client, trigger: Trigger.Trigger | undefined) => {
|
|
181
|
+
if (trigger?.spec?.kind === 'email') {
|
|
182
|
+
return {
|
|
183
|
+
translationKey: 'trigger copy email',
|
|
184
|
+
contentProvider: () => `${Obj.getDatabase(trigger)!.spaceId}@dxos.network`,
|
|
185
|
+
};
|
|
144
186
|
}
|
|
145
187
|
|
|
146
|
-
if (trigger?.spec?.kind ===
|
|
188
|
+
if (trigger?.spec?.kind === 'webhook') {
|
|
147
189
|
return { translationKey: 'trigger copy url', contentProvider: () => getWebhookUrl(client, trigger) };
|
|
148
190
|
}
|
|
149
191
|
|
|
150
192
|
return undefined;
|
|
151
193
|
};
|
|
152
194
|
|
|
153
|
-
const getWebhookUrl = (client: Client, trigger:
|
|
154
|
-
const spaceId =
|
|
195
|
+
const getWebhookUrl = (client: Client, trigger: Trigger.Trigger) => {
|
|
196
|
+
const spaceId = Obj.getDatabase(trigger)!.spaceId;
|
|
155
197
|
const edgeUrl = new URL(client.config.values.runtime!.services!.edge!.url!);
|
|
156
198
|
const isSecure = edgeUrl.protocol.startsWith('https') || edgeUrl.protocol.startsWith('wss');
|
|
157
199
|
edgeUrl.protocol = isSecure ? 'https' : 'http';
|
|
158
200
|
return new URL(`/webhook/${spaceId}:${trigger.id}`, edgeUrl).toString();
|
|
159
201
|
};
|
|
160
202
|
|
|
161
|
-
const getFunctionName = (
|
|
203
|
+
const getFunctionName = (functions: Function.Function[], trigger: Trigger.Trigger) => {
|
|
162
204
|
// TODO(wittjosiah): Truncation should be done in the UI.
|
|
163
205
|
// Warning that the List component is currently a can of worms.
|
|
164
206
|
const shortId = trigger.function && `${trigger.function.dxn.toString().slice(0, 16)}…`;
|
|
165
207
|
const functionObject = functions.find((fn) => fn === trigger.function?.target);
|
|
166
|
-
|
|
167
|
-
|
|
208
|
+
return functionObject?.name ?? shortId;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const scriptMatch = (script: Script.Script) => (trigger: Trigger.Trigger) => {
|
|
212
|
+
const fn = trigger.function?.target;
|
|
213
|
+
if (!Obj.instanceOf(Function.Function, fn)) {
|
|
214
|
+
return false;
|
|
168
215
|
}
|
|
169
216
|
|
|
170
|
-
return
|
|
217
|
+
return fn.source?.target === script;
|
|
171
218
|
};
|
|
219
|
+
|
|
220
|
+
const projectMatch = (project: Project.Project) => {
|
|
221
|
+
const viewQueries = EFn.pipe(
|
|
222
|
+
project.columns,
|
|
223
|
+
Array.map((column) => column.view.target),
|
|
224
|
+
Array.filter(isNonNullable),
|
|
225
|
+
Array.map((view) => Obj.getSnapshot(view).query.ast),
|
|
226
|
+
Array.map((ast) => JSON.stringify(ast)),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
return (trigger: Trigger.Trigger) => {
|
|
230
|
+
const spec = Obj.getSnapshot(trigger).spec;
|
|
231
|
+
if (spec?.kind !== 'subscription') {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// TODO(wittjosiah): Implement better way of comparing query ASTs.
|
|
236
|
+
return viewQueries.some((query) => JSON.stringify(spec.query) === query);
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const triggerMatch = Match.type<Obj.Unknown>().pipe(
|
|
241
|
+
Match.withReturnType<(trigger: Trigger.Trigger) => boolean>(),
|
|
242
|
+
Match.when(
|
|
243
|
+
(obj) => Obj.instanceOf(Script.Script, obj),
|
|
244
|
+
(obj) => scriptMatch(obj),
|
|
245
|
+
),
|
|
246
|
+
Match.when(
|
|
247
|
+
(obj) => Obj.instanceOf(Project.Project, obj),
|
|
248
|
+
(obj) => projectMatch(obj),
|
|
249
|
+
),
|
|
250
|
+
Match.orElse((_obj) => () => true),
|
|
251
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
8
|
+
import { ControlPage, ControlSection } from '@dxos/react-ui-form';
|
|
9
|
+
|
|
10
|
+
import { meta } from '../meta';
|
|
11
|
+
|
|
12
|
+
import { AutomationPanel, type AutomationPanelProps } from './AutomationPanel';
|
|
13
|
+
import { TriggersSettings } from './TriggerSettings';
|
|
14
|
+
|
|
15
|
+
export const AutomationSettings = (props: AutomationPanelProps) => {
|
|
16
|
+
const { t } = useTranslation(meta.id);
|
|
17
|
+
return (
|
|
18
|
+
<ControlPage>
|
|
19
|
+
<ControlSection
|
|
20
|
+
title={t('automation verbose label', { ns: meta.id })}
|
|
21
|
+
description={t('automation description', { ns: meta.id })}
|
|
22
|
+
>
|
|
23
|
+
<AutomationPanel {...props} />
|
|
24
|
+
<TriggersSettings db={props.space.db} />
|
|
25
|
+
</ControlSection>
|
|
26
|
+
</ControlPage>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default AutomationSettings;
|
|
@@ -7,24 +7,29 @@ import React from 'react';
|
|
|
7
7
|
import { type Space } from '@dxos/react-client/echo';
|
|
8
8
|
import { useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { ControlPage, ControlSection } from '@dxos/react-ui-form';
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
import { meta } from '../meta';
|
|
11
12
|
|
|
12
13
|
import { FunctionsPanel } from './FunctionsPanel';
|
|
13
|
-
import {
|
|
14
|
+
import { FunctionsRegistry } from './FunctionsRegistry';
|
|
14
15
|
|
|
15
16
|
export const FunctionsContainer = ({ space }: { space: Space }) => {
|
|
16
|
-
const { t } = useTranslation(
|
|
17
|
+
const { t } = useTranslation(meta.id);
|
|
17
18
|
return (
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
<ControlPage>
|
|
20
|
+
<ControlSection
|
|
21
|
+
title={t('functions verbose label', { ns: meta.id })}
|
|
22
|
+
description={t('functions description', { ns: meta.id })}
|
|
23
|
+
>
|
|
24
|
+
<FunctionsPanel space={space} />
|
|
25
|
+
</ControlSection>
|
|
26
|
+
<ControlSection
|
|
27
|
+
title={t('functions registry verbose label', { ns: meta.id })}
|
|
28
|
+
description={t('functions registry description', { ns: meta.id })}
|
|
29
|
+
>
|
|
30
|
+
<FunctionsRegistry space={space} />
|
|
31
|
+
</ControlSection>
|
|
32
|
+
</ControlPage>
|
|
28
33
|
);
|
|
29
34
|
};
|
|
30
35
|
|
|
@@ -2,18 +2,21 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useCallback, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { Common } from '@dxos/app-framework';
|
|
9
|
+
import { useOperationInvoker } from '@dxos/app-framework/react';
|
|
10
|
+
import { Obj } from '@dxos/echo';
|
|
11
|
+
import { Function, Script } from '@dxos/functions';
|
|
12
|
+
import { SpaceOperation } from '@dxos/plugin-space/types';
|
|
13
|
+
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
14
|
+
import { Button, IconButton, useTranslation } from '@dxos/react-ui';
|
|
12
15
|
import { controlItemClasses } from '@dxos/react-ui-form';
|
|
13
16
|
import { List } from '@dxos/react-ui-list';
|
|
14
|
-
import { ghostHover, mx } from '@dxos/
|
|
17
|
+
import { ghostHover, mx } from '@dxos/ui-theme';
|
|
15
18
|
|
|
16
|
-
import {
|
|
19
|
+
import { meta } from '../../meta';
|
|
17
20
|
|
|
18
21
|
const grid = 'grid grid-cols-[1fr_auto] min-bs-[2.5rem]';
|
|
19
22
|
|
|
@@ -22,10 +25,10 @@ export type FunctionsPanelProps = {
|
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
25
|
-
const { t } = useTranslation(
|
|
26
|
-
const functions = useQuery(space, Filter.type(
|
|
27
|
-
const scripts = useQuery(space, Filter.type(
|
|
28
|
-
const {
|
|
28
|
+
const { t } = useTranslation(meta.id);
|
|
29
|
+
const functions = useQuery(space.db, Filter.type(Function.Function));
|
|
30
|
+
const scripts = useQuery(space.db, Filter.type(Script.Script));
|
|
31
|
+
const { invokePromise } = useOperationInvoker();
|
|
29
32
|
|
|
30
33
|
const functionToScriptMap = useMemo(
|
|
31
34
|
() =>
|
|
@@ -40,13 +43,13 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
40
43
|
}
|
|
41
44
|
return map;
|
|
42
45
|
},
|
|
43
|
-
{} as Record<string,
|
|
46
|
+
{} as Record<string, Script.Script>,
|
|
44
47
|
),
|
|
45
48
|
[functions, scripts],
|
|
46
49
|
);
|
|
47
50
|
|
|
48
51
|
const getScriptName = useCallback(
|
|
49
|
-
(func:
|
|
52
|
+
(func: Function.Function) => {
|
|
50
53
|
const script = functionToScriptMap[func.id];
|
|
51
54
|
return script?.name;
|
|
52
55
|
},
|
|
@@ -54,23 +57,28 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
54
57
|
);
|
|
55
58
|
|
|
56
59
|
const handleGoToScript = useCallback(
|
|
57
|
-
(func:
|
|
60
|
+
(func: Function.Function) => {
|
|
58
61
|
const script = functionToScriptMap[func.id];
|
|
59
62
|
if (script) {
|
|
60
|
-
void
|
|
63
|
+
void invokePromise(Common.LayoutOperation.Open, { subject: [Obj.getDXN(script).toString()] });
|
|
61
64
|
}
|
|
62
65
|
},
|
|
63
|
-
[functionToScriptMap,
|
|
66
|
+
[functionToScriptMap, invokePromise],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const handleDelete = useCallback(
|
|
70
|
+
(func: Function.Function) => invokePromise(SpaceOperation.RemoveObjects, { objects: [func] }),
|
|
71
|
+
[invokePromise],
|
|
64
72
|
);
|
|
65
73
|
|
|
66
74
|
return (
|
|
67
75
|
<div role='none' className={mx(controlItemClasses)}>
|
|
68
76
|
{functions.length > 0 && (
|
|
69
|
-
<List.Root<
|
|
77
|
+
<List.Root<Function.Function> items={functions} isItem={Schema.is(Function.Function)} getId={(func) => func.id}>
|
|
70
78
|
{({ items }) => (
|
|
71
|
-
<div role='list' className='flex flex-col
|
|
79
|
+
<div role='list' className='flex flex-col is-full'>
|
|
72
80
|
{items?.map((func) => (
|
|
73
|
-
<List.Item<
|
|
81
|
+
<List.Item<Function.Function>
|
|
74
82
|
key={func.id}
|
|
75
83
|
item={func}
|
|
76
84
|
classNames={mx(grid, ghostHover, 'items-center', 'pli-2', 'min-bs-[3rem]')}
|
|
@@ -84,6 +92,12 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
84
92
|
{functionToScriptMap[func.id] && (
|
|
85
93
|
<Button onClick={() => handleGoToScript(func)}>{t('go to function source button label')}</Button>
|
|
86
94
|
)}
|
|
95
|
+
<IconButton
|
|
96
|
+
iconOnly
|
|
97
|
+
icon='ph--trash--regular'
|
|
98
|
+
label={t('delete function button label')}
|
|
99
|
+
onClick={() => handleDelete(func)}
|
|
100
|
+
/>
|
|
87
101
|
</List.Item>
|
|
88
102
|
))}
|
|
89
103
|
</div>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import React, { useCallback } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Function } from '@dxos/functions';
|
|
10
|
+
import { getDeployedFunctions } from '@dxos/functions-runtime/edge';
|
|
11
|
+
import { useClient } from '@dxos/react-client';
|
|
12
|
+
import { Filter, Query, type Space, useQuery } from '@dxos/react-client/echo';
|
|
13
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
14
|
+
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
15
|
+
import { controlItemClasses } from '@dxos/react-ui-form';
|
|
16
|
+
import { List } from '@dxos/react-ui-list';
|
|
17
|
+
import { ghostHover, mx } from '@dxos/ui-theme';
|
|
18
|
+
|
|
19
|
+
import { meta } from '../../meta';
|
|
20
|
+
|
|
21
|
+
const grid = 'grid grid-cols-[1fr_1fr_auto] min-bs-[2.5rem]';
|
|
22
|
+
|
|
23
|
+
type FunctionsRegistryProps = {
|
|
24
|
+
space: Space;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const FunctionsRegistry = ({ space }: FunctionsRegistryProps) => {
|
|
28
|
+
const client = useClient();
|
|
29
|
+
const [loading, setLoading] = useState(true);
|
|
30
|
+
const [functions, setFunctions] = useState<Function.Function[]>([]);
|
|
31
|
+
const { t } = useTranslation(meta.id);
|
|
32
|
+
|
|
33
|
+
const dbFunctions = useQuery(space.db, Filter.type(Function.Function));
|
|
34
|
+
|
|
35
|
+
const state = (func: Function.Function) => {
|
|
36
|
+
const dbFunction = dbFunctions.find((f) => f.key === func.key);
|
|
37
|
+
if (!dbFunction) {
|
|
38
|
+
return 'import';
|
|
39
|
+
}
|
|
40
|
+
if (dbFunction.version === func.version && dbFunction.updated === func.updated) {
|
|
41
|
+
return 'none';
|
|
42
|
+
}
|
|
43
|
+
return 'update';
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
useAsyncEffect(async () => {
|
|
47
|
+
setLoading(true);
|
|
48
|
+
const functions = await getDeployedFunctions(client, true);
|
|
49
|
+
setFunctions(functions);
|
|
50
|
+
setLoading(false);
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
const hanleImportOrUpdate = useCallback(
|
|
54
|
+
async (func: Function.Function) => {
|
|
55
|
+
const functions = await space.db.query(Query.type(Function.Function, { key: func.key })).run();
|
|
56
|
+
const [existingFunc] = functions;
|
|
57
|
+
if (!existingFunc) {
|
|
58
|
+
space.db.add(func);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
Function.setFrom(existingFunc, func);
|
|
62
|
+
},
|
|
63
|
+
[space],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div role='none' className={mx(controlItemClasses)}>
|
|
68
|
+
{functions.length > 0 && (
|
|
69
|
+
<List.Root<Function.Function> items={functions} isItem={Schema.is(Function.Function)} getId={(func) => func.id}>
|
|
70
|
+
{({ items }) => (
|
|
71
|
+
<div role='list' className='flex flex-col is-full'>
|
|
72
|
+
{items?.map((func) => (
|
|
73
|
+
<List.Item<Function.Function>
|
|
74
|
+
key={func.id}
|
|
75
|
+
item={func}
|
|
76
|
+
classNames={mx(grid, ghostHover, 'items-center', 'pli-2', 'min-bs-[3rem]')}
|
|
77
|
+
>
|
|
78
|
+
<div className='flex flex-col truncate'>
|
|
79
|
+
<List.ItemTitle classNames='truncate'>{func.name}</List.ItemTitle>
|
|
80
|
+
<div className='text-xs text-description truncate'>{func.key}</div>
|
|
81
|
+
</div>
|
|
82
|
+
<div className='flex flex-col truncate'>
|
|
83
|
+
<div className='text-xs text-description truncate'>{func.version}</div>
|
|
84
|
+
<div className='text-xs text-description truncate'>
|
|
85
|
+
{func.updated ? `Uploaded ${new Date(func.updated).toLocaleString()}` : ''}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<IconButton
|
|
90
|
+
iconOnly
|
|
91
|
+
icon={state(func) === 'update' ? 'ph--arrows-clockwise--regular' : 'ph--download--regular'}
|
|
92
|
+
label={
|
|
93
|
+
state(func) === 'update' ? t('update function button label') : t('import function button label')
|
|
94
|
+
}
|
|
95
|
+
disabled={state(func) === 'none'}
|
|
96
|
+
onClick={() => hanleImportOrUpdate(func)}
|
|
97
|
+
/>
|
|
98
|
+
</List.Item>
|
|
99
|
+
))}
|
|
100
|
+
</div>
|
|
101
|
+
)}
|
|
102
|
+
</List.Root>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{functions.length === 0 && !loading && (
|
|
106
|
+
<div className='text-center plb-4 text-gray-500'>{t('no functions found')}</div>
|
|
107
|
+
)}
|
|
108
|
+
{loading && <div className='text-center plb-4 text-gray-500'>{t('loading functions')}</div>}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
};
|