storyblok 4.27.0 → 4.27.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.mjs +213 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -898,10 +898,15 @@ var CommandError = class extends Error {
|
|
|
898
898
|
var Logger = class {
|
|
899
899
|
transports = [];
|
|
900
900
|
context = {};
|
|
901
|
+
hasReportedTransportError = false;
|
|
901
902
|
constructor(options) {
|
|
902
903
|
if (options?.transports) this.transports = options.transports;
|
|
903
904
|
if (options?.context) this.context = options.context;
|
|
904
905
|
}
|
|
906
|
+
setTransports(transports) {
|
|
907
|
+
this.transports = transports;
|
|
908
|
+
this.hasReportedTransportError = false;
|
|
909
|
+
}
|
|
905
910
|
log(level, message, context) {
|
|
906
911
|
const timestamp = /* @__PURE__ */ new Date();
|
|
907
912
|
const mergedContext = context ? {
|
|
@@ -914,7 +919,19 @@ var Logger = class {
|
|
|
914
919
|
message,
|
|
915
920
|
context: Object.keys(mergedContext).length ? mergedContext : void 0
|
|
916
921
|
};
|
|
917
|
-
for (const transport of this.transports)
|
|
922
|
+
for (const transport of this.transports) try {
|
|
923
|
+
transport.log(record);
|
|
924
|
+
} catch (error) {
|
|
925
|
+
this.reportTransportError(error);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
reportTransportError(error) {
|
|
929
|
+
if (this.hasReportedTransportError) return;
|
|
930
|
+
this.hasReportedTransportError = true;
|
|
931
|
+
try {
|
|
932
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
933
|
+
process.stderr.write(`Logging failed, some log entries may be missing: ${reason}\n`);
|
|
934
|
+
} catch {}
|
|
918
935
|
}
|
|
919
936
|
error(message, context) {
|
|
920
937
|
this.log("error", message, context);
|
|
@@ -935,7 +952,7 @@ function getLogger(options) {
|
|
|
935
952
|
return loggerInstance;
|
|
936
953
|
}
|
|
937
954
|
function setLoggerTransports(transports) {
|
|
938
|
-
if (loggerInstance) loggerInstance.transports
|
|
955
|
+
if (loggerInstance) loggerInstance.setTransports(transports);
|
|
939
956
|
}
|
|
940
957
|
//#endregion
|
|
941
958
|
//#region src/utils/format.ts
|
|
@@ -1615,9 +1632,8 @@ const OVERFLOW_SUFFIX = "more failure reason(s)";
|
|
|
1615
1632
|
* Accumulates per-item failures keyed by their human-readable reason string
|
|
1616
1633
|
* and produces a compact grouped summary for terminal output.
|
|
1617
1634
|
*
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
* unique cause instead of one line per failed item.
|
|
1635
|
+
* Keeps failure displays consistent across commands (assets, migrations):
|
|
1636
|
+
* one line per unique cause instead of one line per failed item.
|
|
1621
1637
|
*
|
|
1622
1638
|
* Usage:
|
|
1623
1639
|
* ```ts
|
|
@@ -1625,8 +1641,8 @@ const OVERFLOW_SUFFIX = "more failure reason(s)";
|
|
|
1625
1641
|
* // …during processing:
|
|
1626
1642
|
* failures.record(toError(error).message, asset.short_filename);
|
|
1627
1643
|
* // …after processing, before/after stopping progress bars:
|
|
1628
|
-
* for (const line of failures.toListLines()) {
|
|
1629
|
-
* ui.warn(line);
|
|
1644
|
+
* for (const line of failures.toListLines("push", ["asset", "assets"])) {
|
|
1645
|
+
* ui.warn(line);
|
|
1630
1646
|
* }
|
|
1631
1647
|
* ```
|
|
1632
1648
|
*/
|
|
@@ -1668,13 +1684,14 @@ var FailureReasonGroup = class {
|
|
|
1668
1684
|
* - Multiple: `Failed to push N assets — reason (e.g. "a", "b")`
|
|
1669
1685
|
* - Overflow: `… and N more failure reason(s)`
|
|
1670
1686
|
*
|
|
1671
|
-
*
|
|
1687
|
+
* `verb` is the opening word ("push", "transfer", "migrate", …) and the
|
|
1688
|
+
* nouns name what failed, singular and plural.
|
|
1672
1689
|
*/
|
|
1673
|
-
toListLines(verb
|
|
1690
|
+
toListLines(verb, [singular, plural]) {
|
|
1674
1691
|
const all = this.entries();
|
|
1675
1692
|
const lines = all.slice(0, MAX_REASONS).map(({ reason, count, examples }) => {
|
|
1676
1693
|
if (count === 1 && examples.length > 0) return `Failed to ${verb} "${examples[0]}": ${reason}`;
|
|
1677
|
-
return `Failed to ${verb} ${count} ${count === 1 ?
|
|
1694
|
+
return `Failed to ${verb} ${count} ${count === 1 ? singular : plural} — ${reason}${examples.length > 0 ? ` (e.g. ${examples.map((e) => `"${e}"`).join(", ")})` : ""}`;
|
|
1678
1695
|
});
|
|
1679
1696
|
if (all.length > MAX_REASONS) lines.push(`… and ${all.length - MAX_REASONS} ${OVERFLOW_SUFFIX}`);
|
|
1680
1697
|
return lines;
|
|
@@ -1981,25 +1998,32 @@ var Reporter = class Reporter {
|
|
|
1981
1998
|
this.report.summary[key] = value;
|
|
1982
1999
|
return this;
|
|
1983
2000
|
}
|
|
1984
|
-
|
|
2001
|
+
/**
|
|
2002
|
+
* Writes the report. Pass the error that stopped the command early, so the
|
|
2003
|
+
* report says the run failed even though its summaries look complete.
|
|
2004
|
+
*/
|
|
2005
|
+
finalize(stoppedBy) {
|
|
1985
2006
|
if (!this.enabled) return;
|
|
1986
2007
|
const endedAt = /* @__PURE__ */ new Date();
|
|
1987
2008
|
this.report.meta.endedAt = endedAt.toISOString();
|
|
1988
2009
|
this.report.meta.durationMs = endedAt.getTime() - this.startedAt.getTime();
|
|
1989
|
-
|
|
2010
|
+
if (stoppedBy) {
|
|
2011
|
+
this.report.meta.error = stoppedBy.message;
|
|
2012
|
+
this.report.status = REPORT_STATUS.failure;
|
|
2013
|
+
} else this.updateStatus();
|
|
1990
2014
|
saveToFileSync(this.filePath, JSON.stringify(this.report, null, 2));
|
|
1991
2015
|
if (this.maxFiles !== void 0) pruneSiblingRunFiles(this.filePath, this.maxFiles);
|
|
1992
2016
|
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Each summary is a stage, and stages often count the same items (e.g. a
|
|
2019
|
+
* story that is processed and then fails to update), so counts are never
|
|
2020
|
+
* added up across stages: a stage where everything failed fails the run.
|
|
2021
|
+
*/
|
|
1993
2022
|
updateStatus() {
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
failedTotal += item.failed;
|
|
1999
|
-
}
|
|
2000
|
-
if (failedTotal === 0) this.report.status = REPORT_STATUS.success;
|
|
2001
|
-
else if (succeededTotal > 0) this.report.status = REPORT_STATUS.partialSuccess;
|
|
2002
|
-
else this.report.status = REPORT_STATUS.failure;
|
|
2023
|
+
const stages = Object.values(this.report.summary);
|
|
2024
|
+
if (stages.every((stage) => stage.failed === 0)) this.report.status = REPORT_STATUS.success;
|
|
2025
|
+
else if (stages.some((stage) => stage.failed > 0 && stage.succeeded + (stage.skipped ?? 0) === 0)) this.report.status = REPORT_STATUS.failure;
|
|
2026
|
+
else this.report.status = REPORT_STATUS.partialSuccess;
|
|
2003
2027
|
}
|
|
2004
2028
|
static pruneReportFiles(directory, keep) {
|
|
2005
2029
|
return pruneRunFiles(directory, Reporter.FILE_EXTENSION, keep);
|
|
@@ -4844,6 +4868,33 @@ const ERROR_CODES = {
|
|
|
4844
4868
|
MIGRATION_STORY_UPDATE_NULL: "MIGRATION_STORY_UPDATE_NULL"
|
|
4845
4869
|
};
|
|
4846
4870
|
//#endregion
|
|
4871
|
+
//#region src/commands/migrations/run/failed-stories.ts
|
|
4872
|
+
function toReason({ step, migration, error }) {
|
|
4873
|
+
if (step === "fetch") return `Fetch failed: ${error}`;
|
|
4874
|
+
if (step === "update") return `Update failed: ${error}`;
|
|
4875
|
+
return migration ? `${migration} failed: ${error}` : error;
|
|
4876
|
+
}
|
|
4877
|
+
/**
|
|
4878
|
+
* Lists failed stories grouped by reason, so one cause shared by hundreds of
|
|
4879
|
+
* stories reads as one line. The reason carries the API's own explanation
|
|
4880
|
+
* (e.g. a workflow stage that doesn't allow publishing) when there is one.
|
|
4881
|
+
*/
|
|
4882
|
+
function listFailedStories(failed) {
|
|
4883
|
+
const group = new FailureReasonGroup();
|
|
4884
|
+
for (const story of failed) {
|
|
4885
|
+
const { id, name } = story;
|
|
4886
|
+
group.record(toReason(story), name && name !== id.toString() ? `${name} (id ${id})` : `id ${id}`);
|
|
4887
|
+
}
|
|
4888
|
+
return group.toListLines("migrate", ["story", "stories"]);
|
|
4889
|
+
}
|
|
4890
|
+
/**
|
|
4891
|
+
* Whether an error would fail every remaining story the same way (revoked
|
|
4892
|
+
* credentials), so continuing the run would only repeat it for each story.
|
|
4893
|
+
*/
|
|
4894
|
+
function isSystemicError(error) {
|
|
4895
|
+
return error instanceof APIError && error.errorId === "unauthorized";
|
|
4896
|
+
}
|
|
4897
|
+
//#endregion
|
|
4847
4898
|
//#region src/commands/migrations/run/streams/stories-stream.ts
|
|
4848
4899
|
/**
|
|
4849
4900
|
* Iterator that fetches stories
|
|
@@ -4886,21 +4937,27 @@ async function* storiesIterator(spaceId, params, onTotal) {
|
|
|
4886
4937
|
/**
|
|
4887
4938
|
* Given a stream of stories, fetches the content for each story and streams the full story.
|
|
4888
4939
|
* This is necessary because the content is not included in the stories stream.
|
|
4940
|
+
* A story that can't be fetched is reported through `onError` and skipped, so
|
|
4941
|
+
* it doesn't stop the remaining stories from being migrated. An error that
|
|
4942
|
+
* would fail every remaining story too (e.g. revoked credentials) stops the run.
|
|
4889
4943
|
*/
|
|
4890
4944
|
var StoriesStream = class extends Transform {
|
|
4891
4945
|
spaceId;
|
|
4892
4946
|
onProgress;
|
|
4947
|
+
onError;
|
|
4893
4948
|
semaphore;
|
|
4894
|
-
constructor(spaceId, onProgress) {
|
|
4949
|
+
constructor(spaceId, onProgress, onError) {
|
|
4895
4950
|
super({ objectMode: true });
|
|
4896
4951
|
this.spaceId = spaceId;
|
|
4897
4952
|
this.onProgress = onProgress;
|
|
4953
|
+
this.onError = onError;
|
|
4898
4954
|
this.semaphore = createPipelineBackpressureLock();
|
|
4899
4955
|
}
|
|
4900
4956
|
async _transform(chunk, _encoding, callback) {
|
|
4901
4957
|
try {
|
|
4902
4958
|
await this.semaphore.acquire();
|
|
4903
4959
|
const story = await fetchStory(this.spaceId, chunk.id.toString());
|
|
4960
|
+
if (!story) throw new Error("The API returned no story");
|
|
4904
4961
|
this.push(story);
|
|
4905
4962
|
this.onProgress?.();
|
|
4906
4963
|
getLogger().info("Fetched story", { storyId: chunk.id });
|
|
@@ -4909,10 +4966,17 @@ var StoriesStream = class extends Transform {
|
|
|
4909
4966
|
const error = toError(maybeError);
|
|
4910
4967
|
getLogger().error(error.message, {
|
|
4911
4968
|
storyId: chunk.id,
|
|
4969
|
+
storyName: chunk.name,
|
|
4912
4970
|
error,
|
|
4913
4971
|
errorCode: ERROR_CODES.MIGRATION_STORY_FETCH_ERROR
|
|
4914
4972
|
});
|
|
4915
|
-
|
|
4973
|
+
this.onError?.({
|
|
4974
|
+
storyId: chunk.id,
|
|
4975
|
+
name: chunk.name,
|
|
4976
|
+
full_slug: chunk.full_slug,
|
|
4977
|
+
error
|
|
4978
|
+
});
|
|
4979
|
+
callback(isSystemicError(error) ? error : null);
|
|
4916
4980
|
} finally {
|
|
4917
4981
|
this.semaphore.release();
|
|
4918
4982
|
}
|
|
@@ -4926,10 +4990,10 @@ var StoriesStream = class extends Transform {
|
|
|
4926
4990
|
/**
|
|
4927
4991
|
* Creates a stream of stories
|
|
4928
4992
|
*/
|
|
4929
|
-
const createStoriesStream = async ({ spaceId, params, onTotal, onProgress }) => {
|
|
4993
|
+
const createStoriesStream = async ({ spaceId, params, onTotal, onProgress, onError }) => {
|
|
4930
4994
|
const iterator = storiesIterator(spaceId, params, onTotal);
|
|
4931
4995
|
const listStoriesStream = Readable.from(iterator);
|
|
4932
|
-
return pipeline(listStoriesStream, new StoriesStream(spaceId, onProgress), (err) => {
|
|
4996
|
+
return pipeline(listStoriesStream, new StoriesStream(spaceId, onProgress, onError), (err) => {
|
|
4933
4997
|
if (err) getLogger().error(err.message, {
|
|
4934
4998
|
error: err,
|
|
4935
4999
|
errorCode: ERROR_CODES.MIGRATION_CREATE_STORIES_PIPELINE_ERROR
|
|
@@ -5110,16 +5174,23 @@ var MigrationStream = class extends Transform {
|
|
|
5110
5174
|
this.migrationFunctions.set(migrationFile.name, migrationFunction);
|
|
5111
5175
|
return migrationFunction;
|
|
5112
5176
|
}
|
|
5177
|
+
recordFailure(failed) {
|
|
5178
|
+
this.results.failed.push(failed);
|
|
5179
|
+
this.options.onError?.(failed);
|
|
5180
|
+
}
|
|
5113
5181
|
async processStory(story) {
|
|
5114
5182
|
const relevantMigrations = this.options.componentName ? this.options.migrationFiles.filter((file) => migrationTargetsComponent(file.name, this.options.componentName)) : this.options.migrationFiles;
|
|
5115
5183
|
if (!story.content) {
|
|
5116
|
-
this.
|
|
5184
|
+
this.recordFailure({
|
|
5117
5185
|
storyId: story.id,
|
|
5186
|
+
name: story.name,
|
|
5187
|
+
full_slug: story.full_slug,
|
|
5118
5188
|
migrationNames: relevantMigrations.map((m) => m.name),
|
|
5119
5189
|
error: /* @__PURE__ */ new Error("Story content is missing")
|
|
5120
5190
|
});
|
|
5121
5191
|
getLogger().error("Failed to process story: Content is missing", {
|
|
5122
5192
|
storyId: story.id,
|
|
5193
|
+
storyName: story.name,
|
|
5123
5194
|
errorCode: ERROR_CODES.MIGRATION_STORY_CONTENT_MISSING
|
|
5124
5195
|
});
|
|
5125
5196
|
return [];
|
|
@@ -5131,25 +5202,34 @@ var MigrationStream = class extends Transform {
|
|
|
5131
5202
|
}
|
|
5132
5203
|
async applyMigrationsToStory(story, migrationFiles) {
|
|
5133
5204
|
const migrationNames = migrationFiles.map((f) => f.name);
|
|
5205
|
+
let migrationName;
|
|
5134
5206
|
try {
|
|
5135
5207
|
const storyContent = structuredClone(story.content);
|
|
5136
5208
|
const originalContentHash = hash(storyContent);
|
|
5137
5209
|
let processed = false;
|
|
5138
5210
|
for (const migrationFile of migrationFiles) {
|
|
5211
|
+
migrationName = migrationFile.name;
|
|
5139
5212
|
const migrationFunction = await this.getOrLoadMigrationFunction(migrationFile);
|
|
5140
5213
|
if (!migrationFunction) {
|
|
5141
5214
|
const error = /* @__PURE__ */ new Error(`Failed to load migration function from file "${migrationFile.name}"`);
|
|
5142
|
-
this.
|
|
5215
|
+
this.recordFailure({
|
|
5143
5216
|
storyId: story.id,
|
|
5217
|
+
name: story.name,
|
|
5218
|
+
full_slug: story.full_slug,
|
|
5144
5219
|
migrationNames,
|
|
5145
5220
|
error
|
|
5146
5221
|
});
|
|
5147
|
-
getLogger().error(error.message, {
|
|
5222
|
+
getLogger().error(error.message, {
|
|
5223
|
+
storyId: story.id,
|
|
5224
|
+
storyName: story.name,
|
|
5225
|
+
errorCode: ERROR_CODES.MIGRATION_FILE_NOT_FOUND
|
|
5226
|
+
});
|
|
5148
5227
|
return null;
|
|
5149
5228
|
}
|
|
5150
5229
|
const migrationProcessed = applyMigrationToAllBlocks(storyContent, migrationFunction, migrationFile.name);
|
|
5151
5230
|
processed = processed || migrationProcessed;
|
|
5152
5231
|
}
|
|
5232
|
+
migrationName = void 0;
|
|
5153
5233
|
const contentChanged = originalContentHash !== hash(storyContent);
|
|
5154
5234
|
if (processed && contentChanged) {
|
|
5155
5235
|
await saveRollbackData({
|
|
@@ -5178,6 +5258,7 @@ var MigrationStream = class extends Transform {
|
|
|
5178
5258
|
return {
|
|
5179
5259
|
storyId: story.id,
|
|
5180
5260
|
name: story.name,
|
|
5261
|
+
full_slug: story.full_slug,
|
|
5181
5262
|
content: storyContent,
|
|
5182
5263
|
published: story.published ?? void 0,
|
|
5183
5264
|
unpublished_changes: story.unpublished_changes ?? void 0
|
|
@@ -5210,14 +5291,19 @@ var MigrationStream = class extends Transform {
|
|
|
5210
5291
|
}
|
|
5211
5292
|
} catch (maybeError) {
|
|
5212
5293
|
const error = toError(maybeError);
|
|
5213
|
-
this.
|
|
5294
|
+
this.recordFailure({
|
|
5214
5295
|
storyId: story.id,
|
|
5296
|
+
name: story.name,
|
|
5297
|
+
full_slug: story.full_slug,
|
|
5215
5298
|
migrationNames,
|
|
5299
|
+
migrationName,
|
|
5216
5300
|
error
|
|
5217
5301
|
});
|
|
5218
5302
|
getLogger().error(error.message, {
|
|
5219
5303
|
storyId: story.id,
|
|
5304
|
+
storyName: story.name,
|
|
5220
5305
|
migrationNames,
|
|
5306
|
+
migrationName,
|
|
5221
5307
|
error,
|
|
5222
5308
|
errorCode: ERROR_CODES.MIGRATION_APPLY_TO_STORY_ERROR
|
|
5223
5309
|
});
|
|
@@ -5238,7 +5324,7 @@ var MigrationStream = class extends Transform {
|
|
|
5238
5324
|
*/
|
|
5239
5325
|
getSummary() {
|
|
5240
5326
|
const { successful, failed, skipped } = this.results;
|
|
5241
|
-
let summary = `Migration Results: ${new Set(successful.map((result) => result.storyId)).size} stories
|
|
5327
|
+
let summary = `Migration Results: ${new Set(successful.map((result) => result.storyId)).size} stories migrated, ${skipped.length} stories skipped`;
|
|
5242
5328
|
if (skipped.length > 0) {
|
|
5243
5329
|
const skippedByReason = skipped.reduce((acc, item) => {
|
|
5244
5330
|
if (!acc[item.reason]) acc[item.reason] = 0;
|
|
@@ -5328,7 +5414,20 @@ var UpdateStream = class extends Writable {
|
|
|
5328
5414
|
async _write(chunk, _encoding, callback) {
|
|
5329
5415
|
try {
|
|
5330
5416
|
await this.semaphore.acquire();
|
|
5331
|
-
this.
|
|
5417
|
+
if (this.destroyed) {
|
|
5418
|
+
this.semaphore.release();
|
|
5419
|
+
callback();
|
|
5420
|
+
return;
|
|
5421
|
+
}
|
|
5422
|
+
this.updateStory(chunk).catch((maybeError) => {
|
|
5423
|
+
const error = toError(maybeError);
|
|
5424
|
+
getLogger().error(error.message, {
|
|
5425
|
+
storyId: chunk.storyId,
|
|
5426
|
+
storyName: chunk.name,
|
|
5427
|
+
error,
|
|
5428
|
+
errorCode: ERROR_CODES.MIGRATION_STORY_UPDATE_ERROR
|
|
5429
|
+
});
|
|
5430
|
+
}).finally(() => {
|
|
5332
5431
|
this.semaphore.release();
|
|
5333
5432
|
});
|
|
5334
5433
|
callback();
|
|
@@ -5337,7 +5436,7 @@ var UpdateStream = class extends Writable {
|
|
|
5337
5436
|
}
|
|
5338
5437
|
}
|
|
5339
5438
|
async updateStory(migrationResult) {
|
|
5340
|
-
const { storyId, name, content, published, unpublished_changes } = migrationResult;
|
|
5439
|
+
const { storyId, name, full_slug, content, published, unpublished_changes } = migrationResult;
|
|
5341
5440
|
const storyName = name || storyId.toString();
|
|
5342
5441
|
try {
|
|
5343
5442
|
const payload = {
|
|
@@ -5367,38 +5466,44 @@ var UpdateStream = class extends Writable {
|
|
|
5367
5466
|
getLogger().info("Updated story", { storyId });
|
|
5368
5467
|
} else {
|
|
5369
5468
|
const error = /* @__PURE__ */ new Error("Update returned null");
|
|
5370
|
-
this.
|
|
5469
|
+
this.recordFailure({
|
|
5371
5470
|
storyId,
|
|
5372
5471
|
name: storyName,
|
|
5472
|
+
full_slug,
|
|
5373
5473
|
error
|
|
5374
5474
|
});
|
|
5375
|
-
this.results.totalProcessed++;
|
|
5376
|
-
this.options.onProgress?.(this.results.totalProcessed);
|
|
5377
5475
|
getLogger().error(`Failed to update story: ${error.message}`, {
|
|
5378
5476
|
storyId,
|
|
5477
|
+
storyName,
|
|
5379
5478
|
errorCode: ERROR_CODES.MIGRATION_STORY_UPDATE_NULL
|
|
5380
5479
|
});
|
|
5381
5480
|
}
|
|
5382
5481
|
} catch (maybeError) {
|
|
5383
5482
|
const error = toError(maybeError);
|
|
5384
|
-
this.
|
|
5483
|
+
this.recordFailure({
|
|
5385
5484
|
storyId,
|
|
5386
5485
|
name: storyName,
|
|
5486
|
+
full_slug,
|
|
5387
5487
|
error
|
|
5388
5488
|
});
|
|
5389
|
-
this.results.totalProcessed++;
|
|
5390
|
-
this.options.onProgress?.(this.results.totalProcessed);
|
|
5391
5489
|
getLogger().error(error.message, {
|
|
5392
5490
|
storyId,
|
|
5491
|
+
storyName,
|
|
5393
5492
|
error,
|
|
5394
5493
|
errorCode: ERROR_CODES.MIGRATION_STORY_UPDATE_ERROR
|
|
5395
5494
|
});
|
|
5495
|
+
if (isSystemicError(error)) this.destroy(error);
|
|
5396
5496
|
}
|
|
5397
5497
|
}
|
|
5498
|
+
recordFailure(failed) {
|
|
5499
|
+
this.results.failed.push(failed);
|
|
5500
|
+
this.results.totalProcessed++;
|
|
5501
|
+
this.options.onProgress?.(this.results.totalProcessed);
|
|
5502
|
+
this.options.onError?.(failed);
|
|
5503
|
+
}
|
|
5398
5504
|
async _destroy(error, callback) {
|
|
5399
5505
|
try {
|
|
5400
5506
|
await this.semaphore.drain();
|
|
5401
|
-
callback();
|
|
5402
5507
|
} catch (batchError) {
|
|
5403
5508
|
callback(batchError);
|
|
5404
5509
|
return;
|
|
@@ -5472,6 +5577,10 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
5472
5577
|
const storiesProgress = ui.createProgressBar({ title: "Fetching Stories...".padEnd(19) });
|
|
5473
5578
|
const migrationsProgress = ui.createProgressBar({ title: "Applying Migrations".padEnd(19) });
|
|
5474
5579
|
const updateProgress = ui.createProgressBar({ title: "Updating Stories...".padEnd(19) });
|
|
5580
|
+
const failedStories = [];
|
|
5581
|
+
let listedStories = 0;
|
|
5582
|
+
let fetchedStories = 0;
|
|
5583
|
+
let fetchFailedStories = 0;
|
|
5475
5584
|
const storiesStream = await createStoriesStream({
|
|
5476
5585
|
spaceId: space,
|
|
5477
5586
|
params: {
|
|
@@ -5482,11 +5591,25 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
5482
5591
|
})
|
|
5483
5592
|
},
|
|
5484
5593
|
onTotal: (total) => {
|
|
5594
|
+
listedStories = total;
|
|
5485
5595
|
storiesProgress.setTotal(total);
|
|
5486
5596
|
migrationsProgress.setTotal(total);
|
|
5487
5597
|
},
|
|
5488
5598
|
onProgress: () => {
|
|
5599
|
+
fetchedStories++;
|
|
5600
|
+
storiesProgress.increment();
|
|
5601
|
+
},
|
|
5602
|
+
onError: ({ storyId, name, full_slug, error }) => {
|
|
5603
|
+
fetchFailedStories++;
|
|
5489
5604
|
storiesProgress.increment();
|
|
5605
|
+
migrationsProgress.increment();
|
|
5606
|
+
failedStories.push({
|
|
5607
|
+
id: storyId,
|
|
5608
|
+
name,
|
|
5609
|
+
full_slug,
|
|
5610
|
+
step: "fetch",
|
|
5611
|
+
error: error.message
|
|
5612
|
+
});
|
|
5490
5613
|
}
|
|
5491
5614
|
});
|
|
5492
5615
|
const migrationStream = new MigrationStream({
|
|
@@ -5500,6 +5623,16 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
5500
5623
|
},
|
|
5501
5624
|
onProgress: () => {
|
|
5502
5625
|
migrationsProgress.increment();
|
|
5626
|
+
},
|
|
5627
|
+
onError: ({ storyId, name, full_slug, error, migrationName }) => {
|
|
5628
|
+
failedStories.push({
|
|
5629
|
+
id: storyId,
|
|
5630
|
+
name,
|
|
5631
|
+
full_slug,
|
|
5632
|
+
step: "migrate",
|
|
5633
|
+
migration: migrationName,
|
|
5634
|
+
error: error.message
|
|
5635
|
+
});
|
|
5503
5636
|
}
|
|
5504
5637
|
});
|
|
5505
5638
|
const updateStream = new UpdateStream({
|
|
@@ -5508,22 +5641,23 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
5508
5641
|
dryRun,
|
|
5509
5642
|
onProgress: () => {
|
|
5510
5643
|
updateProgress.increment();
|
|
5644
|
+
},
|
|
5645
|
+
onError: ({ storyId, name, full_slug, error }) => {
|
|
5646
|
+
failedStories.push({
|
|
5647
|
+
id: storyId,
|
|
5648
|
+
name,
|
|
5649
|
+
full_slug,
|
|
5650
|
+
step: "update",
|
|
5651
|
+
error: error.message
|
|
5652
|
+
});
|
|
5511
5653
|
}
|
|
5512
5654
|
});
|
|
5513
|
-
await new Promise((resolve
|
|
5655
|
+
const fatalError = await new Promise((resolve) => {
|
|
5514
5656
|
pipeline(storiesStream, migrationStream, updateStream, (err) => {
|
|
5515
|
-
|
|
5516
|
-
reject(err);
|
|
5517
|
-
return;
|
|
5518
|
-
}
|
|
5519
|
-
resolve();
|
|
5657
|
+
resolve(err ?? null);
|
|
5520
5658
|
});
|
|
5521
5659
|
});
|
|
5522
5660
|
ui.stopAllProgressBars();
|
|
5523
|
-
const migrationSummary = migrationStream.getSummary();
|
|
5524
|
-
ui.info(migrationSummary);
|
|
5525
|
-
const updateSummary = updateStream.getSummary();
|
|
5526
|
-
ui.info(updateSummary);
|
|
5527
5661
|
const migrationStreamResults = migrationStream.getResults();
|
|
5528
5662
|
const migrationResults = {
|
|
5529
5663
|
total: migrationStreamResults.totalProcessed,
|
|
@@ -5537,13 +5671,40 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
5537
5671
|
succeeded: updateStreamResults.successful.length,
|
|
5538
5672
|
failed: updateStreamResults.failed.length
|
|
5539
5673
|
};
|
|
5674
|
+
const fetchResults = {
|
|
5675
|
+
total: fetchedStories + fetchFailedStories,
|
|
5676
|
+
succeeded: fetchedStories,
|
|
5677
|
+
failed: fetchFailedStories
|
|
5678
|
+
};
|
|
5679
|
+
if (fatalError && listedStories > 0) {
|
|
5680
|
+
const finishedStories = fetchResults.failed + migrationResults.failed + migrationResults.skipped + updateResults.total;
|
|
5681
|
+
ui.warn(`Run stopped after ${finishedStories} of ${listedStories} stories.`);
|
|
5682
|
+
}
|
|
5683
|
+
if (!fatalError || listedStories > 0) ui.info(migrationStream.getSummary());
|
|
5684
|
+
if (updateResults.total > 0 || !fatalError && failedStories.length === 0) ui.info(updateStream.getSummary());
|
|
5685
|
+
if (failedStories.length > 0) ui.list(listFailedStories(failedStories));
|
|
5686
|
+
const fullListPath = reporter.enabled ? reporter.filePath : logger.transports.find((transport) => transport instanceof FileTransport)?.filePath;
|
|
5540
5687
|
logger.info("Migration finished", {
|
|
5688
|
+
fetchResults,
|
|
5541
5689
|
migrationResults,
|
|
5542
5690
|
updateResults
|
|
5543
5691
|
});
|
|
5692
|
+
reporter.addSummary("fetchResults", fetchResults);
|
|
5544
5693
|
reporter.addSummary("migrationResults", migrationResults);
|
|
5545
5694
|
reporter.addSummary("updateResults", updateResults);
|
|
5546
|
-
reporter.
|
|
5695
|
+
if (failedStories.length > 0) reporter.addMeta("failedStories", failedStories);
|
|
5696
|
+
try {
|
|
5697
|
+
reporter.finalize(fatalError ?? void 0);
|
|
5698
|
+
if (failedStories.length > 0 && fullListPath) ui.info(`All failed stories are listed in ${fullListPath}`);
|
|
5699
|
+
} catch (error) {
|
|
5700
|
+
if (!fatalError) throw error;
|
|
5701
|
+
handleError(error, verbose);
|
|
5702
|
+
}
|
|
5703
|
+
if (fatalError) {
|
|
5704
|
+
handleError(fatalError, verbose);
|
|
5705
|
+
return;
|
|
5706
|
+
}
|
|
5707
|
+
process.exitCode = failedStories.length > 0 ? 1 : 0;
|
|
5547
5708
|
} catch (error) {
|
|
5548
5709
|
handleError(error, verbose);
|
|
5549
5710
|
}
|
|
@@ -9779,7 +9940,7 @@ const upsertAssetsPipeline = async ({ assetBinaryPath, assetData, directoryPath,
|
|
|
9779
9940
|
}
|
|
9780
9941
|
}));
|
|
9781
9942
|
await pipeline$1(steps);
|
|
9782
|
-
for (const line of failures.toListLines()) ui.warn(line);
|
|
9943
|
+
for (const line of failures.toListLines("push", ["asset", "assets"])) ui.warn(line);
|
|
9783
9944
|
return [["assetResults", summary]];
|
|
9784
9945
|
};
|
|
9785
9946
|
const mapAssetReferencesInStoriesPipeline = async ({ logger, maps, schemas, space, transports, ui }) => {
|
|
@@ -10261,7 +10422,7 @@ assetsCommand.command("transfer [asset-id...]").option("-s, --space <space>", "s
|
|
|
10261
10422
|
if (summary.failed > 0) {
|
|
10262
10423
|
const failures = new FailureReasonGroup();
|
|
10263
10424
|
for (const result of results) if (result.status === "failed") failures.record(result.reason ?? "Unknown error");
|
|
10264
|
-
ui.list(failures.toListLines("transfer"));
|
|
10425
|
+
ui.list(failures.toListLines("transfer", ["asset", "assets"]));
|
|
10265
10426
|
}
|
|
10266
10427
|
reporter.addSummary("transferResults", summary);
|
|
10267
10428
|
reporter.finalize();
|