@rebasepro/server 0.31.0-canary.g902a0ce → 0.31.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.
- package/dist/{access-CCsVee6z.js → access-D1CTJSLK.js} +3 -1
- package/dist/access-D1CTJSLK.js.map +1 -0
- package/dist/{access-CSfmyM87.js → access-Dtu87BMj.js} +2 -2
- package/dist/{access-CSfmyM87.js.map → access-Dtu87BMj.js.map} +1 -1
- package/dist/{auth-Blo1R8rc.js → auth-BOz84vIr.js} +3 -3
- package/dist/{auth-Blo1R8rc.js.map → auth-BOz84vIr.js.map} +1 -1
- package/dist/auth-secrets-BZUH9916.js +60 -0
- package/dist/auth-secrets-BZUH9916.js.map +1 -0
- package/dist/{contract-routes-WwMWHWS9.js → contract-routes-o5oqNhfc.js} +2 -2
- package/dist/{contract-routes-WwMWHWS9.js.map → contract-routes-o5oqNhfc.js.map} +1 -1
- package/dist/{cron-routes-Cqm5wQsK.js → cron-routes-BOu-bY7I.js} +2 -2
- package/dist/{cron-routes-Cqm5wQsK.js.map → cron-routes-BOu-bY7I.js.map} +1 -1
- package/dist/{dist-CDIqWaSr.js → dist-fBcYxf4h.js} +2 -2
- package/dist/{dist-CDIqWaSr.js.map → dist-fBcYxf4h.js.map} +1 -1
- package/dist/index.es.js +21 -21
- package/dist/{load-schema-CtyLeq-H.js → load-schema-Cv5XLVjW.js} +2 -37
- package/dist/load-schema-Cv5XLVjW.js.map +1 -0
- package/dist/{openapi-generator-mn6hsEmw.js → openapi-generator-CoAFACMx.js} +2 -2
- package/dist/{openapi-generator-mn6hsEmw.js.map → openapi-generator-CoAFACMx.js.map} +1 -1
- package/dist/{query-parser-CkKSbs1s.js → query-parser-D9Uf8aha.js} +2 -2
- package/dist/{query-parser-CkKSbs1s.js.map → query-parser-D9Uf8aha.js.map} +1 -1
- package/dist/{rls-simulator-routes-BxzeNXmI.js → rls-simulator-routes-BvH6wI64.js} +2 -2
- package/dist/{rls-simulator-routes-BxzeNXmI.js.map → rls-simulator-routes-BvH6wI64.js.map} +1 -1
- package/dist/{schema-editor-routes-mPCyks4X.js → schema-editor-routes-CzITcAgt.js} +2 -2
- package/dist/{schema-editor-routes-mPCyks4X.js.map → schema-editor-routes-CzITcAgt.js.map} +1 -1
- package/dist/{schema-tables-D4MEBZFi.js → schema-tables-lJHnyqj4.js} +2 -2
- package/dist/{schema-tables-D4MEBZFi.js.map → schema-tables-lJHnyqj4.js.map} +1 -1
- package/dist/{schema-tables-routes-D3iLb5XU.js → schema-tables-routes-Uss-ljon.js} +3 -3
- package/dist/{schema-tables-routes-D3iLb5XU.js.map → schema-tables-routes-Uss-ljon.js.map} +1 -1
- package/dist/{table-source-editor-xvccIOH1.js → table-source-editor-qmyi5vxX.js} +2 -2
- package/dist/{table-source-editor-xvccIOH1.js.map → table-source-editor-qmyi5vxX.js.map} +1 -1
- package/package.json +5 -5
- package/dist/access-CCsVee6z.js.map +0 -1
- package/dist/load-schema-CtyLeq-H.js.map +0 -1
|
@@ -3,9 +3,9 @@ import __rebaseProcess from "process";
|
|
|
3
3
|
globalThis.process ??= __rebaseProcess;
|
|
4
4
|
__rebaseCreateRequire(import.meta.url);
|
|
5
5
|
import { Pn as __exportAll, Q as SCHEMA_VERSION_HEADER, Y as computeSchemaVersion } from "./src-DLIb1O9l.js";
|
|
6
|
-
import { a as serializeTables, i as schemaViewKey, n as compileServedPolicies, r as schemaViewFor } from "./schema-tables-
|
|
6
|
+
import { a as serializeTables, i as schemaViewKey, n as compileServedPolicies, r as schemaViewFor } from "./schema-tables-lJHnyqj4.js";
|
|
7
7
|
import { t as ApiError } from "./errors-DpTMfX77.js";
|
|
8
|
-
import { s as callerScopes } from "./access-
|
|
8
|
+
import { s as callerScopes } from "./access-Dtu87BMj.js";
|
|
9
9
|
import { Hono } from "hono";
|
|
10
10
|
//#region src/api/schema-tables-routes.ts
|
|
11
11
|
var schema_tables_routes_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -136,4 +136,4 @@ function createSchemaTablesRoutes(config) {
|
|
|
136
136
|
//#endregion
|
|
137
137
|
export { schema_tables_routes_exports as n, schemaCallerOf as t };
|
|
138
138
|
|
|
139
|
-
//# sourceMappingURL=schema-tables-routes-
|
|
139
|
+
//# sourceMappingURL=schema-tables-routes-Uss-ljon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-tables-routes-D3iLb5XU.js","names":[],"sources":["../src/api/schema-tables-routes.ts"],"sourcesContent":["import { Hono, type Context, type MiddlewareHandler } from \"hono\";\nimport {\n SCHEMA_VERSION_HEADER,\n computeSchemaVersion,\n type TableDescriptor\n} from \"@rebasepro/types\";\nimport type { HonoEnv } from \"./types\";\nimport { ApiError } from \"./errors\";\nimport { callerScopes } from \"../auth/access\";\nimport type { TableRegistry } from \"../schema/table-registry\";\nimport {\n compileServedPolicies,\n schemaViewFor,\n schemaViewKey,\n serializeTables,\n type SchemaCaller,\n type SchemaTablesPersons,\n type SchemaView,\n type TablePolicies\n} from \"./schema-tables\";\n\n/**\n * `GET {basePath}/schema/tables` — the tables this backend serves, as the\n * caller may see them — and `GET {basePath}/schema/tables/:slug`.\n *\n * The zero-config CMS renders every table from it, the Studio draws its schema\n * visualizer and RLS editor from it; the body is {@link serializeTables} for\n * the caller's view. Status codes:\n *\n * - `200` — a JSON array of `TableDescriptor` (one descriptor for `/:slug`),\n * with `ETag: W/\"<schemaVersion>-<view key>\"`, `Cache-Control: private,\n * no-cache` and the schema-version header. A signed-in person without\n * `schema:read` is described only the tables their roles can reach, with\n * only the rules that can apply to them, unless the backend says\n * `schemaTables: { persons: \"all\" }`; the view key carries their roles.\n * - `304` — `If-None-Match` named the current tag.\n * - `401` — nobody is signed in (and the backend did not opt into\n * `schemaTables: { public: true }`), or the credential sent is invalid.\n * - `403 SCOPE_MISSING` — a credential holding neither `schema:read` nor a\n * `data:*` scope.\n * - `404 SCHEMA_UNAVAILABLE` — no authentication is configured, so there is\n * no caller to redact for; `auth.requireAuth: false` does not change that.\n * - `404 TABLE_NOT_FOUND` — `/:slug` names a table this caller is not served.\n *\n * @module\n */\n\n/**\n * What the endpoint and `/api/meta/contract` both serve from: the registry's\n * descriptors and compiled policies, cached per registry revision.\n *\n * @group Schema\n */\nexport interface SchemaTablesService {\n /** The schema version the bodies describe. */\n version(): string;\n /** The tables a view is served. */\n tablesFor(view: SchemaView): TableDescriptor[];\n /** The `ETag` of what a view is served. */\n etagFor(view: SchemaView): string;\n}\n\n/**\n * Options of {@link createSchemaTablesService}.\n *\n * @group Schema\n */\nexport interface SchemaTablesServiceConfig {\n /** The descriptors served. Its revision invalidates every cache. */\n tableRegistry: Pick<TableRegistry, \"list\" | \"revision\">;\n /**\n * The declared tables: what the policy compiler reads. Introspected tables\n * are not among them — Rebase did not generate their policies, so it\n * serves none for them.\n */\n policySource: () => readonly TableDescriptor[];\n /**\n * The schema version the bundle recorded at build time, quoted while the\n * registry is as it was when the service was created. Recomputed from the\n * descriptors when absent, and after the registry changes: the recorded\n * stamp no longer describes it then.\n */\n schemaVersion?: string;\n}\n\n/** Distinct views cached per revision; more than this and the cache starts over. */\nconst MAX_CACHED_VIEWS = 256;\n\n/**\n * Build the cache both routes read.\n *\n * @group Schema\n */\nexport function createSchemaTablesService(config: SchemaTablesServiceConfig): SchemaTablesService {\n const registry = config.tableRegistry;\n const bootRevision = registry.revision;\n let cache: {\n revision: number;\n version: string;\n policies?: Map<string, TablePolicies>;\n bodies: Map<string, TableDescriptor[]>;\n } | undefined;\n\n const current = () => {\n if (cache && cache.revision === registry.revision) return cache;\n const version = registry.revision === bootRevision && config.schemaVersion\n ? config.schemaVersion\n : computeSchemaVersion(registry.list());\n cache = { revision: registry.revision, version, bodies: new Map() };\n return cache;\n };\n\n return {\n version: () => current().version,\n etagFor: (view) => `W/\"${current().version}-${schemaViewKey(view)}\"`,\n tablesFor: (view) => {\n const state = current();\n const key = schemaViewKey(view);\n const cached = state.bodies.get(key);\n if (cached) return cached;\n const tables = registry.list();\n if (view.privileged && !state.policies) {\n // A view has no policies of its own (`posture: \"view\"`).\n const policied = tables.filter(table => table.kind === \"table\").map(table => table.slug);\n state.policies = compileServedPolicies(config.policySource(), new Set(policied));\n }\n const body = serializeTables(tables, view, state.policies);\n if (state.bodies.size >= MAX_CACHED_VIEWS) state.bodies.clear();\n state.bodies.set(key, body);\n return body;\n }\n };\n}\n\n/**\n * Options of {@link createSchemaTablesRoutes}.\n *\n * @group Schema\n */\nexport interface SchemaTablesRoutesConfig {\n service: SchemaTablesService;\n /**\n * `false` when the backend has no authentication configured: every request\n * is answered `404 SCHEMA_UNAVAILABLE`.\n */\n available: boolean;\n /**\n * Identify the caller: verify whatever credential the request carries and\n * set `user` (and `scopes`, for a credential that narrows them). A request\n * with no credential must pass through with no `user`.\n */\n authenticate: MiddlewareHandler<HonoEnv>[];\n /** `schemaTables.public`: serve anonymous callers the tables with a public `select` rule. */\n publicTables?: boolean;\n /**\n * `schemaTables.persons`: what a signed-in person without `schema:read` is\n * described — the tables their roles can reach (`\"granted\"`, the default)\n * or every table (`\"all\"`). See {@link SchemaTablesPersons}.\n */\n persons?: SchemaTablesPersons;\n}\n\n/** The roles on the request's caller. */\nfunction rolesOf(c: Context<HonoEnv>): string[] {\n const user = c.get(\"user\");\n if (typeof user !== \"object\" || user === null || !(\"roles\" in user) || !Array.isArray(user.roles)) return [];\n return user.roles.filter((role): role is string => typeof role === \"string\");\n}\n\n/**\n * Who a request comes from, as the serializer judges it: nobody, a person\n * (their roles' scopes), or a credential (exactly the scopes it carries).\n *\n * @group Schema\n */\nexport function schemaCallerOf(c: Context<HonoEnv>): SchemaCaller {\n if (!c.get(\"user\")) return { kind: \"anonymous\", roles: [], scopes: [] };\n const narrowed = c.get(\"scopes\");\n return narrowed\n ? { kind: \"credential\", roles: rolesOf(c), scopes: narrowed }\n : { kind: \"person\", roles: rolesOf(c), scopes: callerScopes(c) };\n}\n\n/** Whether an `If-None-Match` header names this tag (or `*`). */\nfunction matches(header: string | undefined, etag: string): boolean {\n if (!header) return false;\n return header.split(\",\").map(tag => tag.trim()).some(tag => tag === etag || tag === \"*\");\n}\n\n/**\n * Mount `GET /tables` and `GET /tables/:slug` (the caller mounts the router at\n * `{basePath}/schema`).\n *\n * @group Schema\n */\nexport function createSchemaTablesRoutes(config: SchemaTablesRoutesConfig): Hono<HonoEnv> {\n const router = new Hono<HonoEnv>();\n\n if (!config.available) {\n router.all(\"/*\", (c) => c.json({\n error: {\n code: \"SCHEMA_UNAVAILABLE\",\n message: \"This backend serves its tables only to authenticated callers, and no authentication is \" +\n \"configured (no auth adapter and no auth.jwtSecret). Configure auth to enable GET /schema/tables.\"\n }\n }, 404));\n return router;\n }\n\n router.use(\"/*\", ...config.authenticate);\n\n const viewOf = (c: Context<HonoEnv>): SchemaView => {\n const caller = schemaCallerOf(c);\n if (caller.kind === \"anonymous\" && !config.publicTables) {\n throw ApiError.unauthenticated(\"Authentication required: the tables are described to signed-in callers and credentials only.\");\n }\n const view = schemaViewFor(caller, { persons: config.persons ?? \"granted\" });\n if (\"refused\" in view) throw new ApiError(403, \"SCOPE_MISSING\", view.message, { requiredScope: \"schema:read\" });\n return view;\n };\n\n const answer = <T>(c: Context<HonoEnv>, view: SchemaView, body: () => T): Response => {\n const etag = config.service.etagFor(view);\n c.header(\"ETag\", etag);\n c.header(\"Cache-Control\", \"private, no-cache\");\n c.header(\"Vary\", \"Authorization\");\n c.header(SCHEMA_VERSION_HEADER, config.service.version());\n if (matches(c.req.header(\"if-none-match\"), etag)) return c.body(null, 304);\n return c.json(body());\n };\n\n router.get(\"/tables\", (c) => {\n const view = viewOf(c);\n return answer(c, view, () => config.service.tablesFor(view));\n });\n\n router.get(\"/tables/:slug\", (c) => {\n const view = viewOf(c);\n const slug = c.req.param(\"slug\");\n const table = config.service.tablesFor(view).find(candidate => candidate.slug === slug);\n if (!table) throw ApiError.notFound(`No table \"${slug}\" is served to this caller.`, \"TABLE_NOT_FOUND\");\n return answer(c, view, () => table);\n });\n\n return router;\n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4B;EAClF,MAAM,OAAO,OAAO,QAAQ,QAAQ,IAAI;EACxC,EAAE,OAAO,QAAQ,IAAI;EACrB,EAAE,OAAO,iBAAiB,mBAAmB;EAC7C,EAAE,OAAO,QAAQ,eAAe;EAChC,EAAE,OAAO,uBAAuB,OAAO,QAAQ,QAAQ,CAAC;EACxD,IAAI,QAAQ,EAAE,IAAI,OAAO,eAAe,GAAG,IAAI,GAAG,OAAO,EAAE,KAAK,MAAM,GAAG;EACzE,OAAO,EAAE,KAAK,KAAK,CAAC;CACxB;CAEA,OAAO,IAAI,YAAY,MAAM;EACzB,MAAM,OAAO,OAAO,CAAC;EACrB,OAAO,OAAO,GAAG,YAAY,OAAO,QAAQ,UAAU,IAAI,CAAC;CAC/D,CAAC;CAED,OAAO,IAAI,kBAAkB,MAAM;EAC/B,MAAM,OAAO,OAAO,CAAC;EACrB,MAAM,OAAO,EAAE,IAAI,MAAM,MAAM;EAC/B,MAAM,QAAQ,OAAO,QAAQ,UAAU,IAAI,CAAC,CAAC,MAAK,cAAa,UAAU,SAAS,IAAI;EACtF,IAAI,CAAC,OAAO,MAAM,SAAS,SAAS,aAAa,KAAK,8BAA8B,iBAAiB;EACrG,OAAO,OAAO,GAAG,YAAY,KAAK;CACtC,CAAC;CAED,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"schema-tables-routes-Uss-ljon.js","names":[],"sources":["../src/api/schema-tables-routes.ts"],"sourcesContent":["import { Hono, type Context, type MiddlewareHandler } from \"hono\";\nimport {\n SCHEMA_VERSION_HEADER,\n computeSchemaVersion,\n type TableDescriptor\n} from \"@rebasepro/types\";\nimport type { HonoEnv } from \"./types\";\nimport { ApiError } from \"./errors\";\nimport { callerScopes } from \"../auth/access\";\nimport type { TableRegistry } from \"../schema/table-registry\";\nimport {\n compileServedPolicies,\n schemaViewFor,\n schemaViewKey,\n serializeTables,\n type SchemaCaller,\n type SchemaTablesPersons,\n type SchemaView,\n type TablePolicies\n} from \"./schema-tables\";\n\n/**\n * `GET {basePath}/schema/tables` — the tables this backend serves, as the\n * caller may see them — and `GET {basePath}/schema/tables/:slug`.\n *\n * The zero-config CMS renders every table from it, the Studio draws its schema\n * visualizer and RLS editor from it; the body is {@link serializeTables} for\n * the caller's view. Status codes:\n *\n * - `200` — a JSON array of `TableDescriptor` (one descriptor for `/:slug`),\n * with `ETag: W/\"<schemaVersion>-<view key>\"`, `Cache-Control: private,\n * no-cache` and the schema-version header. A signed-in person without\n * `schema:read` is described only the tables their roles can reach, with\n * only the rules that can apply to them, unless the backend says\n * `schemaTables: { persons: \"all\" }`; the view key carries their roles.\n * - `304` — `If-None-Match` named the current tag.\n * - `401` — nobody is signed in (and the backend did not opt into\n * `schemaTables: { public: true }`), or the credential sent is invalid.\n * - `403 SCOPE_MISSING` — a credential holding neither `schema:read` nor a\n * `data:*` scope.\n * - `404 SCHEMA_UNAVAILABLE` — no authentication is configured, so there is\n * no caller to redact for; `auth.requireAuth: false` does not change that.\n * - `404 TABLE_NOT_FOUND` — `/:slug` names a table this caller is not served.\n *\n * @module\n */\n\n/**\n * What the endpoint and `/api/meta/contract` both serve from: the registry's\n * descriptors and compiled policies, cached per registry revision.\n *\n * @group Schema\n */\nexport interface SchemaTablesService {\n /** The schema version the bodies describe. */\n version(): string;\n /** The tables a view is served. */\n tablesFor(view: SchemaView): TableDescriptor[];\n /** The `ETag` of what a view is served. */\n etagFor(view: SchemaView): string;\n}\n\n/**\n * Options of {@link createSchemaTablesService}.\n *\n * @group Schema\n */\nexport interface SchemaTablesServiceConfig {\n /** The descriptors served. Its revision invalidates every cache. */\n tableRegistry: Pick<TableRegistry, \"list\" | \"revision\">;\n /**\n * The declared tables: what the policy compiler reads. Introspected tables\n * are not among them — Rebase did not generate their policies, so it\n * serves none for them.\n */\n policySource: () => readonly TableDescriptor[];\n /**\n * The schema version the bundle recorded at build time, quoted while the\n * registry is as it was when the service was created. Recomputed from the\n * descriptors when absent, and after the registry changes: the recorded\n * stamp no longer describes it then.\n */\n schemaVersion?: string;\n}\n\n/** Distinct views cached per revision; more than this and the cache starts over. */\nconst MAX_CACHED_VIEWS = 256;\n\n/**\n * Build the cache both routes read.\n *\n * @group Schema\n */\nexport function createSchemaTablesService(config: SchemaTablesServiceConfig): SchemaTablesService {\n const registry = config.tableRegistry;\n const bootRevision = registry.revision;\n let cache: {\n revision: number;\n version: string;\n policies?: Map<string, TablePolicies>;\n bodies: Map<string, TableDescriptor[]>;\n } | undefined;\n\n const current = () => {\n if (cache && cache.revision === registry.revision) return cache;\n const version = registry.revision === bootRevision && config.schemaVersion\n ? config.schemaVersion\n : computeSchemaVersion(registry.list());\n cache = { revision: registry.revision, version, bodies: new Map() };\n return cache;\n };\n\n return {\n version: () => current().version,\n etagFor: (view) => `W/\"${current().version}-${schemaViewKey(view)}\"`,\n tablesFor: (view) => {\n const state = current();\n const key = schemaViewKey(view);\n const cached = state.bodies.get(key);\n if (cached) return cached;\n const tables = registry.list();\n if (view.privileged && !state.policies) {\n // A view has no policies of its own (`posture: \"view\"`).\n const policied = tables.filter(table => table.kind === \"table\").map(table => table.slug);\n state.policies = compileServedPolicies(config.policySource(), new Set(policied));\n }\n const body = serializeTables(tables, view, state.policies);\n if (state.bodies.size >= MAX_CACHED_VIEWS) state.bodies.clear();\n state.bodies.set(key, body);\n return body;\n }\n };\n}\n\n/**\n * Options of {@link createSchemaTablesRoutes}.\n *\n * @group Schema\n */\nexport interface SchemaTablesRoutesConfig {\n service: SchemaTablesService;\n /**\n * `false` when the backend has no authentication configured: every request\n * is answered `404 SCHEMA_UNAVAILABLE`.\n */\n available: boolean;\n /**\n * Identify the caller: verify whatever credential the request carries and\n * set `user` (and `scopes`, for a credential that narrows them). A request\n * with no credential must pass through with no `user`.\n */\n authenticate: MiddlewareHandler<HonoEnv>[];\n /** `schemaTables.public`: serve anonymous callers the tables with a public `select` rule. */\n publicTables?: boolean;\n /**\n * `schemaTables.persons`: what a signed-in person without `schema:read` is\n * described — the tables their roles can reach (`\"granted\"`, the default)\n * or every table (`\"all\"`). See {@link SchemaTablesPersons}.\n */\n persons?: SchemaTablesPersons;\n}\n\n/** The roles on the request's caller. */\nfunction rolesOf(c: Context<HonoEnv>): string[] {\n const user = c.get(\"user\");\n if (typeof user !== \"object\" || user === null || !(\"roles\" in user) || !Array.isArray(user.roles)) return [];\n return user.roles.filter((role): role is string => typeof role === \"string\");\n}\n\n/**\n * Who a request comes from, as the serializer judges it: nobody, a person\n * (their roles' scopes), or a credential (exactly the scopes it carries).\n *\n * @group Schema\n */\nexport function schemaCallerOf(c: Context<HonoEnv>): SchemaCaller {\n if (!c.get(\"user\")) return { kind: \"anonymous\", roles: [], scopes: [] };\n const narrowed = c.get(\"scopes\");\n return narrowed\n ? { kind: \"credential\", roles: rolesOf(c), scopes: narrowed }\n : { kind: \"person\", roles: rolesOf(c), scopes: callerScopes(c) };\n}\n\n/** Whether an `If-None-Match` header names this tag (or `*`). */\nfunction matches(header: string | undefined, etag: string): boolean {\n if (!header) return false;\n return header.split(\",\").map(tag => tag.trim()).some(tag => tag === etag || tag === \"*\");\n}\n\n/**\n * Mount `GET /tables` and `GET /tables/:slug` (the caller mounts the router at\n * `{basePath}/schema`).\n *\n * @group Schema\n */\nexport function createSchemaTablesRoutes(config: SchemaTablesRoutesConfig): Hono<HonoEnv> {\n const router = new Hono<HonoEnv>();\n\n if (!config.available) {\n router.all(\"/*\", (c) => c.json({\n error: {\n code: \"SCHEMA_UNAVAILABLE\",\n message: \"This backend serves its tables only to authenticated callers, and no authentication is \" +\n \"configured (no auth adapter and no auth.jwtSecret). Configure auth to enable GET /schema/tables.\"\n }\n }, 404));\n return router;\n }\n\n router.use(\"/*\", ...config.authenticate);\n\n const viewOf = (c: Context<HonoEnv>): SchemaView => {\n const caller = schemaCallerOf(c);\n if (caller.kind === \"anonymous\" && !config.publicTables) {\n throw ApiError.unauthenticated(\"Authentication required: the tables are described to signed-in callers and credentials only.\");\n }\n const view = schemaViewFor(caller, { persons: config.persons ?? \"granted\" });\n if (\"refused\" in view) throw new ApiError(403, \"SCOPE_MISSING\", view.message, { requiredScope: \"schema:read\" });\n return view;\n };\n\n const answer = <T>(c: Context<HonoEnv>, view: SchemaView, body: () => T): Response => {\n const etag = config.service.etagFor(view);\n c.header(\"ETag\", etag);\n c.header(\"Cache-Control\", \"private, no-cache\");\n c.header(\"Vary\", \"Authorization\");\n c.header(SCHEMA_VERSION_HEADER, config.service.version());\n if (matches(c.req.header(\"if-none-match\"), etag)) return c.body(null, 304);\n return c.json(body());\n };\n\n router.get(\"/tables\", (c) => {\n const view = viewOf(c);\n return answer(c, view, () => config.service.tablesFor(view));\n });\n\n router.get(\"/tables/:slug\", (c) => {\n const view = viewOf(c);\n const slug = c.req.param(\"slug\");\n const table = config.service.tablesFor(view).find(candidate => candidate.slug === slug);\n if (!table) throw ApiError.notFound(`No table \"${slug}\" is served to this caller.`, \"TABLE_NOT_FOUND\");\n return answer(c, view, () => table);\n });\n\n return router;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsFA,IAAM,mBAAmB;;;;;;AAOzB,SAAgB,0BAA0B,QAAwD;CAC9F,MAAM,WAAW,OAAO;CACxB,MAAM,eAAe,SAAS;CAC9B,IAAI;CAOJ,MAAM,gBAAgB;EAClB,IAAI,SAAS,MAAM,aAAa,SAAS,UAAU,OAAO;EAC1D,MAAM,UAAU,SAAS,aAAa,gBAAgB,OAAO,gBACvD,OAAO,gBACP,qBAAqB,SAAS,KAAK,CAAC;EAC1C,QAAQ;GAAE,UAAU,SAAS;GAAU;GAAS,wBAAQ,IAAI,IAAI;EAAE;EAClE,OAAO;CACX;CAEA,OAAO;EACH,eAAe,QAAQ,CAAC,CAAC;EACzB,UAAU,SAAS,MAAM,QAAQ,CAAC,CAAC,QAAQ,GAAG,cAAc,IAAI,EAAE;EAClE,YAAY,SAAS;GACjB,MAAM,QAAQ,QAAQ;GACtB,MAAM,MAAM,cAAc,IAAI;GAC9B,MAAM,SAAS,MAAM,OAAO,IAAI,GAAG;GACnC,IAAI,QAAQ,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IAAI;EACtF,IAAI,CAAC,OAAO,MAAM,SAAS,SAAS,aAAa,KAAK,8BAA8B,iBAAiB;EACrG,OAAO,OAAO,GAAG,YAAY,KAAK;CACtC,CAAC;CAED,OAAO;AACX"}
|
|
@@ -4,7 +4,7 @@ globalThis.process ??= __rebaseProcess;
|
|
|
4
4
|
__rebaseCreateRequire(import.meta.url);
|
|
5
5
|
import { Gt as resourceKeyOf, Pn as __exportAll, f as rel, h as isColumnBuilder, l as isTableDef, m as col, o as defineTable, p as ColumnBuilder, r as columnDefFromWire, t as src_exports, u as isViewDef } from "./src-DLIb1O9l.js";
|
|
6
6
|
import { r as toSnakeCase } from "./strings.es-k0kjzQBh.js";
|
|
7
|
-
import { a as loadBackendSchema, c as deriveJunctionTable, d as isSchemaDefinitionError, i as isSchemaLoadError, l as deriveJunctionTargetKey, o as deriveBelongsToLocalKey, r as compileSchemaDefs, s as deriveJunctionSourceKey, u as deriveTargetForeignKey } from "./load-schema-
|
|
7
|
+
import { a as loadBackendSchema, c as deriveJunctionTable, d as isSchemaDefinitionError, i as isSchemaLoadError, l as deriveJunctionTargetKey, o as deriveBelongsToLocalKey, r as compileSchemaDefs, s as deriveJunctionSourceKey, u as deriveTargetForeignKey } from "./load-schema-Cv5XLVjW.js";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import fs from "node:fs";
|
|
10
10
|
import fsp from "node:fs/promises";
|
|
@@ -2909,4 +2909,4 @@ function removeVariable(workspace, file, statement, declaration) {
|
|
|
2909
2909
|
//#endregion
|
|
2910
2910
|
export { replaceNode as _, literalString as a, opaqueMembers as c, unwrapExpression as d, applyEdits as f, removeListItem as g, listShape as h, isData as i, printKey as l, itemText as m, TableSourceEditError as n, member as o, insertListItem as p, TableSourceEditor as r, memberName as s, IDENTIFIER as t, table_source_editor_exports as u, printSchemaValue as v };
|
|
2911
2911
|
|
|
2912
|
-
//# sourceMappingURL=table-source-editor-
|
|
2912
|
+
//# sourceMappingURL=table-source-editor-qmyi5vxX.js.map
|