@constructive-io/seeder 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -7,7 +7,14 @@ import { Inquirerer } from 'inquirerer';
7
7
  import { parseType, print } from '@0no-co/graphql.web';
8
8
  import * as t from 'gql-ast';
9
9
  import { gql, GraphQLClient } from 'graphql-request';
10
- import { getPolicyCategory, getDataNodeForPolicy, buildNodeData, cleanTable, buildPostGraphileCreate, toCamelCaseSingular, toCreateMutationName, sanitizePolicyData, injectSchemaFields, getPolicyFieldDefaults, CRUD_OPERATIONS, CRUD_TO_PRIVILEGE, getFieldsRequiringColumns, DEFAULT_CRUD_GRANT_PRIVILEGES, prepareCreateInput } from '@constructive-io/data';
10
+ import '@constructive-io/graphql-query/client/index.js';
11
+ import { buildPostGraphileCreate, toCamelCaseSingular, toCreateMutationName } from '@constructive-io/graphql-query/generators/index.js';
12
+ import '@constructive-io/graphql-query/query-builder.js';
13
+ import '@constructive-io/graphql-query/types/core.js';
14
+ import '@constructive-io/graphql-query/ast.js';
15
+ import '@constructive-io/graphql-query/custom-ast.js';
16
+ import '@constructive-io/graphql-query/meta-object/convert.js';
17
+ import '@constructive-io/graphql-query/meta-object/validate.js';
11
18
  import { readFile } from 'fs/promises';
12
19
  import path from 'path';
13
20
  import { pathToFileURL } from 'url';
@@ -15,7 +22,7 @@ import { z } from 'zod';
15
22
 
16
23
  // package.json
17
24
  var package_default = {
18
- version: "0.5.0"};
25
+ version: "0.5.2"};
19
26
 
20
27
  // src/blueprints/base.ts
21
28
  function getProvisionedTableNames(blueprint) {
@@ -20271,6 +20278,666 @@ async function provisionDatabase(db, options) {
20271
20278
  }
20272
20279
  return provisionResult;
20273
20280
  }
