@strapi/data-transfer 4.10.0-beta.0 → 4.10.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 (189) hide show
  1. package/dist/engine/diagnostic.d.ts +10 -10
  2. package/dist/engine/diagnostic.js.map +1 -0
  3. package/dist/engine/errors.d.ts +2 -2
  4. package/dist/engine/errors.js.map +1 -0
  5. package/dist/engine/index.d.ts +1 -1
  6. package/dist/engine/index.js.map +1 -0
  7. package/dist/engine/validation/index.js.map +1 -0
  8. package/dist/engine/validation/provider.js.map +1 -0
  9. package/dist/engine/validation/schemas/index.js +29 -12
  10. package/dist/engine/validation/schemas/index.js.map +1 -0
  11. package/dist/errors/base.js.map +1 -0
  12. package/dist/errors/constants.d.ts +1 -1
  13. package/dist/errors/constants.js.map +1 -0
  14. package/dist/errors/index.js.map +1 -0
  15. package/dist/errors/providers.d.ts +2 -2
  16. package/dist/errors/providers.js.map +1 -0
  17. package/dist/file/index.js.map +1 -0
  18. package/dist/file/providers/destination/index.d.ts +1 -0
  19. package/dist/file/providers/destination/index.js +2 -1
  20. package/dist/file/providers/destination/index.js.map +1 -0
  21. package/dist/file/providers/destination/utils.d.ts +1 -1
  22. package/dist/file/providers/destination/utils.js +2 -1
  23. package/dist/file/providers/destination/utils.js.map +1 -0
  24. package/dist/file/providers/index.js.map +1 -0
  25. package/dist/file/providers/source/index.d.ts +1 -1
  26. package/dist/file/providers/source/index.js +34 -24
  27. package/dist/file/providers/source/index.js.map +1 -0
  28. package/dist/file/providers/source/utils.d.ts +37 -0
  29. package/dist/file/providers/source/utils.js +62 -0
  30. package/dist/file/providers/source/utils.js.map +1 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/strapi/index.js.map +1 -0
  33. package/dist/strapi/providers/index.js.map +1 -0
  34. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  35. package/dist/strapi/providers/local-destination/strategies/index.js.map +1 -0
  36. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -1
  37. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  38. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  39. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +1 -1
  40. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  41. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -1
  42. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  43. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  44. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  45. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  46. package/dist/strapi/providers/local-source/index.d.ts +1 -1
  47. package/dist/strapi/providers/local-source/index.js.map +1 -0
  48. package/dist/strapi/providers/local-source/links.js.map +1 -0
  49. package/dist/strapi/providers/remote-destination/index.js +4 -19
  50. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  51. package/dist/strapi/providers/remote-source/index.js +3 -4
  52. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  53. package/dist/strapi/providers/utils.d.ts +8 -3
  54. package/dist/strapi/providers/utils.js +22 -1
  55. package/dist/strapi/providers/utils.js.map +1 -0
  56. package/dist/strapi/queries/entity.js.map +1 -0
  57. package/dist/strapi/queries/index.js.map +1 -0
  58. package/dist/strapi/queries/link.js.map +1 -0
  59. package/dist/strapi/remote/constants.d.ts +2 -2
  60. package/dist/strapi/remote/constants.js.map +1 -0
  61. package/dist/strapi/remote/flows/default.js.map +1 -0
  62. package/dist/strapi/remote/flows/index.d.ts +1 -1
  63. package/dist/strapi/remote/flows/index.js.map +1 -0
  64. package/dist/strapi/remote/handlers/abstract.d.ts +1 -1
  65. package/dist/strapi/remote/handlers/abstract.js.map +1 -0
  66. package/dist/strapi/remote/handlers/constants.d.ts +1 -1
  67. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  68. package/dist/strapi/remote/handlers/index.js.map +1 -0
  69. package/dist/strapi/remote/handlers/pull.d.ts +1 -1
  70. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  71. package/dist/strapi/remote/handlers/push.d.ts +1 -1
  72. package/dist/strapi/remote/handlers/push.js.map +1 -0
  73. package/dist/strapi/remote/handlers/utils.d.ts +1 -1
  74. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  75. package/dist/strapi/remote/index.js.map +1 -0
  76. package/dist/utils/encryption/decrypt.js.map +1 -0
  77. package/dist/utils/encryption/encrypt.js.map +1 -0
  78. package/dist/utils/encryption/index.js.map +1 -0
  79. package/dist/utils/index.js.map +1 -0
  80. package/dist/utils/json.d.ts +1 -1
  81. package/dist/utils/json.js.map +1 -0
  82. package/dist/utils/providers.d.ts +1 -1
  83. package/dist/utils/providers.js.map +1 -0
  84. package/dist/utils/schema.js.map +1 -0
  85. package/dist/utils/stream.d.ts +1 -1
  86. package/dist/utils/stream.js.map +1 -0
  87. package/dist/utils/transaction.js.map +1 -0
  88. package/package.json +18 -17
  89. package/jest.config.js +0 -14
  90. package/lib/engine/diagnostic.d.ts +0 -40
  91. package/lib/engine/diagnostic.js +0 -50
  92. package/lib/engine/errors.d.ts +0 -28
  93. package/lib/engine/errors.js +0 -29
  94. package/lib/engine/index.d.ts +0 -44
  95. package/lib/engine/index.js +0 -506
  96. package/lib/engine/validation/index.d.ts +0 -2
  97. package/lib/engine/validation/index.js +0 -19
  98. package/lib/engine/validation/provider.d.ts +0 -3
  99. package/lib/engine/validation/provider.js +0 -18
  100. package/lib/engine/validation/schemas/index.d.ts +0 -7
  101. package/lib/engine/validation/schemas/index.js +0 -53
  102. package/lib/errors/base.d.ts +0 -8
  103. package/lib/errors/base.js +0 -13
  104. package/lib/errors/constants.d.ts +0 -3
  105. package/lib/errors/constants.js +0 -9
  106. package/lib/errors/index.d.ts +0 -2
  107. package/lib/errors/index.js +0 -19
  108. package/lib/errors/providers.d.ts +0 -21
  109. package/lib/errors/providers.js +0 -32
  110. package/lib/file/index.d.ts +0 -1
  111. package/lib/file/index.js +0 -28
  112. package/lib/file/providers/destination/index.d.ts +0 -45
  113. package/lib/file/providers/destination/index.js +0 -174
  114. package/lib/file/providers/destination/utils.d.ts +0 -9
  115. package/lib/file/providers/destination/utils.js +0 -61
  116. package/lib/file/providers/index.d.ts +0 -2
  117. package/lib/file/providers/index.js +0 -19
  118. package/lib/file/providers/source/index.d.ts +0 -40
  119. package/lib/file/providers/source/index.js +0 -220
  120. package/lib/index.d.ts +0 -4
  121. package/lib/index.js +0 -31
  122. package/lib/strapi/index.d.ts +0 -3
  123. package/lib/strapi/index.js +0 -30
  124. package/lib/strapi/providers/index.d.ts +0 -3
  125. package/lib/strapi/providers/index.js +0 -22
  126. package/lib/strapi/providers/local-destination/index.d.ts +0 -34
  127. package/lib/strapi/providers/local-destination/index.js +0 -220
  128. package/lib/strapi/providers/local-destination/strategies/index.d.ts +0 -1
  129. package/lib/strapi/providers/local-destination/strategies/index.js +0 -28
  130. package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +0 -5
  131. package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
  132. package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +0 -11
  133. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +0 -103
  134. package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +0 -32
  135. package/lib/strapi/providers/local-destination/strategies/restore/index.js +0 -107
  136. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +0 -4
  137. package/lib/strapi/providers/local-destination/strategies/restore/links.js +0 -32
  138. package/lib/strapi/providers/local-source/assets.d.ts +0 -5
  139. package/lib/strapi/providers/local-source/assets.js +0 -31
  140. package/lib/strapi/providers/local-source/configuration.d.ts +0 -5
  141. package/lib/strapi/providers/local-source/configuration.js +0 -36
  142. package/lib/strapi/providers/local-source/entities.d.ts +0 -10
  143. package/lib/strapi/providers/local-source/entities.js +0 -85
  144. package/lib/strapi/providers/local-source/index.d.ts +0 -27
  145. package/lib/strapi/providers/local-source/index.js +0 -98
  146. package/lib/strapi/providers/local-source/links.d.ts +0 -5
  147. package/lib/strapi/providers/local-source/links.js +0 -23
  148. package/lib/strapi/providers/remote-destination/index.d.ts +0 -37
  149. package/lib/strapi/providers/remote-destination/index.js +0 -284
  150. package/lib/strapi/providers/remote-destination/utils.d.ts +0 -31
  151. package/lib/strapi/providers/remote-destination/utils.js +0 -72
  152. package/lib/strapi/queries/entity.d.ts +0 -19
  153. package/lib/strapi/queries/entity.js +0 -130
  154. package/lib/strapi/queries/index.d.ts +0 -2
  155. package/lib/strapi/queries/index.js +0 -29
  156. package/lib/strapi/queries/link.d.ts +0 -6
  157. package/lib/strapi/queries/link.js +0 -215
  158. package/lib/strapi/remote/constants.d.ts +0 -2
  159. package/lib/strapi/remote/constants.js +0 -6
  160. package/lib/strapi/remote/controllers/index.d.ts +0 -1
  161. package/lib/strapi/remote/controllers/index.js +0 -18
  162. package/lib/strapi/remote/controllers/push.d.ts +0 -26
  163. package/lib/strapi/remote/controllers/push.js +0 -116
  164. package/lib/strapi/remote/flows/default.d.ts +0 -3
  165. package/lib/strapi/remote/flows/default.js +0 -41
  166. package/lib/strapi/remote/flows/index.d.ts +0 -18
  167. package/lib/strapi/remote/flows/index.js +0 -59
  168. package/lib/strapi/remote/handlers.d.ts +0 -10
  169. package/lib/strapi/remote/handlers.js +0 -285
  170. package/lib/strapi/remote/index.d.ts +0 -3
  171. package/lib/strapi/remote/index.js +0 -30
  172. package/lib/utils/encryption/decrypt.d.ts +0 -11
  173. package/lib/utils/encryption/decrypt.js +0 -47
  174. package/lib/utils/encryption/encrypt.d.ts +0 -11
  175. package/lib/utils/encryption/encrypt.js +0 -47
  176. package/lib/utils/encryption/index.d.ts +0 -2
  177. package/lib/utils/encryption/index.js +0 -19
  178. package/lib/utils/index.d.ts +0 -5
  179. package/lib/utils/index.js +0 -32
  180. package/lib/utils/json.d.ts +0 -30
  181. package/lib/utils/json.js +0 -68
  182. package/lib/utils/providers.d.ts +0 -2
  183. package/lib/utils/providers.js +0 -11
  184. package/lib/utils/schema.d.ts +0 -7
  185. package/lib/utils/schema.js +0 -29
  186. package/lib/utils/stream.d.ts +0 -27
  187. package/lib/utils/stream.js +0 -59
  188. package/lib/utils/transaction.d.ts +0 -3
  189. package/lib/utils/transaction.js +0 -88
