@supatype/cli 0.1.0-alpha.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +285 -69
- package/.turbo/turbo-typecheck.log +1 -1
- package/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/bin/dev-entry.ts +2 -1
- package/dist/app/framework.js +1 -3
- package/dist/app/framework.js.map +1 -1
- package/dist/app/proxy-dev-app.d.ts +14 -0
- package/dist/app/proxy-dev-app.d.ts.map +1 -1
- package/dist/app/proxy-dev-app.js +110 -6
- package/dist/app/proxy-dev-app.js.map +1 -1
- package/dist/app-config.d.ts +10 -0
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +72 -0
- package/dist/app-config.js.map +1 -1
- package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/dist/binary-cache.d.ts +19 -7
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +92 -46
- package/dist/binary-cache.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +17 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.d.ts +3 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +86 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/admin.d.ts +28 -1
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +297 -149
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/adopt.d.ts +3 -0
- package/dist/commands/adopt.d.ts.map +1 -0
- package/dist/commands/adopt.js +55 -0
- package/dist/commands/adopt.js.map +1 -0
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +20 -17
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +11 -10
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.d.ts +4 -9
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +75 -125
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +37 -58
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +140 -96
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +74 -39
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +39 -39
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +78 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/engine.d.ts.map +1 -1
- package/dist/commands/engine.js +5 -4
- package/dist/commands/engine.js.map +1 -1
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +172 -119
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +5 -4
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +35 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +883 -107
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/introspect.d.ts +3 -0
- package/dist/commands/introspect.d.ts.map +1 -0
- package/dist/commands/introspect.js +35 -0
- package/dist/commands/introspect.js.map +1 -0
- package/dist/commands/keys.d.ts +15 -1
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +46 -10
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/link-helpers.d.ts +15 -0
- package/dist/commands/link-helpers.d.ts.map +1 -0
- package/dist/commands/link-helpers.js +225 -0
- package/dist/commands/link-helpers.js.map +1 -0
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +5 -4
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/migrate-from-v1.d.ts.map +1 -1
- package/dist/commands/migrate-from-v1.js +3 -2
- package/dist/commands/migrate-from-v1.js.map +1 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +119 -26
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/pg.d.ts.map +1 -1
- package/dist/commands/pg.js +11 -12
- package/dist/commands/pg.js.map +1 -1
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +55 -46
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +33 -5
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +111 -138
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +4 -3
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/self-host.d.ts +2 -2
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +65 -50
- package/dist/commands/self-host.js.map +1 -1
- package/dist/commands/self-update.d.ts.map +1 -1
- package/dist/commands/self-update.js +3 -2
- package/dist/commands/self-update.js.map +1 -1
- package/dist/commands/status.d.ts +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +95 -29
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +3 -2
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +54 -21
- package/dist/commands/update.js.map +1 -1
- package/dist/compose-rename.d.ts +10 -0
- package/dist/compose-rename.d.ts.map +1 -0
- package/dist/compose-rename.js +67 -0
- package/dist/compose-rename.js.map +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/dev-compose.d.ts +26 -0
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +357 -79
- package/dist/dev-compose.js.map +1 -1
- package/dist/dev-log-bus.d.ts +30 -0
- package/dist/dev-log-bus.d.ts.map +1 -0
- package/dist/dev-log-bus.js +87 -0
- package/dist/dev-log-bus.js.map +1 -0
- package/dist/dev-log-filter.d.ts +10 -0
- package/dist/dev-log-filter.d.ts.map +1 -0
- package/dist/dev-log-filter.js +36 -0
- package/dist/dev-log-filter.js.map +1 -0
- package/dist/dev-logo.d.ts +12 -0
- package/dist/dev-logo.d.ts.map +1 -0
- package/dist/dev-logo.js +56 -0
- package/dist/dev-logo.js.map +1 -0
- package/dist/dev-ports.d.ts +27 -0
- package/dist/dev-ports.d.ts.map +1 -0
- package/dist/dev-ports.js +171 -0
- package/dist/dev-ports.js.map +1 -0
- package/dist/dev-session-lock.d.ts +25 -0
- package/dist/dev-session-lock.d.ts.map +1 -0
- package/dist/dev-session-lock.js +81 -0
- package/dist/dev-session-lock.js.map +1 -0
- package/dist/dev-session.d.ts +26 -0
- package/dist/dev-session.d.ts.map +1 -0
- package/dist/dev-session.js +106 -0
- package/dist/dev-session.js.map +1 -0
- package/dist/dev-shutdown.d.ts +25 -0
- package/dist/dev-shutdown.d.ts.map +1 -0
- package/dist/dev-shutdown.js +114 -0
- package/dist/dev-shutdown.js.map +1 -0
- package/dist/dev-task-colors.d.ts +13 -0
- package/dist/dev-task-colors.d.ts.map +1 -0
- package/dist/dev-task-colors.js +43 -0
- package/dist/dev-task-colors.js.map +1 -0
- package/dist/dev-tui.d.ts +24 -0
- package/dist/dev-tui.d.ts.map +1 -0
- package/dist/dev-tui.js +188 -0
- package/dist/dev-tui.js.map +1 -0
- package/dist/diff-output.d.ts +5 -1
- package/dist/diff-output.d.ts.map +1 -1
- package/dist/diff-output.js +69 -0
- package/dist/diff-output.js.map +1 -1
- package/dist/docker-runtime.d.ts +30 -0
- package/dist/docker-runtime.d.ts.map +1 -0
- package/dist/docker-runtime.js +118 -0
- package/dist/docker-runtime.js.map +1 -0
- package/dist/engine-client.d.ts +10 -1
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +76 -17
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-push-output.d.ts +17 -0
- package/dist/engine-push-output.d.ts.map +1 -0
- package/dist/engine-push-output.js +64 -0
- package/dist/engine-push-output.js.map +1 -0
- package/dist/ensure-binary.js +2 -2
- package/dist/ensure-binary.js.map +1 -1
- package/dist/env-file.d.ts +5 -0
- package/dist/env-file.d.ts.map +1 -0
- package/dist/env-file.js +33 -0
- package/dist/env-file.js.map +1 -0
- package/dist/gitignore.d.ts +8 -0
- package/dist/gitignore.d.ts.map +1 -0
- package/dist/gitignore.js +41 -0
- package/dist/gitignore.js.map +1 -0
- package/dist/kong-config.d.ts +9 -0
- package/dist/kong-config.d.ts.map +1 -1
- package/dist/kong-config.js +18 -1
- package/dist/kong-config.js.map +1 -1
- package/dist/link.d.ts +66 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +160 -0
- package/dist/link.js.map +1 -0
- package/dist/process-manager.d.ts +8 -0
- package/dist/process-manager.d.ts.map +1 -1
- package/dist/process-manager.js +53 -9
- package/dist/process-manager.js.map +1 -1
- package/dist/project-config.d.ts +30 -3
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +37 -4
- package/dist/project-config.js.map +1 -1
- package/dist/prompts.d.ts +3 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +3 -0
- package/dist/prompts.js.map +1 -0
- package/dist/pull-utils.d.ts +50 -14
- package/dist/pull-utils.d.ts.map +1 -1
- package/dist/pull-utils.js +152 -12
- package/dist/pull-utils.js.map +1 -1
- package/dist/resolve-target.d.ts +86 -0
- package/dist/resolve-target.d.ts.map +1 -0
- package/dist/resolve-target.js +291 -0
- package/dist/resolve-target.js.map +1 -0
- package/dist/restore-system-relation-targets.d.ts +3 -0
- package/dist/restore-system-relation-targets.d.ts.map +1 -0
- package/dist/restore-system-relation-targets.js +45 -0
- package/dist/restore-system-relation-targets.js.map +1 -0
- package/dist/runtime-routes.d.ts.map +1 -1
- package/dist/runtime-routes.js +7 -0
- package/dist/runtime-routes.js.map +1 -1
- package/dist/schema-ast-v2.d.ts +1 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js +2 -2
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/schema-sources.d.ts +40 -0
- package/dist/schema-sources.d.ts.map +1 -0
- package/dist/schema-sources.js +183 -0
- package/dist/schema-sources.js.map +1 -0
- package/dist/scripts/postinstall.js +5 -1
- package/dist/scripts/postinstall.js.map +1 -1
- package/dist/self-host-compose.d.ts +37 -1
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +234 -43
- package/dist/self-host-compose.js.map +1 -1
- package/dist/storage-provision.d.ts +4 -0
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +24 -2
- package/dist/storage-provision.js.map +1 -1
- package/dist/supatype-eval-1781522769253.d.mts +2 -0
- package/dist/supatype-eval-1781522769253.d.mts.map +1 -0
- package/dist/supatype-eval-1781522769253.mjs +3 -0
- package/dist/supatype-eval-1781522769253.mjs.map +1 -0
- package/dist/systemd.js +2 -2
- package/dist/systemd.js.map +1 -1
- package/dist/target-client.d.ts +10 -0
- package/dist/target-client.d.ts.map +1 -0
- package/dist/target-client.js +22 -0
- package/dist/target-client.js.map +1 -0
- package/dist/type-extractor.d.ts +11 -0
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +95 -8
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/brand.d.ts +9 -0
- package/dist/ui/brand.d.ts.map +1 -0
- package/dist/ui/brand.js +11 -0
- package/dist/ui/brand.js.map +1 -0
- package/dist/ui/confirm.d.ts +12 -0
- package/dist/ui/confirm.d.ts.map +1 -0
- package/dist/ui/confirm.js +28 -0
- package/dist/ui/confirm.js.map +1 -0
- package/dist/ui/fatal.d.ts +10 -0
- package/dist/ui/fatal.d.ts.map +1 -0
- package/dist/ui/fatal.js +34 -0
- package/dist/ui/fatal.js.map +1 -0
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/interactive.d.ts +3 -0
- package/dist/ui/interactive.d.ts.map +1 -0
- package/dist/ui/interactive.js +5 -0
- package/dist/ui/interactive.js.map +1 -0
- package/dist/ui/messages.d.ts +10 -0
- package/dist/ui/messages.d.ts.map +1 -0
- package/dist/ui/messages.js +35 -0
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/next-steps.d.ts +3 -0
- package/dist/ui/next-steps.d.ts.map +1 -0
- package/dist/ui/next-steps.js +10 -0
- package/dist/ui/next-steps.js.map +1 -0
- package/dist/ui/progress.d.ts +5 -0
- package/dist/ui/progress.d.ts.map +1 -0
- package/dist/ui/progress.js +24 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/prompts.d.ts +14 -0
- package/dist/ui/prompts.d.ts.map +1 -0
- package/dist/ui/prompts.js +34 -0
- package/dist/ui/prompts.js.map +1 -0
- package/package.json +5 -2
- package/src/app/framework.ts +1 -3
- package/src/app/proxy-dev-app.ts +114 -6
- package/src/app-config.ts +80 -0
- package/src/binary-cache.ts +102 -52
- package/src/cli.ts +16 -2
- package/src/commands/add.ts +97 -0
- package/src/commands/admin.ts +381 -190
- package/src/commands/adopt.ts +82 -0
- package/src/commands/app.ts +20 -17
- package/src/commands/cache.ts +11 -10
- package/src/commands/cloud.ts +91 -142
- package/src/commands/db.ts +40 -63
- package/src/commands/deploy.ts +186 -126
- package/src/commands/dev.ts +98 -55
- package/src/commands/diff.ts +52 -43
- package/src/commands/doctor.ts +103 -0
- package/src/commands/engine.ts +5 -4
- package/src/commands/functions.ts +187 -123
- package/src/commands/generate.ts +5 -4
- package/src/commands/init.ts +1087 -104
- package/src/commands/introspect.ts +48 -0
- package/src/commands/keys.ts +56 -14
- package/src/commands/link-helpers.ts +273 -0
- package/src/commands/logs.ts +5 -4
- package/src/commands/migrate-from-v1.ts +3 -2
- package/src/commands/migrate.ts +167 -27
- package/src/commands/pg.ts +13 -18
- package/src/commands/plugins.ts +55 -46
- package/src/commands/pull.ts +38 -9
- package/src/commands/push.ts +148 -175
- package/src/commands/seed.ts +5 -4
- package/src/commands/self-host.ts +85 -54
- package/src/commands/self-update.ts +3 -2
- package/src/commands/status.ts +102 -33
- package/src/commands/types.ts +3 -2
- package/src/commands/update.ts +59 -23
- package/src/compose-rename.ts +76 -0
- package/src/config.ts +2 -1
- package/src/dev-compose.ts +462 -76
- package/src/dev-log-bus.ts +101 -0
- package/src/dev-log-filter.ts +32 -0
- package/src/dev-logo.ts +61 -0
- package/src/dev-ports.ts +212 -0
- package/src/dev-session-lock.ts +101 -0
- package/src/dev-session.ts +130 -0
- package/src/dev-shutdown.ts +147 -0
- package/src/dev-task-colors.ts +47 -0
- package/src/dev-tui.ts +232 -0
- package/src/diff-output.ts +79 -1
- package/src/docker-runtime.ts +151 -0
- package/src/engine-client.ts +81 -17
- package/src/engine-push-output.ts +75 -0
- package/src/ensure-binary.ts +2 -2
- package/src/env-file.ts +37 -0
- package/src/gitignore.ts +48 -0
- package/src/kong-config.ts +24 -1
- package/src/link.ts +243 -0
- package/src/process-manager.ts +66 -10
- package/src/project-config.ts +62 -7
- package/src/prompts.ts +2 -0
- package/src/pull-utils.ts +217 -23
- package/src/resolve-target.ts +419 -0
- package/src/restore-system-relation-targets.ts +45 -0
- package/src/runtime-routes.ts +7 -0
- package/src/schema-ast-v2.ts +2 -1
- package/src/schema-sources.ts +248 -0
- package/src/scripts/postinstall.ts +7 -1
- package/src/self-host-compose.ts +262 -46
- package/src/storage-provision.ts +33 -1
- package/src/supatype-eval-1781522769253.mts +1 -0
- package/src/systemd.ts +2 -2
- package/src/target-client.ts +40 -0
- package/src/type-extractor.ts +124 -11
- package/src/ui/README.md +17 -0
- package/src/ui/brand.ts +12 -0
- package/src/ui/confirm.ts +38 -0
- package/src/ui/fatal.ts +43 -0
- package/src/ui/index.ts +8 -0
- package/src/ui/interactive.ts +4 -0
- package/src/ui/messages.ts +43 -0
- package/src/ui/next-steps.ts +10 -0
- package/src/ui/progress.ts +28 -0
- package/src/ui/prompts.ts +40 -0
- package/tests/admin-ensure.test.ts +59 -0
- package/tests/cli-help.test.ts +27 -2
- package/tests/config.test.ts +29 -2
- package/tests/dev-ports.test.ts +41 -0
- package/tests/dev-session-lock.test.ts +54 -0
- package/tests/dev-ui.test.ts +162 -0
- package/tests/docker-runtime.test.ts +236 -0
- package/tests/engine-push-output.test.ts +67 -0
- package/tests/init.test.ts +197 -18
- package/tests/link.test.ts +148 -0
- package/tests/minisign.test.ts +102 -0
- package/tests/proxy-dev-app.test.ts +45 -1
- package/tests/pull-utils.test.ts +5 -4
- package/tests/runtime-contract.test.ts +186 -2
- package/tests/schema-sources.test.ts +119 -0
- package/tests/storage-provision.test.ts +100 -0
- package/tests/ui-confirm.test.ts +41 -0
- package/tests/ui-messages.test.ts +66 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
readdirSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
cpSync,
|
|
8
|
+
} from "node:fs"
|
|
9
|
+
import { join, resolve, relative } from "node:path"
|
|
10
|
+
import { gzipSync, gunzipSync } from "node:zlib"
|
|
11
|
+
import { collectSchemaSourcePaths, type SchemaSourceGraph } from "./type-extractor.js"
|
|
12
|
+
import { loadConfig } from "./config.js"
|
|
13
|
+
import { projectRootFromConfig, schemaPathFromProject } from "./project-config.js"
|
|
14
|
+
|
|
15
|
+
const MAX_COMPRESSED_BYTES = 2 * 1024 * 1024
|
|
16
|
+
const WARN_COMPRESSED_BYTES = 512 * 1024
|
|
17
|
+
|
|
18
|
+
export interface SchemaSourcesManifest {
|
|
19
|
+
version: number
|
|
20
|
+
format: "tar+gzip"
|
|
21
|
+
entryPoint: string
|
|
22
|
+
fileCount: number
|
|
23
|
+
uncompressedBytes: number
|
|
24
|
+
compressedBytes: number
|
|
25
|
+
files: Array<{ path: string; sha256: string; bytes: number }>
|
|
26
|
+
pushedBy?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SchemaSourcesPayload {
|
|
30
|
+
manifest: SchemaSourcesManifest
|
|
31
|
+
dataBase64: string
|
|
32
|
+
gz: Buffer
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function padTarField(value: string, len: number): string {
|
|
36
|
+
return value.slice(0, len).padEnd(len, "\0")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function tarChecksum(header: Buffer): number {
|
|
40
|
+
let sum = 0
|
|
41
|
+
for (let i = 0; i < 512; i++) {
|
|
42
|
+
sum += i >= 148 && i < 156 ? 32 : header[i]!
|
|
43
|
+
}
|
|
44
|
+
return sum
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function writeTarEntry(name: string, content: Buffer): Buffer {
|
|
48
|
+
const header = Buffer.alloc(512, 0)
|
|
49
|
+
const size = content.length
|
|
50
|
+
header.write(padTarField(name, 100), 0, 100, "ascii")
|
|
51
|
+
header.write("0000644\0", 100, 8, "ascii")
|
|
52
|
+
header.write("0000000\0", 108, 8, "ascii")
|
|
53
|
+
header.write("0000000\0", 116, 8, "ascii")
|
|
54
|
+
header.write(padTarField(size.toString(8), 11), 124, 12, "ascii")
|
|
55
|
+
header.write("00000000000\0", 136, 12, "ascii")
|
|
56
|
+
header.write(" ", 148, 8, "ascii")
|
|
57
|
+
header.write("ustar\0", 257, 6, "ascii")
|
|
58
|
+
header.write("00", 263, 2, "ascii")
|
|
59
|
+
const chk = tarChecksum(header)
|
|
60
|
+
header.write(chk.toString(8).padStart(6, "0") + "\0 ", 148, 8, "ascii")
|
|
61
|
+
|
|
62
|
+
const pad = (512 - (size % 512)) % 512
|
|
63
|
+
return Buffer.concat([header, content, Buffer.alloc(pad)])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function packSchemaSources(graph: SchemaSourceGraph): Buffer {
|
|
67
|
+
const chunks: Buffer[] = []
|
|
68
|
+
for (const file of graph.files) {
|
|
69
|
+
const content = readFileSync(file.absolutePath)
|
|
70
|
+
chunks.push(writeTarEntry(file.relativePath.replace(/\\/g, "/"), content))
|
|
71
|
+
}
|
|
72
|
+
chunks.push(Buffer.alloc(1024, 0))
|
|
73
|
+
return Buffer.concat(chunks)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function unpackSchemaSources(tar: Buffer, projectRoot: string): Map<string, Buffer> {
|
|
77
|
+
const root = resolve(projectRoot)
|
|
78
|
+
const out = new Map<string, Buffer>()
|
|
79
|
+
let offset = 0
|
|
80
|
+
while (offset + 512 <= tar.length) {
|
|
81
|
+
const header = tar.subarray(offset, offset + 512)
|
|
82
|
+
offset += 512
|
|
83
|
+
if (header.every((b) => b === 0)) break
|
|
84
|
+
const name = header.subarray(0, 100).toString("utf8").replace(/\0.*$/, "").trim()
|
|
85
|
+
if (!name) break
|
|
86
|
+
const sizeOct = header.subarray(124, 136).toString("utf8").replace(/\0.*$/, "").trim()
|
|
87
|
+
const size = parseInt(sizeOct, 8) || 0
|
|
88
|
+
const content = tar.subarray(offset, offset + size)
|
|
89
|
+
offset += size + ((512 - (size % 512)) % 512)
|
|
90
|
+
const rel = name.replace(/\\/g, "/")
|
|
91
|
+
if (rel.startsWith("..") || rel.includes("/../")) {
|
|
92
|
+
throw new Error(`Invalid tar path: ${name}`)
|
|
93
|
+
}
|
|
94
|
+
const dest = resolve(root, rel)
|
|
95
|
+
if (!dest.startsWith(root)) {
|
|
96
|
+
throw new Error(`Tar path escapes project root: ${name}`)
|
|
97
|
+
}
|
|
98
|
+
out.set(rel, Buffer.from(content))
|
|
99
|
+
}
|
|
100
|
+
return out
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function buildSchemaSourcesPayload(
|
|
104
|
+
cwd: string,
|
|
105
|
+
pushedBy?: string,
|
|
106
|
+
): SchemaSourcesPayload | null {
|
|
107
|
+
const config = loadConfig(cwd)
|
|
108
|
+
const root = projectRootFromConfig(config, cwd)
|
|
109
|
+
const entry = schemaPathFromProject(config, cwd)
|
|
110
|
+
const graph = collectSchemaSourcePaths(entry, root)
|
|
111
|
+
if (graph.files.length === 0) return null
|
|
112
|
+
|
|
113
|
+
const tarBuf = packSchemaSources(graph)
|
|
114
|
+
const gz = gzipSync(tarBuf, { level: 9 })
|
|
115
|
+
|
|
116
|
+
if (gz.length > MAX_COMPRESSED_BYTES) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Schema snapshot too large (${(gz.length / 1024).toFixed(0)} KB compressed, max 2 MB). Split schema modules.`,
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
if (gz.length > WARN_COMPRESSED_BYTES) {
|
|
122
|
+
console.warn(`Warning: large schema snapshot (${(gz.length / 1024).toFixed(0)} KB compressed).`)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const manifest: SchemaSourcesManifest = {
|
|
126
|
+
version: 1,
|
|
127
|
+
format: "tar+gzip",
|
|
128
|
+
entryPoint: graph.entryPoint,
|
|
129
|
+
fileCount: graph.files.length,
|
|
130
|
+
uncompressedBytes: graph.files.reduce((s, f) => s + f.bytes, 0),
|
|
131
|
+
compressedBytes: gz.length,
|
|
132
|
+
files: graph.files.map((f) => ({ path: f.relativePath, sha256: f.sha256, bytes: f.bytes })),
|
|
133
|
+
...(pushedBy ? { pushedBy } : {}),
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
manifest,
|
|
138
|
+
dataBase64: gz.toString("base64"),
|
|
139
|
+
gz,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function cacheSchemaSourcesLocally(cwd: string, migrationName: string, gz: Buffer): void {
|
|
144
|
+
const dir = join(cwd, ".supatype", "schema-snapshots")
|
|
145
|
+
mkdirSync(dir, { recursive: true })
|
|
146
|
+
writeFileSync(join(dir, `${migrationName}.tar.gz`), gz)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function restoreSchemaSourcesFromGz(
|
|
150
|
+
gz: Buffer,
|
|
151
|
+
manifest: SchemaSourcesManifest,
|
|
152
|
+
projectRoot: string,
|
|
153
|
+
opts?: { backupDir?: string },
|
|
154
|
+
): string[] {
|
|
155
|
+
const tar = gunzipSync(gz)
|
|
156
|
+
const files = unpackSchemaSources(tar, projectRoot)
|
|
157
|
+
const root = resolve(projectRoot)
|
|
158
|
+
const restored: string[] = []
|
|
159
|
+
|
|
160
|
+
if (opts?.backupDir) {
|
|
161
|
+
mkdirSync(opts.backupDir, { recursive: true })
|
|
162
|
+
for (const path of manifest.files) {
|
|
163
|
+
const abs = join(root, path.path)
|
|
164
|
+
if (existsSync(abs)) {
|
|
165
|
+
const dest = join(opts.backupDir, path.path)
|
|
166
|
+
mkdirSync(join(dest, ".."), { recursive: true })
|
|
167
|
+
cpSync(abs, dest)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
for (const [rel, content] of files) {
|
|
173
|
+
const abs = join(root, rel)
|
|
174
|
+
mkdirSync(join(abs, ".."), { recursive: true })
|
|
175
|
+
writeFileSync(abs, content)
|
|
176
|
+
restored.push(rel)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return restored
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function findOrphanSchemaFiles(
|
|
183
|
+
projectRoot: string,
|
|
184
|
+
entryPoint: string,
|
|
185
|
+
manifestPaths: Set<string>,
|
|
186
|
+
): string[] {
|
|
187
|
+
const entry = resolve(projectRoot, entryPoint)
|
|
188
|
+
const graph = collectSchemaSourcePaths(entry, projectRoot)
|
|
189
|
+
const orphans: string[] = []
|
|
190
|
+
const schemaDir = join(projectRoot, graph.entryPoint.split("/").slice(0, -1).join("/") || ".")
|
|
191
|
+
if (!existsSync(schemaDir)) return orphans
|
|
192
|
+
|
|
193
|
+
const walk = (dir: string): void => {
|
|
194
|
+
for (const ent of readdirSync(dir, { withFileTypes: true })) {
|
|
195
|
+
const abs = join(dir, ent.name)
|
|
196
|
+
if (ent.isDirectory()) {
|
|
197
|
+
walk(abs)
|
|
198
|
+
continue
|
|
199
|
+
}
|
|
200
|
+
if (!/\.(ts|tsx)$/.test(ent.name)) continue
|
|
201
|
+
const rel = relative(projectRoot, abs).replace(/\\/g, "/")
|
|
202
|
+
if (!manifestPaths.has(rel) && !graph.files.some((f) => f.relativePath === rel)) {
|
|
203
|
+
orphans.push(rel)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
walk(schemaDir)
|
|
208
|
+
return orphans
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function resolvePushedBy(): string {
|
|
212
|
+
return (
|
|
213
|
+
process.env["SUPATYPE_PUSHED_BY"] ??
|
|
214
|
+
process.env["USER"] ??
|
|
215
|
+
process.env["USERNAME"] ??
|
|
216
|
+
"local"
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface SchemaSourcePushArtifacts {
|
|
221
|
+
gzPath: string
|
|
222
|
+
manifestPath: string
|
|
223
|
+
/** Paths inside the Docker /project bind mount. */
|
|
224
|
+
dockerGzPath: string
|
|
225
|
+
dockerManifestPath: string
|
|
226
|
+
payload: SchemaSourcesPayload
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Write schema source blob + manifest under `.supatype/` for engine push (CLI + dev watch). */
|
|
230
|
+
export function writeSchemaSourcePushArtifacts(cwd: string): SchemaSourcePushArtifacts | null {
|
|
231
|
+
const payload = buildSchemaSourcesPayload(cwd, resolvePushedBy())
|
|
232
|
+
if (!payload) return null
|
|
233
|
+
|
|
234
|
+
const dir = join(cwd, ".supatype")
|
|
235
|
+
mkdirSync(dir, { recursive: true })
|
|
236
|
+
const gzPath = join(dir, "schema-sources-push.gz")
|
|
237
|
+
const manifestPath = join(dir, "schema-sources-manifest.json")
|
|
238
|
+
writeFileSync(gzPath, payload.gz)
|
|
239
|
+
writeFileSync(manifestPath, JSON.stringify(payload.manifest))
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
gzPath,
|
|
243
|
+
manifestPath,
|
|
244
|
+
dockerGzPath: "/project/.supatype/schema-sources-push.gz",
|
|
245
|
+
dockerManifestPath: "/project/.supatype/schema-sources-manifest.json",
|
|
246
|
+
payload,
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -38,7 +38,13 @@ async function main() {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (anyFailed) {
|
|
41
|
-
|
|
41
|
+
// npm hides postinstall output unless --foreground-scripts, so don't rely on
|
|
42
|
+
// this being seen: the CLI re-attempts the download (with retry) on first use.
|
|
43
|
+
console.error(
|
|
44
|
+
"[supatype] Some component binaries failed to download. " +
|
|
45
|
+
"They will be re-downloaded automatically on first use; " +
|
|
46
|
+
"run 'supatype update' to retry now.",
|
|
47
|
+
)
|
|
42
48
|
} else {
|
|
43
49
|
console.log("[supatype] All component binaries downloaded successfully.")
|
|
44
50
|
}
|