@strapi/data-transfer 4.12.2 → 4.13.0-beta.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/engine/diagnostic.d.ts +40 -0
- package/dist/engine/diagnostic.js +50 -0
- package/dist/engine/diagnostic.js.map +1 -0
- package/dist/engine/errors.d.ts +28 -0
- package/dist/engine/errors.js +29 -0
- package/dist/engine/errors.js.map +1 -0
- package/dist/engine/index.d.ts +64 -0
- package/dist/engine/index.js +664 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/validation/index.d.ts +2 -0
- package/dist/engine/validation/index.js +19 -0
- package/dist/engine/validation/index.js.map +1 -0
- package/dist/engine/validation/provider.d.ts +3 -0
- package/dist/engine/validation/provider.js +18 -0
- package/dist/engine/validation/provider.js.map +1 -0
- package/dist/engine/validation/schemas/index.d.ts +7 -0
- package/dist/engine/validation/schemas/index.js +70 -0
- package/dist/engine/validation/schemas/index.js.map +1 -0
- package/dist/errors/base.d.ts +8 -0
- package/dist/errors/base.js +13 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/constants.d.ts +3 -0
- package/dist/errors/constants.js +9 -0
- package/dist/errors/constants.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +19 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/providers.d.ts +23 -0
- package/dist/errors/providers.js +32 -0
- package/dist/errors/providers.js.map +1 -0
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.js +28 -0
- package/dist/file/index.js.map +1 -0
- package/dist/file/providers/destination/index.d.ts +46 -0
- package/dist/file/providers/destination/index.js +181 -0
- package/dist/file/providers/destination/index.js.map +1 -0
- package/dist/file/providers/destination/utils.d.ts +9 -0
- package/dist/file/providers/destination/utils.js +62 -0
- package/dist/file/providers/destination/utils.js.map +1 -0
- package/dist/file/providers/index.d.ts +2 -0
- package/dist/file/providers/index.js +19 -0
- package/dist/file/providers/index.js.map +1 -0
- package/dist/file/providers/source/index.d.ts +40 -0
- package/dist/file/providers/source/index.js +242 -0
- package/dist/file/providers/source/index.js.map +1 -0
- package/dist/file/providers/source/utils.d.ts +37 -0
- package/dist/file/providers/source/utils.js +62 -0
- package/dist/file/providers/source/utils.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/strapi/index.d.ts +3 -0
- package/dist/strapi/index.js +30 -0
- package/dist/strapi/index.js.map +1 -0
- package/dist/strapi/providers/index.d.ts +4 -0
- package/dist/strapi/providers/index.js +23 -0
- package/dist/strapi/providers/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/index.d.ts +34 -0
- package/dist/strapi/providers/local-destination/index.js +321 -0
- package/dist/strapi/providers/local-destination/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/index.d.ts +1 -0
- package/dist/strapi/providers/local-destination/strategies/index.js +28 -0
- package/dist/strapi/providers/local-destination/strategies/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +5 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +51 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +11 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js +103 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +32 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.js +107 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +4 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.js +32 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
- package/dist/strapi/providers/local-source/assets.d.ts +5 -0
- package/dist/strapi/providers/local-source/assets.js +98 -0
- package/dist/strapi/providers/local-source/assets.js.map +1 -0
- package/dist/strapi/providers/local-source/configuration.d.ts +5 -0
- package/dist/strapi/providers/local-source/configuration.js +36 -0
- package/dist/strapi/providers/local-source/configuration.js.map +1 -0
- package/dist/strapi/providers/local-source/entities.d.ts +10 -0
- package/dist/strapi/providers/local-source/entities.js +85 -0
- package/dist/strapi/providers/local-source/entities.js.map +1 -0
- package/dist/strapi/providers/local-source/index.d.ts +26 -0
- package/dist/strapi/providers/local-source/index.js +98 -0
- package/dist/strapi/providers/local-source/index.js.map +1 -0
- package/dist/strapi/providers/local-source/links.d.ts +5 -0
- package/dist/strapi/providers/local-source/links.js +23 -0
- package/dist/strapi/providers/local-source/links.js.map +1 -0
- package/dist/strapi/providers/remote-destination/index.d.ts +39 -0
- package/dist/strapi/providers/remote-destination/index.js +269 -0
- package/dist/strapi/providers/remote-destination/index.js.map +1 -0
- package/dist/strapi/providers/remote-source/index.d.ts +39 -0
- package/dist/strapi/providers/remote-source/index.js +239 -0
- package/dist/strapi/providers/remote-source/index.js.map +1 -0
- package/dist/strapi/providers/utils.d.ts +39 -0
- package/dist/strapi/providers/utils.js +138 -0
- package/dist/strapi/providers/utils.js.map +1 -0
- package/dist/strapi/queries/entity.d.ts +2 -0
- package/dist/strapi/queries/entity.js +130 -0
- package/dist/strapi/queries/entity.js.map +1 -0
- package/dist/strapi/queries/index.d.ts +2 -0
- package/dist/strapi/queries/index.js +29 -0
- package/dist/strapi/queries/index.js.map +1 -0
- package/dist/strapi/queries/link.d.ts +7 -0
- package/dist/strapi/queries/link.js +215 -0
- package/dist/strapi/queries/link.js.map +1 -0
- package/dist/strapi/remote/constants.d.ts +4 -0
- package/dist/strapi/remote/constants.js +6 -0
- package/dist/strapi/remote/constants.js.map +1 -0
- package/dist/strapi/remote/flows/default.d.ts +3 -0
- package/dist/strapi/remote/flows/default.js +41 -0
- package/dist/strapi/remote/flows/default.js.map +1 -0
- package/dist/strapi/remote/flows/index.d.ts +18 -0
- package/dist/strapi/remote/flows/index.js +59 -0
- package/dist/strapi/remote/flows/index.js.map +1 -0
- package/dist/strapi/remote/handlers/abstract.d.ts +71 -0
- package/dist/strapi/remote/handlers/abstract.js +3 -0
- package/dist/strapi/remote/handlers/abstract.js.map +1 -0
- package/dist/strapi/remote/handlers/constants.d.ts +2 -0
- package/dist/strapi/remote/handlers/constants.js +5 -0
- package/dist/strapi/remote/handlers/constants.js.map +1 -0
- package/dist/strapi/remote/handlers/index.d.ts +3 -0
- package/dist/strapi/remote/handlers/index.js +10 -0
- package/dist/strapi/remote/handlers/index.js.map +1 -0
- package/dist/strapi/remote/handlers/pull.d.ts +22 -0
- package/dist/strapi/remote/handlers/pull.js +243 -0
- package/dist/strapi/remote/handlers/pull.js.map +1 -0
- package/dist/strapi/remote/handlers/push.d.ts +75 -0
- package/dist/strapi/remote/handlers/push.js +311 -0
- package/dist/strapi/remote/handlers/push.js.map +1 -0
- package/dist/strapi/remote/handlers/utils.d.ts +25 -0
- package/dist/strapi/remote/handlers/utils.js +217 -0
- package/dist/strapi/remote/handlers/utils.js.map +1 -0
- package/dist/strapi/remote/index.d.ts +2 -0
- package/dist/strapi/remote/index.js +29 -0
- package/dist/strapi/remote/index.js.map +1 -0
- package/dist/utils/encryption/decrypt.d.ts +11 -0
- package/dist/utils/encryption/decrypt.js +47 -0
- package/dist/utils/encryption/decrypt.js.map +1 -0
- package/dist/utils/encryption/encrypt.d.ts +11 -0
- package/dist/utils/encryption/encrypt.js +47 -0
- package/dist/utils/encryption/encrypt.js.map +1 -0
- package/dist/utils/encryption/index.d.ts +2 -0
- package/dist/utils/encryption/index.js +19 -0
- package/dist/utils/encryption/index.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +33 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json.d.ts +30 -0
- package/dist/utils/json.js +68 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/middleware.d.ts +2 -0
- package/dist/utils/middleware.js +14 -0
- package/dist/utils/middleware.js.map +1 -0
- package/dist/utils/providers.d.ts +2 -0
- package/dist/utils/providers.js +11 -0
- package/dist/utils/providers.js.map +1 -0
- package/dist/utils/schema.d.ts +6 -0
- package/dist/utils/schema.js +29 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/stream.d.ts +27 -0
- package/dist/utils/stream.js +59 -0
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/transaction.d.ts +3 -0
- package/dist/utils/transaction.js +88 -0
- package/dist/utils/transaction.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TransferStage } from '../../../../types';
|
|
2
|
+
export type Step = {
|
|
3
|
+
kind: 'action';
|
|
4
|
+
action: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'transfer';
|
|
7
|
+
stage: TransferStage;
|
|
8
|
+
locked?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export { default as DEFAULT_TRANSFER_FLOW } from './default';
|
|
11
|
+
export interface TransferFlow {
|
|
12
|
+
has(step: Step): boolean;
|
|
13
|
+
can(step: Step): boolean;
|
|
14
|
+
cannot(step: Step): boolean;
|
|
15
|
+
set(step: Step): this;
|
|
16
|
+
get(): Step | null;
|
|
17
|
+
}
|
|
18
|
+
export declare const createFlow: (flow: readonly Step[]) => TransferFlow;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createFlow = exports.DEFAULT_TRANSFER_FLOW = void 0;
|
|
7
|
+
var default_1 = require("./default");
|
|
8
|
+
Object.defineProperty(exports, "DEFAULT_TRANSFER_FLOW", { enumerable: true, get: function () { return __importDefault(default_1).default; } });
|
|
9
|
+
const createFlow = (flow) => {
|
|
10
|
+
const state = { step: null };
|
|
11
|
+
/**
|
|
12
|
+
* Equality check between two steps
|
|
13
|
+
*/
|
|
14
|
+
const stepEqual = (stepA, stepB) => {
|
|
15
|
+
if (stepA.kind === 'action' && stepB.kind === 'action') {
|
|
16
|
+
return stepA.action === stepB.action;
|
|
17
|
+
}
|
|
18
|
+
if (stepA.kind === 'transfer' && stepB.kind === 'transfer') {
|
|
19
|
+
return stepA.stage === stepB.stage;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Find the index for a given step
|
|
25
|
+
*/
|
|
26
|
+
const findStepIndex = (step) => flow.findIndex((flowStep) => stepEqual(step, flowStep));
|
|
27
|
+
return {
|
|
28
|
+
has(step) {
|
|
29
|
+
return findStepIndex(step) !== -1;
|
|
30
|
+
},
|
|
31
|
+
can(step) {
|
|
32
|
+
if (state.step === null) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const indexesDifference = findStepIndex(step) - findStepIndex(state.step);
|
|
36
|
+
// It's possible to send multiple time the same transfer step in a row
|
|
37
|
+
if (indexesDifference === 0 && step.kind === 'transfer') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return indexesDifference > 0;
|
|
41
|
+
},
|
|
42
|
+
cannot(step) {
|
|
43
|
+
return !this.can(step);
|
|
44
|
+
},
|
|
45
|
+
set(step) {
|
|
46
|
+
const canSwitch = this.can(step);
|
|
47
|
+
if (!canSwitch) {
|
|
48
|
+
throw new Error('Impossible to proceed to the given step');
|
|
49
|
+
}
|
|
50
|
+
state.step = step;
|
|
51
|
+
return this;
|
|
52
|
+
},
|
|
53
|
+
get() {
|
|
54
|
+
return state.step;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.createFlow = createFlow;
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/remote/flows/index.ts"],"names":[],"mappings":";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CAAC,IAAU;YACf,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAED,GAAG,CAAC,IAAU;YACZ,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAEjC,IAAI,CAAC,SAAS,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;aAC5D;YAED,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;YAElB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,GAAG;YACD,OAAO,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA/DW,QAAA,UAAU,cA+DrB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { WebSocket, RawData } from 'ws';
|
|
3
|
+
import type { ValidTransferCommand } from './constants';
|
|
4
|
+
import type { TransferMethod } from '../constants';
|
|
5
|
+
type BufferLike = Parameters<WebSocket['send']>[0];
|
|
6
|
+
export interface TransferState {
|
|
7
|
+
id?: string;
|
|
8
|
+
startedAt?: number;
|
|
9
|
+
response?: {
|
|
10
|
+
uuid?: string;
|
|
11
|
+
e?: Error | null;
|
|
12
|
+
data?: unknown;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface Handler {
|
|
16
|
+
get transferID(): TransferState['id'];
|
|
17
|
+
set transferID(id: TransferState['id']);
|
|
18
|
+
get startedAt(): TransferState['startedAt'];
|
|
19
|
+
set startedAt(id: TransferState['startedAt']);
|
|
20
|
+
get response(): TransferState['response'];
|
|
21
|
+
set response(response: TransferState['response']);
|
|
22
|
+
addUUID(uuid: string): void;
|
|
23
|
+
hasUUID(uuid: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns whether a transfer is currently in progress or not
|
|
26
|
+
*/
|
|
27
|
+
isTransferStarted(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Make sure the current transfer is started and initialized
|
|
30
|
+
*/
|
|
31
|
+
assertValidTransfer(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Checks that the given string is a valid transfer command
|
|
34
|
+
*/
|
|
35
|
+
assertValidTransferCommand(command: string): asserts command is ValidTransferCommand;
|
|
36
|
+
/**
|
|
37
|
+
* Respond to a specific message
|
|
38
|
+
*/
|
|
39
|
+
respond<T = unknown>(uuid?: string, e?: Error | null, data?: T): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* It sends a message to the client
|
|
42
|
+
*/
|
|
43
|
+
send<T extends BufferLike>(message: T, cb?: (err?: Error) => void): void;
|
|
44
|
+
/**
|
|
45
|
+
* It sends a message to the client and waits for a confirmation
|
|
46
|
+
*/
|
|
47
|
+
confirm<T = unknown>(message: T): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Check the current auth has the permission for the given scope
|
|
50
|
+
*/
|
|
51
|
+
verifyAuth(scope?: TransferMethod): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Invoke a function and return its result to the client
|
|
54
|
+
*/
|
|
55
|
+
executeAndRespond<T = unknown>(uuid: string, fn: () => T): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Lifecycle called on error or when the ws connection is closed
|
|
58
|
+
*/
|
|
59
|
+
teardown(): Promise<void> | void;
|
|
60
|
+
/**
|
|
61
|
+
* Lifecycle called to cleanup the transfer state
|
|
62
|
+
*/
|
|
63
|
+
cleanup(): Promise<void> | void;
|
|
64
|
+
init(...args: unknown[]): unknown;
|
|
65
|
+
end(...args: unknown[]): unknown;
|
|
66
|
+
status(...args: unknown[]): unknown;
|
|
67
|
+
onMessage(message: RawData, isBinary: boolean): Promise<void> | void;
|
|
68
|
+
onClose(code: number, reason: Buffer): Promise<void> | void;
|
|
69
|
+
onError(err: Error): Promise<void> | void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../src/strapi/remote/handlers/abstract.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/strapi/remote/handlers/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handlerControllerFactory = exports.createPullController = exports.createPushController = void 0;
|
|
4
|
+
var push_1 = require("./push");
|
|
5
|
+
Object.defineProperty(exports, "createPushController", { enumerable: true, get: function () { return push_1.createPushController; } });
|
|
6
|
+
var pull_1 = require("./pull");
|
|
7
|
+
Object.defineProperty(exports, "createPullController", { enumerable: true, get: function () { return pull_1.createPullController; } });
|
|
8
|
+
var utils_1 = require("./utils");
|
|
9
|
+
Object.defineProperty(exports, "handlerControllerFactory", { enumerable: true, get: function () { return utils_1.handlerControllerFactory; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/remote/handlers/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2D;AAAlD,4GAAA,oBAAoB,OAAA;AAC7B,+BAA2D;AAAlD,4GAAA,oBAAoB,OAAA;AAC7B,iCAAmE;AAA1D,iHAAA,wBAAwB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="koa" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { Handler } from './abstract';
|
|
5
|
+
import { ILocalStrapiSourceProvider } from '../../providers';
|
|
6
|
+
import type { TransferStage, Protocol } from '../../../../types';
|
|
7
|
+
declare const VALID_TRANSFER_ACTIONS: readonly ["bootstrap", "close", "getMetadata", "getSchemas"];
|
|
8
|
+
type PullTransferAction = (typeof VALID_TRANSFER_ACTIONS)[number];
|
|
9
|
+
export interface PullHandler extends Handler {
|
|
10
|
+
provider?: ILocalStrapiSourceProvider;
|
|
11
|
+
streams?: {
|
|
12
|
+
[stage in TransferStage]?: Readable;
|
|
13
|
+
};
|
|
14
|
+
assertValidTransferAction(action: string): asserts action is PullTransferAction;
|
|
15
|
+
onTransferMessage(msg: Protocol.Client.TransferMessage): Promise<unknown> | unknown;
|
|
16
|
+
onTransferAction(msg: Protocol.Client.Action): Promise<unknown> | unknown;
|
|
17
|
+
onTransferStep(msg: Protocol.Client.TransferPullMessage): Promise<unknown> | unknown;
|
|
18
|
+
createReadableStreamForStep(step: TransferStage): Promise<void>;
|
|
19
|
+
flush(stage: TransferStage, id: string): Promise<void> | void;
|
|
20
|
+
}
|
|
21
|
+
export declare const createPullController: (options: import("./utils").HandlerOptions) => (ctx: import("koa").Context) => Promise<void>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPullController = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const providers_1 = require("../../providers");
|
|
8
|
+
const providers_2 = require("../../../errors/providers");
|
|
9
|
+
const TRANSFER_KIND = 'pull';
|
|
10
|
+
const VALID_TRANSFER_ACTIONS = ['bootstrap', 'close', 'getMetadata', 'getSchemas'];
|
|
11
|
+
exports.createPullController = (0, utils_1.handlerControllerFactory)((proto) => ({
|
|
12
|
+
isTransferStarted() {
|
|
13
|
+
return proto.isTransferStarted.call(this) && this.provider !== undefined;
|
|
14
|
+
},
|
|
15
|
+
verifyAuth() {
|
|
16
|
+
return proto.verifyAuth.call(this, TRANSFER_KIND);
|
|
17
|
+
},
|
|
18
|
+
cleanup() {
|
|
19
|
+
proto.cleanup.call(this);
|
|
20
|
+
this.streams = {};
|
|
21
|
+
delete this.provider;
|
|
22
|
+
},
|
|
23
|
+
assertValidTransferAction(action) {
|
|
24
|
+
// Abstract the constant to string[] to allow looser check on the given action
|
|
25
|
+
const validActions = VALID_TRANSFER_ACTIONS;
|
|
26
|
+
if (validActions.includes(action)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
throw new providers_2.ProviderTransferError(`Invalid action provided: "${action}"`, {
|
|
30
|
+
action,
|
|
31
|
+
validActions: Object.keys(VALID_TRANSFER_ACTIONS),
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
async onMessage(raw) {
|
|
35
|
+
const msg = JSON.parse(raw.toString());
|
|
36
|
+
if (!(0, utils_1.isDataTransferMessage)(msg)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!msg.uuid) {
|
|
40
|
+
await this.respond(undefined, new Error('Missing uuid in message'));
|
|
41
|
+
}
|
|
42
|
+
if (proto.hasUUID(msg.uuid)) {
|
|
43
|
+
const previousResponse = proto.response;
|
|
44
|
+
if (previousResponse?.uuid === msg.uuid) {
|
|
45
|
+
await this.respond(previousResponse?.uuid, previousResponse.e, previousResponse.data);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const { uuid, type } = msg;
|
|
50
|
+
proto.addUUID(uuid);
|
|
51
|
+
// Regular command message (init, end, status)
|
|
52
|
+
if (type === 'command') {
|
|
53
|
+
const { command } = msg;
|
|
54
|
+
await this.executeAndRespond(uuid, () => {
|
|
55
|
+
this.assertValidTransferCommand(command);
|
|
56
|
+
// The status command don't have params
|
|
57
|
+
if (command === 'status') {
|
|
58
|
+
return this.status();
|
|
59
|
+
}
|
|
60
|
+
return this[command](msg.params);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Transfer message (the transfer must be init first)
|
|
64
|
+
else if (type === 'transfer') {
|
|
65
|
+
await this.executeAndRespond(uuid, async () => {
|
|
66
|
+
await this.verifyAuth();
|
|
67
|
+
this.assertValidTransfer();
|
|
68
|
+
return this.onTransferMessage(msg);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Invalid messages
|
|
72
|
+
else {
|
|
73
|
+
await this.respond(uuid, new Error('Bad Request'));
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
async onTransferMessage(msg) {
|
|
77
|
+
const { kind } = msg;
|
|
78
|
+
if (kind === 'action') {
|
|
79
|
+
return this.onTransferAction(msg);
|
|
80
|
+
}
|
|
81
|
+
if (kind === 'step') {
|
|
82
|
+
return this.onTransferStep(msg);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
async onTransferAction(msg) {
|
|
86
|
+
const { action } = msg;
|
|
87
|
+
this.assertValidTransferAction(action);
|
|
88
|
+
return this.provider?.[action]();
|
|
89
|
+
},
|
|
90
|
+
async flush(stage, id) {
|
|
91
|
+
const batchSize = 1024 * 1024;
|
|
92
|
+
let batch = [];
|
|
93
|
+
const stream = this.streams?.[stage];
|
|
94
|
+
const batchLength = () => Buffer.byteLength(JSON.stringify(batch));
|
|
95
|
+
const sendBatch = async () => {
|
|
96
|
+
await this.confirm({
|
|
97
|
+
type: 'transfer',
|
|
98
|
+
data: batch,
|
|
99
|
+
ended: false,
|
|
100
|
+
error: null,
|
|
101
|
+
id,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
if (!stream) {
|
|
105
|
+
throw new providers_2.ProviderTransferError(`No available stream found for ${stage}`);
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
for await (const chunk of stream) {
|
|
109
|
+
batch.push(chunk);
|
|
110
|
+
if (batchLength() >= batchSize) {
|
|
111
|
+
await sendBatch();
|
|
112
|
+
batch = [];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (batch.length > 0) {
|
|
116
|
+
await sendBatch();
|
|
117
|
+
batch = [];
|
|
118
|
+
}
|
|
119
|
+
await this.confirm({ type: 'transfer', data: null, ended: true, error: null, id });
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
await this.confirm({ type: 'transfer', data: null, ended: true, error: e, id });
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
async onTransferStep(msg) {
|
|
126
|
+
const { step, action } = msg;
|
|
127
|
+
if (action === 'start') {
|
|
128
|
+
if (this.streams?.[step] instanceof stream_1.Readable) {
|
|
129
|
+
throw new Error('Stream already created, something went wrong');
|
|
130
|
+
}
|
|
131
|
+
const flushUUID = (0, crypto_1.randomUUID)();
|
|
132
|
+
await this.createReadableStreamForStep(step);
|
|
133
|
+
this.flush(step, flushUUID);
|
|
134
|
+
return { ok: true, id: flushUUID };
|
|
135
|
+
}
|
|
136
|
+
if (action === 'end') {
|
|
137
|
+
const stream = this.streams?.[step];
|
|
138
|
+
if (stream?.readableEnded === false) {
|
|
139
|
+
await new Promise((resolve) => {
|
|
140
|
+
stream?.on('close', resolve).destroy();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
delete this.streams?.[step];
|
|
144
|
+
return { ok: true };
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
async createReadableStreamForStep(step) {
|
|
148
|
+
const mapper = {
|
|
149
|
+
entities: () => this.provider?.createEntitiesReadStream(),
|
|
150
|
+
links: () => this.provider?.createLinksReadStream(),
|
|
151
|
+
configuration: () => this.provider?.createConfigurationReadStream(),
|
|
152
|
+
assets: () => {
|
|
153
|
+
const assets = this.provider?.createAssetsReadStream();
|
|
154
|
+
let batch = [];
|
|
155
|
+
const batchLength = () => {
|
|
156
|
+
return batch.reduce((acc, chunk) => (chunk.action === 'stream' ? acc + chunk.data.byteLength : acc), 0);
|
|
157
|
+
};
|
|
158
|
+
const BATCH_MAX_SIZE = 1024 * 1024; // 1MB
|
|
159
|
+
if (!assets) {
|
|
160
|
+
throw new Error('bad');
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Generates batches of 1MB of data from the assets stream to avoid
|
|
164
|
+
* sending too many small chunks
|
|
165
|
+
*
|
|
166
|
+
* @param stream Assets stream from the local source provider
|
|
167
|
+
*/
|
|
168
|
+
async function* generator(stream) {
|
|
169
|
+
let hasStarted = false;
|
|
170
|
+
let assetID = '';
|
|
171
|
+
for await (const chunk of stream) {
|
|
172
|
+
const { stream: assetStream, ...assetData } = chunk;
|
|
173
|
+
if (!hasStarted) {
|
|
174
|
+
assetID = (0, crypto_1.randomUUID)();
|
|
175
|
+
// Start the transfer of a new asset
|
|
176
|
+
batch.push({ action: 'start', assetID, data: assetData });
|
|
177
|
+
hasStarted = true;
|
|
178
|
+
}
|
|
179
|
+
for await (const assetChunk of assetStream) {
|
|
180
|
+
// Add the asset data to the batch
|
|
181
|
+
batch.push({ action: 'stream', assetID, data: assetChunk });
|
|
182
|
+
// if the batch size is bigger than BATCH_MAX_SIZE stream the batch
|
|
183
|
+
if (batchLength() >= BATCH_MAX_SIZE) {
|
|
184
|
+
yield batch;
|
|
185
|
+
batch = [];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// All the asset data has been streamed and gets ready for the next one
|
|
189
|
+
hasStarted = false;
|
|
190
|
+
batch.push({ action: 'end', assetID });
|
|
191
|
+
yield batch;
|
|
192
|
+
batch = [];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return stream_1.Readable.from(generator(assets));
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
if (!(step in mapper)) {
|
|
199
|
+
throw new Error('Invalid transfer step, impossible to create a stream');
|
|
200
|
+
}
|
|
201
|
+
if (!this.streams) {
|
|
202
|
+
throw new Error('Invalid transfer state');
|
|
203
|
+
}
|
|
204
|
+
this.streams[step] = await mapper[step]();
|
|
205
|
+
},
|
|
206
|
+
// Commands
|
|
207
|
+
async init() {
|
|
208
|
+
if (this.transferID || this.provider) {
|
|
209
|
+
throw new Error('Transfer already in progress');
|
|
210
|
+
}
|
|
211
|
+
await this.verifyAuth();
|
|
212
|
+
this.transferID = (0, crypto_1.randomUUID)();
|
|
213
|
+
this.startedAt = Date.now();
|
|
214
|
+
this.streams = {};
|
|
215
|
+
this.provider = (0, providers_1.createLocalStrapiSourceProvider)({
|
|
216
|
+
autoDestroy: false,
|
|
217
|
+
getStrapi: () => strapi,
|
|
218
|
+
});
|
|
219
|
+
return { transferID: this.transferID };
|
|
220
|
+
},
|
|
221
|
+
async end(params) {
|
|
222
|
+
await this.verifyAuth();
|
|
223
|
+
if (this.transferID !== params.transferID) {
|
|
224
|
+
throw new providers_2.ProviderTransferError('Bad transfer ID provided');
|
|
225
|
+
}
|
|
226
|
+
this.cleanup();
|
|
227
|
+
return { ok: true };
|
|
228
|
+
},
|
|
229
|
+
async status() {
|
|
230
|
+
const isStarted = this.isTransferStarted();
|
|
231
|
+
if (!isStarted) {
|
|
232
|
+
const startedAt = this.startedAt;
|
|
233
|
+
return {
|
|
234
|
+
active: true,
|
|
235
|
+
kind: TRANSFER_KIND,
|
|
236
|
+
startedAt,
|
|
237
|
+
elapsed: Date.now() - startedAt,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return { active: false, kind: null, elapsed: null, startedAt: null };
|
|
241
|
+
},
|
|
242
|
+
}));
|
|
243
|
+
//# sourceMappingURL=pull.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull.js","sourceRoot":"","sources":["../../../../src/strapi/remote/handlers/pull.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,mCAAoC;AAGpC,mCAA0E;AAC1E,+CAA8F;AAC9F,yDAAkE;AAIlE,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,sBAAsB,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,CAAU,CAAC;AAoB/E,QAAA,oBAAoB,GAAG,IAAA,gCAAwB,EAAuB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7F,iBAAiB;QACf,OAAO,KAAK,CAAC,iBAAiB,CA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AAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvE,CAAC;CACF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="koa" />
|
|
3
|
+
import { Writable, PassThrough } from 'stream';
|
|
4
|
+
import type { TransferFlow } from '../flows';
|
|
5
|
+
import type { TransferStage, IAsset, Protocol } from '../../../../types';
|
|
6
|
+
import { createLocalStrapiDestinationProvider } from '../../providers';
|
|
7
|
+
import { Handler } from './abstract';
|
|
8
|
+
declare const VALID_TRANSFER_ACTIONS: readonly ["bootstrap", "close", "rollback", "beforeTransfer", "getMetadata", "getSchemas"];
|
|
9
|
+
type PushTransferAction = (typeof VALID_TRANSFER_ACTIONS)[number];
|
|
10
|
+
export interface PushHandler extends Handler {
|
|
11
|
+
/**
|
|
12
|
+
* Local Strapi Destination Provider used to write data to the current Strapi instance
|
|
13
|
+
*/
|
|
14
|
+
provider?: ReturnType<typeof createLocalStrapiDestinationProvider>;
|
|
15
|
+
/**
|
|
16
|
+
* Holds all the stages' stream for the current transfer handler (one registry per connection)
|
|
17
|
+
*/
|
|
18
|
+
streams?: {
|
|
19
|
+
[stage in TransferStage]?: Writable;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Holds all the transferred assets for the current transfer handler (one registry per connection)
|
|
23
|
+
*/
|
|
24
|
+
assets: {
|
|
25
|
+
[filepath: string]: IAsset & {
|
|
26
|
+
stream: PassThrough;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Ochestrate and manage the transfer messages' ordering
|
|
31
|
+
*/
|
|
32
|
+
flow?: TransferFlow;
|
|
33
|
+
/**
|
|
34
|
+
* Checks that the given action is a valid push transfer action
|
|
35
|
+
*/
|
|
36
|
+
assertValidTransferAction(action: string): asserts action is PushTransferAction;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new writable stream for the given step in the handler's stream registry
|
|
39
|
+
*/
|
|
40
|
+
createWritableStreamForStep(step: TransferStage): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Simple override of the auth verification
|
|
43
|
+
*/
|
|
44
|
+
verifyAuth(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Callback when receiving a regular transfer message
|
|
47
|
+
*/
|
|
48
|
+
onTransferMessage(msg: Protocol.Client.TransferMessage): Promise<unknown> | unknown;
|
|
49
|
+
/**
|
|
50
|
+
* Callback when receiving a transfer action message
|
|
51
|
+
*/
|
|
52
|
+
onTransferAction(msg: Protocol.Client.Action): Promise<unknown> | unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Callback when receiving a transfer step message
|
|
55
|
+
*/
|
|
56
|
+
onTransferStep(msg: Protocol.Client.TransferPushMessage): Promise<unknown> | unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Start streaming an asset
|
|
59
|
+
*/
|
|
60
|
+
streamAsset(this: PushHandler, payload: Protocol.Client.GetTransferPushStreamData<'assets'>): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Try to move to a specific transfer stage & lock the step
|
|
63
|
+
*/
|
|
64
|
+
lockTransferStep(stage: TransferStage): void;
|
|
65
|
+
/**
|
|
66
|
+
* Try to move to unlock the current step
|
|
67
|
+
*/
|
|
68
|
+
unlockTransferStep(stage: TransferStage): void;
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether it's possible to stream a chunk for the given stage
|
|
71
|
+
*/
|
|
72
|
+
assertValidStreamTransferStep(stage: TransferStage): void;
|
|
73
|
+
}
|
|
74
|
+
export declare const createPushController: (options: import("./utils").HandlerOptions) => (ctx: import("koa").Context) => Promise<void>;
|
|
75
|
+
export {};
|