@opra/common 0.19.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/browser.js +117 -683
  2. package/cjs/document/data-type/builtin/index.js +2 -0
  3. package/cjs/document/data-type/builtin/null.type.js +15 -0
  4. package/cjs/document/data-type/builtin/object-id.type.js +15 -0
  5. package/cjs/document/data-type/complex-type.js +1 -0
  6. package/cjs/document/data-type/enum-type.js +1 -0
  7. package/cjs/document/data-type/mapped-type.js +1 -0
  8. package/cjs/document/data-type/simple-type.js +1 -0
  9. package/cjs/document/data-type/union-type.js +1 -0
  10. package/cjs/document/factory/create-document.js +3 -3
  11. package/cjs/http/index.js +1 -2
  12. package/esm/document/data-type/builtin/index.js +2 -0
  13. package/esm/document/data-type/builtin/null.type.js +12 -0
  14. package/esm/document/data-type/builtin/object-id.type.js +12 -0
  15. package/esm/document/data-type/complex-type.js +1 -0
  16. package/esm/document/data-type/enum-type.js +1 -0
  17. package/esm/document/data-type/mapped-type.js +1 -0
  18. package/esm/document/data-type/simple-type.js +1 -0
  19. package/esm/document/data-type/union-type.js +1 -0
  20. package/esm/document/factory/create-document.js +4 -4
  21. package/esm/http/index.js +1 -2
  22. package/package.json +9 -24
  23. package/types/document/data-type/builtin/index.d.ts +2 -0
  24. package/types/document/data-type/builtin/null.type.d.ts +2 -0
  25. package/types/document/data-type/builtin/object-id.type.d.ts +2 -0
  26. package/types/document/data-type/complex-type.d.ts +1 -0
  27. package/types/document/data-type/enum-type.d.ts +1 -0
  28. package/types/document/data-type/mapped-type.d.ts +1 -0
  29. package/types/document/data-type/simple-type.d.ts +1 -0
  30. package/types/document/data-type/union-type.d.ts +1 -0
  31. package/types/exception/error-issue.d.ts +1 -1
  32. package/types/http/index.d.ts +1 -2
  33. package/cjs/http/http-message.host.js +0 -251
  34. package/cjs/http/http-request-message.js +0 -152
  35. package/cjs/http/http-response-message.js +0 -238
  36. package/cjs/http/interfaces/cookie-options.interface.js +0 -2
  37. package/esm/http/http-message.host.js +0 -246
  38. package/esm/http/http-request-message.js +0 -148
  39. package/esm/http/http-response-message.js +0 -233
  40. package/esm/http/interfaces/cookie-options.interface.js +0 -1
  41. package/types/http/http-message.host.d.ts +0 -122
  42. package/types/http/http-request-message.d.ts +0 -213
  43. package/types/http/http-response-message.d.ts +0 -318
  44. package/types/http/interfaces/cookie-options.interface.d.ts +0 -4
