@rebasepro/cli 0.10.0 → 0.10.1-canary.0a881d4

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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/bundle.d.ts +146 -0
  3. package/dist/commands/apps.d.ts +1 -0
  4. package/dist/commands/build.d.ts +1 -1
  5. package/dist/commands/cloud/bundle-deploy.d.ts +53 -0
  6. package/dist/commands/cloud/context.d.ts +28 -0
  7. package/dist/commands/cloud/deployments.d.ts +16 -0
  8. package/dist/commands/cloud/env.d.ts +2 -0
  9. package/dist/commands/cloud/resources.d.ts +38 -0
  10. package/dist/commands/generate_sdk.d.ts +12 -0
  11. package/dist/commands/start.d.ts +1 -1
  12. package/dist/fold-static.d.ts +46 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.es.js +2567 -100
  15. package/dist/index.es.js.map +1 -1
  16. package/dist/manifest.d.ts +83 -0
  17. package/dist/utils/package-manager.d.ts +26 -2
  18. package/dist/utils/project.d.ts +11 -3
  19. package/package.json +8 -7
  20. package/runtime/dev-server.mjs +43 -0
  21. package/templates/overlays/baas/backend/src/index.ts +28 -4
  22. package/templates/overlays/baas/backend/src/storage.ts +71 -0
  23. package/templates/overlays/baas/rebase.json +14 -0
  24. package/templates/template/.env.example +16 -3
  25. package/templates/template/README.md +39 -29
  26. package/templates/template/backend/src/index.ts +28 -4
  27. package/templates/template/config/admin.d.ts +9 -0
  28. package/templates/template/config/collections/authors.ts +11 -9
  29. package/templates/template/config/collections/posts.ts +6 -4
  30. package/templates/template/config/collections/presets/ecommerce/categories.ts +7 -5
  31. package/templates/template/config/collections/presets/ecommerce/orders.ts +32 -20
  32. package/templates/template/config/collections/presets/ecommerce/products.ts +21 -13
  33. package/templates/template/config/collections/tags.ts +5 -3
  34. package/templates/template/config/collections/users.ts +34 -29
  35. package/templates/template/config/frontend-assets.d.ts +17 -0
  36. package/templates/template/config/index.ts +6 -0
  37. package/templates/template/config/package.json +26 -25
  38. package/templates/template/config/storage.ts +88 -0
  39. package/templates/template/gitignore +4 -0
  40. package/templates/template/rebase.json +20 -0
package/README.md CHANGED
@@ -20,7 +20,7 @@ The CLI is also bundled with every Rebase project as a local dependency.
20
20
  | `rebase start` | Start the backend server (production) |
21
21
  | `rebase schema generate` | Generate Drizzle schema from collection definitions |
22
22
  | `rebase schema introspect` | Introspect an existing database → Rebase collections |
23
- | `rebase db push` | Apply schema directly to database (dev) |
23
+ | `rebase db push` | Apply schema directly to database (dev). Previews the plan and refuses destructive changes (e.g. dropped columns) unless confirmed interactively or run with `--allow-destructive`. |
24
24
  | `rebase db generate` | Generate SQL migration files |
25
25
  | `rebase db migrate` | Run pending migrations |
26
26
  | `rebase generate-sdk` | Generate a typed TypeScript SDK from collections |
