@strapi/data-transfer 5.1.0 → 5.2.0
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.js
CHANGED
|
@@ -2604,11 +2604,21 @@ class RemoteStrapiDestinationProvider {
|
|
|
2604
2604
|
ws;
|
|
2605
2605
|
dispatcher;
|
|
2606
2606
|
transferID;
|
|
2607
|
+
stats;
|
|
2607
2608
|
constructor(options) {
|
|
2608
2609
|
this.options = options;
|
|
2609
2610
|
this.ws = null;
|
|
2610
2611
|
this.dispatcher = null;
|
|
2611
2612
|
this.transferID = null;
|
|
2613
|
+
this.resetStats();
|
|
2614
|
+
}
|
|
2615
|
+
resetStats() {
|
|
2616
|
+
this.stats = {
|
|
2617
|
+
assets: { count: 0 },
|
|
2618
|
+
entities: { count: 0 },
|
|
2619
|
+
links: { count: 0 },
|
|
2620
|
+
configuration: { count: 0 }
|
|
2621
|
+
};
|
|
2612
2622
|
}
|
|
2613
2623
|
async initTransfer() {
|
|
2614
2624
|
const { strategy, restore } = this.options;
|
|
@@ -2620,6 +2630,7 @@ class RemoteStrapiDestinationProvider {
|
|
|
2620
2630
|
if (!res?.transferID) {
|
|
2621
2631
|
throw new ProviderTransferError("Init failed, invalid response from the server");
|
|
2622
2632
|
}
|
|
2633
|
+
this.resetStats();
|
|
2623
2634
|
return res.transferID;
|
|
2624
2635
|
}
|
|
2625
2636
|
#startStepOnce(stage) {
|
|
@@ -2637,25 +2648,35 @@ class RemoteStrapiDestinationProvider {
|
|
|
2637
2648
|
}
|
|
2638
2649
|
return new ProviderTransferError("Unexpected error");
|
|
2639
2650
|
}
|
|
2651
|
+
this.stats[step] = { count: 0 };
|
|
2640
2652
|
return null;
|
|
2641
2653
|
}
|
|
2642
2654
|
async #endStep(step) {
|
|
2643
2655
|
try {
|
|
2644
|
-
await this.dispatcher?.dispatchTransferStep({
|
|
2656
|
+
const res = await this.dispatcher?.dispatchTransferStep({
|
|
2657
|
+
action: "end",
|
|
2658
|
+
step
|
|
2659
|
+
});
|
|
2660
|
+
return { stats: res?.stats ?? null, error: null };
|
|
2645
2661
|
} catch (e) {
|
|
2646
2662
|
if (e instanceof Error) {
|
|
2647
|
-
return e;
|
|
2663
|
+
return { stats: null, error: e };
|
|
2648
2664
|
}
|
|
2649
2665
|
if (typeof e === "string") {
|
|
2650
|
-
return new ProviderTransferError(e);
|
|
2666
|
+
return { stats: null, error: new ProviderTransferError(e) };
|
|
2651
2667
|
}
|
|
2652
|
-
return new ProviderTransferError("Unexpected error");
|
|
2668
|
+
return { stats: null, error: new ProviderTransferError("Unexpected error") };
|
|
2653
2669
|
}
|
|
2654
|
-
return null;
|
|
2655
2670
|
}
|
|
2656
|
-
async #streamStep(step,
|
|
2671
|
+
async #streamStep(step, message) {
|
|
2657
2672
|
try {
|
|
2658
|
-
|
|
2673
|
+
if (step === "assets") {
|
|
2674
|
+
const assetMessage = message;
|
|
2675
|
+
this.stats[step].count += assetMessage.filter((data) => data.action === "start").length;
|
|
2676
|
+
} else {
|
|
2677
|
+
this.stats[step].count += message.length;
|
|
2678
|
+
}
|
|
2679
|
+
await this.dispatcher?.dispatchTransferStep({ action: "stream", step, data: message });
|
|
2659
2680
|
} catch (e) {
|
|
2660
2681
|
if (e instanceof Error) {
|
|
2661
2682
|
return e;
|
|
@@ -2682,8 +2703,16 @@ class RemoteStrapiDestinationProvider {
|
|
|
2682
2703
|
return callback(streamError);
|
|
2683
2704
|
}
|
|
2684
2705
|
}
|
|
2685
|
-
const
|
|
2686
|
-
|
|
2706
|
+
const { error, stats } = await this.#endStep(step);
|
|
2707
|
+
const { count } = this.stats[step];
|
|
2708
|
+
if (stats && (stats.started !== count || stats.finished !== count)) {
|
|
2709
|
+
callback(
|
|
2710
|
+
new Error(
|
|
2711
|
+
`Data missing: sent ${this.stats[step].count} ${step}, recieved ${stats.started} and saved ${stats.finished} ${step}`
|
|
2712
|
+
)
|
|
2713
|
+
);
|
|
2714
|
+
}
|
|
2715
|
+
callback(error);
|
|
2687
2716
|
},
|
|
2688
2717
|
write: async (chunk, _encoding, callback) => {
|
|
2689
2718
|
const startError = await startTransferOnce();
|
|
@@ -2812,7 +2841,7 @@ class RemoteStrapiDestinationProvider {
|
|
|
2812
2841
|
await flush();
|
|
2813
2842
|
}
|
|
2814
2843
|
if (hasStarted) {
|
|
2815
|
-
const endStepError = await this.#endStep("assets");
|
|
2844
|
+
const { error: endStepError } = await this.#endStep("assets");
|
|
2816
2845
|
if (endStepError) {
|
|
2817
2846
|
return callback(endStepError);
|
|
2818
2847
|
}
|
|
@@ -3653,6 +3682,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3653
3682
|
throw new Error("Stream already created, something went wrong");
|
|
3654
3683
|
}
|
|
3655
3684
|
await this.createWritableStreamForStep(stage);
|
|
3685
|
+
this.stats[stage] = { started: 0, finished: 0 };
|
|
3656
3686
|
return { ok: true };
|
|
3657
3687
|
}
|
|
3658
3688
|
if (msg.action === "stream") {
|
|
@@ -3664,7 +3694,13 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3664
3694
|
if (stage === "assets") {
|
|
3665
3695
|
return this.streamAsset(msg.data);
|
|
3666
3696
|
}
|
|
3667
|
-
await Promise.all(
|
|
3697
|
+
await Promise.all(
|
|
3698
|
+
msg.data.map(async (item) => {
|
|
3699
|
+
this.stats[stage].started += 1;
|
|
3700
|
+
await writeAsync(stream2, item);
|
|
3701
|
+
this.stats[stage].finished += 1;
|
|
3702
|
+
})
|
|
3703
|
+
);
|
|
3668
3704
|
}
|
|
3669
3705
|
if (msg.action === "end") {
|
|
3670
3706
|
this.unlockTransferStep(stage);
|
|
@@ -3675,7 +3711,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3675
3711
|
});
|
|
3676
3712
|
}
|
|
3677
3713
|
delete this.streams?.[stage];
|
|
3678
|
-
return { ok: true };
|
|
3714
|
+
return { ok: true, stats: this.stats[stage] };
|
|
3679
3715
|
}
|
|
3680
3716
|
},
|
|
3681
3717
|
async onTransferAction(msg) {
|
|
@@ -3705,6 +3741,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3705
3741
|
throw new Error("Stream not defined");
|
|
3706
3742
|
}
|
|
3707
3743
|
if (action === "start") {
|
|
3744
|
+
this.stats.assets.started += 1;
|
|
3708
3745
|
this.assets[assetID] = { ...item.data, stream: new stream$1.PassThrough() };
|
|
3709
3746
|
writeAsync(assetsStream, this.assets[assetID]);
|
|
3710
3747
|
}
|
|
@@ -3717,6 +3754,7 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3717
3754
|
await new Promise((resolve, reject2) => {
|
|
3718
3755
|
const { stream: assetStream } = this.assets[assetID];
|
|
3719
3756
|
assetStream.on("close", () => {
|
|
3757
|
+
this.stats.assets.finished += 1;
|
|
3720
3758
|
delete this.assets[assetID];
|
|
3721
3759
|
resolve();
|
|
3722
3760
|
}).on("error", reject2).end();
|
|
@@ -3741,6 +3779,12 @@ const createPushController = handlerControllerFactory((proto) => ({
|
|
|
3741
3779
|
this.startedAt = Date.now();
|
|
3742
3780
|
this.assets = {};
|
|
3743
3781
|
this.streams = {};
|
|
3782
|
+
this.stats = {
|
|
3783
|
+
assets: { started: 0, finished: 0 },
|
|
3784
|
+
configuration: { started: 0, finished: 0 },
|
|
3785
|
+
entities: { started: 0, finished: 0 },
|
|
3786
|
+
links: { started: 0, finished: 0 }
|
|
3787
|
+
};
|
|
3744
3788
|
this.flow = createFlow(DEFAULT_TRANSFER_FLOW);
|
|
3745
3789
|
this.provider = createLocalStrapiDestinationProvider({
|
|
3746
3790
|
...params.options,
|