@powerhousedao/switchboard 6.2.3-dev.7 → 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.
Files changed (195) hide show
  1. package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
  2. package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
  3. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
  4. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
  5. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
  6. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
  7. package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
  8. package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
  9. package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
  10. package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
  11. package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
  12. package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
  13. package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
  14. package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
  15. package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
  16. package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
  17. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
  18. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
  19. package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
  20. package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
  21. package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
  22. package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
  23. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
  24. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
  25. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
  26. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
  27. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
  28. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
  29. package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
  30. package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
  31. package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
  32. package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
  33. package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
  34. package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
  35. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
  36. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
  37. package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
  38. package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
  39. package/.tsbuild/test/inspection-flag.test.d.ts +2 -0
  40. package/.tsbuild/test/inspection-flag.test.d.ts.map +1 -0
  41. package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
  42. package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
  43. package/.tsbuild/test/mcp-flag.test.d.ts +2 -0
  44. package/.tsbuild/test/mcp-flag.test.d.ts.map +1 -0
  45. package/.tsbuild/test/observability-signals.test.d.ts +2 -0
  46. package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
  47. package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
  48. package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
  49. package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
  50. package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
  51. package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
  52. package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
  53. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  54. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  55. package/.tsbuild/test/port-probe.test.d.ts +2 -0
  56. package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
  57. package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
  58. package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
  59. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  60. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  61. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  62. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  63. package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
  64. package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
  65. package/.tsbuild/test/workflow/harness.d.ts +56 -0
  66. package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
  67. package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
  68. package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
  69. package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
  70. package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
  71. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
  72. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
  73. package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
  74. package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
  75. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
  76. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
  77. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
  78. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
  79. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  80. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  81. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  82. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  83. package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
  84. package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
  85. package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
  86. package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
  87. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  88. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  89. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  90. package/.tsbuild/tsdown.config.d.ts.map +1 -1
  91. package/.tsbuild/vitest.config.d.ts.map +1 -1
  92. package/Auth.md +144 -2
  93. package/CHANGELOG.md +869 -0
  94. package/README.md +47 -10
  95. package/dist/index.d.mts +2 -1
  96. package/dist/index.mjs +50 -50
  97. package/dist/index.mjs.map +1 -1
  98. package/dist/install-packages.d.mts +2 -1
  99. package/dist/install-packages.mjs +2 -2
  100. package/dist/install-packages.mjs.map +1 -1
  101. package/dist/mcp-SsBK14Jm.mjs +32 -0
  102. package/dist/mcp-SsBK14Jm.mjs.map +1 -0
  103. package/dist/migrate.d.mts +2 -1
  104. package/dist/migrate.mjs +4 -3
  105. package/dist/migrate.mjs.map +1 -1
  106. package/dist/plugin-host-CGO4XZzK.d.mts +38 -0
  107. package/dist/plugin-host-CGO4XZzK.d.mts.map +1 -0
  108. package/dist/plugins/attachments.d.mts +33 -0
  109. package/dist/plugins/attachments.d.mts.map +1 -0
  110. package/dist/plugins/attachments.mjs +4 -0
  111. package/dist/plugins/mcp.d.mts +31 -0
  112. package/dist/plugins/mcp.d.mts.map +1 -0
  113. package/dist/plugins/mcp.mjs +4 -0
  114. package/dist/plugins/privacy.d.mts +22 -0
  115. package/dist/plugins/privacy.d.mts.map +1 -0
  116. package/dist/plugins/privacy.mjs +4 -0
  117. package/dist/plugins/workflows.d.mts +79 -0
  118. package/dist/plugins/workflows.d.mts.map +1 -0
  119. package/dist/plugins/workflows.mjs +4 -0
  120. package/dist/privacy-BsFl7GzK.mjs +118 -0
  121. package/dist/privacy-BsFl7GzK.mjs.map +1 -0
  122. package/dist/{server-CiKkVE6g.mjs → server-Be1vmpxu.mjs} +1213 -244
  123. package/dist/server-Be1vmpxu.mjs.map +1 -0
  124. package/dist/server.d.mts +208 -45
  125. package/dist/server.d.mts.map +1 -1
  126. package/dist/server.mjs +4 -5
  127. package/dist/{utils-Baw7rThP.mjs → utils-Dh845exv.mjs} +48 -9
  128. package/dist/utils-Dh845exv.mjs.map +1 -0
  129. package/dist/utils.d.mts +10 -5
  130. package/dist/utils.d.mts.map +1 -1
  131. package/dist/utils.mjs +3 -3
  132. package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
  133. package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
  134. package/dist/workflows-fsBcElEi.mjs +1382 -0
  135. package/dist/workflows-fsBcElEi.mjs.map +1 -0
  136. package/package.json +50 -20
  137. package/scripts/install-packages.sh +0 -0
  138. package/test/attachment-reference-read-model.test.ts +6 -1
  139. package/test/attachments/auth.test.ts +85 -0
  140. package/test/attachments/byte-grants.test.ts +290 -0
  141. package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
  142. package/test/attachments/download-target.test.ts +201 -32
  143. package/test/attachments/index.test.ts +47 -4
  144. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  145. package/test/attachments/routes-integration.test.ts +60 -4
  146. package/test/attachments/routes.test.ts +271 -24
  147. package/test/attachments/service-config.test.ts +13 -3
  148. package/test/attachments/url-signer.test.ts +105 -0
  149. package/test/boot-create-signature-policy.test.ts +108 -0
  150. package/test/boot-inspection-enabled.test.ts +150 -0
  151. package/test/boot-mcp-enabled.test.ts +130 -0
  152. package/test/boot-privacy.test.ts +243 -0
  153. package/test/boot-unsupported-stored-documents.test.ts +213 -0
  154. package/test/boot-without-renown.test.ts +81 -0
  155. package/test/boot-without-require-signatures.test.ts +74 -0
  156. package/test/boot-worker-trust-policy.test.ts +90 -0
  157. package/test/boot-workflow-singleton-conflict.test.ts +107 -0
  158. package/test/boot-workflow-singleton-retry.test.ts +133 -0
  159. package/test/builder-defaults.test.ts +80 -0
  160. package/test/create-signature-policy.test.ts +69 -0
  161. package/test/default-drive-slug.test.ts +97 -0
  162. package/test/durable-node-fs-pg16.test.ts +80 -0
  163. package/test/fatal-shutdown.test.ts +165 -0
  164. package/test/inspection-flag.test.ts +62 -0
  165. package/test/inspection-throttle.test.ts +23 -0
  166. package/test/mcp-flag.test.ts +56 -0
  167. package/test/observability-signals.test.ts +131 -0
  168. package/test/pglite-dialect.test.ts +217 -2
  169. package/test/pglite-preflight.test.ts +313 -0
  170. package/test/pglite-storage-dirs.test.ts +103 -0
  171. package/test/pglite-version.test.ts +9 -1
  172. package/test/plugin-config-schemas.test.ts +83 -0
  173. package/test/plugin-presence.test.ts +269 -0
  174. package/test/port-probe.test.ts +45 -0
  175. package/test/renown-trust-policy.test.ts +315 -0
  176. package/test/shutdown.test.ts +278 -0
  177. package/test/snapshot-writer.ts +94 -0
  178. package/test/unsupported-stored-documents.test.ts +72 -0
  179. package/test/worker-pool.test.ts +27 -1
  180. package/test/workflow/harness.ts +289 -0
  181. package/test/workflow/oauth.test.ts +214 -0
  182. package/test/workflow/resolvers.test.ts +357 -0
  183. package/test/workflow/webhook-dedupe.test.ts +295 -0
  184. package/test/workflow/webhook-signed.test.ts +509 -0
  185. package/test/workflow/webhook-trigger-test.test.ts +82 -0
  186. package/test/workflow/webhook-unsigned.test.ts +345 -0
  187. package/test/workflow-reactor-access.test.ts +384 -0
  188. package/test/workflow-reactor-enforcement.test.ts +808 -0
  189. package/test/workflow-read-gate.test.ts +213 -0
  190. package/test/workflow-runtime.test.ts +1122 -0
  191. package/test/workflows-plugin-config.test.ts +77 -0
  192. package/tsconfig.json +11 -2
  193. package/tsdown.config.ts +9 -1
  194. package/dist/server-CiKkVE6g.mjs.map +0 -1
  195. package/dist/utils-Baw7rThP.mjs.map +0 -1
