@constructive-io/schema-builder 0.2.0 → 0.2.1

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 (131) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/card-widths-CmIxkRfh.cjs +28 -0
  3. package/dist/card-widths-CmIxkRfh.cjs.map +1 -0
  4. package/dist/card-widths-pI4Kw4Xz.js +22 -0
  5. package/dist/card-widths-pI4Kw4Xz.js.map +1 -0
  6. package/dist/core-WwCS0CKu.cjs +66 -0
  7. package/dist/core-WwCS0CKu.cjs.map +1 -0
  8. package/dist/core-kx6KjxE5.js +49 -0
  9. package/dist/core-kx6KjxE5.js.map +1 -0
  10. package/dist/core.cjs +14 -212
  11. package/dist/core.d.cts +3 -54
  12. package/dist/core.d.ts +3 -54
  13. package/dist/core.js +3 -200
  14. package/dist/create-table-card-BzNKfpXO.cjs +7726 -0
  15. package/dist/create-table-card-BzNKfpXO.cjs.map +1 -0
  16. package/dist/create-table-card-pZ0Aq6rr.js +7685 -0
  17. package/dist/create-table-card-pZ0Aq6rr.js.map +1 -0
  18. package/dist/delete-confirm-dialog-Ch4tWj6B.cjs +42 -0
  19. package/dist/delete-confirm-dialog-Ch4tWj6B.cjs.map +1 -0
  20. package/dist/delete-confirm-dialog-K0AWE643.js +37 -0
  21. package/dist/delete-confirm-dialog-K0AWE643.js.map +1 -0
  22. package/dist/empty-state-card-DMn8ADRq.cjs +62 -0
  23. package/dist/empty-state-card-DMn8ADRq.cjs.map +1 -0
  24. package/dist/empty-state-card-Dnn36JVH.js +57 -0
  25. package/dist/empty-state-card-Dnn36JVH.js.map +1 -0
  26. package/dist/fields.cjs +8 -7763
  27. package/dist/fields.d.cts +39 -39
  28. package/dist/fields.d.ts +39 -39
  29. package/dist/fields.js +2 -7735
  30. package/dist/generated-types-DZMUyNBH.d.cts +27 -0
  31. package/dist/generated-types-DZMUyNBH.d.ts +27 -0
  32. package/dist/index-9h0EROdb.d.cts +56 -0
  33. package/dist/index-CwQ9QpxA.d.ts +7 -0
  34. package/dist/index-DOWB1UBK.d.cts +56 -0
  35. package/dist/index-DOWB1UBK.d.ts +56 -0
  36. package/dist/index-Dgb_e3AP.d.cts +7 -0
  37. package/dist/index-p_NegPQ5.d.ts +56 -0
  38. package/dist/index.cjs +736 -13712
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +4 -10
  41. package/dist/index.d.ts +4 -10
  42. package/dist/index.js +725 -13680
  43. package/dist/index.js.map +1 -1
  44. package/dist/indexes-view-CJ1WQKdp.js +736 -0
  45. package/dist/indexes-view-CJ1WQKdp.js.map +1 -0
  46. package/dist/indexes-view-peIv6QUZ.cjs +759 -0
  47. package/dist/indexes-view-peIv6QUZ.cjs.map +1 -0
  48. package/dist/indexes.cjs +6 -1041
  49. package/dist/indexes.d.cts +27 -27
  50. package/dist/indexes.d.ts +27 -27
  51. package/dist/indexes.js +2 -1016
  52. package/dist/invalidate-database-entities-9DsT5NlP.cjs +2862 -0
  53. package/dist/invalidate-database-entities-9DsT5NlP.cjs.map +1 -0
  54. package/dist/invalidate-database-entities-CmmOT3S0.js +2559 -0
  55. package/dist/invalidate-database-entities-CmmOT3S0.js.map +1 -0
  56. package/dist/keyboard-activation-BQiV0scm.js +13 -0
  57. package/dist/keyboard-activation-BQiV0scm.js.map +1 -0
  58. package/dist/keyboard-activation-D-L0IU6Y.cjs +19 -0
  59. package/dist/keyboard-activation-D-L0IU6Y.cjs.map +1 -0
  60. package/dist/policies-view-BRbpbyB6.js +1018 -0
  61. package/dist/policies-view-BRbpbyB6.js.map +1 -0
  62. package/dist/policies-view-H1HTjpmv.cjs +1023 -0
  63. package/dist/policies-view-H1HTjpmv.cjs.map +1 -0
  64. package/dist/policies.cjs +10 -5939
  65. package/dist/policies.d.cts +55 -50
  66. package/dist/policies.d.ts +55 -50
  67. package/dist/policies.js +4 -5911
  68. package/dist/policy-config-form-BwyK7DGV.js +2502 -0
  69. package/dist/policy-config-form-BwyK7DGV.js.map +1 -0
  70. package/dist/policy-config-form-CefFo6Fw.cjs +2629 -0
  71. package/dist/policy-config-form-CefFo6Fw.cjs.map +1 -0
  72. package/dist/policy-types-D_sYWb-b.d.cts +81 -0
  73. package/dist/policy-types-D_sYWb-b.d.ts +81 -0
  74. package/dist/query-BmN_qO0W.js +171 -0
  75. package/dist/query-BmN_qO0W.js.map +1 -0
  76. package/dist/query-DU-KZleN.cjs +212 -0
  77. package/dist/query-DU-KZleN.cjs.map +1 -0
  78. package/dist/relationships-view-B5TAcPHU.cjs +2452 -0
  79. package/dist/relationships-view-B5TAcPHU.cjs.map +1 -0
  80. package/dist/relationships-view-DbwFh5r-.js +2417 -0
  81. package/dist/relationships-view-DbwFh5r-.js.map +1 -0
  82. package/dist/relationships.cjs +9 -4328
  83. package/dist/relationships.d.cts +93 -92
  84. package/dist/relationships.d.ts +93 -92
  85. package/dist/relationships.js +2 -4300
  86. package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
  87. package/dist/schema-builder-sidebar-Ctu621Vw.cjs +604 -0
  88. package/dist/schema-builder-sidebar-Ctu621Vw.cjs.map +1 -0
  89. package/dist/schema-builder-sidebar-VR-Ctidc.js +593 -0
  90. package/dist/schema-builder-sidebar-VR-Ctidc.js.map +1 -0
  91. package/dist/table-editor-C-hHz3DJ.cjs +1935 -0
  92. package/dist/table-editor-C-hHz3DJ.cjs.map +1 -0
  93. package/dist/table-editor-IVp3B4nG.js +1906 -0
  94. package/dist/table-editor-IVp3B4nG.js.map +1 -0
  95. package/dist/tables.cjs +6 -5643
  96. package/dist/tables.d.cts +22 -21
  97. package/dist/tables.d.ts +22 -21
  98. package/dist/tables.js +3 -5618
  99. package/dist/testing.cjs +63 -62
  100. package/dist/testing.cjs.map +1 -1
  101. package/dist/testing.d.cts +4 -4
  102. package/dist/testing.d.ts +4 -4
  103. package/dist/testing.js +62 -61
  104. package/dist/testing.js.map +1 -1
  105. package/dist/types-GUrH1Qny.d.cts +200 -0
  106. package/dist/types-GUrH1Qny.d.ts +200 -0
  107. package/dist/use-update-table-C7v3gRyG.cjs +291 -0
  108. package/dist/use-update-table-C7v3gRyG.cjs.map +1 -0
  109. package/dist/use-update-table-Dz6knGoH.js +244 -0
  110. package/dist/use-update-table-Dz6knGoH.js.map +1 -0
  111. package/package.json +6 -6
  112. package/dist/core.cjs.map +0 -1
  113. package/dist/core.js.map +0 -1
  114. package/dist/fields.cjs.map +0 -1
  115. package/dist/fields.js.map +0 -1
  116. package/dist/generated-types-CnAlqHU_.d.cts +0 -25
  117. package/dist/generated-types-CnAlqHU_.d.ts +0 -25
  118. package/dist/indexes.cjs.map +0 -1
  119. package/dist/indexes.js.map +0 -1
  120. package/dist/policies.cjs.map +0 -1
  121. package/dist/policies.js.map +0 -1
  122. package/dist/policy-types-CEYAR5TN.d.cts +0 -79
  123. package/dist/policy-types-CEYAR5TN.d.ts +0 -79
  124. package/dist/relationships.cjs.map +0 -1
  125. package/dist/relationships.js.map +0 -1
  126. package/dist/tables.cjs.map +0 -1
  127. package/dist/tables.js.map +0 -1
  128. package/dist/types-Du86atZ8.d.cts +0 -199
  129. package/dist/types-Du86atZ8.d.ts +0 -199
  130. package/dist/types-bX2dCrdl.d.cts +0 -52
  131. package/dist/types-bX2dCrdl.d.ts +0 -52
