permdock 0.31.0 → 0.32.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 (142) hide show
  1. package/dist/{adoption-scan-9brJ_mUG.js → adoption-scan-BJMEEu7V.js} +1 -1
  2. package/dist/{arazzo-Cs-3yoxR.js → arazzo-BAgh0PT6.js} +1 -1
  3. package/dist/{arazzo-C0bltfjv.js → arazzo-C_xK2Kaa.js} +1 -1
  4. package/dist/better-supabase/index.d.ts +26 -4
  5. package/dist/better-supabase/index.js +11 -2
  6. package/dist/{bsb-access-tags-B1TBUQLj.js → bsb-access-tags-CjeR7v7-.js} +10 -43
  7. package/dist/{bsb-action-keys-iKmZChtQ.js → bsb-action-keys-CYEREFMg.js} +1 -1
  8. package/dist/{casbin-DGsO-QmR.js → casbin-BErdqy1J.js} +1 -1
  9. package/dist/{casbin-s6_zDJi1.js → casbin-EwdKipQs.js} +1 -1
  10. package/dist/cli/bin.js +1 -1
  11. package/dist/cli/generate/watch-worker.js +2 -2
  12. package/dist/cli/index.d.ts +3 -3
  13. package/dist/cli/index.js +2 -2
  14. package/dist/cli/plugins/app.d.ts +1 -1
  15. package/dist/cli/plugins/app.js +1 -1
  16. package/dist/cli/plugins/better-supabase.d.ts +1 -1
  17. package/dist/cli/plugins/openapi.d.ts +1 -1
  18. package/dist/cli/plugins/openapi.js +1 -1
  19. package/dist/cli/plugins/powersync.d.ts +1 -1
  20. package/dist/cli/plugins/powersync.js +1 -1
  21. package/dist/cli/plugins/rls.d.ts +2 -2
  22. package/dist/cli/plugins/rls.js +1 -1
  23. package/dist/cli/plugins/schemas.d.ts +1 -1
  24. package/dist/cli/plugins/schemas.js +1 -1
  25. package/dist/cli/plugins/scim.d.ts +2 -2
  26. package/dist/cli/plugins/supabase-hook.d.ts +2 -2
  27. package/dist/cli/plugins/supabase-hook.js +1 -1
  28. package/dist/cli/plugins/supabase.d.ts +3 -3
  29. package/dist/cli/plugins/supabase.js +2 -2
  30. package/dist/cli/plugins/ui.d.ts +1 -1
  31. package/dist/cli/plugins/ui.js +1 -1
  32. package/dist/{client-subject-BOPbpwgm.d.ts → client-subject-xCSkKD1C.d.ts} +1 -1
  33. package/dist/{cloud-fRv3j6sq.js → cloud-DW3q3qnp.js} +2 -2
  34. package/dist/{codemod-DsqEKP6A.js → codemod-CF7NNDzA.js} +14 -11
  35. package/dist/{codemod-DT0dMVdd.js → codemod-DVDMFsTX.js} +8 -7
  36. package/dist/{collect-CCgmm5xN.js → collect-CE5wK0AX.js} +1 -1
  37. package/dist/{compile-DNVVdVWs.js → compile-BXKYYmT1.js} +3 -3
  38. package/dist/{completion-DrJkWgZa.js → completion-B59uPAnZ.js} +1 -1
  39. package/dist/{config-D8iWeV9k.js → config-7QvEq57a.js} +2 -2
  40. package/dist/{config-BaKkd6HB.js → config-VCa1RLUe.js} +1 -1
  41. package/dist/{config-report-uuD5eVEn.js → config-report-CjvA6lGI.js} +1 -1
  42. package/dist/{context-Ne0EdD45.js → context-CAFddgb9.js} +1 -1
  43. package/dist/{custom-role-rebuild-BBKC7Bt1.js → custom-role-rebuild-BK73tPib.js} +1 -1
  44. package/dist/{doctor-Ch4VGl2q.js → doctor-ELj5hrVv.js} +2 -2
  45. package/dist/{doctor-C1T2G2mn.js → doctor-ervtBRzG.js} +61 -33
  46. package/dist/{execute-BhWXiQAy.js → execute-ix7AAdWg.js} +3 -3
  47. package/dist/{gen-CGjbD8I_.js → gen-8rW_AUG5.js} +2 -2
  48. package/dist/gen-BtiGMiuH.js +1 -0
  49. package/dist/{gen-kind-thoT0NYV.js → gen-kind-C9ikF8nb.js} +1 -1
  50. package/dist/{generate-vEW8Brg8.js → generate-BmpCt5oi.js} +3 -3
  51. package/dist/{generate-eor7vXGN.js → generate-CW7gNfLr.js} +16 -12
  52. package/dist/{generate-options-MJgn0dgl.js → generate-options-DiR4r_sk.js} +7 -7
  53. package/dist/{hook-sql-DJQ_yOEC.js → hook-sql-D-abRHut.js} +5 -5
  54. package/dist/{import-CGQIK3iN.js → import-BAhoTYTk.js} +1 -1
  55. package/dist/{init-C6te_dSg.js → init-DkRHIe8-.js} +3 -3
  56. package/dist/{init-DN19mlwE.js → init-zxb0BVDJ.js} +1 -1
  57. package/dist/{interactive-only-BjYwp9mm.js → interactive-only-Dqww0ABO.js} +18 -1
  58. package/dist/{keys-qFqDoYeF.js → keys-DQsHrgBM.js} +1 -1
  59. package/dist/{login-BYXaH_yT.js → login-C1p3gmj8.js} +1 -1
  60. package/dist/{login-CMzfsdm8.js → login-DOEZveP6.js} +3 -3
  61. package/dist/{manager-chain-CStuYb7A.js → manager-chain-DdkiCw5q.js} +1 -1
  62. package/dist/{manifest-CowZuywo.js → manifest-31igzVGQ.js} +33 -33
  63. package/dist/{manifest-DdNYR_pl.js → manifest-B487A3po.js} +1 -1
  64. package/dist/{manifest-CA3E0KP8.d.ts → manifest-DgsxeAsM.d.ts} +38 -1
  65. package/dist/{manifest-schema-CLbcbDz7.js → manifest-schema-D7RQbnGY.js} +44 -1
  66. package/dist/{model-BqHWwfcg.js → model-BXhr8gUI.js} +1 -1
  67. package/dist/next/index.d.ts +2 -1
  68. package/dist/next/index.js +2 -1
  69. package/dist/next/plugin.d.ts +1 -1
  70. package/dist/next/plugin.js +1 -1
  71. package/dist/{openapi-Dsh0MDSZ.js → openapi-BeMVHVY4.js} +1 -1
  72. package/dist/{openapi-BP7YpJeF.js → openapi-DEGesHWH.js} +1 -1
  73. package/dist/{openapi-document-_QSOtSKS.js → openapi-document-CEQ6jqqR.js} +1 -1
  74. package/dist/{output-Didy9Ys4.js → output-C7EPeSZj.js} +1 -1
  75. package/dist/{ownership-CG5_N8b5.js → ownership-Csk9C3Js.js} +8 -5
  76. package/dist/{pipeline-B4iyaOK7.js → pipeline-Bbu7uw28.js} +2 -2
  77. package/dist/{plugin-DQJuZVl1.d.ts → plugin-L3G7jPGE.d.ts} +1 -1
  78. package/dist/{policy-hnVT4MC4.js → policy-CSOOQ3rR.js} +1 -1
  79. package/dist/{policy-bundle-BIDV0DZF.js → policy-bundle-KYI0EnrM.js} +3 -3
  80. package/dist/{powersync-DUvN9v5a.js → powersync-C1ix7CEY.js} +1 -1
  81. package/dist/{powersync-D7YfMHke.js → powersync-CGvu6j5U.js} +1 -1
  82. package/dist/{powersync-_2ElzOhQ.js → powersync-CM6Vg4RH.js} +6 -6
  83. package/dist/{provider-D1vlNPWo.js → provider-BV_v0JAY.js} +18 -3
  84. package/dist/{prune-config-5vtQpiLk.js → prune-config-CdoPJIGz.js} +5 -5
  85. package/dist/{pull-BnxZmo3f.js → pull-BaB401Bk.js} +2 -2
  86. package/dist/pull-Bp63vtgu.js +1 -0
  87. package/dist/{push-Bu0uCkJg.js → push-DcjvEj0m.js} +1 -1
  88. package/dist/{rbac-CwcucZPx.js → rbac-mblGDx-Z.js} +1 -1
  89. package/dist/{rename-CLoDRrbc.js → rename-BZNOV8H9.js} +2 -2
  90. package/dist/report-DCAiUc5U.js +1 -0
  91. package/dist/{report-BI_hek_d.js → report-DievqWhf.js} +75 -5
  92. package/dist/{resolve-names-CTji5IPe.js → resolve-names-Cth1UQ-8.js} +2 -2
  93. package/dist/{rls-UY6p6ztg.js → rls-BtkZgaZp.js} +7 -2
  94. package/dist/{rls-BPHCyA5v.js → rls-DUYok5e9.js} +17 -7
  95. package/dist/{rls-files-CDZdTh8v.js → rls-files-ucAI0J5j.js} +1 -1
  96. package/dist/{rls-options-BgD-KZkm.d.ts → rls-options-BFGRmdcH.d.ts} +1 -1
  97. package/dist/run-BjMxYYTe.js +1 -0
  98. package/dist/{run-C3ztA88m.js → run-WIqPbnjD.js} +3 -3
  99. package/dist/{scan-m5m1M6Qn.js → scan-Badcllgg.js} +1 -1
  100. package/dist/{schema-BpGuLrwk.js → schema-DBRKgQb4.js} +1 -1
  101. package/dist/{skills-BytzDi34.js → skills-Ba9hHGO6.js} +1 -1
  102. package/dist/{skills-CzhnDo-C.js → skills-CTKq3o8D.js} +1 -1
  103. package/dist/{sources-D5n28164.d.ts → sources-CjgZns7t.d.ts} +1 -1
  104. package/dist/supabase/index.d.ts +3 -3
  105. package/dist/supabase/index.js +1 -1
  106. package/dist/{supabase-CAswAUeb.js → supabase-CGiB83XQ.js} +1 -1
  107. package/dist/supabase-hook-CluYxKee.js +2 -0
  108. package/dist/{supabase-hook-C0LIaT7b.js → supabase-hook-CqO_0Koh.js} +9 -183
  109. package/dist/{supabase-schemas-BUFeyErz.js → supabase-schemas-BglbAG2Z.js} +9 -8
  110. package/dist/table-reads-AnHPrBp8.js +517 -0
  111. package/dist/table-reads-BviGc0L_.js +1 -0
  112. package/dist/{tables-sLA1CpuN.js → tables-CDq0HVVq.js} +7 -4
  113. package/dist/tenant-check-D7g9oNVH.js +105 -0
  114. package/dist/testing/fixtures/index.d.ts +1 -1
  115. package/dist/testing/fixtures/index.js +14 -8
  116. package/dist/testing/index.d.ts +1 -1
  117. package/dist/testing/index.js +1 -1
  118. package/dist/{types-config-BiMM_zJ-.d.ts → types-config-DNIw_Gt5.d.ts} +1 -1
  119. package/dist/{types-run-N2ffLN_Z.d.ts → types-run-Bwn1MuW0.d.ts} +1 -1
  120. package/dist/unplugin/index.d.ts +1 -1
  121. package/dist/unplugin/index.js +1 -1
  122. package/dist/{usage-DT6QK86a.js → usage-CW6xhRcV.js} +2 -2
  123. package/dist/usage-Ci7Glu-H.js +1 -0
  124. package/dist/{usage-Dcbg6zu6.js → usage-n4V2k_a6.js} +1 -1
  125. package/dist/{verify-DNERav8K.js → verify-CKzngsUH.js} +3 -3
  126. package/dist/warm-5yxlUmBh.js +32 -0
  127. package/dist/warm-BR-mrnY-.d.ts +16 -0
  128. package/dist/{watch-BsQ4n3NV.js → watch-C12Ub7x4.js} +2 -2
  129. package/dist/{watch-fldErlRf.js → watch-D-5ztqN8.js} +1 -1
  130. package/dist/watch-J1PfGMfb.js +1 -0
  131. package/package.json +1 -1
  132. package/schemas/supabase-manifest-v1.json +109 -19
  133. package/skills/permdock-data/references/queries-and-rls.md +1 -1
  134. package/dist/gen-CkUEZ5Z6.js +0 -1
  135. package/dist/platform-CSxTsLsr.js +0 -35
  136. package/dist/pull-CGncYZNZ.js +0 -1
  137. package/dist/report-BevPHMy6.js +0 -1
  138. package/dist/run-3ySqmufy.js +0 -1
  139. package/dist/supabase-hook-DXGg5bNn.js +0 -2
  140. package/dist/tenant-check-gL2miiaS.js +0 -31
  141. package/dist/usage-DdOFc5xq.js +0 -1
  142. package/dist/watch-eay1PztJ.js +0 -1