package/dist/server.d.mts CHANGED
@@ -1,12 +1,31 @@
1
+ import { n as WorkflowTriggersCapability } from "./workflow-runtime-7GaJ13c9.mjs";
1
2
  import { ILogger } from "document-model";
2
- import { ChannelScheme, IDocumentModelLoader, IReactorClient, InProcessReactorClientModule, JwtHandler, ReactorBuilder, ReactorClientBuilder, ReactorFeatureFlags, SignerConfig } from "@powerhousedao/reactor";
3
+ import "@powerhousedao/reactor-api/pglite-node";
4
+ import { ChannelScheme, Database, IDocumentModelLoader, IReactorClient, InProcessReactorClientModule, JwtHandler, ModelManifestEntry, PoolInstrumentation, ReactorBuilder, ReactorClientBuilder, ReactorFeatureFlags, ReactorStorageFacts, SignerConfig, UnsupportedStoredDocuments, UnsupportedStoredProtocolError } from "@powerhousedao/reactor";
3
5
  import { AttachmentReferenceProjectionCapability } from "@powerhousedao/reactor-api";
4
6
  import { IAttachmentService } from "@powerhousedao/reactor-attachments";
5
7
  import { IRenown } from "@renown/sdk/node";
8
+ import { Kysely } from "kysely";
9
+ import { IErasureService } from "@powerhousedao/reactor-privacy";
10
+ import { ResolvedPlugin } from "@powerhousedao/host-core";
6
11
  import { DriveInput } from "@powerhousedao/shared/document-drive";
