@supatype/cli 0.9.1 → 0.9.2
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 +303 -91
- package/bin/node-version.js +28 -0
- package/bin/supatype.js +8 -4
- package/dist/app/port-holder.d.ts +33 -0
- package/dist/app/port-holder.d.ts.map +1 -0
- package/dist/app/port-holder.js +66 -0
- package/dist/app/port-holder.js.map +1 -0
- package/dist/app/proxy-dev-app.d.ts +21 -3
- package/dist/app/proxy-dev-app.d.ts.map +1 -1
- package/dist/app/proxy-dev-app.js +84 -46
- package/dist/app/proxy-dev-app.js.map +1 -1
- package/dist/app/vite-dev-args.d.ts +20 -0
- package/dist/app/vite-dev-args.d.ts.map +1 -0
- package/dist/app/vite-dev-args.js +65 -0
- package/dist/app/vite-dev-args.js.map +1 -0
- package/dist/app-config.d.ts +2 -0
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +27 -8
- package/dist/app-config.js.map +1 -1
- package/dist/augmentation-generator.d.ts +2 -0
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +7 -3
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/binary-download-lock.d.ts.map +1 -1
- package/dist/binary-download-lock.js +2 -10
- package/dist/binary-download-lock.js.map +1 -1
- package/dist/cache-provider.d.ts +17 -2
- package/dist/cache-provider.d.ts.map +1 -1
- package/dist/cache-provider.js +28 -3
- package/dist/cache-provider.js.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +10 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/admin.js +5 -11
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +22 -2
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/dev.d.ts +21 -4
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +222 -68
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.js +1 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +3 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +6 -8
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +193 -114
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/link-helpers.js +1 -1
- package/dist/commands/link-helpers.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +3 -1
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/self-host.d.ts +3 -3
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +68 -269
- package/dist/commands/self-host.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +156 -63
- package/dist/commands/update.js.map +1 -1
- package/dist/compose-db-roles.d.ts.map +1 -1
- package/dist/compose-db-roles.js +3 -0
- package/dist/compose-db-roles.js.map +1 -1
- package/dist/compose-rename.d.ts.map +1 -1
- package/dist/compose-rename.js +5 -0
- package/dist/compose-rename.js.map +1 -1
- package/dist/compose-render-mode.d.ts +8 -3
- package/dist/compose-render-mode.d.ts.map +1 -1
- package/dist/compose-render-mode.js +13 -5
- package/dist/compose-render-mode.js.map +1 -1
- package/dist/compose-services.d.ts.map +1 -1
- package/dist/compose-services.js +3 -2
- package/dist/compose-services.js.map +1 -1
- package/dist/config-mailer-env.d.ts +6 -2
- package/dist/config-mailer-env.d.ts.map +1 -1
- package/dist/config-mailer-env.js +9 -11
- package/dist/config-mailer-env.js.map +1 -1
- package/dist/config-version-pin.d.ts +42 -0
- package/dist/config-version-pin.d.ts.map +1 -0
- package/dist/config-version-pin.js +64 -0
- package/dist/config-version-pin.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -2
- package/dist/config.js.map +1 -1
- package/dist/dev-compose.d.ts +9 -4
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +87 -53
- package/dist/dev-compose.js.map +1 -1
- package/dist/dev-initial-push.d.ts.map +1 -1
- package/dist/dev-initial-push.js +6 -0
- package/dist/dev-initial-push.js.map +1 -1
- package/dist/dev-ports.d.ts +7 -2
- package/dist/dev-ports.d.ts.map +1 -1
- package/dist/dev-ports.js +44 -22
- package/dist/dev-ports.js.map +1 -1
- package/dist/dev-ready-panel.d.ts +26 -3
- package/dist/dev-ready-panel.d.ts.map +1 -1
- package/dist/dev-ready-panel.js +37 -5
- package/dist/dev-ready-panel.js.map +1 -1
- package/dist/dev-self-start.d.ts +16 -0
- package/dist/dev-self-start.d.ts.map +1 -0
- package/dist/dev-self-start.js +31 -0
- package/dist/dev-self-start.js.map +1 -0
- package/dist/dev-session-lock.d.ts +66 -2
- package/dist/dev-session-lock.d.ts.map +1 -1
- package/dist/dev-session-lock.js +104 -5
- package/dist/dev-session-lock.js.map +1 -1
- package/dist/dev-session.d.ts +6 -1
- package/dist/dev-session.d.ts.map +1 -1
- package/dist/dev-session.js +9 -3
- package/dist/dev-session.js.map +1 -1
- package/dist/dev-shutdown.d.ts +11 -2
- package/dist/dev-shutdown.d.ts.map +1 -1
- package/dist/dev-shutdown.js +23 -9
- package/dist/dev-shutdown.js.map +1 -1
- package/dist/docker-runtime.d.ts +31 -7
- package/dist/docker-runtime.d.ts.map +1 -1
- package/dist/docker-runtime.js +104 -36
- package/dist/docker-runtime.js.map +1 -1
- package/dist/engine-columns.d.ts +26 -0
- package/dist/engine-columns.d.ts.map +1 -0
- package/dist/engine-columns.js +67 -0
- package/dist/engine-columns.js.map +1 -0
- package/dist/env-file.d.ts +18 -3
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +23 -7
- package/dist/env-file.js.map +1 -1
- package/dist/frontend-env.d.ts +3 -2
- package/dist/frontend-env.d.ts.map +1 -1
- package/dist/frontend-env.js +1 -1
- package/dist/frontend-env.js.map +1 -1
- package/dist/functions-deno-types.d.ts.map +1 -1
- package/dist/functions-deno-types.js +5 -5
- package/dist/functions-deno-types.js.map +1 -1
- package/dist/functions-worker-files.d.ts.map +1 -1
- package/dist/functions-worker-files.js +2 -13
- package/dist/functions-worker-files.js.map +1 -1
- package/dist/generated/release-images.d.ts +6 -6
- package/dist/generated/release-images.js +3 -3
- package/dist/gitignore.d.ts +29 -2
- package/dist/gitignore.d.ts.map +1 -1
- package/dist/gitignore.js +86 -21
- package/dist/gitignore.js.map +1 -1
- package/dist/hooks-generator.d.ts.map +1 -1
- package/dist/hooks-generator.js +4 -2
- package/dist/hooks-generator.js.map +1 -1
- package/dist/host-database.d.ts +6 -2
- package/dist/host-database.d.ts.map +1 -1
- package/dist/host-database.js +10 -2
- package/dist/host-database.js.map +1 -1
- package/dist/init-dependency-versions.d.ts +2 -3
- package/dist/init-dependency-versions.d.ts.map +1 -1
- package/dist/init-dependency-versions.js +12 -9
- package/dist/init-dependency-versions.js.map +1 -1
- package/dist/init-example.d.ts.map +1 -1
- package/dist/init-example.js +13 -1
- package/dist/init-example.js.map +1 -1
- package/dist/init-expo-runtime-env.d.ts +25 -0
- package/dist/init-expo-runtime-env.d.ts.map +1 -0
- package/dist/init-expo-runtime-env.js +112 -0
- package/dist/init-expo-runtime-env.js.map +1 -0
- package/dist/init-next-runtime-env.d.ts +14 -1
- package/dist/init-next-runtime-env.d.ts.map +1 -1
- package/dist/init-next-runtime-env.js +116 -35
- package/dist/init-next-runtime-env.js.map +1 -1
- package/dist/init-package-json.d.ts +11 -3
- package/dist/init-package-json.d.ts.map +1 -1
- package/dist/init-package-json.js +20 -13
- package/dist/init-package-json.js.map +1 -1
- package/dist/init-port-registry.d.ts +19 -0
- package/dist/init-port-registry.d.ts.map +1 -0
- package/dist/init-port-registry.js +57 -0
- package/dist/init-port-registry.js.map +1 -0
- package/dist/init-project-detect.d.ts +20 -0
- package/dist/init-project-detect.d.ts.map +1 -1
- package/dist/init-project-detect.js +41 -8
- package/dist/init-project-detect.js.map +1 -1
- package/dist/init-vite-node.d.ts +21 -0
- package/dist/init-vite-node.d.ts.map +1 -0
- package/dist/init-vite-node.js +75 -0
- package/dist/init-vite-node.js.map +1 -0
- package/dist/jsx-first-child.d.ts +18 -0
- package/dist/jsx-first-child.d.ts.map +1 -0
- package/dist/jsx-first-child.js +53 -0
- package/dist/jsx-first-child.js.map +1 -0
- package/dist/keyspace-password-file.d.ts +46 -0
- package/dist/keyspace-password-file.d.ts.map +1 -0
- package/dist/keyspace-password-file.js +128 -0
- package/dist/keyspace-password-file.js.map +1 -0
- package/dist/kong-config.d.ts +1 -0
- package/dist/kong-config.d.ts.map +1 -1
- package/dist/kong-config.js +64 -20
- package/dist/kong-config.js.map +1 -1
- package/dist/local-gateway.d.ts +11 -3
- package/dist/local-gateway.d.ts.map +1 -1
- package/dist/local-gateway.js +16 -7
- package/dist/local-gateway.js.map +1 -1
- package/dist/local-secrets.d.ts +10 -0
- package/dist/local-secrets.d.ts.map +1 -1
- package/dist/local-secrets.js +13 -0
- package/dist/local-secrets.js.map +1 -1
- package/dist/local-stack-guard.d.ts.map +1 -1
- package/dist/local-stack-guard.js +3 -2
- package/dist/local-stack-guard.js.map +1 -1
- package/dist/local-stack.d.ts.map +1 -1
- package/dist/local-stack.js +7 -6
- package/dist/local-stack.js.map +1 -1
- package/dist/local-storage.d.ts +3 -5
- package/dist/local-storage.d.ts.map +1 -1
- package/dist/local-storage.js +10 -10
- package/dist/local-storage.js.map +1 -1
- package/dist/mailer-autoconfirm.d.ts +29 -24
- package/dist/mailer-autoconfirm.d.ts.map +1 -1
- package/dist/mailer-autoconfirm.js +47 -43
- package/dist/mailer-autoconfirm.js.map +1 -1
- package/dist/model-hooks.d.ts +4 -4
- package/dist/model-hooks.d.ts.map +1 -1
- package/dist/model-hooks.js +13 -7
- package/dist/model-hooks.js.map +1 -1
- package/dist/native-dev-env.d.ts +25 -2
- package/dist/native-dev-env.d.ts.map +1 -1
- package/dist/native-dev-env.js +39 -4
- package/dist/native-dev-env.js.map +1 -1
- package/dist/native-keyspace.d.ts +21 -6
- package/dist/native-keyspace.d.ts.map +1 -1
- package/dist/native-keyspace.js +48 -14
- package/dist/native-keyspace.js.map +1 -1
- package/dist/native-leftover-postgres.d.ts +23 -0
- package/dist/native-leftover-postgres.d.ts.map +1 -0
- package/dist/native-leftover-postgres.js +55 -0
- package/dist/native-leftover-postgres.js.map +1 -0
- package/dist/native-leftover-services.d.ts +17 -0
- package/dist/native-leftover-services.d.ts.map +1 -0
- package/dist/native-leftover-services.js +93 -0
- package/dist/native-leftover-services.js.map +1 -0
- package/dist/native-pg-auth.d.ts.map +1 -1
- package/dist/native-pg-auth.js +2 -1
- package/dist/native-pg-auth.js.map +1 -1
- package/dist/native-port-lock.d.ts +37 -0
- package/dist/native-port-lock.d.ts.map +1 -0
- package/dist/native-port-lock.js +78 -0
- package/dist/native-port-lock.js.map +1 -0
- package/dist/native-realtime.d.ts +6 -3
- package/dist/native-realtime.d.ts.map +1 -1
- package/dist/native-realtime.js +65 -24
- package/dist/native-realtime.js.map +1 -1
- package/dist/native-roles-sql.d.ts.map +1 -1
- package/dist/native-roles-sql.js +2 -1
- package/dist/native-roles-sql.js.map +1 -1
- package/dist/native-storage-import.d.ts.map +1 -1
- package/dist/native-storage-import.js +6 -5
- package/dist/native-storage-import.js.map +1 -1
- package/dist/native-storage.d.ts +42 -7
- package/dist/native-storage.d.ts.map +1 -1
- package/dist/native-storage.js +196 -50
- package/dist/native-storage.js.map +1 -1
- package/dist/parent-watch.d.ts.map +1 -1
- package/dist/parent-watch.js +4 -8
- package/dist/parent-watch.js.map +1 -1
- package/dist/postgres-ctl.d.ts +31 -5
- package/dist/postgres-ctl.d.ts.map +1 -1
- package/dist/postgres-ctl.js +49 -11
- package/dist/postgres-ctl.js.map +1 -1
- package/dist/postgres-image.d.ts +16 -0
- package/dist/postgres-image.d.ts.map +1 -1
- package/dist/postgres-image.js +34 -11
- package/dist/postgres-image.js.map +1 -1
- package/dist/process-info.d.ts +14 -0
- package/dist/process-info.d.ts.map +1 -0
- package/dist/process-info.js +41 -0
- package/dist/process-info.js.map +1 -0
- package/dist/process-manager.d.ts +73 -4
- package/dist/process-manager.d.ts.map +1 -1
- package/dist/process-manager.js +121 -45
- package/dist/process-manager.js.map +1 -1
- package/dist/process-tree.d.ts +48 -0
- package/dist/process-tree.d.ts.map +1 -0
- package/dist/process-tree.js +141 -0
- package/dist/process-tree.js.map +1 -0
- package/dist/project-config.d.ts +33 -4
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +5 -1
- package/dist/project-config.js.map +1 -1
- package/dist/required-host-components.d.ts.map +1 -1
- package/dist/required-host-components.js +3 -5
- package/dist/required-host-components.js.map +1 -1
- package/dist/route-manifest.d.ts +24 -0
- package/dist/route-manifest.d.ts.map +1 -1
- package/dist/route-manifest.js +60 -2
- package/dist/route-manifest.js.map +1 -1
- package/dist/run-captured.d.ts +3 -1
- package/dist/run-captured.d.ts.map +1 -1
- package/dist/run-captured.js.map +1 -1
- package/dist/run-until-stopped.d.ts +3 -0
- package/dist/run-until-stopped.d.ts.map +1 -1
- package/dist/run-until-stopped.js +25 -11
- package/dist/run-until-stopped.js.map +1 -1
- package/dist/runtime-routes.d.ts +5 -0
- package/dist/runtime-routes.d.ts.map +1 -1
- package/dist/runtime-routes.js +5 -1
- package/dist/runtime-routes.js.map +1 -1
- package/dist/secret-sql.d.ts +13 -0
- package/dist/secret-sql.d.ts.map +1 -0
- package/dist/secret-sql.js +13 -0
- package/dist/secret-sql.js.map +1 -0
- package/dist/seed-ir.d.ts +8 -1
- package/dist/seed-ir.d.ts.map +1 -1
- package/dist/seed-ir.js +92 -6
- package/dist/seed-ir.js.map +1 -1
- package/dist/seed.d.ts +15 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/self-host-compose.d.ts +15 -1
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +216 -51
- package/dist/self-host-compose.js.map +1 -1
- package/dist/stack-exit-watch.d.ts +15 -0
- package/dist/stack-exit-watch.d.ts.map +1 -1
- package/dist/stack-exit-watch.js +41 -13
- package/dist/stack-exit-watch.js.map +1 -1
- package/dist/stack-folder.d.ts +28 -0
- package/dist/stack-folder.d.ts.map +1 -0
- package/dist/stack-folder.js +123 -0
- package/dist/stack-folder.js.map +1 -0
- package/dist/stack-setting-warnings.d.ts +2 -1
- package/dist/stack-setting-warnings.d.ts.map +1 -1
- package/dist/stack-setting-warnings.js +6 -1
- package/dist/stack-setting-warnings.js.map +1 -1
- package/dist/storage-provision.d.ts +12 -2
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +36 -11
- package/dist/storage-provision.js.map +1 -1
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +27 -3
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/dev/DevReadyPanelView.js +1 -1
- package/dist/ui/dev/DevReadyPanelView.js.map +1 -1
- package/dist/valkey-sidecar.d.ts +24 -11
- package/dist/valkey-sidecar.d.ts.map +1 -1
- package/dist/valkey-sidecar.js +45 -25
- package/dist/valkey-sidecar.js.map +1 -1
- package/dist/windows-processes.d.ts +7 -0
- package/dist/windows-processes.d.ts.map +1 -0
- package/dist/windows-processes.js +31 -0
- package/dist/windows-processes.js.map +1 -0
- package/dist/write-if-changed.d.ts +12 -0
- package/dist/write-if-changed.d.ts.map +1 -0
- package/dist/write-if-changed.js +32 -0
- package/dist/write-if-changed.js.map +1 -0
- package/package.json +6 -4
- package/dist/systemd.d.ts +0 -26
- package/dist/systemd.d.ts.map +0 -1
- package/dist/systemd.js +0 -117
- package/dist/systemd.js.map +0 -1
package/dist/native-storage.js
CHANGED
|
@@ -4,44 +4,61 @@
|
|
|
4
4
|
* image transforms come from one codebase rather than from the server's own object store.
|
|
5
5
|
*
|
|
6
6
|
* The server proxies /storage/v1 to the URL in the route manifest once the service answers. When
|
|
7
|
-
* it cannot be started,
|
|
8
|
-
*
|
|
7
|
+
* it cannot be started, storage is off: /storage/v1 answers 503, and dev says why and how to fix
|
|
8
|
+
* it. The server's built-in object store is never mounted, since it applies no read rules (0.9.1
|
|
9
|
+
* release test: any token, the anon key included, could read or sign any object in a private bucket).
|
|
9
10
|
*/
|
|
10
11
|
import { join } from "node:path";
|
|
11
12
|
import { isJsonObject } from "@supatype/shared";
|
|
12
13
|
import { EMBEDDED_CLI_VERSION } from "./cli-version-embedded.js";
|
|
13
14
|
import { pushStartUndo } from "./dev-shutdown.js";
|
|
14
15
|
import { errorMessage } from "./error-message.js";
|
|
15
|
-
import { keepsObjectsLocally,
|
|
16
|
+
import { keepsObjectsLocally, OWN_BUCKET_S3_SETTINGS, serverStoreRoot } from "./local-storage.js";
|
|
16
17
|
import { importLegacyNativeStorage } from "./native-storage-import.js";
|
|
17
|
-
import { ProcessManager } from "./process-manager.js";
|
|
18
|
-
import {
|
|
18
|
+
import { ProcessManager, superviseUntilReady } from "./process-manager.js";
|
|
19
|
+
import { switchServices } from "./route-manifest.js";
|
|
19
20
|
import { resolveStorageLaunch } from "./storage-launch.js";
|
|
20
21
|
/**
|
|
21
|
-
* How the server answers /storage/v1: by proxy to the storage service when it runs,
|
|
22
|
-
*
|
|
23
|
-
* on S3
|
|
22
|
+
* How the server answers /storage/v1: by proxy to the storage service when it runs, on S3 or not.
|
|
23
|
+
* With the service down, a project whose objects stay on this machine gets no storage at all, and a
|
|
24
|
+
* project on S3 is left to the server's own settings (a SUPATYPE_STORAGE_URL in .env, say).
|
|
25
|
+
*
|
|
26
|
+
* When the service is not running, SUPATYPE_STORAGE_DISABLED has a 0.9.2 server answer 503
|
|
27
|
+
* "storage service is not running". An older server ignores it, so the URL is blanked as well
|
|
28
|
+
* rather than left out: unset, the server proxies to its default of http://localhost:5000,
|
|
29
|
+
* whatever answers there, while blank it answers 502 "storage not configured".
|
|
30
|
+
*
|
|
31
|
+
* Every other storage variable is blanked, since the shell's reach the server too (ProcessManager
|
|
32
|
+
* passes process.env on): a STORAGE_PROVIDER=local there would mount the built-in store.
|
|
24
33
|
*/
|
|
25
|
-
export function serverStorageEnv(storage, config
|
|
26
|
-
if (storage
|
|
27
|
-
return {
|
|
28
|
-
return
|
|
34
|
+
export function serverStorageEnv(storage, config) {
|
|
35
|
+
if (storage === null && !keepsObjectsLocally(config))
|
|
36
|
+
return {};
|
|
37
|
+
return {
|
|
38
|
+
SUPATYPE_STORAGE_URL: storage?.url ?? "",
|
|
39
|
+
SUPATYPE_STORAGE_DISABLED: storage === null ? "true" : "",
|
|
40
|
+
STORAGE_PROVIDER: "",
|
|
41
|
+
STORAGE_PATH: "",
|
|
42
|
+
};
|
|
29
43
|
}
|
|
30
|
-
/** How long the service has to answer /health before dev
|
|
44
|
+
/** How long the service has to answer /health before dev turns storage off. */
|
|
31
45
|
const READY_TIMEOUT_MS = 60_000;
|
|
32
46
|
/** Where the service keeps object bytes, apart from the server's object store under `storage/`. */
|
|
33
47
|
function nativeStorageServiceRoot(stateRoot) {
|
|
34
48
|
return join(stateRoot, "storage-service");
|
|
35
49
|
}
|
|
50
|
+
/** The file backend under the state directory, for a project whose objects stay on this machine. */
|
|
51
|
+
function fileBackendEnv(stateRoot) {
|
|
52
|
+
return { STORAGE_BACKEND: "file", STORAGE_FILE_PATH: nativeStorageServiceRoot(stateRoot) };
|
|
53
|
+
}
|
|
36
54
|
/** The environment compose gives the storage image, for a single developer on one machine. */
|
|
37
|
-
function storageEnv(opts) {
|
|
55
|
+
function storageEnv(opts, backend) {
|
|
38
56
|
return {
|
|
39
57
|
DATABASE_URL: opts.databaseUrl,
|
|
40
58
|
JWT_SECRET: opts.jwtSecret,
|
|
41
59
|
PORT: String(opts.port),
|
|
42
60
|
HOST: "127.0.0.1",
|
|
43
|
-
|
|
44
|
-
STORAGE_FILE_PATH: nativeStorageServiceRoot(opts.stateRoot),
|
|
61
|
+
...backend,
|
|
45
62
|
// A local project has no plan, so no limits beyond each bucket's own, as self-host compose.
|
|
46
63
|
PROJECT_TIER: "enterprise",
|
|
47
64
|
STORAGE_QUOTA: "-1",
|
|
@@ -78,63 +95,192 @@ export async function waitForStorageReady(url, crashed, { timeoutMs = READY_TIME
|
|
|
78
95
|
/** How often the wait asks /health, and the most one ask and pause may count: the ask's own limit and the pause. */
|
|
79
96
|
const READY_POLL_MS = 250;
|
|
80
97
|
const READY_STEP_MAX_MS = 2_000 + READY_POLL_MS;
|
|
98
|
+
const storageUrl = (opts) => `http://127.0.0.1:${opts.port}`;
|
|
81
99
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
100
|
+
* Spawns the service under the crash-loop supervisor. Its stop is recorded as an undo of dev's
|
|
101
|
+
* start the moment it is spawned, so a Ctrl+C while it is still starting stops it too. Stopping
|
|
102
|
+
* for good while switched on switches storage off.
|
|
85
103
|
*/
|
|
86
|
-
|
|
87
|
-
let exited = false;
|
|
104
|
+
function spawnStorage(launch, opts, kind, watch) {
|
|
88
105
|
const proc = new ProcessManager(launch.bin, launch.args, {
|
|
89
106
|
label: "storage",
|
|
90
107
|
pidDir: opts.pidDir,
|
|
91
108
|
colour: "\x1b[34m",
|
|
92
|
-
env: storageEnv(opts),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
env: storageEnv(opts, kind.backend),
|
|
110
|
+
onStopped: () => {
|
|
111
|
+
watch.gone = true;
|
|
112
|
+
if (watch.on)
|
|
113
|
+
storageOff(opts.manifestPath, `Storage exited. ${WHILE_OFF}`);
|
|
96
114
|
},
|
|
115
|
+
...opts.supervision,
|
|
97
116
|
});
|
|
98
117
|
proc.start();
|
|
99
|
-
pushStartUndo(() =>
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
pushStartUndo(() => proc.stop());
|
|
119
|
+
return proc;
|
|
120
|
+
}
|
|
121
|
+
/** Why the service did not answer by its deadline (it exited, or the time is up), or undefined once it has. */
|
|
122
|
+
async function readyOrWhy(proc, opts) {
|
|
123
|
+
const crashed = () => proc.stopRequested || proc.crashes > 0;
|
|
124
|
+
try {
|
|
125
|
+
await waitForStorageReady(storageUrl(opts), crashed, { ...(opts.readyTimeoutMs !== undefined && { timeoutMs: opts.readyTimeoutMs }) });
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
return errorMessage(err);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Starts the service and switches storage on once it answers and `kind.prepare` has run. One that
|
|
134
|
+
* has not answered by its deadline is switched off at the gateway, left with the crash-loop
|
|
135
|
+
* supervisor, and switched on once it answers. It was stopped there, and the server read whether
|
|
136
|
+
* storage was on only at its start, so nothing could switch it on later (0.9.2 release test N-FF2).
|
|
137
|
+
* The service while storage is on, or null.
|
|
138
|
+
*/
|
|
139
|
+
async function startStorage(launch, opts, kind) {
|
|
140
|
+
const watch = { on: false, gone: false };
|
|
141
|
+
const proc = spawnStorage(launch, opts, kind, watch);
|
|
142
|
+
const why = await readyOrWhy(proc, opts);
|
|
143
|
+
if (proc.stopRequested)
|
|
144
|
+
return null;
|
|
145
|
+
if (why === undefined) {
|
|
146
|
+
if (!(await switchOn(proc, opts, kind, watch)))
|
|
147
|
+
return null;
|
|
148
|
+
console.log(`[supatype] Storage service: ${storageUrl(opts)} (${kind.where})`);
|
|
149
|
+
return { proc, url: storageUrl(opts) };
|
|
150
|
+
}
|
|
151
|
+
storageOff(opts.manifestPath, `Storage (${kind.where}) is not answering yet: ${why}. It is switched off at the gateway until it answers, and restarted when it exits. ${WHILE_OFF}`);
|
|
152
|
+
void superviseUntilReady(proc, {
|
|
153
|
+
probe: async () => ((await reportsReady(storageUrl(opts))) ? true : undefined),
|
|
154
|
+
onReady: () => switchOnLate(proc, opts, kind, watch),
|
|
155
|
+
isGone: () => watch.gone,
|
|
102
156
|
});
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Switches on a service switched off for not answering by its deadline, says so, and hands it to
|
|
161
|
+
* `onLateStart`. Nothing awaits a late start, so what it could not do (create a bucket, say) is said here.
|
|
162
|
+
*/
|
|
163
|
+
async function switchOnLate(proc, opts, kind, watch) {
|
|
164
|
+
if (!(await switchOn(proc, opts, kind, watch)))
|
|
165
|
+
return;
|
|
166
|
+
const url = storageUrl(opts);
|
|
167
|
+
console.log(`[supatype] Storage answers at ${url} now, so it is switched back on at the gateway.`);
|
|
103
168
|
try {
|
|
104
|
-
await
|
|
105
|
-
return proc;
|
|
169
|
+
await opts.onLateStart?.({ proc, url });
|
|
106
170
|
}
|
|
107
171
|
catch (err) {
|
|
108
|
-
|
|
109
|
-
|
|
172
|
+
console.warn(`[supatype] ⚠ ${errorMessage(err)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Runs `kind.prepare`, then switches storage on. When it throws, the service is stopped and storage
|
|
177
|
+
* stays off, saying why, and this answers false.
|
|
178
|
+
*/
|
|
179
|
+
async function switchOn(proc, opts, kind, watch) {
|
|
180
|
+
const url = storageUrl(opts);
|
|
181
|
+
try {
|
|
182
|
+
await kind.prepare?.(url);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
// Said in storage's own pane too, which otherwise ends on its last line of output (N-FF2).
|
|
186
|
+
await proc.stop(errorMessage(err));
|
|
187
|
+
storageOff(opts.manifestPath, offUntilRestart(errorMessage(err)));
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
switchServices(opts.manifestPath, { storage: true }, { storage_url: url });
|
|
191
|
+
watch.on = true;
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
/** What the gateway answers while storage is switched off. */
|
|
195
|
+
const WHILE_OFF = '/storage/v1 answers 503 "storage service is not running" while it is off.';
|
|
196
|
+
/** Storage off until dev's next start, and why: the service could not be found, or prepared. */
|
|
197
|
+
function offUntilRestart(why) {
|
|
198
|
+
return ("Storage is off: the storage service did not start, so /storage/v1 answers 503 " +
|
|
199
|
+
"\"storage service is not running\".\n" +
|
|
200
|
+
` ${why}\n` +
|
|
201
|
+
" Fix the cause above and restart `supatype dev`. Your stored files are kept and come back then.");
|
|
202
|
+
}
|
|
203
|
+
/** Switch storage off at the gateway, which answers /storage/v1 itself while it is, and say `message`. */
|
|
204
|
+
function storageOff(manifestPath, message) {
|
|
205
|
+
switchServices(manifestPath, { storage: false }, { storage_url: undefined });
|
|
206
|
+
console.warn(`[supatype] ⚠ ${message}`);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Imports what the server's object store holds and the service does not. Until it has gone through,
|
|
211
|
+
* storage stays off rather than answer without it; the old files stay on disk and the next start
|
|
212
|
+
* imports them again.
|
|
213
|
+
*/
|
|
214
|
+
async function importServerStore(opts, url) {
|
|
215
|
+
try {
|
|
216
|
+
await importLegacyNativeStorage({ legacyRoot: serverStoreRoot(opts.stateRoot), url, jwtSecret: opts.jwtSecret, cliVersion: EMBEDDED_CLI_VERSION });
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
throw new Error(`could not import the server's object store: ${errorMessage(err)}`);
|
|
110
220
|
}
|
|
111
221
|
}
|
|
112
222
|
/**
|
|
113
223
|
* Start the storage service for native dev, import what the server's object store holds and the
|
|
114
|
-
* service does not, and record the service in the route manifest. Null
|
|
115
|
-
*
|
|
224
|
+
* service does not, and record the service in the route manifest. Null unless storage is on: the
|
|
225
|
+
* service could not be found (off until the next start), or has not answered yet (switched on once
|
|
226
|
+
* it does, and handed to `onLateStart`).
|
|
116
227
|
*/
|
|
117
228
|
export async function startNativeStorage(opts, resolveLaunch = resolveStorageLaunch) {
|
|
118
|
-
|
|
229
|
+
let launch;
|
|
119
230
|
try {
|
|
120
|
-
|
|
121
|
-
// Until everything the server's store held is in the service, the server's store keeps
|
|
122
|
-
// answering, so nothing a developer stored there goes missing while an import fails.
|
|
123
|
-
await importLegacyNativeStorage({ legacyRoot: serverStoreRoot(opts.stateRoot), url, jwtSecret: opts.jwtSecret, cliVersion: EMBEDDED_CLI_VERSION })
|
|
124
|
-
.catch(async (err) => {
|
|
125
|
-
await proc.stop();
|
|
126
|
-
throw new Error(`could not import the server's object store: ${errorMessage(err)}`);
|
|
127
|
-
});
|
|
128
|
-
patchRouteManifest(opts.manifestPath, { storage_url: url });
|
|
129
|
-
console.log(`[supatype] Storage service: ${url} (objects in ${nativeStorageServiceRoot(opts.stateRoot)})`);
|
|
130
|
-
return { proc, url };
|
|
231
|
+
launch = await resolveLaunch(opts.config, opts.cwd);
|
|
131
232
|
}
|
|
132
233
|
catch (err) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
234
|
+
return storageOff(opts.manifestPath, offUntilRestart(errorMessage(err)));
|
|
235
|
+
}
|
|
236
|
+
return startStorage(launch, opts, {
|
|
237
|
+
backend: fileBackendEnv(opts.stateRoot),
|
|
238
|
+
where: `objects in ${nativeStorageServiceRoot(opts.stateRoot)}`,
|
|
239
|
+
prepare: (url) => importServerStore(opts, url),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The storage service's backend for a project on S3 (`storage.provider: "s3"`): the project's own
|
|
244
|
+
* bucket, every Supatype bucket a prefix in it, from `env` (the shell over .env). Null when
|
|
245
|
+
* SUPATYPE_STORAGE_URL names a storage service of the developer's own, which the server then proxies
|
|
246
|
+
* to as .env says. Throws on a blank S3_BUCKET: the service's other defaults point at a SeaweedFS
|
|
247
|
+
* native dev does not run, so starting without one would only move the failure to the first upload.
|
|
248
|
+
*/
|
|
249
|
+
export function nativeS3StorageEnv(env) {
|
|
250
|
+
if ((env["SUPATYPE_STORAGE_URL"] ?? "").trim() !== "")
|
|
137
251
|
return null;
|
|
252
|
+
if ((env["S3_BUCKET"] ?? "").trim() === "") {
|
|
253
|
+
throw new Error('storage.provider is "s3", but S3_BUCKET is blank in .env. Set S3_BUCKET to the bucket this ' +
|
|
254
|
+
"project keeps its files in (with S3_REGION for AWS, or S3_ENDPOINT for MinIO, R2 and the like), " +
|
|
255
|
+
'or set storage.provider to "local" to keep them on this machine.');
|
|
256
|
+
}
|
|
257
|
+
// Blank stays blank: the service reads a blank setting as unset, and it overrides any value
|
|
258
|
+
// the service would otherwise inherit from dev's own environment.
|
|
259
|
+
return { STORAGE_BACKEND: "s3", ...Object.fromEntries(OWN_BUCKET_S3_SETTINGS.map((key) => [key, env[key] ?? ""])) };
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Whether native dev starts a storage service of its own: for a project whose objects stay on this
|
|
263
|
+
* machine, and for one on S3 unless SUPATYPE_STORAGE_URL names the developer's own (`s3Env` null).
|
|
264
|
+
* Only then is storage dev's to switch off, and its URL left out of the panel while it is.
|
|
265
|
+
*/
|
|
266
|
+
export function startsStorageService(config, s3Env) {
|
|
267
|
+
return keepsObjectsLocally(config) || s3Env !== null;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Starts the storage service on the project's S3 bucket and records it in the route manifest.
|
|
271
|
+
* Null unless storage is on, as for a local project: the service could not be found (off until the
|
|
272
|
+
* next start; dev exited here until 0.9.2 round 2, R2-S2, against the storage docs and Docker dev),
|
|
273
|
+
* or has not answered by its deadline (switched on once it does, 0.9.2 release test N-FF2).
|
|
274
|
+
*/
|
|
275
|
+
export async function startNativeS3Storage(opts, s3Env, resolveLaunch = resolveStorageLaunch) {
|
|
276
|
+
const bucket = s3Env["S3_BUCKET"] ?? "";
|
|
277
|
+
let launch;
|
|
278
|
+
try {
|
|
279
|
+
launch = await resolveLaunch(opts.config, opts.cwd);
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
return storageOff(opts.manifestPath, offUntilRestart(`the storage service for S3 bucket ${bucket}: ${errorMessage(err)}`));
|
|
138
283
|
}
|
|
284
|
+
return startStorage(launch, opts, { backend: s3Env, where: `objects in S3 bucket ${bucket}` });
|
|
139
285
|
}
|
|
140
286
|
//# sourceMappingURL=native-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-storage.js","sourceRoot":"","sources":["../src/native-storage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"native-storage.js","sourceRoot":"","sources":["../src/native-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACjG,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAA2B,MAAM,sBAAsB,CAAA;AAEnG,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AA4B1D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA6B,EAAE,MAA6B;IAC3F,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAA;IAC/D,OAAO;QACL,oBAAoB,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE;QACxC,yBAAyB,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QACzD,gBAAgB,EAAE,EAAE;QACpB,YAAY,EAAE,EAAE;KACjB,CAAA;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAE/B,mGAAmG;AACnG,SAAS,wBAAwB,CAAC,SAAiB;IACjD,OAAO,I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AAChG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parent-watch.d.ts","sourceRoot":"","sources":["../src/parent-watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,MAAM,CAAA;IACd,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAC5B;AAED,mGAAmG;AACnG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO7C;AAED,eAAO,MAAM,SAAS,EAAE,YAGvB,CAAA;AAED,MAAM,WAAW,WAAW;IAC1B,8FAA8F;IAC9F,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,IAAI,IAAI,IAAI,CAAA;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,IAAI,GAAE,kBAAuB,GAAG,WAAW,CA0B1F;AAED,2EAA2E;AAC3E,
|
|
1
|
+
{"version":3,"file":"parent-watch.d.ts","sourceRoot":"","sources":["../src/parent-watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,MAAM,CAAA;IACd,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAC5B;AAED,mGAAmG;AACnG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO7C;AAED,eAAO,MAAM,SAAS,EAAE,YAGvB,CAAA;AAED,MAAM,WAAW,WAAW;IAC1B,8FAA8F;IAC9F,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,IAAI,IAAI,IAAI,CAAA;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,IAAI,GAAE,kBAAuB,GAAG,WAAW,CA0B1F;AAED,2EAA2E;AAC3E,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG9E"}
|
package/dist/parent-watch.js
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* that then exited (Start-Process, `start` from a script) names a grandparent gone from the start,
|
|
19
19
|
* and dev stopped itself two seconds after every start.
|
|
20
20
|
*/
|
|
21
|
-
import { execFile } from "node:child_process";
|
|
22
21
|
import { errorCode } from "./error-message.js";
|
|
22
|
+
import { windowsProcessFields } from "./windows-processes.js";
|
|
23
23
|
/** True when a process with this PID exists. EPERM means it exists and belongs to someone else. */
|
|
24
24
|
export function pidAlive(pid) {
|
|
25
25
|
try {
|
|
@@ -69,12 +69,8 @@ export function watchParent(onGone, opts = {}) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/** The parent of `pid` on Windows, or undefined when it cannot be read. */
|
|
72
|
-
export function windowsParentOf(pid) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const parent = Number(stdout.trim());
|
|
76
|
-
resolve(err || !Number.isInteger(parent) || parent <= 0 ? undefined : parent);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
72
|
+
export async function windowsParentOf(pid) {
|
|
73
|
+
const parent = Number((await windowsProcessFields([pid], "ParentProcessId")).get(pid));
|
|
74
|
+
return Number.isInteger(parent) && parent > 0 ? parent : undefined;
|
|
79
75
|
}
|
|
80
76
|
//# sourceMappingURL=parent-watch.js.map
|
package/dist/parent-watch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parent-watch.js","sourceRoot":"","sources":["../src/parent-watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parent-watch.js","sourceRoot":"","sources":["../src/parent-watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAO7D,mGAAmG;AACnG,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,SAAS,CAAC,GAAG,CAAC,KAAK,OAAO,CAAA;IACnC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAiB;IACrC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI;IACxB,KAAK,EAAE,QAAQ;CAChB,CAAA;AAaD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAkB,EAAE,OAA2B,EAAE;IAC3E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,SAAS,CAAA;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC3B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,IAAI,KAAiD,CAAA;IAErD,MAAM,IAAI,GAAG,GAAS,EAAE;QACtB,IAAI,KAAK,KAAK,SAAS;YAAE,aAAa,CAAC,KAAK,CAAC,CAAA;QAC7C,KAAK,GAAG,SAAS,CAAA;IACnB,CAAC,CAAA;IACD,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YACvB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,KAAK,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;YACrF,IAAI,CAAC,IAAI;gBAAE,OAAM;YACjB,IAAI,EAAE,CAAA;YACN,MAAM,EAAE,CAAA;QACV,CAAC,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,CAAA;QAC3B,KAAK,CAAC,KAAK,EAAE,EAAE,CAAA;IACjB,CAAC;IACD,OAAO;QACL,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE;YACjB,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;gBAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1E,CAAC;QACD,IAAI;KACL,CAAA;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,MAAM,oBAAoB,CAAC,CAAC,GAAG,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACtF,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;AACpE,CAAC"}
|
package/dist/postgres-ctl.d.ts
CHANGED
|
@@ -20,11 +20,16 @@ export interface PgOptions {
|
|
|
20
20
|
keyspacePort?: number;
|
|
21
21
|
/** Database durable keys are written to. Ignored while everything is ephemeral. */
|
|
22
22
|
keyspaceDatabase?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The file the keyspace reads the `supatype` user's password from (`pg_keyspace.password_file`),
|
|
25
|
+
* which native dev writes before the start (native-keyspace.ts). Only the path is a setting.
|
|
26
|
+
*/
|
|
27
|
+
keyspacePasswordFile?: string;
|
|
23
28
|
/** The project's database, where pg_cron and pg_net run their jobs. */
|
|
24
29
|
database?: string;
|
|
25
30
|
}
|
|
26
31
|
/** What the server's settings are decided from: the install, the keyspace and the database. */
|
|
27
|
-
type PgSettingsOptions = Pick<PgOptions, "pgBinDir" | "keyspacePort" | "keyspaceDatabase" | "database">;
|
|
32
|
+
type PgSettingsOptions = Pick<PgOptions, "pgBinDir" | "keyspacePort" | "keyspaceDatabase" | "keyspacePasswordFile" | "database">;
|
|
28
33
|
/**
|
|
29
34
|
* Native Postgres bundles are built with prefix /usr/local/supatype-pg; dyld/ld
|
|
30
35
|
* must load libpq and friends from the extracted lib/ next to bin/.
|
|
@@ -116,7 +121,8 @@ export declare function nativeKeyspaceLibraryPresent(pgBinDir: string | null | u
|
|
|
116
121
|
*/
|
|
117
122
|
export declare function nativeGraphqlServerEnv(pgBinDir: string | null | undefined): Record<string, string>;
|
|
118
123
|
/**
|
|
119
|
-
* Where the native RESP keyspace looks for a free port, and how far it looks
|
|
124
|
+
* Where the native RESP keyspace looks for a free port, and how far it looks;
|
|
125
|
+
* the Valkey sidecar that stands in for it looks in the same ports.
|
|
120
126
|
*
|
|
121
127
|
* 6379 first, because that is what a developer's tooling and the Valkey
|
|
122
128
|
* sidecar before it both used, so the familiar port stays the usual answer.
|
|
@@ -160,10 +166,12 @@ export declare function firstFreePort(base: number, span: number): Promise<numbe
|
|
|
160
166
|
*/
|
|
161
167
|
export declare function pgServerOptions(opts: PgOptions): string;
|
|
162
168
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
169
|
+
* One `-c name=value` of the options pg_ctl hands the server. On Linux and macOS pg_ctl starts
|
|
170
|
+
* Postgres through `/bin/sh`, so a value with a space or a quote, as a password file under a home
|
|
171
|
+
* directory like `/Users/Ada Lovelace` has, is single-quoted for that shell. Every other value is
|
|
172
|
+
* a plain word, as before; Windows, whose archive has no keyspace, is left as it was.
|
|
165
173
|
*/
|
|
166
|
-
export declare function
|
|
174
|
+
export declare function pgSettingArg(name: string, value: string, platform?: NodeJS.Platform): string;
|
|
167
175
|
/** {@link pgServerSettings} as name and value pairs, in the order they are given. */
|
|
168
176
|
export declare function pgServerSettingPairs(opts: PgSettingsOptions): [string, string][];
|
|
169
177
|
export declare function start(opts: PgOptions): void;
|
|
@@ -184,6 +192,17 @@ export declare function writeClusterSettings(opts: PgSettingsOptions & {
|
|
|
184
192
|
* or that names no pid, is left for pg_ctl and Postgres to judge. True when it was removed.
|
|
185
193
|
*/
|
|
186
194
|
export declare function removeStalePidFile(dataDir: string, alive?: (pid: number) => boolean): boolean;
|
|
195
|
+
/** What a data directory's `postmaster.pid` says about the server that wrote it. */
|
|
196
|
+
export interface PostmasterPid {
|
|
197
|
+
/** The postmaster's pid; 0 when the first line is not one. */
|
|
198
|
+
pid: number;
|
|
199
|
+
/** The data directory it was started on, as Postgres wrote it (forward slashes on Windows too). */
|
|
200
|
+
dataDir: string;
|
|
201
|
+
/** The port it listens on; 0 when the file does not say yet. */
|
|
202
|
+
port: number;
|
|
203
|
+
}
|
|
204
|
+
/** `postmaster.pid` in `dataDir`: its first, second and fourth lines. Null when there is none. */
|
|
205
|
+
export declare function readPostmasterPid(dataDir: string): PostmasterPid | null;
|
|
187
206
|
/**
|
|
188
207
|
* Stop Postgres using pg_ctl (fast mode), when it is running.
|
|
189
208
|
*
|
|
@@ -222,6 +241,13 @@ export declare function connectSucceeds(port: number, timeoutMs?: number, host?:
|
|
|
222
241
|
* the failure this exists to prevent.
|
|
223
242
|
*/
|
|
224
243
|
export declare function isPortInUse(port: number): Promise<boolean>;
|
|
244
|
+
/**
|
|
245
|
+
* True when the port is taken on either loopback. A dev server on Node's default `localhost` can
|
|
246
|
+
* listen on [::1] alone (Windows resolves it there first), which {@link isPortInUse} cannot see:
|
|
247
|
+
* a bind on 127.0.0.1 succeeds beside it. 0.9.1 release test (FF21): init proposed Vite's 5173
|
|
248
|
+
* while another project's app held it.
|
|
249
|
+
*/
|
|
250
|
+
export declare function isLoopbackPortInUse(port: number): Promise<boolean>;
|
|
225
251
|
/** The command that shows what holds `port`, for this platform. */
|
|
226
252
|
export declare function portCheckCommand(port: number): string;
|
|
227
253
|
/** Returns the full path to a Postgres binary, appending .exe on Windows. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-ctl.d.ts","sourceRoot":"","sources":["../src/postgres-ctl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,MAAM,WAAW,SAAS;IACxB,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;IAChB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mFAAmF;IACnF,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,+FAA+F;AAC/F,KAAK,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,kBAAkB,GAAG,UAAU,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"postgres-ctl.d.ts","sourceRoot":"","sources":["../src/postgres-ctl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,MAAM,WAAW,SAAS;IACxB,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;IAChB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,C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I,EAAE,SAAS,EAAE,SAAS,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlF;AA8BD;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAM,EAAE,IAAI,SAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAazG;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGhE;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAExE;AAED,mEAAmE;AACnE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAMD,6EAA6E;AAC7E,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D"}
|
package/dist/postgres-ctl.js
CHANGED
|
@@ -250,7 +250,8 @@ function nativeLibraryPresent(pgBinDir, stem) {
|
|
|
250
250
|
return [`${stem}.so`, `${stem}.dylib`, `${stem}.dll`].some((lib) => existsSync(join(prefix, "lib", lib)) || existsSync(join(prefix, "lib", "postgresql", lib)));
|
|
251
251
|
}
|
|
252
252
|
/**
|
|
253
|
-
* Where the native RESP keyspace looks for a free port, and how far it looks
|
|
253
|
+
* Where the native RESP keyspace looks for a free port, and how far it looks;
|
|
254
|
+
* the Valkey sidecar that stands in for it looks in the same ports.
|
|
254
255
|
*
|
|
255
256
|
* 6379 first, because that is what a developer's tooling and the Valkey
|
|
256
257
|
* sidecar before it both used, so the familiar port stays the usual answer.
|
|
@@ -301,12 +302,21 @@ export async function firstFreePort(base, span) {
|
|
|
301
302
|
export function pgServerOptions(opts) {
|
|
302
303
|
return `-p ${opts.port} ${pgServerSettings(opts)}`;
|
|
303
304
|
}
|
|
305
|
+
/** {@link pgServerOptions} without the port: every setting a native Postgres starts with. */
|
|
306
|
+
function pgServerSettings(opts) {
|
|
307
|
+
return pgServerSettingPairs(opts).map(([name, value]) => pgSettingArg(name, value)).join(" ");
|
|
308
|
+
}
|
|
304
309
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
310
|
+
* One `-c name=value` of the options pg_ctl hands the server. On Linux and macOS pg_ctl starts
|
|
311
|
+
* Postgres through `/bin/sh`, so a value with a space or a quote, as a password file under a home
|
|
312
|
+
* directory like `/Users/Ada Lovelace` has, is single-quoted for that shell. Every other value is
|
|
313
|
+
* a plain word, as before; Windows, whose archive has no keyspace, is left as it was.
|
|
307
314
|
*/
|
|
308
|
-
export function
|
|
309
|
-
|
|
315
|
+
export function pgSettingArg(name, value, platform = process.platform) {
|
|
316
|
+
const arg = `${name}=${value}`;
|
|
317
|
+
if (platform === "win32" || /^[\w.,:/=@+-]*$/.test(arg))
|
|
318
|
+
return `-c ${arg}`;
|
|
319
|
+
return `-c '${arg.replaceAll("'", "'\\''")}'`;
|
|
310
320
|
}
|
|
311
321
|
/** {@link pgServerSettings} as name and value pairs, in the order they are given. */
|
|
312
322
|
export function pgServerSettingPairs(opts) {
|
|
@@ -341,9 +351,23 @@ function preloadedLibraries(opts) {
|
|
|
341
351
|
function databaseSetting(name, opts) {
|
|
342
352
|
return opts.database ? [[name, opts.database]] : [];
|
|
343
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* The keyspace's settings. 0.9.2 release test (N-RB2): it listened on 0.0.0.0 and answered every
|
|
356
|
+
* client, so native dev on Linux served an open, writable store to the network. It listens on
|
|
357
|
+
* loopback only, and reads the `supatype` user's password from the file native dev wrote
|
|
358
|
+
* (native-keyspace.ts), which also makes it refuse every client that has not logged in, from its
|
|
359
|
+
* first accept. With no file it still refuses everyone (`require_auth`), rather than serve them.
|
|
360
|
+
* `nativeKeyspacePort` only asks for a keyspace from an archive that has these settings
|
|
361
|
+
* (KEYSPACE_AUTH_SINCE).
|
|
362
|
+
*/
|
|
344
363
|
function keyspaceSettings(opts) {
|
|
364
|
+
const auth = opts.keyspacePasswordFile
|
|
365
|
+
? ["pg_keyspace.password_file", opts.keyspacePasswordFile]
|
|
366
|
+
: ["pg_keyspace.require_auth", "on"];
|
|
345
367
|
return [
|
|
346
368
|
["pg_keyspace.port", String(opts.keyspacePort)],
|
|
369
|
+
["pg_keyspace.listen_address", "127.0.0.1"],
|
|
370
|
+
auth,
|
|
347
371
|
["pg_keyspace.durability", "ephemeral"],
|
|
348
372
|
["pg_keyspace.keys", "50000"],
|
|
349
373
|
["pg_keyspace.ring_mb", "8"],
|
|
@@ -422,17 +446,22 @@ function runPgCtlStart(opts, args, logPath) {
|
|
|
422
446
|
* or that names no pid, is left for pg_ctl and Postgres to judge. True when it was removed.
|
|
423
447
|
*/
|
|
424
448
|
export function removeStalePidFile(dataDir, alive = pidAlive) {
|
|
425
|
-
const
|
|
426
|
-
if (!existsSync(pidFile))
|
|
427
|
-
return false;
|
|
428
|
-
const firstLine = (readFileSync(pidFile, "utf8").split("\n")[0] ?? "").trim();
|
|
429
|
-
const pid = /^\d+$/.test(firstLine) ? Number(firstLine) : 0;
|
|
449
|
+
const pid = readPostmasterPid(dataDir)?.pid ?? 0;
|
|
430
450
|
if (pid <= 0 || alive(pid))
|
|
431
451
|
return false;
|
|
432
|
-
rmSync(
|
|
452
|
+
rmSync(join(dataDir, "postmaster.pid"), { force: true });
|
|
433
453
|
console.log(`[supatype] Removed a stale postmaster.pid (process ${pid} is gone) from ${dataDir}.`);
|
|
434
454
|
return true;
|
|
435
455
|
}
|
|
456
|
+
/** `postmaster.pid` in `dataDir`: its first, second and fourth lines. Null when there is none. */
|
|
457
|
+
export function readPostmasterPid(dataDir) {
|
|
458
|
+
const pidFile = join(dataDir, "postmaster.pid");
|
|
459
|
+
if (!existsSync(pidFile))
|
|
460
|
+
return null;
|
|
461
|
+
const lines = readFileSync(pidFile, "utf8").split("\n").map((line) => line.trim());
|
|
462
|
+
const whole = (line) => (/^\d+$/.test(line ?? "") ? Number(line) : 0);
|
|
463
|
+
return { pid: whole(lines[0]), dataDir: lines[1] ?? "", port: whole(lines[3]) };
|
|
464
|
+
}
|
|
436
465
|
/**
|
|
437
466
|
* Stop Postgres using pg_ctl (fast mode), when it is running.
|
|
438
467
|
*
|
|
@@ -551,6 +580,15 @@ export async function isPortInUse(port) {
|
|
|
551
580
|
return true;
|
|
552
581
|
return bindFails(port, "127.0.0.1");
|
|
553
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* True when the port is taken on either loopback. A dev server on Node's default `localhost` can
|
|
585
|
+
* listen on [::1] alone (Windows resolves it there first), which {@link isPortInUse} cannot see:
|
|
586
|
+
* a bind on 127.0.0.1 succeeds beside it. 0.9.1 release test (FF21): init proposed Vite's 5173
|
|
587
|
+
* while another project's app held it.
|
|
588
|
+
*/
|
|
589
|
+
export async function isLoopbackPortInUse(port) {
|
|
590
|
+
return (await isPortInUse(port)) || (await connectSucceeds(port, 400, "::1"));
|
|
591
|
+
}
|
|
554
592
|
/** The command that shows what holds `port`, for this platform. */
|
|
555
593
|
export function portCheckCommand(port) {
|
|
556
594
|
return process.platform === "win32" ? `netstat -ano | findstr :${port}` : `lsof -i :${port}`;
|