@strapi/data-transfer 4.10.0-beta.0 → 4.10.0-beta.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.
Files changed (163) hide show
  1. package/dist/engine/diagnostic.js.map +1 -0
  2. package/dist/engine/errors.js.map +1 -0
  3. package/dist/engine/index.js.map +1 -0
  4. package/dist/engine/validation/index.js.map +1 -0
  5. package/dist/engine/validation/provider.js.map +1 -0
  6. package/dist/engine/validation/schemas/index.d.ts +3 -3
  7. package/dist/engine/validation/schemas/index.js +29 -12
  8. package/dist/engine/validation/schemas/index.js.map +1 -0
  9. package/dist/errors/base.js.map +1 -0
  10. package/dist/errors/constants.js.map +1 -0
  11. package/dist/errors/index.js.map +1 -0
  12. package/dist/errors/providers.js.map +1 -0
  13. package/dist/file/index.js.map +1 -0
  14. package/dist/file/providers/destination/index.js.map +1 -0
  15. package/dist/file/providers/destination/utils.js.map +1 -0
  16. package/dist/file/providers/index.js.map +1 -0
  17. package/dist/file/providers/source/index.js.map +1 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/strapi/index.js.map +1 -0
  20. package/dist/strapi/providers/index.js.map +1 -0
  21. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  22. package/dist/strapi/providers/local-destination/strategies/index.js.map +1 -0
  23. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  24. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  25. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  26. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  27. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  28. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  29. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  30. package/dist/strapi/providers/local-source/index.js.map +1 -0
  31. package/dist/strapi/providers/local-source/links.js.map +1 -0
  32. package/dist/strapi/providers/remote-destination/index.js +4 -19
  33. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  34. package/dist/strapi/providers/remote-source/index.js +3 -4
  35. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  36. package/dist/strapi/providers/utils.d.ts +7 -2
  37. package/dist/strapi/providers/utils.js +22 -1
  38. package/dist/strapi/providers/utils.js.map +1 -0
  39. package/dist/strapi/queries/entity.js.map +1 -0
  40. package/dist/strapi/queries/index.js.map +1 -0
  41. package/dist/strapi/queries/link.js.map +1 -0
  42. package/dist/strapi/remote/constants.js.map +1 -0
  43. package/dist/strapi/remote/flows/default.js.map +1 -0
  44. package/dist/strapi/remote/flows/index.js.map +1 -0
  45. package/dist/strapi/remote/handlers/abstract.js.map +1 -0
  46. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  47. package/dist/strapi/remote/handlers/index.js.map +1 -0
  48. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  49. package/dist/strapi/remote/handlers/push.js.map +1 -0
  50. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  51. package/dist/strapi/remote/index.js.map +1 -0
  52. package/dist/utils/encryption/decrypt.js.map +1 -0
  53. package/dist/utils/encryption/encrypt.js.map +1 -0
  54. package/dist/utils/encryption/index.js.map +1 -0
  55. package/dist/utils/index.js.map +1 -0
  56. package/dist/utils/json.d.ts +1 -1
  57. package/dist/utils/json.js.map +1 -0
  58. package/dist/utils/providers.js.map +1 -0
  59. package/dist/utils/schema.js.map +1 -0
  60. package/dist/utils/stream.js.map +1 -0
  61. package/dist/utils/transaction.js.map +1 -0
  62. package/package.json +17 -16
  63. package/jest.config.js +0 -14
  64. package/lib/engine/diagnostic.d.ts +0 -40
  65. package/lib/engine/diagnostic.js +0 -50
  66. package/lib/engine/errors.d.ts +0 -28
  67. package/lib/engine/errors.js +0 -29
  68. package/lib/engine/index.d.ts +0 -44
  69. package/lib/engine/index.js +0 -506
  70. package/lib/engine/validation/index.d.ts +0 -2
  71. package/lib/engine/validation/index.js +0 -19
  72. package/lib/engine/validation/provider.d.ts +0 -3
  73. package/lib/engine/validation/provider.js +0 -18
  74. package/lib/engine/validation/schemas/index.d.ts +0 -7
  75. package/lib/engine/validation/schemas/index.js +0 -53
  76. package/lib/errors/base.d.ts +0 -8
  77. package/lib/errors/base.js +0 -13
  78. package/lib/errors/constants.d.ts +0 -3
  79. package/lib/errors/constants.js +0 -9
  80. package/lib/errors/index.d.ts +0 -2
  81. package/lib/errors/index.js +0 -19
  82. package/lib/errors/providers.d.ts +0 -21
  83. package/lib/errors/providers.js +0 -32
  84. package/lib/file/index.d.ts +0 -1
  85. package/lib/file/index.js +0 -28
  86. package/lib/file/providers/destination/index.d.ts +0 -45
  87. package/lib/file/providers/destination/index.js +0 -174
  88. package/lib/file/providers/destination/utils.d.ts +0 -9
  89. package/lib/file/providers/destination/utils.js +0 -61
  90. package/lib/file/providers/index.d.ts +0 -2
  91. package/lib/file/providers/index.js +0 -19
  92. package/lib/file/providers/source/index.d.ts +0 -40
  93. package/lib/file/providers/source/index.js +0 -220
  94. package/lib/index.d.ts +0 -4
  95. package/lib/index.js +0 -31
  96. package/lib/strapi/index.d.ts +0 -3
  97. package/lib/strapi/index.js +0 -30
  98. package/lib/strapi/providers/index.d.ts +0 -3
  99. package/lib/strapi/providers/index.js +0 -22
  100. package/lib/strapi/providers/local-destination/index.d.ts +0 -34
  101. package/lib/strapi/providers/local-destination/index.js +0 -220
  102. package/lib/strapi/providers/local-destination/strategies/index.d.ts +0 -1
  103. package/lib/strapi/providers/local-destination/strategies/index.js +0 -28
  104. package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +0 -5
  105. package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
  106. package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +0 -11
  107. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +0 -103
  108. package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +0 -32
  109. package/lib/strapi/providers/local-destination/strategies/restore/index.js +0 -107
  110. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +0 -4
  111. package/lib/strapi/providers/local-destination/strategies/restore/links.js +0 -32
  112. package/lib/strapi/providers/local-source/assets.d.ts +0 -5
  113. package/lib/strapi/providers/local-source/assets.js +0 -31
  114. package/lib/strapi/providers/local-source/configuration.d.ts +0 -5
  115. package/lib/strapi/providers/local-source/configuration.js +0 -36
  116. package/lib/strapi/providers/local-source/entities.d.ts +0 -10
  117. package/lib/strapi/providers/local-source/entities.js +0 -85
  118. package/lib/strapi/providers/local-source/index.d.ts +0 -27
  119. package/lib/strapi/providers/local-source/index.js +0 -98
  120. package/lib/strapi/providers/local-source/links.d.ts +0 -5
  121. package/lib/strapi/providers/local-source/links.js +0 -23
  122. package/lib/strapi/providers/remote-destination/index.d.ts +0 -37
  123. package/lib/strapi/providers/remote-destination/index.js +0 -284
  124. package/lib/strapi/providers/remote-destination/utils.d.ts +0 -31
  125. package/lib/strapi/providers/remote-destination/utils.js +0 -72
  126. package/lib/strapi/queries/entity.d.ts +0 -19
  127. package/lib/strapi/queries/entity.js +0 -130
  128. package/lib/strapi/queries/index.d.ts +0 -2
  129. package/lib/strapi/queries/index.js +0 -29
  130. package/lib/strapi/queries/link.d.ts +0 -6
  131. package/lib/strapi/queries/link.js +0 -215
  132. package/lib/strapi/remote/constants.d.ts +0 -2
  133. package/lib/strapi/remote/constants.js +0 -6
  134. package/lib/strapi/remote/controllers/index.d.ts +0 -1
  135. package/lib/strapi/remote/controllers/index.js +0 -18
  136. package/lib/strapi/remote/controllers/push.d.ts +0 -26
  137. package/lib/strapi/remote/controllers/push.js +0 -116
  138. package/lib/strapi/remote/flows/default.d.ts +0 -3
  139. package/lib/strapi/remote/flows/default.js +0 -41
  140. package/lib/strapi/remote/flows/index.d.ts +0 -18
  141. package/lib/strapi/remote/flows/index.js +0 -59
  142. package/lib/strapi/remote/handlers.d.ts +0 -10
  143. package/lib/strapi/remote/handlers.js +0 -285
  144. package/lib/strapi/remote/index.d.ts +0 -3
  145. package/lib/strapi/remote/index.js +0 -30
  146. package/lib/utils/encryption/decrypt.d.ts +0 -11
  147. package/lib/utils/encryption/decrypt.js +0 -47
  148. package/lib/utils/encryption/encrypt.d.ts +0 -11
  149. package/lib/utils/encryption/encrypt.js +0 -47
  150. package/lib/utils/encryption/index.d.ts +0 -2
  151. package/lib/utils/encryption/index.js +0 -19
  152. package/lib/utils/index.d.ts +0 -5
  153. package/lib/utils/index.js +0 -32
  154. package/lib/utils/json.d.ts +0 -30
  155. package/lib/utils/json.js +0 -68
  156. package/lib/utils/providers.d.ts +0 -2
  157. package/lib/utils/providers.js +0 -11
  158. package/lib/utils/schema.d.ts +0 -7
  159. package/lib/utils/schema.js +0 -29
  160. package/lib/utils/stream.d.ts +0 -27
  161. package/lib/utils/stream.js +0 -59
  162. package/lib/utils/transaction.d.ts +0 -3
  163. package/lib/utils/transaction.js +0 -88
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLinksStream = void 0;
4
- const stream_1 = require("stream");
5
- const link_1 = require("../../queries/link");
6
- /**
7
- * Create a Readable which will stream all the links from a Strapi instance
8
- */
9
- const createLinksStream = (strapi) => {
10
- const uids = [...Object.keys(strapi.contentTypes), ...Object.keys(strapi.components)];
11
- // Async generator stream that returns every link from a Strapi instance
12
- return stream_1.Readable.from((async function* linkGenerator() {
13
- const query = (0, link_1.createLinkQuery)(strapi);
14
- for (const uid of uids) {
15
- const generator = query().generateAll(uid);
16
- for await (const link of generator) {
17
- yield link;
18
- }
19
- }
20
- })());
21
- };
22
- exports.createLinksStream = createLinksStream;
23
- //# sourceMappingURL=links.js.map
@@ -1,37 +0,0 @@
1
- /// <reference types="node" />
2
- import { WebSocket } from 'ws';
3
- import { Writable } from 'stream';
4
- import { createDispatcher } from './utils';
5
- import type { IDestinationProvider, IMetadata, ProviderType } from '../../../../types';
6
- import type { ILocalStrapiDestinationProviderOptions } from '../local-destination';
7
- interface ITransferTokenAuth {
8
- type: 'token';
9
- token: string;
10
- }
11
- export interface IRemoteStrapiDestinationProviderOptions extends Pick<ILocalStrapiDestinationProviderOptions, 'restore' | 'strategy'> {
12
- url: URL;
13
- auth?: ITransferTokenAuth;
14
- }
15
- declare class RemoteStrapiDestinationProvider implements IDestinationProvider {
16
- #private;
17
- name: string;
18
- type: ProviderType;
19
- options: IRemoteStrapiDestinationProviderOptions;
20
- ws: WebSocket | null;
21
- dispatcher: ReturnType<typeof createDispatcher> | null;
22
- transferID: string | null;
23
- constructor(options: IRemoteStrapiDestinationProviderOptions);
24
- initTransfer(): Promise<string>;
25
- bootstrap(): Promise<void>;
26
- close(): Promise<void>;
27
- getMetadata(): Promise<IMetadata | null> | null;
28
- beforeTransfer(): Promise<void>;
29
- rollback(): Promise<void>;
30
- getSchemas(): Promise<Strapi.Schemas | null>;
31
- createEntitiesWriteStream(): Writable;
32
- createLinksWriteStream(): Writable;
33
- createConfigurationWriteStream(): Writable;
34
- createAssetsWriteStream(): Writable | Promise<Writable>;
35
- }
36
- export declare const createRemoteStrapiDestinationProvider: (options: IRemoteStrapiDestinationProviderOptions) => RemoteStrapiDestinationProvider;
37
- export {};
@@ -1,284 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _RemoteStrapiDestinationProvider_instances, _RemoteStrapiDestinationProvider_startStepOnce, _RemoteStrapiDestinationProvider_startStep, _RemoteStrapiDestinationProvider_endStep, _RemoteStrapiDestinationProvider_streamStep, _RemoteStrapiDestinationProvider_writeStream;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createRemoteStrapiDestinationProvider = void 0;
10
- const ws_1 = require("ws");
11
- const uuid_1 = require("uuid");
12
- const stream_1 = require("stream");
13
- const fp_1 = require("lodash/fp");
14
- const utils_1 = require("./utils");
15
- const constants_1 = require("../../remote/constants");
16
- const providers_1 = require("../../../errors/providers");
17
- const jsonLength = (obj) => Buffer.byteLength(JSON.stringify(obj));
18
- class RemoteStrapiDestinationProvider {
19
- constructor(options) {
20
- _RemoteStrapiDestinationProvider_instances.add(this);
21
- this.name = 'destination::remote-strapi';
22
- this.type = 'destination';
23
- this.options = options;
24
- this.ws = null;
25
- this.dispatcher = null;
26
- this.transferID = null;
27
- }
28
- async initTransfer() {
29
- const { strategy, restore } = this.options;
30
- // Wait for the connection to be made to the server, then init the transfer
31
- return new Promise((resolve, reject) => {
32
- this.ws
33
- ?.once('open', async () => {
34
- try {
35
- const query = this.dispatcher?.dispatchCommand({
36
- command: 'init',
37
- params: { options: { strategy, restore }, transfer: 'push' },
38
- });
39
- const res = (await query);
40
- if (!res?.transferID) {
41
- throw new providers_1.ProviderTransferError('Init failed, invalid response from the server');
42
- }
43
- resolve(res.transferID);
44
- }
45
- catch (e) {
46
- reject(e);
47
- }
48
- })
49
- .once('error', (message) => {
50
- reject(message);
51
- });
52
- });
53
- }
54
- async bootstrap() {
55
- const { url, auth } = this.options;
56
- const validProtocols = ['https:', 'http:'];
57
- let ws;
58
- if (!validProtocols.includes(url.protocol)) {
59
- throw new providers_1.ProviderValidationError(`Invalid protocol "${url.protocol}"`, {
60
- check: 'url',
61
- details: {
62
- protocol: url.protocol,
63
- validProtocols,
64
- },
65
- });
66
- }
67
- const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
68
- const wsUrl = `${wsProtocol}//${url.host}${url.pathname}${constants_1.TRANSFER_PATH}`;
69
- // No auth defined, trying public access for transfer
70
- if (!auth) {
71
- ws = new ws_1.WebSocket(wsUrl);
72
- }
73
- // Common token auth, this should be the main auth method
74
- else if (auth.type === 'token') {
75
- const headers = { Authorization: `Bearer ${auth.token}` };
76
- ws = new ws_1.WebSocket(wsUrl, { headers });
77
- }
78
- // Invalid auth method provided
79
- else {
80
- throw new providers_1.ProviderValidationError('Auth method not available', {
81
- check: 'auth.type',
82
- details: {
83
- auth: auth.type,
84
- },
85
- });
86
- }
87
- this.ws = ws;
88
- this.dispatcher = (0, utils_1.createDispatcher)(this.ws);
89
- this.transferID = await this.initTransfer();
90
- this.dispatcher.setTransferProperties({ id: this.transferID, kind: 'push' });
91
- await this.dispatcher.dispatchTransferAction('bootstrap');
92
- }
93
- async close() {
94
- // Gracefully close the remote transfer process
95
- if (this.transferID && this.dispatcher) {
96
- await this.dispatcher.dispatchTransferAction('close');
97
- await this.dispatcher.dispatchCommand({
98
- command: 'end',
99
- params: { transferID: this.transferID },
100
- });
101
- }
102
- await new Promise((resolve) => {
103
- const { ws } = this;
104
- if (!ws || ws.CLOSED) {
105
- resolve();
106
- return;
107
- }
108
- ws.on('close', () => resolve()).close();
109
- });
110
- }
111
- getMetadata() {
112
- return this.dispatcher?.dispatchTransferAction('getMetadata') ?? null;
113
- }
114
- async beforeTransfer() {
115
- await this.dispatcher?.dispatchTransferAction('beforeTransfer');
116
- }
117
- async rollback() {
118
- await this.dispatcher?.dispatchTransferAction('rollback');
119
- }
120
- getSchemas() {
121
- if (!this.dispatcher) {
122
- return Promise.resolve(null);
123
- }
124
- return this.dispatcher.dispatchTransferAction('getSchemas');
125
- }
126
- createEntitiesWriteStream() {
127
- return __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_writeStream).call(this, 'entities');
128
- }
129
- createLinksWriteStream() {
130
- return __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_writeStream).call(this, 'links');
131
- }
132
- createConfigurationWriteStream() {
133
- return __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_writeStream).call(this, 'configuration');
134
- }
135
- createAssetsWriteStream() {
136
- let batch = [];
137
- let hasStarted = false;
138
- const batchSize = 1024 * 1024; // 1MB;
139
- const batchLength = () => {
140
- return batch.reduce((acc, chunk) => (chunk.action === 'stream' ? acc + chunk.data.byteLength : acc), 0);
141
- };
142
- const startAssetsTransferOnce = __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_startStepOnce).call(this, 'assets');
143
- const flush = async () => {
144
- const streamError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, 'assets', batch);
145
- batch = [];
146
- return streamError;
147
- };
148
- const safePush = async (chunk) => {
149
- batch.push(chunk);
150
- if (batchLength() >= batchSize) {
151
- const streamError = await flush();
152
- if (streamError) {
153
- throw streamError;
154
- }
155
- }
156
- };
157
- return new stream_1.Writable({
158
- objectMode: true,
159
- final: async (callback) => {
160
- if (batch.length > 0) {
161
- await flush();
162
- }
163
- if (hasStarted) {
164
- await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, 'assets', null);
165
- const endStepError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_endStep).call(this, 'assets');
166
- if (endStepError) {
167
- return callback(endStepError);
168
- }
169
- }
170
- return callback(null);
171
- },
172
- async write(asset, _encoding, callback) {
173
- const startError = await startAssetsTransferOnce();
174
- if (startError) {
175
- return callback(startError);
176
- }
177
- hasStarted = true;
178
- const assetID = (0, uuid_1.v4)();
179
- const { filename, filepath, stats, stream } = asset;
180
- try {
181
- await safePush({
182
- action: 'start',
183
- assetID,
184
- data: { filename, filepath, stats },
185
- });
186
- for await (const chunk of stream) {
187
- await safePush({ action: 'stream', assetID, data: chunk });
188
- }
189
- await safePush({ action: 'end', assetID });
190
- callback();
191
- }
192
- catch (error) {
193
- if (error instanceof Error) {
194
- callback(error);
195
- }
196
- }
197
- },
198
- });
199
- }
200
- }
201
- _RemoteStrapiDestinationProvider_instances = new WeakSet(), _RemoteStrapiDestinationProvider_startStepOnce = function _RemoteStrapiDestinationProvider_startStepOnce(stage) {
202
- return (0, fp_1.once)(() => __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_startStep).call(this, stage));
203
- }, _RemoteStrapiDestinationProvider_startStep = async function _RemoteStrapiDestinationProvider_startStep(step) {
204
- try {
205
- await this.dispatcher?.dispatchTransferStep({ action: 'start', step });
206
- }
207
- catch (e) {
208
- if (e instanceof Error) {
209
- return e;
210
- }
211
- if (typeof e === 'string') {
212
- return new providers_1.ProviderTransferError(e);
213
- }
214
- return new providers_1.ProviderTransferError('Unexpected error');
215
- }
216
- return null;
217
- }, _RemoteStrapiDestinationProvider_endStep = async function _RemoteStrapiDestinationProvider_endStep(step) {
218
- try {
219
- await this.dispatcher?.dispatchTransferStep({ action: 'end', step });
220
- }
221
- catch (e) {
222
- if (e instanceof Error) {
223
- return e;
224
- }
225
- if (typeof e === 'string') {
226
- return new providers_1.ProviderTransferError(e);
227
- }
228
- return new providers_1.ProviderTransferError('Unexpected error');
229
- }
230
- return null;
231
- }, _RemoteStrapiDestinationProvider_streamStep = async function _RemoteStrapiDestinationProvider_streamStep(step, data) {
232
- try {
233
- await this.dispatcher?.dispatchTransferStep({ action: 'stream', step, data });
234
- }
235
- catch (e) {
236
- if (e instanceof Error) {
237
- return e;
238
- }
239
- if (typeof e === 'string') {
240
- return new providers_1.ProviderTransferError(e);
241
- }
242
- return new providers_1.ProviderTransferError('Unexpected error');
243
- }
244
- return null;
245
- }, _RemoteStrapiDestinationProvider_writeStream = function _RemoteStrapiDestinationProvider_writeStream(step) {
246
- const batchSize = 1024 * 1024; // 1MB;
247
- const startTransferOnce = __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_startStepOnce).call(this, step);
248
- let batch = [];
249
- const batchLength = () => jsonLength(batch);
250
- return new stream_1.Writable({
251
- objectMode: true,
252
- final: async (callback) => {
253
- if (batch.length > 0) {
254
- const streamError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, step, batch);
255
- batch = [];
256
- if (streamError) {
257
- return callback(streamError);
258
- }
259
- }
260
- const e = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_endStep).call(this, step);
261
- callback(e);
262
- },
263
- write: async (chunk, _encoding, callback) => {
264
- const startError = await startTransferOnce();
265
- if (startError) {
266
- return callback(startError);
267
- }
268
- batch.push(chunk);
269
- if (batchLength() >= batchSize) {
270
- const streamError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, step, batch);
271
- batch = [];
272
- if (streamError) {
273
- return callback(streamError);
274
- }
275
- }
276
- callback();
277
- },
278
- });
279
- };
280
- const createRemoteStrapiDestinationProvider = (options) => {
281
- return new RemoteStrapiDestinationProvider(options);
282
- };
283
- exports.createRemoteStrapiDestinationProvider = createRemoteStrapiDestinationProvider;
284
- //# sourceMappingURL=index.js.map
@@ -1,31 +0,0 @@
1
- import { WebSocket } from 'ws';
2
- import type { client } from '../../../../types/remote/protocol';
3
- interface IDispatcherState {
4
- transfer?: {
5
- kind: client.TransferKind;
6
- id: string;
7
- };
8
- }
9
- interface IDispatchOptions {
10
- attachTransfer?: boolean;
11
- }
12
- declare type Dispatch<T> = Omit<T, 'transferID' | 'uuid'>;
13
- declare const createDispatcher: (ws: WebSocket) => {
14
- readonly transferID: string | undefined;
15
- readonly transferKind: "push" | "pull" | undefined;
16
- setTransferProperties: (properties: Exclude<IDispatcherState['transfer'], undefined>) => void;
17
- dispatch: <U = null>(message: Dispatch<client.Message>, options?: IDispatchOptions) => Promise<U | null>;
18
- dispatchCommand: <U_1 extends "end" | "init" | "status">(payload: {
19
- command: U_1;
20
- } & ([client.GetCommandParams<U_1>] extends [never] ? unknown : {
21
- params: client.GetCommandParams<U_1>;
22
- })) => Promise<null>;
23
- dispatchTransferAction: <T>(action: client.Action['action']) => Promise<T | null>;
24
- dispatchTransferStep: <T_1, A extends "stream" | "end" | "start" = "stream" | "end" | "start", S extends "entities" | "links" | "configuration" | "assets" = "entities" | "links" | "configuration" | "assets">(payload: {
25
- step: S;
26
- action: A;
27
- } & (A extends "stream" ? {
28
- data: client.GetTransferPushStreamData<S>;
29
- } : unknown)) => Promise<T_1 | null>;
30
- };
31
- export { createDispatcher };
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDispatcher = void 0;
4
- const uuid_1 = require("uuid");
5
- const providers_1 = require("../../../errors/providers");
6
- const createDispatcher = (ws) => {
7
- const state = {};
8
- const dispatch = async (message, options = {}) => {
9
- if (!ws) {
10
- throw new Error('No websocket connection found');
11
- }
12
- return new Promise((resolve, reject) => {
13
- const uuid = (0, uuid_1.v4)();
14
- const payload = { ...message, uuid };
15
- if (options.attachTransfer) {
16
- Object.assign(payload, { transferID: state.transfer?.id });
17
- }
18
- const stringifiedPayload = JSON.stringify(payload);
19
- ws.send(stringifiedPayload, (error) => {
20
- if (error) {
21
- reject(error);
22
- }
23
- });
24
- const onResponse = (raw) => {
25
- const response = JSON.parse(raw.toString());
26
- if (response.uuid === uuid) {
27
- if (response.error) {
28
- return reject(new providers_1.ProviderError('error', response.error.message));
29
- }
30
- resolve(response.data ?? null);
31
- }
32
- else {
33
- ws.once('message', onResponse);
34
- }
35
- };
36
- ws.once('message', onResponse);
37
- });
38
- };
39
- const dispatchCommand = (payload) => {
40
- return dispatch({ type: 'command', ...payload });
41
- };
42
- const dispatchTransferAction = async (action) => {
43
- const payload = { type: 'transfer', kind: 'action', action };
44
- return dispatch(payload, { attachTransfer: true }) ?? Promise.resolve(null);
45
- };
46
- const dispatchTransferStep = async (payload) => {
47
- const message = {
48
- type: 'transfer',
49
- kind: 'step',
50
- ...payload,
51
- };
52
- return dispatch(message, { attachTransfer: true }) ?? Promise.resolve(null);
53
- };
54
- const setTransferProperties = (properties) => {
55
- state.transfer = { ...properties };
56
- };
57
- return {
58
- get transferID() {
59
- return state.transfer?.id;
60
- },
61
- get transferKind() {
62
- return state.transfer?.kind;
63
- },
64
- setTransferProperties,
65
- dispatch,
66
- dispatchCommand,
67
- dispatchTransferAction,
68
- dispatchTransferStep,
69
- };
70
- };
71
- exports.createDispatcher = createDispatcher;
72
- //# sourceMappingURL=utils.js.map
@@ -1,19 +0,0 @@
1
- import type { ContentTypeSchema } from '@strapi/strapi';
2
- declare const createEntityQuery: (strapi: Strapi.Strapi) => (uid: string) => {
3
- create: <T extends {
4
- data: U;
5
- }, U extends object>(params: T) => Promise<any>;
6
- createMany: <T_1 extends {
7
- data: U_1[];
8
- }, U_1 extends object>(params: T_1) => Promise<{
9
- count: number;
10
- }>;
11
- deleteMany: <T_2 extends object>(params?: T_2 | undefined) => Promise<{
12
- count: number;
13
- } | null>;
14
- getDeepPopulateComponentLikeQuery: (contentType: ContentTypeSchema, params?: {
15
- select: string;
16
- }) => any;
17
- readonly deepPopulateComponentLikeQuery: any;
18
- };
19
- export { createEntityQuery };
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.createEntityQuery = void 0;
27
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
28
- // @ts-ignore
29
- const componentsService = __importStar(require("@strapi/strapi/lib/services/entity-service/components"));
30
- const fp_1 = require("lodash/fp");
31
- const sanitizeComponentLikeAttributes = (model, data) => {
32
- const { attributes } = model;
33
- const componentLikeAttributesKey = Object.entries(attributes)
34
- .filter(([, attribute]) => ['component', 'dynamiczone'].includes(attribute.type))
35
- .map(([key]) => key);
36
- return (0, fp_1.omit)(componentLikeAttributesKey, data);
37
- };
38
- const omitInvalidCreationAttributes = (0, fp_1.omit)(['id']);
39
- const createEntityQuery = (strapi) => {
40
- const components = {
41
- async assignToEntity(uid, data) {
42
- const model = strapi.getModel(uid);
43
- const entityComponents = await componentsService.createComponents(uid, data);
44
- const dataWithoutComponents = sanitizeComponentLikeAttributes(model, data);
45
- return (0, fp_1.assign)(entityComponents, dataWithoutComponents);
46
- },
47
- async get(uid, entity) {
48
- return componentsService.getComponents(uid, entity);
49
- },
50
- delete(uid, componentsToDelete) {
51
- return componentsService.deleteComponents(uid, componentsToDelete, { loadComponents: false });
52
- },
53
- };
54
- const query = (uid) => {
55
- const create = async (params) => {
56
- const dataWithComponents = await components.assignToEntity(uid, params.data);
57
- const sanitizedData = omitInvalidCreationAttributes(dataWithComponents);
58
- return strapi.db.query(uid).create({ ...params, data: sanitizedData });
59
- };
60
- const createMany = async (params) => {
61
- return (Promise.resolve(params.data)
62
- // Create components for each entity
63
- .then((0, fp_1.map)((data) => components.assignToEntity(uid, data)))
64
- // Remove unwanted attributes
65
- .then((0, fp_1.map)(omitInvalidCreationAttributes))
66
- // Execute a strapi db createMany query with all the entities + their created components
67
- .then((data) => strapi.db.query(uid).createMany({ ...params, data })));
68
- };
69
- const deleteMany = async (params) => {
70
- const entitiesToDelete = await strapi.db.query(uid).findMany(params ?? {});
71
- if (!entitiesToDelete.length) {
72
- return null;
73
- }
74
- const componentsToDelete = await Promise.all(entitiesToDelete.map((entityToDelete) => components.get(uid, entityToDelete)));
75
- const deletedEntities = await strapi.db.query(uid).deleteMany(params);
76
- await Promise.all(componentsToDelete.map((compos) => components.delete(uid, compos)));
77
- return deletedEntities;
78
- };
79
- const getDeepPopulateComponentLikeQuery = (contentType, params = { select: '*' }) => {
80
- const { attributes } = contentType;
81
- const populate = {};
82
- const entries = Object.entries(attributes);
83
- for (const [key, attribute] of entries) {
84
- if (attribute.type === 'component') {
85
- const component = strapi.getModel(attribute.component);
86
- const subPopulate = getDeepPopulateComponentLikeQuery(component, params);
87
- if (((0, fp_1.isArray)(subPopulate) || (0, fp_1.isObject)(subPopulate)) && (0, fp_1.size)(subPopulate) > 0) {
88
- populate[key] = { ...params, populate: subPopulate };
89
- }
90
- if ((0, fp_1.isArray)(subPopulate) && (0, fp_1.isEmpty)(subPopulate)) {
91
- populate[key] = { ...params };
92
- }
93
- }
94
- if (attribute.type === 'dynamiczone') {
95
- const { components: componentsUID } = attribute;
96
- const on = {};
97
- for (const componentUID of componentsUID) {
98
- const component = strapi.getModel(componentUID);
99
- const subPopulate = getDeepPopulateComponentLikeQuery(component, params);
100
- if (((0, fp_1.isArray)(subPopulate) || (0, fp_1.isObject)(subPopulate)) && (0, fp_1.size)(subPopulate) > 0) {
101
- on[componentUID] = { ...params, populate: subPopulate };
102
- }
103
- if ((0, fp_1.isArray)(subPopulate) && (0, fp_1.isEmpty)(subPopulate)) {
104
- on[componentUID] = { ...params };
105
- }
106
- }
107
- populate[key] = (0, fp_1.size)(on) > 0 ? { on } : true;
108
- }
109
- }
110
- const values = Object.values(populate);
111
- if (values.every((value) => value === true)) {
112
- return Object.keys(populate);
113
- }
114
- return populate;
115
- };
116
- return {
117
- create,
118
- createMany,
119
- deleteMany,
120
- getDeepPopulateComponentLikeQuery,
121
- get deepPopulateComponentLikeQuery() {
122
- const contentType = strapi.getModel(uid);
123
- return getDeepPopulateComponentLikeQuery(contentType);
124
- },
125
- };
126
- };
127
- return query;
128
- };
129
- exports.createEntityQuery = createEntityQuery;
130
- //# sourceMappingURL=entity.js.map
@@ -1,2 +0,0 @@
1
- export * as entity from './entity';
2
- export * as link from './link';
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.link = exports.entity = void 0;
27
- exports.entity = __importStar(require("./entity"));
28
- exports.link = __importStar(require("./link"));
29
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- import { ILink } from '../../../types';
2
- export declare const createLinkQuery: (strapi: Strapi.Strapi, trx?: any) => () => {
3
- generateAll: (uid: string) => AsyncGenerator<ILink>;
4
- generateAllForAttribute: (uid: string, fieldName: string) => AsyncGenerator<ILink>;
5
- insert: (link: ILink) => Promise<void>;
6
- };