@strapi/data-transfer 4.13.0 → 4.13.2
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 +675 -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 +365 -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 +109 -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,269 @@
|
|
|
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 crypto_1 = require("crypto");
|
|
11
|
+
const stream_1 = require("stream");
|
|
12
|
+
const fp_1 = require("lodash/fp");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const constants_1 = require("../../remote/constants");
|
|
15
|
+
const providers_1 = require("../../../errors/providers");
|
|
16
|
+
const jsonLength = (obj) => Buffer.byteLength(JSON.stringify(obj));
|
|
17
|
+
class RemoteStrapiDestinationProvider {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
_RemoteStrapiDestinationProvider_instances.add(this);
|
|
20
|
+
this.name = 'destination::remote-strapi';
|
|
21
|
+
this.type = 'destination';
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.ws = null;
|
|
24
|
+
this.dispatcher = null;
|
|
25
|
+
this.transferID = null;
|
|
26
|
+
}
|
|
27
|
+
async initTransfer() {
|
|
28
|
+
const { strategy, restore } = this.options;
|
|
29
|
+
const query = this.dispatcher?.dispatchCommand({
|
|
30
|
+
command: 'init',
|
|
31
|
+
params: { options: { strategy, restore }, transfer: 'push' },
|
|
32
|
+
});
|
|
33
|
+
const res = (await query);
|
|
34
|
+
if (!res?.transferID) {
|
|
35
|
+
throw new providers_1.ProviderTransferError('Init failed, invalid response from the server');
|
|
36
|
+
}
|
|
37
|
+
return res.transferID;
|
|
38
|
+
}
|
|
39
|
+
async bootstrap() {
|
|
40
|
+
const { url, auth } = this.options;
|
|
41
|
+
const validProtocols = ['https:', 'http:'];
|
|
42
|
+
let ws;
|
|
43
|
+
if (!validProtocols.includes(url.protocol)) {
|
|
44
|
+
throw new providers_1.ProviderValidationError(`Invalid protocol "${url.protocol}"`, {
|
|
45
|
+
check: 'url',
|
|
46
|
+
details: {
|
|
47
|
+
protocol: url.protocol,
|
|
48
|
+
validProtocols,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
53
|
+
const wsUrl = `${wsProtocol}//${url.host}${(0, utils_1.trimTrailingSlash)(url.pathname)}${constants_1.TRANSFER_PATH}/push`;
|
|
54
|
+
// No auth defined, trying public access for transfer
|
|
55
|
+
if (!auth) {
|
|
56
|
+
ws = await (0, utils_1.connectToWebsocket)(wsUrl);
|
|
57
|
+
}
|
|
58
|
+
// Common token auth, this should be the main auth method
|
|
59
|
+
else if (auth.type === 'token') {
|
|
60
|
+
const headers = { Authorization: `Bearer ${auth.token}` };
|
|
61
|
+
ws = await (0, utils_1.connectToWebsocket)(wsUrl, { headers });
|
|
62
|
+
}
|
|
63
|
+
// Invalid auth method provided
|
|
64
|
+
else {
|
|
65
|
+
throw new providers_1.ProviderValidationError('Auth method not available', {
|
|
66
|
+
check: 'auth.type',
|
|
67
|
+
details: {
|
|
68
|
+
auth: auth.type,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
this.ws = ws;
|
|
73
|
+
const { retryMessageOptions } = this.options;
|
|
74
|
+
this.dispatcher = (0, utils_1.createDispatcher)(this.ws, retryMessageOptions);
|
|
75
|
+
this.transferID = await this.initTransfer();
|
|
76
|
+
this.dispatcher.setTransferProperties({ id: this.transferID, kind: 'push' });
|
|
77
|
+
await this.dispatcher.dispatchTransferAction('bootstrap');
|
|
78
|
+
}
|
|
79
|
+
async close() {
|
|
80
|
+
// Gracefully close the remote transfer process
|
|
81
|
+
if (this.transferID && this.dispatcher) {
|
|
82
|
+
await this.dispatcher.dispatchTransferAction('close');
|
|
83
|
+
await this.dispatcher.dispatchCommand({
|
|
84
|
+
command: 'end',
|
|
85
|
+
params: { transferID: this.transferID },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
await new Promise((resolve) => {
|
|
89
|
+
const { ws } = this;
|
|
90
|
+
if (!ws || ws.CLOSED) {
|
|
91
|
+
resolve();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
ws.on('close', () => resolve()).close();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getMetadata() {
|
|
98
|
+
return this.dispatcher?.dispatchTransferAction('getMetadata') ?? null;
|
|
99
|
+
}
|
|
100
|
+
async beforeTransfer() {
|
|
101
|
+
await this.dispatcher?.dispatchTransferAction('beforeTransfer');
|
|
102
|
+
}
|
|
103
|
+
async rollback() {
|
|
104
|
+
await this.dispatcher?.dispatchTransferAction('rollback');
|
|
105
|
+
}
|
|
106
|
+
getSchemas() {
|
|
107
|
+
if (!this.dispatcher) {
|
|
108
|
+
return Promise.resolve(null);
|
|
109
|
+
}
|
|
110
|
+
return this.dispatcher.dispatchTransferAction('getSchemas');
|
|
111
|
+
}
|
|
112
|
+
createEntitiesWriteStream() {
|
|
113
|
+
return __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_writeStream).call(this, 'entities');
|
|
114
|
+
}
|
|
115
|
+
createLinksWriteStream() {
|
|
116
|
+
return __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_writeStream).call(this, 'links');
|
|
117
|
+
}
|
|
118
|
+
createConfigurationWriteStream() {
|
|
119
|
+
return __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_writeStream).call(this, 'configuration');
|
|
120
|
+
}
|
|
121
|
+
createAssetsWriteStream() {
|
|
122
|
+
let batch = [];
|
|
123
|
+
let hasStarted = false;
|
|
124
|
+
const batchSize = 1024 * 1024; // 1MB;
|
|
125
|
+
const batchLength = () => {
|
|
126
|
+
return batch.reduce((acc, chunk) => (chunk.action === 'stream' ? acc + chunk.data.byteLength : acc), 0);
|
|
127
|
+
};
|
|
128
|
+
const startAssetsTransferOnce = __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_startStepOnce).call(this, 'assets');
|
|
129
|
+
const flush = async () => {
|
|
130
|
+
const streamError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, 'assets', batch);
|
|
131
|
+
batch = [];
|
|
132
|
+
return streamError;
|
|
133
|
+
};
|
|
134
|
+
const safePush = async (chunk) => {
|
|
135
|
+
batch.push(chunk);
|
|
136
|
+
if (batchLength() >= batchSize) {
|
|
137
|
+
const streamError = await flush();
|
|
138
|
+
if (streamError) {
|
|
139
|
+
throw streamError;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return new stream_1.Writable({
|
|
144
|
+
objectMode: true,
|
|
145
|
+
final: async (callback) => {
|
|
146
|
+
if (batch.length > 0) {
|
|
147
|
+
await flush();
|
|
148
|
+
}
|
|
149
|
+
if (hasStarted) {
|
|
150
|
+
const endStepError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_endStep).call(this, 'assets');
|
|
151
|
+
if (endStepError) {
|
|
152
|
+
return callback(endStepError);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return callback(null);
|
|
156
|
+
},
|
|
157
|
+
async write(asset, _encoding, callback) {
|
|
158
|
+
const startError = await startAssetsTransferOnce();
|
|
159
|
+
if (startError) {
|
|
160
|
+
return callback(startError);
|
|
161
|
+
}
|
|
162
|
+
hasStarted = true;
|
|
163
|
+
const assetID = (0, crypto_1.randomUUID)();
|
|
164
|
+
const { filename, filepath, stats, stream, metadata } = asset;
|
|
165
|
+
try {
|
|
166
|
+
await safePush({
|
|
167
|
+
action: 'start',
|
|
168
|
+
assetID,
|
|
169
|
+
data: { filename, filepath, stats, metadata },
|
|
170
|
+
});
|
|
171
|
+
for await (const chunk of stream) {
|
|
172
|
+
await safePush({ action: 'stream', assetID, data: chunk });
|
|
173
|
+
}
|
|
174
|
+
await safePush({ action: 'end', assetID });
|
|
175
|
+
callback();
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (error instanceof Error) {
|
|
179
|
+
callback(error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
_RemoteStrapiDestinationProvider_instances = new WeakSet(), _RemoteStrapiDestinationProvider_startStepOnce = function _RemoteStrapiDestinationProvider_startStepOnce(stage) {
|
|
187
|
+
return (0, fp_1.once)(() => __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_startStep).call(this, stage));
|
|
188
|
+
}, _RemoteStrapiDestinationProvider_startStep = async function _RemoteStrapiDestinationProvider_startStep(step) {
|
|
189
|
+
try {
|
|
190
|
+
await this.dispatcher?.dispatchTransferStep({ action: 'start', step });
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
if (e instanceof Error) {
|
|
194
|
+
return e;
|
|
195
|
+
}
|
|
196
|
+
if (typeof e === 'string') {
|
|
197
|
+
return new providers_1.ProviderTransferError(e);
|
|
198
|
+
}
|
|
199
|
+
return new providers_1.ProviderTransferError('Unexpected error');
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
}, _RemoteStrapiDestinationProvider_endStep = async function _RemoteStrapiDestinationProvider_endStep(step) {
|
|
203
|
+
try {
|
|
204
|
+
await this.dispatcher?.dispatchTransferStep({ action: 'end', step });
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
if (e instanceof Error) {
|
|
208
|
+
return e;
|
|
209
|
+
}
|
|
210
|
+
if (typeof e === 'string') {
|
|
211
|
+
return new providers_1.ProviderTransferError(e);
|
|
212
|
+
}
|
|
213
|
+
return new providers_1.ProviderTransferError('Unexpected error');
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}, _RemoteStrapiDestinationProvider_streamStep = async function _RemoteStrapiDestinationProvider_streamStep(step, data) {
|
|
217
|
+
try {
|
|
218
|
+
await this.dispatcher?.dispatchTransferStep({ action: 'stream', step, data });
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
if (e instanceof Error) {
|
|
222
|
+
return e;
|
|
223
|
+
}
|
|
224
|
+
if (typeof e === 'string') {
|
|
225
|
+
return new providers_1.ProviderTransferError(e);
|
|
226
|
+
}
|
|
227
|
+
return new providers_1.ProviderTransferError('Unexpected error');
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}, _RemoteStrapiDestinationProvider_writeStream = function _RemoteStrapiDestinationProvider_writeStream(step) {
|
|
231
|
+
const batchSize = 1024 * 1024; // 1MB;
|
|
232
|
+
const startTransferOnce = __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_startStepOnce).call(this, step);
|
|
233
|
+
let batch = [];
|
|
234
|
+
const batchLength = () => jsonLength(batch);
|
|
235
|
+
return new stream_1.Writable({
|
|
236
|
+
objectMode: true,
|
|
237
|
+
final: async (callback) => {
|
|
238
|
+
if (batch.length > 0) {
|
|
239
|
+
const streamError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, step, batch);
|
|
240
|
+
batch = [];
|
|
241
|
+
if (streamError) {
|
|
242
|
+
return callback(streamError);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const e = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_endStep).call(this, step);
|
|
246
|
+
callback(e);
|
|
247
|
+
},
|
|
248
|
+
write: async (chunk, _encoding, callback) => {
|
|
249
|
+
const startError = await startTransferOnce();
|
|
250
|
+
if (startError) {
|
|
251
|
+
return callback(startError);
|
|
252
|
+
}
|
|
253
|
+
batch.push(chunk);
|
|
254
|
+
if (batchLength() >= batchSize) {
|
|
255
|
+
const streamError = await __classPrivateFieldGet(this, _RemoteStrapiDestinationProvider_instances, "m", _RemoteStrapiDestinationProvider_streamStep).call(this, step, batch);
|
|
256
|
+
batch = [];
|
|
257
|
+
if (streamError) {
|
|
258
|
+
return callback(streamError);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
callback();
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
const createRemoteStrapiDestinationProvider = (options) => {
|
|
266
|
+
return new RemoteStrapiDestinationProvider(options);
|
|
267
|
+
};
|
|
268
|
+
exports.createRemoteStrapiDestinationProvider = createRemoteStrapiDestinationProvider;
|
|
269
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/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C,CAAC;gBAExD,KAAK,GAAG,EAAE,CAAC;gBAEX,IAAI,WAAW,EAAE;oBACf,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;iBAC9B;aACF;YACD,MAAM,CAAC,GAAG,MAAM,uBAAA,IAAI,4FAAS,MAAb,IAAI,EAAU,IAAI,CAAC,CAAC;YAEpC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACd,CAAC;QAED,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;YAC1C,MAAM,UAAU,GAAG,MAAM,iBAAiB,EAAE,CAAC;YAC7C,IAAI,UAAU,EAAE;gBACd,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;aAC7B;YAED,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAElB,IAAI,WAAW,EAAE,IAAI,SAAS,EAAE;gBAC9B,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,+FAAY,MAAhB,IAAI,EAAa,IAAI,EAAE,KAAK,CAAC,CAAC;gBAExD,KAAK,GAAG,EAAE,CAAC;gBAEX,IAAI,WAAW,EAAE;oBACf,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;iBAC9B;aACF;YAED,QAAQ,EAAE,CAAC;QACb,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAgMI,MAAM,qCAAqC,GAAG,CACnD,OAAgD,EAChD,EAAE;IACF,OAAO,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC,CAAC;AAJW,QAAA,qCAAqC,yCAIhD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable, Writable } from 'stream';
|
|
3
|
+
import type { Schema, Utils } from '@strapi/strapi';
|
|
4
|
+
import { WebSocket } from 'ws';
|
|
5
|
+
import type { IMetadata, ISourceProvider, ISourceProviderTransferResults, MaybePromise, ProviderType } from '../../../../types';
|
|
6
|
+
import { Auth } from '../../../../types/remote/protocol';
|
|
7
|
+
import { ILocalStrapiSourceProviderOptions } from '../local-source';
|
|
8
|
+
import { createDispatcher } from '../utils';
|
|
9
|
+
export interface IRemoteStrapiSourceProviderOptions extends ILocalStrapiSourceProviderOptions {
|
|
10
|
+
url: URL;
|
|
11
|
+
auth?: Auth.ITransferTokenAuth;
|
|
12
|
+
retryMessageOptions?: {
|
|
13
|
+
retryMessageTimeout: number;
|
|
14
|
+
retryMessageMaxRetries: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
declare class RemoteStrapiSourceProvider implements ISourceProvider {
|
|
18
|
+
#private;
|
|
19
|
+
name: string;
|
|
20
|
+
type: ProviderType;
|
|
21
|
+
options: IRemoteStrapiSourceProviderOptions;
|
|
22
|
+
ws: WebSocket | null;
|
|
23
|
+
dispatcher: ReturnType<typeof createDispatcher> | null;
|
|
24
|
+
constructor(options: IRemoteStrapiSourceProviderOptions);
|
|
25
|
+
results?: ISourceProviderTransferResults | undefined;
|
|
26
|
+
createEntitiesReadStream(): MaybePromise<Readable>;
|
|
27
|
+
createLinksReadStream(): MaybePromise<Readable>;
|
|
28
|
+
writeAsync: <T>(stream: Writable, data: T) => Promise<void>;
|
|
29
|
+
createAssetsReadStream(): Promise<Readable>;
|
|
30
|
+
createConfigurationReadStream(): MaybePromise<Readable>;
|
|
31
|
+
getMetadata(): Promise<IMetadata | null>;
|
|
32
|
+
assertValidProtocol(url: URL): void;
|
|
33
|
+
initTransfer(): Promise<string>;
|
|
34
|
+
bootstrap(): Promise<void>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
getSchemas(): Promise<Utils.String.Dict<Schema.Schema> | null>;
|
|
37
|
+
}
|
|
38
|
+
export declare const createRemoteStrapiSourceProvider: (options: IRemoteStrapiSourceProviderOptions) => RemoteStrapiSourceProvider;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
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 _RemoteStrapiSourceProvider_instances, _RemoteStrapiSourceProvider_createStageReadStream, _RemoteStrapiSourceProvider_startStep, _RemoteStrapiSourceProvider_respond, _RemoteStrapiSourceProvider_endStep;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createRemoteStrapiSourceProvider = void 0;
|
|
10
|
+
const stream_1 = require("stream");
|
|
11
|
+
const fp_1 = require("lodash/fp");
|
|
12
|
+
const providers_1 = require("../../../errors/providers");
|
|
13
|
+
const constants_1 = require("../../remote/constants");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
class RemoteStrapiSourceProvider {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
_RemoteStrapiSourceProvider_instances.add(this);
|
|
18
|
+
this.name = 'source::remote-strapi';
|
|
19
|
+
this.type = 'source';
|
|
20
|
+
this.writeAsync = (stream, data) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
stream.write(data, (error) => {
|
|
23
|
+
if (error) {
|
|
24
|
+
reject(error);
|
|
25
|
+
}
|
|
26
|
+
resolve();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.ws = null;
|
|
32
|
+
this.dispatcher = null;
|
|
33
|
+
}
|
|
34
|
+
createEntitiesReadStream() {
|
|
35
|
+
return __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_createStageReadStream).call(this, 'entities');
|
|
36
|
+
}
|
|
37
|
+
createLinksReadStream() {
|
|
38
|
+
return __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_createStageReadStream).call(this, 'links');
|
|
39
|
+
}
|
|
40
|
+
async createAssetsReadStream() {
|
|
41
|
+
const assets = {};
|
|
42
|
+
const stream = await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_createStageReadStream).call(this, 'assets');
|
|
43
|
+
const pass = new stream_1.PassThrough({ objectMode: true });
|
|
44
|
+
stream
|
|
45
|
+
.on('data', async (payload) => {
|
|
46
|
+
for (const item of payload) {
|
|
47
|
+
const { action } = item;
|
|
48
|
+
// Creates the stream to send the incoming asset through
|
|
49
|
+
if (action === 'start') {
|
|
50
|
+
// Each asset has its own stream identified by its assetID
|
|
51
|
+
assets[item.assetID] = { ...item.data, stream: new stream_1.PassThrough() };
|
|
52
|
+
await this.writeAsync(pass, assets[item.assetID]);
|
|
53
|
+
}
|
|
54
|
+
// Writes the asset data to the created stream
|
|
55
|
+
else if (action === 'stream') {
|
|
56
|
+
// Converts data into buffer
|
|
57
|
+
const rawBuffer = item.data;
|
|
58
|
+
const chunk = Buffer.from(rawBuffer.data);
|
|
59
|
+
await this.writeAsync(assets[item.assetID].stream, chunk);
|
|
60
|
+
}
|
|
61
|
+
// The asset has been transferred
|
|
62
|
+
else if (action === 'end') {
|
|
63
|
+
await new Promise((resolve, reject) => {
|
|
64
|
+
const { stream: assetStream } = assets[item.assetID];
|
|
65
|
+
assetStream
|
|
66
|
+
.on('close', () => {
|
|
67
|
+
// Deletes the stream for the asset
|
|
68
|
+
delete assets[item.assetID];
|
|
69
|
+
resolve();
|
|
70
|
+
})
|
|
71
|
+
.on('error', reject)
|
|
72
|
+
.end();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.on('close', () => {
|
|
78
|
+
pass.end();
|
|
79
|
+
});
|
|
80
|
+
return pass;
|
|
81
|
+
}
|
|
82
|
+
createConfigurationReadStream() {
|
|
83
|
+
return __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_createStageReadStream).call(this, 'configuration');
|
|
84
|
+
}
|
|
85
|
+
async getMetadata() {
|
|
86
|
+
const metadata = await this.dispatcher?.dispatchTransferAction('getMetadata');
|
|
87
|
+
return metadata ?? null;
|
|
88
|
+
}
|
|
89
|
+
assertValidProtocol(url) {
|
|
90
|
+
const validProtocols = ['https:', 'http:'];
|
|
91
|
+
if (!validProtocols.includes(url.protocol)) {
|
|
92
|
+
throw new providers_1.ProviderValidationError(`Invalid protocol "${url.protocol}"`, {
|
|
93
|
+
check: 'url',
|
|
94
|
+
details: {
|
|
95
|
+
protocol: url.protocol,
|
|
96
|
+
validProtocols,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async initTransfer() {
|
|
102
|
+
const query = this.dispatcher?.dispatchCommand({
|
|
103
|
+
command: 'init',
|
|
104
|
+
});
|
|
105
|
+
const res = (await query);
|
|
106
|
+
if (!res?.transferID) {
|
|
107
|
+
throw new providers_1.ProviderTransferError('Init failed, invalid response from the server');
|
|
108
|
+
}
|
|
109
|
+
return res.transferID;
|
|
110
|
+
}
|
|
111
|
+
async bootstrap() {
|
|
112
|
+
const { url, auth } = this.options;
|
|
113
|
+
let ws;
|
|
114
|
+
this.assertValidProtocol(url);
|
|
115
|
+
const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
116
|
+
const wsUrl = `${wsProtocol}//${url.host}${(0, utils_1.trimTrailingSlash)(url.pathname)}${constants_1.TRANSFER_PATH}/pull`;
|
|
117
|
+
// No auth defined, trying public access for transfer
|
|
118
|
+
if (!auth) {
|
|
119
|
+
ws = await (0, utils_1.connectToWebsocket)(wsUrl);
|
|
120
|
+
}
|
|
121
|
+
// Common token auth, this should be the main auth method
|
|
122
|
+
else if (auth.type === 'token') {
|
|
123
|
+
const headers = { Authorization: `Bearer ${auth.token}` };
|
|
124
|
+
ws = await (0, utils_1.connectToWebsocket)(wsUrl, { headers });
|
|
125
|
+
}
|
|
126
|
+
// Invalid auth method provided
|
|
127
|
+
else {
|
|
128
|
+
throw new providers_1.ProviderValidationError('Auth method not available', {
|
|
129
|
+
check: 'auth.type',
|
|
130
|
+
details: {
|
|
131
|
+
auth: auth.type,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
this.ws = ws;
|
|
136
|
+
const { retryMessageOptions } = this.options;
|
|
137
|
+
this.dispatcher = (0, utils_1.createDispatcher)(this.ws, retryMessageOptions);
|
|
138
|
+
const transferID = await this.initTransfer();
|
|
139
|
+
this.dispatcher.setTransferProperties({ id: transferID, kind: 'pull' });
|
|
140
|
+
await this.dispatcher.dispatchTransferAction('bootstrap');
|
|
141
|
+
}
|
|
142
|
+
async close() {
|
|
143
|
+
await this.dispatcher?.dispatchTransferAction('close');
|
|
144
|
+
await new Promise((resolve) => {
|
|
145
|
+
const { ws } = this;
|
|
146
|
+
if (!ws || ws.CLOSED) {
|
|
147
|
+
resolve();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
ws.on('close', () => resolve()).close();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async getSchemas() {
|
|
154
|
+
const schemas = (await this.dispatcher?.dispatchTransferAction('getSchemas')) ?? null;
|
|
155
|
+
return schemas;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
_RemoteStrapiSourceProvider_instances = new WeakSet(), _RemoteStrapiSourceProvider_createStageReadStream = async function _RemoteStrapiSourceProvider_createStageReadStream(stage) {
|
|
159
|
+
const startResult = await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_startStep).call(this, stage);
|
|
160
|
+
if (startResult instanceof Error) {
|
|
161
|
+
throw startResult;
|
|
162
|
+
}
|
|
163
|
+
const { id: processID } = startResult;
|
|
164
|
+
const stream = new stream_1.PassThrough({ objectMode: true });
|
|
165
|
+
const listener = async (raw) => {
|
|
166
|
+
const parsed = JSON.parse(raw.toString());
|
|
167
|
+
// If not a message related to our transfer process, ignore it
|
|
168
|
+
if (!parsed.uuid || parsed?.data?.type !== 'transfer' || parsed?.data?.id !== processID) {
|
|
169
|
+
this.ws?.once('message', listener);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const { uuid, data: message } = parsed;
|
|
173
|
+
const { ended, error, data } = message;
|
|
174
|
+
if (ended) {
|
|
175
|
+
await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_respond).call(this, uuid);
|
|
176
|
+
await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_endStep).call(this, stage);
|
|
177
|
+
stream.end();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (error) {
|
|
181
|
+
await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_respond).call(this, uuid);
|
|
182
|
+
await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_endStep).call(this, stage);
|
|
183
|
+
stream.destroy(error);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// if we get a single items instead of a batch
|
|
187
|
+
// TODO V5: in v5 only allow array
|
|
188
|
+
for (const item of (0, fp_1.castArray)(data)) {
|
|
189
|
+
stream.push(item);
|
|
190
|
+
}
|
|
191
|
+
this.ws?.once('message', listener);
|
|
192
|
+
await __classPrivateFieldGet(this, _RemoteStrapiSourceProvider_instances, "m", _RemoteStrapiSourceProvider_respond).call(this, uuid);
|
|
193
|
+
};
|
|
194
|
+
this.ws?.once('message', listener);
|
|
195
|
+
return stream;
|
|
196
|
+
}, _RemoteStrapiSourceProvider_startStep = async function _RemoteStrapiSourceProvider_startStep(step) {
|
|
197
|
+
try {
|
|
198
|
+
return await this.dispatcher?.dispatchTransferStep({ action: 'start', step });
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
if (e instanceof Error) {
|
|
202
|
+
return e;
|
|
203
|
+
}
|
|
204
|
+
if (typeof e === 'string') {
|
|
205
|
+
return new providers_1.ProviderTransferError(e);
|
|
206
|
+
}
|
|
207
|
+
return new providers_1.ProviderTransferError('Unexpected error');
|
|
208
|
+
}
|
|
209
|
+
}, _RemoteStrapiSourceProvider_respond = async function _RemoteStrapiSourceProvider_respond(uuid) {
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
this.ws?.send(JSON.stringify({ uuid }), (e) => {
|
|
212
|
+
if (e) {
|
|
213
|
+
reject(e);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
resolve(e);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}, _RemoteStrapiSourceProvider_endStep = async function _RemoteStrapiSourceProvider_endStep(step) {
|
|
221
|
+
try {
|
|
222
|
+
await this.dispatcher?.dispatchTransferStep({ action: 'end', step });
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
if (e instanceof Error) {
|
|
226
|
+
return e;
|
|
227
|
+
}
|
|
228
|
+
if (typeof e === 'string') {
|
|
229
|
+
return new providers_1.ProviderTransferError(e);
|
|
230
|
+
}
|
|
231
|
+
return new providers_1.ProviderTransferError('Unexpected error');
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
const createRemoteStrapiSourceProvider = (options) => {
|
|
236
|
+
return new RemoteStrapiSourceProvider(options);
|
|
237
|
+
};
|
|
238
|
+
exports.createRemoteStrapiSourceProvider = createRemoteStrapiSourceProvider;
|
|
239
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/providers/remote-source/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mCAAyD;AAGzD,kCAAsC;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Socket } 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
|
+
type Dispatch<T> = Omit<T, 'transferID' | 'uuid'>;
|
|
13
|
+
export declare const createDispatcher: (ws: WebSocket, retryMessageOptions?: {
|
|
14
|
+
retryMessageMaxRetries: number;
|
|
15
|
+
retryMessageTimeout: number;
|
|
16
|
+
}) => {
|
|
17
|
+
readonly transferID: string | undefined;
|
|
18
|
+
readonly transferKind: "push" | "pull" | undefined;
|
|
19
|
+
setTransferProperties: (properties: Exclude<IDispatcherState['transfer'], undefined>) => void;
|
|
20
|
+
dispatch: <U = null>(message: Dispatch<Client.Message>, options?: IDispatchOptions) => Promise<U | null>;
|
|
21
|
+
dispatchCommand: <U_1 extends "end" | "init" | "status">(payload: {
|
|
22
|
+
command: U_1;
|
|
23
|
+
} & ([Client.GetCommandParams<U_1>] extends [never] ? unknown : {
|
|
24
|
+
params?: Client.GetCommandParams<U_1> | undefined;
|
|
25
|
+
})) => Promise<null>;
|
|
26
|
+
dispatchTransferAction: <T>(action: Client.Action['action']) => Promise<T | null>;
|
|
27
|
+
dispatchTransferStep: <T_1, A extends "stream" | "end" | "start" = "stream" | "end" | "start", S extends "entities" | "links" | "configuration" | "assets" = "entities" | "links" | "configuration" | "assets">(payload: {
|
|
28
|
+
step: S;
|
|
29
|
+
action: A;
|
|
30
|
+
} & (A extends "stream" ? {
|
|
31
|
+
data: Client.GetTransferPushStreamData<S>;
|
|
32
|
+
} : unknown)) => Promise<T_1 | null>;
|
|
33
|
+
};
|
|
34
|
+
type WebsocketParams = ConstructorParameters<typeof WebSocket>;
|
|
35
|
+
type Address = WebsocketParams[0];
|
|
36
|
+
type Options = WebsocketParams[2];
|
|
37
|
+
export declare const connectToWebsocket: (address: Address, options?: Options) => Promise<WebSocket>;
|
|
38
|
+
export declare const trimTrailingSlash: (input: string) => string;
|
|
39
|
+
export {};
|