@rebasepro/server 0.25.1 → 0.27.0

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 (179) hide show
  1. package/dist/{GCSStorageController-CRd9bFrc.js → GCSStorageController-BUClIfp0.js} +40 -3
  2. package/dist/GCSStorageController-BUClIfp0.js.map +1 -0
  3. package/dist/{S3StorageController-D00EFa5P.js → S3StorageController-CixCQEky.js} +58 -10
  4. package/dist/S3StorageController-CixCQEky.js.map +1 -0
  5. package/dist/access-BFAUvsSs.js +1897 -0
  6. package/dist/access-BFAUvsSs.js.map +1 -0
  7. package/dist/api/branch-routes.d.ts +25 -0
  8. package/dist/api/live-schema-routes.d.ts +10 -0
  9. package/dist/api/rest/api-generator.d.ts +9 -1
  10. package/dist/api/rest/idempotency.d.ts +15 -1
  11. package/dist/api/root-error-handler.d.ts +6 -5
  12. package/dist/api/types.d.ts +12 -0
  13. package/dist/{ast-schema-editor-mCeSC03x.js → ast-schema-editor-madTa9Hh.js} +2 -2
  14. package/dist/{ast-schema-editor-mCeSC03x.js.map → ast-schema-editor-madTa9Hh.js.map} +1 -1
  15. package/dist/auth/access.d.ts +10 -0
  16. package/dist/auth/adapter-middleware.d.ts +2 -1
  17. package/dist/auth/adapter-service-key.d.ts +24 -0
  18. package/dist/auth/admin-users-route.d.ts +3 -0
  19. package/dist/auth/api-keys/api-key-middleware.d.ts +21 -1
  20. package/dist/auth/api-keys/api-key-store.d.ts +8 -1
  21. package/dist/auth/api-keys/key-grant.d.ts +18 -1
  22. package/dist/auth/apple-oauth.d.ts +39 -10
  23. package/dist/auth/capabilities.d.ts +2 -0
  24. package/dist/auth/expired-token-sweep.d.ts +5 -0
  25. package/dist/auth/impersonation.d.ts +3 -1
  26. package/dist/auth/interfaces.d.ts +55 -0
  27. package/dist/auth/jwt.d.ts +8 -2
  28. package/dist/auth/oauth-signin-policy.d.ts +21 -35
  29. package/dist/auth/rls-scope.d.ts +17 -7
  30. package/dist/auth/rls-simulator-routes.d.ts +51 -0
  31. package/dist/auth/simulation-read-only.d.ts +28 -0
  32. package/dist/auth/simulation.d.ts +141 -0
  33. package/dist/auth/sql-rate-limit-store.d.ts +15 -1
  34. package/dist/{auth-Dkvo2tTJ.js → auth-DDXPw0mn.js} +527 -1883
  35. package/dist/auth-DDXPw0mn.js.map +1 -0
  36. package/dist/auth_adapter-B7RUMk6e.js +89 -0
  37. package/dist/auth_adapter-B7RUMk6e.js.map +1 -0
  38. package/dist/backend/create-backend.d.ts +6 -0
  39. package/dist/backend/options.d.ts +38 -5
  40. package/dist/{backend-DTAOsLQc.js → backend-CaG_Jyso.js} +9 -2
  41. package/dist/backend-CaG_Jyso.js.map +1 -0
  42. package/dist/{backup-B9m3cb3X.js → backup-B6brPSeB.js} +6 -6
  43. package/dist/{backup-B9m3cb3X.js.map → backup-B6brPSeB.js.map} +1 -1
  44. package/dist/boot/boot.d.ts +2 -15
  45. package/dist/boot/ddl-bootstrap.d.ts +34 -0
  46. package/dist/boot/env.d.ts +12 -0
  47. package/dist/boot/fetch-bundle.d.ts +5 -1
  48. package/dist/boot/provision-only.d.ts +23 -0
  49. package/dist/boot/provision.d.ts +53 -2
  50. package/dist/boot/role.d.ts +2 -0
  51. package/dist/boot/schema-change-recorder.d.ts +45 -0
  52. package/dist/boot/security-headers.d.ts +22 -0
  53. package/dist/branch-routes-B2vvEx53.js +84 -0
  54. package/dist/branch-routes-B2vvEx53.js.map +1 -0
  55. package/dist/{contract-routes-CsFXW7j4.js → contract-routes-CU2A3JnF.js} +2 -2
  56. package/dist/{contract-routes-CsFXW7j4.js.map → contract-routes-CU2A3JnF.js.map} +1 -1
  57. package/dist/cron/cron-loader.d.ts +4 -0
  58. package/dist/cron/cron-store.d.ts +8 -1
  59. package/dist/{cron-loader-Dj6lA4HQ.js → cron-loader-CC1Jy_KN.js} +14 -6
  60. package/dist/cron-loader-CC1Jy_KN.js.map +1 -0
  61. package/dist/{cron-routes-CwbLZguO.js → cron-routes-BK60Rn1r.js} +3 -3
  62. package/dist/{cron-routes-CwbLZguO.js.map → cron-routes-BK60Rn1r.js.map} +1 -1
  63. package/dist/{cron-scheduler-B04ACoUE.js → cron-scheduler-DyCjPlQR.js} +40 -27
  64. package/dist/cron-scheduler-DyCjPlQR.js.map +1 -0
  65. package/dist/{cron-store-DkyfuLOH.js → cron-store-DLn11M8H.js} +10 -9
  66. package/dist/cron-store-DLn11M8H.js.map +1 -0
  67. package/dist/{strings.es-BeZWAodn.js → data_driver-D0mg1Y_x.js} +2 -90
  68. package/dist/data_driver-D0mg1Y_x.js.map +1 -0
  69. package/dist/{ddl-bootstrap-Ck20GSIX.js → ddl-bootstrap-CjRrn12l.js} +91 -2
  70. package/dist/ddl-bootstrap-CjRrn12l.js.map +1 -0
  71. package/dist/deploy/pod-contract.d.ts +1 -1
  72. package/dist/{load-failure-L5hvfDoG.js → dynamic-import-Bi3XK5y-.js} +30 -18
  73. package/dist/dynamic-import-Bi3XK5y-.js.map +1 -0
  74. package/dist/email/dev-sink.d.ts +6 -0
  75. package/dist/email/index.d.ts +1 -1
  76. package/dist/{soft-delete-params-BmlVwecC.js → field-access-DYsvjI_P.js} +27 -57
  77. package/dist/field-access-DYsvjI_P.js.map +1 -0
  78. package/dist/{filter-dialect-O1HK6Nvr.js → filter-dialect-TrKFWLqT.js} +3 -3
  79. package/dist/{filter-dialect-O1HK6Nvr.js.map → filter-dialect-TrKFWLqT.js.map} +1 -1
  80. package/dist/{function-loader-KKDqTcIr.js → function-loader-eFigStYX.js} +34 -18
  81. package/dist/function-loader-eFigStYX.js.map +1 -0
  82. package/dist/functions/function-loader.d.ts +5 -0
  83. package/dist/functions/hono-like.d.ts +12 -0
  84. package/dist/functions/index.js +19 -1
  85. package/dist/functions/index.js.map +1 -1
  86. package/dist/functions/request-timeout.d.ts +3 -3
  87. package/dist/history/history-routes.d.ts +6 -0
  88. package/dist/history/retention-sweep.d.ts +5 -0
  89. package/dist/{history-recorder-B2rkuhuy.js → history-recorder-Bsau7h4X.js} +6 -6
  90. package/dist/history-recorder-Bsau7h4X.js.map +1 -0
  91. package/dist/{history-store-DPofGVDp.js → history-store-BQz5YCkW.js} +26 -2
  92. package/dist/history-store-BQz5YCkW.js.map +1 -0
  93. package/dist/index.d.ts +4 -2
  94. package/dist/index.es.js +3026 -611
  95. package/dist/index.es.js.map +1 -1
  96. package/dist/init/docs.d.ts +1 -1
  97. package/dist/init/health.d.ts +13 -0
  98. package/dist/init/process-safety.d.ts +4 -3
  99. package/dist/init/shutdown.d.ts +8 -0
  100. package/dist/init.d.ts +6 -1
  101. package/dist/jobs/job-store.d.ts +8 -1
  102. package/dist/{jobs-h1WRq3cp.js → jobs-Co6Ni5HP.js} +6 -6
  103. package/dist/jobs-Co6Ni5HP.js.map +1 -0
  104. package/dist/{jwt-D3oFauZI.js → jwt-rDS0884_.js} +4 -3
  105. package/dist/{jwt-D3oFauZI.js.map → jwt-rDS0884_.js.map} +1 -1
  106. package/dist/{keys-COzQ2aE8.js → keys-BXcdRNhJ.js} +2 -2
  107. package/dist/{keys-COzQ2aE8.js.map → keys-BXcdRNhJ.js.map} +1 -1
  108. package/dist/mcp/consent-page.d.ts +38 -1
  109. package/dist/mcp/mcp-routes.d.ts +9 -0
  110. package/dist/mcp/mcp-tools.d.ts +7 -1
  111. package/dist/mcp/oauth-store.d.ts +12 -5
  112. package/dist/metrics/history-recorder.d.ts +4 -1
  113. package/dist/metrics/history-store.d.ts +8 -0
  114. package/dist/metrics/index.d.ts +8 -0
  115. package/dist/metrics/realtime.d.ts +25 -0
  116. package/dist/{offline-BrqCRgih-BtDB1ecy.js → offline-AvuEcg7u-DFHL98OT.js} +127 -40
  117. package/dist/offline-AvuEcg7u-DFHL98OT.js.map +1 -0
  118. package/dist/{offline-store-BhYXViha-BW5j1We_.js → offline-store-BhYXViha-YTmjBpo2.js} +5 -5
  119. package/dist/{offline-store-BhYXViha-BW5j1We_.js.map → offline-store-BhYXViha-YTmjBpo2.js.map} +1 -1
  120. package/dist/{openapi-generator-BjHr6upl.js → openapi-generator-CyxEtYEX.js} +61 -22
  121. package/dist/openapi-generator-CyxEtYEX.js.map +1 -0
  122. package/dist/{proxy-CH8Jsovg.js → proxy-BYir8tWK.js} +4 -6
  123. package/dist/proxy-BYir8tWK.js.map +1 -0
  124. package/dist/{query-parser-otFZqJsC.js → query-parser-CDXWf2hH.js} +6 -5
  125. package/dist/{query-parser-otFZqJsC.js.map → query-parser-CDXWf2hH.js.map} +1 -1
  126. package/dist/{request-timeout-59crS-9u.js → request-timeout-DVjo-c_8.js} +4 -4
  127. package/dist/request-timeout-DVjo-c_8.js.map +1 -0
  128. package/dist/rls-simulator-routes-bEY7-5-u.js +190 -0
  129. package/dist/rls-simulator-routes-bEY7-5-u.js.map +1 -0
  130. package/dist/schema-edit/deployed-schema-guard.d.ts +47 -0
  131. package/dist/{schema-editor-routes-Bsut0bCC.js → schema-editor-routes-Dc3DU_jm.js} +3 -3
  132. package/dist/{schema-editor-routes-Bsut0bCC.js.map → schema-editor-routes-Dc3DU_jm.js.map} +1 -1
  133. package/dist/services/routed-realtime-service.d.ts +1 -1
  134. package/dist/soft-delete-params-BRONCOA2.js +59 -0
  135. package/dist/soft-delete-params-BRONCOA2.js.map +1 -0
  136. package/dist/{sql-export-routes-DmB_uZ4l.js → sql-export-routes-QycX8W8S.js} +38 -4
  137. package/dist/sql-export-routes-QycX8W8S.js.map +1 -0
  138. package/dist/{src-D5Y3N-S4.js → src-Bh9LRPb9.js} +21 -2
  139. package/dist/{src-D5Y3N-S4.js.map → src-Bh9LRPb9.js.map} +1 -1
  140. package/dist/storage/GCSStorageController.d.ts +11 -1
  141. package/dist/storage/LocalStorageController.d.ts +16 -4
  142. package/dist/storage/S3StorageController.d.ts +6 -2
  143. package/dist/storage/index.d.ts +1 -0
  144. package/dist/storage/maintenance-keys.d.ts +17 -0
  145. package/dist/storage/maintenance-routes.d.ts +28 -5
  146. package/dist/storage/maintenance.d.ts +136 -4
  147. package/dist/storage/orphan-scans.d.ts +120 -0
  148. package/dist/storage/policies.d.ts +1 -1
  149. package/dist/storage/streams.d.ts +17 -0
  150. package/dist/storage/types.d.ts +26 -33
  151. package/dist/strings.es-B7QLnHh2.js +96 -0
  152. package/dist/strings.es-B7QLnHh2.js.map +1 -0
  153. package/dist/{upload-validation-Bgo626uY.js → upload-validation-CkkQGs-j.js} +40 -2
  154. package/dist/upload-validation-CkkQGs-j.js.map +1 -0
  155. package/dist/utils/load-failure.d.ts +9 -0
  156. package/package.json +5 -5
  157. package/dist/GCSStorageController-CRd9bFrc.js.map +0 -1
  158. package/dist/S3StorageController-D00EFa5P.js.map +0 -1
  159. package/dist/auth-Dkvo2tTJ.js.map +0 -1
  160. package/dist/auth_adapter-CIItCTc8.js +0 -21
  161. package/dist/auth_adapter-CIItCTc8.js.map +0 -1
  162. package/dist/backend-DTAOsLQc.js.map +0 -1
  163. package/dist/cron-loader-Dj6lA4HQ.js.map +0 -1
  164. package/dist/cron-scheduler-B04ACoUE.js.map +0 -1
  165. package/dist/cron-store-DkyfuLOH.js.map +0 -1
  166. package/dist/ddl-bootstrap-Ck20GSIX.js.map +0 -1
  167. package/dist/function-loader-KKDqTcIr.js.map +0 -1
  168. package/dist/history-recorder-B2rkuhuy.js.map +0 -1
  169. package/dist/history-store-DPofGVDp.js.map +0 -1
  170. package/dist/jobs-h1WRq3cp.js.map +0 -1
  171. package/dist/load-failure-L5hvfDoG.js.map +0 -1
  172. package/dist/offline-BrqCRgih-BtDB1ecy.js.map +0 -1
  173. package/dist/openapi-generator-BjHr6upl.js.map +0 -1
  174. package/dist/proxy-CH8Jsovg.js.map +0 -1
  175. package/dist/request-timeout-59crS-9u.js.map +0 -1
  176. package/dist/soft-delete-params-BmlVwecC.js.map +0 -1
  177. package/dist/sql-export-routes-DmB_uZ4l.js.map +0 -1
  178. package/dist/strings.es-BeZWAodn.js.map +0 -1
  179. package/dist/upload-validation-Bgo626uY.js.map +0 -1
