@optique/core 1.0.0-dev.1846 → 1.0.0-dev.1850
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 +66 -49
- package/dist/annotations.js +66 -49
- package/package.json +1 -1
package/dist/annotations.cjs
CHANGED
|
@@ -46,12 +46,15 @@ const annotationWrapperKeys = new Set([
|
|
|
46
46
|
]);
|
|
47
47
|
const injectedAnnotationWrappers = /* @__PURE__ */ new WeakSet();
|
|
48
48
|
const protectedAnnotationTargets = /* @__PURE__ */ new WeakMap();
|
|
49
|
-
const
|
|
49
|
+
const protectedAnnotationStateViews = /* @__PURE__ */ new WeakMap();
|
|
50
50
|
function throwReadonlyAnnotationMutation() {
|
|
51
51
|
throw new TypeError("Cannot mutate read-only annotation data.");
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
53
|
+
function createAnnotationProtectionContext() {
|
|
54
|
+
return { cache: /* @__PURE__ */ new WeakMap() };
|
|
55
|
+
}
|
|
56
|
+
function registerProtectedAnnotationView(context, target, view) {
|
|
57
|
+
context.cache.set(target, view);
|
|
55
58
|
protectedAnnotationTargets.set(view, target);
|
|
56
59
|
return view;
|
|
57
60
|
}
|
|
@@ -69,8 +72,8 @@ function cacheProtectedMethod(cache, key, factory) {
|
|
|
69
72
|
cache.set(key, created);
|
|
70
73
|
return created;
|
|
71
74
|
}
|
|
72
|
-
function defineProtectedDataProperty(target, key, descriptor) {
|
|
73
|
-
const value = protectAnnotationValue(descriptor.value);
|
|
75
|
+
function defineProtectedDataProperty(context, target, key, descriptor) {
|
|
76
|
+
const value = protectAnnotationValue(descriptor.value, context);
|
|
74
77
|
Object.defineProperty(target, key, {
|
|
75
78
|
configurable: descriptor.configurable,
|
|
76
79
|
enumerable: descriptor.enumerable,
|
|
@@ -78,62 +81,64 @@ function defineProtectedDataProperty(target, key, descriptor) {
|
|
|
78
81
|
set: () => throwReadonlyAnnotationMutation()
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
|
-
function createProtectedObjectView(target) {
|
|
84
|
+
function createProtectedObjectView(target, context) {
|
|
82
85
|
if (Array.isArray(target)) {
|
|
83
86
|
const view$1 = new Array(target.length);
|
|
87
|
+
registerProtectedAnnotationView(context, target, view$1);
|
|
84
88
|
for (const key of Reflect.ownKeys(target)) {
|
|
85
89
|
if (key === "length") continue;
|
|
86
90
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
87
91
|
if (descriptor == null) continue;
|
|
88
92
|
if ("value" in descriptor) {
|
|
89
|
-
defineProtectedDataProperty(view$1, key, descriptor);
|
|
93
|
+
defineProtectedDataProperty(context, view$1, key, descriptor);
|
|
90
94
|
continue;
|
|
91
95
|
}
|
|
92
96
|
Object.defineProperty(view$1, key, {
|
|
93
97
|
configurable: descriptor.configurable,
|
|
94
98
|
enumerable: descriptor.enumerable,
|
|
95
|
-
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
|
|
99
|
+
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target), context),
|
|
96
100
|
set: () => throwReadonlyAnnotationMutation()
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
|
-
return
|
|
103
|
+
return Object.freeze(view$1);
|
|
100
104
|
}
|
|
101
105
|
const view = Object.create(Object.getPrototypeOf(target));
|
|
106
|
+
registerProtectedAnnotationView(context, target, view);
|
|
102
107
|
for (const key of Reflect.ownKeys(target)) {
|
|
103
108
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
104
109
|
if (descriptor == null) continue;
|
|
105
110
|
if ("value" in descriptor) {
|
|
106
|
-
defineProtectedDataProperty(view, key, descriptor);
|
|
111
|
+
defineProtectedDataProperty(context, view, key, descriptor);
|
|
107
112
|
continue;
|
|
108
113
|
}
|
|
109
114
|
Object.defineProperty(view, key, {
|
|
110
115
|
configurable: descriptor.configurable,
|
|
111
116
|
enumerable: descriptor.enumerable,
|
|
112
|
-
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
|
|
117
|
+
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target), context),
|
|
113
118
|
set: () => throwReadonlyAnnotationMutation()
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
|
-
return
|
|
121
|
+
return Object.freeze(view);
|
|
117
122
|
}
|
|
118
|
-
function createProtectedMapView(target) {
|
|
123
|
+
function createProtectedMapView(target, context) {
|
|
119
124
|
const methodCache = /* @__PURE__ */ new Map();
|
|
120
125
|
const view = new Proxy(target, {
|
|
121
126
|
get(target$1, key) {
|
|
122
127
|
if (key === "size") return target$1.size;
|
|
123
128
|
if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
124
|
-
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup))));
|
|
129
|
+
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup)), context));
|
|
125
130
|
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
126
131
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, mapKey) => {
|
|
127
|
-
callback.call(thisArg, protectAnnotationValue(value$1), protectAnnotationValue(mapKey), view);
|
|
132
|
+
callback.call(thisArg, protectAnnotationValue(value$1, context), protectAnnotationValue(mapKey, context), view);
|
|
128
133
|
}));
|
|
129
134
|
if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
130
|
-
for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1);
|
|
135
|
+
for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1, context);
|
|
131
136
|
});
|
|
132
137
|
if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
133
|
-
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
|
|
138
|
+
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1, context);
|
|
134
139
|
});
|
|
135
140
|
if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
136
|
-
for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey), protectAnnotationValue(entryValue)];
|
|
141
|
+
for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey, context), protectAnnotationValue(entryValue, context)];
|
|
137
142
|
});
|
|
138
143
|
const value = Reflect.get(target$1, key, target$1);
|
|
139
144
|
return typeof value === "function" ? value.bind(target$1) : value;
|
|
@@ -154,9 +159,9 @@ function createProtectedMapView(target) {
|
|
|
154
159
|
throwReadonlyAnnotationMutation();
|
|
155
160
|
}
|
|
156
161
|
});
|
|
157
|
-
return registerProtectedAnnotationView(target, view);
|
|
162
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
158
163
|
}
|
|
159
|
-
function createProtectedSetView(target) {
|
|
164
|
+
function createProtectedSetView(target, context) {
|
|
160
165
|
const methodCache = /* @__PURE__ */ new Map();
|
|
161
166
|
const view = new Proxy(target, {
|
|
162
167
|
get(target$1, key) {
|
|
@@ -164,15 +169,15 @@ function createProtectedSetView(target) {
|
|
|
164
169
|
if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
165
170
|
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
166
171
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1) => {
|
|
167
|
-
const protectedValue = protectAnnotationValue(value$1);
|
|
172
|
+
const protectedValue = protectAnnotationValue(value$1, context);
|
|
168
173
|
callback.call(thisArg, protectedValue, protectedValue, view);
|
|
169
174
|
}));
|
|
170
175
|
if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
171
|
-
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
|
|
176
|
+
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1, context);
|
|
172
177
|
});
|
|
173
178
|
if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
174
179
|
for (const value$1 of target$1.values()) {
|
|
175
|
-
const protectedValue = protectAnnotationValue(value$1);
|
|
180
|
+
const protectedValue = protectAnnotationValue(value$1, context);
|
|
176
181
|
yield [protectedValue, protectedValue];
|
|
177
182
|
}
|
|
178
183
|
});
|
|
@@ -195,9 +200,9 @@ function createProtectedSetView(target) {
|
|
|
195
200
|
throwReadonlyAnnotationMutation();
|
|
196
201
|
}
|
|
197
202
|
});
|
|
198
|
-
return registerProtectedAnnotationView(target, view);
|
|
203
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
199
204
|
}
|
|
200
|
-
function createProtectedDateView(target) {
|
|
205
|
+
function createProtectedDateView(target, context) {
|
|
201
206
|
const methodCache = /* @__PURE__ */ new Map();
|
|
202
207
|
const view = new Proxy(target, {
|
|
203
208
|
get(target$1, key) {
|
|
@@ -221,15 +226,17 @@ function createProtectedDateView(target) {
|
|
|
221
226
|
throwReadonlyAnnotationMutation();
|
|
222
227
|
}
|
|
223
228
|
});
|
|
224
|
-
return registerProtectedAnnotationView(target, view);
|
|
229
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
225
230
|
}
|
|
226
|
-
function createProtectedRegExpView(target) {
|
|
231
|
+
function createProtectedRegExpView(target, context) {
|
|
227
232
|
const methodCache = /* @__PURE__ */ new Map();
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
const cloned = new RegExp(target);
|
|
234
|
+
cloned.lastIndex = target.lastIndex;
|
|
235
|
+
const view = new Proxy(cloned, {
|
|
236
|
+
get(clonedTarget, key) {
|
|
237
|
+
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
231
238
|
if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
232
|
-
return typeof value === "function" ? value.bind(
|
|
239
|
+
return typeof value === "function" ? value.bind(clonedTarget) : value;
|
|
233
240
|
},
|
|
234
241
|
set() {
|
|
235
242
|
throwReadonlyAnnotationMutation();
|
|
@@ -247,9 +254,9 @@ function createProtectedRegExpView(target) {
|
|
|
247
254
|
throwReadonlyAnnotationMutation();
|
|
248
255
|
}
|
|
249
256
|
});
|
|
250
|
-
return registerProtectedAnnotationView(target, view);
|
|
257
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
251
258
|
}
|
|
252
|
-
function createProtectedURLSearchParamsView(target) {
|
|
259
|
+
function createProtectedURLSearchParamsView(target, context) {
|
|
253
260
|
const methodCache = /* @__PURE__ */ new Map();
|
|
254
261
|
const view = new Proxy(target, {
|
|
255
262
|
get(target$1, key) {
|
|
@@ -283,12 +290,12 @@ function createProtectedURLSearchParamsView(target) {
|
|
|
283
290
|
throwReadonlyAnnotationMutation();
|
|
284
291
|
}
|
|
285
292
|
});
|
|
286
|
-
return registerProtectedAnnotationView(target, view);
|
|
293
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
287
294
|
}
|
|
288
|
-
function createProtectedURLView(target) {
|
|
295
|
+
function createProtectedURLView(target, context) {
|
|
289
296
|
const view = new Proxy(target, {
|
|
290
297
|
get(target$1, key) {
|
|
291
|
-
if (key === "searchParams") return protectAnnotationValue(target$1.searchParams);
|
|
298
|
+
if (key === "searchParams") return protectAnnotationValue(target$1.searchParams, context);
|
|
292
299
|
const value = Reflect.get(target$1, key, target$1);
|
|
293
300
|
return typeof value === "function" ? value.bind(target$1) : value;
|
|
294
301
|
},
|
|
@@ -308,23 +315,23 @@ function createProtectedURLView(target) {
|
|
|
308
315
|
throwReadonlyAnnotationMutation();
|
|
309
316
|
}
|
|
310
317
|
});
|
|
311
|
-
return registerProtectedAnnotationView(target, view);
|
|
318
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
312
319
|
}
|
|
313
|
-
function protectAnnotationValue(value) {
|
|
320
|
+
function protectAnnotationValue(value, context) {
|
|
314
321
|
if (value == null || typeof value !== "object") return value;
|
|
315
322
|
const target = value;
|
|
316
323
|
if (isProtectedAnnotationView(value)) return value;
|
|
317
|
-
const cached =
|
|
324
|
+
const cached = context.cache.get(target);
|
|
318
325
|
if (cached !== void 0) return cached;
|
|
319
|
-
if (target instanceof Map) return createProtectedMapView(target);
|
|
320
|
-
if (target instanceof Set) return createProtectedSetView(target);
|
|
321
|
-
if (target instanceof Date) return createProtectedDateView(target);
|
|
322
|
-
if (target instanceof RegExp) return createProtectedRegExpView(target);
|
|
323
|
-
if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target);
|
|
324
|
-
if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target);
|
|
325
|
-
if (Array.isArray(target)) return createProtectedObjectView(target);
|
|
326
|
+
if (target instanceof Map) return createProtectedMapView(target, context);
|
|
327
|
+
if (target instanceof Set) return createProtectedSetView(target, context);
|
|
328
|
+
if (target instanceof Date) return createProtectedDateView(target, context);
|
|
329
|
+
if (target instanceof RegExp) return createProtectedRegExpView(target, context);
|
|
330
|
+
if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target, context);
|
|
331
|
+
if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target, context);
|
|
332
|
+
if (Array.isArray(target)) return createProtectedObjectView(target, context);
|
|
326
333
|
const proto = Object.getPrototypeOf(target);
|
|
327
|
-
if (proto === Object.prototype || proto === null) return createProtectedObjectView(target);
|
|
334
|
+
if (proto === Object.prototype || proto === null) return createProtectedObjectView(target, context);
|
|
328
335
|
return value;
|
|
329
336
|
}
|
|
330
337
|
/**
|
|
@@ -347,7 +354,17 @@ function getAnnotations(state) {
|
|
|
347
354
|
if (state == null || typeof state !== "object") return void 0;
|
|
348
355
|
const stateObj = state;
|
|
349
356
|
const annotations = stateObj[annotationKey];
|
|
350
|
-
if (annotations != null && typeof annotations === "object")
|
|
357
|
+
if (annotations != null && typeof annotations === "object") {
|
|
358
|
+
if (isProtectedAnnotationView(annotations)) return annotations;
|
|
359
|
+
const cached = protectedAnnotationStateViews.get(stateObj);
|
|
360
|
+
if (cached?.raw === annotations) return cached.view;
|
|
361
|
+
const protectedView = protectAnnotationValue(annotations, createAnnotationProtectionContext());
|
|
362
|
+
protectedAnnotationStateViews.set(stateObj, {
|
|
363
|
+
raw: annotations,
|
|
364
|
+
view: protectedView
|
|
365
|
+
});
|
|
366
|
+
return protectedView;
|
|
367
|
+
}
|
|
351
368
|
return void 0;
|
|
352
369
|
}
|
|
353
370
|
/**
|
|
@@ -448,7 +465,7 @@ function hasMeaningfulAnnotations(annotations) {
|
|
|
448
465
|
*/
|
|
449
466
|
function injectAnnotations(state, annotations) {
|
|
450
467
|
if (!hasMeaningfulAnnotations(annotations)) return state;
|
|
451
|
-
const protectedAnnotations = protectAnnotationValue(annotations);
|
|
468
|
+
const protectedAnnotations = protectAnnotationValue(annotations, createAnnotationProtectionContext());
|
|
452
469
|
if (state == null || typeof state !== "object") {
|
|
453
470
|
const wrapper = {};
|
|
454
471
|
Object.defineProperties(wrapper, {
|
package/dist/annotations.js
CHANGED
|
@@ -45,12 +45,15 @@ const annotationWrapperKeys = new Set([
|
|
|
45
45
|
]);
|
|
46
46
|
const injectedAnnotationWrappers = /* @__PURE__ */ new WeakSet();
|
|
47
47
|
const protectedAnnotationTargets = /* @__PURE__ */ new WeakMap();
|
|
48
|
-
const
|
|
48
|
+
const protectedAnnotationStateViews = /* @__PURE__ */ new WeakMap();
|
|
49
49
|
function throwReadonlyAnnotationMutation() {
|
|
50
50
|
throw new TypeError("Cannot mutate read-only annotation data.");
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
52
|
+
function createAnnotationProtectionContext() {
|
|
53
|
+
return { cache: /* @__PURE__ */ new WeakMap() };
|
|
54
|
+
}
|
|
55
|
+
function registerProtectedAnnotationView(context, target, view) {
|
|
56
|
+
context.cache.set(target, view);
|
|
54
57
|
protectedAnnotationTargets.set(view, target);
|
|
55
58
|
return view;
|
|
56
59
|
}
|
|
@@ -68,8 +71,8 @@ function cacheProtectedMethod(cache, key, factory) {
|
|
|
68
71
|
cache.set(key, created);
|
|
69
72
|
return created;
|
|
70
73
|
}
|
|
71
|
-
function defineProtectedDataProperty(target, key, descriptor) {
|
|
72
|
-
const value = protectAnnotationValue(descriptor.value);
|
|
74
|
+
function defineProtectedDataProperty(context, target, key, descriptor) {
|
|
75
|
+
const value = protectAnnotationValue(descriptor.value, context);
|
|
73
76
|
Object.defineProperty(target, key, {
|
|
74
77
|
configurable: descriptor.configurable,
|
|
75
78
|
enumerable: descriptor.enumerable,
|
|
@@ -77,62 +80,64 @@ function defineProtectedDataProperty(target, key, descriptor) {
|
|
|
77
80
|
set: () => throwReadonlyAnnotationMutation()
|
|
78
81
|
});
|
|
79
82
|
}
|
|
80
|
-
function createProtectedObjectView(target) {
|
|
83
|
+
function createProtectedObjectView(target, context) {
|
|
81
84
|
if (Array.isArray(target)) {
|
|
82
85
|
const view$1 = new Array(target.length);
|
|
86
|
+
registerProtectedAnnotationView(context, target, view$1);
|
|
83
87
|
for (const key of Reflect.ownKeys(target)) {
|
|
84
88
|
if (key === "length") continue;
|
|
85
89
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
86
90
|
if (descriptor == null) continue;
|
|
87
91
|
if ("value" in descriptor) {
|
|
88
|
-
defineProtectedDataProperty(view$1, key, descriptor);
|
|
92
|
+
defineProtectedDataProperty(context, view$1, key, descriptor);
|
|
89
93
|
continue;
|
|
90
94
|
}
|
|
91
95
|
Object.defineProperty(view$1, key, {
|
|
92
96
|
configurable: descriptor.configurable,
|
|
93
97
|
enumerable: descriptor.enumerable,
|
|
94
|
-
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
|
|
98
|
+
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target), context),
|
|
95
99
|
set: () => throwReadonlyAnnotationMutation()
|
|
96
100
|
});
|
|
97
101
|
}
|
|
98
|
-
return
|
|
102
|
+
return Object.freeze(view$1);
|
|
99
103
|
}
|
|
100
104
|
const view = Object.create(Object.getPrototypeOf(target));
|
|
105
|
+
registerProtectedAnnotationView(context, target, view);
|
|
101
106
|
for (const key of Reflect.ownKeys(target)) {
|
|
102
107
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
103
108
|
if (descriptor == null) continue;
|
|
104
109
|
if ("value" in descriptor) {
|
|
105
|
-
defineProtectedDataProperty(view, key, descriptor);
|
|
110
|
+
defineProtectedDataProperty(context, view, key, descriptor);
|
|
106
111
|
continue;
|
|
107
112
|
}
|
|
108
113
|
Object.defineProperty(view, key, {
|
|
109
114
|
configurable: descriptor.configurable,
|
|
110
115
|
enumerable: descriptor.enumerable,
|
|
111
|
-
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
|
|
116
|
+
get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target), context),
|
|
112
117
|
set: () => throwReadonlyAnnotationMutation()
|
|
113
118
|
});
|
|
114
119
|
}
|
|
115
|
-
return
|
|
120
|
+
return Object.freeze(view);
|
|
116
121
|
}
|
|
117
|
-
function createProtectedMapView(target) {
|
|
122
|
+
function createProtectedMapView(target, context) {
|
|
118
123
|
const methodCache = /* @__PURE__ */ new Map();
|
|
119
124
|
const view = new Proxy(target, {
|
|
120
125
|
get(target$1, key) {
|
|
121
126
|
if (key === "size") return target$1.size;
|
|
122
127
|
if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
123
|
-
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup))));
|
|
128
|
+
if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup)), context));
|
|
124
129
|
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
125
130
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, mapKey) => {
|
|
126
|
-
callback.call(thisArg, protectAnnotationValue(value$1), protectAnnotationValue(mapKey), view);
|
|
131
|
+
callback.call(thisArg, protectAnnotationValue(value$1, context), protectAnnotationValue(mapKey, context), view);
|
|
127
132
|
}));
|
|
128
133
|
if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
129
|
-
for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1);
|
|
134
|
+
for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1, context);
|
|
130
135
|
});
|
|
131
136
|
if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
132
|
-
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
|
|
137
|
+
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1, context);
|
|
133
138
|
});
|
|
134
139
|
if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
135
|
-
for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey), protectAnnotationValue(entryValue)];
|
|
140
|
+
for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey, context), protectAnnotationValue(entryValue, context)];
|
|
136
141
|
});
|
|
137
142
|
const value = Reflect.get(target$1, key, target$1);
|
|
138
143
|
return typeof value === "function" ? value.bind(target$1) : value;
|
|
@@ -153,9 +158,9 @@ function createProtectedMapView(target) {
|
|
|
153
158
|
throwReadonlyAnnotationMutation();
|
|
154
159
|
}
|
|
155
160
|
});
|
|
156
|
-
return registerProtectedAnnotationView(target, view);
|
|
161
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
157
162
|
}
|
|
158
|
-
function createProtectedSetView(target) {
|
|
163
|
+
function createProtectedSetView(target, context) {
|
|
159
164
|
const methodCache = /* @__PURE__ */ new Map();
|
|
160
165
|
const view = new Proxy(target, {
|
|
161
166
|
get(target$1, key) {
|
|
@@ -163,15 +168,15 @@ function createProtectedSetView(target) {
|
|
|
163
168
|
if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
164
169
|
if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
|
|
165
170
|
if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1) => {
|
|
166
|
-
const protectedValue = protectAnnotationValue(value$1);
|
|
171
|
+
const protectedValue = protectAnnotationValue(value$1, context);
|
|
167
172
|
callback.call(thisArg, protectedValue, protectedValue, view);
|
|
168
173
|
}));
|
|
169
174
|
if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
170
|
-
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
|
|
175
|
+
for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1, context);
|
|
171
176
|
});
|
|
172
177
|
if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
|
|
173
178
|
for (const value$1 of target$1.values()) {
|
|
174
|
-
const protectedValue = protectAnnotationValue(value$1);
|
|
179
|
+
const protectedValue = protectAnnotationValue(value$1, context);
|
|
175
180
|
yield [protectedValue, protectedValue];
|
|
176
181
|
}
|
|
177
182
|
});
|
|
@@ -194,9 +199,9 @@ function createProtectedSetView(target) {
|
|
|
194
199
|
throwReadonlyAnnotationMutation();
|
|
195
200
|
}
|
|
196
201
|
});
|
|
197
|
-
return registerProtectedAnnotationView(target, view);
|
|
202
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
198
203
|
}
|
|
199
|
-
function createProtectedDateView(target) {
|
|
204
|
+
function createProtectedDateView(target, context) {
|
|
200
205
|
const methodCache = /* @__PURE__ */ new Map();
|
|
201
206
|
const view = new Proxy(target, {
|
|
202
207
|
get(target$1, key) {
|
|
@@ -220,15 +225,17 @@ function createProtectedDateView(target) {
|
|
|
220
225
|
throwReadonlyAnnotationMutation();
|
|
221
226
|
}
|
|
222
227
|
});
|
|
223
|
-
return registerProtectedAnnotationView(target, view);
|
|
228
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
224
229
|
}
|
|
225
|
-
function createProtectedRegExpView(target) {
|
|
230
|
+
function createProtectedRegExpView(target, context) {
|
|
226
231
|
const methodCache = /* @__PURE__ */ new Map();
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
const cloned = new RegExp(target);
|
|
233
|
+
cloned.lastIndex = target.lastIndex;
|
|
234
|
+
const view = new Proxy(cloned, {
|
|
235
|
+
get(clonedTarget, key) {
|
|
236
|
+
const value = Reflect.get(clonedTarget, key, clonedTarget);
|
|
230
237
|
if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
|
|
231
|
-
return typeof value === "function" ? value.bind(
|
|
238
|
+
return typeof value === "function" ? value.bind(clonedTarget) : value;
|
|
232
239
|
},
|
|
233
240
|
set() {
|
|
234
241
|
throwReadonlyAnnotationMutation();
|
|
@@ -246,9 +253,9 @@ function createProtectedRegExpView(target) {
|
|
|
246
253
|
throwReadonlyAnnotationMutation();
|
|
247
254
|
}
|
|
248
255
|
});
|
|
249
|
-
return registerProtectedAnnotationView(target, view);
|
|
256
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
250
257
|
}
|
|
251
|
-
function createProtectedURLSearchParamsView(target) {
|
|
258
|
+
function createProtectedURLSearchParamsView(target, context) {
|
|
252
259
|
const methodCache = /* @__PURE__ */ new Map();
|
|
253
260
|
const view = new Proxy(target, {
|
|
254
261
|
get(target$1, key) {
|
|
@@ -282,12 +289,12 @@ function createProtectedURLSearchParamsView(target) {
|
|
|
282
289
|
throwReadonlyAnnotationMutation();
|
|
283
290
|
}
|
|
284
291
|
});
|
|
285
|
-
return registerProtectedAnnotationView(target, view);
|
|
292
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
286
293
|
}
|
|
287
|
-
function createProtectedURLView(target) {
|
|
294
|
+
function createProtectedURLView(target, context) {
|
|
288
295
|
const view = new Proxy(target, {
|
|
289
296
|
get(target$1, key) {
|
|
290
|
-
if (key === "searchParams") return protectAnnotationValue(target$1.searchParams);
|
|
297
|
+
if (key === "searchParams") return protectAnnotationValue(target$1.searchParams, context);
|
|
291
298
|
const value = Reflect.get(target$1, key, target$1);
|
|
292
299
|
return typeof value === "function" ? value.bind(target$1) : value;
|
|
293
300
|
},
|
|
@@ -307,23 +314,23 @@ function createProtectedURLView(target) {
|
|
|
307
314
|
throwReadonlyAnnotationMutation();
|
|
308
315
|
}
|
|
309
316
|
});
|
|
310
|
-
return registerProtectedAnnotationView(target, view);
|
|
317
|
+
return registerProtectedAnnotationView(context, target, view);
|
|
311
318
|
}
|
|
312
|
-
function protectAnnotationValue(value) {
|
|
319
|
+
function protectAnnotationValue(value, context) {
|
|
313
320
|
if (value == null || typeof value !== "object") return value;
|
|
314
321
|
const target = value;
|
|
315
322
|
if (isProtectedAnnotationView(value)) return value;
|
|
316
|
-
const cached =
|
|
323
|
+
const cached = context.cache.get(target);
|
|
317
324
|
if (cached !== void 0) return cached;
|
|
318
|
-
if (target instanceof Map) return createProtectedMapView(target);
|
|
319
|
-
if (target instanceof Set) return createProtectedSetView(target);
|
|
320
|
-
if (target instanceof Date) return createProtectedDateView(target);
|
|
321
|
-
if (target instanceof RegExp) return createProtectedRegExpView(target);
|
|
322
|
-
if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target);
|
|
323
|
-
if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target);
|
|
324
|
-
if (Array.isArray(target)) return createProtectedObjectView(target);
|
|
325
|
+
if (target instanceof Map) return createProtectedMapView(target, context);
|
|
326
|
+
if (target instanceof Set) return createProtectedSetView(target, context);
|
|
327
|
+
if (target instanceof Date) return createProtectedDateView(target, context);
|
|
328
|
+
if (target instanceof RegExp) return createProtectedRegExpView(target, context);
|
|
329
|
+
if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target, context);
|
|
330
|
+
if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target, context);
|
|
331
|
+
if (Array.isArray(target)) return createProtectedObjectView(target, context);
|
|
325
332
|
const proto = Object.getPrototypeOf(target);
|
|
326
|
-
if (proto === Object.prototype || proto === null) return createProtectedObjectView(target);
|
|
333
|
+
if (proto === Object.prototype || proto === null) return createProtectedObjectView(target, context);
|
|
327
334
|
return value;
|
|
328
335
|
}
|
|
329
336
|
/**
|
|
@@ -346,7 +353,17 @@ function getAnnotations(state) {
|
|
|
346
353
|
if (state == null || typeof state !== "object") return void 0;
|
|
347
354
|
const stateObj = state;
|
|
348
355
|
const annotations = stateObj[annotationKey];
|
|
349
|
-
if (annotations != null && typeof annotations === "object")
|
|
356
|
+
if (annotations != null && typeof annotations === "object") {
|
|
357
|
+
if (isProtectedAnnotationView(annotations)) return annotations;
|
|
358
|
+
const cached = protectedAnnotationStateViews.get(stateObj);
|
|
359
|
+
if (cached?.raw === annotations) return cached.view;
|
|
360
|
+
const protectedView = protectAnnotationValue(annotations, createAnnotationProtectionContext());
|
|
361
|
+
protectedAnnotationStateViews.set(stateObj, {
|
|
362
|
+
raw: annotations,
|
|
363
|
+
view: protectedView
|
|
364
|
+
});
|
|
365
|
+
return protectedView;
|
|
366
|
+
}
|
|
350
367
|
return void 0;
|
|
351
368
|
}
|
|
352
369
|
/**
|
|
@@ -447,7 +464,7 @@ function hasMeaningfulAnnotations(annotations) {
|
|
|
447
464
|
*/
|
|
448
465
|
function injectAnnotations(state, annotations) {
|
|
449
466
|
if (!hasMeaningfulAnnotations(annotations)) return state;
|
|
450
|
-
const protectedAnnotations = protectAnnotationValue(annotations);
|
|
467
|
+
const protectedAnnotations = protectAnnotationValue(annotations, createAnnotationProtectionContext());
|
|
451
468
|
if (state == null || typeof state !== "object") {
|
|
452
469
|
const wrapper = {};
|
|
453
470
|
Object.defineProperties(wrapper, {
|