@strapi/data-transfer 4.13.0-beta.0 → 4.13.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.
Files changed (169) hide show
  1. package/package.json +5 -5
  2. package/dist/engine/diagnostic.d.ts +0 -40
  3. package/dist/engine/diagnostic.js +0 -50
  4. package/dist/engine/diagnostic.js.map +0 -1
  5. package/dist/engine/errors.d.ts +0 -28
  6. package/dist/engine/errors.js +0 -29
  7. package/dist/engine/errors.js.map +0 -1
  8. package/dist/engine/index.d.ts +0 -64
  9. package/dist/engine/index.js +0 -664
  10. package/dist/engine/index.js.map +0 -1
  11. package/dist/engine/validation/index.d.ts +0 -2
  12. package/dist/engine/validation/index.js +0 -19
  13. package/dist/engine/validation/index.js.map +0 -1
  14. package/dist/engine/validation/provider.d.ts +0 -3
  15. package/dist/engine/validation/provider.js +0 -18
  16. package/dist/engine/validation/provider.js.map +0 -1
  17. package/dist/engine/validation/schemas/index.d.ts +0 -7
  18. package/dist/engine/validation/schemas/index.js +0 -70
  19. package/dist/engine/validation/schemas/index.js.map +0 -1
  20. package/dist/errors/base.d.ts +0 -8
  21. package/dist/errors/base.js +0 -13
  22. package/dist/errors/base.js.map +0 -1
  23. package/dist/errors/constants.d.ts +0 -3
  24. package/dist/errors/constants.js +0 -9
  25. package/dist/errors/constants.js.map +0 -1
  26. package/dist/errors/index.d.ts +0 -2
  27. package/dist/errors/index.js +0 -19
  28. package/dist/errors/index.js.map +0 -1
  29. package/dist/errors/providers.d.ts +0 -23
  30. package/dist/errors/providers.js +0 -32
  31. package/dist/errors/providers.js.map +0 -1
  32. package/dist/file/index.d.ts +0 -1
  33. package/dist/file/index.js +0 -28
  34. package/dist/file/index.js.map +0 -1
  35. package/dist/file/providers/destination/index.d.ts +0 -46
  36. package/dist/file/providers/destination/index.js +0 -181
  37. package/dist/file/providers/destination/index.js.map +0 -1
  38. package/dist/file/providers/destination/utils.d.ts +0 -9
  39. package/dist/file/providers/destination/utils.js +0 -62
  40. package/dist/file/providers/destination/utils.js.map +0 -1
  41. package/dist/file/providers/index.d.ts +0 -2
  42. package/dist/file/providers/index.js +0 -19
  43. package/dist/file/providers/index.js.map +0 -1
  44. package/dist/file/providers/source/index.d.ts +0 -40
  45. package/dist/file/providers/source/index.js +0 -242
  46. package/dist/file/providers/source/index.js.map +0 -1
  47. package/dist/file/providers/source/utils.d.ts +0 -37
  48. package/dist/file/providers/source/utils.js +0 -62
  49. package/dist/file/providers/source/utils.js.map +0 -1
  50. package/dist/index.d.ts +0 -4
  51. package/dist/index.js +0 -31
  52. package/dist/index.js.map +0 -1
  53. package/dist/strapi/index.d.ts +0 -3
  54. package/dist/strapi/index.js +0 -30
  55. package/dist/strapi/index.js.map +0 -1
  56. package/dist/strapi/providers/index.d.ts +0 -4
  57. package/dist/strapi/providers/index.js +0 -23
  58. package/dist/strapi/providers/index.js.map +0 -1
  59. package/dist/strapi/providers/local-destination/index.d.ts +0 -34
  60. package/dist/strapi/providers/local-destination/index.js +0 -321
  61. package/dist/strapi/providers/local-destination/index.js.map +0 -1
  62. package/dist/strapi/providers/local-destination/strategies/index.d.ts +0 -1
  63. package/dist/strapi/providers/local-destination/strategies/index.js +0 -28
  64. package/dist/strapi/providers/local-destination/strategies/index.js.map +0 -1
  65. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +0 -5
  66. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
  67. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +0 -1
  68. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +0 -11
  69. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +0 -103
  70. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
  71. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +0 -32
  72. package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -107
  73. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
  74. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +0 -4
  75. package/dist/strapi/providers/local-destination/strategies/restore/links.js +0 -32
  76. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +0 -1
  77. package/dist/strapi/providers/local-source/assets.d.ts +0 -5
  78. package/dist/strapi/providers/local-source/assets.js +0 -98
  79. package/dist/strapi/providers/local-source/assets.js.map +0 -1
  80. package/dist/strapi/providers/local-source/configuration.d.ts +0 -5
  81. package/dist/strapi/providers/local-source/configuration.js +0 -36
  82. package/dist/strapi/providers/local-source/configuration.js.map +0 -1
  83. package/dist/strapi/providers/local-source/entities.d.ts +0 -10
  84. package/dist/strapi/providers/local-source/entities.js +0 -85
  85. package/dist/strapi/providers/local-source/entities.js.map +0 -1
  86. package/dist/strapi/providers/local-source/index.d.ts +0 -26
  87. package/dist/strapi/providers/local-source/index.js +0 -98
  88. package/dist/strapi/providers/local-source/index.js.map +0 -1
  89. package/dist/strapi/providers/local-source/links.d.ts +0 -5
  90. package/dist/strapi/providers/local-source/links.js +0 -23
  91. package/dist/strapi/providers/local-source/links.js.map +0 -1
  92. package/dist/strapi/providers/remote-destination/index.d.ts +0 -39
  93. package/dist/strapi/providers/remote-destination/index.js +0 -269
  94. package/dist/strapi/providers/remote-destination/index.js.map +0 -1
  95. package/dist/strapi/providers/remote-source/index.d.ts +0 -39
  96. package/dist/strapi/providers/remote-source/index.js +0 -239
  97. package/dist/strapi/providers/remote-source/index.js.map +0 -1
  98. package/dist/strapi/providers/utils.d.ts +0 -39
  99. package/dist/strapi/providers/utils.js +0 -138
  100. package/dist/strapi/providers/utils.js.map +0 -1
  101. package/dist/strapi/queries/entity.d.ts +0 -2
  102. package/dist/strapi/queries/entity.js +0 -130
  103. package/dist/strapi/queries/entity.js.map +0 -1
  104. package/dist/strapi/queries/index.d.ts +0 -2
  105. package/dist/strapi/queries/index.js +0 -29
  106. package/dist/strapi/queries/index.js.map +0 -1
  107. package/dist/strapi/queries/link.d.ts +0 -7
  108. package/dist/strapi/queries/link.js +0 -215
  109. package/dist/strapi/queries/link.js.map +0 -1
  110. package/dist/strapi/remote/constants.d.ts +0 -4
  111. package/dist/strapi/remote/constants.js +0 -6
  112. package/dist/strapi/remote/constants.js.map +0 -1
  113. package/dist/strapi/remote/flows/default.d.ts +0 -3
  114. package/dist/strapi/remote/flows/default.js +0 -41
  115. package/dist/strapi/remote/flows/default.js.map +0 -1
  116. package/dist/strapi/remote/flows/index.d.ts +0 -18
  117. package/dist/strapi/remote/flows/index.js +0 -59
  118. package/dist/strapi/remote/flows/index.js.map +0 -1
  119. package/dist/strapi/remote/handlers/abstract.d.ts +0 -71
  120. package/dist/strapi/remote/handlers/abstract.js +0 -3
  121. package/dist/strapi/remote/handlers/abstract.js.map +0 -1
  122. package/dist/strapi/remote/handlers/constants.d.ts +0 -2
  123. package/dist/strapi/remote/handlers/constants.js +0 -5
  124. package/dist/strapi/remote/handlers/constants.js.map +0 -1
  125. package/dist/strapi/remote/handlers/index.d.ts +0 -3
  126. package/dist/strapi/remote/handlers/index.js +0 -10
  127. package/dist/strapi/remote/handlers/index.js.map +0 -1
  128. package/dist/strapi/remote/handlers/pull.d.ts +0 -22
  129. package/dist/strapi/remote/handlers/pull.js +0 -243
  130. package/dist/strapi/remote/handlers/pull.js.map +0 -1
  131. package/dist/strapi/remote/handlers/push.d.ts +0 -75
  132. package/dist/strapi/remote/handlers/push.js +0 -311
  133. package/dist/strapi/remote/handlers/push.js.map +0 -1
  134. package/dist/strapi/remote/handlers/utils.d.ts +0 -25
  135. package/dist/strapi/remote/handlers/utils.js +0 -217
  136. package/dist/strapi/remote/handlers/utils.js.map +0 -1
  137. package/dist/strapi/remote/index.d.ts +0 -2
  138. package/dist/strapi/remote/index.js +0 -29
  139. package/dist/strapi/remote/index.js.map +0 -1
  140. package/dist/utils/encryption/decrypt.d.ts +0 -11
  141. package/dist/utils/encryption/decrypt.js +0 -47
  142. package/dist/utils/encryption/decrypt.js.map +0 -1
  143. package/dist/utils/encryption/encrypt.d.ts +0 -11
  144. package/dist/utils/encryption/encrypt.js +0 -47
  145. package/dist/utils/encryption/encrypt.js.map +0 -1
  146. package/dist/utils/encryption/index.d.ts +0 -2
  147. package/dist/utils/encryption/index.js +0 -19
  148. package/dist/utils/encryption/index.js.map +0 -1
  149. package/dist/utils/index.d.ts +0 -6
  150. package/dist/utils/index.js +0 -33
  151. package/dist/utils/index.js.map +0 -1
  152. package/dist/utils/json.d.ts +0 -30
  153. package/dist/utils/json.js +0 -68
  154. package/dist/utils/json.js.map +0 -1
  155. package/dist/utils/middleware.d.ts +0 -2
  156. package/dist/utils/middleware.js +0 -14
  157. package/dist/utils/middleware.js.map +0 -1
  158. package/dist/utils/providers.d.ts +0 -2
  159. package/dist/utils/providers.js +0 -11
  160. package/dist/utils/providers.js.map +0 -1
  161. package/dist/utils/schema.d.ts +0 -6
  162. package/dist/utils/schema.js +0 -29
  163. package/dist/utils/schema.js.map +0 -1
  164. package/dist/utils/stream.d.ts +0 -27
  165. package/dist/utils/stream.js +0 -59
  166. package/dist/utils/stream.js.map +0 -1
  167. package/dist/utils/transaction.d.ts +0 -3
  168. package/dist/utils/transaction.js +0 -88
  169. package/dist/utils/transaction.js.map +0 -1
