@api-client/core 0.4.0 → 0.4.1

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 (106) hide show
  1. package/build/browser.d.ts +5 -2
  2. package/build/browser.js +7 -2
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +6 -4
  5. package/build/index.js +4 -3
  6. package/build/index.js.map +1 -1
  7. package/build/src/models/HttpHistory.d.ts +29 -0
  8. package/build/src/models/HttpHistory.js.map +1 -1
  9. package/build/src/models/RequestLog.d.ts +8 -0
  10. package/build/src/models/RequestLog.js +14 -1
  11. package/build/src/models/RequestLog.js.map +1 -1
  12. package/build/src/runtime/node/InteropInterfaces.d.ts +115 -0
  13. package/build/src/runtime/node/InteropInterfaces.js +2 -0
  14. package/build/src/runtime/node/InteropInterfaces.js.map +1 -0
  15. package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -7
  16. package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
  17. package/build/src/runtime/node/ProjectRequestRunner.d.ts +17 -49
  18. package/build/src/runtime/node/ProjectRequestRunner.js +39 -10
  19. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  20. package/build/src/runtime/node/ProjectRunner.d.ts +1 -59
  21. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  22. package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
  23. package/build/src/runtime/store/AuthSdk.d.ts +28 -0
  24. package/build/src/runtime/store/AuthSdk.js +123 -0
  25. package/build/src/runtime/store/AuthSdk.js.map +1 -0
  26. package/build/src/runtime/store/BackendSdk.d.ts +8 -0
  27. package/build/src/runtime/store/BackendSdk.js +25 -0
  28. package/build/src/runtime/store/BackendSdk.js.map +1 -0
  29. package/build/src/runtime/store/HistorySdk.d.ts +48 -0
  30. package/build/src/runtime/store/HistorySdk.js +142 -0
  31. package/build/src/runtime/store/HistorySdk.js.map +1 -0
  32. package/build/src/runtime/store/Http.d.ts +14 -0
  33. package/build/src/runtime/store/Http.js +4 -0
  34. package/build/src/runtime/store/Http.js.map +1 -0
  35. package/build/src/runtime/store/HttpNode.d.ts +16 -0
  36. package/build/src/runtime/store/HttpNode.js +95 -0
  37. package/build/src/runtime/store/HttpNode.js.map +1 -0
  38. package/build/src/runtime/store/HttpWeb.d.ts +15 -0
  39. package/build/src/runtime/store/HttpWeb.js +83 -0
  40. package/build/src/runtime/store/HttpWeb.js.map +1 -0
  41. package/build/src/runtime/store/ProjectsSdk.d.ts +43 -0
  42. package/build/src/runtime/store/ProjectsSdk.js +144 -0
  43. package/build/src/runtime/store/ProjectsSdk.js.map +1 -0
  44. package/build/src/runtime/store/RouteBuilder.d.ts +42 -0
  45. package/build/src/runtime/store/RouteBuilder.js +75 -0
  46. package/build/src/runtime/store/RouteBuilder.js.map +1 -0
  47. package/build/src/runtime/store/Sdk.d.ts +79 -0
  48. package/build/src/runtime/store/Sdk.js +117 -0
  49. package/build/src/runtime/store/Sdk.js.map +1 -0
  50. package/build/src/runtime/store/SdkBase.d.ts +45 -0
  51. package/build/src/runtime/store/SdkBase.js +40 -0
  52. package/build/src/runtime/store/SdkBase.js.map +1 -0
  53. package/build/src/runtime/store/SpacesSdk.d.ts +50 -0
  54. package/build/src/runtime/store/SpacesSdk.js +185 -0
  55. package/build/src/runtime/store/SpacesSdk.js.map +1 -0
  56. package/build/src/runtime/store/StoreSdkNode.d.ts +10 -0
  57. package/build/src/runtime/store/StoreSdkNode.js +11 -0
  58. package/build/src/runtime/store/StoreSdkNode.js.map +1 -0
  59. package/build/src/runtime/store/StoreSdkWeb.d.ts +10 -0
  60. package/build/src/runtime/store/StoreSdkWeb.js +11 -0
  61. package/build/src/runtime/store/StoreSdkWeb.js.map +1 -0
  62. package/build/src/runtime/store/UsersSdk.d.ts +18 -0
  63. package/build/src/runtime/store/UsersSdk.js +88 -0
  64. package/build/src/runtime/store/UsersSdk.js.map +1 -0
  65. package/build/src/runtime/store/WsClient.d.ts +24 -0
  66. package/build/src/runtime/store/WsClient.js +4 -0
  67. package/build/src/runtime/store/WsClient.js.map +1 -0
  68. package/build/src/runtime/store/WsClientNode.d.ts +24 -0
  69. package/build/src/runtime/store/WsClientNode.js +66 -0
  70. package/build/src/runtime/store/WsClientNode.js.map +1 -0
  71. package/build/src/runtime/store/WsClientWeb.d.ts +23 -0
  72. package/build/src/runtime/store/WsClientWeb.js +73 -0
  73. package/build/src/runtime/store/WsClientWeb.js.map +1 -0
  74. package/package.json +4 -6
  75. package/src/models/HttpHistory.ts +30 -0
  76. package/src/models/RequestLog.ts +17 -1
  77. package/src/runtime/node/InteropInterfaces.ts +121 -0
  78. package/src/runtime/node/ProjectParallelRunner.ts +2 -9
  79. package/src/runtime/node/ProjectRequestRunner.ts +42 -61
  80. package/src/runtime/node/ProjectRunner.ts +1 -60
  81. package/src/runtime/node/ProjectRunnerWorker.ts +2 -1
  82. package/src/runtime/store/AuthSdk.ts +126 -0
  83. package/src/runtime/store/BackendSdk.ts +25 -0
  84. package/src/runtime/store/HistorySdk.ts +157 -0
  85. package/src/runtime/store/Http.ts +18 -0
  86. package/src/runtime/store/HttpNode.ts +100 -0
  87. package/src/runtime/store/HttpWeb.ts +89 -0
  88. package/src/runtime/store/ProjectsSdk.ts +147 -0
  89. package/src/runtime/store/RouteBuilder.ts +89 -0
  90. package/src/runtime/store/Sdk.ts +131 -0
  91. package/src/runtime/store/SdkBase.ts +72 -0
  92. package/src/runtime/store/SpacesSdk.ts +190 -0
  93. package/src/runtime/store/StoreSdkNode.ts +13 -0
  94. package/src/runtime/store/StoreSdkWeb.ts +13 -0
  95. package/src/runtime/store/UsersSdk.ts +89 -0
  96. package/src/runtime/store/WsClient.ts +28 -0
  97. package/src/runtime/store/WsClientNode.ts +68 -0
  98. package/src/runtime/store/WsClientWeb.ts +75 -0
  99. package/build/src/models/HistoryIndex.d.ts +0 -45
  100. package/build/src/models/HistoryIndex.js +0 -56
  101. package/build/src/models/HistoryIndex.js.map +0 -1
  102. package/build/src/runtime/store/StoreSdk.d.ts +0 -279
  103. package/build/src/runtime/store/StoreSdk.js +0 -842
  104. package/build/src/runtime/store/StoreSdk.js.map +0 -1
  105. package/src/models/HistoryIndex.ts +0 -81
  106. package/src/runtime/store/StoreSdk.ts +0 -895
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WsClient.js","sourceRoot":"","sources":["../../../../src/runtime/store/WsClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAgB,QAAS,SAAQ,OAAO;CAwB7C"}
@@ -0,0 +1,24 @@
1
+ import WebSocket from 'ws';
2
+ import { WsClient } from './WsClient.js';
3
+ export declare class WsClientNode extends WsClient {
4
+ /**
5
+ * Creates a WS client with optional token
6
+ * @param addr The ws:// address
7
+ * @param token Optional token to add.
8
+ */
9
+ getClient(addr: string, token?: string | undefined): WebSocket;
10
+ /**
11
+ * Connect to the WS server
12
+ *
13
+ * @param client The client to wait for connection.
14
+ */
15
+ connect(client: WebSocket): Promise<void>;
16
+ /**
17
+ * Disconnects from the WS server.
18
+ */
19
+ disconnect(client: WebSocket): Promise<void>;
20
+ /**
21
+ * The combination of `getClient()` and `connect()`.
22
+ */
23
+ createAndConnect(addr: string, token?: string): Promise<WebSocket>;
24
+ }
@@ -0,0 +1,66 @@
1
+ import WebSocket from 'ws';
2
+ import { WsClient } from './WsClient.js';
3
+ export class WsClientNode extends WsClient {
4
+ /**
5
+ * Creates a WS client with optional token
6
+ * @param addr The ws:// address
7
+ * @param token Optional token to add.
8
+ */
9
+ getClient(addr, token = this.sdk.token) {
10
+ let url = addr;
11
+ if (token) {
12
+ url += url.includes('?') ? '&' : '?';
13
+ url += 'token=';
14
+ url += token;
15
+ }
16
+ if (url.startsWith('http:')) {
17
+ url = `ws:${url.substring(5)}`;
18
+ }
19
+ else if (url.startsWith('https:')) {
20
+ url = `wss:${url.substring(6)}`;
21
+ }
22
+ return new WebSocket(url);
23
+ }
24
+ /**
25
+ * Connect to the WS server
26
+ *
27
+ * @param client The client to wait for connection.
28
+ */
29
+ connect(client) {
30
+ return new Promise((resolve, reject) => {
31
+ client.once('open', () => {
32
+ client.removeAllListeners('error');
33
+ resolve();
34
+ });
35
+ client.once('error', (err) => {
36
+ client.removeAllListeners('open');
37
+ reject(err);
38
+ });
39
+ });
40
+ }
41
+ /**
42
+ * Disconnects from the WS server.
43
+ */
44
+ disconnect(client) {
45
+ return new Promise((resolve, reject) => {
46
+ client.once('close', () => {
47
+ client.removeAllListeners('error');
48
+ resolve();
49
+ });
50
+ client.once('error', (err) => {
51
+ client.removeAllListeners('close');
52
+ reject(err);
53
+ });
54
+ client.close();
55
+ });
56
+ }
57
+ /**
58
+ * The combination of `getClient()` and `connect()`.
59
+ */
60
+ async createAndConnect(addr, token) {
61
+ const client = this.getClient(addr, token);
62
+ await this.connect(client);
63
+ return client;
64
+ }
65
+ }
66
+ //# sourceMappingURL=WsClientNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WsClientNode.js","sourceRoot":"","sources":["../../../../src/runtime/store/WsClientNode.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,YAAa,SAAQ,QAAQ;IACxC;;;;OAIG;IACH,SAAS,CAAC,IAAY,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK;QAC5C,IAAI,GAAG,GAAG,IAAI,CAAC;QACf,IAAI,KAAK,EAAE;YACT,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACrC,GAAG,IAAI,QAAQ,CAAC;YAChB,GAAG,IAAI,KAAK,CAAC;SACd;QACD,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAC3B,GAAG,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC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gBAAgB,CAAC,IAAY,EAAE,KAAc;QACjD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import { WsClient } from './WsClient.js';
2
+ export declare class WsClientWeb extends WsClient {
3
+ /**
4
+ * Creates a WS client with optional token
5
+ * @param addr The ws:// address
6
+ * @param token Optional token to add.
7
+ */
8
+ getClient(addr: string, token?: string | undefined): WebSocket;
9
+ /**
10
+ * Connect to the WS server
11
+ *
12
+ * @param client The client to wait for connection.
13
+ */
14
+ connect(client: WebSocket): Promise<void>;
15
+ /**
16
+ * Disconnects from the WS server.
17
+ */
18
+ disconnect(client: WebSocket): Promise<void>;
19
+ /**
20
+ * The combination of `getClient()` and `connect()`.
21
+ */
22
+ createAndConnect(addr: string, token?: string): Promise<WebSocket>;
23
+ }
@@ -0,0 +1,73 @@
1
+ import { WsClient } from './WsClient.js';
2
+ export class WsClientWeb extends WsClient {
3
+ /**
4
+ * Creates a WS client with optional token
5
+ * @param addr The ws:// address
6
+ * @param token Optional token to add.
7
+ */
8
+ getClient(addr, token = this.sdk.token) {
9
+ let url = addr;
10
+ if (token) {
11
+ url += url.includes('?') ? '&' : '?';
12
+ url += 'token=';
13
+ url += token;
14
+ }
15
+ if (url.startsWith('http:')) {
16
+ url = `ws:${url.substring(5)}`;
17
+ }
18
+ else if (url.startsWith('https:')) {
19
+ url = `wss:${url.substring(6)}`;
20
+ }
21
+ return new WebSocket(url);
22
+ }
23
+ /**
24
+ * Connect to the WS server
25
+ *
26
+ * @param client The client to wait for connection.
27
+ */
28
+ connect(client) {
29
+ return new Promise((resolve, reject) => {
30
+ function opened() {
31
+ client.removeEventListener('open', opened);
32
+ client.removeEventListener('error', errored);
33
+ resolve();
34
+ }
35
+ function errored() {
36
+ client.removeEventListener('open', opened);
37
+ client.removeEventListener('error', errored);
38
+ reject(new Error(`Unable to connect to: ${client.url}`));
39
+ }
40
+ client.addEventListener('open', opened);
41
+ client.addEventListener('error', errored);
42
+ });
43
+ }
44
+ /**
45
+ * Disconnects from the WS server.
46
+ */
47
+ disconnect(client) {
48
+ return new Promise((resolve, reject) => {
49
+ function closed() {
50
+ client.removeEventListener('close', closed);
51
+ client.removeEventListener('error', errored);
52
+ resolve();
53
+ }
54
+ function errored() {
55
+ client.removeEventListener('close', closed);
56
+ client.removeEventListener('error', errored);
57
+ reject(new Error(`Unable to connect to: ${client.url}`));
58
+ }
59
+ client.addEventListener('close', closed);
60
+ client.addEventListener('error', errored);
61
+ client.close();
62
+ });
63
+ }
64
+ /**
65
+ * The combination of `getClient()` and `connect()`.
66
+ */
67
+ async createAndConnect(addr, token) {
68
+ const client = this.getClient(addr, token);
69
+ await this.connect(client);
70
+ return client;
71
+ }
72
+ }
73
+ //# sourceMappingURL=WsClientWeb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WsClientWeb.js","sourceRoot":"","sources":["../../../../src/runtime/store/WsClientWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,WAAY,SAAQ,QAAQ;IACvC;;;;OAIG;IACH,SAAS,CAAC,IAAY,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK;QAC5C,IAAI,GAAG,GAAG,IAAI,CAAC;QACf,IAAI,KAAK,EAAE;YACT,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACrC,GAAG,IAAI,QAAQ,CAAC;YAChB,GAAG,IAAI,KAAK,CAAC;SACd;QACD,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAC3B,GAAG,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,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AM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC5C,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC3D,CAAC;YACD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACzC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC1C,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CAAC,IAAY,EAAE,KAAc;QACjD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "license": "Apache-2.0",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -56,6 +56,7 @@
56
56
  "mocha": "^9.1.3",
