@ptolemy2002/rgx 13.10.0 → 13.11.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 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
- rgxJSONClasses[name] = entry;
82
- return entry;
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
- assertHasRGXJSONClass(name);
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 = getRGXJSONClass(name).validateArgs(args);
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
- const args = json.args ?? [];
183
- assertValidRGXJSONClassArgs(json.class, args);
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.10.0",
3
+ "version": "13.11.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,13 +43,14 @@
43
43
  "ts-jest": "^29.1.0",
44
44
  "ts-patch": "^3.3.0",
45
45
  "tsconfig-paths": "^4.2.0",
46
+ "typescript": "^5.9.3",
46
47
  "typescript-transform-paths": "^3.5.3"
47
48
  },
48
49
  "dependencies": {
49
50
  "@ptolemy2002/immutability-utils": "^2.0.0",
50
51
  "@ptolemy2002/js-utils": "^3.2.2",
51
52
  "@ptolemy2002/ts-brand-utils": "^1.0.0",
52
- "@ptolemy2002/ts-utils": "^3.4.0",
53
+ "@ptolemy2002/ts-utils": "^4.0.0",
53
54
  "is-callable": "^1.2.7",
54
55
  "lodash.clonedeep": "^4.5.0"
55
56
  }