@rebasepro/server 0.16.0 → 0.16.1-canary.g2d1aec8

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 (160) hide show
  1. package/dist/api/contract-routes.d.ts +1 -1
  2. package/dist/api/errors.d.ts +1 -1
  3. package/dist/api/index.d.ts +3 -3
  4. package/dist/api/live-schema-routes.d.ts +111 -0
  5. package/dist/api/logs-routes.d.ts +1 -1
  6. package/dist/api/mount.d.ts +41 -0
  7. package/dist/api/rest/api-generator.d.ts +2 -2
  8. package/dist/api/rest/index.d.ts +1 -1
  9. package/dist/api/rest/query-parser.d.ts +1 -1
  10. package/dist/api/schema-editor-routes.d.ts +1 -1
  11. package/dist/api/types.d.ts +3 -4
  12. package/dist/{schema-editor-routes-CV9k0w3G.js → ast-schema-editor-BpFYpT38.js} +2 -39
  13. package/dist/ast-schema-editor-BpFYpT38.js.map +1 -0
  14. package/dist/auth/adapter-middleware.d.ts +2 -2
  15. package/dist/auth/admin-roles-route.d.ts +2 -2
  16. package/dist/auth/admin-user-ops.d.ts +3 -3
  17. package/dist/auth/admin-users-route.d.ts +4 -4
  18. package/dist/auth/api-keys/api-key-middleware.d.ts +2 -2
  19. package/dist/auth/api-keys/api-key-permission-guard.d.ts +1 -1
  20. package/dist/auth/api-keys/api-key-routes.d.ts +2 -2
  21. package/dist/auth/api-keys/api-key-store.d.ts +1 -1
  22. package/dist/auth/api-keys/index.d.ts +9 -9
  23. package/dist/auth/apple-oauth.d.ts +2 -2
  24. package/dist/auth/auth-hooks.d.ts +3 -3
  25. package/dist/auth/bitbucket-oauth.d.ts +2 -2
  26. package/dist/auth/builtin-auth-adapter.d.ts +7 -4
  27. package/dist/auth/captcha.d.ts +86 -0
  28. package/dist/auth/cookie-utils.d.ts +2 -2
  29. package/dist/auth/discord-oauth.d.ts +2 -2
  30. package/dist/auth/facebook-oauth.d.ts +2 -2
  31. package/dist/auth/github-oauth.d.ts +2 -2
  32. package/dist/auth/gitlab-oauth.d.ts +2 -2
  33. package/dist/auth/google-oauth.d.ts +1 -1
  34. package/dist/auth/index.d.ts +56 -54
  35. package/dist/auth/jwks-routes.d.ts +1 -1
  36. package/dist/auth/jwt.d.ts +1 -1
  37. package/dist/auth/linkedin-oauth.d.ts +2 -2
  38. package/dist/auth/magic-link-routes.d.ts +10 -3
  39. package/dist/auth/mfa-gate.d.ts +1 -1
  40. package/dist/auth/mfa-routes.d.ts +3 -3
  41. package/dist/auth/microsoft-oauth.d.ts +2 -2
  42. package/dist/auth/middleware.d.ts +5 -5
  43. package/dist/auth/rate-limiter.d.ts +2 -2
  44. package/dist/auth/require-auth.d.ts +1 -1
  45. package/dist/auth/reset-password-admin.d.ts +4 -4
  46. package/dist/auth/routes.d.ts +13 -4
  47. package/dist/auth/session-routes.d.ts +3 -3
  48. package/dist/auth/slack-oauth.d.ts +2 -2
  49. package/dist/auth/spotify-oauth.d.ts +2 -2
  50. package/dist/auth/token-revocation.d.ts +2 -2
  51. package/dist/auth/twitter-oauth.d.ts +2 -2
  52. package/dist/{auth-5Et5mnUA.js → auth-C74dqR2B.js} +250 -15
  53. package/dist/auth-C74dqR2B.js.map +1 -0
  54. package/dist/backup/backup-common.d.ts +1 -1
  55. package/dist/backup/backup-routes.d.ts +3 -3
  56. package/dist/backup/index.d.ts +3 -3
  57. package/dist/{backup-C6ljYVTp.js → backup-BJ86ah4T.js} +2 -2
  58. package/dist/{backup-C6ljYVTp.js.map → backup-BJ86ah4T.js.map} +1 -1
  59. package/dist/boot/boot.d.ts +5 -5
  60. package/dist/boot/bundle.d.ts +1 -1
  61. package/dist/boot/driver.d.ts +1 -1
  62. package/dist/boot/env.d.ts +13 -1
  63. package/dist/boot/options.d.ts +30 -6
  64. package/dist/boot/role.d.ts +3 -2
  65. package/dist/boot/sources.d.ts +1 -1
  66. package/dist/collections/BackendCollectionRegistry.d.ts +1 -1
  67. package/dist/collections/loader.d.ts +1 -1
  68. package/dist/{contract-routes-DZ-LBpSL.js → contract-routes-BEq7euZg.js} +2 -2
  69. package/dist/contract-routes-BEq7euZg.js.map +1 -0
  70. package/dist/cron/cron-routes.d.ts +2 -2
  71. package/dist/cron/cron-scheduler.d.ts +2 -2
  72. package/dist/cron/index.d.ts +8 -8
  73. package/dist/{cron-loader-YhhQeVBM.js → cron-loader-BMvtW6-J.js} +2 -2
  74. package/dist/{cron-loader-YhhQeVBM.js.map → cron-loader-BMvtW6-J.js.map} +1 -1
  75. package/dist/{cron-routes-maM_RlUu.js → cron-routes-BvYk-Kmi.js} +2 -2
  76. package/dist/{cron-routes-maM_RlUu.js.map → cron-routes-BvYk-Kmi.js.map} +1 -1
  77. package/dist/{cron-scheduler-DIpYBmZP.js → cron-scheduler-Buf-uVam.js} +2 -2
  78. package/dist/{cron-scheduler-DIpYBmZP.js.map → cron-scheduler-Buf-uVam.js.map} +1 -1
  79. package/dist/{cron-store-DfH_4Cd9.js → cron-store-CyF-oInV.js} +3 -3
  80. package/dist/{cron-store-DfH_4Cd9.js.map → cron-store-CyF-oInV.js.map} +1 -1
  81. package/dist/{ddl-bootstrap-Cywoj8Ta.js → ddl-bootstrap-DgSnERYN.js} +17 -3
  82. package/dist/ddl-bootstrap-DgSnERYN.js.map +1 -0
  83. package/dist/dev-secrets.d.ts +52 -0
  84. package/dist/email/dev-sink.d.ts +67 -0
  85. package/dist/email/index.d.ts +9 -7
  86. package/dist/email/link-base.d.ts +1 -1
  87. package/dist/email/smtp-email-service.d.ts +1 -1
  88. package/dist/env.d.ts +1 -1
  89. package/dist/{errors-EBYiaJ2E.js → errors-D_LwNKRM.js} +5 -5
  90. package/dist/errors-D_LwNKRM.js.map +1 -0
  91. package/dist/{function-loader-DDS1v7YX.js → function-loader-BrLmC_-y.js} +3 -3
  92. package/dist/{function-loader-DDS1v7YX.js.map → function-loader-BrLmC_-y.js.map} +1 -1
  93. package/dist/functions/context.d.ts +141 -0
  94. package/dist/functions/define-function.d.ts +1 -1
  95. package/dist/functions/function-routes.d.ts +2 -2
  96. package/dist/functions/guards.d.ts +76 -0
  97. package/dist/functions/index.d.ts +96 -5
  98. package/dist/functions/index.js +919 -0
  99. package/dist/functions/index.js.map +1 -0
  100. package/dist/functions/internal.d.ts +26 -0
  101. package/dist/functions/proxy.d.ts +1 -1
  102. package/dist/functions/request-timeout.d.ts +9 -1
  103. package/dist/functions/runtime-env.d.ts +92 -0
  104. package/dist/functions/wait-until.d.ts +74 -0
  105. package/dist/history/history-routes.d.ts +2 -2
  106. package/dist/history/index.d.ts +1 -1
  107. package/dist/index.d.ts +63 -54
  108. package/dist/index.es.js +2183 -164
  109. package/dist/index.es.js.map +1 -1
  110. package/dist/init/docs.d.ts +1 -1
  111. package/dist/init/middlewares.d.ts +1 -1
  112. package/dist/init/shutdown.d.ts +4 -0
  113. package/dist/init/storage.d.ts +1 -1
  114. package/dist/init/surfaces.d.ts +10 -0
  115. package/dist/init.d.ts +104 -18
  116. package/dist/jobs/index.d.ts +5 -5
  117. package/dist/{jobs-CyOKXXlu.js → jobs-Bn6nhY8J.js} +3 -3
  118. package/dist/{jobs-CyOKXXlu.js.map → jobs-Bn6nhY8J.js.map} +1 -1
  119. package/dist/{jwt-DxH9fLPt.js → jwt-BbJi0TR0.js} +2 -2
  120. package/dist/{jwt-DxH9fLPt.js.map → jwt-BbJi0TR0.js.map} +1 -1
  121. package/dist/{logger-DfvF_8r-.js → logger-TdvXIGqR.js} +101 -8
  122. package/dist/logger-TdvXIGqR.js.map +1 -0
  123. package/dist/metrics/index.d.ts +1 -1
  124. package/dist/{proxy-Bj5DVllb.js → proxy-QJKSS-CV.js} +5 -3
  125. package/dist/{proxy-Bj5DVllb.js.map → proxy-QJKSS-CV.js.map} +1 -1
  126. package/dist/{request-timeout-BuFoEKwT.js → request-timeout-OofPCHQT.js} +17 -3
  127. package/dist/request-timeout-OofPCHQT.js.map +1 -0
  128. package/dist/rls-audit/index.d.ts +111 -0
  129. package/dist/schema-edit/apply-schema-change.d.ts +141 -0
  130. package/dist/schema-edit/github-repository.d.ts +67 -0
  131. package/dist/schema-edit/local-git-repository.d.ts +28 -0
  132. package/dist/schema-edit/project-root.d.ts +29 -0
  133. package/dist/schema-edit/remote-source.d.ts +25 -0
  134. package/dist/schema-edit/schema-edit-permissions.d.ts +129 -0
  135. package/dist/schema-editor-routes-yh2cQcdJ.js +44 -0
  136. package/dist/schema-editor-routes-yh2cQcdJ.js.map +1 -0
  137. package/dist/services/webhook-service.d.ts +1 -1
  138. package/dist/singleton.d.ts +7 -0
  139. package/dist/storage/GCSStorageController.d.ts +1 -1
  140. package/dist/storage/LocalStorageController.d.ts +1 -1
  141. package/dist/storage/S3StorageController.d.ts +1 -1
  142. package/dist/storage/cache-headers.d.ts +87 -0
  143. package/dist/storage/index.d.ts +11 -11
  144. package/dist/storage/policies.d.ts +88 -0
  145. package/dist/storage/range.d.ts +63 -0
  146. package/dist/storage/routes.d.ts +3 -3
  147. package/dist/storage/storage-registry.d.ts +1 -1
  148. package/dist/storage/tus-handler.d.ts +2 -2
  149. package/dist/utils/host.d.ts +58 -0
  150. package/dist/utils/logger.d.ts +0 -15
  151. package/dist/utils/request-id.d.ts +1 -1
  152. package/functions/package.json +24 -0
  153. package/package.json +13 -7
  154. package/dist/auth-5Et5mnUA.js.map +0 -1
  155. package/dist/contract-routes-DZ-LBpSL.js.map +0 -1
  156. package/dist/ddl-bootstrap-Cywoj8Ta.js.map +0 -1
  157. package/dist/errors-EBYiaJ2E.js.map +0 -1
  158. package/dist/logger-DfvF_8r-.js.map +0 -1
  159. package/dist/request-timeout-BuFoEKwT.js.map +0 -1
  160. package/dist/schema-editor-routes-CV9k0w3G.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { Hono } from "hono";
