fastly.js 0.9.0 → 0.9.2
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 +2 -2
- package/dist/browser.js +548 -263
- package/dist/index.js +548 -263
- package/dist/vcl-compiler.d.ts +8 -11
- package/dist/vcl-parser-impl.d.ts +5 -0
- package/dist/vcl-regex.d.ts +14 -0
- package/dist/vcl-std.d.ts +2 -1
- package/dist/vcl-strings.d.ts +2 -7
- package/dist/vcl-utf8.d.ts +27 -4
- package/dist/vcl-value.d.ts +11 -0
- package/package.json +9 -9
package/dist/vcl-compiler.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type VCLPlatform } from "./platform.js";
|
|
2
2
|
import type { VCLProgram } from "./vcl-parser.js";
|
|
3
|
+
import { VCLFailure } from "./vcl-value.js";
|
|
3
4
|
export interface VCLBackend {
|
|
4
5
|
name: string;
|
|
5
6
|
host: string;
|
|
@@ -111,7 +112,7 @@ export interface VCLContext {
|
|
|
111
112
|
ip: string;
|
|
112
113
|
};
|
|
113
114
|
re?: {
|
|
114
|
-
groups?: Record<
|
|
115
|
+
groups?: Record<string, string>;
|
|
115
116
|
};
|
|
116
117
|
platform: VCLPlatform;
|
|
117
118
|
locals: Record<string, any>;
|
|
@@ -174,10 +175,11 @@ export interface VCLContext {
|
|
|
174
175
|
[key: string]: any;
|
|
175
176
|
};
|
|
176
177
|
utf8?: {
|
|
177
|
-
is_valid: (s:
|
|
178
|
-
codepoint_count: (s:
|
|
179
|
-
substr: (s:
|
|
180
|
-
strpad: (s:
|
|
178
|
+
is_valid: (s: unknown) => boolean;
|
|
179
|
+
codepoint_count: (s: unknown) => number;
|
|
180
|
+
substr: (s: unknown, offset: number, length?: number) => string | null;
|
|
181
|
+
strpad: (s: unknown, width: number, pad: unknown) => string | VCLFailure;
|
|
182
|
+
translate: (input: unknown, set1: unknown, set2: unknown) => string | VCLFailure;
|
|
181
183
|
};
|
|
182
184
|
waf?: Record<string, any>;
|
|
183
185
|
error?: (status: number, message: string) => string;
|
|
@@ -274,7 +276,7 @@ export interface VCLContext {
|
|
|
274
276
|
};
|
|
275
277
|
strrev?: (s: string) => string;
|
|
276
278
|
strrep?: (s: string, count: number) => string;
|
|
277
|
-
strpad?: (s: string, width: number, pad: string) => string;
|
|
279
|
+
strpad?: (s: string, width: number, pad: string) => string | VCLFailure;
|
|
278
280
|
strcasecmp?: (s1: string, s2: string) => number;
|
|
279
281
|
replace_prefix?: (s: string, prefix: string, replacement: string) => string;
|
|
280
282
|
replace_suffix?: (s: string, suffix: string, replacement: string) => string;
|
|
@@ -493,11 +495,6 @@ export declare class VCLCompiler {
|
|
|
493
495
|
private evaluateBinaryExpression;
|
|
494
496
|
/**
|
|
495
497
|
* Equality for the == and != operators.
|
|
496
|
-
* A STRING left operand drives the comparison: the right side is
|
|
497
|
-
* stringified per its VCL type and compared byte-wise, matching how
|
|
498
|
-
* Fastly compiles string equality to VRT_strcmp with the right operand
|
|
499
|
-
* rendered through the type's to-string conversion.
|
|
500
|
-
* NOTSET values compare using their display string "(null)".
|
|
501
498
|
*/
|
|
502
499
|
private vclEquals;
|
|
503
500
|
private regexMatch;
|
|
@@ -123,4 +123,9 @@ export declare class VCLParser {
|
|
|
123
123
|
private previous;
|
|
124
124
|
private error;
|
|
125
125
|
private parseFunctionCall;
|
|
126
|
+
/**
|
|
127
|
+
* Fastly builds the translation table at compile time, so both sets must be
|
|
128
|
+
* constant strings. vcl-utf8 owns the rules about their contents.
|
|
129
|
+
*/
|
|
130
|
+
private checkTranslateSets;
|
|
126
131
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Turns a string into its UTF-8 bytes, one byte per char. */
|
|
2
|
+
export declare function toBytes(s: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Turns a byte string back into text.
|
|
5
|
+
* A match can split a multi-byte character, and the broken part becomes U+FFFD.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fromBytes(s: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Compiles a VCL regex into a JavaScript one, to run on toBytes() of the subject.
|
|
10
|
+
* Throws on syntax we can't translate, like atomic groups, possessive quantifiers or \K.
|
|
11
|
+
*
|
|
12
|
+
* Compiled regexes are shared, so reset lastIndex before using a global one.
|
|
13
|
+
*/
|
|
14
|
+
export declare function compileRegex(pattern: string, flags?: "" | "g"): RegExp;
|
package/dist/vcl-std.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type VCLFailure } from "./vcl-value.js";
|
|
1
2
|
export interface StdModule {
|
|
2
3
|
strlen: (s: string) => number;
|
|
3
4
|
tolower: (s: string) => string;
|
|
@@ -5,7 +6,7 @@ export interface StdModule {
|
|
|
5
6
|
strstr: (haystack: string, needle: string) => string | null;
|
|
6
7
|
strrev: (s: string) => string | null;
|
|
7
8
|
strrep: (s: string, count: number) => string;
|
|
8
|
-
strpad: (s: string, width: number, pad: string) => string;
|
|
9
|
+
strpad: (s: string, width: number, pad: string) => string | VCLFailure;
|
|
9
10
|
strcasecmp: (s1: string, s2: string) => boolean;
|
|
10
11
|
prefixof: (s: string, prefix: string) => boolean;
|
|
11
12
|
suffixof: (s: string, suffix: string) => boolean;
|
package/dist/vcl-strings.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { VCLFailure } from "./vcl-value.js";
|
|
1
2
|
export declare function isAlnumByte(b: number): boolean;
|
|
2
3
|
/** Value of a hex digit byte, or -1 when the byte is not a hex digit. */
|
|
3
4
|
export declare function hexVal(b: number): number;
|
|
@@ -17,7 +18,7 @@ export declare function substr(str: string, offset: number, length?: number): st
|
|
|
17
18
|
export declare function subfield(header: string, name: string, separator?: string): string | null;
|
|
18
19
|
export declare function strcasecmp(a: string, b: string): boolean;
|
|
19
20
|
export declare function strstr(haystack: string, needle: string): string | null;
|
|
20
|
-
export declare function strpad(s: string, width: number, pad: string): string;
|
|
21
|
+
export declare function strpad(s: string, width: number, pad: string): string | VCLFailure;
|
|
21
22
|
export declare function strrep(s: string, count: number): string;
|
|
22
23
|
export declare function strrev(s: string): string | null;
|
|
23
24
|
export declare function prefixof(s: string, prefix: string): boolean;
|
|
@@ -39,9 +40,3 @@ export declare function urlNormalize(input: string): string;
|
|
|
39
40
|
export declare function boltsort_sort(url: string): string;
|
|
40
41
|
export declare function setcookie_get_value_by_name(setCookieHeader: string, name: string): string | null;
|
|
41
42
|
export declare function setcookie_delete_by_name(setCookieHeader: string, name: string): string;
|
|
42
|
-
export declare const Utf8Module: {
|
|
43
|
-
is_valid: (str: string) => boolean;
|
|
44
|
-
codepoint_count: (str: string) => number;
|
|
45
|
-
substr: (str: string, offset: number, length?: number) => string;
|
|
46
|
-
strpad: (str: string, width: number, pad: string) => string;
|
|
47
|
-
};
|
package/dist/vcl-utf8.d.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
+
import { VCLFailure } from "./vcl-value.js";
|
|
2
|
+
/**
|
|
3
|
+
* The rules Fastly applies to the two character sets when it compiles a
|
|
4
|
+
* utf8.translate call. Returns the error message, or null when the sets are good.
|
|
5
|
+
*/
|
|
6
|
+
export declare function translateSetsError(set1: string, set2: string): string | null;
|
|
1
7
|
export declare const UTF8Module: {
|
|
2
|
-
is_valid: (s:
|
|
3
|
-
codepoint_count: (s:
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
is_valid: (s: unknown) => boolean;
|
|
9
|
+
codepoint_count: (s: unknown) => number;
|
|
10
|
+
/**
|
|
11
|
+
* A negative offset counts back from the end, and so does a negative length.
|
|
12
|
+
* An offset outside the string gives a not-set STRING.
|
|
13
|
+
*/
|
|
14
|
+
substr: (s: unknown, offset: number, length?: number) => string | null;
|
|
15
|
+
/**
|
|
16
|
+
* A positive width pads on the left, a negative width on the right. The pad
|
|
17
|
+
* string repeats until the result is wide enough.
|
|
18
|
+
*
|
|
19
|
+
* An empty pad string returns the input. Fastly makes this test first, before
|
|
20
|
+
* every other rule.
|
|
21
|
+
*/
|
|
22
|
+
strpad: (s: unknown, width: number, pad: unknown) => string | VCLFailure;
|
|
23
|
+
/**
|
|
24
|
+
* Each character of set1 becomes the character at the same position in set2.
|
|
25
|
+
* Extra characters of set1 all become the last character of set2. Every other
|
|
26
|
+
* character stays as it is.
|
|
27
|
+
*/
|
|
28
|
+
translate: (input: unknown, set1: unknown, set2: unknown) => string | VCLFailure;
|
|
6
29
|
};
|
package/dist/vcl-value.d.ts
CHANGED
|
@@ -60,6 +60,17 @@ export declare const HEADER_FRAGMENT_SEPARATOR = "\n";
|
|
|
60
60
|
export declare function firstHeaderFragment(value: string): string;
|
|
61
61
|
/** Convert any runtime value to its VCL string form. */
|
|
62
62
|
export declare function vclToString(v: any): string;
|
|
63
|
+
/** True when the string is valid UTF-8. */
|
|
64
|
+
export declare function isValidUtf8(s: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* A builtin that fails with a fastly.error returns this. The value is what the
|
|
67
|
+
* caller reads, and null means a not-set STRING.
|
|
68
|
+
*/
|
|
69
|
+
export declare class VCLFailure {
|
|
70
|
+
readonly value: string | null;
|
|
71
|
+
readonly error: string;
|
|
72
|
+
constructor(value: string | null, error: string);
|
|
73
|
+
}
|
|
63
74
|
/** Check if a value is a NOTSET VCLString */
|
|
64
75
|
export declare function isNotSet(v: any): v is VCLString;
|
|
65
76
|
/** Get the raw string value (empty string for NOTSET) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastly.js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "A reimplementation of the Fastly platform in TypeScript: parse and execute Fastly VCL locally, with the full request pipeline, caching, ESI, and the VCL standard library.",
|
|
5
5
|
"author": "Frank Denis <github@pureftpd.org>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
44
|
+
"node": ">=20.19"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"start": "bun run index.ts",
|
|
@@ -74,17 +74,17 @@
|
|
|
74
74
|
"typecheck": "tsc --noEmit"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@biomejs/biome": "^2.
|
|
78
|
-
"@types/bun": "^1.
|
|
77
|
+
"@biomejs/biome": "^2.6.8",
|
|
78
|
+
"@types/bun": "^1.4.4",
|
|
79
79
|
"@types/chai": "^5.2.3",
|
|
80
|
-
"chai": "^6.
|
|
81
|
-
"typescript": "^
|
|
80
|
+
"chai": "^6.3.0",
|
|
81
|
+
"typescript": "^7.0.2"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@noble/ciphers": "^2.
|
|
85
|
-
"@noble/hashes": "^2.
|
|
84
|
+
"@noble/ciphers": "^2.4.0",
|
|
85
|
+
"@noble/hashes": "^2.4.0",
|
|
86
86
|
"buffer": "^6.0.3",
|
|
87
87
|
"js-xxhash": "^5.0.1",
|
|
88
|
-
"uuid": "^
|
|
88
|
+
"uuid": "^14.0.3"
|
|
89
89
|
}
|
|
90
90
|
}
|