@tailor-platform/sdk 0.22.0 → 0.22.3

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.
@@ -1,5 +1,5 @@
1
1
  import { a as __toCommonJS, i as __require, n as __esmMin, o as __toESM, r as __export, t as __commonJSMin } from "./chunk-DhYkiPYI.mjs";
2
- import { i as WORKFLOW_JOB_BRAND, r as getDistDir, u as tailorUserMap } from "./config-BGY8v5d7.mjs";
2
+ import { i as WORKFLOW_JOB_BRAND, r as getDistDir } from "./config-CtRi0Lgg.mjs";
3
3
  import Module, { createRequire } from "node:module";
4
4
  import { defineCommand } from "citty";
5
5
  import * as path$20 from "node:path";
@@ -23,9 +23,9 @@ import fsPromises, { glob } from "node:fs/promises";
23
23
  import { fileURLToPath, pathToFileURL } from "node:url";
24
24
  import ml from "multiline-ts";
25
25
  import { xdgConfig } from "xdg-basedir";
26
- import * as inflection from "inflection";
27
26
  import util from "node:util";
28
27
  import assert from "node:assert";
28
+ import * as inflection from "inflection";
29
29
  import * as rolldown from "rolldown";
30
30
  import { parseSync } from "oxc-parser";
31
31
  import { create, fromJson } from "@bufbuild/protobuf";
@@ -1453,92 +1453,6 @@ const apiCommand = defineCommand({
1453
1453
  })
1454
1454
  });
1455
1455
 
1456
- //#endregion
1457
- //#region src/cli/application/auth/service.ts
1458
- var AuthService = class {
1459
- _userProfile;
1460
- _tenantProvider;
1461
- constructor(config, tailorDBServices) {
1462
- this.config = config;
1463
- this.tailorDBServices = tailorDBServices;
1464
- }
1465
- get userProfile() {
1466
- return this._userProfile;
1467
- }
1468
- get tenantProvider() {
1469
- return this._tenantProvider;
1470
- }
1471
- async resolveNamespaces() {
1472
- await Promise.all(this.tailorDBServices.map((service) => service.loadTypes()));
1473
- if (this.tailorDBServices.length === 1) {
1474
- const singleNamespace = this.tailorDBServices[0].namespace;
1475
- this._userProfile = this.config.userProfile ? {
1476
- ...this.config.userProfile,
1477
- namespace: singleNamespace
1478
- } : void 0;
1479
- this._tenantProvider = this.config.tenantProvider ? {
1480
- ...this.config.tenantProvider,
1481
- namespace: singleNamespace
1482
- } : void 0;
1483
- return;
1484
- }
1485
- const userProfileTypeName = this.config.userProfile?.type && typeof this.config.userProfile.type === "object" && "name" in this.config.userProfile.type ? this.config.userProfile.type.name : void 0;
1486
- const tenantProviderTypeName = typeof this.config.tenantProvider?.type === "string" ? this.config.tenantProvider.type : void 0;
1487
- let userProfileNamespace;
1488
- let tenantProviderNamespace;
1489
- for (const service of this.tailorDBServices) {
1490
- const types$2 = service.getTypes();
1491
- if (userProfileTypeName && !userProfileNamespace && Object.prototype.hasOwnProperty.call(types$2, userProfileTypeName)) userProfileNamespace = service.namespace;
1492
- if (tenantProviderTypeName && !tenantProviderNamespace && Object.prototype.hasOwnProperty.call(types$2, tenantProviderTypeName)) tenantProviderNamespace = service.namespace;
1493
- if (userProfileNamespace && tenantProviderNamespace) break;
1494
- }
1495
- if (this.config.userProfile && !userProfileNamespace) throw new Error(`userProfile type "${this.config.userProfile.type.name}" not found in any TailorDB namespace`);
1496
- if (this.config.tenantProvider && !tenantProviderNamespace) throw new Error(`tenantProvider type "${this.config.tenantProvider.type}" not found in any TailorDB namespace`);
1497
- this._userProfile = this.config.userProfile ? {
1498
- ...this.config.userProfile,
1499
- namespace: userProfileNamespace
1500
- } : void 0;
1501
- this._tenantProvider = this.config.tenantProvider ? {
1502
- ...this.config.tenantProvider,
1503
- namespace: tenantProviderNamespace
1504
- } : void 0;
1505
- }
1506
- };
1507
-
1508
- //#endregion
1509
- //#region src/cli/application/file-loader.ts
1510
- const DEFAULT_IGNORE_PATTERNS = ["**/*.test.ts", "**/*.spec.ts"];
1511
- /**
1512
- * Load files matching the given patterns, excluding files that match ignore patterns.
1513
- * By default, test files (*.test.ts, *.spec.ts) are excluded unless ignores is explicitly specified.
1514
- *
1515
- * @param config - Configuration with files patterns and optional ignores patterns
1516
- * @returns Array of absolute file paths
1517
- */
1518
- function loadFilesWithIgnores(config) {
1519
- const ignorePatterns = config.ignores ?? DEFAULT_IGNORE_PATTERNS;
1520
- const ignoreFiles = /* @__PURE__ */ new Set();
1521
- for (const ignorePattern of ignorePatterns) {
1522
- const absoluteIgnorePattern = path$20.resolve(process.cwd(), ignorePattern);
1523
- try {
1524
- fs$15.globSync(absoluteIgnorePattern).forEach((file) => ignoreFiles.add(file));
1525
- } catch (error) {
1526
- logger.warn(`Failed to glob ignore pattern "${ignorePattern}": ${String(error)}`);
1527
- }
1528
- }
1529
- const files = [];
1530
- for (const pattern of config.files) {
1531
- const absolutePattern = path$20.resolve(process.cwd(), pattern);
1532
- try {
1533
- const filteredFiles = fs$15.globSync(absolutePattern).filter((file) => !ignoreFiles.has(file));
1534
- files.push(...filteredFiles);
1535
- } catch (error) {
1536
- logger.warn(`Failed to glob pattern "${pattern}": ${String(error)}`);
1537
- }
1538
- }
1539
- return files;
1540
- }
1541
-
1542
1456
  //#endregion