2
2
  import { type CollectionConfig } from "@rebasepro/types";
3
- import type { HonoEnv } from "./types";
3
+ import type { HonoEnv } from "./types.js";
4
4
  /**
5
5
  * The project contract endpoint.
6
6
  *
@@ -1,5 +1,5 @@
1
1
  import type { ErrorHandler } from "hono";
2
- import type { HonoEnv } from "./types";
2
+ import type { HonoEnv } from "./types.js";
3
3
  /**
4
4
  * Standardized API error class.
5
5
  * Throw this from any route handler — the errorHandler middleware
@@ -2,6 +2,6 @@
2
2
  * API generation infrastructure for Rebase
3
3
  * Automatically generates REST APIs from CollectionConfig definitions
4
4
  */
5
- export * from "./rest";
6
- export * from "./types";
7
- export * from "./errors";
5
+ export * from "./rest/index.js";
6
+ export * from "./types.js";
7
+ export * from "./errors.js";
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Creating and altering collections against a running backend.
3
+ *
4
+ * The existing schema editor rewrites collection source and is off in
5
+ * production, for an honest reason: a deployed server's files are rebuilt from
6
+ * the repository on every deploy, so an edit there would be discarded. These
7
+ * routes are the answer to that — they commit the change to the repository the
8
+ * server is running in, and *then* apply the DDL, so the edit survives the next
9
+ * deploy because the deploy is built from it.
10
+ *
11
+ * Two routes, and the first one is the important one.
12
+ *
13
+ * ## Why `plan` exists separately from `apply`
14
+ *
15
+ * `POST /plan` has no side effects and answers what would happen. That is not a
16
+ * convenience: a schema change has three possible verdicts and two of them are
17
+ * refusals, so a UI that could only try-and-see would be asking people to
18
+ * discover `needs-migration` by pressing a button on a live database.
19
+ *
20
+ * It also surfaces the `diverges` cases, which are the ones nothing else in the
21
+ * system reports — a required property that will arrive nullable, an enum value
22
+ * that will never land. Those apply "successfully" today and leave a database
23
+ * that does not match its configuration.
24
+ *
25
+ * ## What these routes will not do
26
+ *
27
+ * Anything the boot-time ensure path cannot express. No drops, no type changes,
28
+ * no primary keys. The planner refuses them and this refuses to route around it
29
+ * — `applySchemaChange` re-checks rather than trusting the plan it is handed.
30
+ */
31
+ import { Hono } from "hono";
32
+ import { type CollectionConfig, type DatabaseAdmin, type SchemaCommitPaths } from "@rebasepro/types";
33
+ import { HonoEnv } from "./types.js";
34
+ import { type SchemaEditRepository } from "../schema-edit/apply-schema-change.js";
35
+ import { type SchemaEditPolicy } from "../schema-edit/schema-edit-permissions.js";
36
+ export interface LiveSchemaRoutesConfig {
37
+ /**
38
+ * The collections the running server was built from — the `before` side.
39
+ * Read at request time, because the registry is assembled after the routes
40
+ * are mounted.
41
+ */
42
+ getCollections: () => CollectionConfig[];
43
+ /** The driver's admin, for planning and for running the DDL. */
44
+ getAdmin: () => DatabaseAdmin | undefined;
45
+ /**
46
+ * The working tree to commit into, or undefined when there is none — a
47
+ * bundle deployment has compiled output and no source, and this stays off
48
+ * there rather than inventing somewhere to write.
49
+ */
50
+ getRepository: (author?: {
51
+ name: string;
52
+ email: string;
53
+ }) => SchemaEditRepository | undefined;
54
+ /**
55
+ * Rewrite the collection source for a proposed change, returning the files
56
+ * that changed. Supplied by the caller because it is the AST editor's job,
57
+ * and that needs `ts-morph`, which is an optional dependency.
58
+ */
59
+ writeSource?: (change: ProposedChange) => Promise<{
60
+ path: string;
61
+ contents: string;
62
+ }[]>;
63
+ /**
64
+ * Which paths {@link writeSource} will touch, without touching them.
65
+ *
66
+ * The dirty-tree check needs them *before* the write, or it reads the
67
+ * change's own edit as somebody else's work in progress and refuses.
68
+ */
69
+ sourcePathsFor?: (change: ProposedChange) => string[];
70
+ /**
71
+ * Where this project's generated artifacts belong, relative to the
72
+ * repository.
73
+ *
74
+ * Absent for a project that *is* the repository, which is what the defaults
75
+ * describe. Present for one in a subdirectory, where the defaults would
76
+ * write `backend/` and `drizzle/` beside `.git` and leave the project's real
77
+ * generated files untouched — committing a source change alongside a stale
78
+ * schema, which is the failure committing the whole change exists to avoid.
79
+ */
80
+ commitPaths?: Partial<SchemaCommitPaths>;
81
+ /**
82
+ * Who may apply a change, as opposed to preview one.
83
+ *
84
+ * See `schema-edit-permissions.ts`. The short version: applying writes a
85
+ * commit, a commit needs an author, and a credential is not an author.
86
+ */
87
+ policy?: SchemaEditPolicy;
88
+ }
89
+ /** What the panel posts: one collection, in the shape it should end up. */
90
+ export interface ProposedChange {
91
+ collectionId: string;
92
+ /** The whole collection as it should be after the edit. */
93
+ collection: Record<string, unknown>;
94
+ }
95
+ /**
96
+ * The git identity for the caller.
97
+ *
98
+ * `undefined` when the request carries no user — a service key, say — which
99
+ * lets the repository fall back to its own git config rather than inventing a
100
+ * name for somebody.
101
+ */
102
+ export declare function commitAuthor(user: unknown): {
103
+ name: string;
104
+ email: string;
105
+ } | undefined;
106
+ /**
107
+ * The proposed collection set: everything as it is, with one collection
108
+ * replaced or added.
109
+ */
110
+ export declare function proposedCollections(current: CollectionConfig[], change: ProposedChange): CollectionConfig[];
111
+ export declare function createLiveSchemaRoutes(config: LiveSchemaRoutesConfig): Hono<HonoEnv>;
@@ -1,6 +1,6 @@
1
1
  import { Hono } from "hono";