@@ -5,193 +5,18 @@ import { _ as writeOutputFiles, d as pgDeltaPath, g as underSchemaDir, h as serv
5
5
  import { i as readJsonFile, o as sqlFiles, s as writeFileEnsuringDir } from "./files-DAR51W3J.js";
6
6
  import { n as formatManifestJson, t as MANIFEST_FILE } from "./manifest-json-DMaBWmcG.js";
7
7
  import { c as requirePolicy } from "./load-m7jmit3y.js";
8
- import { n as hookUri } from "./rbac-CwcucZPx.js";
9
- import { a as parseSqlFile, c as readPolicy, d as sqlCalls, t as SqlSyntaxError } from "./ast-Dnm2TOHN.js";
10
- import { i as taggedAccessPolicies } from "./bsb-access-Bcw6GrQm.js";
11
- import { t as isPlatformSchema } from "./platform-CSxTsLsr.js";
12
- import { n as tenantCheck } from "./tenant-check-gL2miiaS.js";
13
- import { i as droppedPolicy, o as reportFiles } from "./report-BI_hek_d.js";
14
- import { a as supabaseHookSql, c as asideAuthzReceive, f as declarativeSql, i as supabaseHookManifest, l as configToml, n as hooklessDatabase, o as defaultOut, r as supabaseDatabaseManifest, s as hookMarker, t as grantsLabel } from "./hook-sql-DJQ_yOEC.js";
8
+ import { a as tryKeyReasons } from "./tenant-check-D7g9oNVH.js";
9
+ import { n as hookUri } from "./rbac-mblGDx-Z.js";
10
+ import { a as withTableReads } from "./table-reads-AnHPrBp8.js";
11
+ import { a as supabaseHookSql, c as asideAuthzReceive, f as declarativeSql, i as supabaseHookManifest, l as configToml, n as hooklessDatabase, o as defaultOut, r as supabaseDatabaseManifest, s as hookMarker, t as grantsLabel } from "./hook-sql-D-abRHut.js";
15
12
  import { r as HOOK_MARKER, s as hookMarkerFields } from "./markers-C-kThnKN.js";
16
13
  import { i as withSchemaDefaults } from "./schema-tables-Ba9LE_XB.js";
17
- import { l as supabaseConfig, n as resolveSchemas, r as schemasRefusal, t as isSupabaseSchemas } from "./supabase-schemas-BUFeyErz.js";
14
+ import { l as supabaseConfig, n as resolveSchemas, r as schemasRefusal, t as isSupabaseSchemas } from "./supabase-schemas-BglbAG2Z.js";
18
15
  import { t as readMemberships } from "./read-memberships-BkePIa1F.js";
19
16
  import { r as pgConnector } from "./pg-DmS5ITHu.js";
20
17
  import { n as MIGRATION_DIRS } from "./constants-PCJiir_3.js";
21
18
  import { existsSync, readFileSync, readdirSync } from "node:fs";
22
19
  import { dirname, join, resolve } from "node:path";
23
- // src/cli/rls/table-reads.ts
24
- /** better-supabase's own tables, which its block SQL owns. */
25
- const LIBRARY_SCHEMAS = /* @__PURE__ */ new Set(["better_supabase"]);
26
- function relationName(relation) {
27
- if (!isRecord(relation) || typeof relation["relname"] !== "string") return;
28
- return `${typeof relation["schemaname"] === "string" ? relation["schemaname"] : "public"}.${relation["relname"]}`.toLowerCase();
29
- }
30
- function enablesRls(node) {
31
- return (Array.isArray(node["cmds"]) ? node["cmds"] : []).some((cmd) => {
32
- const alter = isRecord(cmd) ? cmd["AlterTableCmd"] : void 0;
33
- return isRecord(alter) && alter["subtype"] === "AT_EnableRowSecurity";
34
- });
35
- }
36
- function readsColumn(expr) {
37
- if (Array.isArray(expr)) return expr.some((item) => readsColumn(item));
38
- if (!isRecord(expr)) return false;
39
- return Object.entries(expr).some(([key, child]) => key === "ColumnRef" || readsColumn(child));
40
- }
41
- function appliesToSelect(policy) {
42
- return (policy.command === "select" || policy.command === "all") && policy.roles.some((role) => role === "authenticated" || role === "public");
43
- }
44
- /** The rule a permissive select policy that is not the tenant form breaks. */
45
- function ruleOf(policy, plainHelper) {
46
- const names = sqlCalls(policy.using).map((call) => call.name.join("."));
47
- if (names.length > 0 && names.every((name) => name === plainHelper)) return "form";
48
- if (names.some((name) => name.includes("follows"))) return "follows";
49
- if (names.some((name) => name.includes("_via"))) return "via";
50
- if (names.some((name) => name.includes("walk"))) return "walk";
51
- if (names.some((name) => name === "auth.uid" || name.endsWith("permdock_user_id"))) return "owner";
52
- return policy.using === void 0 ? "unknown" : "condition";
53
- }
54
- function keysOf(expr, helper) {
55
- return sqlCalls(expr).flatMap((call) => {
56
- if (call.name.join(".") !== helper) return [];
57
- const args = Array.isArray(call.node["args"]) ? call.node["args"] : [];
58
- const constant = args.length === 1 && isRecord(args[0]) ? args[0]["A_Const"] : void 0;
59
- const value = isRecord(constant) && isRecord(constant["sval"]) ? constant["sval"]["sval"] : void 0;
60
- return typeof value === "string" ? [value] : [];
61
- });
62
- }
63
- function readOf(table, facts, helpers, fieldTables) {
64
- if (facts === void 0 || !facts.rls) return {
65
- table,
66
- share: "row",
67
- rules: ["unknown"]
68
- };
69
- const selects = [...facts.policies.values()].filter(appliesToSelect);
70
- const permissive = selects.filter((policy) => policy.permissive);
71
- const rules = /* @__PURE__ */ new Set();
72
- const columns = /* @__PURE__ */ new Set();
73
- const keys = /* @__PURE__ */ new Set();
74
- if (fieldTables.has(table)) rules.add("fields");
75
- if (permissive.length === 0) rules.add("unknown");
76
- for (const policy of permissive) {
77
- const check = policy.tagged ?? tenantCheck(policy.using, helpers.byPermission);
78
- for (const key of policy.tagged === void 0 ? keysOf(policy.using, helpers.byPermission) : [policy.tagged.key]) keys.add(key);
79
- if (check === void 0) rules.add(ruleOf(policy, helpers.plain));
80
- else columns.add(check.column);
81
- }
82
- if (selects.some((policy) => !policy.permissive && readsColumn(policy.using))) rules.add("restrictive");
83
- if (rules.size === 0 && columns.size > 1) rules.add("condition");
84
- const permissions = [...keys].toSorted();
85
- const listed = permissions.length === 0 ? {} : { permissions };
86
- if (rules.size > 0) return {
87
- table,
88
- share: "row",
89
- ...listed,
90
- rules: [...rules].toSorted()
91
- };
92
- const [column] = columns;
93
- return {
94
- table,
95
- share: "tenant",
96
- ...column === void 0 ? {} : { column },
97
- ...listed
98
- };
99
- }
100
- /**
101
- * `rls.tableReads`: for each table the schema files and migrations create, from
102
- * the select policies they leave defined plus the policies `@bsb access` tags
103
- * render. A table is `tenant` only when row level security is on, it has no
104
- * field view, every permissive select policy for `authenticated` is `<column>
105
- * in (select <schema>.permitted_<root>_ids_by_permission('<key>'))` on one
106
- * column, and every restrictive select policy reads no column of the row.
107
- * Everything else is `row`, with the rules it breaks. Tables in the helpers'
108
- * schema, `better_supabase` and platform schemas are left out. A file
109
- * libpg_query rejects is skipped. The files are read from disk, so select
110
- * policies a `generate` run changes in `rls.out` are recorded on the next run.
111
- */
112
- async function tableReads(input) {
113
- const created = /* @__PURE__ */ new Set();
114
- const facts = /* @__PURE__ */ new Map();
115
- const factsOf = (table) => {
116
- const found = facts.get(table) ?? {
117
- rls: false,
118
- policies: /* @__PURE__ */ new Map()
119
- };
120
- facts.set(table, found);
121
- return found;
122
- };
123
- for (const file of reportFiles(input.cwd, input.config)) {
124
- let nodes;
125
- try {
126
- nodes = await parseSqlFile(readFileSync(file, "utf8"));
127
- } catch (error) {
128
- if (error instanceof SqlSyntaxError) continue;
129
- throw error;
130
- }
131
- for (const node of nodes) if (node.kind === "CreateStmt") {
132
- const table = relationName(node.node["relation"]);
133
- if (table !== void 0) created.add(table);
134
- } else if (node.kind === "AlterTableStmt" && enablesRls(node.node)) {
135
- const table = relationName(node.node["relation"]);
136
- if (table !== void 0) factsOf(table).rls = true;
137
- } else if (node.kind === "DropStmt") {
138
- const dropped = droppedPolicy(node.node);
139
- if (dropped !== void 0) facts.get(`${dropped.schema}.${dropped.table}`.toLowerCase())?.policies.delete(dropped.name);
140
- } else {
141
- const policy = readPolicy(node);
142
- if (policy !== void 0) factsOf(`${policy.schema}.${policy.table}`.toLowerCase()).policies.set(policy.name, policy);
143
- }
144
- }
145
- for (const tagged of await taggedAccessPolicies(input.cwd)) {
146
- if (tagged.operation.toLowerCase() !== "read") continue;
147
- factsOf(`${tagged.schema}.${tagged.table}`.toLowerCase()).policies.set(tagged.name, {
148
- name: tagged.name,
149
- command: "select",
150
- permissive: true,
151
- roles: ["authenticated"],
152
- tagged: {
153
- column: tagged.tenantColumn,
154
- key: tagged.key
155
- }
156
- });
157
- }
158
- const helpers = {
159
- plain: `${input.schema}.permitted_${input.root}_ids`,
160
- byPermission: `${input.schema}.permitted_${input.root}_ids_by_permission`
161
- };
162
- const helperSchema = input.schema.toLowerCase();
163
- return [...created].filter((table) => {
164
- const schema = table.slice(0, table.indexOf("."));
165
- return schema !== helperSchema && !LIBRARY_SCHEMAS.has(schema) && !isPlatformSchema(schema);
166
- }).toSorted().map((table) => readOf(table, facts.get(table), helpers, input.fieldTables ?? /* @__PURE__ */ new Set()));
167
- }
168
- /** `tableReads` for the helpers, root scope and field views `manifest` names. */
169
- function manifestTableReads(cwd, config, manifest) {
170
- const root = manifest.rls.scopes[0]?.name;
171
- if (root === void 0) return Promise.resolve([]);
172
- const fieldTables = new Set(Object.values(manifest.names?.resources ?? {}).flatMap((names) => names.table === void 0 || names.visible === void 0 ? [] : [(names.table.includes(".") ? names.table : `public.${names.table}`).toLowerCase()]));
173
- return tableReads({
174
- cwd,
175
- config,
176
- schema: manifest.rls.schema,
177
- root,
178
- fieldTables
179
- });
180
- }
181
- /**
182
- * `manifest` with `rls.tableReads` from the files on disk; unchanged when the
183
- * files create no table.
184
- */
185
- async function withTableReads(cwd, config, manifest) {
186
- const reads = await manifestTableReads(cwd, config, manifest);
187
- return reads.length === 0 ? manifest : {
188
- ...manifest,
189
- rls: {
190
- ...manifest.rls,
191
- tableReads: reads
192
- }
193
- };
194
- }
195
20
  // src/cli/supabase-setup.ts
196
21
  const HELPER_NAME = /^(?:permdock_has|permitted_[a-z][a-z0-9_]*_ids|member_[a-z][a-z0-9_]*_ids(?:_for|_of)?)$/u;
197
22
  function escape(text) {
@@ -484,8 +309,9 @@ async function runSupabase(input) {
484
309
  if (area === "inspect" && action === void 0) {
485
310
  const policy = await loadHookPolicy(input.cwd, input.config);
486
311
  const config = await withSchemaDefaults(input.cwd, input.config, policy);
312
+ const reasons = tryKeyReasons(input.config, policy, input.cwd);
487
313
  if (hooklessDatabase(input.config)) {
488
- const bare = await withTableReads(input.cwd, input.config, supabaseDatabaseManifest(scopeList(policy.scopes), config, overrides, policy));
314
+ const bare = await withTableReads(input.cwd, input.config, supabaseDatabaseManifest(scopeList(policy.scopes), config, overrides, policy), reasons);
489
315
  if (input.out !== void 0 || input.check) return manifestFile(input.cwd, typeof input.out === "string" ? input.out : MANIFEST_FILE, bare, input.check);
490
316
  return {
491
317
  code: 0,
@@ -496,7 +322,7 @@ async function runSupabase(input) {
496
322
  ...overrides,
497
323
  out: hookOut(input.cwd, input.config, input.schema, flag),
498
324
  schemas: schemas.mode
499
- }, policy));
325
+ }, policy), reasons);
500
326
  const api = managementApi(input.cwd, manifest);
501
327
  if (input.out !== void 0 || input.check) return manifestFile(input.cwd, typeof input.out === "string" ? input.out : MANIFEST_FILE, {
502
328
  ...manifest,
@@ -581,4 +407,4 @@ async function runSupabase(input) {
581
407
  ].join("\n")
582
408
  };
583
409
  }
584
- export { manifestTableReads as a, pd039 as i, loadScopes as n, runSupabase as r, hookOut as t };
410
+ export { pd039 as i, loadScopes as n, runSupabase as r, hookOut as t };
@@ -1,7 +1,7 @@
1
1
  import "./sources-DnjJPGfb.js";
2
2
  import { a as describeError } from "./errors-DgLOqc6j.js";
3
- import { n as hookUri } from "./rbac-CwcucZPx.js";
4
- import { t as supabaseConfigFile } from "./supabase-dir-0lxKbrYu.js";
3
+ import { n as hookUri } from "./rbac-mblGDx-Z.js";
4
+ import { n as supabaseDir, t as supabaseConfigFile } from "./supabase-dir-0lxKbrYu.js";
5
5
  import { existsSync, readFileSync } from "node:fs";
6
6
  import { join, posix } from "node:path";
7
7
  import { createRequire } from "node:module";
@@ -931,18 +931,19 @@ function readSupabaseConfig(cwd, env = process.env) {
931
931
  } },
