@optique/core 1.0.0-dev.1903 → 1.0.0-dev.1972
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/annotation-state.cjs +66 -31
- package/dist/annotation-state.d.cts +24 -0
- package/dist/annotation-state.d.ts +24 -0
- package/dist/annotation-state.js +65 -31
- package/dist/annotations.cjs +2 -267
- package/dist/annotations.d.cts +2 -152
- package/dist/annotations.d.ts +2 -152
- package/dist/annotations.js +2 -256
- package/dist/completion.cjs +1 -1
- package/dist/completion.d.cts +1 -1
- package/dist/completion.d.ts +1 -1
- package/dist/completion.js +1 -1
- package/dist/constructs.cjs +206 -238
- package/dist/constructs.d.cts +1 -1
- package/dist/constructs.d.ts +1 -1
- package/dist/constructs.js +96 -128
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/dependency-metadata.cjs +1 -1
- package/dist/dependency-metadata.d.cts +1 -1
- package/dist/dependency-metadata.d.ts +1 -1
- package/dist/dependency-metadata.js +1 -1
- package/dist/dependency-runtime.cjs +2 -2
- package/dist/dependency-runtime.js +2 -2
- package/dist/dependency.cjs +7 -1111
- package/dist/dependency.d.cts +2 -838
- package/dist/dependency.d.ts +2 -838
- package/dist/dependency.js +2 -1078
- package/dist/execution-context.cjs +56 -0
- package/dist/execution-context.js +53 -0
- package/dist/extension.cjs +87 -0
- package/dist/extension.d.cts +97 -0
- package/dist/extension.d.ts +97 -0
- package/dist/extension.js +76 -0
- package/dist/facade.cjs +19 -19
- package/dist/facade.d.cts +1 -1
- package/dist/facade.d.ts +1 -1
- package/dist/facade.js +19 -19
- package/dist/index.cjs +4 -41
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/internal/annotations.cjs +316 -0
- package/dist/internal/annotations.d.cts +140 -0
- package/dist/internal/annotations.d.ts +140 -0
- package/dist/internal/annotations.js +306 -0
- package/dist/internal/dependency.cjs +984 -0
- package/dist/internal/dependency.d.cts +539 -0
- package/dist/internal/dependency.d.ts +539 -0
- package/dist/internal/dependency.js +964 -0
- package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
- package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
- package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
- package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
- package/dist/internal/parser.cjs +728 -0
- package/dist/internal/parser.d.cts +947 -0
- package/dist/internal/parser.d.ts +947 -0
- package/dist/internal/parser.js +711 -0
- package/dist/modifiers.cjs +67 -95
- package/dist/modifiers.d.cts +1 -1
- package/dist/modifiers.d.ts +1 -1
- package/dist/modifiers.js +51 -79
- package/dist/parser.cjs +11 -743
- package/dist/parser.d.cts +3 -991
- package/dist/parser.d.ts +3 -991
- package/dist/parser.js +2 -704
- package/dist/phase2-seed.cjs +4 -4
- package/dist/phase2-seed.js +4 -4
- package/dist/primitives.cjs +40 -75
- package/dist/primitives.d.cts +1 -1
- package/dist/primitives.d.ts +1 -1
- package/dist/primitives.js +27 -62
- package/dist/program.d.cts +1 -1
- package/dist/program.d.ts +1 -1
- package/dist/valueparser.cjs +23 -23
- package/dist/valueparser.d.cts +3 -3
- package/dist/valueparser.d.ts +3 -3
- package/dist/valueparser.js +23 -23
- package/package.json +9 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_annotations = require('./annotations.cjs');
|
|
2
|
-
const require_parser = require('./parser.cjs');
|
|
1
|
+
const require_annotations = require('./internal/annotations.cjs');
|
|
2
|
+
const require_parser = require('./internal/parser.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/annotation-state.ts
|
|
5
5
|
/**
|
|
@@ -11,6 +11,7 @@ const require_parser = require('./parser.cjs');
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
const annotationViewTargets = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
const delegatedAnnotationCloneTargets = /* @__PURE__ */ new WeakMap();
|
|
14
15
|
/**
|
|
15
16
|
* Unwraps an annotation-view proxy to its original target object.
|
|
16
17
|
*
|
|
@@ -23,14 +24,18 @@ function unwrapAnnotationView(value) {
|
|
|
23
24
|
if (value == null || typeof value !== "object") return value;
|
|
24
25
|
return annotationViewTargets.get(value) ?? value;
|
|
25
26
|
}
|
|
27
|
+
function unwrapDelegatedAnnotationClone(value) {
|
|
28
|
+
if (value == null || typeof value !== "object") return value;
|
|
29
|
+
return delegatedAnnotationCloneTargets.get(value) ?? value;
|
|
30
|
+
}
|
|
26
31
|
/**
|
|
27
|
-
* Creates
|
|
32
|
+
* Creates an annotation-aware proxy without changing the target shape.
|
|
28
33
|
*
|
|
29
34
|
* @param state The object state to expose through an annotation-aware view.
|
|
30
35
|
* @param annotations The annotations to surface through the proxy.
|
|
31
36
|
* @returns A proxy over the unwrapped target object that reports the supplied
|
|
32
37
|
* annotations while preserving the target's structural behavior.
|
|
33
|
-
* @
|
|
38
|
+
* @since 1.0.0
|
|
34
39
|
*/
|
|
35
40
|
function withAnnotationView(state, annotations) {
|
|
36
41
|
const target = unwrapAnnotationView(state);
|
|
@@ -59,48 +64,74 @@ function normalizeInjectedAnnotationState(state) {
|
|
|
59
64
|
return require_annotations.unwrapInjectedAnnotationWrapper(state);
|
|
60
65
|
}
|
|
61
66
|
function isNonPlainDelegatedObject(state) {
|
|
62
|
-
if (Array.isArray(state) || state instanceof Date || state instanceof Map || state instanceof Set || state instanceof RegExp) return false;
|
|
63
67
|
const proto = Object.getPrototypeOf(state);
|
|
68
|
+
if (proto === Array.prototype || proto === Date.prototype || proto === Map.prototype || proto === Set.prototype || proto === RegExp.prototype) return false;
|
|
64
69
|
return proto !== Object.prototype && proto !== null;
|
|
65
70
|
}
|
|
71
|
+
function inheritDelegatedAnnotations(parentState, childState) {
|
|
72
|
+
const target = normalizeDelegatedAnnotationState(childState);
|
|
73
|
+
const delegatedState = require_annotations.inheritAnnotations(parentState, target);
|
|
74
|
+
if (delegatedState !== target) delegatedAnnotationCloneTargets.set(delegatedState, target);
|
|
75
|
+
return delegatedState;
|
|
76
|
+
}
|
|
66
77
|
/**
|
|
67
78
|
* Removes Optique's internal annotation carriers from a delegated state.
|
|
68
79
|
*
|
|
69
|
-
* This unwraps
|
|
70
|
-
* proxies used for
|
|
80
|
+
* This unwraps primitive-state annotation wrappers, tracked delegated clones,
|
|
81
|
+
* and annotation-view proxies used for object states.
|
|
71
82
|
*
|
|
72
83
|
* @param state The delegated state to normalize.
|
|
73
84
|
* @returns The original underlying state value.
|
|
74
85
|
* @internal
|
|
75
86
|
*/
|
|
76
87
|
function normalizeDelegatedAnnotationState(state) {
|
|
77
|
-
return normalizeInjectedAnnotationState(unwrapAnnotationView(state));
|
|
88
|
+
return normalizeInjectedAnnotationState(unwrapDelegatedAnnotationClone(unwrapAnnotationView(state)));
|
|
78
89
|
}
|
|
79
90
|
/**
|
|
80
91
|
* Returns whether the given state uses an internal delegated annotation carrier.
|
|
81
92
|
*
|
|
82
93
|
* @param state The candidate state to inspect.
|
|
83
|
-
* @returns `true` when the state is an injected primitive wrapper
|
|
84
|
-
* annotation-view proxy.
|
|
94
|
+
* @returns `true` when the state is an injected primitive wrapper, a tracked
|
|
95
|
+
* delegated clone, or an annotation-view proxy.
|
|
85
96
|
* @internal
|
|
86
97
|
*/
|
|
87
98
|
function hasDelegatedAnnotationCarrier(state) {
|
|
88
|
-
return state != null && typeof state === "object" && (require_annotations.isInjectedAnnotationWrapper(state) || annotationViewTargets.has(state));
|
|
99
|
+
return state != null && typeof state === "object" && (require_annotations.isInjectedAnnotationWrapper(state) || delegatedAnnotationCloneTargets.has(state) || annotationViewTargets.has(state));
|
|
100
|
+
}
|
|
101
|
+
function getOrCreateNestedNormalizationClone(entry) {
|
|
102
|
+
entry.clone ??= entry.createClone();
|
|
103
|
+
return entry.clone;
|
|
89
104
|
}
|
|
90
105
|
function getPendingNestedNormalizationEntry(originalValue, normalizedValue, seen) {
|
|
91
106
|
if (originalValue == null || typeof originalValue !== "object") return void 0;
|
|
92
107
|
const entry = seen.get(originalValue);
|
|
93
|
-
return entry != null && entry.clone === normalizedValue && (!entry.finalized || entry.preferCloneOnRead) ? entry : void 0;
|
|
108
|
+
return entry != null && entry.clone != null && entry.clone === normalizedValue && (!entry.finalized || entry.preferCloneOnRead) ? entry : void 0;
|
|
94
109
|
}
|
|
95
110
|
function createPendingNestedNormalizationClone(source) {
|
|
96
|
-
|
|
111
|
+
if (!Array.isArray(source)) return Object.create(Object.getPrototypeOf(source));
|
|
112
|
+
if (Object.getPrototypeOf(source) === Array.prototype) return [];
|
|
113
|
+
try {
|
|
114
|
+
return source.slice(0, 0);
|
|
115
|
+
} catch {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function createPendingNestedNormalizationCollectionClone(source) {
|
|
120
|
+
const proto = Object.getPrototypeOf(source);
|
|
121
|
+
if (source instanceof Map && proto === Map.prototype) return /* @__PURE__ */ new Map();
|
|
122
|
+
if (source instanceof Set && proto === Set.prototype) return /* @__PURE__ */ new Set();
|
|
123
|
+
const Constructor = source.constructor;
|
|
124
|
+
if (typeof Constructor === "function") try {
|
|
125
|
+
return new Constructor();
|
|
126
|
+
} catch {}
|
|
127
|
+
return source instanceof Map ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
97
128
|
}
|
|
98
129
|
function normalizeNestedDelegatedStructuredState(source, seen, preferPendingClone) {
|
|
99
|
-
const clone = createPendingNestedNormalizationClone(source);
|
|
100
130
|
const entry = {
|
|
101
|
-
clone,
|
|
131
|
+
clone: void 0,
|
|
132
|
+
createClone: () => createPendingNestedNormalizationClone(source),
|
|
102
133
|
finalized: false,
|
|
103
|
-
result:
|
|
134
|
+
result: source,
|
|
104
135
|
preferCloneOnRead: false
|
|
105
136
|
};
|
|
106
137
|
seen.set(source, entry);
|
|
@@ -130,6 +161,7 @@ function normalizeNestedDelegatedStructuredState(source, seen, preferPendingClon
|
|
|
130
161
|
value: nextValue
|
|
131
162
|
};
|
|
132
163
|
}
|
|
164
|
+
const clone = getOrCreateNestedNormalizationClone(entry);
|
|
133
165
|
Object.defineProperties(clone, descriptors);
|
|
134
166
|
entry.finalized = true;
|
|
135
167
|
entry.preferCloneOnRead = !changed && hasPendingAliasOverride;
|
|
@@ -137,11 +169,11 @@ function normalizeNestedDelegatedStructuredState(source, seen, preferPendingClon
|
|
|
137
169
|
return changed || preferPendingClone ? clone : source;
|
|
138
170
|
}
|
|
139
171
|
function normalizeNestedDelegatedMapState(source, seen, preferPendingClone) {
|
|
140
|
-
const clone = /* @__PURE__ */ new Map();
|
|
141
172
|
const entry = {
|
|
142
|
-
clone,
|
|
173
|
+
clone: void 0,
|
|
174
|
+
createClone: () => createPendingNestedNormalizationCollectionClone(source),
|
|
143
175
|
finalized: false,
|
|
144
|
-
result:
|
|
176
|
+
result: source,
|
|
145
177
|
preferCloneOnRead: false
|
|
146
178
|
};
|
|
147
179
|
seen.set(source, entry);
|
|
@@ -172,6 +204,7 @@ function normalizeNestedDelegatedMapState(source, seen, preferPendingClone) {
|
|
|
172
204
|
entry.result = source;
|
|
173
205
|
return source;
|
|
174
206
|
}
|
|
207
|
+
const clone = getOrCreateNestedNormalizationClone(entry);
|
|
175
208
|
for (const [key, value] of normalizedEntries) clone.set(key, value);
|
|
176
209
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
177
210
|
for (const [key, nextValue] of overrides) {
|
|
@@ -189,11 +222,11 @@ function normalizeNestedDelegatedMapState(source, seen, preferPendingClone) {
|
|
|
189
222
|
return changed || preferPendingClone ? clone : source;
|
|
190
223
|
}
|
|
191
224
|
function normalizeNestedDelegatedSetState(source, seen, preferPendingClone) {
|
|
192
|
-
const clone = /* @__PURE__ */ new Set();
|
|
193
225
|
const entry = {
|
|
194
|
-
clone,
|
|
226
|
+
clone: void 0,
|
|
227
|
+
createClone: () => createPendingNestedNormalizationCollectionClone(source),
|
|
195
228
|
finalized: false,
|
|
196
|
-
result:
|
|
229
|
+
result: source,
|
|
197
230
|
preferCloneOnRead: false
|
|
198
231
|
};
|
|
199
232
|
seen.set(source, entry);
|
|
@@ -222,6 +255,7 @@ function normalizeNestedDelegatedSetState(source, seen, preferPendingClone) {
|
|
|
222
255
|
entry.result = source;
|
|
223
256
|
return source;
|
|
224
257
|
}
|
|
258
|
+
const clone = getOrCreateNestedNormalizationClone(entry);
|
|
225
259
|
for (const value of normalizedValues) clone.add(value);
|
|
226
260
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
227
261
|
for (const [key, nextValue] of overrides) {
|
|
@@ -260,8 +294,8 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
260
294
|
const source = normalized;
|
|
261
295
|
const existing = seen.get(source);
|
|
262
296
|
if (existing != null) {
|
|
263
|
-
if (!existing.finalized) return existing
|
|
264
|
-
return preferPendingClone && existing.preferCloneOnRead ? existing
|
|
297
|
+
if (!existing.finalized) return getOrCreateNestedNormalizationClone(existing);
|
|
298
|
+
return preferPendingClone && existing.preferCloneOnRead ? getOrCreateNestedNormalizationClone(existing) : existing.result;
|
|
265
299
|
}
|
|
266
300
|
if (Array.isArray(source)) return normalizeNestedDelegatedStructuredState(source, seen, preferPendingClone);
|
|
267
301
|
if (source instanceof Map) return normalizeNestedDelegatedMapState(source, seen, preferPendingClone);
|
|
@@ -274,10 +308,10 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
274
308
|
* Creates a short-lived delegated state that exposes the parent's annotations
|
|
275
309
|
* regardless of the child state's runtime shape.
|
|
276
310
|
*
|
|
277
|
-
* Primitive and nullish states use `injectAnnotations()`,
|
|
278
|
-
*
|
|
279
|
-
* annotation-view proxy so class invariants such as private
|
|
280
|
-
* intact.
|
|
311
|
+
* Primitive and nullish states use `injectAnnotations()`, clone-based object
|
|
312
|
+
* delegation is tracked so it can be normalized back out later, and non-plain
|
|
313
|
+
* objects use an annotation-view proxy so class invariants such as private
|
|
314
|
+
* fields remain intact.
|
|
281
315
|
*
|
|
282
316
|
* @param parentState The state carrying the annotations to delegate.
|
|
283
317
|
* @param childState The child state that should observe those annotations.
|
|
@@ -288,10 +322,10 @@ function getDelegatedAnnotationState(parentState, childState) {
|
|
|
288
322
|
const annotations = require_annotations.getAnnotations(parentState);
|
|
289
323
|
if (annotations === void 0) return childState;
|
|
290
324
|
if (require_annotations.isInjectedAnnotationWrapper(childState)) return require_annotations.injectAnnotations(normalizeInjectedAnnotationState(childState), annotations);
|
|
291
|
-
if (require_annotations.getAnnotations(childState) === annotations) return childState;
|
|
292
325
|
if (childState == null || typeof childState !== "object") return require_annotations.injectAnnotations(childState, annotations);
|
|
326
|
+
if (require_annotations.getAnnotations(childState) === annotations && (delegatedAnnotationCloneTargets.has(childState) || annotationViewTargets.has(childState))) return childState;
|
|
293
327
|
if (isNonPlainDelegatedObject(childState)) return withAnnotationView(childState, annotations);
|
|
294
|
-
return
|
|
328
|
+
return inheritDelegatedAnnotations(parentState, childState);
|
|
295
329
|
}
|
|
296
330
|
/**
|
|
297
331
|
* Returns whether a state is still at the initial sentinel after normalizing
|
|
@@ -387,4 +421,5 @@ exports.normalizeDelegatedAnnotationState = normalizeDelegatedAnnotationState;
|
|
|
387
421
|
exports.normalizeInjectedAnnotationState = normalizeInjectedAnnotationState;
|
|
388
422
|
exports.normalizeNestedDelegatedAnnotationState = normalizeNestedDelegatedAnnotationState;
|
|
389
423
|
exports.reconcileObjectChildState = reconcileObjectChildState;
|
|
390
|
-
exports.unwrapAnnotationView = unwrapAnnotationView;
|
|
424
|
+
exports.unwrapAnnotationView = unwrapAnnotationView;
|
|
425
|
+
exports.withAnnotationView = withAnnotationView;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Annotations } from "./internal/annotations.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/annotation-state.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates an annotation-aware proxy without changing the target shape.
|
|
7
|
+
*
|
|
8
|
+
* @param state The object state to expose through an annotation-aware view.
|
|
9
|
+
* @param annotations The annotations to surface through the proxy.
|
|
10
|
+
* @returns A proxy over the unwrapped target object that reports the supplied
|
|
11
|
+
* annotations while preserving the target's structural behavior.
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
declare function withAnnotationView<T extends object>(state: T, annotations: Annotations): T;
|
|
15
|
+
/**
|
|
16
|
+
* Removes Optique's internal primitive-state annotation wrapper when present.
|
|
17
|
+
*
|
|
18
|
+
* @param state The parser state to normalize.
|
|
19
|
+
* @returns The wrapped primitive sentinel when the input is an injected
|
|
20
|
+
* annotation wrapper; otherwise the original input unchanged.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
//#endregion
|
|
24
|
+
export { withAnnotationView };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Annotations } from "./internal/annotations.js";
|
|
2
|
+
|
|
3
|
+
//#region src/annotation-state.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates an annotation-aware proxy without changing the target shape.
|
|
7
|
+
*
|
|
8
|
+
* @param state The object state to expose through an annotation-aware view.
|
|
9
|
+
* @param annotations The annotations to surface through the proxy.
|
|
10
|
+
* @returns A proxy over the unwrapped target object that reports the supplied
|
|
11
|
+
* annotations while preserving the target's structural behavior.
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
declare function withAnnotationView<T extends object>(state: T, annotations: Annotations): T;
|
|
15
|
+
/**
|
|
16
|
+
* Removes Optique's internal primitive-state annotation wrapper when present.
|
|
17
|
+
*
|
|
18
|
+
* @param state The parser state to normalize.
|
|
19
|
+
* @returns The wrapped primitive sentinel when the input is an injected
|
|
20
|
+
* annotation wrapper; otherwise the original input unchanged.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
//#endregion
|
|
24
|
+
export { withAnnotationView };
|
package/dist/annotation-state.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
2
|
-
import { inheritParentAnnotationsKey } from "./parser.js";
|
|
1
|
+
import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
|
+
import { inheritParentAnnotationsKey } from "./internal/parser.js";
|
|
3
3
|
|
|
4
4
|
//#region src/annotation-state.ts
|
|
5
5
|
/**
|
|
@@ -11,6 +11,7 @@ import { inheritParentAnnotationsKey } from "./parser.js";
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
const annotationViewTargets = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
const delegatedAnnotationCloneTargets = /* @__PURE__ */ new WeakMap();
|
|
14
15
|
/**
|
|
15
16
|
* Unwraps an annotation-view proxy to its original target object.
|
|
16
17
|
*
|
|
@@ -23,14 +24,18 @@ function unwrapAnnotationView(value) {
|
|
|
23
24
|
if (value == null || typeof value !== "object") return value;
|
|
24
25
|
return annotationViewTargets.get(value) ?? value;
|
|
25
26
|
}
|
|
27
|
+
function unwrapDelegatedAnnotationClone(value) {
|
|
28
|
+
if (value == null || typeof value !== "object") return value;
|
|
29
|
+
return delegatedAnnotationCloneTargets.get(value) ?? value;
|
|
30
|
+
}
|
|
26
31
|
/**
|
|
27
|
-
* Creates
|
|
32
|
+
* Creates an annotation-aware proxy without changing the target shape.
|
|
28
33
|
*
|
|
29
34
|
* @param state The object state to expose through an annotation-aware view.
|
|
30
35
|
* @param annotations The annotations to surface through the proxy.
|
|
31
36
|
* @returns A proxy over the unwrapped target object that reports the supplied
|
|
32
37
|
* annotations while preserving the target's structural behavior.
|
|
33
|
-
* @
|
|
38
|
+
* @since 1.0.0
|
|
34
39
|
*/
|
|
35
40
|
function withAnnotationView(state, annotations) {
|
|
36
41
|
const target = unwrapAnnotationView(state);
|
|
@@ -59,48 +64,74 @@ function normalizeInjectedAnnotationState(state) {
|
|
|
59
64
|
return unwrapInjectedAnnotationWrapper(state);
|
|
60
65
|
}
|
|
61
66
|
function isNonPlainDelegatedObject(state) {
|
|
62
|
-
if (Array.isArray(state) || state instanceof Date || state instanceof Map || state instanceof Set || state instanceof RegExp) return false;
|
|
63
67
|
const proto = Object.getPrototypeOf(state);
|
|
68
|
+
if (proto === Array.prototype || proto === Date.prototype || proto === Map.prototype || proto === Set.prototype || proto === RegExp.prototype) return false;
|
|
64
69
|
return proto !== Object.prototype && proto !== null;
|
|
65
70
|
}
|
|
71
|
+
function inheritDelegatedAnnotations(parentState, childState) {
|
|
72
|
+
const target = normalizeDelegatedAnnotationState(childState);
|
|
73
|
+
const delegatedState = inheritAnnotations(parentState, target);
|
|
74
|
+
if (delegatedState !== target) delegatedAnnotationCloneTargets.set(delegatedState, target);
|
|
75
|
+
return delegatedState;
|
|
76
|
+
}
|
|
66
77
|
/**
|
|
67
78
|
* Removes Optique's internal annotation carriers from a delegated state.
|
|
68
79
|
*
|
|
69
|
-
* This unwraps
|
|
70
|
-
* proxies used for
|
|
80
|
+
* This unwraps primitive-state annotation wrappers, tracked delegated clones,
|
|
81
|
+
* and annotation-view proxies used for object states.
|
|
71
82
|
*
|
|
72
83
|
* @param state The delegated state to normalize.
|
|
73
84
|
* @returns The original underlying state value.
|
|
74
85
|
* @internal
|
|
75
86
|
*/
|
|
76
87
|
function normalizeDelegatedAnnotationState(state) {
|
|
77
|
-
return normalizeInjectedAnnotationState(unwrapAnnotationView(state));
|
|
88
|
+
return normalizeInjectedAnnotationState(unwrapDelegatedAnnotationClone(unwrapAnnotationView(state)));
|
|
78
89
|
}
|
|
79
90
|
/**
|
|
80
91
|
* Returns whether the given state uses an internal delegated annotation carrier.
|
|
81
92
|
*
|
|
82
93
|
* @param state The candidate state to inspect.
|
|
83
|
-
* @returns `true` when the state is an injected primitive wrapper
|
|
84
|
-
* annotation-view proxy.
|
|
94
|
+
* @returns `true` when the state is an injected primitive wrapper, a tracked
|
|
95
|
+
* delegated clone, or an annotation-view proxy.
|
|
85
96
|
* @internal
|
|
86
97
|
*/
|
|
87
98
|
function hasDelegatedAnnotationCarrier(state) {
|
|
88
|
-
return state != null && typeof state === "object" && (isInjectedAnnotationWrapper(state) || annotationViewTargets.has(state));
|
|
99
|
+
return state != null && typeof state === "object" && (isInjectedAnnotationWrapper(state) || delegatedAnnotationCloneTargets.has(state) || annotationViewTargets.has(state));
|
|
100
|
+
}
|
|
101
|
+
function getOrCreateNestedNormalizationClone(entry) {
|
|
102
|
+
entry.clone ??= entry.createClone();
|
|
103
|
+
return entry.clone;
|
|
89
104
|
}
|
|
90
105
|
function getPendingNestedNormalizationEntry(originalValue, normalizedValue, seen) {
|
|
91
106
|
if (originalValue == null || typeof originalValue !== "object") return void 0;
|
|
92
107
|
const entry = seen.get(originalValue);
|
|
93
|
-
return entry != null && entry.clone === normalizedValue && (!entry.finalized || entry.preferCloneOnRead) ? entry : void 0;
|
|
108
|
+
return entry != null && entry.clone != null && entry.clone === normalizedValue && (!entry.finalized || entry.preferCloneOnRead) ? entry : void 0;
|
|
94
109
|
}
|
|
95
110
|
function createPendingNestedNormalizationClone(source) {
|
|
96
|
-
|
|
111
|
+
if (!Array.isArray(source)) return Object.create(Object.getPrototypeOf(source));
|
|
112
|
+
if (Object.getPrototypeOf(source) === Array.prototype) return [];
|
|
113
|
+
try {
|
|
114
|
+
return source.slice(0, 0);
|
|
115
|
+
} catch {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function createPendingNestedNormalizationCollectionClone(source) {
|
|
120
|
+
const proto = Object.getPrototypeOf(source);
|
|
121
|
+
if (source instanceof Map && proto === Map.prototype) return /* @__PURE__ */ new Map();
|
|
122
|
+
if (source instanceof Set && proto === Set.prototype) return /* @__PURE__ */ new Set();
|
|
123
|
+
const Constructor = source.constructor;
|
|
124
|
+
if (typeof Constructor === "function") try {
|
|
125
|
+
return new Constructor();
|
|
126
|
+
} catch {}
|
|
127
|
+
return source instanceof Map ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
97
128
|
}
|
|
98
129
|
function normalizeNestedDelegatedStructuredState(source, seen, preferPendingClone) {
|
|
99
|
-
const clone = createPendingNestedNormalizationClone(source);
|
|
100
130
|
const entry = {
|
|
101
|
-
clone,
|
|
131
|
+
clone: void 0,
|
|
132
|
+
createClone: () => createPendingNestedNormalizationClone(source),
|
|
102
133
|
finalized: false,
|
|
103
|
-
result:
|
|
134
|
+
result: source,
|
|
104
135
|
preferCloneOnRead: false
|
|
105
136
|
};
|
|
106
137
|
seen.set(source, entry);
|
|
@@ -130,6 +161,7 @@ function normalizeNestedDelegatedStructuredState(source, seen, preferPendingClon
|
|
|
130
161
|
value: nextValue
|
|
131
162
|
};
|
|
132
163
|
}
|
|
164
|
+
const clone = getOrCreateNestedNormalizationClone(entry);
|
|
133
165
|
Object.defineProperties(clone, descriptors);
|
|
134
166
|
entry.finalized = true;
|
|
135
167
|
entry.preferCloneOnRead = !changed && hasPendingAliasOverride;
|
|
@@ -137,11 +169,11 @@ function normalizeNestedDelegatedStructuredState(source, seen, preferPendingClon
|
|
|
137
169
|
return changed || preferPendingClone ? clone : source;
|
|
138
170
|
}
|
|
139
171
|
function normalizeNestedDelegatedMapState(source, seen, preferPendingClone) {
|
|
140
|
-
const clone = /* @__PURE__ */ new Map();
|
|
141
172
|
const entry = {
|
|
142
|
-
clone,
|
|
173
|
+
clone: void 0,
|
|
174
|
+
createClone: () => createPendingNestedNormalizationCollectionClone(source),
|
|
143
175
|
finalized: false,
|
|
144
|
-
result:
|
|
176
|
+
result: source,
|
|
145
177
|
preferCloneOnRead: false
|
|
146
178
|
};
|
|
147
179
|
seen.set(source, entry);
|
|
@@ -172,6 +204,7 @@ function normalizeNestedDelegatedMapState(source, seen, preferPendingClone) {
|
|
|
172
204
|
entry.result = source;
|
|
173
205
|
return source;
|
|
174
206
|
}
|
|
207
|
+
const clone = getOrCreateNestedNormalizationClone(entry);
|
|
175
208
|
for (const [key, value] of normalizedEntries) clone.set(key, value);
|
|
176
209
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
177
210
|
for (const [key, nextValue] of overrides) {
|
|
@@ -189,11 +222,11 @@ function normalizeNestedDelegatedMapState(source, seen, preferPendingClone) {
|
|
|
189
222
|
return changed || preferPendingClone ? clone : source;
|
|
190
223
|
}
|
|
191
224
|
function normalizeNestedDelegatedSetState(source, seen, preferPendingClone) {
|
|
192
|
-
const clone = /* @__PURE__ */ new Set();
|
|
193
225
|
const entry = {
|
|
194
|
-
clone,
|
|
226
|
+
clone: void 0,
|
|
227
|
+
createClone: () => createPendingNestedNormalizationCollectionClone(source),
|
|
195
228
|
finalized: false,
|
|
196
|
-
result:
|
|
229
|
+
result: source,
|
|
197
230
|
preferCloneOnRead: false
|
|
198
231
|
};
|
|
199
232
|
seen.set(source, entry);
|
|
@@ -222,6 +255,7 @@ function normalizeNestedDelegatedSetState(source, seen, preferPendingClone) {
|
|
|
222
255
|
entry.result = source;
|
|
223
256
|
return source;
|
|
224
257
|
}
|
|
258
|
+
const clone = getOrCreateNestedNormalizationClone(entry);
|
|
225
259
|
for (const value of normalizedValues) clone.add(value);
|
|
226
260
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
227
261
|
for (const [key, nextValue] of overrides) {
|
|
@@ -260,8 +294,8 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
260
294
|
const source = normalized;
|
|
261
295
|
const existing = seen.get(source);
|
|
262
296
|
if (existing != null) {
|
|
263
|
-
if (!existing.finalized) return existing
|
|
264
|
-
return preferPendingClone && existing.preferCloneOnRead ? existing
|
|
297
|
+
if (!existing.finalized) return getOrCreateNestedNormalizationClone(existing);
|
|
298
|
+
return preferPendingClone && existing.preferCloneOnRead ? getOrCreateNestedNormalizationClone(existing) : existing.result;
|
|
265
299
|
}
|
|
266
300
|
if (Array.isArray(source)) return normalizeNestedDelegatedStructuredState(source, seen, preferPendingClone);
|
|
267
301
|
if (source instanceof Map) return normalizeNestedDelegatedMapState(source, seen, preferPendingClone);
|
|
@@ -274,10 +308,10 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
274
308
|
* Creates a short-lived delegated state that exposes the parent's annotations
|
|
275
309
|
* regardless of the child state's runtime shape.
|
|
276
310
|
*
|
|
277
|
-
* Primitive and nullish states use `injectAnnotations()`,
|
|
278
|
-
*
|
|
279
|
-
* annotation-view proxy so class invariants such as private
|
|
280
|
-
* intact.
|
|
311
|
+
* Primitive and nullish states use `injectAnnotations()`, clone-based object
|
|
312
|
+
* delegation is tracked so it can be normalized back out later, and non-plain
|
|
313
|
+
* objects use an annotation-view proxy so class invariants such as private
|
|
314
|
+
* fields remain intact.
|
|
281
315
|
*
|
|
282
316
|
* @param parentState The state carrying the annotations to delegate.
|
|
283
317
|
* @param childState The child state that should observe those annotations.
|
|
@@ -288,10 +322,10 @@ function getDelegatedAnnotationState(parentState, childState) {
|
|
|
288
322
|
const annotations = getAnnotations(parentState);
|
|
289
323
|
if (annotations === void 0) return childState;
|
|
290
324
|
if (isInjectedAnnotationWrapper(childState)) return injectAnnotations(normalizeInjectedAnnotationState(childState), annotations);
|
|
291
|
-
if (getAnnotations(childState) === annotations) return childState;
|
|
292
325
|
if (childState == null || typeof childState !== "object") return injectAnnotations(childState, annotations);
|
|
326
|
+
if (getAnnotations(childState) === annotations && (delegatedAnnotationCloneTargets.has(childState) || annotationViewTargets.has(childState))) return childState;
|
|
293
327
|
if (isNonPlainDelegatedObject(childState)) return withAnnotationView(childState, annotations);
|
|
294
|
-
return
|
|
328
|
+
return inheritDelegatedAnnotations(parentState, childState);
|
|
295
329
|
}
|
|
296
330
|
/**
|
|
297
331
|
* Returns whether a state is still at the initial sentinel after normalizing
|
|
@@ -377,4 +411,4 @@ function reconcileObjectChildState(parentState, childState) {
|
|
|
377
411
|
}
|
|
378
412
|
|
|
379
413
|
//#endregion
|
|
380
|
-
export { annotationViewTargets, getDelegatedAnnotationState, getWrappedChildParseState, getWrappedChildState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeInjectedAnnotationState, normalizeNestedDelegatedAnnotationState, reconcileObjectChildState, unwrapAnnotationView };
|
|
414
|
+
export { annotationViewTargets, getDelegatedAnnotationState, getWrappedChildParseState, getWrappedChildState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeInjectedAnnotationState, normalizeNestedDelegatedAnnotationState, reconcileObjectChildState, unwrapAnnotationView, withAnnotationView };
|