@plitzi/sdk-server 0.38.16 → 0.38.18
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/CHANGELOG.md +115 -0
- package/README.md +33 -18
- package/dist/adapters/cloudAdapters.js +2 -2
- package/dist/core/auth/csrf.d.ts +16 -11
- package/dist/core/auth/csrf.js +35 -17
- package/dist/core/configSeam.js +1 -1
- package/dist/core/http/stages/crossSiteWrites.d.ts +5 -4
- package/dist/core/http/stages/crossSiteWrites.js +6 -5
- package/dist/core/http/stages/images.js +1 -1
- package/dist/core/http/stages/livePages.d.ts +43 -0
- package/dist/core/http/stages/livePages.js +80 -0
- package/dist/core/server/baseServer.d.ts +6 -2
- package/dist/core/server/baseServer.js +1 -0
- package/dist/core/server/fleet/channel.js +1 -1
- package/dist/core/server/fleet/relay.js +1 -1
- package/dist/core/server/pageServer.js +11 -8
- package/dist/helpers/cache/keys.js +1 -1
- package/dist/helpers/flagOverrides.d.ts +2 -1
- package/dist/helpers/paintedCookie.js +2 -2
- package/dist/{modules → hosts}/authoringHost/index.d.ts +13 -5
- package/dist/{modules → hosts}/authoringHost/index.js +31 -26
- package/dist/{modules → hosts}/project/plugins.d.ts +2 -2
- package/dist/{modules → hosts}/project/plugins.js +5 -6
- package/dist/{modules → hosts}/project/serveProject.d.ts +2 -2
- package/dist/{modules → hosts}/project/serveProject.js +12 -15
- package/dist/{modules → hosts}/project/spaceFailure.js +3 -3
- package/dist/{modules → hosts}/project/watchSpace.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/layers.test.d.ts +1 -0
- package/dist/modules/actions/jobs/later.js +1 -1
- package/dist/modules/actions/runtime/credentials.js +1 -1
- package/dist/modules/actions/runtime/kvList.js +1 -1
- package/dist/modules/actions/runtime/runAction.js +1 -1
- package/dist/modules/connectors/resolver.js +1 -1
- package/dist/modules/functions/capabilities.js +1 -1
- package/dist/modules/functions/load.js +1 -1
- package/dist/modules/functions/manifest.js +2 -2
- package/dist/modules/functions/routes.js +1 -1
- package/dist/modules/functions/runner/messages.js +1 -1
- package/dist/modules/functions/scope.js +1 -1
- package/dist/modules/images/imageProxy.js +1 -1
- package/dist/modules/realtime/socket.js +1 -1
- package/dist/modules/rsc/publicFileResolver.js +1 -1
- package/dist/modules/rsc/resolveRscData.d.ts +2 -1
- package/dist/modules/rsc/resolveRscData.js +1 -1
- package/dist/modules/runtime/bundle.js +1 -1
- package/dist/modules/ssr/prepareRender.js +8 -7
- package/dist/modules/ssr/resolvePageSeo.js +1 -1
- package/dist/modules/ssr/views/template.ejs +18 -9
- package/dist/plugins/compile.js +1 -1
- package/dist/plugins/copy.js +1 -1
- package/dist/plugins/watch.d.ts +1 -1
- package/dist/plugins/watch.js +1 -1
- package/dist/project.d.ts +4 -4
- package/dist/project.js +1 -2
- package/dist/sqlite.js +1 -2
- package/package.json +30 -15
- package/dist/core/http/stages/devReload.d.ts +0 -29
- package/dist/core/http/stages/devReload.js +0 -57
- /package/dist/core/{createServer.devReload.test.d.ts → createServer.livePages.test.d.ts} +0 -0
- /package/dist/{modules → hosts}/authoringHost/index.test.d.ts +0 -0
- /package/dist/{modules → hosts}/project/serveProject.test.d.ts +0 -0
- /package/dist/{modules → hosts}/project/spaceFailure.d.ts +0 -0
- /package/dist/{modules → hosts}/project/watchSpace.d.ts +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { openEventStream } from "../sse.js";
|
|
2
|
+
import "../../previewToken.js";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
//#region src/core/http/stages/livePages.ts
|
|
5
|
+
/** Where an open page listens for what the server has to tell it: its space changed, a plugin was built again. */
|
|
6
|
+
var LIVE_PAGES_PATH = "/__plitzi/live";
|
|
7
|
+
/**
|
|
8
|
+
* The pages open on this server, told what changed under them without the server restarting.
|
|
9
|
+
*
|
|
10
|
+
* - **The space** (`updatePages`): every page showing it swaps it where it stands — its state, scroll and focus kept —
|
|
11
|
+
* or loads again when it cannot (`replaceSpace` of the SDK's `render`). The edit loop of a project that authors its
|
|
12
|
+
* space in code (`serveProject` re-authors and hands the new documents over), and a page an agent keeps rewriting
|
|
13
|
+
* (`createAuthoringHost`'s `update`). A page listens for the space it was drawn with: the host's own, or one draft
|
|
14
|
+
* (`?__pt=<id>`, named by the page in its listening address — never by the cookie, which one browser shares between
|
|
15
|
+
* every draft it has open).
|
|
16
|
+
* - **Everything** (`reloadPages`): every page loads again.
|
|
17
|
+
* - **A plugin built again** (`plugin`): every page imports the new bundle and swaps it where it is drawn.
|
|
18
|
+
*
|
|
19
|
+
* Only with `livePages` on: every open page keeps a connection for it, which a server whose space never changes under
|
|
20
|
+
* it — a published one, or a platform's — would pay for and get nothing from. The template listens only then too.
|
|
21
|
+
*
|
|
22
|
+
* Each connection is greeted with this process's `boot`, and a page that reconnects to a different one loads again: the
|
|
23
|
+
* server restarted — `start:dev` saw its code change (`main.ts`, its options, its actions, `src/functions/`) — and
|
|
24
|
+
* what is on screen was built by the one before. Without it the page kept the old plugin until somebody reloaded it,
|
|
25
|
+
* which reads as "my change did nothing".
|
|
26
|
+
*/
|
|
27
|
+
var createLivePages = () => {
|
|
28
|
+
/** Each open page's stream, by the space it shows: `''` the host's own, otherwise the draft's token. */
|
|
29
|
+
const listening = /* @__PURE__ */ new Map();
|
|
30
|
+
const boot = randomUUID();
|
|
31
|
+
const stage = (ctx) => {
|
|
32
|
+
if (!ctx.config.livePages || ctx.req.path !== "/__plitzi/live") return Promise.resolve(false);
|
|
33
|
+
const stream = openEventStream(ctx.rawRes, {
|
|
34
|
+
onAbort: () => listening.delete(stream),
|
|
35
|
+
retryMs: 1e3
|
|
36
|
+
});
|
|
37
|
+
listening.set(stream, ctx.req.query["__pt"] ?? "");
|
|
38
|
+
stream.send("hello", { boot });
|
|
39
|
+
ctx.raw.once("close", () => {
|
|
40
|
+
listening.delete(stream);
|
|
41
|
+
stream.close();
|
|
42
|
+
});
|
|
43
|
+
return Promise.resolve(true);
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
stage,
|
|
47
|
+
/** Every page open on this server loads again. */
|
|
48
|
+
reload: () => listening.forEach((_, stream) => stream.send("reload", {})),
|
|
49
|
+
/**
|
|
50
|
+
* The pages showing the host's own space — or, with `draft`, that draft — swap it for `documents` where they stand;
|
|
51
|
+
* one that cannot loads again. How many pages were told.
|
|
52
|
+
*/
|
|
53
|
+
update: (documents, { draft = "" } = {}) => {
|
|
54
|
+
let told = 0;
|
|
55
|
+
listening.forEach((scope, stream) => {
|
|
56
|
+
if (scope === draft) {
|
|
57
|
+
stream.send("space", { documents });
|
|
58
|
+
told += 1;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return told;
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* A plugin built again: every open page imports its new bundle and swaps it where it is drawn (`keyName` is what
|
|
65
|
+
* the page registered it as), and points its stylesheet at the new one — without loading again.
|
|
66
|
+
*/
|
|
67
|
+
plugin: ({ keyName, js, css }) => listening.forEach((_, stream) => stream.send("plugin", {
|
|
68
|
+
key: keyName,
|
|
69
|
+
js,
|
|
70
|
+
css
|
|
71
|
+
})),
|
|
72
|
+
/** The streams ended — the server is going away, and each page reconnects to whichever comes up next. */
|
|
73
|
+
close: () => {
|
|
74
|
+
listening.forEach((_, stream) => stream.close());
|
|
75
|
+
listening.clear();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { LIVE_PAGES_PATH, createLivePages };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Handler } from '../transports';
|
|
2
|
-
import { CacheManager, PluginRegistry, SSRServer, SSRServerConfig } from '@plitzi/sdk-shared';
|
|
2
|
+
import { CacheManager, OfflineDataRaw, PluginRegistry, SSRServer, SSRServerConfig } from '@plitzi/sdk-shared';
|
|
3
3
|
export interface HttpServerParts {
|
|
4
4
|
label: string;
|
|
5
5
|
cache: CacheManager | null;
|
|
@@ -18,8 +18,12 @@ export interface HttpServerParts {
|
|
|
18
18
|
/** What the primary does once, before it starts the workers — work each of them would otherwise repeat, or race
|
|
19
19
|
* the others to do. */
|
|
20
20
|
beforeFork?: () => Promise<void>;
|
|
21
|
-
/** The open pages told to load again (`SSRServer.reloadPages`) — a page server
|
|
21
|
+
/** The open pages told to load again (`SSRServer.reloadPages`) — a page server with `livePages`; nothing elsewhere. */
|
|
22
22
|
reloadPages?: () => void;
|
|
23
|
+
/** The open pages handed new documents (`SSRServer.updatePages`) — a page server with `livePages`; none elsewhere. */
|
|
24
|
+
updatePages?: (documents: OfflineDataRaw, options?: {
|
|
25
|
+
draft?: string;
|
|
26
|
+
}) => number;
|
|
23
27
|
/** A plugin's server half replaced while the server runs (`SSRServer.functions`) — a page server that runs actions. */
|
|
24
28
|
setPluginFunctions?: (plugin: string, definition: unknown) => void;
|
|
25
29
|
}
|
|
@@ -35,6 +35,7 @@ var createHttpServer = (config, makeHandlerForPort, parts) => {
|
|
|
35
35
|
cache: channel && parts.cache ? relayCache(parts.cache, `${channel}.cache`) : parts.cache,
|
|
36
36
|
plugins: channel && parts.forgetPlugins ? relayPlugins(parts.plugins, parts.forgetPlugins, `${channel}.plugins`, label) : parts.plugins,
|
|
37
37
|
reloadPages: parts.reloadPages ?? (() => void 0),
|
|
38
|
+
updatePages: parts.updatePages ?? (() => 0),
|
|
38
39
|
functions: { setPlugin: parts.setPluginFunctions ?? (() => {
|
|
39
40
|
throw new Error(`[${label}] This server runs no actions, so no plugin's functions`);
|
|
40
41
|
}) },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
1
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
2
2
|
//#region src/core/server/fleet/channel.ts
|
|
3
3
|
/** The channel is shared with `node:cluster` and anything else the deployment sends: only these are ours. */
|
|
4
4
|
var isFleetMessage = (value) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { serverLog } from "../../../helpers/serverLog.js";
|
|
2
2
|
import { broadcast, onBroadcast } from "./link.js";
|
|
3
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
3
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
4
4
|
//#region src/core/server/fleet/relay.ts
|
|
5
5
|
/**
|
|
6
6
|
* `server.cache` and `server.plugins` in a fleet, whose workers each keep their own: what one process is told, every
|
|
@@ -16,7 +16,7 @@ import { compileTemplate } from "../../modules/ssr/template.js";
|
|
|
16
16
|
import { PluginManager } from "../../plugins/manager.js";
|
|
17
17
|
import { watchPluginSources } from "../../plugins/watch.js";
|
|
18
18
|
import { makeHandler } from "../http/dispatcher.js";
|
|
19
|
-
import {
|
|
19
|
+
import { createLivePages } from "../http/stages/livePages.js";
|
|
20
20
|
import { buildPagePipeline } from "../services/registry.js";
|
|
21
21
|
//#region src/core/server/pageServer.ts
|
|
22
22
|
/** The page-serving machinery: html/rsc caches, the render template and the plugin manager, driving the page
|
|
@@ -52,19 +52,19 @@ var createPageServer = (config, services, extensions) => {
|
|
|
52
52
|
};
|
|
53
53
|
const actions = actionsModuleFor(config);
|
|
54
54
|
const realtime = realtimeModuleFor(config);
|
|
55
|
-
const
|
|
55
|
+
const livePages = config.livePages ? createLivePages() : void 0;
|
|
56
56
|
/**
|
|
57
57
|
* A plugin whose source changed is built again and handed to the open pages, which swap it where it is drawn — the
|
|
58
|
-
* rest of the page, its state included, stays as it was. Only while developing with `
|
|
58
|
+
* rest of the page, its state included, stays as it was. Only while developing (`devMode`) with `livePages` on: nobody edits a
|
|
59
59
|
* deployment's plugins under it, and a page that does not listen has nothing to swap.
|
|
60
60
|
*/
|
|
61
|
-
const stopWatchingPlugins =
|
|
61
|
+
const stopWatchingPlugins = livePages && config.devMode ? watchPluginSources(pluginManager, (key) => {
|
|
62
62
|
invalidatePluginComponentCache();
|
|
63
63
|
pluginManager.rebuild(key).then((entry) => {
|
|
64
|
-
if (entry?.js)
|
|
64
|
+
if (entry?.js) livePages.plugin(entry);
|
|
65
65
|
});
|
|
66
66
|
}) : void 0;
|
|
67
|
-
const stages = [...
|
|
67
|
+
const stages = [...livePages ? [livePages.stage] : [], ...buildPagePipeline(services, extensions)];
|
|
68
68
|
const makeHandlerForPort = (port) => {
|
|
69
69
|
const buildContext = (raw, rawRes, req, res) => ({
|
|
70
70
|
raw,
|
|
@@ -99,9 +99,12 @@ var createPageServer = (config, services, extensions) => {
|
|
|
99
99
|
onClosing: () => {
|
|
100
100
|
realtime?.close();
|
|
101
101
|
stopWatchingPlugins?.();
|
|
102
|
-
|
|
102
|
+
livePages?.close();
|
|
103
103
|
},
|
|
104
|
-
...
|
|
104
|
+
...livePages ? {
|
|
105
|
+
reloadPages: livePages.reload,
|
|
106
|
+
updatePages: livePages.update
|
|
107
|
+
} : {},
|
|
105
108
|
...actions ? { setPluginFunctions: (plugin, definition) => {
|
|
106
109
|
if (definition !== void 0 && !isFunctionsDefinition(definition)) throw new Error(`[SSR] The functions of plugin "${plugin}" are not a definition: defineFunctions({ … })`);
|
|
107
110
|
actions.setPluginFunctions(plugin, definition);
|
|
@@ -3,7 +3,7 @@ import { ssrPaintedCookieName } from "../paintedCookie.js";
|
|
|
3
3
|
import { readCookie } from "../readCookie.js";
|
|
4
4
|
import { flagsCookieName } from "@plitzi/sdk-shared/flags";
|
|
5
5
|
import { debugCookieName } from "@plitzi/sdk-shared/devTools";
|
|
6
|
-
import { themeFromCookies } from "@plitzi/sdk-shared/theme";
|
|
6
|
+
import { themeFromCookies } from "@plitzi/sdk-shared/theme/cookie";
|
|
7
7
|
//#region src/helpers/cache/keys.ts
|
|
8
8
|
var flagsVersionOf = (req) => req.ctx?.spaceDeployment?.flagsVersion ?? "";
|
|
9
9
|
/** The fields of an HTML key, in the order they are joined. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Environment,
|
|
1
|
+
import { Environment, SSRServerConfig } from '@plitzi/sdk-shared';
|
|
2
|
+
import { FlagOverrides } from '@plitzi/sdk-shared/flags';
|
|
2
3
|
/** The deployment's own layer for one space: `config.flags`, asked per space when it is a function. */
|
|
3
4
|
export declare const serverFlagsFor: (config: Pick<SSRServerConfig, "flags">, space: {
|
|
4
5
|
spaceId: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getKeyDecoded } from "@plitzi/sdk-shared/helpers
|
|
2
|
-
import { paintedStateCookieName } from "@plitzi/sdk-shared/state
|
|
1
|
+
import { getKeyDecoded } from "@plitzi/sdk-shared/helpers";
|
|
2
|
+
import { paintedStateCookieName } from "@plitzi/sdk-shared/state";
|
|
3
3
|
//#region src/helpers/paintedCookie.ts
|
|
4
4
|
/**
|
|
5
5
|
* The name the painted state of a server-rendered page is kept under, for this request's host.
|
|
@@ -8,14 +8,19 @@ import { SSRServer } from '@plitzi/sdk-shared';
|
|
|
8
8
|
* Each page is a space kept as a draft of the host's one space (`?__pt=<id>`), which is how a page server tells many
|
|
9
9
|
* apart on one host: the page arrives with its whole space in it, every page after it is the browser's, and a reload
|
|
10
10
|
* that lost the address finds it again in the draft's cookie. So a page here is drawn in the browser alone — no server
|
|
11
|
-
* provider, action, function or channel of its own: it is data and its look.
|
|
11
|
+
* provider, action, function or channel of its own: it is data and its look. `put` again under the same id and the
|
|
12
|
+
* pages open at it take the new version where they stand (`livePages`), so a page an agent keeps improving is seen to
|
|
13
|
+
* grow rather than reload.
|
|
12
14
|
*
|
|
13
15
|
* Author them where they cannot reach anything (`authorIsolated` of `@plitzi/sdk-authoring/node`) and serve them here,
|
|
14
|
-
* on
|
|
16
|
+
* on a HOST of their own — never the app's, nor another port of it: a cookie belongs to a host whatever its port, so a
|
|
17
|
+
* page somebody else wrote would run beside the app's cookies. Locally `127.0.0.1` beside the app's `localhost`; in
|
|
18
|
+
* production a domain of its own, since a sibling sub-domain shares the app's site and its domain-wide cookies.
|
|
15
19
|
*
|
|
16
20
|
* ```ts
|
|
21
|
+
* // The app at https://localhost:8080.
|
|
17
22
|
* const host = createAuthoringHost({ dir: 'tmp/pages', port: 8091, frameAncestors: ['https://localhost:8080'] });
|
|
18
|
-
* await host.server.listen(8091, '
|
|
23
|
+
* await host.server.listen(8091, '127.0.0.1'); // its pages at https://127.0.0.1:8091
|
|
19
24
|
*
|
|
20
25
|
* const result = await authorIsolated('tmp/pages/weather.ts');
|
|
21
26
|
* if (result.ok) {
|
|
@@ -32,14 +37,17 @@ export type AuthoringHostConfig = Omit<ServerConfig, 'adapters' | 'auth' | 'draf
|
|
|
32
37
|
export type AuthoringHost = {
|
|
33
38
|
server: SSRServer;
|
|
34
39
|
/**
|
|
35
|
-
* Keeps a space under `id` — a new one when left out, which nobody can guess —
|
|
36
|
-
*
|
|
40
|
+
* Keeps a space under `id` — a new one when left out, which nobody can guess — and answers the address its pages are
|
|
41
|
+
* at: its home is `path`, any other page that path with the page's own in front of `?`. Replacing what `id` held, the
|
|
42
|
+
* pages open at it swap the new space where they stand — scroll, focus and what the person was doing kept — and
|
|
43
|
+
* `updated` says how many did.
|
|
37
44
|
*/
|
|
38
45
|
put: (documents: AuthoredDocuments, options?: {
|
|
39
46
|
id?: string;
|
|
40
47
|
}) => {
|
|
41
48
|
id: string;
|
|
42
49
|
path: string;
|
|
50
|
+
updated: number;
|
|
43
51
|
};
|
|
44
52
|
/** Forgets a page: its address answers 404 from then on. Whether there was one. */
|
|
45
53
|
drop: (id: string) => boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { serverLog } from "../../helpers/serverLog.js";
|
|
2
2
|
import { PREVIEW_TOKEN_PARAM, readDraftToken } from "../../core/previewToken.js";
|
|
3
3
|
import { createServer } from "../../core/createServer.js";
|
|
4
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
4
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
5
5
|
import { randomBytes } from "node:crypto";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
-
//#region src/
|
|
8
|
+
//#region src/hosts/authoringHost/index.ts
|
|
9
9
|
/** The one space the host serves, which every page is a draft of. */
|
|
10
10
|
var SPACE_ID = 1;
|
|
11
11
|
/** An id is a file's name and a query's value: nothing that could be read as a path or need escaping. */
|
|
@@ -73,36 +73,41 @@ var createAuthoringHost = ({ dir, frameAncestors, ...config }) => {
|
|
|
73
73
|
revision: 0,
|
|
74
74
|
...frameAncestors ? { frameAncestors } : {}
|
|
75
75
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
76
|
+
const server = createServer({
|
|
77
|
+
livePages: true,
|
|
78
|
+
...config,
|
|
79
|
+
preview: {
|
|
80
|
+
sessionTtlMs: SESSION_TTL_MS,
|
|
81
|
+
...config.preview
|
|
82
|
+
},
|
|
83
|
+
draftStore,
|
|
84
|
+
adapters: {
|
|
85
|
+
getOfflineData: () => Promise.resolve(void 0),
|
|
86
|
+
getSpaceDeployment: (req) => {
|
|
87
|
+
const id = readDraftToken(req);
|
|
88
|
+
if (id === void 0) return Promise.resolve({ error: {
|
|
89
|
+
code: 404,
|
|
90
|
+
message: `Nothing here: each page of this host is at the address put() answered — /?${PREVIEW_TOKEN_PARAM}=<id>`
|
|
91
|
+
} });
|
|
92
|
+
if (!pages.has(id)) return Promise.resolve({ error: {
|
|
93
|
+
code: 404,
|
|
94
|
+
message: `No page "${id}" here: put() it, or it was dropped`
|
|
95
|
+
} });
|
|
96
|
+
return Promise.resolve(deployment);
|
|
98
97
|
}
|
|
99
|
-
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
server,
|
|
100
102
|
put: (documents, { id = randomBytes(16).toString("base64url") } = {}) => {
|
|
101
103
|
if (!ID.test(id)) throw new Error(`A page id is letters, digits, "-" and "_", up to 64 of them — not "${id}"`);
|
|
104
|
+
const replacing = pages.has(id);
|
|
102
105
|
keep(id, documents);
|
|
106
|
+
const updated = replacing ? server.updatePages(documents, { draft: id }) : 0;
|
|
103
107
|
return {
|
|
104
108
|
id,
|
|
105
|
-
path: `/?${PREVIEW_TOKEN_PARAM}=${id}
|
|
109
|
+
path: `/?${PREVIEW_TOKEN_PARAM}=${id}`,
|
|
110
|
+
updated
|
|
106
111
|
};
|
|
107
112
|
},
|
|
108
113
|
drop,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionsDefinition } from '
|
|
1
|
+
import { FunctionsDefinition } from '../../modules/functions/contract';
|
|
2
2
|
import { PluginSource, SSRServer } from '@plitzi/sdk-shared';
|
|
3
3
|
/**
|
|
4
4
|
* A project's plugins, as its server registers them: every folder of `src/plugins` built from its source, and every
|
|
@@ -22,7 +22,7 @@ export type ProjectPlugins = {
|
|
|
22
22
|
export declare const projectPlugins: (root: string) => Promise<ProjectPlugins>;
|
|
23
23
|
/**
|
|
24
24
|
* A plugin edited while developing is built again by the server, and the open pages swap it where it is drawn — the
|
|
25
|
-
* rest of the page, its state included, stays as it was (`
|
|
25
|
+
* rest of the page, its state included, stays as it was (`livePages`). Its server half (`functions/`) is loaded again
|
|
26
26
|
* here, in place. A plugin ADDED — a new folder with an `index.ts`, what `plitzi plugin add` writes — is registered
|
|
27
27
|
* here, and the pages load again to render it; one removed is turned off. A folder the server cannot build, or whose
|
|
28
28
|
* server half has no entry, is said in the terminal as the layout check says it at boot — once, until it changes — and
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { loadFunctions, loadFunctionsSource } from "
|
|
1
|
+
import { loadFunctions, loadFunctionsSource } from "../../modules/functions/load.js";
|
|
2
2
|
import { PLUGIN_FUNCTIONS_SOURCE } from "@plitzi/sdk-shared/actions";
|
|
3
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
3
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { existsSync, readFileSync, readdirSync, watch } from "node:fs";
|
|
6
|
-
import { checkPluginFolder, layoutFindingText, pluginEntry, pluginTypeOf, readVendorPlugin } from "@plitzi/sdk-shared/project
|
|
7
|
-
|
|
8
|
-
//#region src/modules/project/plugins.ts
|
|
6
|
+
import { PLUGINS_DIR, PLUGIN_FUNCTIONS_DIR, VENDOR_PLUGINS_DIR, checkPluginFolder, layoutFindingText, pluginEntry, pluginTypeOf, readVendorPlugin } from "@plitzi/sdk-shared/project";
|
|
7
|
+
//#region src/hosts/project/plugins.ts
|
|
9
8
|
/**
|
|
10
9
|
* `action: 'compile'` is what makes a folder's plugin SERVER-rendered: the server builds the entry with esbuild, keeps
|
|
11
10
|
* React external so the plugin runs on the one copy the page already has, serves the bundle to the browser AND
|
|
@@ -87,7 +86,7 @@ var projectPlugins = async (root) => {
|
|
|
87
86
|
};
|
|
88
87
|
/**
|
|
89
88
|
* A plugin edited while developing is built again by the server, and the open pages swap it where it is drawn — the
|
|
90
|
-
* rest of the page, its state included, stays as it was (`
|
|
89
|
+
* rest of the page, its state included, stays as it was (`livePages`). Its server half (`functions/`) is loaded again
|
|
91
90
|
* here, in place. A plugin ADDED — a new folder with an `index.ts`, what `plitzi plugin add` writes — is registered
|
|
92
91
|
* here, and the pages load again to render it; one removed is turned off. A folder the server cannot build, or whose
|
|
93
92
|
* server half has no entry, is said in the terminal as the layout check says it at boot — once, until it changes — and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthoredDocuments } from './watchSpace';
|
|
2
2
|
import { ServerConfig } from '../../core/createServer';
|
|
3
|
-
import { ConnectorManifest } from '
|
|
3
|
+
import { ConnectorManifest } from '../../modules/connectors';
|
|
4
4
|
import { ActionEntry, SSRServer } from '@plitzi/sdk-shared';
|
|
5
5
|
/** What `serveProject` sets itself, from the project's layout — so never the project's options'. */
|
|
6
6
|
type SetByProject = 'port' | 'health' | 'adapters' | 'plugins' | 'publicDir' | 'dataDir' | 'functions' | 'action';
|
|
@@ -8,7 +8,7 @@ type SetByProject = 'port' | 'health' | 'adapters' | 'plugins' | 'publicDir' | '
|
|
|
8
8
|
* What a project's server does besides serving its space — its `src/config/serverOptions.ts`: what `createServer`
|
|
9
9
|
* takes, but for what `serveProject` wires from the project's layout, and an action's `lookups`, which are the
|
|
10
10
|
* project's `src/actions/`. `logLevel` and `logger` are the project's to change; `action.kv` too. So are `devMode` and
|
|
11
|
-
* `
|
|
11
|
+
* `livePages`, which follow `NODE_ENV` when left out — on unless it is `production`. A deployment started without it (a
|
|
12
12
|
* container's `CMD`, a process manager with no environment) says `devMode: false` here, and a public action answers
|
|
13
13
|
* with its output alone, never the trace of every step.
|
|
14
14
|
*/
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { consoleLogger } from "../../helpers/serverLog.js";
|
|
2
2
|
import { isFleetWorker } from "../../core/server/fleet/role.js";
|
|
3
|
-
import { loadFunctions } from "
|
|
3
|
+
import { loadFunctions } from "../../modules/functions/load.js";
|
|
4
4
|
import { createServer as createServer$1 } from "../../core/createServer.js";
|
|
5
5
|
import { closeOnSignals } from "../../core/server/closeOnSignals.js";
|
|
6
6
|
import { freePort } from "../../core/freePort.js";
|
|
7
7
|
import { createCloudAdapters } from "../../adapters/cloudAdapters.js";
|
|
8
8
|
import { createJsonAdapters } from "../../adapters/jsonAdapters.js";
|
|
9
|
-
import { createFileKv } from "
|
|
10
|
-
import { credentialsFromEnv } from "
|
|
11
|
-
import { reachOwnServer } from "
|
|
12
|
-
import { loadRuntime, loadRuntimeModule } from "
|
|
13
|
-
import { serveRuntime } from "
|
|
9
|
+
import { createFileKv } from "../../modules/actions/runtime/fileKv.js";
|
|
10
|
+
import { credentialsFromEnv } from "../../modules/actions/runtime/credentials.js";
|
|
11
|
+
import { reachOwnServer } from "../../modules/runtime/inside.js";
|
|
12
|
+
import { loadRuntime, loadRuntimeModule } from "../../modules/runtime/bundle.js";
|
|
13
|
+
import { serveRuntime } from "../../modules/runtime/stages.js";
|
|
14
14
|
import { projectPlugins, watchProjectPlugins } from "./plugins.js";
|
|
15
15
|
import { createSpaceFailure } from "./spaceFailure.js";
|
|
16
16
|
import { watchSpace } from "./watchSpace.js";
|
|
@@ -19,14 +19,11 @@ import { X509Certificate } from "node:crypto";
|
|
|
19
19
|
import { hostname, networkInterfaces } from "node:os";
|
|
20
20
|
import { isIP } from "node:net";
|
|
21
21
|
import path from "node:path";
|
|
22
|
+
import { EMPTY_SCHEMA } from "@plitzi/sdk-shared/schema";
|
|
22
23
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
23
|
-
import {
|
|
24
|
-
import { localNetworkName, networkAddresses } from "@plitzi/sdk-shared/project
|
|
25
|
-
|
|
26
|
-
import { projectModule, projectRoot } from "@plitzi/sdk-shared/project/root";
|
|
27
|
-
import { EMPTY_SCHEMA } from "@plitzi/sdk-shared/schema/schemaConstants";
|
|
28
|
-
import { EMPTY_STYLE_SCHEMA } from "@plitzi/sdk-shared/style/styleConstants";
|
|
29
|
-
//#region src/modules/project/serveProject.ts
|
|
24
|
+
import { EMPTY_STYLE_SCHEMA } from "@plitzi/sdk-shared/style";
|
|
25
|
+
import { DATA_DIR, DEV_SERVER_FILE, FUNCTIONS_DIR, KV_FILE, PROJECT_TMP, PUBLIC_DIR, RUNTIME_BUNDLE, RUNTIME_ENTRY, assertProjectLayout, layoutFindingText, localNetworkName, networkAddresses, projectModule, projectRoot } from "@plitzi/sdk-shared/project";
|
|
26
|
+
//#region src/hosts/project/serveProject.ts
|
|
30
27
|
/**
|
|
31
28
|
* The errors whose message is the whole report — every problem, where it is and what to write instead — and whose
|
|
32
29
|
* stack would only point inside the SDK: the project's root, its layout, a space module with no space, a space that does
|
|
@@ -229,7 +226,7 @@ var startProject = async (options) => {
|
|
|
229
226
|
...tls ? { tls } : {},
|
|
230
227
|
port,
|
|
231
228
|
devMode: serverOptions.devMode ?? developing,
|
|
232
|
-
|
|
229
|
+
livePages: serverOptions.livePages ?? serverOptions.devMode ?? developing,
|
|
233
230
|
health: { name },
|
|
234
231
|
adapters,
|
|
235
232
|
plugins: plugins.sources,
|
|
@@ -267,7 +264,7 @@ var startProject = async (options) => {
|
|
|
267
264
|
const watching = developing ? [...held ? [watchSpace(root, (authored) => {
|
|
268
265
|
held.documents = authored;
|
|
269
266
|
spaceFailure.clear();
|
|
270
|
-
server.
|
|
267
|
+
server.updatePages(authored);
|
|
271
268
|
})] : [], watchProjectPlugins(root, server, plugins)] : [];
|
|
272
269
|
const close = async () => {
|
|
273
270
|
watching.forEach((stop) => stop());
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LIVE_PAGES_PATH } from "../../core/http/stages/livePages.js";
|
|
2
2
|
import { escapeHtml } from "../../helpers/escapeHtml.js";
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/hosts/project/spaceFailure.ts
|
|
4
4
|
/**
|
|
5
5
|
* The page a project's server answers with while its space does not author — while developing only.
|
|
6
6
|
*
|
|
@@ -33,7 +33,7 @@ var pageOf = (message) => `<!doctype html>
|
|
|
33
33
|
<script>
|
|
34
34
|
(() => {
|
|
35
35
|
let boot;
|
|
36
|
-
const events = new EventSource(${JSON.stringify(
|
|
36
|
+
const events = new EventSource(${JSON.stringify(LIVE_PAGES_PATH)});
|
|
37
37
|
events.addEventListener('reload', () => location.reload());
|
|
38
38
|
events.addEventListener('hello', event => {
|
|
39
39
|
const next = JSON.parse(event.data).boot;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
1
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { watch } from "node:fs";
|
|
4
|
-
import { AUTHOR_FILE, SOURCE_DIR } from "@plitzi/sdk-shared/project
|
|
4
|
+
import { AUTHOR_FILE, SOURCE_DIR } from "@plitzi/sdk-shared/project";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/hosts/project/watchSpace.ts
|
|
7
7
|
/**
|
|
8
8
|
* What the author script sent: its own `{ schema, style }`, which `authorSpace` built and checked — the message is
|
|
9
9
|
* looked at only for its shape, so a stray one from a script that is not the CLI's is not served.
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { createAuthAdapters } from './adapters/authAdapters';
|
|
|
12
12
|
export { authoringPreview, createMemoryCache, createSpaceAdapters, fixedSpace, presentsCredential, refuse, verifiedDomain, wildcardSubdomain } from './adapters/space';
|
|
13
13
|
export { createLocalFontStore, hostedPathsOf } from './core/fontStore';
|
|
14
14
|
export { createMemoryDraftStore, takeDraftOverride } from './modules/ssr/preview';
|
|
15
|
-
export { createAuthoringHost } from './
|
|
15
|
+
export { createAuthoringHost } from './hosts/authoringHost';
|
|
16
16
|
export { createMemoryPubSub } from './modules/realtime/memoryPubSub';
|
|
17
17
|
export { createRedisPubSub } from './modules/realtime/redisPubSub';
|
|
18
18
|
export { PREVIEW_TOKEN_PARAM } from './core/previewToken';
|
|
@@ -28,6 +28,6 @@ export type { FontStore, StoredFont } from './core/fontStore';
|
|
|
28
28
|
export type { PubSubAdapter, SSRRealtimeConfig } from '@plitzi/sdk-shared';
|
|
29
29
|
export type { RedisPubSubClients } from './modules/realtime/redisPubSub';
|
|
30
30
|
export type { ResolvedServices, ServerConfig } from './core/createServer';
|
|
31
|
-
export type { AuthoringHost, AuthoringHostConfig } from './
|
|
31
|
+
export type { AuthoringHost, AuthoringHostConfig } from './hosts/authoringHost';
|
|
32
32
|
export type { Closable, CloseOnSignalsOptions } from './core/server/closeOnSignals';
|
|
33
33
|
export type { BaseContext, PipelineExtensions, SSRContext, Stage } from './core/http/types';
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,6 @@ import { createMemoryCache, refuse } from "./adapters/space/types.js";
|
|
|
19
19
|
import { authoringPreview, fixedSpace, presentsCredential, verifiedDomain, wildcardSubdomain } from "./adapters/space/resolvers.js";
|
|
20
20
|
import { createSpaceAdapters } from "./adapters/space/index.js";
|
|
21
21
|
import { createLocalFontStore, hostedPathsOf } from "./core/fontStore.js";
|
|
22
|
-
import { createAuthoringHost } from "./
|
|
22
|
+
import { createAuthoringHost } from "./hosts/authoringHost/index.js";
|
|
23
23
|
import { createRedisPubSub } from "./modules/realtime/redisPubSub.js";
|
|
24
24
|
export { PREVIEW_TOKEN_PARAM, authoringPreview, buildHealthPayload, closeOnSignals, consoleLogger, createAuthAdapters, createAuthoringHost, createCloudAdapters, createConnectorResolver, createJsonAdapters, createLocalFontStore, createMemoryCache, createMemoryDraftStore, createMemoryPubSub, createRedisPubSub, createServer, createSpaceAdapters, fetchConnectorRecords, fixedSpace, freePort, hostedPathsOf, isLogged, loadFunctions, loadFunctionsSource, logLevelOf, presentsCredential, readFunctionsDir, rebaseMedia, refuse, registerHealthCheck, renderLogEvent, resolveRscData, resolveServices, serverLog, takeDraftOverride, unusedPort, verifiedDomain, wildcardSubdomain, writeConnectorRecord };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findTriggerNode } from "../runtime/triggers.js";
|
|
2
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
2
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
//#region src/modules/actions/jobs/later.ts
|
|
5
5
|
/** A month: past it, a run set for later is a schedule, and a cron says it better. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
1
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
2
2
|
//#region src/modules/actions/runtime/credentials.ts
|
|
3
3
|
/** Where a project's server — and `plitzi functions dev` — reads the credentials its space's code names. */
|
|
4
4
|
var CREDENTIALS_ENV = "PLITZI_CREDENTIALS";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
1
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
2
2
|
//#region src/modules/actions/runtime/kvList.ts
|
|
3
3
|
/**
|
|
4
4
|
* The most a list holds. A list is one value of the store, read and written whole, so it is for what a page shows at
|
|
@@ -13,7 +13,7 @@ import { createSigning } from "./signing.js";
|
|
|
13
13
|
import { createRunFetch, taskContextFor } from "./taskContext.js";
|
|
14
14
|
import onAbort from "../../../helpers/onAbort.js";
|
|
15
15
|
import { FAILURE_HANDLER_TASK } from "@plitzi/sdk-shared/actions";
|
|
16
|
-
import { evaluateRuleGroup } from "@plitzi/sdk-shared/helpers
|
|
16
|
+
import { evaluateRuleGroup } from "@plitzi/sdk-shared/helpers";
|
|
17
17
|
import { resolveStepParam } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
18
18
|
//#region src/modules/actions/runtime/runAction.ts
|
|
19
19
|
/** How often a run asks the shared store whether it has been cancelled. Once a second is far finer than the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fetchConnectorRecords } from "./engine.js";
|
|
2
2
|
import { collectBoundPaths, projectSlice } from "./projection.js";
|
|
3
|
-
import getSourceName from "@plitzi/sdk-shared/dataSource/helpers
|
|
3
|
+
import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
|
|
4
4
|
//#region src/modules/connectors/resolver.ts
|
|
5
5
|
var DEFAULT_PAGE_PARAM = "page";
|
|
6
6
|
var toLimit = (limit, singleRecord) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
1
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
2
2
|
//#region src/modules/functions/capabilities.ts
|
|
3
3
|
var TEXTUAL = /^(text\/|application\/([\w.+-]*\+)?(json|xml|javascript|x-www-form-urlencoded))/i;
|
|
4
4
|
/** A body as the wire carries it: as text when its type says it is text, base64 otherwise. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildFunctions } from "./build.js";
|
|
2
2
|
import { readFunctionsSource } from "@plitzi/sdk-shared/actions";
|
|
3
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers
|
|
3
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
4
4
|
import { readFile, readdir } from "node:fs/promises";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
//#region src/modules/functions/load.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pluginTaskProblem } from "./scope.js";
|
|
2
2
|
import { taskName, taskNameProblem } from "../actions/tasks/registry.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PLUGIN_ROUTES_SEGMENT } from "@plitzi/sdk-shared/actions";
|
|
4
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
5
5
|
//#region src/modules/functions/manifest.ts
|
|
6
6
|
var ROUTE_METHODS = [
|
|
7
7
|
"GET",
|
|
@@ -6,8 +6,8 @@ import { functionLimitsFor } from "./config.js";
|
|
|
6
6
|
import { parseRouteKey, reservedRouteProblem } from "./manifest.js";
|
|
7
7
|
import { answerCall, readCall, responseOf, wireRequestOf, wireResponseFrom } from "./capabilities.js";
|
|
8
8
|
import { FunctionFailure } from "./protocol.js";
|
|
9
|
+
import { PLUGIN_ROUTES_SEGMENT } from "@plitzi/sdk-shared/actions";
|
|
9
10
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { PLUGIN_ROUTES_SEGMENT } from "@plitzi/sdk-shared/actions/functions";
|
|
11
11
|
//#region src/modules/functions/routes.ts
|
|
12
12
|
/** A route key's params from a path it answers, or nothing when it does not answer it. */
|
|
13
13
|
var matchKey = (key, method, path) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PLUGIN_ROUTES_SEGMENT } from "@plitzi/sdk-shared/actions
|
|
1
|
+
import { PLUGIN_ROUTES_SEGMENT } from "@plitzi/sdk-shared/actions";
|
|
2
2
|
//#region src/modules/functions/scope.ts
|
|
3
3
|
/** Where a plugin's routes answer, under `/fn`: `/fn/plugins/<type>/…`. */
|
|
4
4
|
var PLUGIN_ROUTES = `/${PLUGIN_ROUTES_SEGMENT}/`;
|