@@ -0,0 +1,146 @@
1
+ import { type NativeDependency, type RebaseBundleManifest, type RebaseBackendAppConfig } from "@rebasepro/types";
2
+ export declare const DEFAULT_BUNDLE_DIR = "dist-bundle";
3
+ export interface BuildBundleOptions {
4
+ projectRoot: string;
5
+ appName: string;
6
+ app: RebaseBackendAppConfig;
7
+ /** Output directory, absolute or relative to the project root. */
8
+ outDir?: string;
9
+ /** Runtime range from the manifest, recorded for compatibility checks. */
10
+ runtimeRange: string;
11
+ /** Skip type checking. Faster, and strictly worse — for iteration only. */
12
+ skipTypeCheck?: boolean;
13
+ /** Skip regenerating the Drizzle schema from the collections. */
14
+ skipSchema?: boolean;
15
+ /** Emit progress. */
16
+ log?: (message: string) => void;
17
+ }
18
+ export interface BuildBundleResult {
19
+ outDir: string;
20
+ manifest: RebaseBundleManifest;
21
+ collectionCount: number;
22
+ }
23
+ /**
24
+ * Whether the compiled config package exports a `storageAuthorize` hook.
25
+ *
26
+ * Recorded in the manifest so a host can refuse a deploy that would enable file
27
+ * storage with no access model, rather than let the runtime's boot guard turn it
28
+ * into a crash loop the developer cannot read.
29
+ *
30
+ * Read from the *compiled* index, deliberately: that is the exact module the
31
+ * runtime imports and reads the export off, so this cannot disagree with what
32
+ * actually happens at boot. It is a textual check rather than an import because
33
+ * a freshly built bundle cannot resolve its own dependencies until it is
34
+ * deployed — the same reason schema hashing reads source.
35
+ *
36
+ * Errs toward `false`: a missed detection costs a deploy rejection whose message
37
+ * says exactly how to proceed, while a false positive would hand back the crash
38
+ * loop this exists to prevent.
39
+ */
40
+ export declare function detectStorageAuthorize(compiledConfigDir: string): boolean;
41
+ /**
42
+ * Detect native code in the dependency closure.
43
+ *
44
+ * Walks declared runtime dependencies breadth-first through `node_modules`,
45
+ * flagging anything with a `binding.gyp`, a prebuilt `.node` binary, or an
46
+ * install script that builds one. The managed runtime cannot run these: a
47
+ * binary compiled for one image will not load in another, and finding that out
48
+ * at deploy time is far better than in a crash loop.
49
+ *
50
+ * The walk is bounded. A dependency graph can be enormous, and this is a
51
+ * heuristic gate whose false negatives are caught at deploy time anyway.
52
+ */
53
+ export declare function detectNativeDependencies(projectRoot: string, declared: Record<string, string>, limit?: number): NativeDependency[];
54
+ /**
55
+ * Collect the runtime dependencies a bundle needs installed beside it.
56
+ *
57
+ * Packages the runtime image already provides are excluded — reinstalling a
58
+ * second copy of the server next to the one running the process is at best
59
+ * wasted space and at worst a version conflict. Workspace packages are excluded
60
+ * too: they are not on the registry the runtime installs from, and the project's
61
+ * own config package already travels inside the bundle.
62
+ */
63
+ export declare function collectDeclaredDependencies(projectRoot: string): Record<string, string>;
64
+ /**
65
+ * Rewrite relative import specifiers in emitted JavaScript so Node can resolve them.
66
+ *
67
+ * TypeScript deliberately does not touch specifiers: `moduleResolution: "bundler"`
68
+ * lets a project write `from "./posts"` or `from "./collections"`, and TypeScript
69
+ * emits them unchanged on the assumption that a bundler will finish the job.
70
+ * Nothing bundles a Rebase bundle — the runtime imports these files directly with
71
+ * Node's ESM loader, which requires a full path with an extension and refuses
72
+ * directory imports outright.
73
+ *
74
+ * Without this, adopting the bundle would mean asking every project written in
75
+ * the (extremely common) extensionless style to rewrite all of its imports. The
76
+ * rewrite is mechanical and verifiable: only relative specifiers are touched, and
77
+ * only when the target file actually exists on disk.
78
+ */
79
+ export declare function normalizeEsmSpecifiers(outDir: string): {
80
+ rewritten: number;
81
+ unresolved: string[];
82
+ };
83
+ /**
84
+ * Compile and assemble a bundle.
85
+ */
86
+ export declare function buildBundle(options: BuildBundleOptions): Promise<BuildBundleResult>;
87
+ /**
88
+ * Package a built static app (a `static` or bundled-`admin` app) into a bundle.
89
+ *
90
+ * A static bundle is the counterpart to a backend bundle: the same shape, the
91
+ * same runtime image runs it, but its manifest says `mode: "static"` and it
92
+ * carries only the built assets under `static/`. That is what lets a frontend or
93
+ * admin app be its own deployable, scalable unit rather than something baked into
94
+ * the backend container.
95
+ *
96
+ * `assetsDir` is the app's built output (e.g. `frontend/dist`), already produced
97
+ * by its own build command. This copies it into the bundle and writes the
98
+ * manifest — no compilation, no dependency closure (a static bundle installs
99
+ * nothing at boot).
100
+ */
101
+ /**
102
+ * Fold a built static app into a backend bundle, so one runtime serves both.
103
+ *
104
+ * ## Why this exists
105
+ *
106
+ * A managed tenant runs one pod, and `bootFromBundle` on the backend path already
107
+ * knows how to serve a SPA — it looks for `entry.static` and mounts `serveSPA`
108
+ * last, behind `REBASE_SERVE_STATIC`. What was missing was anything putting the
109
+ * assets there.
110
+ *
111
+ * The consequence was not subtle. A project whose custom image served its website
112
+ * at `/` and its API at `/api` — the shape the scaffolded template produces — lost
113
+ * the website the moment it moved to the managed runtime: the API answered
114
+ * perfectly and every page 404'd. Managed could not be a drop-in replacement for
115
+ * custom while the frontend simply vanished.
116
+ *
117
+ * Folding restores parity with the container it replaces, which is the only
118
+ * honest baseline. It is deliberately the FIRST implementation and not the last:
119
+ * a static app on its own bucket behind a CDN is better for cache behaviour and
120
+ * lets the frontend deploy independently. But that needs infrastructure that does
121
+ * not exist yet, and "your site is gone" is not an acceptable state to leave a
122
+ * project in while it gets built.
123
+ *
124
+ * The trade it makes, stated plainly: frontend and backend now deploy together
125
+ * and the bundle carries the built assets. For a project that was shipping both
126
+ * in one image already, that is exactly what it had.
127
+ */
128
+ export declare function foldStaticIntoBundle(options: {
129
+ /** The backend bundle directory, already written. */
130
+ bundleDir: string;
131
+ /** Directory of built frontend assets (the static app's `output`). */
132
+ assetsDir: string;
133
+ }): {
134
+ fileCount: number;
135
+ };
136
+ export declare function buildStaticBundle(options: {
137
+ projectRoot: string;
138
+ appName: string;
139
+ assetsDir: string;
140
+ outDir: string;
141
+ runtimeRange: string;
142
+ }): {
143
+ outDir: string;
144
+ manifest: RebaseBundleManifest;
145
+ fileCount: number;
146
+ };
@@ -0,0 +1 @@
1
+ export declare function appsCommand(subcommand: string | undefined, rawArgs?: string[]): Promise<void>;
@@ -1 +1 @@
1
- export declare function buildCommand(): Promise<void>;
1
+ export declare function buildCommand(rawArgs?: string[]): Promise<void>;
@@ -0,0 +1,53 @@
1
+ import type { RebaseBundleManifest } from "@rebasepro/types";
2
+ /** Read and shallow-validate a built bundle's manifest. */
3
+ export declare function readBundleManifest(bundleDir: string): RebaseBundleManifest;
4
+ /**
5
+ * Tar a built bundle into a gzipped archive.
6
+ *
7
+ * `node_modules` is excluded on purpose: the bundle ships a `package.json`, and
8
+ * the managed runtime installs the declared dependencies at boot. Uploading an
9
+ * installed `node_modules` would bloat the archive and could carry a
10
+ * platform-specific build that will not run on the runtime image.
11
+ */
12
+ export declare function packBundle(bundleDir: string, outPath: string): Promise<void>;
13
+ /**
14
+ * Assemble the deploy-trigger body for a bundle deploy.
15
+ *
16
+ * The manifest travels with the trigger so the control plane can validate intake
17
+ * without unpacking the uploaded archive first — a rejection (native deps, no
18
+ * matching runtime) is then a fast, cheap answer.
19
+ */
20
+ export declare function bundleDeployBody(input: {
21
+ projectId: string;
22
+ bundleId: string;
23
+ manifest: RebaseBundleManifest;
24
+ app?: string;
25
+ message?: string;
26
+ /**
27
+ * Every app this repository declares in `rebase.json`, so the platform can
28
+ * register the whole set rather than only the one being deployed.
29
+ */
30
+ declaredApps?: DeclaredApp[];
31
+ }): Record<string, unknown>;
32
+ /** An app as `rebase.json` declares it, reduced to what the registry stores. */
33
+ export interface DeclaredApp {
34
+ name: string;
35
+ type: string;
36
+ }
37
+ /**
38
+ * The apps a project manifest declares.
39
+ *
40
+ * A deploy only ever ships ONE app's bundle, so the trigger alone could never
41
+ * tell the platform that the repository also contains a web frontend and an
42
+ * admin panel — and the Apps page, whose whole job is to show the set, listed a
43
+ * single entry called "backend". Sending the declared set fixes that without
44
+ * pretending the others are deployed: the platform registers them, and their
45
+ * status says what is actually true.
46
+ */
47
+ export declare function declaredAppsFrom(manifest: {
48
+ apps?: Record<string, {
49
+ type?: string;
50
+ }>;
51
+ } | null | undefined): DeclaredApp[];
52
+ /** Upload a bundle archive; returns the control-plane bundle id. */
53
+ export declare function uploadBundle(url: string, token: string, projectId: string, tarPath: string): Promise<string>;
@@ -62,6 +62,24 @@ export interface ProjectLink {
62
62
  slug?: string;
63
63
  projectName?: string;
64
64
  orgId?: string;
65
+ /**
66
+ * Base URL of the project's own API.
67
+ *
68
+ * For a cloud project this is a convenience derived from the subdomain. For
69
+ * a **self-hosted** project it is the entire link: there is no control plane
70
+ * to look anything up in, so `projectId` is empty and this is what commands
71
+ * resolve against.
72
+ *
73
+ * Keeping both kinds of link in one file is deliberate. A second link file
74
+ * for self-hosting would fork every command that reads one, and the tooling
75
+ * would drift into being cloud-only by accident.
76
+ */
77
+ apiUrl?: string;
78
+ /**
79
+ * How this checkout is linked. Absent means `cloud` — which is every link
80
+ * written before this field existed.
81
+ */
82
+ mode?: "cloud" | "direct";
65
83
  }