@@ -0,0 +1,2629 @@
1
+ 'use client';
2
+ const require_rolldown_runtime = require('./rolldown-runtime-D_qnwXdH.cjs');
3
+ const require_query = require('./query-DU-KZleN.cjs');
4
+ const require_invalidate_database_entities = require('./invalidate-database-entities-9DsT5NlP.cjs');
5
+ let react = require("react");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let _constructive_io_ui_tooltip = require("@constructive-io/ui/tooltip");
8
+ let lucide_react = require("lucide-react");
9
+ let _tanstack_react_query = require("@tanstack/react-query");
10
+ let _constructive_io_ui_button = require("@constructive-io/ui/button");
11
+ let _constructive_io_ui_combobox = require("@constructive-io/ui/combobox");
12
+ let _constructive_io_ui_input = require("@constructive-io/ui/input");
13
+ let _constructive_io_ui_label = require("@constructive-io/ui/label");
14
+ let node_type_registry = require("node-type-registry");
15
+ node_type_registry = require_rolldown_runtime.__toESM(node_type_registry, 1);
16
+ let _constructive_io_ui_select = require("@constructive-io/ui/select");
17
+ let _constructive_io_ui_switch = require("@constructive-io/ui/switch");
18
+
19
+ //#region src/compat/admin-sdk.ts
20
+ function useAdminSdkClient() {
21
+ const { adapter, scope } = require_query.useSchemaBuilder();
22
+ return {
23
+ fetchAppPermissionsQuery: (variables, signal) => adapter.policies.appPermissions(variables, {
24
+ scope,
25
+ signal
26
+ }),
27
+ fetchOrgPermissionsQuery: (variables, signal) => adapter.policies.orgPermissions(variables, {
28
+ scope,
29
+ signal
30
+ })
31
+ };
32
+ }
33
+
34
+ //#endregion
35
+ //#region src/schema/schema-builder-core/lib/data/policy-provisioning.ts
36
+ const MEMBERSHIP_TYPES$1 = {
37
+ APP: 1,
38
+ ORGANIZATION: 2,
39
+ GROUP: 3
40
+ };
41
+ const POLICY_PROVISIONING_CONFIG = {
42
+ AuthzDirectOwner: {
43
+ category: "has-module",
44
+ hasDataNode: true,
45
+ dataNodeType: "DataDirectOwner",
46
+ fieldOverrides: { entity_field: {
47
+ type: "string",
48
+ required: true,
49
+ label: "Owner Field Name",
50
+ placeholder: "owner_id",
51
+ description: "Column that stores the owner user ID",
52
+ defaultValue: "owner_id"
53
+ } }
54
+ },
55
+ AuthzEntityMembership: {
56
+ category: "has-module",
57
+ hasDataNode: true,
58
+ dataNodeType: "DataEntityMembership",
59
+ fieldOverrides: {
60
+ entity_field: {
61
+ type: "string",
62
+ required: true,
63
+ label: "Entity Field Name",
64
+ placeholder: "entity_id",
65
+ description: "Column referencing the org/group",
66
+ defaultValue: "entity_id"
67
+ },
68
+ membership_type: {
69
+ type: "integer",
70
+ hidden: true,
71
+ defaultValue: MEMBERSHIP_TYPES$1.ORGANIZATION
72
+ },
73
+ permission: {
74
+ type: "string",
75
+ component: "permission-select",
76
+ label: "Required Permission",
77
+ description: "Optional permission the user must have"
78
+ },
79
+ is_admin: {
80
+ type: "boolean",
81
+ label: "Admins",
82
+ description: "People with admin access can view this."
83
+ },
84
+ is_owner: {
85
+ type: "boolean",
86
+ label: "Owners",
87
+ description: "People who own the membership can view this."
88
+ }
89
+ }
90
+ },
91
+ AuthzDirectOwnerAny: {
92
+ category: "needs-fields",
93
+ hasDataNode: false,
94
+ fieldOverrides: { entity_fields: {
95
+ type: "uuid[]",
96
+ required: true,
97
+ label: "Owner Fields",
98
+ description: "UUID columns to check for ownership (OR logic)",
99
+ defaultValue: ["owner_id"],
100
+ pgType: "uuid"
101
+ } }
102
+ },
103
+ AuthzAppMembership: {
104
+ category: "no-fields",
105
+ hasDataNode: false,
106
+ fieldOverrides: {
107
+ permission: {
108
+ type: "string",
109
+ component: "permission-select",
110
+ label: "Required Permission",
111
+ description: "Optional permission the user must have"
112
+ },
113
+ is_admin: {
114
+ type: "boolean",
115
+ label: "Admins",
116
+ description: "People with admin access can view this."
117
+ },
118
+ is_owner: {
119
+ type: "boolean",
120
+ label: "Owners",
121
+ description: "People who own the membership can view this."
122
+ }
123
+ }
124
+ },
125
+ AuthzPublishable: {
126
+ category: "has-module",
127
+ hasDataNode: true,
128
+ dataNodeType: "DataPublishable",
129
+ fieldOverrides: {
130
+ is_published_field: {
131
+ type: "string",
132
+ label: "Published Flag Field",
133
+ placeholder: "is_published",
134
+ defaultValue: "is_published"
135
+ },
136
+ published_at_field: {
137
+ type: "string",
138
+ label: "Published At Field",
139
+ placeholder: "published_at",
140
+ defaultValue: "published_at"
141
+ },
142
+ require_published_at: {
143
+ type: "boolean",
144
+ label: "Require Published At",
145
+ description: "Also require that the publish date has passed",
146
+ defaultValue: true
147
+ }
148
+ }
149
+ },
150
+ AuthzTemporal: {
151
+ category: "needs-fields",
152
+ hasDataNode: false,
153
+ fieldOverrides: {
154
+ valid_from_field: {
155
+ type: "string",
156
+ required: true,
157
+ label: "Valid From Field",
158
+ placeholder: "valid_from",
159
+ description: "Column for start time",
160
+ defaultValue: "valid_from",
161
+ pgType: "timestamptz"
162
+ },
163
+ valid_until_field: {
164
+ type: "string",
165
+ required: true,
166
+ label: "Valid Until Field",
167
+ placeholder: "valid_until",
168
+ description: "Column for end time",
169
+ defaultValue: "valid_until",
170
+ pgType: "timestamptz"
171
+ },
172
+ valid_from_inclusive: {
173
+ type: "boolean",
174
+ label: "Include Start",
175
+ description: "Include start boundary",
176
+ defaultValue: true
177
+ },
178
+ valid_until_inclusive: {
179
+ type: "boolean",
180
+ label: "Include End",
181
+ description: "Include end boundary",
182
+ defaultValue: false
183
+ }
184
+ }
185
+ },
186
+ AuthzMemberList: {
187
+ category: "needs-fields",
188
+ hasDataNode: false,
189
+ fieldOverrides: { array_field: {
190
+ type: "string",
191
+ required: true,
192
+ label: "Member List Field",
193
+ placeholder: "allowed_users",
194
+ description: "Column containing list of user IDs",
195
+ defaultValue: "allowed_users",
196
+ pgType: "uuid[]"
197
+ } }
198
+ },
199
+ AuthzRelatedMemberList: {
200
+ category: "needs-table",
201
+ hasDataNode: false,
202
+ fieldOverrides: {
203
+ owned_schema: { hidden: true },
204
+ owned_table: {
205
+ type: "string",
206
+ required: true,
207
+ component: "table-select",
208
+ label: "Related Table",
209
+ placeholder: "groups",
210
+ description: "Table containing the member list"
211
+ },
212
+ owned_table_key: {
213
+ type: "uuid",
214
+ required: true,
215
+ label: "Member List Column",
216
+ placeholder: "member_ids",
217
+ description: "List column in related table",
218
+ dependsOn: "owned_table"
219
+ },
220
+ owned_table_ref_key: {
221
+ type: "uuid",
222
+ required: true,
223
+ label: "Reference Key",
224
+ placeholder: "id",
225
+ description: "FK column in related table",
226
+ dependsOn: "owned_table"
227
+ },
228
+ this_object_key: {
229
+ type: "uuid",
230
+ required: true,
231
+ label: "Foreign Key",
232
+ placeholder: "group_id",
233
+ description: "FK on this table to related table"
234
+ }
235
+ }
236
+ },
237
+ AuthzRelatedEntityMembership: {
238
+ category: "needs-table",
239
+ hasDataNode: false,
240
+ fieldOverrides: {
241
+ entity_field: {
242
+ type: "uuid",
243
+ required: true,
244
+ label: "Foreign Key Field",
245
+ description: "Field on this table referencing the linked table"
246
+ },
247
+ membership_type: {
248
+ type: "integer",
249
+ required: true,
250
+ component: "membership-type-select",
251
+ label: "Membership Scope"
252
+ },
253
+ obj_schema: { hidden: true },
254
+ obj_table: {
255
+ type: "string",
256
+ required: true,
257
+ component: "table-select",
258
+ label: "Linked Table",
259
+ description: "Table to check for membership"
260
+ },
261
+ obj_field: {
262
+ type: "uuid",
263
+ required: true,
264
+ label: "Entity Field on Linked Table",
265
+ description: "Field containing entity ID for membership check",
266
+ dependsOn: "obj_table"
267
+ },
268
+ permission: {
269
+ type: "string",
270
+ component: "permission-select",
271
+ label: "Required Permission"
272
+ },
273
+ is_admin: {
274
+ type: "boolean",
275
+ label: "Admins",
276
+ description: "People with admin access can view this."
277
+ },
278
+ is_owner: {
279
+ type: "boolean",
280
+ label: "Owners",
281
+ description: "People who own the membership can view this."
282
+ }
283
+ }
284
+ },
285
+ AuthzOrgHierarchy: {
286
+ category: "has-module",
287
+ hasDataNode: true,
288
+ dataNodeType: "DataOwnershipInEntity",
289
+ disabled: true,
290
+ fieldOverrides: {
291
+ direction: {
292
+ type: "string",
293
+ required: true,
294
+ label: "Direction",
295
+ description: "Which direction to traverse the org hierarchy",
296
+ defaultValue: "down",
297
+ options: [{
298
+ value: "down",
299
+ label: "Down",
300
+ description: "Managers can see their subordinates"
301
+ }, {
302
+ value: "up",
303
+ label: "Up",
304
+ description: "Subordinates can see their managers"
305
+ }]
306
+ },
307
+ entity_field: {
308
+ type: "string",
309
+ label: "Entity Field Name",
310
+ placeholder: "entity_id",
311
+ description: "Field referencing the org entity",
312
+ defaultValue: "entity_id"
313
+ },
314
+ anchor_field: {
315
+ type: "string",
316
+ required: true,
317
+ label: "Anchor Field",
318
+ placeholder: "owner_id",
319
+ description: "Field referencing the user (e.g., owner_id)",
320
+ defaultValue: "owner_id"
321
+ },
322
+ max_depth: {
323
+ type: "integer",
324
+ label: "Max Depth",
325
+ description: "Optional max depth to limit visibility"
326
+ }
327
+ }
328
+ },
329
+ AuthzAllowAll: {
330
+ category: "no-fields",
331
+ hasDataNode: false
332
+ },
333
+ AuthzDenyAll: {
334
+ category: "no-fields",
335
+ hasDataNode: false
336
+ },
337
+ AuthzComposite: {
338
+ category: "no-fields",
339
+ hasDataNode: false
340
+ }
341
+ };
342
+ const DATA_NODE_GENERATED_FIELDS$1 = {
343
+ DataDirectOwner: [{
344
+ name: "owner_id",
345
+ type: "uuid",
346
+ nullable: false,
347
+ description: "References the owning user"
348
+ }],
349
+ DataEntityMembership: [{
350
+ name: "entity_id",
351
+ type: "uuid",
352
+ nullable: false,
353
+ description: "References the organization or group"
354
+ }],
355
+ DataOwnershipInEntity: [{
356
+ name: "owner_id",
357
+ type: "uuid",
358
+ nullable: false,
359
+ description: "References the owning user"
360
+ }, {
361
+ name: "entity_id",
362
+ type: "uuid",
363
+ nullable: false,
364
+ description: "References the organization or group"
365
+ }],
366
+ DataPublishable: [{
367
+ name: "is_published",
368
+ type: "boolean",
369
+ nullable: false,
370
+ description: "Whether the record is published"
371
+ }, {
372
+ name: "published_at",
373
+ type: "timestamptz",
374
+ nullable: true,
375
+ description: "When the record was published"
376
+ }],
377
+ DataTimestamps: [{
378
+ name: "created_at",
379
+ type: "timestamptz",
380
+ nullable: false,
381
+ description: "When the record was created"
382
+ }, {
383
+ name: "updated_at",
384
+ type: "timestamptz",
385
+ nullable: false,
386
+ description: "When the record was last updated"
387
+ }],
388
+ DataPeoplestamps: [{
389
+ name: "created_by",
390
+ type: "uuid",
391
+ nullable: true,
392
+ description: "User who created the record"
393
+ }, {
394
+ name: "updated_by",
395
+ type: "uuid",
396
+ nullable: true,
397
+ description: "User who last updated the record"
398
+ }],
399
+ DataSoftDelete: [{
400
+ name: "is_deleted",
401
+ type: "boolean",
402
+ nullable: false,
403
+ description: "Whether the record is soft-deleted"
404
+ }, {
405
+ name: "deleted_at",
406
+ type: "timestamptz",
407
+ nullable: true,
408
+ description: "When the record was deleted"
409
+ }]
410
+ };
411
+ const AUTO_INJECT_SCHEMA_FIELDS = /* @__PURE__ */ new Set(["owned_schema", "obj_schema"]);
412
+ function getPolicyCategory$1(policyType) {
413
+ return POLICY_PROVISIONING_CONFIG[policyType]?.category ?? "no-fields";
414
+ }
415
+ function getDataNodeForPolicy$1(policyType) {
416
+ return POLICY_PROVISIONING_CONFIG[policyType]?.dataNodeType;
417
+ }
418
+ function getGeneratedFields$1(dataNodeType) {
419
+ return DATA_NODE_GENERATED_FIELDS$1[dataNodeType] ?? [];
420
+ }
421
+ function getFieldsRequiringColumns$1(policyType) {
422
+ const config = POLICY_PROVISIONING_CONFIG[policyType];
423
+ if (!config?.fieldOverrides) return [];
424
+ const result = [];
425
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
426
+ if (!override.pgType) continue;
427
+ const defaultName = Array.isArray(override.defaultValue) ? override.defaultValue : typeof override.defaultValue === "string" ? override.defaultValue : key;
428
+ result.push({
429
+ key,
430
+ defaultName,
431
+ pgType: override.pgType
432
+ });
433
+ }
434
+ return result;
435
+ }
436
+ function sanitizePolicyData$1(data) {
437
+ const sanitized = {};
438
+ for (const [key, value] of Object.entries(data)) {
439
+ if (value === void 0 || value === null) continue;
440
+ if (typeof value === "string" && value.trim() === "") continue;
441
+ if (Array.isArray(value) && value.length === 0) continue;
442
+ sanitized[key] = value;
443
+ }
444
+ return sanitized;
445
+ }
446
+ function injectSchemaFields$1(policyData, schemaId, policyType) {
447
+ const config = POLICY_PROVISIONING_CONFIG[policyType];
448
+ if (!config?.fieldOverrides) return policyData;
449
+ const next = { ...policyData };
450
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
451
+ if (!AUTO_INJECT_SCHEMA_FIELDS.has(key)) continue;
452
+ if (override.hidden && next[key] === void 0) next[key] = schemaId;
453
+ }
454
+ return next;
455
+ }
456
+ function buildNodeDataForDataNodeType(dataNodeType, policyData) {
457
+ if (!dataNodeType) return {};
458
+ const data = {};
459
+ if (dataNodeType === "DataDirectOwner") {
460
+ if (policyData.entity_field && policyData.entity_field !== "owner_id") data.owner_field_name = policyData.entity_field;
461
+ }
462
+ if (dataNodeType === "DataEntityMembership") {
463
+ if (policyData.entity_field && policyData.entity_field !== "entity_id") data.entity_field_name = policyData.entity_field;
464
+ }
465
+ if (dataNodeType === "DataOwnershipInEntity") {
466
+ if (policyData.entity_field && policyData.entity_field !== "entity_id") data.entity_field_name = policyData.entity_field;
467
+ if (policyData.anchor_field && policyData.anchor_field !== "owner_id") data.owner_field_name = policyData.anchor_field;
468
+ }
469
+ return data;
470
+ }
471
+ function buildNodeData$1(policyType, policyData) {
472
+ return buildNodeDataForDataNodeType(getDataNodeForPolicy$1(policyType), policyData);
473
+ }
474
+
475
+ //#endregion
476
+ //#region src/schema/schema-builder-policies/lib/gql/hooks/schema-builder/use-table-grants.ts
477
+ /**
478
+ * Hook for managing table grants (permissions)
479
+ * Tier 4 wrapper: orchestrates table lookup + grant creation using SDK hooks
480
+ */
481
+ /**
482
+ * Fetches table metadata including fields by database ID and table name.
483
+ * Required for grant operations to get table ID and field IDs.
484
+ * Uses SDK hooks via composition.
485
+ */
486
+ async function getTableByName(databaseId, tableName, client) {
487
+ try {
488
+ const table = (await client.fetchTablesQuery({ selection: {
489
+ fields: {
490
+ id: true,
491
+ name: true,
492
+ useRls: true
493
+ },
494
+ where: {
495
+ databaseId: { equalTo: databaseId },
496
+ name: { equalTo: tableName }
497
+ },
498
+ first: 1
499
+ } }))?.tables?.nodes?.[0];
500
+ if (!table?.id) return null;
501
+ const fields = (await client.fetchFieldsQuery({ selection: {
502
+ fields: {
503
+ id: true,
504
+ name: true
505
+ },
506
+ where: { tableId: { equalTo: table.id } }
507
+ } }))?.fields?.nodes ?? [];
508
+ return {
509
+ id: table.id,
510
+ name: table.name ?? tableName,
511
+ useRls: table.useRls ?? false,
512
+ fields: fields.map((f) => ({
513
+ id: f.id ?? "",
514
+ name: f.name ?? ""
515
+ })).filter((f) => f.id && f.name)
516
+ };
517
+ } catch (error) {
518
+ console.error(`Failed to fetch table ${tableName}:`, error);
519
+ return null;
520
+ }
521
+ }
522
+ /**
523
+ * Resolves field names to field IDs using table metadata.
524
+ */
525
+ function resolveFieldIds(table, fieldNames) {
526
+ const fieldIds = [];
527
+ for (const fieldName of fieldNames) {
528
+ const field = table.fields.find((f) => f.name === fieldName);
529
+ if (field) fieldIds.push(field.id);
530
+ else console.warn(`Field ${fieldName} not found in table ${table.name}, skipping from grant`);
531
+ }
532
+ return fieldIds;
533
+ }
534
+ /**
535
+ * Hook for creating table grants (permissions).
536
+ * Supports both table-level grants (all fields) and field-level grants (specific fields).
537
+ *
538
+ * @example
539
+ * // Table-level grant (all fields)
540
+ * createGrant({
541
+ * databaseId: 'xxx',
542
+ * tableName: 'products',
543
+ * privileges: ['select', 'delete']
544
+ * })
545
+ *
546
+ * @example
547
+ * // Field-level grant (specific fields only)
548
+ * createGrant({
549
+ * databaseId: 'xxx',
550
+ * tableName: 'products',
551
+ * privileges: ['insert'],
552
+ * fieldNames: ['name', 'description', 'price']
553
+ * })
554
+ */
555
+ function useCreateTableGrant() {
556
+ const queryClient = (0, _tanstack_react_query.useQueryClient)();
557
+ const sdkClient = require_invalidate_database_entities.useSchemaBuilderSdkClient();
558
+ const createGrantMutation = require_invalidate_database_entities.useCreateTableGrantMutation({ selection: { fields: { id: true } } });
559
+ return (0, _tanstack_react_query.useMutation)({
560
+ mutationFn: async (input) => {
561
+ const { databaseId, tableName, privileges, fieldNames, roleName = "authenticated" } = input;
562
+ const table = await getTableByName(databaseId, tableName, sdkClient);
563
+ if (!table) throw new Error(`Table ${tableName} not found`);
564
+ let fieldIds;
565
+ if (fieldNames && fieldNames.length > 0) {
566
+ fieldIds = resolveFieldIds(table, fieldNames);
567
+ if (fieldIds.length === 0) throw new Error(`No valid fields found for grant on table ${tableName}`);
568
+ }
569
+ const results = [];
570
+ for (const privilege of privileges) try {
571
+ const grantInput = {
572
+ tableId: table.id,
573
+ privilege,
574
+ granteeName: roleName,
575
+ ...fieldIds && fieldIds.length > 0 && { fieldIds }
576
+ };
577
+ const result = await createGrantMutation.mutateAsync(grantInput);
578
+ results.push(result);
579
+ } catch (error) {
580
+ if (error?.message?.includes("already exists") || error?.message?.includes("duplicate key") || error?.message?.includes("unique constraint") || error?.message?.includes("unique violation")) continue;
581
+ throw new Error(`Failed to create ${privilege} grant on ${tableName}: ${error.message}`);
582
+ }
583
+ return results;
584
+ },
585
+ onSuccess: async (_result, variables) => {
586
+ await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, variables.databaseId);
587
+ },
588
+ onError: (error) => {
589
+ console.error("Failed to create table grant:", error);
590
+ }
591
+ });
592
+ }
593
+ /**
594
+ * Hook for creating multiple table grants in batch.
595
+ * Useful when setting up a new table with standard permissions.
596
+ *
597
+ * @example
598
+ * batchCreateGrants({
599
+ * databaseId: 'xxx',
600
+ * tableName: 'products',
601
+ * grants: [
602
+ * { privileges: ['select', 'delete'] }, // All fields
603
+ * { privileges: ['insert'], fieldNames: ['name', 'price'] }, // Specific fields
604
+ * { privileges: ['update'], fieldNames: ['name', 'description'] },
605
+ * ]
606
+ * })
607
+ */
608
+ function useBatchCreateTableGrants() {
609
+ const { mutateAsync: createGrant } = useCreateTableGrant();
610
+ return (0, _tanstack_react_query.useMutation)({
611
+ mutationFn: async (input) => {
612
+ const { databaseId, tableName, grants } = input;
613
+ const results = [];
614
+ for (const grant of grants) try {
615
+ const result = await createGrant({
616
+ databaseId,
617
+ tableName,
618
+ ...grant
619
+ });
620
+ results.push(result);
621
+ } catch (error) {
622
+ console.error(`Failed to create grant for ${tableName}:`, error);
623
+ }
624
+ return results;
625
+ },
626
+ onError: (error) => {
627
+ console.error("Failed to create batch grants:", error);
628
+ }
629
+ });
630
+ }
631
+
632
+ //#endregion
633
+ //#region src/schema/schema-builder-core/lib/constants/membership-types.ts
634
+ const MEMBERSHIP_TYPES = {
635
+ APP: 1,
636
+ ORGANIZATION: 2,
637
+ GROUP: 3
638
+ };
639
+
640
+ //#endregion
641
+ //#region src/schema/schema-builder-core/components/policies/policy-config.ts
642
+ /**
643
+ * Frontend UI decorator for policy types.
644
+ *
645
+ * Backend node_type_registry is the source of truth for policy type identity
646
+ * (name, displayName). This config adds frontend-only concerns:
647
+ * icons, descriptions, workflow categories, field overrides.
648
+ * Display order is determined by object insertion order.
649
+ *
650
+ * Policy types NOT in this config will not appear in the wizard.
651
+ */
652
+ const paramOf = (def) => def.parameter_schema.properties;
653
+ const POLICY_TYPE_UI_CONFIG = {
654
+ AuthzDirectOwner: {
655
+ fallbackTitle: node_type_registry.AuthzDirectOwner.display_name,
656
+ description: node_type_registry.AuthzDirectOwner.description,
657
+ icon: lucide_react.User,
658
+ category: "has-module",
659
+ hasDataNode: true,
660
+ dataNodeType: node_type_registry.DataDirectOwner.name,
661
+ fieldOverrides: { entity_field: {
662
+ type: "string",
663
+ required: true,
664
+ label: "Owner Field Name",
665
+ placeholder: "owner_id",
666
+ description: paramOf(node_type_registry.AuthzDirectOwner)?.entity_field?.description,
667
+ defaultValue: "owner_id"
668
+ } }
669
+ },
670
+ AuthzEntityMembership: {
671
+ fallbackTitle: node_type_registry.AuthzEntityMembership.display_name,
672
+ description: node_type_registry.AuthzEntityMembership.description,
673
+ icon: lucide_react.Shield,
674
+ category: "has-module",
675
+ hasDataNode: true,
676
+ dataNodeType: node_type_registry.DataEntityMembership.name,
677
+ fieldOverrides: {
678
+ entity_field: {
679
+ type: "string",
680
+ required: true,
681
+ label: "Entity Field Name",
682
+ placeholder: "entity_id",
683
+ description: paramOf(node_type_registry.AuthzEntityMembership)?.entity_field?.description,
684
+ defaultValue: "entity_id"
685
+ },
686
+ membership_type: {
687
+ type: "integer",
688
+ hidden: true,
689
+ defaultValue: MEMBERSHIP_TYPES.ORGANIZATION
690
+ },
691
+ permission: {
692
+ type: "string",
693
+ component: "permission-select",
694
+ label: "Required Permission",
695
+ description: paramOf(node_type_registry.AuthzEntityMembership)?.permission?.description
696
+ },
697
+ is_admin: {
698
+ type: "boolean",
699
+ label: "Admins",
700
+ description: paramOf(node_type_registry.AuthzEntityMembership)?.is_admin?.description
701
+ },
702
+ is_owner: {
703
+ type: "boolean",
704
+ label: "Owners",
705
+ description: paramOf(node_type_registry.AuthzEntityMembership)?.is_owner?.description
706
+ }
707
+ }
708
+ },
709
+ AuthzDirectOwnerAny: {
710
+ fallbackTitle: node_type_registry.AuthzDirectOwnerAny.display_name,
711
+ description: node_type_registry.AuthzDirectOwnerAny.description,
712
+ icon: lucide_react.Users,
713
+ category: "needs-fields",
714
+ hasDataNode: false,
715
+ fieldOverrides: { entity_fields: {
716
+ type: "uuid[]",
717
+ required: true,
718
+ label: "Owner Fields",
719
+ description: paramOf(node_type_registry.AuthzDirectOwnerAny)?.entity_fields?.description,
720
+ defaultValue: ["owner_id"],
721
+ pgType: "uuid"
722
+ } }
723
+ },
724
+ AuthzAppMembership: {
725
+ fallbackTitle: node_type_registry.AuthzAppMembership.display_name,
726
+ description: node_type_registry.AuthzAppMembership.description,
727
+ icon: lucide_react.Globe,
728
+ category: "no-fields",
729
+ hasDataNode: false,
730
+ fieldOverrides: {
731
+ permission: {
732
+ type: "string",
733
+ component: "permission-select",
734
+ label: "Required Permission",
735
+ description: paramOf(node_type_registry.AuthzAppMembership)?.permission?.description
736
+ },
737
+ is_admin: {
738
+ type: "boolean",
739
+ label: "Admins",
740
+ description: paramOf(node_type_registry.AuthzAppMembership)?.is_admin?.description
741
+ },
742
+ is_owner: {
743
+ type: "boolean",
744
+ label: "Owners",
745
+ description: paramOf(node_type_registry.AuthzAppMembership)?.is_owner?.description
746
+ }
747
+ }
748
+ },
749
+ AuthzPublishable: {
750
+ fallbackTitle: node_type_registry.AuthzPublishable.display_name,
751
+ description: node_type_registry.AuthzPublishable.description,
752
+ icon: lucide_react.Eye,
753
+ category: "has-module",
754
+ hasDataNode: true,
755
+ dataNodeType: node_type_registry.DataPublishable.name,
756
+ fieldOverrides: {
757
+ is_published_field: {
758
+ type: "string",
759
+ label: "Published Flag Field",
760
+ placeholder: "is_published",
761
+ description: paramOf(node_type_registry.AuthzPublishable)?.is_published_field?.description,
762
+ defaultValue: paramOf(node_type_registry.AuthzPublishable)?.is_published_field?.default ?? "is_published"
763
+ },
764
+ published_at_field: {
765
+ type: "string",
766
+ label: "Published At Field",
767
+ placeholder: "published_at",
768
+ description: paramOf(node_type_registry.AuthzPublishable)?.published_at_field?.description,
769
+ defaultValue: paramOf(node_type_registry.AuthzPublishable)?.published_at_field?.default ?? "published_at"
770
+ },
771
+ require_published_at: {
772
+ type: "boolean",
773
+ label: "Require Published At",
774
+ description: paramOf(node_type_registry.AuthzPublishable)?.require_published_at?.description,
775
+ defaultValue: paramOf(node_type_registry.AuthzPublishable)?.require_published_at?.default ?? true
776
+ }
777
+ }
778
+ },
779
+ AuthzTemporal: {
780
+ fallbackTitle: node_type_registry.AuthzTemporal.display_name,
781
+ description: node_type_registry.AuthzTemporal.description,
782
+ icon: lucide_react.Clock,
783
+ category: "needs-fields",
784
+ hasDataNode: false,
785
+ fieldOverrides: {
786
+ valid_from_field: {
787
+ type: "string",
788
+ required: true,
789
+ label: "Valid From Field",
790
+ placeholder: "valid_from",
791
+ description: paramOf(node_type_registry.AuthzTemporal)?.valid_from_field?.description,
792
+ defaultValue: "valid_from",
793
+ pgType: "timestamptz"
794
+ },
795
+ valid_until_field: {
796
+ type: "string",
797
+ required: true,
798
+ label: "Valid Until Field",
799
+ placeholder: "valid_until",
800
+ description: paramOf(node_type_registry.AuthzTemporal)?.valid_until_field?.description,
801
+ defaultValue: "valid_until",
802
+ pgType: "timestamptz"
803
+ },
804
+ valid_from_inclusive: {
805
+ type: "boolean",
806
+ label: "Include Start",
807
+ description: paramOf(node_type_registry.AuthzTemporal)?.valid_from_inclusive?.description,
808
+ defaultValue: paramOf(node_type_registry.AuthzTemporal)?.valid_from_inclusive?.default ?? true
809
+ },
810
+ valid_until_inclusive: {
811
+ type: "boolean",
812
+ label: "Include End",
813
+ description: paramOf(node_type_registry.AuthzTemporal)?.valid_until_inclusive?.description,
814
+ defaultValue: paramOf(node_type_registry.AuthzTemporal)?.valid_until_inclusive?.default ?? false
815
+ }
816
+ }
817
+ },
818
+ AuthzMemberList: {
819
+ fallbackTitle: node_type_registry.AuthzMemberList.display_name,
820
+ description: node_type_registry.AuthzMemberList.description,
821
+ icon: lucide_react.Users,
822
+ category: "needs-fields",
823
+ hasDataNode: false,
824
+ fieldOverrides: { array_field: {
825
+ type: "string",
826
+ required: true,
827
+ label: "Member List Field",
828
+ placeholder: "allowed_users",
829
+ description: paramOf(node_type_registry.AuthzMemberList)?.array_field?.description,
830
+ defaultValue: "allowed_users",
831
+ pgType: "uuid[]"
832
+ } }
833
+ },
834
+ AuthzRelatedMemberList: {
835
+ fallbackTitle: node_type_registry.AuthzRelatedMemberList.display_name,
836
+ description: node_type_registry.AuthzRelatedMemberList.description,
837
+ icon: lucide_react.UserCheck,
838
+ category: "needs-table",
839
+ hasDataNode: false,
840
+ fieldOverrides: {
841
+ owned_schema: { hidden: true },
842
+ owned_table: {
843
+ type: "string",
844
+ required: true,
845
+ component: "table-select",
846
+ label: "Related Table",
847
+ placeholder: "groups",
848
+ description: paramOf(node_type_registry.AuthzRelatedMemberList)?.owned_table?.description
849
+ },
850
+ owned_table_key: {
851
+ type: "uuid",
852
+ required: true,
853
+ label: "Member List Column",
854
+ placeholder: "member_ids",
855
+ description: paramOf(node_type_registry.AuthzRelatedMemberList)?.owned_table_key?.description,
856
+ dependsOn: "owned_table"
857
+ },
858
+ owned_table_ref_key: {
859
+ type: "uuid",
860
+ required: true,
861
+ label: "Reference Key",
862
+ placeholder: "id",
863
+ description: paramOf(node_type_registry.AuthzRelatedMemberList)?.owned_table_ref_key?.description,
864
+ dependsOn: "owned_table"
865
+ },
866
+ this_object_key: {
867
+ type: "uuid",
868
+ required: true,
869
+ label: "Foreign Key",
870
+ placeholder: "group_id",
871
+ description: paramOf(node_type_registry.AuthzRelatedMemberList)?.this_object_key?.description
872
+ }
873
+ }
874
+ },
875
+ AuthzRelatedEntityMembership: {
876
+ fallbackTitle: node_type_registry.AuthzRelatedEntityMembership.display_name,
877
+ description: node_type_registry.AuthzRelatedEntityMembership.description,
878
+ icon: lucide_react.Link,
879
+ category: "needs-table",
880
+ hasDataNode: false,
881
+ fieldOverrides: {
882
+ entity_field: {
883
+ type: "uuid",
884
+ required: true,
885
+ label: "Foreign Key Field",
886
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.entity_field?.description
887
+ },
888
+ membership_type: {
889
+ type: "integer",
890
+ required: true,
891
+ component: "membership-type-select",
892
+ label: "Membership Scope",
893
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.membership_type?.description
894
+ },
895
+ obj_schema: { hidden: true },
896
+ obj_table: {
897
+ type: "string",
898
+ required: true,
899
+ component: "table-select",
900
+ label: "Linked Table",
901
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.obj_table?.description
902
+ },
903
+ obj_field: {
904
+ type: "uuid",
905
+ required: true,
906
+ label: "Entity Field on Linked Table",
907
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.obj_field?.description,
908
+ dependsOn: "obj_table"
909
+ },
910
+ permission: {
911
+ type: "string",
912
+ component: "permission-select",
913
+ label: "Required Permission",
914
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.permission?.description
915
+ },
916
+ is_admin: {
917
+ type: "boolean",
918
+ label: "Admins",
919
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.is_admin?.description
920
+ },
921
+ is_owner: {
922
+ type: "boolean",
923
+ label: "Owners",
924
+ description: paramOf(node_type_registry.AuthzRelatedEntityMembership)?.is_owner?.description
925
+ }
926
+ }
927
+ },
928
+ AuthzOrgHierarchy: {
929
+ fallbackTitle: node_type_registry.AuthzOrgHierarchy.display_name,
930
+ description: node_type_registry.AuthzOrgHierarchy.description,
931
+ icon: lucide_react.Network,
932
+ category: "has-module",
933
+ hasDataNode: true,
934
+ dataNodeType: node_type_registry.DataOwnershipInEntity.name,
935
+ disabled: true,
936
+ fieldOverrides: {
937
+ direction: {
938
+ type: "string",
939
+ required: true,
940
+ label: "Direction",
941
+ description: paramOf(node_type_registry.AuthzOrgHierarchy)?.direction?.description,
942
+ defaultValue: "down",
943
+ options: [{
944
+ value: "down",
945
+ label: "Down",
946
+ description: "Managers can see their subordinates"
947
+ }, {
948
+ value: "up",
949
+ label: "Up",
950
+ description: "Subordinates can see their managers"
951
+ }]
952
+ },
953
+ entity_field: {
954
+ type: "string",
955
+ label: "Entity Field Name",
956
+ placeholder: "entity_id",
957
+ description: paramOf(node_type_registry.AuthzOrgHierarchy)?.entity_field?.description,
958
+ defaultValue: paramOf(node_type_registry.AuthzOrgHierarchy)?.entity_field?.default ?? "entity_id"
959
+ },
960
+ anchor_field: {
961
+ type: "string",
962
+ required: true,
963
+ label: "Anchor Field",
964
+ placeholder: "owner_id",
965
+ description: paramOf(node_type_registry.AuthzOrgHierarchy)?.anchor_field?.description,
966
+ defaultValue: "owner_id"
967
+ },
968
+ max_depth: {
969
+ type: "integer",
970
+ label: "Max Depth",
971
+ description: paramOf(node_type_registry.AuthzOrgHierarchy)?.max_depth?.description
972
+ }
973
+ }
974
+ },
975
+ AuthzAllowAll: {
976
+ fallbackTitle: node_type_registry.AuthzAllowAll.display_name,
977
+ description: node_type_registry.AuthzAllowAll.description,
978
+ icon: lucide_react.Unlock,
979
+ category: "no-fields",
980
+ hasDataNode: false
981
+ },
982
+ AuthzDenyAll: {
983
+ fallbackTitle: node_type_registry.AuthzDenyAll.display_name,
984
+ description: node_type_registry.AuthzDenyAll.description,
985
+ icon: lucide_react.Lock,
986
+ category: "no-fields",
987
+ hasDataNode: false
988
+ },
989
+ AuthzComposite: {
990
+ fallbackTitle: node_type_registry.AuthzComposite.display_name,
991
+ description: node_type_registry.AuthzComposite.description,
992
+ icon: lucide_react.Layers,
993
+ category: "no-fields",
994
+ hasDataNode: false
995
+ }
996
+ };
997
+ const MEMBERSHIP_TYPE_OPTIONS$1 = [
998
+ {
999
+ value: MEMBERSHIP_TYPES.APP,
1000
+ label: "App Member",
1001
+ description: "Memberships to the app."
1002
+ },
1003
+ {
1004
+ value: MEMBERSHIP_TYPES.ORGANIZATION,
1005
+ label: "Organization Member",
1006
+ description: "Membership to an organization."
1007
+ },
1008
+ {
1009
+ value: MEMBERSHIP_TYPES.GROUP,
1010
+ label: "Group Member",
1011
+ description: "User's membership to a group."
1012
+ }
1013
+ ];
1014
+ /**
1015
+ * Fields that are auto-generated by each data node type.
1016
+ *
1017
+ * When a policy uses a data node (hasDataNode: true), these fields
1018
+ * will be automatically created on the table.
1019
+ */
1020
+ const DATA_NODE_GENERATED_FIELDS = {
1021
+ DataDirectOwner: [{
1022
+ name: "owner_id",
1023
+ type: "uuid",
1024
+ nullable: false,
1025
+ description: "References the owning user"
1026
+ }],
1027
+ DataEntityMembership: [{
1028
+ name: "entity_id",
1029
+ type: "uuid",
1030
+ nullable: false,
1031
+ description: "References the organization or group"
1032
+ }],
1033
+ DataOwnershipInEntity: [{
1034
+ name: "owner_id",
1035
+ type: "uuid",
1036
+ nullable: false,
1037
+ description: "References the owning user"
1038
+ }, {
1039
+ name: "entity_id",
1040
+ type: "uuid",
1041
+ nullable: false,
1042
+ description: "References the organization or group"
1043
+ }],
1044
+ DataPublishable: [{
1045
+ name: "is_published",
1046
+ type: "boolean",
1047
+ nullable: false,
1048
+ description: "Whether the record is published"
1049
+ }, {
1050
+ name: "published_at",
1051
+ type: "timestamptz",
1052
+ nullable: true,
1053
+ description: "When the record was published"
1054
+ }],
1055
+ DataTimestamps: [{
1056
+ name: "created_at",
1057
+ type: "timestamptz",
1058
+ nullable: false,
1059
+ description: "When the record was created"
1060
+ }, {
1061
+ name: "updated_at",
1062
+ type: "timestamptz",
1063
+ nullable: false,
1064
+ description: "When the record was last updated"
1065
+ }],
1066
+ DataPeoplestamps: [{
1067
+ name: "created_by",
1068
+ type: "uuid",
1069
+ nullable: true,
1070
+ description: "User who created the record"
1071
+ }, {
1072
+ name: "updated_by",
1073
+ type: "uuid",
1074
+ nullable: true,
1075
+ description: "User who last updated the record"
1076
+ }],
1077
+ DataSoftDelete: [{
1078
+ name: "is_deleted",
1079
+ type: "boolean",
1080
+ nullable: false,
1081
+ description: "Whether the record is soft-deleted"
1082
+ }, {
1083
+ name: "deleted_at",
1084
+ type: "timestamptz",
1085
+ nullable: true,
1086
+ description: "When the record was deleted"
1087
+ }]
1088
+ };
1089
+ /**
1090
+ * Get generated fields for a data node type
1091
+ */
1092
+ function getGeneratedFields(dataNodeType) {
1093
+ return getGeneratedFields$1(dataNodeType);
1094
+ }
1095
+ /**
1096
+ * Derives the mapping from generated field names to policy keys for a given policy type.
1097
+ * This is computed from fieldOverrides where defaultValue matches a generated field name.
1098
+ *
1099
+ * Returns: { generatedFieldName: { policyKey, defaultValue } }
1100
+ */
1101
+ function getGeneratedFieldMappings(policyType) {
1102
+ if (!policyType.dataNodeType) return void 0;
1103
+ const generatedFields = DATA_NODE_GENERATED_FIELDS[policyType.dataNodeType];
1104
+ if (!generatedFields) return void 0;
1105
+ const generatedFieldNames = new Set(generatedFields.map((f) => f.name));
1106
+ const result = {};
1107
+ for (const [policyKey, override] of Object.entries(policyType.fieldOverrides ?? {})) {
1108
+ const defaultValue = override?.defaultValue;
1109
+ if (typeof defaultValue === "string" && generatedFieldNames.has(defaultValue)) result[defaultValue] = {
1110
+ policyKey,
1111
+ defaultValue
1112
+ };
1113
+ }
1114
+ return Object.keys(result).length > 0 ? result : void 0;
1115
+ }
1116
+ /**
1117
+ * Get the data node type for a policy type.
1118
+ */
1119
+ function getDataNodeForPolicy(policyType) {
1120
+ return getDataNodeForPolicy$1(policyType);
1121
+ }
1122
+ /**
1123
+ * Sanitize policy data by removing undefined/null values
1124
+ */
1125
+ function sanitizePolicyData(data) {
1126
+ return sanitizePolicyData$1(data);
1127
+ }
1128
+ /**
1129
+ * Build node data from policy data for the provision call.
1130
+ *
1131
+ * Some node types need specific configuration from the policy data
1132
+ * (e.g., DataDirectOwner may need a custom field name)
1133
+ */
1134
+ function buildNodeData(policyData, policyType) {
1135
+ return buildNodeData$1(policyType.name, policyData);
1136
+ }
1137
+ /**
1138
+ * Inject schema ID into policy data for fields that require it.
1139
+ * These fields are hidden from the form but need to be populated at submit time.
1140
+ */
1141
+ function injectSchemaFields(policyData, schemaId, policyType) {
1142
+ return injectSchemaFields$1(policyData, schemaId, policyType);
1143
+ }
1144
+ /**
1145
+ * Get the policy category for a policy type
1146
+ */
1147
+ function getPolicyCategory(policyType) {
1148
+ return getPolicyCategory$1(policyType);
1149
+ }
1150
+ /**
1151
+ * Get fields that need database columns created (those with pgType in fieldOverrides)
1152
+ */
1153
+ function getFieldsRequiringColumns(policyType) {
1154
+ return getFieldsRequiringColumns$1(policyType);
1155
+ }
1156
+ /**
1157
+ * Walk a composite condition tree and inject schema fields into each leaf's data.
1158
+ * Returns a new tree (immutable).
1159
+ */
1160
+ function injectSchemaFieldsIntoCompositeTree(tree, schemaId) {
1161
+ return {
1162
+ ...tree,
1163
+ children: tree.children.map((child) => {
1164
+ if (child.type === "condition") return {
1165
+ ...child,
1166
+ data: {
1167
+ ...child.data,
1168
+ data: injectSchemaFields(child.data.data, schemaId, child.data.policyType)
1169
+ }
1170
+ };
1171
+ return injectSchemaFieldsIntoCompositeTree(child, schemaId);
1172
+ })
1173
+ };
1174
+ }
1175
+
1176
+ //#endregion
1177
+ //#region src/schema/schema-builder-policies/lib/gql/hooks/schema-builder/policies/use-create-policy-field.ts
1178
+ /**
1179
+ * Hook for creating fields for policies
1180
+ * Tier 4 wrapper: uses SDK + transform + custom cache invalidation
1181
+ */
1182
+ function useCreatePolicyField() {
1183
+ const queryClient = (0, _tanstack_react_query.useQueryClient)();
1184
+ const createFieldMutation = require_invalidate_database_entities.useCreateFieldMutation({ selection: { fields: {
1185
+ id: true,
1186
+ name: true,
1187
+ type: true
1188
+ } } });
1189
+ return (0, _tanstack_react_query.useMutation)({
1190
+ mutationFn: async (input) => {
1191
+ const createdField = (await createFieldMutation.mutateAsync({
1192
+ name: input.name,
1193
+ tableId: input.tableId,
1194
+ databaseId: input.databaseId,
1195
+ type: require_invalidate_database_entities.toFieldType(input.fieldType),
1196
+ isRequired: false
1197
+ })).createField?.field;
1198
+ if (!createdField?.id) throw new Error("Failed to create field");
1199
+ return {
1200
+ id: createdField.id,
1201
+ name: createdField.name ?? "",
1202
+ type: require_invalidate_database_entities.fieldTypeToTypeName(createdField.type)
1203
+ };
1204
+ },
1205
+ onSuccess: async (_createdField, variables) => {
1206
+ await queryClient.invalidateQueries({ queryKey: require_invalidate_database_entities.databasePoliciesQueryKeys.byDatabase(variables.databaseId) });
1207
+ }
1208
+ });
1209
+ }
1210
+
1211
+ //#endregion
1212
+ //#region src/schema/schema-builder-core/components/policies/policy-types.ts
1213
+ /**
1214
+ * Reverse mapping from SQL privileges to CRUD operations
1215
+ */
1216
+ const PRIVILEGE_TO_OPERATION = {
1217
+ INSERT: "create",
1218
+ SELECT: "read",
1219
+ UPDATE: "update",
1220
+ DELETE: "delete"
1221
+ };
1222
+ /**
1223
+ * All CRUD operations in display order
1224
+ */
1225
+ const CRUD_OPERATIONS = [
1226
+ "create",
1227
+ "read",
1228
+ "update",
1229
+ "delete"
1230
+ ];
1231
+ const OPERATION_STYLES = {
1232
+ create: {
1233
+ bgClass: "bg-emerald-500/10 ring-1 ring-emerald-500/30",
1234
+ textClass: "text-emerald-600 dark:text-emerald-400",
1235
+ iconName: "Plus"
1236
+ },
1237
+ read: {
1238
+ bgClass: "bg-sky-500/10 ring-1 ring-sky-500/30",
1239
+ textClass: "text-sky-600 dark:text-sky-400",
1240
+ iconName: "Search"
1241
+ },
1242
+ update: {
1243
+ bgClass: "bg-amber-500/10 ring-1 ring-amber-500/30",
1244
+ textClass: "text-amber-600 dark:text-amber-400",
1245
+ iconName: "Pencil"
1246
+ },
1247
+ delete: {
1248
+ bgClass: "bg-rose-500/10 ring-1 ring-rose-500/30",
1249
+ textClass: "text-rose-600 dark:text-rose-400",
1250
+ iconName: "Trash2"
1251
+ }
1252
+ };
1253
+
1254
+ //#endregion
1255
+ //#region src/schema/schema-builder-core/lib/policies/provision-helpers.ts
1256
+ /** Full-CRUD grant on all columns. */
1257
+ const ALL_CRUD_PRIVILEGES = [
1258
+ ["select", "*"],
1259
+ ["insert", "*"],
1260
+ ["update", "*"],
1261
+ ["delete", "*"]
1262
+ ];
1263
+ const CRUD_OP_TO_LOWER_PRIVILEGE = {
1264
+ create: "insert",
1265
+ read: "select",
1266
+ update: "update",
1267
+ delete: "delete"
1268
+ };
1269
+ /** Convert a CRUD op (`'read'`, `'create'`, …) to the lowercase privilege verb the backend expects. */
1270
+ function crudOpToPrivilege(op) {
1271
+ return CRUD_OP_TO_LOWER_PRIVILEGE[op];
1272
+ }
1273
+ /** Convert many CRUD ops to their lowercase privilege verbs. */
1274
+ function crudOpsToPrivileges(ops) {
1275
+ return ops.map(crudOpToPrivilege);
1276
+ }
1277
+ /**
1278
+ * Build a single-entry `grants[]` array: one role group with the given privileges.
1279
+ * Defaults to `['authenticated']` with full-CRUD on all columns.
1280
+ */
1281
+ function buildGrants(roles = ["authenticated"], privileges = ALL_CRUD_PRIVILEGES) {
1282
+ return [{
1283
+ roles,
1284
+ privileges
1285
+ }];
1286
+ }
1287
+ /**
1288
+ * Build a single `policies[]` entry. Only `$type` is required; other fields are omitted
1289
+ * when falsy/empty so the backend defaults kick in.
1290
+ */
1291
+ function buildPolicyEntry(type, opts = {}) {
1292
+ const entry = { $type: type };
1293
+ if (opts.data && Object.keys(opts.data).length > 0) entry.data = opts.data;
1294
+ if (opts.privileges && opts.privileges.length > 0) entry.privileges = opts.privileges;
1295
+ if (opts.policy_role) entry.policy_role = opts.policy_role;
1296
+ if (opts.permissive !== void 0) entry.permissive = opts.permissive;
1297
+ if (opts.policy_name) entry.policy_name = opts.policy_name;
1298
+ return entry;
1299
+ }
1300
+ /**
1301
+ * Group enabled CRUD operations by (roleName, isPermissive). Each distinct group
1302
+ * becomes one `policies[]` entry, since the backend models them as separate policies.
1303
+ */
1304
+ function groupOperationsByConfig(enabledOperations, operations) {
1305
+ const groupMap = /* @__PURE__ */ new Map();
1306
+ for (const op of enabledOperations) {
1307
+ const config = operations[op];
1308
+ const key = `${config.roleName}:${config.isPermissive}`;
1309
+ let group = groupMap.get(key);
1310
+ if (!group) {
1311
+ group = {
1312
+ roleName: config.roleName,
1313
+ isPermissive: config.isPermissive,
1314
+ privileges: []
1315
+ };
1316
+ groupMap.set(key, group);
1317
+ }
1318
+ group.privileges.push(...crudOpsToPrivileges([op]));
1319
+ }
1320
+ return [...groupMap.values()];
1321
+ }
1322
+
1323
+ //#endregion
1324
+ //#region src/schema/schema-builder-core/lib/policies/add-policies-to-table.ts
1325
+ /**
1326
+ * Non-React core for adding RLS policies to an existing table.
1327
+ *
1328
+ * Shared by:
1329
+ * - `useCreateTableWithPolicies` (existing-table standard branch in policy-hooks.ts)
1330
+ * - `executeAddPolicies` chat tool (exec-add-policies.ts)
1331
+ *
1332
+ * Scope: standard policy categories only (`has-module`, `no-fields`, `needs-table`).
1333
+ * `needs-fields` and `AuthzComposite` need column creation / multi-step orchestration
1334
+ * that lives in the React hook for now.
1335
+ */
1336
+ const SUPPORTED_CATEGORIES = /* @__PURE__ */ new Set([
1337
+ "has-module",
1338
+ "no-fields",
1339
+ "needs-table"
1340
+ ]);
1341
+ var UnsupportedPolicyCategoryError = class extends Error {
1342
+ policyType;
1343
+ category;
1344
+ constructor(policyType, category) {
1345
+ super(`Policy type "${policyType}" has category "${category}" which requires column creation or composite handling — use the policies UI instead.`);
1346
+ this.policyType = policyType;
1347
+ this.category = category;
1348
+ this.name = "UnsupportedPolicyCategoryError";
1349
+ }
1350
+ };
1351
+ /**
1352
+ * Install all policy entries in a single `secureTableProvision.create` call.
1353
+ * The backend `policies[]` and `nodes[]` arrays accept multiple items per call, so the
1354
+ * whole batch is atomic — either all policies land or none do.
1355
+ */
1356
+ async function addPoliciesToExistingTable(input) {
1357
+ for (const entry of input.policies) {
1358
+ const category = getPolicyCategory(entry.policyType);
1359
+ if (!SUPPORTED_CATEGORIES.has(category)) throw new UnsupportedPolicyCategoryError(entry.policyType, category);
1360
+ }
1361
+ const policiesArray = [];
1362
+ const nodesByType = /* @__PURE__ */ new Map();
1363
+ for (const entry of input.policies) {
1364
+ const groups = groupOperationsByConfig(entry.enabledOperations ?? CRUD_OPERATIONS, entry.operations);
1365
+ for (const group of groups) {
1366
+ const ops = group.privileges.join("_");
1367
+ const rand = Math.random().toString(36).slice(2, 8);
1368
+ policiesArray.push(buildPolicyEntry(entry.policyType, {
1369
+ privileges: group.privileges,
1370
+ policy_role: group.roleName,
1371
+ permissive: group.isPermissive,
1372
+ data: entry.sharedPolicyData,
1373
+ policy_name: `${ops}_${rand}`
1374
+ }));
1375
+ }
1376
+ if (entry.dataNodeType && !nodesByType.has(entry.dataNodeType)) {
1377
+ const nodeData = entry.nodeData ?? {};
1378
+ nodesByType.set(entry.dataNodeType, {
1379
+ $type: entry.dataNodeType,
1380
+ ...Object.keys(nodeData).length > 0 ? { data: nodeData } : {}
1381
+ });
1382
+ }
1383
+ }
1384
+ const provisionInput = {
1385
+ databaseId: input.databaseId,
1386
+ schemaId: input.schemaId,
1387
+ tableId: input.tableId,
1388
+ grants: buildGrants(),
1389
+ policies: policiesArray
1390
+ };
1391
+ if (nodesByType.size > 0) provisionInput.nodes = [...nodesByType.values()];
1392
+ await input.createSecureTableProvision(provisionInput);
1393
+ return { success: true };
1394
+ }
1395
+
1396
+ //#endregion
1397
+ //#region src/schema/schema-builder-policies/components/policies/policy-hooks.ts
1398
+ /**
1399
+ * Build policy types from UI config only (fallback when backend unavailable)
1400
+ */
1401
+ function buildPolicyTypesFromUIConfig() {
1402
+ return Object.entries(POLICY_TYPE_UI_CONFIG).filter(([, c]) => !c.disabled).map(([name, uiConfig]) => ({
1403
+ name,
1404
+ title: uiConfig.fallbackTitle,
1405
+ description: uiConfig.description,
1406
+ icon: uiConfig.icon,
1407
+ category: uiConfig.category,
1408
+ hasDataNode: uiConfig.hasDataNode,
1409
+ dataNodeType: uiConfig.dataNodeType,
1410
+ generatedFields: uiConfig.dataNodeType ? getGeneratedFields(uiConfig.dataNodeType) : [],
1411
+ fieldOverrides: uiConfig.fieldOverrides,
1412
+ advancedFields: uiConfig.advancedFields,
1413
+ diagramKey: name
1414
+ }));
1415
+ }
1416
+ /**
1417
+ * Hook to fetch policy types from the backend registry and merge with UI config.
1418
+ *
1419
+ * Falls back to UI config only if backend returns no data.
1420
+ * Display order follows POLICY_TYPE_UI_CONFIG insertion order.
1421
+ */
1422
+ function usePolicyTypes() {
1423
+ return {
1424
+ policyTypes: (0, react.useMemo)(() => {
1425
+ return buildPolicyTypesFromUIConfig();
1426
+ }, []),
1427
+ isLoading: false,
1428
+ error: null
1429
+ };
1430
+ }
1431
+ /**
1432
+ * Hook to get a single policy type by name
1433
+ */
1434
+ function usePolicyType(policyTypeName) {
1435
+ const { policyTypes, isLoading, error } = usePolicyTypes();
1436
+ return {
1437
+ policyType: (0, react.useMemo)(() => {
1438
+ if (!policyTypeName) return null;
1439
+ return policyTypes.find((pt) => pt.name === policyTypeName) ?? null;
1440
+ }, [policyTypes, policyTypeName]),
1441
+ isLoading,
1442
+ error
1443
+ };
1444
+ }
1445
+ /**
1446
+ * Resolve a FieldOverride to a FormFieldType.
1447
+ * component takes priority over type.
1448
+ */
1449
+ function resolveFormFieldType(override) {
1450
+ if (override.component) return override.component;
1451
+ switch (override.type) {
1452
+ case "boolean": return "boolean";
1453
+ case "integer": return "number";
1454
+ case "uuid": return "field-select";
1455
+ case "uuid[]": return "field-multi-select";
1456
+ default: return "text";
1457
+ }
1458
+ }
1459
+ /**
1460
+ * Build form fields from fieldOverrides config.
1461
+ */
1462
+ function buildFormFields(overrides) {
1463
+ if (!overrides) return [];
1464
+ const fields = [];
1465
+ for (const [key, override] of Object.entries(overrides)) {
1466
+ if (override.hidden) continue;
1467
+ if (!override.type && !override.component) continue;
1468
+ fields.push({
1469
+ key,
1470
+ type: resolveFormFieldType(override),
1471
+ label: override.label ?? formatKeyAsLabel(key),
1472
+ description: override.description,
1473
+ placeholder: override.placeholder,
1474
+ required: override.required ?? false,
1475
+ defaultValue: override.defaultValue,
1476
+ dependsOn: override.dependsOn,
1477
+ options: override.options,
1478
+ pgType: override.pgType
1479
+ });
1480
+ }
1481
+ return fields;
1482
+ }
1483
+ /**
1484
+ * Format a snake_case key as a human-readable label
1485
+ */
1486
+ function formatKeyAsLabel(key) {
1487
+ return key.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1488
+ }
1489
+ /**
1490
+ * Hook to convert a policy type's field overrides to form fields
1491
+ *
1492
+ * Returns:
1493
+ * - mainFields: Fields shown in the main form area
1494
+ * - advancedFields: Fields shown in the collapsible advanced section
1495
+ */
1496
+ function useFormSchema(policyType) {
1497
+ return (0, react.useMemo)(() => {
1498
+ if (!policyType) return {
1499
+ mainFields: [],
1500
+ advancedFields: [],
1501
+ allFields: []
1502
+ };
1503
+ const allFields = buildFormFields(policyType.fieldOverrides);
1504
+ const advancedKeys = new Set(policyType.advancedFields ?? []);
1505
+ return {
1506
+ mainFields: allFields.filter((f) => !advancedKeys.has(f.key)),
1507
+ advancedFields: allFields.filter((f) => advancedKeys.has(f.key)),
1508
+ allFields
1509
+ };
1510
+ }, [policyType]);
1511
+ }
1512
+ /**
1513
+ * Get default values for all fields in a policy type
1514
+ */
1515
+ function getDefaultFormValues(policyType) {
1516
+ if (!policyType) return {};
1517
+ const fields = buildFormFields(policyType.fieldOverrides);
1518
+ const defaults = {};
1519
+ for (const field of fields) if (field.defaultValue !== void 0) defaults[field.key] = field.defaultValue;
1520
+ if (policyType.fieldOverrides) {
1521
+ for (const [key, override] of Object.entries(policyType.fieldOverrides)) if (override.hidden && override.defaultValue !== void 0 && defaults[key] === void 0) defaults[key] = override.defaultValue;
1522
+ }
1523
+ return defaults;
1524
+ }
1525
+ /**
1526
+ * Check if a policy type has fields that need user configuration.
1527
+ * Returns true if any required or non-defaulted field is empty.
1528
+ */
1529
+ function hasRequiredFieldsMissing(policyType, data) {
1530
+ if (!policyType) return false;
1531
+ const fields = buildFormFields(policyType.fieldOverrides);
1532
+ for (const field of fields) {
1533
+ if (field.type === "boolean") continue;
1534
+ if (field.type === "permission-select") continue;
1535
+ const value = data[field.key];
1536
+ if (!(value === null || value === void 0 || typeof value === "string" && value.trim() === "" || Array.isArray(value) && value.length === 0)) continue;
1537
+ if (field.required) return true;
1538
+ if (field.defaultValue === void 0 || field.defaultValue === null || field.defaultValue === "") return true;
1539
+ }
1540
+ return false;
1541
+ }
1542
+ /**
1543
+ * Hook to create a table with CRUD policies via `secure_table_provision`.
1544
+ *
1545
+ * One provision call now carries all grants + all policies for a table atomically,
1546
+ * so operations grouped by (role, permissive) become separate `policies[]` entries
1547
+ * in a single call rather than a sequence of calls.
1548
+ *
1549
+ * - Standard (has-module / no-fields / needs-table): single call.
1550
+ * - Needs-fields: table-creation call, per-field createField calls, then single policy call.
1551
+ * - Composite: table-creation call bundles all sub-policy data nodes, per-leaf createField calls
1552
+ * for needs-fields leaves, then single composite-policy call.
1553
+ */
1554
+ function useCreateTableWithPolicies() {
1555
+ const queryClient = (0, _tanstack_react_query.useQueryClient)();
1556
+ const { selectTable } = require_invalidate_database_entities.useSchemaBuilderSelectors();
1557
+ const createProvision = require_invalidate_database_entities.useCreateSecureTableProvisionMutation({ selection: { fields: {
1558
+ id: true,
1559
+ tableId: true,
1560
+ tableName: true
1561
+ } } });
1562
+ const createField = useCreatePolicyField();
1563
+ const mutation = (0, _tanstack_react_query.useMutation)({
1564
+ mutationFn: async (input) => {
1565
+ const { databaseId, schemaId, tableId: existingTableId, tableName, policyType, dataNodeType, nodeData = {}, sharedPolicyData, operations, enabledOperations = CRUD_OPERATIONS, fieldNameOverrides = {}, compositeTree } = input;
1566
+ const category = getPolicyCategory(policyType);
1567
+ let tableId = existingTableId;
1568
+ if (policyType === "AuthzComposite" && compositeTree) {
1569
+ const leaves = compositeTree.children.filter((c) => c.type === "condition");
1570
+ const seenModules = /* @__PURE__ */ new Set();
1571
+ const seenFields = /* @__PURE__ */ new Set();
1572
+ const firstModuleLeaf = leaves.find((leaf) => {
1573
+ const subCategory = getPolicyCategory(leaf.data.policyType);
1574
+ const subConfig = POLICY_TYPE_UI_CONFIG[leaf.data.policyType];
1575
+ return subCategory === "has-module" && subConfig?.dataNodeType;
1576
+ });
1577
+ const step1Input = {
1578
+ databaseId,
1579
+ schemaId,
1580
+ grants: buildGrants()
1581
+ };
1582
+ if (tableId) step1Input.tableId = tableId;
1583
+ else step1Input.tableName = tableName;
1584
+ if (firstModuleLeaf) {
1585
+ const subConfig = POLICY_TYPE_UI_CONFIG[firstModuleLeaf.data.policyType];
1586
+ if (subConfig?.dataNodeType) {
1587
+ seenModules.add(subConfig.dataNodeType);
1588
+ const modData = buildNodeData(firstModuleLeaf.data.data, { dataNodeType: subConfig.dataNodeType });
1589
+ const moduleNode = {
1590
+ $type: subConfig.dataNodeType,
1591
+ ...Object.keys(modData).length > 0 ? { data: modData } : {}
1592
+ };
1593
+ step1Input.nodes = !tableId ? [{ $type: "DataId" }, moduleNode] : [moduleNode];
1594
+ }
1595
+ }
1596
+ const r = await createProvision.mutateAsync(step1Input);
1597
+ if (!tableId) {
1598
+ tableId = r.createSecureTableProvision?.secureTableProvision?.tableId ?? void 0;
1599
+ if (!tableId) throw new Error("Provision failed: no tableId returned");
1600
+ }
1601
+ for (const leaf of leaves) {
1602
+ const subType = leaf.data.policyType;
1603
+ const subData = leaf.data.data;
1604
+ const subCategory = getPolicyCategory(subType);
1605
+ const subConfig = POLICY_TYPE_UI_CONFIG[subType];
1606
+ if (subCategory === "has-module" && subConfig?.dataNodeType && !seenModules.has(subConfig.dataNodeType)) {
1607
+ seenModules.add(subConfig.dataNodeType);
1608
+ const modData = buildNodeData(subData, { dataNodeType: subConfig.dataNodeType });
1609
+ await createProvision.mutateAsync({
1610
+ databaseId,
1611
+ schemaId,
1612
+ tableId,
1613
+ nodes: [{
1614
+ $type: subConfig.dataNodeType,
1615
+ ...Object.keys(modData).length > 0 ? { data: modData } : {}
1616
+ }]
1617
+ });
1618
+ }
1619
+ if (subCategory === "needs-fields") for (const fieldConfig of getFieldsRequiringColumns(subType)) {
1620
+ const resolved = subData[fieldConfig.key] || fieldConfig.defaultName;
1621
+ const names = Array.isArray(resolved) ? resolved : [resolved];
1622
+ for (const name of names) if (!seenFields.has(name)) {
1623
+ seenFields.add(name);
1624
+ await createField.mutateAsync({
1625
+ name,
1626
+ tableId,
1627
+ databaseId,
1628
+ fieldType: fieldConfig.pgType
1629
+ });
1630
+ }
1631
+ }
1632
+ }
1633
+ const config = operations[enabledOperations[0]];
1634
+ await createProvision.mutateAsync({
1635
+ databaseId,
1636
+ schemaId,
1637
+ tableId,
1638
+ policies: [buildPolicyEntry("AuthzComposite", {
1639
+ privileges: crudOpsToPrivileges(enabledOperations),
1640
+ policy_role: config.roleName,
1641
+ permissive: config.isPermissive,
1642
+ data: sharedPolicyData
1643
+ })]
1644
+ });
1645
+ return {
1646
+ tableId,
1647
+ tableName,
1648
+ policyIds: []
1649
+ };
1650
+ }
1651
+ if (category === "needs-fields") {
1652
+ if (!tableId) {
1653
+ tableId = (await createProvision.mutateAsync({
1654
+ databaseId,
1655
+ schemaId,
1656
+ tableName,
1657
+ grants: buildGrants()
1658
+ })).createSecureTableProvision?.secureTableProvision?.tableId ?? void 0;
1659
+ if (!tableId) throw new Error("Provision failed: no tableId returned");
1660
+ }
1661
+ const createdFieldNames = {};
1662
+ const fieldsToCreate = getFieldsRequiringColumns(policyType);
1663
+ for (const fieldConfig of fieldsToCreate) {
1664
+ const resolved = fieldNameOverrides?.[fieldConfig.key] || fieldConfig.defaultName;
1665
+ const fieldNames = Array.isArray(resolved) ? resolved : [resolved];
1666
+ for (const name of fieldNames) await createField.mutateAsync({
1667
+ name,
1668
+ tableId,
1669
+ databaseId,
1670
+ fieldType: fieldConfig.pgType
1671
+ });
1672
+ createdFieldNames[fieldConfig.key] = Array.isArray(fieldConfig.defaultName) ? fieldNames : fieldNames[0];
1673
+ }
1674
+ const policyData = {
1675
+ ...sharedPolicyData,
1676
+ ...createdFieldNames
1677
+ };
1678
+ const groups = groupOperationsByConfig(enabledOperations, operations);
1679
+ await createProvision.mutateAsync({
1680
+ databaseId,
1681
+ schemaId,
1682
+ tableId,
1683
+ policies: groups.map((group) => buildPolicyEntry(policyType, {
1684
+ privileges: group.privileges,
1685
+ policy_role: group.roleName,
1686
+ permissive: group.isPermissive,
1687
+ data: policyData,
1688
+ policy_name: group.privileges.join("_")
1689
+ }))
1690
+ });
1691
+ return {
1692
+ tableId,
1693
+ tableName,
1694
+ policyIds: []
1695
+ };
1696
+ }
1697
+ if (tableId) {
1698
+ await addPoliciesToExistingTable({
1699
+ createSecureTableProvision: (input) => createProvision.mutateAsync(input),
1700
+ databaseId,
1701
+ schemaId,
1702
+ tableId,
1703
+ policies: [{
1704
+ policyType,
1705
+ dataNodeType,
1706
+ nodeData,
1707
+ sharedPolicyData,
1708
+ operations,
1709
+ enabledOperations
1710
+ }]
1711
+ });
1712
+ return {
1713
+ tableId,
1714
+ tableName,
1715
+ policyIds: []
1716
+ };
1717
+ }
1718
+ const policiesArray = groupOperationsByConfig(enabledOperations, operations).map((group) => buildPolicyEntry(policyType, {
1719
+ privileges: group.privileges,
1720
+ policy_role: group.roleName,
1721
+ permissive: group.isPermissive,
1722
+ data: sharedPolicyData,
1723
+ policy_name: group.privileges.join("_")
1724
+ }));
1725
+ const provisionInput = {
1726
+ databaseId,
1727
+ schemaId,
1728
+ tableName,
1729
+ grants: buildGrants(),
1730
+ policies: policiesArray
1731
+ };
1732
+ if (dataNodeType) provisionInput.nodes = [{ $type: "DataId" }, {
1733
+ $type: dataNodeType,
1734
+ ...Object.keys(nodeData).length > 0 ? { data: nodeData } : {}
1735
+ }];
1736
+ const newTableId = (await createProvision.mutateAsync(provisionInput)).createSecureTableProvision?.secureTableProvision?.tableId ?? void 0;
1737
+ if (!newTableId) throw new Error("Provision failed: no tableId returned");
1738
+ return {
1739
+ tableId: newTableId,
1740
+ tableName,
1741
+ policyIds: []
1742
+ };
1743
+ },
1744
+ onSuccess: async (result, variables) => {
1745
+ await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, variables.databaseId);
1746
+ if (!variables.tableId) selectTable(result.tableId, result.tableName);
1747
+ },
1748
+ onError: (error) => {
1749
+ console.error("Failed to create table with policies:", error);
1750
+ }
1751
+ });
1752
+ return {
1753
+ createTableWithPolicies: mutation.mutateAsync,
1754
+ isCreating: mutation.isPending,
1755
+ error: mutation.error
1756
+ };
1757
+ }
1758
+
1759
+ //#endregion
1760
+ //#region src/schema/schema-builder-policies/components/policies/policy-config-form/auto-generated-fields-info.tsx
1761
+ /**
1762
+ * Info box showing fields that will be automatically created by a table module.
1763
+ * Supports inline editing of field names when mappings are provided.
1764
+ */
1765
+ function AutoGeneratedFieldsInfo({ fields, value, onChange, fieldMappings, disabled }) {
1766
+ const [editingField, setEditingField] = (0, react.useState)(null);
1767
+ const [editValue, setEditValue] = (0, react.useState)("");
1768
+ if (!fields.length) return null;
1769
+ const handleStartEdit = (fieldName, currentValue) => {
1770
+ setEditingField(fieldName);
1771
+ setEditValue(currentValue);
1772
+ };
1773
+ const handleSave = (fieldName) => {
1774
+ const mapping = fieldMappings?.[fieldName];
1775
+ if (mapping && onChange && editValue.trim()) onChange(mapping.policyKey, editValue.trim());
1776
+ setEditingField(null);
1777
+ setEditValue("");
1778
+ };
1779
+ const handleCancel = () => {
1780
+ setEditingField(null);
1781
+ setEditValue("");
1782
+ };
1783
+ const handleKeyDown = (e, fieldName) => {
1784
+ if (e.key === "Enter") handleSave(fieldName);
1785
+ else if (e.key === "Escape") handleCancel();
1786
+ };
1787
+ const getDisplayName = (field) => {
1788
+ const mapping = fieldMappings?.[field.name];
1789
+ if (mapping && value) {
1790
+ const customValue = value[mapping.policyKey];
1791
+ if (typeof customValue === "string" && customValue !== mapping.defaultValue) return customValue;
1792
+ }
1793
+ return field.name;
1794
+ };
1795
+ const hasFieldMapping = (fieldName) => {
1796
+ return !!fieldMappings?.[fieldName] && !!onChange;
1797
+ };
1798
+ const handleReset = (fieldName) => {
1799
+ const mapping = fieldMappings?.[fieldName];
1800
+ if (mapping && onChange) {
1801
+ onChange(mapping.policyKey, mapping.defaultValue);
1802
+ setEditValue(mapping.defaultValue);
1803
+ }
1804
+ };
1805
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1806
+ className: "border-border/60 overflow-hidden rounded-lg border",
1807
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1808
+ className: "bg-muted/50 flex items-center gap-2 border-b px-4 py-2.5",
1809
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Table2, { className: "text-muted-foreground h-4 w-4" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1810
+ className: "text-muted-foreground text-xs font-medium",
1811
+ children: "The following fields will be auto-generated:"
1812
+ })]
1813
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1814
+ className: "divide-border divide-y",
1815
+ children: fields.map((field) => {
1816
+ const displayName = getDisplayName(field);
1817
+ const canEdit = hasFieldMapping(field.name);
1818
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1819
+ className: "space-y-1 px-4 py-3",
1820
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1821
+ className: "flex items-center gap-2",
1822
+ children: [editingField === field.name ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
1823
+ type: "text",
1824
+ value: editValue,
1825
+ onChange: (e) => setEditValue(e.target.value),
1826
+ onKeyDown: (e) => handleKeyDown(e, field.name),
1827
+ className: "w-40 text-xs",
1828
+ size: "sm",
1829
+ autoFocus: true
1830
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1831
+ className: "flex items-center gap-0.5",
1832
+ children: [
1833
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipTrigger, {
1834
+ asChild: true,
1835
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1836
+ type: "button",
1837
+ onClick: () => handleSave(field.name),
1838
+ "aria-label": `Save ${displayName} field name`,
1839
+ className: "hover:bg-muted text-muted-foreground hover:text-foreground grid size-10 place-items-center rounded-lg\n transition-[background-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.96]",
1840
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CheckIcon, { className: "h-3.5 w-3.5" })
1841
+ })
1842
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipContent, { children: "Save" })] }),
1843
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipTrigger, {
1844
+ asChild: true,
1845
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1846
+ type: "button",
1847
+ onClick: handleCancel,
1848
+ "aria-label": "Cancel field name edit",
1849
+ className: "hover:bg-muted text-muted-foreground hover:text-foreground grid size-10 place-items-center rounded-lg\n transition-[background-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.96]",
1850
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.XIcon, { className: "h-3.5 w-3.5" })
1851
+ })
1852
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipContent, { children: "Cancel" })] }),
1853
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipTrigger, {
1854
+ asChild: true,
1855
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1856
+ type: "button",
1857
+ onClick: () => handleReset(field.name),
1858
+ "aria-label": `Reset ${displayName} field name`,
1859
+ className: "hover:bg-muted text-muted-foreground hover:text-foreground grid size-10 place-items-center rounded-lg\n transition-[background-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.96]",
1860
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.RotateCcwIcon, { className: "h-3.5 w-3.5" })
1861
+ })
1862
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipContent, { children: "Reset to default" })] })
1863
+ ]
1864
+ })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1865
+ className: "text-sm font-medium",
1866
+ children: displayName
1867
+ }), canEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipTrigger, {
1868
+ asChild: true,
1869
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1870
+ type: "button",
1871
+ onClick: () => handleStartEdit(field.name, displayName),
1872
+ disabled,
1873
+ "aria-label": `Edit ${displayName} field name`,
1874
+ className: "hover:bg-muted text-muted-foreground hover:text-foreground grid size-10 place-items-center rounded-lg opacity-60\n transition-[background-color,color,opacity,scale] duration-150 ease-out hover:opacity-100 motion-safe:active:scale-[0.96]\n disabled:cursor-not-allowed disabled:opacity-30\n disabled:hover:bg-transparent",
1875
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.PencilIcon, { className: "h-3 w-3" })
1876
+ })
1877
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipContent, { children: "Edit field name" })] })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1878
+ className: "bg-muted text-muted-foreground rounded px-1.5 py-0.5 font-mono text-[10px] font-medium",
1879
+ children: field.type
1880
+ })]
1881
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1882
+ className: "text-muted-foreground text-xs",
1883
+ children: field.description
1884
+ })]
1885
+ }, field.name);
1886
+ })
1887
+ })]
1888
+ });
1889
+ }
1890
+
1891
+ //#endregion
1892
+ //#region src/schema/schema-builder-policies/lib/gql/hooks/schema-builder/policies/use-permissions.ts
1893
+ /**
1894
+ * Hook for fetching app and membership permissions
1895
+ * Tier 4 wrapper: Uses SDK hooks + cache invalidation
1896
+ */
1897
+ function usePermissions(options = {}) {
1898
+ const isEnabled = options.enabled !== false;
1899
+ const { scope } = require_invalidate_database_entities.useSchemaBuilderRuntime();
1900
+ const { fetchAppPermissionsQuery, fetchOrgPermissionsQuery } = useAdminSdkClient();
1901
+ return (0, _tanstack_react_query.useQuery)({
1902
+ queryKey: require_query.schemaBuilderQueryKey(scope, "policies", "permissions"),
1903
+ queryFn: async () => {
1904
+ const [appResult, orgResult] = await Promise.all([fetchAppPermissionsQuery({ selection: {
1905
+ fields: {
1906
+ id: true,
1907
+ name: true,
1908
+ bitnum: true,
1909
+ bitstr: true,
1910
+ description: true
1911
+ },
1912
+ orderBy: ["NAME_ASC"]
1913
+ } }), fetchOrgPermissionsQuery({ selection: {
1914
+ fields: {
1915
+ id: true,
1916
+ name: true,
1917
+ bitnum: true,
1918
+ bitstr: true,
1919
+ description: true
1920
+ },
1921
+ orderBy: ["NAME_ASC"]
1922
+ } })]);
1923
+ return {
1924
+ appPermissions: (appResult.appPermissions?.nodes ?? []).map((node) => ({
1925
+ id: node.id ?? "",
1926
+ name: node.name ?? "",
1927
+ bitnum: node.bitnum ?? null,
1928
+ bitstr: node.bitstr ?? null,
1929
+ description: node.description ?? null
1930
+ })),
1931
+ membershipPermissions: (orgResult.orgPermissions?.nodes ?? []).map((node) => ({
1932
+ id: node.id ?? "",
1933
+ name: node.name ?? "",
1934
+ bitnum: node.bitnum ?? null,
1935
+ bitstr: node.bitstr ?? null,
1936
+ description: node.description ?? null
1937
+ }))
1938
+ };
1939
+ },
1940
+ enabled: isEnabled,
1941
+ staleTime: 300 * 1e3,
1942
+ refetchOnMount: isEnabled,
1943
+ refetchOnWindowFocus: false,
1944
+ refetchOnReconnect: false
1945
+ });
1946
+ }
1947
+
1948
+ //#endregion
1949
+ //#region src/schema/schema-builder-policies/components/policies/multi-value-field-editor.tsx
1950
+ function normalizeValue(value) {
1951
+ if (Array.isArray(value)) return value.map((v) => String(v));
1952
+ if (typeof value === "string") return value.trim() ? [value] : [];
1953
+ return [];
1954
+ }
1955
+ function MultiValueFieldEditor({ value, onChange, disabled, emptyText = "No fields yet", addButtonText = "Add field", typeBadge }) {
1956
+ const normalizedValue = (0, react.useMemo)(() => normalizeValue(value), [value]);
1957
+ const idsRef = (0, react.useRef)([]);
1958
+ const inputRefs = (0, react.useRef)([]);
1959
+ const pendingFocusIndex = (0, react.useRef)(null);
1960
+ (0, react.useEffect)(() => {
1961
+ const nextIds = idsRef.current.slice(0, normalizedValue.length);
1962
+ while (nextIds.length < normalizedValue.length) nextIds.push(`mv-${crypto.randomUUID()}`);
1963
+ idsRef.current = nextIds;
1964
+ }, [normalizedValue.length]);
1965
+ (0, react.useEffect)(() => {
1966
+ if (pendingFocusIndex.current === null) return;
1967
+ const idx = pendingFocusIndex.current;
1968
+ const el = inputRefs.current[idx] ?? null;
1969
+ if (el) {
1970
+ el.focus();
1971
+ el.select();
1972
+ }
1973
+ pendingFocusIndex.current = null;
1974
+ }, [normalizedValue.length]);
1975
+ const addOption = (0, react.useCallback)(() => {
1976
+ pendingFocusIndex.current = normalizedValue.length;
1977
+ idsRef.current = [...idsRef.current, `mv-${crypto.randomUUID()}`];
1978
+ onChange([...normalizedValue, ""]);
1979
+ }, [normalizedValue, onChange]);
1980
+ const updateOption = (0, react.useCallback)((index, nextValue) => {
1981
+ const next = normalizedValue.slice();
1982
+ next[index] = nextValue;
1983
+ onChange(next);
1984
+ }, [normalizedValue, onChange]);
1985
+ const removeOption = (0, react.useCallback)((index) => {
1986
+ idsRef.current = idsRef.current.filter((_, i) => i !== index);
1987
+ onChange(normalizedValue.filter((_, i) => i !== index));
1988
+ }, [normalizedValue, onChange]);
1989
+ const insertAfter = (0, react.useCallback)((index) => {
1990
+ const next = normalizedValue.slice();
1991
+ next.splice(index + 1, 0, "");
1992
+ const nextIds = idsRef.current.slice();
1993
+ nextIds.splice(index + 1, 0, `mv-${crypto.randomUUID()}`);
1994
+ idsRef.current = nextIds;
1995
+ pendingFocusIndex.current = index + 1;
1996
+ onChange(next);
1997
+ }, [normalizedValue, onChange]);
1998
+ const rowIds = idsRef.current;
1999
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2000
+ className: "space-y-2",
2001
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2002
+ className: "space-y-2",
2003
+ children: normalizedValue.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2004
+ className: "text-muted-foreground rounded-md border border-dashed p-3 text-xs",
2005
+ children: emptyText
2006
+ }) : normalizedValue.map((opt, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2007
+ className: "bg-background flex items-center gap-2 rounded-md border px-2 py-1.5",
2008
+ children: [
2009
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
2010
+ ref: (el) => {
2011
+ inputRefs.current[index] = el;
2012
+ },
2013
+ value: opt,
2014
+ onChange: (e) => updateOption(index, e.target.value),
2015
+ onKeyDown: (e) => {
2016
+ if (e.key === "Enter") {
2017
+ e.preventDefault();
2018
+ insertAfter(index);
2019
+ }
2020
+ },
2021
+ disabled,
2022
+ className: "h-8 border-none shadow-none focus-visible:ring-0"
2023
+ }),
2024
+ typeBadge && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2025
+ className: "text-muted-foreground shrink-0 text-xs",
2026
+ children: typeBadge
2027
+ }),
2028
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
2029
+ type: "button",
2030
+ variant: "ghost",
2031
+ size: "sm",
2032
+ onClick: () => removeOption(index),
2033
+ disabled,
2034
+ className: "text-muted-foreground/80 hover:text-destructive h-8 w-8 p-0",
2035
+ "aria-label": "Remove field",
2036
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "h-4 w-4" })
2037
+ })
2038
+ ]
2039
+ }, rowIds[index] ?? `mv-${index}`))
2040
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2041
+ className: "pt-1",
2042
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
2043
+ type: "button",
2044
+ variant: "outline",
2045
+ size: "sm",
2046
+ onClick: addOption,
2047
+ disabled,
2048
+ className: "h-7 gap-1.5 px-2",
2049
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, { className: "h-3.5 w-3.5" }), addButtonText]
2050
+ })
2051
+ })]
2052
+ });
2053
+ }
2054
+
2055
+ //#endregion
2056
+ //#region src/schema/schema-builder-policies/components/policies/policy-config-form/dynamic-form-field.tsx
2057
+ const MEMBERSHIP_TYPE_OPTIONS = [
2058
+ {
2059
+ value: "1",
2060
+ label: "App Member",
2061
+ description: "Check membership to the application"
2062
+ },
2063
+ {
2064
+ value: "2",
2065
+ label: "Organization Member",
2066
+ description: "Check membership to an organization"
2067
+ },
2068
+ {
2069
+ value: "3",
2070
+ label: "Group Member",
2071
+ description: "Check membership to a group"
2072
+ }
2073
+ ];
2074
+ const MEMBERSHIP_LABEL_MAP = {
2075
+ "1": "App Member",
2076
+ "2": "Organization Member",
2077
+ "3": "Group Member"
2078
+ };
2079
+ const normalizeFieldType = (type) => (type ?? "").toLowerCase();
2080
+ const isUuidType = (type) => {
2081
+ const t = normalizeFieldType(type);
2082
+ return (t === "uuid" || t === "uuid!") && !t.includes("[");
2083
+ };
2084
+ const isUuidArrayType = (type) => {
2085
+ const t = normalizeFieldType(type);
2086
+ return t === "uuid[]" || t === "uuid[]!" || t.startsWith("uuid[");
2087
+ };
2088
+ function getFieldsFromTable(tables, tableName) {
2089
+ return tables.find((t) => t.name === tableName)?.fields?.slice().sort((a, b) => (a.fieldOrder ?? 0) - (b.fieldOrder ?? 0)).map((f) => ({
2090
+ name: f.name,
2091
+ type: f.type ?? null
2092
+ })) ?? [];
2093
+ }
2094
+ /**
2095
+ * Table select using searchable Combobox
2096
+ */
2097
+ function TableSelectField({ field, value, onChange, disabled, tables }) {
2098
+ const tableOptions = (0, react.useMemo)(() => tables.filter((t) => t.category === "APP").map((t) => ({
2099
+ label: t.name,
2100
+ value: t.id
2101
+ })), [tables]);
2102
+ const selectedTable = tables.find((t) => t.name === value);
2103
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_combobox.Combobox, {
2104
+ items: tableOptions,
2105
+ value: tableOptions.find((o) => o.value === selectedTable?.id) ?? null,
2106
+ onValueChange: (next) => {
2107
+ if (next) {
2108
+ const table = tables.find((t) => t.id === next.value);
2109
+ if (table) onChange(table.name);
2110
+ }
2111
+ },
2112
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxInput, {
2113
+ placeholder: field.placeholder ?? "Search tables...",
2114
+ showClear: false
2115
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_combobox.ComboboxPopup, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxEmpty, { children: "No tables found" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxList, {
2116
+ className: "scrollbar-neutral-thin max-h-[180px] overflow-y-auto",
2117
+ children: (table) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxItem, {
2118
+ value: table,
2119
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2120
+ className: "truncate",
2121
+ children: table.label
2122
+ })
2123
+ }, table.value)
2124
+ })] })]
2125
+ });
2126
+ }
2127
+ /**
2128
+ * Determine if a field key expects UUID array type
2129
+ */
2130
+ function expectsUuidArray(key) {
2131
+ return key === "owned_table_key";
2132
+ }
2133
+ /**
2134
+ * Determine if a field key expects UUID type
2135
+ */
2136
+ function expectsUuid(key) {
2137
+ return key.includes("_key") || key.includes("_ref_key");
2138
+ }
2139
+ /**
2140
+ * Field select dropdown, populated from fields of a dependent table
2141
+ */
2142
+ function DependentFieldSelectField({ field, value, onChange, disabled, tables, formData }) {
2143
+ const dependentTableName = field.dependsOn ? formData[field.dependsOn] : "";
2144
+ const isUuidArrayField = expectsUuidArray(field.key);
2145
+ const isUuidField = expectsUuid(field.key) && !isUuidArrayField;
2146
+ const hasTypeFilter = isUuidField || isUuidArrayField;
2147
+ const { fieldOptions, allFieldCount } = (0, react.useMemo)(() => {
2148
+ if (!dependentTableName) return {
2149
+ fieldOptions: [],
2150
+ allFieldCount: 0
2151
+ };
2152
+ const allFields = getFieldsFromTable(tables, dependentTableName);
2153
+ let filtered = allFields;
2154
+ if (isUuidArrayField) filtered = allFields.filter((f) => isUuidArrayType(f.type));
2155
+ else if (isUuidField) filtered = allFields.filter((f) => isUuidType(f.type));
2156
+ return {
2157
+ fieldOptions: filtered,
2158
+ allFieldCount: allFields.length
2159
+ };
2160
+ }, [
2161
+ dependentTableName,
2162
+ tables,
2163
+ field.key,
2164
+ isUuidArrayField,
2165
+ isUuidField
2166
+ ]);
2167
+ const isDisabled = disabled || !dependentTableName;
2168
+ const placeholder = !dependentTableName ? "Select table first" : field.placeholder ?? "Select field";
2169
+ const typeLabel = isUuidArrayField ? "UUID array" : "UUID";
2170
+ const hasHiddenFields = hasTypeFilter && allFieldCount > fieldOptions.length;
2171
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
2172
+ value: value || "",
2173
+ onValueChange: onChange,
2174
+ disabled: isDisabled,
2175
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectValue, { placeholder }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, {
2176
+ className: "max-h-48",
2177
+ children: !dependentTableName ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2178
+ className: "text-muted-foreground py-4 text-center text-xs",
2179
+ children: "Select a table first"
2180
+ }) : fieldOptions.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2181
+ className: "text-muted-foreground py-4 text-center text-xs",
2182
+ children: hasTypeFilter ? `No ${typeLabel} fields on "${dependentTableName}"` : "No fields available"
2183
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [fieldOptions.map((f) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectFieldItem, {
2184
+ value: f.name,
2185
+ name: f.name,
2186
+ type: f.type ?? void 0
2187
+ }, f.name)), hasHiddenFields && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2188
+ className: "text-muted-foreground flex items-center gap-1.5 border-t px-2 py-1.5 text-xs",
2189
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Info, { className: "h-3 w-3 shrink-0" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
2190
+ "Non-",
2191
+ typeLabel,
2192
+ " fields are hidden"
2193
+ ] })]
2194
+ })] })
2195
+ })]
2196
+ });
2197
+ }
2198
+ /**
2199
+ * Permission select dropdown, populated from usePermissions
2200
+ */
2201
+ function PermissionSelectField({ field, value, onChange, disabled, formData }) {
2202
+ const { data: permissions, isLoading } = usePermissions();
2203
+ const isAppLevel = formData?.membership_type === MEMBERSHIP_TYPES.APP;
2204
+ const permissionsList = isAppLevel ? permissions?.appPermissions || [] : permissions?.membershipPermissions || [];
2205
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
2206
+ value: value || "",
2207
+ onValueChange: (v) => onChange(v || void 0),
2208
+ disabled,
2209
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectValue, { placeholder: isLoading ? "Loading..." : `Select ${isAppLevel ? "app" : "membership"} permission` }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, {
2210
+ className: "max-h-48",
2211
+ children: permissionsList.filter((p) => p.name).map((permission) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectRichItem, {
2212
+ value: permission.name,
2213
+ label: permission.name ?? void 0,
2214
+ description: permission.description
2215
+ }, permission.id))
2216
+ })]
2217
+ });
2218
+ }
2219
+ /**
2220
+ * Renders a form field based on its type.
2221
+ * When tables data is available, uses proper dropdowns for table/field selection.
2222
+ */
2223
+ function DynamicFormField({ field, value, onChange, disabled, tables, formData }) {
2224
+ const hasTables = tables && tables.length > 0;
2225
+ const renderField = () => {
2226
+ switch (field.type) {
2227
+ case "table-select":
2228
+ if (hasTables) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableSelectField, {
2229
+ field,
2230
+ value: value ?? "",
2231
+ onChange,
2232
+ disabled,
2233
+ tables
2234
+ });
2235
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
2236
+ type: "text",
2237
+ value: value ?? "",
2238
+ onChange: (e) => onChange(e.target.value),
2239
+ placeholder: field.placeholder,
2240
+ disabled
2241
+ });
2242
+ case "field-select":
2243
+ if (field.dependsOn && hasTables && formData) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DependentFieldSelectField, {
2244
+ field,
2245
+ value: value ?? "",
2246
+ onChange,
2247
+ disabled,
2248
+ tables,
2249
+ formData
2250
+ });
2251
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
2252
+ type: "text",
2253
+ value: value ?? "",
2254
+ onChange: (e) => onChange(e.target.value),
2255
+ placeholder: field.placeholder,
2256
+ disabled
2257
+ });
2258
+ case "field-multi-select": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MultiValueFieldEditor, {
2259
+ value,
2260
+ onChange,
2261
+ disabled,
2262
+ emptyText: "No fields added yet",
2263
+ addButtonText: "Add field",
2264
+ typeBadge: field.pgType
2265
+ });
2266
+ case "membership-type-select": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
2267
+ value: value !== null && value !== void 0 ? String(value) : "",
2268
+ onValueChange: (v) => onChange(parseInt(v, 10)),
2269
+ disabled,
2270
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectValue, {
2271
+ placeholder: "Select scope",
2272
+ children: value !== null && value !== void 0 ? MEMBERSHIP_LABEL_MAP[String(value)] ?? String(value) : void 0
2273
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, { children: MEMBERSHIP_TYPE_OPTIONS.map((opt) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectRichItem, {
2274
+ value: opt.value,
2275
+ label: opt.label,
2276
+ description: opt.description
2277
+ }, opt.value)) })]
2278
+ });
2279
+ case "permission-select": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PermissionSelectField, {
2280
+ field,
2281
+ value: value ?? void 0,
2282
+ onChange,
2283
+ disabled,
2284
+ formData
2285
+ });
2286
+ case "boolean": return null;
2287
+ case "number": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
2288
+ type: "number",
2289
+ value: value !== null && value !== void 0 ? String(value) : "",
2290
+ onChange: (e) => onChange(e.target.value ? parseInt(e.target.value, 10) : null),
2291
+ placeholder: field.placeholder,
2292
+ disabled
2293
+ });
2294
+ default:
2295
+ if (field.options) {
2296
+ const selectedLabel = field.options.find((o) => o.value === value)?.label;
2297
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
2298
+ value: value ?? "",
2299
+ onValueChange: onChange,
2300
+ disabled,
2301
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectValue, {
2302
+ placeholder: field.placeholder ?? "Select...",
2303
+ children: selectedLabel
2304
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, { children: field.options.map((opt) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectRichItem, {
2305
+ value: opt.value,
2306
+ label: opt.label,
2307
+ description: opt.description
2308
+ }, opt.value)) })]
2309
+ });
2310
+ }
2311
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
2312
+ type: "text",
2313
+ value: value ?? "",
2314
+ onChange: (e) => onChange(e.target.value),
2315
+ placeholder: field.placeholder,
2316
+ disabled
2317
+ });
2318
+ }
2319
+ };
2320
+ if (field.type === "boolean") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2321
+ className: "flex items-center justify-between rounded-lg border px-4 py-3 pt-2.5",
2322
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2323
+ className: "space-y-0.5",
2324
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_label.Label, {
2325
+ className: "inline-flex items-center text-sm font-medium",
2326
+ children: [field.label, !field.required && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2327
+ className: "text-muted-foreground ml-1 text-xs font-normal",
2328
+ children: "(optional)"
2329
+ })]
2330
+ }), field.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2331
+ className: "text-muted-foreground text-xs",
2332
+ children: field.description
2333
+ })]
2334
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
2335
+ checked: value === true || value === "true",
2336
+ onCheckedChange: (v) => onChange(v),
2337
+ disabled
2338
+ })]
2339
+ });
2340
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2341
+ className: "space-y-1.5",
2342
+ children: [
2343
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_label.Label, {
2344
+ className: "inline-flex items-center",
2345
+ children: [field.label, !field.required && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2346
+ className: "text-muted-foreground ml-1 text-xs font-normal",
2347
+ children: "(optional)"
2348
+ })]
2349
+ }),
2350
+ field.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2351
+ className: "text-muted-foreground text-xs mb-2",
2352
+ children: field.description
2353
+ }),
2354
+ renderField()
2355
+ ]
2356
+ });
2357
+ }
2358
+
2359
+ //#endregion
2360
+ //#region src/schema/schema-builder-policies/components/policies/policy-config-form/access-control-group.tsx
2361
+ function getAccessSummary(fields, values) {
2362
+ const enabled = fields.filter((f) => values[f.key] === true || values[f.key] === "true");
2363
+ if (enabled.length === 0) return "Members";
2364
+ const labels = enabled.map((f) => f.label);
2365
+ if (labels.length === 1) return `Members who are ${labels[0]}`;
2366
+ return `Members who are ${labels.slice(0, -1).join(", ")} or ${labels[labels.length - 1]}`;
2367
+ }
2368
+ /**
2369
+ * Grouped card for is_admin / is_owner boolean fields.
2370
+ * Renders a "Who can access this?" card with checkboxes, switches, and a dynamic summary.
2371
+ */
2372
+ function AccessControlGroup({ fields, values, onChange, disabled }) {
2373
+ const summary = getAccessSummary(fields, values);
2374
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2375
+ "data-chat-component": "access-control-group",
2376
+ className: "rounded-lg border",
2377
+ children: [
2378
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2379
+ className: "px-4 pt-4 pb-3",
2380
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
2381
+ className: "text-balance text-sm font-semibold",
2382
+ children: "Who can access this?"
2383
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2384
+ className: "text-muted-foreground text-xs",
2385
+ children: "Limit access to certain members. Choose which types of members can access."
2386
+ })]
2387
+ }),
2388
+ fields.map((field) => {
2389
+ const checked = values[field.key] === true || values[field.key] === "true";
2390
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2391
+ className: "flex items-center justify-between border-t px-4 py-3",
2392
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2393
+ className: "min-w-0 flex-1 space-y-0.5",
2394
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2395
+ className: "text-sm font-medium leading-none",
2396
+ children: field.label
2397
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2398
+ className: "text-muted-foreground text-xs",
2399
+ children: field.description
2400
+ })]
2401
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
2402
+ checked,
2403
+ onCheckedChange: (v) => onChange(field.key, v),
2404
+ disabled
2405
+ })]
2406
+ }, field.key);
2407
+ }),
2408
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2409
+ className: "border-t px-4 py-3",
2410
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
2411
+ className: "text-xs",
2412
+ children: [
2413
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2414
+ className: "font-semibold",
2415
+ children: "Access:"
2416
+ }),
2417
+ " ",
2418
+ summary
2419
+ ]
2420
+ })
2421
+ })
2422
+ ]
2423
+ });
2424
+ }
2425
+
2426
+ //#endregion
2427
+ //#region src/schema/schema-builder-policies/components/policies/policy-config-form/policy-config-form.tsx
2428
+ const ACCESS_CONTROL_KEYS = /* @__PURE__ */ new Set(["is_admin", "is_owner"]);
2429
+ /**
2430
+ * Dynamic form for configuring a policy type.
2431
+ *
2432
+ * Renders fields based on the policy type's field overrides.
2433
+ * All fields are shown inline (no advanced section).
2434
+ */
2435
+ function PolicyConfigForm({ policyType, value, onChange, disabled, hideAutoGeneratedInfo }) {
2436
+ const { mainFields: allMainFields, advancedFields: allAdvancedFields } = useFormSchema(policyType);
2437
+ const { currentDatabase } = require_invalidate_database_entities.useSchemaBuilderSelectors();
2438
+ const databaseId = currentDatabase?.databaseId ?? "";
2439
+ const { data: tables = [] } = require_invalidate_database_entities.useDatabasePolicies(databaseId, { enabled: Boolean(databaseId) });
2440
+ const allFields = (0, react.useMemo)(() => [...allMainFields, ...allAdvancedFields], [allMainFields, allAdvancedFields]);
2441
+ const handleFieldChange = (key, fieldValue) => {
2442
+ const updates = { [key]: fieldValue };
2443
+ for (const f of allFields) if (f.dependsOn === key) updates[f.key] = f.type === "field-multi-select" ? [] : "";
2444
+ onChange({
2445
+ ...value,
2446
+ ...updates
2447
+ });
2448
+ };
2449
+ const fieldMappings = (0, react.useMemo)(() => getGeneratedFieldMappings(policyType), [policyType]);
2450
+ const inlineEditedKeys = (0, react.useMemo)(() => {
2451
+ if (!fieldMappings) return /* @__PURE__ */ new Set();
2452
+ return new Set(Object.values(fieldMappings).map((m) => m.policyKey));
2453
+ }, [fieldMappings]);
2454
+ const filteredFields = (0, react.useMemo)(() => {
2455
+ if (hideAutoGeneratedInfo) return allFields;
2456
+ return allFields.filter((field) => !inlineEditedKeys.has(field.key));
2457
+ }, [
2458
+ allFields,
2459
+ inlineEditedKeys,
2460
+ hideAutoGeneratedInfo
2461
+ ]);
2462
+ const accessControlFields = (0, react.useMemo)(() => filteredFields.filter((f) => ACCESS_CONTROL_KEYS.has(f.key)), [filteredFields]);
2463
+ const regularFields = (0, react.useMemo)(() => filteredFields.filter((f) => !ACCESS_CONTROL_KEYS.has(f.key)), [filteredFields]);
2464
+ const hasNoConfig = filteredFields.length === 0 && policyType.generatedFields.length === 0 && inlineEditedKeys.size === 0;
2465
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2466
+ "data-chat-component": "policy-config-form",
2467
+ "data-chat-policy-type": policyType.name,
2468
+ className: "space-y-4",
2469
+ children: [
2470
+ !hideAutoGeneratedInfo && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoGeneratedFieldsInfo, {
2471
+ fields: policyType.generatedFields,
2472
+ value,
2473
+ onChange: handleFieldChange,
2474
+ fieldMappings,
2475
+ disabled
2476
+ }),
2477
+ regularFields.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2478
+ className: "space-y-4",
2479
+ children: regularFields.map((field) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DynamicFormField, {
2480
+ field,
2481
+ value: value[field.key],
2482
+ onChange: (v) => handleFieldChange(field.key, v),
2483
+ disabled,
2484
+ tables,
2485
+ formData: value
2486
+ }, field.key))
2487
+ }),
2488
+ accessControlFields.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccessControlGroup, {
2489
+ fields: accessControlFields,
2490
+ values: value,
2491
+ onChange: handleFieldChange,
2492
+ disabled
2493
+ }),
2494
+ hasNoConfig && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2495
+ className: "text-muted-foreground text-sm italic",
2496
+ children: "This policy type requires no configuration."
2497
+ })
2498
+ ]
2499
+ });
2500
+ }
2501
+
2502
+ //#endregion
2503
+ Object.defineProperty(exports, 'CRUD_OPERATIONS', {
2504
+ enumerable: true,
2505
+ get: function () {
2506
+ return CRUD_OPERATIONS;
2507
+ }
2508
+ });
2509
+ Object.defineProperty(exports, 'OPERATION_STYLES', {
2510
+ enumerable: true,
2511
+ get: function () {
2512
+ return OPERATION_STYLES;
2513
+ }
2514
+ });
2515
+ Object.defineProperty(exports, 'POLICY_TYPE_UI_CONFIG', {
2516
+ enumerable: true,
2517
+ get: function () {
2518
+ return POLICY_TYPE_UI_CONFIG;
2519
+ }
2520
+ });
2521
+ Object.defineProperty(exports, 'PRIVILEGE_TO_OPERATION', {
2522
+ enumerable: true,
2523
+ get: function () {
2524
+ return PRIVILEGE_TO_OPERATION;
2525
+ }
2526
+ });
2527
+ Object.defineProperty(exports, 'PolicyConfigForm', {
2528
+ enumerable: true,
2529
+ get: function () {
2530
+ return PolicyConfigForm;
2531
+ }
2532
+ });
2533
+ Object.defineProperty(exports, 'buildGrants', {
2534
+ enumerable: true,
2535
+ get: function () {
2536
+ return buildGrants;
2537
+ }
2538
+ });
2539
+ Object.defineProperty(exports, 'buildNodeData', {
2540
+ enumerable: true,
2541
+ get: function () {
2542
+ return buildNodeData;
2543
+ }
2544
+ });
2545
+ Object.defineProperty(exports, 'buildPolicyEntry', {
2546
+ enumerable: true,
2547
+ get: function () {
2548
+ return buildPolicyEntry;
2549
+ }
2550
+ });
2551
+ Object.defineProperty(exports, 'getDataNodeForPolicy', {
2552
+ enumerable: true,
2553
+ get: function () {
2554
+ return getDataNodeForPolicy;
2555
+ }
2556
+ });
2557
+ Object.defineProperty(exports, 'getDefaultFormValues', {
2558
+ enumerable: true,
2559
+ get: function () {
2560
+ return getDefaultFormValues;
2561
+ }
2562
+ });
2563
+ Object.defineProperty(exports, 'getFieldsRequiringColumns', {
2564
+ enumerable: true,
2565
+ get: function () {
2566
+ return getFieldsRequiringColumns;
2567
+ }
2568
+ });
2569
+ Object.defineProperty(exports, 'hasRequiredFieldsMissing', {
2570
+ enumerable: true,
2571
+ get: function () {
2572
+ return hasRequiredFieldsMissing;
2573
+ }
2574
+ });
2575
+ Object.defineProperty(exports, 'injectSchemaFields', {
2576
+ enumerable: true,
2577
+ get: function () {
2578
+ return injectSchemaFields;
2579
+ }
2580
+ });
2581
+ Object.defineProperty(exports, 'injectSchemaFieldsIntoCompositeTree', {
2582
+ enumerable: true,
2583
+ get: function () {
2584
+ return injectSchemaFieldsIntoCompositeTree;
2585
+ }
2586
+ });
2587
+ Object.defineProperty(exports, 'sanitizePolicyData', {
2588
+ enumerable: true,
2589
+ get: function () {
2590
+ return sanitizePolicyData;
2591
+ }
2592
+ });
2593
+ Object.defineProperty(exports, 'useBatchCreateTableGrants', {
2594
+ enumerable: true,
2595
+ get: function () {
2596
+ return useBatchCreateTableGrants;
2597
+ }
2598
+ });
2599
+ Object.defineProperty(exports, 'useCreateTableGrant', {
2600
+ enumerable: true,
2601
+ get: function () {
2602
+ return useCreateTableGrant;
2603
+ }
2604
+ });
2605
+ Object.defineProperty(exports, 'useCreateTableWithPolicies', {
2606
+ enumerable: true,
2607
+ get: function () {
2608
+ return useCreateTableWithPolicies;
2609
+ }
2610
+ });
2611
+ Object.defineProperty(exports, 'usePermissions', {
2612
+ enumerable: true,
2613
+ get: function () {
2614
+ return usePermissions;
2615
+ }
2616
+ });
2617
+ Object.defineProperty(exports, 'usePolicyType', {
2618
+ enumerable: true,
2619
+ get: function () {
2620
+ return usePolicyType;
2621
+ }
2622
+ });
2623
+ Object.defineProperty(exports, 'usePolicyTypes', {
2624
+ enumerable: true,
2625
+ get: function () {
2626
+ return usePolicyTypes;
2627
+ }
2628
+ });
2629
+ //# sourceMappingURL=policy-config-form-CefFo6Fw.cjs.map