@tailor-platform/sdk 0.22.2 → 0.22.4

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,10 +1,10 @@
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 } from "./config-BYrX78K0.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";
6
6
  import path from "node:path";
7
- import process$1, { loadEnvFile } from "node:process";
7
+ import { loadEnvFile } from "node:process";
8
8
  import { z } from "zod";
9
9
  import chalk from "chalk";
10
10
  import { createConsola } from "consola";
@@ -19,13 +19,14 @@ import fs from "node:fs";
19
19
  import * as os$3 from "node:os";
20
20
  import os from "node:os";
21
21
  import { parseTOML, parseYAML, stringifyYAML } from "confbox";
22
- import fsPromises, { glob } from "node:fs/promises";
23
- import { fileURLToPath, pathToFileURL } from "node:url";
22
+ import { findUpSync } from "find-up-simple";
24
23
  import ml from "multiline-ts";
25
24
  import { xdgConfig } from "xdg-basedir";
26
- import * as inflection from "inflection";
25
+ import { pathToFileURL } from "node:url";
26
+ import { glob } from "node:fs/promises";
27
27
  import util from "node:util";
28
28
  import assert from "node:assert";
29
+ import * as inflection from "inflection";
29
30
  import * as rolldown from "rolldown";
30
31
  import { parseSync } from "oxc-parser";
31
32
  import { create, fromJson } from "@bufbuild/protobuf";
@@ -1211,25 +1212,6 @@ async function fetchMachineUserToken(url, clientId, clientSecret) {
1211
1212
  }).parse(rawJson);
1212
1213
  }
1213
1214
 
1214
- //#endregion
1215
- //#region ../../node_modules/find-up-simple/index.js
1216
- const toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
1217
- function findUpSync(name$1, { cwd = process$1.cwd(), type = "file", stopAt } = {}) {
1218
- let directory = path.resolve(toPath(cwd) ?? "");
1219
- const { root } = path.parse(directory);
1220
- stopAt = path.resolve(directory, toPath(stopAt) ?? root);
1221
- const isAbsoluteName = path.isAbsolute(name$1);
1222
- while (directory) {
1223
- const filePath = isAbsoluteName ? name$1 : path.join(directory, name$1);
1224
- try {
1225
- const stats = fs.statSync(filePath, { throwIfNoEntry: false });
1226
- if (type === "file" && stats?.isFile() || type === "directory" && stats?.isDirectory()) return filePath;
1227
- } catch {}
1228
- if (directory === stopAt || directory === root) break;
1229
- directory = path.dirname(directory);
1230
- }
1231
- }
1232
-
1233
1215
  //#endregion
1234
1216
  //#region src/cli/context.ts