57
57
  "shrink-ray-current": "^4.1.3",
58
58
  "sinon": "^13.0.1",
59
+ "source-map-support": "^0.5.21",
59
60
  "ssl-root-cas": "^1.3.1",
60
61
  "ts-node": "^10.4.0",
61
62
  "typescript": "^4.4.4"
@@ -68,10 +69,7 @@
68
69
  "tsc:watch": "tsc --watch",
69
70
  "test:browser": "wtr --playwright --browsers chromium firefox webkit --coverage",
70
71
  "test:browser:watch": "wtr --watch --playwright --browsers chromium",
71
- "test:mocha": "mocha --require test/http-server-fixture.js",
72
- "test:mocha:watch": "mocha --watch --require test/http-server-fixture.js",
73
- "test:mocha:watch2": "node scripts/test-node-watch.js",
74
- "test:mocha:watch3": "mocha --watch --recursive --parallel --require test/http-server-fixture.js",
72
+ "test:mocha": "npm run build-ts && mocha",
75
73
  "test": "npm run test:mocha && npm run test:browser"
76
74
  },
77
75
  "husky": {
@@ -86,8 +84,8 @@
86
84
  },
87
85
  "dependencies": {
88
86
  "@metrichor/jmespath": "^0.3.1",
89
- "@pawel-up/jexl": "^3.0.0",
90
87
  "@pawel-up/data-mock": "^0.1.7",
88
+ "@pawel-up/jexl": "^3.0.0",
91
89
  "@xmldom/xmldom": "^0.8.1",
92
90
  "console-table-printer": "^2.10.0",
93
91
  "form-data": "^4.0.0",
@@ -48,6 +48,36 @@ export interface IHttpHistory {
48
48
  midnight?: number;
49
49
  }
50
50
 
51
+ /**
52
+ * An interface used when adding a history in bulk.
53
+ * The store creates a history object propagating meta values defined here
54
+ * onto the history objects.
55
+ * Because of that, bulk operation can only be performed when the requests are made in similar
56
+ * context (app, space, project).
57
+ */
58
+ export interface IHttpHistoryBulkAdd {
59
+ /**
60
+ * Optional user space id. Must be set when the originating request belongs to a user space.
61
+ */
62
+ space?: string;
63
+ /**
64
+ * Optional project id. Must be set when the originating request belongs to a user space.
65
+ */
66
+ project?: string;
67
+ /**
68
+ * Optional application id. Must be set when the application that created this record does not use the concept of a user space.
69
+ */
70
+ app?: string;
71
+ /**
72
+ * The optional request id in the project that generated this log.
73
+ */
74
+ request?: string;
75
+ /**
76
+ * The list of request logs.
77
+ */
78
+ log: IRequestLog[];
79
+ }
80
+
51
81
  /**
52
82
  * An HTTP history is an object containing an information of a request and response
53
83
  * made with the application.
@@ -28,6 +28,10 @@ export interface IRequestLog {
28
28
  * Request and response size. Some HTTP clients may not give this information.
29
29
  */
30
30
  size?: IRequestsSize;
31
+ /**
32
+ * Optional request ID defined on an HTTP project that triggered this log.
33
+ */
34
+ requestId?: string;
31
35
  }
