ovr 5.0.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 +49 -83
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +40 -92
- 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 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- 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 -200
- 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 +30 -30
- package/dist/trie/index.d.ts.map +1 -1
- package/dist/trie/index.js +67 -82
- 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 +3 -3
- package/src/app/index.ts +99 -224
- package/src/context/index.ts +262 -0
- package/src/cookie/index.ts +189 -0
- package/src/index.ts +6 -7
- package/src/jsx/{intrinsic-elements.ts → elements.ts} +14 -7
- package/src/jsx/index.ts +81 -223
- 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 +87 -111
- package/src/util/index.ts +112 -0
- package/dist/app/context.d.ts +0 -149
- package/dist/app/context.d.ts.map +0 -1
- package/dist/app/context.js +0 -246
- 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 -51
- package/dist/app/helper/index.d.ts.map +0 -1
- package/dist/app/helper/index.js +0 -82
- 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/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 -303
- package/src/app/helper/get.ts +0 -46
- package/src/app/helper/index.ts +0 -156
- package/src/app/helper/post.ts +0 -54
- package/src/app/memo/index.ts +0 -40
- 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,54 +1,44 @@
|
|
|
1
|
-
export class Route {
|
|
2
|
-
/** Route pattern */
|
|
3
|
-
pattern;
|
|
4
|
-
/** Store returned when route is found */
|
|
5
|
-
store;
|
|
6
|
-
/**
|
|
7
|
-
* @param pattern route pattern
|
|
8
|
-
* @param store value to store in the patterns final node
|
|
9
|
-
*/
|
|
10
|
-
constructor(pattern, store) {
|
|
11
|
-
if (pattern[0] !== "/") {
|
|
12
|
-
throw new Error(`Invalid route: ${pattern} - route pattern must begin with "/"`);
|
|
13
|
-
}
|
|
14
|
-
this.pattern = pattern;
|
|
15
|
-
this.store = store;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
1
|
class ParamNode {
|
|
19
2
|
/** Name of the parameter (without the colon ":") */
|
|
20
3
|
name;
|
|
21
4
|
/** Matched route */
|
|
22
|
-
route
|
|
5
|
+
route;
|
|
23
6
|
/** Static child node */
|
|
24
|
-
|
|
7
|
+
child;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new parameter node.
|
|
10
|
+
*
|
|
11
|
+
* @param name Name of the parameter.
|
|
12
|
+
*/
|
|
25
13
|
constructor(name) {
|
|
26
14
|
this.name = name;
|
|
27
15
|
}
|
|
28
16
|
}
|
|
29
17
|
export class Trie {
|
|
30
18
|
/** Unique segment of the pattern trie */
|
|
31
|
-
|
|
19
|
+
seg;
|
|
32
20
|
/** Static child node map, key is the first character in the segment */
|
|
33
|
-
|
|
21
|
+
map;
|
|
34
22
|
/** Parametric child node */
|
|
35
|
-
|
|
23
|
+
param;
|
|
36
24
|
/** Matched route */
|
|
37
|
-
route
|
|
25
|
+
route;
|
|
38
26
|
/** Matched wildcard route */
|
|
39
|
-
|
|
27
|
+
wild;
|
|
40
28
|
static #paramMatch = /:.+?(?=\/|$)/g;
|
|
41
29
|
static #paramSplit = /:.+?(?=\/|$)/;
|
|
42
30
|
/**
|
|
31
|
+
* Create a new trie.
|
|
32
|
+
*
|
|
43
33
|
* @param segment pattern segment
|
|
44
|
-
* @param
|
|
34
|
+
* @param children static children nodes to add to staticMap
|
|
45
35
|
*/
|
|
46
|
-
constructor(segment = "/",
|
|
47
|
-
this.
|
|
48
|
-
if (
|
|
49
|
-
this.
|
|
50
|
-
for (const child of
|
|
51
|
-
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);
|
|
52
42
|
}
|
|
53
43
|
}
|
|
54
44
|
}
|
|
@@ -58,10 +48,10 @@ export class Trie {
|
|
|
58
48
|
*/
|
|
59
49
|
clone(segment) {
|
|
60
50
|
const clone = new Trie(segment);
|
|
61
|
-
clone.
|
|
62
|
-
clone.
|
|
51
|
+
clone.map = this.map;
|
|
52
|
+
clone.param = this.param;
|
|
63
53
|
clone.route = this.route;
|
|
64
|
-
clone.
|
|
54
|
+
clone.wild = this.wild;
|
|
65
55
|
return clone;
|
|
66
56
|
}
|
|
67
57
|
/**
|
|
@@ -74,11 +64,13 @@ export class Trie {
|
|
|
74
64
|
* @returns the new child produced from the new segment
|
|
75
65
|
*/
|
|
76
66
|
fork(charIndex, segment) {
|
|
77
|
-
const existingChild = this.clone(this.segment.slice(charIndex)); // "posts/"
|
|
78
67
|
const newChild = new Trie(segment.slice(charIndex)); // "movies/"
|
|
79
68
|
Object.assign(this,
|
|
80
69
|
// "api/" with the above as children
|
|
81
|
-
new Trie(this.
|
|
70
|
+
new Trie(this.seg.slice(0, charIndex), [
|
|
71
|
+
this.clone(this.seg.slice(charIndex)), // "posts/"
|
|
72
|
+
newChild,
|
|
73
|
+
]));
|
|
82
74
|
return newChild;
|
|
83
75
|
}
|
|
84
76
|
/**
|
|
@@ -89,19 +81,14 @@ export class Trie {
|
|
|
89
81
|
* @param segment
|
|
90
82
|
*/
|
|
91
83
|
split(segment) {
|
|
92
|
-
|
|
93
|
-
Object.assign(this, new Trie(segment, [secondHalf]));
|
|
84
|
+
Object.assign(this, new Trie(segment, [this.clone(this.seg.slice(segment.length))]));
|
|
94
85
|
}
|
|
95
86
|
/**
|
|
96
87
|
* @param name name of the param
|
|
97
88
|
* @returns the existing child with the same name, or creates a new
|
|
98
89
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
throw new Error(`Cannot create parameter "${name}" because a different parameter ` +
|
|
102
|
-
`("${this.paramChild.name}") already exists in this location.\n\n${this}`);
|
|
103
|
-
}
|
|
104
|
-
return (this.paramChild ??= new ParamNode(name));
|
|
90
|
+
set(name) {
|
|
91
|
+
return (this.param ??= new ParamNode(name));
|
|
105
92
|
}
|
|
106
93
|
/**
|
|
107
94
|
* @param route route return when pattern is matched
|
|
@@ -109,7 +96,7 @@ export class Trie {
|
|
|
109
96
|
*/
|
|
110
97
|
add(route) {
|
|
111
98
|
let current = this;
|
|
112
|
-
let pattern = route.pattern; // created to not modify the original
|
|
99
|
+
let pattern = route.method + route.pattern; // created to not modify the original
|
|
113
100
|
const endsWithWildcard = pattern.endsWith("*");
|
|
114
101
|
if (endsWithWildcard)
|
|
115
102
|
pattern = pattern.slice(0, -1);
|
|
@@ -126,37 +113,37 @@ export class Trie {
|
|
|
126
113
|
if (staticIndex > 0) {
|
|
127
114
|
// there is only a second static segment (could just be "/")
|
|
128
115
|
// if there is a param to split them, so there must be a param here
|
|
129
|
-
const paramChild = current.
|
|
116
|
+
const paramChild = current.set(
|
|
130
117
|
// param without the ":" (only increment when this is reached)
|
|
131
118
|
paramSegments[paramIndex++].slice(1));
|
|
132
|
-
if (!paramChild.
|
|
119
|
+
if (!paramChild.child) {
|
|
133
120
|
// new - create node with the next static segment
|
|
134
|
-
current = paramChild.
|
|
121
|
+
current = paramChild.child = new Trie(staticSegment);
|
|
135
122
|
continue; // next segment - no need to check since it's new
|
|
136
123
|
}
|
|
137
124
|
// there's already a static child - need to check if it's a match
|
|
138
|
-
current = paramChild.
|
|
125
|
+
current = paramChild.child;
|
|
139
126
|
}
|
|
140
127
|
// check if the staticSegment matches the current node
|
|
141
128
|
for (let charIndex = 0;;) {
|
|
142
129
|
if (charIndex === staticSegment.length) {
|
|
143
130
|
// finished iterating through the staticSegment
|
|
144
|
-
if (charIndex < current.
|
|
131
|
+
if (charIndex < current.seg.length) {
|
|
145
132
|
// too short
|
|
146
133
|
current.split(staticSegment);
|
|
147
134
|
}
|
|
148
135
|
break; // next segment
|
|
149
136
|
}
|
|
150
|
-
if (charIndex === current.
|
|
137
|
+
if (charIndex === current.seg.length) {
|
|
151
138
|
// passed the end of the current node
|
|
152
|
-
if (!current.
|
|
139
|
+
if (!current.map) {
|
|
153
140
|
// new pattern, create new leaf
|
|
154
|
-
current.
|
|
141
|
+
current.map = new Map();
|
|
155
142
|
}
|
|
156
143
|
else {
|
|
157
144
|
// there's already static children,
|
|
158
145
|
// check to see if there's a leaf that starts with the char
|
|
159
|
-
const staticChild = current.
|
|
146
|
+
const staticChild = current.map.get(staticSegment.charCodeAt(charIndex));
|
|
160
147
|
if (staticChild) {
|
|
161
148
|
// re-run loop with existing staticChild
|
|
162
149
|
current = staticChild;
|
|
@@ -167,11 +154,11 @@ export class Trie {
|
|
|
167
154
|
}
|
|
168
155
|
// otherwise, add new staticChild
|
|
169
156
|
const staticChild = new Trie(staticSegment.slice(charIndex));
|
|
170
|
-
current.
|
|
157
|
+
current.map.set(staticSegment.charCodeAt(charIndex), staticChild);
|
|
171
158
|
current = staticChild;
|
|
172
159
|
break; // next segment
|
|
173
160
|
}
|
|
174
|
-
if (staticSegment[charIndex] !== current.
|
|
161
|
+
if (staticSegment[charIndex] !== current.seg[charIndex]) {
|
|
175
162
|
// different than the node - fork
|
|
176
163
|
current = current.fork(charIndex, staticSegment);
|
|
177
164
|
break; // next segment
|
|
@@ -182,16 +169,15 @@ export class Trie {
|
|
|
182
169
|
}
|
|
183
170
|
if (paramIndex < paramSegments.length) {
|
|
184
171
|
// final segment is a param
|
|
185
|
-
current.
|
|
186
|
-
route;
|
|
172
|
+
current.set(paramSegments[paramIndex].slice(1)).route = route;
|
|
187
173
|
}
|
|
188
174
|
else if (endsWithWildcard) {
|
|
189
175
|
// final segment is a wildcard
|
|
190
|
-
current.
|
|
176
|
+
current.wild = route;
|
|
191
177
|
}
|
|
192
178
|
else {
|
|
193
179
|
// final segment is static
|
|
194
|
-
current.route
|
|
180
|
+
current.route = route;
|
|
195
181
|
}
|
|
196
182
|
return this;
|
|
197
183
|
}
|
|
@@ -200,64 +186,63 @@ export class Trie {
|
|
|
200
186
|
* @returns `Route` and the matched `params` if found, otherwise `null`
|
|
201
187
|
*/
|
|
202
188
|
find(pathname) {
|
|
189
|
+
const segmentLength = this.seg.length;
|
|
203
190
|
if (
|
|
204
191
|
// too short
|
|
205
|
-
pathname.length <
|
|
192
|
+
pathname.length < segmentLength ||
|
|
206
193
|
// segment does not match current node segment
|
|
207
|
-
!pathname.startsWith(this.
|
|
194
|
+
!pathname.startsWith(this.seg)) {
|
|
208
195
|
return null;
|
|
209
196
|
}
|
|
210
|
-
if (pathname === this.
|
|
197
|
+
if (pathname === this.seg) {
|
|
211
198
|
// reached the end of the path
|
|
212
199
|
if (this.route)
|
|
213
200
|
return { route: this.route, params: {} };
|
|
214
|
-
if (this.
|
|
215
|
-
return { route: this.
|
|
201
|
+
if (this.wild)
|
|
202
|
+
return { route: this.wild, params: { "*": "" } };
|
|
216
203
|
return null;
|
|
217
204
|
}
|
|
218
|
-
if (this.
|
|
205
|
+
if (this.map) {
|
|
219
206
|
// check for a static leaf that starts with the first character
|
|
220
|
-
const staticChild = this.
|
|
207
|
+
const staticChild = this.map.get(pathname.charCodeAt(segmentLength));
|
|
221
208
|
if (staticChild) {
|
|
222
|
-
const result = staticChild.find(pathname.slice(
|
|
209
|
+
const result = staticChild.find(pathname.slice(segmentLength));
|
|
223
210
|
if (result)
|
|
224
211
|
return result;
|
|
225
212
|
}
|
|
226
213
|
}
|
|
227
214
|
// check for param leaf
|
|
228
|
-
if (this.
|
|
229
|
-
const slashIndex = pathname.indexOf("/",
|
|
215
|
+
if (this.param) {
|
|
216
|
+
const slashIndex = pathname.indexOf("/", segmentLength);
|
|
230
217
|
// if there is not a slash immediately following this.segment
|
|
231
|
-
if (slashIndex !==
|
|
218
|
+
if (slashIndex !== segmentLength) {
|
|
232
219
|
// there is a valid parameter
|
|
233
220
|
if (
|
|
234
221
|
// param is the end of the pathname
|
|
235
222
|
slashIndex === -1 &&
|
|
236
|
-
this.
|
|
223
|
+
this.param.route) {
|
|
237
224
|
return {
|
|
238
|
-
route: this.
|
|
239
|
-
params: {
|
|
240
|
-
[this.paramChild.name]: pathname.slice(this.segment.length),
|
|
241
|
-
},
|
|
225
|
+
route: this.param.route,
|
|
226
|
+
params: { [this.param.name]: pathname.slice(segmentLength) },
|
|
242
227
|
};
|
|
243
228
|
}
|
|
244
|
-
else if (this.
|
|
229
|
+
else if (this.param.child) {
|
|
245
230
|
// there's a static node after the param
|
|
246
231
|
// this is how there can be multiple params, "/" in between
|
|
247
|
-
const result = this.
|
|
232
|
+
const result = this.param.child.find(pathname.slice(slashIndex));
|
|
248
233
|
if (result) {
|
|
249
234
|
// add original params to the result
|
|
250
|
-
result.params[this.
|
|
235
|
+
result.params[this.param.name] = pathname.slice(segmentLength, slashIndex);
|
|
251
236
|
return result;
|
|
252
237
|
}
|
|
253
238
|
}
|
|
254
239
|
}
|
|
255
240
|
}
|
|
256
241
|
// check for wildcard leaf
|
|
257
|
-
if (this.
|
|
242
|
+
if (this.wild) {
|
|
258
243
|
return {
|
|
259
|
-
route: this.
|
|
260
|
-
params: { "*": pathname.slice(
|
|
244
|
+
route: this.wild,
|
|
245
|
+
params: { "*": pathname.slice(segmentLength) },
|
|
261
246
|
};
|
|
262
247
|
}
|
|
263
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
3
|
"description": "The Streaming Framework",
|
|
4
|
-
"version": "
|
|
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
|
}
|