1235
1217
  const pfConfigSchema = z.object({
@@ -87997,7 +87979,7 @@ var require_eslint_helpers = /* @__PURE__ */ __commonJSMin(((exports, module) =>
87997
87979
  */
87998
87980
  async function globMatch({ basePath, pattern }) {
87999
87981
  let found = false;
88000
- const { hfs } = await import("./src-DqwtAff-.mjs");
87982
+ const { hfs } = await import("./src-BU1BDRRs.mjs");
88001
87983
  const matcher = new Minimatch(normalizeToPosix(path$9.relative(basePath, pattern)), MINIMATCH_OPTIONS);
88002
87984
  const walkSettings = {
88003
87985
  directoryFilter(entry) {
@@ -88044,7 +88026,7 @@ var require_eslint_helpers = /* @__PURE__ */ __commonJSMin(((exports, module) =>
88044
88026
  return new Minimatch(patternToUse, MINIMATCH_OPTIONS);
88045
88027
  });
88046
88028
  const unmatchedPatterns = new Set([...relativeToPatterns.keys()]);
88047
- const { hfs } = await import("./src-DqwtAff-.mjs");
88029
+ const { hfs } = await import("./src-BU1BDRRs.mjs");
88048
88030
  const walk = hfs.walk(basePath, {
88049
88031
  async directoryFilter(entry) {
88050
88032
  if (!matchers.some((matcher) => matcher.match(entry.path, true))) return false;
@@ -98113,6 +98095,230 @@ function ensureNoExternalVariablesInFieldScripts(typeName, fieldName, fieldConfi
98113
98095
  });
98114
98096
  }
98115
98097
 
98098
+ //#endregion
98099
+ //#region src/parser/service/tailordb/permission.ts
98100
+ const operatorMap = {
98101
+ "=": "eq",
98102
+ "!=": "ne",
98103
+ in: "in",
98104
+ "not in": "nin"
98105
+ };
98106
+ function normalizeOperand(operand) {
98107
+ if (typeof operand === "object" && "user" in operand) return { user: operand.user === "id" ? "_id" : operand.user };
98108
+ return operand;
98109
+ }
98110
+ function normalizeConditions(conditions) {
98111
+ return conditions.map((cond) => {
98112
+ const [left, operator, right] = cond;
98113
+ return [
98114
+ normalizeOperand(left),
98115
+ operatorMap[operator],
98116
+ normalizeOperand(right)
98117
+ ];
98118
+ });
98119
+ }
98120
+ function isObjectFormat(p$1) {
98121
+ return typeof p$1 === "object" && p$1 !== null && "conditions" in p$1;
98122
+ }
98123
+ function isSingleArrayConditionFormat(cond) {
98124
+ return cond.length >= 2 && typeof cond[1] === "string";
98125
+ }
98126
+ function normalizePermission(permission) {
98127
+ return Object.keys(permission).reduce((acc, action) => {
98128
+ acc[action] = permission[action].map((p$1) => normalizeActionPermission(p$1));
98129
+ return acc;
98130
+ }, {});
98131
+ }
98132
+ function normalizeGqlPermission(permission) {
98133
+ return permission.map((policy) => normalizeGqlPolicy(policy));
98134
+ }
98135
+ function normalizeGqlPolicy(policy) {
98136
+ return {
98137
+ conditions: policy.conditions ? normalizeConditions(policy.conditions) : [],
98138
+ actions: policy.actions === "all" ? ["all"] : policy.actions,
98139
+ permit: policy.permit ? "allow" : "deny",
98140
+ description: policy.description
98141
+ };
98142
+ }
98143
+ /**
98144
+ * Parse raw permissions into normalized permissions.
98145
+ * This is the main entry point for permission parsing in the parser layer.
98146
+ */
98147
+ function parsePermissions(rawPermissions) {
98148
+ return {
98149
+ ...rawPermissions.record && { record: normalizePermission(rawPermissions.record) },
98150
+ ...rawPermissions.gql && { gql: normalizeGqlPermission(rawPermissions.gql) }
98151
+ };
98152
+ }
98153
+ function normalizeActionPermission(permission) {
98154
+ if (isObjectFormat(permission)) {
98155
+ const conditions$1 = permission.conditions;
98156
+ return {
98157
+ conditions: normalizeConditions(isSingleArrayConditionFormat(conditions$1) ? [conditions$1] : conditions$1),
98158
+ permit: permission.permit ? "allow" : "deny",
98159
+ description: permission.description
98160
+ };
98161
+ }
98162
+ if (!Array.isArray(permission)) throw new Error("Invalid permission format");
98163
+ if (isSingleArrayConditionFormat(permission)) {
98164
+ const [op1, operator, op2, permit] = [...permission, true];
98165
+ return {
98166
+ conditions: normalizeConditions([[
98167
+ op1,
98168
+ operator,
98169
+ op2
98170
+ ]]),
98171
+ permit: permit ? "allow" : "deny"
98172
+ };
98173
+ }
98174
+ const conditions = [];
98175
+ const conditionArray = permission;
98176
+ let conditionArrayPermit = true;
98177
+ for (const item of conditionArray) {
98178
+ if (typeof item === "boolean") {
98179
+ conditionArrayPermit = item;
98180
+ continue;
98181
+ }
98182
+ conditions.push(item);
98183
+ }
98184
+ return {
98185
+ conditions: normalizeConditions(conditions),
98186
+ permit: conditionArrayPermit ? "allow" : "deny"
98187
+ };
98188
+ }
98189
+
98190
+ //#endregion
98191
+ //#region src/parser/service/tailordb/type-parser.ts
98192
+ /**
98193
+ * Parse multiple TailorDB types, build relationships, and validate uniqueness.
98194
+ * This is the main entry point for parsing TailorDB types.
98195
+ */
98196
+ function parseTypes(rawTypes, namespace, typeSourceInfo) {
98197
+ const types$2 = {};
98198
+ for (const [typeName, type] of Object.entries(rawTypes)) types$2[typeName] = parseTailorDBType(type);
98199
+ buildBackwardRelationships(types$2);
98200
+ validatePluralFormUniqueness(types$2, namespace, typeSourceInfo);
98201
+ return types$2;
98202
+ }
98203
+ /**
98204
+ * Parse a TailorDBType into a ParsedTailorDBType.
98205
+ */
98206
+ function parseTailorDBType(type) {
98207
+ const metadata = type.metadata;
98208
+ const pluralForm = metadata.settings?.pluralForm || inflection.pluralize(type.name);
98209
+ const fields = {};
98210
+ const forwardRelationships = {};
98211
+ for (const [fieldName, fieldDef] of Object.entries(type.fields)) {
98212
+ const fieldConfig = parseFieldConfig(fieldDef);
98213
+ ensureNoExternalVariablesInFieldScripts(type.name, fieldName, fieldConfig);
98214
+ const parsedField = {
98215
+ name: fieldName,
98216
+ config: fieldConfig
98217
+ };
98218
+ const ref$1 = fieldDef.reference;
98219
+ if (ref$1) {
98220
+ const targetType = ref$1.type?.name;
98221
+ if (targetType) {
98222
+ const forwardName = ref$1.nameMap?.[0] || inflection.camelize(targetType, true);
98223
+ const backwardName = ref$1.nameMap?.[1] || "";
98224
+ const key = ref$1.key || "id";
98225
+ parsedField.relation = {
98226
+ targetType,
98227
+ forwardName,
98228
+ backwardName,
98229
+ key,
98230
+ unique: fieldDef.metadata?.unique ?? false
98231
+ };
98232
+ forwardRelationships[forwardName] = {
98233
+ name: forwardName,
98234
+ targetType,
98235
+ targetField: fieldName,
98236
+ sourceField: key,
98237
+ isArray: false,
98238
+ description: ref$1.type?.metadata?.description || ""
98239
+ };
98240
+ }
98241
+ }
98242
+ fields[fieldName] = parsedField;
98243
+ }
98244
+ return {
98245
+ name: type.name,
98246
+ pluralForm,
98247
+ description: metadata.description,
98248
+ fields,
98249
+ forwardRelationships,
98250
+ backwardRelationships: {},
98251
+ settings: metadata.settings || {},
98252
+ permissions: parsePermissions(metadata.permissions || {}),
98253
+ indexes: metadata.indexes,
98254
+ files: metadata.files
98255
+ };
98256
+ }
98257
+ /**
98258
+ * Build backward relationships between parsed types.
98259
+ */
98260
+ function buildBackwardRelationships(types$2) {
98261
+ 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) {
98262
+ let backwardName = field.relation.backwardName;
98263
+ if (!backwardName) {
98264
+ const lowerName = inflection.camelize(otherTypeName, true);
98265
+ backwardName = field.relation.unique ? inflection.singularize(lowerName) : inflection.pluralize(lowerName);
98266
+ }
98267
+ type.backwardRelationships[backwardName] = {
98268
+ name: backwardName,
98269
+ targetType: otherTypeName,
98270
+ targetField: fieldName,
98271
+ sourceField: field.relation.key,
98272
+ isArray: !field.relation.unique,
98273
+ description: otherType.description || ""
98274
+ };
98275
+ }
98276
+ }
98277
+ /**
98278
+ * Validate GraphQL query field name uniqueness.
98279
+ * Checks for:
98280
+ * 1. Each type's singular query name != plural query name
98281
+ * 2. No duplicate query names across all types
98282
+ */
98283
+ function validatePluralFormUniqueness(types$2, namespace, typeSourceInfo) {
98284
+ const errors = [];
98285
+ for (const [, parsedType] of Object.entries(types$2)) {
98286
+ const singularQuery = inflection.camelize(parsedType.name, true);
98287
+ if (singularQuery === inflection.camelize(parsedType.pluralForm, true)) {
98288
+ const sourceInfo = typeSourceInfo?.[parsedType.name];
98289
+ const location = sourceInfo ? ` (${sourceInfo.filePath})` : "";
98290
+ errors.push(`Type "${parsedType.name}"${location} has identical singular and plural query names "${singularQuery}". Use db.type(["${parsedType.name}", "UniquePluralForm"], {...}) to set a unique pluralForm.`);
98291
+ }
98292
+ }
98293
+ const queryNameToSource = {};
98294
+ for (const parsedType of Object.values(types$2)) {
98295
+ const singularQuery = inflection.camelize(parsedType.name, true);
98296
+ const pluralQuery = inflection.camelize(parsedType.pluralForm, true);
98297
+ if (!queryNameToSource[singularQuery]) queryNameToSource[singularQuery] = [];
98298
+ queryNameToSource[singularQuery].push({
98299
+ typeName: parsedType.name,
98300
+ kind: "singular"
98301
+ });
98302
+ if (singularQuery !== pluralQuery) {
98303
+ if (!queryNameToSource[pluralQuery]) queryNameToSource[pluralQuery] = [];
98304
+ queryNameToSource[pluralQuery].push({
98305
+ typeName: parsedType.name,
98306
+ kind: "plural"
98307
+ });
98308
+ }
98309
+ }
98310
+ const duplicates = Object.entries(queryNameToSource).filter(([, sources]) => sources.length > 1);
98311
+ for (const [queryName, sources] of duplicates) {
98312
+ const sourceList = sources.map((s) => {
98313
+ const sourceInfo = typeSourceInfo?.[s.typeName];
98314
+ const location = sourceInfo ? ` (${sourceInfo.filePath})` : "";
98315
+ return `"${s.typeName}"${location} (${s.kind})`;
98316
+ }).join(", ");
98317
+ errors.push(`GraphQL query field "${queryName}" conflicts between: ${sourceList}`);
98318
+ }
98319
+ if (errors.length > 0) throw new Error(`GraphQL field name conflicts detected in TailorDB service "${namespace}".\n${errors.map((e) => ` - ${e}`).join("\n")}`);
98320
+ }
98321
+
98116
98322
  //#endregion
98117
98323
  //#region src/cli/application/tailordb/service.ts
98118
98324
  var TailorDBService = class {
@@ -98173,77 +98379,7 @@ var TailorDBService = class {
98173
98379
  parseTypes() {
98174
98380
  const allTypes = {};
98175
98381
  for (const fileTypes of Object.values(this.rawTypes)) for (const [typeName, type] of Object.entries(fileTypes)) allTypes[typeName] = type;
98176
- this.types = {};
98177
- for (const [typeName, type] of Object.entries(allTypes)) this.types[typeName] = this.parseTailorDBType(type);
98178
- this.buildBackwardRelationships(this.types);
98179
- }
98180
- parseTailorDBType(type) {
98181
- const metadata = type.metadata;
98182
- const pluralForm = metadata.settings?.pluralForm || inflection.pluralize(type.name);
98183
- const fields = {};
98184
- const forwardRelationships = {};
98185
- for (const [fieldName, fieldDef] of Object.entries(type.fields)) {
98186
- const fieldConfig = parseFieldConfig(fieldDef);
98187
- ensureNoExternalVariablesInFieldScripts(type.name, fieldName, fieldConfig);
98188
- const parsedField = {
98189
- name: fieldName,
98190
- config: fieldConfig
98191
- };
98192
- const ref$1 = fieldDef.reference;
98193
- if (ref$1) {
98194
- const targetType = ref$1.type?.name;
98195
- if (targetType) {
98196
- const forwardName = ref$1.nameMap?.[0] || inflection.camelize(targetType, true);
98197
- const backwardName = ref$1.nameMap?.[1] || "";
98198
- const key = ref$1.key || "id";
98199
- parsedField.relation = {
98200
- targetType,
98201
- forwardName,
98202
- backwardName,
98203
- key,
98204
- unique: fieldDef.metadata?.unique ?? false
98205
- };
98206
- forwardRelationships[forwardName] = {
98207
- name: forwardName,
98208
- targetType,
98209
- targetField: fieldName,
98210
- sourceField: key,
98211
- isArray: false,
98212
- description: ref$1.type?.metadata?.description || ""
98213
- };
98214
- }
98215
- }
98216
- fields[fieldName] = parsedField;
98217
- }
98218
- return {
98219
- name: type.name,
98220
- pluralForm,
98221
- description: metadata.description,
98222
- fields,
98223
- forwardRelationships,
98224
- backwardRelationships: {},
98225
- settings: metadata.settings || {},
98226
- permissions: metadata.permissions || {},
98227
- indexes: metadata.indexes,
98228
- files: metadata.files
98229
- };
98230
- }
98231
- buildBackwardRelationships(types$2) {
98232
- 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) {
98233
- let backwardName = field.relation.backwardName;
98234
- if (!backwardName) {
98235
- const lowerName = inflection.camelize(otherTypeName, true);
98236
- backwardName = field.relation.unique ? inflection.singularize(lowerName) : inflection.pluralize(lowerName);
98237
- }
98238
- type.backwardRelationships[backwardName] = {
98239
- name: backwardName,
98240
- targetType: otherTypeName,
98241
- targetField: fieldName,
98242
- sourceField: field.relation.key,
98243
- isArray: !field.relation.unique,
98244
- description: otherType.description || ""
98245
- };
98246
- }
98382
+ this.types = parseTypes(allTypes, this.namespace, this.typeSourceInfo);
98247
98383
  }
98248
98384
  };
98249
98385
 
@@ -101875,16 +102011,18 @@ async function confirmOwnerConflict(conflicts, appName, yes) {
101875
102011
  }
101876
102012
  async function confirmUnmanagedResources(resources, appName, yes) {
101877
102013
  if (resources.length === 0) return;
101878
- logger.warn("Unmanaged resources detected:");
102014
+ logger.warn("Existing resources not tracked by tailor-sdk were found:");
101879
102015
  logger.log(` ${styles.info("Resources")}:`);
101880
102016
  for (const r$1 of resources) logger.log(` • ${styles.bold(r$1.resourceType)} ${styles.info(`"${r$1.resourceName}"`)}`);
101881
102017
  logger.newline();
101882
- logger.log(" These resources are not managed by any application.");
102018
+ logger.log(" These resources may have been created by older SDK versions, Terraform, or CUE.");
102019
+ logger.log(" To continue, confirm that tailor-sdk should manage them.");
102020
+ logger.log(" If they are managed by another tool (e.g., Terraform), cancel and manage them there instead.");
101883
102021
  if (yes) {
101884
102022
  logger.success(`Adding to "${appName}" (--yes flag specified)...`, { mode: "plain" });
101885
102023
  return;
101886
102024
  }
101887
- if (!await logger.prompt(`Add these resources to "${appName}"?`, {
102025
+ if (!await logger.prompt(`Allow tailor-sdk to manage these resources for "${appName}"?`, {
101888
102026
  type: "confirm",
101889
102027
  initial: false
101890
102028
  })) throw new Error(ml`
@@ -103771,7 +103909,7 @@ var DependencyWatcher = class {
103771
103909
  this.dependencyCache.clear();
103772
103910
  const impactResult = this.calculateImpact(absolutePath);
103773
103911
  if (impactResult.affectedGroups.length > 0) {
103774
- logger.warn("File change detected, restarting watch process...", { mode: "stream" });
103912
+ logger.info("File change detected, restarting watch process...", { mode: "stream" });
103775
103913
  logger.info(`Changed file: ${absolutePath}`, { mode: "stream" });
103776
103914
  logger.info(`Affected groups: ${impactResult.affectedGroups.join(", ")}`, { mode: "stream" });
103777
103915
  if (this.restartCallback) this.restartCallback();
@@ -104071,7 +104209,7 @@ var GenerationManager = class {
104071
104209
  }
104072
104210
  async restartWatchProcess() {
104073
104211
  logger.newline();
104074
- logger.warn("Restarting watch process to clear module cache...", { mode: "stream" });
104212
+ logger.info("Restarting watch process to clear module cache...", { mode: "stream" });
104075
104213
  logger.newline();
104076
104214
  if (this.watcher) await this.watcher.stop();
104077
104215
  const args = process.argv.slice(2);
@@ -105458,4 +105596,4 @@ const listCommand = defineCommand({
105458
105596
 
105459
105597
  //#endregion
105460
105598
  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 };
105461
- //# sourceMappingURL=list-CqNMJdug.mjs.map
105599
+ //# sourceMappingURL=list-BSi-MJbT.mjs.map