@strapi/data-transfer 4.6.0-beta.1 → 4.6.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 (113) hide show
  1. package/lib/engine/diagnostic.d.ts +40 -0
  2. package/lib/engine/diagnostic.js +50 -0
  3. package/lib/engine/errors.d.ts +28 -0
  4. package/lib/engine/errors.js +29 -0
  5. package/{dist → lib}/engine/index.d.ts +18 -4
  6. package/{dist → lib}/engine/index.js +211 -45
  7. package/lib/engine/validation/index.d.ts +2 -0
  8. package/{dist → lib/engine/validation}/index.js +2 -2
  9. package/lib/engine/validation/provider.d.ts +3 -0
  10. package/lib/engine/validation/provider.js +18 -0
  11. package/{dist/strategies → lib/engine/validation/schemas}/index.d.ts +2 -2
  12. package/{dist/strategies → lib/engine/validation/schemas}/index.js +3 -2
  13. package/lib/errors/base.d.ts +8 -0
  14. package/lib/errors/base.js +13 -0
  15. package/lib/errors/constants.d.ts +3 -0
  16. package/lib/errors/constants.js +9 -0
  17. package/lib/errors/index.d.ts +2 -0
  18. package/{dist/providers → lib/errors}/index.js +2 -6
  19. package/lib/errors/providers.d.ts +21 -0
  20. package/lib/errors/providers.js +32 -0
  21. package/lib/file/index.d.ts +1 -0
  22. package/{dist/providers/shared → lib/file}/index.js +2 -2
  23. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/index.d.ts +6 -6
  24. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/index.js +7 -7
  25. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/utils.d.ts +0 -0
  26. package/{dist/providers/local-file-destination-provider → lib/file/providers/destination}/utils.js +0 -0
  27. package/lib/file/providers/index.d.ts +2 -0
  28. package/lib/file/providers/index.js +19 -0
  29. package/{dist/providers/local-file-source-provider → lib/file/providers/source}/index.d.ts +9 -8
  30. package/{dist/providers/local-file-source-provider → lib/file/providers/source}/index.js +42 -56
  31. package/lib/index.d.ts +4 -0
  32. package/lib/index.js +31 -0
  33. package/lib/strapi/index.d.ts +4 -0
  34. package/lib/strapi/index.js +35 -0
  35. package/lib/strapi/providers/index.d.ts +3 -0
  36. package/lib/strapi/providers/index.js +22 -0
  37. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/index.d.ts +10 -7
  38. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/index.js +65 -37
  39. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/index.d.ts +0 -0
  40. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/index.js +0 -0
  41. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/configuration.d.ts +2 -2
  42. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/configuration.js +17 -10
  43. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/entities.d.ts +2 -0
  44. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +103 -0
  45. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/index.d.ts +0 -0
  46. package/{dist/providers/local-strapi-destination-provider → lib/strapi/providers/local-destination}/strategies/restore/index.js +4 -3
  47. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +4 -0
  48. package/lib/strapi/providers/local-destination/strategies/restore/links.js +32 -0
  49. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/assets.d.ts +0 -0
  50. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/assets.js +0 -0
  51. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.d.ts +0 -0
  52. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.js +12 -13
  53. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/entities.d.ts +0 -0
  54. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/entities.js +11 -4
  55. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.d.ts +6 -6
  56. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.js +12 -27
  57. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/links.d.ts +0 -0
  58. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/links.js +1 -1
  59. package/lib/strapi/providers/remote-destination/index.d.ts +40 -0
  60. package/lib/strapi/providers/remote-destination/index.js +186 -0
  61. package/lib/strapi/providers/remote-destination/utils.d.ts +31 -0
  62. package/lib/strapi/providers/remote-destination/utils.js +72 -0
  63. package/{dist/providers/shared/strapi → lib/strapi/queries}/entity.d.ts +0 -0
  64. package/{dist/providers/shared/strapi → lib/strapi/queries}/entity.js +0 -0
  65. package/{dist/providers/shared/strapi → lib/strapi/queries}/index.d.ts +0 -0
  66. package/{dist/providers/shared/strapi → lib/strapi/queries}/index.js +0 -0
  67. package/{dist/providers/shared/strapi → lib/strapi/queries}/link.d.ts +2 -2
  68. package/{dist/providers/shared/strapi → lib/strapi/queries}/link.js +17 -3
  69. package/lib/strapi/register.d.ts +7 -0
  70. package/lib/strapi/register.js +13 -0
  71. package/lib/strapi/remote/constants.d.ts +2 -0
  72. package/lib/strapi/remote/constants.js +6 -0
  73. package/lib/strapi/remote/controllers/index.d.ts +1 -0
  74. package/lib/strapi/remote/controllers/index.js +18 -0
  75. package/lib/strapi/remote/controllers/push.d.ts +25 -0
  76. package/lib/strapi/remote/controllers/push.js +95 -0
  77. package/lib/strapi/remote/handlers.d.ts +3 -0
  78. package/lib/strapi/remote/handlers.js +193 -0
  79. package/lib/strapi/remote/index.d.ts +3 -0
  80. package/lib/strapi/remote/index.js +30 -0
  81. package/lib/strapi/remote/routes.d.ts +21 -0
  82. package/lib/strapi/remote/routes.js +22 -0
  83. package/lib/utils/encryption/decrypt.d.ts +11 -0
  84. package/{dist → lib/utils}/encryption/decrypt.js +8 -0
  85. package/lib/utils/encryption/encrypt.d.ts +11 -0
  86. package/{dist → lib/utils}/encryption/encrypt.js +8 -0
  87. package/{dist → lib/utils}/encryption/index.d.ts +0 -0
  88. package/{dist → lib/utils}/encryption/index.js +0 -0
  89. package/{dist → lib}/utils/index.d.ts +2 -0
  90. package/{dist → lib}/utils/index.js +3 -1
  91. package/{dist → lib}/utils/json.d.ts +7 -0
  92. package/{dist → lib}/utils/json.js +8 -1
  93. package/lib/utils/providers.d.ts +2 -0
  94. package/lib/utils/providers.js +11 -0
  95. package/{dist → lib}/utils/schema.d.ts +4 -0
  96. package/{dist → lib}/utils/schema.js +9 -2
  97. package/lib/utils/stream.d.ts +27 -0
  98. package/lib/utils/stream.js +59 -0
  99. package/lib/utils/transaction.d.ts +3 -0
  100. package/lib/utils/transaction.js +70 -0
  101. package/package.json +20 -12
  102. package/dist/encryption/decrypt.d.ts +0 -3
  103. package/dist/encryption/encrypt.d.ts +0 -3
  104. package/dist/index.d.ts +0 -2
  105. package/dist/providers/index.d.ts +0 -4
  106. package/dist/providers/local-strapi-destination-provider/strategies/restore/entities.js +0 -88
  107. package/dist/providers/local-strapi-destination-provider/strategies/restore/links.d.ts +0 -3
  108. package/dist/providers/local-strapi-destination-provider/strategies/restore/links.js +0 -29
  109. package/dist/providers/shared/index.d.ts +0 -1
  110. package/dist/providers/test-utils/index.d.ts +0 -111
  111. package/dist/providers/test-utils/index.js +0 -64
  112. package/dist/utils/stream.d.ts +0 -10
  113. package/dist/utils/stream.js +0 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/data-transfer",