1543
1457
  //#region src/parser/service/auth/schema.ts
1544
1458
  const AuthInvokerSchema = z.object({
@@ -1549,12 +1463,6 @@ const secretValueSchema = z.object({
1549
1463
  vaultName: z.string(),
1550
1464
  secretKey: z.string()
1551
1465
  });
1552
- const samlBaseSchema = z.object({
1553
- name: z.string(),
1554
- kind: z.literal("SAML"),
1555
- spCertBase64: secretValueSchema.optional(),
1556
- spKeyBase64: secretValueSchema.optional()
1557
- });
1558
1466
  const OIDCSchema = z.object({
1559
1467
  name: z.string(),
1560
1468
  kind: z.literal("OIDC"),
@@ -1564,7 +1472,10 @@ const OIDCSchema = z.object({
1564
1472
  issuerURL: z.string().optional(),
1565
1473
  usernameClaim: z.string().optional()
1566
1474
  });
1567
- const SAMLSchema = samlBaseSchema.extend({
1475
+ const SAMLSchema = z.object({
1476
+ name: z.string(),
1477
+ kind: z.literal("SAML"),
1478
+ enableSignRequest: z.boolean().default(false),
1568
1479
  metadataURL: z.string().optional(),
1569
1480
  rawMetadata: z.string().optional()
1570
1481
  }).refine((value) => {
@@ -1713,6 +1624,100 @@ const AuthConfigSchema = z.object({
1713
1624
  tenantProvider: TenantProviderSchema.optional()
1714
1625
  }).brand("AuthConfig");
1715
1626
 
1627
+ //#endregion
1628
+ //#region src/cli/application/auth/service.ts
1629
+ var AuthService = class {
1630
+ _userProfile;
1631
+ _tenantProvider;
1632
+ _parsedConfig;
1633
+ constructor(config, tailorDBServices) {
1634
+ this.config = config;
1635
+ this.tailorDBServices = tailorDBServices;
1636
+ this._parsedConfig = {
1637
+ ...config,
1638
+ idProvider: IdProviderSchema.optional().parse(config.idProvider)
1639
+ };
1640
+ }
1641
+ get userProfile() {
1642
+ return this._userProfile;
1643
+ }
1644
+ get tenantProvider() {
1645
+ return this._tenantProvider;
1646
+ }
1647
+ get parsedConfig() {
1648
+ return this._parsedConfig;
1649
+ }
1650
+ async resolveNamespaces() {
1651
+ await Promise.all(this.tailorDBServices.map((service) => service.loadTypes()));
1652
+ if (this.tailorDBServices.length === 1) {
1653
+ const singleNamespace = this.tailorDBServices[0].namespace;
1654
+ this._userProfile = this.config.userProfile ? {
1655
+ ...this.config.userProfile,
1656
+ namespace: singleNamespace
1657
+ } : void 0;
1658
+ this._tenantProvider = this.config.tenantProvider ? {
1659
+ ...this.config.tenantProvider,
1660
+ namespace: singleNamespace
1661
+ } : void 0;
1662
+ return;
1663
+ }
1664
+ const userProfileTypeName = this.config.userProfile?.type && typeof this.config.userProfile.type === "object" && "name" in this.config.userProfile.type ? this.config.userProfile.type.name : void 0;
1665
+ const tenantProviderTypeName = typeof this.config.tenantProvider?.type === "string" ? this.config.tenantProvider.type : void 0;
1666
+ let userProfileNamespace;
1667
+ let tenantProviderNamespace;
1668
+ for (const service of this.tailorDBServices) {
1669
+ const types$2 = service.getTypes();
1670
+ if (userProfileTypeName && !userProfileNamespace && Object.prototype.hasOwnProperty.call(types$2, userProfileTypeName)) userProfileNamespace = service.namespace;
1671
+ if (tenantProviderTypeName && !tenantProviderNamespace && Object.prototype.hasOwnProperty.call(types$2, tenantProviderTypeName)) tenantProviderNamespace = service.namespace;
1672
+ if (userProfileNamespace && tenantProviderNamespace) break;
1673
+ }
1674
+ if (this.config.userProfile && !userProfileNamespace) throw new Error(`userProfile type "${this.config.userProfile.type.name}" not found in any TailorDB namespace`);
1675
+ if (this.config.tenantProvider && !tenantProviderNamespace) throw new Error(`tenantProvider type "${this.config.tenantProvider.type}" not found in any TailorDB namespace`);
1676
+ this._userProfile = this.config.userProfile ? {
1677
+ ...this.config.userProfile,
1678
+ namespace: userProfileNamespace
1679
+ } : void 0;
1680
+ this._tenantProvider = this.config.tenantProvider ? {
1681
+ ...this.config.tenantProvider,
1682
+ namespace: tenantProviderNamespace
1683
+ } : void 0;
1684
+ }
1685
+ };
1686
+
1687
+ //#endregion
1688
+ //#region src/cli/application/file-loader.ts
1689
+ const DEFAULT_IGNORE_PATTERNS = ["**/*.test.ts", "**/*.spec.ts"];
1690
+ /**
1691
+ * Load files matching the given patterns, excluding files that match ignore patterns.
1692
+ * By default, test files (*.test.ts, *.spec.ts) are excluded unless ignores is explicitly specified.
1693
+ *
1694
+ * @param config - Configuration with files patterns and optional ignores patterns
1695
+ * @returns Array of absolute file paths
1696
+ */
1697
+ function loadFilesWithIgnores(config) {
1698
+ const ignorePatterns = config.ignores ?? DEFAULT_IGNORE_PATTERNS;
1699
+ const ignoreFiles = /* @__PURE__ */ new Set();
1700
+ for (const ignorePattern of ignorePatterns) {
1701
+ const absoluteIgnorePattern = path$20.resolve(process.cwd(), ignorePattern);
1702
+ try {
1703
+ fs$15.globSync(absoluteIgnorePattern).forEach((file) => ignoreFiles.add(file));
1704
+ } catch (error) {
1705
+ logger.warn(`Failed to glob ignore pattern "${ignorePattern}": ${String(error)}`);
1706
+ }
1707
+ }
1708
+ const files = [];
1709
+ for (const pattern of config.files) {
1710
+ const absolutePattern = path$20.resolve(process.cwd(), pattern);
1711
+ try {
1712
+ const filteredFiles = fs$15.globSync(absolutePattern).filter((file) => !ignoreFiles.has(file));
1713
+ files.push(...filteredFiles);
1714
+ } catch (error) {
1715
+ logger.warn(`Failed to glob pattern "${pattern}": ${String(error)}`);
1716
+ }
1717
+ }
1718
+ return files;
1719
+ }
1720
+
1716
1721
  //#endregion
1717
1722
  //#region src/parser/service/common.ts
1718
1723
  const functionSchema = z.custom((val) => typeof val === "function");
@@ -1915,6 +1920,65 @@ var ResolverService = class {
1915
1920
  }
1916
1921
  };
1917
1922
 
1923
+ //#endregion
1924
+ //#region src/parser/service/tailordb/field.ts
1925
+ const tailorUserMap = `{ id: user.id, type: user.type, workspaceId: user.workspace_id, attributes: user.attribute_map, attributeList: user.attributes }`;
1926
+ /**
1927
+ * Convert a function to a string representation.
1928
+ * Handles method shorthand syntax (e.g., `create() { ... }`) by converting it to
1929
+ * a function expression (e.g., `function create() { ... }`).
1930
+ */
1931
+ const stringifyFunction = (fn) => {
1932
+ const src = fn.toString().trim();
1933
+ if (/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/.test(src) && !src.startsWith("function") && !src.startsWith("(") && !src.includes("=>")) return `function ${src}`;
1934
+ return src;
1935
+ };
1936
+ /**
1937
+ * Convert a hook function to a script expression.
1938
+ */
1939
+ const convertHookToExpr = (fn) => {
1940
+ return `(${stringifyFunction(fn)})({ value: _value, data: _data, user: ${tailorUserMap} })`;
1941
+ };
1942
+ /**
1943
+ * Parse TailorDBField into OperatorFieldConfig.
1944
+ * This transforms user-defined functions into script expressions.
1945
+ */
1946
+ function parseFieldConfig(field) {
1947
+ const metadata = field.metadata;
1948
+ const fieldType = field.type;
1949
+ const nestedFields = field.fields;
1950
+ return {
1951
+ type: fieldType,
1952
+ ...metadata,
1953
+ ...fieldType === "nested" && nestedFields && Object.keys(nestedFields).length > 0 ? { fields: Object.entries(nestedFields).reduce((acc, [key, nestedField]) => {
1954
+ acc[key] = parseFieldConfig(nestedField);
1955
+ return acc;
1956
+ }, {}) } : {},
1957
+ validate: metadata.validate?.map((v$1) => {
1958
+ const { fn, message } = typeof v$1 === "function" ? {
1959
+ fn: v$1,
1960
+ message: `failed by \`${v$1.toString().trim()}\``
1961
+ } : {
1962
+ fn: v$1[0],
1963
+ message: v$1[1]
1964
+ };
1965
+ return {
1966
+ script: { expr: `(${fn.toString().trim()})({ value: _value, data: _data, user: ${tailorUserMap} })` },
1967
+ errorMessage: message
1968
+ };
1969
+ }),
1970
+ hooks: metadata.hooks ? {
1971
+ create: metadata.hooks.create ? { expr: convertHookToExpr(metadata.hooks.create) } : void 0,
1972
+ update: metadata.hooks.update ? { expr: convertHookToExpr(metadata.hooks.update) } : void 0
1973
+ } : void 0,
1974
+ serial: metadata.serial ? {
1975
+ start: metadata.serial.start,
1976
+ maxValue: metadata.serial.maxValue,
1977
+ format: "format" in metadata.serial ? metadata.serial.format : void 0
1978
+ } : void 0
1979
+ };
1980
+ }
1981
+
1918
1982
  //#endregion
1919
1983
  //#region ../../node_modules/eslint/package.json
1920
1984
  var require_package$3 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -98049,6 +98113,176 @@ function ensureNoExternalVariablesInFieldScripts(typeName, fieldName, fieldConfi
98049
98113
  });
98050
98114
  }
98051
98115
 
98116
+ //#endregion
98117
+ //#region src/parser/service/tailordb/permission.ts
98118
+ const operatorMap = {
98119
+ "=": "eq",
98120
+ "!=": "ne",
98121
+ in: "in",
98122
+ "not in": "nin"
98123
+ };
98124
+ function normalizeOperand(operand) {
98125
+ if (typeof operand === "object" && "user" in operand) return { user: operand.user === "id" ? "_id" : operand.user };
98126
+ return operand;
98127
+ }
98128
+ function normalizeConditions(conditions) {
98129
+ return conditions.map((cond) => {
98130
+ const [left, operator, right] = cond;
98131
+ return [
98132
+ normalizeOperand(left),
98133
+ operatorMap[operator],
98134
+ normalizeOperand(right)
98135
+ ];
98136
+ });
98137
+ }
98138
+ function isObjectFormat(p$1) {
98139
+ return typeof p$1 === "object" && p$1 !== null && "conditions" in p$1;
98140
+ }
98141
+ function isSingleArrayConditionFormat(cond) {
98142
+ return cond.length >= 2 && typeof cond[1] === "string";
98143
+ }
98144
+ function normalizePermission(permission) {
98145
+ return Object.keys(permission).reduce((acc, action) => {
98146
+ acc[action] = permission[action].map((p$1) => normalizeActionPermission(p$1));
98147
+ return acc;
98148
+ }, {});
98149
+ }
98150
+ function normalizeGqlPermission(permission) {
98151
+ return permission.map((policy) => normalizeGqlPolicy(policy));
98152
+ }
98153
+ function normalizeGqlPolicy(policy) {
98154
+ return {
98155
+ conditions: policy.conditions ? normalizeConditions(policy.conditions) : [],
98156
+ actions: policy.actions === "all" ? ["all"] : policy.actions,
98157
+ permit: policy.permit ? "allow" : "deny",
98158
+ description: policy.description
98159
+ };
98160
+ }
98161
+ /**
98162
+ * Parse raw permissions into normalized permissions.
98163
+ * This is the main entry point for permission parsing in the parser layer.
98164
+ */
98165
+ function parsePermissions(rawPermissions) {
98166
+ return {
98167
+ ...rawPermissions.record && { record: normalizePermission(rawPermissions.record) },
98168
+ ...rawPermissions.gql && { gql: normalizeGqlPermission(rawPermissions.gql) }
98169
+ };
98170
+ }
98171
+ function normalizeActionPermission(permission) {
98172
+ if (isObjectFormat(permission)) {
98173
+ const conditions$1 = permission.conditions;
98174
+ return {
98175
+ conditions: normalizeConditions(isSingleArrayConditionFormat(conditions$1) ? [conditions$1] : conditions$1),
98176
+ permit: permission.permit ? "allow" : "deny",
98177
+ description: permission.description
98178
+ };
98179
+ }
98180
+ if (!Array.isArray(permission)) throw new Error("Invalid permission format");
98181
+ if (isSingleArrayConditionFormat(permission)) {
98182
+ const [op1, operator, op2, permit] = [...permission, true];
98183
+ return {
98184
+ conditions: normalizeConditions([[
98185
+ op1,
98186
+ operator,
98187
+ op2
98188
+ ]]),
98189
+ permit: permit ? "allow" : "deny"
98190
+ };
98191
+ }
98192
+ const conditions = [];
98193
+ const conditionArray = permission;
98194
+ let conditionArrayPermit = true;
98195
+ for (const item of conditionArray) {
98196
+ if (typeof item === "boolean") {
98197
+ conditionArrayPermit = item;
98198
+ continue;
98199
+ }
98200
+ conditions.push(item);
98201
+ }
98202
+ return {
98203
+ conditions: normalizeConditions(conditions),
98204
+ permit: conditionArrayPermit ? "allow" : "deny"
98205
+ };
98206
+ }
98207
+
98208
+ //#endregion
98209
+ //#region src/parser/service/tailordb/type-parser.ts
98210
+ /**
98211
+ * Parse a TailorDBType into a ParsedTailorDBType.
98212
+ * This is the main entry point for parsing TailorDB types in the parser layer.
98213
+ */
98214
+ function parseTailorDBType(type) {
98215
+ const metadata = type.metadata;
98216
+ const pluralForm = metadata.settings?.pluralForm || inflection.pluralize(type.name);
98217
+ const fields = {};
98218
+ const forwardRelationships = {};
98219
+ for (const [fieldName, fieldDef] of Object.entries(type.fields)) {
98220
+ const fieldConfig = parseFieldConfig(fieldDef);
98221
+ ensureNoExternalVariablesInFieldScripts(type.name, fieldName, fieldConfig);
98222
+ const parsedField = {
98223
+ name: fieldName,
98224
+ config: fieldConfig
98225
+ };
98226
+ const ref$1 = fieldDef.reference;
98227
+ if (ref$1) {
98228
+ const targetType = ref$1.type?.name;
98229
+ if (targetType) {
98230
+ const forwardName = ref$1.nameMap?.[0] || inflection.camelize(targetType, true);
98231
+ const backwardName = ref$1.nameMap?.[1] || "";
98232
+ const key = ref$1.key || "id";
98233
+ parsedField.relation = {
98234
+ targetType,
98235
+ forwardName,
98236
+ backwardName,
98237
+ key,
98238
+ unique: fieldDef.metadata?.unique ?? false
98239
+ };
98240
+ forwardRelationships[forwardName] = {
98241
+ name: forwardName,
98242
+ targetType,
98243
+ targetField: fieldName,
98244
+ sourceField: key,
98245
+ isArray: false,
98246
+ description: ref$1.type?.metadata?.description || ""
98247
+ };
98248
+ }
98249
+ }
98250
+ fields[fieldName] = parsedField;
98251
+ }
98252
+ return {
98253
+ name: type.name,
98254
+ pluralForm,
98255
+ description: metadata.description,
98256
+ fields,
98257
+ forwardRelationships,
98258
+ backwardRelationships: {},
98259
+ settings: metadata.settings || {},
98260
+ permissions: parsePermissions(metadata.permissions || {}),
98261
+ indexes: metadata.indexes,
98262
+ files: metadata.files
98263
+ };
98264
+ }
98265
+ /**
98266
+ * Build backward relationships between parsed types.
98267
+ */
98268
+ function buildBackwardRelationships(types$2) {
98269
+ for (const [typeName, type] of Object.entries(types$2)) for (const [otherTypeName, otherType] of Object.entries(types$2)) for (const [fieldName, field] of Object.entries(otherType.fields)) if (field.relation && field.relation.targetType === typeName) {
98270
+ let backwardName = field.relation.backwardName;
98271
+ if (!backwardName) {
98272
+ const lowerName = inflection.camelize(otherTypeName, true);
98273
+ backwardName = field.relation.unique ? inflection.singularize(lowerName) : inflection.pluralize(lowerName);
98274
+ }
98275
+ type.backwardRelationships[backwardName] = {
98276
+ name: backwardName,
98277
+ targetType: otherTypeName,
98278
+ targetField: fieldName,
98279
+ sourceField: field.relation.key,
98280
+ isArray: !field.relation.unique,
98281
+ description: otherType.description || ""
98282
+ };
98283
+ }
98284
+ }
98285
+
98052
98286
  //#endregion
98053
98287
  //#region src/cli/application/tailordb/service.ts
98054
98288
  var TailorDBService = class {
@@ -98110,77 +98344,8 @@ var TailorDBService = class {
98110
98344
  const allTypes = {};
98111
98345
  for (const fileTypes of Object.values(this.rawTypes)) for (const [typeName, type] of Object.entries(fileTypes)) allTypes[typeName] = type;
98112
98346
  this.types = {};
98113
- for (const [typeName, type] of Object.entries(allTypes)) this.types[typeName] = this.parseTailorDBType(type);
98114
- this.buildBackwardRelationships(this.types);
98115
- }
98116
- parseTailorDBType(type) {
98117
- const schema = type.metadata.schema;
98118
- const pluralForm = schema?.settings?.pluralForm || inflection.pluralize(type.name);
98119
- const fields = {};
98120
- const forwardRelationships = {};
98121
- for (const [fieldName, fieldDef] of Object.entries(type.fields)) {
98122
- const fieldConfig = schema.fields?.[fieldName];
98123
- if (!fieldConfig) continue;
98124
- ensureNoExternalVariablesInFieldScripts(type.name, fieldName, fieldConfig);
98125
- const parsedField = {
98126
- name: fieldName,
98127
- config: fieldConfig
98128
- };
98129
- const ref$1 = fieldDef.reference;
98130
- if (ref$1) {
98131
- const targetType = ref$1.type?.name;
98132
- if (targetType) {
98133
- const forwardName = ref$1.nameMap?.[0] || inflection.camelize(targetType, true);
98134
- const backwardName = ref$1.nameMap?.[1] || "";
98135
- const key = ref$1.key || "id";
98136
- parsedField.relation = {
98137
- targetType,
98138
- forwardName,
98139
- backwardName,
98140
- key,
98141
- unique: fieldDef.metadata?.unique ?? false
98142
- };
98143
- forwardRelationships[forwardName] = {
98144
- name: forwardName,
98145
- targetType,
98146
- targetField: fieldName,
98147
- sourceField: key,
98148
- isArray: false,
98149
- description: ref$1.type?.metadata?.description || ""
98150
- };
98151
- }
98152
- }
98153
- fields[fieldName] = parsedField;
98154
- }
98155
- return {
98156
- name: type.name,
98157
- pluralForm,
98158
- description: schema?.description,
98159
- fields,
98160
- forwardRelationships,
98161
- backwardRelationships: {},
98162
- settings: schema?.settings || {},
98163
- permissions: schema?.permissions || {},
98164
- indexes: schema?.indexes,
98165
- files: schema?.files
98166
- };
98167
- }
98168
- buildBackwardRelationships(types$2) {
98169
- for (const [typeName, type] of Object.entries(types$2)) for (const [otherTypeName, otherType] of Object.entries(types$2)) for (const [fieldName, field] of Object.entries(otherType.fields)) if (field.relation && field.relation.targetType === typeName) {
98170
- let backwardName = field.relation.backwardName;
98171
- if (!backwardName) {
98172
- const lowerName = inflection.camelize(otherTypeName, true);
98173
- backwardName = field.relation.unique ? inflection.singularize(lowerName) : inflection.pluralize(lowerName);
98174
- }
98175
- type.backwardRelationships[backwardName] = {
98176
- name: backwardName,
98177
- targetType: otherTypeName,
98178
- targetField: fieldName,
98179
- sourceField: field.relation.key,
98180
- isArray: !field.relation.unique,
98181
- description: otherType.description || ""
98182
- };
98183
- }
98347
+ for (const [typeName, type] of Object.entries(allTypes)) this.types[typeName] = parseTailorDBType(type);
98348
+ buildBackwardRelationships(this.types);
98184
98349
  }
98185
98350
  };
98186
98351
 
@@ -99943,9 +100108,9 @@ var TypeProcessor = class {
99943
100108
  Serial: false
99944
100109
  }
99945
100110
  };
99946
- const fieldResults = Object.entries(fields).map(([fieldName, nestedFieldConfig]) => ({
100111
+ const fieldResults = Object.entries(fields).map(([fieldName, nestedOperatorFieldConfig]) => ({
99947
100112
  fieldName,
99948
- ...this.generateFieldType(nestedFieldConfig)
100113
+ ...this.generateFieldType(nestedOperatorFieldConfig)
99949
100114
  }));
99950
100115
  const fieldTypes = fieldResults.map((result) => `${result.fieldName}: ${result.type}`);
99951
100116
  const aggregatedUtilityTypes = fieldResults.reduce((acc, result) => ({
@@ -101051,7 +101216,8 @@ async function planServices$2(client, workspaceId, appName, auths) {
101051
101216
  label: metadata?.labels[sdkNameLabelKey]
101052
101217
  };
101053
101218
  }));
101054
- for (const { config } of auths) {
101219
+ for (const auth of auths) {
101220
+ const { parsedConfig: config } = auth;
101055
101221
  const existing = existingServices[config.name];
101056
101222
  const metaRequest = await buildMetaRequest(trn$5(workspaceId, config.name), appName);
101057
101223
  if (existing) {
@@ -101113,7 +101279,8 @@ async function planIdPConfigs(client, workspaceId, auths, deletedServices) {
101113
101279
  }
101114
101280
  });
101115
101281
  };
101116
- for (const { config } of auths) {
101282
+ for (const authService of auths) {
101283
+ const { parsedConfig: config } = authService;
101117
101284
  const existingIdPConfigs = await fetchIdPConfigs(config.name);
101118
101285
  const existingNameSet = /* @__PURE__ */ new Set();
101119
101286
  existingIdPConfigs.forEach((idpConfig$1) => {
@@ -101185,14 +101352,7 @@ function protoIdPConfig(idpConfig) {
101185
101352
  case: "saml",
101186
101353
  value: {
101187
101354
  ...idpConfig.metadataURL !== void 0 ? { metadataUrl: idpConfig.metadataURL } : { rawMetadata: idpConfig.rawMetadata },
101188
- ...idpConfig.spCertBase64 && { spCertBase64: {
101189
- vaultName: idpConfig.spCertBase64.vaultName,
101190
- secretKey: idpConfig.spCertBase64.secretKey
101191
- } },
101192
- ...idpConfig.spKeyBase64 && { spKeyBase64: {
101193
- vaultName: idpConfig.spKeyBase64.vaultName,
101194
- secretKey: idpConfig.spKeyBase64.secretKey
101195
- } }
101355
+ enableSignRequest: idpConfig.enableSignRequest
101196
101356
  }
101197
101357
  } }
101198
101358
  };
@@ -101255,11 +101415,12 @@ async function protoBuiltinIdPConfig(client, workspaceId, builtinIdPConfig) {
101255
101415
  async function planUserProfileConfigs(client, workspaceId, auths, deletedServices) {
101256
101416
  const changeSet = new ChangeSet("Auth userProfileConfigs");
101257
101417
  for (const auth of auths) {
101258
- const name$1 = `${auth.config.name}-user-profile-config`;
101418
+ const { parsedConfig: config } = auth;
101419
+ const name$1 = `${config.name}-user-profile-config`;
101259
101420
  try {
101260
101421
  await client.getUserProfileConfig({
101261
101422
  workspaceId,
101262
- namespaceName: auth.config.name
101423
+ namespaceName: config.name
101263
101424
  });
101264
101425
  } catch (error) {
101265
101426
  if (error instanceof ConnectError && error.code === Code.NotFound) {
@@ -101267,7 +101428,7 @@ async function planUserProfileConfigs(client, workspaceId, auths, deletedService
101267
101428
  name: name$1,
101268
101429
  request: {
101269
101430
  workspaceId,
101270
- namespaceName: auth.config.name,
101431
+ namespaceName: config.name,
101271
101432
  userProfileProviderConfig: protoUserProfileConfig(auth.userProfile)
101272
101433
  }
101273
101434
  });
@@ -101279,7 +101440,7 @@ async function planUserProfileConfigs(client, workspaceId, auths, deletedService
101279
101440
  name: name$1,
101280
101441
  request: {
101281
101442
  workspaceId,
101282
- namespaceName: auth.config.name,
101443
+ namespaceName: config.name,
101283
101444
  userProfileProviderConfig: protoUserProfileConfig(auth.userProfile)
101284
101445
  }
101285
101446
  });
@@ -101287,7 +101448,7 @@ async function planUserProfileConfigs(client, workspaceId, auths, deletedService
101287
101448
  name: name$1,
101288
101449
  request: {
101289
101450
  workspaceId,
101290
- namespaceName: auth.config.name
101451
+ namespaceName: config.name
101291
101452
  }
101292
101453
  });
101293
101454
  }
@@ -101332,11 +101493,12 @@ function protoUserProfileConfig(userProfile) {
101332
101493
  async function planTenantConfigs(client, workspaceId, auths, deletedServices) {
101333
101494
  const changeSet = new ChangeSet("Auth tenantConfigs");
101334
101495
  for (const auth of auths) {
101335
- const name$1 = `${auth.config.name}-tenant-config`;
101496
+ const { parsedConfig: config } = auth;
101497
+ const name$1 = `${config.name}-tenant-config`;
101336
101498
  try {
101337
101499
  await client.getTenantConfig({
101338
101500
  workspaceId,
101339
- namespaceName: auth.config.name
101501
+ namespaceName: config.name
101340
101502
  });
101341
101503
  } catch (error) {
101342
101504
  if (error instanceof ConnectError && error.code === Code.NotFound) {
@@ -101344,7 +101506,7 @@ async function planTenantConfigs(client, workspaceId, auths, deletedServices) {
101344
101506
  name: name$1,
101345
101507
  request: {
101346
101508
  workspaceId,
101347
- namespaceName: auth.config.name,
101509
+ namespaceName: config.name,
101348
101510
  tenantProviderConfig: protoTenantConfig(auth.tenantProvider)
101349
101511
  }
101350
101512
  });
@@ -101356,7 +101518,7 @@ async function planTenantConfigs(client, workspaceId, auths, deletedServices) {
101356
101518
  name: name$1,
101357
101519
  request: {
101358
101520
  workspaceId,
101359
- namespaceName: auth.config.name,
101521
+ namespaceName: config.name,
101360
101522
  tenantProviderConfig: protoTenantConfig(auth.tenantProvider)
101361
101523
  }
101362
101524
  });
@@ -101364,7 +101526,7 @@ async function planTenantConfigs(client, workspaceId, auths, deletedServices) {
101364
101526
  name: name$1,
101365
101527
  request: {
101366
101528
  workspaceId,
101367
- namespaceName: auth.config.name
101529
+ namespaceName: config.name
101368
101530
  }
101369
101531
  });
101370
101532
  }
@@ -101418,7 +101580,8 @@ async function planMachineUsers(client, workspaceId, auths, deletedServices) {
101418
101580
  }
101419
101581
  });
101420
101582
  };
101421
- for (const { config } of auths) {
101583
+ for (const auth of auths) {
101584
+ const { parsedConfig: config } = auth;
101422
101585
  const existingMachineUsers = await fetchMachineUsers(config.name);
101423
101586
  const existingNameSet = /* @__PURE__ */ new Set();
101424
101587
  existingMachineUsers.forEach((machineUser) => {
@@ -101495,7 +101658,8 @@ async function planOAuth2Clients(client, workspaceId, auths, deletedServices) {
101495
101658
  }
101496
101659
  });
101497
101660
  };
101498
- for (const { config } of auths) {
101661
+ for (const auth of auths) {
101662
+ const { parsedConfig: config } = auth;
101499
101663
  const existingOAuth2Clients = await fetchOAuth2Clients(config.name);
101500
101664
  const existingNameSet = /* @__PURE__ */ new Set();
101501
101665
  existingOAuth2Clients.forEach((oauth2Client) => {
@@ -101570,7 +101734,8 @@ function protoOAuth2Client(oauth2ClientName, oauth2Client) {
101570
101734
  }
101571
101735
  async function planSCIMConfigs(client, workspaceId, auths, deletedServices) {
101572
101736
  const changeSet = new ChangeSet("Auth scimConfigs");
101573
- for (const { config } of auths) {
101737
+ for (const auth of auths) {
101738
+ const { parsedConfig: config } = auth;
101574
101739
  const name$1 = `${config.name}-scim-config`;
101575
101740
  try {
101576
101741
  await client.getAuthSCIMConfig({
@@ -101664,7 +101829,8 @@ async function planSCIMResources(client, workspaceId, auths, deletedServices) {
101664
101829
  throw error;
101665
101830
  }
101666
101831
  };
101667
- for (const { config } of auths) {
101832
+ for (const auth of auths) {
101833
+ const { parsedConfig: config } = auth;
101668
101834
  const existingSCIMResources = await fetchSCIMResources(config.name);
101669
101835
  const existingNameSet = /* @__PURE__ */ new Set();
101670
101836
  existingSCIMResources.forEach((scimResource) => {
@@ -101811,16 +101977,18 @@ async function confirmOwnerConflict(conflicts, appName, yes) {
101811
101977
  }
101812
101978
  async function confirmUnmanagedResources(resources, appName, yes) {
101813
101979
  if (resources.length === 0) return;
101814
- logger.warn("Unmanaged resources detected:");
101980
+ logger.warn("Existing resources not tracked by tailor-sdk were found:");
101815
101981
  logger.log(` ${styles.info("Resources")}:`);
101816
101982
  for (const r$1 of resources) logger.log(` • ${styles.bold(r$1.resourceType)} ${styles.info(`"${r$1.resourceName}"`)}`);
101817
101983
  logger.newline();
101818
- logger.log(" These resources are not managed by any application.");
101984
+ logger.log(" These resources may have been created by older SDK versions, Terraform, or CUE.");
101985
+ logger.log(" To continue, confirm that tailor-sdk should manage them.");
101986
+ logger.log(" If they are managed by another tool (e.g., Terraform), cancel and manage them there instead.");
101819
101987
  if (yes) {
101820
101988
  logger.success(`Adding to "${appName}" (--yes flag specified)...`, { mode: "plain" });
101821
101989
  return;
101822
101990
  }
101823
- if (!await logger.prompt(`Add these resources to "${appName}"?`, {
101991
+ if (!await logger.prompt(`Allow tailor-sdk to manage these resources for "${appName}"?`, {
101824
101992
  type: "confirm",
101825
101993
  initial: false
101826
101994
  })) throw new Error(ml`
@@ -101850,20 +102018,6 @@ async function confirmImportantResourceDeletion(resources, yes) {
101850
102018
 
101851
102019
  //#endregion
101852
102020
  //#region src/cli/apply/services/executor.ts
101853
- /**
101854
- * Convert a function to a string representation.
101855
- * Handles method shorthand syntax (e.g., `requestBody() { ... }`) by converting it to
101856
- * a function expression (e.g., `function requestBody() { ... }`).
101857
- *
101858
- * TODO: This function should be moved to the parser module.
101859
- * The same function exists in `src/configure/services/tailordb/schema.ts`.
101860
- * These should be unified into a common utility in the parser layer.
101861
- */
101862
- const stringifyFunction = (fn) => {
101863
- const src = fn.toString().trim();
101864
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/.test(src) && !src.startsWith("function") && !src.startsWith("(") && !src.includes("=>")) return `function ${src}`;
101865
- return src;
101866
- };
101867
102021
  async function applyExecutor(client, result, phase = "create-update") {
101868
102022
  const { changeSet } = result;
101869
102023
  if (phase === "create-update") await Promise.all([...changeSet.creates.map(async (create$1) => {
@@ -102860,7 +103014,7 @@ function protoOperand(operand) {
102860
103014
  case: "oldRecordField",
102861
103015
  value: operand.oldRecord
102862
103016
  } };
102863
- else throw new Error(`Unknown operand: ${operand}`);
103017
+ else throw new Error(`Unknown operand: ${JSON.stringify(operand)}`);
102864
103018
  return { kind: {
102865
103019
  case: "value",
102866
103020
  value: fromJson(ValueSchema, operand)
@@ -103014,7 +103168,7 @@ function protoGqlOperand(operand) {
103014
103168
  case: "userField",
103015
103169
  value: operand.user
103016
103170
  } };
103017
- else throw new Error(`Unknown operand: ${operand}`);
103171
+ else throw new Error(`Unknown operand: ${JSON.stringify(operand)}`);
103018
103172
  return { kind: {
103019
103173
  case: "value",
103020
103174
  value: fromJson(ValueSchema, operand)
@@ -103933,7 +104087,7 @@ var GenerationManager = class {
103933
104087
  getAuthInput() {
103934
104088
  const authService = this.application.authService;
103935
104089
  if (!authService) return void 0;
103936
- const config = authService.config;
104090
+ const config = authService.parsedConfig;
103937
104091
  return {
103938
104092
  name: config.name,
103939
104093
  userProfile: authService.userProfile ? {
@@ -105408,4 +105562,4 @@ const listCommand = defineCommand({
105408
105562
 
105409
105563
  //#endregion
105410
105564
  export { jsonArgs as $, printData as A, loadAccessToken as B, listOAuth2Clients as C, tokenCommand as D, getMachineUserToken as E, generateUserTypes as F, fetchUserInfo as G, readPlatformConfig as H, loadConfig as I, readPackageJson as J, initOAuth2Client as K, apiCall as L, generateCommand as M, apply as N, listCommand$3 as O, applyCommand as P, deploymentArgs as Q, apiCommand as R, listCommand$2 as S, getOAuth2Client as T, writePlatformConfig as U, loadWorkspaceId as V, fetchAll as W, commonArgs as X, PATScope as Y, confirmationArgs as Z, listWorkflowExecutions as _, createCommand as a, remove as b, resumeWorkflow as c, listCommand$1 as d, withCommonArgs as et, listWorkflows as f, getWorkflowExecution as g, executionsCommand as h, deleteWorkspace as i, generate as j, listMachineUsers as k, startCommand as l, getWorkflow as m, listWorkspaces as n, logger as nt, createWorkspace as o, getCommand as p, initOperatorClient as q, deleteCommand as r, resumeCommand as s, listCommand as t, workspaceArgs as tt, startWorkflow as u, show as v, getCommand$1 as w, removeCommand as x, showCommand as y, fetchLatestToken as z };
105411
- //# sourceMappingURL=list-B11wQhss.mjs.map
105565
+ //# sourceMappingURL=list-BHj1dQPk.mjs.map