2
2
  import type { MiddlewareHandler } from "hono";
3
- import type { HonoEnv } from "./types";
3
+ import type { HonoEnv } from "./types.js";
4
4
  export interface LogEntry {
5
5
  id: string;
6
6
  timestamp: string;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Mounting a surface at its canonical path, and at the path it used to have.
3
+ *
4
+ * Several admin-only surfaces grew up at the top level — `/api/cron`,
5
+ * `/api/logs`, `/api/schema-editor` — while the ones added later went under
6
+ * `/api/admin`. Nothing was wrong with either choice on its own; what was wrong
7
+ * was having both, because the shape of the path stopped predicting whether a
8
+ * caller needed to be an admin. `docs/api-conventions.md` states the rule the
9
+ * repo now follows and this module is how existing callers survive it.
10
+ *
11
+ * ## Why an alias rather than a redirect
12
+ *
13
+ * A 308 would be correct and would break things anyway: `fetch` follows
14
+ * redirects but drops an `Authorization` header on a cross-origin hop, and a
15
+ * good deal of client code posts to these paths with one attached. An alias
16
+ * serves the same handler at both paths, so nothing observable changes for a
17
+ * caller that has not moved yet.
18
+ *
19
+ * The alias is not silent. Every response through it carries `Deprecation` and
20
+ * a `Link` naming the successor, which is what makes the old path removable
21
+ * later: an operator can find the callers in their own logs rather than
22
+ * discovering them when the path is gone.
23
+ */
24
+ import { Hono } from "hono";
25
+ import type { HonoEnv } from "./types.js";
26
+ export interface MountOptions {
27
+ /** Where the surface lives now. */
28
+ canonical: string;
29
+ /** Where it used to live, when it has moved. */
30
+ legacy?: string;
31
+ /** For the boot log — "Cron", "Logs". */
32
+ surface: string;
33
+ }
34
+ /**
35
+ * Mount `router` at its canonical path, and at its legacy path when it has one.
36
+ *
37
+ * The same router instance serves both, so the two paths cannot drift: there is
38
+ * one set of handlers and one gate, and an alias that forgot to apply the admin
39
+ * gate is not a state this can reach.
40
+ */
41
+ export declare function mountWithLegacyAlias(app: Hono<HonoEnv>, router: Hono<HonoEnv>, options: MountOptions): void;
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
2
  import { AuthAdapter, DataDriver, CollectionConfig } from "@rebasepro/types";
3
- import { HonoEnv } from "../types";
4
- import { type ListLimitOptions } from "./query-parser";
3
+ import { HonoEnv } from "../types.js";
4
+ import { type ListLimitOptions } from "./query-parser.js";
5
5
  /**
6
6
  * Lightweight REST API generator that leverages existing Rebase DataDriver.
7
7
  * Supports `include` query parameter for eager-loading relations via Drizzle.
@@ -1 +1 @@
1
- export * from "./api-generator";
1
+ export * from "./api-generator.js";
@@ -1,5 +1,5 @@
1
1
  import type { ListLimitBounds, OrderByTuple } from "@rebasepro/types";
2
- import { QueryOptions } from "../types";
2
+ import { QueryOptions } from "../types.js";
3
3
  export declare const mapOperator: (op: string) => import("@rebasepro/types").WhereFilterOp | null;
4
4
  type OrderByEntry = {
5
5
  field: string;
@@ -1,3 +1,3 @@
1
1
  import { Hono } from "hono";
2
- import { HonoEnv } from "./types";
2
+ import { HonoEnv } from "./types.js";
3
3
  export declare function createSchemaEditorRoutes(collectionsDir: string): Hono<HonoEnv>;
@@ -1,7 +1,6 @@
1
- import { VectorSearchParams, LogicalCondition, FilterValues } from "@rebasepro/types";
2
- import type { AuthResult } from "../auth/middleware";
3
- import { DataDriver } from "@rebasepro/types";
4
- import type { ApiKeyMasked } from "../auth/api-keys/api-key-types";
1
+ import type { VectorSearchParams, LogicalCondition, FilterValues, DataDriver } from "@rebasepro/types";
2
+ import type { AuthResult } from "../auth/middleware.js";
3
+ import type { ApiKeyMasked } from "../auth/api-keys/api-key-types.js";
5
4
  /**
6
5
  * Hono Environment Variables
7
6
  * Passed to generic Hono<HonoEnv> to type `c.get()`
@@ -3,10 +3,8 @@ import "process";
3
3
  __createRequire(import.meta.url);
4
4
  import "./src-CrCxd8km.js";
5
5
  import { i as nestAdminPropertyKeys, r as nestAdminCollectionKeys } from "./admin_block-DLILvzle.js";
6
- import { n as errorHandler } from "./errors-EBYiaJ2E.js";
7
6
  import * as fs$1 from "fs";
8
7
  import * as path$1 from "path";
9
- import { Hono } from "hono";
10
8
  import { IndentationText, Node, Project, SyntaxKind } from "ts-morph";
11
9
  //#region src/api/ast-schema-editor.ts
12
10
  /**
@@ -397,41 +395,6 @@ var AstSchemaEditor = class AstSchemaEditor {
397
395
  }
398
396
  };
399
397
  //#endregion
400
- //#region src/api/schema-editor-routes.ts
401
- function createSchemaEditorRoutes(collectionsDir) {
402
- const router = new Hono();
403
- router.onError(errorHandler);
404
- const editor = new AstSchemaEditor(collectionsDir);
405
- router.post("/property/save", async (c) => {
406
- const { collectionId, propertyKey, propertyConfig } = await c.req.json();
407
- await editor.saveProperty(collectionId, propertyKey, propertyConfig);
408
- return c.json({ success: true });
409
- });
410
- router.post("/property/delete", async (c) => {
411
- const { collectionId, propertyKey } = await c.req.json();
412
- await editor.deleteProperty(collectionId, propertyKey);
413
- return c.json({ success: true });
414
- });
415
- /**
416
- * `partial: true` means "this payload is what changed", not "this is the
417
- * collection". Without it a one-key patch — which is what adding a column
418
- * posts — is read as a whole-collection save and deletes everything it does
419
- * not mention, `securityRules` included. Absent, it defaults to a full save,
420
- * so an older panel keeps the behaviour it was written against.
421
- */
422
- router.post("/collection/save", async (c) => {
423
- const { collectionId, collectionData, partial } = await c.req.json();
424
- await editor.saveCollection(collectionId, collectionData, { partial: partial === true });
425
- return c.json({ success: true });
426
- });
427
- router.post("/collection/delete", async (c) => {
428
- const { collectionId } = await c.req.json();
429
- await editor.deleteCollection(collectionId);
430
- return c.json({ success: true });
431
- });
432
- return router;
433
- }
434
- //#endregion
435
- export { createSchemaEditorRoutes };
398
+ export { AstSchemaEditor };
436
399
 
