repluggable-core 0.0.0-pr280.413 → 0.0.0-pr282.418
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/__tests__/spec-setup.js +3 -0
- package/dist/es/{API.d.ts → src/API.d.ts} +31 -10
- package/dist/es/src/API.d.ts.map +1 -0
- package/dist/es/src/API.js +2 -0
- package/dist/es/src/API.js.map +1 -0
- package/dist/es/src/IterableWeakMap.d.ts +20 -0
- package/dist/es/src/IterableWeakMap.d.ts.map +1 -0
- package/dist/es/src/IterableWeakMap.js +92 -0
- package/dist/es/src/IterableWeakMap.js.map +1 -0
- package/dist/es/src/appHost.d.ts +7 -0
- package/dist/es/src/appHost.d.ts.map +1 -0
- package/dist/es/src/appHost.js +848 -0
- package/dist/es/src/appHost.js.map +1 -0
- package/dist/es/src/appHostServices.d.ts +12 -0
- package/dist/es/src/appHostServices.d.ts.map +1 -0
- package/dist/es/src/appHostServices.js +25 -0
- package/dist/es/src/appHostServices.js.map +1 -0
- package/dist/es/src/appHostUtils.d.ts +4 -0
- package/dist/es/src/appHostUtils.d.ts.map +1 -0
- package/dist/es/src/appHostUtils.js +8 -0
- package/dist/es/src/appHostUtils.js.map +1 -0
- package/dist/es/src/extensionSlot.d.ts +8 -0
- package/dist/es/src/extensionSlot.d.ts.map +1 -0
- package/dist/es/src/extensionSlot.js +59 -0
- package/dist/es/src/extensionSlot.js.map +1 -0
- package/dist/es/src/hot.d.ts +14 -0
- package/dist/es/src/hot.d.ts.map +1 -0
- package/dist/es/src/hot.js +52 -0
- package/dist/es/src/hot.js.map +1 -0
- package/dist/es/src/index.d.ts +11 -0
- package/dist/es/src/index.d.ts.map +1 -0
- package/dist/es/src/index.js +10 -0
- package/dist/es/src/index.js.map +1 -0
- package/dist/es/src/installedShellsState.d.ts +19 -0
- package/dist/es/src/installedShellsState.d.ts.map +1 -0
- package/dist/es/src/installedShellsState.js +30 -0
- package/dist/es/src/installedShellsState.js.map +1 -0
- package/dist/es/src/interceptAnyObject.d.ts +7 -0
- package/dist/es/src/interceptAnyObject.d.ts.map +1 -0
- package/dist/es/src/interceptAnyObject.js +21 -0
- package/dist/es/src/interceptAnyObject.js.map +1 -0
- package/dist/es/src/interceptEntryPoints.d.ts +6 -0
- package/dist/es/src/interceptEntryPoints.d.ts.map +1 -0
- package/dist/es/src/interceptEntryPoints.js +22 -0
- package/dist/es/src/interceptEntryPoints.js.map +1 -0
- package/dist/es/src/invokeSlotCallbacks.d.ts +3 -0
- package/dist/es/src/invokeSlotCallbacks.d.ts.map +1 -0
- package/dist/es/src/invokeSlotCallbacks.js +20 -0
- package/dist/es/src/invokeSlotCallbacks.js.map +1 -0
- package/dist/es/src/loggers.d.ts +4 -0
- package/dist/es/src/loggers.d.ts.map +1 -0
- package/dist/es/src/loggers.js +100 -0
- package/dist/es/src/loggers.js.map +1 -0
- package/dist/es/src/monitorAPI.d.ts +3 -0
- package/dist/es/src/monitorAPI.d.ts.map +1 -0
- package/dist/es/src/monitorAPI.js +53 -0
- package/dist/es/src/monitorAPI.js.map +1 -0
- package/dist/es/src/repluggableAppDebug/index.d.ts +2 -0
- package/dist/es/src/repluggableAppDebug/index.d.ts.map +1 -0
- package/dist/es/src/repluggableAppDebug/index.js +2 -0
- package/dist/es/src/repluggableAppDebug/index.js.map +1 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.d.ts +15 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.d.ts.map +1 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.js +94 -0
- package/dist/es/src/repluggableAppDebug/performanceDebugInfo.js.map +1 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts +24 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js +132 -0
- package/dist/es/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -0
- package/dist/es/src/tarjanGraph.d.ts +27 -0
- package/dist/es/src/tarjanGraph.d.ts.map +1 -0
- package/dist/es/src/tarjanGraph.js +94 -0
- package/dist/es/src/tarjanGraph.js.map +1 -0
- package/dist/es/src/throttledStore.d.ts +32 -0
- package/dist/es/src/throttledStore.d.ts.map +1 -0
- package/dist/es/src/throttledStore.js +240 -0
- package/dist/es/src/throttledStore.js.map +1 -0
- package/dist/es/test/IterableWeakMap.spec.d.ts +2 -0
- package/dist/es/test/IterableWeakMap.spec.d.ts.map +1 -0
- package/dist/es/test/IterableWeakMap.spec.js +218 -0
- package/dist/es/test/IterableWeakMap.spec.js.map +1 -0
- package/dist/es/test/appHost.mock.d.ts +4 -0
- package/dist/es/test/appHost.mock.d.ts.map +1 -0
- package/dist/es/test/appHost.mock.js +54 -0
- package/dist/es/test/appHost.mock.js.map +1 -0
- package/dist/es/test/appHost.spec.d.ts +2 -0
- package/dist/es/test/appHost.spec.d.ts.map +1 -0
- package/dist/es/test/appHost.spec.js +1323 -0
- package/dist/es/test/appHost.spec.js.map +1 -0
- package/dist/es/test/customExtensionSlot.spec.d.ts +2 -0
- package/dist/es/test/customExtensionSlot.spec.d.ts.map +1 -0
- package/dist/es/test/customExtensionSlot.spec.js +112 -0
- package/dist/es/test/customExtensionSlot.spec.js.map +1 -0
- package/dist/es/test/extensionSlot.spec.d.ts +2 -0
- package/dist/es/test/extensionSlot.spec.d.ts.map +1 -0
- package/dist/es/test/extensionSlot.spec.js +73 -0
- package/dist/es/test/extensionSlot.spec.js.map +1 -0
- package/dist/es/test/installedShellsState.spec.d.ts +2 -0
- package/dist/es/test/installedShellsState.spec.d.ts.map +1 -0
- package/dist/es/test/installedShellsState.spec.js +28 -0
- package/dist/es/test/installedShellsState.spec.js.map +1 -0
- package/dist/es/test/interceptAnyObject.spec.d.ts +2 -0
- package/dist/es/test/interceptAnyObject.spec.d.ts.map +1 -0
- package/dist/es/test/interceptAnyObject.spec.js +166 -0
- package/dist/es/test/interceptAnyObject.spec.js.map +1 -0
- package/dist/es/test/interceptEntryPoints.spec.d.ts +2 -0
- package/dist/es/test/interceptEntryPoints.spec.d.ts.map +1 -0
- package/dist/es/test/interceptEntryPoints.spec.js +244 -0
- package/dist/es/test/interceptEntryPoints.spec.js.map +1 -0
- package/dist/es/test/loggers.spec.d.ts +2 -0
- package/dist/es/test/loggers.spec.d.ts.map +1 -0
- package/dist/es/test/loggers.spec.js +218 -0
- package/dist/es/test/loggers.spec.js.map +1 -0
- package/dist/es/test/repluggableAppDebug.spec.d.ts +2 -0
- package/dist/es/test/repluggableAppDebug.spec.d.ts.map +1 -0
- package/dist/es/test/repluggableAppDebug.spec.js +107 -0
- package/dist/es/test/repluggableAppDebug.spec.js.map +1 -0
- package/dist/es/test/testKit.spec.d.ts +2 -0
- package/dist/es/test/testKit.spec.d.ts.map +1 -0
- package/dist/es/test/testKit.spec.js +129 -0
- package/dist/es/test/testKit.spec.js.map +1 -0
- package/dist/es/testKit/emptyLoggerOptions.d.ts +3 -0
- package/dist/es/testKit/emptyLoggerOptions.d.ts.map +1 -0
- package/dist/es/testKit/emptyLoggerOptions.js +15 -0
- package/dist/es/testKit/emptyLoggerOptions.js.map +1 -0
- package/dist/es/testKit/index.d.ts +25 -0
- package/dist/es/testKit/index.d.ts.map +1 -0
- package/dist/es/testKit/index.js +130 -0
- package/dist/es/testKit/index.js.map +1 -0
- package/dist/es/testKit/mockPackage.d.ts +21 -0
- package/dist/es/testKit/mockPackage.d.ts.map +1 -0
- package/dist/es/testKit/mockPackage.js +85 -0
- package/dist/es/testKit/mockPackage.js.map +1 -0
- package/dist/es/testKit/withConsoleErrors.d.ts +2 -0
- package/dist/es/testKit/withConsoleErrors.d.ts.map +1 -0
- package/dist/es/testKit/withConsoleErrors.js +12 -0
- package/dist/es/testKit/withConsoleErrors.js.map +1 -0
- package/dist/es/testKit/withThrowOnError.d.ts +3 -0
- package/dist/es/testKit/withThrowOnError.d.ts.map +1 -0
- package/dist/es/testKit/withThrowOnError.js +27 -0
- package/dist/es/testKit/withThrowOnError.js.map +1 -0
- package/dist/src/API.d.ts +31 -10
- package/dist/src/API.d.ts.map +1 -1
- package/dist/src/API.js +3 -0
- package/dist/src/API.js.map +1 -1
- package/dist/src/IterableWeakMap.d.ts +20 -0
- package/dist/src/IterableWeakMap.d.ts.map +1 -0
- package/dist/src/IterableWeakMap.js +96 -0
- package/dist/src/IterableWeakMap.js.map +1 -0
- package/dist/src/appHost.d.ts +7 -0
- package/dist/src/appHost.d.ts.map +1 -0
- package/dist/src/appHost.js +856 -0
- package/dist/src/appHost.js.map +1 -0
- package/dist/src/appHostServices.d.ts +12 -0
- package/dist/src/appHostServices.d.ts.map +1 -0
- package/dist/src/appHostServices.js +29 -0
- package/dist/src/appHostServices.js.map +1 -0
- package/dist/src/appHostUtils.d.ts +4 -0
- package/dist/src/appHostUtils.d.ts.map +1 -0
- package/dist/src/appHostUtils.js +16 -0
- package/dist/src/appHostUtils.js.map +1 -0
- package/dist/src/extensionSlot.d.ts +8 -0
- package/dist/src/extensionSlot.d.ts.map +1 -0
- package/dist/src/extensionSlot.js +67 -0
- package/dist/src/extensionSlot.js.map +1 -0
- package/dist/src/hot.d.ts +14 -0
- package/dist/src/hot.d.ts.map +1 -0
- package/dist/src/hot.js +56 -0
- package/dist/src/hot.js.map +1 -0
- package/dist/src/index.d.ts +10 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/installedShellsState.d.ts +19 -0
- package/dist/src/installedShellsState.d.ts.map +1 -0
- package/dist/src/installedShellsState.js +38 -0
- package/dist/src/installedShellsState.js.map +1 -0
- package/dist/src/interceptAnyObject.d.ts +7 -0
- package/dist/src/interceptAnyObject.d.ts.map +1 -0
- package/dist/src/interceptAnyObject.js +28 -0
- package/dist/src/interceptAnyObject.js.map +1 -0
- package/dist/src/interceptEntryPoints.d.ts +6 -0
- package/dist/src/interceptEntryPoints.d.ts.map +1 -0
- package/dist/src/interceptEntryPoints.js +30 -0
- package/dist/src/interceptEntryPoints.js.map +1 -0
- package/dist/src/invokeSlotCallbacks.d.ts +3 -0
- package/dist/src/invokeSlotCallbacks.d.ts.map +1 -0
- package/dist/src/invokeSlotCallbacks.js +24 -0
- package/dist/src/invokeSlotCallbacks.js.map +1 -0
- package/dist/src/loggers.d.ts +4 -0
- package/dist/src/loggers.d.ts.map +1 -0
- package/dist/src/loggers.js +104 -0
- package/dist/src/loggers.js.map +1 -0
- package/dist/src/monitorAPI.d.ts +3 -0
- package/dist/src/monitorAPI.d.ts.map +1 -0
- package/dist/src/monitorAPI.js +57 -0
- package/dist/src/monitorAPI.js.map +1 -0
- package/dist/src/repluggableAppDebug/index.d.ts +2 -0
- package/dist/src/repluggableAppDebug/index.d.ts.map +1 -0
- package/dist/src/repluggableAppDebug/index.js +6 -0
- package/dist/src/repluggableAppDebug/index.js.map +1 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.d.ts +15 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.d.ts.map +1 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.js +101 -0
- package/dist/src/repluggableAppDebug/performanceDebugInfo.js.map +1 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts +24 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.d.ts.map +1 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js +139 -0
- package/dist/src/repluggableAppDebug/repluggableAppDebug.js.map +1 -0
- package/dist/src/tarjanGraph.d.ts +27 -0
- package/dist/src/tarjanGraph.d.ts.map +1 -0
- package/dist/src/tarjanGraph.js +100 -0
- package/dist/src/tarjanGraph.js.map +1 -0
- package/dist/src/throttledStore.d.ts +32 -0
- package/dist/src/throttledStore.d.ts.map +1 -0
- package/dist/src/throttledStore.js +249 -0
- package/dist/src/throttledStore.js.map +1 -0
- package/dist/test/IterableWeakMap.spec.d.ts +2 -0
- package/dist/test/IterableWeakMap.spec.d.ts.map +1 -0
- package/dist/test/IterableWeakMap.spec.js +220 -0
- package/dist/test/IterableWeakMap.spec.js.map +1 -0
- package/dist/test/appHost.mock.d.ts +4 -0
- package/dist/test/appHost.mock.d.ts.map +1 -0
- package/dist/test/appHost.mock.js +59 -0
- package/dist/test/appHost.mock.js.map +1 -0
- package/dist/test/appHost.spec.d.ts +2 -0
- package/dist/test/appHost.spec.d.ts.map +1 -0
- package/dist/test/appHost.spec.js +1328 -0
- package/dist/test/appHost.spec.js.map +1 -0
- package/dist/test/customExtensionSlot.spec.d.ts +2 -0
- package/dist/test/customExtensionSlot.spec.d.ts.map +1 -0
- package/dist/test/customExtensionSlot.spec.js +117 -0
- package/dist/test/customExtensionSlot.spec.js.map +1 -0
- package/dist/test/extensionSlot.spec.d.ts +2 -0
- package/dist/test/extensionSlot.spec.d.ts.map +1 -0
- package/dist/test/extensionSlot.spec.js +75 -0
- package/dist/test/extensionSlot.spec.js.map +1 -0
- package/dist/test/installedShellsState.spec.d.ts +2 -0
- package/dist/test/installedShellsState.spec.d.ts.map +1 -0
- package/dist/test/installedShellsState.spec.js +30 -0
- package/dist/test/installedShellsState.spec.js.map +1 -0
- package/dist/test/interceptAnyObject.spec.d.ts +2 -0
- package/dist/test/interceptAnyObject.spec.d.ts.map +1 -0
- package/dist/test/interceptAnyObject.spec.js +171 -0
- package/dist/test/interceptAnyObject.spec.js.map +1 -0
- package/dist/test/interceptEntryPoints.spec.d.ts +2 -0
- package/dist/test/interceptEntryPoints.spec.d.ts.map +1 -0
- package/dist/test/interceptEntryPoints.spec.js +249 -0
- package/dist/test/interceptEntryPoints.spec.js.map +1 -0
- package/dist/test/loggers.spec.d.ts +2 -0
- package/dist/test/loggers.spec.d.ts.map +1 -0
- package/dist/test/loggers.spec.js +220 -0
- package/dist/test/loggers.spec.js.map +1 -0
- package/dist/test/repluggableAppDebug.spec.d.ts +2 -0
- package/dist/test/repluggableAppDebug.spec.d.ts.map +1 -0
- package/dist/test/repluggableAppDebug.spec.js +109 -0
- package/dist/test/repluggableAppDebug.spec.js.map +1 -0
- package/dist/test/testKit.spec.d.ts +2 -0
- package/dist/test/testKit.spec.d.ts.map +1 -0
- package/dist/test/testKit.spec.js +134 -0
- package/dist/test/testKit.spec.js.map +1 -0
- package/dist/testKit/emptyLoggerOptions.d.ts +3 -0
- package/dist/testKit/emptyLoggerOptions.d.ts.map +1 -0
- package/dist/testKit/emptyLoggerOptions.js +18 -0
- package/dist/testKit/emptyLoggerOptions.js.map +1 -0
- package/dist/testKit/index.d.ts +25 -0
- package/dist/testKit/index.d.ts.map +1 -0
- package/dist/testKit/index.js +158 -0
- package/dist/testKit/index.js.map +1 -0
- package/dist/testKit/mockPackage.d.ts +21 -0
- package/dist/testKit/mockPackage.d.ts.map +1 -0
- package/dist/testKit/mockPackage.js +91 -0
- package/dist/testKit/mockPackage.js.map +1 -0
- package/dist/testKit/withConsoleErrors.d.ts +2 -0
- package/dist/testKit/withConsoleErrors.d.ts.map +1 -0
- package/dist/testKit/withConsoleErrors.js +16 -0
- package/dist/testKit/withConsoleErrors.js.map +1 -0
- package/dist/testKit/withThrowOnError.d.ts +3 -0
- package/dist/testKit/withThrowOnError.d.ts.map +1 -0
- package/dist/testKit/withThrowOnError.js +31 -0
- package/dist/testKit/withThrowOnError.js.map +1 -0
- package/jest.config.js +16 -0
- package/package.json +5 -3
- package/src/API.ts +474 -378
- package/src/IterableWeakMap.ts +121 -0
- package/src/appHost.ts +1383 -0
- package/src/appHostServices.ts +42 -0
- package/src/appHostUtils.ts +11 -0
- package/src/extensionSlot.ts +96 -0
- package/src/hot.ts +53 -0
- package/src/index.ts +55 -3
- package/src/installedShellsState.ts +54 -0
- package/src/interceptAnyObject.ts +39 -0
- package/src/interceptEntryPoints.ts +25 -0
- package/src/invokeSlotCallbacks.ts +20 -0
- package/src/loggers.ts +112 -0
- package/src/monitorAPI.ts +71 -0
- package/src/repluggableAppDebug/debug.d.ts +37 -0
- package/src/repluggableAppDebug/index.ts +1 -0
- package/src/repluggableAppDebug/performanceDebugInfo.ts +96 -0
- package/src/repluggableAppDebug/repluggableAppDebug.ts +192 -0
- package/src/tarjanGraph.ts +96 -0
- package/src/throttledStore.ts +355 -0
- package/test/IterableWeakMap.spec.ts +284 -0
- package/test/appHost.mock.ts +58 -0
- package/test/appHost.spec.ts +1629 -0
- package/test/customExtensionSlot.spec.ts +153 -0
- package/test/extensionSlot.spec.ts +94 -0
- package/test/installedShellsState.spec.ts +39 -0
- package/test/interceptAnyObject.spec.ts +217 -0
- package/test/interceptEntryPoints.spec.ts +291 -0
- package/test/loggers.spec.ts +288 -0
- package/test/repluggableAppDebug.spec.ts +118 -0
- package/test/testKit.spec.tsx +153 -0
- package/testKit/emptyLoggerOptions.ts +16 -0
- package/testKit/index.ts +172 -0
- package/testKit/mockPackage.ts +99 -0
- package/testKit/package.json +3 -0
- package/testKit/withConsoleErrors.ts +12 -0
- package/testKit/withThrowOnError.ts +34 -0
- package/tsconfig.json +11 -1
- package/dist/es/API.d.ts.map +0 -1
- package/dist/es/API.js +0 -2
- package/dist/es/API.js.map +0 -1
- package/dist/es/index.d.ts +0 -2
- package/dist/es/index.d.ts.map +0 -1
- package/dist/es/index.js +0 -2
- package/dist/es/index.js.map +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AppHostOptions, EntryPoint, Shell, SlotKey } from './API'
|
|
2
|
+
|
|
3
|
+
export interface AppHostAPI {
|
|
4
|
+
getAllEntryPoints(): EntryPoint[]
|
|
5
|
+
getAppHostOptions(): AppHostOptions
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const AppHostServicesEntryPointName = 'APP-HOST-SERVICES'
|
|
9
|
+
|
|
10
|
+
export const AppHostAPI: SlotKey<AppHostAPI> = {
|
|
11
|
+
name: 'AppHost API',
|
|
12
|
+
public: true
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AppHostServicesProvider {
|
|
16
|
+
getAppHostServicesShell(): Shell
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createAppHostServicesEntryPoint(apiFactory: () => AppHostAPI): EntryPoint & AppHostServicesProvider {
|
|
20
|
+
let cachedShell: Shell | null = null
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
name: AppHostServicesEntryPointName,
|
|
24
|
+
|
|
25
|
+
declareAPIs() {
|
|
26
|
+
return [AppHostAPI]
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
attach(shell: Shell) {
|
|
30
|
+
cachedShell = shell
|
|
31
|
+
shell.contributeAPI(AppHostAPI, apiFactory)
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
getAppHostServicesShell() {
|
|
35
|
+
if (cachedShell) {
|
|
36
|
+
return cachedShell
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw new Error('Shell for AppHostServices entry point was not yet created')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AnyEntryPoint, AnySlotKey } from './API'
|
|
2
|
+
|
|
3
|
+
import _ from 'lodash'
|
|
4
|
+
|
|
5
|
+
export const dependentAPIs = (entryPoint: AnyEntryPoint): AnySlotKey[] => {
|
|
6
|
+
return _.chain(entryPoint).invoke('getDependencyAPIs').defaultTo([]).value()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const declaredAPIs = (entryPoint: AnyEntryPoint): AnySlotKey[] => {
|
|
10
|
+
return _.chain(entryPoint).invoke('declareAPIs').defaultTo([]).value()
|
|
11
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppHost,
|
|
3
|
+
ContributionPredicate,
|
|
4
|
+
ExtensionItem,
|
|
5
|
+
ExtensionItemFilter,
|
|
6
|
+
PrivateExtensionSlot,
|
|
7
|
+
Shell,
|
|
8
|
+
SlotKey,
|
|
9
|
+
CustomExtensionSlot,
|
|
10
|
+
CustomExtensionSlotHandler,
|
|
11
|
+
PrivateAppHost
|
|
12
|
+
} from './API'
|
|
13
|
+
import _ from 'lodash'
|
|
14
|
+
|
|
15
|
+
export interface AnyExtensionSlot {
|
|
16
|
+
readonly name: string
|
|
17
|
+
readonly declaringShell?: Shell
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const alwaysTrue = () => true
|
|
21
|
+
|
|
22
|
+
type Unsubscribe = () => void
|
|
23
|
+
|
|
24
|
+
export function createExtensionSlot<T>(
|
|
25
|
+
key: SlotKey<T>,
|
|
26
|
+
host: PrivateAppHost,
|
|
27
|
+
declaringShell?: Shell
|
|
28
|
+
): PrivateExtensionSlot<T> & AnyExtensionSlot {
|
|
29
|
+
let items: ExtensionItem<T>[] = []
|
|
30
|
+
let subscribers: (() => void)[] = []
|
|
31
|
+
const slotUniqueId = _.uniqueId()
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
host,
|
|
35
|
+
declaringShell,
|
|
36
|
+
name: key.name,
|
|
37
|
+
contribute,
|
|
38
|
+
getItems,
|
|
39
|
+
getSingleItem,
|
|
40
|
+
getItemByName,
|
|
41
|
+
discardBy,
|
|
42
|
+
subscribe
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function contribute(fromShell: Shell, item: T, condition?: ContributionPredicate): void {
|
|
46
|
+
items.push({
|
|
47
|
+
shell: fromShell,
|
|
48
|
+
contribution: item,
|
|
49
|
+
condition: condition || alwaysTrue,
|
|
50
|
+
uniqueId: _.uniqueId(`${fromShell.name}_extItem_`)
|
|
51
|
+
})
|
|
52
|
+
host.executeWhenFree(slotUniqueId, () => subscribers.forEach(func => func()))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getItems(forceAll: boolean = false): ExtensionItem<T>[] {
|
|
56
|
+
return forceAll ? items : items.filter(item => item.condition())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getSingleItem(): ExtensionItem<T> | undefined {
|
|
60
|
+
return items.find(item => item.condition())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getItemByName(name: string): ExtensionItem<T> | undefined {
|
|
64
|
+
return items.find(item => item.name === name && item.condition())
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function discardBy(predicate: ExtensionItemFilter<T>) {
|
|
68
|
+
const originalContributionCount = items.length
|
|
69
|
+
items = items.filter(v => !predicate(v))
|
|
70
|
+
if (items.length !== originalContributionCount) {
|
|
71
|
+
subscribers.forEach(func => func())
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function subscribe(callback: () => void): Unsubscribe {
|
|
76
|
+
subscribers.push(callback)
|
|
77
|
+
return () => {
|
|
78
|
+
subscribers = subscribers.filter(func => func !== callback)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function createCustomExtensionSlot<T>(
|
|
84
|
+
key: SlotKey<T>,
|
|
85
|
+
handler: CustomExtensionSlotHandler<T>,
|
|
86
|
+
host: AppHost,
|
|
87
|
+
declaringShell?: Shell
|
|
88
|
+
): CustomExtensionSlot<T> & AnyExtensionSlot {
|
|
89
|
+
return {
|
|
90
|
+
name: key.name,
|
|
91
|
+
host,
|
|
92
|
+
declaringShell,
|
|
93
|
+
contribute: (...args) => handler.contribute(...args),
|
|
94
|
+
discardBy: (...args) => handler.discardBy(...args)
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/hot.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AppHost, EntryPoint } from './API'
|
|
2
|
+
|
|
3
|
+
export type Hot = typeof hot
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* To enable HMR, use the `hot` util to wrap the export of your repluggable package
|
|
7
|
+
*
|
|
8
|
+
* @param {NodeModule} sourceModule
|
|
9
|
+
* @param {EntryPoint[]} entryPoints
|
|
10
|
+
* @param {AppHost} [host] Optional. The AppHost to be used for removing / adding entrypoints. If not provided, `window.repluggableAppDebug.host` will be used,
|
|
11
|
+
* @example ```ts
|
|
12
|
+
* export default hot(module, [FooEntryPoint, BarEntryPoint])
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function hot(sourceModule: any, entryPoints: EntryPoint[], host?: AppHost) {
|
|
16
|
+
if (!sourceModule.hot) {
|
|
17
|
+
return entryPoints
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getHostInstance = () => {
|
|
21
|
+
const hostInstance = host ?? globalThis.repluggableAppDebug?.host
|
|
22
|
+
if (!hostInstance) {
|
|
23
|
+
console.error(
|
|
24
|
+
`HMR error: cannot find host object.\n` +
|
|
25
|
+
`hot(...) was called without the optional host parameter, and the fallback globalThis.repluggableAppDebug.host doesn't exist`
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return hostInstance
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const shellNames = entryPoints.map(x => x.name)
|
|
33
|
+
const shortModuleId = sourceModule.id.split('/').pop()
|
|
34
|
+
|
|
35
|
+
sourceModule.hot.accept()
|
|
36
|
+
sourceModule.hot.dispose(async () => {
|
|
37
|
+
const hostInstance = getHostInstance()
|
|
38
|
+
if (hostInstance) {
|
|
39
|
+
console.debug(`----- HMR[${shortModuleId}] > REMOVING SHELLS >`, shellNames)
|
|
40
|
+
await hostInstance.removeShells(shellNames)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (sourceModule.hot.status() === 'apply') {
|
|
45
|
+
const hostInstance = getHostInstance()
|
|
46
|
+
if (hostInstance) {
|
|
47
|
+
console.debug(`----- HMR[${shortModuleId}] > ADDING SHELLS >`, shellNames)
|
|
48
|
+
hostInstance.addShells(entryPoints)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return entryPoints
|
|
53
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,56 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
EntryPointOrPackage,
|
|
3
|
+
EntryPointOrPackagesMap,
|
|
4
|
+
EntryPoint,
|
|
5
|
+
AppHost,
|
|
6
|
+
AppHostAPI,
|
|
7
|
+
AppHostOptions,
|
|
8
|
+
Shell,
|
|
9
|
+
ExtensionSlot,
|
|
10
|
+
ExtensionItem,
|
|
11
|
+
CustomExtensionSlot,
|
|
12
|
+
CustomExtensionSlotHandler,
|
|
13
|
+
AnySlotKey,
|
|
14
|
+
SlotKey,
|
|
15
|
+
ReactComponentContributor,
|
|
16
|
+
ReducersMapObjectContributor,
|
|
17
|
+
EntryPointInterceptor,
|
|
18
|
+
ShellLogger,
|
|
19
|
+
ShellLoggerSpan,
|
|
20
|
+
HostLogger,
|
|
21
|
+
LogSeverity,
|
|
22
|
+
APILayer,
|
|
23
|
+
StateObserverUnsubscribe,
|
|
24
|
+
StateObserver,
|
|
25
|
+
ObservableState,
|
|
26
|
+
ScopedStore,
|
|
27
|
+
} from "./API";
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
createAppHost,
|
|
31
|
+
makeLazyEntryPoint,
|
|
32
|
+
mainViewSlotKey,
|
|
33
|
+
stateSlotKey,
|
|
34
|
+
} from "./appHost";
|
|
35
|
+
|
|
36
|
+
export { AppHostServicesProvider } from "./appHostServices";
|
|
37
|
+
|
|
38
|
+
export { createShellLogger } from "./loggers";
|
|
39
|
+
|
|
40
|
+
export { invokeSlotCallbacks } from "./invokeSlotCallbacks";
|
|
41
|
+
|
|
42
|
+
export { interceptAnyObject } from "./interceptAnyObject";
|
|
43
|
+
|
|
44
|
+
export { monitorAPI } from "./monitorAPI";
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
InstalledShellsSelectors,
|
|
48
|
+
ShellToggleSet,
|
|
49
|
+
} from "./installedShellsState";
|
|
50
|
+
|
|
51
|
+
export { hot } from "./hot";
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
interceptEntryPoints,
|
|
55
|
+
interceptEntryPointsMap,
|
|
56
|
+
} from "./interceptEntryPoints";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import { Action, AnyAction, ReducersMapObject } from 'redux'
|
|
3
|
+
|
|
4
|
+
export interface ShellToggleSet {
|
|
5
|
+
[name: string]: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface InstalledShellsState {
|
|
9
|
+
readonly installedShells: ShellToggleSet
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface UpdateInstalledShellsAction extends Action {
|
|
13
|
+
readonly updates: ShellToggleSet
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const UPDATE_INSTALLED_SHELLS_ACTION = '$installedShells/update'
|
|
17
|
+
|
|
18
|
+
export const contributeInstalledShellsState = (): ReducersMapObject => {
|
|
19
|
+
return {
|
|
20
|
+
$installedShells: installedShellsReducer
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const selectRootState = (state: any): InstalledShellsState => state.$installedShells
|
|
25
|
+
|
|
26
|
+
export const InstalledShellsSelectors = {
|
|
27
|
+
getInstalledShellsSet(state: any): ShellToggleSet {
|
|
28
|
+
return selectRootState(state).installedShells
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const InstalledShellsActions = {
|
|
33
|
+
updateInstalledShells: (updates: ShellToggleSet): UpdateInstalledShellsAction => {
|
|
34
|
+
return {
|
|
35
|
+
type: UPDATE_INSTALLED_SHELLS_ACTION,
|
|
36
|
+
updates
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const toggleInstalledShells = (currentlyInstalled: ShellToggleSet, updates: ShellToggleSet): ShellToggleSet =>
|
|
42
|
+
_.pickBy(_.assign({}, currentlyInstalled, updates), _.identity)
|
|
43
|
+
|
|
44
|
+
export const installedShellsReducer = (state: InstalledShellsState = { installedShells: {} }, action: AnyAction): InstalledShellsState => {
|
|
45
|
+
switch (action.type) {
|
|
46
|
+
case UPDATE_INSTALLED_SHELLS_ACTION:
|
|
47
|
+
return {
|
|
48
|
+
...state,
|
|
49
|
+
installedShells: toggleInstalledShells(state.installedShells, action.updates)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return state
|
|
54
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
|
|
3
|
+
export type FunctionInterceptor = (name: string, original: Function) => Function
|
|
4
|
+
export type PropertyInterceptor = (name: string, original: any) => any
|
|
5
|
+
|
|
6
|
+
export interface AnyObject {
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
const isPlainObject = (value: any): value is AnyObject => _.isPlainObject(value)
|
|
10
|
+
|
|
11
|
+
export function interceptAnyObject<T>(
|
|
12
|
+
inner: T,
|
|
13
|
+
onFunction?: FunctionInterceptor,
|
|
14
|
+
onProperty?: PropertyInterceptor,
|
|
15
|
+
includeNestedLevels?: number
|
|
16
|
+
): T {
|
|
17
|
+
if (isPlainObject(inner)) {
|
|
18
|
+
const result = _.mapValues(inner, (original, key) => {
|
|
19
|
+
if (typeof original === 'function' && typeof onFunction === 'function') {
|
|
20
|
+
return onFunction(key, original)
|
|
21
|
+
}
|
|
22
|
+
if (includeNestedLevels && _.isPlainObject(original)) {
|
|
23
|
+
return interceptAnyObject(
|
|
24
|
+
original,
|
|
25
|
+
onFunction ? (name, func) => onFunction(`${key}.${name}`, func) : undefined,
|
|
26
|
+
onProperty ? (name, value) => onProperty(`${key}.${name}`, value) : undefined,
|
|
27
|
+
includeNestedLevels - 1
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
if (typeof onProperty === 'function') {
|
|
31
|
+
return onProperty(key, original)
|
|
32
|
+
}
|
|
33
|
+
return original
|
|
34
|
+
}) as T
|
|
35
|
+
|
|
36
|
+
return result
|
|
37
|
+
}
|
|
38
|
+
return inner
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import { EntryPoint, EntryPointOrPackage, EntryPointInterceptor, EntryPointOrPackagesMap } from './API'
|
|
3
|
+
|
|
4
|
+
export function interceptEntryPoints(entryPoints: EntryPointOrPackage, interceptor: EntryPointInterceptor): EntryPoint[] {
|
|
5
|
+
return (_.flatten([entryPoints]) as EntryPoint[]).map(ep => applyInterceptor(ep, interceptor))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function interceptEntryPointsMap(entryPointsMap: EntryPointOrPackagesMap, interceptor: EntryPointInterceptor) {
|
|
9
|
+
return _.mapValues(entryPointsMap, ep => interceptEntryPoints(ep, interceptor))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function applyInterceptor(inner: EntryPoint, interceptor: EntryPointInterceptor): EntryPoint {
|
|
13
|
+
return {
|
|
14
|
+
name: interceptor.interceptName ? interceptor.interceptName(inner.name) : inner.name,
|
|
15
|
+
layer: inner.layer,
|
|
16
|
+
tags: interceptor.interceptTags ? interceptor.interceptTags(inner.tags) : inner.tags,
|
|
17
|
+
getDependencyAPIs: interceptor.interceptGetDependencyAPIs
|
|
18
|
+
? interceptor.interceptGetDependencyAPIs(inner.getDependencyAPIs)
|
|
19
|
+
: inner.getDependencyAPIs,
|
|
20
|
+
declareAPIs: interceptor.interceptDeclareAPIs ? interceptor.interceptDeclareAPIs(inner.declareAPIs) : inner.declareAPIs,
|
|
21
|
+
attach: interceptor.interceptAttach ? interceptor.interceptAttach(inner.attach) : inner.attach,
|
|
22
|
+
detach: interceptor.interceptDetach ? interceptor.interceptDetach(inner.detach) : inner.detach,
|
|
23
|
+
extend: interceptor.interceptExtend ? interceptor.interceptExtend(inner.extend) : inner.extend
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExtensionSlot } from './API'
|
|
2
|
+
|
|
3
|
+
export function invokeSlotCallbacks<T extends any[]>(slot: ExtensionSlot<(...args: T) => void | Promise<void>>, ...args: T): void {
|
|
4
|
+
const slotItems = slot.getItems()
|
|
5
|
+
|
|
6
|
+
if (slot.host.options.monitoring.disableMonitoring) {
|
|
7
|
+
slotItems.forEach(slotItem => {
|
|
8
|
+
try {
|
|
9
|
+
slotItem.contribution(...args)
|
|
10
|
+
} catch (e) {
|
|
11
|
+
console.error(e)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
} else {
|
|
15
|
+
slotItems.forEach(slotItem => {
|
|
16
|
+
const messageId = `${slot.host}-${slot.name}:${slotItem.shell.name}${slotItem.name && '-' + slotItem.name}`
|
|
17
|
+
slotItem.shell.log.monitor(messageId, {}, () => slotItem.contribution(...args))
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/loggers.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { HostLogger, LogSeverity, ShellLogger, EntryPoint, AppHost, ShellLoggerSpan, EntryPointTags } from './API'
|
|
2
|
+
|
|
3
|
+
const consoleLoggerSpan: ShellLoggerSpan = {
|
|
4
|
+
end(success, error, keyValuePairs) {
|
|
5
|
+
if (error) {
|
|
6
|
+
console.error(error, keyValuePairs)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const ConsoleHostLogger: HostLogger = {
|
|
12
|
+
spanRoot(messageId: string, error?: Error, keyValuePairs?: Object): ShellLoggerSpan {
|
|
13
|
+
return consoleLoggerSpan
|
|
14
|
+
},
|
|
15
|
+
spanChild(messageId: string, error?: Error, keyValuePairs?: Object): ShellLoggerSpan {
|
|
16
|
+
return consoleLoggerSpan
|
|
17
|
+
},
|
|
18
|
+
log(severity: LogSeverity, id: string, error?: Error, keyValuePairs?: Object): void {
|
|
19
|
+
const consoleFunc = getConsoleOutputFunc(severity)
|
|
20
|
+
consoleFunc(id, keyValuePairs)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createShellLogger(host: AppHost, entryPoint: EntryPoint): ShellLogger {
|
|
25
|
+
const entryPointTags = buildEntryPointTags()
|
|
26
|
+
|
|
27
|
+
const spanChild = (messageId: string, keyValuePairs?: Object): ShellLoggerSpan => {
|
|
28
|
+
return host.log.spanChild(messageId, withEntryPointTags(keyValuePairs))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const spanRoot = (messageId: string, keyValuePairs?: Object): ShellLoggerSpan => {
|
|
32
|
+
return host.log.spanRoot(messageId, withEntryPointTags(keyValuePairs))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
log(severity: LogSeverity, id: string, keyValuePairs?: Object): void {
|
|
37
|
+
host.log.log(severity, id, undefined, withEntryPointTags(keyValuePairs))
|
|
38
|
+
},
|
|
39
|
+
debug(messageId: string, keyValuePairs?: Object): void {
|
|
40
|
+
host.log.log('debug', messageId, undefined, withEntryPointTags(keyValuePairs))
|
|
41
|
+
},
|
|
42
|
+
info(messageId: string, keyValuePairs?: Object): void {
|
|
43
|
+
host.log.log('info', messageId, undefined, withEntryPointTags(keyValuePairs))
|
|
44
|
+
},
|
|
45
|
+
warning(messageId: string, keyValuePairs?: Object): void {
|
|
46
|
+
host.log.log('warning', messageId, undefined, withEntryPointTags(keyValuePairs))
|
|
47
|
+
},
|
|
48
|
+
error(messageId: string, error?: Error, keyValuePairs?: Object): void {
|
|
49
|
+
host.log.log('error', messageId, error, withEntryPointTags(keyValuePairs))
|
|
50
|
+
},
|
|
51
|
+
critical(messageId: string, error?: Error, keyValuePairs?: Object): void {
|
|
52
|
+
host.log.log('critical', messageId, error, withEntryPointTags(keyValuePairs))
|
|
53
|
+
},
|
|
54
|
+
spanChild,
|
|
55
|
+
spanRoot,
|
|
56
|
+
monitor
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function monitor(messageId: string, keyValuePairs: Object, monitoredCode: () => any): any {
|
|
60
|
+
const allTags = withEntryPointTags(keyValuePairs)
|
|
61
|
+
const span = spanChild(messageId, allTags)
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const returnValue = monitoredCode()
|
|
65
|
+
|
|
66
|
+
if (isPromise(returnValue)) {
|
|
67
|
+
return returnValue
|
|
68
|
+
.then(retVal => {
|
|
69
|
+
span.end(true, undefined, { ...allTags, returnValue: retVal })
|
|
70
|
+
return retVal
|
|
71
|
+
})
|
|
72
|
+
.catch(error => {
|
|
73
|
+
span.end(false, error, allTags)
|
|
74
|
+
throw error
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
span.end(true, undefined, { ...allTags, returnValue })
|
|
78
|
+
return returnValue
|
|
79
|
+
} catch (error) {
|
|
80
|
+
span.end(false, error, allTags)
|
|
81
|
+
throw error
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function buildEntryPointTags(): EntryPointTags {
|
|
86
|
+
return entryPoint.tags ? { ...entryPoint.tags, $ep: entryPoint.name } : { $ep: entryPoint.name }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function withEntryPointTags(keyValuePairs?: Object) {
|
|
90
|
+
return keyValuePairs ? { ...keyValuePairs, ...entryPointTags } : entryPointTags
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isPromise(obj: any | Promise<any>): obj is Promise<any> {
|
|
94
|
+
return !!obj && typeof obj === 'object' && typeof obj.then === 'function'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getConsoleOutputFunc(severity: LogSeverity): Console['log'] {
|
|
99
|
+
switch (severity) {
|
|
100
|
+
case 'debug':
|
|
101
|
+
return console.debug
|
|
102
|
+
case 'event':
|
|
103
|
+
return console.info
|
|
104
|
+
case 'warning':
|
|
105
|
+
return console.warn
|
|
106
|
+
case 'error':
|
|
107
|
+
case 'critical':
|
|
108
|
+
return console.error
|
|
109
|
+
default:
|
|
110
|
+
return console.log
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AppHostOptions, Shell, enrichedMemoizationFunction, ContributeAPIOptions } from './API'
|
|
2
|
+
import { interceptAnyObject } from './interceptAnyObject'
|
|
3
|
+
|
|
4
|
+
function isEnrichedMemoizationFunction(func: any): func is enrichedMemoizationFunction {
|
|
5
|
+
return func.hasOwnProperty('cache') && func.hasOwnProperty('hit')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function isMemberNamesArray<TAPI>(value: boolean | (keyof TAPI)[] | undefined): value is (keyof TAPI)[] {
|
|
9
|
+
return Array.isArray(value)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function monitorAPI<TAPI>(
|
|
13
|
+
shell: Shell,
|
|
14
|
+
hostOptions: AppHostOptions,
|
|
15
|
+
apiName: string,
|
|
16
|
+
api: TAPI,
|
|
17
|
+
//trace: Trace[],
|
|
18
|
+
//memoized: StatisticsMemoization[]
|
|
19
|
+
apiOptions?: ContributeAPIOptions<TAPI>
|
|
20
|
+
): TAPI {
|
|
21
|
+
if (hostOptions.monitoring.disableMonitoring || (apiOptions && apiOptions.disableMonitoring === true)) {
|
|
22
|
+
return api
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const shouldMonitor =
|
|
26
|
+
apiOptions && isMemberNamesArray(apiOptions.disableMonitoring)
|
|
27
|
+
? (funcName: string) => {
|
|
28
|
+
const { disableMonitoring } = apiOptions
|
|
29
|
+
if (isMemberNamesArray(disableMonitoring)) {
|
|
30
|
+
return !disableMonitoring.find(memberName => {
|
|
31
|
+
const memberNameString = memberName as string
|
|
32
|
+
return (
|
|
33
|
+
funcName.indexOf(memberNameString) === 0 &&
|
|
34
|
+
(funcName.length === memberNameString.length || funcName.charAt(memberNameString.length) === '.')
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
: () => true
|
|
40
|
+
|
|
41
|
+
return interceptAnyObject(
|
|
42
|
+
api,
|
|
43
|
+
(funcName, originalFunc) => {
|
|
44
|
+
if (!shouldMonitor(funcName)) {
|
|
45
|
+
console.log('DISABLED MONITORING>', funcName)
|
|
46
|
+
return originalFunc
|
|
47
|
+
}
|
|
48
|
+
//let funcId = `${apiName}::${funcName}`
|
|
49
|
+
let isMemoized = false
|
|
50
|
+
if (isEnrichedMemoizationFunction(originalFunc)) {
|
|
51
|
+
isMemoized = true
|
|
52
|
+
//funcId += '(Memoized)'
|
|
53
|
+
//memoized.push({ name: funcId, func: originalFunc })
|
|
54
|
+
}
|
|
55
|
+
return (...args: any[]) => {
|
|
56
|
+
const tags = {
|
|
57
|
+
$api: apiName,
|
|
58
|
+
$apiFunc: funcName,
|
|
59
|
+
$args: args,
|
|
60
|
+
$memoized: isMemoized || undefined
|
|
61
|
+
}
|
|
62
|
+
return shell.log.monitor(`${apiName}.${funcName}`, tags, () => {
|
|
63
|
+
return originalFunc.apply(api, args)
|
|
64
|
+
//wrapWithMeasure(options, originalFunc, api, args, funcId, trace)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
undefined,
|
|
69
|
+
apiOptions && apiOptions.includesNamespaces ? 4 : 0
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EntryPoint, AppHost, AnySlotKey, LazyEntryPointFactory, PrivateShell, SlotKey } from '../API'
|
|
2
|
+
import { AnyExtensionSlot } from '../extensionSlot'
|
|
3
|
+
import { Hot } from '../hot'
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
// Have to use var is this variable reassigned in the global scope
|
|
7
|
+
var repluggableAppDebug: RepluggableAppDebugInfo
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface RepluggableAppDebugInfo {
|
|
11
|
+
host: AppHost
|
|
12
|
+
uniqueShellNames: Set<string>
|
|
13
|
+
extensionSlots: Map<AnySlotKey, AnyExtensionSlot>
|
|
14
|
+
addedShells: Map<string, PrivateShell>
|
|
15
|
+
lazyShells: Map<string, LazyEntryPointFactory>
|
|
16
|
+
readyAPIs: Set<AnySlotKey>
|
|
17
|
+
shellInstallers: WeakMap<PrivateShell, string[]>
|
|
18
|
+
utils: RepluggableDebugUtils
|
|
19
|
+
hmr: RepluggableHMR
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface RepluggableDebugUtils {
|
|
23
|
+
apis(): APIDebugInfo[]
|
|
24
|
+
unReadyEntryPoints(): EntryPoint[]
|
|
25
|
+
getRootUnreadyAPI(): SlotKey<any>[]
|
|
26
|
+
whyEntryPointUnready(name: string): void
|
|
27
|
+
findAPI(name: string): APIDebugInfo[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RepluggableHMR {
|
|
31
|
+
hot: Hot
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface APIDebugInfo {
|
|
35
|
+
key: AnySlotKey
|
|
36
|
+
impl(): any
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { setupDebugInfo } from './repluggableAppDebug'
|