12
+ import { DocumentModelModule, ISigner, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
13
+ import "@electric-sql/pglite";
7
14
  import { IRenown as IRenown$1 } from "@renown/sdk";
8
- import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/document-model";
9
-
15
+ //#region src/pglite-version.d.ts
16
+ declare const SUPPORTED_PG_MAJORS: readonly [16, 17];
17
+ type SupportedPgMajor = (typeof SUPPORTED_PG_MAJORS)[number];
18
+ //#endregion
19
+ //#region src/privacy.d.mts
20
+ type PrivacyOptions = {
21
+ /** Wins over PH_PRIVACY_ENABLED. */
22
+ enabled?: boolean;
23
+ /** Wins over PH_PRIVACY_DEPLOYMENT_SECRET. */
24
+ deploymentSecret?: string;
25
+ /** The reactor's signer, for a caller-provided reactor. */
26
+ signer?: ISigner;
27
+ };
28
+ //#endregion
10
29
  //#region src/types.d.ts
11
30
  /**
12
31
  * Drive container document type chosen for the boot-time default drive. The
@@ -14,27 +33,28 @@ import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/docu
14
33
  * `powerhouse/reactor-drive` is wired through `addDefaultReactorDrive` and
15
34
  * uses the relationship-based child graph.
16
35
  */
17
- type SwitchboardDriveDocumentType = "powerhouse/document-drive" | "powerhouse/reactor-drive";
36
+ export type SwitchboardDriveDocumentType = "powerhouse/document-drive" | "powerhouse/reactor-drive";
18
37
  /** A {@link DriveInput} extended with the optional drive-container type. */
19
- type SwitchboardDriveInput = DriveInput & {
38
+ export type SwitchboardDriveInput = DriveInput & {
20
39
  documentType?: SwitchboardDriveDocumentType;
21
40
  };
22
- type StorageOptions = {
41
+ export type StorageOptions = {
23
42
  type: "filesystem" | "memory" | "postgres" | "browser";
24
43
  filesystemPath?: string;
25
44
  postgresUrl?: string;
26
45
  };
27
- type IdentityOptions = {
28
- /** Path to the keypair file. Defaults to ~/.ph/keypair.json */keypairPath?: string;
46
+ export type IdentityOptions = {
47
+ /** Path to the keypair file. Defaults to ~/.ph/keypair.json */
48
+ keypairPath?: string;
29
49
  /**
30
50
  * If true, won't start without an existing keypair.
31
51
  * Use this to ensure the switchboard only runs with an authenticated identity.
32
52
  */
33
- requireExisting?: boolean; /** Base url of the Renown instance to use */
34
- baseUrl?: string; /** If true, unsigned actions will be rejected */
35
- requireSignatures?: boolean;
53
+ requireExisting?: boolean;
54
+ /** Base url of the Renown instance to use */
55
+ baseUrl?: string;
36
56
  };
37
- type StartServerOptions = {
57
+ export type StartServerOptions = {
38
58
  /**
39
59
  * Pre-built ReactorClientModule (typically from
40
60
  * `@powerhousedao/reactor#ReactorClientBuilder.buildModule`). When set, the
@@ -56,6 +76,21 @@ type StartServerOptions = {
56
76
  * pieces as needed.
57
77
  */
58
78
  reactor?: InProcessReactorClientModule;
79
+ /**
80
+ * Route uncaught exceptions, and unhandled rejections nothing else listens
81
+ * for, through the reactor's SIGTERM shutdown, so PGlite stores are flushed
82
+ * before the process exits with code 1. Installed once the switchboard's own reactor is built;
83
+ * ignored when `reactor` is passed. For process entry points only, since
84
+ * it adds process-wide listeners.
85
+ */
86
+ fatalErrorShutdown?: boolean;
87
+ /**
88
+ * Install the owned reactor's SIGINT/SIGTERM handlers (default true).
89
+ * False when a supervisor owns the process exit (a `ph run` compound
90
+ * member): the reactor then stops only through `shutdown()`. Ignored with
91
+ * a caller-provided `reactor`.
92
+ */
93
+ signalHandlers?: boolean;
59
94
  /**
60
95
  * Registry URL for the HttpPackageLoader. Enables `PackagesSubgraph`
61
96
  * (install/uninstall mutations) plus dynamic package resolution.
@@ -85,9 +120,28 @@ type StartServerOptions = {
85
120
  * When configured, the switchboard will load the keypair from `ph login`
86
121
  * and can authenticate with remote services on behalf of the user.
87
122
  */
88
- identity?: IdentityOptions; /** Base URL for the attachment service; defaults to `PH_SWITCHBOARD_PUBLIC_URL` then `http(s)://localhost:${port}`. */
123
+ identity?: IdentityOptions;
124
+ /** Base URL for the attachment service; defaults to `PH_SWITCHBOARD_PUBLIC_URL` then `http(s)://localhost:${port}`. */
89
125
  attachmentServiceUrl?: string;
126
+ /** Mount the MCP server at `/mcp`. On by default; `false` wins over
127
+ * MCP_ENABLED, which can turn it off but never on. */
90
128
  mcp?: boolean;
129
+ /** The plugin composition to boot with (FEATURE_PLUGIN_HOST_ENABLED): the
130
+ * resolved host.js runner.plugins entries, supplied by the uniform-runners
131
+ * switchboard runner (R2 step 2) or a test. Omitted = the built-in default
132
+ * composition. Resolved plugins, not specifiers — resolution happens at the
133
+ * runner against the PROJECT dependency tree. */
134
+ pluginComposition?: ResolvedPlugin[];
135
+ /** Mount the read-only inspection subgraph at `/graphql/inspection`. On by
136
+ * default; `false` wins over INSPECTION_ENABLED, which can turn it off. */
137
+ inspection?: boolean;
138
+ /** Powerhouse workflows: the runtime, its subgraph, its webhooks and its
139
+ * document models. Wins over PH_WORKFLOWS_ENABLED and the config file. */
140
+ workflows?: {
141
+ enabled?: boolean;
142
+ };
143
+ /** The GDPR add-on; off unless this or PH_PRIVACY_ENABLED turns it on. */
144
+ privacy?: PrivacyOptions;
91
145
  processorConfig?: Map<string, unknown>;
92
146
  disableLocalPackages?: boolean;
93
147
  enableDocumentModelSubgraphs?: boolean;
@@ -144,12 +198,40 @@ type StartServerOptions = {
144
198
  enabled?: boolean;
145
199
  dbPoolSize?: number;
146
200
  };
201
+ /**
202
+ * Stored documents at protocol versions this build does not run: "refuse"
203
+ * (the default) fails the boot with a StoredDocumentsRefusedError;
204
+ * "read-only" starts with a warning and keeps those documents read-only.
205
+ * Unset falls back to the REACTOR_UNSUPPORTED_STORED_DOCUMENTS env var.
206
+ * Ignored when `reactor` is passed.
207
+ */
208
+ unsupportedStoredDocuments?: UnsupportedStoredDocuments;
147
209
  };
148
- type SwitchboardReactor = {
210
+ export type SwitchboardReactor = {
149
211
  defaultDriveUrl: string | undefined;
150
- reactor: IReactorClient; /** Switchboard-backed remote attachment service over its own `/attachments/*` API, for downstream consumers. */
151
- attachmentService: IAttachmentService; /** Whether the authoritative attachment-reference projection is active. */
152
- attachmentReferenceProjection: AttachmentReferenceProjectionCapability; /** The Renown instance if identity was initialized */
212
+ reactor: IReactorClient;
213
+ /** Switchboard-backed remote attachment service over its own `/attachments/*` API, for downstream consumers.
214
+ * Undefined when the attachments plugin is absent from the composition
215
+ * (FEATURE_PLUGIN_HOST_ENABLED — presence is activation, rewire R2.3). */
216
+ attachmentService: IAttachmentService | undefined;
217
+ /** Whether the authoritative attachment-reference projection is active. */
218
+ attachmentReferenceProjection: AttachmentReferenceProjectionCapability;
219
+ /** Whether the workflow runtime's operation intake is indexing. Undefined
220
+ * when workflows are off; unavailable means no document trigger fires. */
221
+ workflowTriggers?: WorkflowTriggersCapability;
222
+ /** Whether workflows are on, after the option, PH_WORKFLOWS_ENABLED and the config file. */
223
+ workflowsEnabled: boolean;
224
+ /** The boot list of importable models workers and workflow pieces load; empty when none are resolved. */
225
+ modelManifest(): ModelManifestEntry[];
226
+ /** Present when the privacy add-on runs: its erasure service. */
227
+ privacy?: {
228
+ erasure: IErasureService;
229
+ };
230
+ /** Whether `/mcp` is mounted, after the option and MCP_ENABLED. */
231
+ mcpEnabled: boolean;
232
+ /** Whether `/graphql/inspection` is mounted, after the option and INSPECTION_ENABLED. */
233
+ inspectionEnabled: boolean;
234
+ /** The Renown instance if identity was initialized */
153
235
  renown: IRenown$1 | null;
154
236
  /**
155
237
  * Port the HTTP server actually bound to. May differ from the requested
@@ -157,45 +239,68 @@ type SwitchboardReactor = {
157
239
  */
158
240
  port: number;
159
241
  /**
160
- * Drain switchboard-owned resources: HTTP server, GraphQL manager,
161
- * attachments, MCP, packages subgraph, and the read-model DB. This does
162
- * NOT kill the reactor — in owned-reactor mode the reactor lifecycle is
163
- * handled by its own SIGINT signal handlers, which then drain the api via
164
- * the shutdown hook switchboard registered on the builder. In
165
- * caller-provided mode the caller owns the reactor lifecycle separately.
166
- *
167
- * Callers using a caller-provided reactor must invoke this from their own
168
- * teardown / SIGINT path so api resources are released; killing the
169
- * reactor alone won't release them.
242
+ * Idempotent. Owned reactor: runs the reactor module's memoized
243
+ * `shutdown()` (kill, shutdown hooks incl. the api drain, database).
244
+ * Caller-provided reactor: drains the api only (HTTP server, GraphQL
245
+ * manager, attachments, MCP, read-model DB); the caller owns the reactor
246
+ * and must call this from its own teardown.
170
247
  */
171
248
  shutdown: () => Promise<void>;
172
249
  };
173
250
  //#endregion
174
251
  //#region src/builder-defaults.d.mts
175
252
  type SwitchboardReactorDefaultsOptions = {
176
- documentModels?: DocumentModelModule[]; /** Upgrade manifests for versioned models, one per document type. */
177
- upgradeManifests?: UpgradeManifest<readonly number[]>[]; /** Default true. */
253
+ documentModels?: DocumentModelModule[];
254
+ /** Upgrade manifests for versioned models, one per document type. */
255
+ upgradeManifests?: UpgradeManifest<readonly number[]>[];
256
+ /** Default true. */
178
257
  includeBaseModels?: boolean;
179
258
  /**
180
259
  * Channel scheme. Defaults to `ChannelScheme.SWITCHBOARD`, which populates
181
260
  * `reactorModule.syncModule.syncManager` — required by reactor-api. Set
182
- * to `false` only if the caller will configure a scheme themselves.
261
+ * to `false` if the caller configures sync itself (`withChannelScheme` or
262
+ * `withSync`); the builder refuses both together.
183
263
  */
184
- channelScheme?: ChannelScheme | false; /** Defaults to true. Set false when the caller owns SIGINT handling. */
185
- signalHandlers?: boolean; /** Executor tuning. Omit to use the reactor's own defaults. */
264
+ channelScheme?: ChannelScheme | false;
265
+ /** Defaults to true. Set false when the caller owns SIGINT handling. */
266
+ signalHandlers?: boolean;
267
+ /** Executor tuning. Omit to use the reactor's own defaults. */
186
268
  executorConfig?: {
187
269
  maxSkipThreshold?: number;
188
270
  featureFlags?: Partial<ReactorFeatureFlags>;
189
- }; /** Wire dynamic document-model loading via HTTP. */
271
+ };
272
+ /** Wire dynamic document-model loading via HTTP. */
190
273
  documentModelLoader?: IDocumentModelLoader;
191
274
  logger?: ILogger;
192
275
  /**
193
- * Identity signer (typically from `getRenownSignerConfig`). Applied to the
194
- * `ReactorClientBuilder`; omit for unsigned operation.
276
+ * Identity signer (typically from `getRenownSignerConfig`). Signs client
277
+ * writes and the operations the executor synthesizes, in pooled workers
278
+ * through `workerSigner`; omit for unsigned operation.
195
279
  */
196
280
  signer?: SignerConfig;
281
+ /**
282
+ * Which keys may sign as which users (typically from
283
+ * `getRenownTrustPolicyConfig`); wins over one carried by `signer`.
284
+ */
285
+ trustPolicy?: Pick<SignerConfig, "trustPolicy" | "workerTrustPolicy">;
286
+ /** What the client creates new documents as; see `resolveCreateSignaturePolicy`. */
287
+ createSignaturePolicy?: SignaturePolicy;
197
288
  };
198
- declare function applySwitchboardReactorDefaults(reactorBuilder: ReactorBuilder, clientBuilder: ReactorClientBuilder, options?: SwitchboardReactorDefaultsOptions): void;
289
+ export declare function applySwitchboardReactorDefaults(reactorBuilder: ReactorBuilder, clientBuilder: ReactorClientBuilder, options?: SwitchboardReactorDefaultsOptions): void;
290
+ //#endregion
291
+ //#region src/unsupported-stored-documents.d.mts
292
+ /** From REACTOR_UNSUPPORTED_STORED_DOCUMENTS; `input` wins when defined. */
293
+ export declare function resolveUnsupportedStoredDocuments(input: UnsupportedStoredDocuments | undefined, env: NodeJS.ProcessEnv): UnsupportedStoredDocuments;
294
+ /** The reactor refused to start over documents this build does not run. */
295
+ export declare class StoredDocumentsRefusedError extends Error {
296
+ readonly versions: readonly {
297
+ protocol: string;
298
+ version: number;
299
+ }[];
300
+ readonly documents: number;
301
+ constructor(cause: UnsupportedStoredProtocolError);
302
+ static isError(error: unknown): error is StoredDocumentsRefusedError;
303
+ }
199
304
  //#endregion
200
305
  //#region src/server.d.mts
201
306
  /**
@@ -203,9 +308,65 @@ declare function applySwitchboardReactorDefaults(reactorBuilder: ReactorBuilder,
203
308
  * the port is free, false if the OS reports it in use. Any other error is
204
309
  * surfaced so we don't silently mask real issues (permissions, bad host, …).
205
310
  */
206
- declare function isPortAvailable(port: number): Promise<boolean>;
311
+ export declare function isPortAvailable(port: number): Promise<boolean>;
312
+ /**
313
+ * The reactor's storage handle, plus the pool instrumentation when that
314
+ * storage is Postgres. The PGlite branch has no `pg.Pool` at all, so the
315
+ * instrumentation is absent rather than optional-by-convention.
316
+ */
317
+ type ReactorStorage = {
318
+ kysely: Kysely<Database>;
319
+ poolInstrumentation: PoolInstrumentation | undefined;
320
+ storageFacts: ReactorStorageFacts;
321
+ };
322
+ export declare function createReactorKysely(opts: {
323
+ reactorDbUrl: string | undefined;
324
+ reactorPgliteDir: string | null;
325
+ reactorPgliteMajor: SupportedPgMajor | null;
326
+ inMemory: boolean;
327
+ /**
328
+ * Resolved lazily: only the Postgres branch has a host pool, and
329
+ * {@link resolveHostPoolSize} throws on a bad REACTOR_DB_POOL_SIZE_HOST.
330
+ * Called eagerly it would fail a PGlite-backed server over a value that
331
+ * path never reads.
332
+ */
333
+ hostPoolSize: () => number;
334
+ logger: ILogger;
335
+ }): Promise<ReactorStorage>;
336
+ export interface PgliteStorageDirs {
337
+ /** Read-model store: a Postgres URL or a PGlite dir. */
338
+ readModelPath: string;
339
+ /** Reactor store: a Postgres URL or a PGlite dir. */
340
+ reactorPath: string;
341
+ /** PGlite dir for the reactor, null for Postgres or a caller-owned reactor. */
342
+ reactorPgliteDir: string | null;
343
+ /** PGlite dir for the read model, null for Postgres. */
344
+ readModelPgliteDir: string | null;
345
+ /** The PGlite dirs for the pre-flight, as before (not deduplicated). */
346
+ pgliteDirs: string[];
347
+ /** Set when BOTH stores are PGlite on one dir (see resolvePgliteStorageDirs). */
348
+ sharedPgliteDir: string | null;
349
+ }
350
+ /**
351
+ * Where the two stores live — the classic resolution, relocated verbatim.
352
+ * Classic layout: `./.ph/reactor-storage` for the reactor and
353
+ * `.ph/read-storage` for the read model (the same names inside
354
+ * `${userData}/.ph` under a shell's PH_USER_DATA_DIR). `dbPath` also names
355
+ * the reactor store unless PH_REACTOR_DATABASE_URL does: with `dbPath` alone
356
+ * both stores share one location. That is the long-standing contract of
357
+ * `--db-path` and fine for one Postgres database, but for PGlite it is two
358
+ * postmasters on one data dir — reported via `sharedPgliteDir` so the caller
359
+ * warns. Not refused: changing that contract is a separate decision.
360
+ */
361
+ export declare function resolvePgliteStorageDirs(opts: {
362
+ dbPath: string | undefined;
363
+ reactorDbUrl: string | undefined;
364
+ /** The caller passed its own reactor — the reactor-side dir is unused. */
365
+ callerReactor: boolean;
366
+ phDir?: string;
367
+ }): PgliteStorageDirs;
207
368
  /** Derive the remote attachment service config for switchboard's own `/attachments/*` API. */
208
- declare function deriveAttachmentServiceConfig(options: Pick<StartServerOptions, "attachmentServiceUrl" | "https">, serverPort: number, renown: IRenown | null): {
369
+ export declare function deriveAttachmentServiceConfig(options: Pick<StartServerOptions, "attachmentServiceUrl" | "https">, serverPort: number, renown: IRenown | null): {
209
370
  remoteUrl: string;
210
371
  jwtHandler: JwtHandler | undefined;
211
372
  };
@@ -220,13 +381,15 @@ declare function deriveAttachmentServiceConfig(options: Pick<StartServerOptions,
220
381
  * dangling until the process exits.
221
382
  *
222
383
  * When `options.reactor` is omitted, the switchboard builds and owns the
223
- * reactor. `shutdown()` on the returned handle only drains the api (HTTP
224
- * server, GraphQL, MCP, attachments); the reactor itself is torn down by
225
- * its own signal handlers (`withSignalHandlers`), which call `kill()` and
226
- * trigger the `withShutdownHook` chain that disposes the api. Programmatic
227
- * full teardown isn't currently exposed — wire it via SIGINT/SIGTERM.
384
+ * reactor. `shutdown()` on the returned handle then runs the reactor
385
+ * module's `shutdown()`: `kill()`, the `withShutdownHook` chain that drains
386
+ * the api (HTTP server, GraphQL, MCP, attachments, read-model db), then the
387
+ * reactor database. It does not exit the process. It is the same memoized
388
+ * teardown the SIGINT/SIGTERM handlers (`withSignalHandlers`) run, so calling
389
+ * it twice, or receiving a signal around it, tears down once.
228
390
  */
229
- declare const startSwitchboard: (options?: StartServerOptions) => Promise<SwitchboardReactor>;
391
+ export declare const startSwitchboard: (options?: StartServerOptions) => Promise<SwitchboardReactor>;
230
392
  //#endregion
231
- export { IdentityOptions, StartServerOptions, StorageOptions, SwitchboardDriveDocumentType, SwitchboardDriveInput, SwitchboardReactor, type SwitchboardReactorDefaultsOptions, applySwitchboardReactorDefaults, deriveAttachmentServiceConfig, isPortAvailable, startSwitchboard };
393
+ export type { SwitchboardReactorDefaultsOptions, WorkflowTriggersCapability };
394
+ export {};
232
395
  //# sourceMappingURL=server.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.mts","names":[],"sources":["../src/types.ts","../src/builder-defaults.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;AAgBA;KAAY,4BAAA;;KAKA,qBAAA,GAAwB,UAAA;EAClC,YAAA,GAAe,4BAAA;AAAA;AAAA,KAGL,cAAA;EACV,IAAA;EACA,cAAA;EACA,WAAA;AAAA;AAAA,KAGU,eAAA;EATiC,+DAW3C,WAAA;EARU;;;;EAaV,eAAA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,EAAgB,cAAA,EAChB,aAAA,EAAe,oBAAA,EACf,OAAA,GAAS,iCAAA;;;;;;;;iBCuDK,eAAA,CAAgB,IAAA,WAAe,OAAA;;iBA0H/B,6BAAA,CACd,OAAA,EAAS,IAAA,CAAK,kBAAA,qCACd,UAAA,UACA,MAAA,EAAQ,OAAA;EACL,SAAA;EAAmB,UAAA,EAAY,UAAA;AAAA;;AF1OpC;;;;;;;;;AAIA;;;;;;;cEogCa,gBAAA,GACX,OAAA,GAAS,kBAAA,KACR,OAAA,CAAQ,kBAAA"}
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,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as applySwitchboardReactorDefaults, n as isPortAvailable, r as startSwitchboard, t as deriveAttachmentServiceConfig } from "./server-CiKkVE6g.mjs";
3
- import "./utils-Baw7rThP.mjs";
4
- export { applySwitchboardReactorDefaults, deriveAttachmentServiceConfig, isPortAvailable, startSwitchboard };
5
- !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]="43d97572-0a08-5683-83a3-d8477151600e")}catch(e){}}();
6
- //# debugId=43d97572-0a08-5683-83a3-d8477151600e
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
+ 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]="534d7300-c326-56aa-9687-d11cdffdf0c0")}catch(e){}}();
5
+ //# debugId=534d7300-c326-56aa-9687-d11cdffdf0c0
@@ -1,9 +1,43 @@
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]="686dcce6-c280-5558-89dd-a18a7e514cdf")}catch(e){}}();
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
+ import { withSignaturePolicy } from "@powerhousedao/shared/document-model";
5
6
  //#region src/utils.mts
