wip: Adding in properties and nested path

This commit is contained in:
J H
2024-03-23 09:03:56 -06:00
parent 4a27128a1c
commit f5360cb8d4
13 changed files with 198 additions and 180 deletions

View File

@@ -1,14 +1,9 @@
import { DependenciesReceipt } from "../config/setupConfig"
import { SetInterfaces } from "../interfaces/setupInterfaces"
import { SDKManifest } from "../manifest/ManifestTypes"
import {
Effects,
ExpectedExports,
ExposeUiPaths,
ExposeUiPathsAll,
} from "../types"
import { ExposedStorePaths } from "../store/setupExposeStore"
import { Effects, ExpectedExports } from "../types"
import { Migrations } from "./migrations/setupMigrations"
import { SetupExports } from "./setupExports"
import { Install } from "./setupInstall"
import { Uninstall } from "./setupUninstall"
@@ -17,11 +12,11 @@ export function setupInit<Manifest extends SDKManifest, Store>(
install: Install<Manifest, Store>,
uninstall: Uninstall<Manifest, Store>,
setInterfaces: SetInterfaces<Manifest, Store, any, any>,
setupExports: SetupExports<Store>,
setDependencies: (options: {
effects: Effects
input: any
}) => Promise<DependenciesReceipt>,
exposedStore: ExposedStorePaths,
): {
init: ExpectedExports.init
uninit: ExpectedExports.uninit
@@ -34,9 +29,7 @@ export function setupInit<Manifest extends SDKManifest, Store>(
...opts,
input: null,
})
const { services, ui } = await setupExports(opts)
await opts.effects.exposeForDependents({ paths: services })
await opts.effects.exposeUi(forExpose(ui))
await opts.effects.exposeForDependents({ paths: exposedStore })
await setDependencies({ effects: opts.effects, input: null })
},
uninit: async (opts) => {
@@ -45,30 +38,3 @@ export function setupInit<Manifest extends SDKManifest, Store>(
},
}
}
function forExpose<Store>(ui: { [key: string]: ExposeUiPaths<Store> }) {
return Object.fromEntries(
Object.entries(ui).map(([key, value]) => [key, forExpose_(value)]),
)
}
function forExpose_<Store>(ui: ExposeUiPaths<Store>): ExposeUiPathsAll {
if (ui.type === ("object" as const)) {
return {
type: "object" as const,
value: Object.fromEntries(
Object.entries(ui.value).map(([key, value]) => [
key,
forExpose_(value),
]),
),
description: ui.description ?? null,
}
}
return {
description: null,
copyable: null,
qr: null,
...ui,
}
}