@ptolemy2002/rgx 13.10.0 → 13.11.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.
- package/README.md +3 -0
- package/dist/json.js +34 -8
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -41,6 +41,9 @@ Because there is so much to document, it has been broken up into multiple files.
|
|
|
41
41
|
- [lookahead](./docs/class/token/lookaround/lookahead.md) - The `RGXLookaheadToken` class, which represents a lookahead assertion in a regular expression.
|
|
42
42
|
- [lookbehind](./docs/class/token/lookaround/lookbehind.md) - The `RGXLookbehindToken` class, which represents a lookbehind assertion in a regular expression.
|
|
43
43
|
|
|
44
|
+
## Pending Breaking Changes
|
|
45
|
+
Breaking changes that would improve the library, but are not worth a major release by themselves, are tracked in [PENDING_BREAKING_CHANGES.md](./PENDING_BREAKING_CHANGES.md) along with the non-breaking workarounds currently in place for them. They will be made in the next major release.
|
|
46
|
+
|
|
44
47
|
## Peer Dependencies
|
|
45
48
|
N/A
|
|
46
49
|
|
package/dist/json.js
CHANGED
|
@@ -59,6 +59,22 @@ const collection_1 = require("./collection");
|
|
|
59
59
|
const ExtRegExp_1 = require("./ExtRegExp");
|
|
60
60
|
const resolve_1 = require("./resolve");
|
|
61
61
|
const rgxJSONClasses = {};
|
|
62
|
+
// Maps args arrays that have already passed the validator of the class they are mapped to and are currently
|
|
63
|
+
// being constructed. rgxJSONClassArgs uses this to skip validating them a second time.
|
|
64
|
+
const validatedRGXJSONClassArgs = new WeakMap();
|
|
65
|
+
function constructValidatedRGXJSONClass(name, raw, args) {
|
|
66
|
+
validatedRGXJSONClassArgs.set(args, name);
|
|
67
|
+
try {
|
|
68
|
+
return raw.construct(args);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
validatedRGXJSONClassArgs.delete(args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getRGXJSONClassRecord(name) {
|
|
75
|
+
assertHasRGXJSONClass(name);
|
|
76
|
+
return rgxJSONClasses[name];
|
|
77
|
+
}
|
|
62
78
|
// ------------------ Registry ------------------
|
|
63
79
|
function listRGXJSONClasses() {
|
|
64
80
|
return Object.keys(rgxJSONClasses);
|
|
@@ -78,8 +94,17 @@ function assertNotHasRGXJSONClass(name) {
|
|
|
78
94
|
}
|
|
79
95
|
function registerRGXJSONClass(name, entry) {
|
|
80
96
|
assertNotHasRGXJSONClass(name);
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
// Copied so that later changes to the given entry cannot bypass the guard.
|
|
98
|
+
const raw = { validateArgs: entry.validateArgs, construct: entry.construct };
|
|
99
|
+
const guarded = Object.freeze({
|
|
100
|
+
validateArgs: raw.validateArgs,
|
|
101
|
+
construct: (args) => {
|
|
102
|
+
assertValidRGXJSONClassArgs(name, args);
|
|
103
|
+
return constructValidatedRGXJSONClass(name, raw, args);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
rgxJSONClasses[name] = { raw, guarded };
|
|
107
|
+
return guarded;
|
|
83
108
|
}
|
|
84
109
|
function registerRGXJSONClassToken(name, constructor) {
|
|
85
110
|
return registerRGXJSONClass(name, {
|
|
@@ -88,15 +113,14 @@ function registerRGXJSONClassToken(name, constructor) {
|
|
|
88
113
|
});
|
|
89
114
|
}
|
|
90
115
|
function getRGXJSONClass(name) {
|
|
91
|
-
|
|
92
|
-
return rgxJSONClasses[name];
|
|
116
|
+
return getRGXJSONClassRecord(name).guarded;
|
|
93
117
|
}
|
|
94
118
|
function unregisterRGXJSONClass(name) {
|
|
95
119
|
assertHasRGXJSONClass(name);
|
|
96
120
|
delete rgxJSONClasses[name];
|
|
97
121
|
}
|
|
98
122
|
function validateRGXJSONClassArgs(name, args) {
|
|
99
|
-
const result =
|
|
123
|
+
const result = getRGXJSONClassRecord(name).raw.validateArgs(args);
|
|
100
124
|
if (result === true)
|
|
101
125
|
return true;
|
|
102
126
|
if (result === false)
|
|
@@ -129,6 +153,9 @@ function assertRGXJSONClassTokenOf(json, name) {
|
|
|
129
153
|
function rgxJSONClassArgs(json, name, validate) {
|
|
130
154
|
assertRGXJSONClassTokenOf(json, name);
|
|
131
155
|
const args = json.args ?? [];
|
|
156
|
+
// The registry already validated these args against this class before constructing.
|
|
157
|
+
if (validatedRGXJSONClassArgs.get(args) === name)
|
|
158
|
+
return args;
|
|
132
159
|
const result = validate(args);
|
|
133
160
|
if (result === true)
|
|
134
161
|
return args;
|
|
@@ -179,9 +206,8 @@ function rgxTokenFromJSON(json) {
|
|
|
179
206
|
return new ExtRegExp_1.ExtRegExp(json.source, json.flags ?? '');
|
|
180
207
|
}
|
|
181
208
|
if (tg.isRGXJSONClassToken(json, false)) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return getRGXJSONClass(json.class).construct(args);
|
|
209
|
+
// The guarded construct validates the args before constructing.
|
|
210
|
+
return getRGXJSONClass(json.class).construct(json.args ?? []);
|
|
185
211
|
}
|
|
186
212
|
if (Array.isArray(json))
|
|
187
213
|
return json.map(item => rgxTokenFromJSON(item));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptolemy2002/rgx",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.11.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,14 +20,13 @@
|
|
|
20
20
|
"url": "https://github.com/Ptolemy2002/rgx"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"prepare": "npx ts-patch install -s",
|
|
23
|
+
"prepare": "npx ts-patch install -s && npx typesync",
|
|
24
24
|
"build": "bash ./scripts/build.sh",
|
|
25
25
|
"_build": "tsc --project ./tsconfig.build.json",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
27
|
"test": "jest",
|
|
28
28
|
"test:watch": "jest --watch",
|
|
29
29
|
"test:coverage": "jest --coverage",
|
|
30
|
-
"postinstall": "npx typesync",
|
|
31
30
|
"uninstall": "bash ./scripts/uninstall.sh",
|
|
32
31
|
"reinstall": "bash ./scripts/reinstall.sh",
|
|
33
32
|
"release": "bash ./scripts/release.sh",
|
|
@@ -43,13 +42,14 @@
|
|
|
43
42
|
"ts-jest": "^29.1.0",
|
|
44
43
|
"ts-patch": "^3.3.0",
|
|
45
44
|
"tsconfig-paths": "^4.2.0",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
46
|
"typescript-transform-paths": "^3.5.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@ptolemy2002/immutability-utils": "^2.0.0",
|
|
50
50
|
"@ptolemy2002/js-utils": "^3.2.2",
|
|
51
51
|
"@ptolemy2002/ts-brand-utils": "^1.0.0",
|
|
52
|
-
"@ptolemy2002/ts-utils": "^
|
|
52
|
+
"@ptolemy2002/ts-utils": "^4.0.0",
|
|
53
53
|
"is-callable": "^1.2.7",
|
|
54
54
|
"lodash.clonedeep": "^4.5.0"
|
|
55
55
|
}
|