@stealthscale/sdk-host 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,92 +1,9 @@
1
- import { DataClientOptions, QueryClient } from "@stealthscale/provider-data";
2
- import { AccessSource, FlagSource, Product, SessionSource, When } from "@stealthscale/sdk-core";
3
- import { HostReport, HostStores, RenderTarget } from "@stealthscale/sdk-plugin";
4
- import { SettingStore } from "@stealthscale/settings";
1
+ import { n as HostOptions, t as Host } from "./options-DBsArZKT.js";
2
+ import { Product, When } from "@stealthscale/sdk-core";
3
+ import { RenderTarget } from "@stealthscale/sdk-plugin";
5
4
  import { AnyRoute, AnyRouter, NotFoundRouteProps, RouteMap, RoutesContext } from "@stealthscale/provider-router";
6
5
  import { ReactNode } from "react";
7
6
  import { DataContext } from "@stealthscale/provider-data/router";
8
- import { FormGlyphs } from "@stealthscale/component-forms/form";
9
- //#region src/host/options.d.ts
10
- /**
11
- * Lists what a host is created from.
12
- */
13
- export interface HostOptions {
14
- /**
15
- * Source of decisions on single resources. Every decision is the tenant-wide one without it.
16
- */
17
- readonly access?: AccessSource | undefined;
18
- /**
19
- * The transport and the changes stream the host's data client runs on. A sampled transport over
20
- * the contracts' samples where left out.
21
- */
22
- readonly data?: Pick<DataClientOptions, "changes" | "transport"> | undefined;
23
- /**
24
- * Source of flag values per session. Every flag has its product value or its default without
25
- * one.
26
- */
27
- readonly flags?: FlagSource | undefined;
28
- /**
29
- * Milliseconds `ready` waits for the flag source's first `identify`. 1,000 by default.
30
- */
31
- readonly flagsTimeout?: number | undefined;
32
- /**
33
- * Glyphs the settings sections' forms render: the mark in a checked box, a select's chevron and
34
- * the others the forms package names. A form renders no mark it has no glyph for.
35
- */
36
- readonly glyphs?: FormGlyphs | undefined;
37
- /**
38
- * Reads and writes flag overrides. On by default outside a production build.
39
- */
40
- readonly overrides?: boolean | undefined;
41
- /**
42
- * The resolved product with its plugins' manifests, from `virtual:product`.
43
- */
44
- readonly product: Product;
45
- /**
46
- * Failed renders in a row after which a route or an extension is quarantined. 3 by default.
47
- */
48
- readonly quarantineAfter?: number | undefined;
49
- /**
50
- * Receives every entry the host reports. Writes to the console by default.
51
- */
52
- readonly report?: ((entry: HostReport) => void) | undefined;
53
- /**
54
- * Source of the session.
55
- */
56
- readonly session: SessionSource;
57
- /**
58
- * Where the host keeps a person's switches, settings and placements.
59
- */
60
- readonly store: SettingStore;
61
- }
62
- /**
63
- * Describes a host: the state of one page, or of one request on a server.
64
- */
65
- export interface Host {
66
- /**
67
- * The data client of the page or the request, which the router's context contains.
68
- */
69
- readonly data: QueryClient;
70
- /**
71
- * Stops listening to the session source, the flag source, the access source and the setting
72
- * store, and cancels the data client's fetches.
73
- */
74
- readonly dispose: () => void;
75
- /**
76
- * Resolves once the eager plugins' modules are imported and the flag source has identified the
77
- * session, or once the flag timeout passes.
78
- */
79
- readonly ready: () => Promise<void>;
80
- /**
81
- * Lifts a target's quarantine and forgets its failures.
82
- */
83
- readonly retry: (target: RenderTarget) => void;
84
- /**
85
- * The host's stores, which `HostProvider` provides and the hooks of `sdk-plugin` read.
86
- */
87
- readonly stores: HostStores;
88
- }
89
- //#endregion
90
7
  //#region src/host/create-host.d.ts
