@agentic-kit/harness 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +176 -0
  3. package/blueprint/blueprint-defaults.d.ts +2 -0
  4. package/blueprint/blueprint-defaults.js +123 -0
  5. package/blueprint/blueprint-schema.d.ts +138 -0
  6. package/blueprint/blueprint-schema.js +86 -0
  7. package/blueprint/field-type.d.ts +25 -0
  8. package/blueprint/field-type.js +99 -0
  9. package/blueprint/internal-policies.d.ts +2 -0
  10. package/blueprint/internal-policies.js +14 -0
  11. package/blueprint/policy-provisioning.d.ts +79 -0
  12. package/blueprint/policy-provisioning.js +570 -0
  13. package/esm/blueprint/blueprint-defaults.d.ts +2 -0
  14. package/esm/blueprint/blueprint-defaults.js +120 -0
  15. package/esm/blueprint/blueprint-schema.d.ts +138 -0
  16. package/esm/blueprint/blueprint-schema.js +83 -0
  17. package/esm/blueprint/field-type.d.ts +25 -0
  18. package/esm/blueprint/field-type.js +94 -0
  19. package/esm/blueprint/internal-policies.d.ts +2 -0
  20. package/esm/blueprint/internal-policies.js +10 -0
  21. package/esm/blueprint/policy-provisioning.d.ts +79 -0
  22. package/esm/blueprint/policy-provisioning.js +553 -0
  23. package/esm/gating/confirm-gate.d.ts +46 -0
  24. package/esm/gating/confirm-gate.js +55 -0
  25. package/esm/gating/decline-guard.d.ts +7 -0
  26. package/esm/gating/decline-guard.js +48 -0
  27. package/esm/gating/preview.d.ts +37 -0
  28. package/esm/gating/preview.js +5 -0
  29. package/esm/gating/prompts.d.ts +8 -0
  30. package/esm/gating/prompts.js +175 -0
  31. package/esm/index.d.ts +20 -0
  32. package/esm/index.js +20 -0
  33. package/esm/skills/fetch.d.ts +31 -0
  34. package/esm/skills/fetch.js +84 -0
  35. package/esm/skills/frontmatter.d.ts +7 -0
  36. package/esm/skills/frontmatter.js +28 -0
  37. package/esm/skills/integrity.d.ts +8 -0
  38. package/esm/skills/integrity.js +28 -0
  39. package/esm/skills/manifest.d.ts +39 -0
  40. package/esm/skills/manifest.js +36 -0
  41. package/esm/skills/materialize.d.ts +13 -0
  42. package/esm/skills/materialize.js +26 -0
  43. package/esm/skills/overlay.d.ts +11 -0
  44. package/esm/skills/overlay.js +25 -0
  45. package/esm/skills/registry.d.ts +36 -0
  46. package/esm/skills/registry.js +30 -0
  47. package/esm/skills/source.d.ts +21 -0
  48. package/esm/skills/source.js +51 -0
  49. package/esm/skills/update-check.d.ts +36 -0
  50. package/esm/skills/update-check.js +74 -0
  51. package/esm/stash.d.ts +20 -0
  52. package/esm/stash.js +19 -0
  53. package/esm/types.d.ts +60 -0
  54. package/esm/types.js +8 -0
  55. package/gating/confirm-gate.d.ts +46 -0
  56. package/gating/confirm-gate.js +58 -0
  57. package/gating/decline-guard.d.ts +7 -0
  58. package/gating/decline-guard.js +52 -0
  59. package/gating/preview.d.ts +37 -0
  60. package/gating/preview.js +6 -0
  61. package/gating/prompts.d.ts +8 -0
  62. package/gating/prompts.js +179 -0
  63. package/index.d.ts +20 -0
  64. package/index.js +36 -0
  65. package/package.json +42 -0
  66. package/skills/fetch.d.ts +31 -0
  67. package/skills/fetch.js +122 -0
  68. package/skills/frontmatter.d.ts +7 -0
  69. package/skills/frontmatter.js +31 -0
  70. package/skills/integrity.d.ts +8 -0
  71. package/skills/integrity.js +64 -0
  72. package/skills/manifest.d.ts +39 -0
  73. package/skills/manifest.js +40 -0
  74. package/skills/materialize.d.ts +13 -0
  75. package/skills/materialize.js +62 -0
  76. package/skills/overlay.d.ts +11 -0
  77. package/skills/overlay.js +28 -0
  78. package/skills/registry.d.ts +36 -0
  79. package/skills/registry.js +34 -0
  80. package/skills/source.d.ts +21 -0
  81. package/skills/source.js +88 -0
  82. package/skills/update-check.d.ts +36 -0
  83. package/skills/update-check.js +110 -0
  84. package/stash.d.ts +20 -0
  85. package/stash.js +55 -0
  86. package/types.d.ts +60 -0
  87. package/types.js +9 -0
