better-supabase 0.21.0 → 0.22.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 (216) hide show
  1. package/dist/{adapter-DZJZTY6g.js → adapter-D4aNBxhm.js} +2 -2
  2. package/dist/api-3C0AWFeP.js +696 -0
  3. package/dist/{api-Cj4W_pqT.d.ts → api-CHObZL7m.d.ts} +1 -1
  4. package/dist/{app-tables-C5HjXs2k.d.ts → app-tables-BGzdnQm5.d.ts} +1 -1
  5. package/dist/astro/index.js +5 -5
  6. package/dist/blocks/access-requests/index.js +1 -1
  7. package/dist/blocks/activities/index.js +1 -1
  8. package/dist/blocks/agents/index.js +1 -1
  9. package/dist/blocks/ai-chat/index.js +1 -1
  10. package/dist/blocks/ai-keys/index.js +1 -1
  11. package/dist/blocks/announcements/index.js +1 -1
  12. package/dist/blocks/api-keys/index.js +1 -1
  13. package/dist/blocks/approvals/index.js +1 -1
  14. package/dist/blocks/assets/index.js +1 -1
  15. package/dist/blocks/assignment/index.js +1 -1
  16. package/dist/blocks/attachments/index.js +1 -1
  17. package/dist/blocks/audit/index.d.ts +1 -1
  18. package/dist/blocks/audit/index.js +1 -1
  19. package/dist/blocks/automations/index.js +1 -1
  20. package/dist/blocks/billable-time/index.js +1 -1
  21. package/dist/blocks/billing/index.js +2 -2
  22. package/dist/blocks/bookings/index.js +1 -1
  23. package/dist/blocks/bulk/index.js +1 -1
  24. package/dist/blocks/calendar/index.js +1 -1
  25. package/dist/blocks/catalog/index.js +1 -1
  26. package/dist/blocks/channels/index.js +1 -1
  27. package/dist/blocks/collections/index.js +1 -1
  28. package/dist/blocks/compliance/index.js +1 -1
  29. package/dist/blocks/connectors/index.js +1 -1
  30. package/dist/blocks/contacts/index.js +1 -1
  31. package/dist/blocks/content/index.js +1 -1
  32. package/dist/blocks/contracts/index.js +1 -1
  33. package/dist/blocks/courses/index.js +1 -1
  34. package/dist/blocks/custom-fields/index.js +1 -1
  35. package/dist/blocks/data-lifecycle/index.js +1 -1
  36. package/dist/blocks/deals/index.js +1 -1
  37. package/dist/blocks/dispatch/index.js +1 -1
  38. package/dist/blocks/documents/index.js +1 -1
  39. package/dist/blocks/domains/index.js +1 -1
  40. package/dist/blocks/donations/index.js +1 -1
  41. package/dist/blocks/drive/index.js +1 -1
  42. package/dist/blocks/employees/index.js +1 -1
  43. package/dist/blocks/enrichment/index.js +1 -1
  44. package/dist/blocks/enrollments/index.js +1 -1
  45. package/dist/blocks/expenses/index.js +1 -1
  46. package/dist/blocks/flags/index.js +1 -1
  47. package/dist/blocks/forecasts/index.js +1 -1
  48. package/dist/blocks/forms/index.js +1 -1
  49. package/dist/blocks/guests/index.js +1 -1
  50. package/dist/blocks/hiring/index.js +1 -1
  51. package/dist/blocks/imports/index.js +1 -1
  52. package/dist/blocks/inbox/index.js +1 -1
  53. package/dist/blocks/incidents/index.js +1 -1
  54. package/dist/blocks/index.js +2 -2
  55. package/dist/blocks/inventory/index.js +1 -1
  56. package/dist/blocks/invoices/index.js +1 -1
  57. package/dist/blocks/leases/index.js +1 -1
  58. package/dist/blocks/leave/index.js +1 -1
  59. package/dist/blocks/ledger/index.js +1 -1
  60. package/dist/blocks/mail-sync/index.js +1 -1
  61. package/dist/blocks/messaging/index.js +1 -1
  62. package/dist/blocks/metrics/index.js +1 -1
  63. package/dist/blocks/moderation/index.js +1 -1
  64. package/dist/blocks/notifications/index.js +3 -3
  65. package/dist/blocks/numbering/index.js +1 -1
  66. package/dist/blocks/oauth-server/index.js +1 -1
  67. package/dist/blocks/orders/index.js +1 -1
  68. package/dist/blocks/organizations/index.js +1 -1
  69. package/dist/blocks/outbox/index.js +1 -1
  70. package/dist/blocks/passes/index.js +1 -1
  71. package/dist/blocks/pipelines/index.js +1 -1
  72. package/dist/blocks/posts/index.js +1 -1
  73. package/dist/blocks/promotions/index.js +1 -1
  74. package/dist/blocks/push/index.js +1 -1
  75. package/dist/blocks/quotes/index.js +1 -1
  76. package/dist/blocks/reactions/index.js +1 -1
  77. package/dist/blocks/relations/index.js +1 -1
  78. package/dist/blocks/reminders/index.js +1 -1
  79. package/dist/blocks/reviews/index.js +1 -1
  80. package/dist/blocks/saved-views/index.js +1 -1
  81. package/dist/blocks/scores/index.js +1 -1
  82. package/dist/blocks/search/index.js +1 -1
  83. package/dist/blocks/security-events/index.js +1 -1
  84. package/dist/blocks/segments/index.js +1 -1
  85. package/dist/blocks/sequences/index.js +1 -1
  86. package/dist/blocks/service-accounts/index.js +1 -1
  87. package/dist/blocks/settings/index.js +1 -1
  88. package/dist/blocks/share-links/index.js +1 -1
  89. package/dist/blocks/shipments/index.js +1 -1
  90. package/dist/blocks/signatures/index.js +1 -1
  91. package/dist/blocks/signing-keys/index.js +1 -1
  92. package/dist/blocks/sla/index.js +1 -1
  93. package/dist/blocks/sso/index.js +1 -1
  94. package/dist/blocks/state-machine/index.js +1 -1
  95. package/dist/blocks/tags/index.js +1 -1
  96. package/dist/blocks/tasks/index.js +2 -2
  97. package/dist/blocks/teams/index.js +1 -1
  98. package/dist/blocks/templates/index.js +1 -1
  99. package/dist/blocks/time-tracking/index.js +1 -1
  100. package/dist/blocks/timeline/index.js +1 -1
  101. package/dist/blocks/trash/index.js +1 -1
  102. package/dist/blocks/vercel-marketplace/index.js +1 -1
  103. package/dist/blocks/versions/index.js +1 -1
  104. package/dist/blocks/waitlist/index.js +1 -1
  105. package/dist/blocks/webhooks/index.js +4 -4
  106. package/dist/blocks/workflow-editor/index.js +1 -1
  107. package/dist/blocks/workflows/index.js +1 -1
  108. package/dist/cli/{add-C0w-mVTQ.js → add-B6CQOt3A.js} +2 -2
  109. package/dist/cli/{add-BTDPjVGC.js → add-BXFzr0Wf.js} +9 -9
  110. package/dist/cli/add-w_HumDPX.js +1 -0
  111. package/dist/cli/{backfill-BDdBs6Ne.js → backfill-Dflp6JZk.js} +1 -1
  112. package/dist/cli/bin.js +1 -1
  113. package/dist/cli/{blocks-Bs-lA-U_.js → blocks-CBH3N7Fy.js} +1 -1
  114. package/dist/cli/{blocks-CQLME-HQ.js → blocks-FtOIcUbu.js} +1 -1
  115. package/dist/cli/{cache-DDKao2Va.js → cache-61VwYKEv.js} +1 -1
  116. package/dist/cli/{codemod-Bjl998Do.js → codemod-CqPRa25J.js} +1 -1
  117. package/dist/cli/{content-mapper-DgSTl-DL.js → content-mapper-DGQQY5IA.js} +2 -2
  118. package/dist/cli/{doctor-CMLWbt44.js → doctor-BxxSO193.js} +19 -17
  119. package/dist/cli/{gen-D3VX8WdV.js → gen-D2cqqqTH.js} +11 -11
  120. package/dist/cli/index.d.ts +1 -1
  121. package/dist/cli/index.js +6 -6
  122. package/dist/cli/{init-D6D6eWze.js → init-BnG1IE1y.js} +5 -5
  123. package/dist/cli/{live-C_xgTOfD.js → live-D26OWOAb.js} +2 -2
  124. package/dist/cli/{mcp-B0Irjbes.js → mcp-1l3C_GdB.js} +2 -2
  125. package/dist/cli/{metadata-cLXra-XB.js → metadata-DDfPBHwI.js} +3 -3
  126. package/dist/cli/{migration-safety-OUK-Afbb.js → migration-safety-CQbrfZIx.js} +1 -1
  127. package/dist/cli/{migrations-CHenMvl_.js → migrations-Ch5Uuvyj.js} +1 -1
  128. package/dist/cli/{module-migration-6V7vXWUK.js → module-migration-Dul1uTYX.js} +2 -2
  129. package/dist/cli/{powersync-D83yAFbl.js → powersync-CfT-tRx1.js} +2 -2
  130. package/dist/cli/powersync-Vmhw5c1N.js +1 -0
  131. package/dist/cli/{print-C0OmQyTu.js → print-CbPT4PTL.js} +2 -2
  132. package/dist/cli/{remove-BWlOngNT.js → remove-kDH1yxKZ.js} +5 -5
  133. package/dist/cli/{render-9m70qveo.js → render-0Vd7BaNA.js} +3 -3
  134. package/dist/cli/{run-gE4eAazR.js → run-Dafms0D2.js} +8 -8
  135. package/dist/cli/{run-He3M-ZRq.js → run-DxTd55Ug.js} +21 -21
  136. package/dist/cli/{shared-Cx2WFVWq.js → shared-BQAMXvwd.js} +1 -1
  137. package/dist/cli/{snapshot-CZb3uVKE.js → snapshot-B8K6gYjA.js} +2 -2
  138. package/dist/cli/{source-CrYSCdPZ.js → source-CXDyCWz5.js} +1 -1
  139. package/dist/cli/{spec-Cn5RhuQc.js → spec-BGsnTkIl.js} +2 -2
  140. package/dist/cli/{spec-D4b9ePuQ.js → spec-CaN7nOqI.js} +1 -1
  141. package/dist/cli/{sql-layout-CLJ67h3L.js → sql-layout-BGAlcp1U.js} +2 -2
  142. package/dist/cli/{sync-B8VGiaHk.js → sync-CT_5VG0E.js} +3 -3
  143. package/dist/cli/{upgrade-DMiYx1C8.js → upgrade-DA7aO88E.js} +2 -2
  144. package/dist/cli/{upgrade-BvBWK3Fo.js → upgrade-frUtPDDb.js} +4 -4
  145. package/dist/cli/{version-BVg2Z6yv.js → version-CUdPyV6J.js} +1 -1
  146. package/dist/{composite-Dw5ofSF_.js → composite-CBRbvn5j.js} +2 -2
  147. package/dist/config/index.d.ts +1 -1
  148. package/dist/config/index.js +4 -4
  149. package/dist/{config-CD2OGfCG.js → config-C9AOcQ9S.js} +1 -1
  150. package/dist/{config-BOt5T6Vs.js → config-CH-D2B-4.js} +3 -3
  151. package/dist/{context-sgrUjA3U.d.ts → context-DEisra3V.d.ts} +15 -3
  152. package/dist/create/index.d.ts +72 -451
  153. package/dist/create/index.js +15 -1687
  154. package/dist/create/lite/index.d.ts +250 -13
  155. package/dist/create/lite/index.js +1007 -24
  156. package/dist/credentials/index.js +1 -1
  157. package/dist/edge/index.js +7 -7
  158. package/dist/elysia/index.js +1 -1
  159. package/dist/events/index.js +1 -1
  160. package/dist/expo/index.js +3 -3
  161. package/dist/{framework-DXM1vNcV.js → framework-DYEUraqt.js} +1 -1
  162. package/dist/h3/index.js +1 -1
  163. package/dist/h3/v1/index.js +1 -1
  164. package/dist/hono/index.js +6 -6
  165. package/dist/{index-5JSxY1MG.d.ts → index-3p_oWttZ.d.ts} +77 -2
  166. package/dist/{index-Bt7_mxn0.d.ts → index-CM2aGNRo.d.ts} +1 -1
  167. package/dist/{app-tables-DyswUg6J.js → instances-CK0jR3Pc.js} +147 -3
  168. package/dist/{kit-DhlB-vv_.js → kit-Bcd9wYCV.js} +1 -1
  169. package/dist/mapper/bin.js +5 -5
  170. package/dist/mcp/index.js +6 -6
  171. package/dist/mcp/sdk/index.js +2 -2
  172. package/dist/nestjs/index.js +1 -1
  173. package/dist/next/index.js +7 -7
  174. package/dist/node/index.js +1 -1
  175. package/dist/orpc/index.d.ts +1 -1
  176. package/dist/orpc/index.js +5 -5
  177. package/dist/otel/index.js +4 -4
  178. package/dist/preset/index.d.ts +4 -4
  179. package/dist/preset/index.js +4 -4
  180. package/dist/{preset-B3CukUhu.js → preset-CS490mYJ.js} +179 -7
  181. package/dist/project-NmP1NdLi.js +1760 -0
  182. package/dist/react/index.js +2 -2
  183. package/dist/react/server.js +2 -2
  184. package/dist/{react-_D_CeZMk.js → react-CcrQQl0_.js} +2 -2
  185. package/dist/react-router/index.js +5 -5
  186. package/dist/realtime/index.js +1 -1
  187. package/dist/{refusal-D48CMqpQ.js → refusal-DDlInPff.js} +2 -2
  188. package/dist/{instances-DDt7NdVl.js → resolved-names-DdlJzoMK.js} +2 -146
  189. package/dist/{resource-R3KToNze.js → resource-BUJcZKiW.js} +2 -2
  190. package/dist/{resources-DqIwoQsP.js → resources-jb3R6rEa.js} +1 -1
  191. package/dist/server/index.js +7 -7
  192. package/dist/{sign-in-1FJiXXyG.js → sign-in-NO7LWlw4.js} +2 -2
  193. package/dist/solid/index.js +1 -1
  194. package/dist/solid-start/index.js +5 -5
  195. package/dist/spec/index.d.ts +2 -2
  196. package/dist/spec/index.js +2 -693
  197. package/dist/sql/index.d.ts +3 -3
  198. package/dist/sql/index.js +2 -2
  199. package/dist/{sql-BjjgwJKg.js → sql-BMXEHTvr.js} +17 -3
  200. package/dist/svelte/index.js +1 -1
  201. package/dist/sveltekit/index.js +5 -5
  202. package/dist/tanstack-start/index.js +5 -5
  203. package/dist/testing/index.d.ts +2 -2
  204. package/dist/testing/index.js +4 -4
  205. package/dist/types-BC1HLEVx.d.ts +461 -0
  206. package/dist/vue/index.js +1 -1
  207. package/dist/yjs/index.js +1 -1
  208. package/package.json +1 -1
  209. package/dist/cli/add-CspY9jKT.js +0 -1
  210. package/dist/cli/powersync-DwhCH0gs.js +0 -1
  211. package/dist/types-DGHfTW8_.d.ts +0 -9
  212. package/dist/{build-CM8PJqwW.js → build-CH2N3Yf0.js} +3 -3
  213. package/dist/{create-blocks-CUS28FfS.js → create-blocks-BfrDUSM6.js} +1 -1
  214. package/dist/{data-hooks-tgF1Ct0F.js → data-hooks-CdcZfVS1.js} +1 -1
  215. package/dist/{respond-3RKp6VgU.js → respond-CZMWbUs3.js} +1 -1
  216. package/dist/{topic-J9I3yu6f.js → topic-DClSoqY7.js} +1 -1