@@ -1,213 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
- import { IncomingHttpHeaders } from 'http';
6
- import { Readable } from 'stream';
7
- import { HttpMessage } from './http-message.host.js';
8
- export interface HttpRequestMessage extends HttpMessage {
9
- /**
10
- * In case of server request, the HTTP version sent by the client. In the case of
11
- * client response, the HTTP version of the connected-to server.
12
- * Probably either `'1.1'` or `'1.0'`.
13
- *
14
- * Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
15
- * @since v0.1.1
16
- */
17
- httpVersion: string;
18
- httpVersionMajor: number;
19
- httpVersionMinor: number;
20
- /**
21
- * The request/response headers object.
22
- *
23
- * Key-value pairs of header names and values. Header names are lower-cased.
24
- */
25
- readonly headers: IncomingHttpHeaders;
26
- /**
27
- * The raw request/response headers list exactly as they were received.
28
- */
29
- rawHeaders: string[];
30
- /**
31
- * The request/response trailers object.
32
- */
33
- readonly trailers: NodeJS.Dict<string>;
34
- /**
35
- * The raw request/response trailer keys and values exactly as they were received.
36
- */
37
- rawTrailers: string[];
38
- readonly complete: boolean;
39
- readonly upgrade?: any;
40
- /**
41
- * Return the protocol string "http" or "https"
42
- * when requested with TLS. When the "trust proxy"
43
- * setting is enabled the "X-Forwarded-Proto" header
44
- * field will be trusted. If you're running behind
45
- * a reverse proxy that supplies https for you this
46
- * may be enabled.
47
- */
48
- protocol: string;
49
- /**
50
- * Short-hand for:
51
- *
52
- * req.protocol == 'https'
53
- */
54
- secure: boolean;
55
- /**
56
- * Return the remote address, or when
57
- * "trust proxy" is `true` return
58
- * the upstream addr.
59
- */
60
- ip: string;
61
- /**
62
- * When "trust proxy" is `true`, parse
63
- * the "X-Forwarded-For" ip address list.
64
- *
65
- * For example if the value were "client, proxy1, proxy2"
66
- * you would receive the array `["client", "proxy1", "proxy2"]`
67
- * where "proxy2" is the furthest down-stream.
68
- */
69
- ips: string[];
70
- /**
71
- * Parse the "Host" header field hostname.
72
- */
73
- hostname: string;
74
- method: string;
75
- url: string;
76
- baseUrl: string;
77
- query: Record<string, any>;
78
- /**
79
- * Return request header.
80
- *
81
- * The `Referrer` header field is special-cased,
82
- * both `Referrer` and `Referer` are interchangeable.
83
- *
84
- * Examples:
85
- *
86
- * req.get('Content-Type');
87
- * // => "text/plain"
88
- *
89
- * req.get('content-type');
90
- * // => "text/plain"
91
- *
92
- * req.get('Something');
93
- * // => undefined
94
- *
95
- * Aliased as `req.header()`.
96
- */
97
- get(name: 'set-cookie'): string[] | undefined;
98
- get(name: string): string | undefined;
99
- header(name: 'set-cookie'): string[] | undefined;
100
- header(name: string): string | undefined;
101
- /**
102
- * Check if the given `type(s)` is acceptable, returning
103
- * the best match when true, otherwise `undefined`, in which
104
- * case you should respond with 406 "Not Acceptable".
105
- *
106
- * The `type` value may be a single mime type string
107
- * such as "application/json", the extension name
108
- * such as "json", a comma-delimted list such as "json, html, text/plain",
109
- * or an array `["json", "html", "text/plain"]`. When a list
110
- * or array is given the _best_ match, if any is returned.
111
- *
112
- * Examples:
113
- *
114
- * // Accept: text/html
115
- * req.accepts('html');
116
- * // => "html"
117
- *
118
- * // Accept: text/*, application/json
119
- * req.accepts('html');
120
- * // => "html"
121
- * req.accepts('text/html');
122
- * // => "text/html"
123
- * req.accepts('json, text');
124
- * // => "json"
125
- * req.accepts('application/json');
126
- * // => "application/json"
127
- *
128
- * // Accept: text/*, application/json
129
- * req.accepts('image/png');
130
- * req.accepts('png');
131
- * // => undefined
132
- *
133
- * // Accept: text/*;q=.5, application/json
134
- * req.accepts(['html', 'json']);
135
- * req.accepts('html, json');
136
- * // => "json"
137
- */
138
- accepts(): string[];
139
- accepts(type: string): string | false;
140
- accepts(type: string[]): string | false;
141
- accepts(...type: string[]): string | false;
142
- /**
143
- * Returns the first accepted charset of the specified character sets,
144
- * based on the request's Accept-Charset HTTP header field.
145
- * If none of the specified charsets is accepted, returns false.
146
- *
147
- * For more information, or if you have issues or concerns, see accepts.
148
- */
149
- acceptsCharsets(): string[];
150
- acceptsCharsets(charset: string): string | false;
151
- acceptsCharsets(charset: string[]): string | false;
152
- acceptsCharsets(...charset: string[]): string | false;
153
- /**
154
- * Returns the first accepted encoding of the specified encodings,
155
- * based on the request's Accept-Encoding HTTP header field.
156
- * If none of the specified encodings is accepted, returns false.
157
- *
158
- * For more information, or if you have issues or concerns, see accepts.
159
- */
160
- acceptsEncodings(): string[];
161
- acceptsEncodings(encoding: string): string | false;
162
- acceptsEncodings(encoding: string[]): string | false;
163
- acceptsEncodings(...encoding: string[]): string | false;
164
- /**
165
- * Returns the first accepted language of the specified languages,
166
- * based on the request's Accept-Language HTTP header field.
167
- * If none of the specified languages is accepted, returns false.
168
- *
169
- * For more information, or if you have issues or concerns, see accepts.
170
- */
171
- acceptsLanguages(): string[];
172
- acceptsLanguages(lang: string): string | false;
173
- acceptsLanguages(lang: string[]): string | false;
174
- acceptsLanguages(...lang: string[]): string | false;
175
- /**
176
- * Check if the incoming request contains the "Content-Type"
177
- * header field, and it contains the give mime `type`.
178
- *
179
- * Examples:
180
- *
181
- * // With Content-Type: text/html; charset=utf-8
182
- * req.is('html');
183
- * req.is('text/html');
184
- * req.is('text/*');
185
- * // => true
186
- *
187
- * // When Content-Type is application/json
188
- * req.is('json');
189
- * req.is('application/json');
190
- * req.is('application/*');
191
- * // => true
192
- *
193
- * req.is('html');
194
- * // => false
195
- */
196
- is(type: string | string[]): string | false | null;
197
- is(...types: string[]): string | false | null;
198
- }
199
- export declare namespace HttpRequestMessage {
200
- interface Initiator extends HttpMessage.Initiator {
201
- httpVersionMajor?: number;
202
- httpVersionMinor?: number;
203
- method: string;
204
- url: string;
205
- protocol?: string;
206
- baseUrl?: string;
207
- ip?: string;
208
- ips?: [];
209
- }
210
- function create(init: Initiator): HttpRequestMessage;
211
- function fromBuffer(buffer: Buffer | ArrayBuffer): HttpRequestMessage;
212
- function fromStream(readable: Readable): Promise<HttpRequestMessage>;
213
- }
@@ -1,318 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Readable } from 'stream';
4
- import { HttpMessage, HttpMessageHost } from './http-message.host.js';
5
- import type { HttpRequestMessage } from './http-request-message.js';
6
- import { CookieOptions } from './interfaces/cookie-options.interface.js';
7
- export interface HttpResponseMessage extends HttpMessage {
8
- method?: string | undefined;
9
- url?: string | undefined;
10
- body?: any;
11
- statusCode?: number;
12
- statusMessage?: string;
13
- readonly upgrade?: any;
14
- /**
15
- * Return request header.
16
- *
17
- * The `Referrer` header field is special-cased,
18
- * both `Referrer` and `Referer` are interchangeable.
19
- *
20
- * Examples:
21
- *
22
- * req.get('Content-Type');
23
- * // => "text/plain"
24
- *
25
- * req.get('content-type');
26
- * // => "text/plain"
27
- *
28
- * req.get('Something');
29
- * // => undefined
30
- *
31
- * Aliased as `req.header()`.
32
- */
33
- get(field: string): string | undefined;
34
- getHeader(name: string): number | string | string[] | undefined;
35
- /**
36
- * Set header `field` to `val`,
37
- * or pass an object of header fields.
38
- *
39
- * Examples:
40
- *
41
- * msg.setHeader('Foo', ['bar', 'baz']);
42
- * msg.setHeader('Accept', 'application/json');
43
- * msg.setHeader({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
44
- *
45
- */
46
- setHeader(name: string, value: number | string | readonly string[]): this;
47
- /**
48
- * Set status `code`.
49
- */
50
- status(code: number): this;
51
- /**
52
- * Set the response HTTP status code to `statusCode` and send its string representation as the response body.
53
- * @link http://expressjs.com/4x/api.html#res.sendStatus
54
- *
55
- * Examples:
56
- *
57
- * res.sendStatus(200); // equivalent to res.status(200).send('OK')
58
- * res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
59
- * res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
60
- * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
61
- */
62
- sendStatus(code: number): this;
63
- /**
64
- * Set Link header field with the given `links`.
65
- *
66
- * Examples:
67
- *
68
- * res.links({
69
- * next: 'http://api.example.com/users?page=2',
70
- * last: 'http://api.example.com/users?page=5'
71
- * });
72
- */
73
- links(links: any): this;
74
- /**
75
- * Send JSON response.
76
- *
77
- * Examples:
78
- *
79
- * res.json(null);
80
- * res.json({ user: 'tj' });
81
- * res.status(500).json('oh noes!');
82
- * res.status(404).json('I dont have that');
83
- */
84
- json(body: any): this;
85
- /**
86
- * Set _Content-Type_ response header with `type` through `mime.lookup()`
87
- * when it does not contain "/", or set the Content-Type to `type` otherwise.
88
- *
89
- * Examples:
90
- *
91
- * res.type('.html');
92
- * res.type('html');
93
- * res.type('json');
94
- * res.type('application/json');
95
- * res.type('png');
96
- */
97
- contentType(type: string): this;
98
- /**
99
- * Set _Content-Type_ response header with `type` through `mime.lookup()`
100
- * when it does not contain "/", or set the Content-Type to `type` otherwise.
101
- *
102
- * Examples:
103
- *
104
- * res.type('.html');
105
- * res.type('html');
106
- * res.type('json');
107
- * res.type('application/json');
108
- * res.type('png');
109
- */
110
- type(type: string): this;
111
- /**
112
- * Set _Content-Disposition_ header to _attachment_ with optional `filename`.
113
- */
114
- attachment(filename?: string): this;
115
- /**
116
- * Set header `field` to `val`, or pass
117
- * an object of header fields.
118
- *
119
- * Examples:
120
- *
121
- * res.set('Foo', ['bar', 'baz']);
122
- * res.set('Accept', 'application/json');
123
- * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
124
- *
125
- * Aliased as `res.header()`.
126
- */
127
- set(field: any): this;
128
- set(field: string, value?: string | string[]): this;
129
- header(field: any): this;
130
- header(field: string, value?: string | string[]): this;
131
- append(field: string, value?: string | string[]): this;
132
- /** Clear cookie `name`. */
133
- clearCookie(name: string, options?: CookieOptions): this;
134
- /**
135
- * Set cookie `name` to `val`, with the given `options`.
136
- *
137
- * Options:
138
- *
139
- * - `maxAge` max-age in milliseconds, converted to `expires`
140
- * - `signed` sign the cookie
141
- * - `path` defaults to "/"
142
- *
143
- * Examples:
144
- *
145
- * // "Remember Me" for 15 minutes
146
- * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
147
- *
148
- * // save as above
149
- * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
150
- */
151
- cookie(name: string, val: string, options: CookieOptions): this;
152
- cookie(name: string, val: any, options: CookieOptions): this;
153
- cookie(name: string, val: any): this;
154
- /**
155
- * Set the location header to `url`.
156
- *
157
- * The given `url` can also be the name of a mapped url, for
158
- * example by default express supports "back" which redirects
159
- * to the _Referrer_ or _Referer_ headers or "/".
160
- *
161
- * Examples:
162
- *
163
- * res.location('/foo/bar').;
164
- * res.location('http://example.com');
165
- * res.location('../login'); // /blog/post/1 -> /blog/login
166
- *
167
- * Mounting:
168
- *
169
- * When an application is mounted and `res.location()`
170
- * is given a path that does _not_ lead with "/" it becomes
171
- * relative to the mount-point. For example if the application
172
- * is mounted at "/blog", the following would become "/blog/login".
173
- *
174
- * res.location('login');
175
- *
176
- * While the leading slash would result in a location of "/login":
177
- *
178
- * res.location('/login');
179
- */
180
- location(url: string): this;
181
- /**
182
- * Redirect to the given `url` with optional response `status`
183
- * defaulting to 302.
184
- *
185
- * The resulting `url` is determined by `res.location()`, so
186
- * it will play nicely with mounted apps, relative paths,
187
- * `"back"` etc.
188
- *
189
- * Examples:
190
- *
191
- * res.redirect('back');
192
- * res.redirect('/foo/bar');
193
- * res.redirect('http://example.com');
194
- * res.redirect(301, 'http://example.com');
195
- * res.redirect('http://example.com', 301);
196
- * res.redirect('../login'); // /blog/post/1 -> /blog/login
197
- */
198
- redirect(url: string): void;
199
- redirect(status: number, url: string): void;
200
- /** @deprecated use res.redirect(status, url) instead */
201
- redirect(url: string, status: number): void;
202
- }
203
- /**
204
- * @namespace HttpResponseMessage
205
- */
206
- export declare namespace HttpResponseMessage {
207
- interface Initiator extends HttpMessage.Initiator {
208
- statusCode?: number;
209
- statusMessage?: string;
210
- req?: HttpRequestMessage;
211
- chunkedEncoding?: boolean;
212
- }
213
- function create(init: Initiator): HttpResponseMessage;
214
- function fromBuffer(buffer: Buffer | ArrayBuffer): HttpResponseMessage;
215
- function fromStream(readable: Readable): Promise<HttpResponseMessage>;
216
- }
217
- /**
218
- * @class HttpResponseMessageHost
219
- */
220
- export declare class HttpResponseMessageHost extends HttpMessageHost implements HttpResponseMessage {
221
- chunkedEncoding?: boolean;
222
- req?: HttpRequestMessage;
223
- statusCode?: number;
224
- statusMessage?: string;
225
- constructor();
226
- header(name: 'set-cookie' | 'Set-Cookie', value: string | string[]): this;
227
- header(name: string, value: number | string): this;
228
- header(headers: Record<string, number | string | string[]>): this;
229
- append(name: string, value: string | string[]): this;
230
- /**
231
- * Set "Content-Disposition" header to "attachment" with optional `filename`.
232
- */
233
- attachment(filename?: string): this;
234
- /**
235
- * Alias for msg.type()
236
- */
237
- contentType(type: string): this;
238
- /**
239
- * Set _Content-Type_ response header with `type` through `mime.lookup()`
240
- * when it does not contain "/", or set the Content-Type to `type` otherwise.
241
- *
242
- * Examples:
243
- *
244
- * res.type('.html');
245
- * res.type('html');
246
- * res.type('json');
247
- * res.type('application/json');
248
- * res.type('png');
249
- */
250
- type(type: string): this;
251
- /**
252
- * Set cookie `name` to `value`, with the given `options`.
253
- *
254
- * Options:
255
- *
256
- * - `maxAge` max-age in milliseconds, converted to `expires`
257
- * - `signed` sign the cookie
258
- * - `path` defaults to "/"
259
- *
260
- * Examples:
261
- *
262
- * // "Remember Me" for 15 minutes
263
- * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
264
- *
265
- * // same as above
266
- * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
267
- *
268
- */
269
- cookie(name: string, value: string, options?: CookieOptions): this;
270
- /**
271
- * Clear cookie `name`.
272
- */
273
- clearCookie(name: string, options?: CookieOptions): this;
274
- /**
275
- * Set Link header field with the given `links`.
276
- *
277
- * Examples:
278
- *
279
- * res.links({
280
- * next: 'http://api.example.com/users?page=2',
281
- * last: 'http://api.example.com/users?page=5'
282
- * });
283
- *
284
- */
285
- links(links: Record<string, string>): this;
286
- redirect(url: string): any;
287
- redirect(status: number, url: string): any;
288
- /**
289
- * Send JSON response.
290
- *
291
- * Examples:
292
- *
293
- * res.json(null);
294
- * res.json({ user: 'tj' });
295
- */
296
- json(obj: any): this;
297
- location(url: string): this;
298
- /**
299
- * Set status `code`.
300
- */
301
- status(code: number): this;
302
- /**
303
- * Set the response HTTP status code to `statusCode` and send its string representation as the response body.
304
- * @link http://expressjs.com/4x/api.html#res.sendStatus
305
- *
306
- * Examples:
307
- *
308
- * res.sendStatus(200); // equivalent to res.status(200).send('OK')
309
- * res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
310
- * res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
311
- * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
312
- */
313
- sendStatus(statusCode: number): this;
314
- protected _init(init: HttpResponseMessage.Initiator): void;
315
- static create(init: HttpResponseMessage.Initiator): HttpResponseMessage;
316
- static fromBuffer(buffer: Buffer | ArrayBuffer): HttpResponseMessage;
317
- static fromStream(readable: Readable): Promise<HttpResponseMessage>;
318
- }
@@ -1,4 +0,0 @@
1
- import cookie from 'cookie';
2
- export interface CookieOptions extends cookie.CookieSerializeOptions {
3
- signed?: boolean;
4
- }