932
932
  ...pgDelta === void 0 ? {} : { pgDelta: {
933
933
  ...typeof enabled === "boolean" ? { enabled } : {},
934
- schemaDir: declarativeSchemaDir(schemaPath)
934
+ schemaDir: declarativeSchemaDir(schemaPath, cwd)
935
935
  } },
936
936
  ...unresolved.length === 0 ? {} : { unresolvedEnv: unresolved }
937
937
  }
938
938
  };
939
939
  }
940
940
  /**
941
- * `supabase/` joined with `declarative_schema_path`, which defaults to
942
- * `schemas`.
941
+ * The Supabase directory joined with `declarative_schema_path`, which defaults
942
+ * to `schemas`, relative to `cwd`. The directory is the nearest `supabase/`
943
+ * above `cwd` (`supabaseDir`), so a package of a monorepo finds the root one.
943
944
  */
944
- function declarativeSchemaDir(schemaPath) {
945
- return posix.join("supabase", typeof schemaPath === "string" ? schemaPath : "schemas").replace(/\/$/u, "");
945
+ function declarativeSchemaDir(schemaPath, cwd) {
946
+ return posix.join(cwd === void 0 ? "supabase" : supabaseDir(cwd), typeof schemaPath === "string" ? schemaPath : "schemas").replace(/\/$/u, "");
946
947
  }
947
948
  /**
948
949
  * The parsed config, or `{}` when it is missing or does not parse (PD045
@@ -1068,7 +1069,7 @@ function resolveSchemas(cwd, config, flag) {
1068
1069
  switch (mode) {
1069
1070
  case "pg-delta": return {
1070
1071
  mode,
1071
- schemaDir: toml?.schemaDir ?? declarativeSchemaDir()
1072
+ schemaDir: toml?.schemaDir ?? declarativeSchemaDir(void 0, cwd)
1072
1073
  };
1073
1074
  case "migra":
1074
1075
  case "migrations": return { mode };