91
8
  /**
92
9
  * Creates a host for one page, or for one request on a server.
@@ -130,6 +47,23 @@ export interface HostIntegrationOptions {
130
47
  */
131
48
  export declare function setupHostIntegration({ host, router }: HostIntegrationOptions): void;
132
49
  //#endregion
50
+ //#region src/parts/caught.d.ts
51
+ /**
52
+ * Writes an error that a React error boundary caught to the console, and leaves the router's
53
+ * not-found out.
54
+ */
55
+ /**
56
+ * Writes an error that an error boundary caught to the console, as React's default does in a
57
+ * production build, and returns without writing for the router's not-found.
58
+ *
59
+ * @remarks
60
+ * A page throws the router's not-found for parameters it cannot resolve, and the router's
61
+ * boundary renders the product's not-found page in the page's place. React reports every error a
62
+ * boundary catches, so a root without this handler writes each such not-found to the console. A
63
+ * product passes the handler to `createRoot` and `hydrateRoot` as `onCaughtError`.
64
+ */
65
+ export declare function onCaughtError(error: unknown): void;
66
+ //#endregion
133
67
  //#region src/parts/content.d.ts
134
68
  /**
135
69
  * Renders the root route's outlet inside the `content` region, so the region's extensions decorate
@@ -143,14 +77,15 @@ export declare function HostContent(): ReactNode;
143
77
  //#endregion
144
78
  //#region src/parts/not-found.d.ts
145
79
  /**
146
- * Renders the not-found page the router's data describes.
80
+ * Renders the not-found page that the router's data describes, or the loading page while the
81
+ * router loads the address again with the routes of the page's releases.
147
82
  *
148
83
  * @remarks
149
- * A page whose plugin a switch turned off names the plugin and offers a button that turns it on.
150
- * A page whose plugin a kill switch stopped names the plugin and offers nothing. A quarantined
151
- * page offers a retry that lifts the quarantine. Data of another shape, or none, renders a plain
152
- * not-found page, which states nothing about the address. The host runs the router's
153
- * `beforeLoad` again after a switch or a retry, and the page renders again in this one's place.
84
+ * The page treats the router's data as the host's own where the route evaluator threw it, and
85
+ * ignores any other data. Where the page's document contains a deployment, a plain
86
+ * not-found page renders the loading page on a server and while it hydrates. It renders the
87
+ * loading page until the router loaded the address again. The heading takes focus where the page
88
+ * renders in place of the page a person is on.
154
89
  */
155
90
  export declare function HostNotFound({ data }: NotFoundRouteProps): ReactNode;
156
91
  //#endregion
@@ -201,7 +136,8 @@ export interface HostRootProps {
201
136
  * @remarks
202
137
  * The router renders the root route's component inside a catch boundary of its own, so the
203
138
  * component renders the host's last boundary around the frame, and an error in the frame
204
- * renders the failure page and is reported with the target `host`.
139
+ * renders the failure page and is reported with the target `host`. The component provides the
140
+ * palette's open state, so a control in the frame opens the palette that `Mod+K` opens.
205
141
  */
206
142
  export declare function HostRoot({ children }: HostRootProps): ReactNode;
207
143
  //#endregion
@@ -278,11 +214,14 @@ export type NotFoundData = PageQuarantined | PluginUnavailable;
278
214
  * The routes compile in one call, so the compiler sees every path at once. Each route loads its
279
215
  * page with the modules of the plugins in its `loads`, loads its `data` through the data client
280
216
  * in the router's context, validates its search with its contract's validator, and evaluates its
281
- * condition against the host in the router's context. The settings route renders the settings
282
- * frame, its index opens the first settings page, and each settings page renders its sections.
283
- * The pages import through the manifests' importers as `instrumented` wraps them.
217
+ * condition against the host in the router's context. Each route renders the root's not-found
218
+ * page in its own place, so a page that throws the router's not-found shows it inside the frame
219
+ * and counts no failure. The settings route renders the settings frame, its index opens the first
220
+ * settings page, and each settings page renders its sections. The pages import through the
221
+ * manifests' importers as `instrumented` wraps them.
284
222
  * @param product - The product, with each installed plugin's manifest.
285
223
  * @returns The function that compiles the routes under the root, for the root's `addChildren`.
286
224
  */
287
225
  export declare function createHostRoutes(product: Product): (root: AnyRoute) => readonly AnyRoute[];
288
- //#endregion
226
+ //#endregion
227
+ export { Host, HostOptions };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as HostContent, i as HostNotFound, n as HostRoot, o as createHost, r as HostProvider, s as internalsOf, t as createHostRoutes } from "./create-routes-CkgZV-dU.js";
1
+ import { c as HostProvider, d as HostContent, f as onCaughtError, l as HostNotFound, m as internalsOf, n as HostRoot, p as createHost, t as createHostRoutes } from "./create-routes-D4iCBYZe.js";
2
2
  import { subjectOf } from "@stealthscale/sdk-core";
