@zenstackhq/cli 3.7.0-beta.1 → 3.7.1
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/index.cjs +46 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +48 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -430,6 +430,18 @@ function getRelationFkName(decl) {
|
|
|
430
430
|
return ((decl?.attributes.find((a) => a.decl.ref?.name === "@relation"))?.args.find((a) => a.name === "map")?.value)?.value;
|
|
431
431
|
}
|
|
432
432
|
/**
|
|
433
|
+
* Gets the relation name from the @relation attribute's `name` argument.
|
|
434
|
+
* e.g., @relation('myRelation', fields: [...], references: [...]) -> "myRelation"
|
|
435
|
+
* e.g., @relation(name: 'myRelation', fields: [...], references: [...]) -> "myRelation"
|
|
436
|
+
* e.g., @relation(fields: [...], references: [...]) -> undefined
|
|
437
|
+
* e.g., @relation('backRef') -> "backRef"
|
|
438
|
+
*/
|
|
439
|
+
function getRelationName(decl) {
|
|
440
|
+
const relationAttr = decl?.attributes?.find((a) => a.decl?.ref?.name === "@relation");
|
|
441
|
+
if (!relationAttr) return void 0;
|
|
442
|
+
return (0, _zenstackhq_language_utils.getAttributeArgLiteral)(relationAttr, "name");
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
433
445
|
* Gets the FK field names from the @relation attribute's `fields` argument.
|
|
434
446
|
* Returns a sorted, comma-separated string of field names for comparison.
|
|
435
447
|
* e.g., @relation(fields: [userId], references: [id]) -> "userId"
|
|
@@ -2176,6 +2188,16 @@ const providers = {
|
|
|
2176
2188
|
};
|
|
2177
2189
|
//#endregion
|
|
2178
2190
|
//#region src/actions/db.ts
|
|
2191
|
+
function hasRelationFieldsArg(field) {
|
|
2192
|
+
return !!field.attributes.find((a) => a.decl.ref?.name === "@relation")?.args.some((a) => a.name === "fields");
|
|
2193
|
+
}
|
|
2194
|
+
function getReferencedModelName(field) {
|
|
2195
|
+
return field.type.reference?.ref ? getDbName(field.type.reference.ref) : void 0;
|
|
2196
|
+
}
|
|
2197
|
+
function matchesRelationNameFallback(field, relationName, candidate) {
|
|
2198
|
+
const referencedModelName = getReferencedModelName(field);
|
|
2199
|
+
return !!referencedModelName && getRelationName(candidate) === relationName && hasRelationFieldsArg(candidate) === hasRelationFieldsArg(field) && getReferencedModelName(candidate) === referencedModelName;
|
|
2200
|
+
}
|
|
2179
2201
|
/**
|
|
2180
2202
|
* CLI action for db related commands
|
|
2181
2203
|
*/
|
|
@@ -2335,16 +2357,21 @@ async function runPull(options) {
|
|
|
2335
2357
|
}
|
|
2336
2358
|
newDataModel.fields.forEach((f) => {
|
|
2337
2359
|
let originalFields = originalDataModel.fields.filter((d) => getDbName(d) === getDbName(f));
|
|
2338
|
-
const isRelationField = f.$type === "DataField" && !!f.attributes?.some((a) => a?.decl?.ref?.name === "@relation");
|
|
2339
|
-
if (originalFields.length === 0 && isRelationField && !getRelationFieldsKey(f)) return;
|
|
2340
2360
|
if (originalFields.length === 0) {
|
|
2341
|
-
const newFieldsKey = getRelationFieldsKey(f);
|
|
2342
|
-
if (newFieldsKey) originalFields = originalDataModel.fields.filter((d) => getRelationFieldsKey(d) === newFieldsKey);
|
|
2361
|
+
const newFieldsKey = (0, _zenstackhq_language_ast.isDataField)(f) ? getRelationFieldsKey(f) : void 0;
|
|
2362
|
+
if (newFieldsKey) originalFields = originalDataModel.fields.filter((d) => (0, _zenstackhq_language_ast.isDataField)(d) && getRelationFieldsKey(d) === newFieldsKey);
|
|
2343
2363
|
}
|
|
2344
|
-
if (originalFields.length === 0)
|
|
2345
|
-
|
|
2364
|
+
if (originalFields.length === 0) {
|
|
2365
|
+
const newFkName = (0, _zenstackhq_language_ast.isDataField)(f) ? getRelationFkName(f) : void 0;
|
|
2366
|
+
if (newFkName) originalFields = originalDataModel.fields.filter((d) => (0, _zenstackhq_language_ast.isDataField)(d) && getRelationFkName(d) === newFkName);
|
|
2367
|
+
}
|
|
2368
|
+
if (originalFields.length === 0) {
|
|
2369
|
+
const newRelName = (0, _zenstackhq_language_ast.isDataField)(f) ? getRelationName(f) : void 0;
|
|
2370
|
+
if (newRelName) originalFields = originalDataModel.fields.filter((d) => (0, _zenstackhq_language_ast.isDataField)(d) && (0, _zenstackhq_language_ast.isDataField)(f) && matchesRelationNameFallback(f, newRelName, d));
|
|
2371
|
+
}
|
|
2372
|
+
if (originalFields.length === 0) originalFields = originalDataModel.fields.filter((d) => (0, _zenstackhq_language_ast.isDataField)(f) && (0, _zenstackhq_language_ast.isDataField)(d) && f.type.reference?.ref && d.type.reference?.ref && getDbName(f.type.reference.ref) === getDbName(d.type.reference.ref));
|
|
2346
2373
|
if (originalFields.length > 1) {
|
|
2347
|
-
if (
|
|
2374
|
+
if (!((0, _zenstackhq_language_ast.isDataField)(f) && !getRelationFieldsKey(f))) console.warn(colors.default.yellow(`Found more original fields, need to tweak the search algorithm. ${originalDataModel.name}->[${originalFields.map((of) => of.name).join(", ")}](${f.name})`));
|
|
2348
2375
|
return;
|
|
2349
2376
|
}
|
|
2350
2377
|
const originalField = originalFields.at(0);
|
|
@@ -2439,12 +2466,19 @@ async function runPull(options) {
|
|
|
2439
2466
|
});
|
|
2440
2467
|
originalDataModel.fields.filter((f) => {
|
|
2441
2468
|
if (newDataModel.fields.find((d) => getDbName(d) === getDbName(f))) return false;
|
|
2442
|
-
const originalFieldsKey = getRelationFieldsKey(f);
|
|
2469
|
+
const originalFieldsKey = (0, _zenstackhq_language_ast.isDataField)(f) ? getRelationFieldsKey(f) : void 0;
|
|
2443
2470
|
if (originalFieldsKey) {
|
|
2444
|
-
if (newDataModel.fields.find((d) => getRelationFieldsKey(d) === originalFieldsKey)) return false;
|
|
2471
|
+
if (newDataModel.fields.find((d) => (0, _zenstackhq_language_ast.isDataField)(d) && getRelationFieldsKey(d) === originalFieldsKey)) return false;
|
|
2472
|
+
}
|
|
2473
|
+
const originalFkName = (0, _zenstackhq_language_ast.isDataField)(f) ? getRelationFkName(f) : void 0;
|
|
2474
|
+
if (originalFkName) {
|
|
2475
|
+
if (newDataModel.fields.find((d) => (0, _zenstackhq_language_ast.isDataField)(d) && getRelationFkName(d) === originalFkName)) return false;
|
|
2476
|
+
}
|
|
2477
|
+
const originalRelName = (0, _zenstackhq_language_ast.isDataField)(f) ? getRelationName(f) : void 0;
|
|
2478
|
+
if (originalRelName) {
|
|
2479
|
+
if (newDataModel.fields.find((d) => (0, _zenstackhq_language_ast.isDataField)(d) && (0, _zenstackhq_language_ast.isDataField)(f) && matchesRelationNameFallback(f, originalRelName, d))) return false;
|
|
2445
2480
|
}
|
|
2446
|
-
|
|
2447
|
-
return !newDataModel.fields.find((d) => f.$type === "DataField" && d.$type === "DataField" && f.type.reference?.ref && d.type.reference?.ref && getDbName(f.type.reference.ref) === getDbName(d.type.reference.ref));
|
|
2481
|
+
return !newDataModel.fields.find((d) => (0, _zenstackhq_language_ast.isDataField)(f) && (0, _zenstackhq_language_ast.isDataField)(d) && f.type.reference?.ref && d.type.reference?.ref && getDbName(f.type.reference.ref) === getDbName(d.type.reference.ref));
|
|
2448
2482
|
}).forEach((f) => {
|
|
2449
2483
|
const _model = f.$container;
|
|
2450
2484
|
const index = _model.fields.findIndex((d) => d === f);
|
|
@@ -3190,7 +3224,7 @@ function startServer(client, schema, options) {
|
|
|
3190
3224
|
}
|
|
3191
3225
|
//#endregion
|
|
3192
3226
|
//#region src/constants.ts
|
|
3193
|
-
const TELEMETRY_TRACKING_TOKEN = "
|
|
3227
|
+
const TELEMETRY_TRACKING_TOKEN = "74944eb779d7d3b4ce185be843fde9fc";
|
|
3194
3228
|
//#endregion
|
|
3195
3229
|
//#region src/utils/is-ci.ts
|
|
3196
3230
|
const isInCi = node_process.env["CI"] !== "0" && node_process.env["CI"] !== "false" && ("CI" in node_process.env || "CONTINUOUS_INTEGRATION" in node_process.env || Object.keys(node_process.env).some((key) => key.startsWith("CI_")));
|