3
- "version": "4.6.0-beta.1",
3
+ "version": "4.6.0",
4
4
  "description": "Data transfer capabilities for Strapi",
5
5
  "keywords": [
6
6
  "strapi",
@@ -24,21 +24,23 @@
24
24
  "url": "https://strapi.io"
25
25
  }
26
26
  ],
27
- "main": "./dist/index.js",
28
- "types": "./dist/index.d.ts",
27
+ "main": "./lib/index.js",
28
+ "types": "./lib/index.d.ts",
29
29
  "scripts": {
30
- "build": "tsc -p tsconfig.json",
31
- "clean": "rimraf ./dist",
30
+ "build": "yarn build:ts",
31
+ "build:ts": "tsc -p tsconfig.json",
32
32
  "build:clean": "yarn clean && yarn build",
33
- "watch": "yarn build -w",
34
- "test:unit": "jest --verbose"
33
+ "clean": "rimraf ./lib",
34
+ "prepublishOnly": "yarn build:clean",
35
+ "test:unit": "jest --verbose",
36
+ "watch": "yarn build:ts -w --preserveWatchOutput"
35
37
  },
36
38
  "directories": {
37
- "lib": "./dist"
39
+ "lib": "./lib"
38
40
  },
39
41
  "dependencies": {
40
- "@strapi/logger": "4.6.0-beta.1",
41
- "@strapi/strapi": "4.6.0-beta.1",
42
+ "@strapi/logger": "4.6.0",
43
+ "@strapi/strapi": "4.6.0",
42
44
  "chalk": "4.1.2",
43
45
  "fs-extra": "10.0.0",
44
46
  "lodash": "4.17.21",
@@ -47,17 +49,23 @@
47
49
  "stream-chain": "2.2.5",
48
50
  "stream-json": "1.7.4",
49
51
  "tar": "6.1.12",
50
- "tar-stream": "2.2.0"
52
+ "tar-stream": "2.2.0",
53
+ "uuid": "9.0.0",
54
+ "ws": "8.11.0"
51
55
  },