66
84
  export declare function readLink(cwd?: string): ProjectLink | null;
67
85
  export declare function writeLink(link: ProjectLink, cwd?: string): void;
@@ -100,6 +118,16 @@ export declare function initOutputMode(rawArgs: string[]): boolean;
100
118
  export declare function isJsonMode(): boolean;
101
119
  /** Force the mode (tests only — production latches it via `initOutputMode`). */
102
120
  export declare function setJsonModeForTest(value: boolean): void;
121
+ /**
122
+ * Write one JSON value to stdout, followed by a newline.
123
+ *
124
+ * Indented, because the overwhelmingly common reader is a person or an agent
125
+ * looking at a terminal — JSON mode is entered automatically whenever stdout is
126
+ * not a TTY, so `rebase cloud deployments list` piped anywhere at all produced
127
+ * a project's entire deployment history as one unwrapped line. `JSON.parse`
128
+ * does not care about the whitespace; everything else does.
129
+ */
130
+ export declare function printJson(value: unknown): void;
103
131
  /**
104
132
  * The one output primitive every new command uses: in JSON mode emit `json`
105
133
  * (and nothing else); otherwise run `human`. Keeping the two behind a single
@@ -18,6 +18,10 @@ export interface DeploymentRow {
18
18
  triggered_by_user_id?: string;
19
19
  gitCommitHash?: string;
20
20
  gitCommitMessage?: string;
21
+ deployMessage?: string;
22
+ deploy_message?: string;
23
+ frameworkVersion?: string;
24
+ framework_version?: string;
21
25
  }
22
26
  /**
23
27
  * The backend's rule EXACTLY: a rollback is honoured only for a successful
@@ -33,6 +37,18 @@ export declare function triggerInfo(dep: DeploymentRow): {
33
37
  };
34
38
  /** Shape one deployment row into the stable JSON view the CLI publishes. */
