@optique/core 1.0.0-dev.1858 → 1.0.0-dev.1862
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/annotations.cjs +18 -5
- package/dist/annotations.d.cts +1 -1
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.js +18 -5
- package/package.json +1 -1
package/dist/annotations.cjs
CHANGED
|
@@ -104,6 +104,9 @@ function copyOwnProperties(source, target, transformValue, excludedKeys) {
|
|
|
104
104
|
Object.defineProperty(target, key, descriptor);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
+
function normalizeProtectedCollectionItem(value, context) {
|
|
108
|
+
return context.rewrapProtectedViews && isProtectedAnnotationView(value) ? unwrapProtectedAnnotationTarget(value) : value;
|
|
109
|
+
}
|
|
107
110
|
const regExpExcludedKeys = new Set(["lastIndex"]);
|
|
108
111
|
function copyRegExpMetadata(source, target, transformValue) {
|
|
109
112
|
copyOwnProperties(source, target, transformValue, regExpExcludedKeys);
|
|
@@ -156,13 +159,18 @@ function createProtectedObjectView(target, context) {
|
|
|
156
159
|
}
|
|
157
160
|
function createProtectedMapView(target, context) {
|
|
158
161
|
const methodCache = /* @__PURE__ */ new Map();
|
|
159
|
-
const cloned = new Map(
|
|
162
|
+
const cloned = /* @__PURE__ */ new Map();
|
|
163
|
+
for (const [entryKey, entryValue] of target.entries()) cloned.set(normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context));
|
|
160
164
|
const view = new Proxy(cloned, {
|
|
161
165
|
get(clonedTarget, key) {
|
|
162
166
|
if (key === "size") return clonedTarget.size;
|
|
167
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
163
168
|
if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
164
|
-
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) =>
|
|
165
|
-
|
|
169
|
+
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => {
|
|
170
|
+
if (clonedTarget.has(lookup)) return protectAnnotationValue(clonedTarget.get(lookup), context);
|
|
171
|
+
return protectAnnotationValue(clonedTarget.get(unwrapProtectedAnnotationTarget(lookup)), context);
|
|
172
|
+
});
|
|
173
|
+
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(lookup) || clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
166
174
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1, mapKey) => {
|
|
167
175
|
callback.call(thisArg, protectAnnotationValue(value$1, context), protectAnnotationValue(mapKey, context), view);
|
|
168
176
|
}));
|
|
@@ -201,12 +209,14 @@ function createProtectedMapView(target, context) {
|
|
|
201
209
|
}
|
|
202
210
|
function createProtectedSetView(target, context) {
|
|
203
211
|
const methodCache = /* @__PURE__ */ new Map();
|
|
204
|
-
const cloned = new Set(
|
|
212
|
+
const cloned = /* @__PURE__ */ new Set();
|
|
213
|
+
for (const value of target.values()) cloned.add(normalizeProtectedCollectionItem(value, context));
|
|
205
214
|
const view = new Proxy(cloned, {
|
|
206
215
|
get(clonedTarget, key) {
|
|
207
216
|
if (key === "size") return clonedTarget.size;
|
|
217
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
208
218
|
if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
209
|
-
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
219
|
+
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(lookup) || clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
210
220
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1) => {
|
|
211
221
|
const protectedValue = protectAnnotationValue(value$1, context);
|
|
212
222
|
callback.call(thisArg, protectedValue, protectedValue, view);
|
|
@@ -280,6 +290,7 @@ function createProtectedRegExpView(target, context) {
|
|
|
280
290
|
const view = new Proxy(cloned, {
|
|
281
291
|
get(clonedTarget, key) {
|
|
282
292
|
if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
293
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
283
294
|
const ownDescriptor = Object.getOwnPropertyDescriptor(clonedTarget, key);
|
|
284
295
|
if (ownDescriptor != null && "value" in ownDescriptor) return ownDescriptor.value;
|
|
285
296
|
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
@@ -312,6 +323,7 @@ function createProtectedURLSearchParamsView(target, context) {
|
|
|
312
323
|
const view = new Proxy(cloned, {
|
|
313
324
|
get(clonedTarget, key) {
|
|
314
325
|
if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
326
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
315
327
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1, name) => {
|
|
316
328
|
callback.call(thisArg, value$1, name, view);
|
|
317
329
|
}));
|
|
@@ -350,6 +362,7 @@ function createProtectedURLView(target, context) {
|
|
|
350
362
|
const cloned = new URL(target.href);
|
|
351
363
|
const view = new Proxy(cloned, {
|
|
352
364
|
get(clonedTarget, key) {
|
|
365
|
+
if (key === "valueOf") return () => view;
|
|
353
366
|
if (key === "searchParams") return protectAnnotationValue(clonedTarget.searchParams, context);
|
|
354
367
|
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
355
368
|
return typeof value === "function" ? value.bind(clonedTarget) : protectAnnotationValue(value, context);
|
package/dist/annotations.d.cts
CHANGED
|
@@ -88,7 +88,7 @@ interface ParseOptions {
|
|
|
88
88
|
* Optique treats these values as immutable input and exposes them back to
|
|
89
89
|
* parsers only through protected read-only views.
|
|
90
90
|
*/
|
|
91
|
-
annotations?: Annotations | ReadonlyAnnotations;
|
|
91
|
+
readonly annotations?: Annotations | ReadonlyAnnotations;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Extracts annotations from parser state.
|
package/dist/annotations.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ interface ParseOptions {
|
|
|
88
88
|
* Optique treats these values as immutable input and exposes them back to
|
|
89
89
|
* parsers only through protected read-only views.
|
|
90
90
|
*/
|
|
91
|
-
annotations?: Annotations | ReadonlyAnnotations;
|
|
91
|
+
readonly annotations?: Annotations | ReadonlyAnnotations;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Extracts annotations from parser state.
|
package/dist/annotations.js
CHANGED
|
@@ -103,6 +103,9 @@ function copyOwnProperties(source, target, transformValue, excludedKeys) {
|
|
|
103
103
|
Object.defineProperty(target, key, descriptor);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
function normalizeProtectedCollectionItem(value, context) {
|
|
107
|
+
return context.rewrapProtectedViews && isProtectedAnnotationView(value) ? unwrapProtectedAnnotationTarget(value) : value;
|
|
108
|
+
}
|
|
106
109
|
const regExpExcludedKeys = new Set(["lastIndex"]);
|
|
107
110
|
function copyRegExpMetadata(source, target, transformValue) {
|
|
108
111
|
copyOwnProperties(source, target, transformValue, regExpExcludedKeys);
|
|
@@ -155,13 +158,18 @@ function createProtectedObjectView(target, context) {
|
|
|
155
158
|
}
|
|
156
159
|
function createProtectedMapView(target, context) {
|
|
157
160
|
const methodCache = /* @__PURE__ */ new Map();
|
|
158
|
-
const cloned = new Map(
|
|
161
|
+
const cloned = /* @__PURE__ */ new Map();
|
|
162
|
+
for (const [entryKey, entryValue] of target.entries()) cloned.set(normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context));
|
|
159
163
|
const view = new Proxy(cloned, {
|
|
160
164
|
get(clonedTarget, key) {
|
|
161
165
|
if (key === "size") return clonedTarget.size;
|
|
166
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
162
167
|
if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
163
|
-
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) =>
|
|
164
|
-
|
|
168
|
+
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => {
|
|
169
|
+
if (clonedTarget.has(lookup)) return protectAnnotationValue(clonedTarget.get(lookup), context);
|
|
170
|
+
return protectAnnotationValue(clonedTarget.get(unwrapProtectedAnnotationTarget(lookup)), context);
|
|
171
|
+
});
|
|
172
|
+
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(lookup) || clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
165
173
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1, mapKey) => {
|
|
166
174
|
callback.call(thisArg, protectAnnotationValue(value$1, context), protectAnnotationValue(mapKey, context), view);
|
|
167
175
|
}));
|
|
@@ -200,12 +208,14 @@ function createProtectedMapView(target, context) {
|
|
|
200
208
|
}
|
|
201
209
|
function createProtectedSetView(target, context) {
|
|
202
210
|
const methodCache = /* @__PURE__ */ new Map();
|
|
203
|
-
const cloned = new Set(
|
|
211
|
+
const cloned = /* @__PURE__ */ new Set();
|
|
212
|
+
for (const value of target.values()) cloned.add(normalizeProtectedCollectionItem(value, context));
|
|
204
213
|
const view = new Proxy(cloned, {
|
|
205
214
|
get(clonedTarget, key) {
|
|
206
215
|
if (key === "size") return clonedTarget.size;
|
|
216
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
207
217
|
if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
208
|
-
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
218
|
+
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(lookup) || clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
209
219
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1) => {
|
|
210
220
|
const protectedValue = protectAnnotationValue(value$1, context);
|
|
211
221
|
callback.call(thisArg, protectedValue, protectedValue, view);
|
|
@@ -279,6 +289,7 @@ function createProtectedRegExpView(target, context) {
|
|
|
279
289
|
const view = new Proxy(cloned, {
|
|
280
290
|
get(clonedTarget, key) {
|
|
281
291
|
if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
292
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
282
293
|
const ownDescriptor = Object.getOwnPropertyDescriptor(clonedTarget, key);
|
|
283
294
|
if (ownDescriptor != null && "value" in ownDescriptor) return ownDescriptor.value;
|
|
284
295
|
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
@@ -311,6 +322,7 @@ function createProtectedURLSearchParamsView(target, context) {
|
|
|
311
322
|
const view = new Proxy(cloned, {
|
|
312
323
|
get(clonedTarget, key) {
|
|
313
324
|
if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
325
|
+
if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
|
|
314
326
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1, name) => {
|
|
315
327
|
callback.call(thisArg, value$1, name, view);
|
|
316
328
|
}));
|
|
@@ -349,6 +361,7 @@ function createProtectedURLView(target, context) {
|
|
|
349
361
|
const cloned = new URL(target.href);
|
|
350
362
|
const view = new Proxy(cloned, {
|
|
351
363
|
get(clonedTarget, key) {
|
|
364
|
+
if (key === "valueOf") return () => view;
|
|
352
365
|
if (key === "searchParams") return protectAnnotationValue(clonedTarget.searchParams, context);
|
|
353
366
|
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
354
367
|
return typeof value === "function" ? value.bind(clonedTarget) : protectAnnotationValue(value, context);
|