@@ -1,701 +1,10 @@
1
1
  import { r as isPlainObject } from "../clone-CkG0-hlI.js";
2
2
  import { a as methodNotAllowed } from "../problem-Bf0cJ7tk.js";
3
3
  import { t as SPEC_PINS } from "../spec-pins-D3zDek-u.js";
4
+ import { a as toOpenApi30Schema, n as openapiFormat, o as defineDocumentFormat, r as OPENAPI_33_PREVIEW_VERSION, t as defineApi } from "../api-3C0AWFeP.js";
5
+ import { a as topicsFrom, c as PROBLEM_SCHEMA, d as mergeJson, f as pointerToken, i as safeKey, l as convertStandard, r as CLOUD_EVENT_TRAIT, s as DEFAULT_ERRORS, t as buildApiModel, u as pascal } from "../build-CH2N3Yf0.js";
4
6
  import { t as FUNCTION_DESCRIPTOR } from "../function-contract-pEmsaUIf.js";
5
7
  import { n as memoized, t as importOptionalPeer } from "../optional-peer-C1NbBRJm.js";
6
- import { a as topicsFrom, c as PROBLEM_SCHEMA, d as mergeJson, f as pointerToken, i as safeKey, l as convertStandard, n as publishedResources, o as publishedBlocks, r as CLOUD_EVENT_TRAIT, s as DEFAULT_ERRORS, t as buildApiModel, u as pascal } from "../build-CM8PJqwW.js";
7
- //#region src/spec/format.ts
8
- /**
9
- * Identity helper that fixes `apiVersion` and checks that the default version
10
- * exists.
11
- */
12
- function defineDocumentFormat(format) {
13
- if (!Object.hasOwn(format.versions, format.defaultVersion)) throw new TypeError(`Document format "${format.id}": the default version "${format.defaultVersion}" is not in versions`);
14
- if (format.versions[format.defaultVersion].status === "preview") throw new TypeError(`Document format "${format.id}": a preview version cannot be the default`);
15
- return {
16
- ...format,
17
- apiVersion: 1
18
- };
19
- }
20
- //#endregion
21
- //#region src/openapi/schema30.ts
22
- /** Keywords whose value is one subschema. */
23
- const SINGLE = /* @__PURE__ */ new Set([
24
- "items",
25
- "additionalProperties",
26
- "not"
27
- ]);
28
- /** Keywords whose value is a list of subschemas. */
29
- const LISTS = /* @__PURE__ */ new Set([
30
- "allOf",
31
- "anyOf",
32
- "oneOf"
33
- ]);
34
- /** 2020-12 keywords the OpenAPI 3.0 Schema Object does not have. */
35
- const DROPPED = /* @__PURE__ */ new Set([
36
- "$schema",
37
- "$id",
38
- "$anchor",
39
- "$dynamicAnchor",
40
- "$dynamicRef",
41
- "$comment",
42
- "$defs",
43
- "$vocabulary",
44
- "prefixItems",
45
- "contains",
46
- "minContains",
47
- "maxContains",
48
- "propertyNames",
49
- "patternProperties",
50
- "dependentRequired",
51
- "dependentSchemas",
52
- "unevaluatedItems",
53
- "unevaluatedProperties",
54
- "if",
55
- "then",
56
- "else",
57
- "contentMediaType",
58
- "contentSchema"
59
- ]);
60
- const isNullSchema = (value) => isPlainObject(value) && value["type"] === "null" && Object.keys(value).length === 1;
61
- /**
62
- * Rewrites a JSON Schema 2020-12 schema into the OpenAPI 3.0 Schema Object:
63
- * `null` in `type` or in an `anyOf`/`oneOf` becomes `nullable`, a type list
64
- * becomes `anyOf`, `const` becomes a one-value `enum`, `examples` becomes
65
- * `example`, numeric `exclusiveMinimum`/`exclusiveMaximum` become the boolean
66
- * form, `contentEncoding: base64` becomes `format: byte`, and a `$ref` with
67
- * siblings is wrapped in `allOf`. Keywords 3.0 does not have are left out. The
68
- * input is not changed.
69
- */
70
- function toOpenApi30Schema(schema) {
71
- const out = {};
72
- let nullable = false;
73
- for (const [key, value] of Object.entries(schema)) {
74
- if (DROPPED.has(key)) continue;
75
- if (key === "properties" && isPlainObject(value)) out[key] = Object.fromEntries(Object.entries(value).map(([name, child]) => [name, isPlainObject(child) ? toOpenApi30Schema(child) : child]));
76
- else if (SINGLE.has(key) && isPlainObject(value)) out[key] = toOpenApi30Schema(value);
77
- else if (LISTS.has(key) && Array.isArray(value)) {
78
- const branches = value;
79
- const rest = branches.filter((branch) => !isNullSchema(branch));
80
- if (key !== "allOf" && rest.length < branches.length) nullable = true;
81
- out[key] = rest.map((branch) => isPlainObject(branch) ? toOpenApi30Schema(branch) : branch);
82
- } else if (key === "examples" && Array.isArray(value)) {
83
- if (value.length > 0) out["example"] = value[0];
84
- } else if ((key === "exclusiveMinimum" || key === "exclusiveMaximum") && typeof value === "number") {
85
- out[key === "exclusiveMinimum" ? "minimum" : "maximum"] = value;
86
- out[key] = true;
87
- } else if (key === "const") out["enum"] = [value];
88
- else if (key === "contentEncoding") {
89
- if (value === "base64" && schema["format"] === void 0) out["format"] = "byte";
90
- } else if (key === "type" && Array.isArray(value)) {
91
- const types = value;
92
- const rest = types.filter((type) => type !== "null");
93
- if (rest.length < types.length) nullable = true;
94
- if (rest.length === 1) out["type"] = rest[0];
95
- else if (rest.length > 1) out["anyOf"] = rest.map((type) => ({ type }));
96
- } else if (key === "type" && value === "null") {
97
- nullable = true;
98
- out["enum"] = [null];
99
- } else out[key] = value;
100
- }
101
- for (const key of ["anyOf", "oneOf"]) {
102
- const branches = out[key];
103
- if (!Array.isArray(branches) || branches.length !== 1) continue;
104
- const only = branches[0];
105
- if (!isPlainObject(only)) continue;
106
- delete out[key];
107
- if (typeof only["$ref"] === "string") out["allOf"] = [only];
108
- else for (const [name, entry] of Object.entries(only)) if (!(name in out)) out[name] = entry;
109
- }
110
- if (typeof out["$ref"] === "string" && Object.keys(out).length > 1) {
111
- const { $ref, ...siblings } = out;
112
- return {
113
- allOf: [{ $ref }],
114
- ...siblings,
115
- ...nullable ? { nullable: true } : {}
116
- };
117
- }
118
- if (nullable) {
119
- if (typeof out["$ref"] === "string") return {
120
- allOf: [{ $ref: out["$ref"] }],
121
- nullable: true
122
- };
123
- out["nullable"] = true;
124
- }
125
- return out;
126
- }
127
- const mapEntries = (value, convert) => isPlainObject(value) ? Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, isPlainObject(entry) ? convert(entry) : entry])) : value;
128
- const withSchema = (holder) => {
129
- const out = { ...holder };
130
- for (const key of ["schema", "x-oai-itemSchema"]) {
131
- const schema = out[key];
132
- if (isPlainObject(schema)) out[key] = toOpenApi30Schema(schema);
133
- }
134
- if (isPlainObject(out["content"])) out["content"] = mapEntries(out["content"], withSchema);
135
- if (isPlainObject(out["headers"])) out["headers"] = mapEntries(out["headers"], withSchema);
136
- return out;
137
- };
138
- const lowerParameters = (value) => Array.isArray(value) ? value.map((entry) => isPlainObject(entry) ? withSchema(entry) : entry) : value;
139
- const lowerOperation$1 = (operation) => {
140
- const out = { ...operation };
141
- out["parameters"] = lowerParameters(out["parameters"]);
142
- if (out["parameters"] === void 0) delete out["parameters"];
143
- if (isPlainObject(out["requestBody"])) out["requestBody"] = withSchema(out["requestBody"]);
144
- if (isPlainObject(out["responses"])) out["responses"] = mapEntries(out["responses"], withSchema);
145
- return out;
146
- };
147
- const PATH_ITEM_LISTS = /* @__PURE__ */ new Set(["parameters"]);
148
- const lowerPathItem = (item) => {
149
- const out = {};
150
- for (const [key, value] of Object.entries(item)) if (PATH_ITEM_LISTS.has(key)) out[key] = lowerParameters(value);
151
- else if (isPlainObject(value) && !key.startsWith("x-") && key !== "servers") out[key] = lowerOperation$1(value);
152
- else out[key] = value;
153
- return out;
154
- };
155
- /**
156
- * Lowers every Schema Object position of an OpenAPI document to the 3.0
157
- * dialect.
158
- */
159
- function lowerDocumentSchemas30(document) {
160
- const out = { ...document };
161
- if (isPlainObject(out["paths"])) out["paths"] = mapEntries(out["paths"], lowerPathItem);
162
- const components = out["components"];
163
- if (isPlainObject(components)) {
164
- const lowered = {
165
- ...components,
166
- schemas: mapEntries(components["schemas"], toOpenApi30Schema)
167
- };
168
- for (const key of [
169
- "responses",
170
- "parameters",
171
- "requestBodies",
172
- "headers"
173
- ]) if (isPlainObject(components[key])) lowered[key] = mapEntries(components[key], withSchema);
174
- if (lowered["schemas"] === void 0) delete lowered["schemas"];
175
- out["components"] = lowered;
176
- }
177
- return out;
178
- }
179
- //#endregion
180
- //#region src/openapi/types.ts
181
- /** The `openapi` field `3.3-preview` emits, as in the v3.3-dev branch. */
182
- const OPENAPI_33_PREVIEW_VERSION = "3.3.0";
183
- /** The file name `openapiFormat` writes for every version. */
184
- const OPENAPI_FILE_NAME = "openapi.json";
185
- //#endregion
186
- //#region src/openapi/format.ts
187
- const DIALECT = "https://json-schema.org/draft/2020-12/schema";
188
- const OPENAPI_FIELD = {
189
- "3.0": SPEC_PINS.openapi30,
190
- "3.1": SPEC_PINS.openapi31,
191
- "3.2": SPEC_PINS.openapi32,
192
- "3.3-preview": OPENAPI_33_PREVIEW_VERSION
193
- };
194
- /** Path Item fields that hold an Operation Object. */
195
- const METHODS = /* @__PURE__ */ new Set([
196
- "get",
197
- "put",
198
- "post",
199
- "delete",
200
- "options",
201
- "head",
202
- "patch",
203
- "trace",
204
- "query"
205
- ]);
206
- const omitUndefined$2 = (value) => Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
207
- function lowerContent(content, features) {
208
- return Object.fromEntries(Object.entries(content).map(([type, media]) => [type, omitUndefined$2({
209
- schema: media.schema,
210
- [features.native32 ? "itemSchema" : "x-oai-itemSchema"]: media.itemSchema,
211
- examples: media.examples ? Object.fromEntries(Object.entries(media.examples).map(([name, example]) => [name, omitUndefined$2({ ...example })])) : void 0
212
- })]));
213
- }
214
- function lowerResponse(response, features) {
215
- return omitUndefined$2({
216
- [features.native32 ? "summary" : "x-oai-summary"]: response.summary,
217
- description: response.description,
218
- headers: response.headers ? Object.fromEntries(Object.entries(response.headers).map(([name, header]) => [name, omitUndefined$2({ ...header })])) : void 0,
219
- content: response.content ? lowerContent(response.content, features) : void 0
220
- });
221
- }
222
- const lowerResponseOrRef = (response, features) => "ref" in response ? { $ref: `#/components/responses/${response.ref}` } : lowerResponse(response, features);
223
- const lowerParameter = (parameter) => omitUndefined$2({ ...parameter });
224
- function lowerSecurity(requirements, features) {
225
- return requirements.filter((requirement) => Object.keys(requirement).every((name) => !features.dropped.has(name))).map((requirement) => ({ ...requirement }));
226
- }
227
- function lowerScheme$1(scheme, features) {
228
- switch (scheme.type) {
229
- case "http":
230
- case "apiKey":
231
- case "openIdConnect": return omitUndefined$2({ ...scheme });
232
- case "oauth2": {
233
- const { metadataUrl, ...rest } = scheme;
234
- return omitUndefined$2({
235
- ...rest,
236
- [features.native32 ? "oauth2MetadataUrl" : `${features.prefix}oauth2MetadataUrl`]: metadataUrl
237
- });
238
- }
239
- case "profile": return features.is33 ? omitUndefined$2({ ...scheme }) : void 0;
240
- default: return scheme;
241
- }
242
- }
243
- function lowerOperation(operation, features) {
244
- return omitUndefined$2({
245
- operationId: operation.id,
246
- summary: operation.summary,
247
- description: operation.description,
248
- tags: operation.tags.length > 0 ? [...operation.tags] : void 0,
249
- deprecated: operation.deprecated,
250
- parameters: operation.parameters.length > 0 ? operation.parameters.map(lowerParameter) : void 0,
251
- requestBody: operation.requestBody ? omitUndefined$2({
252
- description: operation.requestBody.description,
253
- required: operation.requestBody.required,
254
- content: lowerContent(operation.requestBody.content, features)
255
- }) : void 0,
256
- responses: Object.fromEntries(Object.entries(operation.responses).map(([status, response]) => [status, lowerResponseOrRef(response, features)])),
257
- servers: operation.servers ? lowerServers(operation.servers, features) : void 0,
258
- security: operation.security ? lowerSecurity(operation.security, features) : void 0,
259
- ...operation.extensions
260
- });
261
- }
262
- function lowerServers(servers, features) {
263
- return servers.length > 0 ? servers.map((server) => omitUndefined$2({
264
- url: server.url,
265
- description: server.description,
266
- [features.native32 ? "name" : "x-oai-name"]: server.name
267
- })) : void 0;
268
- }
269
- const sameJson = (a, b) => JSON.stringify(a) === JSON.stringify(b);
270
- /**
271
- * Builds one Path Item. Path parameters every operation shares move to the Path
272
- * Item; in 3.3 a `security` every operation shares does too.
273
- */
274
- function pathItem(operations, features) {
275
- const pathParameters = (operation) => Array.isArray(operation["parameters"]) ? operation["parameters"].filter((parameter) => isPlainObject(parameter) && parameter["in"] === "path") : [];
276
- const first = operations[0];
277
- const shared = first ? pathParameters(first.operation) : [];
278
- const hoist = shared.length > 0 && operations.every(({ operation }) => sameJson(pathParameters(operation), shared));
279
- const firstSecurity = first?.operation["security"];
280
- const hoistSecurity = features.is33 && firstSecurity !== void 0 && operations.every(({ operation }) => sameJson(operation["security"], firstSecurity));
281
- const item = {};
282
- if (hoist) item["parameters"] = shared;
283
- if (hoistSecurity) item["security"] = firstSecurity;
284
- for (const { method, operation } of operations) {
285
- const out = { ...operation };
286
- if (hoist) {
287
- const rest = Array.isArray(out["parameters"]) ? out["parameters"].filter((parameter) => !isPlainObject(parameter) || parameter["in"] !== "path") : [];
288
- if (rest.length > 0) out["parameters"] = rest;
289
- else delete out["parameters"];
290
- }
291
- if (hoistSecurity) delete out["security"];
292
- item[method] = out;
293
- }
294
- return item;
295
- }
296
- const STANDARD_WEBHOOK_HEADERS$1 = [
297
- {
298
- name: "webhook-id",
299
- in: "header",
300
- required: true,
301
- description: "Unique message id; the same on every retry.",
302
- schema: { type: "string" }
303
- },
304
- {
305
- name: "webhook-timestamp",
306
- in: "header",
307
- required: true,
308
- description: "Unix time in seconds when the message was sent.",
309
- schema: {
310
- type: "string",
311
- pattern: "^[0-9]+$"
312
- }
313
- },
314
- {
315
- name: "webhook-signature",
316
- in: "header",
317
- required: true,
318
- description: "Space-separated signatures of `id.timestamp.body`, each `v1,<base64>`.",
319
- schema: { type: "string" }
320
- }
321
- ];
322
- function lowerWebhook(webhook) {
323
- return { post: omitUndefined$2({
324
- operationId: `on${pascal(webhook.id.replaceAll(".", "_"))}`,
325
- summary: webhook.summary,
326
- description: webhook.description,
327
- parameters: webhook.standardWebhooks ? STANDARD_WEBHOOK_HEADERS$1.map((header) => ({ ...header })) : void 0,
328
- requestBody: {
329
- required: true,
330
- content: { "application/json": { schema: webhook.payload } }
331
- },
332
- responses: { "2XX": { description: "The receiver accepted the event." } }
333
- }) };
334
- }
335
- function lowerTags(model, features) {
336
- return model.tags.map((tag) => features.native32 ? omitUndefined$2({ ...tag }) : omitUndefined$2({
337
- name: tag.name,
338
- description: tag.description,
339
- [`${features.prefix}summary`]: tag.summary,
340
- [`${features.prefix}parent`]: tag.parent,
341
- [`${features.prefix}kind`]: tag.kind
342
- }));
343
- }
344
- function lowerOpenApi(model, version, ctx) {
345
- const is33 = version === "3.3-preview";
346
- const dropped = new Set(is33 ? [] : Object.entries(model.securitySchemes).filter(([, scheme]) => scheme.type === "profile").map(([name]) => name));
347
- const features = {
348
- version,
349
- native32: version === "3.2" || is33,
350
- is30: version === "3.0",
351
- is33,
352
- prefix: model.extensionPrefix,
353
- dropped
354
- };
355
- for (const name of dropped) ctx.report({
356
- code: "preview-only",
357
- severity: "info",
358
- message: `Security scheme "${name}" uses Security Profiles, which only 3.3-preview emits; it and the requirements that name it are left out`,
359
- pointer: `/components/securitySchemes/${pointerToken(name)}`
360
- });
361
- const grouped = /* @__PURE__ */ new Map();
362
- const placed = [];
363
- for (const operation of model.operations) {
364
- if (operation.method === "query" && !features.native32) {
365
- ctx.report({
366
- code: "method-unsupported",
367
- severity: "warning",
368
- message: `Operation "${operation.id}" uses the QUERY method, which OpenAPI ${version} cannot describe; it is left out`,
369
- pointer: `/paths/${pointerToken(operation.path)}`
370
- });
371
- continue;
372
- }
373
- const list = grouped.get(operation.path) ?? [];
374
- list.push({
375
- method: operation.method,
376
- operation: lowerOperation(operation, features)
377
- });
378
- grouped.set(operation.path, list);
379
- placed.push(operation);
380
- }
381
- const paths = {};
382
- for (const [path, operations] of grouped) paths[path] = pathItem(operations, features);
383
- const securitySchemes = {};
384
- for (const [name, scheme] of Object.entries(model.securitySchemes)) {
385
- const lowered = lowerScheme$1(scheme, features);
386
- if (lowered) securitySchemes[name] = lowered;
387
- }
388
- const components = {
389
- schemas: structuredClone(model.schemas),
390
- responses: Object.fromEntries(Object.entries(model.responses).map(([name, response]) => [name, lowerResponse(response, features)])),
391
- securitySchemes
392
- };
393
- if (is33 && model.securityProfileRequirements) components["securityProfileRequirements"] = structuredClone(model.securityProfileRequirements);
394
- let webhooks;
395
- if (model.webhooks.length > 0) {
396
- if (features.is30) ctx.report({
397
- code: "webhooks-unsupported",
398
- severity: "warning",
399
- message: `OpenAPI 3.0 has no webhooks; ${model.webhooks.length} webhook(s) are left out`
400
- });
401
- else webhooks = Object.fromEntries(model.webhooks.map((webhook) => [webhook.id, lowerWebhook(webhook)]));
402
- }
403
- const info = features.is30 ? omitUndefined$2({
404
- ...model.info,
405
- summary: void 0,
406
- license: model.info.license ? omitUndefined$2({
407
- ...model.info.license,
408
- identifier: void 0
409
- }) : void 0
410
- }) : omitUndefined$2({ ...model.info });
411
- let document = omitUndefined$2({
412
- openapi: OPENAPI_FIELD[version],
413
- [features.native32 ? "$self" : "x-oai-$self"]: model.self,
414
- info: structuredClone(info),
415
- jsonSchemaDialect: features.is30 ? void 0 : DIALECT,
416
- servers: lowerServers(model.servers, features),
417
- tags: lowerTags(model, features),
418
- security: lowerSecurity(model.security, features),
419
- paths,
420
- webhooks,
421
- components,
422
- [`${features.prefix}preview`]: is33 ? SPEC_PINS.openapi33Preview : void 0
423
- });
424
- for (const [index, fragment] of model.fragments.entries()) document = mergeJson(document, fragment, (pointer) => {
425
- ctx.report({
426
- code: "fragment-conflict",
427
- severity: "warning",
428
- message: `Fragment ${index} replaces a generated value`,
429
- pointer
430
- });
431
- });
432
- for (const operation of placed) {
433
- if (!operation.extend) continue;
434
- const patch = { paths: { [operation.path]: { [operation.method]: operation.extend } } };
435
- document = mergeJson(document, patch);
436
- }
437
- if (features.is30) document = lowerDocumentSchemas30(document);
438
- if (!isOpenApiDocument(document)) throw new TypeError("better-supabase/spec: a fragment removed a required document field");
439
- return document;
440
- }
441
- /** The fields every OpenAPI document this format renders has. */
442
- function isOpenApiDocument(value) {
443
- return typeof value["openapi"] === "string" && isPlainObject(value["info"]) && isPlainObject(value["paths"]) && isPlainObject(value["components"]) && Array.isArray(value["tags"]) && Array.isArray(value["security"]);
444
- }
445
- const PATH_PARAM = /\{([^}]+)\}/g;
446
- function resolves(document, ref) {
447
- if (!ref.startsWith("#")) return true;
448
- let node = document;
449
- for (const raw of ref.slice(2).split("/")) {
450
- if (raw === "" && ref === "#") break;
451
- const key = raw.replaceAll("~1", "/").replaceAll("~0", "~");
452
- if (Array.isArray(node)) node = node[Number(key)];
453
- else if (isPlainObject(node)) node = node[key];
454
- else return false;
455
- if (node === void 0) return false;
456
- }
457
- return true;
458
- }
459
- function collectRefs$1(value, pointer, out) {
460
- if (Array.isArray(value)) for (const [index, item] of value.entries()) collectRefs$1(item, `${pointer}/${index}`, out);
461
- else if (isPlainObject(value)) for (const [key, item] of Object.entries(value)) if (key === "$ref" && typeof item === "string") out.push([pointer, item]);
462
- else collectRefs$1(item, `${pointer}/${pointerToken(key)}`, out);
463
- }
464
- /**
465
- * The keys of `value[key]` when it is an object; documents read from disk may
466
- * omit any field.
467
- */
468
- function keysAt(value, key) {
469
- if (!isPlainObject(value)) return [];
470
- const child = value[key];
471
- return isPlainObject(child) ? Object.keys(child) : [];
472
- }
473
- function lintOpenApi(document) {
474
- const diagnostics = [];
475
- const ids = /* @__PURE__ */ new Map();
476
- const components = document.components;
477
- const schemes = new Set(keysAt(components, "securitySchemes"));
478
- const checkSecurity = (requirements, pointer) => {
479
- if (!Array.isArray(requirements)) return;
480
- const list = requirements;
481
- for (const requirement of list) {
482
- if (!isPlainObject(requirement)) continue;
483
- for (const name of Object.keys(requirement)) if (!schemes.has(name)) diagnostics.push({
484
- code: "security-unresolved",
485
- severity: "error",
486
- message: `Security requirement names an unknown scheme "${name}"`,
487
- pointer
488
- });
489
- }
490
- };
491
- checkSecurity(document.security, "/security");
492
- const paths = document.paths;
493
- for (const [path, item] of Object.entries(isPlainObject(paths) ? paths : {})) {
494
- if (!isPlainObject(item)) continue;
495
- const base = `/paths/${pointerToken(path)}`;
496
- const templated = new Set([...path.matchAll(PATH_PARAM)].map((match) => match[1] ?? ""));
497
- const shared = Array.isArray(item["parameters"]) ? item["parameters"] : [];
498
- checkSecurity(item["security"], `${base}/security`);
499
- for (const [method, operation] of Object.entries(item)) {
500
- if (!METHODS.has(method) || !isPlainObject(operation)) continue;
501
- const pointer = `${base}/${method}`;
502
- const id = operation["operationId"];
503
- if (typeof id === "string") {
504
- const seen = ids.get(id);
505
- if (seen) diagnostics.push({
506
- code: "operation-id-duplicate",
507
- severity: "error",
508
- message: `operationId "${id}" is also used at ${seen}`,
509
- pointer
510
- });
511
- else ids.set(id, pointer);
512
- }
513
- checkSecurity(operation["security"], `${pointer}/security`);
514
- const own = Array.isArray(operation["parameters"]) ? operation["parameters"] : [];
515
- const declared = /* @__PURE__ */ new Set();
516
- for (const parameter of [...shared, ...own]) {
517
- if (!isPlainObject(parameter) || parameter["in"] !== "path") continue;
518
- const name = String(parameter["name"]);
519
- declared.add(name);
520
- if (!templated.has(name)) diagnostics.push({
521
- code: "path-param-unknown",
522
- severity: "error",
523
- message: `Path parameter "${name}" is not in the path template`,
524
- pointer
525
- });
526
- }
527
- for (const name of templated) if (!declared.has(name)) diagnostics.push({
528
- code: "path-param-missing",
529
- severity: "error",
530
- message: `Path template parameter "${name}" has no parameter`,
531
- pointer
532
- });
533
- }
534
- }
535
- const refs = [];
536
- collectRefs$1(document, "", refs);
537
- for (const [pointer, ref] of refs) if (!resolves(document, ref)) diagnostics.push({
538
- code: "ref-unresolved",
539
- severity: "error",
540
- message: `$ref "${ref}" does not resolve inside the document`,
541
- pointer
542
- });
543
- return diagnostics;
544
- }
545
- /**
546
- * OpenAPI as a `DocumentFormat`. 3.1 is the default; 3.0 is legacy (schemas
547
- * lowered to the 3.0 Schema Object); 3.2 has native `$self`, nested tags,
548
- * `itemSchema`, `oauth2MetadataUrl` and `query`; `3.3-preview` follows the
549
- * v3.3-dev branch at `SPEC_PINS.openapi33Preview`, with Path Item `security`
550
- * and the Security Profiles proposal. Below 3.2, the 3.2 fields travel as the
551
- * registered `x-oai-*` extensions where one exists, and as the model's prefixed
552
- * extensions otherwise.
553
- */
554
- const openapiFormat = defineDocumentFormat({
555
- id: "openapi",
556
- versions: {
557
- "3.0": {
558
- pin: SPEC_PINS.openapi30,
559
- status: "legacy"
560
- },
561
- "3.1": {
562
- pin: SPEC_PINS.openapi31,
563
- status: "stable"
564
- },
565
- "3.2": {
566
- pin: SPEC_PINS.openapi32,
567
- status: "stable"
568
- },
569
- "3.3-preview": {
570
- pin: SPEC_PINS.openapi33Preview,
571
- status: "preview"
572
- }
573
- },
574
- defaultVersion: "3.1",
575
- lower: lowerOpenApi,
576
- lint: lintOpenApi,
577
- fileName: () => OPENAPI_FILE_NAME
578
- });
579
- //#endregion
580
- //#region src/spec/api.ts
581
- function dedupe(diagnostics) {
582
- const seen = /* @__PURE__ */ new Set();
583
- return diagnostics.filter((diagnostic) => {
584
- const key = `${diagnostic.code}\u0000${diagnostic.pointer ?? ""}\u0000${diagnostic.message}`;
585
- if (seen.has(key)) return false;
586
- seen.add(key);
587
- return true;
588
- });
589
- }
590
- /**
591
- * The API model for a `defineSupabase()` result, and the documents it renders.
592
- * The model is built once per options object; each format and version is
593
- * lowered once and copied for every render.
594
- *
595
- * ```ts
596
- * const api = defineApi(betterSupabase, {
597
- * info: { title: "CRM API", version: "1.0.0" },
598
- * resources: { customers: { list: customerList } },
599
- * });
600
- * ```
601
- *
602
- * Without `resources` it publishes every table, and without `blocks` every
603
- * block instance `betterSupabase.blocks(set)` registered:
604
- *
605
- * ```ts
606
- * const api = defineApi(betterSupabase, { info, basePath: "/api" });
607
- * export const { procedures } = bsb.router(api, { meta: openapi });
608
- * const { document } = api.openapi({ version: "3.2" });
609
- * ```
610
- */
611
- function defineApi(source, options) {
612
- const built = buildApiModel(source, options);
613
- const lowered = /* @__PURE__ */ new WeakMap();
614
- const lower = (format, version) => {
615
- let byVersion = lowered.get(format);
616
- if (!byVersion) {
617
- byVersion = /* @__PURE__ */ new Map();
618
- lowered.set(format, byVersion);
619
- }
620
- let hit = byVersion.get(version);
621
- if (!hit) {
622
- const diagnostics = [];
623
- hit = {
624
- document: format.lower(built.model, version, { report: (diagnostic) => {
625
- diagnostics.push(diagnostic);
626
- } }),
627
- diagnostics
628
- };
629
- byVersion.set(version, hit);
630
- }
631
- return hit;
632
- };
633
- const render = (format, renderOptions = {}) => {
634
- const fallback = format.defaultVersion;
635
- const version = renderOptions.version ?? fallback;
636
- const status = format.versions[version];
637
- if (!status) throw new TypeError(`Document format "${format.id}" has no version "${String(version)}"`);
638
- const diagnostics = [...built.diagnostics];
639
- if (status.status === "preview") diagnostics.push({
640
- code: "preview-version",
641
- severity: "warning",
642
- message: `${format.id} ${String(version)} follows a draft (${status.pin}); its fields may change before release`
643
- });
644
- const base = lower(format, version);
645
- diagnostics.push(...base.diagnostics);
646
- let document = structuredClone(base.document);
647
- if (renderOptions.transform) {
648
- const rendered = {
649
- format: format.id,
650
- version,
651
- document
652
- };
653
- document = renderOptions.transform(rendered) ?? document;
654
- }
655
- const overlays = renderOptions.overlays ?? [];
656
- if (overlays.length > 0) {
657
- const engine = renderOptions.applyOverlays ?? options.applyOverlays;
658
- if (!engine) throw new TypeError("better-supabase/spec: overlays need applyOverlays (from better-supabase/spec)");
659
- const result = engine(document, overlays);
660
- document = result.document;
661
- diagnostics.push(...result.diagnostics ?? []);
662
- }
663
- diagnostics.push(...format.lint?.(document, version) ?? []);
664
- return {
665
- format: format.id,
666
- version,
667
- document,
668
- diagnostics: dedupe(diagnostics),
669
- fileName: format.fileName(version)
670
- };
671
- };
672
- return {
673
- model: built.model,
674
- basePath: (options.basePath ?? "").replace(/\/$/, ""),
675
- resources: publishedResources(source.meta, options),
676
- blocks: publishedBlocks(source.options?.blocks, options.blocks),
677
- diagnostics: built.diagnostics,
678
- render,
679
- openapi(openapiOptions = {}) {
680
- const { transform, version, overlays, applyOverlays } = openapiOptions;
681
- const renderOptions = {
682
- ...version === void 0 ? {} : { version },
683
- ...overlays === void 0 ? {} : { overlays },
684
- ...applyOverlays === void 0 ? {} : { applyOverlays },
685
- ...transform === void 0 ? {} : { transform: (rendered) => transform(rendered) }
686
- };
687
- const result = render(openapiFormat, renderOptions);
688
- return {
689
- format: "openapi",
690
- version: result.version,
691
- document: result.document,
692
- diagnostics: result.diagnostics,
693
- fileName: result.fileName
694
- };
695
- }
696
- };
697
- }
698
- //#endregion
699
8
  //#region src/spec/function-route.ts
700
9
  function isDescriptor(value) {
701
10
  return typeof value === "object" && value !== null && "input" in value;