@usebruno/filestore 0.5.0 → 0.7.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.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/workers/worker-script.js +1 -1
- package/dist/cjs/workers/worker-script.js.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/workers/worker-script.js +1 -1
- package/dist/esm/workers/worker-script.js.map +1 -1
- package/dist/formats/bru/index.d.ts +20 -0
- package/dist/formats/bru/index.d.ts.map +1 -0
- package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts +57 -0
- package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts.map +1 -0
- package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts +2 -0
- package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts.map +1 -0
- package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts +2 -0
- package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts.map +1 -0
- package/dist/{cjs/workers/formats → formats}/bru/utils/oauth2-additional-params.d.ts +1 -0
- package/dist/formats/bru/utils/oauth2-additional-params.d.ts.map +1 -0
- package/dist/{esm/formats → formats}/bru/utils/request-parse-and-redact-body-data.d.ts +1 -0
- package/dist/formats/bru/utils/request-parse-and-redact-body-data.d.ts.map +1 -0
- package/dist/formats/yml/common/actions.d.ts +14 -0
- package/dist/formats/yml/common/actions.d.ts.map +1 -0
- package/dist/formats/yml/common/assertions.d.ts +5 -0
- package/dist/formats/yml/common/assertions.d.ts.map +1 -0
- package/dist/formats/yml/common/auth-oauth2.d.ts +5 -0
- package/dist/formats/yml/common/auth-oauth2.d.ts.map +1 -0
- package/dist/formats/yml/common/auth.d.ts +5 -0
- package/dist/formats/yml/common/auth.d.ts.map +1 -0
- package/dist/formats/yml/common/body.d.ts +5 -0
- package/dist/formats/yml/common/body.d.ts.map +1 -0
- package/dist/formats/yml/common/headers.d.ts +7 -0
- package/dist/formats/yml/common/headers.d.ts.map +1 -0
- package/dist/formats/yml/common/params.d.ts +5 -0
- package/dist/formats/yml/common/params.d.ts.map +1 -0
- package/dist/formats/yml/common/scripts.d.ts +14 -0
- package/dist/formats/yml/common/scripts.d.ts.map +1 -0
- package/dist/formats/yml/common/variables.d.ts +17 -0
- package/dist/formats/yml/common/variables.d.ts.map +1 -0
- package/dist/formats/yml/index.d.ts +10 -0
- package/dist/formats/yml/index.d.ts.map +1 -0
- package/dist/formats/yml/items/parseGraphQLRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseGraphQLRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/parseGrpcRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseGrpcRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/parseHttpRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseHttpRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/parseScript.d.ts +5 -0
- package/dist/formats/yml/items/parseScript.d.ts.map +1 -0
- package/dist/formats/yml/items/parseWebsocketRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseWebsocketRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyGrpcRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyGrpcRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyHttpRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyHttpRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyScript.d.ts +4 -0
- package/dist/formats/yml/items/stringifyScript.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts.map +1 -0
- package/dist/formats/yml/parseCollection.d.ts +8 -0
- package/dist/formats/yml/parseCollection.d.ts.map +1 -0
- package/dist/formats/yml/parseEnvironment.d.ts +4 -0
- package/dist/formats/yml/parseEnvironment.d.ts.map +1 -0
- package/dist/formats/yml/parseFolder.d.ts +4 -0
- package/dist/formats/yml/parseFolder.d.ts.map +1 -0
- package/dist/formats/yml/parseItem.d.ts +4 -0
- package/dist/formats/yml/parseItem.d.ts.map +1 -0
- package/dist/formats/yml/stringifyCollection.d.ts +3 -0
- package/dist/formats/yml/stringifyCollection.d.ts.map +1 -0
- package/dist/formats/yml/stringifyEnvironment.d.ts +4 -0
- package/dist/formats/yml/stringifyEnvironment.d.ts.map +1 -0
- package/dist/formats/yml/stringifyFolder.d.ts +4 -0
- package/dist/formats/yml/stringifyFolder.d.ts.map +1 -0
- package/dist/formats/yml/stringifyItem.d.ts +4 -0
- package/dist/formats/yml/stringifyItem.d.ts.map +1 -0
- package/dist/formats/yml/utils.d.ts +3 -0
- package/dist/formats/yml/utils.d.ts.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/{esm/workers → workers}/WorkerQueue/index.d.ts +1 -0
- package/dist/workers/WorkerQueue/index.d.ts.map +1 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/worker-script.d.ts +2 -0
- package/dist/workers/worker-script.d.ts.map +1 -0
- package/package.json +12 -6
- package/src/constants.ts +3 -0
- package/src/formats/bru/index.ts +9 -9
- package/src/formats/bru/tests/oauth2-additional-params.spec.js +1 -1
- package/src/formats/bru/utils/oauth2-additional-params.ts +17 -18
- package/src/formats/bru/utils/request-parse-and-redact-body-data.ts +13 -13
- package/src/formats/yml/common/actions.ts +78 -0
- package/src/formats/yml/common/assertions.ts +146 -0
- package/src/formats/yml/common/auth-oauth2.ts +555 -0
- package/src/formats/yml/common/auth.ts +245 -0
- package/src/formats/yml/common/body.ts +238 -0
- package/src/formats/yml/common/headers.ts +58 -0
- package/src/formats/yml/common/params.ts +57 -0
- package/src/formats/yml/common/scripts.ts +64 -0
- package/src/formats/yml/common/variables.ts +68 -0
- package/src/formats/yml/index.ts +20 -0
- package/src/formats/yml/items/parseGraphQLRequest.ts +137 -0
- package/src/formats/yml/items/parseGrpcRequest.ts +116 -0
- package/src/formats/yml/items/parseHttpRequest.ts +195 -0
- package/src/formats/yml/items/parseScript.ts +25 -0
- package/src/formats/yml/items/parseWebsocketRequest.ts +107 -0
- package/src/formats/yml/items/stringifyGraphQLRequest.ts +168 -0
- package/src/formats/yml/items/stringifyGrpcRequest.ts +137 -0
- package/src/formats/yml/items/stringifyHttpRequest.ts +222 -0
- package/src/formats/yml/items/stringifyScript.ts +22 -0
- package/src/formats/yml/items/stringifyWebsocketRequest.ts +114 -0
- package/src/formats/yml/parseCollection.ts +220 -0
- package/src/formats/yml/parseEnvironment.ts +57 -0
- package/src/formats/yml/parseFolder.ts +93 -0
- package/src/formats/yml/parseItem.ts +102 -0
- package/src/formats/yml/stringifyCollection.ts +264 -0
- package/src/formats/yml/stringifyEnvironment.ts +67 -0
- package/src/formats/yml/stringifyFolder.ts +107 -0
- package/src/formats/yml/stringifyItem.ts +37 -0
- package/src/formats/yml/utils.ts +38 -0
- package/src/index.ts +64 -32
- package/src/types/bruno-lang.d.ts +1 -1
- package/src/types.ts +5 -124
- package/src/utils/index.ts +25 -0
- package/src/workers/WorkerQueue/index.ts +10 -10
- package/src/workers/index.ts +21 -20
- package/src/workers/worker-script.ts +21 -6
- package/dist/cjs/formats/bru/index.d.ts +0 -19
- package/dist/cjs/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- package/dist/cjs/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/cjs/index.d.ts +0 -16
- package/dist/cjs/types.d.ts +0 -142
- package/dist/cjs/workers/WorkerQueue/index.d.ts +0 -26
- package/dist/cjs/workers/formats/bru/index.d.ts +0 -19
- package/dist/cjs/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/cjs/workers/index.d.ts +0 -16
- package/dist/cjs/workers/types.d.ts +0 -142
- package/dist/cjs/workers/worker-script.d.ts +0 -1
- package/dist/cjs/workers/workers/WorkerQueue/index.d.ts +0 -26
- package/dist/cjs/workers/workers/index.d.ts +0 -10
- package/dist/cjs/workers/workers/worker-script.d.ts +0 -1
- package/dist/esm/formats/bru/index.d.ts +0 -19
- package/dist/esm/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- package/dist/esm/index.d.ts +0 -16
- package/dist/esm/types.d.ts +0 -142
- package/dist/esm/workers/formats/bru/index.d.ts +0 -19
- package/dist/esm/workers/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- package/dist/esm/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/esm/workers/index.d.ts +0 -16
- package/dist/esm/workers/types.d.ts +0 -142
- package/dist/esm/workers/worker-script.d.ts +0 -1
- package/dist/esm/workers/workers/WorkerQueue/index.d.ts +0 -26
- package/dist/esm/workers/workers/index.d.ts +0 -10
- package/dist/esm/workers/workers/worker-script.d.ts +0 -1
package/src/types.ts
CHANGED
|
@@ -1,130 +1,11 @@
|
|
|
1
|
+
export type CollectionFormat = 'bru' | 'yml';
|
|
2
|
+
|
|
1
3
|
export interface ParseOptions {
|
|
2
|
-
format?:
|
|
4
|
+
format?: CollectionFormat;
|
|
3
5
|
}
|
|
4
6
|
|
|
5
7
|
export interface StringifyOptions {
|
|
6
|
-
format?:
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface RequestBody {
|
|
10
|
-
mode?: string;
|
|
11
|
-
raw?: string;
|
|
12
|
-
formUrlEncoded?: Array<{ name: string; value: string; enabled: boolean }>;
|
|
13
|
-
multipartForm?: Array<{ name: string; value: string; type: string; enabled: boolean }>;
|
|
14
|
-
json?: string;
|
|
15
|
-
xml?: string;
|
|
16
|
-
sparql?: string;
|
|
17
|
-
graphql?: {
|
|
18
|
-
query?: string;
|
|
19
|
-
variables?: string;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface AuthConfig {
|
|
24
|
-
mode?: string;
|
|
25
|
-
basic?: {
|
|
26
|
-
username?: string;
|
|
27
|
-
password?: string;
|
|
28
|
-
};
|
|
29
|
-
bearer?: {
|
|
30
|
-
token?: string;
|
|
31
|
-
};
|
|
32
|
-
apikey?: {
|
|
33
|
-
key?: string;
|
|
34
|
-
value?: string;
|
|
35
|
-
placement?: string;
|
|
36
|
-
};
|
|
37
|
-
awsv4?: {
|
|
38
|
-
accessKeyId?: string;
|
|
39
|
-
secretAccessKey?: string;
|
|
40
|
-
sessionToken?: string;
|
|
41
|
-
service?: string;
|
|
42
|
-
region?: string;
|
|
43
|
-
profileName?: string;
|
|
44
|
-
};
|
|
45
|
-
oauth2?: {
|
|
46
|
-
grantType?: string;
|
|
47
|
-
callbackUrl?: string;
|
|
48
|
-
authorizationUrl?: string;
|
|
49
|
-
accessTokenUrl?: string;
|
|
50
|
-
clientId?: string;
|
|
51
|
-
clientSecret?: string;
|
|
52
|
-
scope?: string;
|
|
53
|
-
state?: string;
|
|
54
|
-
pkce?: boolean;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface RequestParam {
|
|
59
|
-
name: string;
|
|
60
|
-
value: string;
|
|
61
|
-
enabled: boolean;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface RequestHeader {
|
|
65
|
-
name: string;
|
|
66
|
-
value: string;
|
|
67
|
-
enabled: boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface RequestAssertion {
|
|
71
|
-
name: string;
|
|
72
|
-
value: string;
|
|
73
|
-
enabled: boolean;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface RequestVars {
|
|
77
|
-
req?: Array<{ name: string; value: string; enabled: boolean }>;
|
|
78
|
-
res?: Array<{ name: string; value: string; enabled: boolean }>;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface RequestScript {
|
|
82
|
-
req?: string;
|
|
83
|
-
res?: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface RequestSettings {
|
|
87
|
-
[key: string]: any;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface RequestData {
|
|
91
|
-
method: string;
|
|
92
|
-
url: string;
|
|
93
|
-
params: RequestParam[];
|
|
94
|
-
headers: RequestHeader[];
|
|
95
|
-
auth: AuthConfig;
|
|
96
|
-
body: RequestBody;
|
|
97
|
-
script: RequestScript;
|
|
98
|
-
vars: RequestVars;
|
|
99
|
-
assertions: RequestAssertion[];
|
|
100
|
-
tests: string;
|
|
101
|
-
docs: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface ParsedRequest {
|
|
105
|
-
type: 'http-request' | 'graphql-request';
|
|
106
|
-
name: string;
|
|
107
|
-
seq: number;
|
|
108
|
-
settings: RequestSettings;
|
|
109
|
-
tags: string[];
|
|
110
|
-
request: RequestData;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface ParsedCollection {
|
|
114
|
-
name: string;
|
|
115
|
-
type?: string;
|
|
116
|
-
version?: string;
|
|
117
|
-
[key: string]: any;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface EnvironmentVariable {
|
|
121
|
-
name: string;
|
|
122
|
-
value: string;
|
|
123
|
-
enabled: boolean;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface ParsedEnvironment {
|
|
127
|
-
variables: EnvironmentVariable[];
|
|
8
|
+
format?: CollectionFormat;
|
|
128
9
|
}
|
|
129
10
|
|
|
130
11
|
export interface WorkerTask {
|
|
@@ -138,4 +19,4 @@ export interface WorkerTask {
|
|
|
138
19
|
|
|
139
20
|
export interface Lane {
|
|
140
21
|
maxSize: number;
|
|
141
|
-
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { customAlphabet } = require('nanoid');
|
|
2
|
+
|
|
3
|
+
export const isString = (value: unknown): value is string => typeof value === 'string';
|
|
4
|
+
|
|
5
|
+
export const isNumber = (value: unknown): value is number => typeof value === 'number';
|
|
6
|
+
|
|
7
|
+
export const isNonEmptyString = (value: unknown): value is string => isString(value) && value.trim().length > 0;
|
|
8
|
+
|
|
9
|
+
export const ensureString = (value: unknown, fallback: string = ''): string => {
|
|
10
|
+
if (value === null || value === undefined) {
|
|
11
|
+
return fallback;
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
return String(value);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const uuid = () => {
|
|
20
|
+
// https://github.com/ai/nanoid/blob/main/url-alphabet/index.js
|
|
21
|
+
const urlAlphabet = 'useandom26T198340PX75pxJACKVERYMINDBUSHWOLFGQZbfghjklqvwyzrict';
|
|
22
|
+
const customNanoId = customAlphabet(urlAlphabet, 21);
|
|
23
|
+
|
|
24
|
+
return customNanoId();
|
|
25
|
+
};
|
|
@@ -21,14 +21,14 @@ class WorkerQueue {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async getWorkerForScriptPath(scriptPath: string) {
|
|
24
|
-
if (!this.workers) this.workers = {};
|
|
24
|
+
if (!this.workers) this.workers = {};
|
|
25
25
|
let worker = this.workers[scriptPath];
|
|
26
26
|
if (!worker || worker.threadId === -1) {
|
|
27
27
|
this.workers[scriptPath] = worker = new Worker(scriptPath);
|
|
28
28
|
}
|
|
29
29
|
return worker;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
async enqueue(task: QueuedTask) {
|
|
33
33
|
const { priority, scriptPath, data, taskType } = task;
|
|
34
34
|
|
|
@@ -40,9 +40,9 @@ class WorkerQueue {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
async processQueue() {
|
|
43
|
-
if (this.isProcessing || this.queue.length === 0){
|
|
43
|
+
if (this.isProcessing || this.queue.length === 0) {
|
|
44
44
|
return;
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
this.isProcessing = true;
|
|
48
48
|
const { scriptPath, data, taskType, resolve, reject } = this.queue.shift() as QueuedTask;
|
|
@@ -61,12 +61,12 @@ class WorkerQueue {
|
|
|
61
61
|
async runWorker({ scriptPath, data, taskType }: { scriptPath: string; data: any; taskType: 'parse' | 'stringify' }) {
|
|
62
62
|
return new Promise(async (resolve, reject) => {
|
|
63
63
|
let worker = await this.getWorkerForScriptPath(scriptPath);
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
const messageHandler = (data: any) => {
|
|
66
66
|
worker.off('message', messageHandler);
|
|
67
67
|
worker.off('error', errorHandler);
|
|
68
68
|
worker.off('exit', exitHandler);
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
if (data?.error) {
|
|
71
71
|
reject(new Error(data?.error));
|
|
72
72
|
} else {
|
|
@@ -89,7 +89,7 @@ class WorkerQueue {
|
|
|
89
89
|
delete this.workers[scriptPath];
|
|
90
90
|
reject(new Error(`Worker stopped with exit code ${code}`));
|
|
91
91
|
};
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
worker.on('message', messageHandler);
|
|
94
94
|
worker.on('error', errorHandler);
|
|
95
95
|
worker.on('exit', exitHandler);
|
|
@@ -99,16 +99,16 @@ class WorkerQueue {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
async cleanup() {
|
|
102
|
-
const promises = Object.values(this.workers).map(worker => {
|
|
102
|
+
const promises = Object.values(this.workers).map((worker) => {
|
|
103
103
|
if (worker.threadId !== -1) {
|
|
104
104
|
return worker.terminate();
|
|
105
105
|
}
|
|
106
106
|
return Promise.resolve();
|
|
107
107
|
});
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
await Promise.allSettled(promises);
|
|
110
110
|
this.workers = {};
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
export default WorkerQueue;
|
|
114
|
+
export default WorkerQueue;
|
package/src/workers/index.ts
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import WorkerQueue from './WorkerQueue';
|
|
2
|
-
import { Lane } from '../types';
|
|
2
|
+
import { Lane, CollectionFormat } from '../types';
|
|
3
|
+
import { DEFAULT_COLLECTION_FORMAT } from '../constants';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
|
|
5
6
|
const sizeInMB = (size: number): number => {
|
|
6
7
|
return size / (1024 * 1024);
|
|
7
|
-
}
|
|
8
|
+
};
|
|
8
9
|
|
|
9
10
|
const getSize = (data: any): number => {
|
|
10
11
|
return sizeInMB(typeof data === 'string' ? Buffer.byteLength(data, 'utf8') : Buffer.byteLength(JSON.stringify(data), 'utf8'));
|
|
11
|
-
}
|
|
12
|
+
};
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Lanes are used to determine which worker queue to use based on the size of the data.
|
|
15
|
-
*
|
|
16
|
+
*
|
|
16
17
|
* The first lane is for smaller files (<0.1MB), the second lane is for larger files (>=0.1MB).
|
|
17
18
|
* This helps with parsing performance.
|
|
18
19
|
*/
|
|
19
20
|
const LANES: Lane[] = [{
|
|
20
21
|
maxSize: 0.005
|
|
21
|
-
},{
|
|
22
|
+
}, {
|
|
22
23
|
maxSize: 0.1
|
|
23
|
-
},{
|
|
24
|
+
}, {
|
|
24
25
|
maxSize: 1
|
|
25
|
-
},{
|
|
26
|
+
}, {
|
|
26
27
|
maxSize: 10
|
|
27
|
-
},{
|
|
28
|
+
}, {
|
|
28
29
|
maxSize: 100
|
|
29
30
|
}];
|
|
30
31
|
|
|
@@ -38,7 +39,7 @@ class BruParserWorker {
|
|
|
38
39
|
private workerQueues: WorkerQueueWithSize[];
|
|
39
40
|
|
|
40
41
|
constructor() {
|
|
41
|
-
this.workerQueues = LANES?.map(lane => ({
|
|
42
|
+
this.workerQueues = LANES?.map((lane) => ({
|
|
42
43
|
maxSize: lane?.maxSize,
|
|
43
44
|
workerQueue: new WorkerQueue()
|
|
44
45
|
}));
|
|
@@ -47,40 +48,40 @@ class BruParserWorker {
|
|
|
47
48
|
private getWorkerQueue(size: number): WorkerQueue {
|
|
48
49
|
// Find the first queue that can handle the given size
|
|
49
50
|
// or fallback to the last queue for largest files
|
|
50
|
-
const queueForSize = this.workerQueues.find((queue) =>
|
|
51
|
+
const queueForSize = this.workerQueues.find((queue) =>
|
|
51
52
|
queue.maxSize >= size
|
|
52
53
|
);
|
|
53
54
|
|
|
54
55
|
return queueForSize?.workerQueue ?? this.workerQueues[this.workerQueues.length - 1].workerQueue;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
private async enqueueTask({ data, taskType }: { data: any; taskType: 'parse' | 'stringify' }): Promise<any> {
|
|
58
|
+
private async enqueueTask({ data, taskType, format = DEFAULT_COLLECTION_FORMAT }: { data: any; taskType: 'parse' | 'stringify'; format?: CollectionFormat }): Promise<any> {
|
|
58
59
|
const size = getSize(data);
|
|
59
60
|
const workerQueue = this.getWorkerQueue(size);
|
|
60
61
|
const workerScriptPath = path.join(__dirname, './workers/worker-script.js');
|
|
61
|
-
|
|
62
|
+
|
|
62
63
|
return workerQueue.enqueue({
|
|
63
|
-
data,
|
|
64
|
+
data: { data, format },
|
|
64
65
|
priority: size,
|
|
65
66
|
scriptPath: workerScriptPath,
|
|
66
|
-
taskType
|
|
67
|
+
taskType
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
async parseRequest(data: any): Promise<any> {
|
|
71
|
-
return this.enqueueTask({ data, taskType: 'parse' });
|
|
71
|
+
async parseRequest(data: any, format: CollectionFormat = DEFAULT_COLLECTION_FORMAT): Promise<any> {
|
|
72
|
+
return this.enqueueTask({ data, taskType: 'parse', format });
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
async stringifyRequest(data: any): Promise<any> {
|
|
75
|
-
return this.enqueueTask({ data, taskType: 'stringify' });
|
|
75
|
+
async stringifyRequest(data: any, format: CollectionFormat = DEFAULT_COLLECTION_FORMAT): Promise<any> {
|
|
76
|
+
return this.enqueueTask({ data, taskType: 'stringify', format });
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
async cleanup(): Promise<void> {
|
|
79
|
-
const cleanupPromises = this.workerQueues.map(({ workerQueue }) =>
|
|
80
|
+
const cleanupPromises = this.workerQueues.map(({ workerQueue }) =>
|
|
80
81
|
workerQueue.cleanup()
|
|
81
82
|
);
|
|
82
83
|
await Promise.allSettled(cleanupPromises);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
export default BruParserWorker;
|
|
87
|
+
export default BruParserWorker;
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
import { parentPort } from 'node:worker_threads';
|
|
2
|
-
import {
|
|
2
|
+
import { parseBruRequest, stringifyBruRequest } from '../formats/bru';
|
|
3
|
+
import { parseYmlItem, stringifyYmlItem } from '../formats/yml';
|
|
4
|
+
import { CollectionFormat } from '../types';
|
|
5
|
+
import { DEFAULT_COLLECTION_FORMAT } from '../constants';
|
|
3
6
|
|
|
4
7
|
interface WorkerMessage {
|
|
5
8
|
taskType: 'parse' | 'stringify';
|
|
6
|
-
data:
|
|
9
|
+
data: {
|
|
10
|
+
data: any;
|
|
11
|
+
format?: CollectionFormat;
|
|
12
|
+
};
|
|
7
13
|
}
|
|
8
14
|
|
|
9
15
|
parentPort?.on('message', async (message: WorkerMessage) => {
|
|
10
16
|
try {
|
|
11
|
-
const { taskType, data } = message;
|
|
17
|
+
const { taskType, data: messageData } = message;
|
|
18
|
+
const { data, format = DEFAULT_COLLECTION_FORMAT } = messageData;
|
|
12
19
|
let result: any;
|
|
13
20
|
|
|
14
21
|
if (taskType === 'parse') {
|
|
15
|
-
|
|
22
|
+
if (format === 'yml') {
|
|
23
|
+
result = parseYmlItem(data);
|
|
24
|
+
} else {
|
|
25
|
+
result = parseBruRequest(data);
|
|
26
|
+
}
|
|
16
27
|
} else if (taskType === 'stringify') {
|
|
17
|
-
|
|
28
|
+
if (format === 'yml') {
|
|
29
|
+
result = stringifyYmlItem(data);
|
|
30
|
+
} else {
|
|
31
|
+
result = stringifyBruRequest(data);
|
|
32
|
+
}
|
|
18
33
|
} else {
|
|
19
34
|
throw new Error(`Unknown task type: ${taskType}`);
|
|
20
35
|
}
|
|
@@ -24,4 +39,4 @@ parentPort?.on('message', async (message: WorkerMessage) => {
|
|
|
24
39
|
console.error('Worker error:', error);
|
|
25
40
|
parentPort?.postMessage({ error: error?.message });
|
|
26
41
|
}
|
|
27
|
-
});
|
|
42
|
+
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const bruRequestToJson: (data: string | any, parsed?: boolean) => any;
|
|
2
|
-
export declare const jsonRequestToBru: (json: any) => string;
|
|
3
|
-
export declare const bruCollectionToJson: (data: string | any, parsed?: boolean) => any;
|
|
4
|
-
export declare const jsonCollectionToBru: (json: any, isFolder?: boolean) => string;
|
|
5
|
-
export declare const bruEnvironmentToJson: (bru: string) => any;
|
|
6
|
-
export declare const jsonEnvironmentToBru: (json: any) => string;
|
|
7
|
-
export declare const bruExampleToJson: (data: string | any, parsed?: boolean, parentType?: string, parentMethod?: string) => any;
|
|
8
|
-
export declare const jsonExampleToBru: (json: any) => {
|
|
9
|
-
name: any;
|
|
10
|
-
description: any;
|
|
11
|
-
request: {
|
|
12
|
-
method: any;
|
|
13
|
-
url: any;
|
|
14
|
-
headers: any;
|
|
15
|
-
body: any;
|
|
16
|
-
params: any;
|
|
17
|
-
};
|
|
18
|
-
response: any;
|
|
19
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
type T_Oauth2ParameterSendInType = 'headers' | 'queryparams' | 'body';
|
|
2
|
-
export interface T_OAuth2AdditionalParam {
|
|
3
|
-
name: string;
|
|
4
|
-
value: string;
|
|
5
|
-
enabled: boolean;
|
|
6
|
-
sendIn: T_Oauth2ParameterSendInType;
|
|
7
|
-
}
|
|
8
|
-
export interface T_OAuth2AdditionalParameters {
|
|
9
|
-
authorization?: T_OAuth2AdditionalParam[];
|
|
10
|
-
token?: T_OAuth2AdditionalParam[];
|
|
11
|
-
refresh?: T_OAuth2AdditionalParam[];
|
|
12
|
-
}
|
|
13
|
-
export interface T_Oauth2Auth {
|
|
14
|
-
grantType: string;
|
|
15
|
-
additionalParameters?: T_OAuth2AdditionalParameters;
|
|
16
|
-
}
|
|
17
|
-
export interface T_BruJson {
|
|
18
|
-
auth: {
|
|
19
|
-
oauth2: T_Oauth2Auth;
|
|
20
|
-
};
|
|
21
|
-
oauth2_additional_parameters_auth_req_headers?: any[];
|
|
22
|
-
oauth2_additional_parameters_auth_req_queryparams?: any[];
|
|
23
|
-
oauth2_additional_parameters_access_token_req_headers?: any[];
|
|
24
|
-
oauth2_additional_parameters_access_token_req_queryparams?: any[];
|
|
25
|
-
oauth2_additional_parameters_access_token_req_bodyvalues?: any[];
|
|
26
|
-
oauth2_additional_parameters_refresh_token_req_headers?: any[];
|
|
27
|
-
oauth2_additional_parameters_refresh_token_req_queryparams?: any[];
|
|
28
|
-
oauth2_additional_parameters_refresh_token_req_bodyvalues?: any[];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* This function extracts OAuth2 additional parameters from various sources in the bru json data and organizes
|
|
32
|
-
* them into a structured format based on their usage context (authorization, token, refresh).
|
|
33
|
-
*
|
|
34
|
-
* @param json - json object containing OAuth2 configuration and additional parameters
|
|
35
|
-
* @returns OAuth2 additional parameters
|
|
36
|
-
*/
|
|
37
|
-
export declare const getOauth2AdditionalParameters: (json: T_BruJson) => T_OAuth2AdditionalParameters;
|
|
38
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses a .bru file and extracts body content while redacting it from the main content
|
|
3
|
-
* @param {string} bruFileContent - The raw content of the .bru file
|
|
4
|
-
* @returns {Object} Object containing redacted file content and extracted body data
|
|
5
|
-
*/
|
|
6
|
-
export declare const bruRequestParseAndRedactBodyData: (bruFileContent: string) => {
|
|
7
|
-
bruFileStringWithRedactedBody: string;
|
|
8
|
-
extractedBodyContent: Record<string, string>;
|
|
9
|
-
};
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import BruParserWorker from './workers';
|
|
2
|
-
import { ParseOptions, StringifyOptions, ParsedRequest, ParsedCollection, ParsedEnvironment } from './types';
|
|
3
|
-
export declare const parseRequest: (content: string, options?: ParseOptions) => any;
|
|
4
|
-
export declare const parseRequestAndRedactBody: (content: string, options?: ParseOptions) => any;
|
|
5
|
-
export declare const stringifyRequest: (requestObj: ParsedRequest, options?: StringifyOptions) => string;
|
|
6
|
-
export declare const parseRequestViaWorker: (content: string) => Promise<any>;
|
|
7
|
-
export declare const stringifyRequestViaWorker: (requestObj: any) => Promise<string>;
|
|
8
|
-
export declare const parseCollection: (content: string, options?: ParseOptions) => any;
|
|
9
|
-
export declare const stringifyCollection: (collectionObj: ParsedCollection, options?: StringifyOptions) => string;
|
|
10
|
-
export declare const parseFolder: (content: string, options?: ParseOptions) => any;
|
|
11
|
-
export declare const stringifyFolder: (folderObj: any, options?: StringifyOptions) => string;
|
|
12
|
-
export declare const parseEnvironment: (content: string, options?: ParseOptions) => any;
|
|
13
|
-
export declare const stringifyEnvironment: (envObj: ParsedEnvironment, options?: StringifyOptions) => string;
|
|
14
|
-
export declare const parseDotEnv: (content: string) => Record<string, string>;
|
|
15
|
-
export { BruParserWorker };
|
|
16
|
-
export * from './types';
|
package/dist/cjs/types.d.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
export interface ParseOptions {
|
|
2
|
-
format?: 'bru' | 'yaml';
|
|
3
|
-
}
|
|
4
|
-
export interface StringifyOptions {
|
|
5
|
-
format?: 'bru' | 'yaml';
|
|
6
|
-
}
|
|
7
|
-
export interface RequestBody {
|
|
8
|
-
mode?: string;
|
|
9
|
-
raw?: string;
|
|
10
|
-
formUrlEncoded?: Array<{
|
|
11
|
-
name: string;
|
|
12
|
-
value: string;
|
|
13
|
-
enabled: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
multipartForm?: Array<{
|
|
16
|
-
name: string;
|
|
17
|
-
value: string;
|
|
18
|
-
type: string;
|
|
19
|
-
enabled: boolean;
|
|
20
|
-
}>;
|
|
21
|
-
json?: string;
|
|
22
|
-
xml?: string;
|
|
23
|
-
sparql?: string;
|
|
24
|
-
graphql?: {
|
|
25
|
-
query?: string;
|
|
26
|
-
variables?: string;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export interface AuthConfig {
|
|
30
|
-
mode?: string;
|
|
31
|
-
basic?: {
|
|
32
|
-
username?: string;
|
|
33
|
-
password?: string;
|
|
34
|
-
};
|
|
35
|
-
bearer?: {
|
|
36
|
-
token?: string;
|
|
37
|
-
};
|
|
38
|
-
apikey?: {
|
|
39
|
-
key?: string;
|
|
40
|
-
value?: string;
|
|
41
|
-
placement?: string;
|
|
42
|
-
};
|
|
43
|
-
awsv4?: {
|
|
44
|
-
accessKeyId?: string;
|
|
45
|
-
secretAccessKey?: string;
|
|
46
|
-
sessionToken?: string;
|
|
47
|
-
service?: string;
|
|
48
|
-
region?: string;
|
|
49
|
-
profileName?: string;
|
|
50
|
-
};
|
|
51
|
-
oauth2?: {
|
|
52
|
-
grantType?: string;
|
|
53
|
-
callbackUrl?: string;
|
|
54
|
-
authorizationUrl?: string;
|
|
55
|
-
accessTokenUrl?: string;
|
|
56
|
-
clientId?: string;
|
|
57
|
-
clientSecret?: string;
|
|
58
|
-
scope?: string;
|
|
59
|
-
state?: string;
|
|
60
|
-
pkce?: boolean;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export interface RequestParam {
|
|
64
|
-
name: string;
|
|
65
|
-
value: string;
|
|
66
|
-
enabled: boolean;
|
|
67
|
-
}
|
|
68
|
-
export interface RequestHeader {
|
|
69
|
-
name: string;
|
|
70
|
-
value: string;
|
|
71
|
-
enabled: boolean;
|
|
72
|
-
}
|
|
73
|
-
export interface RequestAssertion {
|
|
74
|
-
name: string;
|
|
75
|
-
value: string;
|
|
76
|
-
enabled: boolean;
|
|
77
|
-
}
|
|
78
|
-
export interface RequestVars {
|
|
79
|
-
req?: Array<{
|
|
80
|
-
name: string;
|
|
81
|
-
value: string;
|
|
82
|
-
enabled: boolean;
|
|
83
|
-
}>;
|
|
84
|
-
res?: Array<{
|
|
85
|
-
name: string;
|
|
86
|
-
value: string;
|
|
87
|
-
enabled: boolean;
|
|
88
|
-
}>;
|
|
89
|
-
}
|
|
90
|
-
export interface RequestScript {
|
|
91
|
-
req?: string;
|
|
92
|
-
res?: string;
|
|
93
|
-
}
|
|
94
|
-
export interface RequestSettings {
|
|
95
|
-
[key: string]: any;
|
|
96
|
-
}
|
|
97
|
-
export interface RequestData {
|
|
98
|
-
method: string;
|
|
99
|
-
url: string;
|
|
100
|
-
params: RequestParam[];
|
|
101
|
-
headers: RequestHeader[];
|
|
102
|
-
auth: AuthConfig;
|
|
103
|
-
body: RequestBody;
|
|
104
|
-
script: RequestScript;
|
|
105
|
-
vars: RequestVars;
|
|
106
|
-
assertions: RequestAssertion[];
|
|
107
|
-
tests: string;
|
|
108
|
-
docs: string;
|
|
109
|
-
}
|
|
110
|
-
export interface ParsedRequest {
|
|
111
|
-
type: 'http-request' | 'graphql-request';
|
|
112
|
-
name: string;
|
|
113
|
-
seq: number;
|
|
114
|
-
settings: RequestSettings;
|
|
115
|
-
tags: string[];
|
|
116
|
-
request: RequestData;
|
|
117
|
-
}
|
|
118
|
-
export interface ParsedCollection {
|
|
119
|
-
name: string;
|
|
120
|
-
type?: string;
|
|
121
|
-
version?: string;
|
|
122
|
-
[key: string]: any;
|
|
123
|
-
}
|
|
124
|
-
export interface EnvironmentVariable {
|
|
125
|
-
name: string;
|
|
126
|
-
value: string;
|
|
127
|
-
enabled: boolean;
|
|
128
|
-
}
|
|
129
|
-
export interface ParsedEnvironment {
|
|
130
|
-
variables: EnvironmentVariable[];
|
|
131
|
-
}
|
|
132
|
-
export interface WorkerTask {
|
|
133
|
-
data: any;
|
|
134
|
-
priority: number;
|
|
135
|
-
scriptPath: string;
|
|
136
|
-
taskType?: 'parse' | 'stringify';
|
|
137
|
-
resolve?: (value: any) => void;
|
|
138
|
-
reject?: (reason?: any) => void;
|
|
139
|
-
}
|
|
140
|
-
export interface Lane {
|
|
141
|
-
maxSize: number;
|
|
142
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Worker } from 'node:worker_threads';
|
|
3
|
-
interface QueuedTask {
|
|
4
|
-
priority: number;
|
|
5
|
-
scriptPath: string;
|
|
6
|
-
data: any;
|
|
7
|
-
taskType: 'parse' | 'stringify';
|
|
8
|
-
resolve?: (value: any) => void;
|
|
9
|
-
reject?: (reason?: any) => void;
|
|
10
|
-
}
|
|
11
|
-
declare class WorkerQueue {
|
|
12
|
-
private queue;
|
|
13
|
-
private isProcessing;
|
|
14
|
-
private workers;
|
|
15
|
-
constructor();
|
|
16
|
-
getWorkerForScriptPath(scriptPath: string): Promise<Worker>;
|
|
17
|
-
enqueue(task: QueuedTask): Promise<unknown>;
|
|
18
|
-
processQueue(): Promise<void>;
|
|
19
|
-
runWorker({ scriptPath, data, taskType }: {
|
|
20
|
-
scriptPath: string;
|
|
21
|
-
data: any;
|
|
22
|
-
taskType: 'parse' | 'stringify';
|
|
23
|
-
}): Promise<unknown>;
|
|
24
|
-
cleanup(): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
export default WorkerQueue;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const bruRequestToJson: (data: string | any, parsed?: boolean) => any;
|
|
2
|
-
export declare const jsonRequestToBru: (json: any) => string;
|
|
3
|
-
export declare const bruCollectionToJson: (data: string | any, parsed?: boolean) => any;
|
|
4
|
-
export declare const jsonCollectionToBru: (json: any, isFolder?: boolean) => string;
|
|
5
|
-
export declare const bruEnvironmentToJson: (bru: string) => any;
|
|
6
|
-
export declare const jsonEnvironmentToBru: (json: any) => string;
|
|
7
|
-
export declare const bruExampleToJson: (data: string | any, parsed?: boolean, parentType?: string, parentMethod?: string) => any;
|
|
8
|
-
export declare const jsonExampleToBru: (json: any) => {
|
|
9
|
-
name: any;
|
|
10
|
-
description: any;
|
|
11
|
-
request: {
|
|
12
|
-
method: any;
|
|
13
|
-
url: any;
|
|
14
|
-
headers: any;
|
|
15
|
-
body: any;
|
|
16
|
-
params: any;
|
|
17
|
-
};
|
|
18
|
-
response: any;
|
|
19
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses a .bru file and extracts body content while redacting it from the main content
|
|
3
|
-
* @param {string} bruFileContent - The raw content of the .bru file
|
|
4
|
-
* @returns {Object} Object containing redacted file content and extracted body data
|
|
5
|
-
*/
|
|
6
|
-
export declare const bruRequestParseAndRedactBodyData: (bruFileContent: string) => {
|
|
7
|
-
bruFileStringWithRedactedBody: string;
|
|
8
|
-
extractedBodyContent: Record<string, string>;
|
|
9
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import BruParserWorker from './workers';
|
|
2
|
-
import { ParseOptions, StringifyOptions, ParsedRequest, ParsedCollection, ParsedEnvironment } from './types';
|
|
3
|
-
export declare const parseRequest: (content: string, options?: ParseOptions) => any;
|
|
4
|
-
export declare const parseRequestAndRedactBody: (content: string, options?: ParseOptions) => any;
|
|
5
|
-
export declare const stringifyRequest: (requestObj: ParsedRequest, options?: StringifyOptions) => string;
|
|
6
|
-
export declare const parseRequestViaWorker: (content: string) => Promise<any>;
|
|
7
|
-
export declare const stringifyRequestViaWorker: (requestObj: any) => Promise<string>;
|
|
8
|
-
export declare const parseCollection: (content: string, options?: ParseOptions) => any;
|
|
9
|
-
export declare const stringifyCollection: (collectionObj: ParsedCollection, options?: StringifyOptions) => string;
|
|
10
|
-
export declare const parseFolder: (content: string, options?: ParseOptions) => any;
|
|
11
|
-
export declare const stringifyFolder: (folderObj: any, options?: StringifyOptions) => string;
|
|
12
|
-
export declare const parseEnvironment: (content: string, options?: ParseOptions) => any;
|
|
13
|
-
export declare const stringifyEnvironment: (envObj: ParsedEnvironment, options?: StringifyOptions) => string;
|
|
14
|
-
export declare const parseDotEnv: (content: string) => Record<string, string>;
|
|
15
|
-
export { BruParserWorker };
|
|
16
|
-
export * from './types';
|