@@ -0,0 +1,570 @@
1
+ "use strict";
2
+ /**
3
+ * VENDORED — verbatim from @constructive-io/data (workspace-only, unpublished):
4
+ * constructive-client/packages/data/src/policy-provisioning.ts
5
+ *
6
+ * Zero-import pure-config module. Vendored because the package is not published
7
+ * to npm. Keep in sync with the upstream source. Do not edit by hand except to
8
+ * re-sync from upstream.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.DATA_NODE_GENERATED_FIELDS = exports.POLICY_PROVISIONING_CONFIG = exports.DEFAULT_CRUD_GRANT_PRIVILEGES = exports.CRUD_TO_PRIVILEGE = exports.CRUD_OPERATIONS = exports.MEMBERSHIP_TYPES = void 0;
12
+ exports.getPolicyProvisioningConfig = getPolicyProvisioningConfig;
13
+ exports.getPolicyCategory = getPolicyCategory;
14
+ exports.getDataNodeForPolicy = getDataNodeForPolicy;
15
+ exports.policyRequiresDataNode = policyRequiresDataNode;
16
+ exports.policyCanBeNodeless = policyCanBeNodeless;
17
+ exports.getGeneratedFields = getGeneratedFields;
18
+ exports.hasGeneratedFields = hasGeneratedFields;
19
+ exports.getPolicyFieldDefaults = getPolicyFieldDefaults;
20
+ exports.getFieldsRequiringColumns = getFieldsRequiringColumns;
21
+ exports.sanitizePolicyData = sanitizePolicyData;
22
+ exports.injectSchemaFields = injectSchemaFields;
23
+ exports.buildNodeDataForDataNodeType = buildNodeDataForDataNodeType;
24
+ exports.buildNodeData = buildNodeData;
25
+ exports.groupCrudOperationsByConfig = groupCrudOperationsByConfig;
26
+ exports.MEMBERSHIP_TYPES = {
27
+ APP: 1,
28
+ ORGANIZATION: 2,
29
+ GROUP: 3,
30
+ };
31
+ exports.CRUD_OPERATIONS = ['create', 'read', 'update', 'delete'];
32
+ exports.CRUD_TO_PRIVILEGE = {
33
+ create: 'INSERT',
34
+ read: 'SELECT',
35
+ update: 'UPDATE',
36
+ delete: 'DELETE',
37
+ };
38
+ exports.DEFAULT_CRUD_GRANT_PRIVILEGES = [
39
+ ['select', '*'],
40
+ ['insert', '*'],
41
+ ['update', '*'],
42
+ ['delete', '*'],
43
+ ];
44
+ exports.POLICY_PROVISIONING_CONFIG = {
45
+ AuthzDirectOwner: {
46
+ category: 'has-module',
47
+ hasDataNode: true,
48
+ dataNodeType: 'DataDirectOwner',
49
+ fieldOverrides: {
50
+ entity_field: {
51
+ type: 'string',
52
+ required: true,
53
+ label: 'Owner Field Name',
54
+ placeholder: 'owner_id',
55
+ description: 'Column that stores the owner user ID',
56
+ defaultValue: 'owner_id',
57
+ },
58
+ },
59
+ },
60
+ AuthzEntityMembership: {
61
+ category: 'has-module',
62
+ hasDataNode: true,
63
+ dataNodeType: 'DataEntityMembership',
64
+ fieldOverrides: {
65
+ entity_field: {
66
+ type: 'string',
67
+ required: true,
68
+ label: 'Entity Field Name',
69
+ placeholder: 'entity_id',
70
+ description: 'Column referencing the org/group',
71
+ defaultValue: 'entity_id',
72
+ },
73
+ membership_type: {
74
+ type: 'integer',
75
+ hidden: true,
76
+ defaultValue: exports.MEMBERSHIP_TYPES.ORGANIZATION,
77
+ },
78
+ permission: {
79
+ type: 'string',
80
+ component: 'permission-select',
81
+ label: 'Required Permission',
82
+ description: 'Optional permission the user must have',
83
+ },
84
+ is_admin: {
85
+ type: 'boolean',
86
+ label: 'Admins',
87
+ description: 'People with admin access can view this.',
88
+ },
89
+ is_owner: {
90
+ type: 'boolean',
91
+ label: 'Owners',
92
+ description: 'People who own the membership can view this.',
93
+ },
94
+ },
95
+ },
96
+ AuthzDirectOwnerAny: {
97
+ category: 'needs-fields',
98
+ hasDataNode: false,
99
+ fieldOverrides: {
100
+ entity_fields: {
101
+ type: 'uuid[]',
102
+ required: true,
103
+ label: 'Owner Fields',
104
+ description: 'UUID columns to check for ownership (OR logic)',
105
+ defaultValue: ['owner_id'],
106
+ pgType: 'uuid',
107
+ },
108
+ },
109
+ },
110
+ AuthzAppMembership: {
111
+ category: 'no-fields',
112
+ hasDataNode: false,
113
+ fieldOverrides: {
114
+ permission: {
115
+ type: 'string',
116
+ component: 'permission-select',
117
+ label: 'Required Permission',
118
+ description: 'Optional permission the user must have',
119
+ },
120
+ is_admin: {
121
+ type: 'boolean',
122
+ label: 'Admins',
123
+ description: 'People with admin access can view this.',
124
+ },
125
+ is_owner: {
126
+ type: 'boolean',
127
+ label: 'Owners',
128
+ description: 'People who own the membership can view this.',
129
+ },
130
+ },
131
+ },
132
+ AuthzPublishable: {
133
+ category: 'has-module',
134
+ hasDataNode: true,
135
+ dataNodeType: 'DataPublishable',
136
+ fieldOverrides: {
137
+ is_published_field: {
138
+ type: 'string',
139
+ label: 'Published Flag Field',
140
+ placeholder: 'is_published',
141
+ defaultValue: 'is_published',
142
+ },
143
+ published_at_field: {
144
+ type: 'string',
145
+ label: 'Published At Field',
146
+ placeholder: 'published_at',
147
+ defaultValue: 'published_at',
148
+ },
149
+ require_published_at: {
150
+ type: 'boolean',
151
+ label: 'Require Published At',
152
+ description: 'Also require that the publish date has passed',
153
+ defaultValue: true,
154
+ },
155
+ },
156
+ },
157
+ AuthzTemporal: {
158
+ category: 'needs-fields',
159
+ hasDataNode: false,
160
+ fieldOverrides: {
161
+ valid_from_field: {
162
+ type: 'string',
163
+ required: true,
164
+ label: 'Valid From Field',
165
+ placeholder: 'valid_from',
166
+ description: 'Column for start time',
167
+ defaultValue: 'valid_from',
168
+ pgType: 'timestamptz',
169
+ },
170
+ valid_until_field: {
171
+ type: 'string',
172
+ required: true,
173
+ label: 'Valid Until Field',
174
+ placeholder: 'valid_until',
175
+ description: 'Column for end time',
176
+ defaultValue: 'valid_until',
177
+ pgType: 'timestamptz',
178
+ },
179
+ valid_from_inclusive: {
180
+ type: 'boolean',
181
+ label: 'Include Start',
182
+ description: 'Include start boundary',
183
+ defaultValue: true,
184
+ },
185
+ valid_until_inclusive: {
186
+ type: 'boolean',
187
+ label: 'Include End',
188
+ description: 'Include end boundary',
189
+ defaultValue: false,
190
+ },
191
+ },
192
+ },
193
+ AuthzMemberList: {
194
+ category: 'needs-fields',
195
+ hasDataNode: false,
196
+ fieldOverrides: {
197
+ array_field: {
198
+ type: 'string',
199
+ required: true,
200
+ label: 'Member List Field',
201
+ placeholder: 'allowed_users',
202
+ description: 'Column containing list of user IDs',
203
+ defaultValue: 'allowed_users',
204
+ pgType: 'uuid[]',
205
+ },
206
+ },
207
+ },
208
+ AuthzRelatedMemberList: {
209
+ category: 'needs-table',
210
+ hasDataNode: false,
211
+ fieldOverrides: {
212
+ owned_schema: {
213
+ hidden: true,
214
+ },
215
+ owned_table: {
216
+ type: 'string',
217
+ required: true,
218
+ component: 'table-select',
219
+ label: 'Related Table',
220
+ placeholder: 'groups',
221
+ description: 'Table containing the member list',
222
+ },
223
+ owned_table_key: {
224
+ type: 'uuid',
225
+ required: true,
226
+ label: 'Member List Column',
227
+ placeholder: 'member_ids',
228
+ description: 'List column in related table',
229
+ dependsOn: 'owned_table',
230
+ },
231
+ owned_table_ref_key: {
232
+ type: 'uuid',
233
+ required: true,
234
+ label: 'Reference Key',
235
+ placeholder: 'id',
236
+ description: 'FK column in related table',
237
+ dependsOn: 'owned_table',
238
+ },
239
+ this_object_key: {
240
+ type: 'uuid',
241
+ required: true,
242
+ label: 'Foreign Key',
243
+ placeholder: 'group_id',
244
+ description: 'FK on this table to related table',
245
+ },
246
+ },
247
+ },
248
+ AuthzRelatedEntityMembership: {
249
+ category: 'needs-table',
250
+ hasDataNode: false,
251
+ fieldOverrides: {
252
+ entity_field: {
253
+ type: 'uuid',
254
+ required: true,
255
+ label: 'Foreign Key Field',
256
+ description: 'Field on this table referencing the linked table',
257
+ },
258
+ membership_type: {
259
+ type: 'integer',
260
+ required: true,
261
+ component: 'membership-type-select',
262
+ label: 'Membership Scope',
263
+ },
264
+ obj_schema: {
265
+ hidden: true,
266
+ },
267
+ obj_table: {
268
+ type: 'string',
269
+ required: true,
270
+ component: 'table-select',
271
+ label: 'Linked Table',
272
+ description: 'Table to check for membership',
273
+ },
274
+ obj_field: {
275
+ type: 'uuid',
276
+ required: true,
277
+ label: 'Entity Field on Linked Table',
278
+ description: 'Field containing entity ID for membership check',
279
+ dependsOn: 'obj_table',
280
+ },
281
+ permission: {
282
+ type: 'string',
283
+ component: 'permission-select',
284
+ label: 'Required Permission',
285
+ },
286
+ is_admin: {
287
+ type: 'boolean',
288
+ label: 'Admins',
289
+ description: 'People with admin access can view this.',
290
+ },
291
+ is_owner: {
292
+ type: 'boolean',
293
+ label: 'Owners',
294
+ description: 'People who own the membership can view this.',
295
+ },
296
+ },
297
+ },
298
+ AuthzOrgHierarchy: {
299
+ category: 'has-module',
300
+ hasDataNode: true,
301
+ dataNodeType: 'DataOwnershipInEntity',
302
+ disabled: true,
303
+ fieldOverrides: {
304
+ direction: {
305
+ type: 'string',
306
+ required: true,
307
+ label: 'Direction',
308
+ description: 'Which direction to traverse the org hierarchy',
309
+ defaultValue: 'down',
310
+ options: [
311
+ { value: 'down', label: 'Down', description: 'Managers can see their subordinates' },
312
+ { value: 'up', label: 'Up', description: 'Subordinates can see their managers' },
313
+ ],
314
+ },
315
+ entity_field: {
316
+ type: 'string',
317
+ label: 'Entity Field Name',
318
+ placeholder: 'entity_id',
319
+ description: 'Field referencing the org entity',
320
+ defaultValue: 'entity_id',
321
+ },
322
+ anchor_field: {
323
+ type: 'string',
324
+ required: true,
325
+ label: 'Anchor Field',
326
+ placeholder: 'owner_id',
327
+ description: 'Field referencing the user (e.g., owner_id)',
328
+ defaultValue: 'owner_id',
329
+ },
330
+ max_depth: {
331
+ type: 'integer',
332
+ label: 'Max Depth',
333
+ description: 'Optional max depth to limit visibility',
334
+ },
335
+ },
336
+ },
337
+ AuthzAllowAll: {
338
+ category: 'no-fields',
339
+ hasDataNode: false,
340
+ },
341
+ AuthzDenyAll: {
342
+ category: 'no-fields',
343
+ hasDataNode: false,
344
+ },
345
+ AuthzComposite: {
346
+ category: 'no-fields',
347
+ hasDataNode: false,
348
+ },
349
+ };
350
+ exports.DATA_NODE_GENERATED_FIELDS = {
351
+ DataDirectOwner: [
352
+ {
353
+ name: 'owner_id',
354
+ type: 'uuid',
355
+ nullable: false,
356
+ description: 'References the owning user',
357
+ },
358
+ ],
359
+ DataEntityMembership: [
360
+ {
361
+ name: 'entity_id',
362
+ type: 'uuid',
363
+ nullable: false,
364
+ description: 'References the organization or group',
365
+ },
366
+ ],
367
+ DataOwnershipInEntity: [
368
+ {
369
+ name: 'owner_id',
370
+ type: 'uuid',
371
+ nullable: false,
372
+ description: 'References the owning user',
373
+ },
374
+ {
375
+ name: 'entity_id',
376
+ type: 'uuid',
377
+ nullable: false,
378
+ description: 'References the organization or group',
379
+ },
380
+ ],
381
+ DataPublishable: [
382
+ {
383
+ name: 'is_published',
384
+ type: 'boolean',
385
+ nullable: false,
386
+ description: 'Whether the record is published',
387
+ },
388
+ {
389
+ name: 'published_at',
390
+ type: 'timestamptz',
391
+ nullable: true,
392
+ description: 'When the record was published',
393
+ },
394
+ ],
395
+ DataTimestamps: [
396
+ {
397
+ name: 'created_at',
398
+ type: 'timestamptz',
399
+ nullable: false,
400
+ description: 'When the record was created',
401
+ },
402
+ {
403
+ name: 'updated_at',
404
+ type: 'timestamptz',
405
+ nullable: false,
406
+ description: 'When the record was last updated',
407
+ },
408
+ ],
409
+ DataPeoplestamps: [
410
+ {
411
+ name: 'created_by',
412
+ type: 'uuid',
413
+ nullable: true,
414
+ description: 'User who created the record',
415
+ },
416
+ {
417
+ name: 'updated_by',
418
+ type: 'uuid',
419
+ nullable: true,
420
+ description: 'User who last updated the record',
421
+ },
422
+ ],
423
+ DataSoftDelete: [
424
+ {
425
+ name: 'is_deleted',
426
+ type: 'boolean',
427
+ nullable: false,
428
+ description: 'Whether the record is soft-deleted',
429
+ },
430
+ {
431
+ name: 'deleted_at',
432
+ type: 'timestamptz',
433
+ nullable: true,
434
+ description: 'When the record was deleted',
435
+ },
436
+ ],
437
+ };
438
+ const AUTO_INJECT_SCHEMA_FIELDS = new Set(['owned_schema', 'obj_schema']);
439
+ function getPolicyProvisioningConfig(policyType) {
440
+ return exports.POLICY_PROVISIONING_CONFIG[policyType];
441
+ }
442
+ function getPolicyCategory(policyType) {
443
+ return exports.POLICY_PROVISIONING_CONFIG[policyType]?.category ?? 'no-fields';
444
+ }
445
+ function getDataNodeForPolicy(policyType) {
446
+ return exports.POLICY_PROVISIONING_CONFIG[policyType]?.dataNodeType;
447
+ }
448
+ function policyRequiresDataNode(policyType) {
449
+ return exports.POLICY_PROVISIONING_CONFIG[policyType]?.hasDataNode === true;
450
+ }
451
+ function policyCanBeNodeless(policyType) {
452
+ return exports.POLICY_PROVISIONING_CONFIG[policyType]?.hasDataNode !== true;
453
+ }
454
+ function getGeneratedFields(dataNodeType) {
455
+ return exports.DATA_NODE_GENERATED_FIELDS[dataNodeType] ?? [];
456
+ }
457
+ function hasGeneratedFields(dataNodeType) {
458
+ return dataNodeType in exports.DATA_NODE_GENERATED_FIELDS;
459
+ }
460
+ function getPolicyFieldDefaults(policyType) {
461
+ const config = exports.POLICY_PROVISIONING_CONFIG[policyType];
462
+ if (!config?.fieldOverrides) {
463
+ return {};
464
+ }
465
+ const defaults = {};
466
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
467
+ if (override.defaultValue !== undefined) {
468
+ defaults[key] = override.defaultValue;
469
+ }
470
+ }
471
+ return defaults;
472
+ }
473
+ function getFieldsRequiringColumns(policyType) {
474
+ const config = exports.POLICY_PROVISIONING_CONFIG[policyType];
475
+ if (!config?.fieldOverrides) {
476
+ return [];
477
+ }
478
+ const result = [];
479
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
480
+ if (!override.pgType) {
481
+ continue;
482
+ }
483
+ const defaultName = Array.isArray(override.defaultValue)
484
+ ? override.defaultValue
485
+ : typeof override.defaultValue === 'string'
486
+ ? override.defaultValue
487
+ : key;
488
+ result.push({
489
+ key,
490
+ defaultName,
491
+ pgType: override.pgType,
492
+ });
493
+ }
494
+ return result;
495
+ }
496
+ function sanitizePolicyData(data) {
497
+ const sanitized = {};
498
+ for (const [key, value] of Object.entries(data)) {
499
+ if (value === undefined || value === null) {
500
+ continue;
501
+ }
502
+ if (typeof value === 'string' && value.trim() === '') {
503
+ continue;
504
+ }
505
+ if (Array.isArray(value) && value.length === 0) {
506
+ continue;
507
+ }
508
+ sanitized[key] = value;
509
+ }
510
+ return sanitized;
511
+ }
512
+ function injectSchemaFields(policyData, schemaId, policyType) {
513
+ const config = exports.POLICY_PROVISIONING_CONFIG[policyType];
514
+ if (!config?.fieldOverrides) {
515
+ return policyData;
516
+ }
517
+ const next = { ...policyData };
518
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
519
+ if (!AUTO_INJECT_SCHEMA_FIELDS.has(key)) {
520
+ continue;
521
+ }
522
+ if (override.hidden && next[key] === undefined) {
523
+ next[key] = schemaId;
524
+ }
525
+ }
526
+ return next;
527
+ }
528
+ function buildNodeDataForDataNodeType(dataNodeType, policyData) {
529
+ if (!dataNodeType) {
530
+ return {};
531
+ }
532
+ const data = {};
533
+ if (dataNodeType === 'DataDirectOwner') {
534
+ if (policyData.entity_field && policyData.entity_field !== 'owner_id') {
535
+ data.owner_field_name = policyData.entity_field;
536
+ }
537
+ }
538
+ if (dataNodeType === 'DataEntityMembership') {
539
+ if (policyData.entity_field && policyData.entity_field !== 'entity_id') {
540
+ data.entity_field_name = policyData.entity_field;
541
+ }
542
+ }
543
+ if (dataNodeType === 'DataOwnershipInEntity') {
544
+ if (policyData.entity_field && policyData.entity_field !== 'entity_id') {
545
+ data.entity_field_name = policyData.entity_field;
546
+ }
547
+ if (policyData.anchor_field && policyData.anchor_field !== 'owner_id') {
548
+ data.owner_field_name = policyData.anchor_field;
549
+ }
550
+ }
551
+ return data;
552
+ }
553
+ function buildNodeData(policyType, policyData) {
554
+ return buildNodeDataForDataNodeType(getDataNodeForPolicy(policyType), policyData);
555
+ }
556
+ function groupCrudOperationsByConfig(enabledOperations, operations, privilegeMap) {
557
+ const grouped = new Map();
558
+ for (const operation of enabledOperations) {
559
+ const config = operations[operation];
560
+ const key = `${config.roleName}:${config.isPermissive}`;
561
+ const current = grouped.get(key) ?? {
562
+ roleName: config.roleName,
563
+ isPermissive: config.isPermissive,
564
+ privileges: [],
565
+ };
566
+ current.privileges.push(privilegeMap[operation]);
567
+ grouped.set(key, current);
568
+ }
569
+ return [...grouped.values()];
570
+ }
@@ -0,0 +1,2 @@
1
+ import type { BlueprintDefinition } from './blueprint-schema';
2
+ export declare function expandBlueprintDefaults(definition: BlueprintDefinition): Record<string, unknown>;
@@ -0,0 +1,120 @@
1
+ import { toFieldDefault, toFieldType } from './field-type';
2
+ import { buildNodeData, DATA_NODE_GENERATED_FIELDS, getPolicyFieldDefaults, getPolicyProvisioningConfig, } from './policy-provisioning';
3
+ const DEFAULT_GRANTS = [
4
+ {
5
+ roles: ['authenticated'],
6
+ privileges: [
7
+ ['select', '*'],
8
+ ['insert', '*'],
9
+ ['update', '*'],
10
+ ['delete', '*'],
11
+ ],
12
+ },
13
+ ];
14
+ const ALL_PRIVILEGES = ['select', 'insert', 'update', 'delete'];
15
+ export function expandBlueprintDefaults(definition) {
16
+ const tables = definition.tables.map((table) => {
17
+ let nodes = table.nodes;
18
+ if (!nodes || nodes.length === 0) {
19
+ const derived = ['DataId'];
20
+ for (const policy of table.policies) {
21
+ const config = getPolicyProvisioningConfig(policy.$type);
22
+ if (config?.dataNodeType) {
23
+ const defaults = getPolicyFieldDefaults(policy.$type);
24
+ const policyData = { ...defaults, ...(policy.data ?? {}) };
25
+ const nodeData = buildNodeData(policy.$type, policyData);
26
+ const entry = {
27
+ $type: config.dataNodeType,
28
+ };
29
+ if (Object.keys(nodeData).length > 0)
30
+ entry.data = nodeData;
31
+ derived.push(entry);
32
+ }
33
+ }
34
+ derived.push('DataTimestamps');
35
+ nodes = derived;
36
+ }
37
+ else {
38
+ const getType = (n) => (typeof n === 'string' ? n : n.$type);
39
+ const existingTypes = new Set(nodes.map(getType));
40
+ if (!existingTypes.has('DataId')) {
41
+ nodes = ['DataId', ...nodes];
42
+ existingTypes.add('DataId');
43
+ }
44
+ else if (getType(nodes[0]) !== 'DataId') {
45
+ nodes = ['DataId', ...nodes.filter((n) => getType(n) !== 'DataId')];
46
+ }
47
+ const missing = [];
48
+ for (const policy of table.policies) {
49
+ const config = getPolicyProvisioningConfig(policy.$type);
50
+ if (config?.dataNodeType && !existingTypes.has(config.dataNodeType)) {
51
+ const defaults = getPolicyFieldDefaults(policy.$type);
52
+ const policyData = { ...defaults, ...(policy.data ?? {}) };
53
+ const nodeData = buildNodeData(policy.$type, policyData);
54
+ const entry = {
55
+ $type: config.dataNodeType,
56
+ };
57
+ if (Object.keys(nodeData).length > 0)
58
+ entry.data = nodeData;
59
+ missing.push(entry);
60
+ existingTypes.add(config.dataNodeType);
61
+ }
62
+ }
63
+ if (!existingTypes.has('DataTimestamps')) {
64
+ nodes = [...nodes, ...missing, 'DataTimestamps'];
65
+ }
66
+ else if (missing.length > 0) {
67
+ const tsIdx = nodes.findIndex((n) => getType(n) === 'DataTimestamps');
68
+ if (tsIdx >= 0) {
69
+ nodes = [...nodes.slice(0, tsIdx), ...missing, ...nodes.slice(tsIdx)];
70
+ }
71
+ else {
72
+ nodes = [...nodes, ...missing];
73
+ }
74
+ }
75
+ }
76
+ const policies = table.policies.map((p) => {
77
+ const defaults = getPolicyFieldDefaults(p.$type);
78
+ const data = Object.keys(defaults).length > 0
79
+ ? { ...defaults, ...(p.data ?? {}) }
80
+ : p.data;
81
+ return {
82
+ ...p,
83
+ ...(data && { data }),
84
+ privileges: p.privileges ?? ALL_PRIVILEGES,
85
+ policy_role: p.policy_role ?? 'authenticated',
86
+ permissive: p.permissive ?? true,
87
+ };
88
+ });
89
+ const autoFields = new Set(['id']);
90
+ for (const node of nodes) {
91
+ const nodeType = typeof node === 'string' ? node : node.$type;
92
+ for (const f of DATA_NODE_GENERATED_FIELDS[nodeType] ?? []) {
93
+ autoFields.add(f.name);
94
+ }
95
+ }
96
+ const fields = table.fields
97
+ ?.filter((f) => !autoFields.has(f.name))
98
+ .map((f) => {
99
+ const out = { name: f.name, type: toFieldType(f.type) };
100
+ if (f.is_required)
101
+ out.is_required = true;
102
+ const def = toFieldDefault(f.default);
103
+ if (def !== undefined)
104
+ out.default = def;
105
+ return out;
106
+ });
107
+ return {
108
+ table_name: table.table_name,
109
+ use_rls: true,
110
+ grants: DEFAULT_GRANTS,
111
+ nodes,
112
+ policies,
113
+ ...(fields && fields.length > 0 && { fields }),
114
+ };
115
+ });
116
+ return {
117
+ tables,
118
+ ...(definition.relations && definition.relations.length > 0 && { relations: definition.relations }),
119
+ };
120
+ }