@@ -1,18 +0,0 @@
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;
@@ -1,59 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/remote/flows/index.ts"],"names":[],"mappings":";;;;;;AAMA,qCAA6D;AAApD,iIAAA,OAAO,OAAyB;AAclC,MAAM,UAAU,GAAG,CAAC,IAAqB,EAAgB,EAAE;IAChE,MAAM,KAAK,GAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAErC;;OAEG;IACH,MAAM,SAAS,GAAG,CAAC,KAAW,EAAE,KAAW,EAAW,EAAE;QACtD,IAAI,KAAK,CAAC,IAAI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D;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"}
@@ -1,71 +0,0 @@
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 {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=abstract.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../src/strapi/remote/handlers/abstract.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare const VALID_TRANSFER_COMMANDS: readonly ["init", "end", "status"];
2
- export type ValidTransferCommand = (typeof VALID_TRANSFER_COMMANDS)[number];
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VALID_TRANSFER_COMMANDS = void 0;
4
- exports.VALID_TRANSFER_COMMANDS = ['init', 'end', 'status'];
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- export { createPushController, PushHandler } from './push';
2
- export { createPullController, PullHandler } from './pull';
3
- export { handlerControllerFactory, HandlerOptions } from './utils';
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,22 +0,0 @@
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 {};
@@ -1,243 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;IAC3E,CAAC;IAED,UAAU;QACR,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACpD,CAAC;IAED,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAElB,OAAO,IAAI,CAAC,QAAQ,CAAC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AAC;QAE5B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAElB,IAAI,CAAC,QAAQ,GAAG,IAAA,2CAA+B,EAAC;YAC9C,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;SACxB,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,GAAG,CAEP,MAA+C;QAE/C,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAExB,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,EAAE;YACzC,MAAM,IAAI,iCAAqB,CAAC,0BAA0B,CAAC,CAAC;SAC7D;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;QAEf,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAE3C,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,SAAS,GAAG,IAAI,CAAC,SAAmB,CAAC;YAC3C,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE,aAAa;gBACnB,SAAS;gBACT,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;aAChC,CAAC;SACH;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvE,CAAC;CACF,CAAC,CAAC,CAAC"}
@@ -1,75 +0,0 @@
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 {};