35
39
  export declare function deploymentView(dep: DeploymentRow): Record<string, unknown>;
40
+ /**
41
+ * Rows shown when `--limit` is not given.
42
+ *
43
+ * History is unbounded and grows one row per deploy, so "all of it" is the
44
+ * wrong default in both directions: a wall of near-identical lines in a
45
+ * terminal, and — since JSON mode is entered automatically for any non-TTY
46
+ * stdout — a project's entire history dumped at anything that pipes the
47
+ * command. Recent deploys are what the question is almost always about.
48
+ */
49
+ export declare const DEFAULT_DEPLOYMENTS_LIMIT = 20;
50
+ /** `--limit N`, bounded. A garbage value is a refusal, never a silent default. */
51
+ export declare function parseDeploymentsLimit(raw: number | undefined): number;
36
52
  export declare function deploymentsListCommand(rawArgs: string[]): Promise<void>;
37
53
  export declare function rollbackCommand(rawArgs: string[]): Promise<void>;
38
54
  export declare function cancelCommand(rawArgs: string[]): Promise<void>;
@@ -4,3 +4,5 @@ export declare function parseEnvAssignment(operands: string[]): {
4
4
  key: string;
5
5
  value: string;
6
6
  } | null;
7
+ /** The prefix that makes `key` a build-time variable, or undefined. */
8
+ export declare function buildTimeEnvPrefix(key: string): string | undefined;
@@ -1,6 +1,44 @@
1
+ /** The control plane's verdict on what a tenant's uploads actually do. */
2
+ interface StorageState {
3
+ effective?: {
4
+ kind?: string;
5
+ summary?: string;
6
+ storageType?: string;
7
+ missing?: string[];
8
+ };
9
+ source?: string;
10
+ configured?: string;
11
+ overridden?: boolean;
12
+ }
13
+ /**
14
+ * One line describing this project's storage — or `undefined` when the control
15
+ * plane could not be asked, which prints as a blank rather than a guess.
16
+ *
17
+ * `status` used to render the `storages` row and nothing else, so a project
18
+ * whose bucket is configured through its own `STORAGE_TYPE`/`S3_*` variables —
19
+ * the supported path, and the one `mergeStorageEnv` deliberately lets WIN over
20
+ * the row — was reported as `Storage: none` while its pod logged `Initialized
21
+ * storage backends count: 1` against a live bucket. Storage is the thing an app
22
+ * refuses to boot without, so that false negative sends someone off to
23
+ * provision a bucket they already have. The row is not the answer; the tenant's
24
+ * resolved environment is, and the control plane computes it with the same two
25
+ * functions the build log uses.
26
+ */
27
+ export declare function describeStorageState(state: StorageState | undefined): string | undefined;
28
+ /**
29
+ * One line describing the database.
30
+ *
31
+ * `connectionStatus` is written `"untested"` at creation and only ever changed
32
+ * by `rebase cloud db test`, so `managed (untested)` was reporting the absence
33
+ * of a manual test as though it were the database's condition — on a project
34
+ * that had just deployed against it. A never-tested database says only its
35
+ * type; the verdict appears once there is one.
36
+ */
37
+ export declare function describeDatabaseState(db: Record<string, unknown> | undefined): string | undefined;
1
38
  export declare function statusCommand(rawArgs: string[]): Promise<void>;