52
56
  "devDependencies": {
53
57
  "@tsconfig/node16": "1.0.3",
54
58
  "@types/fs-extra": "9.0.13",
55
59
  "@types/jest": "29.2.0",
60
+ "@types/koa": "2.13.4",
56
61
  "@types/semver": "7.3.13",
57
62
  "@types/stream-chain": "2.0.1",
58
63
  "@types/stream-json": "1.7.2",
59
64
  "@types/tar": "6.1.3",
60
65
  "@types/tar-stream": "2.2.2",
66
+ "@types/uuid": "9.0.0",
67
+ "knex": "2.4.0",
68
+ "koa": "2.13.4",
61
69
  "rimraf": "3.0.2",
62
70
  "typescript": "4.6.2"
63
71
  },
@@ -65,5 +73,5 @@
65
73
  "node": ">=14.19.1 <=18.x.x",
66
74
  "npm": ">=6.0.0"
67
75
  },
68
- "gitHead": "2c0bcabdf0bf2a269fed50c6f23ba777845968a0"
76
+ "gitHead": "a9e55435c489f3379d88565bf3f729deb29bfb45"
69
77
  }
@@ -1,3 +0,0 @@
1
- import { Cipher } from 'crypto';
2
- import { Algorithm } from '../../types';
3
- export declare const createDecryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
@@ -1,3 +0,0 @@
1
- import { Cipher } from 'crypto';
2
- import { Algorithm } from '../../types';
3
- export declare const createEncryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './engine';
2
- export * from './providers';
@@ -1,4 +0,0 @@
1
- export * from './local-file-source-provider';
2
- export * from './local-strapi-source-provider';
3
- export * from './local-file-destination-provider';
4
- export * from './local-strapi-destination-provider';
@@ -1,88 +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.createEntitiesWriteStream = void 0;
27
- const fp_1 = require("lodash/fp");
28
- const stream_1 = require("stream");
29
- const utils_1 = require("../../../../utils");
30
- const shared = __importStar(require("../../../shared"));
31
- const createEntitiesWriteStream = (options) => {
32
- const { strapi, updateMappingTable } = options;
33
- const query = shared.strapi.entity.createEntityQuery(strapi);
34
- return new stream_1.Writable({
35
- objectMode: true,
36
- async write(entity, _encoding, callback) {
37
- const { type, id, data } = entity;
38
- const { create, getDeepPopulateComponentLikeQuery } = query(type);
39
- const contentType = strapi.getModel(type);
40
- const resolveType = (paths) => {
41
- let type = contentType;
42
- let value = data;
43
- for (const path of paths) {
44
- value = (0, fp_1.get)(path, value);
45
- if (typeof type === 'function') {
46
- type = type(value);
47
- }
48
- if (path in type.attributes) {
49
- const attribute = type.attributes[path];
50
- if (attribute.type === 'component') {
51
- type = strapi.getModel(attribute.component);
52
- }
53
- if (attribute.type === 'dynamiczone') {
54
- type = ({ __component }) => strapi.getModel(__component);
55
- }
56
- }
57
- }
58
- return type.uid;
59
- };
60
- try {
61
- // Create the entity
62
- const created = await create({
63
- data,
64
- populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),
65
- select: 'id',
66
- });
67
- const diffs = utils_1.json.diff(data, created);
68
- updateMappingTable(type, id, created.id);
69
- diffs.forEach((diff) => {
70
- if (diff.kind === 'modified' && diff.path.at(-1) === 'id') {
71
- const target = resolveType(diff.path);
72
- const [oldID, newID] = diff.values;
73
- updateMappingTable(target, oldID, newID);
74
- }
75
- });
76
- }
77
- catch (e) {
78
- if (e instanceof Error) {
79
- return callback(e);
80
- }
81
- return callback(new Error(`Failed to create "${type}" (${id})`));
82
- }
83
- return callback(null);
84
- },
85
- });
86
- };
87
- exports.createEntitiesWriteStream = createEntitiesWriteStream;
88
- //# sourceMappingURL=entities.js.map
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { Writable } from 'stream';
3
- export declare const createLinksWriteStream: (mapID: (uid: string, id: number) => number | undefined, strapi: Strapi.Strapi) => Writable;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLinksWriteStream = void 0;
4
- const stream_1 = require("stream");
5
- const link_1 = require("../../../shared/strapi/link");
6
- const createLinksWriteStream = (mapID, strapi) => {
7
- return new stream_1.Writable({
8
- objectMode: true,
9
- async write(link, _encoding, callback) {
10
- const { left, right } = link;
11
- const query = (0, link_1.createLinkQuery)(strapi);
12
- // Map IDs if needed
13
- left.ref = mapID(left.type, left.ref) ?? left.ref;
14
- right.ref = mapID(right.type, right.ref) ?? right.ref;
15
- try {
16
- await query().insert(link);
17
- }
18
- catch (e) {
19
- if (e instanceof Error) {
20
- return callback(e);
21
- }
22
- return callback(new Error(`An error happened while trying to import a ${left.type} link. ${e}`));
23
- }
24
- callback(null);
25
- },
26
- });
27
- };
28
- exports.createLinksWriteStream = createLinksWriteStream;
29
- //# sourceMappingURL=links.js.map
@@ -1 +0,0 @@
1
- export * as strapi from './strapi';
@@ -1,111 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="jest" />
3
- import { Readable } from 'stream';
4
- /**
5
- * Collect every entity in a Readable stream
6
- */
7
- export declare const collect: <T = unknown>(stream: Readable) => Promise<T[]>;
8
- /**
9
- * Create a "Strapi" like object factory based on the
10
- * given params and cast it to the correct type
11
- */
12
- export declare const getStrapiFactory: <T extends {
13
- readonly EE?: unknown;
14
- readonly config?: unknown;
15
- readonly auth?: unknown;
16
- readonly contentAPI?: unknown;
17
- readonly sanitizers?: unknown;
18
- readonly services?: unknown;
19
- service?: unknown;
20
- readonly controllers?: unknown;
21
- controller?: unknown;
22
- readonly contentTypes?: unknown;
23
- contentType?: unknown;
24
- readonly components?: unknown;
25
- readonly customFields?: unknown;
26
- readonly policies?: unknown;
27
- policy?: unknown;
28
- readonly middlewares?: unknown;
29
- middleware?: unknown;
30
- readonly plugins?: unknown;
31
- plugin?: unknown;
32
- readonly hooks?: unknown;
33
- hook?: unknown;
34
- readonly api?: unknown;
35
- register?: unknown;
36
- bootstrap?: unknown;
37
- destroy?: unknown;
38
- runLifecyclesFunctions?: unknown;
39
- start?: unknown;
40
- stopWithError?: unknown;
41
- stop?: unknown;
42
- load?: unknown;
43
- reload?: unknown;
44
- startWebhooks?: unknown;
45
- postListen?: unknown;
46
- listen?: unknown;
47
- openAdmin?: unknown;
48
- loadAdmin?: unknown;
49
- loadPlugins?: unknown;
50
- loadPolicies?: unknown;
51
- loadAPIs?: unknown;
52
- loadComponents?: unknown;
53
- loadMiddlewares?: unknown;
54
- loadApp?: unknown;
55
- registerInternalHooks?: unknown;
56
- getModel?: unknown;
57
- query?: unknown;
58
- container?: unknown;
59
- dirs?: unknown;
60
- isLoaded?: unknown;
61
- server?: unknown;
62
- fs?: unknown;
63
- eventHub?: unknown;
64
- startupLogger?: unknown;
65
- log?: unknown;
66
- cron?: unknown;
67
- telemetry?: unknown;
68
- db?: unknown;
69
- store?: unknown;
70
- entityValidator?: unknown;
71
- entityService?: unknown;
72
- }>(properties?: T | undefined) => () => import("@strapi/strapi").Strapi;
73
- /**
74
- * Union type used to represent the default content types available
75
- */
76
- export declare type ContentType = 'foo' | 'bar';
77
- /**
78
- * Factory to get default content types test values
79
- */
80
- export declare const getContentTypes: () => {
81
- foo: {
82
- uid: "foo";
83
- attributes: {
84
- [attribute: string]: unknown;
85
- };
86
- };
87
- bar: {
88
- uid: "bar";
89
- attributes: {
90
- [attribute: string]: unknown;
91
- };
92
- };
93
- };
94
- /**
95
- * Create a factory of readable streams (wrapped with a jest mock function)
96
- */
97
- export declare const createMockedReadableFactory: <T extends string = ContentType>(source: { [ct in T]: {
98
- [key: string]: unknown;
99
- id: number;
100
- }[]; }) => jest.Mock<Readable, [uid: T]>;
101
- /**
102
- * Create a factory of mocked query builders
103
- */
104
- export declare const createMockedQueryBuilder: <T extends string = ContentType>(data: { [key in T]: unknown[]; }) => jest.Mock<{
105
- populate(populate: unknown): any;
106
- stream(): Readable;
107
- }, [uid: T]>;
108
- /**
109
- * Update the global store with the given strapi value
110
- */
111
- export declare const setGlobalStrapi: (strapi: Strapi.Strapi) => void;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setGlobalStrapi = exports.createMockedQueryBuilder = exports.createMockedReadableFactory = exports.getContentTypes = exports.getStrapiFactory = exports.collect = void 0;
4
- const stream_1 = require("stream");
5
- /**
6
- * Collect every entity in a Readable stream
7
- */
8
- const collect = (stream) => {
9
- const chunks = [];
10
- return new Promise((resolve, reject) => {
11
- stream
12
- .on('data', (chunk) => chunks.push(chunk))
13
- .on('close', () => resolve(chunks))
14
- .on('error', reject);
15
- });
16
- };
17
- exports.collect = collect;
18
- /**
19
- * Create a "Strapi" like object factory based on the
20
- * given params and cast it to the correct type
21
- */
22
- const getStrapiFactory = (properties) => () => {
23
- return { ...properties };
24
- };
25
- exports.getStrapiFactory = getStrapiFactory;
26
- /**
27
- * Factory to get default content types test values
28
- */
29
- const getContentTypes = () => ({
30
- foo: { uid: 'foo', attributes: { title: { type: 'string' } } },
31
- bar: { uid: 'bar', attributes: { age: { type: 'number' } } },
32
- });
33
- exports.getContentTypes = getContentTypes;
34
- /**
35
- * Create a factory of readable streams (wrapped with a jest mock function)
36
- */
37
- const createMockedReadableFactory = (source) => jest.fn((uid) => {
38
- return stream_1.Readable.from(source[uid] || []);
39
- });
40
- exports.createMockedReadableFactory = createMockedReadableFactory;
41
- /**
42
- * Create a factory of mocked query builders
43
- */
44
- const createMockedQueryBuilder = (data) => jest.fn((uid) => {
45
- const state = { populate: undefined };
46
- return {
47
- populate(populate) {
48
- state.populate = populate;
49
- return this;
50
- },
51
- stream() {
52
- return stream_1.Readable.from(data[uid]);
53
- },
54
- };
55
- });
56
- exports.createMockedQueryBuilder = createMockedQueryBuilder;
57
- /**
58
- * Update the global store with the given strapi value
59
- */
60
- const setGlobalStrapi = (strapi) => {
61
- global.strapi = strapi;
62
- };
63
- exports.setGlobalStrapi = setGlobalStrapi;
64
- //# sourceMappingURL=index.js.map
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- import { Transform, Readable } from 'stream';
3
- declare type TransformOptions = ConstructorParameters<typeof Transform>[0];
4
- export declare const filter: <T>(predicate: (value: T) => boolean | Promise<boolean>, options?: TransformOptions) => Transform;
5
- export declare const map: <T>(predicate: (value: T) => T | Promise<T>, options?: TransformOptions) => Transform;
6
- /**
7
- * Collect every entity in a Readable stream
8
- */
9
- export declare const collect: <T = unknown>(stream: Readable) => Promise<T[]>;
10
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collect = exports.map = exports.filter = void 0;
4
- const stream_1 = require("stream");
5
- const filter = (predicate, options = { objectMode: true }) => {
6
- return new stream_1.Transform({
7
- ...options,
8
- async transform(chunk, _encoding, callback) {
9
- const keep = await predicate(chunk);
10
- callback(null, keep ? chunk : undefined);
11
- },
12
- });
13
- };
14
- exports.filter = filter;
15
- const map = (predicate, options = { objectMode: true }) => {
16
- return new stream_1.Transform({
17
- ...options,
18
- async transform(chunk, _encoding, callback) {
19
- const mappedValue = await predicate(chunk);
20
- callback(null, mappedValue);
21
- },
22
- });
23
- };
24
- exports.map = map;
25
- /**
26
- * Collect every entity in a Readable stream
27
- */
28
- const collect = (stream) => {
29
- const chunks = [];
30
- return new Promise((resolve) => {
31
- stream.on('data', (chunk) => chunks.push(chunk));
32
- stream.on('end', () => {
33
- stream.destroy();
34
- resolve(chunks);
35
- });
36
- });
37
- };
38
- exports.collect = collect;
39
- //# sourceMappingURL=stream.js.map