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