@usebruno/filestore 0.3.1 → 0.5.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/formats/bru/index.d.ts +13 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/workers/formats/bru/index.d.ts +13 -0
- package/dist/cjs/workers/worker-script.js +1 -1
- package/dist/cjs/workers/worker-script.js.map +1 -1
- package/dist/esm/formats/bru/index.d.ts +13 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/workers/formats/bru/index.d.ts +13 -0
- package/dist/esm/workers/worker-script.js +1 -1
- package/dist/esm/workers/worker-script.js.map +1 -1
- package/package.json +2 -2
- package/src/formats/bru/index.ts +137 -5
package/src/formats/bru/index.ts
CHANGED
|
@@ -24,11 +24,19 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
|
|
|
24
24
|
case 'grpc':
|
|
25
25
|
requestType = 'grpc-request';
|
|
26
26
|
break;
|
|
27
|
+
case 'ws':
|
|
28
|
+
requestType = 'ws-request';
|
|
29
|
+
break;
|
|
27
30
|
default:
|
|
28
31
|
requestType = 'http-request';
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
const sequence = _.get(json, 'meta.seq');
|
|
35
|
+
const urlPath: Record<typeof requestType, string> = {
|
|
36
|
+
'grpc-request': 'grpc.url',
|
|
37
|
+
'ws-request': 'ws.url',
|
|
38
|
+
'default': 'http.url'
|
|
39
|
+
};
|
|
32
40
|
const transformedJson = {
|
|
33
41
|
type: requestType,
|
|
34
42
|
name: _.get(json, 'meta.name'),
|
|
@@ -38,8 +46,10 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
|
|
|
38
46
|
request: {
|
|
39
47
|
// Preserving special characters in custom methods. Using _.upperCase strips special characters.
|
|
40
48
|
method:
|
|
41
|
-
requestType === 'grpc-request'
|
|
42
|
-
|
|
49
|
+
requestType === 'grpc-request'
|
|
50
|
+
? _.get(json, 'grpc.method', '')
|
|
51
|
+
: String(_.get(json, 'http.method') ?? '').toUpperCase(),
|
|
52
|
+
url: _.get(json, urlPath[requestType], _.get(json, urlPath.default)),
|
|
43
53
|
headers: requestType === 'grpc-request' ? _.get(json, 'metadata', []) : _.get(json, 'headers', []),
|
|
44
54
|
auth: _.get(json, 'auth', {}),
|
|
45
55
|
body: _.get(json, 'body', {}),
|
|
@@ -48,8 +58,11 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
|
|
|
48
58
|
assertions: _.get(json, 'assertions', []),
|
|
49
59
|
tests: _.get(json, 'tests', ''),
|
|
50
60
|
docs: _.get(json, 'docs', '')
|
|
51
|
-
}
|
|
52
|
-
|
|
61
|
+
},
|
|
62
|
+
examples: _.get(json, 'examples', []).map((e: any) => {
|
|
63
|
+
return bruExampleToJson(e, true, requestType, _.get(json, 'http.method'));
|
|
64
|
+
})
|
|
65
|
+
} as any;
|
|
53
66
|
|
|
54
67
|
// Add request type specific fields
|
|
55
68
|
if (requestType === 'grpc-request') {
|
|
@@ -67,6 +80,17 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
|
|
|
67
80
|
}
|
|
68
81
|
])
|
|
69
82
|
});
|
|
83
|
+
} else if (requestType === 'ws-request') {
|
|
84
|
+
transformedJson.request.auth.mode = _.get(json, 'ws.auth', 'none');
|
|
85
|
+
transformedJson.request.body = _.get(json, 'body', {
|
|
86
|
+
mode: 'ws',
|
|
87
|
+
ws: _.get(json, 'body.ws', [
|
|
88
|
+
{
|
|
89
|
+
name: 'message 1',
|
|
90
|
+
content: '{}'
|
|
91
|
+
}
|
|
92
|
+
])
|
|
93
|
+
});
|
|
70
94
|
} else {
|
|
71
95
|
// For HTTP and GraphQL
|
|
72
96
|
(transformedJson.request as any).params = _.get(json, 'params', []);
|
|
@@ -83,9 +107,9 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
|
|
|
83
107
|
transformedJson.request.auth.oauth2.additionalParameters = additionalParameters;
|
|
84
108
|
}
|
|
85
109
|
}
|
|
86
|
-
|
|
87
110
|
return transformedJson;
|
|
88
111
|
} catch (error) {
|
|
112
|
+
console.log('bruRequestToJson error', error);
|
|
89
113
|
throw error;
|
|
90
114
|
}
|
|
91
115
|
};
|
|
@@ -103,6 +127,9 @@ export const jsonRequestToBru = (json: any): string => {
|
|
|
103
127
|
case 'grpc-request':
|
|
104
128
|
type = 'grpc';
|
|
105
129
|
break;
|
|
130
|
+
case 'ws-request':
|
|
131
|
+
type = 'ws';
|
|
132
|
+
break;
|
|
106
133
|
default:
|
|
107
134
|
type = 'http';
|
|
108
135
|
}
|
|
@@ -156,6 +183,22 @@ export const jsonRequestToBru = (json: any): string => {
|
|
|
156
183
|
}
|
|
157
184
|
])
|
|
158
185
|
});
|
|
186
|
+
} else if (type === 'ws') {
|
|
187
|
+
bruJson.ws = {
|
|
188
|
+
url: _.get(json, 'request.url'),
|
|
189
|
+
auth: _.get(json, 'request.auth.mode', 'none'),
|
|
190
|
+
body: _.get(json, 'request.body.mode', 'ws')
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
bruJson.body = _.get(json, 'request.body', {
|
|
194
|
+
mode: 'ws',
|
|
195
|
+
ws: _.get(json, 'request.body.ws', [
|
|
196
|
+
{
|
|
197
|
+
name: 'message 1',
|
|
198
|
+
content: '{}'
|
|
199
|
+
}
|
|
200
|
+
])
|
|
201
|
+
});
|
|
159
202
|
}
|
|
160
203
|
|
|
161
204
|
// Common fields for all request types
|
|
@@ -175,6 +218,7 @@ export const jsonRequestToBru = (json: any): string => {
|
|
|
175
218
|
bruJson.tests = _.get(json, 'request.tests', '');
|
|
176
219
|
bruJson.settings = _.get(json, 'settings', {});
|
|
177
220
|
bruJson.docs = _.get(json, 'request.docs', '');
|
|
221
|
+
bruJson.examples = _.get(json, 'examples', []).map((e: any) => jsonExampleToBru(e));
|
|
178
222
|
|
|
179
223
|
const bru = jsonToBruV2(bruJson);
|
|
180
224
|
return bru;
|
|
@@ -295,3 +339,91 @@ export const jsonEnvironmentToBru = (json: any): string => {
|
|
|
295
339
|
throw error;
|
|
296
340
|
}
|
|
297
341
|
};
|
|
342
|
+
|
|
343
|
+
// New functions for example handling
|
|
344
|
+
export const bruExampleToJson = (data: string | any, parsed: boolean = false, parentType?: string, parentMethod?: string): any => {
|
|
345
|
+
try {
|
|
346
|
+
const json = parsed ? data : bruToJsonV2(data);
|
|
347
|
+
|
|
348
|
+
// Use parent request's type and method if provided
|
|
349
|
+
const requestType = parentType || _.get(json, 'meta.type', 'http');
|
|
350
|
+
const requestMethod = parentMethod || _.get(json, 'http.method', 'GET');
|
|
351
|
+
|
|
352
|
+
let transformedType = requestType;
|
|
353
|
+
switch (requestType) {
|
|
354
|
+
case 'http':
|
|
355
|
+
transformedType = 'http-request';
|
|
356
|
+
break;
|
|
357
|
+
case 'graphql':
|
|
358
|
+
transformedType = 'graphql-request';
|
|
359
|
+
break;
|
|
360
|
+
case 'grpc':
|
|
361
|
+
transformedType = 'grpc-request';
|
|
362
|
+
break;
|
|
363
|
+
case 'ws':
|
|
364
|
+
transformedType = 'ws-request';
|
|
365
|
+
break;
|
|
366
|
+
default:
|
|
367
|
+
transformedType = 'http-request';
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Follow the same structure as the main request, but with missing fields for examples
|
|
371
|
+
const transformedJson = {
|
|
372
|
+
type: transformedType,
|
|
373
|
+
name: _.get(json, 'name'),
|
|
374
|
+
description: _.get(json, 'description', ''),
|
|
375
|
+
// Examples don't have seq, settings, tags
|
|
376
|
+
request: {
|
|
377
|
+
method: _.get(json, 'request.method') || requestMethod,
|
|
378
|
+
url: _.get(json, 'request.url'),
|
|
379
|
+
headers: _.get(json, 'request.headers', []),
|
|
380
|
+
body: _.get(json, 'request.body', {
|
|
381
|
+
mode: 'none'
|
|
382
|
+
}),
|
|
383
|
+
// Examples don't have script, vars, assertions, tests, docs
|
|
384
|
+
params: _.get(json, 'request.params', [])
|
|
385
|
+
},
|
|
386
|
+
response: {
|
|
387
|
+
headers: _.get(json, 'response.headers', []).map((header: any) => ({
|
|
388
|
+
name: header.name,
|
|
389
|
+
value: header.value
|
|
390
|
+
})),
|
|
391
|
+
status: String(_.get(json, 'response.status', '200')),
|
|
392
|
+
statusText: _.get(json, 'response.statusText', 'OK'),
|
|
393
|
+
body: {
|
|
394
|
+
type: _.get(json, 'response.body.type', 'json'),
|
|
395
|
+
content: _.get(json, 'response.body.content', '')
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
} as any;
|
|
399
|
+
|
|
400
|
+
return transformedJson;
|
|
401
|
+
} catch (error) {
|
|
402
|
+
console.log('bruExampleToJson error', error);
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export const jsonExampleToBru = (json: any) => {
|
|
408
|
+
try {
|
|
409
|
+
// Transform the JSON to match the same structure as main request, but with missing fields
|
|
410
|
+
const exampleJson = {
|
|
411
|
+
name: _.get(json, 'name'),
|
|
412
|
+
description: _.get(json, 'description', ''),
|
|
413
|
+
// Examples don't have seq, settings, tags
|
|
414
|
+
request: {
|
|
415
|
+
method: _.get(json, 'request.method'),
|
|
416
|
+
url: _.get(json, 'request.url'),
|
|
417
|
+
headers: _.get(json, 'request.headers', []),
|
|
418
|
+
body: _.get(json, 'request.body', {}),
|
|
419
|
+
// Examples don't have script, vars, assertions, tests, docs
|
|
420
|
+
params: _.get(json, 'request.params', [])
|
|
421
|
+
},
|
|
422
|
+
response: _.get(json, 'response', {})
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
return exampleJson;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
};
|