@stuntman/shared 0.1.3 → 0.1.4
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/package.json +1 -1
- package/dist/appError.d.ts +0 -14
- package/dist/appError.js +0 -17
- package/dist/config.d.ts +0 -2
- package/dist/config.js +0 -45
- package/dist/constants.d.ts +0 -14
- package/dist/constants.js +0 -17
- package/dist/index.d.ts +0 -166
- package/dist/index.js +0 -40
- package/dist/logger.d.ts +0 -9
- package/dist/logger.js +0 -17
- package/dist/rawHeaders.d.ts +0 -12
- package/dist/rawHeaders.js +0 -83
- package/dist/stringify.d.ts +0 -1
- package/dist/stringify.js +0 -10
package/package.json
CHANGED
package/dist/appError.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type * as Stuntman from '.';
|
|
2
|
-
export interface AppErrorInterface {
|
|
3
|
-
name?: string;
|
|
4
|
-
httpCode: Stuntman.HttpCode;
|
|
5
|
-
message: string;
|
|
6
|
-
isOperational?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare class AppError extends Error {
|
|
9
|
-
readonly name: string;
|
|
10
|
-
readonly httpCode: Stuntman.HttpCode;
|
|
11
|
-
readonly uuid?: string;
|
|
12
|
-
readonly isOperational: boolean;
|
|
13
|
-
constructor(args: AppErrorInterface);
|
|
14
|
-
}
|
package/dist/appError.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppError = void 0;
|
|
4
|
-
class AppError extends Error {
|
|
5
|
-
constructor(args) {
|
|
6
|
-
super(args.message);
|
|
7
|
-
this.isOperational = true;
|
|
8
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
9
|
-
this.name = args.name || 'Error';
|
|
10
|
-
this.httpCode = args.httpCode;
|
|
11
|
-
if (args.isOperational !== undefined) {
|
|
12
|
-
this.isOperational = args.isOperational;
|
|
13
|
-
}
|
|
14
|
-
Error.captureStackTrace(this);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.AppError = AppError;
|
package/dist/config.d.ts
DELETED
package/dist/config.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.serverConfig = void 0;
|
|
7
|
-
const _1 = require(".");
|
|
8
|
-
const config_1 = __importDefault(require("config"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
// TODO safeguards & defaults
|
|
11
|
-
const defaultConfig = {
|
|
12
|
-
api: {
|
|
13
|
-
disabled: false,
|
|
14
|
-
port: _1.DEFAULT_API_PORT,
|
|
15
|
-
apiKeyReadOnly: null,
|
|
16
|
-
apiKeyReadWrite: null,
|
|
17
|
-
},
|
|
18
|
-
mock: {
|
|
19
|
-
domain: _1.DEFAULT_MOCK_DOMAIN,
|
|
20
|
-
externalDns: _1.EXTERNAL_DNS,
|
|
21
|
-
port: _1.DEFAULT_MOCK_PORT,
|
|
22
|
-
timeout: _1.DEFAULT_PROXY_TIMEOUT,
|
|
23
|
-
rulesPath: path_1.default.join(process.cwd(), 'rules'),
|
|
24
|
-
},
|
|
25
|
-
storage: {
|
|
26
|
-
traffic: {
|
|
27
|
-
limitCount: _1.DEFAULT_CACHE_MAX_ENTRIES,
|
|
28
|
-
limitSize: _1.DEFAULT_CACHE_MAX_SIZE,
|
|
29
|
-
ttl: _1.DEFAULT_CACHE_TTL,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
webgui: {
|
|
33
|
-
disabled: false,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
config_1.default.util.setModuleDefaults('stuntman', defaultConfig);
|
|
37
|
-
let configFromFile = {};
|
|
38
|
-
try {
|
|
39
|
-
configFromFile = config_1.default.get('stuntman');
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.warn('unable to find correct config - starting with defaults');
|
|
44
|
-
}
|
|
45
|
-
exports.serverConfig = configFromFile;
|
package/dist/constants.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_PROXY_TIMEOUT = 60000;
|
|
2
|
-
export declare const DEFAULT_RULE_PRIORITY = 100;
|
|
3
|
-
export declare const DEFAULT_MOCK_PORT = 2015;
|
|
4
|
-
export declare const DEFAULT_API_PORT = 1985;
|
|
5
|
-
export declare const DEFAULT_CACHE_MAX_ENTRIES = 500;
|
|
6
|
-
export declare const DEFAULT_CACHE_MAX_SIZE: number;
|
|
7
|
-
export declare const DEFAULT_CACHE_TTL: number;
|
|
8
|
-
export declare const DEFAULT_MOCK_DOMAIN = "stuntman";
|
|
9
|
-
export declare const DEFAULT_RULE_TTL_SECONDS: number;
|
|
10
|
-
export declare const MIN_RULE_TTL_SECONDS = 10;
|
|
11
|
-
export declare const MAX_RULE_TTL_SECONDS: number;
|
|
12
|
-
export declare const CATCH_ALL_RULE_PRIORITY: number;
|
|
13
|
-
export declare const CATCH_RULE_NAME = "internal/catch-all";
|
|
14
|
-
export declare const EXTERNAL_DNS: string[];
|
package/dist/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EXTERNAL_DNS = exports.CATCH_RULE_NAME = exports.CATCH_ALL_RULE_PRIORITY = exports.MAX_RULE_TTL_SECONDS = exports.MIN_RULE_TTL_SECONDS = exports.DEFAULT_RULE_TTL_SECONDS = exports.DEFAULT_MOCK_DOMAIN = exports.DEFAULT_CACHE_TTL = exports.DEFAULT_CACHE_MAX_SIZE = exports.DEFAULT_CACHE_MAX_ENTRIES = exports.DEFAULT_API_PORT = exports.DEFAULT_MOCK_PORT = exports.DEFAULT_RULE_PRIORITY = exports.DEFAULT_PROXY_TIMEOUT = void 0;
|
|
4
|
-
exports.DEFAULT_PROXY_TIMEOUT = 60000;
|
|
5
|
-
exports.DEFAULT_RULE_PRIORITY = 100;
|
|
6
|
-
exports.DEFAULT_MOCK_PORT = 2015;
|
|
7
|
-
exports.DEFAULT_API_PORT = 1985;
|
|
8
|
-
exports.DEFAULT_CACHE_MAX_ENTRIES = 500;
|
|
9
|
-
exports.DEFAULT_CACHE_MAX_SIZE = 500 * 1024 * 1024;
|
|
10
|
-
exports.DEFAULT_CACHE_TTL = 1000 * 60 * 60;
|
|
11
|
-
exports.DEFAULT_MOCK_DOMAIN = 'stuntman';
|
|
12
|
-
exports.DEFAULT_RULE_TTL_SECONDS = 60 * 10;
|
|
13
|
-
exports.MIN_RULE_TTL_SECONDS = 10;
|
|
14
|
-
exports.MAX_RULE_TTL_SECONDS = 60 * 60;
|
|
15
|
-
exports.CATCH_ALL_RULE_PRIORITY = Infinity;
|
|
16
|
-
exports.CATCH_RULE_NAME = 'internal/catch-all';
|
|
17
|
-
exports.EXTERNAL_DNS = ['8.8.8.8', '1.1.1.1'];
|
package/dist/index.d.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
export * from './constants';
|
|
2
|
-
export * from './appError';
|
|
3
|
-
export * from './logger';
|
|
4
|
-
export * from './stringify';
|
|
5
|
-
export * from './rawHeaders';
|
|
6
|
-
export * from './config';
|
|
7
|
-
export declare const INDEX_DTS: string;
|
|
8
|
-
type NonObject = string | number | boolean | symbol | undefined | null | any[];
|
|
9
|
-
interface SerializableTypesRecord<T> {
|
|
10
|
-
[k: string | number]: T;
|
|
11
|
-
}
|
|
12
|
-
export type RecursivePartial<T> = {
|
|
13
|
-
[P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
|
|
14
|
-
};
|
|
15
|
-
type SerializableTypes = string | number | boolean | undefined | null | RegExp | SerializableTypes[] | SerializableTypesRecord<SerializableTypes>;
|
|
16
|
-
export declare enum HttpCode {
|
|
17
|
-
OK = 200,
|
|
18
|
-
NO_CONTENT = 204,
|
|
19
|
-
BAD_REQUEST = 400,
|
|
20
|
-
UNAUTHORIZED = 401,
|
|
21
|
-
NOT_FOUND = 404,
|
|
22
|
-
CONFLICT = 409,
|
|
23
|
-
UNPROCESSABLE_ENTITY = 422,
|
|
24
|
-
INTERNAL_SERVER_ERROR = 500
|
|
25
|
-
}
|
|
26
|
-
export type LocalVariables = Record<string, SerializableTypes>;
|
|
27
|
-
export type RuleMatchResult = boolean | {
|
|
28
|
-
result: boolean;
|
|
29
|
-
enableRuleIds?: string[];
|
|
30
|
-
disableRuleIds?: string[];
|
|
31
|
-
description?: string;
|
|
32
|
-
};
|
|
33
|
-
export type RemotableFunction<T extends Function> = {
|
|
34
|
-
localFn: T;
|
|
35
|
-
localVariables?: LocalVariables;
|
|
36
|
-
};
|
|
37
|
-
export type SerializedRemotableFunction = {
|
|
38
|
-
localFn: string;
|
|
39
|
-
variable?: string;
|
|
40
|
-
remoteFn: string;
|
|
41
|
-
};
|
|
42
|
-
type WithRemotableFunctions<Type> = {
|
|
43
|
-
[PropertyKey in keyof Type]: Extract<Type[PropertyKey], Function> extends never ? Exclude<Type[PropertyKey], NonObject> extends never ? Type[PropertyKey] : WithRemotableFunctions<Exclude<Type[PropertyKey], NonObject>> : Exclude<Type[PropertyKey], Function> | RemotableFunction<Extract<Type[PropertyKey], Function>>;
|
|
44
|
-
};
|
|
45
|
-
export type WithSerializedFunctions<Type> = {
|
|
46
|
-
[PropertyKey in keyof Type]: Extract<Type[PropertyKey], RemotableFunction<Function>> extends never ? Exclude<Type[PropertyKey], NonObject> extends never ? Type[PropertyKey] : WithSerializedFunctions<Exclude<Type[PropertyKey], NonObject>> : Exclude<Type[PropertyKey], RemotableFunction<Function>> | SerializedRemotableFunction;
|
|
47
|
-
};
|
|
48
|
-
export interface RawHeadersInterface extends Array<string> {
|
|
49
|
-
get: (name: string) => string | undefined;
|
|
50
|
-
set: (name: string, value: string) => void;
|
|
51
|
-
has: (name: string, value?: string) => boolean;
|
|
52
|
-
add: (name: string, value: string) => void;
|
|
53
|
-
remove: (name: string) => void;
|
|
54
|
-
toHeaderPairs: () => readonly [string, string][];
|
|
55
|
-
}
|
|
56
|
-
export type BaseRequest = {
|
|
57
|
-
rawHeaders: RawHeadersInterface;
|
|
58
|
-
url: string;
|
|
59
|
-
body?: any;
|
|
60
|
-
method: string;
|
|
61
|
-
};
|
|
62
|
-
export type Request = BaseRequest & {
|
|
63
|
-
id: string;
|
|
64
|
-
timestamp: number;
|
|
65
|
-
gqlBody?: GQLRequestBody;
|
|
66
|
-
};
|
|
67
|
-
export type Response = {
|
|
68
|
-
rawHeaders?: RawHeadersInterface;
|
|
69
|
-
status?: number;
|
|
70
|
-
body?: any;
|
|
71
|
-
timestamp?: number;
|
|
72
|
-
};
|
|
73
|
-
export type LogEntry = {
|
|
74
|
-
originalRequest: Request;
|
|
75
|
-
labels?: string[];
|
|
76
|
-
mockRuleId?: string;
|
|
77
|
-
originalResponse?: Response;
|
|
78
|
-
modifiedRequest?: Request;
|
|
79
|
-
modifiedResponse?: Response;
|
|
80
|
-
};
|
|
81
|
-
export type RuleMatchFunction = (request: Request) => RuleMatchResult;
|
|
82
|
-
export type RequestManipulationFn = (request: Request) => Request;
|
|
83
|
-
export type ResponseManipulationFn = (request: Request, response: Response) => Response;
|
|
84
|
-
export type ResponseGenerationFn = (request: Request) => Response;
|
|
85
|
-
export type Actions = {
|
|
86
|
-
mockResponse: Response | ResponseGenerationFn;
|
|
87
|
-
modifyRequest?: undefined;
|
|
88
|
-
modifyResponse?: undefined;
|
|
89
|
-
} | {
|
|
90
|
-
mockResponse?: undefined;
|
|
91
|
-
modifyRequest?: RequestManipulationFn;
|
|
92
|
-
modifyResponse?: ResponseManipulationFn;
|
|
93
|
-
};
|
|
94
|
-
export type Rule = {
|
|
95
|
-
id: string;
|
|
96
|
-
priority?: number;
|
|
97
|
-
matches: RuleMatchFunction;
|
|
98
|
-
labels?: string[];
|
|
99
|
-
actions?: Actions;
|
|
100
|
-
disableAfterUse?: boolean | number;
|
|
101
|
-
removeAfterUse?: boolean | number;
|
|
102
|
-
ttlSeconds: number;
|
|
103
|
-
storeTraffic?: boolean;
|
|
104
|
-
isEnabled?: boolean;
|
|
105
|
-
};
|
|
106
|
-
export type DeployedRule = Omit<Rule, 'disableAfterUse' | 'removeAfterUse' | 'ttlSeconds'>;
|
|
107
|
-
export type SerializableRule = WithRemotableFunctions<Rule>;
|
|
108
|
-
export type SerializedRule = WithSerializedFunctions<SerializableRule>;
|
|
109
|
-
export type LiveRule = Rule & {
|
|
110
|
-
counter: number;
|
|
111
|
-
createdTimestamp: number;
|
|
112
|
-
};
|
|
113
|
-
export type GQLRequestBody = {
|
|
114
|
-
operationName: string;
|
|
115
|
-
variables?: any;
|
|
116
|
-
query: string;
|
|
117
|
-
type: 'query' | 'mutation';
|
|
118
|
-
methodName?: string;
|
|
119
|
-
};
|
|
120
|
-
export type WebGuiConfig = {
|
|
121
|
-
disabled: boolean;
|
|
122
|
-
};
|
|
123
|
-
export type ApiConfig = {
|
|
124
|
-
port: number;
|
|
125
|
-
disabled: boolean;
|
|
126
|
-
apiKeyReadWrite: string | null;
|
|
127
|
-
apiKeyReadOnly: string | null;
|
|
128
|
-
};
|
|
129
|
-
export type ClientConfig = {
|
|
130
|
-
protocol?: 'http' | 'https';
|
|
131
|
-
host?: string;
|
|
132
|
-
port?: number;
|
|
133
|
-
timeout?: number;
|
|
134
|
-
};
|
|
135
|
-
export type MockConfig = {
|
|
136
|
-
domain: string;
|
|
137
|
-
port: number;
|
|
138
|
-
httpsPort?: number;
|
|
139
|
-
httpsKey?: string;
|
|
140
|
-
httpsCert?: string;
|
|
141
|
-
timeout: number;
|
|
142
|
-
externalDns: string[];
|
|
143
|
-
rulesPath: string;
|
|
144
|
-
};
|
|
145
|
-
export type StorageConfig = {
|
|
146
|
-
limitCount: number;
|
|
147
|
-
limitSize: number;
|
|
148
|
-
ttl: number;
|
|
149
|
-
};
|
|
150
|
-
export type ServerConfig = {
|
|
151
|
-
webgui: WebGuiConfig;
|
|
152
|
-
api: ApiConfig;
|
|
153
|
-
mock: MockConfig;
|
|
154
|
-
storage: {
|
|
155
|
-
traffic: StorageConfig;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
export interface RuleExecutorInterface {
|
|
159
|
-
addRule: (rule: Rule, overwrite?: boolean) => Promise<LiveRule>;
|
|
160
|
-
removeRule: (id: string) => Promise<void>;
|
|
161
|
-
enableRule: (id: string) => void;
|
|
162
|
-
disableRule: (id: string) => void;
|
|
163
|
-
findMatchingRule: (request: Request) => Promise<LiveRule | null>;
|
|
164
|
-
getRules: () => Promise<readonly LiveRule[]>;
|
|
165
|
-
getRule: (id: string) => Promise<LiveRule | undefined>;
|
|
166
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.HttpCode = exports.INDEX_DTS = void 0;
|
|
21
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
22
|
-
__exportStar(require("./constants"), exports);
|
|
23
|
-
__exportStar(require("./appError"), exports);
|
|
24
|
-
__exportStar(require("./logger"), exports);
|
|
25
|
-
__exportStar(require("./stringify"), exports);
|
|
26
|
-
__exportStar(require("./rawHeaders"), exports);
|
|
27
|
-
__exportStar(require("./config"), exports);
|
|
28
|
-
const fs_1 = __importDefault(require("fs"));
|
|
29
|
-
exports.INDEX_DTS = fs_1.default.readFileSync(`${__dirname}/index.d.ts`, 'utf-8');
|
|
30
|
-
var HttpCode;
|
|
31
|
-
(function (HttpCode) {
|
|
32
|
-
HttpCode[HttpCode["OK"] = 200] = "OK";
|
|
33
|
-
HttpCode[HttpCode["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
34
|
-
HttpCode[HttpCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
35
|
-
HttpCode[HttpCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
36
|
-
HttpCode[HttpCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
37
|
-
HttpCode[HttpCode["CONFLICT"] = 409] = "CONFLICT";
|
|
38
|
-
HttpCode[HttpCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
39
|
-
HttpCode[HttpCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
40
|
-
})(HttpCode = exports.HttpCode || (exports.HttpCode = {}));
|
package/dist/logger.d.ts
DELETED
package/dist/logger.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.logger = void 0;
|
|
8
|
-
const pino_1 = __importDefault(require("pino"));
|
|
9
|
-
exports.logger = (0, pino_1.default)({
|
|
10
|
-
level: (_a = process.env.LOG_LEVEL) !== null && _a !== void 0 ? _a : 'info',
|
|
11
|
-
messageKey: 'message',
|
|
12
|
-
formatters: {
|
|
13
|
-
level(label) {
|
|
14
|
-
return { level: label };
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
});
|
package/dist/rawHeaders.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type * as Stuntman from '.';
|
|
2
|
-
export declare class RawHeaders extends Array<string> implements Stuntman.RawHeadersInterface {
|
|
3
|
-
get(name: string): string | undefined;
|
|
4
|
-
has(name: string, value?: string): boolean;
|
|
5
|
-
set(name: string, value: string): void;
|
|
6
|
-
add(name: string, value: string): void;
|
|
7
|
-
remove(name: string): void;
|
|
8
|
-
toHeaderPairs(): readonly [string, string][];
|
|
9
|
-
static fromHeaderPairs(headerPairs: [string, string][]): RawHeaders;
|
|
10
|
-
static fromHeadersRecord(headersRecord: Record<string, string | string[] | undefined>): RawHeaders;
|
|
11
|
-
static toHeaderPairs(rawHeaders: string[]): readonly [string, string][];
|
|
12
|
-
}
|
package/dist/rawHeaders.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RawHeaders = void 0;
|
|
4
|
-
class RawHeaders extends Array {
|
|
5
|
-
get(name) {
|
|
6
|
-
const headers = this.toHeaderPairs();
|
|
7
|
-
const matchingHeaders = headers.filter((h) => h[0].toLowerCase() === name.toLowerCase());
|
|
8
|
-
if (matchingHeaders.length === 0) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (matchingHeaders.length === 1) {
|
|
12
|
-
return matchingHeaders[0][1];
|
|
13
|
-
}
|
|
14
|
-
throw new Error('Multiple headers with same name. Manipulate rawHeaders instead');
|
|
15
|
-
}
|
|
16
|
-
has(name, value) {
|
|
17
|
-
const foundValue = this.get(name);
|
|
18
|
-
if (value === undefined) {
|
|
19
|
-
return foundValue !== undefined;
|
|
20
|
-
}
|
|
21
|
-
return foundValue === value;
|
|
22
|
-
}
|
|
23
|
-
set(name, value) {
|
|
24
|
-
let foundHeaders = 0;
|
|
25
|
-
for (let headerIndex = 0; headerIndex < this.length; headerIndex += 2) {
|
|
26
|
-
if (this[headerIndex].toLowerCase() === name.toLowerCase()) {
|
|
27
|
-
this[headerIndex + 1] = value;
|
|
28
|
-
++foundHeaders;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (foundHeaders === 0) {
|
|
32
|
-
return this.add(name, value);
|
|
33
|
-
}
|
|
34
|
-
if (foundHeaders > 1) {
|
|
35
|
-
throw new Error('Multiple headers with same name. Manipulate rawHeaders instead');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
add(name, value) {
|
|
39
|
-
this.push(name);
|
|
40
|
-
this.push(value);
|
|
41
|
-
}
|
|
42
|
-
remove(name) {
|
|
43
|
-
const headersCopy = [...this];
|
|
44
|
-
let foundHeaders = 0;
|
|
45
|
-
for (let headerIndex = 0; headerIndex < headersCopy.length; headerIndex += 2) {
|
|
46
|
-
if (this[headerIndex - foundHeaders * 2].toLowerCase() === name.toLowerCase()) {
|
|
47
|
-
delete this[headerIndex];
|
|
48
|
-
delete this[headerIndex];
|
|
49
|
-
++foundHeaders;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (foundHeaders > 1) {
|
|
53
|
-
throw new Error('Multiple headers with same name. Manipulate rawHeaders instead');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
toHeaderPairs() {
|
|
57
|
-
return RawHeaders.toHeaderPairs(this);
|
|
58
|
-
}
|
|
59
|
-
static fromHeaderPairs(headerPairs) {
|
|
60
|
-
return new RawHeaders(...headerPairs.flatMap((x) => x));
|
|
61
|
-
}
|
|
62
|
-
static fromHeadersRecord(headersRecord) {
|
|
63
|
-
const output = new RawHeaders();
|
|
64
|
-
for (const [key, value] of Object.entries(headersRecord)) {
|
|
65
|
-
if (typeof value === 'string' || value === undefined) {
|
|
66
|
-
output.add(key, value !== null && value !== void 0 ? value : '');
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
for (const subValue of value) {
|
|
70
|
-
output.add(key, subValue);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return output;
|
|
74
|
-
}
|
|
75
|
-
static toHeaderPairs(rawHeaders) {
|
|
76
|
-
const headers = new Array();
|
|
77
|
-
for (let headerIndex = 0; headerIndex < rawHeaders.length; headerIndex += 2) {
|
|
78
|
-
headers.push([rawHeaders[headerIndex], rawHeaders[headerIndex + 1]]);
|
|
79
|
-
}
|
|
80
|
-
return headers;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.RawHeaders = RawHeaders;
|
package/dist/stringify.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const stringify: (obj: any) => string;
|
package/dist/stringify.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringify = void 0;
|
|
4
|
-
const stringify = (obj) => JSON.stringify(obj, (key, value) => {
|
|
5
|
-
if (typeof value === 'function' || value instanceof RegExp) {
|
|
6
|
-
return value.toString();
|
|
7
|
-
}
|
|
8
|
-
return value;
|
|
9
|
-
});
|
|
10
|
-
exports.stringify = stringify;
|