@opra/common 0.20.3 → 0.21.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/browser.js +295 -402
- package/cjs/document/api-document.js +8 -0
- package/cjs/document/data-type/mapped-type.js +1 -1
- package/cjs/document/data-type/union-type.js +1 -1
- package/cjs/document/factory/factory.js +3 -2
- package/cjs/document/factory/process-resources.js +22 -7
- package/cjs/document/index.js +1 -0
- package/cjs/document/resource/storage.js +81 -0
- package/cjs/helpers/mixin-utils.js +6 -5
- package/cjs/helpers/responsive-map.js +6 -1
- package/cjs/http/index.js +0 -1
- package/cjs/schema/opra-schema.ns.js +1 -0
- package/cjs/schema/resource/storage.interface.js +7 -0
- package/cjs/schema/type-guards.js +6 -1
- package/esm/document/api-document.js +8 -0
- package/esm/document/data-type/mapped-type.js +2 -2
- package/esm/document/data-type/union-type.js +2 -2
- package/esm/document/factory/factory.js +4 -3
- package/esm/document/factory/process-resources.js +18 -4
- package/esm/document/index.js +1 -0
- package/esm/document/resource/storage.js +77 -0
- package/esm/helpers/mixin-utils.js +4 -3
- package/esm/helpers/responsive-map.js +6 -1
- package/esm/http/index.js +0 -1
- package/esm/schema/opra-schema.ns.js +1 -0
- package/esm/schema/resource/storage.interface.js +4 -0
- package/esm/schema/type-guards.js +4 -0
- package/package.json +2 -2
- package/types/document/api-document.d.ts +3 -10
- package/types/document/factory/factory.d.ts +4 -3
- package/types/document/factory/process-resources.d.ts +4 -2
- package/types/document/index.d.ts +1 -0
- package/types/document/resource/storage.d.ts +44 -0
- package/types/helpers/mixin-utils.d.ts +1 -1
- package/types/http/index.d.ts +0 -1
- package/types/schema/opra-schema.ns.d.ts +1 -0
- package/types/schema/resource/resource.interface.d.ts +3 -2
- package/types/schema/resource/storage.interface.d.ts +18 -0
- package/types/schema/type-guards.d.ts +1 -0
- package/cjs/http/http-headers.js +0 -227
- package/esm/http/http-headers.js +0 -223
- package/types/http/http-headers.d.ts +0 -86
|
@@ -7,7 +7,7 @@ import { addReferences } from './add-references.js';
|
|
|
7
7
|
import { createBuiltinTypeDocument, createDocument, createDocumentFromUrl } from './create-document.js';
|
|
8
8
|
import { extractCollectionSchema, extractSingletonSchema, importResourceClass } from './import-resource-class.js';
|
|
9
9
|
import { extractComplexTypeSchema, extractEnumTypeSchema, extractFieldSchema, extractMappedTypeSchema, extractSimpleTypeSchema, extractUnionTypeSchema, importTypeClass } from './import-type-class.js';
|
|
10
|
-
import {
|
|
10
|
+
import { createCollectionResource, createFileResource, createSingletonResource, processResourceQueue } from './process-resources.js';
|
|
11
11
|
import { addDataType, createDataTypeInstance, processTypes } from './process-types.js';
|
|
12
12
|
/**
|
|
13
13
|
* @namespace DocumentFactory
|
|
@@ -48,8 +48,9 @@ export declare class DocumentFactory {
|
|
|
48
48
|
protected extractSingletonSchema: typeof extractSingletonSchema;
|
|
49
49
|
protected extractCollectionSchema: typeof extractCollectionSchema;
|
|
50
50
|
protected processResourceQueue: typeof processResourceQueue;
|
|
51
|
-
protected
|
|
52
|
-
protected
|
|
51
|
+
protected createCollectionResource: typeof createCollectionResource;
|
|
52
|
+
protected createSingletonResource: typeof createSingletonResource;
|
|
53
|
+
protected createFileResource: typeof createFileResource;
|
|
53
54
|
/**
|
|
54
55
|
* Creates ApiDocument instance from given schema object
|
|
55
56
|
* @param init
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
2
2
|
import { Collection } from '../resource/collection.js';
|
|
3
3
|
import { Singleton } from '../resource/singleton.js';
|
|
4
|
+
import { Storage } from '../resource/storage.js';
|
|
4
5
|
import type { DocumentFactory } from './factory.js';
|
|
5
6
|
export declare function processResourceQueue(this: DocumentFactory): Promise<void>;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function createCollectionResource(this: DocumentFactory, name: string, schema: OpraSchema.Collection): Promise<Collection>;
|
|
8
|
+
export declare function createSingletonResource(this: DocumentFactory, name: string, schema: OpraSchema.Singleton): Promise<Singleton>;
|
|
9
|
+
export declare function createFileResource(this: DocumentFactory, name: string, schema: OpraSchema.Storage): Promise<Storage>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
+
import type { ApiDocument } from '../api-document.js';
|
|
4
|
+
import { Resource } from './resource.js';
|
|
5
|
+
export declare namespace Storage {
|
|
6
|
+
export interface InitArguments extends Resource.InitArguments, Pick<OpraSchema.Storage, 'operations'> {
|
|
7
|
+
}
|
|
8
|
+
export interface DecoratorOptions extends Resource.DecoratorOptions {
|
|
9
|
+
}
|
|
10
|
+
export interface Metadata extends OpraSchema.Storage {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
interface Operation {
|
|
14
|
+
handlerName?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Operations {
|
|
17
|
+
delete?: OpraSchema.Storage.DeleteOperation & Operation;
|
|
18
|
+
get?: OpraSchema.Storage.GetOperation & Operation;
|
|
19
|
+
put?: OpraSchema.Storage.PutOperation & Operation;
|
|
20
|
+
}
|
|
21
|
+
export type DeleteOperationOptions = StrictOmit<OpraSchema.Storage.DeleteOperation, 'handler'>;
|
|
22
|
+
export type GetOperationOptions = StrictOmit<OpraSchema.Storage.GetOperation, 'handler'>;
|
|
23
|
+
export type PutOperationOptions = StrictOmit<OpraSchema.Storage.PutOperation, 'handler'>;
|
|
24
|
+
export {};
|
|
25
|
+
}
|
|
26
|
+
declare class StorageClass extends Resource {
|
|
27
|
+
readonly kind = "Storage";
|
|
28
|
+
readonly operations: Storage.Operations;
|
|
29
|
+
readonly controller?: object | Type;
|
|
30
|
+
constructor(document: ApiDocument, init: Storage.InitArguments);
|
|
31
|
+
exportSchema(): OpraSchema.Storage;
|
|
32
|
+
}
|
|
33
|
+
export interface StorageConstructor {
|
|
34
|
+
prototype: Storage;
|
|
35
|
+
new (document: ApiDocument, init: Storage.InitArguments): Storage;
|
|
36
|
+
(options?: Storage.DecoratorOptions): ClassDecorator;
|
|
37
|
+
Delete: (options?: Storage.DeleteOperationOptions) => PropertyDecorator;
|
|
38
|
+
Get: (options?: Storage.GetOperationOptions) => PropertyDecorator;
|
|
39
|
+
Put: (options?: Storage.PutOperationOptions) => PropertyDecorator;
|
|
40
|
+
}
|
|
41
|
+
export interface Storage extends StorageClass {
|
|
42
|
+
}
|
|
43
|
+
export declare const Storage: StorageConstructor;
|
|
44
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Type } from 'ts-gems';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function mergePrototype(targetProto: any, baseProto: any, filter?: (k: string) => boolean): void;
|
|
3
3
|
export declare function inheritPropertyInitializers(target: Record<string, any>, sourceClass: Type, isPropertyInherited?: (key: string) => boolean): void;
|
package/types/http/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './resource/container.interface.js';
|
|
|
10
10
|
export * from './resource/endpoint.interface.js';
|
|
11
11
|
export * from './resource/resource.interface.js';
|
|
12
12
|
export * from './resource/singleton.interface.js';
|
|
13
|
+
export * from './resource/storage.interface.js';
|
|
13
14
|
export * from './constants.js';
|
|
14
15
|
export * from './document.interface.js';
|
|
15
16
|
export * from './type-guards.js';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Collection } from './collection.interface.js';
|
|
2
2
|
import type { Container } from './container.interface.js';
|
|
3
3
|
import type { Singleton } from './singleton.interface.js';
|
|
4
|
-
|
|
4
|
+
import type { Storage } from './storage.interface';
|
|
5
|
+
export type Resource = Collection | Singleton | Storage | Container;
|
|
5
6
|
export declare namespace Resource {
|
|
6
7
|
type Name = string;
|
|
7
|
-
type Kind = Collection.Kind | Singleton.Kind | Container.Kind;
|
|
8
|
+
type Kind = Collection.Kind | Singleton.Kind | Storage.Kind | Container.Kind;
|
|
8
9
|
}
|
|
9
10
|
export interface ResourceBase {
|
|
10
11
|
kind: string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Endpoint } from './endpoint.interface.js';
|
|
2
|
+
import type { ResourceBase } from './resource.interface.js';
|
|
3
|
+
export interface Storage extends ResourceBase {
|
|
4
|
+
kind: Storage.Kind;
|
|
5
|
+
operations: Storage.Operations;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace Storage {
|
|
8
|
+
const Kind = "Storage";
|
|
9
|
+
type Kind = 'Storage';
|
|
10
|
+
type DeleteOperation = Endpoint;
|
|
11
|
+
type GetOperation = Endpoint;
|
|
12
|
+
type PutOperation = Endpoint & {};
|
|
13
|
+
interface Operations {
|
|
14
|
+
delete?: DeleteOperation;
|
|
15
|
+
get?: GetOperation;
|
|
16
|
+
put?: PutOperation;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -17,4 +17,5 @@ export declare function isEnumType(obj: any): obj is EnumType;
|
|
|
17
17
|
export declare function isResource(obj: any): obj is Resource;
|
|
18
18
|
export declare function isCollection(obj: any): obj is Collection;
|
|
19
19
|
export declare function isSingleton(obj: any): obj is Singleton;
|
|
20
|
+
export declare function isStorage(obj: any): obj is Singleton;
|
|
20
21
|
export declare function isContainer(obj: any): obj is Container;
|
package/cjs/http/http-headers.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HttpHeaders = void 0;
|
|
5
|
-
const index_js_1 = require("../helpers/index.js");
|
|
6
|
-
const http_headers_codes_enum_js_1 = require("./enums/http-headers-codes.enum.js");
|
|
7
|
-
const knownKeys = Object.values(http_headers_codes_enum_js_1.HttpHeaderCodes);
|
|
8
|
-
const knownKeysLower = knownKeys.map(x => x.toLowerCase());
|
|
9
|
-
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
10
|
-
const kEntries = Symbol('kEntries');
|
|
11
|
-
const kOptions = Symbol('kOptions');
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @class HttpHeaders
|
|
15
|
-
*/
|
|
16
|
-
class HttpHeaders {
|
|
17
|
-
constructor(init, options) {
|
|
18
|
-
this[_a] = new index_js_1.ResponsiveMap();
|
|
19
|
-
this[kOptions] = { ...options, onChange: undefined };
|
|
20
|
-
if (init) {
|
|
21
|
-
if (typeof init === 'string')
|
|
22
|
-
this.parse(init);
|
|
23
|
-
else
|
|
24
|
-
this.set(init);
|
|
25
|
-
}
|
|
26
|
-
this[kOptions].onChange = options?.onChange;
|
|
27
|
-
}
|
|
28
|
-
get size() {
|
|
29
|
-
return this[kEntries].size;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Appends a new value to the existing set of values for a header
|
|
33
|
-
* and returns this instance
|
|
34
|
-
*/
|
|
35
|
-
append(name, value) {
|
|
36
|
-
this._append(name, value);
|
|
37
|
-
this.changed();
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Appends multiple values to the existing set of values for a header
|
|
42
|
-
* and returns this instance
|
|
43
|
-
*/
|
|
44
|
-
appendAll(headers) {
|
|
45
|
-
if (headers.forEach && typeof headers.forEach === 'function')
|
|
46
|
-
headers.forEach((value, name) => this._append(name, value));
|
|
47
|
-
else
|
|
48
|
-
Object.keys(headers).forEach(name => this._append(name, headers[name]));
|
|
49
|
-
this.changed();
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
set(arg0, arg1) {
|
|
53
|
-
if (typeof arg0 === 'object') {
|
|
54
|
-
if (arg0.forEach && typeof arg0.forEach === 'function')
|
|
55
|
-
arg0.forEach((value, name) => this._set(name, value));
|
|
56
|
-
else
|
|
57
|
-
Object.keys(arg0).forEach(name => this._set(name, arg0[name]));
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
if (!arg1 && arg1 !== 0)
|
|
61
|
-
this[kEntries].delete(arg0);
|
|
62
|
-
else
|
|
63
|
-
this._set(arg0, arg1);
|
|
64
|
-
}
|
|
65
|
-
this.changed();
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
parse(init) {
|
|
69
|
-
this.clear();
|
|
70
|
-
init.split('\n').forEach(line => {
|
|
71
|
-
const index = line.indexOf(':');
|
|
72
|
-
if (index > 0) {
|
|
73
|
-
const name = line.slice(0, index);
|
|
74
|
-
const value = line.slice(index + 1).trim();
|
|
75
|
-
if (HttpHeaders.NON_DELIMITED_HEADERS[name])
|
|
76
|
-
this._append(name, value);
|
|
77
|
-
else if (HttpHeaders.SEMICOLON_DELIMITED_HEADERS[name]) {
|
|
78
|
-
const a = value.split(';');
|
|
79
|
-
this._append(name, a.length > 1 ? a : value);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const a = value.split(',');
|
|
83
|
-
this._append(name, a.length > 1 ? a : value);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Retrieves value of a given header
|
|
90
|
-
*/
|
|
91
|
-
get(name) {
|
|
92
|
-
return this[kEntries].get(name);
|
|
93
|
-
}
|
|
94
|
-
clear() {
|
|
95
|
-
if (this[kEntries].size) {
|
|
96
|
-
this[kEntries].clear();
|
|
97
|
-
this.changed();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Deletes a header entry
|
|
102
|
-
*/
|
|
103
|
-
delete(name) {
|
|
104
|
-
if (this[kEntries].delete(name)) {
|
|
105
|
-
this.changed();
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns an iterable of key, value pairs for every entry in the map.
|
|
112
|
-
*/
|
|
113
|
-
entries() {
|
|
114
|
-
return this[kEntries].entries();
|
|
115
|
-
}
|
|
116
|
-
forEach(callbackFn, thisArg) {
|
|
117
|
-
const iterator = this.entries();
|
|
118
|
-
let entry = iterator.next();
|
|
119
|
-
let v;
|
|
120
|
-
while (!entry.done) {
|
|
121
|
-
v = entry.value[1];
|
|
122
|
-
callbackFn.call(thisArg || this, (Array.isArray(v) ? v.join(';') : String(v)), entry.value[0], this);
|
|
123
|
-
entry = iterator.next();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Retrieves the names of the headers.
|
|
128
|
-
*/
|
|
129
|
-
keys() {
|
|
130
|
-
return this[kEntries].keys();
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Checks for existence of a given header.
|
|
134
|
-
*/
|
|
135
|
-
has(name) {
|
|
136
|
-
return this[kEntries].has(name);
|
|
137
|
-
}
|
|
138
|
-
sort(compareFn) {
|
|
139
|
-
this[kEntries].sort(compareFn);
|
|
140
|
-
this.changed();
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
toObject() {
|
|
144
|
-
const out = {};
|
|
145
|
-
for (const [k, v] of this.entries())
|
|
146
|
-
out[k] = Array.isArray(v) ? v.join(';') : String(v);
|
|
147
|
-
return out;
|
|
148
|
-
}
|
|
149
|
-
getProxy() {
|
|
150
|
-
const _this = this;
|
|
151
|
-
return this[kEntries].getProxy({
|
|
152
|
-
set(target, p, newValue, receiver) {
|
|
153
|
-
if (typeof p === 'string') {
|
|
154
|
-
_this.set(p, newValue);
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
return Reflect.set(target, p, newValue, receiver);
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
[(_a = kEntries, nodeInspectCustom)]() {
|
|
162
|
-
return this[kEntries];
|
|
163
|
-
}
|
|
164
|
-
[Symbol.iterator]() {
|
|
165
|
-
return this.entries();
|
|
166
|
-
}
|
|
167
|
-
get [Symbol.toStringTag]() {
|
|
168
|
-
return 'HttpHeaders';
|
|
169
|
-
}
|
|
170
|
-
_append(name, value) {
|
|
171
|
-
const i = knownKeysLower.indexOf(name.toLowerCase());
|
|
172
|
-
const normalizedName = knownKeys[i] || name;
|
|
173
|
-
name = name.toLowerCase();
|
|
174
|
-
let stored = this[kEntries].get(normalizedName);
|
|
175
|
-
if (HttpHeaders.NON_DELIMITED_HEADERS[name]) {
|
|
176
|
-
value = String(Array.isArray(value) ? value[0] : value);
|
|
177
|
-
this[kEntries].set(normalizedName, value);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (HttpHeaders.ARRAY_HEADERS[name]) {
|
|
181
|
-
stored = (stored ? [stored, value] : [value])
|
|
182
|
-
.flat().map(String);
|
|
183
|
-
this[kEntries].set(normalizedName, stored);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const arr = stored ? [stored] : [];
|
|
187
|
-
if (Array.isArray(value))
|
|
188
|
-
arr.push(...value);
|
|
189
|
-
else
|
|
190
|
-
arr.push(value);
|
|
191
|
-
this[kEntries].set(normalizedName, arr.join(HttpHeaders.SEMICOLON_DELIMITED_HEADERS[name] ? '; ' : ', '));
|
|
192
|
-
}
|
|
193
|
-
_set(name, value) {
|
|
194
|
-
this[kEntries].delete(name);
|
|
195
|
-
if (!value && value !== 0)
|
|
196
|
-
return;
|
|
197
|
-
this._append(name, value);
|
|
198
|
-
}
|
|
199
|
-
changed() {
|
|
200
|
-
if (this[kOptions].onChange)
|
|
201
|
-
this[kOptions].onChange();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
exports.HttpHeaders = HttpHeaders;
|
|
205
|
-
HttpHeaders.kEntries = kEntries;
|
|
206
|
-
HttpHeaders.kOptions = kOptions;
|
|
207
|
-
HttpHeaders.NON_DELIMITED_HEADERS = {
|
|
208
|
-
'age': true,
|
|
209
|
-
'from': true,
|
|
210
|
-
'etag': true,
|
|
211
|
-
'server': true,
|
|
212
|
-
'referer': true,
|
|
213
|
-
'expires': true,
|
|
214
|
-
'location': true,
|
|
215
|
-
'user-agent': true,
|
|
216
|
-
'retry-after': true,
|
|
217
|
-
'content-type': true,
|
|
218
|
-
'content-length': true,
|
|
219
|
-
'max-forwards': true,
|
|
220
|
-
'last-modified': true,
|
|
221
|
-
'authorization': true,
|
|
222
|
-
'proxy-authorization': true,
|
|
223
|
-
'if-modified-since': true,
|
|
224
|
-
'if-unmodified-since': true
|
|
225
|
-
};
|
|
226
|
-
HttpHeaders.SEMICOLON_DELIMITED_HEADERS = { 'cookie': true };
|
|
227
|
-
HttpHeaders.ARRAY_HEADERS = { 'set-cookie': true };
|
package/esm/http/http-headers.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import { ResponsiveMap } from '../helpers/index.js';
|
|
3
|
-
import { HttpHeaderCodes } from './enums/http-headers-codes.enum.js';
|
|
4
|
-
const knownKeys = Object.values(HttpHeaderCodes);
|
|
5
|
-
const knownKeysLower = knownKeys.map(x => x.toLowerCase());
|
|
6
|
-
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
7
|
-
const kEntries = Symbol('kEntries');
|
|
8
|
-
const kOptions = Symbol('kOptions');
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @class HttpHeaders
|
|
12
|
-
*/
|
|
13
|
-
export class HttpHeaders {
|
|
14
|
-
constructor(init, options) {
|
|
15
|
-
this[_a] = new ResponsiveMap();
|
|
16
|
-
this[kOptions] = { ...options, onChange: undefined };
|
|
17
|
-
if (init) {
|
|
18
|
-
if (typeof init === 'string')
|
|
19
|
-
this.parse(init);
|
|
20
|
-
else
|
|
21
|
-
this.set(init);
|
|
22
|
-
}
|
|
23
|
-
this[kOptions].onChange = options?.onChange;
|
|
24
|
-
}
|
|
25
|
-
get size() {
|
|
26
|
-
return this[kEntries].size;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Appends a new value to the existing set of values for a header
|
|
30
|
-
* and returns this instance
|
|
31
|
-
*/
|
|
32
|
-
append(name, value) {
|
|
33
|
-
this._append(name, value);
|
|
34
|
-
this.changed();
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Appends multiple values to the existing set of values for a header
|
|
39
|
-
* and returns this instance
|
|
40
|
-
*/
|
|
41
|
-
appendAll(headers) {
|
|
42
|
-
if (headers.forEach && typeof headers.forEach === 'function')
|
|
43
|
-
headers.forEach((value, name) => this._append(name, value));
|
|
44
|
-
else
|
|
45
|
-
Object.keys(headers).forEach(name => this._append(name, headers[name]));
|
|
46
|
-
this.changed();
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
set(arg0, arg1) {
|
|
50
|
-
if (typeof arg0 === 'object') {
|
|
51
|
-
if (arg0.forEach && typeof arg0.forEach === 'function')
|
|
52
|
-
arg0.forEach((value, name) => this._set(name, value));
|
|
53
|
-
else
|
|
54
|
-
Object.keys(arg0).forEach(name => this._set(name, arg0[name]));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
if (!arg1 && arg1 !== 0)
|
|
58
|
-
this[kEntries].delete(arg0);
|
|
59
|
-
else
|
|
60
|
-
this._set(arg0, arg1);
|
|
61
|
-
}
|
|
62
|
-
this.changed();
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
parse(init) {
|
|
66
|
-
this.clear();
|
|
67
|
-
init.split('\n').forEach(line => {
|
|
68
|
-
const index = line.indexOf(':');
|
|
69
|
-
if (index > 0) {
|
|
70
|
-
const name = line.slice(0, index);
|
|
71
|
-
const value = line.slice(index + 1).trim();
|
|
72
|
-
if (HttpHeaders.NON_DELIMITED_HEADERS[name])
|
|
73
|
-
this._append(name, value);
|
|
74
|
-
else if (HttpHeaders.SEMICOLON_DELIMITED_HEADERS[name]) {
|
|
75
|
-
const a = value.split(';');
|
|
76
|
-
this._append(name, a.length > 1 ? a : value);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const a = value.split(',');
|
|
80
|
-
this._append(name, a.length > 1 ? a : value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Retrieves value of a given header
|
|
87
|
-
*/
|
|
88
|
-
get(name) {
|
|
89
|
-
return this[kEntries].get(name);
|
|
90
|
-
}
|
|
91
|
-
clear() {
|
|
92
|
-
if (this[kEntries].size) {
|
|
93
|
-
this[kEntries].clear();
|
|
94
|
-
this.changed();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Deletes a header entry
|
|
99
|
-
*/
|
|
100
|
-
delete(name) {
|
|
101
|
-
if (this[kEntries].delete(name)) {
|
|
102
|
-
this.changed();
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Returns an iterable of key, value pairs for every entry in the map.
|
|
109
|
-
*/
|
|
110
|
-
entries() {
|
|
111
|
-
return this[kEntries].entries();
|
|
112
|
-
}
|
|
113
|
-
forEach(callbackFn, thisArg) {
|
|
114
|
-
const iterator = this.entries();
|
|
115
|
-
let entry = iterator.next();
|
|
116
|
-
let v;
|
|
117
|
-
while (!entry.done) {
|
|
118
|
-
v = entry.value[1];
|
|
119
|
-
callbackFn.call(thisArg || this, (Array.isArray(v) ? v.join(';') : String(v)), entry.value[0], this);
|
|
120
|
-
entry = iterator.next();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Retrieves the names of the headers.
|
|
125
|
-
*/
|
|
126
|
-
keys() {
|
|
127
|
-
return this[kEntries].keys();
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Checks for existence of a given header.
|
|
131
|
-
*/
|
|
132
|
-
has(name) {
|
|
133
|
-
return this[kEntries].has(name);
|
|
134
|
-
}
|
|
135
|
-
sort(compareFn) {
|
|
136
|
-
this[kEntries].sort(compareFn);
|
|
137
|
-
this.changed();
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
toObject() {
|
|
141
|
-
const out = {};
|
|
142
|
-
for (const [k, v] of this.entries())
|
|
143
|
-
out[k] = Array.isArray(v) ? v.join(';') : String(v);
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
getProxy() {
|
|
147
|
-
const _this = this;
|
|
148
|
-
return this[kEntries].getProxy({
|
|
149
|
-
set(target, p, newValue, receiver) {
|
|
150
|
-
if (typeof p === 'string') {
|
|
151
|
-
_this.set(p, newValue);
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
return Reflect.set(target, p, newValue, receiver);
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
[(_a = kEntries, nodeInspectCustom)]() {
|
|
159
|
-
return this[kEntries];
|
|
160
|
-
}
|
|
161
|
-
[Symbol.iterator]() {
|
|
162
|
-
return this.entries();
|
|
163
|
-
}
|
|
164
|
-
get [Symbol.toStringTag]() {
|
|
165
|
-
return 'HttpHeaders';
|
|
166
|
-
}
|
|
167
|
-
_append(name, value) {
|
|
168
|
-
const i = knownKeysLower.indexOf(name.toLowerCase());
|
|
169
|
-
const normalizedName = knownKeys[i] || name;
|
|
170
|
-
name = name.toLowerCase();
|
|
171
|
-
let stored = this[kEntries].get(normalizedName);
|
|
172
|
-
if (HttpHeaders.NON_DELIMITED_HEADERS[name]) {
|
|
173
|
-
value = String(Array.isArray(value) ? value[0] : value);
|
|
174
|
-
this[kEntries].set(normalizedName, value);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (HttpHeaders.ARRAY_HEADERS[name]) {
|
|
178
|
-
stored = (stored ? [stored, value] : [value])
|
|
179
|
-
.flat().map(String);
|
|
180
|
-
this[kEntries].set(normalizedName, stored);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const arr = stored ? [stored] : [];
|
|
184
|
-
if (Array.isArray(value))
|
|
185
|
-
arr.push(...value);
|
|
186
|
-
else
|
|
187
|
-
arr.push(value);
|
|
188
|
-
this[kEntries].set(normalizedName, arr.join(HttpHeaders.SEMICOLON_DELIMITED_HEADERS[name] ? '; ' : ', '));
|
|
189
|
-
}
|
|
190
|
-
_set(name, value) {
|
|
191
|
-
this[kEntries].delete(name);
|
|
192
|
-
if (!value && value !== 0)
|
|
193
|
-
return;
|
|
194
|
-
this._append(name, value);
|
|
195
|
-
}
|
|
196
|
-
changed() {
|
|
197
|
-
if (this[kOptions].onChange)
|
|
198
|
-
this[kOptions].onChange();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
HttpHeaders.kEntries = kEntries;
|
|
202
|
-
HttpHeaders.kOptions = kOptions;
|
|
203
|
-
HttpHeaders.NON_DELIMITED_HEADERS = {
|
|
204
|
-
'age': true,
|
|
205
|
-
'from': true,
|
|
206
|
-
'etag': true,
|
|
207
|
-
'server': true,
|
|
208
|
-
'referer': true,
|
|
209
|
-
'expires': true,
|
|
210
|
-
'location': true,
|
|
211
|
-
'user-agent': true,
|
|
212
|
-
'retry-after': true,
|
|
213
|
-
'content-type': true,
|
|
214
|
-
'content-length': true,
|
|
215
|
-
'max-forwards': true,
|
|
216
|
-
'last-modified': true,
|
|
217
|
-
'authorization': true,
|
|
218
|
-
'proxy-authorization': true,
|
|
219
|
-
'if-modified-since': true,
|
|
220
|
-
'if-unmodified-since': true
|
|
221
|
-
};
|
|
222
|
-
HttpHeaders.SEMICOLON_DELIMITED_HEADERS = { 'cookie': true };
|
|
223
|
-
HttpHeaders.ARRAY_HEADERS = { 'set-cookie': true };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference lib="dom" />
|
|
3
|
-
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
4
|
-
import { ResponsiveMap } from '../helpers/index.js';
|
|
5
|
-
declare const nodeInspectCustom: unique symbol;
|
|
6
|
-
declare const kEntries: unique symbol;
|
|
7
|
-
declare const kOptions: unique symbol;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @namespace HttpHeaders
|
|
11
|
-
*/
|
|
12
|
-
export declare namespace HttpHeaders {
|
|
13
|
-
type Initiator = Headers | HttpHeaders | IncomingHttpHeaders | OutgoingHttpHeaders | HeadersObject | Map<string, string | string[]>;
|
|
14
|
-
type HeadersObject = Record<string, string | string[]>;
|
|
15
|
-
interface Options {
|
|
16
|
-
onChange?: () => void;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @class HttpHeaders
|
|
22
|
-
*/
|
|
23
|
-
export declare class HttpHeaders {
|
|
24
|
-
protected static kEntries: symbol;
|
|
25
|
-
protected static kOptions: symbol;
|
|
26
|
-
protected [kEntries]: ResponsiveMap<string | string[]>;
|
|
27
|
-
protected [kOptions]: HttpHeaders.Options;
|
|
28
|
-
constructor(init?: HttpHeaders.Initiator | string, options?: HttpHeaders.Options);
|
|
29
|
-
get size(): number;
|
|
30
|
-
/**
|
|
31
|
-
* Appends a new value to the existing set of values for a header
|
|
32
|
-
* and returns this instance
|
|
33
|
-
*/
|
|
34
|
-
append(name: string, value: string | number | string[]): this;
|
|
35
|
-
/**
|
|
36
|
-
* Appends multiple values to the existing set of values for a header
|
|
37
|
-
* and returns this instance
|
|
38
|
-
*/
|
|
39
|
-
appendAll(headers: HttpHeaders.Initiator): this;
|
|
40
|
-
/**
|
|
41
|
-
* Appends multiple values to the existing set of values for a header
|
|
42
|
-
* and returns this instance
|
|
43
|
-
*/
|
|
44
|
-
set(init: HttpHeaders.Initiator): this;
|
|
45
|
-
/**
|
|
46
|
-
* Sets or modifies a value for a given header.
|
|
47
|
-
* If the header already exists, its value is replaced with the given value
|
|
48
|
-
*/
|
|
49
|
-
set(name: string, value: number | string | string[] | undefined): this;
|
|
50
|
-
parse(init: string): void;
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves value of a given header
|
|
53
|
-
*/
|
|
54
|
-
get(name: string): string | string[] | undefined;
|
|
55
|
-
clear(): void;
|
|
56
|
-
/**
|
|
57
|
-
* Deletes a header entry
|
|
58
|
-
*/
|
|
59
|
-
delete(name: string): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Returns an iterable of key, value pairs for every entry in the map.
|
|
62
|
-
*/
|
|
63
|
-
entries(): IterableIterator<[string, string | string[]]>;
|
|
64
|
-
forEach(callbackFn: (value: number | string | string[], key: string, parent: HttpHeaders) => void, thisArg?: any): void;
|
|
65
|
-
/**
|
|
66
|
-
* Retrieves the names of the headers.
|
|
67
|
-
*/
|
|
68
|
-
keys(): IterableIterator<string>;
|
|
69
|
-
/**
|
|
70
|
-
* Checks for existence of a given header.
|
|
71
|
-
*/
|
|
72
|
-
has(name: string): boolean;
|
|
73
|
-
sort(compareFn?: (a: string, b: string) => number): this;
|
|
74
|
-
toObject(): Record<string, string>;
|
|
75
|
-
getProxy(): HttpHeaders.HeadersObject;
|
|
76
|
-
[nodeInspectCustom](): ResponsiveMap<string | string[]>;
|
|
77
|
-
[Symbol.iterator](): IterableIterator<[string, number | string | string[]]>;
|
|
78
|
-
get [Symbol.toStringTag](): string;
|
|
79
|
-
protected _append(name: string, value: any): void;
|
|
80
|
-
protected _set(name: string, value: any): void;
|
|
81
|
-
protected changed(): void;
|
|
82
|
-
static NON_DELIMITED_HEADERS: any;
|
|
83
|
-
static SEMICOLON_DELIMITED_HEADERS: any;
|
|
84
|
-
static ARRAY_HEADERS: any;
|
|
85
|
-
}
|
|
86
|
-
export {};
|