@queue-it/fastly 3.6.0 → 4.4.3-beta.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/README.md +156 -58
- package/package.json +23 -16
- package/src/contextProvider.ts +175 -0
- package/src/fastlyCryptoProvider.ts +8 -0
- package/src/helper.ts +11 -0
- package/{assembly/sdk → src}/helpers/crypto.ts +338 -340
- package/src/index.ts +3 -0
- package/src/integrationConfigProvider.ts +199 -0
- package/src/requestResponseHandler.ts +200 -0
- package/README-INTERNAL.md +0 -21
- package/asconfig.json +0 -17
- package/assembly/__tests__/CustomerIntegrationDecodingHandler.spec.ts +0 -1086
- package/assembly/__tests__/IntegrationConfigHelpersTest.spec.ts +0 -574
- package/assembly/__tests__/KnownUserTest.spec.ts +0 -1894
- package/assembly/__tests__/Mocks.ts +0 -321
- package/assembly/__tests__/QueueParameterHelper.spec.ts +0 -59
- package/assembly/__tests__/UserInQueueService.spec.ts +0 -418
- package/assembly/__tests__/UserInQueueStateCookieRepository.spec.ts +0 -337
- package/assembly/__tests__/as-pect.config.js +0 -57
- package/assembly/__tests__/as-pect.d.ts +0 -1
- package/assembly/contextProvider.ts +0 -123
- package/assembly/helper.ts +0 -23
- package/assembly/index.ts +0 -10
- package/assembly/integrationConfigProvider.ts +0 -32
- package/assembly/requestResponseHandler.ts +0 -92
- package/assembly/sdk/HttpContextProvider.ts +0 -24
- package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -198
- package/assembly/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +0 -232
- package/assembly/sdk/IntegrationConfig/IntegrationConfigModel.ts +0 -93
- package/assembly/sdk/KnownUser.ts +0 -396
- package/assembly/sdk/Models.ts +0 -105
- package/assembly/sdk/QueueITHelpers.ts +0 -263
- package/assembly/sdk/UserInQueueService.ts +0 -245
- package/assembly/sdk/UserInQueueStateCookieRepository.ts +0 -189
- package/assembly/sdk/helpers/Date.ts +0 -194
- package/assembly/sdk/helpers/Uri.ts +0 -308
- package/assembly/tsconfig.json +0 -6
- package/index.js +0 -5
- package/pipelines/ci.yaml +0 -28
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// @ts-ignore: decorator
|
|
2
|
-
@inline const
|
|
3
|
-
MILLIS_PER_DAY = 1000 * 60 * 60 * 24,
|
|
4
|
-
MILLIS_PER_HOUR = 1000 * 60 * 60,
|
|
5
|
-
MILLIS_PER_MINUTE = 1000 * 60,
|
|
6
|
-
MILLIS_PER_SECOND = 1000;
|
|
7
|
-
// ymdFromEpochDays returns values via globals to avoid allocations
|
|
8
|
-
// @ts-ignore: decorator
|
|
9
|
-
@lazy let _month: i32, _day: i32;
|
|
10
|
-
|
|
11
|
-
// Date#toISOString ////////////////////////////////////////////////////////////////////////////////
|
|
12
|
-
{
|
|
13
|
-
let date = new Date(-62167219200000);
|
|
14
|
-
assert(toISOString(date) == "0000-01-01T00:00:00.000Z");
|
|
15
|
-
assert(toUTCString(date) == "Sat, 01 Jan 0000 00:00:00 GMT");
|
|
16
|
-
date = new Date(-62167219200000 - 1);
|
|
17
|
-
assert(toISOString(date) == "-000001-12-31T23:59:59.999Z");
|
|
18
|
-
assert(toUTCString(date) == "Fri, 31 Dec -0001 23:59:59 GMT");
|
|
19
|
-
date = new Date(-62127219200000);
|
|
20
|
-
assert(toISOString(date) == "0001-04-07T23:06:40.000Z");
|
|
21
|
-
assert(toUTCString(date) == "Sat, 07 Apr 0001 23:06:40 GMT");
|
|
22
|
-
date = new Date(1231231231020);
|
|
23
|
-
assert(toISOString(date) == "2009-01-06T08:40:31.020Z");
|
|
24
|
-
assert(toUTCString(date) == "Tue, 06 Jan 2009 08:40:31 GMT");
|
|
25
|
-
date = new Date(1231231231456);
|
|
26
|
-
assert(toISOString(date) == "2009-01-06T08:40:31.456Z");
|
|
27
|
-
assert(toUTCString(date) == "Tue, 06 Jan 2009 08:40:31 GMT");
|
|
28
|
-
date = new Date(322331231231020);
|
|
29
|
-
assert(toISOString(date) == "+012184-04-08T13:07:11.020Z");
|
|
30
|
-
assert(toUTCString(date) == "Thu, 08 Apr 12184 13:07:11 GMT");
|
|
31
|
-
date = new Date(253402300799999);
|
|
32
|
-
assert(toISOString(date) == "9999-12-31T23:59:59.999Z");
|
|
33
|
-
assert(toUTCString(date) == "Fri, 31 Dec 9999 23:59:59 GMT");
|
|
34
|
-
date = new Date(253402300800000);
|
|
35
|
-
assert(toISOString(date) == "+010000-01-01T00:00:00.000Z");
|
|
36
|
-
assert(toUTCString(date) == "Sat, 01 Jan 10000 00:00:00 GMT");
|
|
37
|
-
date = new Date(-62847038769226);
|
|
38
|
-
assert(toISOString(date) == "-000022-06-16T17:13:50.774Z");
|
|
39
|
-
assert(toUTCString(date) == "Fri, 16 Jun -0022 17:13:50 GMT");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function getYear(date: Date): i32 {
|
|
43
|
-
return ymdFromEpochDays(i32(floorDiv(date.getTime(), MILLIS_PER_DAY)));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function getSeconds(date: Date): i64 {
|
|
47
|
-
return (date.getTime() / MILLIS_PER_SECOND) % 60;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getMonth(date: Date): i32 {
|
|
51
|
-
return mFromEpochDays(i32(floorDiv(date.getTime(), MILLIS_PER_DAY)))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function getDay(date: Date): i32 {
|
|
55
|
-
return dFromEpochDays(i32(floorDiv(date.getTime(), MILLIS_PER_DAY)))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function ymdFromEpochDays(z: i32): i32 {
|
|
59
|
-
z += 719468;
|
|
60
|
-
var era = <u32>floorDiv(z, 146097);
|
|
61
|
-
var doe = <u32>z - era * 146097; // [0, 146096]
|
|
62
|
-
var yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; // [0, 399]
|
|
63
|
-
var year = yoe + era * 400;
|
|
64
|
-
var doy = doe - (365 * yoe + yoe / 4 - yoe / 100); // [0, 365]
|
|
65
|
-
var mo = (5 * doy + 2) / 153; // [0, 11]
|
|
66
|
-
_day = doy - (153 * mo + 2) / 5 + 1; // [1, 31]
|
|
67
|
-
mo += mo < 10 ? 3 : -9; // [1, 12]
|
|
68
|
-
_month = mo;
|
|
69
|
-
year += u32(mo <= 2);
|
|
70
|
-
return year;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function mFromEpochDays(z: i32): i32 {
|
|
74
|
-
z += 719468;
|
|
75
|
-
var era = <u32>floorDiv(z, 146097);
|
|
76
|
-
var doe = <u32>z - era * 146097; // [0, 146096]
|
|
77
|
-
var yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; // [0, 399]
|
|
78
|
-
var year = yoe + era * 400;
|
|
79
|
-
var doy = doe - (365 * yoe + yoe / 4 - yoe / 100); // [0, 365]
|
|
80
|
-
var mo = (5 * doy + 2) / 153; // [0, 11]
|
|
81
|
-
_day = doy - (153 * mo + 2) / 5 + 1; // [1, 31]
|
|
82
|
-
mo += mo < 10 ? 3 : -9; // [1, 12]
|
|
83
|
-
return mo
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function dFromEpochDays(z: i32): i32 {
|
|
87
|
-
z += 719468;
|
|
88
|
-
var era = <u32>floorDiv(z, 146097);
|
|
89
|
-
var doe = <u32>z - era * 146097; // [0, 146096]
|
|
90
|
-
var yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; // [0, 399]
|
|
91
|
-
var year = yoe + era * 400;
|
|
92
|
-
var doy = doe - (365 * yoe + yoe / 4 - yoe / 100); // [0, 365]
|
|
93
|
-
var mo = (5 * doy + 2) / 153; // [0, 11]
|
|
94
|
-
_day = doy - (153 * mo + 2) / 5 + 1; // [1, 31]
|
|
95
|
-
return _day
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function toISOString(date: Date): string {
|
|
99
|
-
// TODO: add more low-level helper which combine toString and padStart without extra allocation
|
|
100
|
-
let yearStr: string = '';
|
|
101
|
-
let year = getYear(date);
|
|
102
|
-
let isNeg = year < 0;
|
|
103
|
-
if (isNeg || year >= 10000) {
|
|
104
|
-
yearStr = (isNeg ? "-" : "+") + abs(year).toString().padStart(6, "0");
|
|
105
|
-
} else {
|
|
106
|
-
yearStr = year.toString().padStart(4, "0");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
yearStr +
|
|
111
|
-
"-" +
|
|
112
|
-
getMonth(date).toString().padStart(2, "0") +
|
|
113
|
-
"-" +
|
|
114
|
-
getDay(date).toString().padStart(2, "0") +
|
|
115
|
-
"T" +
|
|
116
|
-
getUTCHours(date).toString().padStart(2, "0") +
|
|
117
|
-
":" +
|
|
118
|
-
getUTCMinutes(date).toString().padStart(2, "0") +
|
|
119
|
-
":" +
|
|
120
|
-
getUTCSeconds(date).toString().padStart(2, "0") +
|
|
121
|
-
"." +
|
|
122
|
-
getUTCMilliseconds(date).toString().padStart(3, "0") +
|
|
123
|
-
"Z"
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function toUTCString(date: Date): string {
|
|
128
|
-
const weeks: StaticArray<string> = [
|
|
129
|
-
"Sun, ", "Mon, ", "Tue, ", "Wed, ", "Thu, ", "Fri, ", "Sat, "
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
const months: StaticArray<string> = [
|
|
133
|
-
" Jan ", " Feb ", " Mar ", " Apr ", " May ", " Jun ",
|
|
134
|
-
" Jul ", " Aug ", " Sep ", " Oct ", " Nov ", " Dec "
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
const mo = getMonth(date);
|
|
138
|
-
const da = getDay(date);
|
|
139
|
-
const yr = getYear(date);
|
|
140
|
-
const wd = dayOfWeek(yr, mo, da);
|
|
141
|
-
let year = abs(yr).toString().padStart(4, "0");
|
|
142
|
-
if (yr < 0) year = "-" + year;
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
unchecked(weeks[wd]) +
|
|
146
|
-
da.toString().padStart(2, "0") +
|
|
147
|
-
unchecked(months[mo - 1]) +
|
|
148
|
-
year +
|
|
149
|
-
" " +
|
|
150
|
-
getUTCHours(date).toString().padStart(2, "0") +
|
|
151
|
-
":" +
|
|
152
|
-
getUTCMinutes(date).toString().padStart(2, "0") +
|
|
153
|
-
":" +
|
|
154
|
-
getUTCSeconds(date).toString().padStart(2, "0") +
|
|
155
|
-
" GMT"
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function getUTCHours(date: Date): i32 {
|
|
160
|
-
return i32(euclidRem(date.getTime(), MILLIS_PER_DAY)) / MILLIS_PER_HOUR;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function getUTCMinutes(date: Date): i32 {
|
|
164
|
-
return i32(euclidRem(date.getTime(), MILLIS_PER_HOUR)) / MILLIS_PER_MINUTE;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getUTCSeconds(date: Date): i32 {
|
|
168
|
-
return i32(euclidRem(date.getTime(), MILLIS_PER_MINUTE)) / MILLIS_PER_SECOND;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function getUTCMilliseconds(date: Date): i32 {
|
|
172
|
-
return i32(euclidRem(date.getTime(), MILLIS_PER_SECOND));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// TomohikoSakamoto algorithm from https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
|
|
176
|
-
function dayOfWeek(year: i32, month: i32, day: i32): i32 {
|
|
177
|
-
const tab = memory.data<u8>([0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]);
|
|
178
|
-
|
|
179
|
-
year -= i32(month < 3);
|
|
180
|
-
year += floorDiv(year, 4) - floorDiv(year, 100) + floorDiv(year, 400);
|
|
181
|
-
month = <i32>load<u8>(tab + month - 1);
|
|
182
|
-
return euclidRem(year + month + day, 7);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// @ts-ignore: decorator
|
|
186
|
-
@inline function floorDiv<T extends number>(a: T, b: T): T {
|
|
187
|
-
return (a >= 0 ? a : a - b + 1) / b as T;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// @ts-ignore: decorator
|
|
191
|
-
@inline function euclidRem<T extends number>(a: T, b: T): T {
|
|
192
|
-
var m = a % b;
|
|
193
|
-
return m + (m < 0 ? b : 0) as T;
|
|
194
|
-
}
|
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
const enum CharCode {
|
|
2
|
-
PERCENT = 0x25,
|
|
3
|
-
_0 = 0x30,
|
|
4
|
-
a = 0x61,
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class URIError extends Error {
|
|
8
|
-
constructor(message: string = "") {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = "URIError";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// @ts-ignore: decorator
|
|
15
|
-
@lazy @inline
|
|
16
|
-
export const E_URI_MALFORMED: string = "URI malformed";
|
|
17
|
-
|
|
18
|
-
// Truncated lookup boolean table that helps us quickly determine
|
|
19
|
-
// if a char needs to be escaped for URIs (RFC 2396).
|
|
20
|
-
// @ts-ignore: decorator
|
|
21
|
-
@lazy export const URI_UNSAFE = memory.data<u8>([
|
|
22
|
-
/* skip 32 + 1 always set to '1' head slots
|
|
23
|
-
*/ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
24
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
|
|
25
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
26
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
|
|
27
|
-
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
28
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, /*
|
|
29
|
-
skip 128 + 1 always set to '1' tail slots */
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
// Truncated lookup boolean table that helps us quickly determine
|
|
33
|
-
// if a char needs to be escaped for URLs (RFC 3986).
|
|
34
|
-
// @ts-ignore: decorator
|
|
35
|
-
@lazy export const URL_UNSAFE = memory.data<u8>([
|
|
36
|
-
/* skip 32 + 1 always set to '1' head slots
|
|
37
|
-
*/ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1,
|
|
38
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
|
39
|
-
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
40
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
|
|
41
|
-
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
42
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, /*
|
|
43
|
-
skip 128 + 1 always set to '1' tail slots */
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
// Truncated lookup boolean table for determine reserved chars: ;/?:@&=+$,#
|
|
47
|
-
// @ts-ignore: decorator
|
|
48
|
-
@lazy export const URI_RESERVED = memory.data<u8>([
|
|
49
|
-
/* skip 32 + 3 always set to '0' head slots
|
|
50
|
-
*/ 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1,
|
|
51
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1,
|
|
52
|
-
1, /* skip 191 always set to '0' tail slots */
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
export function encode(src: usize, len: usize, table: usize): usize {
|
|
56
|
-
if (!len) return src;
|
|
57
|
-
|
|
58
|
-
var i: usize = 0, offset: usize = 0, outSize = len << 1;
|
|
59
|
-
var dst = __new(outSize, idof<String>());
|
|
60
|
-
|
|
61
|
-
while (i < len) {
|
|
62
|
-
let org = i;
|
|
63
|
-
let c: u32, c1: u32;
|
|
64
|
-
// fast scan a check chars until it valid ASCII
|
|
65
|
-
// and safe for copying withoud escaping.
|
|
66
|
-
do {
|
|
67
|
-
c = <u32>load<u16>(src + (i << 1));
|
|
68
|
-
// is it valid ASII and safe?
|
|
69
|
-
if (c - 33 < 94) { // 127 - 33
|
|
70
|
-
if (load<u8>(table + (c - 33))) break;
|
|
71
|
-
} else break;
|
|
72
|
-
} while (++i < len);
|
|
73
|
-
|
|
74
|
-
// if we have some safe range of sequence just copy it without encoding
|
|
75
|
-
if (i > org) {
|
|
76
|
-
let size = i - org << 1;
|
|
77
|
-
if (offset + size > outSize) {
|
|
78
|
-
outSize = offset + size;
|
|
79
|
-
dst = __renew(dst, outSize);
|
|
80
|
-
}
|
|
81
|
-
// TODO: should we optimize for short cases like 2 byte size?
|
|
82
|
-
memory.copy(
|
|
83
|
-
dst + offset,
|
|
84
|
-
src + (org << 1),
|
|
85
|
-
size
|
|
86
|
-
);
|
|
87
|
-
offset += size;
|
|
88
|
-
// return if we reach end on input string
|
|
89
|
-
if (i >= len) break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// decode UTF16 with checking for unpaired surrogates
|
|
93
|
-
if (c >= 0xD800) {
|
|
94
|
-
if (c >= 0xDC00 && c <= 0xDFFF) {
|
|
95
|
-
throw new URIError(E_URI_MALFORMED);
|
|
96
|
-
}
|
|
97
|
-
if (c <= 0xDBFF) {
|
|
98
|
-
if (i >= len) {
|
|
99
|
-
throw new URIError(E_URI_MALFORMED);
|
|
100
|
-
}
|
|
101
|
-
c1 = <u32>load<u16>(src + (++i << 1));
|
|
102
|
-
if (c1 < 0xDC00 || c1 > 0xDFFF) {
|
|
103
|
-
throw new URIError(E_URI_MALFORMED);
|
|
104
|
-
}
|
|
105
|
-
c = (((c & 0x3FF) << 10) | (c1 & 0x3FF)) + 0x10000;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
let estSize = offset + (c < 0x80 ? 1 * 6 : 4 * 6);
|
|
110
|
-
if (estSize > outSize) {
|
|
111
|
-
// doubling estimated size but only for greater than one
|
|
112
|
-
// input lenght due to we already estemated it for worst case
|
|
113
|
-
outSize = len > 1 ? estSize << 1 : estSize;
|
|
114
|
-
dst = __renew(dst, outSize);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (c < 0x80) {
|
|
118
|
-
// encode ASCII unsafe code point
|
|
119
|
-
storeHex(dst, offset, c);
|
|
120
|
-
offset += 6;
|
|
121
|
-
} else {
|
|
122
|
-
// encode UTF-8 unsafe code point
|
|
123
|
-
if (c < 0x800) {
|
|
124
|
-
storeHex(dst, offset, (c >> 6) | 0xC0);
|
|
125
|
-
offset += 6;
|
|
126
|
-
} else {
|
|
127
|
-
if (c < 0x10000) {
|
|
128
|
-
storeHex(dst, offset, (c >> 12) | 0xE0);
|
|
129
|
-
offset += 6;
|
|
130
|
-
} else {
|
|
131
|
-
storeHex(dst, offset, (c >> 18) | 0xF0);
|
|
132
|
-
offset += 6;
|
|
133
|
-
storeHex(dst, offset, (c >> 12 & 0x3F) | 0x80);
|
|
134
|
-
offset += 6;
|
|
135
|
-
}
|
|
136
|
-
storeHex(dst, offset, (c >> 6 & 0x3F) | 0x80);
|
|
137
|
-
offset += 6;
|
|
138
|
-
}
|
|
139
|
-
storeHex(dst, offset, (c & 0x3F) | 0x80);
|
|
140
|
-
offset += 6;
|
|
141
|
-
}
|
|
142
|
-
++i;
|
|
143
|
-
}
|
|
144
|
-
// shink output string buffer if necessary
|
|
145
|
-
if (outSize > offset) {
|
|
146
|
-
dst = __renew(dst, offset);
|
|
147
|
-
}
|
|
148
|
-
return dst;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function decode(src: usize, len: usize, component: bool): usize {
|
|
152
|
-
if (!len) return src;
|
|
153
|
-
|
|
154
|
-
var i: usize = 0, offset: usize = 0, ch: u32 = 0;
|
|
155
|
-
var dst = __new(len << 1, idof<String>());
|
|
156
|
-
|
|
157
|
-
while (i < len) {
|
|
158
|
-
let org = i;
|
|
159
|
-
while (i < len && (ch = load<u16>(src + (i << 1))) != CharCode.PERCENT) i++;
|
|
160
|
-
|
|
161
|
-
if (i > org) {
|
|
162
|
-
let size = i - org << 1;
|
|
163
|
-
// TODO: should we optimize for short cases like 2 byte size?
|
|
164
|
-
memory.copy(
|
|
165
|
-
dst + offset,
|
|
166
|
-
src + (org << 1),
|
|
167
|
-
size
|
|
168
|
-
);
|
|
169
|
-
offset += size;
|
|
170
|
-
if (i >= len) break;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// decode hex
|
|
174
|
-
if (
|
|
175
|
-
i + 2 >= len ||
|
|
176
|
-
ch != CharCode.PERCENT ||
|
|
177
|
-
(ch = loadHex(src, i + 1 << 1)) == -1
|
|
178
|
-
) {
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
i += 3;
|
|
183
|
-
if (ch < 0x80) {
|
|
184
|
-
if (!component && isReserved(ch)) {
|
|
185
|
-
ch = CharCode.PERCENT;
|
|
186
|
-
i -= 2;
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
// decode UTF-8 sequence
|
|
190
|
-
let nb = utf8LenFromUpperByte(ch);
|
|
191
|
-
// minimal surrogate: 2 => 0x80, 3 => 0x800, 4 => 0x10000, _ => -1
|
|
192
|
-
let lo: u32 = 1 << (17 * nb >> 2) - 1;
|
|
193
|
-
// mask: 2 => 31, 3 => 15, 4 => 7, _ => 0
|
|
194
|
-
ch &= nb ? (0x80 >> nb) - 1 : 0;
|
|
195
|
-
|
|
196
|
-
while (--nb != 0) {
|
|
197
|
-
let c1: u32;
|
|
198
|
-
// decode hex
|
|
199
|
-
if (
|
|
200
|
-
i + 2 >= len ||
|
|
201
|
-
load<u16>(src + (i << 1)) != CharCode.PERCENT ||
|
|
202
|
-
(c1 = loadHex(src, i + 1 << 1)) == -1
|
|
203
|
-
) throw new URIError(E_URI_MALFORMED);
|
|
204
|
-
|
|
205
|
-
i += 3;
|
|
206
|
-
if ((c1 & 0xC0) != 0x80) {
|
|
207
|
-
ch = 0;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
ch = (ch << 6) | (c1 & 0x3F);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// check if UTF8 code point properly fit into invalid UTF16 encoding
|
|
214
|
-
if (ch < lo || lo == -1 || ch > 0x10FFFF || (ch >= 0xD800 && ch < 0xE000)) {
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// encode UTF16
|
|
219
|
-
if (ch >= 0x10000) {
|
|
220
|
-
ch -= 0x10000;
|
|
221
|
-
let lo = ch >> 10 | 0xD800;
|
|
222
|
-
let hi = (ch & 0x03FF) | 0xDC00;
|
|
223
|
-
store<u32>(dst + offset, lo | (hi << 16));
|
|
224
|
-
offset += 4;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
store<u16>(dst + offset, ch);
|
|
229
|
-
offset += 2;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
assert(offset <= (len << 1));
|
|
233
|
-
// shink output string buffer if necessary
|
|
234
|
-
if ((len << 1) > offset) {
|
|
235
|
-
dst = __renew(dst, offset);
|
|
236
|
-
}
|
|
237
|
-
return dst;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function storeHex(dst: usize, offset: usize, ch: u32): void {
|
|
241
|
-
// @ts-ignore: decorator
|
|
242
|
-
const HEX_CHARS = memory.data<u8>([
|
|
243
|
-
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
|
244
|
-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46
|
|
245
|
-
]);
|
|
246
|
-
|
|
247
|
-
store<u16>(dst + offset, CharCode.PERCENT, 0); // %
|
|
248
|
-
store<u32>(
|
|
249
|
-
dst + offset,
|
|
250
|
-
<u32>load<u8>(HEX_CHARS + (ch >> 4 & 0x0F)) |
|
|
251
|
-
<u32>load<u8>(HEX_CHARS + (ch & 0x0F)) << 16,
|
|
252
|
-
2
|
|
253
|
-
); // XX
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function loadHex(src: usize, offset: usize): u32 {
|
|
257
|
-
let c0 = <u32>load<u16>(src + offset, 0);
|
|
258
|
-
let c1 = <u32>load<u16>(src + offset, 2);
|
|
259
|
-
return isHex(c0) && isHex(c1)
|
|
260
|
-
? fromHex(c0) << 4 | fromHex(c1)
|
|
261
|
-
: -1;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// @ts-ignore: decorator
|
|
265
|
-
@inline function fromHex(ch: u32): u32 {
|
|
266
|
-
return (ch | 32) % 39 - 9;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// @ts-ignore: decorator
|
|
270
|
-
@inline function utf8LenFromUpperByte(c0: u32): u32 {
|
|
271
|
-
// same as
|
|
272
|
-
// if (c0 - 0xC0 <= 0xDF - 0xC0) return 2;
|
|
273
|
-
// if (c0 - 0xE0 <= 0xEF - 0xE0) return 3;
|
|
274
|
-
// if (c0 - 0xF0 <= 0xF7 - 0xF0) return 4;
|
|
275
|
-
// return 0;
|
|
276
|
-
return c0 - 0xC0 < 56
|
|
277
|
-
? clz(~(c0 << 24))
|
|
278
|
-
: 0;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// @ts-ignore: decorator
|
|
282
|
-
@inline function isReserved(ch: u32): bool {
|
|
283
|
-
return ch - 35 < 30
|
|
284
|
-
? <bool>load<u8>(URI_RESERVED + (ch - 35))
|
|
285
|
-
: false;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// @ts-ignore: decorator
|
|
289
|
-
@inline function isHex(ch: u32): bool {
|
|
290
|
-
// @ts-ignore
|
|
291
|
-
return (ch - CharCode._0 < 10) | ((ch | 32) - CharCode.a < 6);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export function encodeURI(str: string): string {
|
|
295
|
-
return changetype<string>(encode(changetype<usize>(str), str.length, URI_UNSAFE));
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export function decodeURI(str: string): string {
|
|
299
|
-
return changetype<string>(decode(changetype<usize>(str), str.length, false));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export function encodeURIComponent(str: string): string {
|
|
303
|
-
return changetype<string>(encode(changetype<usize>(str), str.length, URL_UNSAFE));
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export function decodeURIComponent(str: string): string {
|
|
307
|
-
return changetype<string>(decode(changetype<usize>(str), str.length, true));
|
|
308
|
-
}
|
package/assembly/tsconfig.json
DELETED
package/index.js
DELETED
package/pipelines/ci.yaml
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Node.js
|
|
2
|
-
# Build a general Node.js project with npm.
|
|
3
|
-
# Add steps that analyze code, save build artifacts, deploy, and more:
|
|
4
|
-
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
|
|
5
|
-
|
|
6
|
-
trigger:
|
|
7
|
-
- master
|
|
8
|
-
|
|
9
|
-
pool:
|
|
10
|
-
vmImage: 'ubuntu-latest'
|
|
11
|
-
|
|
12
|
-
steps:
|
|
13
|
-
- task: NodeTool@0
|
|
14
|
-
inputs:
|
|
15
|
-
versionSpec: '14.x'
|
|
16
|
-
displayName: 'Install Node.js'
|
|
17
|
-
|
|
18
|
-
- script: |
|
|
19
|
-
npm i
|
|
20
|
-
displayName: 'install dependencies'
|
|
21
|
-
|
|
22
|
-
- script: |
|
|
23
|
-
npm run asbuild
|
|
24
|
-
displayName: 'npm run asbuild'
|
|
25
|
-
|
|
26
|
-
- script: |
|
|
27
|
-
npm run test
|
|
28
|
-
displayName: 'npm run test'
|