3
3
  //#region src/hydration/integration.ts
4
4
  /**
@@ -78,4 +78,4 @@ function setupHostIntegration({ host, router }) {
78
78
  else hydrating(host, router);
79
79
  }
80
80
  //#endregion
81
- export { HostContent, HostNotFound, HostProvider, HostRoot, createHost, createHostRoutes, setupHostIntegration };
81
+ export { HostContent, HostNotFound, HostProvider, HostRoot, createHost, createHostRoutes, onCaughtError, setupHostIntegration };
@@ -0,0 +1,91 @@
1
+ import { DataClientOptions, QueryClient } from "@stealthscale/provider-data";
2
+ import { AccessSource, FlagSource, Product, SessionSource } from "@stealthscale/sdk-core";
3
+ import { HostReport, HostStores, PluginRefused, RenderTarget } from "@stealthscale/sdk-plugin";
4
+ import { SettingStore } from "@stealthscale/settings";
5
+ import { FormGlyphs } from "@stealthscale/component-forms/form";
6
+ //#region src/host/options.d.ts
7
+ /**
8
+ * Lists what a host is created from.
9
+ */
10
+ interface HostOptions {
11
+ /**
12
+ * Source of decisions on single resources. Every decision is the tenant-wide one without it.
13
+ */
14
+ readonly access?: AccessSource | undefined;
15
+ /**
16
+ * The transport and the changes stream the host's data client runs on. A sampled transport over
17
+ * the contracts' samples where left out.
18
+ */
19
+ readonly data?: Pick<DataClientOptions, "changes" | "transport"> | undefined;
20
+ /**
21
+ * Source of flag values per session. Every flag has its product value or its default without
22
+ * one.
23
+ */
24
+ readonly flags?: FlagSource | undefined;
25
+ /**
26
+ * Milliseconds `ready` waits for the flag source's first `identify`. 1,000 by default.
27
+ */
28
+ readonly flagsTimeout?: number | undefined;
29
+ /**
30
+ * Glyphs the settings sections' forms render: the mark in a checked box, a select's chevron and
31
+ * the others the forms package names. A form renders no mark it has no glyph for.
32
+ */
33
+ readonly glyphs?: FormGlyphs | undefined;
34
+ /**
35
+ * Reads and writes flag overrides. On by default outside a production build.
36
+ */
37
+ readonly overrides?: boolean | undefined;
38
+ /**
39
+ * The resolved product with its plugins' manifests, from `virtual:product`.
40
+ */
41
+ readonly product: Product;
42
+ /**
43
+ * Failed renders in a row after which a route or an extension is quarantined. 3 by default.
44
+ */
45
+ readonly quarantineAfter?: number | undefined;
46
+ /**
47
+ * Releases the page did not load at run time, which the host reports as it is created.
48
+ */
49
+ readonly refused?: readonly PluginRefused[] | undefined;
50
+ /**
51
+ * Receives every entry the host reports. Writes to the console by default.
52
+ */
53
+ readonly report?: ((entry: HostReport) => void) | undefined;
54
+ /**
55
+ * Source of the session.
56
+ */
57
+ readonly session: SessionSource;
58
+ /**
59
+ * Where the host keeps a person's switches, settings and placements.
60
+ */
61
+ readonly store: SettingStore;
62
+ }
63
+ /**
64
+ * Describes a host: the state of one page, or of one request on a server.
65
+ */
66
+ interface Host {
67
+ /**
68
+ * The data client of the page or the request, which the router's context contains.
69
+ */
70
+ readonly data: QueryClient;
71
+ /**
72
+ * Stops listening to the session source, the flag source, the access source and the setting
73
+ * store, and cancels the data client's fetches.
74
+ */
75
+ readonly dispose: () => void;
76
+ /**
77
+ * Resolves once the eager plugins' modules are imported and the flag source has identified the
78
+ * session, or once the flag timeout passes.
79
+ */
80
+ readonly ready: () => Promise<void>;
81
+ /**
82
+ * Lifts a target's quarantine and forgets its failures.
83
+ */
84
+ readonly retry: (target: RenderTarget) => void;
85
+ /**
86
+ * The host's stores, which `HostProvider` provides and the hooks of `sdk-plugin` read.
87
+ */
88
+ readonly stores: HostStores;
89
+ }
90
+ //#endregion
91
+ export { HostOptions as n, Host as t };
@@ -11,7 +11,7 @@ import { Heading } from "@stealthscale/component-typography";
11
11
  /**
12
12
  * The props a slot without a sample renders with.
13
13
  */