2
39
  export declare function metricsCommand(rawArgs: string[]): Promise<void>;
3
40
  export declare function webhooksCommand(subcommand: string | undefined, rawArgs: string[]): Promise<void>;
4
41
  export declare function storageCommand(action: string | undefined, rawArgs: string[]): Promise<void>;
5
42
  export declare function clustersCommand(rawArgs: string[]): Promise<void>;
6
43
  export declare function billingCommand(rawArgs: string[]): Promise<void>;
44
+ export {};
@@ -10,6 +10,18 @@ interface GenerateSDKArgs {
10
10
  collectionsDir: string;
11
11
  output: string;
12
12
  cwd: string;
13
+ /**
14
+ * Where to read the schema from instead of local source.
15
+ *
16
+ * `link` uses this checkout's linked project; anything else is treated as
17
+ * the base URL of a Rebase backend. This is what lets a repository that
18
+ * contains no collections — a separate frontend, a second web app — generate
19
+ * a typed client from the project it talks to.
20
+ */
21
+ from?: string;
22
+ /** Bearer token for the contract endpoint. Falls back to REBASE_SERVICE_KEY. */
23
+ token?: string;
24
+ help?: boolean;
13
25
  }
14
26
  /**
15
27
  * Main entry point for the generate-sdk command.
@@ -1 +1 @@
1
- export declare function startCommand(): Promise<void>;
1
+ export declare function startCommand(rawArgs?: string[]): Promise<void>;
@@ -0,0 +1,46 @@
1
+ /** The apps section of a project manifest, as much of it as folding needs. */
2
+ export interface FoldableManifest {
3
+ apps?: Record<string, {
4
+ type?: string;
5
+ build?: string;
6
+ output?: string;
7
+ }>;
8
+ }
9
+ export interface FoldOptions {
10
+ projectRoot: string;
11
+ manifest: FoldableManifest;
12
+ /** The backend bundle directory, already written. */
13
+ bundleDir: string;
14
+ /** Skip running the app's own build command; fold what is already built. */
15
+ skipBuild?: boolean;
16
+ log?: (message: string) => void;
17
+ }
18
+ export interface FoldOutcome {
19
+ appName: string;
20
+ fileCount: number;
21
+ }
22
+ /**
23
+ * Which static app, if any, should be served by the backend.
24
+ *
25
+ * Exactly one `static` app is folded. With several, folding would have to choose,
26
+ * and silently picking one of two websites is worse than doing nothing — so it
27
+ * declines and names what it saw. Pure, so the decision is testable without a
28
+ * filesystem.
29
+ */
30
+ export declare function selectFoldableApp(manifest: FoldableManifest): {
31
+ app?: {
32
+ name: string;
33
+ build?: string;
34
+ output?: string;
35
+ };
36
+ /** Why nothing will be folded, when that is the answer. */
37
+ reason?: string;
38
+ };
39
+ /**
40
+ * Build the project's frontend and fold it into the backend bundle.
41
+ *
42
+ * Throws rather than exiting, so the caller decides whether a missing frontend
43
+ * should fail its command — a `build` may reasonably want to stop, and so should
44
+ * a deploy, but that is not this function's call to make.
45
+ */
46
+ export declare function foldFrontendIntoBundle(options: FoldOptions): Promise<FoldOutcome | null>;
package/dist/index.d.ts CHANGED
@@ -9,5 +9,8 @@ export * from "./commands/auth";
9
9
  export * from "./commands/doctor";
10
10
  export * from "./commands/generate_sdk";
11
11
  export * from "./commands/cloud";
12
+ export * from "./commands/apps";
12
13
  export * from "./utils/project";
13
14
  export * from "./utils/package-manager";
15
+ export * from "./manifest";
16
+ export * from "./bundle";