storyblok 4.27.1 → 4.27.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/index.mjs +269 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -14277,6 +14277,119 @@ function collectTagNames(component) {
|
|
|
14277
14277
|
return [...names];
|
|
14278
14278
|
}
|
|
14279
14279
|
//#endregion
|
|
14280
|
+
//#region src/commands/schema/dimensions.ts
|
|
14281
|
+
const IDENTITY_KEYS = ["entry_value", "name"];
|
|
14282
|
+
function isDimensionIdentity(value) {
|
|
14283
|
+
return isRecord(value) && typeof value.name === "string" && typeof value.entry_value === "string";
|
|
14284
|
+
}
|
|
14285
|
+
/** The declarable dimensions of a `dimensions` value, in entry_value order. */
|
|
14286
|
+
function toDimensionList(value) {
|
|
14287
|
+
return (Array.isArray(value) ? value.filter(isDimensionIdentity) : []).sort((a, b) => compareStrings(a.entry_value, b.entry_value) || compareStrings(a.name, b.name));
|
|
14288
|
+
}
|
|
14289
|
+
function compareStrings(a, b) {
|
|
14290
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
14291
|
+
}
|
|
14292
|
+
/**
|
|
14293
|
+
* A matched dimension keeps its remote id, and with it the values editors
|
|
14294
|
+
* entered for that dimension. An identical dimension is matched first, so the
|
|
14295
|
+
* result does not depend on order when the space holds duplicates. After that,
|
|
14296
|
+
* `entry_value` takes precedence over `name` because the Content Delivery API
|
|
14297
|
+
* `dimension` parameter filters by it.
|
|
14298
|
+
*/
|
|
14299
|
+
function pairDimensions(local, remote) {
|
|
14300
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
14301
|
+
const unmatchedRemote = [...remote];
|
|
14302
|
+
const matchers = [(rd, ld) => isUnchanged(ld, rd), ...IDENTITY_KEYS.map((key) => (rd, ld) => rd[key] === ld[key])];
|
|
14303
|
+
for (const matches of matchers) for (const localDimension of local) {
|
|
14304
|
+
if (pairs.has(localDimension)) continue;
|
|
14305
|
+
const index = unmatchedRemote.findIndex((rd) => matches(rd, localDimension));
|
|
14306
|
+
if (index !== -1) {
|
|
14307
|
+
pairs.set(localDimension, unmatchedRemote[index]);
|
|
14308
|
+
unmatchedRemote.splice(index, 1);
|
|
14309
|
+
}
|
|
14310
|
+
}
|
|
14311
|
+
return {
|
|
14312
|
+
pairs,
|
|
14313
|
+
unmatchedRemote
|
|
14314
|
+
};
|
|
14315
|
+
}
|
|
14316
|
+
function isUnchanged(declared, own) {
|
|
14317
|
+
return own?.name === declared.name && own.entry_value === declared.entry_value;
|
|
14318
|
+
}
|
|
14319
|
+
/**
|
|
14320
|
+
* The Management API checks both the `name` and the `entry_value` of every
|
|
14321
|
+
* dimension an update creates or changes against the stored dimensions, before
|
|
14322
|
+
* it applies any other change of the same update. A value another dimension
|
|
14323
|
+
* still holds is therefore rejected, even when that dimension is renamed or
|
|
14324
|
+
* removed in the same update, and even when the changed dimension keeps that
|
|
14325
|
+
* value.
|
|
14326
|
+
*/
|
|
14327
|
+
function findDimensionConflicts(local, remote) {
|
|
14328
|
+
const { pairs } = pairDimensions(local, remote);
|
|
14329
|
+
const conflicts = [];
|
|
14330
|
+
for (const declared of local) {
|
|
14331
|
+
const own = pairs.get(declared);
|
|
14332
|
+
if (isUnchanged(declared, own)) continue;
|
|
14333
|
+
for (const key of IDENTITY_KEYS) {
|
|
14334
|
+
const holder = remote.find((rd) => rd !== own && rd[key] === declared[key]);
|
|
14335
|
+
if (holder) conflicts.push({
|
|
14336
|
+
declared,
|
|
14337
|
+
key,
|
|
14338
|
+
holder
|
|
14339
|
+
});
|
|
14340
|
+
}
|
|
14341
|
+
}
|
|
14342
|
+
return conflicts;
|
|
14343
|
+
}
|
|
14344
|
+
/**
|
|
14345
|
+
* The Management API does not check the dimensions of one request against each
|
|
14346
|
+
* other, so dimensions that share a value and are created or changed together
|
|
14347
|
+
* are stored as they are. Duplicates the space already holds, and that the
|
|
14348
|
+
* update leaves untouched, are not reported.
|
|
14349
|
+
*/
|
|
14350
|
+
function findDuplicateDimensions(local, remote) {
|
|
14351
|
+
const { pairs } = pairDimensions(local, remote);
|
|
14352
|
+
const duplicates = /* @__PURE__ */ new Map();
|
|
14353
|
+
for (const declared of local) {
|
|
14354
|
+
if (isUnchanged(declared, pairs.get(declared))) continue;
|
|
14355
|
+
for (const key of IDENTITY_KEYS) {
|
|
14356
|
+
const value = declared[key];
|
|
14357
|
+
if (local.some((other) => other !== declared && other[key] === value)) duplicates.set(`${key}:${value}`, {
|
|
14358
|
+
key,
|
|
14359
|
+
value
|
|
14360
|
+
});
|
|
14361
|
+
}
|
|
14362
|
+
}
|
|
14363
|
+
return [...duplicates.values()];
|
|
14364
|
+
}
|
|
14365
|
+
function formatDuplicateDimensions(datasourceName, duplicates) {
|
|
14366
|
+
return `Datasource '${datasourceName}' declares more than one dimension with ${duplicates.map(({ key, value }) => `the ${key} '${value}'`).join(", ")}. Give each dimension a unique name and entry_value.`;
|
|
14367
|
+
}
|
|
14368
|
+
function describeDimension({ name, entry_value }) {
|
|
14369
|
+
return `'${name}' (entry_value '${entry_value}')`;
|
|
14370
|
+
}
|
|
14371
|
+
function formatDimensionConflicts(datasourceName, conflicts) {
|
|
14372
|
+
return `Datasource '${datasourceName}' cannot be updated in one step: ${conflicts.map(({ declared, key, holder }) => `dimension ${describeDimension(declared)} uses the ${key} '${declared[key]}' still held by the existing dimension ${describeDimension(holder)}`).join("; ")}. The Management API rejects a name or entry_value that another dimension holds before the update. Apply the change in two steps: first change that value on the existing dimension or remove it, then make this change.`;
|
|
14373
|
+
}
|
|
14374
|
+
/** Dimensions an update removes, and with them the values entered for them. */
|
|
14375
|
+
function removedDimensionNames(diff) {
|
|
14376
|
+
const { unmatchedRemote } = pairDimensions(toDimensionList(diff.after?.dimensions), toDimensionList(diff.before?.dimensions));
|
|
14377
|
+
return unmatchedRemote.map((dimension) => dimension.name);
|
|
14378
|
+
}
|
|
14379
|
+
/**
|
|
14380
|
+
* Duplicates a datasource create or update would store, or `null` when there
|
|
14381
|
+
* are none. Pass no `remote` for a create.
|
|
14382
|
+
*/
|
|
14383
|
+
function describeDuplicateDimensions(datasourceName, local, remote) {
|
|
14384
|
+
const duplicates = findDuplicateDimensions(toDimensionList(local), toDimensionList(remote));
|
|
14385
|
+
return duplicates.length > 0 ? formatDuplicateDimensions(datasourceName, duplicates) : null;
|
|
14386
|
+
}
|
|
14387
|
+
/** Why the Management API would reject a datasource update, or `null` when it would not. */
|
|
14388
|
+
function describeDimensionConflicts(datasourceName, local, remote) {
|
|
14389
|
+
const conflicts = findDimensionConflicts(toDimensionList(local), toDimensionList(remote));
|
|
14390
|
+
return conflicts.length > 0 ? formatDimensionConflicts(datasourceName, conflicts) : null;
|
|
14391
|
+
}
|
|
14392
|
+
//#endregion
|
|
14280
14393
|
//#region src/commands/schema/diff-schema.ts
|
|
14281
14394
|
function resolveTagWith(own, other) {
|
|
14282
14395
|
return (entry) => {
|
|
@@ -14360,9 +14473,9 @@ function asRecord(value) {
|
|
|
14360
14473
|
return isRecord(value) ? value : {};
|
|
14361
14474
|
}
|
|
14362
14475
|
/**
|
|
14363
|
-
* An array that is really a set keyed by `name`
|
|
14364
|
-
*
|
|
14365
|
-
*
|
|
14476
|
+
* An array that is really a set keyed by `name` as a name-keyed record, so a
|
|
14477
|
+
* change reads as the member that moved rather than two dumps of the whole
|
|
14478
|
+
* list, and reordering alone is not a change.
|
|
14366
14479
|
* Returns `null` for any other array shape, including one whose duplicate names
|
|
14367
14480
|
* would make the mapping lossy.
|
|
14368
14481
|
*/
|
|
@@ -14379,8 +14492,7 @@ function asNameKeyed(value) {
|
|
|
14379
14492
|
* Like {@link diffKeyed}, but recurses into nested records so a change reads as
|
|
14380
14493
|
* the property that actually moved (`schema.body.maximum`) instead of two dumps
|
|
14381
14494
|
* of the whole enclosing object. Name-keyed arrays are recursed into the same
|
|
14382
|
-
* way
|
|
14383
|
-
* whole.
|
|
14495
|
+
* way; every other non-record value is reported whole.
|
|
14384
14496
|
*/
|
|
14385
14497
|
function diffKeyedDeep(before, after, prefix) {
|
|
14386
14498
|
const changes = [];
|
|
@@ -14434,6 +14546,47 @@ function componentChanges(before, after) {
|
|
|
14434
14546
|
return [...diffKeyed(beforeProps, afterProps), ...diffKeyedDeep(asRecord(beforeSchema), asRecord(afterSchema), "schema.")];
|
|
14435
14547
|
}
|
|
14436
14548
|
/**
|
|
14549
|
+
* Dimension changes as `schema push` applies them: a dimension paired with a
|
|
14550
|
+
* remote one is updated in place and reads as the property that changed, keyed
|
|
14551
|
+
* by the name it has in the space (`dimensions.Light.name` for a rename of
|
|
14552
|
+
* `Light`). Only an unpaired
|
|
14553
|
+
* dimension is `added` or `removed`, and removing one deletes the values
|
|
14554
|
+
* entered for it.
|
|
14555
|
+
*/
|
|
14556
|
+
function dimensionChanges(before, after) {
|
|
14557
|
+
const changes = [];
|
|
14558
|
+
const target = toDimensionList(after);
|
|
14559
|
+
const { pairs, unmatchedRemote } = pairDimensions(target, toDimensionList(before));
|
|
14560
|
+
for (const dimension of target) {
|
|
14561
|
+
const current = pairs.get(dimension);
|
|
14562
|
+
if (!current) {
|
|
14563
|
+
changes.push({
|
|
14564
|
+
field: `dimensions.${dimension.name}`,
|
|
14565
|
+
change: "added",
|
|
14566
|
+
after: dimension
|
|
14567
|
+
});
|
|
14568
|
+
continue;
|
|
14569
|
+
}
|
|
14570
|
+
for (const key of ["entry_value", "name"]) if (current[key] !== dimension[key]) changes.push({
|
|
14571
|
+
field: `dimensions.${current.name}.${key}`,
|
|
14572
|
+
change: "modified",
|
|
14573
|
+
before: current[key],
|
|
14574
|
+
after: dimension[key]
|
|
14575
|
+
});
|
|
14576
|
+
}
|
|
14577
|
+
for (const dimension of unmatchedRemote) changes.push({
|
|
14578
|
+
field: `dimensions.${dimension.name}`,
|
|
14579
|
+
change: "removed",
|
|
14580
|
+
before: dimension
|
|
14581
|
+
});
|
|
14582
|
+
return changes.sort((a, b) => a.field < b.field ? -1 : a.field > b.field ? 1 : 0);
|
|
14583
|
+
}
|
|
14584
|
+
function datasourceChanges(before, after) {
|
|
14585
|
+
const { dimensions: beforeDimensions, ...beforeProps } = before;
|
|
14586
|
+
const { dimensions: afterDimensions, ...afterProps } = after;
|
|
14587
|
+
return [...dimensionChanges(beforeDimensions, afterDimensions), ...diffKeyedDeep(beforeProps, afterProps, "")];
|
|
14588
|
+
}
|
|
14589
|
+
/**
|
|
14437
14590
|
* `cleanComponent` marks an explicitly ungrouped block with a sentinel, because
|
|
14438
14591
|
* a literal `null` would be dropped by the canonical form and become
|
|
14439
14592
|
* indistinguishable from a block that does not manage its group at all. Once the
|
|
@@ -14490,7 +14643,7 @@ function buildEntityDiff(type, name, fromClean, toClean) {
|
|
|
14490
14643
|
type,
|
|
14491
14644
|
name,
|
|
14492
14645
|
action: "update",
|
|
14493
|
-
changes: (type === "component" ? componentChanges(fromClean, toClean) :
|
|
14646
|
+
changes: (type === "component" ? componentChanges(fromClean, toClean) : datasourceChanges(fromClean, toClean)).map(resolveFolderSentinelInChange),
|
|
14494
14647
|
before: resolveFolderSentinel(fromClean),
|
|
14495
14648
|
after: resolveFolderSentinel(toClean)
|
|
14496
14649
|
};
|
|
@@ -14594,8 +14747,19 @@ function diffComponent(name, fromComp, toComp, context, compareGroupUuid, manage
|
|
|
14594
14747
|
const byTagName = comparesTagsByName(fromComp, toComp, context.from, context.to);
|
|
14595
14748
|
return buildEntityDiff("component", name, fromComp ? cleanComponent(applyDefaults(toPathSpace(toTagSpace(omitUnmanagedOptionalKeys(fromComp, toComp), fromTag, byTagName), uuidToPath, manageFolder), COMPONENT_DEFAULTS), { includeGroupUuid }) : null, toComp ? cleanComponent(applyDefaults(toPathSpace(toTagSpace(omitUnmanagedOptionalKeys(toComp, fromComp), toTag, byTagName), uuidToPath, manageFolder), COMPONENT_DEFAULTS), { includeGroupUuid }) : null);
|
|
14596
14749
|
}
|
|
14750
|
+
/**
|
|
14751
|
+
* Dimension order carries no meaning: an update cannot set it, and the
|
|
14752
|
+
* Management API returns dimensions in no guaranteed order.
|
|
14753
|
+
*/
|
|
14754
|
+
function cleanDatasourceForDiff(datasource) {
|
|
14755
|
+
const clean = cleanDatasource(applyDefaults(datasource, DATASOURCE_DEFAULTS));
|
|
14756
|
+
return {
|
|
14757
|
+
...clean,
|
|
14758
|
+
dimensions: toDimensionList(clean.dimensions)
|
|
14759
|
+
};
|
|
14760
|
+
}
|
|
14597
14761
|
function diffDatasource(name, fromDs, toDs) {
|
|
14598
|
-
return buildEntityDiff("datasource", name, fromDs ?
|
|
14762
|
+
return buildEntityDiff("datasource", name, fromDs ? cleanDatasourceForDiff(fromDs) : null, toDs ? cleanDatasourceForDiff(toDs) : null);
|
|
14599
14763
|
}
|
|
14600
14764
|
/**
|
|
14601
14765
|
* Folders (component groups) are identified by slug path. Renames are
|
|
@@ -15038,6 +15202,42 @@ function assertPushableFields(components) {
|
|
|
15038
15202
|
}
|
|
15039
15203
|
if (problems.length > 0) throw new CommandError(`Schema fields that cannot be pushed: ${problems.join(", ")}. Run \`storyblok schema validate\` for the full report.`);
|
|
15040
15204
|
}
|
|
15205
|
+
const DIMENSION_IDENTITY_KEYS = ["name", "entry_value"];
|
|
15206
|
+
/**
|
|
15207
|
+
* Fails the load when a datasource declares dimensions the push cannot carry.
|
|
15208
|
+
*
|
|
15209
|
+
* A `dimensions` value that is not an array reads as no dimensions, so the push
|
|
15210
|
+
* deletes every dimension the space holds. A dimension without a string `name`
|
|
15211
|
+
* and `entry_value` is dropped from the update, so it never reaches the space
|
|
15212
|
+
* and nothing reports it. A blank one is rejected by the Management API, but
|
|
15213
|
+
* only once the push is underway, after other entities may already have been
|
|
15214
|
+
* written. `schema validate` reports the same problems as
|
|
15215
|
+
* `invalid_datasource_dimensions` / `invalid_dimension*`.
|
|
15216
|
+
*/
|
|
15217
|
+
function assertPushableDimensions(datasources) {
|
|
15218
|
+
const problems = [];
|
|
15219
|
+
for (const datasource of datasources) {
|
|
15220
|
+
const datasourceLabel = `datasource "${String(datasource.slug)}"`;
|
|
15221
|
+
const dimensions = datasource.dimensions;
|
|
15222
|
+
if (dimensions === void 0) continue;
|
|
15223
|
+
if (!Array.isArray(dimensions)) {
|
|
15224
|
+
problems.push(`"dimensions" in ${datasourceLabel} is not an array`);
|
|
15225
|
+
continue;
|
|
15226
|
+
}
|
|
15227
|
+
dimensions.forEach((dimension, index) => {
|
|
15228
|
+
const dimensionLabel = `the dimension at index ${index} in ${datasourceLabel}`;
|
|
15229
|
+
if (!isRecord(dimension)) {
|
|
15230
|
+
problems.push(`${dimensionLabel} is not an object`);
|
|
15231
|
+
return;
|
|
15232
|
+
}
|
|
15233
|
+
for (const key of DIMENSION_IDENTITY_KEYS) {
|
|
15234
|
+
const value = dimension[key];
|
|
15235
|
+
if (typeof value !== "string" || value.trim() === "") problems.push(`${dimensionLabel} has a missing or blank "${key}"`);
|
|
15236
|
+
}
|
|
15237
|
+
});
|
|
15238
|
+
}
|
|
15239
|
+
if (problems.length > 0) throw new CommandError(`Datasource dimensions that cannot be pushed: ${problems.join(", ")}. Run \`storyblok schema validate\` for the full report.`);
|
|
15240
|
+
}
|
|
15041
15241
|
const toArray = (value) => Array.isArray(value) ? value : [];
|
|
15042
15242
|
/**
|
|
15043
15243
|
* Classifies a module's exports into wire components, datasources, and folders,
|
|
@@ -15049,6 +15249,7 @@ function classifyExports(moduleExports) {
|
|
|
15049
15249
|
const { components, datasources, folders } = collectSchemaExports(moduleExports);
|
|
15050
15250
|
assertUniqueIdentities(components, datasources);
|
|
15051
15251
|
assertPushableFields(components);
|
|
15252
|
+
assertPushableDimensions(datasources);
|
|
15052
15253
|
const registered = folders.map((folder) => folder.path);
|
|
15053
15254
|
const derived = [];
|
|
15054
15255
|
for (const component of components) {
|
|
@@ -16114,6 +16315,12 @@ function toComponentCreate(input) {
|
|
|
16114
16315
|
function toComponentUpdate(input) {
|
|
16115
16316
|
return buildComponentPayload(input);
|
|
16116
16317
|
}
|
|
16318
|
+
function declaredDimensions(dimensions) {
|
|
16319
|
+
return dimensions.filter(isDimensionIdentity).map(({ name, entry_value }) => ({
|
|
16320
|
+
name,
|
|
16321
|
+
entry_value
|
|
16322
|
+
}));
|
|
16323
|
+
}
|
|
16117
16324
|
/** Converts an unknown input to a DatasourceCreate-compatible payload. */
|
|
16118
16325
|
function toDatasourceCreate(input) {
|
|
16119
16326
|
if (!isRecord(input)) return {
|
|
@@ -16124,32 +16331,33 @@ function toDatasourceCreate(input) {
|
|
|
16124
16331
|
name: typeof input.name === "string" ? input.name : "",
|
|
16125
16332
|
slug: typeof input.slug === "string" ? input.slug : ""
|
|
16126
16333
|
};
|
|
16127
|
-
if (Array.isArray(input.dimensions)) result.dimensions_attributes = input.dimensions
|
|
16128
|
-
name: d.name,
|
|
16129
|
-
entry_value: d.entry_value
|
|
16130
|
-
}));
|
|
16334
|
+
if (Array.isArray(input.dimensions)) result.dimensions_attributes = declaredDimensions(input.dimensions);
|
|
16131
16335
|
return result;
|
|
16132
16336
|
}
|
|
16133
16337
|
/**
|
|
16134
|
-
*
|
|
16135
|
-
*
|
|
16136
|
-
* an empty `dimensions_attributes` array is a no-op.
|
|
16338
|
+
* The Management API treats a dimension without an `id` as new and rejects it
|
|
16339
|
+
* when its `name` or `entry_value` already exists. Removing one requires
|
|
16340
|
+
* `{ id, _destroy: true }`; an empty `dimensions_attributes` array is a no-op.
|
|
16137
16341
|
*/
|
|
16138
16342
|
function toDatasourceUpdate(input, remote) {
|
|
16139
16343
|
const base = toDatasourceCreate(input);
|
|
16140
|
-
const
|
|
16141
|
-
const
|
|
16142
|
-
if (
|
|
16143
|
-
const
|
|
16144
|
-
|
|
16145
|
-
id: rd.id,
|
|
16146
|
-
_destroy: true
|
|
16147
|
-
}));
|
|
16148
|
-
if (destroyEntries.length > 0) return {
|
|
16344
|
+
const localDimensions = isRecord(input) && Array.isArray(input.dimensions) ? declaredDimensions(input.dimensions) : [];
|
|
16345
|
+
const remoteDimensions = (remote.dimensions ?? []).filter((rd) => rd.id != null);
|
|
16346
|
+
if (remoteDimensions.length === 0) return base;
|
|
16347
|
+
const { pairs, unmatchedRemote } = pairDimensions(localDimensions, remoteDimensions);
|
|
16348
|
+
return {
|
|
16149
16349
|
...base,
|
|
16150
|
-
dimensions_attributes: [...
|
|
16350
|
+
dimensions_attributes: [...localDimensions.map((local) => {
|
|
16351
|
+
const match = pairs.get(local);
|
|
16352
|
+
return match ? {
|
|
16353
|
+
id: match.id,
|
|
16354
|
+
...local
|
|
16355
|
+
} : local;
|
|
16356
|
+
}), ...unmatchedRemote.map((rd) => ({
|
|
16357
|
+
id: rd.id,
|
|
16358
|
+
_destroy: true
|
|
16359
|
+
}))]
|
|
16151
16360
|
};
|
|
16152
|
-
return base;
|
|
16153
16361
|
}
|
|
16154
16362
|
//#endregion
|
|
16155
16363
|
//#region src/commands/schema/push/actions.ts
|
|
@@ -16915,6 +17123,12 @@ schemaCommand.command("push <entry-file>").description("Push local TypeScript sc
|
|
|
16915
17123
|
const diffResult = diffSchema(remoteToNormalized(remote), localToNormalized(local), { compareGroupUuid: true });
|
|
16916
17124
|
ui.br();
|
|
16917
17125
|
ui.log(formatDiffOutput(diffResult, { delete: options.delete }));
|
|
17126
|
+
const datasourceWrites = diffResult.diffs.filter((d) => d.type === "datasource" && (d.action === "create" || d.action === "update"));
|
|
17127
|
+
const dimensionConflicts = datasourceWrites.map((d) => describeDuplicateDimensions(d.name, d.after?.dimensions, d.before?.dimensions) ?? describeDimensionConflicts(d.name, d.after?.dimensions, d.before?.dimensions)).filter((message) => message !== null);
|
|
17128
|
+
if (dimensionConflicts.length > 0) {
|
|
17129
|
+
handleError(new CommandError(dimensionConflicts.join("\n")), verbose);
|
|
17130
|
+
return;
|
|
17131
|
+
}
|
|
16918
17132
|
if (options.migrations) {
|
|
16919
17133
|
const breakingChanges = analyzeBreakingChanges(diffResult, local, remote);
|
|
16920
17134
|
if (breakingChanges.length > 0) {
|
|
@@ -16987,6 +17201,7 @@ schemaCommand.command("push <entry-file>").description("Push local TypeScript sc
|
|
|
16987
17201
|
}
|
|
16988
17202
|
}
|
|
16989
17203
|
}
|
|
17204
|
+
for (const datasource of datasourceWrites) for (const dimension of removedDimensionNames(datasource)) ui.warn(`Dimension '${dimension}' of datasource '${datasource.name}' will be deleted along with the values entered for it.`);
|
|
16990
17205
|
if (diffResult.stale > 0 && !options.delete) ui.warn(`${diffResult.stale} stale entity(s) exist remotely but not in schema. Use --delete to remove.`);
|
|
16991
17206
|
if (options.dryRun) {
|
|
16992
17207
|
ui.info("Dry run — no changes applied.");
|
|
@@ -17241,6 +17456,17 @@ function remapGroupUuids(payload, uuidMap) {
|
|
|
17241
17456
|
return result;
|
|
17242
17457
|
}
|
|
17243
17458
|
/**
|
|
17459
|
+
* Throws when a datasource the rollback restores holds dimensions the
|
|
17460
|
+
* Management API would reject, before any rollback op is applied.
|
|
17461
|
+
*/
|
|
17462
|
+
function assertRollbackApplicable(ops, remote) {
|
|
17463
|
+
for (const op of ops) {
|
|
17464
|
+
if (op.type !== "datasource" || op.action !== "update") continue;
|
|
17465
|
+
const conflict = describeDimensionConflicts(op.name, op.payload.dimensions, remote.datasources.get(op.name)?.dimensions);
|
|
17466
|
+
if (conflict) throw new CommandError(conflict);
|
|
17467
|
+
}
|
|
17468
|
+
}
|
|
17469
|
+
/**
|
|
17244
17470
|
* Applies rollback ops to the MAPI in dependency-safe order:
|
|
17245
17471
|
* 1. Folder creates (parent-first) — recreated groups get new uuids, tracked in
|
|
17246
17472
|
* an old→new map so restored components can be remapped onto them.
|
|
@@ -17264,6 +17490,7 @@ async function executeRollback(spaceId, ops, remote) {
|
|
|
17264
17490
|
const componentOps = ops.filter((op) => op.type === "component");
|
|
17265
17491
|
const datasourceOps = ops.filter((op) => op.type === "datasource");
|
|
17266
17492
|
const folderOps = ops.filter((op) => op.type === "folder");
|
|
17493
|
+
assertRollbackApplicable(datasourceOps, remote);
|
|
17267
17494
|
const groupRefByPath = buildGroupRefByPath(remote);
|
|
17268
17495
|
const groupUuidMap = /* @__PURE__ */ new Map();
|
|
17269
17496
|
const folderCreates = folderOps.filter((o) => o.action === "create").sort((a, b) => a.name.split("/").length - b.name.split("/").length);
|
|
@@ -17465,6 +17692,23 @@ schemaCommand.command("rollback [changeset-file]").description("Roll back a Stor
|
|
|
17465
17692
|
}
|
|
17466
17693
|
ui.br();
|
|
17467
17694
|
ui.log(formatRollbackOutput(changeset.changes));
|
|
17695
|
+
const remoteSpinner = ui.createSpinner(`Fetching current remote state from space ${space}...`);
|
|
17696
|
+
let remoteResult;
|
|
17697
|
+
try {
|
|
17698
|
+
remoteResult = await fetchRemoteSchema(space);
|
|
17699
|
+
} catch (maybeError) {
|
|
17700
|
+
remoteSpinner.failed("Failed to fetch remote schema");
|
|
17701
|
+
handleError(toError(maybeError), verbose);
|
|
17702
|
+
return;
|
|
17703
|
+
}
|
|
17704
|
+
const { remote } = remoteResult;
|
|
17705
|
+
remoteSpinner.succeed(`Remote: ${remote.components.size} components, ${remote.componentFolders.size} component folders, ${remote.datasources.size} datasources`);
|
|
17706
|
+
try {
|
|
17707
|
+
assertRollbackApplicable(ops, remote);
|
|
17708
|
+
} catch (maybeError) {
|
|
17709
|
+
handleError(toError(maybeError), verbose);
|
|
17710
|
+
return;
|
|
17711
|
+
}
|
|
17468
17712
|
if (options.dryRun) {
|
|
17469
17713
|
ui.info("Dry run — no changes applied.");
|
|
17470
17714
|
logger.info("Dry run completed", { ops: ops.length });
|
|
@@ -17479,17 +17723,6 @@ schemaCommand.command("rollback [changeset-file]").description("Roll back a Stor
|
|
|
17479
17723
|
return;
|
|
17480
17724
|
}
|
|
17481
17725
|
}
|
|
17482
|
-
const remoteSpinner = ui.createSpinner(`Fetching current remote state from space ${space}...`);
|
|
17483
|
-
let remoteResult;
|
|
17484
|
-
try {
|
|
17485
|
-
remoteResult = await fetchRemoteSchema(space);
|
|
17486
|
-
} catch (maybeError) {
|
|
17487
|
-
remoteSpinner.failed("Failed to fetch remote schema");
|
|
17488
|
-
handleError(toError(maybeError), verbose);
|
|
17489
|
-
return;
|
|
17490
|
-
}
|
|
17491
|
-
const { remote } = remoteResult;
|
|
17492
|
-
remoteSpinner.succeed(`Remote: ${remote.components.size} components, ${remote.componentFolders.size} component folders, ${remote.datasources.size} datasources`);
|
|
17493
17726
|
const rollbackSpinner = ui.createSpinner("Applying rollback...");
|
|
17494
17727
|
let result;
|
|
17495
17728
|
try {
|