437
- //# sourceMappingURL=schema-editor-routes-CV9k0w3G.js.map
400
+ //# sourceMappingURL=ast-schema-editor-BpFYpT38.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-schema-editor-BpFYpT38.js","names":[],"sources":["../src/api/ast-schema-editor.ts"],"sourcesContent":["import { Project, SyntaxKind, Node, ObjectLiteralExpression, ObjectLiteralElementLike, PropertyAssignment, SourceFile, IndentationText } from \"ts-morph\";\nimport { nestAdminCollectionKeys, nestAdminPropertyKeys } from \"@rebasepro/types\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\n/**\n * The helpers a collection file may be wrapped in.\n *\n * `rebase init` scaffolds every collection as\n * `const postsCollection = defineCollection({ … })` — a call expression, not the\n * bare object literal `rebase introspect` emits. An editor that only understood\n * the bare form found nothing to patch in any stock project, and then rewrote the\n * file from the panel's JSON: no wrapper, no imports, no relation thunks.\n */\nconst COLLECTION_FACTORIES = new Set([\"defineCollection\"]);\n\n/**\n * A value that must be emitted as source code rather than as JSON.\n *\n * Everything reaching the writer has been through `JSON.stringify` on the wire,\n * so a function-valued key arrives either missing or as a string. A relation's\n * `target` is a thunk in the file and a slug in the payload; this is how the\n * thunk gets written back.\n */\nclass RawExpression {\n constructor(public readonly text: string) {\n }\n}\n\n/**\n * Move presentation keys into the `admin` block.\n *\n * The rule itself lives in `@rebasepro/types`, next to `ADMIN_COLLECTION_KEYS`,\n * because `@rebasepro/admin-types` has to apply the identical one on the panel's\n * side and this package cannot import that one. Two copies used to exist and\n * they disagreed about precedence, which decided whether a presentation edit was\n * saved or silently reverted to the value the user had just changed away from.\n */\nexport function nestAdminKeys(collectionData: Record<string, unknown>): Record<string, unknown> {\n return nestAdminCollectionKeys(collectionData);\n}\n\nexport class AstSchemaEditor {\n private project: Project;\n private collectionsDir: string;\n\n constructor(collectionsDir: string) {\n this.project = new Project({\n manipulationSettings: {\n indentationText: IndentationText.FourSpaces\n }\n });\n if (fs.existsSync(collectionsDir)) {\n this.project.addSourceFilesAtPaths(`${collectionsDir}/**/*.ts`);\n }\n this.collectionsDir = path.resolve(collectionsDir);\n }\n\n /**\n * Sanitize collectionId to prevent path traversal attacks.\n * Only allows alphanumeric characters, underscores, and hyphens.\n */\n private sanitizeCollectionId(collectionId: string): string {\n const sanitized = collectionId.replace(/[^a-zA-Z0-9_-]/g, \"\");\n if (!sanitized || sanitized !== collectionId) {\n throw new Error(`Invalid collection ID: \"${collectionId}\". Only alphanumeric characters, underscores, and hyphens are allowed.`);\n }\n return sanitized;\n }\n\n /**\n * Resolve a file path and ensure it falls within the collectionsDir.\n */\n private safePath(filename: string): string {\n const resolved = path.resolve(this.collectionsDir, filename);\n if (!resolved.startsWith(this.collectionsDir + path.sep) && resolved !== this.collectionsDir) {\n throw new Error(\"Path traversal detected: resolved path is outside the collections directory.\");\n }\n return resolved;\n }\n\n private getCollectionFile(collectionId: string) {\n const safeId = this.sanitizeCollectionId(collectionId);\n const filePath = this.safePath(`${safeId}.ts`);\n let file = this.project.getSourceFile(filePath);\n if (!file && fs.existsSync(filePath)) {\n this.project.addSourceFilesAtPaths(`${this.collectionsDir}/**/*.ts`);\n file = this.project.getSourceFile(filePath);\n }\n return file;\n }\n\n /**\n * Find the object literal a collection is declared with, through whatever\n * wraps it.\n *\n * `defineCollection({ … })` is the shape `rebase init` writes and the one the\n * docs recommend; `satisfies` / `as` / parentheses are the other ways an\n * author can dress the same literal. Returning `null` for any of them meant\n * the three callers below each failed differently, and the worst of them\n * overwrote the file.\n */\n private unwrapCollectionObject(node: Node | undefined): ObjectLiteralExpression | null {\n if (!node) return null;\n if (Node.isObjectLiteralExpression(node)) return node;\n if (Node.isParenthesizedExpression(node) ||\n Node.isAsExpression(node) ||\n Node.isSatisfiesExpression(node) ||\n Node.isTypeAssertion(node) ||\n Node.isNonNullExpression(node)) {\n return this.unwrapCollectionObject(node.getExpression());\n }\n if (Node.isCallExpression(node)) {\n // `defineCollection`, `admin.defineCollection`, `defineCollection<Post>`\n const callee = node.getExpression().getText().split(\".\").pop();\n if (callee && COLLECTION_FACTORIES.has(callee)) {\n return this.unwrapCollectionObject(node.getArguments()[0]);\n }\n }\n return null;\n }\n\n private getCollectionObject(collectionId: string): ObjectLiteralExpression | null {\n const file = this.getCollectionFile(collectionId);\n if (!file) return null;\n\n const defaultExport = file.getDefaultExportSymbol();\n if (defaultExport) {\n const declaration = defaultExport.getDeclarations()[0];\n if (declaration && declaration.getKind() === SyntaxKind.ExportAssignment) {\n const expr = declaration.asKind(SyntaxKind.ExportAssignment)?.getExpression();\n if (expr && expr.getKind() === SyntaxKind.Identifier) {\n const varName = expr.getText();\n const varDecl = file.getVariableDeclaration(varName);\n const unwrapped = this.unwrapCollectionObject(varDecl?.getInitializer());\n if (unwrapped) return unwrapped;\n } else {\n // `export default defineCollection({ … })`\n const unwrapped = this.unwrapCollectionObject(expr);\n if (unwrapped) return unwrapped;\n }\n }\n }\n // Fallback: the first VariableDeclaration that holds a collection literal\n for (const varDecl of file.getVariableDeclarations()) {\n const init = this.unwrapCollectionObject(varDecl.getInitializer());\n if (init) return init;\n }\n return null;\n }\n\n /**\n * The collection's object literal, or a refusal that says what to do.\n *\n * Every caller needs this to be all-or-nothing: a missing object literal used\n * to mean \"throw\", \"report success and do nothing\" and \"recreate the file\n * from scratch\" depending on which method you called.\n */\n private requireCollectionObject(collectionId: string): ObjectLiteralExpression {\n const file = this.getCollectionFile(collectionId);\n if (!file) {\n throw new Error(`Collection \"${collectionId}\" has no file at ${path.join(this.collectionsDir, `${collectionId}.ts`)}.`);\n }\n const collectionObj = this.getCollectionObject(collectionId);\n if (!collectionObj) {\n throw new Error(this.unreadableFileMessage(collectionId, file));\n }\n return collectionObj;\n }\n\n private unreadableFileMessage(collectionId: string, file: SourceFile): string {\n return `Could not find the collection object in ${file.getFilePath()}. ` +\n \"The schema editor can only edit a collection declared as `const x = defineCollection({ … })` \" +\n \"or `const x: CollectionConfig = { … }` and exported as the file's default. \" +\n `Edit \"${collectionId}\" in code instead.`;\n }\n\n /** Look a key up on an object literal, quoted or not. */\n private findProperty(obj: ObjectLiteralExpression, name: string): ObjectLiteralElementLike | undefined {\n return obj.getProperty((p: ObjectLiteralElementLike) =>\n \"getName\" in p &&\n typeof (p as PropertyAssignment).getName === \"function\" &&\n ((p as PropertyAssignment).getName() === name ||\n (p as PropertyAssignment).getName() === `\"${name}\"` ||\n (p as PropertyAssignment).getName() === `'${name}'`));\n }\n\n private static quoteKey(key: string): string {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);\n }\n\n private static isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) && !(value instanceof RawExpression);\n }\n\n private convertJsonToAstString(obj: unknown, indentLevel = 0, oldAstNode?: ObjectLiteralExpression): string {\n // Base TS-morph parses arrays as 2 levels deep from the property key:\n // PropertiesObject = level 1, PropertyConfig = level 2.\n // We calibrate the spacing multiples to keep the items flush with standard TS format.\n const indentStr = \" \";\n const indent = indentStr.repeat(indentLevel);\n const innerIndent = indentStr.repeat(indentLevel + 1);\n\n if (obj instanceof RawExpression) {\n return obj.text;\n }\n if (obj === null || obj === undefined) {\n return \"undefined\";\n }\n if (typeof obj === \"string\") {\n return JSON.stringify(obj);\n }\n if (typeof obj === \"number\" || typeof obj === \"boolean\") {\n return String(obj);\n }\n if (Array.isArray(obj)) {\n if (obj.length === 0) return \"[]\";\n const items = obj.map(item => this.convertJsonToAstString(item, indentLevel + 1));\n return `[\\n${innerIndent}${items.join(`,\\n${innerIndent}`)}\\n${indent}]`;\n }\n if (typeof obj === \"object\") {\n const record = obj as Record<string, unknown>;\n const keys = Object.keys(record);\n\n // Collect preserved AST properties\n const preservedProps: string[] = [];\n if (oldAstNode) {\n const oldProps = oldAstNode.getProperties();\n for (const oldProp of oldProps) {\n if (oldProp.isKind(SyntaxKind.PropertyAssignment)) {\n const nameNode = oldProp.getNameNode();\n let name = nameNode.getText();\n if (name.startsWith('\"') && name.endsWith('\"')) name = name.slice(1, -1);\n if (name.startsWith(\"'\") && name.endsWith(\"'\")) name = name.slice(1, -1);\n\n // If the JSON object doesn't have this key, check if we should preserve it\n if (!(name in record)) {\n const init = oldProp.getInitializer();\n if (init) {\n const kind = init.getKind();\n const isCode = kind === SyntaxKind.ArrowFunction ||\n kind === SyntaxKind.FunctionExpression ||\n kind === SyntaxKind.Identifier ||\n kind === SyntaxKind.CallExpression ||\n kind === SyntaxKind.JsxElement;\n\n if (isCode || name === \"target\" || name === \"callbacks\" || name === \"permissions\" || name === \"securityRules\") {\n // Preserve this property exactly as it was\n preservedProps.push(`${AstSchemaEditor.quoteKey(name)}: ${init.getText()}`);\n }\n }\n }\n }\n }\n }\n\n if (keys.length === 0 && preservedProps.length === 0) return \"{}\";\n\n const props = keys.map(key => {\n const keyStr = AstSchemaEditor.quoteKey(key);\n\n // If the value is an object, pass the old AST node to recurse\n let childAstNode: ObjectLiteralExpression | undefined;\n if (oldAstNode && AstSchemaEditor.isPlainObject(record[key])) {\n const oldProp = this.findProperty(oldAstNode, key);\n if (oldProp && oldProp.isKind(SyntaxKind.PropertyAssignment)) {\n childAstNode = oldProp.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);\n }\n }\n\n return `${keyStr}: ${this.convertJsonToAstString(record[key], indentLevel + 1, childAstNode)}`;\n });\n\n const allProps = [...props, ...preservedProps];\n return `{\\n${innerIndent}${allProps.join(`,\\n${innerIndent}`)}\\n${indent}}`;\n }\n return \"undefined\";\n }\n\n /**\n * Write only the keys the patch names, leaving every sibling alone.\n *\n * A patch says what changed, not what the collection is. The panel sends one\n * — `{ propertiesOrder }` is what adding a column posts — and rewriting the\n * `admin` block from it deleted the collection's icon, group, list columns\n * and kanban config in the same write.\n */\n private mergeIntoObjectLiteral(target: ObjectLiteralExpression, data: Record<string, unknown>, indentLevel: number): void {\n for (const [key, value] of Object.entries(data)) {\n const existing = this.findProperty(target, key);\n const existingObj = existing && existing.isKind(SyntaxKind.PropertyAssignment)\n ? existing.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression)\n : undefined;\n\n if (existingObj && AstSchemaEditor.isPlainObject(value)) {\n this.mergeIntoObjectLiteral(existingObj, value, indentLevel + 1);\n continue;\n }\n\n const initializer = this.convertJsonToAstString(value, indentLevel, existingObj);\n if (existing && existing.isKind(SyntaxKind.PropertyAssignment)) {\n existing.setInitializer(initializer);\n } else {\n target.addPropertyAssignment({\n name: AstSchemaEditor.quoteKey(key),\n initializer\n });\n }\n }\n }\n\n public async saveProperty(collectionId: string, propertyKey: string, propertyConfig: Record<string, unknown>) {\n const collectionObj = this.requireCollectionObject(collectionId);\n\n // The panel's property forms bind to the flat names — `readOnly`,\n // `hideFromCollection` — while on disk they belong inside the property's\n // own `admin` block. Written flat they are not merely ignored: the boot\n // validator treats a moved key as fatal.\n const nestedConfig = nestAdminPropertyKeys(propertyConfig);\n\n let propertiesProp = collectionObj.getProperty(\"properties\") as PropertyAssignment;\n if (!propertiesProp) {\n propertiesProp = collectionObj.addPropertyAssignment({\n name: \"properties\",\n initializer: \"{}\"\n });\n }\n\n const propsObj = propertiesProp.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);\n if (propsObj) {\n const existingProp = this.findProperty(propsObj, propertyKey);\n\n let oldPropAstNode: ObjectLiteralExpression | undefined;\n if (existingProp && existingProp.isKind(SyntaxKind.PropertyAssignment)) {\n oldPropAstNode = existingProp.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);\n }\n\n const newInitializer = this.convertJsonToAstString(nestedConfig, 2, oldPropAstNode);\n\n if (existingProp) {\n if (existingProp.isKind(SyntaxKind.PropertyAssignment)) {\n existingProp.setInitializer(newInitializer);\n }\n } else {\n propsObj.addPropertyAssignment({\n name: AstSchemaEditor.quoteKey(propertyKey),\n initializer: newInitializer\n });\n }\n\n const file = this.getCollectionFile(collectionId);\n if (file) {\n file.formatText();\n }\n await this.project.save();\n }\n }\n\n public async deleteProperty(collectionId: string, propertyKey: string) {\n const collectionObj = this.requireCollectionObject(collectionId);\n\n const propertiesProp = collectionObj.getProperty(\"properties\") as PropertyAssignment;\n if (propertiesProp) {\n const propsObj = propertiesProp.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);\n if (propsObj) {\n const existingProp = this.findProperty(propsObj, propertyKey);\n if (existingProp) {\n existingProp.remove();\n const file = this.getCollectionFile(collectionId);\n if (file) {\n file.formatText();\n }\n await this.project.save();\n }\n }\n }\n }\n\n /**\n * Write a collection back to its file.\n *\n * `partial` is the difference between \"this is the collection\" and \"this is\n * what changed about it\". The panel sends both — a full save from the editor\n * dialog, and a one-key patch whenever a property is added, deleted or\n * reordered — and they cannot be told apart by looking at the payload. Read\n * as a full save, a patch deletes everything it does not mention, including\n * `securityRules`; the loader then hands the collection the directory\n * default, which in the scaffold is `access: \"public\"`.\n */\n public async saveCollection(collectionId: string, collectionData: Record<string, unknown>, options: { partial?: boolean } = {}) {\n const partial = options.partial === true;\n let file = this.getCollectionFile(collectionId);\n const collectionObj = file ? this.getCollectionObject(collectionId) : null;\n\n if (file && !collectionObj) {\n // The file is there and we could not read it. Recreating it from the\n // panel's JSON would drop the imports, the callbacks and the relation\n // thunks that JSON cannot carry.\n throw new Error(this.unreadableFileMessage(collectionId, file));\n }\n\n if (!file || !collectionObj) {\n if (partial) {\n throw new Error(`Cannot apply a partial update to \"${collectionId}\": it has no collection file yet.`);\n }\n // Create a new file\n const safeId = this.sanitizeCollectionId(collectionId);\n const newFilePath = this.safePath(`${safeId}.ts`);\n if (fs.existsSync(newFilePath)) {\n throw new Error(`Refusing to overwrite ${newFilePath}: a file for \"${collectionId}\" already exists but could not be parsed.`);\n }\n file = this.project.createSourceFile(newFilePath, `import { CollectionConfig } from \"@rebasepro/types\";\\n\\nconst ${safeId}Collection: CollectionConfig = ${this.convertJsonToAstString(nestAdminKeys(collectionData))};\\n\\nexport default ${safeId}Collection;\\n`);\n } else {\n // Update root level properties gracefully\n\n if (!partial) {\n // Force delete securityRules if empty or undefined to handle Formex / serialization stripping\n if (!(\"securityRules\" in collectionData) || collectionData.securityRules === undefined || (Array.isArray(collectionData.securityRules) && collectionData.securityRules.length === 0)) {\n const srProp = collectionObj.getProperty(\"securityRules\");\n if (srProp) {\n srProp.remove();\n }\n\n // If it was in collectionData as an empty array, delete it so the loop below doesn't add it back as \"[]\"\n // Actually, if it's \"[]\", omitting it entirely from the TS file achieves the same logical effect (no RLS rules)\n // and correctly triggers \"unmapped policies\" if the DB still has them.\n delete collectionData[\"securityRules\"];\n }\n }\n\n // The panel works with a flat view model — presentation merged onto the\n // collection — so what arrives here has `icon` and `listProperties` at\n // the top level. On disk they belong inside `admin`. Writing them flat\n // would produce a file the backend loads and ignores and the panel\n // never reads back, which looks exactly like the edit not saving.\n collectionData = nestAdminKeys(collectionData);\n\n for (const key of Object.keys(collectionData)) {\n if (key === \"relations\") {\n this.writeRelations(collectionId, file, collectionObj, collectionData[key]);\n continue;\n }\n\n const prop = collectionObj.getProperty(key) as PropertyAssignment;\n\n let oldAstNode: ObjectLiteralExpression | undefined;\n if (prop && prop.isKind(SyntaxKind.PropertyAssignment)) {\n oldAstNode = prop.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);\n }\n\n if (partial && oldAstNode && AstSchemaEditor.isPlainObject(collectionData[key])) {\n this.mergeIntoObjectLiteral(oldAstNode, collectionData[key] as Record<string, unknown>, 2);\n continue;\n }\n\n const newInit = this.convertJsonToAstString(collectionData[key], 1, oldAstNode);\n if (prop) {\n prop.setInitializer(newInit);\n } else {\n collectionObj.addPropertyAssignment({\n name: key,\n initializer: newInit\n });\n }\n }\n }\n if (file) {\n file.formatText();\n }\n await this.project.save();\n }\n\n /**\n * Write the collection-level `relations` array.\n *\n * Relations are the one key whose values are not all data: `target` is a\n * thunk in the file, and the panel sends the target collection's slug (or,\n * for a relation it did not touch, nothing at all — `JSON.stringify` drops\n * the function). So each entry's target is resolved in that order: a slug\n * becomes `() => xCollection` plus the import it needs, and anything else\n * falls back to the thunk already in the file.\n *\n * This used to be a `continue` with a comment saying relations were handled\n * elsewhere. Nothing handled them; every edit in the Relations tab was\n * dropped without a word.\n */\n private writeRelations(collectionId: string, file: SourceFile, collectionObj: ObjectLiteralExpression, value: unknown): void {\n if (!Array.isArray(value)) return;\n\n const existing = this.findProperty(collectionObj, \"relations\");\n const oldArray = existing && existing.isKind(SyntaxKind.PropertyAssignment)\n ? existing.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)\n : undefined;\n\n const oldElements = oldArray?.getElements() ?? [];\n const oldTargetsByName = new Map<string, string>();\n // Only for entries the file left unnamed — `relationName` is optional, and\n // those cannot be matched any other way. Positional matching is off the\n // moment the array's length changes, because then a position no longer\n // means the same relation.\n const anonymousTargetsByIndex: (string | undefined)[] = [];\n oldElements.forEach((element, index) => {\n const elementObj = element.asKind(SyntaxKind.ObjectLiteralExpression);\n if (!elementObj) return;\n const targetProp = this.findProperty(elementObj, \"target\");\n const targetInit = targetProp && targetProp.isKind(SyntaxKind.PropertyAssignment)\n ? targetProp.getInitializer()\n : undefined;\n if (!targetInit) return;\n\n const nameProp = this.findProperty(elementObj, \"relationName\");\n const nameInit = nameProp && nameProp.isKind(SyntaxKind.PropertyAssignment)\n ? nameProp.getInitializerIfKind(SyntaxKind.StringLiteral)\n : undefined;\n if (nameInit) oldTargetsByName.set(nameInit.getLiteralValue(), targetInit.getText());\n else anonymousTargetsByIndex[index] = targetInit.getText();\n });\n\n const items = value.map((entry, index) => {\n if (!AstSchemaEditor.isPlainObject(entry)) return entry;\n const relation: Record<string, unknown> = { ...entry };\n const relationName = typeof relation.relationName === \"string\" ? relation.relationName : undefined;\n const rawTarget = relation.target;\n\n let targetText: string | undefined;\n if (typeof rawTarget === \"string\" && rawTarget.trim().length > 0) {\n targetText = rawTarget.includes(\"=>\")\n ? rawTarget.trim()\n : this.targetThunk(file, rawTarget.trim());\n } else if (relationName && oldTargetsByName.has(relationName)) {\n targetText = oldTargetsByName.get(relationName);\n } else if (value.length === oldElements.length) {\n targetText = anonymousTargetsByIndex[index];\n }\n\n if (!targetText) {\n throw new Error(`Relation \"${relationName ?? `#${index}`}\" on collection \"${collectionId}\" has no target collection. Pick one before saving.`);\n }\n\n relation.target = new RawExpression(targetText);\n return relation;\n });\n\n const initializer = this.convertJsonToAstString(items, 1);\n if (existing && existing.isKind(SyntaxKind.PropertyAssignment)) {\n existing.setInitializer(initializer);\n } else {\n collectionObj.addPropertyAssignment({ name: \"relations\", initializer });\n }\n }\n\n /**\n * `() => targetCollection` for a target named by its slug, importing it if\n * the file does not already.\n */\n private targetThunk(file: SourceFile, targetSlug: string): string {\n const targetFile = this.getCollectionFile(targetSlug);\n if (!targetFile) {\n throw new Error(`Cannot link to collection \"${targetSlug}\": no file for it in ${this.collectionsDir}.`);\n }\n\n const identifier = this.getDefaultExportName(targetFile);\n if (!identifier) {\n throw new Error(`Cannot link to collection \"${targetSlug}\": ${targetFile.getFilePath()} has no default export to import.`);\n }\n\n if (targetFile.getFilePath() !== file.getFilePath() && !this.hasDefaultImport(file, identifier)) {\n const relative = path.relative(path.dirname(file.getFilePath()), targetFile.getFilePath())\n .split(path.sep)\n .join(\"/\")\n .replace(/\\.tsx?$/, \".js\");\n file.addImportDeclaration({\n defaultImport: identifier,\n moduleSpecifier: relative.startsWith(\".\") ? relative : `./${relative}`\n });\n }\n\n return `() => ${identifier}`;\n }\n\n private hasDefaultImport(file: SourceFile, identifier: string): boolean {\n return file.getImportDeclarations().some(decl => decl.getDefaultImport()?.getText() === identifier);\n }\n\n private getDefaultExportName(file: SourceFile): string | undefined {\n const declaration = file.getDefaultExportSymbol()?.getDeclarations()[0];\n const expr = declaration?.asKind(SyntaxKind.ExportAssignment)?.getExpression();\n if (expr && expr.getKind() === SyntaxKind.Identifier) return expr.getText();\n\n for (const varDecl of file.getVariableDeclarations()) {\n if (this.unwrapCollectionObject(varDecl.getInitializer())) return varDecl.getName();\n }\n return undefined;\n }\n\n public async deleteCollection(collectionId: string) {\n const file = this.getCollectionFile(collectionId);\n if (file) {\n file.deleteImmediatelySync();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,IAAM,uCAAuB,IAAI,IAAI,CAAC,kBAAkB,CAAC;;;;;;;;;AAUzD,IAAM,gBAAN,MAAoB;CACY;CAA5B,YAAY,MAA8B;EAAd,KAAA,OAAA;CAC5B;AACJ;;;;;;;;;;AAWA,SAAgB,cAAc,gBAAkE;CAC5F,OAAO,wBAAwB,cAAc;AACjD;AAEA,IAAa,kBAAb,MAAa,gBAAgB;CACzB;CACA;CAEA,YAAY,gBAAwB;EAChC,KAAK,UAAU,IAAI,QAAQ,EACvB,sBAAsB,EAClB,iBAAiB,gBAAgB,WACrC,EACJ,CAAC;EACD,IAAI,KAAG,WAAW,cAAc,GAC5B,KAAK,QAAQ,sBAAsB,GAAG,eAAe,SAAS;EAElE,KAAK,iBAAiB,OAAK,QAAQ,cAAc;CACrD;;;;;CAMA,qBAA6B,cAA8B;EACvD,MAAM,YAAY,aAAa,QAAQ,mBAAmB,EAAE;EAC5D,IAAI,CAAC,aAAa,cAAc,cAC5B,MAAM,IAAI,MAAM,2BAA2B,aAAa,uEAAuE;EAEnI,OAAO;CACX;;;;CAKA,SAAiB,UAA0B;EACvC,MAAM,WAAW,OAAK,QAAQ,KAAK,gBAAgB,QAAQ;EAC3D,IAAI,CAAC,SAAS,WAAW,KAAK,iBAAiB,OAAK,GAAG,KAAK,aAAa,KAAK,gBAC1E,MAAM,IAAI,MAAM,8EAA8E;EAElG,OAAO;CACX;CAEA,kBAA0B,cAAsB;EAC5C,MAAM,SAAS,KAAK,qBAAqB,YAAY;EACrD,MAAM,WAAW,KAAK,SAAS,GAAG,OAAO,IAAI;EAC7C,IAAI,OAAO,KAAK,QAAQ,cAAc,QAAQ;EAC9C,IAAI,CAAC,QAAQ,KAAG,WAAW,QAAQ,GAAG;GAClC,KAAK,QAAQ,sBAAsB,GAAG,K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,qBAA6B,MAAsC;EAE/D,MAAM,QADc,KAAK,uBAAuB,CAAC,EAAE,gBAAgB,CAAC,CAAC,GAAA,EAC3C,OAAO,WAAW,gBAAgB,CAAC,EAAE,cAAc;EAC7E,IAAI,QAAQ,KAAK,QAAQ,MAAM,WAAW,YAAY,OAAO,KAAK,QAAQ;EAE1E,KAAK,MAAM,WAAW,KAAK,wBAAwB,GAC/C,IAAI,KAAK,uBAAuB,QAAQ,eAAe,CAAC,GAAG,OAAO,QAAQ,QAAQ;CAG1F;CAEA,MAAa,iBAAiB,cAAsB;EAChD,MAAM,OAAO,KAAK,kBAAkB,YAAY;EAChD,IAAI,MACA,KAAK,sBAAsB;CAEnC;AACJ"}
@@ -18,8 +18,8 @@
18
18
  */