@@ -4,10 +4,28 @@ globalThis.process ??= __rebaseProcess;
4
4
  __rebaseCreateRequire(import.meta.url);
5
5
  import { n as __exportAll } from "./rolldown-runtime-dW7B1o5h.js";
6
6
  import { a as logger } from "./logger-CW8pmTS6.js";
7
- import { i as warnDeprecated, n as describeLoadFailure, r as nativeDynamicImport, t as SYNTAX_ERROR_ADVICE } from "./load-failure-L5hvfDoG.js";
7
+ import { a as warnDeprecated, i as describeLoadFailure, r as SYNTAX_ERROR_ADVICE, t as nativeDynamicImport } from "./dynamic-import-Bi3XK5y-.js";
8
8
  import * as fs$1 from "fs";
9
9
  import * as path$1 from "path";
10
10
  import { pathToFileURL } from "url";
11
+ //#region src/functions/hono-like.ts
12
+ /**
13
+ * Duck-type check for Hono apps.
14
+ *
15
+ * Not `instanceof Hono`: a project's own `hono` and the copy this package
16
+ * resolves are often different installs, which do not share a prototype, so
17
+ * `instanceof` answers false for a perfectly good app. Every Hono instance has
18
+ * `.fetch()` and `.routes`.
19
+ *
20
+ * Node-free: `defineFunction` uses it, and it is exported from the portable
21
+ * `@rebasepro/server/functions` entry point.
22
+ */
23
+ function isHonoLike(obj) {
24
+ if (!obj || typeof obj !== "object") return false;
25
+ const record = obj;
26
+ return typeof record.fetch === "function" && Array.isArray(record.routes);
27
+ }
28
+ //#endregion
11
29
  //#region src/functions/function-loader.ts
