@flighthq/net 0.5.1-next.1069.554a2ac → 0.5.1-next.1201.9b49dee
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/README.md +2 -2
- package/dist/net.d.ts +2 -2
- package/dist/net.d.ts.map +1 -1
- package/dist/net.js +4 -4
- package/dist/net.js.map +1 -1
- package/package.json +3 -3
- package/src/enableNetGuards.test.ts +9 -7
- package/src/net.test.ts +9 -7
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/net`. The `@flighthq
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/net@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/net@0.5.1-next.1201.9b49dee](https://github.com/flighthq/flight/tree/9b49dee3f22f6b2838c3d237edcc77bca65734f2/packages/net)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/9b49dee3f22f6b2838c3d237edcc77bca65734f2/LICENSE.md)
|
package/dist/net.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostNetProvider, NetGuard, NetRequest, NetRequestOptions, NetResponse, NetResponseExplanation } from '@flighthq/types/contract';
|
|
2
2
|
export declare function explainNetResponse(response: Readonly<NetResponse>): NetResponseExplanation | null;
|
|
3
|
-
export declare function sendNetRequest(
|
|
3
|
+
export declare function sendNetRequest(hostNet: Readonly<HostNetProvider>, request: Readonly<NetRequest>, options?: Readonly<NetRequestOptions>): Promise<NetResponse>;
|
|
4
4
|
export declare function setNetGuard(guard: NetGuard | null): void;
|
|
5
5
|
//# sourceMappingURL=net.d.ts.map
|
package/dist/net.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EAEvB,MAAM,0BAA0B,CAAC;AAIlC,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,sBAAsB,GAAG,IAAI,CAejG;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,EAClC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAC7B,OAAO,CAAC,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GACpC,OAAO,CAAC,WAAW,CAAC,CA4BtB;AAID,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAExD"}
|
package/dist/net.js
CHANGED
|
@@ -16,10 +16,10 @@ export function explainNetResponse(response) {
|
|
|
16
16
|
}
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
export function sendNetRequest(
|
|
19
|
+
export function sendNetRequest(hostNet, request, options) {
|
|
20
20
|
const guard = _guard;
|
|
21
21
|
if (guard === null)
|
|
22
|
-
return
|
|
22
|
+
return hostNet.sendNetRequest(request, options);
|
|
23
23
|
const method = request.method.toUpperCase();
|
|
24
24
|
if ((method === 'GET' || method === 'HEAD') && request.body !== undefined && request.body !== null) {
|
|
25
25
|
guard({ operation: 'sendNetRequest', reason: 'body-on-get-or-head', request });
|
|
@@ -29,7 +29,7 @@ export function sendNetRequest(host, request, options) {
|
|
|
29
29
|
}
|
|
30
30
|
const progress = options?.progress;
|
|
31
31
|
if (progress === undefined)
|
|
32
|
-
return
|
|
32
|
+
return hostNet.sendNetRequest(request, options);
|
|
33
33
|
let emitted = false;
|
|
34
34
|
const guardedProgress = {
|
|
35
35
|
...progress,
|
|
@@ -38,7 +38,7 @@ export function sendNetRequest(host, request, options) {
|
|
|
38
38
|
progress.emit(value);
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
|
-
return
|
|
41
|
+
return hostNet.sendNetRequest(request, { ...options, progress: guardedProgress }).then((response) => {
|
|
42
42
|
if (!emitted && response.status !== 0) {
|
|
43
43
|
guard({ operation: 'sendNetRequest', reason: 'progress-not-emitted', request });
|
|
44
44
|
}
|
package/dist/net.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.js","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAUA,+FAA+F;AAC/F,uEAAuE;AACvE,MAAM,UAAU,kBAAkB,CAAC,QAA+B;IAChE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC;QACjH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACjG,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO;YACL,MAAM,EAAE,gBAAgB;YACxB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,GAAG,EAAE,QAAQ,CAAC,GAAG;SAClB,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AAC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AAK,CAAC;AACjB,CAAC;AAED,IAAI,MAAM,GAAoB,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/net",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.1201.9b49dee",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/log": "0.5.1-next.
|
|
42
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/log": "0.5.1-next.1201.9b49dee",
|
|
42
|
+
"@flighthq/types": "0.5.1-next.1201.9b49dee"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { addLogSink, createMemoryLogSink, getMemoryLogSinkEntries, removeLogSink } from '@flighthq/log/contract';
|
|
2
|
-
import type {
|
|
2
|
+
import type { HostNetProvider, LogEntry, NetResponse } from '@flighthq/types/contract';
|
|
3
3
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
4
4
|
|
|
5
5
|
import { areNetGuardsEnabled, disableNetGuards, enableNetGuards } from './enableNetGuards';
|
|
@@ -13,7 +13,9 @@ function captureLog(run: () => Promise<void>): Promise<readonly LogEntry[]> {
|
|
|
13
13
|
.finally(() => removeLogSink(sink.sink));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function hostOf(sendNetRequestBackend:
|
|
16
|
+
function hostOf(sendNetRequestBackend: HostNetProvider['sendNetRequest']): {
|
|
17
|
+
readonly net: { readonly http: HostNetProvider };
|
|
18
|
+
} {
|
|
17
19
|
return {
|
|
18
20
|
net: {
|
|
19
21
|
http: { [EntityRuntimeKey]: undefined, sendNetRequest: sendNetRequestBackend },
|
|
@@ -44,7 +46,7 @@ describe('disableNetGuards', () => {
|
|
|
44
46
|
disableNetGuards();
|
|
45
47
|
const host = hostOf(async () => stubResponse());
|
|
46
48
|
const entries = await captureLog(async () => {
|
|
47
|
-
await sendNetRequest(host, { body: 'ignored', method: 'GET', timeoutMs: -1, url: 'u' });
|
|
49
|
+
await sendNetRequest(host.net.http, { body: 'ignored', method: 'GET', timeoutMs: -1, url: 'u' });
|
|
48
50
|
});
|
|
49
51
|
expect(entries).toEqual([]);
|
|
50
52
|
});
|
|
@@ -55,8 +57,8 @@ describe('enableNetGuards', () => {
|
|
|
55
57
|
enableNetGuards();
|
|
56
58
|
const host = hostOf(async () => stubResponse());
|
|
57
59
|
const entries = await captureLog(async () => {
|
|
58
|
-
await sendNetRequest(host, { body: 'ignored', method: 'GET', timeoutMs: -1, url: 'u' });
|
|
59
|
-
await sendNetRequest(host, { body: 'ignored again', method: 'HEAD', timeoutMs: -2, url: 'v' });
|
|
60
|
+
await sendNetRequest(host.net.http, { body: 'ignored', method: 'GET', timeoutMs: -1, url: 'u' });
|
|
61
|
+
await sendNetRequest(host.net.http, { body: 'ignored again', method: 'HEAD', timeoutMs: -2, url: 'v' });
|
|
60
62
|
});
|
|
61
63
|
expect(entries).toHaveLength(2);
|
|
62
64
|
expect(entries.map((entry) => (entry.data as Record<string, unknown>).reason)).toEqual([
|
|
@@ -74,7 +76,7 @@ describe('enableNetGuards', () => {
|
|
|
74
76
|
emit() {},
|
|
75
77
|
};
|
|
76
78
|
const entries = await captureLog(async () => {
|
|
77
|
-
await sendNetRequest(host, { method: 'GET', url: 'u' }, { progress });
|
|
79
|
+
await sendNetRequest(host.net.http, { method: 'GET', url: 'u' }, { progress });
|
|
78
80
|
});
|
|
79
81
|
expect(entries).toHaveLength(1);
|
|
80
82
|
expect(entries[0]).toMatchObject({ channel: 'net' });
|
|
@@ -93,7 +95,7 @@ describe('enableNetGuards', () => {
|
|
|
93
95
|
return stubResponse();
|
|
94
96
|
});
|
|
95
97
|
const entries = await captureLog(async () => {
|
|
96
|
-
await sendNetRequest(host, { method: 'GET', url: 'u' }, { progress });
|
|
98
|
+
await sendNetRequest(host.net.http, { method: 'GET', url: 'u' }, { progress });
|
|
97
99
|
});
|
|
98
100
|
expect(entries).toEqual([]);
|
|
99
101
|
});
|
package/src/net.test.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostNetProvider, NetGuardNotice, NetRequest, NetResponse } from '@flighthq/types/contract';
|
|
2
2
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import * as netContract from './net';
|
|
5
5
|
import { explainNetResponse, sendNetRequest, setNetGuard } from './net';
|
|
6
6
|
|
|
7
|
-
function fakeHost(backend?: Pick<
|
|
7
|
+
function fakeHost(backend?: Pick<HostNetProvider, 'sendNetRequest'>): {
|
|
8
|
+
readonly net: { readonly http: HostNetProvider };
|
|
9
|
+
} {
|
|
8
10
|
return {
|
|
9
11
|
net: {
|
|
10
12
|
http: {
|
|
@@ -67,7 +69,7 @@ describe('R3 boundary', () => {
|
|
|
67
69
|
describe('sendNetRequest', () => {
|
|
68
70
|
it('dispatches through the host backend and passes options', async () => {
|
|
69
71
|
let received: { request?: Readonly<NetRequest>; options?: unknown } = {};
|
|
70
|
-
const backend: Pick<
|
|
72
|
+
const backend: Pick<HostNetProvider, 'sendNetRequest'> = {
|
|
71
73
|
sendNetRequest: async (request, options) => {
|
|
72
74
|
received = { request, options };
|
|
73
75
|
return stubResponse();
|
|
@@ -76,7 +78,7 @@ describe('sendNetRequest', () => {
|
|
|
76
78
|
const host = fakeHost(backend);
|
|
77
79
|
const request: NetRequest = { method: 'GET', url: 'https://example.test' };
|
|
78
80
|
const options = {};
|
|
79
|
-
await sendNetRequest(host, request, options);
|
|
81
|
+
await sendNetRequest(host.net.http, request, options);
|
|
80
82
|
expect(received.request).toBe(request);
|
|
81
83
|
expect(received.options).toBe(options);
|
|
82
84
|
});
|
|
@@ -84,7 +86,7 @@ describe('sendNetRequest', () => {
|
|
|
84
86
|
it('passes the response through unchanged', async () => {
|
|
85
87
|
const response = stubResponse();
|
|
86
88
|
const host = fakeHost({ sendNetRequest: async () => response });
|
|
87
|
-
const result = await sendNetRequest(host, { method: 'GET', url: 'u' });
|
|
89
|
+
const result = await sendNetRequest(host.net.http, { method: 'GET', url: 'u' });
|
|
88
90
|
expect(result).toBe(response);
|
|
89
91
|
});
|
|
90
92
|
});
|
|
@@ -94,9 +96,9 @@ describe('setNetGuard', () => {
|
|
|
94
96
|
const notices: NetGuardNotice[] = [];
|
|
95
97
|
setNetGuard((notice) => notices.push(notice));
|
|
96
98
|
const host = fakeHost();
|
|
97
|
-
await sendNetRequest(host, { body: 'x', method: 'get', timeoutMs: -1, url: 'u' });
|
|
99
|
+
await sendNetRequest(host.net.http, { body: 'x', method: 'get', timeoutMs: -1, url: 'u' });
|
|
98
100
|
setNetGuard(null);
|
|
99
|
-
await sendNetRequest(host, { body: 'x', method: 'HEAD', url: 'v' });
|
|
101
|
+
await sendNetRequest(host.net.http, { body: 'x', method: 'HEAD', url: 'v' });
|
|
100
102
|
expect(notices.map((notice) => notice.reason)).toEqual(['body-on-get-or-head', 'negative-timeout']);
|
|
101
103
|
});
|
|
102
104
|
});
|