14
- const NONE = {};
14
+ const NONE$1 = {};
15
15
  /**
16
16
  * Returns the values a slot renders with: each value the extensions placed in a keyed slot match,
17
17
  * and no value for a slot that is not keyed.
@@ -52,7 +52,7 @@ function placeholderPageOf(routeId, contract) {
52
52
  children: slot.id
53
53
  }), matchesOf(slot, extensions).map((match) => /* @__PURE__ */ jsx(Slot, {
54
54
  match,
55
- props: slot.sample ?? NONE,
55
+ props: slot.sample ?? NONE$1,
56
56
  slot
57
57
  }, match ?? ""))]
58
58
  }, slot.id))] });
@@ -0,0 +1,131 @@
1
+ import { t as ProductRenderOptions } from "./render-DRndY-TD.js";
2
+ import { Product, ProductDefinition } from "@stealthscale/sdk-core";
3
+ import { PluginRefused } from "@stealthscale/sdk-plugin";
4
+ import { Catalogues } from "@stealthscale/provider-i18n";
5
+ import { Root } from "react-dom/client";
6
+ //#region src/app/render-deployed.d.ts
7
+ /**
8
+ * Lists what a product whose page loads releases renders with.
9
+ */
10
+ export interface DeployedRenderOptions extends Omit<ProductRenderOptions, "refused"> {
11
+ /**
12
+ * The product's definition, from `virtual:product`, which the page resolves again with the
13
+ * releases of its document's deployment.
14
+ */
15
+ readonly definition: ProductDefinition;
16
+ }
17
+ /**
18
+ * Loads the releases the document's deployment lists, and renders the product resolved with them
19
+ * once the host is ready.
20
+ *
21
+ * @remarks
22
+ * The host reports each release the page refused. A document without a deployment renders the
23
+ * build's product.
24
+ * @param options - The definition, and what `renderProduct` renders with.
25
+ * @returns The React root the product renders in, which `unmount` takes down.
26
+ */
27
+ export declare function renderDeployed({ catalogues, definition, product, ...options }: DeployedRenderOptions): Promise<Root>;
28
+ //#endregion
29
+ //#region src/releases/catalogues.d.ts
30
+ /**
31
+ * Describes the part of a response a catalogue's fetch reads.
32
+ */
33
+ interface Fetched {
34
+ /**
35
+ * Resolves with the body read as JSON.
36
+ */
37
+ readonly json: () => Promise<unknown>;
38
+ /**
39
+ * True for a status from 200 to 299.
40
+ */
41
+ readonly ok: boolean;
42
+ /**
43
+ * The response's status.
44
+ */
45
+ readonly status: number;
46
+ }
47
+ /**
48
+ * Describes how a catalogue's fetch is asked for: with the integrity of the file.
49
+ */
50
+ interface FetchInit {
51
+ /**
52
+ * The file's integrity, in the form `sha384-<base64>`, which the browser checks.
53
+ */
54
+ readonly integrity: string;
55
+ }
56
+ /**
57
+ * Fetches a URL with the integrity of its file.
58
+ */
59
+ type Fetching = (url: string, init: FetchInit) => Promise<Fetched>;
60
+ //#endregion
61
+ //#region src/releases/preload.d.ts
62
+ /**
63
+ * Describes the part of a document that the preloader reads and writes.
64
+ */
65
+ type PreloadDocument = Pick<Document, "baseURI" | "createElement" | "head" | "querySelectorAll">;
66
+ //#endregion
67
+ //#region src/releases/deployed.d.ts
68
+ /**
69
+ * Lists what a page loads its releases with.
70
+ */
71
+ export interface DeployedOptions {
72
+ /**
73
+ * The page's catalogues, from `virtual:i18n`.
74
+ */
75
+ readonly catalogues: Catalogues;
76
+ /**
77
+ * The product's definition, from `virtual:product`.
78
+ */
79
+ readonly definition: ProductDefinition;
80
+ /**
81
+ * The page's document. It contains the deployment, and the preloader writes the preloads of the
82
+ * releases' modules into it.
83
+ */
84
+ readonly document: Pick<Document, "querySelector"> & PreloadDocument;
85
+ /**
86
+ * Fetches a release's catalogue with its integrity. The page's `fetch` where left out.
87
+ */
88
+ readonly fetching?: Fetching | undefined;
89
+ /**
90
+ * Imports a release's `manifest.js` by its absolute URL. The page's `import()` where left out.
91
+ */
92
+ readonly importing?: ((url: string) => Promise<unknown>) | undefined;
93
+ /**
94
+ * The product the build resolved, from `virtual:product`.
95
+ */
96
+ readonly product: Product;
97
+ }
98
+ /**
99
+ * Describes what a page renders after it loaded the releases of its deployment.
100
+ */
101
+ export interface Deployed {
102
+ /**
103
+ * The page's catalogues with the namespace of each admitted release.
104
+ */
105
+ readonly catalogues: Catalogues;
106
+ /**
107
+ * The product with the plugin of each admitted release.
108
+ */
109
+ readonly product: Product;
110
+ /**
111
+ * Each release the page did not load: the loader's refusals, then the resolution's.
112
+ */
113
+ readonly refused: readonly PluginRefused[];
114
+ }
115
+ /**
116
+ * Loads the releases in a page's document and resolves the product with them.
117
+ *
118
+ * @remarks
119
+ * A document without a deployment renders the build's product. Where the page cannot read the
120
+ * deployment, the page refuses every release with the reason `deployment`, and the build's
121
+ * product renders with an empty list of releases. The product's `releases` contains the id of
122
+ * every release in the document, so the page's first render withholds the same plugins as the
123
+ * server's render. After the function reads a deployment, it registers the preloader of the
124
+ * document. The preloader writes the preloads of a release's module when the release imports that
125
+ * module.
126
+ * @param options - The page's document and catalogues, the definition, the build's product, and how
127
+ * to fetch and to import.
128
+ * @returns The catalogues and the product to render, and each release the page refused.
129
+ */
130
+ export declare function deployedProduct(options: DeployedOptions): Promise<Deployed>;
131
+ //#endregion