@dxos/app-framework 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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/.storybook/main.mts +2 -4
- package/.storybook/preview.mts +2 -2
- package/dist/lib/browser/capability-Q5XRXRD2.mjs +38 -0
- package/dist/lib/browser/capability-Q5XRXRD2.mjs.map +7 -0
- package/dist/lib/browser/capability-V7LR4LQN.mjs +35 -0
- package/dist/lib/browser/capability-V7LR4LQN.mjs.map +7 -0
- package/dist/lib/browser/chunk-23D4SJUE.mjs +42 -0
- package/dist/lib/browser/chunk-23D4SJUE.mjs.map +7 -0
- package/dist/lib/browser/chunk-3JWJXGLK.mjs +79 -0
- package/dist/lib/browser/chunk-3JWJXGLK.mjs.map +7 -0
- package/dist/lib/browser/chunk-3ZS2A3DN.mjs +907 -0
- package/dist/lib/browser/chunk-3ZS2A3DN.mjs.map +7 -0
- package/dist/lib/browser/chunk-45CHLTBV.mjs +34 -0
- package/dist/lib/browser/chunk-45CHLTBV.mjs.map +7 -0
- package/dist/lib/browser/chunk-5LAIGWLU.mjs +467 -0
- package/dist/lib/browser/chunk-5LAIGWLU.mjs.map +7 -0
- package/dist/lib/browser/chunk-66IXTIVK.mjs +48 -0
- package/dist/lib/browser/chunk-66IXTIVK.mjs.map +7 -0
- package/dist/lib/browser/chunk-FJ4765WW.mjs +8 -0
- package/dist/lib/browser/chunk-FJ4765WW.mjs.map +7 -0
- package/dist/lib/browser/chunk-G7SDBRKH.mjs +1 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-JXCBZSBJ.mjs +372 -0
- package/dist/lib/browser/chunk-JXCBZSBJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-MX5DKEJH.mjs +584 -0
- package/dist/lib/browser/chunk-MX5DKEJH.mjs.map +7 -0
- package/dist/lib/browser/chunk-WBHCSOBW.mjs +80 -0
- package/dist/lib/browser/chunk-WBHCSOBW.mjs.map +7 -0
- package/dist/lib/browser/chunk-Z55LVAGN.mjs +213 -0
- package/dist/lib/browser/chunk-Z55LVAGN.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZGJAZSNE.mjs +142 -0
- package/dist/lib/browser/chunk-ZGJAZSNE.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +74 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/common/activation-events.mjs +24 -0
- package/dist/lib/browser/common/capabilities.mjs +46 -0
- package/dist/lib/browser/core/activation-event.mjs +20 -0
- package/dist/lib/browser/core/activation-event.mjs.map +7 -0
- package/dist/lib/browser/core/capability.mjs +30 -0
- package/dist/lib/browser/core/capability.mjs.map +7 -0
- package/dist/lib/browser/core/plugin-manager.mjs +17 -0
- package/dist/lib/browser/core/plugin-manager.mjs.map +7 -0
- package/dist/lib/browser/core/plugin.mjs +37 -0
- package/dist/lib/browser/core/plugin.mjs.map +7 -0
- package/dist/lib/browser/core/url-loader.mjs +20 -0
- package/dist/lib/browser/core/url-loader.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +95 -148
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/invoker-capability-LNX4CGIV.mjs +44 -0
- package/dist/lib/browser/invoker-capability-LNX4CGIV.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +227 -41
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/browser/testing/react.mjs +78 -0
- package/dist/lib/browser/testing/react.mjs.map +7 -0
- package/dist/lib/browser/ui/index.mjs +48 -0
- package/dist/lib/browser/ui/index.mjs.map +7 -0
- package/dist/lib/node-esm/capability-EW5GJCI6.mjs +39 -0
- package/dist/lib/node-esm/capability-EW5GJCI6.mjs.map +7 -0
- package/dist/lib/node-esm/capability-YKBMMD53.mjs +36 -0
- package/dist/lib/node-esm/capability-YKBMMD53.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-37Z53PXZ.mjs +10 -0
- package/dist/lib/node-esm/chunk-37Z53PXZ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6XW6LET6.mjs +35 -0
- package/dist/lib/node-esm/chunk-6XW6LET6.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-D347W3KO.mjs +143 -0
- package/dist/lib/node-esm/chunk-D347W3KO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-D5PO2WXX.mjs +373 -0
- package/dist/lib/node-esm/chunk-D5PO2WXX.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-HTBJU5FX.mjs +214 -0
- package/dist/lib/node-esm/chunk-HTBJU5FX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KM2F6GH6.mjs +468 -0
- package/dist/lib/node-esm/chunk-KM2F6GH6.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OZ7DZA5Z.mjs +2 -0
- package/dist/lib/node-esm/chunk-OZ7DZA5Z.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-Q7XBFII4.mjs +908 -0
- package/dist/lib/node-esm/chunk-Q7XBFII4.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-SBS2YMPT.mjs +43 -0
- package/dist/lib/node-esm/chunk-SBS2YMPT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-SDJ4B2LU.mjs +80 -0
- package/dist/lib/node-esm/chunk-SDJ4B2LU.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WFSRZKBP.mjs +81 -0
- package/dist/lib/node-esm/chunk-WFSRZKBP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WKTLE7MG.mjs +585 -0
- package/dist/lib/node-esm/chunk-WKTLE7MG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XOCUANHO.mjs +49 -0
- package/dist/lib/node-esm/chunk-XOCUANHO.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +75 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/common/activation-events.mjs +25 -0
- package/dist/lib/node-esm/common/activation-events.mjs.map +7 -0
- package/dist/lib/node-esm/common/capabilities.mjs +47 -0
- package/dist/lib/node-esm/common/capabilities.mjs.map +7 -0
- package/dist/lib/node-esm/core/activation-event.mjs +21 -0
- package/dist/lib/node-esm/core/activation-event.mjs.map +7 -0
- package/dist/lib/node-esm/core/capability.mjs +31 -0
- package/dist/lib/node-esm/core/capability.mjs.map +7 -0
- package/dist/lib/node-esm/core/plugin-manager.mjs +18 -0
- package/dist/lib/node-esm/core/plugin-manager.mjs.map +7 -0
- package/dist/lib/node-esm/core/plugin.mjs +38 -0
- package/dist/lib/node-esm/core/plugin.mjs.map +7 -0
- package/dist/lib/node-esm/core/url-loader.mjs +21 -0
- package/dist/lib/node-esm/core/url-loader.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +95 -148
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/invoker-capability-O4T5PHLA.mjs +45 -0
- package/dist/lib/node-esm/invoker-capability-O4T5PHLA.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +227 -41
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/testing/react.mjs +79 -0
- package/dist/lib/node-esm/testing/react.mjs.map +7 -0
- package/dist/lib/node-esm/ui/index.mjs +49 -0
- package/dist/lib/node-esm/ui/index.mjs.map +7 -0
- package/dist/plugin/node-esm/index.mjs +832 -0
- package/dist/plugin/node-esm/index.mjs.map +7 -0
- package/dist/plugin/node-esm/meta.json +1 -0
- package/dist/types/src/cli/cli.d.ts +39 -0
- package/dist/types/src/cli/cli.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/common/activation-events.d.ts +27 -0
- package/dist/types/src/common/activation-events.d.ts.map +1 -0
- package/dist/types/src/common/capabilities.d.ts +110 -197
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/index.d.ts +4 -8
- package/dist/types/src/common/index.d.ts.map +1 -1
- package/dist/types/src/common/operations.d.ts +19 -0
- package/dist/types/src/common/operations.d.ts.map +1 -0
- package/dist/types/src/common/translations.d.ts +8 -8
- package/dist/types/src/common/translations.d.ts.map +1 -1
- package/dist/types/src/context.d.ts +5 -0
- package/dist/types/src/context.d.ts.map +1 -0
- package/dist/types/src/core/{events.d.ts → activation-event.d.ts} +11 -11
- package/dist/types/src/core/activation-event.d.ts.map +1 -0
- package/dist/types/src/core/capability-manager.d.ts +48 -0
- package/dist/types/src/core/capability-manager.d.ts.map +1 -0
- package/dist/types/src/core/capability-manager.test.d.ts +2 -0
- package/dist/types/src/core/capability-manager.test.d.ts.map +1 -0
- package/dist/types/src/core/capability.d.ts +156 -0
- package/dist/types/src/core/capability.d.ts.map +1 -0
- package/dist/types/src/core/index.d.ts +8 -4
- package/dist/types/src/core/index.d.ts.map +1 -1
- package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
- package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manager.d.ts +122 -0
- package/dist/types/src/core/plugin-manager.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manager.test.d.ts +2 -0
- package/dist/types/src/core/plugin-manager.test.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manifest.d.ts +76 -0
- package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
- package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
- package/dist/types/src/core/plugin.d.ts +207 -39
- package/dist/types/src/core/plugin.d.ts.map +1 -1
- package/dist/types/src/core/url-loader.d.ts +112 -0
- package/dist/types/src/core/url-loader.d.ts.map +1 -0
- package/dist/types/src/core/url-loader.test.d.ts +2 -0
- package/dist/types/src/core/url-loader.test.d.ts.map +1 -0
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/OperationPlugin.d.ts +3 -0
- package/dist/types/src/plugin-operation/OperationPlugin.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/capability.d.ts +7 -0
- package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/errors.d.ts +32 -0
- package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/history-tracker.d.ts +18 -0
- package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts +2 -0
- package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/index.d.ts +6 -0
- package/dist/types/src/plugin-operation/history/index.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/types.d.ts +13 -0
- package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +101 -0
- package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/undo-registry.d.ts +23 -0
- package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts +2 -0
- package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/index.d.ts +3 -0
- package/dist/types/src/plugin-operation/index.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/invoker-capability.d.ts +6 -0
- package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/meta.d.ts +3 -0
- package/dist/types/src/plugin-operation/meta.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/testing.d.ts +59 -0
- package/dist/types/src/plugin-operation/testing.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts +3 -0
- package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/capability.d.ts +6 -0
- package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/index.d.ts +2 -0
- package/dist/types/src/plugin-runtime/index.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/meta.d.ts +3 -0
- package/dist/types/src/plugin-runtime/meta.d.ts.map +1 -0
- package/dist/types/src/testing/harness.d.ts +67 -0
- package/dist/types/src/testing/harness.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 -1
- package/dist/types/src/testing/react.d.ts +27 -0
- package/dist/types/src/testing/react.d.ts.map +1 -0
- package/dist/types/src/testing/react.test.d.ts +2 -0
- package/dist/types/src/testing/react.test.d.ts.map +1 -0
- package/dist/types/src/testing/service.d.ts +8 -0
- package/dist/types/src/testing/service.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.d.ts +7 -6
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
- package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
- package/dist/types/src/ui/components/App/App.d.ts +9 -0
- package/dist/types/src/ui/components/App/App.d.ts.map +1 -0
- package/dist/types/src/ui/components/App/App.stories.d.ts +19 -0
- package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/App/index.d.ts +2 -0
- package/dist/types/src/ui/components/App/index.d.ts.map +1 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
- package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
- package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
- package/dist/types/src/{playground/playground.stories.d.ts → ui/components/PluginManager/PluginManagerContext.stories.d.ts} +5 -3
- package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts +10 -0
- package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts.map +1 -0
- package/dist/types/src/ui/components/PluginManager/index.d.ts +2 -0
- package/dist/types/src/ui/components/PluginManager/index.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts +24 -0
- package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts.map +1 -0
- package/dist/types/src/{components/App.stories.d.ts → ui/components/Surface/SurfaceComponent.stories.d.ts} +1 -1
- package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts +11 -0
- package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts +48 -0
- package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/context.d.ts +5 -0
- package/dist/types/src/ui/components/Surface/context.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/index.d.ts +36 -0
- package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/types.d.ts +197 -0
- package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -0
- package/dist/types/src/ui/components/Surface/types.test.d.ts +2 -0
- package/dist/types/src/ui/components/Surface/types.test.d.ts.map +1 -0
- package/dist/types/src/ui/components/index.d.ts +5 -0
- package/dist/types/src/ui/components/index.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/index.d.ts +6 -0
- package/dist/types/src/ui/hooks/index.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useApp.d.ts +88 -0
- package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useApp.test.d.ts +2 -0
- package/dist/types/src/ui/hooks/useApp.test.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useCapabilities.d.ts +31 -0
- package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -0
- package/dist/types/src/{components → ui/hooks}/useLoading.d.ts +1 -2
- package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useSettingsState.d.ts +10 -0
- package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useSurface.d.ts +3 -0
- package/dist/types/src/ui/hooks/useSurface.d.ts.map +1 -0
- package/dist/types/src/ui/index.d.ts +3 -0
- package/dist/types/src/ui/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +34 -0
- package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/boot-loader/index.d.ts +52 -0
- package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/composer/index.d.ts +34 -0
- package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/import-map/index.d.ts +28 -0
- package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/index.d.ts +5 -0
- package/dist/types/src/vite-plugin/index.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/manifest.d.ts +37 -0
- package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/manifest.test.d.ts +2 -0
- package/dist/types/src/vite-plugin/manifest.test.d.ts.map +1 -0
- package/dist/types/src/vite-plugin/packages.d.ts +13 -0
- package/dist/types/src/vite-plugin/packages.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +25 -6
- package/package.json +112 -55
- package/src/cli/cli.ts +107 -0
- package/src/{components → cli}/index.ts +1 -1
- package/src/common/activation-events.ts +44 -0
- package/src/common/capabilities.ts +169 -210
- package/src/common/index.ts +4 -8
- package/src/common/operations.ts +35 -0
- package/src/common/translations.ts +18 -10
- package/src/context.ts +9 -0
- package/src/core/{events.ts → activation-event.ts} +10 -7
- package/src/core/capability-manager.test.ts +151 -0
- package/src/core/capability-manager.ts +192 -0
- package/src/core/capability.ts +247 -0
- package/src/core/index.ts +8 -4
- package/src/core/plugin-asset-cache.ts +60 -0
- package/src/core/plugin-manager.test.ts +1354 -0
- package/src/core/plugin-manager.ts +1025 -0
- package/src/core/plugin-manifest.test.ts +48 -0
- package/src/core/plugin-manifest.ts +102 -0
- package/src/core/plugin.ts +365 -45
- package/src/core/url-loader.test.ts +178 -0
- package/src/core/url-loader.ts +337 -0
- package/src/index.ts +3 -4
- package/src/plugin-operation/OperationPlugin.ts +24 -0
- package/src/plugin-operation/history/capability.ts +36 -0
- package/src/plugin-operation/history/errors.ts +7 -0
- package/src/plugin-operation/history/history-tracker.test.ts +374 -0
- package/src/plugin-operation/history/history-tracker.ts +128 -0
- package/src/plugin-operation/history/index.ts +9 -0
- package/src/plugin-operation/history/types.ts +17 -0
- package/src/plugin-operation/history/undo-mapping.ts +135 -0
- package/src/plugin-operation/history/undo-registry.test.ts +72 -0
- package/src/plugin-operation/history/undo-registry.ts +54 -0
- package/src/plugin-operation/index.ts +6 -0
- package/src/plugin-operation/invoker-capability.ts +55 -0
- package/src/plugin-operation/meta.ts +11 -0
- package/src/plugin-operation/testing.ts +155 -0
- package/src/plugin-runtime/RuntimePlugin.ts +19 -0
- package/src/plugin-runtime/capability.ts +53 -0
- package/src/{playground/layout → plugin-runtime}/index.ts +1 -1
- package/src/plugin-runtime/meta.ts +11 -0
- package/src/testing/harness.ts +229 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/react.test.tsx +48 -0
- package/src/testing/react.tsx +113 -0
- package/src/testing/service.ts +52 -0
- package/src/testing/withPluginManager.stories.tsx +8 -9
- package/src/testing/withPluginManager.tsx +68 -40
- package/src/ui/components/App/App.stories.tsx +92 -0
- package/src/ui/components/App/App.tsx +81 -0
- package/src/{playground/debug → ui/components/App}/index.ts +1 -1
- package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
- package/src/ui/components/Placeholder/Placeholder.tsx +155 -0
- package/src/{playground/logger → ui/components/Placeholder}/index.ts +1 -1
- package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +185 -0
- package/src/{react → ui/components/PluginManager}/PluginManagerProvider.ts +3 -3
- package/src/ui/components/PluginManager/index.ts +5 -0
- package/src/ui/components/Surface/SurfaceComponent.stories.tsx +144 -0
- package/src/ui/components/Surface/SurfaceComponent.tsx +303 -0
- package/src/ui/components/Surface/SurfaceInfo.tsx +107 -0
- package/src/ui/components/Surface/SurfaceProfilerContext.tsx +207 -0
- package/src/ui/components/Surface/context.ts +12 -0
- package/src/ui/components/Surface/index.ts +54 -0
- package/src/ui/components/Surface/types.test.ts +126 -0
- package/src/ui/components/Surface/types.ts +269 -0
- package/src/ui/components/index.ts +8 -0
- package/src/ui/hooks/index.ts +9 -0
- package/src/ui/hooks/useApp.test.tsx +159 -0
- package/src/ui/hooks/useApp.tsx +413 -0
- package/src/ui/hooks/useCapabilities.ts +67 -0
- package/src/{components → ui/hooks}/useLoading.tsx +16 -10
- package/src/ui/hooks/useSettingsState.ts +26 -0
- package/src/ui/hooks/useSurface.ts +13 -0
- package/src/ui/index.ts +6 -0
- package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +263 -0
- package/src/vite-plugin/boot-loader/boot-loader.css +294 -0
- package/src/vite-plugin/boot-loader/boot-loader.js +274 -0
- package/src/vite-plugin/boot-loader/index.ts +112 -0
- package/src/vite-plugin/composer/index.ts +277 -0
- package/src/vite-plugin/import-map/index.ts +524 -0
- package/src/vite-plugin/index.ts +10 -0
- package/src/vite-plugin/manifest.test.ts +24 -0
- package/src/vite-plugin/manifest.ts +50 -0
- package/src/vite-plugin/packages.ts +188 -0
- package/tsconfig.json +18 -15
- package/tsconfig.node.json +2 -4
- package/typedoc.json +2 -4
- package/vitest.config.ts +1 -1
- package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/.swc/plugins/linux_x86_64_19.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429.wasmer-v7 +0 -0
- package/dist/lib/browser/app-graph-builder-XH4OYQLC.mjs +0 -137
- package/dist/lib/browser/app-graph-builder-XH4OYQLC.mjs.map +0 -7
- package/dist/lib/browser/chunk-6V54SRFL.mjs +0 -1638
- package/dist/lib/browser/chunk-6V54SRFL.mjs.map +0 -7
- package/dist/lib/browser/chunk-RGKMLI6U.mjs +0 -35
- package/dist/lib/browser/chunk-RGKMLI6U.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZZVFNUHZ.mjs +0 -467
- package/dist/lib/browser/chunk-ZZVFNUHZ.mjs.map +0 -7
- package/dist/lib/browser/intent-dispatcher-VFMJVO2M.mjs +0 -11
- package/dist/lib/browser/intent-resolver-ICAPD4JL.mjs +0 -39
- package/dist/lib/browser/intent-resolver-ICAPD4JL.mjs.map +0 -7
- package/dist/lib/browser/store-7ZGMHOGB.mjs +0 -30
- package/dist/lib/browser/store-7ZGMHOGB.mjs.map +0 -7
- package/dist/lib/browser/worker.mjs +0 -77
- package/dist/lib/node-esm/app-graph-builder-C7H22SOL.mjs +0 -138
- package/dist/lib/node-esm/app-graph-builder-C7H22SOL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AXSZKZFD.mjs +0 -468
- package/dist/lib/node-esm/chunk-AXSZKZFD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LKPMRTRR.mjs +0 -37
- package/dist/lib/node-esm/chunk-LKPMRTRR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SOVTUUAY.mjs +0 -1640
- package/dist/lib/node-esm/chunk-SOVTUUAY.mjs.map +0 -7
- package/dist/lib/node-esm/intent-dispatcher-SAPOKSLZ.mjs +0 -12
- package/dist/lib/node-esm/intent-resolver-CRNJ6BMD.mjs +0 -40
- package/dist/lib/node-esm/intent-resolver-CRNJ6BMD.mjs.map +0 -7
- package/dist/lib/node-esm/store-H4F4RMYD.mjs +0 -31
- package/dist/lib/node-esm/store-H4F4RMYD.mjs.map +0 -7
- package/dist/lib/node-esm/worker.mjs +0 -78
- package/dist/types/src/common/collaboration.d.ts +0 -20
- package/dist/types/src/common/collaboration.d.ts.map +0 -1
- package/dist/types/src/common/events.d.ts +0 -52
- package/dist/types/src/common/events.d.ts.map +0 -1
- package/dist/types/src/common/file.d.ts +0 -14
- package/dist/types/src/common/file.d.ts.map +0 -1
- package/dist/types/src/common/graph.d.ts +0 -21
- package/dist/types/src/common/graph.d.ts.map +0 -1
- package/dist/types/src/common/layout.d.ts +0 -279
- package/dist/types/src/common/layout.d.ts.map +0 -1
- package/dist/types/src/common/surface.d.ts +0 -59
- package/dist/types/src/common/surface.d.ts.map +0 -1
- package/dist/types/src/components/App.d.ts +0 -10
- package/dist/types/src/components/App.d.ts.map +0 -1
- package/dist/types/src/components/App.stories.d.ts.map +0 -1
- package/dist/types/src/components/DefaultFallback.d.ts +0 -8
- package/dist/types/src/components/DefaultFallback.d.ts.map +0 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +0 -1
- package/dist/types/src/components/useApp.d.ts +0 -44
- package/dist/types/src/components/useApp.d.ts.map +0 -1
- package/dist/types/src/components/useLoading.d.ts.map +0 -1
- package/dist/types/src/core/capabilities.d.ts +0 -117
- package/dist/types/src/core/capabilities.d.ts.map +0 -1
- package/dist/types/src/core/capabilities.test.d.ts +0 -2
- package/dist/types/src/core/capabilities.test.d.ts.map +0 -1
- package/dist/types/src/core/events.d.ts.map +0 -1
- package/dist/types/src/core/manager.d.ts +0 -126
- package/dist/types/src/core/manager.d.ts.map +0 -1
- package/dist/types/src/core/manager.test.d.ts +0 -2
- package/dist/types/src/core/manager.test.d.ts.map +0 -1
- package/dist/types/src/playground/debug/Debug.d.ts +0 -6
- package/dist/types/src/playground/debug/Debug.d.ts.map +0 -1
- package/dist/types/src/playground/debug/index.d.ts +0 -2
- package/dist/types/src/playground/debug/index.d.ts.map +0 -1
- package/dist/types/src/playground/debug/plugin.d.ts +0 -2
- package/dist/types/src/playground/debug/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/generator/Main.d.ts +0 -6
- package/dist/types/src/playground/generator/Main.d.ts.map +0 -1
- package/dist/types/src/playground/generator/Toolbar.d.ts +0 -6
- package/dist/types/src/playground/generator/Toolbar.d.ts.map +0 -1
- package/dist/types/src/playground/generator/generator.d.ts +0 -7
- package/dist/types/src/playground/generator/generator.d.ts.map +0 -1
- package/dist/types/src/playground/generator/index.d.ts +0 -3
- package/dist/types/src/playground/generator/index.d.ts.map +0 -1
- package/dist/types/src/playground/generator/plugin.d.ts +0 -2
- package/dist/types/src/playground/generator/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/layout/Layout.d.ts +0 -8
- package/dist/types/src/playground/layout/Layout.d.ts.map +0 -1
- package/dist/types/src/playground/layout/index.d.ts +0 -2
- package/dist/types/src/playground/layout/index.d.ts.map +0 -1
- package/dist/types/src/playground/layout/plugin.d.ts +0 -2
- package/dist/types/src/playground/layout/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/logger/Toolbar.d.ts +0 -6
- package/dist/types/src/playground/logger/Toolbar.d.ts.map +0 -1
- package/dist/types/src/playground/logger/index.d.ts +0 -2
- package/dist/types/src/playground/logger/index.d.ts.map +0 -1
- package/dist/types/src/playground/logger/plugin.d.ts +0 -2
- package/dist/types/src/playground/logger/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/logger/schema.d.ts +0 -13
- package/dist/types/src/playground/logger/schema.d.ts.map +0 -1
- package/dist/types/src/playground/playground.stories.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts +0 -2
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/actions.d.ts +0 -36
- package/dist/types/src/plugin-intent/actions.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/errors.d.ts +0 -16
- package/dist/types/src/plugin-intent/errors.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/index.d.ts +0 -6
- package/dist/types/src/plugin-intent/index.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +0 -139
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts +0 -2
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/intent.d.ts +0 -63
- package/dist/types/src/plugin-intent/intent.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/meta.d.ts +0 -3
- package/dist/types/src/plugin-intent/meta.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +0 -2
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/actions.d.ts +0 -25
- package/dist/types/src/plugin-settings/actions.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts +0 -4
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/index.d.ts +0 -3
- package/dist/types/src/plugin-settings/index.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/intent-resolver.d.ts +0 -4
- package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/meta.d.ts +0 -3
- package/dist/types/src/plugin-settings/meta.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/store.d.ts +0 -5
- package/dist/types/src/plugin-settings/store.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/translations.d.ts +0 -11
- package/dist/types/src/plugin-settings/translations.d.ts.map +0 -1
- package/dist/types/src/react/ErrorBoundary.d.ts +0 -30
- package/dist/types/src/react/ErrorBoundary.d.ts.map +0 -1
- package/dist/types/src/react/IntentContext.d.ts +0 -8
- package/dist/types/src/react/IntentContext.d.ts.map +0 -1
- package/dist/types/src/react/PluginManagerProvider.d.ts +0 -10
- package/dist/types/src/react/PluginManagerProvider.d.ts.map +0 -1
- package/dist/types/src/react/Surface.d.ts +0 -12
- package/dist/types/src/react/Surface.d.ts.map +0 -1
- package/dist/types/src/react/Surface.stories.d.ts +0 -17
- package/dist/types/src/react/Surface.stories.d.ts.map +0 -1
- package/dist/types/src/react/common.d.ts +0 -13
- package/dist/types/src/react/common.d.ts.map +0 -1
- package/dist/types/src/react/index.d.ts +0 -7
- package/dist/types/src/react/index.d.ts.map +0 -1
- package/dist/types/src/react/useCapabilities.d.ts +0 -13
- package/dist/types/src/react/useCapabilities.d.ts.map +0 -1
- package/dist/types/src/react/useIntentResolver.d.ts +0 -3
- package/dist/types/src/react/useIntentResolver.d.ts.map +0 -1
- package/dist/types/src/worker.d.ts +0 -4
- package/dist/types/src/worker.d.ts.map +0 -1
- package/src/common/collaboration.ts +0 -18
- package/src/common/events.ts +0 -79
- package/src/common/file.ts +0 -22
- package/src/common/graph.ts +0 -30
- package/src/common/layout.ts +0 -277
- package/src/common/surface.ts +0 -83
- package/src/components/App.stories.tsx +0 -33
- package/src/components/App.tsx +0 -59
- package/src/components/DefaultFallback.tsx +0 -26
- package/src/components/useApp.tsx +0 -164
- package/src/core/capabilities.test.ts +0 -136
- package/src/core/capabilities.ts +0 -259
- package/src/core/manager.test.ts +0 -516
- package/src/core/manager.ts +0 -597
- package/src/playground/debug/Debug.tsx +0 -39
- package/src/playground/debug/plugin.ts +0 -16
- package/src/playground/generator/Main.tsx +0 -71
- package/src/playground/generator/Toolbar.tsx +0 -47
- package/src/playground/generator/generator.ts +0 -48
- package/src/playground/generator/index.ts +0 -6
- package/src/playground/generator/plugin.ts +0 -22
- package/src/playground/layout/Layout.tsx +0 -33
- package/src/playground/layout/plugin.ts +0 -18
- package/src/playground/logger/Toolbar.tsx +0 -30
- package/src/playground/logger/plugin.ts +0 -41
- package/src/playground/logger/schema.ts +0 -12
- package/src/playground/playground.stories.tsx +0 -46
- package/src/plugin-intent/IntentPlugin.ts +0 -20
- package/src/plugin-intent/actions.ts +0 -31
- package/src/plugin-intent/errors.ts +0 -40
- package/src/plugin-intent/index.ts +0 -9
- package/src/plugin-intent/intent-dispatcher.test.ts +0 -279
- package/src/plugin-intent/intent-dispatcher.ts +0 -334
- package/src/plugin-intent/intent.ts +0 -154
- package/src/plugin-intent/meta.ts +0 -10
- package/src/plugin-settings/SettingsPlugin.ts +0 -34
- package/src/plugin-settings/actions.ts +0 -25
- package/src/plugin-settings/app-graph-builder.ts +0 -159
- package/src/plugin-settings/index.ts +0 -6
- package/src/plugin-settings/intent-resolver.ts +0 -35
- package/src/plugin-settings/meta.ts +0 -10
- package/src/plugin-settings/store.ts +0 -33
- package/src/plugin-settings/translations.ts +0 -19
- package/src/react/ErrorBoundary.tsx +0 -54
- package/src/react/IntentContext.tsx +0 -35
- package/src/react/Surface.stories.tsx +0 -101
- package/src/react/Surface.tsx +0 -86
- package/src/react/common.ts +0 -13
- package/src/react/index.ts +0 -10
- package/src/react/useCapabilities.ts +0 -31
- package/src/react/useIntentResolver.ts +0 -22
- package/src/worker.ts +0 -11
- /package/dist/lib/browser/{intent-dispatcher-VFMJVO2M.mjs.map → chunk-G7SDBRKH.mjs.map} +0 -0
- /package/dist/lib/browser/{worker.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{node-esm/intent-dispatcher-SAPOKSLZ.mjs.map → browser/common/activation-events.mjs.map} +0 -0
- /package/dist/lib/{node-esm/worker.mjs.map → browser/common/capabilities.mjs.map} +0 -0
|
@@ -0,0 +1,1354 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Atom, Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { afterEach, assert, describe, it } from '@effect/vitest';
|
|
7
|
+
import * as Cause from 'effect/Cause';
|
|
8
|
+
import * as Duration from 'effect/Duration';
|
|
9
|
+
import * as Effect from 'effect/Effect';
|
|
10
|
+
import * as Exit from 'effect/Exit';
|
|
11
|
+
import * as Fiber from 'effect/Fiber';
|
|
12
|
+
import * as Match from 'effect/Match';
|
|
13
|
+
import * as PubSub from 'effect/PubSub';
|
|
14
|
+
import * as Queue from 'effect/Queue';
|
|
15
|
+
import * as TestClock from 'effect/TestClock';
|
|
16
|
+
|
|
17
|
+
import { invariant } from '@dxos/invariant';
|
|
18
|
+
import { type LogConfig, type LogEntry, LogLevel, log } from '@dxos/log';
|
|
19
|
+
|
|
20
|
+
import { ActivationEvents } from '../common';
|
|
21
|
+
import * as ActivationEvent from './activation-event';
|
|
22
|
+
import * as Capability from './capability';
|
|
23
|
+
import type * as CapabilityManager from './capability-manager';
|
|
24
|
+
import * as Plugin from './plugin';
|
|
25
|
+
import * as PluginManager from './plugin-manager';
|
|
26
|
+
|
|
27
|
+
const String = Capability.make<{ string: string }>('org.dxos.test.string');
|
|
28
|
+
const Number = Capability.make<{ number: number }>('org.dxos.test.number');
|
|
29
|
+
const Total = Capability.make<{ total: number }>('org.dxos.test.total');
|
|
30
|
+
|
|
31
|
+
const CountEvent = ActivationEvent.make('org.dxos.test.count');
|
|
32
|
+
const FailEvent = ActivationEvent.make('org.dxos.test.fail');
|
|
33
|
+
|
|
34
|
+
const testMeta = { id: 'org.dxos.plugin.test', name: 'Test' };
|
|
35
|
+
|
|
36
|
+
// TODO(wittjosiah): Factor out?
|
|
37
|
+
const atomCounter = (registry: Registry.Registry, atom: Atom.Atom<any>) => {
|
|
38
|
+
let count = 0;
|
|
39
|
+
let initial = true;
|
|
40
|
+
const dispose = registry.subscribe(
|
|
41
|
+
atom,
|
|
42
|
+
() => {
|
|
43
|
+
if (initial) {
|
|
44
|
+
initial = false;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
count++;
|
|
48
|
+
},
|
|
49
|
+
{ immediate: true },
|
|
50
|
+
);
|
|
51
|
+
return {
|
|
52
|
+
get count() {
|
|
53
|
+
return count;
|
|
54
|
+
},
|
|
55
|
+
[Symbol.dispose]: dispose,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
describe('PluginManager', () => {
|
|
60
|
+
let plugins: Plugin.Plugin[] = [];
|
|
61
|
+
const pluginLoader = Effect.fn(function* (id: string) {
|
|
62
|
+
const plugin = plugins.find((plugin) => plugin.meta.id === id);
|
|
63
|
+
invariant(plugin, `Plugin not found: ${id}`);
|
|
64
|
+
return plugin;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
plugins = [];
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it.effect('should be able to add and remove plugins', () =>
|
|
72
|
+
Effect.gen(function* () {
|
|
73
|
+
const Test = Plugin.make(Plugin.define(testMeta));
|
|
74
|
+
const testPlugin = Test();
|
|
75
|
+
plugins = [testPlugin];
|
|
76
|
+
|
|
77
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
78
|
+
const added = yield* manager.add(testMeta.id);
|
|
79
|
+
assert.strictEqual(added, testPlugin);
|
|
80
|
+
assert.deepStrictEqual(manager.getPlugins(), [testPlugin]);
|
|
81
|
+
assert.deepStrictEqual(manager.getEnabled(), []);
|
|
82
|
+
const removed = yield* manager.remove(testMeta.id);
|
|
83
|
+
assert.isTrue(removed);
|
|
84
|
+
assert.deepStrictEqual(manager.getPlugins(), []);
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
it.effect('should add plugin when locator differs from meta.id', () =>
|
|
89
|
+
Effect.gen(function* () {
|
|
90
|
+
const Test = Plugin.make(Plugin.define(testMeta));
|
|
91
|
+
const testPlugin = Test();
|
|
92
|
+
|
|
93
|
+
const urlLocator = 'https://example.com/plugin.mjs';
|
|
94
|
+
const urlLoader = Effect.fn(function* (locator: string) {
|
|
95
|
+
if (locator === urlLocator) {
|
|
96
|
+
return testPlugin;
|
|
97
|
+
}
|
|
98
|
+
return yield* Effect.fail(new Error(`Unknown locator: ${locator}`));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const manager = PluginManager.make({ pluginLoader: urlLoader });
|
|
102
|
+
const added = yield* manager.add(urlLocator);
|
|
103
|
+
assert.strictEqual(added, testPlugin);
|
|
104
|
+
assert.deepStrictEqual(manager.getPlugins(), [testPlugin]);
|
|
105
|
+
assert.deepStrictEqual(manager.getEnabled(), []);
|
|
106
|
+
yield* manager.enable(added.meta.id);
|
|
107
|
+
assert.deepStrictEqual(manager.getEnabled(), [testMeta.id]);
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
it.effect('should support factory pattern with options', () =>
|
|
112
|
+
Effect.gen(function* () {
|
|
113
|
+
type TestPluginOptions = { count: number };
|
|
114
|
+
const TestPluginFactory = Plugin.define<TestPluginOptions>(testMeta).pipe(
|
|
115
|
+
Plugin.addModule((options: TestPluginOptions) => ({
|
|
116
|
+
id: 'Hello',
|
|
117
|
+
activatesOn: ActivationEvents.Startup,
|
|
118
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: `hello-${options.count}` })),
|
|
119
|
+
})),
|
|
120
|
+
Plugin.addModule({
|
|
121
|
+
id: 'World',
|
|
122
|
+
activatesOn: ActivationEvents.Startup,
|
|
123
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'world' })),
|
|
124
|
+
}),
|
|
125
|
+
Plugin.make,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const plugin = TestPluginFactory({ count: 5 });
|
|
129
|
+
plugins = [plugin];
|
|
130
|
+
|
|
131
|
+
const manager = PluginManager.make({ plugins: [plugin], core: [], pluginLoader });
|
|
132
|
+
yield* manager.enable(testMeta.id);
|
|
133
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
134
|
+
const strings = manager.capabilities.getAll(String);
|
|
135
|
+
assert.strictEqual(strings.length, 2);
|
|
136
|
+
assert.strictEqual(strings[0].string, 'hello-5');
|
|
137
|
+
assert.strictEqual(strings[1].string, 'world');
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
it.effect('should be able to enable and disable plugins', () =>
|
|
142
|
+
Effect.gen(function* () {
|
|
143
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
144
|
+
Plugin.addModule({
|
|
145
|
+
id: 'Hello',
|
|
146
|
+
activatesOn: ActivationEvents.Startup,
|
|
147
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
148
|
+
}),
|
|
149
|
+
Plugin.make,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const testPlugin = Test();
|
|
153
|
+
const manager = PluginManager.make({ plugins: [testPlugin], core: [], pluginLoader });
|
|
154
|
+
yield* manager.enable(testMeta.id);
|
|
155
|
+
assert.deepStrictEqual(manager.getEnabled(), [Test.meta.id]);
|
|
156
|
+
assert.deepStrictEqual(manager.getModules(), [testPlugin.modules[0]]);
|
|
157
|
+
yield* manager.disable(testMeta.id);
|
|
158
|
+
assert.deepStrictEqual(manager.getEnabled(), []);
|
|
159
|
+
assert.deepStrictEqual(manager.getModules(), []);
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
it.effect('should be able to activate plugins', () =>
|
|
164
|
+
Effect.gen(function* () {
|
|
165
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
166
|
+
Plugin.addModule({
|
|
167
|
+
id: 'Hello',
|
|
168
|
+
activatesOn: ActivationEvents.Startup,
|
|
169
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
170
|
+
}),
|
|
171
|
+
Plugin.make,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const testPlugin = Test();
|
|
175
|
+
const manager = PluginManager.make({ plugins: [testPlugin], pluginLoader });
|
|
176
|
+
yield* manager.enable(Test.meta.id);
|
|
177
|
+
assert.deepStrictEqual(manager.getPlugins(), [testPlugin]);
|
|
178
|
+
assert.deepStrictEqual(manager.getEnabled(), [Test.meta.id]);
|
|
179
|
+
assert.deepStrictEqual(manager.getModules(), [testPlugin.modules[0]]);
|
|
180
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
181
|
+
assert.deepStrictEqual(manager.getEventsFired(), []);
|
|
182
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
183
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
184
|
+
assert.deepStrictEqual(manager.getEventsFired(), [ActivationEvents.Startup.id]);
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
it.effect('should handle activate returning void', () =>
|
|
189
|
+
Effect.gen(function* () {
|
|
190
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
191
|
+
Plugin.addModule({
|
|
192
|
+
id: 'NoCapabilities',
|
|
193
|
+
activatesOn: ActivationEvents.Startup,
|
|
194
|
+
activate: Effect.fnUntraced(function* () {}),
|
|
195
|
+
}),
|
|
196
|
+
Plugin.make,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const testPlugin = Test();
|
|
200
|
+
const manager = PluginManager.make({ plugins: [testPlugin], pluginLoader });
|
|
201
|
+
yield* manager.enable(Test.meta.id);
|
|
202
|
+
|
|
203
|
+
const result = yield* manager.activate(ActivationEvents.Startup);
|
|
204
|
+
assert.isTrue(result);
|
|
205
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
206
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 0);
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
it.effect('should propagate errors thrown by module activate callbacks', () =>
|
|
211
|
+
Effect.gen(function* () {
|
|
212
|
+
plugins = [
|
|
213
|
+
Plugin.define(testMeta).pipe(
|
|
214
|
+
Plugin.addModule({
|
|
215
|
+
activatesOn: FailEvent,
|
|
216
|
+
id: 'Fail',
|
|
217
|
+
activate: () => Effect.fail(new Error('test')),
|
|
218
|
+
}),
|
|
219
|
+
Plugin.make,
|
|
220
|
+
)(),
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
224
|
+
yield* manager.add(testMeta.id);
|
|
225
|
+
yield* manager.enable(testMeta.id);
|
|
226
|
+
const error = yield* Effect.flip(manager.activate(FailEvent));
|
|
227
|
+
assert.strictEqual(error.message, 'test');
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
it.effect('should catch and log defects (synchronous throws) in module activation', () =>
|
|
232
|
+
Effect.gen(function* () {
|
|
233
|
+
const DefectEvent = ActivationEvent.make('org.dxos.test.defect');
|
|
234
|
+
const capturedErrors: LogEntry[] = [];
|
|
235
|
+
const removeProcessor = log.addProcessor((_config: LogConfig, entry: LogEntry) => {
|
|
236
|
+
if (entry.level === LogLevel.ERROR) {
|
|
237
|
+
capturedErrors.push(entry);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
plugins = [
|
|
242
|
+
Plugin.define(testMeta).pipe(
|
|
243
|
+
Plugin.addModule({
|
|
244
|
+
activatesOn: DefectEvent,
|
|
245
|
+
id: 'DefectInEffectSync',
|
|
246
|
+
activate: () =>
|
|
247
|
+
Effect.sync(() => {
|
|
248
|
+
// This is a defect - a synchronous throw inside Effect.sync.
|
|
249
|
+
throw new Error('defect in Effect.sync');
|
|
250
|
+
}),
|
|
251
|
+
}),
|
|
252
|
+
Plugin.make,
|
|
253
|
+
)(),
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
257
|
+
yield* manager.add(testMeta.id);
|
|
258
|
+
yield* manager.enable(testMeta.id);
|
|
259
|
+
const error = yield* Effect.flip(manager.activate(DefectEvent));
|
|
260
|
+
|
|
261
|
+
// Verify the error was caught and propagated.
|
|
262
|
+
assert.strictEqual(error.message, 'defect in Effect.sync');
|
|
263
|
+
|
|
264
|
+
// Verify the error was logged with isDefect: true.
|
|
265
|
+
const defectLog = capturedErrors.find(
|
|
266
|
+
(entry) =>
|
|
267
|
+
entry.message?.includes('module failed to activate') &&
|
|
268
|
+
entry.context?.module === 'org.dxos.plugin.test.module.DefectInEffectSync',
|
|
269
|
+
);
|
|
270
|
+
assert.isNotNull(defectLog, 'Expected error log for defect');
|
|
271
|
+
assert.strictEqual(defectLog?.context?.isDefect, true, 'Expected isDefect to be true for synchronous throw');
|
|
272
|
+
|
|
273
|
+
removeProcessor();
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
it.effect('should catch and log defects when activate throws before returning Effect', () =>
|
|
278
|
+
Effect.gen(function* () {
|
|
279
|
+
const DefectEvent = ActivationEvent.make('org.dxos.test.defect-immediate');
|
|
280
|
+
const capturedErrors: LogEntry[] = [];
|
|
281
|
+
const removeProcessor = log.addProcessor((_config: LogConfig, entry: LogEntry) => {
|
|
282
|
+
if (entry.level === LogLevel.ERROR) {
|
|
283
|
+
capturedErrors.push(entry);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
plugins = [
|
|
288
|
+
Plugin.define(testMeta).pipe(
|
|
289
|
+
Plugin.addModule({
|
|
290
|
+
activatesOn: DefectEvent,
|
|
291
|
+
id: 'DefectImmediate',
|
|
292
|
+
activate: () => {
|
|
293
|
+
// This throws immediately before even returning an Effect.
|
|
294
|
+
// This is the most severe type of defect.
|
|
295
|
+
throw new Error('immediate throw before Effect');
|
|
296
|
+
return Effect.succeed(undefined);
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
Plugin.make,
|
|
300
|
+
)(),
|
|
301
|
+
];
|
|
302
|
+
|
|
303
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
304
|
+
yield* manager.add(testMeta.id);
|
|
305
|
+
yield* manager.enable(testMeta.id);
|
|
306
|
+
const error = yield* Effect.flip(manager.activate(DefectEvent));
|
|
307
|
+
|
|
308
|
+
// Verify the error was caught and propagated.
|
|
309
|
+
assert.strictEqual(error.message, 'immediate throw before Effect');
|
|
310
|
+
|
|
311
|
+
// Verify the error was logged with isDefect: true.
|
|
312
|
+
const defectLog = capturedErrors.find(
|
|
313
|
+
(entry) =>
|
|
314
|
+
entry.message?.includes('module failed to activate') &&
|
|
315
|
+
entry.context?.module === 'org.dxos.plugin.test.module.DefectImmediate',
|
|
316
|
+
);
|
|
317
|
+
assert.isNotNull(defectLog, 'Expected error log for immediate defect');
|
|
318
|
+
assert.strictEqual(
|
|
319
|
+
defectLog?.context?.isDefect,
|
|
320
|
+
true,
|
|
321
|
+
'Expected isDefect to be true for immediate throw before Effect',
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
removeProcessor();
|
|
325
|
+
}),
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
it.effect('should fire activation events', () =>
|
|
329
|
+
Effect.gen(function* () {
|
|
330
|
+
plugins = [
|
|
331
|
+
Plugin.define(testMeta).pipe(
|
|
332
|
+
Plugin.addModule({
|
|
333
|
+
id: 'Hello',
|
|
334
|
+
activatesOn: ActivationEvents.Startup,
|
|
335
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
336
|
+
}),
|
|
337
|
+
Plugin.addModule({
|
|
338
|
+
activatesOn: FailEvent,
|
|
339
|
+
id: 'Fail',
|
|
340
|
+
activate: () => Effect.fail(new Error('test')),
|
|
341
|
+
}),
|
|
342
|
+
Plugin.make,
|
|
343
|
+
)(),
|
|
344
|
+
];
|
|
345
|
+
|
|
346
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
347
|
+
const activating = yield* Effect.makeLatch(false);
|
|
348
|
+
const activated = yield* Effect.makeLatch(false);
|
|
349
|
+
const error = yield* Effect.makeLatch(false);
|
|
350
|
+
|
|
351
|
+
const activationFiber = PubSub.subscribe(manager.activation).pipe(
|
|
352
|
+
Effect.flatMap((queue) =>
|
|
353
|
+
Queue.take(queue).pipe(
|
|
354
|
+
Effect.flatMap(({ state }) =>
|
|
355
|
+
Match.value(state).pipe(
|
|
356
|
+
Match.when('activating', () => activating.open),
|
|
357
|
+
Match.when('activated', () => activated.open),
|
|
358
|
+
Match.when('error', () => error.open),
|
|
359
|
+
Match.orElse(() => Effect.succeed(undefined)),
|
|
360
|
+
),
|
|
361
|
+
),
|
|
362
|
+
Effect.forever,
|
|
363
|
+
),
|
|
364
|
+
),
|
|
365
|
+
Effect.scoped,
|
|
366
|
+
Effect.runFork,
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
yield* manager.add(testMeta.id);
|
|
370
|
+
yield* manager.enable(testMeta.id);
|
|
371
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
372
|
+
yield* activating.await;
|
|
373
|
+
yield* activated.await;
|
|
374
|
+
|
|
375
|
+
const activating2 = yield* Effect.makeLatch(false);
|
|
376
|
+
const activationFiber2 = PubSub.subscribe(manager.activation).pipe(
|
|
377
|
+
Effect.flatMap((queue) =>
|
|
378
|
+
Queue.take(queue).pipe(
|
|
379
|
+
Effect.flatMap(({ state }) =>
|
|
380
|
+
Match.value(state).pipe(
|
|
381
|
+
Match.when('activating', () => activating2.open),
|
|
382
|
+
Match.orElse(() => Effect.succeed(undefined)),
|
|
383
|
+
),
|
|
384
|
+
),
|
|
385
|
+
Effect.forever,
|
|
386
|
+
),
|
|
387
|
+
),
|
|
388
|
+
Effect.scoped,
|
|
389
|
+
Effect.runFork,
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
yield* manager.activate(FailEvent).pipe(Effect.catchAll(() => Effect.succeed(false)));
|
|
393
|
+
yield* activating2.await;
|
|
394
|
+
yield* error.await;
|
|
395
|
+
yield* Fiber.interrupt(activationFiber);
|
|
396
|
+
yield* Fiber.interrupt(activationFiber2);
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
it.effect('should be able to reset an activation event', () =>
|
|
401
|
+
Effect.gen(function* () {
|
|
402
|
+
let count = 0;
|
|
403
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
404
|
+
Plugin.addModule({
|
|
405
|
+
id: 'Hello',
|
|
406
|
+
activatesOn: ActivationEvents.Startup,
|
|
407
|
+
activate: () => {
|
|
408
|
+
count++;
|
|
409
|
+
return Effect.succeed(Capability.contributes(String, { string: 'hello' }));
|
|
410
|
+
},
|
|
411
|
+
}),
|
|
412
|
+
Plugin.make,
|
|
413
|
+
);
|
|
414
|
+
const testPlugin = Test();
|
|
415
|
+
plugins = [testPlugin];
|
|
416
|
+
|
|
417
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
418
|
+
|
|
419
|
+
{
|
|
420
|
+
yield* manager.add(testMeta.id);
|
|
421
|
+
yield* manager.enable(testMeta.id);
|
|
422
|
+
const result = yield* manager.activate(ActivationEvents.Startup);
|
|
423
|
+
assert.isTrue(result);
|
|
424
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
425
|
+
assert.strictEqual(count, 1);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
{
|
|
429
|
+
const result = yield* manager.activate(ActivationEvents.Startup);
|
|
430
|
+
assert.isFalse(result);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
{
|
|
434
|
+
const result = yield* manager.reset(ActivationEvents.Startup);
|
|
435
|
+
assert.isTrue(result);
|
|
436
|
+
assert.strictEqual(count, 2);
|
|
437
|
+
}
|
|
438
|
+
}),
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
it.effect('should not fire an unknown event', () =>
|
|
442
|
+
Effect.gen(function* () {
|
|
443
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
444
|
+
const UnknownEvent = ActivationEvent.make('unknown');
|
|
445
|
+
const result = yield* manager.activate(UnknownEvent);
|
|
446
|
+
assert.isFalse(result);
|
|
447
|
+
}),
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
it.effect('should be able to fire custom activation events', () =>
|
|
451
|
+
Effect.gen(function* () {
|
|
452
|
+
const Plugin1 = Plugin.define({ id: 'org.dxos.test.plugin-1', name: 'Plugin 1' }).pipe(
|
|
453
|
+
Plugin.addModule({
|
|
454
|
+
activatesOn: CountEvent,
|
|
455
|
+
id: 'Plugin1',
|
|
456
|
+
activate: () => Effect.succeed([Capability.contributes(Number, { number: 1 })]),
|
|
457
|
+
}),
|
|
458
|
+
Plugin.make,
|
|
459
|
+
);
|
|
460
|
+
const Plugin2 = Plugin.define({ id: 'org.dxos.test.plugin-2', name: 'Plugin 2' }).pipe(
|
|
461
|
+
Plugin.addModule({
|
|
462
|
+
activatesOn: CountEvent,
|
|
463
|
+
id: 'Plugin2',
|
|
464
|
+
activate: () => Effect.succeed([Capability.contributes(Number, { number: 2 })]),
|
|
465
|
+
}),
|
|
466
|
+
Plugin.make,
|
|
467
|
+
);
|
|
468
|
+
const Plugin3 = Plugin.define({ id: 'org.dxos.test.plugin-3', name: 'Plugin 3' }).pipe(
|
|
469
|
+
Plugin.addModule({
|
|
470
|
+
activatesOn: CountEvent,
|
|
471
|
+
id: 'Plugin3',
|
|
472
|
+
activate: () => Effect.succeed([Capability.contributes(Number, { number: 3 })]),
|
|
473
|
+
}),
|
|
474
|
+
Plugin.make,
|
|
475
|
+
);
|
|
476
|
+
const plugin1 = Plugin1();
|
|
477
|
+
const plugin2 = Plugin2();
|
|
478
|
+
const plugin3 = Plugin3();
|
|
479
|
+
plugins = [plugin1, plugin2, plugin3];
|
|
480
|
+
|
|
481
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
482
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
483
|
+
assert.strictEqual(manager.capabilities.getAll(Number).length, 0);
|
|
484
|
+
|
|
485
|
+
yield* manager.add(Plugin1.meta.id);
|
|
486
|
+
yield* manager.enable(Plugin1.meta.id);
|
|
487
|
+
yield* manager.activate(CountEvent);
|
|
488
|
+
assert.deepStrictEqual(manager.getActive(), [plugin1.modules[0].id]);
|
|
489
|
+
assert.strictEqual(manager.capabilities.getAll(Number).length, 1);
|
|
490
|
+
|
|
491
|
+
yield* manager.add(Plugin2.meta.id);
|
|
492
|
+
yield* manager.enable(Plugin2.meta.id);
|
|
493
|
+
yield* manager.activate(CountEvent);
|
|
494
|
+
assert.deepStrictEqual(manager.getActive(), [plugin1.modules[0].id, plugin2.modules[0].id]);
|
|
495
|
+
assert.strictEqual(manager.capabilities.getAll(Number).length, 2);
|
|
496
|
+
|
|
497
|
+
yield* manager.add(Plugin3.meta.id);
|
|
498
|
+
yield* manager.enable(Plugin3.meta.id);
|
|
499
|
+
yield* manager.activate(CountEvent);
|
|
500
|
+
assert.deepStrictEqual(manager.getActive(), [
|
|
501
|
+
plugin1.modules[0].id,
|
|
502
|
+
plugin2.modules[0].id,
|
|
503
|
+
plugin3.modules[0].id,
|
|
504
|
+
]);
|
|
505
|
+
assert.strictEqual(manager.capabilities.getAll(Number).length, 3);
|
|
506
|
+
}),
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
it.effect('should only activate modules after all activatation events have been fired', () =>
|
|
510
|
+
Effect.gen(function* () {
|
|
511
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
512
|
+
Plugin.addModule({
|
|
513
|
+
activatesOn: ActivationEvent.allOf(ActivationEvents.Startup, CountEvent),
|
|
514
|
+
id: 'Hello',
|
|
515
|
+
activate: () => {
|
|
516
|
+
return Effect.succeed(Capability.contributes(String, { string: 'hello' }));
|
|
517
|
+
},
|
|
518
|
+
}),
|
|
519
|
+
Plugin.make,
|
|
520
|
+
);
|
|
521
|
+
const testPlugin = Test();
|
|
522
|
+
plugins = [testPlugin];
|
|
523
|
+
|
|
524
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
525
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
526
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 0);
|
|
527
|
+
|
|
528
|
+
yield* manager.add(testMeta.id);
|
|
529
|
+
yield* manager.enable(testMeta.id);
|
|
530
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
531
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
532
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 0);
|
|
533
|
+
|
|
534
|
+
yield* manager.activate(CountEvent);
|
|
535
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
536
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 1);
|
|
537
|
+
}),
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
it.effect('should only activate modules once when multiple activatation events have been fired', () =>
|
|
541
|
+
Effect.gen(function* () {
|
|
542
|
+
let count = 0;
|
|
543
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
544
|
+
Plugin.addModule({
|
|
545
|
+
id: 'Hello',
|
|
546
|
+
activatesOn: ActivationEvent.oneOf(ActivationEvents.Startup, CountEvent),
|
|
547
|
+
activate: () => {
|
|
548
|
+
count++;
|
|
549
|
+
return Effect.succeed(Capability.contributes(String, { string: 'hello' }));
|
|
550
|
+
},
|
|
551
|
+
}),
|
|
552
|
+
Plugin.make,
|
|
553
|
+
);
|
|
554
|
+
const testPlugin = Test();
|
|
555
|
+
plugins = [testPlugin];
|
|
556
|
+
|
|
557
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
558
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
559
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 0);
|
|
560
|
+
assert.strictEqual(count, 0);
|
|
561
|
+
|
|
562
|
+
yield* manager.add(testMeta.id);
|
|
563
|
+
yield* manager.enable(testMeta.id);
|
|
564
|
+
yield* manager.activate(CountEvent);
|
|
565
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
566
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 1);
|
|
567
|
+
assert.strictEqual(count, 1);
|
|
568
|
+
|
|
569
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
570
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
571
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 1);
|
|
572
|
+
assert.strictEqual(count, 1);
|
|
573
|
+
}),
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
it.effect('should be able to disable and re-enable an active plugin', () =>
|
|
577
|
+
Effect.gen(function* () {
|
|
578
|
+
const state = { total: 0 };
|
|
579
|
+
const computeTotal = (capabilityManager: CapabilityManager.CapabilityManager) => {
|
|
580
|
+
const numbers = capabilityManager.getAll(Number);
|
|
581
|
+
state.total = numbers.reduce((acc: number, n: { number: number }) => acc + n.number, 0);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const Count = Plugin.define({ id: 'org.dxos.test.count', name: 'Count' }).pipe(
|
|
585
|
+
Plugin.addModule({
|
|
586
|
+
id: 'Count',
|
|
587
|
+
activatesOn: ActivationEvents.Startup,
|
|
588
|
+
firesBeforeActivation: [CountEvent],
|
|
589
|
+
activate: Effect.fnUntraced(function* () {
|
|
590
|
+
const capabilityManager = yield* Capability.Service;
|
|
591
|
+
computeTotal(capabilityManager);
|
|
592
|
+
return Capability.contributes(Total, state);
|
|
593
|
+
}),
|
|
594
|
+
}),
|
|
595
|
+
Plugin.make,
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
599
|
+
Plugin.addModule({
|
|
600
|
+
activatesOn: CountEvent,
|
|
601
|
+
id: 'Test1',
|
|
602
|
+
activate: () => Effect.succeed(Capability.contributes(Number, { number: 1 })),
|
|
603
|
+
}),
|
|
604
|
+
Plugin.addModule({
|
|
605
|
+
id: 'Test2',
|
|
606
|
+
activatesOn: CountEvent,
|
|
607
|
+
activate: () => Effect.succeed(Capability.contributes(Number, { number: 2 })),
|
|
608
|
+
}),
|
|
609
|
+
Plugin.addModule({
|
|
610
|
+
id: 'Test3',
|
|
611
|
+
activatesOn: CountEvent,
|
|
612
|
+
activate: () => Effect.succeed(Capability.contributes(Number, { number: 3 })),
|
|
613
|
+
}),
|
|
614
|
+
Plugin.make,
|
|
615
|
+
);
|
|
616
|
+
const countPlugin = Count();
|
|
617
|
+
const testPlugin = Test();
|
|
618
|
+
plugins = [countPlugin, testPlugin];
|
|
619
|
+
|
|
620
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
621
|
+
{
|
|
622
|
+
yield* manager.add(Test.meta.id);
|
|
623
|
+
yield* manager.enable(Test.meta.id);
|
|
624
|
+
yield* manager.add(Count.meta.id);
|
|
625
|
+
yield* manager.enable(Count.meta.id);
|
|
626
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
627
|
+
assert.deepStrictEqual(manager.getActive(), [
|
|
628
|
+
...testPlugin.modules.map((m) => m.id),
|
|
629
|
+
countPlugin.modules[0].id,
|
|
630
|
+
]);
|
|
631
|
+
assert.deepStrictEqual(manager.getPendingReset(), []);
|
|
632
|
+
|
|
633
|
+
const totals = manager.capabilities.getAll(Total);
|
|
634
|
+
assert.strictEqual(totals.length, 1);
|
|
635
|
+
assert.strictEqual(totals[0].total, 6);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
{
|
|
639
|
+
yield* manager.disable(Test.meta.id);
|
|
640
|
+
assert.deepStrictEqual(manager.getActive(), [countPlugin.modules[0].id]);
|
|
641
|
+
assert.deepStrictEqual(manager.getPendingReset(), []);
|
|
642
|
+
|
|
643
|
+
const totals = manager.capabilities.getAll(Total);
|
|
644
|
+
assert.strictEqual(totals.length, 1);
|
|
645
|
+
// Total doesn't change because it is not reactive.
|
|
646
|
+
assert.strictEqual(totals[0].total, 6);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
{
|
|
650
|
+
yield* manager.enable(Test.meta.id);
|
|
651
|
+
assert.deepStrictEqual(manager.getActive(), [
|
|
652
|
+
countPlugin.modules[0].id,
|
|
653
|
+
...testPlugin.modules.map((m) => m.id),
|
|
654
|
+
]);
|
|
655
|
+
assert.deepStrictEqual(manager.getPendingReset(), []);
|
|
656
|
+
|
|
657
|
+
const totals = manager.capabilities.getAll(Total);
|
|
658
|
+
assert.strictEqual(totals.length, 1);
|
|
659
|
+
assert.strictEqual(totals[0].total, 6);
|
|
660
|
+
}
|
|
661
|
+
}),
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
it.effect('should be reactive', () =>
|
|
665
|
+
Effect.gen(function* () {
|
|
666
|
+
const Plugin1 = Plugin.define({ id: 'org.dxos.test.plugin-1', name: 'Plugin 1' }).pipe(
|
|
667
|
+
Plugin.addModule({
|
|
668
|
+
activatesOn: CountEvent,
|
|
669
|
+
id: 'Plugin1',
|
|
670
|
+
activate: () => Effect.succeed([Capability.contributes(Number, { number: 1 })]),
|
|
671
|
+
}),
|
|
672
|
+
Plugin.make,
|
|
673
|
+
);
|
|
674
|
+
const Plugin2 = Plugin.define({ id: 'org.dxos.test.plugin-2', name: 'Plugin 2' }).pipe(
|
|
675
|
+
Plugin.addModule({
|
|
676
|
+
activatesOn: CountEvent,
|
|
677
|
+
id: 'Plugin2',
|
|
678
|
+
activate: () => Effect.succeed([Capability.contributes(Number, { number: 2 })]),
|
|
679
|
+
}),
|
|
680
|
+
Plugin.make,
|
|
681
|
+
);
|
|
682
|
+
const Plugin3 = Plugin.define({ id: 'org.dxos.test.plugin-3', name: 'Plugin 3' }).pipe(
|
|
683
|
+
Plugin.addModule({
|
|
684
|
+
activatesOn: CountEvent,
|
|
685
|
+
id: 'Plugin3',
|
|
686
|
+
activate: () => Effect.succeed([Capability.contributes(Number, { number: 3 })]),
|
|
687
|
+
}),
|
|
688
|
+
Plugin.make,
|
|
689
|
+
);
|
|
690
|
+
plugins = [Plugin1(), Plugin2(), Plugin3()];
|
|
691
|
+
|
|
692
|
+
const registry = Registry.make();
|
|
693
|
+
const manager = PluginManager.make({ pluginLoader, registry });
|
|
694
|
+
using pluginUpdates = atomCounter(registry, manager.plugins);
|
|
695
|
+
using enabledUpdates = atomCounter(registry, manager.enabled);
|
|
696
|
+
using modulesUpdates = atomCounter(registry, manager.modules);
|
|
697
|
+
using activeUpdates = atomCounter(registry, manager.active);
|
|
698
|
+
using eventsFiredUpdates = atomCounter(registry, manager.eventsFired);
|
|
699
|
+
using pendingResetUpdates = atomCounter(registry, manager.pendingReset);
|
|
700
|
+
assert.strictEqual(pluginUpdates.count, 0);
|
|
701
|
+
assert.strictEqual(enabledUpdates.count, 0);
|
|
702
|
+
assert.strictEqual(modulesUpdates.count, 0);
|
|
703
|
+
assert.strictEqual(activeUpdates.count, 0);
|
|
704
|
+
assert.strictEqual(eventsFiredUpdates.count, 0);
|
|
705
|
+
assert.strictEqual(pendingResetUpdates.count, 0);
|
|
706
|
+
|
|
707
|
+
yield* manager.add(Plugin1.meta.id);
|
|
708
|
+
yield* manager.enable(Plugin1.meta.id);
|
|
709
|
+
assert.strictEqual(pluginUpdates.count, 1);
|
|
710
|
+
assert.strictEqual(enabledUpdates.count, 1);
|
|
711
|
+
assert.strictEqual(modulesUpdates.count, 1);
|
|
712
|
+
assert.strictEqual(activeUpdates.count, 0);
|
|
713
|
+
assert.strictEqual(eventsFiredUpdates.count, 0);
|
|
714
|
+
assert.strictEqual(pendingResetUpdates.count, 0);
|
|
715
|
+
|
|
716
|
+
yield* manager.activate(CountEvent);
|
|
717
|
+
assert.strictEqual(pluginUpdates.count, 1);
|
|
718
|
+
assert.strictEqual(enabledUpdates.count, 1);
|
|
719
|
+
assert.strictEqual(modulesUpdates.count, 1);
|
|
720
|
+
assert.strictEqual(activeUpdates.count, 1);
|
|
721
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
722
|
+
assert.strictEqual(pendingResetUpdates.count, 0);
|
|
723
|
+
|
|
724
|
+
yield* manager.add(Plugin2.meta.id);
|
|
725
|
+
yield* manager.enable(Plugin2.meta.id);
|
|
726
|
+
assert.strictEqual(pluginUpdates.count, 2);
|
|
727
|
+
assert.strictEqual(enabledUpdates.count, 2);
|
|
728
|
+
assert.strictEqual(modulesUpdates.count, 2);
|
|
729
|
+
assert.strictEqual(activeUpdates.count, 2);
|
|
730
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
731
|
+
assert.strictEqual(pendingResetUpdates.count, 2);
|
|
732
|
+
|
|
733
|
+
yield* manager.activate(CountEvent);
|
|
734
|
+
assert.strictEqual(pluginUpdates.count, 2);
|
|
735
|
+
assert.strictEqual(enabledUpdates.count, 2);
|
|
736
|
+
assert.strictEqual(modulesUpdates.count, 2);
|
|
737
|
+
assert.strictEqual(activeUpdates.count, 2);
|
|
738
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
739
|
+
assert.strictEqual(pendingResetUpdates.count, 2);
|
|
740
|
+
|
|
741
|
+
yield* manager.add(Plugin3.meta.id);
|
|
742
|
+
yield* manager.enable(Plugin3.meta.id);
|
|
743
|
+
assert.strictEqual(pluginUpdates.count, 3);
|
|
744
|
+
assert.strictEqual(enabledUpdates.count, 3);
|
|
745
|
+
assert.strictEqual(modulesUpdates.count, 3);
|
|
746
|
+
assert.strictEqual(activeUpdates.count, 3);
|
|
747
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
748
|
+
assert.strictEqual(pendingResetUpdates.count, 4);
|
|
749
|
+
|
|
750
|
+
yield* manager.reset(CountEvent);
|
|
751
|
+
assert.strictEqual(pluginUpdates.count, 3);
|
|
752
|
+
assert.strictEqual(enabledUpdates.count, 3);
|
|
753
|
+
assert.strictEqual(modulesUpdates.count, 3);
|
|
754
|
+
// Starts at 3, plus deactivates 3, plus activates 3.
|
|
755
|
+
assert.strictEqual(activeUpdates.count, 9);
|
|
756
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
757
|
+
assert.strictEqual(pendingResetUpdates.count, 4);
|
|
758
|
+
|
|
759
|
+
yield* manager.disable(Plugin1.meta.id);
|
|
760
|
+
assert.strictEqual(pluginUpdates.count, 3);
|
|
761
|
+
assert.strictEqual(enabledUpdates.count, 4);
|
|
762
|
+
assert.strictEqual(modulesUpdates.count, 4);
|
|
763
|
+
assert.strictEqual(activeUpdates.count, 10);
|
|
764
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
765
|
+
assert.strictEqual(pendingResetUpdates.count, 4);
|
|
766
|
+
|
|
767
|
+
yield* manager.remove(Plugin1.meta.id);
|
|
768
|
+
assert.strictEqual(pluginUpdates.count, 4);
|
|
769
|
+
assert.strictEqual(enabledUpdates.count, 4);
|
|
770
|
+
assert.strictEqual(modulesUpdates.count, 4);
|
|
771
|
+
assert.strictEqual(activeUpdates.count, 10);
|
|
772
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
773
|
+
assert.strictEqual(pendingResetUpdates.count, 4);
|
|
774
|
+
|
|
775
|
+
yield* manager.reset(CountEvent);
|
|
776
|
+
assert.strictEqual(pluginUpdates.count, 4);
|
|
777
|
+
assert.strictEqual(enabledUpdates.count, 4);
|
|
778
|
+
assert.strictEqual(modulesUpdates.count, 4);
|
|
779
|
+
// Starts at 10, plus deactivates 2, plus activates 2.
|
|
780
|
+
assert.strictEqual(activeUpdates.count, 14);
|
|
781
|
+
assert.strictEqual(eventsFiredUpdates.count, 1);
|
|
782
|
+
assert.strictEqual(pendingResetUpdates.count, 4);
|
|
783
|
+
}),
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
it.effect('should log a warning when a module takes too long to activate', () =>
|
|
787
|
+
Effect.gen(function* () {
|
|
788
|
+
const capturedWarnings: LogEntry[] = [];
|
|
789
|
+
const removeProcessor = log.addProcessor((_config: LogConfig, entry: LogEntry) => {
|
|
790
|
+
if (entry.level === LogLevel.WARN) {
|
|
791
|
+
capturedWarnings.push(entry);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
const SlowEvent = ActivationEvent.make('org.dxos.test.slow');
|
|
796
|
+
const SlowPlugin = Plugin.define({ id: 'org.dxos.test.slow-plugin', name: 'Slow Plugin' }).pipe(
|
|
797
|
+
Plugin.addModule({
|
|
798
|
+
id: 'SlowModule',
|
|
799
|
+
activatesOn: SlowEvent,
|
|
800
|
+
activate: Effect.fnUntraced(function* () {
|
|
801
|
+
// Simulate a slow activation that takes 15 seconds.
|
|
802
|
+
yield* Effect.sleep(Duration.seconds(15));
|
|
803
|
+
return Capability.contributes(String, { string: 'slow' });
|
|
804
|
+
}),
|
|
805
|
+
}),
|
|
806
|
+
Plugin.make,
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
const slowPlugin = SlowPlugin();
|
|
810
|
+
plugins = [slowPlugin];
|
|
811
|
+
|
|
812
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
813
|
+
yield* manager.add(SlowPlugin.meta.id);
|
|
814
|
+
yield* manager.enable(SlowPlugin.meta.id);
|
|
815
|
+
|
|
816
|
+
// Fork the activation so we can control time with TestClock.
|
|
817
|
+
const activationFiber = yield* Effect.fork(manager.activate(SlowEvent));
|
|
818
|
+
|
|
819
|
+
// Advance time past the 10 second warning threshold.
|
|
820
|
+
yield* TestClock.adjust(Duration.seconds(11));
|
|
821
|
+
|
|
822
|
+
// Check that the warning was logged.
|
|
823
|
+
assert.isTrue(
|
|
824
|
+
capturedWarnings.some((entry) => entry.message?.includes('module is taking a long time to activate')),
|
|
825
|
+
'Expected a warning about slow module activation',
|
|
826
|
+
);
|
|
827
|
+
|
|
828
|
+
// Advance time to let the module finish activating.
|
|
829
|
+
yield* TestClock.adjust(Duration.seconds(5));
|
|
830
|
+
yield* Fiber.join(activationFiber);
|
|
831
|
+
|
|
832
|
+
removeProcessor();
|
|
833
|
+
}),
|
|
834
|
+
);
|
|
835
|
+
|
|
836
|
+
it.effect('should prevent concurrent loads of the same module via semaphore', () =>
|
|
837
|
+
Effect.gen(function* () {
|
|
838
|
+
// Two different events that both can trigger the same module.
|
|
839
|
+
const EventA = ActivationEvent.make('org.dxos.test.event-a');
|
|
840
|
+
const EventB = ActivationEvent.make('org.dxos.test.event-b');
|
|
841
|
+
|
|
842
|
+
let activateCallCount = 0;
|
|
843
|
+
const ConcurrentPlugin = Plugin.define({ id: 'org.dxos.test.concurrent-plugin', name: 'Concurrent Plugin' }).pipe(
|
|
844
|
+
Plugin.addModule({
|
|
845
|
+
id: 'ConcurrentModule',
|
|
846
|
+
// Module activates on either event - this allows two different events to race.
|
|
847
|
+
activatesOn: ActivationEvent.oneOf(EventA, EventB),
|
|
848
|
+
activate: Effect.fnUntraced(function* () {
|
|
849
|
+
activateCallCount++;
|
|
850
|
+
// Simulate slow activation to create window for race condition.
|
|
851
|
+
yield* Effect.sleep(Duration.seconds(5));
|
|
852
|
+
return Capability.contributes(String, { string: 'concurrent' });
|
|
853
|
+
}),
|
|
854
|
+
}),
|
|
855
|
+
Plugin.make,
|
|
856
|
+
);
|
|
857
|
+
|
|
858
|
+
const concurrentPlugin = ConcurrentPlugin();
|
|
859
|
+
plugins = [concurrentPlugin];
|
|
860
|
+
|
|
861
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
862
|
+
yield* manager.add(ConcurrentPlugin.meta.id);
|
|
863
|
+
yield* manager.enable(ConcurrentPlugin.meta.id);
|
|
864
|
+
|
|
865
|
+
// Fork two concurrent activations with DIFFERENT events.
|
|
866
|
+
// Both events trigger the same module, so both will try to call _loadModule.
|
|
867
|
+
// Without the semaphore, both would start loading the same module.
|
|
868
|
+
const fiber1 = yield* Effect.fork(manager.activate(EventA));
|
|
869
|
+
const fiber2 = yield* Effect.fork(manager.activate(EventB));
|
|
870
|
+
|
|
871
|
+
// Advance time to let both activations complete.
|
|
872
|
+
yield* TestClock.adjust(Duration.seconds(6));
|
|
873
|
+
|
|
874
|
+
yield* Fiber.join(fiber1);
|
|
875
|
+
yield* Fiber.join(fiber2);
|
|
876
|
+
|
|
877
|
+
// The semaphore should ensure the module's activate function is only called once,
|
|
878
|
+
// even when two different events race to load the same module.
|
|
879
|
+
assert.strictEqual(activateCallCount, 1, 'module activate should only be called once due to semaphore');
|
|
880
|
+
|
|
881
|
+
// Verify the capability was contributed.
|
|
882
|
+
const strings = manager.capabilities.getAll(String);
|
|
883
|
+
assert.isTrue(strings.length >= 1, 'capability should be contributed');
|
|
884
|
+
assert.strictEqual(strings[0].string, 'concurrent');
|
|
885
|
+
}),
|
|
886
|
+
);
|
|
887
|
+
|
|
888
|
+
it.effect('should deactivate all active modules on shutdown', () =>
|
|
889
|
+
Effect.gen(function* () {
|
|
890
|
+
const Plugin1 = Plugin.define({ id: 'org.dxos.test.plugin-1', name: 'Plugin 1' }).pipe(
|
|
891
|
+
Plugin.addModule({
|
|
892
|
+
activatesOn: ActivationEvents.Startup,
|
|
893
|
+
id: 'Plugin1',
|
|
894
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
895
|
+
}),
|
|
896
|
+
Plugin.make,
|
|
897
|
+
);
|
|
898
|
+
const Plugin2 = Plugin.define({ id: 'org.dxos.test.plugin-2', name: 'Plugin 2' }).pipe(
|
|
899
|
+
Plugin.addModule({
|
|
900
|
+
activatesOn: ActivationEvents.Startup,
|
|
901
|
+
id: 'Plugin2',
|
|
902
|
+
activate: () => Effect.succeed(Capability.contributes(Number, { number: 42 })),
|
|
903
|
+
}),
|
|
904
|
+
Plugin.make,
|
|
905
|
+
);
|
|
906
|
+
const plugin1 = Plugin1();
|
|
907
|
+
const plugin2 = Plugin2();
|
|
908
|
+
plugins = [plugin1, plugin2];
|
|
909
|
+
|
|
910
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
911
|
+
yield* manager.add(Plugin1.meta.id);
|
|
912
|
+
yield* manager.enable(Plugin1.meta.id);
|
|
913
|
+
yield* manager.add(Plugin2.meta.id);
|
|
914
|
+
yield* manager.enable(Plugin2.meta.id);
|
|
915
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
916
|
+
assert.strictEqual(manager.getActive().length, 2);
|
|
917
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 1);
|
|
918
|
+
assert.strictEqual(manager.capabilities.getAll(Number).length, 1);
|
|
919
|
+
|
|
920
|
+
const result = yield* manager.shutdown();
|
|
921
|
+
assert.isTrue(result);
|
|
922
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
923
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 0);
|
|
924
|
+
assert.strictEqual(manager.capabilities.getAll(Number).length, 0);
|
|
925
|
+
}),
|
|
926
|
+
);
|
|
927
|
+
|
|
928
|
+
it.effect('should run capability deactivate hooks during shutdown', () =>
|
|
929
|
+
Effect.gen(function* () {
|
|
930
|
+
let deactivated = false;
|
|
931
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
932
|
+
Plugin.addModule({
|
|
933
|
+
id: 'WithDeactivate',
|
|
934
|
+
activatesOn: ActivationEvents.Startup,
|
|
935
|
+
activate: () =>
|
|
936
|
+
Effect.succeed(
|
|
937
|
+
Capability.contributes(String, { string: 'hello' }, () =>
|
|
938
|
+
Effect.sync(() => {
|
|
939
|
+
deactivated = true;
|
|
940
|
+
}),
|
|
941
|
+
),
|
|
942
|
+
),
|
|
943
|
+
}),
|
|
944
|
+
Plugin.make,
|
|
945
|
+
);
|
|
946
|
+
const testPlugin = Test();
|
|
947
|
+
plugins = [testPlugin];
|
|
948
|
+
|
|
949
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
950
|
+
yield* manager.add(testMeta.id);
|
|
951
|
+
yield* manager.enable(testMeta.id);
|
|
952
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
953
|
+
assert.isFalse(deactivated);
|
|
954
|
+
|
|
955
|
+
yield* manager.shutdown();
|
|
956
|
+
assert.isTrue(deactivated);
|
|
957
|
+
}),
|
|
958
|
+
);
|
|
959
|
+
|
|
960
|
+
it.effect('should deactivate modules in reverse activation order during shutdown', () =>
|
|
961
|
+
Effect.gen(function* () {
|
|
962
|
+
const deactivationOrder: string[] = [];
|
|
963
|
+
const Plugin1 = Plugin.define({ id: 'org.dxos.test.plugin-1', name: 'Plugin 1' }).pipe(
|
|
964
|
+
Plugin.addModule({
|
|
965
|
+
activatesOn: ActivationEvents.Startup,
|
|
966
|
+
id: 'First',
|
|
967
|
+
activate: () =>
|
|
968
|
+
Effect.succeed(
|
|
969
|
+
Capability.contributes(String, { string: 'first' }, () =>
|
|
970
|
+
Effect.sync(() => {
|
|
971
|
+
deactivationOrder.push('First');
|
|
972
|
+
}),
|
|
973
|
+
),
|
|
974
|
+
),
|
|
975
|
+
}),
|
|
976
|
+
Plugin.make,
|
|
977
|
+
);
|
|
978
|
+
const Plugin2 = Plugin.define({ id: 'org.dxos.test.plugin-2', name: 'Plugin 2' }).pipe(
|
|
979
|
+
Plugin.addModule({
|
|
980
|
+
activatesOn: ActivationEvents.Startup,
|
|
981
|
+
id: 'Second',
|
|
982
|
+
activate: () =>
|
|
983
|
+
Effect.succeed(
|
|
984
|
+
Capability.contributes(Number, { number: 2 }, () =>
|
|
985
|
+
Effect.sync(() => {
|
|
986
|
+
deactivationOrder.push('Second');
|
|
987
|
+
}),
|
|
988
|
+
),
|
|
989
|
+
),
|
|
990
|
+
}),
|
|
991
|
+
Plugin.make,
|
|
992
|
+
);
|
|
993
|
+
plugins = [Plugin1(), Plugin2()];
|
|
994
|
+
|
|
995
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
996
|
+
yield* manager.add(Plugin1.meta.id);
|
|
997
|
+
yield* manager.enable(Plugin1.meta.id);
|
|
998
|
+
yield* manager.add(Plugin2.meta.id);
|
|
999
|
+
yield* manager.enable(Plugin2.meta.id);
|
|
1000
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1001
|
+
|
|
1002
|
+
yield* manager.shutdown();
|
|
1003
|
+
assert.deepStrictEqual(deactivationOrder, ['Second', 'First']);
|
|
1004
|
+
}),
|
|
1005
|
+
);
|
|
1006
|
+
|
|
1007
|
+
it.effect('should clear lifecycle bookkeeping during shutdown', () =>
|
|
1008
|
+
Effect.gen(function* () {
|
|
1009
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
1010
|
+
Plugin.addModule({
|
|
1011
|
+
id: 'Hello',
|
|
1012
|
+
activatesOn: ActivationEvents.Startup,
|
|
1013
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
1014
|
+
}),
|
|
1015
|
+
Plugin.make,
|
|
1016
|
+
);
|
|
1017
|
+
const testPlugin = Test();
|
|
1018
|
+
plugins = [testPlugin];
|
|
1019
|
+
|
|
1020
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1021
|
+
yield* manager.add(testMeta.id);
|
|
1022
|
+
yield* manager.enable(testMeta.id);
|
|
1023
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1024
|
+
assert.isTrue(manager.getEventsFired().length > 0);
|
|
1025
|
+
|
|
1026
|
+
yield* manager.shutdown();
|
|
1027
|
+
assert.deepStrictEqual(manager.getEventsFired(), []);
|
|
1028
|
+
assert.deepStrictEqual(manager.getPendingReset(), []);
|
|
1029
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
1030
|
+
}),
|
|
1031
|
+
);
|
|
1032
|
+
|
|
1033
|
+
it.effect('should interrupt in-flight activation during shutdown', () =>
|
|
1034
|
+
Effect.gen(function* () {
|
|
1035
|
+
const activationStarted = yield* Effect.makeLatch(false);
|
|
1036
|
+
const allowActivationToComplete = yield* Effect.makeLatch(false);
|
|
1037
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
1038
|
+
Plugin.addModule({
|
|
1039
|
+
id: 'Hello',
|
|
1040
|
+
activatesOn: ActivationEvents.Startup,
|
|
1041
|
+
activate: () =>
|
|
1042
|
+
Effect.gen(function* () {
|
|
1043
|
+
yield* activationStarted.open;
|
|
1044
|
+
yield* allowActivationToComplete.await;
|
|
1045
|
+
return Capability.contributes(String, { string: 'hello' });
|
|
1046
|
+
}),
|
|
1047
|
+
}),
|
|
1048
|
+
Plugin.make,
|
|
1049
|
+
);
|
|
1050
|
+
const testPlugin = Test();
|
|
1051
|
+
plugins = [testPlugin];
|
|
1052
|
+
|
|
1053
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1054
|
+
yield* manager.add(testMeta.id);
|
|
1055
|
+
yield* manager.enable(testMeta.id);
|
|
1056
|
+
|
|
1057
|
+
const activationFiber = yield* Effect.fork(manager.activate(ActivationEvents.Startup));
|
|
1058
|
+
yield* activationStarted.await;
|
|
1059
|
+
|
|
1060
|
+
const shutdownFiber = yield* Effect.fork(manager.shutdown());
|
|
1061
|
+
yield* allowActivationToComplete.open;
|
|
1062
|
+
|
|
1063
|
+
const shutdownResult = yield* Fiber.join(shutdownFiber);
|
|
1064
|
+
const activationExit = yield* Fiber.await(activationFiber);
|
|
1065
|
+
|
|
1066
|
+
assert.isTrue(shutdownResult);
|
|
1067
|
+
assert.isTrue(Exit.isFailure(activationExit));
|
|
1068
|
+
if (Exit.isFailure(activationExit)) {
|
|
1069
|
+
assert.isTrue(Cause.isInterruptedOnly(activationExit.cause));
|
|
1070
|
+
}
|
|
1071
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 0);
|
|
1072
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
1073
|
+
assert.deepStrictEqual(manager.getEventsFired(), []);
|
|
1074
|
+
}),
|
|
1075
|
+
);
|
|
1076
|
+
|
|
1077
|
+
it.effect('should preserve plugins, core, enabled, and modules after shutdown', () =>
|
|
1078
|
+
Effect.gen(function* () {
|
|
1079
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
1080
|
+
Plugin.addModule({
|
|
1081
|
+
id: 'Hello',
|
|
1082
|
+
activatesOn: ActivationEvents.Startup,
|
|
1083
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
1084
|
+
}),
|
|
1085
|
+
Plugin.make,
|
|
1086
|
+
);
|
|
1087
|
+
const testPlugin = Test();
|
|
1088
|
+
plugins = [testPlugin];
|
|
1089
|
+
|
|
1090
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1091
|
+
yield* manager.add(testMeta.id);
|
|
1092
|
+
yield* manager.enable(testMeta.id);
|
|
1093
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1094
|
+
|
|
1095
|
+
const pluginsBefore = manager.getPlugins();
|
|
1096
|
+
const coreBefore = manager.getCore();
|
|
1097
|
+
const enabledBefore = manager.getEnabled();
|
|
1098
|
+
const modulesBefore = manager.getModules();
|
|
1099
|
+
|
|
1100
|
+
yield* manager.shutdown();
|
|
1101
|
+
|
|
1102
|
+
assert.deepStrictEqual(manager.getPlugins(), pluginsBefore);
|
|
1103
|
+
assert.deepStrictEqual(manager.getCore(), coreBefore);
|
|
1104
|
+
assert.deepStrictEqual(manager.getEnabled(), enabledBefore);
|
|
1105
|
+
assert.deepStrictEqual(manager.getModules(), modulesBefore);
|
|
1106
|
+
}),
|
|
1107
|
+
);
|
|
1108
|
+
|
|
1109
|
+
it.effect('should allow re-activation after shutdown', () =>
|
|
1110
|
+
Effect.gen(function* () {
|
|
1111
|
+
let activateCount = 0;
|
|
1112
|
+
const Test = Plugin.define(testMeta).pipe(
|
|
1113
|
+
Plugin.addModule({
|
|
1114
|
+
id: 'Hello',
|
|
1115
|
+
activatesOn: ActivationEvents.Startup,
|
|
1116
|
+
activate: () => {
|
|
1117
|
+
activateCount++;
|
|
1118
|
+
return Effect.succeed(Capability.contributes(String, { string: 'hello' }));
|
|
1119
|
+
},
|
|
1120
|
+
}),
|
|
1121
|
+
Plugin.make,
|
|
1122
|
+
);
|
|
1123
|
+
const testPlugin = Test();
|
|
1124
|
+
plugins = [testPlugin];
|
|
1125
|
+
|
|
1126
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1127
|
+
yield* manager.add(testMeta.id);
|
|
1128
|
+
yield* manager.enable(testMeta.id);
|
|
1129
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1130
|
+
assert.strictEqual(activateCount, 1);
|
|
1131
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
1132
|
+
|
|
1133
|
+
yield* manager.shutdown();
|
|
1134
|
+
assert.deepStrictEqual(manager.getActive(), []);
|
|
1135
|
+
|
|
1136
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1137
|
+
assert.strictEqual(activateCount, 2);
|
|
1138
|
+
assert.deepStrictEqual(manager.getActive(), [testPlugin.modules[0].id]);
|
|
1139
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 1);
|
|
1140
|
+
}),
|
|
1141
|
+
);
|
|
1142
|
+
|
|
1143
|
+
describe('Plugin.lazy', () => {
|
|
1144
|
+
const lazyMeta = { id: 'org.dxos.plugin.lazy', name: 'Lazy' };
|
|
1145
|
+
|
|
1146
|
+
it('exposes meta synchronously without invoking the loader', () => {
|
|
1147
|
+
let loaderCalls = 0;
|
|
1148
|
+
const Real = Plugin.make(Plugin.define<void>(lazyMeta));
|
|
1149
|
+
const LazyTest = Plugin.lazy(lazyMeta, () => {
|
|
1150
|
+
loaderCalls++;
|
|
1151
|
+
return Promise.resolve({ default: Real });
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
assert.strictEqual(LazyTest.meta.id, lazyMeta.id);
|
|
1155
|
+
assert.strictEqual(LazyTest.meta.name, 'Lazy');
|
|
1156
|
+
assert.strictEqual(loaderCalls, 0);
|
|
1157
|
+
|
|
1158
|
+
const stub = LazyTest();
|
|
1159
|
+
assert.strictEqual(stub.meta.id, lazyMeta.id);
|
|
1160
|
+
assert.deepStrictEqual([...stub.modules], []);
|
|
1161
|
+
assert.isTrue(Plugin.isLazy(stub));
|
|
1162
|
+
assert.strictEqual(loaderCalls, 0);
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
it.effect('resolves the loader on enable and registers the real plugin modules', () =>
|
|
1166
|
+
Effect.gen(function* () {
|
|
1167
|
+
let loaderCalls = 0;
|
|
1168
|
+
const Real = Plugin.define(lazyMeta).pipe(
|
|
1169
|
+
Plugin.addModule({
|
|
1170
|
+
id: 'Hello',
|
|
1171
|
+
activatesOn: ActivationEvents.Startup,
|
|
1172
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
1173
|
+
}),
|
|
1174
|
+
Plugin.make,
|
|
1175
|
+
);
|
|
1176
|
+
const LazyTest = Plugin.lazy(lazyMeta, () => {
|
|
1177
|
+
loaderCalls++;
|
|
1178
|
+
return Promise.resolve({ default: Real });
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
const lazyStub = LazyTest();
|
|
1182
|
+
plugins = [lazyStub];
|
|
1183
|
+
|
|
1184
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1185
|
+
yield* manager.add(lazyMeta.id);
|
|
1186
|
+
// Loader has not been invoked yet — only meta is exposed.
|
|
1187
|
+
assert.strictEqual(loaderCalls, 0);
|
|
1188
|
+
assert.deepStrictEqual(manager.getModules(), []);
|
|
1189
|
+
|
|
1190
|
+
yield* manager.enable(lazyMeta.id);
|
|
1191
|
+
assert.strictEqual(loaderCalls, 1);
|
|
1192
|
+
// After enable the registered plugin should be the real one (not the stub),
|
|
1193
|
+
// and its modules should be registered with the manager.
|
|
1194
|
+
const registered = manager.getPlugins().find((p) => p.meta.id === lazyMeta.id);
|
|
1195
|
+
assert.isDefined(registered);
|
|
1196
|
+
assert.isFalse(Plugin.isLazy(registered!));
|
|
1197
|
+
assert.strictEqual(registered!.modules.length, 1);
|
|
1198
|
+
|
|
1199
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1200
|
+
assert.strictEqual(manager.capabilities.getAll(String).length, 1);
|
|
1201
|
+
}),
|
|
1202
|
+
);
|
|
1203
|
+
|
|
1204
|
+
it.effect('does not invoke the loader if the plugin is never enabled', () =>
|
|
1205
|
+
Effect.gen(function* () {
|
|
1206
|
+
let loaderCalls = 0;
|
|
1207
|
+
const Real = Plugin.make(Plugin.define<void>(lazyMeta));
|
|
1208
|
+
const LazyTest = Plugin.lazy(lazyMeta, () => {
|
|
1209
|
+
loaderCalls++;
|
|
1210
|
+
return Promise.resolve({ default: Real });
|
|
1211
|
+
});
|
|
1212
|
+
const lazyStub = LazyTest();
|
|
1213
|
+
plugins = [lazyStub];
|
|
1214
|
+
|
|
1215
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1216
|
+
yield* manager.add(lazyMeta.id);
|
|
1217
|
+
|
|
1218
|
+
// Activate an event that has no listeners — the lazy plugin must not load.
|
|
1219
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1220
|
+
assert.strictEqual(loaderCalls, 0);
|
|
1221
|
+
}),
|
|
1222
|
+
);
|
|
1223
|
+
|
|
1224
|
+
it.effect('forwards factory options to the real plugin factory', () =>
|
|
1225
|
+
Effect.gen(function* () {
|
|
1226
|
+
type Opts = { greeting: string };
|
|
1227
|
+
const RealFactory = (opts: Opts) =>
|
|
1228
|
+
Plugin.define(lazyMeta).pipe(
|
|
1229
|
+
Plugin.addModule({
|
|
1230
|
+
id: 'Hello',
|
|
1231
|
+
activatesOn: ActivationEvents.Startup,
|
|
1232
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: opts.greeting })),
|
|
1233
|
+
}),
|
|
1234
|
+
Plugin.make,
|
|
1235
|
+
)(undefined as void);
|
|
1236
|
+
|
|
1237
|
+
const RealFactoryWithMeta = Object.assign(RealFactory, { meta: lazyMeta });
|
|
1238
|
+
|
|
1239
|
+
const LazyTest = Plugin.lazy<Opts>(lazyMeta, () => Promise.resolve({ default: RealFactoryWithMeta }));
|
|
1240
|
+
const lazyStub = LazyTest({ greeting: 'hola' });
|
|
1241
|
+
plugins = [lazyStub];
|
|
1242
|
+
|
|
1243
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1244
|
+
yield* manager.add(lazyMeta.id);
|
|
1245
|
+
yield* manager.enable(lazyMeta.id);
|
|
1246
|
+
yield* manager.activate(ActivationEvents.Startup);
|
|
1247
|
+
|
|
1248
|
+
const all = manager.capabilities.getAll(String);
|
|
1249
|
+
assert.strictEqual(all.length, 1);
|
|
1250
|
+
assert.strictEqual(all[0].string, 'hola');
|
|
1251
|
+
}),
|
|
1252
|
+
);
|
|
1253
|
+
|
|
1254
|
+
it.effect('wraps loader rejections in a descriptive error', () =>
|
|
1255
|
+
Effect.gen(function* () {
|
|
1256
|
+
const LazyTest = Plugin.lazy(lazyMeta, () =>
|
|
1257
|
+
Promise.reject<{ default: Plugin.PluginFactory }>(new Error('boom')),
|
|
1258
|
+
);
|
|
1259
|
+
const lazyStub = LazyTest();
|
|
1260
|
+
plugins = [lazyStub];
|
|
1261
|
+
|
|
1262
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1263
|
+
yield* manager.add(lazyMeta.id);
|
|
1264
|
+
|
|
1265
|
+
const exit = yield* Effect.exit(manager.enable(lazyMeta.id));
|
|
1266
|
+
assert.isTrue(Exit.isFailure(exit));
|
|
1267
|
+
if (Exit.isFailure(exit)) {
|
|
1268
|
+
const failure = Cause.failureOption(exit.cause);
|
|
1269
|
+
assert.isTrue(failure._tag === 'Some');
|
|
1270
|
+
if (failure._tag === 'Some') {
|
|
1271
|
+
assert.isTrue(Plugin.LazyPluginError.is(failure.value));
|
|
1272
|
+
assert.strictEqual((failure.value as Plugin.LazyPluginError).context.id, lazyMeta.id);
|
|
1273
|
+
assert.strictEqual((failure.value as Plugin.LazyPluginError).context.reason, 'load-failed');
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}),
|
|
1277
|
+
);
|
|
1278
|
+
|
|
1279
|
+
it.effect('publishes a lazy:<id> error message when resolution fails', () =>
|
|
1280
|
+
Effect.gen(function* () {
|
|
1281
|
+
const LazyTest = Plugin.lazy(lazyMeta, () =>
|
|
1282
|
+
Promise.reject<{ default: Plugin.PluginFactory }>(new Error('boom')),
|
|
1283
|
+
);
|
|
1284
|
+
const lazyStub = LazyTest();
|
|
1285
|
+
plugins = [lazyStub];
|
|
1286
|
+
|
|
1287
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1288
|
+
// Subscribe first so we don't miss the activating/error pair.
|
|
1289
|
+
const queue = yield* PubSub.subscribe(manager.activation);
|
|
1290
|
+
yield* manager.add(lazyMeta.id);
|
|
1291
|
+
yield* Effect.exit(manager.enable(lazyMeta.id));
|
|
1292
|
+
const messages = yield* Queue.takeAll(queue);
|
|
1293
|
+
|
|
1294
|
+
const errorMessage = [...messages].find((m) => m.module === `lazy:${lazyMeta.id}` && m.state === 'error');
|
|
1295
|
+
assert.isDefined(errorMessage);
|
|
1296
|
+
assert.isDefined(errorMessage!.error);
|
|
1297
|
+
}).pipe(Effect.scoped),
|
|
1298
|
+
);
|
|
1299
|
+
|
|
1300
|
+
it.effect('coalesces concurrent lazy resolutions of the same plugin id', () =>
|
|
1301
|
+
Effect.gen(function* () {
|
|
1302
|
+
let factoryCalls = 0;
|
|
1303
|
+
const Real = (() => {
|
|
1304
|
+
const inner = Plugin.make(
|
|
1305
|
+
Plugin.define<void>(lazyMeta).pipe(
|
|
1306
|
+
Plugin.addModule({
|
|
1307
|
+
id: 'Hello',
|
|
1308
|
+
activatesOn: ActivationEvents.Startup,
|
|
1309
|
+
activate: () => Effect.succeed(Capability.contributes(String, { string: 'hello' })),
|
|
1310
|
+
}),
|
|
1311
|
+
),
|
|
1312
|
+
);
|
|
1313
|
+
const factory = (() => {
|
|
1314
|
+
factoryCalls++;
|
|
1315
|
+
return inner();
|
|
1316
|
+
}) as Plugin.PluginFactory;
|
|
1317
|
+
return Object.assign(factory, { meta: lazyMeta });
|
|
1318
|
+
})();
|
|
1319
|
+
const LazyTest = Plugin.lazy(lazyMeta, () => Promise.resolve({ default: Real }));
|
|
1320
|
+
const lazyStub = LazyTest();
|
|
1321
|
+
// `manager.enable(id)` is implicitly called twice — once from the
|
|
1322
|
+
// constructor's core/enabled chain, once from our explicit call. With
|
|
1323
|
+
// coalescing, the underlying factory should still run exactly once.
|
|
1324
|
+
plugins = [lazyStub];
|
|
1325
|
+
const manager = PluginManager.make({ pluginLoader, plugins, core: [lazyMeta.id] });
|
|
1326
|
+
yield* manager.enable(lazyMeta.id);
|
|
1327
|
+
assert.strictEqual(factoryCalls, 1);
|
|
1328
|
+
}),
|
|
1329
|
+
);
|
|
1330
|
+
|
|
1331
|
+
it.effect('fails with a tagged error when the factory output is not a Plugin', () =>
|
|
1332
|
+
Effect.gen(function* () {
|
|
1333
|
+
const BadFactory = Object.assign(() => ({ not: 'a plugin' }) as any, { meta: lazyMeta });
|
|
1334
|
+
const LazyTest = Plugin.lazy(lazyMeta, () => Promise.resolve({ default: BadFactory }));
|
|
1335
|
+
const lazyStub = LazyTest();
|
|
1336
|
+
plugins = [lazyStub];
|
|
1337
|
+
|
|
1338
|
+
const manager = PluginManager.make({ pluginLoader });
|
|
1339
|
+
yield* manager.add(lazyMeta.id);
|
|
1340
|
+
|
|
1341
|
+
const exit = yield* Effect.exit(manager.enable(lazyMeta.id));
|
|
1342
|
+
assert.isTrue(Exit.isFailure(exit));
|
|
1343
|
+
if (Exit.isFailure(exit)) {
|
|
1344
|
+
const failure = Cause.failureOption(exit.cause);
|
|
1345
|
+
assert.isTrue(failure._tag === 'Some');
|
|
1346
|
+
if (failure._tag === 'Some') {
|
|
1347
|
+
assert.isTrue(Plugin.LazyPluginError.is(failure.value));
|
|
1348
|
+
assert.strictEqual((failure.value as Plugin.LazyPluginError).context.reason, 'invalid-plugin');
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}),
|
|
1352
|
+
);
|
|
1353
|
+
});
|
|
1354
|
+
});
|