32
36
 
33
37
  /**
@@ -51,6 +55,10 @@ export class RequestLog {
51
55
  * Request and response size. Some HTTP clients may not give this information.
52
56
  */
53
57
  size?: RequestsSize;
58
+ /**
59
+ * Optional request ID defined on an HTTP project that triggered this log.
60
+ */
61
+ requestId?: string;
54
62
 
55
63
  static fromRequest(request: ISentRequest): RequestLog {
56
64
  return new RequestLog({
@@ -88,7 +96,7 @@ export class RequestLog {
88
96
  * Creates a new response clearing anything that is so far defined.
89
97
  */
90
98
  new(init: IRequestLog): void {
91
- const { request, response, redirects, size } = init;
99
+ const { request, response, redirects, size, requestId } = init;
92
100
  this.kind = Kind;
93
101
  if (request) {
94
102
  this.request = new SentRequest(request);
@@ -112,6 +120,11 @@ export class RequestLog {
112
120
  } else {
113
121
  this.size = undefined;
114
122
  }
123
+ if (requestId) {
124
+ this.requestId = requestId;
125
+ } else {
126
+ this.requestId = undefined;
127
+ }
115
128
  }
116
129
 
117
130
  toJSON(): IRequestLog {
@@ -130,6 +143,9 @@ export class RequestLog {
130
143
  if (this.response) {
131
144
  result.response = this.response.toJSON();
132
145
  }
146
+ if (this.requestId) {
147
+ result.requestId = this.requestId;
148
+ }
133
149
  return result;
134
150
  }
135
151
 
@@ -0,0 +1,121 @@
1
+ import { IProjectRequestIterator, IHttpProject } from '../../models/HttpProject.js';
2
+ import { Environment } from '../../models/Environment.js';
3
+ import { Logger } from '../../lib/logging/Logger.js';
4
+ import { IRequestLog } from '../../models/RequestLog.js';
5
+
6
+ export interface ProjectRunnerOptions {
7
+ /**
8
+ * When provided it overrides any project / folder defined environment.
9
+ */
10
+ environment?: Environment;
11
+ /**
12
+ * Additional variables to pass to the selected environment.
13
+ * This can be use to pass system variables, when needed.
14
+ *
15
+ * To use system variables tou can use `init.variables = process.env`;
16
+ */
17
+ variables?: Record<string, string>;
18
+ /**
19
+ * Overrides the default logger (console).
20
+ */
21
+ logger?: Logger;
22
+ /**
23
+ * The event target to use.
24
+ * By default it creates its own target.
25
+ */
26
+ eventTarget?: EventTarget;
27
+ }
28
+
29
+ export interface ProjectRunnerRunOptions extends IProjectRequestIterator {
30
+ }
31
+
32
+ export interface RunResult {
33
+ /**
34
+ * The key of the request from the HttpProject that was executed.
35
+ */
36
+ key: string;
37
+ /**
38
+ * The key of parent folder of the executed request.
39
+ */
40
+ parent?: string;
41
+ /**
42
+ * Set when a fatal error occurred so the request couldn't be executed.
43
+ * This is not the same as error reported during a request. The log's response can still be IResponseError.
44
+ */
45
+ error?: boolean;
46
+ /**
47
+ * The error message. Always set when the `error` is `true`.
48
+ */
49
+ errorMessage?: string;
50
+ /**
51
+ * The request log.
52
+ * Always set when the `error` is `false`.
53
+ */
54
+ log?: IRequestLog;
55
+ }
56
+
57
+ export interface IProjectParallelRunnerOptions extends IProjectRunnerOptions {
58
+ }
59
+
60
+ export interface IProjectParallelWorkerOptions extends IProjectRunnerOptions {
61
+ project: IHttpProject;
62
+ }
63
+
64
+ export interface IProjectRunnerOptions {
65
+ /**
66
+ * The environment to use.
67
+ * This can be a name or the key of the environment located under the parent or root.
68
+ * It can also be a path to the environment definition. If the file exists it is used. Otherwise it tried to
69
+ * find the environment in the project.
70
+ */
71
+ environment?: string;
72
+ /**
73
+ * The parent folder to execute.
74
+ */
75
+ parent?: string;
76
+ /**
77
+ * The names or the keys of requests to execute.
78
+ * This can be used to limit the number of requests.
79
+ */
80
+ request?: string[];
81
+ /**
82
+ * The number of times the execution should be repeated.
83
+ * Default to 1.
84
+ */
85
+ iterations?: number;
86
+ /**
87
+ * The number of milliseconds to wait between each iteration.
88
+ * Default to the next frame (vary from 1 to tens of milliseconds).
89
+ */
90
+ iterationDelay?: number;
91
+ /**
92
+ * When set it performs parallel execution for each iteration.
93
+ * The number of executions at the same time depends on the number of processor cores
94
+ * available on the current machine. The maximum of the parallel execution
95
+ * is the number of available cores. When the `iterations` number is higher
96
+ * then the "rest" is added to the iterations per each core.
97
+ */
98
+ parallel?: boolean;
99
+ /**
100
+ * When set it includes requests in the current folder and sub-folder according to the order
101
+ * defined in the folder.
102
+ */
103
+ recursive?: boolean;
104
+ /**
105
+ * The opposite of the `requests`. The list of names or keys of requests or folders to ignore.
106
+ * Note, ignore is tested before the `requests`.
107
+ */
108
+ ignore?: string[];
109
+ /**
110
+ * The logger to use with the request factory.
111
+ * When not set it uses the dummy logger (no output).
112
+ */
113
+ logger?: Logger;
114
+ /**
115
+ * When true it copies all system variables to the execution environment.
116
+ * When an array of strings, only takes system variables that are listed in the array.
117
+ * When a map, it uses this map as a list of variables.
118
+ * When not set it does not read system variables.
119
+ */
120
+ variables?: boolean | string[] | Record<string, string>;
121
+ }
@@ -2,10 +2,10 @@ import cluster, { Worker } from 'cluster';
2
2
  import { cpus } from 'os';
3
3
  import { dirname, join } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- import { HttpProject, IHttpProject } from '../../models/HttpProject.js';
6
- import { IProjectRunnerOptions } from './ProjectRunner.js';
5
+ import { HttpProject } from '../../models/HttpProject.js';
7
6
  import { IProjectExecutionLog, IProjectExecutionIteration } from '../reporters/Reporter.js';
8
7
  import { BaseRunner } from './BaseRunner.js';
8
+ import { IProjectParallelRunnerOptions, IProjectParallelWorkerOptions } from './InteropInterfaces.js'
9
9
 
10
10
  const numCPUs = cpus().length;
11
11
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -40,13 +40,6 @@ export interface IWorkerMessage {
40
40
  data?: unknown;
41
41
  }
42
42
 
43
- export interface IProjectParallelRunnerOptions extends IProjectRunnerOptions {
44
- }
45
-
46
- export interface IProjectParallelWorkerOptions extends IProjectRunnerOptions {
47
- project: IHttpProject;
48
- }
49
-
50
43
  export interface ProjectParallelRunner {
51
44
  /**
52
45
  * Dispatched when a status of a worker change.
@@ -6,64 +6,14 @@ import { Property } from '../../models/Property.js';
6
6
  import { ProjectFolder, Kind as ProjectFolderKind } from '../../models/ProjectFolder.js';
7
7
  import { ProjectRequest } from '../../models/ProjectRequest.js';
8
8
  import { IHttpRequest } from '../../models/HttpRequest.js';
9
- import { HttpProject, IProjectRequestIterator } from '../../models/HttpProject.js';
9
+ import { HttpProject } from '../../models/HttpProject.js';
10
10
  import { SentRequest } from '../../models/SentRequest.js';
11
11
  import { ErrorResponse } from '../../models/ErrorResponse.js';
12
12
  import { VariablesStore } from './VariablesStore.js';
13
13
  import { VariablesProcessor } from '../variables/VariablesProcessor.js';
14
14
  import { RequestFactory } from './RequestFactory.js';
15
15
  import { EventTypes } from '../../events/EventTypes.js';
16
-
17
- export interface ProjectRunnerOptions {
18
- /**
19
- * When provided it overrides any project / folder defined environment.
20
- */
21
- environment?: Environment;
22
- /**
23
- * Additional variables to pass to the selected environment.
24
- * This can be use to pass system variables, when needed.
25
- *
26
- * To use system variables tou can use `init.variables = process.env`;
27
- */
28
- variables?: Record<string, string>;
29
- /**
30
- * Overrides the default logger (console).
31
- */
32
- logger?: Logger;
33
- /**
34
- * The event target to use.
35
- * By default it creates its own target.
36
- */
37
- eventTarget?: EventTarget;
38
- }
39
-
40
- export interface ProjectRunnerRunOptions extends IProjectRequestIterator {
41
- }
42
-
43
- export interface RunResult {
44
- /**
45
- * The key of the request from the HttpProject that was executed.
46
- */
47
- key: string;
48
- /**
49
- * The key of parent folder of the executed request.
50
- */
51
- parent?: string;
52
- /**
53
- * Set when a fatal error occurred so the request couldn't be executed.
54
- * This is not the same as error reported during a request. The log's response can still be IResponseError.
55
- */
56
- error?: boolean;
57
- /**
58
- * The error message. Always set when the `error` is `true`.
59
- */
60
- errorMessage?: string;
61
- /**
62
- * The request log.
63
- * Always set when the `error` is `false`.
64
- */
65
- log?: IRequestLog;
66
- }
16
+ import { ProjectRunnerOptions, ProjectRunnerRunOptions, RunResult } from './InteropInterfaces.js';
67
17
 
68
18
  export interface ProjectRequestRunner {
69
19
  /**
@@ -130,20 +80,50 @@ export class ProjectRequestRunner extends EventEmitter {
130
80
  const { project } = this;
131
81
  const executed: RunResult[] = [];
132
82
  for (const request of project.requestIterator(options)) {
133
- const parent = request.getParent() || project;
134
- let variables: Record<string, string>;
135
- if (VariablesStore.has(parent)) {
136
- variables = VariablesStore.get(parent);
137
- } else {
138
- variables = await this.getVariables(parent);
139
- VariablesStore.set(parent, variables);
140
- }
141
- const info = await this.execute(request, variables);
83
+ const info = await this._runItem(request);
142
84
  executed.push(info);
143
85
  }
144
86
  return executed;
145
87
  }
146
88
 
89
+ /**
90
+ * Allows to iterate over project requests recursively and execute each request
91
+ * in order. The generator yields the `RunResult` for the request.
92
+ *
93
+ * Example:
94
+ *
95
+ * ```javascript
96
+ * const runner = new ProjectRequestRunner(...);
97
+ * for await (let runResult of runner) {
98
+ * console.log(runResult);
99
+ * }
100
+ * ```
101
+ */
102
+ async* [Symbol.asyncIterator](): AsyncGenerator<RunResult> {
103
+ const { project } = this;
104
+ for (const request of project.requestIterator({ recursive: true })) {
105
+ const info = await this._runItem(request);
106
+ yield info;
107
+ }
108
+ }
109
+
110
+ private async _runItem(request: ProjectRequest): Promise<RunResult> {
111
+ const folder = request.getParent();
112
+ const parent = folder || this.project;
113
+ let variables: Record<string, string>;
114
+ if (VariablesStore.has(parent)) {
115
+ variables = VariablesStore.get(parent);
116
+ } else {
117
+ variables = await this.getVariables(parent);
118
+ VariablesStore.set(parent, variables);
119
+ }
120
+ const info = await this.execute(request, variables);
121
+ if (folder && folder !== this.project) {
122
+ info.parent = folder.key;
123
+ }
124
+ return info;
125
+ }
126
+
147
127
  protected async execute(request: ProjectRequest, variables: Record<string, string>): Promise<RunResult> {
148
128
  const config = request.getConfig();
149
129
  const factory = new RequestFactory(this.eventTarget);
@@ -189,6 +169,7 @@ export class ProjectRequestRunner extends EventEmitter {
189
169
  this.emit('request', request.key, { ...requestCopy });
190
170
  await factory.processRequestLogic(requestCopy);
191
171
  const result = await factory.executeRequest(requestCopy);
172
+ result.requestId = request.key;
192
173
  await factory.processResponse(result);
193
174
  request.setLog(result);
194
175
  info.log = result;