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