@danceroutine/tango-core 0.1.0 → 1.0.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/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/{TangoError-NPkVPfuH.js → TangoError-DdQVQNZU.js} +5 -1
- package/dist/TangoError-DdQVQNZU.js.map +1 -0
- package/dist/errors/AuthenticationError.d.ts +6 -1
- package/dist/errors/ConflictError.d.ts +6 -1
- package/dist/errors/NotFoundError.d.ts +6 -1
- package/dist/errors/PermissionDenied.d.ts +6 -1
- package/dist/errors/TangoError.d.ts +13 -1
- package/dist/errors/ValidationError.d.ts +5 -1
- package/dist/errors/factories/HttpErrorFactory.d.ts +20 -11
- package/dist/errors/factories/index.d.ts +1 -1
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +4 -4
- package/dist/{errors-CzSQXdgI.js → errors-_tWsmNyZ.js} +81 -34
- package/dist/errors-_tWsmNyZ.js.map +1 -0
- package/dist/http/TangoBody.d.ts +43 -18
- package/dist/http/TangoHeaders.d.ts +10 -5
- package/dist/http/TangoQueryParams.d.ts +69 -0
- package/dist/http/TangoRequest.d.ts +82 -0
- package/dist/http/TangoResponse.d.ts +184 -49
- package/dist/http/index.d.ts +2 -1
- package/dist/http/index.js +4 -4
- package/dist/{http-DOLwwAYt.js → http-D20MQa6p.js} +675 -295
- package/dist/http-D20MQa6p.js.map +1 -0
- package/dist/index.d.ts +9 -7
- package/dist/index.js +7 -6
- package/dist/logging/ConsoleLogger.d.ts +15 -0
- package/dist/logging/Logger.d.ts +13 -0
- package/dist/logging/getLogger.d.ts +23 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging-BWeD4HOO.js +48 -0
- package/dist/logging-BWeD4HOO.js.map +1 -0
- package/dist/runtime/binary/isArrayBuffer.d.ts +3 -0
- package/dist/runtime/binary/isBlob.d.ts +3 -0
- package/dist/runtime/binary/isUint8Array.d.ts +3 -0
- package/dist/runtime/date/isDate.d.ts +3 -0
- package/dist/runtime/error/isError.d.ts +3 -0
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/object/index.d.ts +1 -0
- package/dist/runtime/object/isNil.d.ts +4 -0
- package/dist/runtime/object/isObject.d.ts +3 -0
- package/dist/runtime/web/isFile.d.ts +3 -0
- package/dist/runtime/web/isFormData.d.ts +3 -0
- package/dist/runtime/web/isReadableStream.d.ts +3 -0
- package/dist/runtime/web/isURLSearchParams.d.ts +3 -0
- package/dist/{runtime-DPpCYEe_.js → runtime-B8KkgD3R.js} +14 -4
- package/dist/runtime-B8KkgD3R.js.map +1 -0
- package/dist/sql/SqlDialect.d.ts +5 -0
- package/dist/sql/SqlIdentifierRole.d.ts +13 -0
- package/dist/sql/SqlSafetyEngine.d.ts +50 -0
- package/dist/sql/TrustedSqlFragment.d.ts +5 -0
- package/dist/sql/ValidatedSqlIdentifier.d.ts +7 -0
- package/dist/sql/index.d.ts +13 -0
- package/dist/sql/index.js +3 -0
- package/dist/sql/isTrustedSqlFragment.d.ts +5 -0
- package/dist/sql/quoteSqlIdentifier.d.ts +6 -0
- package/dist/sql/trustedSql.d.ts +5 -0
- package/dist/sql/validateSqlIdentifier.d.ts +6 -0
- package/dist/sql-D3frkfy-.js +116 -0
- package/dist/sql-D3frkfy-.js.map +1 -0
- package/package.json +65 -54
- package/dist/TangoError-NPkVPfuH.js.map +0 -1
- package/dist/errors/factories/HttpErrorFactory.js +0 -91
- package/dist/errors-CzSQXdgI.js.map +0 -1
- package/dist/http/TangoHeaders.js +0 -396
- package/dist/http/TangoResponse.js +0 -556
- package/dist/http-DOLwwAYt.js.map +0 -1
- package/dist/result/Err.d.ts +0 -21
- package/dist/result/Ok.d.ts +0 -21
- package/dist/result/Result.d.ts +0 -33
- package/dist/result/index.d.ts +0 -8
- package/dist/result/index.js +0 -3
- package/dist/result-CBqw9Hlg.js +0 -82
- package/dist/result-CBqw9Hlg.js.map +0 -1
- package/dist/runtime-DPpCYEe_.js.map +0 -1
package/dist/http/TangoBody.d.ts
CHANGED
|
@@ -7,9 +7,13 @@ type HeadersLike = {
|
|
|
7
7
|
get?: (arg: string) => string | null;
|
|
8
8
|
};
|
|
9
9
|
type TangoBodySource = BodyInit | JsonValue | null;
|
|
10
|
+
/** Recursive JSON value contract used by Tango HTTP helpers. */
|
|
10
11
|
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
11
12
|
[key: string]: JsonValue;
|
|
12
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Unified body reader/clone utility for Tango request/response wrappers.
|
|
16
|
+
*/
|
|
13
17
|
export declare class TangoBody {
|
|
14
18
|
static readonly BRAND: "tango.http.body";
|
|
15
19
|
readonly __tangoBrand: typeof TangoBody.BRAND;
|
|
@@ -17,14 +21,53 @@ export declare class TangoBody {
|
|
|
17
21
|
private bodyUsedInternal;
|
|
18
22
|
private headers?;
|
|
19
23
|
constructor(bodySource: TangoBodySource, headers?: HeadersLike);
|
|
24
|
+
/**
|
|
25
|
+
* Narrow an unknown value to `TangoBody`.
|
|
26
|
+
*/
|
|
20
27
|
static isTangoBody(value: unknown): value is TangoBody;
|
|
28
|
+
/**
|
|
29
|
+
* Expose the original body source for cloning and adapter integration.
|
|
30
|
+
*/
|
|
21
31
|
get bodySource(): TangoBodySource;
|
|
32
|
+
/**
|
|
33
|
+
* Report whether a reader method has already consumed this body.
|
|
34
|
+
*/
|
|
22
35
|
get bodyUsed(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Describe the current body shape in a way that is useful for diagnostics.
|
|
38
|
+
*/
|
|
23
39
|
get bodyType(): string;
|
|
24
40
|
/**
|
|
25
41
|
* Returns true if value is a valid JSON value (recursively).
|
|
26
42
|
*/
|
|
27
43
|
static isJsonValue(v: unknown): v is JsonValue;
|
|
44
|
+
/**
|
|
45
|
+
* Deep clone utility for body values. Preserves types and values as in the legacy implementation.
|
|
46
|
+
* If the source is a stream, the stream will be cloned if readable, otherwise throws.
|
|
47
|
+
*/
|
|
48
|
+
static deepCloneBody(body: TangoBodySource): TangoBodySource;
|
|
49
|
+
/**
|
|
50
|
+
* Read a `ReadableStream` into an `ArrayBuffer`.
|
|
51
|
+
*/
|
|
52
|
+
static readStreamToArrayBuffer(stream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>;
|
|
53
|
+
/**
|
|
54
|
+
* Read a `ReadableStream` into a `Uint8Array`.
|
|
55
|
+
*/
|
|
56
|
+
static readStreamToUint8Array(stream: ReadableStream<Uint8Array>): Promise<Uint8Array<ArrayBuffer>>;
|
|
57
|
+
/**
|
|
58
|
+
* Read a `ReadableStream` into UTF-8 text.
|
|
59
|
+
*/
|
|
60
|
+
static readStreamToText(stream: ReadableStream<Uint8Array>): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Determine the content type for this body, if possible.
|
|
63
|
+
* Respects an explicitly passed header, otherwise infers from value type.
|
|
64
|
+
*/
|
|
65
|
+
static detectContentType(body: TangoBodySource, providedType?: string): string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Attempt to determine the content length, in bytes, for this body.
|
|
68
|
+
* Only available for certain body types, otherwise returns undefined.
|
|
69
|
+
*/
|
|
70
|
+
static getContentLength(body: TangoBodySource): Promise<number | undefined>;
|
|
28
71
|
/**
|
|
29
72
|
* Reads the body as an ArrayBuffer.
|
|
30
73
|
*/
|
|
@@ -54,11 +97,6 @@ export declare class TangoBody {
|
|
|
54
97
|
* Returns the original body value (may be used for streaming or clone).
|
|
55
98
|
*/
|
|
56
99
|
getRawBodyInit(): TangoBodySource;
|
|
57
|
-
/**
|
|
58
|
-
* Deep clone utility for body values. Preserves types and values as in the legacy implementation.
|
|
59
|
-
* If the source is a stream, the stream will be cloned if readable, otherwise throws.
|
|
60
|
-
*/
|
|
61
|
-
static deepCloneBody(body: TangoBodySource): TangoBodySource;
|
|
62
100
|
/**
|
|
63
101
|
* Clone the body instance and stream if possible.
|
|
64
102
|
* If the source is a stream, the stream will be cloned if readable, otherwise throws.
|
|
@@ -68,18 +106,5 @@ export declare class TangoBody {
|
|
|
68
106
|
* Helper for all readers. Only allows reading once.
|
|
69
107
|
*/
|
|
70
108
|
private consumeBody;
|
|
71
|
-
static readStreamToArrayBuffer(stream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>;
|
|
72
|
-
static readStreamToUint8Array(stream: ReadableStream<Uint8Array>): Promise<Uint8Array<ArrayBuffer>>;
|
|
73
|
-
static readStreamToText(stream: ReadableStream<Uint8Array>): Promise<string>;
|
|
74
|
-
/**
|
|
75
|
-
* Determine the content type for this body, if possible.
|
|
76
|
-
* Respects an explicitly passed header, otherwise infers from value type.
|
|
77
|
-
*/
|
|
78
|
-
static detectContentType(body: TangoBodySource, providedType?: string): string | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* Attempt to determine the content length, in bytes, for this body.
|
|
81
|
-
* Only available for certain body types, otherwise returns undefined.
|
|
82
|
-
*/
|
|
83
|
-
static getContentLength(body: TangoBodySource): Promise<number | undefined>;
|
|
84
109
|
}
|
|
85
110
|
export {};
|
|
@@ -15,8 +15,14 @@
|
|
|
15
15
|
export declare class TangoHeaders extends Headers {
|
|
16
16
|
static readonly BRAND: "tango.http.headers";
|
|
17
17
|
readonly __tangoBrand: typeof TangoHeaders.BRAND;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Narrow an unknown value to `TangoHeaders`.
|
|
20
|
+
*/
|
|
19
21
|
static isTangoHeaders(value: unknown): value is TangoHeaders;
|
|
22
|
+
/**
|
|
23
|
+
* Serialize a cookie for the Set-Cookie header line.
|
|
24
|
+
*/
|
|
25
|
+
private static serializeCookie;
|
|
20
26
|
private static hasNumberSize;
|
|
21
27
|
private static hasNumberLength;
|
|
22
28
|
private static isNodeBuffer;
|
|
@@ -35,6 +41,9 @@ export declare class TangoHeaders extends Headers {
|
|
|
35
41
|
* @param filename The filename to include in the Content-Disposition header.
|
|
36
42
|
*/
|
|
37
43
|
setContentDispositionAttachment(filename: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Create a copy that preserves all header names and values.
|
|
46
|
+
*/
|
|
38
47
|
clone(): TangoHeaders;
|
|
39
48
|
/**
|
|
40
49
|
* Set a header, replacing the existing value.
|
|
@@ -106,10 +115,6 @@ export declare class TangoHeaders extends Headers {
|
|
|
106
115
|
priority?: 'Low' | 'Medium' | 'High';
|
|
107
116
|
partitioned?: boolean;
|
|
108
117
|
}): void;
|
|
109
|
-
/**
|
|
110
|
-
* Serialize a cookie for the Set-Cookie header line.
|
|
111
|
-
*/
|
|
112
|
-
private static serializeCookie;
|
|
113
118
|
/**
|
|
114
119
|
* Add or override Cache-Control header with helpers for common policies.
|
|
115
120
|
*/
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { TangoRequest } from './TangoRequest';
|
|
2
|
+
type QueryParamRecord = Record<string, string | string[] | undefined>;
|
|
3
|
+
/**
|
|
4
|
+
* Immutable query parameter helper that normalizes framework-specific shapes
|
|
5
|
+
* into one Tango-owned API.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TangoQueryParams {
|
|
8
|
+
static readonly BRAND: "tango.http.query_params";
|
|
9
|
+
readonly __tangoBrand: typeof TangoQueryParams.BRAND;
|
|
10
|
+
private readonly values;
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Narrow an unknown value to `TangoQueryParams`.
|
|
14
|
+
*/
|
|
15
|
+
static isTangoQueryParams(value: unknown): value is TangoQueryParams;
|
|
16
|
+
/**
|
|
17
|
+
* Build query params from a `URLSearchParams` instance.
|
|
18
|
+
*/
|
|
19
|
+
static fromURLSearchParams(params: URLSearchParams): TangoQueryParams;
|
|
20
|
+
/**
|
|
21
|
+
* Build query params from framework record-style search params.
|
|
22
|
+
*/
|
|
23
|
+
static fromRecord(params: QueryParamRecord): TangoQueryParams;
|
|
24
|
+
/**
|
|
25
|
+
* Build query params from a full URL string or URL object.
|
|
26
|
+
*/
|
|
27
|
+
static fromURL(input: string | URL): TangoQueryParams;
|
|
28
|
+
/**
|
|
29
|
+
* Build query params from a request-like object with a URL.
|
|
30
|
+
*/
|
|
31
|
+
static fromRequest(request: Request | TangoRequest): TangoQueryParams;
|
|
32
|
+
/**
|
|
33
|
+
* Get the first value for a query param.
|
|
34
|
+
*/
|
|
35
|
+
get(name: string): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Get all values for a query param.
|
|
38
|
+
*/
|
|
39
|
+
getAll(name: string): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Check whether a query param exists.
|
|
42
|
+
*/
|
|
43
|
+
has(name: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Iterate key -> values entries.
|
|
46
|
+
*/
|
|
47
|
+
entries(): IterableIterator<[string, string[]]>;
|
|
48
|
+
/**
|
|
49
|
+
* Iterate keys present in the query params.
|
|
50
|
+
*/
|
|
51
|
+
keys(): IterableIterator<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Convert back to a native `URLSearchParams` object.
|
|
54
|
+
*/
|
|
55
|
+
toURLSearchParams(): URLSearchParams;
|
|
56
|
+
/**
|
|
57
|
+
* Get a trimmed value, omitting blank strings.
|
|
58
|
+
*/
|
|
59
|
+
getTrimmed(name: string): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Get the free-text search param using Tango's default key.
|
|
62
|
+
*/
|
|
63
|
+
getSearch(key?: string): string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Get the ordering param as trimmed field tokens.
|
|
66
|
+
*/
|
|
67
|
+
getOrdering(key?: string): string[];
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JsonValue } from './TangoBody';
|
|
2
|
+
import { TangoQueryParams } from './TangoQueryParams';
|
|
2
3
|
type TangoRequestInit = {
|
|
3
4
|
method?: string;
|
|
4
5
|
headers?: HeadersInit;
|
|
@@ -13,35 +14,116 @@ type TangoRequestInit = {
|
|
|
13
14
|
referrerPolicy?: ReferrerPolicy;
|
|
14
15
|
signal?: AbortSignal;
|
|
15
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Framework request wrapper that normalizes JSON-like bodies and preserves
|
|
19
|
+
* fetch `Request` compatibility for downstream handlers.
|
|
20
|
+
*/
|
|
16
21
|
export declare class TangoRequest implements Request {
|
|
17
22
|
static readonly BRAND: "tango.http.request";
|
|
18
23
|
readonly __tangoBrand: typeof TangoRequest.BRAND;
|
|
19
24
|
private request;
|
|
20
25
|
private bodySourceValue;
|
|
26
|
+
private queryParamsValue?;
|
|
21
27
|
constructor(input: string | Request, init?: TangoRequestInit);
|
|
28
|
+
/**
|
|
29
|
+
* Narrow an unknown value to `TangoRequest`.
|
|
30
|
+
*/
|
|
22
31
|
static isTangoRequest(value: unknown): value is TangoRequest;
|
|
32
|
+
/**
|
|
33
|
+
* Expose the request cache mode from the underlying fetch request.
|
|
34
|
+
*/
|
|
23
35
|
get cache(): RequestCache;
|
|
36
|
+
/**
|
|
37
|
+
* Expose the request credentials mode from the underlying fetch request.
|
|
38
|
+
*/
|
|
24
39
|
get credentials(): RequestCredentials;
|
|
40
|
+
/**
|
|
41
|
+
* Expose the request destination from the underlying fetch request.
|
|
42
|
+
*/
|
|
25
43
|
get destination(): RequestDestination;
|
|
44
|
+
/**
|
|
45
|
+
* Expose the request headers from the underlying fetch request.
|
|
46
|
+
*/
|
|
26
47
|
get headers(): Headers;
|
|
48
|
+
/**
|
|
49
|
+
* Expose the request integrity value from the underlying fetch request.
|
|
50
|
+
*/
|
|
27
51
|
get integrity(): string;
|
|
52
|
+
/**
|
|
53
|
+
* Expose the request keepalive flag from the underlying fetch request.
|
|
54
|
+
*/
|
|
28
55
|
get keepalive(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Expose the normalized HTTP method.
|
|
58
|
+
*/
|
|
29
59
|
get method(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Expose the request mode from the underlying fetch request.
|
|
62
|
+
*/
|
|
30
63
|
get mode(): RequestMode;
|
|
64
|
+
/**
|
|
65
|
+
* Expose the redirect policy from the underlying fetch request.
|
|
66
|
+
*/
|
|
31
67
|
get redirect(): RequestRedirect;
|
|
68
|
+
/**
|
|
69
|
+
* Expose the referrer from the underlying fetch request.
|
|
70
|
+
*/
|
|
32
71
|
get referrer(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Expose the referrer policy from the underlying fetch request.
|
|
74
|
+
*/
|
|
33
75
|
get referrerPolicy(): ReferrerPolicy;
|
|
76
|
+
/**
|
|
77
|
+
* Expose the abort signal from the underlying fetch request.
|
|
78
|
+
*/
|
|
34
79
|
get signal(): AbortSignal;
|
|
80
|
+
/**
|
|
81
|
+
* Expose the absolute request URL.
|
|
82
|
+
*/
|
|
35
83
|
get url(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Expose the readable request body stream when one exists.
|
|
86
|
+
*/
|
|
36
87
|
get body(): Request['body'];
|
|
88
|
+
/**
|
|
89
|
+
* Report whether the body has been consumed.
|
|
90
|
+
*/
|
|
37
91
|
get bodyUsed(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Expose the pre-normalized body value used to build the request.
|
|
94
|
+
*/
|
|
38
95
|
get bodySource(): BodyInit | JsonValue | null;
|
|
96
|
+
/**
|
|
97
|
+
* Expose normalized query parameters derived from the request URL.
|
|
98
|
+
*/
|
|
99
|
+
get queryParams(): TangoQueryParams;
|
|
100
|
+
/**
|
|
101
|
+
* Read the request body as an array buffer.
|
|
102
|
+
*/
|
|
39
103
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
104
|
+
/**
|
|
105
|
+
* Read the request body as a blob.
|
|
106
|
+
*/
|
|
40
107
|
blob(): Promise<Blob>;
|
|
108
|
+
/**
|
|
109
|
+
* Read the request body as bytes, including runtimes without `Request.bytes()`.
|
|
110
|
+
*/
|
|
41
111
|
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
112
|
+
/**
|
|
113
|
+
* Read the request body as form data.
|
|
114
|
+
*/
|
|
42
115
|
formData(): Promise<FormData>;
|
|
116
|
+
/**
|
|
117
|
+
* Parse the request body as JSON.
|
|
118
|
+
*/
|
|
43
119
|
json<T = unknown>(): Promise<T>;
|
|
120
|
+
/**
|
|
121
|
+
* Read the request body as text.
|
|
122
|
+
*/
|
|
44
123
|
text(): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Clone the request so downstream code can consume it independently.
|
|
126
|
+
*/
|
|
45
127
|
clone(): TangoRequest;
|
|
46
128
|
private normalizeBody;
|
|
47
129
|
}
|
|
@@ -11,10 +11,11 @@ type TangoResponseInit = {
|
|
|
11
11
|
type?: ResponseType;
|
|
12
12
|
url?: string;
|
|
13
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Framework response wrapper with fetch-compatible surface plus ergonomic helpers.
|
|
16
|
+
*/
|
|
14
17
|
export declare class TangoResponse implements Response {
|
|
15
18
|
static readonly BRAND: "tango.http.response";
|
|
16
|
-
private tangoBody;
|
|
17
|
-
private okValue;
|
|
18
19
|
readonly __tangoBrand: typeof TangoResponse.BRAND;
|
|
19
20
|
readonly headers: TangoHeaders;
|
|
20
21
|
readonly redirected: boolean;
|
|
@@ -23,107 +24,116 @@ export declare class TangoResponse implements Response {
|
|
|
23
24
|
readonly type: ResponseType;
|
|
24
25
|
readonly url: string;
|
|
25
26
|
readonly body: Response['body'];
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
private tangoBody;
|
|
28
|
+
private okValue;
|
|
28
29
|
constructor(init?: TangoResponseInit);
|
|
29
|
-
get ok(): boolean;
|
|
30
|
-
get bodyUsed(): boolean;
|
|
31
|
-
setHeader(name: string, value: string): void;
|
|
32
|
-
appendHeader(name: string, value: string): void;
|
|
33
|
-
getHeader(name: string): string | null;
|
|
34
|
-
hasHeader(name: string): boolean;
|
|
35
|
-
deleteHeader(name: string): void;
|
|
36
|
-
vary(...fields: string[]): void;
|
|
37
|
-
setCookie(name: string, value: string, options?: Parameters<TangoHeaders['setCookie']>[2]): void;
|
|
38
|
-
appendCookie(name: string, value: string, options?: Parameters<TangoHeaders['appendCookie']>[2]): void;
|
|
39
|
-
deleteCookie(name: string, options?: Parameters<TangoHeaders['deleteCookie']>[1]): void;
|
|
40
|
-
cacheControl(control: Parameters<TangoHeaders['cacheControl']>[0]): void;
|
|
41
|
-
location(url: string): void;
|
|
42
|
-
contentType(mime: string): void;
|
|
43
|
-
/**
|
|
44
|
-
* Set the X-Request-Id header (request correlation).
|
|
45
|
-
* Returns this for fluent chaining.
|
|
46
|
-
*/
|
|
47
|
-
withRequestId(requestId: string | undefined | null): this;
|
|
48
|
-
/**
|
|
49
|
-
* Set the traceparent header (W3C Trace Context propagation).
|
|
50
|
-
* Returns this for fluent chaining.
|
|
51
|
-
*/
|
|
52
|
-
withTraceparent(traceparent: string | undefined | null): this;
|
|
53
30
|
/**
|
|
54
|
-
*
|
|
55
|
-
* Accepts a string or array of timing metrics.
|
|
56
|
-
* Returns this for fluent chaining.
|
|
31
|
+
* Narrow an unknown value to `TangoResponse`.
|
|
57
32
|
*/
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Set the X-Response-Time header (in ms).
|
|
61
|
-
* Numeric or formatted string (e.g. "76ms").
|
|
62
|
-
* Returns this for fluent chaining.
|
|
63
|
-
*/
|
|
64
|
-
withResponseTime(time: number | string): this;
|
|
33
|
+
static isTangoResponse(value: unknown): value is TangoResponse;
|
|
65
34
|
/**
|
|
66
|
-
*
|
|
67
|
-
* Known headers: x-request-id, traceparent, server-timing
|
|
68
|
-
* Returns this for fluent chaining.
|
|
35
|
+
* Create a JSON response with sensible content headers.
|
|
69
36
|
*/
|
|
70
|
-
propagateTraceHeaders(input: HeadersInit): this;
|
|
71
37
|
static json(data: JsonValue, init?: Omit<TangoResponseInit, 'body' | 'headers'> & {
|
|
72
38
|
headers?: HeadersInit;
|
|
73
39
|
}): TangoResponse;
|
|
40
|
+
/**
|
|
41
|
+
* Create a plain-text response with sensible content headers.
|
|
42
|
+
*/
|
|
74
43
|
static text(text: string, init?: Omit<TangoResponseInit, 'body' | 'headers'> & {
|
|
75
44
|
headers?: HeadersInit;
|
|
76
45
|
}): TangoResponse;
|
|
46
|
+
/**
|
|
47
|
+
* Create an HTML response with sensible content headers.
|
|
48
|
+
*/
|
|
77
49
|
static html(html: string, init?: Omit<TangoResponseInit, 'body' | 'headers'> & {
|
|
78
50
|
headers?: HeadersInit;
|
|
79
51
|
}): TangoResponse;
|
|
52
|
+
/**
|
|
53
|
+
* Create a streaming response without buffering the payload in memory.
|
|
54
|
+
*/
|
|
80
55
|
static stream(stream: ReadableStream<Uint8Array>, init?: Omit<TangoResponseInit, 'body' | 'headers'> & {
|
|
81
56
|
headers?: HeadersInit;
|
|
82
57
|
}): TangoResponse;
|
|
58
|
+
/**
|
|
59
|
+
* Create a redirect response and set the `Location` header.
|
|
60
|
+
*/
|
|
83
61
|
static redirect(url: string, status?: number, init?: Omit<TangoResponseInit, 'body' | 'headers' | 'status'> & {
|
|
84
62
|
headers?: HeadersInit;
|
|
85
63
|
}): TangoResponse;
|
|
64
|
+
/**
|
|
65
|
+
* Create an empty `204 No Content` response.
|
|
66
|
+
*/
|
|
86
67
|
static noContent(init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
87
68
|
headers?: HeadersInit;
|
|
88
69
|
}): TangoResponse;
|
|
70
|
+
/**
|
|
71
|
+
* Create a `201 Created` response and optionally attach a location or body.
|
|
72
|
+
*/
|
|
89
73
|
static created(location?: string, body?: JsonValue, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
90
74
|
headers?: HeadersInit;
|
|
91
75
|
}): TangoResponse;
|
|
76
|
+
/**
|
|
77
|
+
* Create a `405 Method Not Allowed` response and optionally populate `Allow`.
|
|
78
|
+
*/
|
|
79
|
+
static methodNotAllowed(allow?: readonly string[], detail?: string, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
80
|
+
headers?: HeadersInit;
|
|
81
|
+
}): TangoResponse;
|
|
82
|
+
/**
|
|
83
|
+
* Normalize a Tango error or problem-details object into an error response.
|
|
84
|
+
*/
|
|
92
85
|
static error<TDetails extends ErrorDetails = null>(error: TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'headers'> & {
|
|
93
86
|
headers?: HeadersInit;
|
|
94
87
|
}): TangoResponse;
|
|
88
|
+
/**
|
|
89
|
+
* Create a `400 Bad Request` response from a string or structured error.
|
|
90
|
+
*/
|
|
95
91
|
static badRequest<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
96
92
|
headers?: HeadersInit;
|
|
97
93
|
}): TangoResponse;
|
|
94
|
+
/**
|
|
95
|
+
* Create a `401 Unauthorized` response from a string or structured error.
|
|
96
|
+
*/
|
|
98
97
|
static unauthorized<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
99
98
|
headers?: HeadersInit;
|
|
100
99
|
}): TangoResponse;
|
|
100
|
+
/**
|
|
101
|
+
* Create a `403 Forbidden` response from a string or structured error.
|
|
102
|
+
*/
|
|
101
103
|
static forbidden<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
102
104
|
headers?: HeadersInit;
|
|
103
105
|
}): TangoResponse;
|
|
106
|
+
/**
|
|
107
|
+
* Create a `404 Not Found` response from a string or structured error.
|
|
108
|
+
*/
|
|
104
109
|
static notFound<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
105
110
|
headers?: HeadersInit;
|
|
106
111
|
}): TangoResponse;
|
|
112
|
+
/**
|
|
113
|
+
* Create a `409 Conflict` response from a string or structured error.
|
|
114
|
+
*/
|
|
107
115
|
static conflict<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
108
116
|
headers?: HeadersInit;
|
|
109
117
|
}): TangoResponse;
|
|
118
|
+
/**
|
|
119
|
+
* Create a `422 Unprocessable Entity` response from a string or structured error.
|
|
120
|
+
*/
|
|
110
121
|
static unprocessableEntity<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
111
122
|
headers?: HeadersInit;
|
|
112
123
|
}): TangoResponse;
|
|
124
|
+
/**
|
|
125
|
+
* Create a `429 Too Many Requests` response from a string or structured error.
|
|
126
|
+
*/
|
|
113
127
|
static tooManyRequests<TDetails extends ErrorDetails = null>(detail?: string | TangoError | ProblemDetails<TDetails>, init?: Omit<TangoResponseInit, 'body' | 'status' | 'headers'> & {
|
|
114
128
|
headers?: HeadersInit;
|
|
115
129
|
}): TangoResponse;
|
|
130
|
+
/**
|
|
131
|
+
* Create a problem-details style error response with Tango's envelope shape.
|
|
132
|
+
*/
|
|
116
133
|
static problem<TDetails extends ErrorDetails = null>(problem?: string | TangoError | ProblemDetails<TDetails> | unknown, init?: Omit<TangoResponseInit, 'body' | 'headers'> & {
|
|
117
134
|
headers?: HeadersInit;
|
|
118
135
|
status?: number;
|
|
119
136
|
}): TangoResponse;
|
|
120
|
-
clone(): TangoResponse;
|
|
121
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
122
|
-
blob(): Promise<Blob>;
|
|
123
|
-
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
124
|
-
formData(): Promise<FormData>;
|
|
125
|
-
json<T = unknown>(): Promise<T>;
|
|
126
|
-
text(): Promise<string>;
|
|
127
137
|
/**
|
|
128
138
|
* Returns a response for serving a file.
|
|
129
139
|
*/
|
|
@@ -144,6 +154,131 @@ export declare class TangoResponse implements Response {
|
|
|
144
154
|
headers?: HeadersInit;
|
|
145
155
|
};
|
|
146
156
|
}): TangoResponse;
|
|
157
|
+
private static normalizeWebBody;
|
|
158
|
+
/**
|
|
159
|
+
* Expose the original body source for cloning and adapter integration.
|
|
160
|
+
*/
|
|
161
|
+
get bodySource(): BodyInit | JsonValue | null;
|
|
162
|
+
/**
|
|
163
|
+
* Report whether the status code falls inside the 2xx range.
|
|
164
|
+
*/
|
|
165
|
+
get ok(): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Report whether the body has been consumed.
|
|
168
|
+
*/
|
|
169
|
+
get bodyUsed(): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Replace a header value on the response.
|
|
172
|
+
*/
|
|
173
|
+
setHeader(name: string, value: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Append another value for a repeated response header.
|
|
176
|
+
*/
|
|
177
|
+
appendHeader(name: string, value: string): void;
|
|
178
|
+
/**
|
|
179
|
+
* Read a response header value.
|
|
180
|
+
*/
|
|
181
|
+
getHeader(name: string): string | null;
|
|
182
|
+
/**
|
|
183
|
+
* Check whether a response header is present.
|
|
184
|
+
*/
|
|
185
|
+
hasHeader(name: string): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Remove a response header.
|
|
188
|
+
*/
|
|
189
|
+
deleteHeader(name: string): void;
|
|
190
|
+
/**
|
|
191
|
+
* Merge one or more values into the `Vary` header.
|
|
192
|
+
*/
|
|
193
|
+
vary(...fields: string[]): void;
|
|
194
|
+
/**
|
|
195
|
+
* Add a `Set-Cookie` header that replaces prior application intent.
|
|
196
|
+
*/
|
|
197
|
+
setCookie(name: string, value: string, options?: Parameters<TangoHeaders['setCookie']>[2]): void;
|
|
198
|
+
/**
|
|
199
|
+
* Append another `Set-Cookie` header.
|
|
200
|
+
*/
|
|
201
|
+
appendCookie(name: string, value: string, options?: Parameters<TangoHeaders['appendCookie']>[2]): void;
|
|
202
|
+
/**
|
|
203
|
+
* Expire a cookie by issuing a matching deletion cookie header.
|
|
204
|
+
*/
|
|
205
|
+
deleteCookie(name: string, options?: Parameters<TangoHeaders['deleteCookie']>[1]): void;
|
|
206
|
+
/**
|
|
207
|
+
* Set the `Cache-Control` header through Tango's higher-level helper.
|
|
208
|
+
*/
|
|
209
|
+
cacheControl(control: Parameters<TangoHeaders['cacheControl']>[0]): void;
|
|
210
|
+
/**
|
|
211
|
+
* Set the `Location` header on the response.
|
|
212
|
+
*/
|
|
213
|
+
location(url: string): void;
|
|
214
|
+
/**
|
|
215
|
+
* Set the response content type.
|
|
216
|
+
*/
|
|
217
|
+
contentType(mime: string): void;
|
|
218
|
+
/**
|
|
219
|
+
* Set the X-Request-Id header (request correlation).
|
|
220
|
+
* Returns this for fluent chaining.
|
|
221
|
+
*/
|
|
222
|
+
withRequestId(requestId: string | undefined | null): this;
|
|
223
|
+
/**
|
|
224
|
+
* Set the traceparent header (W3C Trace Context propagation).
|
|
225
|
+
* Returns this for fluent chaining.
|
|
226
|
+
*/
|
|
227
|
+
withTraceparent(traceparent: string | undefined | null): this;
|
|
228
|
+
/**
|
|
229
|
+
* Set the Server-Timing header.
|
|
230
|
+
* Accepts a string or array of timing metrics.
|
|
231
|
+
* Returns this for fluent chaining.
|
|
232
|
+
*/
|
|
233
|
+
withServerTiming(timing: string | string[]): this;
|
|
234
|
+
/**
|
|
235
|
+
* Set the X-Response-Time header (in ms).
|
|
236
|
+
* Numeric or formatted string (e.g. "76ms").
|
|
237
|
+
* Returns this for fluent chaining.
|
|
238
|
+
*/
|
|
239
|
+
withResponseTime(time: number | string): this;
|
|
240
|
+
/**
|
|
241
|
+
* Propagate common tracing/correlation headers from provided Headers, TangoHeaders, or plain object.
|
|
242
|
+
* Known headers: x-request-id, traceparent, server-timing
|
|
243
|
+
* Returns this for fluent chaining.
|
|
244
|
+
*/
|
|
245
|
+
propagateTraceHeaders(input: HeadersInit): this;
|
|
246
|
+
/**
|
|
247
|
+
* Clone the response so its body can be consumed independently.
|
|
248
|
+
*/
|
|
249
|
+
clone(): TangoResponse;
|
|
250
|
+
/**
|
|
251
|
+
* Convert this Tango-owned response into a native web `Response`.
|
|
252
|
+
*
|
|
253
|
+
* Adapters use this at the host-framework boundary so Tango can standardize
|
|
254
|
+
* on `TangoResponse` internally while Next.js and other hosts still receive
|
|
255
|
+
* a platform-native response object.
|
|
256
|
+
*/
|
|
257
|
+
toWebResponse(): Response;
|
|
258
|
+
/**
|
|
259
|
+
* Read the response body as an array buffer.
|
|
260
|
+
*/
|
|
261
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
262
|
+
/**
|
|
263
|
+
* Read the response body as a blob.
|
|
264
|
+
*/
|
|
265
|
+
blob(): Promise<Blob>;
|
|
266
|
+
/**
|
|
267
|
+
* Read the response body as bytes.
|
|
268
|
+
*/
|
|
269
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
270
|
+
/**
|
|
271
|
+
* Read the response body as form data.
|
|
272
|
+
*/
|
|
273
|
+
formData(): Promise<FormData>;
|
|
274
|
+
/**
|
|
275
|
+
* Parse the response body as JSON.
|
|
276
|
+
*/
|
|
277
|
+
json<T = unknown>(): Promise<T>;
|
|
278
|
+
/**
|
|
279
|
+
* Read the response body as text.
|
|
280
|
+
*/
|
|
281
|
+
text(): Promise<string>;
|
|
147
282
|
/**
|
|
148
283
|
* Returns a plain object debug representation of this response: { status, headers: { ... }, bodyType: ... }.
|
|
149
284
|
* Intended for testing and debug tooling.
|
package/dist/http/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { TangoBody, type JsonValue } from './TangoBody';
|
|
5
5
|
import { TangoHeaders } from './TangoHeaders';
|
|
6
|
+
import { TangoQueryParams } from './TangoQueryParams';
|
|
6
7
|
import { TangoRequest } from './TangoRequest';
|
|
7
8
|
import { TangoResponse } from './TangoResponse';
|
|
8
|
-
export { TangoBody, TangoHeaders, TangoRequest, TangoResponse };
|
|
9
|
+
export { TangoBody, TangoHeaders, TangoQueryParams, TangoRequest, TangoResponse };
|
|
9
10
|
export type { JsonValue };
|
package/dist/http/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../TangoError-
|
|
2
|
-
import "../runtime-
|
|
3
|
-
import { TangoBody, TangoHeaders, TangoRequest, TangoResponse } from "../http-
|
|
1
|
+
import "../TangoError-DdQVQNZU.js";
|
|
2
|
+
import "../runtime-B8KkgD3R.js";
|
|
3
|
+
import { TangoBody, TangoHeaders, TangoQueryParams, TangoRequest, TangoResponse } from "../http-D20MQa6p.js";
|
|
4
4
|
|
|
5
|
-
export { TangoBody, TangoHeaders, TangoRequest, TangoResponse };
|
|
5
|
+
export { TangoBody, TangoHeaders, TangoQueryParams, TangoRequest, TangoResponse };
|