ovr 4.6.0 → 6.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/dist/LICENSE.md +26 -0
- package/dist/app/index.d.ts +55 -103
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +67 -145
- package/dist/context/index.d.ts +138 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +218 -0
- package/dist/cookie/index.d.ts +121 -0
- package/dist/cookie/index.d.ts.map +1 -0
- package/dist/cookie/index.js +56 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/jsx/{intrinsic-elements.d.ts → elements.d.ts} +14 -7
- package/dist/jsx/elements.d.ts.map +1 -0
- package/dist/jsx/index.d.ts +37 -52
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +71 -197
- package/dist/middleware/index.d.ts +22 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/multipart/index.d.ts +122 -0
- package/dist/multipart/index.d.ts.map +1 -0
- package/dist/multipart/index.js +341 -0
- package/dist/render/index.d.ts +78 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +248 -0
- package/dist/route/index.d.ts +147 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +126 -0
- package/dist/trie/index.d.ts +31 -26
- package/dist/trie/index.d.ts.map +1 -1
- package/dist/trie/index.js +71 -80
- package/dist/util/index.d.ts +38 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +88 -0
- package/package.json +4 -4
- package/src/app/index.ts +128 -265
- package/src/context/index.ts +262 -0
- package/src/cookie/index.ts +189 -0
- package/src/index.ts +6 -8
- package/src/jsx/{intrinsic-elements.ts → elements.ts} +14 -7
- package/src/jsx/index.ts +81 -222
- package/src/middleware/index.ts +29 -0
- package/src/multipart/index.ts +486 -0
- package/src/render/index.ts +300 -0
- package/src/route/index.ts +332 -0
- package/src/trie/index.ts +90 -107
- package/src/util/index.ts +112 -0
- package/dist/app/context.d.ts +0 -147
- package/dist/app/context.d.ts.map +0 -1
- package/dist/app/context.js +0 -283
- package/dist/app/helper/get.d.ts +0 -30
- package/dist/app/helper/get.d.ts.map +0 -1
- package/dist/app/helper/get.js +0 -33
- package/dist/app/helper/index.d.ts +0 -55
- package/dist/app/helper/index.d.ts.map +0 -1
- package/dist/app/helper/index.js +0 -96
- package/dist/app/helper/post.d.ts +0 -35
- package/dist/app/helper/post.d.ts.map +0 -1
- package/dist/app/helper/post.js +0 -15
- package/dist/app/memo/index.d.ts +0 -12
- package/dist/app/memo/index.d.ts.map +0 -1
- package/dist/app/memo/index.js +0 -34
- package/dist/app/mw/csrf.d.ts +0 -23
- package/dist/app/mw/csrf.d.ts.map +0 -1
- package/dist/app/mw/csrf.js +0 -30
- package/dist/jsx/chunk/index.d.ts +0 -38
- package/dist/jsx/chunk/index.d.ts.map +0 -1
- package/dist/jsx/chunk/index.js +0 -69
- package/dist/jsx/intrinsic-elements.d.ts.map +0 -1
- package/dist/jsx/merge-async-generators.d.ts +0 -14
- package/dist/jsx/merge-async-generators.d.ts.map +0 -1
- package/dist/jsx/merge-async-generators.js +0 -42
- package/dist/types/index.d.ts +0 -17
- package/dist/types/index.d.ts.map +0 -1
- package/dist/util/hash.d.ts +0 -11
- package/dist/util/hash.d.ts.map +0 -1
- package/dist/util/hash.js +0 -16
- package/src/app/context.ts +0 -365
- package/src/app/helper/get.ts +0 -46
- package/src/app/helper/index.ts +0 -174
- package/src/app/helper/post.ts +0 -54
- package/src/app/memo/index.ts +0 -40
- package/src/app/mw/csrf.ts +0 -32
- package/src/jsx/chunk/index.ts +0 -79
- package/src/jsx/merge-async-generators.ts +0 -47
- package/src/types/index.ts +0 -42
- package/src/util/hash.ts +0 -17
- /package/dist/jsx/{intrinsic-elements.js → elements.js} +0 -0
- /package/dist/{types → middleware}/index.js +0 -0
package/dist/trie/index.js
CHANGED
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
export class Route {
|
|
2
|
-
/** Route pattern */
|
|
3
|
-
pattern;
|
|
4
|
-
/** Store returned when route is found */
|
|
5
|
-
store;
|
|
6
|
-
constructor(pattern, store) {
|
|
7
|
-
if (pattern[0] !== "/") {
|
|
8
|
-
throw new Error(`Invalid route: ${pattern} - route pattern must begin with "/"`);
|
|
9
|
-
}
|
|
10
|
-
this.pattern = pattern;
|
|
11
|
-
this.store = store;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
1
|
class ParamNode {
|
|
15
2
|
/** Name of the parameter (without the colon ":") */
|
|
16
3
|
name;
|
|
17
4
|
/** Matched route */
|
|
18
|
-
route
|
|
5
|
+
route;
|
|
19
6
|
/** Static child node */
|
|
20
|
-
|
|
7
|
+
child;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new parameter node.
|
|
10
|
+
*
|
|
11
|
+
* @param name Name of the parameter.
|
|
12
|
+
*/
|
|
21
13
|
constructor(name) {
|
|
22
14
|
this.name = name;
|
|
23
15
|
}
|
|
24
16
|
}
|
|
25
17
|
export class Trie {
|
|
26
18
|
/** Unique segment of the pattern trie */
|
|
27
|
-
|
|
19
|
+
seg;
|
|
28
20
|
/** Static child node map, key is the first character in the segment */
|
|
29
|
-
|
|
21
|
+
map;
|
|
30
22
|
/** Parametric child node */
|
|
31
|
-
|
|
23
|
+
param;
|
|
32
24
|
/** Matched route */
|
|
33
|
-
route
|
|
25
|
+
route;
|
|
34
26
|
/** Matched wildcard route */
|
|
35
|
-
|
|
27
|
+
wild;
|
|
28
|
+
static #paramMatch = /:.+?(?=\/|$)/g;
|
|
29
|
+
static #paramSplit = /:.+?(?=\/|$)/;
|
|
36
30
|
/**
|
|
31
|
+
* Create a new trie.
|
|
32
|
+
*
|
|
37
33
|
* @param segment pattern segment
|
|
38
|
-
* @param
|
|
34
|
+
* @param children static children nodes to add to staticMap
|
|
39
35
|
*/
|
|
40
|
-
constructor(segment = "/",
|
|
41
|
-
this.
|
|
42
|
-
if (
|
|
43
|
-
this.
|
|
44
|
-
for (const child of
|
|
45
|
-
this.
|
|
36
|
+
constructor(segment = "/", children) {
|
|
37
|
+
this.seg = segment;
|
|
38
|
+
if (children?.length) {
|
|
39
|
+
this.map ??= new Map();
|
|
40
|
+
for (const child of children) {
|
|
41
|
+
this.map.set(child.seg.charCodeAt(0), child);
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
}
|
|
@@ -52,10 +48,10 @@ export class Trie {
|
|
|
52
48
|
*/
|
|
53
49
|
clone(segment) {
|
|
54
50
|
const clone = new Trie(segment);
|
|
55
|
-
clone.
|
|
56
|
-
clone.
|
|
51
|
+
clone.map = this.map;
|
|
52
|
+
clone.param = this.param;
|
|
57
53
|
clone.route = this.route;
|
|
58
|
-
clone.
|
|
54
|
+
clone.wild = this.wild;
|
|
59
55
|
return clone;
|
|
60
56
|
}
|
|
61
57
|
/**
|
|
@@ -68,11 +64,13 @@ export class Trie {
|
|
|
68
64
|
* @returns the new child produced from the new segment
|
|
69
65
|
*/
|
|
70
66
|
fork(charIndex, segment) {
|
|
71
|
-
const existingChild = this.clone(this.segment.slice(charIndex)); // "posts/"
|
|
72
67
|
const newChild = new Trie(segment.slice(charIndex)); // "movies/"
|
|
73
68
|
Object.assign(this,
|
|
74
69
|
// "api/" with the above as children
|
|
75
|
-
new Trie(this.
|
|
70
|
+
new Trie(this.seg.slice(0, charIndex), [
|
|
71
|
+
this.clone(this.seg.slice(charIndex)), // "posts/"
|
|
72
|
+
newChild,
|
|
73
|
+
]));
|
|
76
74
|
return newChild;
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
@@ -83,19 +81,14 @@ export class Trie {
|
|
|
83
81
|
* @param segment
|
|
84
82
|
*/
|
|
85
83
|
split(segment) {
|
|
86
|
-
|
|
87
|
-
Object.assign(this, new Trie(segment, [secondHalf]));
|
|
84
|
+
Object.assign(this, new Trie(segment, [this.clone(this.seg.slice(segment.length))]));
|
|
88
85
|
}
|
|
89
86
|
/**
|
|
90
87
|
* @param name name of the param
|
|
91
88
|
* @returns the existing child with the same name, or creates a new
|
|
92
89
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
throw new Error(`Cannot create parameter "${name}" because a different parameter ` +
|
|
96
|
-
`("${this.paramChild.name}") already exists in this location.\n\n${this}`);
|
|
97
|
-
}
|
|
98
|
-
return (this.paramChild ??= new ParamNode(name));
|
|
90
|
+
set(name) {
|
|
91
|
+
return (this.param ??= new ParamNode(name));
|
|
99
92
|
}
|
|
100
93
|
/**
|
|
101
94
|
* @param route route return when pattern is matched
|
|
@@ -103,12 +96,12 @@ export class Trie {
|
|
|
103
96
|
*/
|
|
104
97
|
add(route) {
|
|
105
98
|
let current = this;
|
|
106
|
-
let pattern = route.pattern; // created to not modify the original
|
|
99
|
+
let pattern = route.method + route.pattern; // created to not modify the original
|
|
107
100
|
const endsWithWildcard = pattern.endsWith("*");
|
|
108
101
|
if (endsWithWildcard)
|
|
109
102
|
pattern = pattern.slice(0, -1);
|
|
110
|
-
const paramSegments = pattern.match(
|
|
111
|
-
const staticSegments = pattern.split(
|
|
103
|
+
const paramSegments = pattern.match(Trie.#paramMatch) ?? [];
|
|
104
|
+
const staticSegments = pattern.split(Trie.#paramSplit);
|
|
112
105
|
// if the last segment is a param without a trailing slash
|
|
113
106
|
// then there will be an empty string, remove
|
|
114
107
|
if (staticSegments.at(-1) === "")
|
|
@@ -120,37 +113,37 @@ export class Trie {
|
|
|
120
113
|
if (staticIndex > 0) {
|
|
121
114
|
// there is only a second static segment (could just be "/")
|
|
122
115
|
// if there is a param to split them, so there must be a param here
|
|
123
|
-
const paramChild = current.
|
|
116
|
+
const paramChild = current.set(
|
|
124
117
|
// param without the ":" (only increment when this is reached)
|
|
125
118
|
paramSegments[paramIndex++].slice(1));
|
|
126
|
-
if (!paramChild.
|
|
119
|
+
if (!paramChild.child) {
|
|
127
120
|
// new - create node with the next static segment
|
|
128
|
-
current = paramChild.
|
|
121
|
+
current = paramChild.child = new Trie(staticSegment);
|
|
129
122
|
continue; // next segment - no need to check since it's new
|
|
130
123
|
}
|
|
131
124
|
// there's already a static child - need to check if it's a match
|
|
132
|
-
current = paramChild.
|
|
125
|
+
current = paramChild.child;
|
|
133
126
|
}
|
|
134
127
|
// check if the staticSegment matches the current node
|
|
135
128
|
for (let charIndex = 0;;) {
|
|
136
129
|
if (charIndex === staticSegment.length) {
|
|
137
130
|
// finished iterating through the staticSegment
|
|
138
|
-
if (charIndex < current.
|
|
131
|
+
if (charIndex < current.seg.length) {
|
|
139
132
|
// too short
|
|
140
133
|
current.split(staticSegment);
|
|
141
134
|
}
|
|
142
135
|
break; // next segment
|
|
143
136
|
}
|
|
144
|
-
if (charIndex === current.
|
|
137
|
+
if (charIndex === current.seg.length) {
|
|
145
138
|
// passed the end of the current node
|
|
146
|
-
if (!current.
|
|
139
|
+
if (!current.map) {
|
|
147
140
|
// new pattern, create new leaf
|
|
148
|
-
current.
|
|
141
|
+
current.map = new Map();
|
|
149
142
|
}
|
|
150
143
|
else {
|
|
151
144
|
// there's already static children,
|
|
152
145
|
// check to see if there's a leaf that starts with the char
|
|
153
|
-
const staticChild = current.
|
|
146
|
+
const staticChild = current.map.get(staticSegment.charCodeAt(charIndex));
|
|
154
147
|
if (staticChild) {
|
|
155
148
|
// re-run loop with existing staticChild
|
|
156
149
|
current = staticChild;
|
|
@@ -161,11 +154,11 @@ export class Trie {
|
|
|
161
154
|
}
|
|
162
155
|
// otherwise, add new staticChild
|
|
163
156
|
const staticChild = new Trie(staticSegment.slice(charIndex));
|
|
164
|
-
current.
|
|
157
|
+
current.map.set(staticSegment.charCodeAt(charIndex), staticChild);
|
|
165
158
|
current = staticChild;
|
|
166
159
|
break; // next segment
|
|
167
160
|
}
|
|
168
|
-
if (staticSegment[charIndex] !== current.
|
|
161
|
+
if (staticSegment[charIndex] !== current.seg[charIndex]) {
|
|
169
162
|
// different than the node - fork
|
|
170
163
|
current = current.fork(charIndex, staticSegment);
|
|
171
164
|
break; // next segment
|
|
@@ -176,16 +169,15 @@ export class Trie {
|
|
|
176
169
|
}
|
|
177
170
|
if (paramIndex < paramSegments.length) {
|
|
178
171
|
// final segment is a param
|
|
179
|
-
current.
|
|
180
|
-
route;
|
|
172
|
+
current.set(paramSegments[paramIndex].slice(1)).route = route;
|
|
181
173
|
}
|
|
182
174
|
else if (endsWithWildcard) {
|
|
183
175
|
// final segment is a wildcard
|
|
184
|
-
current.
|
|
176
|
+
current.wild = route;
|
|
185
177
|
}
|
|
186
178
|
else {
|
|
187
179
|
// final segment is static
|
|
188
|
-
current.route
|
|
180
|
+
current.route = route;
|
|
189
181
|
}
|
|
190
182
|
return this;
|
|
191
183
|
}
|
|
@@ -194,64 +186,63 @@ export class Trie {
|
|
|
194
186
|
* @returns `Route` and the matched `params` if found, otherwise `null`
|
|
195
187
|
*/
|
|
196
188
|
find(pathname) {
|
|
189
|
+
const segmentLength = this.seg.length;
|
|
197
190
|
if (
|
|
198
191
|
// too short
|
|
199
|
-
pathname.length <
|
|
192
|
+
pathname.length < segmentLength ||
|
|
200
193
|
// segment does not match current node segment
|
|
201
|
-
!pathname.startsWith(this.
|
|
194
|
+
!pathname.startsWith(this.seg)) {
|
|
202
195
|
return null;
|
|
203
196
|
}
|
|
204
|
-
if (pathname === this.
|
|
197
|
+
if (pathname === this.seg) {
|
|
205
198
|
// reached the end of the path
|
|
206
199
|
if (this.route)
|
|
207
200
|
return { route: this.route, params: {} };
|
|
208
|
-
if (this.
|
|
209
|
-
return { route: this.
|
|
201
|
+
if (this.wild)
|
|
202
|
+
return { route: this.wild, params: { "*": "" } };
|
|
210
203
|
return null;
|
|
211
204
|
}
|
|
212
|
-
if (this.
|
|
205
|
+
if (this.map) {
|
|
213
206
|
// check for a static leaf that starts with the first character
|
|
214
|
-
const staticChild = this.
|
|
207
|
+
const staticChild = this.map.get(pathname.charCodeAt(segmentLength));
|
|
215
208
|
if (staticChild) {
|
|
216
|
-
const result = staticChild.find(pathname.slice(
|
|
209
|
+
const result = staticChild.find(pathname.slice(segmentLength));
|
|
217
210
|
if (result)
|
|
218
211
|
return result;
|
|
219
212
|
}
|
|
220
213
|
}
|
|
221
214
|
// check for param leaf
|
|
222
|
-
if (this.
|
|
223
|
-
const slashIndex = pathname.indexOf("/",
|
|
215
|
+
if (this.param) {
|
|
216
|
+
const slashIndex = pathname.indexOf("/", segmentLength);
|
|
224
217
|
// if there is not a slash immediately following this.segment
|
|
225
|
-
if (slashIndex !==
|
|
218
|
+
if (slashIndex !== segmentLength) {
|
|
226
219
|
// there is a valid parameter
|
|
227
220
|
if (
|
|
228
221
|
// param is the end of the pathname
|
|
229
222
|
slashIndex === -1 &&
|
|
230
|
-
this.
|
|
223
|
+
this.param.route) {
|
|
231
224
|
return {
|
|
232
|
-
route: this.
|
|
233
|
-
params: {
|
|
234
|
-
[this.paramChild.name]: pathname.slice(this.segment.length),
|
|
235
|
-
},
|
|
225
|
+
route: this.param.route,
|
|
226
|
+
params: { [this.param.name]: pathname.slice(segmentLength) },
|
|
236
227
|
};
|
|
237
228
|
}
|
|
238
|
-
else if (this.
|
|
229
|
+
else if (this.param.child) {
|
|
239
230
|
// there's a static node after the param
|
|
240
231
|
// this is how there can be multiple params, "/" in between
|
|
241
|
-
const result = this.
|
|
232
|
+
const result = this.param.child.find(pathname.slice(slashIndex));
|
|
242
233
|
if (result) {
|
|
243
234
|
// add original params to the result
|
|
244
|
-
result.params[this.
|
|
235
|
+
result.params[this.param.name] = pathname.slice(segmentLength, slashIndex);
|
|
245
236
|
return result;
|
|
246
237
|
}
|
|
247
238
|
}
|
|
248
239
|
}
|
|
249
240
|
}
|
|
250
241
|
// check for wildcard leaf
|
|
251
|
-
if (this.
|
|
242
|
+
if (this.wild) {
|
|
252
243
|
return {
|
|
253
|
-
route: this.
|
|
254
|
-
params: { "*": pathname.slice(
|
|
244
|
+
route: this.wild,
|
|
245
|
+
params: { "*": pathname.slice(segmentLength) },
|
|
255
246
|
};
|
|
256
247
|
}
|
|
257
248
|
return null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** General utility types */
|
|
2
|
+
export declare namespace Util {
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
type MaybeFunction<T> = T | (() => T);
|
|
5
|
+
type DeepArray<T> = T | DeepArray<T>[];
|
|
6
|
+
}
|
|
7
|
+
/** Header parsing utils */
|
|
8
|
+
export declare class Header {
|
|
9
|
+
static readonly contentType = "content-type";
|
|
10
|
+
/**
|
|
11
|
+
* @param header header value to parse
|
|
12
|
+
* @returns Base/first param
|
|
13
|
+
*/
|
|
14
|
+
static shift(header: string | null): [string | null, string | null];
|
|
15
|
+
/**
|
|
16
|
+
* @param header header value to parse
|
|
17
|
+
* @returns Map containing each key=value pair
|
|
18
|
+
*/
|
|
19
|
+
static params(header: string | null): Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
/** Hash util */
|
|
22
|
+
export declare class Hash {
|
|
23
|
+
/**
|
|
24
|
+
* Fast hashing algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
25
|
+
*
|
|
26
|
+
* @param s String to hash
|
|
27
|
+
* @returns Hashed string
|
|
28
|
+
*/
|
|
29
|
+
static djb2(s: string): string;
|
|
30
|
+
}
|
|
31
|
+
/** Shared encoding to use across features */
|
|
32
|
+
export declare class Codec {
|
|
33
|
+
#private;
|
|
34
|
+
static encode: (s: string) => Uint8Array<ArrayBuffer>;
|
|
35
|
+
/** DO NOT USE FOR STREAMS */
|
|
36
|
+
static decode: (input?: Uint8Array) => string;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,yBAAiB,IAAI,CAAC;IACrB,KAAY,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7C,KAAY,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7C,KAAY,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;CAC9C;AAED,2BAA2B;AAC3B,qBAAa,MAAM;IAElB,MAAM,CAAC,QAAQ,CAAC,WAAW,kBAAkB;IAE7C;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAWnE;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAmDnC;AAED,gBAAgB;AAChB,qBAAa,IAAI;IAChB;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM;CAQrB;AAED,6CAA6C;AAC7C,qBAAa,KAAK;;IAIjB,MAAM,CAAC,MAAM,GAAI,GAAG,MAAM,6BAA8B;IAExD,6BAA6B;IAC7B,MAAM,CAAC,MAAM,GAAI,QAAQ,UAAU,YAAkC;CACrE"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Header parsing utils */
|
|
2
|
+
export class Header {
|
|
3
|
+
// shared content type header to minify better
|
|
4
|
+
static contentType = "content-type";
|
|
5
|
+
/**
|
|
6
|
+
* @param header header value to parse
|
|
7
|
+
* @returns Base/first param
|
|
8
|
+
*/
|
|
9
|
+
static shift(header) {
|
|
10
|
+
if (header) {
|
|
11
|
+
const semi = header.indexOf(";");
|
|
12
|
+
if (semi !== -1) {
|
|
13
|
+
return [header.slice(0, semi), header.slice(semi)];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return [header, null];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @param header header value to parse
|
|
20
|
+
* @returns Map containing each key=value pair
|
|
21
|
+
*/
|
|
22
|
+
static params(header) {
|
|
23
|
+
const parsed = {};
|
|
24
|
+
if (header) {
|
|
25
|
+
const headerLength = header.length;
|
|
26
|
+
for (let cursor = 0; cursor < headerLength;) {
|
|
27
|
+
const equal = header.indexOf("=", cursor);
|
|
28
|
+
if (equal === -1)
|
|
29
|
+
break; // done
|
|
30
|
+
let semi = header.indexOf(";", cursor);
|
|
31
|
+
if (semi === -1)
|
|
32
|
+
semi = headerLength;
|
|
33
|
+
if (equal > semi) {
|
|
34
|
+
// equal is in the next pair, current is malformed
|
|
35
|
+
// move the cursor to the start of the next and ignore
|
|
36
|
+
cursor = header.lastIndexOf(";", equal - 1) + 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const key = header.slice(cursor, equal).trim();
|
|
40
|
+
if (!(key in parsed)) {
|
|
41
|
+
// first value should take precedence
|
|
42
|
+
let value = header.slice(equal + 1, semi).trim();
|
|
43
|
+
if (value[0] === '"' && value[value.length - 1] === '"') {
|
|
44
|
+
// remove quotes
|
|
45
|
+
value = value.slice(1, -1);
|
|
46
|
+
}
|
|
47
|
+
if (value.includes("%")) {
|
|
48
|
+
// most values don't need to be decoded
|
|
49
|
+
try {
|
|
50
|
+
// cookies must be a simple string
|
|
51
|
+
value = decodeURIComponent(value);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// ignore
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
parsed[key] = value;
|
|
58
|
+
}
|
|
59
|
+
cursor = semi + 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return parsed;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Hash util */
|
|
66
|
+
export class Hash {
|
|
67
|
+
/**
|
|
68
|
+
* Fast hashing algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
69
|
+
*
|
|
70
|
+
* @param s String to hash
|
|
71
|
+
* @returns Hashed string
|
|
72
|
+
*/
|
|
73
|
+
static djb2(s) {
|
|
74
|
+
let hash = 5381;
|
|
75
|
+
let i = s.length;
|
|
76
|
+
while (i)
|
|
77
|
+
hash = (hash * 33) ^ s.charCodeAt(--i);
|
|
78
|
+
return (hash >>> 0).toString(36);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Shared encoding to use across features */
|
|
82
|
+
export class Codec {
|
|
83
|
+
static #encoder = new TextEncoder();
|
|
84
|
+
static #decoder = new TextDecoder("utf-8", { fatal: true });
|
|
85
|
+
static encode = (s) => Codec.#encoder.encode(s);
|
|
86
|
+
/** DO NOT USE FOR STREAMS */
|
|
87
|
+
static decode = (input) => Codec.#decoder.decode(input);
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ovr",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "
|
|
3
|
+
"description": "The Streaming Framework",
|
|
4
|
+
"version": "6.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/ovrjs/ovr.git"
|
|
9
9
|
},
|
|
10
10
|
"author": {
|
|
11
11
|
"name": "Ross Robino",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"check": "tsc --noEmit",
|
|
42
42
|
"dev": "tsc --watch",
|
|
43
|
-
"build": "tsc"
|
|
43
|
+
"build": "tsc && cp ../../LICENSE.md dist"
|
|
44
44
|
}
|
|
45
45
|
}
|