12
30
  var function_loader_exports = /* @__PURE__ */ __exportAll({
13
31
  functionList: () => functionList,
@@ -88,13 +106,19 @@ async function loadFunctionsWithDiagnostics(directory, importModule = nativeDyna
88
106
  * Never throws: a single malformed function must not crash server boot. The
89
107
  * backend mounts the router regardless and surfaces the count of skipped files
90
108
  * on the listing endpoint.
109
+ *
110
+ * `failed` is the part of `problems` that threw or did not parse. The rest are
111
+ * files the loader has no use for, and a helper beside the functions is one of
112
+ * those: it exports no app, and nothing is wrong with the project.
91
113
  */
92
114
  async function readFunctionsDirectory(directory, importModule = nativeDynamicImport) {
93
115
  const functions = {};
94
116
  const problems = [];
117
+ const failed = [];
95
118
  if (!fs$1.existsSync(directory)) return {
96
119
  functions,
97
- problems
120
+ problems,
121
+ failed
98
122
  };
99
123
  const entries = fs$1.readdirSync(directory, { withFileTypes: true });
100
124
  for (const entry of entries) {
@@ -136,13 +160,15 @@ async function readFunctionsDirectory(directory, importModule = nativeDynamicImp
136
160
  const exportType = typeof exported;
137
161
  const keys = exported && typeof exported === "object" ? Object.getOwnPropertyNames(Object.getPrototypeOf(exported)).slice(0, 10).join(", ") : "N/A";
138
162
  logger.warn(`[functions] ${file}: default export is not a Hono app or factory. Skipping.\n export type: ${exportType}${exported?.constructor?.name ? ` (${exported.constructor.name})` : ""}\n prototype methods: ${keys}\n Hint: ensure the function exports a Hono app created with the same hono version as the server.
139
- Author with \`defineFunction(...)\` from @rebasepro/server for a typed, checked contract.
163
+ Author with \`defineFunction(...)\` from @rebasepro/server/functions for a typed, checked contract.
140
164
  The loader checks for .fetch() and .routes — any Hono-compatible app will work.`);
141
165
  problems.push(`${file} (not a Hono app or factory)`);
142
166
  } catch (err) {
143
167
  const message = err instanceof Error ? err.message : String(err);
144
168
  logger.error(`[functions] Failed to load ${file}: ${message}`);
145
- problems.push(describeLoadFailure(file, err));
169
+ const failure = describeLoadFailure(file, err);
170
+ problems.push(failure);
171
+ failed.push(failure);
146
172
  }
147
173
  }
148
174
  }
@@ -156,21 +182,11 @@ async function readFunctionsDirectory(directory, importModule = nativeDynamicImp
156
182
  }
157
183
  return {
158
184
  functions,
159
- problems
185
+ problems,
186
+ failed
160
187
  };
161
188
  }
162
- /**
163
- * Duck-type check for Hono apps.
164
- * We avoid `instanceof Hono` because different Hono versions
165
- * installed in the user's project vs. our dependencies will
166
- * not share the same prototype, causing false negatives.
167
- */
168
- function isHonoLike(obj) {
169
- if (!obj || typeof obj !== "object") return false;
170
- const record = obj;
171
- return typeof record.fetch === "function" && Array.isArray(record.routes);
172
- }
173
189
  //#endregion
174
- export { loadFunctionsWithDiagnostics as i, loadFunctions as n, loadFunctionsFromDirectory as r, function_loader_exports as t };
190
+ export { isHonoLike as a, loadFunctionsWithDiagnostics as i, loadFunctions as n, loadFunctionsFromDirectory as r, function_loader_exports as t };
175
191
 
176
- //# sourceMappingURL=function-loader-KKDqTcIr.js.map
192
+ //# sourceMappingURL=function-loader-eFigStYX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-loader-eFigStYX.js","names":[],"sources":["../src/functions/hono-like.ts","../src/functions/function-loader.ts"],"sourcesContent":["/**\n * Duck-type check for Hono apps.\n *\n * Not `instanceof Hono`: a project's own `hono` and the copy this package\n * resolves are often different installs, which do not share a prototype, so\n * `instanceof` answers false for a perfectly good app. Every Hono instance has\n * `.fetch()` and `.routes`.\n *\n * Node-free: `defineFunction` uses it, and it is exported from the portable\n * `@rebasepro/server/functions` entry point.\n */\nexport function isHonoLike(obj: unknown): boolean {\n if (!obj || typeof obj !== \"object\") return false;\n const record = obj as Record<string, unknown>;\n return typeof record.fetch === \"function\" && Array.isArray(record.routes);\n}\n","import * as fs from \"fs\";\nimport * as path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { Hono } from \"hono\";\nimport type { HonoEnv } from \"../api/types\";\nimport { logger } from \"../utils/logger.js\";\nimport { nativeDynamicImport, type ModuleImporter } from \"../utils/dynamic-import.js\";\nimport { describeLoadFailure, SYNTAX_ERROR_ADVICE } from \"../utils/load-failure.js\";\nimport { warnDeprecated } from \"@rebasepro/common\";\nimport { isHonoLike } from \"./hono-like\";\n\n/**\n * One custom function: a Hono app, served at `<functions mount>/<name>`.\n *\n * What `defineFunction(...)` returns, and what a function file default-exports:\n * a Hono app over {@link HonoEnv}, the environment a function runs in — build\n * one by hand as `new Hono<HonoEnv>()`. Any Hono-compatible app works at\n * runtime — the loader checks for `.fetch()` and `.routes` rather than an\n * `instanceof`, because a project and the server can hold two copies of hono.\n */\nexport type FunctionApp = Hono<HonoEnv>;\n\n/**\n * Functions as values: the URL segment each one answers at, to its app.\n *\n * `functions: { \"send-invoice\": sendInvoice }` serves `sendInvoice` at\n * `/api/functions/send-invoice` — the same thing a file named\n * `functions/send-invoice.ts` does. {@link loadFunctions} returns exactly this\n * shape, so `functions: await loadFunctions(dir)` and `functionsDir: dir` serve\n * the same routes.\n */\nexport type FunctionsRecord = Record<string, FunctionApp>;\n\n/** How a directory of modules is read. Shared by the function and cron loaders. */\nexport interface LoadDirectoryOptions {\n /**\n * How a module file is imported. Defaults to the runtime's own `import()`;\n * a caller with its own loader hooks (tsx, a test runner's sandbox) passes\n * `url => import(url)` so they apply.\n */\n importModule?: ModuleImporter;\n /**\n * Called once for every file the loader saw and did **not** load, as\n * `<file> (<reason>)`. The files are skipped either way — one malformed\n * file must not take the others with it — and logged; this is how a caller\n * reports them anywhere else.\n */\n onSkip?: (problem: string) => void;\n}\n\n/**\n * Load the custom functions in a directory, as values.\n *\n * Each file default-exports a Hono app — `defineFunction(...)` — or a factory\n * returning one. The filename without its extension is the record key, which\n * is the URL segment it is served at: `functions/send-invoice.ts` →\n * `{ \"send-invoice\": app }`. Only the top level is read.\n *\n * Never throws for a bad file: it is skipped, logged, and passed to\n * `options.onSkip`.\n *\n * @example\n * ```ts\n * const functions = await loadFunctions(path.resolve(\"functions\"));\n * const backend = await createRebaseBackend({ database, functions, provision: true });\n * ```\n */\nexport async function loadFunctions(directory: string, options: LoadDirectoryOptions = {}): Promise<FunctionsRecord> {\n const { functions, problems } = await readFunctionsDirectory(directory, options.importModule);\n if (options.onSkip) for (const problem of problems) options.onSkip(problem);\n return functions;\n}\n\n/** A loaded function, by name. The shape {@link createFunctionRoutes} mounts. */\nexport interface LoadedFunction {\n /** Endpoint name derived from filename (e.g., \"send-invoice\") */\n name: string;\n /** The Hono sub-app to mount */\n app: FunctionApp;\n}\n\n/** What a directory of function files produced: what mounted, and what did not. */\nexport interface LoadedFunctions {\n /** The functions that will be served. */\n functions: LoadedFunction[];\n /**\n * One entry per file the loader saw and did **not** mount, each already\n * phrased as `<name> (<reason>)`.\n */\n problems: string[];\n}\n\n/** A record of functions as the list {@link createFunctionRoutes} mounts, in record order. */\nexport function functionList(functions: FunctionsRecord): LoadedFunction[] {\n return Object.entries(functions).map(([name, app]) => ({ name, app }));\n}\n\n/**\n * Extensions the bundler compiles (or a developer might reasonably write) that\n * this loader cannot import. `rebase build` globs `functions/**\\/*.ts`, so the\n * build's idea of \"a function file\" is strictly wider than the runtime's — the\n * worst direction for a mismatch to go. Anything listed here is reported as a\n * problem instead of vanishing; non-code files (`.md`, `.json`, `.txt`) stay\n * silent, because a README next to your functions is not a mistake.\n */\nconst UNSUPPORTED_CODE_EXTENSIONS = [\".mts\", \".cts\", \".tsx\", \".jsx\", \".mjs\", \".cjs\"];\n\n/**\n * @deprecated Use `loadFunctions` instead, which returns the functions as a\n * record keyed by name. Will be removed in a future release.\n */\nexport async function loadFunctionsFromDirectory(\n directory: string,\n importModule: ModuleImporter = nativeDynamicImport\n): Promise<LoadedFunction[]> {\n warnDeprecated(\n \"server.loadFunctionsFromDirectory\",\n \"`loadFunctionsFromDirectory` is deprecated; use `loadFunctions(dir)`, which returns `{ [name]: app }`.\"\n );\n return functionList((await readFunctionsDirectory(directory, importModule)).functions);\n}\n\n/**\n * @deprecated Use `loadFunctions` instead, with `onSkip` to collect the files\n * it skipped. Will be removed in a future release.\n */\nexport async function loadFunctionsWithDiagnostics(\n directory: string,\n importModule: ModuleImporter = nativeDynamicImport\n): Promise<LoadedFunctions> {\n warnDeprecated(\n \"server.loadFunctionsWithDiagnostics\",\n \"`loadFunctionsWithDiagnostics` is deprecated; use `loadFunctions(dir, { onSkip })`, which returns `{ [name]: app }`.\"\n );\n const { functions, problems } = await readFunctionsDirectory(directory, importModule);\n return { functions: functionList(functions), problems };\n}\n\n/**\n * Read a directory of function files: what loaded, keyed by name, and one\n * `<file> (<reason>)` per file that did not.\n *\n * Never throws: a single malformed function must not crash server boot. The\n * backend mounts the router regardless and surfaces the count of skipped files\n * on the listing endpoint.\n *\n * `failed` is the part of `problems` that threw or did not parse. The rest are\n * files the loader has no use for, and a helper beside the functions is one of\n * those: it exports no app, and nothing is wrong with the project.\n */\nexport async function readFunctionsDirectory(\n directory: string,\n importModule: ModuleImporter = nativeDynamicImport\n): Promise<{ functions: FunctionsRecord; problems: string[]; failed: string[] }> {\n const functions: FunctionsRecord = {};\n // Aggregate problem files so a broken function surfaces as one loud\n // summary line, not just a warning buried per-file. We still don't throw:\n // a single malformed function must not crash server boot.\n const problems: string[] = [];\n const failed: string[] = [];\n\n if (!fs.existsSync(directory)) {\n return { functions, problems, failed };\n }\n\n // `withFileTypes` so a directory entry is a *reported* skip rather than a\n // filter miss. `readdirSync(dir)` returned bare names, and a subdirectory\n // simply failed the `.ts`/`.js` test — so `functions/admin/users.ts` was\n // compiled by `rebase build`, shipped in the bundle, and then dropped at\n // boot without a single log line.\n const entries = fs.readdirSync(directory, { withFileTypes: true });\n for (const entry of entries) {\n const file = entry.name;\n\n if (entry.isDirectory()) {\n // Dot-directories are tooling (`.git`, `.turbo`), not intent.\n if (file.startsWith(\".\") || file === \"node_modules\") continue;\n logger.warn(\n `[functions] ${file}/: subdirectory ignored. Functions are loaded from the top level of ` +\n `${directory} only, so nothing under ${file}/ is served. Move the file up (or flatten the ` +\n \"name: `admin/users.ts` → `admin-users.ts`).\"\n );\n problems.push(`${file}/ (subdirectory — functions are not loaded recursively)`);\n continue;\n }\n\n const extension = path.extname(file);\n if (\n !file.startsWith(\".\") &&\n !file.includes(\".test.\") &&\n UNSUPPORTED_CODE_EXTENSIONS.includes(extension)\n ) {\n logger.warn(\n `[functions] ${file}: ${extension} files are not loaded. Rename it to .ts (or .js) to serve it.`\n );\n problems.push(`${file} (unsupported extension ${extension})`);\n continue;\n }\n\n if (\n (file.endsWith(\".ts\") || file.endsWith(\".js\")) &&\n // Dotfiles: notably macOS bsdtar AppleDouble sidecars (`._foo.ts`),\n // binary blobs that cannot be imported.\n !file.startsWith(\".\") &&\n !file.includes(\".test.\") &&\n !file.endsWith(\".d.ts\") &&\n file !== \"index.ts\" &&\n file !== \"index.js\"\n ) {\n const filePath = path.join(directory, file);\n try {\n const fileUrl = pathToFileURL(filePath).href;\n\n const mod = await importModule(fileUrl);\n\n const exported = mod.default;\n\n if (!exported) {\n logger.warn(`[functions] ${file}: no default export. Skipping.`);\n problems.push(`${file} (no default export)`);\n continue;\n }\n\n // Accept a Hono instance — use duck-typing to handle different\n // Hono versions which may not share the same prototype.\n const app = isHonoLike(exported)\n ? exported as FunctionApp\n // Also accept a factory function that returns a Hono instance\n : typeof exported === \"function\" ? exported() : undefined;\n if (isHonoLike(app)) {\n const name = path.basename(file, path.extname(file));\n // `send.ts` and `send.js` side by side name one URL. A\n // record holds one app per name, so the second is reported\n // rather than silently replacing the first.\n if (Object.hasOwn(functions, name)) {\n logger.warn(`[functions] ${file}: another file is already served as '${name}'. Skipping.`);\n problems.push(`${file} (another file is already served as '${name}')`);\n continue;\n }\n functions[name] = app as FunctionApp;\n logger.debug(`⚡ Loaded function route: ${name}`);\n continue;\n }\n\n // Provide actionable diagnostics\n const exportType = typeof exported;\n const keys = exported && typeof exported === \"object\"\n ? Object.getOwnPropertyNames(Object.getPrototypeOf(exported)).slice(0, 10).join(\", \")\n : \"N/A\";\n logger.warn(\n `[functions] ${file}: default export is not a Hono app or factory. Skipping.\\n` +\n ` export type: ${exportType}${exported?.constructor?.name ? ` (${exported.constructor.name})` : \"\"}\\n` +\n ` prototype methods: ${keys}\\n` +\n \" Hint: ensure the function exports a Hono app created with the same hono version as the server.\\n\" +\n \" Author with `defineFunction(...)` from @rebasepro/server/functions for a typed, checked contract.\\n\" +\n \" The loader checks for .fetch() and .routes — any Hono-compatible app will work.\"\n );\n problems.push(`${file} (not a Hono app or factory)`);\n } catch (err: unknown) {\n const message =\n err instanceof Error ? err.message : String(err);\n logger.error(`[functions] Failed to load ${file}: ${message}`);\n const failure = describeLoadFailure(file, err);\n problems.push(failure);\n failed.push(failure);\n }\n }\n }\n\n if (problems.length > 0) {\n // Advice keyed to what actually went wrong. The old line said\n // \"author them with `defineFunction(...)`\" for every failure — which is\n // the fix for a wrong export shape and no help at all for the commonest\n // one: a file that threw while being imported, usually a module-scope\n // `process.env.X` read that came back undefined. Told to reach for\n // `defineFunction`, an author rewrites a file whose export was already\n // correct and gets the same failure.\n const advice: string[] = [];\n if (problems.some(p => p.includes(\"(syntax error\"))) {\n advice.push(SYNTAX_ERROR_ADVICE);\n }\n if (problems.some(p => p.includes(\"(threw:\"))) {\n advice.push(\n \" A file that threw ran at import time. Read configuration *inside* a handler \" +\n \"(`requireEnv(c, \\\"STRIPE_KEY\\\")`, or a lazily-built client) rather than at module \" +\n \"scope, where one undefined variable takes the whole file down before any route exists.\"\n );\n }\n if (problems.some(p => p.includes(\"(no default export)\"))) {\n advice.push(\n \" A file with no default export exports nothing the loader can mount. \" +\n \"`export default defineFunction((app) => { … })`.\"\n );\n }\n if (problems.some(p => p.includes(\"(not a Hono app or factory)\"))) {\n advice.push(\n \" A default export the loader did not recognise is usually two copies of hono. \" +\n \"Author with `defineFunction(...)` from @rebasepro/server/functions, which uses the \" +\n \"server's own copy.\"\n );\n }\n logger.warn(\n `[functions] ${problems.length} function file(s) were skipped and will NOT be served:\\n` +\n problems.map((p) => ` - ${p}`).join(\"\\n\") + \"\\n\" +\n advice.join(\"\\n\")\n );\n }\n\n return { functions, problems, failed };\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA,SAAgB,WAAW,KAAuB;CAC9C,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,SAAS;CACf,OAAO,OAAO,OAAO,UAAU,cAAc,MAAM,QAAQ,OAAO,MAAM;AAC5E;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoDA,eAAsB,cAAc,WAAmB,UAAgC,CAAC,GAA6B;CACjH,MAAM,EAAE,WAAW,aAAa,MAAM,uBAAuB,WAAW,QAAQ,YAAY;CAC5F,IAAI,QAAQ,QAAQ,KAAK,MAAM,WAAW,UAAU,QAAQ,OAAO,OAAO;CAC1E,OAAO;AACX;;AAsBA,SAAgB,aAAa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,UAAU,OAAO,GAAG;IACnD,OAAO,MAAM,8BAA8B,KAAK,IAAI,SAAS;IAC7D,MAAM,UAAU,oBAAoB,MAAM,GAAG;IAC7C,SAAS,KAAK,OAAO;IACrB,OAAO,KAAK,OAAO;GACvB;EACJ;CACJ;CAEA,IAAI,SAAS,SAAS,GAAG;EAQrB,MAAM,SAAmB,CAAC;EAC1B,IAAI,SAAS,MAAK,MAAK,EAAE,SAAS,eAAe,CAAC,GAC9C,OAAO,KAAK,mBAAmB;EAEnC,IAAI,SAAS,MAAK,MAAK,EAAE,SAAS,SAAS,CAAC,GACxC,OAAO,KACH,wPAGJ;EAEJ,IAAI,SAAS,MAAK,MAAK,EAAE,SAAS,qBAAqB,CAAC,GACpD,OAAO,KACH,wHAEJ;EAEJ,IAAI,SAAS,MAAK,MAAK,EAAE,SAAS,6BAA6B,CAAC,GAC5D,OAAO,KACH,sLAGJ;EAEJ,OAAO,KACH,eAAe,SAAS,OAAO,4DAC/B,SAAS,KAAK,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,OAC7C,OAAO,KAAK,IAAI,CACpB;CACJ;CAEA,OAAO;EAAE;EAAW;EAAU;CAAO;AACzC"}
@@ -91,8 +91,13 @@ export declare function loadFunctionsWithDiagnostics(directory: string, importMo
91
91
  * Never throws: a single malformed function must not crash server boot. The
92
92
  * backend mounts the router regardless and surfaces the count of skipped files
93
93
  * on the listing endpoint.
94
+ *
95
+ * `failed` is the part of `problems` that threw or did not parse. The rest are
96
+ * files the loader has no use for, and a helper beside the functions is one of
97
+ * those: it exports no app, and nothing is wrong with the project.
94
98
  */
95
99
  export declare function readFunctionsDirectory(directory: string, importModule?: ModuleImporter): Promise<{
96
100
  functions: FunctionsRecord;
97
101
  problems: string[];
102
+ failed: string[];
98
103
  }>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Duck-type check for Hono apps.
3
+ *
4
+ * Not `instanceof Hono`: a project's own `hono` and the copy this package
5
+ * resolves are often different installs, which do not share a prototype, so
6
+ * `instanceof` answers false for a perfectly good app. Every Hono instance has
7
+ * `.fetch()` and `.routes`.
8
+ *
9
+ * Node-free: `defineFunction` uses it, and it is exported from the portable
10
+ * `@rebasepro/server/functions` entry point.
11
+ */
12
+ export declare function isHonoLike(obj: unknown): boolean;
@@ -194,6 +194,24 @@ var rebase = new Proxy({}, {
194
194
  }
195
195
  });
196
196
  //#endregion
197
+ //#region src/functions/hono-like.ts
198
+ /**
199
+ * Duck-type check for Hono apps.
200
+ *
201
+ * Not `instanceof Hono`: a project's own `hono` and the copy this package
202
+ * resolves are often different installs, which do not share a prototype, so
203
+ * `instanceof` answers false for a perfectly good app. Every Hono instance has
204
+ * `.fetch()` and `.routes`.
205
+ *
206
+ * Node-free: `defineFunction` uses it, and it is exported from the portable
207
+ * `@rebasepro/server/functions` entry point.
208
+ */
209
+ function isHonoLike(obj) {
210
+ if (!obj || typeof obj !== "object") return false;
211
+ const record = obj;
212
+ return typeof record.fetch === "function" && Array.isArray(record.routes);
213
+ }
214
+ //#endregion
197
215
  //#region src/functions/define-function.ts
198
216
  /**
199
217
  * The `rebase` handle, seen through the `Database` a function names.
@@ -246,7 +264,7 @@ function typedSingleton() {
246
264
  function defineFunction(definition) {
247
265
  const app = new Hono();
248
266
  const returned = definition(app, { rebase: typedSingleton() });
249
- return returned instanceof Hono ? returned : app;
267
+ return isHonoLike(returned) ? returned : app;
250
268
  }
251
269
  //#endregion
252
270
  //#region src/auth/admin-roles.ts