@@ -1,215 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLinkQuery = void 0;
4
- const fp_1 = require("lodash/fp");
5
- // TODO: Remove any types when we'll have types for DB metadata
6
- const createLinkQuery = (strapi, trx) => {
7
- const query = () => {
8
- const { connection } = strapi.db;
9
- async function* generateAllForAttribute(uid, fieldName) {
10
- const metadata = strapi.db.metadata.get(uid);
11
- if (!metadata) {
12
- throw new Error(`No metadata found for ${uid}`);
13
- }
14
- const attributes = filterValidRelationalAttributes(metadata.attributes);
15
- if (!(fieldName in attributes)) {
16
- throw new Error(`${fieldName} is not a valid relational attribute name`);
17
- }
18
- const attribute = attributes[fieldName];
19
- const kind = getLinkKind(attribute, uid);
20
- const { relation, target } = attribute;
21
- // The relation is stored in the same table
22
- // TODO: handle manyToOne joinColumn
23
- if (attribute.joinColumn) {
24
- const joinColumnName = attribute.joinColumn.name;
25
- const qb = connection.queryBuilder().select('id', joinColumnName).from(metadata.tableName);
26
- if (trx) {
27
- qb.transacting(trx);
28
- }
29
- // TODO: stream the query to improve performances
30
- const entries = await qb;
31
- for (const entry of entries) {
32
- const ref = entry[joinColumnName];
33
- if (ref !== null) {
34
- yield {
35
- kind,
36
- relation,
37
- left: { type: uid, ref: entry.id, field: fieldName },
38
- right: { type: target, ref },
39
- };
40
- }
41
- }
42
- }
43
- // The relation uses a join table
44
- if (attribute.joinTable) {
45
- const { name, joinColumn, inverseJoinColumn, orderColumnName, morphColumn, inverseOrderColumnName, } = attribute.joinTable;
46
- const qb = connection.queryBuilder().from(name);
47
- const columns = {
48
- left: { ref: null },
49
- right: { ref: null },
50
- };
51
- const left = { type: uid, field: fieldName };
52
- const right = {};
53
- if (kind === 'relation.basic' || kind === 'relation.circular') {
54
- right.type = attribute.target;
55
- right.field = attribute.inversedBy;
56
- columns.left.ref = joinColumn.name;
57
- columns.right.ref = inverseJoinColumn.name;
58
- if (orderColumnName) {
59
- columns.left.order = orderColumnName;
60
- }
61
- if (inverseOrderColumnName) {
62
- columns.right.order = inverseOrderColumnName;
63
- }
64
- }
65
- if (kind === 'relation.morph') {
66
- columns.left.ref = joinColumn.name;
67
- columns.right.ref = morphColumn.idColumn.name;
68
- columns.right.type = morphColumn.typeColumn.name;
69
- columns.right.field = 'field';
70
- columns.right.order = 'order';
71
- }
72
- const validColumns = [
73
- // Left
74
- columns.left.ref,
75
- columns.left.order,
76
- // Right
77
- columns.right.ref,
78
- columns.right.type,
79
- columns.right.field,
80
- columns.right.order,
81
- ].filter((column) => !(0, fp_1.isNil)(column));
82
- qb.select(validColumns);
83
- if (trx) {
84
- qb.transacting(trx);
85
- }
86
- // TODO: stream the query to improve performances
87
- const entries = await qb;
88
- for (const entry of entries) {
89
- if (columns.left.ref) {
90
- left.ref = entry[columns.left.ref];
91
- }
92
- if (columns.right.ref) {
93
- right.ref = entry[columns.right.ref];
94
- }
95
- if (columns.left.order) {
96
- left.pos = entry[columns.left.order];
97
- }
98
- if (columns.right.order) {
99
- right.pos = entry[columns.right.order];
100
- }
101
- if (columns.right.type) {
102
- right.type = entry[columns.right.type];
103
- }
104
- if (columns.right.field) {
105
- right.field = entry[columns.right.field];
106
- }
107
- const link = {
108
- kind,
109
- relation,
110
- left: (0, fp_1.clone)(left),
111
- right: (0, fp_1.clone)(right),
112
- };
113
- yield link;
114
- }
115
- }
116
- }
117
- async function* generateAll(uid) {
118
- const metadata = strapi.db.metadata.get(uid);
119
- if (!metadata) {
120
- throw new Error(`No metadata found for ${uid}`);
121
- }
122
- const attributes = filterValidRelationalAttributes(metadata.attributes);
123
- for (const fieldName of Object.keys(attributes)) {
124
- for await (const link of generateAllForAttribute(uid, fieldName)) {
125
- yield link;
126
- }
127
- }
128
- }
129
- const insert = async (link) => {
130
- const { kind, left, right } = link;
131
- const metadata = strapi.db.metadata.get(left.type);
132
- const attribute = metadata.attributes[left.field];
133
- const payload = {};
134
- if (attribute.joinColumn) {
135
- const joinColumnName = attribute.joinColumn.name;
136
- const qb = connection(metadata.tableName)
137
- .where('id', left.ref)
138
- .update({ [joinColumnName]: right.ref });
139
- if (trx) {
140
- qb.transacting(trx);
141
- }
142
- await qb;
143
- }
144
- if (attribute.joinTable) {
145
- const { name, joinColumn, inverseJoinColumn, orderColumnName, inverseOrderColumnName, morphColumn, } = attribute.joinTable;
146
- if (joinColumn) {
147
- Object.assign(payload, { [joinColumn.name]: left.ref });
148
- }
149
- const assignInverseColumn = () => {
150
- if (inverseJoinColumn) {
151
- Object.assign(payload, {
152
- [inverseJoinColumn.name]: right.ref,
153
- });
154
- }
155
- };
156
- const assignOrderColumns = () => {
157
- if (orderColumnName) {
158
- Object.assign(payload, { [orderColumnName]: left.pos ?? null });
159
- }
160
- if (inverseOrderColumnName) {
161
- Object.assign(payload, { [inverseOrderColumnName]: right.pos ?? null });
162
- }
163
- };
164
- const assignMorphColumns = () => {
165
- const { idColumn, typeColumn } = morphColumn ?? {};
166
- if (idColumn) {
167
- Object.assign(payload, { [idColumn.name]: right.ref });
168
- }
169
- if (typeColumn) {
170
- Object.assign(payload, { [typeColumn.name]: right.type });
171
- }
172
- Object.assign(payload, { order: right.pos ?? null, field: right.field ?? null });
173
- };
174
- if (kind === 'relation.basic' || kind === 'relation.circular') {
175
- assignInverseColumn();
176
- }
177
- if (kind === 'relation.morph') {
178
- assignMorphColumns();
179
- }
180
- assignOrderColumns();
181
- const qb = connection.insert(payload).into(name);
182
- if (trx) {
183
- qb.transacting(trx);
184
- }
185
- await qb;
186
- }
187
- };
188
- return { generateAll, generateAllForAttribute, insert };
189
- };
190
- return query;
191
- };
192
- exports.createLinkQuery = createLinkQuery;
193
- const filterValidRelationalAttributes = (attributes) => {
194
- const isOwner = (attribute) => {
195
- return attribute.owner || (!attribute.mappedBy && !attribute.morphBy);
196
- };
197
- const isComponentLike = (attribute) => {
198
- return attribute.component || attribute.components;
199
- };
200
- return Object.entries(attributes)
201
- .filter(([, attribute]) => {
202
- return attribute.type === 'relation' && isOwner(attribute) && !isComponentLike(attribute);
203
- })
204
- .reduce((acc, [key, attribute]) => ({ ...acc, [key]: attribute }), {});
205
- };
206
- const getLinkKind = (attribute, uid) => {
207
- if (attribute.relation.startsWith('morph')) {
208
- return 'relation.morph';
209
- }
210
- if (attribute.target === uid) {
211
- return 'relation.circular';
212
- }
213
- return 'relation.basic';
214
- };
215
- //# sourceMappingURL=link.js.map
@@ -1,2 +0,0 @@
1
- export declare const TRANSFER_PATH: "/transfer/runner/connect";
2
- export declare const TRANSFER_METHODS: readonly ["push", "pull"];
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TRANSFER_METHODS = exports.TRANSFER_PATH = void 0;
4
- exports.TRANSFER_PATH = '/transfer/runner/connect';
5
- exports.TRANSFER_METHODS = ['push', 'pull'];
6
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- export * from './push';
@@ -1,18 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./push"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1,26 +0,0 @@
1
- /// <reference types="node" />
2
- import { Writable } from 'stream-chain';
3
- import type { IMetadata } from '../../../../types';
4
- import type { TransferPushMessage, TransferPushStep } from '../../../../types/remote/protocol/client';
5
- import { ILocalStrapiDestinationProviderOptions } from '../../providers';
6
- export interface IPushController {
7
- streams: {
8
- [stage in TransferPushStep]?: Writable;
9
- };
10
- actions: {
11
- getMetadata(): Promise<IMetadata>;
12
- getSchemas(): Strapi.Schemas;
13
- bootstrap(): Promise<void>;
14
- close(): Promise<void>;
15
- beforeTransfer(): Promise<void>;
16
- rollback(): Promise<void>;
17
- };
18
- transfer: {
19
- [key in TransferPushStep]: <T extends TransferPushMessage>(value: T extends {
20
- step: key;
21
- data: infer U;
22
- } ? U : never) => Promise<void>;
23
- };
24
- }
25
- declare const createPushController: (options: ILocalStrapiDestinationProviderOptions) => IPushController;
26
- export default createPushController;
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const stream_chain_1 = require("stream-chain");
4
- const providers_1 = require("../../providers");
5
- const createPushController = (options) => {
6
- const provider = (0, providers_1.createLocalStrapiDestinationProvider)(options);
7
- const streams = {};
8
- const assets = {};
9
- const writeAsync = (stream, data) => {
10
- return new Promise((resolve, reject) => {
11
- stream.write(data, (error) => {
12
- if (error) {
13
- reject(error);
14
- }
15
- resolve();
16
- });
17
- });
18
- };
19
- return {
20
- streams,
21
- actions: {
22
- async getSchemas() {
23
- return provider.getSchemas();
24
- },
25
- async getMetadata() {
26
- return provider.getMetadata();
27
- },
28
- async bootstrap() {
29
- return provider.bootstrap();
30
- },
31
- async close() {
32
- return provider.close();
33
- },
34
- async beforeTransfer() {
35
- return provider.beforeTransfer();
36
- },
37
- async rollback() {
38
- await provider.rollback();
39
- },
40
- },
41
- transfer: {
42
- async entities(entities) {
43
- if (!streams.entities) {
44
- streams.entities = provider.createEntitiesWriteStream();
45
- }
46
- for (const entity of entities) {
47
- if (streams.entities) {
48
- await writeAsync(streams.entities, entity);
49
- }
50
- }
51
- },
52
- async links(links) {
53
- if (!streams.links) {
54
- streams.links = await provider.createLinksWriteStream();
55
- }
56
- for (const link of links) {
57
- if (streams.links) {
58
- await writeAsync(streams.links, link);
59
- }
60
- }
61
- },
62
- async configuration(configs) {
63
- if (!streams.configuration) {
64
- streams.configuration = await provider.createConfigurationWriteStream();
65
- }
66
- for (const config of configs) {
67
- if (streams.configuration) {
68
- await writeAsync(streams.configuration, config);
69
- }
70
- }
71
- },
72
- async assets(payloads) {
73
- if (payloads === null) {
74
- streams.assets?.end();
75
- return;
76
- }
77
- if (!streams.assets) {
78
- streams.assets = await provider.createAssetsWriteStream();
79
- }
80
- for (const payload of payloads) {
81
- if (streams.assets.closed) {
82
- return;
83
- }
84
- const { action, assetID } = payload;
85
- if (action === 'start' && streams.assets) {
86
- assets[assetID] = { ...payload.data, stream: new stream_chain_1.PassThrough() };
87
- writeAsync(streams.assets, assets[assetID]);
88
- }
89
- if (action === 'stream') {
90
- // The buffer has gone through JSON operations and is now of shape { type: "Buffer"; data: UInt8Array }
91
- // We need to transform it back into a Buffer instance
92
- const rawBuffer = payload.data;
93
- const chunk = Buffer.from(rawBuffer.data);
94
- await writeAsync(assets[assetID].stream, chunk);
95
- }
96
- if (action === 'end') {
97
- await new Promise((resolve, reject) => {
98
- const { stream } = assets[assetID];
99
- stream
100
- .on('close', () => {
101
- delete assets[assetID];
102
- resolve();
103
- })
104
- .on('error', (e) => {
105
- reject(e);
106
- })
107
- .end();
108
- });
109
- }
110
- }
111
- },
112
- },
113
- };
114
- };
115
- exports.default = createPushController;
116
- //# sourceMappingURL=push.js.map
@@ -1,3 +0,0 @@
1
- import type { Step } from '.';
2
- declare const _default: readonly Step[];
3
- export default _default;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [
4
- {
5
- kind: 'action',
6
- action: 'bootstrap',
7
- },
8
- {
9
- kind: 'action',
10
- action: 'init',
11
- },
12
- {
13
- kind: 'action',
14
- action: 'beforeTransfer',
15
- },
16
- {
17
- kind: 'transfer',
18
- stage: 'schemas',
19
- },
20
- {
21
- kind: 'transfer',
22
- stage: 'entities',
23
- },
24
- {
25
- kind: 'transfer',
26
- stage: 'assets',
27
- },
28
- {
29
- kind: 'transfer',
30
- stage: 'links',
31
- },
32
- {
33
- kind: 'transfer',
34
- stage: 'configuration',
35
- },
36
- {
37
- kind: 'action',
38
- action: 'close',
39
- },
40
- ];
41
- //# sourceMappingURL=default.js.map
@@ -1,18 +0,0 @@
1
- import type { TransferStage } from '../../../../types';
2
- export declare 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 declare const createFlow: (flow: readonly Step[]) => {
12
- has(step: Step): boolean;
13
- can(step: Step): boolean;
14
- cannot(step: Step): boolean;
15
- set(step: Step): any;
16
- get(): Step | null;
17
- };
18
- export declare type TransferFlow = ReturnType<typeof createFlow>;
@@ -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,10 +0,0 @@
1
- import type { Context } from 'koa';
2
- import type { ServerOptions } from 'ws';
3
- import { TRANSFER_METHODS } from './constants';
4
- declare type TransferMethod = (typeof TRANSFER_METHODS)[number];
5
- interface IHandlerOptions {
6
- verify: (ctx: Context, scope?: TransferMethod) => Promise<void>;
7
- server?: ServerOptions;
8
- }
9
- export declare const createTransferHandler: (options: IHandlerOptions) => (ctx: Context) => Promise<void>;
10
- export {};