19
19
  import type { MiddlewareHandler, Context } from "hono";
20
20
  import type { DataDriver, AuthAdapter } from "@rebasepro/types";
21
- import type { HonoEnv } from "../api/types";
22
- import type { ApiKeyStore } from "./api-keys/api-key-store";
21
+ import type { HonoEnv } from "../api/types.js";
22
+ import type { ApiKeyStore } from "./api-keys/api-key-store.js";
23
23
  export interface AdapterAuthMiddlewareOptions {
24
24
  /** The auth adapter to delegate verification to. */
25
25
  adapter: AuthAdapter;
@@ -4,8 +4,8 @@
4
4
  * Mounts: GET /roles
5
5
  */
6
6
  import { Hono } from "hono";
7
- import type { AuthRepository } from "./interfaces";
8
- import type { HonoEnv } from "../api/types";
7
+ import type { AuthRepository } from "./interfaces.js";
8
+ import type { HonoEnv } from "../api/types.js";
9
9
  export interface AdminRolesRouteConfig {
10
10
  authRepo: AuthRepository;
11
11
  serviceKey?: string;
@@ -9,9 +9,9 @@
9
9
  * 2. Backend-level hook (`AuthHooks.onAdminCreateUser`) — global override
10
10
  * 3. Built-in default — framework fallback
11
11
  */
12
- import type { AuthRepository } from "./interfaces";
13
- import type { EmailService, EmailConfig } from "../email";
14
- import type { ResolvedAuthHooks } from "./auth-hooks";
12
+ import type { AuthRepository } from "./interfaces.js";
13
+ import type { EmailService, EmailConfig } from "../email/index.js";
14
+ import type { ResolvedAuthHooks } from "./auth-hooks.js";
15
15
  import type { AuthCollectionConfig } from "@rebasepro/types";
16
16
  /**
17
17
  * Generate a cryptographically secure random password that meets strength requirements.
@@ -10,10 +10,10 @@
10
10
  * POST /bootstrap
11
11
  */
12
12
  import { Hono } from "hono";
13
- import type { AuthRepository } from "./interfaces";
14
- import type { AuthHooks } from "./auth-hooks";
15
- import type { EmailService, EmailConfig } from "../email";
16
- import type { HonoEnv } from "../api/types";
13
+ import type { AuthRepository } from "./interfaces.js";
14
+ import type { AuthHooks } from "./auth-hooks.js";
15
+ import type { EmailService, EmailConfig } from "../email/index.js";
16
+ import type { HonoEnv } from "../api/types.js";
17
17
  import type { AuthCollectionConfig } from "@rebasepro/types";
18
18
  export interface AdminUsersRouteConfig {
19
19
  authRepo: AuthRepository;
@@ -23,8 +23,8 @@
23
23
  */
24
24
  import type { Context, MiddlewareHandler } from "hono";
25
25
  import type { DataDriver } from "@rebasepro/types";
26
- import type { HonoEnv } from "../../api/types";
27
- import type { ApiKeyStore } from "./api-key-store";
26
+ import type { HonoEnv } from "../../api/types.js";
27
+ import type { ApiKeyStore } from "./api-key-store.js";
28
28
  /**
29
29
  * Check whether a token looks like a Rebase API key.
30
30
  */
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import type { ApiKeyPermission } from "./api-key-types";
10
+ import type { ApiKeyPermission } from "./api-key-types.js";
11
11
  /** Operations that map to HTTP methods. */
12
12
  export type ApiKeyOperation = "read" | "write" | "delete";
13
13
  /**
@@ -8,8 +8,8 @@
8
8
  * @module
9
9
  */
10
10
  import { Hono } from "hono";
11
- import type { HonoEnv } from "../../api/types";
12
- import type { ApiKeyStore } from "./api-key-store";
11
+ import type { HonoEnv } from "../../api/types.js";
12
+ import type { ApiKeyStore } from "./api-key-store.js";
13
13
  export interface ApiKeyRouteOptions {
14
14
  store: ApiKeyStore;
15
15
  serviceKey?: string;
@@ -8,7 +8,7 @@
8
8
  * @module
9
9
  */
10
10
  import type { DataDriver } from "@rebasepro/types";
11
- import type { ApiKey, ApiKeyMasked, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest } from "./api-key-types";
11
+ import type { ApiKey, ApiKeyMasked, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest } from "./api-key-types.js";
12
12
  export interface ApiKeyStore {
13
13
  /** Ensure the `rebase.api_keys` table exists. Called once on startup. */
14
14
  ensureTable(): Promise<void>;
@@ -6,12 +6,12 @@
6
6
  *
7
7
  * @module
8
8
  */
9
- export type { ApiKey, ApiKeyMasked, ApiKeyPermission, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest } from "./api-key-types";
10
- export { createApiKeyStore } from "./api-key-store";
11
- export type { ApiKeyStore } from "./api-key-store";
12
- export { isApiKeyToken, validateApiKey, createApiKeyPreAuth, createFunctionApiKeyGuard, createStorageApiKeyGuard } from "./api-key-middleware";
13
- export type { ApiKeyAuthOptions } from "./api-key-middleware";
14
- export { httpMethodToOperation, isOperationAllowed, isFunctionAllowed, isStorageAllowed } from "./api-key-permission-guard";
15
- export type { ApiKeyOperation } from "./api-key-permission-guard";
16
- export { createApiKeyRoutes } from "./api-key-routes";
17
- export type { ApiKeyRouteOptions } from "./api-key-routes";
9
+ export type { ApiKey, ApiKeyMasked, ApiKeyPermission, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest } from "./api-key-types.js";
10
+ export { createApiKeyStore } from "./api-key-store.js";
11
+ export type { ApiKeyStore } from "./api-key-store.js";
12
+ export { isApiKeyToken, validateApiKey, createApiKeyPreAuth, createFunctionApiKeyGuard, createStorageApiKeyGuard } from "./api-key-middleware.js";
13
+ export type { ApiKeyAuthOptions } from "./api-key-middleware.js";
14
+ export { httpMethodToOperation, isOperationAllowed, isFunctionAllowed, isStorageAllowed } from "./api-key-permission-guard.js";
15
+ export type { ApiKeyOperation } from "./api-key-permission-guard.js";
16
+ export { createApiKeyRoutes } from "./api-key-routes.js";
17
+ export type { ApiKeyRouteOptions } from "./api-key-routes.js";
@@ -1,5 +1,5 @@
1
- import type { OAuthProvider } from "./interfaces";
2
- import { type OAuthCodeFlowPayload } from "./oauth-code-flow";
1
+ import type { OAuthProvider } from "./interfaces.js";
2
+ import { type OAuthCodeFlowPayload } from "./oauth-code-flow.js";
3
3
  /** Extra field Apple's client sends that no other provider has. */
4
4
  export interface AppleCodeFlowPayload extends OAuthCodeFlowPayload {
5
5
  /**
@@ -36,9 +36,9 @@
36
36
  * };
37
37
  * ```
38
38
  */
39
- import type { PasswordValidationResult } from "./password";
40
- import type { AuthRepository, UserData, CreateUserData } from "./interfaces";
41
- import type { EmailService, EmailConfig } from "../email";
39
+ import type { PasswordValidationResult } from "./password.js";
40
+ import type { AuthRepository, UserData, CreateUserData } from "./interfaces.js";
41
+ import type { EmailService, EmailConfig } from "../email/index.js";
42
42
  import type { AuthResponsePayload, TransformAuthResponseContext } from "@rebasepro/types";
43
43
  /**
44
44
  * Authentication method identifier for lifecycle hooks.
@@ -1,5 +1,5 @@
1
- import type { OAuthProvider } from "./interfaces";
2
- import { type OAuthCodeFlowPayload } from "./oauth-code-flow";
1
+ import type { OAuthProvider } from "./interfaces.js";
2
+ import { type OAuthCodeFlowPayload } from "./oauth-code-flow.js";
3
3
  /**
4
4
  * Creates a Bitbucket OAuth Provider integration (OAuth 2.0 consumer).
5
5
  */
@@ -10,9 +10,10 @@
10
10
  * present the same functionality through the pluggable `AuthAdapter` contract.
11
11
  */
12
12
  import type { AuthAdapter } from "@rebasepro/types";
13
- import type { AuthRepository, OAuthProvider } from "./interfaces";
14
- import type { AuthHooks } from "./auth-hooks";
15
- import type { EmailService, EmailConfig } from "../email";
13
+ import type { CaptchaConfig } from "./captcha.js";
14
+ import type { AuthRepository, OAuthProvider } from "./interfaces.js";
15
+ import type { AuthHooks } from "./auth-hooks.js";
16
+ import type { EmailService, EmailConfig } from "../email/index.js";
16
17
  /**
17
18
  * Configuration for the built-in Rebase auth adapter.
18
19
  *
@@ -50,6 +51,8 @@ export interface BuiltinAuthAdapterConfig {
50
51
  allowAnonymous?: boolean;
51
52
  /** Whether to expose the authenticated email→minimal-profile lookup route. */
52
53
  allowUserLookup?: boolean;
54
+ /** Bot protection for the auth routes. See `captcha.ts`. */
55
+ captcha?: CaptchaConfig;
53
56
  /** Default role to assign to new users. */
54
57
  defaultRole?: string;
55
58
  /** OAuth providers to register. */
@@ -65,7 +68,7 @@ export interface BuiltinAuthAdapterConfig {
65
68
  /** Enable magic link (passwordless email) login. Requires email service. */
66
69
  enableMagicLink?: boolean;
67
70
  /** Opt-in httpOnly cookie mode for refresh tokens. */
68
- cookieAuth?: import("./routes").CookieAuthConfig;
71
+ cookieAuth?: import("./routes.js").CookieAuthConfig;
69
72
  }
70
73
  /**
71
74
  * Create the built-in Rebase auth adapter.