@strapi/data-transfer 5.1.0 → 5.1.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.js +56 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -12
- package/dist/index.mjs.map +1 -1
- package/dist/strapi/providers/remote-destination/index.d.ts +7 -1
- package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -1
- package/dist/strapi/remote/handlers/push.d.ts +3 -0
- package/dist/strapi/remote/handlers/push.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -2576,11 +2576,21 @@ class RemoteStrapiDestinationProvider {
|
|
|
2576
2576
|
ws;
|
|
2577
2577
|
dispatcher;
|
|
2578
2578
|
transferID;
|
|
2579
|
+
stats;
|
|
2579
2580
|
constructor(options) {
|
|
2580
2581
|
this.options = options;
|
|
2581
2582
|
this.ws = null;
|
|
2582
2583
|
this.dispatcher = null;
|
|
2583
2584
|
this.transferID = null;
|
|
2585
|
+
this.resetStats();
|
|
2586
|
+
}
|
|
2587
|
+
resetStats() {
|
|
2588
|
+
this.stats = {
|
|
2589
|
+
assets: { count: 0 },
|
|
2590
|
+
entities: { count: 0 },
|
|
2591
|
+
links: { count: 0 },
|
|
2592
|
+
configuration: { count: 0 }
|
|
2593
|
+
};
|
|
2584
2594
|
}
|
|
2585
2595
|
async initTransfer() {
|
|
2586
2596
|
const { strategy, restore } = this.options;
|
|
@@ -2592,6 +2602,7 @@ class RemoteStrapiDestinationProvider {
|
|
|
2592
2602
|
if (!res?.transferID) {
|
|
2593
2603
|
throw new ProviderTransferError("Init failed, invalid response from the server");
|
|
2594
2604
|
}
|
|
2605
|
+
this.resetStats();
|
|
2595
2606
|
return res.transferID;
|
|
2596
2607
|
}
|
|
2597
2608
|
#startStepOnce(stage) {
|
|
@@ -2609,25 +2620,35 @@ class RemoteStrapiDestinationProvider {
|
|
|
2609
2620
|
}
|
|
2610
2621
|
return new ProviderTransferError("Unexpected error");
|
|
2611
2622
|
}
|
|
2623
|
+
this.stats[step] = { count: 0 };
|
|
2612
2624
|
return null;
|
|
2613
2625
|
}
|
|
2614
2626
|
async #endStep(step) {
|
|
2615
2627
|
try {
|
|
2616
|
-
await this.dispatcher?.dispatchTransferStep({
|
|
2628
|
+
const res = await this.dispatcher?.dispatchTransferStep({
|
|
2629
|
+
action: "end",
|
|
2630
|
+
step
|
|
2631
|
+
});
|
|
2632
|
+
return { stats: res?.stats ?? null, error: null };
|
|
2617
2633
|
} catch (e) {
|
|
2618
2634
|
if (e instanceof Error) {
|
|
2619
|
-
return e;
|
|
2635
|
+
return { stats: null, error: e };
|
|
2620
2636
|
}
|
|
2621
2637
|
if (typeof e === "string") {
|
|
2622
|
-
return new ProviderTransferError(e);
|
|
2638
|
+
return { stats: null, error: new ProviderTransferError(e) };
|
|
2623
2639
|
}
|
|
2624
|
-
return new ProviderTransferError("Unexpected error");
|
|
2640
|
+
return { stats: null, error: new ProviderTransferError("Unexpected error") };
|
|
2625
2641
|
}
|
|
2626
|
-
return null;
|
|
2627
2642
|
}
|
|
2628
|
-
async #streamStep(step,
|
|
2643
|
+
async #streamStep(step, message) {
|
|
2629
2644
|
try {
|
|
2630
|
-
|
|
2645
|
+
if (step === "assets") {
|
|
2646
|
+
const assetMessage = message;
|
|
2647
|
+
this.stats[step].count += assetMessage.filter((data) => data.action === "start").length;
|
|
2648
|
+
} else {
|
|
2649
|
+
this.stats[step].count += message.length;
|
|
2650
|
+
}
|
|
2651
|
+
await this.dispatcher?.dispatchTransferStep({ action: "stream", step, data: message });
|
|
2631
2652
|
} catch (e) {
|
|
2632
2653
|
if (e instanceof Error) {
|
|
2633
2654
|
return e;
|
|
@@ -2654,8 +2675,16 @@ class RemoteStrapiDestinationProvider {
|
|
|
2654
2675
|
return callback(streamError);
|
|
2655
2676
|
}
|
|
2656
2677
|
}
|
|
2657
|
-
const
|
|
2658
|
-
|
|
2678
|
+
const { error, stats } = await this.#endStep(step);
|
|
2679
|
+
const { count } = this.stats[step];
|
|
2680
|
+
if (stats && (stats.started !== count || stats.finished !== count)) {
|
|
2681
|
+
callback(
|
|
2682
|
+
new Error(
|
|
2683
|
+
`Data missing: sent ${this.stats[step].count} ${step}, recieved ${stats.started} and saved ${stats.finished} ${step}`
|
|
2684
|
+
)
|
|
2685
|
+
);
|
|
2686
|
+
}
|
|
2687
|
+
callback(error);
|
|
2659
2688
|
},
|
|
2660
2689
|
write: async (chunk, _encoding, callback) => {
|
|
2661
2690
|
const startError = await startTransferOnce();
|
|
@@ -2784,7 +2813,7 @@ class RemoteStrapiDestinationProvider {
|
|
|
2784
2813
|
await flush();
|
|
2785
2814
|
}
|
|
2786
2815
|
if (hasStarted) {
|
|
2787
|
-
const endStepError = await this.#endStep("assets");
|
|
2816
|
+
const { error: endStepError } = await this.#endStep("assets");
|
|
2788
2817
|
if (endStepError) {
|
|
2789
2818
|
return callback(endStepError);
|
|
2790
2819
|
}
|
|
@@ -3625,6 +3654,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3625
3654
|
throw new Error("Stream already created, something went wrong");
|
|
3626
3655
|
}
|
|
3627
3656
|
await this.createWritableStreamForStep(stage);
|
|
3657
|
+
this.stats[stage] = { started: 0, finished: 0 };
|
|
3628
3658
|
return { ok: true };
|
|
3629
3659
|
}
|
|
3630
3660
|
if (msg.action === "stream") {
|
|
@@ -3636,7 +3666,13 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3636
3666
|
if (stage === "assets") {
|
|
3637
3667
|
return this.streamAsset(msg.data);
|
|
3638
3668
|
}
|
|
3639
|
-
await Promise.all(
|
|
3669
|
+
await Promise.all(
|
|
3670
|
+
msg.data.map(async (item) => {
|
|
3671
|
+
this.stats[stage].started += 1;
|
|
3672
|
+
await writeAsync(stream2, item);
|
|
3673
|
+
this.stats[stage].finished += 1;
|
|
3674
|
+
})
|
|
3675
|
+
);
|
|
3640
3676
|
}
|
|
3641
3677
|
if (msg.action === "end") {
|
|
3642
3678
|
this.unlockTransferStep(stage);
|
|
@@ -3647,7 +3683,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3647
3683
|
});
|
|
3648
3684
|
}
|
|
3649
3685
|
delete this.streams?.[stage];
|
|
3650
|
-
return { ok: true };
|
|
3686
|
+
return { ok: true, stats: this.stats[stage] };
|
|
3651
3687
|
}
|
|
3652
3688
|
},
|
|
3653
3689
|
async onTransferAction(msg) {
|
|
@@ -3677,6 +3713,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3677
3713
|
throw new Error("Stream not defined");
|
|
3678
3714
|
}
|
|
3679
3715
|
if (action === "start") {
|
|
3716
|
+
this.stats.assets.started += 1;
|
|
3680
3717
|
this.assets[assetID] = { ...item.data, stream: new PassThrough() };
|
|
3681
3718
|
writeAsync(assetsStream, this.assets[assetID]);
|
|
3682
3719
|
}
|
|
@@ -3689,6 +3726,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3689
3726
|
await new Promise((resolve, reject2) => {
|
|
3690
3727
|
const { stream: assetStream } = this.assets[assetID];
|
|
3691
3728
|
assetStream.on("close", () => {
|
|
3729
|
+
this.stats.assets.finished += 1;
|
|
3692
3730
|
delete this.assets[assetID];
|
|
3693
3731
|
resolve();
|
|
3694
3732
|
}).on("error", reject2).end();
|
|
@@ -3713,6 +3751,12 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3713
3751
|
this.startedAt = Date.now();
|
|
3714
3752
|
this.assets = {};
|
|
3715
3753
|
this.streams = {};
|
|
3754
|
+
this.stats = {
|
|
3755
|
+
assets: { started: 0, finished: 0 },
|
|
3756
|
+
configuration: { started: 0, finished: 0 },
|
|
3757
|
+
entities: { started: 0, finished: 0 },
|
|
3758
|
+
links: { started: 0, finished: 0 }
|
|
3759
|
+
};
|
|
3716
3760
|
this.flow = createFlow(DEFAULT_TRANSFER_FLOW);
|
|
3717
3761
|
this.provider = createLocalStrapiDestinationProvider({
|
|
3718
3762
|
...params.options,
|