20281
+ function pgFieldToCamelCase(str) {
20282
+ return str.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
20283
+ }
20284
+ function convertInflection(inflection) {
20285
+ if (!inflection) return void 0;
20286
+ return {
20287
+ allRows: inflection.allRows ?? "",
20288
+ allRowsSimple: inflection.allRowsSimple ?? "",
20289
+ conditionType: inflection.conditionType ?? "",
20290
+ connection: inflection.connection ?? "",
20291
+ createField: inflection.createField ?? "",
20292
+ createInputType: inflection.createInputType ?? "",
20293
+ createPayloadType: inflection.createPayloadType ?? "",
20294
+ deleteByPrimaryKey: inflection.deleteByPrimaryKey ?? null,
20295
+ deletePayloadType: inflection.deletePayloadType ?? "",
20296
+ edge: inflection.edge ?? "",
20297
+ edgeField: inflection.edgeField ?? "",
20298
+ enumType: inflection.enumType ?? "",
20299
+ filterType: inflection.filterType ?? null,
20300
+ inputType: inflection.inputType ?? "",
20301
+ orderByType: inflection.orderByType ?? "",
20302
+ patchField: inflection.patchField ?? "",
20303
+ patchType: inflection.patchType ?? null,
20304
+ tableFieldName: inflection.tableFieldName ?? "",
20305
+ tableType: inflection.tableType ?? "",
20306
+ typeName: inflection.typeName ?? "",
20307
+ updateByPrimaryKey: inflection.updateByPrimaryKey ?? null,
20308
+ updatePayloadType: inflection.updatePayloadType ?? null
20309
+ };
20310
+ }
20311
+ function convertQueryNames(query) {
20312
+ if (!query) return void 0;
20313
+ return {
20314
+ all: query.all,
20315
+ one: query.one ?? null,
20316
+ create: query.create ?? "",
20317
+ update: query.update ?? null,
20318
+ delete: query.delete ?? null
20319
+ };
20320
+ }
20321
+ function cleanTable(metaTable) {
20322
+ const relations = metaTable.relations;
20323
+ return {
20324
+ name: metaTable.name,
20325
+ inflection: convertInflection(metaTable.inflection),
20326
+ query: convertQueryNames(metaTable.query),
20327
+ fields: (metaTable.fields || []).filter((f) => f != null).map((field2) => ({
20328
+ name: pgFieldToCamelCase(field2.name),
20329
+ type: {
20330
+ gqlType: field2.type.gqlType,
20331
+ isArray: field2.type.isArray,
20332
+ modifier: field2.type.modifier,
20333
+ pgAlias: field2.type.pgAlias,
20334
+ pgType: field2.type.pgType,
20335
+ subtype: field2.type.subtype,
20336
+ typmod: field2.type.typmod
20337
+ },
20338
+ isNotNull: field2.isNotNull ?? field2.type.isNotNull ?? null,
20339
+ hasDefault: field2.hasDefault ?? field2.type.hasDefault ?? null
20340
+ })),
20341
+ relations: {
20342
+ belongsTo: (relations?.belongsTo || []).filter((r) => r != null).map((relation) => ({
20343
+ fieldName: relation.fieldName ?? null,
20344
+ isUnique: relation.isUnique,
20345
+ referencesTable: relation.references?.name || "",
20346
+ type: relation.type ?? null,
20347
+ keys: (relation.keys || []).filter((k) => k != null).map((key) => ({
20348
+ name: pgFieldToCamelCase(key.name),
20349
+ type: {
20350
+ gqlType: key.type?.gqlType || "",
20351
+ isArray: key.type?.isArray || false,
20352
+ modifier: key.type?.modifier,
20353
+ pgAlias: key.type?.pgAlias,
20354
+ pgType: key.type?.pgType,
20355
+ subtype: key.type?.subtype,
20356
+ typmod: key.type?.typmod
20357
+ }
20358
+ }))
20359
+ })),
20360
+ hasOne: (relations?.hasOne || []).filter((r) => r != null).map((relation) => ({
20361
+ fieldName: relation.fieldName ?? null,
20362
+ isUnique: relation.isUnique,
20363
+ referencedByTable: relation.referencedBy?.name || "",
20364
+ type: relation.type ?? null,
20365
+ keys: (relation.keys || []).filter((k) => k != null).map((key) => ({
20366
+ name: pgFieldToCamelCase(key.name),
20367
+ type: {
20368
+ gqlType: key.type?.gqlType || "",
20369
+ isArray: key.type?.isArray || false,
20370
+ modifier: key.type?.modifier,
20371
+ pgAlias: key.type?.pgAlias,
20372
+ pgType: key.type?.pgType,
20373
+ subtype: key.type?.subtype,
20374
+ typmod: key.type?.typmod
20375
+ }
20376
+ }))
20377
+ })),
20378
+ hasMany: (relations?.hasMany || []).filter((r) => r != null).map((relation) => ({
20379
+ fieldName: relation.fieldName ?? null,
20380
+ isUnique: relation.isUnique,
20381
+ referencedByTable: relation.referencedBy?.name || "",
20382
+ type: relation.type ?? null,
20383
+ keys: (relation.keys || []).filter((k) => k != null).map((key) => ({
20384
+ name: pgFieldToCamelCase(key.name),
20385
+ type: {
20386
+ gqlType: key.type?.gqlType || "",
20387
+ isArray: key.type?.isArray || false,
20388
+ modifier: key.type?.modifier,
20389
+ pgAlias: key.type?.pgAlias,
20390
+ pgType: key.type?.pgType,
20391
+ subtype: key.type?.subtype,
20392
+ typmod: key.type?.typmod
20393
+ }
20394
+ }))
20395
+ })),
20396
+ manyToMany: (relations?.manyToMany || []).filter((r) => r != null).map((relation) => ({
20397
+ fieldName: relation.fieldName ?? null,
20398
+ rightTable: relation.rightTable?.name || "",
20399
+ junctionTable: relation.junctionTable?.name || "",
20400
+ type: relation.type ?? null
20401
+ }))
20402
+ }
20403
+ };
20404
+ }
20405
+ function isPlainObject(value) {
20406
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
20407
+ }
20408
+ function hasNestedDirtyFields(dirtyFields, prefix) {
20409
+ for (const field2 of dirtyFields) {
20410
+ if (field2 === prefix || field2.startsWith(`${prefix}.`)) {
20411
+ return true;
20412
+ }
20413
+ }
20414
+ return false;
20415
+ }
20416
+ function isFieldOrAncestorDirty(dirtyFields, path2) {
20417
+ if (dirtyFields.has(path2)) return true;
20418
+ const parts = path2.split(".");
20419
+ for (let i = 1; i < parts.length; i++) {
20420
+ const ancestorPath = parts.slice(0, i).join(".");
20421
+ if (dirtyFields.has(ancestorPath)) return true;
20422
+ }
20423
+ return false;
20424
+ }
20425
+ function getNestedValue(obj, path2) {
20426
+ const parts = path2.split(".");
20427
+ let current = obj;
20428
+ for (const part of parts) {
20429
+ if (current === null || current === void 0) return void 0;
20430
+ if (typeof current !== "object") return void 0;
20431
+ current = current[part];
20432
+ }
20433
+ return current;
20434
+ }
20435
+ function prepareMutationInput(input, options) {
20436
+ const { operation, dirtyFields, defaultValues, alwaysInclude = [], exclude = [], _pathPrefix = "" } = options;
20437
+ const result = {};
20438
+ const alwaysIncludeSet = new Set(alwaysInclude);
20439
+ const excludeSet = new Set(exclude);
20440
+ for (const [key, value] of Object.entries(input)) {
20441
+ const fullPath = _pathPrefix ? `${_pathPrefix}.${key}` : key;
20442
+ const isDirty = dirtyFields ? isFieldOrAncestorDirty(dirtyFields, fullPath) : true;
20443
+ const hasDirtyTracking = !!dirtyFields;
20444
+ if (excludeSet.has(key) || excludeSet.has(fullPath)) continue;
20445
+ if (alwaysIncludeSet.has(key) || alwaysIncludeSet.has(fullPath)) {
20446
+ result[key] = value;
20447
+ continue;
20448
+ }
20449
+ if (value === void 0) continue;
20450
+ if (value === null) {
20451
+ if (operation === "create") {
20452
+ if (hasDirtyTracking && isDirty) {
20453
+ result[key] = null;
20454
+ }
20455
+ } else {
20456
+ if (isDirty) {
20457
+ result[key] = null;
20458
+ }
20459
+ }
20460
+ continue;
20461
+ }
20462
+ if (value === "") {
20463
+ if (operation === "create") {
20464
+ if (hasDirtyTracking && isDirty) {
20465
+ result[key] = "";
20466
+ }
20467
+ } else {
20468
+ if (isDirty) {
20469
+ result[key] = "";
20470
+ }
20471
+ }
20472
+ continue;
20473
+ }
20474
+ if (Array.isArray(value)) {
20475
+ if (hasDirtyTracking && !isDirty && !hasNestedDirtyFields(dirtyFields, fullPath)) {
20476
+ continue;
20477
+ }
20478
+ result[key] = value;
20479
+ continue;
20480
+ }
20481
+ if (isPlainObject(value)) {
20482
+ const hasRelevantDirtyFields = !hasDirtyTracking || isDirty || hasNestedDirtyFields(dirtyFields, fullPath);
20483
+ if (!hasRelevantDirtyFields) {
20484
+ continue;
20485
+ }
20486
+ const nestedResult = prepareMutationInput(value, {
20487
+ ...options,
20488
+ _pathPrefix: fullPath
20489
+ });
20490
+ if (Object.keys(nestedResult).length > 0) {
20491
+ result[key] = nestedResult;
20492
+ }
20493
+ continue;
20494
+ }
20495
+ if (hasDirtyTracking && !isDirty) {
20496
+ continue;
20497
+ }
20498
+ if (defaultValues) {
20499
+ const defaultValue = getNestedValue(defaultValues, fullPath);
20500
+ if (value === defaultValue && !isDirty) {
20501
+ continue;
20502
+ }
20503
+ }
20504
+ result[key] = value;
20505
+ }
20506
+ return result;
20507
+ }
20508
+ function prepareCreateInput(input, options) {
20509
+ return prepareMutationInput(input, { ...options, operation: "create" });
20510
+ }
20511
+ var MEMBERSHIP_TYPES = {
20512
+ APP: 1,
20513
+ ORGANIZATION: 2};
20514
+ var CRUD_OPERATIONS = ["create", "read", "update", "delete"];
20515
+ var CRUD_TO_PRIVILEGE = {
20516
+ create: "INSERT",
20517
+ read: "SELECT",
20518
+ update: "UPDATE",
20519
+ delete: "DELETE"
20520
+ };
20521
+ var DEFAULT_CRUD_GRANT_PRIVILEGES = [
20522
+ ["select", "*"],
20523
+ ["insert", "*"],
20524
+ ["update", "*"],
20525
+ ["delete", "*"]
20526
+ ];
20527
+ var POLICY_PROVISIONING_CONFIG = {
20528
+ AuthzDirectOwner: {
20529
+ category: "has-module",
20530
+ hasDataNode: true,
20531
+ dataNodeType: "DataDirectOwner",
20532
+ fieldOverrides: {
20533
+ entity_field: {
20534
+ type: "string",
20535
+ required: true,
20536
+ label: "Owner Field Name",
20537
+ placeholder: "owner_id",
20538
+ description: "Column that stores the owner user ID",
20539
+ defaultValue: "owner_id"
20540
+ }
20541
+ }
20542
+ },
20543
+ AuthzEntityMembership: {
20544
+ category: "has-module",
20545
+ hasDataNode: true,
20546
+ dataNodeType: "DataEntityMembership",
20547
+ fieldOverrides: {
20548
+ entity_field: {
20549
+ type: "string",
20550
+ required: true,
20551
+ label: "Entity Field Name",
20552
+ placeholder: "entity_id",
20553
+ description: "Column referencing the org/group",
20554
+ defaultValue: "entity_id"
20555
+ },
20556
+ membership_type: {
20557
+ type: "integer",
20558
+ hidden: true,
20559
+ defaultValue: MEMBERSHIP_TYPES.ORGANIZATION
20560
+ },
20561
+ permission: {
20562
+ type: "string",
20563
+ component: "permission-select",
20564
+ label: "Required Permission",
20565
+ description: "Optional permission the user must have"
20566
+ },
20567
+ is_admin: {
20568
+ type: "boolean",
20569
+ label: "Admins",
20570
+ description: "People with admin access can view this."
20571
+ },
20572
+ is_owner: {
20573
+ type: "boolean",
20574
+ label: "Owners",
20575
+ description: "People who own the membership can view this."
20576
+ }
20577
+ }
20578
+ },
20579
+ AuthzDirectOwnerAny: {
20580
+ category: "needs-fields",
20581
+ hasDataNode: false,
20582
+ fieldOverrides: {
20583
+ entity_fields: {
20584
+ type: "uuid[]",
20585
+ required: true,
20586
+ label: "Owner Fields",
20587
+ description: "UUID columns to check for ownership (OR logic)",
20588
+ defaultValue: ["owner_id"],
20589
+ pgType: "uuid"
20590
+ }
20591
+ }
20592
+ },
20593
+ AuthzMembership: {
20594
+ category: "no-fields",
20595
+ hasDataNode: false,
20596
+ fieldOverrides: {
20597
+ membership_type: {
20598
+ type: "integer",
20599
+ required: true,
20600
+ component: "membership-type-select",
20601
+ label: "Membership Scope",
20602
+ description: "Which type of membership to check against",
20603
+ defaultValue: MEMBERSHIP_TYPES.APP
20604
+ },
20605
+ permission: {
20606
+ type: "string",
20607
+ component: "permission-select",
20608
+ label: "Required Permission",
20609
+ description: "Optional permission the user must have"
20610
+ },
20611
+ is_admin: {
20612
+ type: "boolean",
20613
+ label: "Admins",
20614
+ description: "People with admin access can view this."
20615
+ },
20616
+ is_owner: {
20617
+ type: "boolean",
20618
+ label: "Owners",
20619
+ description: "People who own the membership can view this."
20620
+ }
20621
+ }
20622
+ },
20623
+ AuthzPublishable: {
20624
+ category: "has-module",
20625
+ hasDataNode: true,
20626
+ dataNodeType: "DataPublishable",
20627
+ fieldOverrides: {
20628
+ is_published_field: {
20629
+ type: "string",
20630
+ label: "Published Flag Field",
20631
+ placeholder: "is_published",
20632
+ defaultValue: "is_published"
20633
+ },
20634
+ published_at_field: {
20635
+ type: "string",
20636
+ label: "Published At Field",
20637
+ placeholder: "published_at",
20638
+ defaultValue: "published_at"
20639
+ },
20640
+ require_published_at: {
20641
+ type: "boolean",
20642
+ label: "Require Published At",
20643
+ description: "Also require that the publish date has passed",
20644
+ defaultValue: true
20645
+ }
20646
+ }
20647
+ },
20648
+ AuthzTemporal: {
20649
+ category: "needs-fields",
20650
+ hasDataNode: false,
20651
+ fieldOverrides: {
20652
+ valid_from_field: {
20653
+ type: "string",
20654
+ required: true,
20655
+ label: "Valid From Field",
20656
+ placeholder: "valid_from",
20657
+ description: "Column for start time",
20658
+ defaultValue: "valid_from",
20659
+ pgType: "timestamptz"
20660
+ },
20661
+ valid_until_field: {
20662
+ type: "string",
20663
+ required: true,
20664
+ label: "Valid Until Field",
20665
+ placeholder: "valid_until",
20666
+ description: "Column for end time",
20667
+ defaultValue: "valid_until",
20668
+ pgType: "timestamptz"
20669
+ },
20670
+ valid_from_inclusive: {
20671
+ type: "boolean",
20672
+ label: "Include Start",
20673
+ description: "Include start boundary",
20674
+ defaultValue: true
20675
+ },
20676
+ valid_until_inclusive: {
20677
+ type: "boolean",
20678
+ label: "Include End",
20679
+ description: "Include end boundary",
20680
+ defaultValue: false
20681
+ }
20682
+ }
20683
+ },
20684
+ AuthzMemberList: {
20685
+ category: "needs-fields",
20686
+ hasDataNode: false,
20687
+ fieldOverrides: {
20688
+ array_field: {
20689
+ type: "string",
20690
+ required: true,
20691
+ label: "Member List Field",
20692
+ placeholder: "allowed_users",
20693
+ description: "Column containing list of user IDs",
20694
+ defaultValue: "allowed_users",
20695
+ pgType: "uuid[]"
20696
+ }
20697
+ }
20698
+ },
20699
+ AuthzRelatedMemberList: {
20700
+ category: "needs-table",
20701
+ hasDataNode: false,
20702
+ fieldOverrides: {
20703
+ owned_schema: {
20704
+ hidden: true
20705
+ },
20706
+ owned_table: {
20707
+ type: "string",
20708
+ required: true,
20709
+ component: "table-select",
20710
+ label: "Related Table",
20711
+ placeholder: "groups",
20712
+ description: "Table containing the member list"
20713
+ },
20714
+ owned_table_key: {
20715
+ type: "uuid",
20716
+ required: true,
20717
+ label: "Member List Column",
20718
+ placeholder: "member_ids",
20719
+ description: "List column in related table",
20720
+ dependsOn: "owned_table"
20721
+ },
20722
+ owned_table_ref_key: {
20723
+ type: "uuid",
20724
+ required: true,
20725
+ label: "Reference Key",
20726
+ placeholder: "id",
20727
+ description: "FK column in related table",
20728
+ dependsOn: "owned_table"
20729
+ },
20730
+ this_object_key: {
20731
+ type: "uuid",
20732
+ required: true,
20733
+ label: "Foreign Key",
20734
+ placeholder: "group_id",
20735
+ description: "FK on this table to related table"
20736
+ }
20737
+ }
20738
+ },
20739
+ AuthzRelatedEntityMembership: {
20740
+ category: "needs-table",
20741
+ hasDataNode: false,
20742
+ fieldOverrides: {
20743
+ entity_field: {
20744
+ type: "uuid",
20745
+ required: true,
20746
+ label: "Foreign Key Field",
20747
+ description: "Field on this table referencing the linked table"
20748
+ },
20749
+ membership_type: {
20750
+ type: "integer",
20751
+ required: true,
20752
+ component: "membership-type-select",
20753
+ label: "Membership Scope"
20754
+ },
20755
+ obj_schema: {
20756
+ hidden: true
20757
+ },
20758
+ obj_table: {
20759
+ type: "string",
20760
+ required: true,
20761
+ component: "table-select",
20762
+ label: "Linked Table",
20763
+ description: "Table to check for membership"
20764
+ },
20765
+ obj_field: {
20766
+ type: "uuid",
20767
+ required: true,
20768
+ label: "Entity Field on Linked Table",
20769
+ description: "Field containing entity ID for membership check",
20770
+ dependsOn: "obj_table"
20771
+ },
20772
+ permission: {
20773
+ type: "string",
20774
+ component: "permission-select",
20775
+ label: "Required Permission"
20776
+ },
20777
+ is_admin: {
20778
+ type: "boolean",
20779
+ label: "Admins",
20780
+ description: "People with admin access can view this."
20781
+ },
20782
+ is_owner: {
20783
+ type: "boolean",
20784
+ label: "Owners",
20785
+ description: "People who own the membership can view this."
20786
+ }
20787
+ }
20788
+ },
20789
+ AuthzOrgHierarchy: {
20790
+ category: "has-module",
20791
+ hasDataNode: true,
20792
+ dataNodeType: "DataOwnershipInEntity",
20793
+ disabled: true,
20794
+ fieldOverrides: {
20795
+ direction: {
20796
+ type: "string",
20797
+ required: true,
20798
+ label: "Direction",
20799
+ description: "Which direction to traverse the org hierarchy",
20800
+ defaultValue: "down",
20801
+ options: [
20802
+ { value: "down", label: "Down", description: "Managers can see their subordinates" },
20803
+ { value: "up", label: "Up", description: "Subordinates can see their managers" }
20804
+ ]
20805
+ },
20806
+ entity_field: {
20807
+ type: "string",
20808
+ label: "Entity Field Name",
20809
+ placeholder: "entity_id",
20810
+ description: "Field referencing the org entity",
20811
+ defaultValue: "entity_id"
20812
+ },
20813
+ anchor_field: {
20814
+ type: "string",
20815
+ required: true,
20816
+ label: "Anchor Field",
20817
+ placeholder: "owner_id",
20818
+ description: "Field referencing the user (e.g., owner_id)"
20819
+ },
20820
+ max_depth: {
20821
+ type: "integer",
20822
+ label: "Max Depth",
20823
+ description: "Optional max depth to limit visibility"
20824
+ }
20825
+ }
20826
+ },
20827
+ AuthzAllowAll: {
20828
+ category: "no-fields",
20829
+ hasDataNode: false
20830
+ },
20831
+ AuthzDenyAll: {
20832
+ category: "no-fields",
20833
+ hasDataNode: false
20834
+ },
20835
+ AuthzComposite: {
20836
+ category: "no-fields",
20837
+ hasDataNode: false
20838
+ }
20839
+ };
20840
+ var AUTO_INJECT_SCHEMA_FIELDS = /* @__PURE__ */ new Set(["owned_schema", "obj_schema"]);
20841
+ function getPolicyCategory(policyType) {
20842
+ return POLICY_PROVISIONING_CONFIG[policyType]?.category ?? "no-fields";
20843
+ }
20844
+ function getDataNodeForPolicy(policyType) {
20845
+ return POLICY_PROVISIONING_CONFIG[policyType]?.dataNodeType;
20846
+ }
20847
+ function getPolicyFieldDefaults(policyType) {
20848
+ const config = POLICY_PROVISIONING_CONFIG[policyType];
20849
+ if (!config?.fieldOverrides) {
20850
+ return {};
20851
+ }
20852
+ const defaults = {};
20853
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
20854
+ if (override.defaultValue !== void 0) {
20855
+ defaults[key] = override.defaultValue;
20856
+ }
20857
+ }
20858
+ return defaults;
20859
+ }
20860
+ function getFieldsRequiringColumns(policyType) {
20861
+ const config = POLICY_PROVISIONING_CONFIG[policyType];
20862
+ if (!config?.fieldOverrides) {
20863
+ return [];
20864
+ }
20865
+ const result = [];
20866
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
20867
+ if (!override.pgType) {
20868
+ continue;
20869
+ }
20870
+ const defaultName = Array.isArray(override.defaultValue) ? override.defaultValue : typeof override.defaultValue === "string" ? override.defaultValue : key;
20871
+ result.push({
20872
+ key,
20873
+ defaultName,
20874
+ pgType: override.pgType
20875
+ });
20876
+ }
20877
+ return result;
20878
+ }
20879
+ function sanitizePolicyData(data) {
20880
+ const sanitized = {};
20881
+ for (const [key, value] of Object.entries(data)) {
20882
+ if (value === void 0 || value === null) {
20883
+ continue;
20884
+ }
20885
+ if (typeof value === "string" && value.trim() === "") {
20886
+ continue;
20887
+ }
20888
+ if (Array.isArray(value) && value.length === 0) {
20889
+ continue;
20890
+ }
20891
+ sanitized[key] = value;
20892
+ }
20893
+ return sanitized;
20894
+ }
20895
+ function injectSchemaFields(policyData, schemaId, policyType) {
20896
+ const config = POLICY_PROVISIONING_CONFIG[policyType];
20897
+ if (!config?.fieldOverrides) {
20898
+ return policyData;
20899
+ }
20900
+ const next = { ...policyData };
20901
+ for (const [key, override] of Object.entries(config.fieldOverrides)) {
20902
+ if (!AUTO_INJECT_SCHEMA_FIELDS.has(key)) {
20903
+ continue;
20904
+ }
20905
+ if (override.hidden && next[key] === void 0) {
20906
+ next[key] = schemaId;
20907
+ }
20908
+ }
20909
+ return next;
20910
+ }
20911
+ function buildNodeDataForDataNodeType(dataNodeType, policyData) {
20912
+ if (!dataNodeType) {
20913
+ return {};
20914
+ }
20915
+ const data = {};
20916
+ if (dataNodeType === "DataDirectOwner") {
20917
+ if (policyData.entity_field && policyData.entity_field !== "owner_id") {
20918
+ data.owner_field_name = policyData.entity_field;
20919
+ }
20920
+ }
20921
+ if (dataNodeType === "DataEntityMembership") {
20922
+ if (policyData.entity_field && policyData.entity_field !== "entity_id") {
20923
+ data.entity_field_name = policyData.entity_field;
20924
+ }
20925
+ }
20926
+ if (dataNodeType === "DataOwnershipInEntity") {
20927
+ if (policyData.entity_field && policyData.entity_field !== "entity_id") {
20928
+ data.entity_field_name = policyData.entity_field;
20929
+ }
20930
+ if (policyData.anchor_field && policyData.anchor_field !== "owner_id") {
20931
+ data.owner_field_name = policyData.anchor_field;
20932
+ }
20933
+ }
20934
+ return data;
20935
+ }
20936
+ function buildNodeData(policyType, policyData) {
20937
+ return buildNodeDataForDataNodeType(getDataNodeForPolicy(policyType), policyData);
20938
+ }
20939
+
20940
+ // src/tables.ts
20274
20941
  function assert2(condition, message) {
20275
20942
  if (!condition) {
20276
20943
  throw new Error(message);