6
- async function addDefaultDrive(client, drive, serverPort) {
7
+ /**
8
+ * A configured id pins the drive, and only a legacy drive can take a chosen
9
+ * id; otherwise the client's creation default applies.
10
+ */
11
+ async function underCreatePolicy(client, document, id) {
12
+ return id ? withSignaturePolicy(document, "legacy", { id }) : withSignaturePolicy(document, await client.getCreateSignaturePolicy());
13
+ }
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) {
7
41
  let driveId = drive.id;
8
42
  if (!driveId || driveId.length === 0) driveId = drive.slug;
9
43
  if (!driveId || driveId.length === 0) throw new Error("Invalid Drive Id");
@@ -13,7 +47,7 @@ async function addDefaultDrive(client, drive, serverPort) {
13
47
  } catch {}
14
48
  if (existingDrive) return `http://localhost:${serverPort}/d/${driveId}`;
15
49
  const { global } = driveCreateState();
16
- const document = driveCreateDocument({
50
+ const created = driveCreateDocument({
17
51
  global: {
18
52
  ...global,
19
53
  name: drive.global.name,
@@ -26,7 +60,9 @@ async function addDefaultDrive(client, drive, serverPort) {
26
60
  triggers: drive.local?.triggers ?? []
27
61
  }
28
62
  });
29
- if (drive.id && drive.id.length > 0) document.header.id = drive.id;
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);
30
66
  if (drive.slug && drive.slug.length > 0) document.header.slug = drive.slug;
31
67
  if (drive.global.name) document.header.name = drive.global.name;
32
68
  if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
@@ -37,7 +73,8 @@ async function addDefaultDrive(client, drive, serverPort) {
37
73
  }
38
74
  return `http://localhost:${serverPort}/d/${driveId}`;
39
75
  }
40
- async function addDefaultReactorDrive(client, drive, serverPort) {
76
+ /** addDefaultDrive for a reactor drive. */
77
+ async function addDefaultReactorDrive(client, drive, serverPort, logger = console) {
41
78
  let driveId = drive.id;
42
79
  if (!driveId || driveId.length === 0) driveId = drive.slug;
43
80
  if (!driveId || driveId.length === 0) throw new Error("Invalid Drive Id");
@@ -47,7 +84,7 @@ async function addDefaultReactorDrive(client, drive, serverPort) {
47
84
  } catch {}
48
85
  if (existingDrive) return `http://localhost:${serverPort}/d/${driveId}`;
49
86
  const { global, local } = reactorDriveCreateState();
50
- const document = reactorDriveCreateDocument({
87
+ const created = reactorDriveCreateDocument({
51
88
  global: {
52
89
  ...global,
53
90
  name: drive.global.name,
@@ -59,7 +96,9 @@ async function addDefaultReactorDrive(client, drive, serverPort) {
59
96
  sharingType: drive.local?.sharingType ?? local.sharingType
60
97
  }
61
98
  });
62
- if (drive.id && drive.id.length > 0) document.header.id = drive.id;
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);
63
102
  if (drive.slug && drive.slug.length > 0) document.header.slug = drive.slug;
64
103
  if (drive.global.name) document.header.name = drive.global.name;
65
104
  if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
@@ -76,5 +115,5 @@ function isPostgresUrl(url) {
76
115
  //#endregion
77
116
  export { addDefaultReactorDrive as n, isPostgresUrl as r, addDefaultDrive as t };
78
117
 
79
- //# sourceMappingURL=utils-Baw7rThP.mjs.map
80
- //# debugId=686dcce6-c280-5558-89dd-a18a7e514cdf
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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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,10 +1,15 @@
1
1
  import { IReactorClient } from "@powerhousedao/reactor";
2
2
  import { DriveInput } from "@powerhousedao/shared/document-drive";
3
-
4
3
  //#region src/utils.d.mts
5
- declare function addDefaultDrive(client: IReactorClient, drive: DriveInput, serverPort: number): Promise<string>;
6
- declare function addDefaultReactorDrive(client: IReactorClient, drive: DriveInput, serverPort: number): Promise<string>;
7
- declare function isPostgresUrl(url: string): boolean;
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>;
12
+ export declare function isPostgresUrl(url: string): boolean;
8
13
  //#endregion
9
- export { addDefaultDrive, addDefaultReactorDrive, isPostgresUrl };
14
+ export {};
10
15
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.mts"],"mappings":";;;;iBAWsB,eAAA,CACpB,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,UAAA,EACP,UAAA,WAAkB,OAAA;AAAA,iBAgEE,sBAAA,CACpB,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,UAAA,EACP,UAAA,WAAkB,OAAA;AAAA,iBA6DJ,aAAA,CAAc,GAAA"}
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-Baw7rThP.mjs";
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]="8227e60f-e412-513a-b0cb-502740b7f818")}catch(e){}}();
4
- //# debugId=8227e60f-e412-513a-b0cb-502740b7f818
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
@@ -0,0 +1,30 @@
1
+ import { ILogger } from "document-model";
2
+ import { IReactorClient, InProcessReactorClientModule, ModelManifestEntry, ReactorBuilder } from "@powerhousedao/reactor";
3
+ import { SubgraphClass } from "@powerhousedao/reactor-api";
4
+ import "@powerhousedao/shared/document-model";
5
+ import "@powerhousedao/reactor-workflow";
6
+ import "@powerhousedao/shared/processors";
7
+ //#region src/workflow-runtime.d.mts
8
+ /** Whether the operation intake is indexing. Same shape as the attachment
9
+ * reference projection, because it is the same limitation. */
10
+ type WorkflowTriggersCapability = {
11
+ status: "available";
12
+ } | {
13
+ status: "unavailable";
14
+ reason: "in-process-reactor-module-unavailable" | "live-read-model-registration-unsupported" | "workflow-singleton-lost";
15
+ };
16
+ interface ComposedWorkflowRuntime {
17
+ subgraph: SubgraphClass;
18
+ /** Whether document operations reach the runtime at all; unavailable once
19
+ * the singleton is lost. */
20
+ readonly triggers: WorkflowTriggersCapability;
21
+ /** The owner name this host holds the workflow singleton under; undefined
22
+ * when the lease was not taken (a suite that opted out). */
23
+ singletonOwner?: string;
24
+ start(): Promise<void>;
25
+ stop(): Promise<void>;
26
+ }
27
+ //#endregion
28
+ export { WorkflowTriggersCapability as n, ComposedWorkflowRuntime as t };
29
+ export {};
30
+ //# sourceMappingURL=workflow-runtime-7GaJ13c9.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-runtime-7GaJ13c9.d.mts","names":[],"sources":["../src/workflow-runtime.mts"],"mappings":";;;;;;;;;KAiEY;EACN;;EAEA;EACA;;UAuRW;EACf,UAAU;;;WAGD,UAAU;;;EAGnB;EACA,SAAS;EACT,QAAQ"}