@powerhousedao/switchboard 6.2.3-dev.70 → 6.2.3-dev.71
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/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +27 -0
- package/dist/index.mjs +1 -1
- package/dist/{mcp-cNWW82NH.mjs → mcp-SsBK14Jm.mjs} +10 -5
- package/dist/mcp-SsBK14Jm.mjs.map +1 -0
- package/dist/plugins/attachments.d.mts +10 -0
- package/dist/plugins/attachments.d.mts.map +1 -1
- package/dist/plugins/attachments.mjs +4 -4
- package/dist/plugins/mcp.d.mts +10 -0
- package/dist/plugins/mcp.d.mts.map +1 -1
- package/dist/plugins/mcp.mjs +4 -4
- package/dist/plugins/privacy.d.mts +10 -0
- package/dist/plugins/privacy.d.mts.map +1 -1
- package/dist/plugins/privacy.mjs +4 -4
- package/dist/plugins/workflows.d.mts +46 -3
- package/dist/plugins/workflows.d.mts.map +1 -1
- package/dist/plugins/workflows.mjs +4 -4
- package/dist/{privacy-C8KVimKF.mjs → privacy-BsFl7GzK.mjs} +9 -4
- package/dist/{privacy-C8KVimKF.mjs.map → privacy-BsFl7GzK.mjs.map} +1 -1
- package/dist/{server-CF_mjyJi.mjs → server-Be1vmpxu.mjs} +54 -27
- package/dist/server-Be1vmpxu.mjs.map +1 -0
- package/dist/server.d.mts +18 -15
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/dist/{utils-uaBlzyjS.mjs → utils-Dh845exv.mjs} +42 -9
- package/dist/utils-Dh845exv.mjs.map +1 -0
- package/dist/utils.d.mts +8 -2
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +3 -3
- package/dist/{workflows-qKtqZhn3.mjs → workflows-fsBcElEi.mjs} +111 -67
- package/dist/{workflows-qKtqZhn3.mjs.map → workflows-fsBcElEi.mjs.map} +1 -1
- package/package.json +18 -17
- package/test/default-drive-slug.test.ts +97 -0
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/port-probe.test.ts +45 -0
- package/test/shutdown.test.ts +278 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/dist/mcp-cNWW82NH.mjs.map +0 -1
- package/dist/server-CF_mjyJi.mjs.map +0 -1
- package/dist/utils-uaBlzyjS.mjs.map +0 -1
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;cASa;KACD,2BAA2B;;;KCe3B;;EAEV;;EAEA;;EAEA,SAAS;;;;;;;;;;YCRC;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;YAGU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;EACA;EACA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;EAMA,oBAAoB;;;EAGpB;;;EAGA;IACE;;;EAGF,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;EACA,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;YAGnB;EACV;EACA,SAAS;;;;EAIT,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,QAAQ;;;;;EAKR
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;cASa;KACD,2BAA2B;;;KCe3B;;EAEV;;EAEA;;EAEA,SAAS;;;;;;;;;;YCRC;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;YAGU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;;;EAOA;EACA;EACA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;EAMA,oBAAoB;;;EAGpB;;;EAGA;IACE;;;EAGF,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;EACA,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;YAGnB;EACV;EACA,SAAS;;;;EAIT,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,QAAQ;;;;;EAKR;;;;;;;;EAQA,gBAAgB;;;;KC/NN;EAIV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCvEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC;IAAqB;IAAkB;;WACvC;EAET,YAAY,OAAO;SAcZ,QAAQ,iBAAiB,SAAS;;;;;;;;;wBCmMrB,gBAAgB,eAAe;;;;;;KAqFhD;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;wBAGM,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;;;;;;EAOA;EACA,QAAQ;IACN,QAAQ;iBA2DK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;EACA;IACE;;wBAgCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBA0oCvB,mBAAgB,UAClB,uBACR,QAAQ"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as startSwitchboard, i as resolvePgliteStorageDirs,
|
|
2
|
+
import { a as startSwitchboard, i as resolvePgliteStorageDirs, n as deriveAttachmentServiceConfig, o as StoredDocumentsRefusedError, r as isPortAvailable, s as resolveUnsupportedStoredDocuments, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-Be1vmpxu.mjs";
|
|
3
3
|
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, isPortAvailable, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
4
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
5
|
-
//# debugId=
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="534d7300-c326-56aa-9687-d11cdffdf0c0")}catch(e){}}();
|
|
5
|
+
//# debugId=534d7300-c326-56aa-9687-d11cdffdf0c0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="102fe578-0eb1-55eb-b9db-3f973785a8ea")}catch(e){}}();
|
|
3
3
|
import { reactorDriveCreateDocument, reactorDriveCreateState } from "@powerhousedao/reactor-drive";
|
|
4
4
|
import { driveCreateDocument, driveCreateState } from "@powerhousedao/shared/document-drive";
|
|
5
5
|
import { withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
@@ -11,7 +11,33 @@ import { withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
|
11
11
|
async function underCreatePolicy(client, document, id) {
|
|
12
12
|
return id ? withSignaturePolicy(document, "legacy", { id }) : withSignaturePolicy(document, await client.getCreateSignaturePolicy());
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
/** The document that already holds `slug`; null when two do (an id and a slug). */
|
|
15
|
+
async function slugHolder(client, slug) {
|
|
16
|
+
let id;
|
|
17
|
+
try {
|
|
18
|
+
id = await client.resolveIdOrSlug(slug);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return error instanceof Error && error.name === "DocumentNotFoundError" ? void 0 : null;
|
|
21
|
+
}
|
|
22
|
+
return client.get(id);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A default drive whose slug another document holds: a drive of the same type
|
|
26
|
+
* stands in for it (its URL); anything else keeps it uncreated (null), with an
|
|
27
|
+
* error logged so the server still starts. Undefined when the slug is free.
|
|
28
|
+
*/
|
|
29
|
+
async function slugTakenBy(client, drive, documentType, serverPort, logger) {
|
|
30
|
+
if (!drive.slug) return void 0;
|
|
31
|
+
const holder = await slugHolder(client, drive.slug);
|
|
32
|
+
if (holder === void 0) return void 0;
|
|
33
|
+
if (holder?.header.documentType === documentType) return `http://localhost:${serverPort}/d/${holder.header.id}`;
|
|
34
|
+
const owner = holder ? `${holder.header.documentType} document ${holder.header.id}` : "two documents";
|
|
35
|
+
logger.error(`The default drive "${drive.slug}" was not created: the slug belongs to ${owner}.`);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/** Creates a configured drive unless one with its id or slug exists; the
|
|
39
|
+
* URL it is served at, or undefined when another document holds the slug. */
|
|
40
|
+
async function addDefaultDrive(client, drive, serverPort, logger = console) {
|
|
15
41
|
let driveId = drive.id;
|
|
16
42
|
if (!driveId || driveId.length === 0) driveId = drive.slug;
|
|
17
43
|
if (!driveId || driveId.length === 0) throw new Error("Invalid Drive Id");
|
|
@@ -21,7 +47,7 @@ async function addDefaultDrive(client, drive, serverPort) {
|
|
|
21
47
|
} catch {}
|
|
22
48
|
if (existingDrive) return `http://localhost:${serverPort}/d/${driveId}`;
|
|
23
49
|
const { global } = driveCreateState();
|
|
24
|
-
const
|
|
50
|
+
const created = driveCreateDocument({
|
|
25
51
|
global: {
|
|
26
52
|
...global,
|
|
27
53
|
name: drive.global.name,
|
|
@@ -33,7 +59,10 @@ async function addDefaultDrive(client, drive, serverPort) {
|
|
|
33
59
|
listeners: drive.local?.listeners ?? [],
|
|
34
60
|
triggers: drive.local?.triggers ?? []
|
|
35
61
|
}
|
|
36
|
-
})
|
|
62
|
+
});
|
|
63
|
+
const taken = await slugTakenBy(client, drive, created.header.documentType, serverPort, logger);
|
|
64
|
+
if (taken !== void 0) return taken ?? void 0;
|
|
65
|
+
const document = await underCreatePolicy(client, created, drive.id);
|
|
37
66
|
if (drive.slug && drive.slug.length > 0) document.header.slug = drive.slug;
|
|
38
67
|
if (drive.global.name) document.header.name = drive.global.name;
|
|
39
68
|
if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
|
|
@@ -44,7 +73,8 @@ async function addDefaultDrive(client, drive, serverPort) {
|
|
|
44
73
|
}
|
|
45
74
|
return `http://localhost:${serverPort}/d/${driveId}`;
|
|
46
75
|
}
|
|
47
|
-
|
|
76
|
+
/** addDefaultDrive for a reactor drive. */
|
|
77
|
+
async function addDefaultReactorDrive(client, drive, serverPort, logger = console) {
|
|
48
78
|
let driveId = drive.id;
|
|
49
79
|
if (!driveId || driveId.length === 0) driveId = drive.slug;
|
|
50
80
|
if (!driveId || driveId.length === 0) throw new Error("Invalid Drive Id");
|
|
@@ -54,7 +84,7 @@ async function addDefaultReactorDrive(client, drive, serverPort) {
|
|
|
54
84
|
} catch {}
|
|
55
85
|
if (existingDrive) return `http://localhost:${serverPort}/d/${driveId}`;
|
|
56
86
|
const { global, local } = reactorDriveCreateState();
|
|
57
|
-
const
|
|
87
|
+
const created = reactorDriveCreateDocument({
|
|
58
88
|
global: {
|
|
59
89
|
...global,
|
|
60
90
|
name: drive.global.name,
|
|
@@ -65,7 +95,10 @@ async function addDefaultReactorDrive(client, drive, serverPort) {
|
|
|
65
95
|
availableOffline: drive.local?.availableOffline ?? local.availableOffline,
|
|
66
96
|
sharingType: drive.local?.sharingType ?? local.sharingType
|
|
67
97
|
}
|
|
68
|
-
})
|
|
98
|
+
});
|
|
99
|
+
const taken = await slugTakenBy(client, drive, created.header.documentType, serverPort, logger);
|
|
100
|
+
if (taken !== void 0) return taken ?? void 0;
|
|
101
|
+
const document = await underCreatePolicy(client, created, drive.id);
|
|
69
102
|
if (drive.slug && drive.slug.length > 0) document.header.slug = drive.slug;
|
|
70
103
|
if (drive.global.name) document.header.name = drive.global.name;
|
|
71
104
|
if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
|
|
@@ -82,5 +115,5 @@ function isPostgresUrl(url) {
|
|
|
82
115
|
//#endregion
|
|
83
116
|
export { addDefaultReactorDrive as n, isPostgresUrl as r, addDefaultDrive as t };
|
|
84
117
|
|
|
85
|
-
//# sourceMappingURL=utils-
|
|
86
|
-
//# debugId=
|
|
118
|
+
//# sourceMappingURL=utils-Dh845exv.mjs.map
|
|
119
|
+
//# debugId=102fe578-0eb1-55eb-b9db-3f973785a8ea
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-Dh845exv.mjs","sources":["../src/utils.mts"],"sourcesContent":["import type { IReactorClient } from \"@powerhousedao/reactor\";\nimport {\n reactorDriveCreateDocument,\n reactorDriveCreateState,\n} from \"@powerhousedao/reactor-drive\";\nimport {\n driveCreateDocument,\n driveCreateState,\n} from \"@powerhousedao/shared/document-drive\";\nimport type { DriveInput } from \"@powerhousedao/shared/document-drive\";\nimport {\n withSignaturePolicy,\n type PHDocument,\n} from \"@powerhousedao/shared/document-model\";\n\n/**\n * A configured id pins the drive, and only a legacy drive can take a chosen\n * id; otherwise the client's creation default applies.\n */\nasync function underCreatePolicy<TDocument extends PHDocument>(\n client: IReactorClient,\n document: TDocument,\n id: string | undefined,\n): Promise<TDocument> {\n return id\n ? withSignaturePolicy(document, \"legacy\", { id })\n : withSignaturePolicy(document, await client.getCreateSignaturePolicy());\n}\n\ntype DefaultDriveLogger = { error: (message: string) => void };\n\n/** The document that already holds `slug`; null when two do (an id and a slug). */\nasync function slugHolder(\n client: IReactorClient,\n slug: string,\n): Promise<PHDocument | null | undefined> {\n let id: string;\n try {\n id = await client.resolveIdOrSlug(slug);\n } catch (error) {\n const notFound =\n error instanceof Error && error.name === \"DocumentNotFoundError\";\n return notFound ? undefined : null;\n }\n return client.get(id);\n}\n\n/**\n * A default drive whose slug another document holds: a drive of the same type\n * stands in for it (its URL); anything else keeps it uncreated (null), with an\n * error logged so the server still starts. Undefined when the slug is free.\n */\nasync function slugTakenBy(\n client: IReactorClient,\n drive: DriveInput,\n documentType: string,\n serverPort: number,\n logger: DefaultDriveLogger,\n): Promise<string | null | undefined> {\n if (!drive.slug) return undefined;\n const holder = await slugHolder(client, drive.slug);\n if (holder === undefined) return undefined;\n if (holder?.header.documentType === documentType) {\n return `http://localhost:${serverPort}/d/${holder.header.id}`;\n }\n const owner = holder\n ? `${holder.header.documentType} document ${holder.header.id}`\n : \"two documents\";\n logger.error(\n `The default drive \"${drive.slug}\" was not created: the slug belongs to ${owner}.`,\n );\n return null;\n}\n\n/** Creates a configured drive unless one with its id or slug exists; the\n * URL it is served at, or undefined when another document holds the slug. */\nexport async function addDefaultDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n let driveId = drive.id;\n if (!driveId || driveId.length === 0) {\n driveId = drive.slug;\n }\n\n if (!driveId || driveId.length === 0) {\n throw new Error(\"Invalid Drive Id\");\n }\n\n // check if the drive already exists\n let existingDrive;\n try {\n existingDrive = await client.get(driveId);\n } catch {\n //\n }\n\n // already exists, return the existing drive url\n if (existingDrive) {\n return `http://localhost:${serverPort}/d/${driveId}`;\n }\n\n const { global } = driveCreateState();\n const created = driveCreateDocument({\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n availableOffline: drive.local?.availableOffline ?? false,\n sharingType: drive.local?.sharingType ?? \"public\",\n listeners: drive.local?.listeners ?? [],\n triggers: drive.local?.triggers ?? [],\n },\n });\n\n const taken = await slugTakenBy(\n client,\n drive,\n created.header.documentType,\n serverPort,\n logger,\n );\n if (taken !== undefined) return taken ?? undefined;\n\n const document = await underCreatePolicy(client, created, drive.id);\n if (drive.slug && drive.slug.length > 0) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await client.create(document);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n }\n\n return `http://localhost:${serverPort}/d/${driveId}`;\n}\n\n/** addDefaultDrive for a reactor drive. */\nexport async function addDefaultReactorDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n let driveId = drive.id;\n if (!driveId || driveId.length === 0) {\n driveId = drive.slug;\n }\n\n if (!driveId || driveId.length === 0) {\n throw new Error(\"Invalid Drive Id\");\n }\n\n let existingDrive;\n try {\n existingDrive = await client.get(driveId);\n } catch {\n //\n }\n\n if (existingDrive) {\n return `http://localhost:${serverPort}/d/${driveId}`;\n }\n\n const { global, local } = reactorDriveCreateState();\n const created = reactorDriveCreateDocument({\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n ...local,\n availableOffline: drive.local?.availableOffline ?? local.availableOffline,\n sharingType: drive.local?.sharingType ?? local.sharingType,\n },\n });\n\n const taken = await slugTakenBy(\n client,\n drive,\n created.header.documentType,\n serverPort,\n logger,\n );\n if (taken !== undefined) return taken ?? undefined;\n\n const document = await underCreatePolicy(client, created, drive.id);\n if (drive.slug && drive.slug.length > 0) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await client.create(document);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n }\n\n return `http://localhost:${serverPort}/d/${driveId}`;\n}\n\nexport function isPostgresUrl(url: string) {\n return url.startsWith(\"postgresql\") || url.startsWith(\"postgres\");\n}\n"],"names":[],"mappings":";;;;;;;;;;AAmBA,eAAe,kBACb,QACA,UACA,IACoB;CACpB,OAAO,KACH,oBAAoB,UAAU,UAAU,EAAE,GAAG,CAAC,IAC9C,oBAAoB,UAAU,MAAM,OAAO,yBAAyB,CAAC;AAC3E;;AAKA,eAAe,WACb,QACA,MACwC;CACxC,IAAI;CACJ,IAAI;EACF,KAAK,MAAM,OAAO,gBAAgB,IAAI;CACxC,SAAS,OAAO;EAGd,OADE,iBAAiB,SAAS,MAAM,SAAS,0BACzB,KAAA,IAAY;CAChC;CACA,OAAO,OAAO,IAAI,EAAE;AACtB;;;;;;AAOA,eAAe,YACb,QACA,OACA,cACA,YACA,QACoC;CACpC,IAAI,CAAC,MAAM,MAAM,OAAO,KAAA;CACxB,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM,IAAI;CAClD,IAAI,WAAW,KAAA,GAAW,OAAO,KAAA;CACjC,IAAI,QAAQ,OAAO,iBAAiB,cAClC,OAAO,oBAAoB,WAAW,KAAK,OAAO,OAAO;CAE3D,MAAM,QAAQ,SACV,GAAG,OAAO,OAAO,aAAa,YAAY,OAAO,OAAO,OACxD;CACJ,OAAO,MACL,sBAAsB,MAAM,KAAK,yCAAyC,MAAM,EAClF;CACA,OAAO;AACT;;;AAIA,eAAsB,gBACpB,QACA,OACA,YACA,SAA6B,SACA;CAC7B,IAAI,UAAU,MAAM;CACpB,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,UAAU,MAAM;CAGlB,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,MAAM,IAAI,MAAM,kBAAkB;CAIpC,IAAI;CACJ,IAAI;EACF,gBAAgB,MAAM,OAAO,IAAI,OAAO;CAC1C,QAAQ,CAER;CAGA,IAAI,eACF,OAAO,oBAAoB,WAAW,KAAK;CAG7C,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,UAAU,oBAAoB;EAClC,QAAQ;GACN,GAAG;GACH,MAAM,MAAM,OAAO;GACnB,MAAM,MAAM,OAAO,QAAQ,OAAO;EACpC;EACA,OAAO;GACL,kBAAkB,MAAM,OAAO,oBAAoB;GACnD,aAAa,MAAM,OAAO,eAAe;GACzC,WAAW,MAAM,OAAO,aAAa,CAAC;GACtC,UAAU,MAAM,OAAO,YAAY,CAAC;EACtC;CACF,CAAC;CAED,MAAM,QAAQ,MAAM,YAClB,QACA,OACA,QAAQ,OAAO,cACf,YACA,MACF;CACA,IAAI,UAAU,KAAA,GAAW,OAAO,SAAS,KAAA;CAEzC,MAAM,WAAW,MAAM,kBAAkB,QAAQ,SAAS,MAAM,EAAE;CAClE,IAAI,MAAM,QAAQ,MAAM,KAAK,SAAS,GACpC,SAAS,OAAO,OAAO,MAAM;CAE/B,IAAI,MAAM,OAAO,MACf,SAAS,OAAO,OAAO,MAAM,OAAO;CAEtC,IAAI,MAAM,iBACR,SAAS,OAAO,OAAO,EAAE,iBAAiB,MAAM,gBAAgB;CAGlE,IAAI;EACF,MAAM,OAAO,OAAO,QAAQ;CAC9B,SAAS,GAAG;EAEV,IAAI,EADiB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAA,CAC5C,SAAS,gBAAgB,GACzC,MAAM;CAEV;CAEA,OAAO,oBAAoB,WAAW,KAAK;AAC7C;;AAGA,eAAsB,uBACpB,QACA,OACA,YACA,SAA6B,SACA;CAC7B,IAAI,UAAU,MAAM;CACpB,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,UAAU,MAAM;CAGlB,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,MAAM,IAAI,MAAM,kBAAkB;CAGpC,IAAI;CACJ,IAAI;EACF,gBAAgB,MAAM,OAAO,IAAI,OAAO;CAC1C,QAAQ,CAER;CAEA,IAAI,eACF,OAAO,oBAAoB,WAAW,KAAK;CAG7C,MAAM,EAAE,QAAQ,UAAU,wBAAwB;CAClD,MAAM,UAAU,2BAA2B;EACzC,QAAQ;GACN,GAAG;GACH,MAAM,MAAM,OAAO;GACnB,MAAM,MAAM,OAAO,QAAQ,OAAO;EACpC;EACA,OAAO;GACL,GAAG;GACH,kBAAkB,MAAM,OAAO,oBAAoB,MAAM;GACzD,aAAa,MAAM,OAAO,eAAe,MAAM;EACjD;CACF,CAAC;CAED,MAAM,QAAQ,MAAM,YAClB,QACA,OACA,QAAQ,OAAO,cACf,YACA,MACF;CACA,IAAI,UAAU,KAAA,GAAW,OAAO,SAAS,KAAA;CAEzC,MAAM,WAAW,MAAM,kBAAkB,QAAQ,SAAS,MAAM,EAAE;CAClE,IAAI,MAAM,QAAQ,MAAM,KAAK,SAAS,GACpC,SAAS,OAAO,OAAO,MAAM;CAE/B,IAAI,MAAM,OAAO,MACf,SAAS,OAAO,OAAO,MAAM,OAAO;CAEtC,IAAI,MAAM,iBACR,SAAS,OAAO,OAAO,EAAE,iBAAiB,MAAM,gBAAgB;CAGlE,IAAI;EACF,MAAM,OAAO,OAAO,QAAQ;CAC9B,SAAS,GAAG;EAEV,IAAI,EADiB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAA,CAC5C,SAAS,gBAAgB,GACzC,MAAM;CAEV;CAEA,OAAO,oBAAoB,WAAW,KAAK;AAC7C;AAEA,SAAgB,cAAc,KAAa;CACzC,OAAO,IAAI,WAAW,YAAY,KAAK,IAAI,WAAW,UAAU;AAClE","debug_id":"102fe578-0eb1-55eb-b9db-3f973785a8ea"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { IReactorClient } from "@powerhousedao/reactor";
|
|
2
2
|
import { DriveInput } from "@powerhousedao/shared/document-drive";
|
|
3
3
|
//#region src/utils.d.mts
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type DefaultDriveLogger = {
|
|
5
|
+
error: (message: string) => void;
|
|
6
|
+
};
|
|
7
|
+
/** Creates a configured drive unless one with its id or slug exists; the
|
|
8
|
+
* URL it is served at, or undefined when another document holds the slug. */
|
|
9
|
+
export declare function addDefaultDrive(client: IReactorClient, drive: DriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
|
|
10
|
+
/** addDefaultDrive for a reactor drive. */
|
|
11
|
+
export declare function addDefaultReactorDrive(client: IReactorClient, drive: DriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
|
|
6
12
|
export declare function isPostgresUrl(url: string): boolean;
|
|
7
13
|
//#endregion
|
|
8
14
|
export {};
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.mts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.mts"],"mappings":";;;KA6BK;EAAuB,QAAQ;;;;wBA+Cd,gBACpB,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP;;wBAuEmB,uBACpB,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP;wBAmEa,cAAc"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as addDefaultReactorDrive, r as isPostgresUrl, t as addDefaultDrive } from "./utils-
|
|
1
|
+
import { n as addDefaultReactorDrive, r as isPostgresUrl, t as addDefaultDrive } from "./utils-Dh845exv.mjs";
|
|
2
2
|
export { addDefaultDrive, addDefaultReactorDrive, isPostgresUrl };
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
4
|
-
//# debugId=
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2d19697b-ad80-5612-b400-332850c7a2e3")}catch(e){}}();
|
|
4
|
+
//# debugId=2d19697b-ad80-5612-b400-332850c7a2e3
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="643936e6-57f0-5d17-b85e-b80a8d07783c")}catch(e){}}();
|
|
3
3
|
import { REACTOR_SCHEMA, supportsLiveReadModelRegistration } from "@powerhousedao/reactor";
|
|
4
4
|
import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, callerSubject, createCanonicalDocumentIdResolver } from "@powerhousedao/reactor-api";
|
|
5
5
|
import { parseRef } from "@powerhousedao/reactor-attachments";
|
|
6
|
+
import { z } from "zod";
|
|
6
7
|
import { GraphQLError, Kind } from "graphql";
|
|
7
8
|
import { gql } from "graphql-tag";
|
|
8
9
|
//#region src/fatal-shutdown.mts
|
|
@@ -1264,75 +1265,118 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1264
1265
|
}
|
|
1265
1266
|
//#endregion
|
|
1266
1267
|
//#region src/plugins/workflows.mts
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1268
|
+
/** The drive app Workflow Studio registers under (packages/workflow). */
|
|
1269
|
+
const WORKFLOW_STUDIO_EDITOR_ID = "workflow-studio";
|
|
1270
|
+
/** The drive the plugin seeds unless the entry says otherwise. */
|
|
1271
|
+
const DEFAULT_WORKFLOWS_DRIVE = {
|
|
1272
|
+
slug: "workflows",
|
|
1273
|
+
name: "Workflows"
|
|
1274
|
+
};
|
|
1275
|
+
const workflowsDriveSchema = z.strictObject({
|
|
1276
|
+
/** The seeding key and the served `/d/<slug>` path (default "workflows"). */
|
|
1277
|
+
slug: z.string().min(1).optional(),
|
|
1278
|
+
/** Display name (default "Workflows"). */
|
|
1279
|
+
name: z.string().min(1).optional(),
|
|
1280
|
+
/** Fixed id; without one the id is project-hashed like classic `ph vetra`
|
|
1281
|
+
* (`workflows-<sha256(projectPath)[0:8]>`, slug unchanged), so existing
|
|
1282
|
+
* stores keep theirs. `projectHash: true` hashes the served slug as well. */
|
|
1283
|
+
id: z.string().min(1).optional(),
|
|
1284
|
+
projectHash: z.union([z.boolean(), z.literal("id")]).optional(),
|
|
1285
|
+
icon: z.string().optional()
|
|
1286
|
+
});
|
|
1287
|
+
const workflowsPluginConfigSchema = z.strictObject({
|
|
1288
|
+
/** The Workflows drive to seed; `false` runs the runtime without one. */
|
|
1289
|
+
drive: z.union([workflowsDriveSchema, z.literal(false)]).optional() });
|
|
1290
|
+
/** The drive declaration the entry config amounts to (host-core's
|
|
1291
|
+
* DriveDeclaration shape; kept structural here to avoid the import cycle the
|
|
1292
|
+
* Contributions type documents). `undefined` when `drive: false`. */
|
|
1293
|
+
function workflowsDriveDeclaration(config) {
|
|
1294
|
+
if (config.drive === false) return void 0;
|
|
1295
|
+
const drive = config.drive ?? {};
|
|
1296
|
+
return {
|
|
1297
|
+
slug: drive.slug ?? DEFAULT_WORKFLOWS_DRIVE.slug,
|
|
1298
|
+
name: drive.name ?? DEFAULT_WORKFLOWS_DRIVE.name,
|
|
1299
|
+
preferredEditor: WORKFLOW_STUDIO_EDITOR_ID,
|
|
1300
|
+
...drive.id !== void 0 ? { id: drive.id } : { projectHash: drive.projectHash ?? "id" },
|
|
1301
|
+
...drive.icon !== void 0 ? { icon: drive.icon } : {}
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
function createWorkflowsPlugin(rawConfig = {}) {
|
|
1305
|
+
const drive = workflowsDriveDeclaration(workflowsPluginConfigSchema.parse(rawConfig ?? {}));
|
|
1306
|
+
return {
|
|
1307
|
+
name: "switchboard-workflows",
|
|
1308
|
+
appliesTo: "switchboard",
|
|
1309
|
+
configSchema: workflowsPluginConfigSchema,
|
|
1310
|
+
contributions: { drives: drive ? [drive] : [] },
|
|
1311
|
+
hooks: {
|
|
1312
|
+
transformServerOptions: (options) => {
|
|
1313
|
+
const current = options.workflows;
|
|
1314
|
+
if (current?.enabled === false) return options;
|
|
1315
|
+
return {
|
|
1316
|
+
...options,
|
|
1317
|
+
workflows: {
|
|
1318
|
+
...current,
|
|
1319
|
+
enabled: true
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
},
|
|
1323
|
+
onSubgraphsRegistering: async (ctx) => {
|
|
1324
|
+
const orchestration = ctx.workflowsOrchestration;
|
|
1325
|
+
if (!orchestration?.enabled) return;
|
|
1326
|
+
const logger = ctx.logger;
|
|
1327
|
+
const lateSubgraphs = ctx.lateSubgraphs;
|
|
1328
|
+
let workflows;
|
|
1329
|
+
let workflowsRetry;
|
|
1330
|
+
try {
|
|
1331
|
+
workflows = await orchestration.composeWorkflows();
|
|
1332
|
+
} catch (error) {
|
|
1333
|
+
if (!isWorkflowSingletonConflict(error)) throw error;
|
|
1334
|
+
logger.warn(`Workflows are enabled but another live process ("${error.owner ?? "unknown"}") holds the workflow singleton until ${error.expiresAt ?? "unknown"}. This Switchboard has booted WITHOUT the workflow runtime: no trigger of any kind fires here, and the workflow GraphQL face is absent. Everything else serves normally. Stop the other owner, or set PH_WORKFLOWS_SINGLETON_OWNER to the same stable name on the slot that owns workflows. This Switchboard retries the claim and starts workflows once the lease comes free.`);
|
|
1335
|
+
workflowsRetry = retryWorkflowSingleton({
|
|
1336
|
+
compose: orchestration.composeWorkflows,
|
|
1337
|
+
onComposed: async (composed) => {
|
|
1300
1338
|
try {
|
|
1301
|
-
await composed.
|
|
1302
|
-
} catch (
|
|
1303
|
-
|
|
1339
|
+
await composed.start();
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
try {
|
|
1342
|
+
await composed.stop();
|
|
1343
|
+
} catch (stopError) {
|
|
1344
|
+
logger.error("Stopping the late workflow runtime failed: @error", stopError);
|
|
1345
|
+
}
|
|
1346
|
+
throw error;
|
|
1304
1347
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1348
|
+
logger.info("Workflow runtime started");
|
|
1349
|
+
ctx.workflows = composed;
|
|
1350
|
+
await orchestration.registerWorkflowSubgraph(composed);
|
|
1351
|
+
try {
|
|
1352
|
+
await orchestration.updateRouter();
|
|
1353
|
+
} catch (error) {
|
|
1354
|
+
orchestration.reportMountFailure(error);
|
|
1355
|
+
}
|
|
1356
|
+
},
|
|
1357
|
+
logger
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
ctx.workflowsRetry = workflowsRetry;
|
|
1361
|
+
if (workflows) {
|
|
1362
|
+
ctx.workflows = workflows;
|
|
1363
|
+
lateSubgraphs.push(orchestration.registerWorkflowSubgraph(workflows));
|
|
1364
|
+
await workflows.start();
|
|
1365
|
+
logger.info("Workflow runtime started");
|
|
1366
|
+
orchestration.setWorkflowsFact();
|
|
1367
|
+
}
|
|
1368
|
+
},
|
|
1369
|
+
onShutdown: async (ctx) => {
|
|
1370
|
+
await ctx.workflowsRetry?.stop();
|
|
1371
|
+
await ctx.workflows?.stop();
|
|
1326
1372
|
}
|
|
1327
|
-
},
|
|
1328
|
-
onShutdown: async (ctx) => {
|
|
1329
|
-
await ctx.workflowsRetry?.stop();
|
|
1330
|
-
await ctx.workflows?.stop();
|
|
1331
1373
|
}
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
/** The default-config instance: the built-in composition's entry. */
|
|
1377
|
+
const workflowsPlugin = createWorkflowsPlugin({});
|
|
1334
1378
|
//#endregion
|
|
1335
|
-
export {
|
|
1379
|
+
export { triggerFatalShutdown as _, workflowsPlugin as a, WORKFLOW_TELEMETRY_SCOPE as c, isWorkflowSingletonConflict as d, modelManifestSource as f, installFatalErrorShutdown as g, workflowSingletonLossHandler as h, workflowsDriveDeclaration as i, assertWorkflowPackageLoadable as l, retryWorkflowSingleton as m, WORKFLOW_STUDIO_EDITOR_ID as n, workflowsPluginConfigSchema as o, resolveWorkflowsEnabled as p, createWorkflowsPlugin as r, WORKFLOW_PACKAGE_NAME as s, DEFAULT_WORKFLOWS_DRIVE as t, composeWorkflowRuntime as u };
|
|
1336
1380
|
|
|
1337
|
-
//# sourceMappingURL=workflows-
|
|
1338
|
-
//# debugId=
|
|
1381
|
+
//# sourceMappingURL=workflows-fsBcElEi.mjs.map
|
|
1382
|
+
//# debugId=643936e6-57f0-5d17-b85e-b80a8d07783c
|