@optique/core 1.0.0-dev.1841 → 1.0.0-dev.1842

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.
@@ -45,12 +45,274 @@ const annotationWrapperKeys = new Set([
45
45
  annotationWrapperKey
46
46
  ]);
47
47
  const injectedAnnotationWrappers = /* @__PURE__ */ new WeakSet();
48
+ const protectedAnnotationTargets = /* @__PURE__ */ new WeakMap();
49
+ const annotationProtectionCache = /* @__PURE__ */ new WeakMap();
50
+ function throwReadonlyAnnotationMutation() {
51
+ throw new TypeError("Cannot mutate read-only annotation data.");
52
+ }
53
+ function registerProtectedAnnotationView(target, view) {
54
+ annotationProtectionCache.set(target, view);
55
+ protectedAnnotationTargets.set(view, target);
56
+ return view;
57
+ }
58
+ function isProtectedAnnotationView(value) {
59
+ return value != null && typeof value === "object" && protectedAnnotationTargets.has(value);
60
+ }
61
+ function unwrapProtectedAnnotationTarget(value) {
62
+ if (value == null || typeof value !== "object") return value;
63
+ return protectedAnnotationTargets.get(value) ?? value;
64
+ }
65
+ function cacheProtectedMethod(cache, key, factory) {
66
+ const cached = cache.get(key);
67
+ if (cached !== void 0) return cached;
68
+ const created = factory();
69
+ cache.set(key, created);
70
+ return created;
71
+ }
72
+ function protectDescriptor(descriptor) {
73
+ if (descriptor == null || !("value" in descriptor)) return descriptor;
74
+ return {
75
+ ...descriptor,
76
+ value: protectAnnotationValue(descriptor.value)
77
+ };
78
+ }
79
+ function createProtectedObjectView(target) {
80
+ const view = new Proxy(target, {
81
+ get(target$1, key, receiver) {
82
+ return protectAnnotationValue(Reflect.get(target$1, key, receiver));
83
+ },
84
+ set() {
85
+ throwReadonlyAnnotationMutation();
86
+ },
87
+ defineProperty() {
88
+ throwReadonlyAnnotationMutation();
89
+ },
90
+ deleteProperty() {
91
+ throwReadonlyAnnotationMutation();
92
+ },
93
+ setPrototypeOf() {
94
+ throwReadonlyAnnotationMutation();
95
+ },
96
+ preventExtensions() {
97
+ throwReadonlyAnnotationMutation();
98
+ },
99
+ getOwnPropertyDescriptor(target$1, key) {
100
+ return protectDescriptor(Reflect.getOwnPropertyDescriptor(target$1, key));
101
+ }
102
+ });
103
+ return registerProtectedAnnotationView(target, view);
104
+ }
105
+ function createProtectedMapView(target) {
106
+ const methodCache = /* @__PURE__ */ new Map();
107
+ const view = new Proxy(target, {
108
+ get(target$1, key) {
109
+ if (key === "size") return target$1.size;
110
+ if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
111
+ if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup))));
112
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
113
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, mapKey) => {
114
+ callback.call(thisArg, protectAnnotationValue(value$1), protectAnnotationValue(mapKey), view);
115
+ }));
116
+ if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
117
+ for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1);
118
+ });
119
+ if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
120
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
121
+ });
122
+ if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
123
+ for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey), protectAnnotationValue(entryValue)];
124
+ });
125
+ const value = Reflect.get(target$1, key, target$1);
126
+ return typeof value === "function" ? value.bind(target$1) : value;
127
+ },
128
+ set() {
129
+ throwReadonlyAnnotationMutation();
130
+ },
131
+ defineProperty() {
132
+ throwReadonlyAnnotationMutation();
133
+ },
134
+ deleteProperty() {
135
+ throwReadonlyAnnotationMutation();
136
+ },
137
+ setPrototypeOf() {
138
+ throwReadonlyAnnotationMutation();
139
+ },
140
+ preventExtensions() {
141
+ throwReadonlyAnnotationMutation();
142
+ }
143
+ });
144
+ return registerProtectedAnnotationView(target, view);
145
+ }
146
+ function createProtectedSetView(target) {
147
+ const methodCache = /* @__PURE__ */ new Map();
148
+ const view = new Proxy(target, {
149
+ get(target$1, key) {
150
+ if (key === "size") return target$1.size;
151
+ if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
152
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
153
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1) => {
154
+ const protectedValue = protectAnnotationValue(value$1);
155
+ callback.call(thisArg, protectedValue, protectedValue, view);
156
+ }));
157
+ if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
158
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
159
+ });
160
+ if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
161
+ for (const value$1 of target$1.values()) {
162
+ const protectedValue = protectAnnotationValue(value$1);
163
+ yield [protectedValue, protectedValue];
164
+ }
165
+ });
166
+ const value = Reflect.get(target$1, key, target$1);
167
+ return typeof value === "function" ? value.bind(target$1) : value;
168
+ },
169
+ set() {
170
+ throwReadonlyAnnotationMutation();
171
+ },
172
+ defineProperty() {
173
+ throwReadonlyAnnotationMutation();
174
+ },
175
+ deleteProperty() {
176
+ throwReadonlyAnnotationMutation();
177
+ },
178
+ setPrototypeOf() {
179
+ throwReadonlyAnnotationMutation();
180
+ },
181
+ preventExtensions() {
182
+ throwReadonlyAnnotationMutation();
183
+ }
184
+ });
185
+ return registerProtectedAnnotationView(target, view);
186
+ }
187
+ function createProtectedDateView(target) {
188
+ const methodCache = /* @__PURE__ */ new Map();
189
+ const view = new Proxy(target, {
190
+ get(target$1, key) {
191
+ const value = Reflect.get(target$1, key, target$1);
192
+ if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
193
+ return typeof value === "function" ? value.bind(target$1) : value;
194
+ },
195
+ set() {
196
+ throwReadonlyAnnotationMutation();
197
+ },
198
+ defineProperty() {
199
+ throwReadonlyAnnotationMutation();
200
+ },
201
+ deleteProperty() {
202
+ throwReadonlyAnnotationMutation();
203
+ },
204
+ setPrototypeOf() {
205
+ throwReadonlyAnnotationMutation();
206
+ },
207
+ preventExtensions() {
208
+ throwReadonlyAnnotationMutation();
209
+ }
210
+ });
211
+ return registerProtectedAnnotationView(target, view);
212
+ }
213
+ function createProtectedRegExpView(target) {
214
+ const methodCache = /* @__PURE__ */ new Map();
215
+ const view = new Proxy(target, {
216
+ get(target$1, key) {
217
+ const value = Reflect.get(target$1, key, target$1);
218
+ if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
219
+ return typeof value === "function" ? value.bind(target$1) : value;
220
+ },
221
+ set() {
222
+ throwReadonlyAnnotationMutation();
223
+ },
224
+ defineProperty() {
225
+ throwReadonlyAnnotationMutation();
226
+ },
227
+ deleteProperty() {
228
+ throwReadonlyAnnotationMutation();
229
+ },
230
+ setPrototypeOf() {
231
+ throwReadonlyAnnotationMutation();
232
+ },
233
+ preventExtensions() {
234
+ throwReadonlyAnnotationMutation();
235
+ }
236
+ });
237
+ return registerProtectedAnnotationView(target, view);
238
+ }
239
+ function createProtectedURLSearchParamsView(target) {
240
+ const methodCache = /* @__PURE__ */ new Map();
241
+ const view = new Proxy(target, {
242
+ get(target$1, key) {
243
+ if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
244
+ const value = Reflect.get(target$1, key, target$1);
245
+ return typeof value === "function" ? value.bind(target$1) : value;
246
+ },
247
+ set() {
248
+ throwReadonlyAnnotationMutation();
249
+ },
250
+ defineProperty() {
251
+ throwReadonlyAnnotationMutation();
252
+ },
253
+ deleteProperty() {
254
+ throwReadonlyAnnotationMutation();
255
+ },
256
+ setPrototypeOf() {
257
+ throwReadonlyAnnotationMutation();
258
+ },
259
+ preventExtensions() {
260
+ throwReadonlyAnnotationMutation();
261
+ }
262
+ });
263
+ return registerProtectedAnnotationView(target, view);
264
+ }
265
+ function createProtectedURLView(target) {
266
+ const view = new Proxy(target, {
267
+ get(target$1, key) {
268
+ if (key === "searchParams") return protectAnnotationValue(target$1.searchParams);
269
+ const value = Reflect.get(target$1, key, target$1);
270
+ return typeof value === "function" ? value.bind(target$1) : value;
271
+ },
272
+ set() {
273
+ throwReadonlyAnnotationMutation();
274
+ },
275
+ defineProperty() {
276
+ throwReadonlyAnnotationMutation();
277
+ },
278
+ deleteProperty() {
279
+ throwReadonlyAnnotationMutation();
280
+ },
281
+ setPrototypeOf() {
282
+ throwReadonlyAnnotationMutation();
283
+ },
284
+ preventExtensions() {
285
+ throwReadonlyAnnotationMutation();
286
+ }
287
+ });
288
+ return registerProtectedAnnotationView(target, view);
289
+ }
290
+ function protectAnnotationValue(value) {
291
+ if (value == null || typeof value !== "object") return value;
292
+ const target = value;
293
+ if (isProtectedAnnotationView(value)) return value;
294
+ const cached = annotationProtectionCache.get(target);
295
+ if (cached !== void 0) return cached;
296
+ if (target instanceof Map) return createProtectedMapView(target);
297
+ if (target instanceof Set) return createProtectedSetView(target);
298
+ if (target instanceof Date) return createProtectedDateView(target);
299
+ if (target instanceof RegExp) return createProtectedRegExpView(target);
300
+ if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target);
301
+ if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target);
302
+ if (Array.isArray(target)) return createProtectedObjectView(target);
303
+ const proto = Object.getPrototypeOf(target);
304
+ if (proto === Object.prototype || proto === null) return createProtectedObjectView(target);
305
+ return value;
306
+ }
48
307
  /**
49
308
  * Extracts annotations from parser state.
50
309
  *
51
310
  * @param state Parser state that may contain annotations
52
- * @returns Annotations object or undefined if no annotations are present
311
+ * @returns Read-only annotations view or undefined if no annotations are
312
+ * present
53
313
  * @since 0.10.0
314
+ * @since 1.0.0 Returns protected read-only annotation views instead of
315
+ * caller-owned objects.
54
316
  *
55
317
  * @example
56
318
  * ```typescript
@@ -62,7 +324,7 @@ function getAnnotations(state) {
62
324
  if (state == null || typeof state !== "object") return void 0;
63
325
  const stateObj = state;
64
326
  const annotations = stateObj[annotationKey];
65
- if (annotations != null && typeof annotations === "object") return annotations;
327
+ if (annotations != null && typeof annotations === "object") return protectAnnotationValue(annotations);
66
328
  return void 0;
67
329
  }
68
330
  /**
@@ -163,11 +425,12 @@ function hasMeaningfulAnnotations(annotations) {
163
425
  */
164
426
  function injectAnnotations(state, annotations) {
165
427
  if (!hasMeaningfulAnnotations(annotations)) return state;
428
+ const protectedAnnotations = protectAnnotationValue(annotations);
166
429
  if (state == null || typeof state !== "object") {
167
430
  const wrapper = {};
168
431
  Object.defineProperties(wrapper, {
169
432
  [annotationKey]: {
170
- value: annotations,
433
+ value: protectedAnnotations,
171
434
  enumerable: true,
172
435
  writable: true,
173
436
  configurable: true
@@ -190,40 +453,40 @@ function injectAnnotations(state, annotations) {
190
453
  }
191
454
  if (Array.isArray(state)) {
192
455
  const cloned$1 = [...state];
193
- cloned$1[annotationKey] = annotations;
456
+ cloned$1[annotationKey] = protectedAnnotations;
194
457
  return cloned$1;
195
458
  }
196
459
  if (isInjectedAnnotationWrapper(state)) {
197
- state[annotationKey] = annotations;
460
+ state[annotationKey] = protectedAnnotations;
198
461
  return state;
199
462
  }
200
463
  if (state instanceof Date) {
201
464
  const cloned$1 = new Date(state.getTime());
202
- cloned$1[annotationKey] = annotations;
465
+ cloned$1[annotationKey] = protectedAnnotations;
203
466
  return cloned$1;
204
467
  }
205
468
  if (state instanceof Map) {
206
469
  const cloned$1 = new Map(state);
207
- cloned$1[annotationKey] = annotations;
470
+ cloned$1[annotationKey] = protectedAnnotations;
208
471
  return cloned$1;
209
472
  }
210
473
  if (state instanceof Set) {
211
474
  const cloned$1 = new Set(state);
212
- cloned$1[annotationKey] = annotations;
475
+ cloned$1[annotationKey] = protectedAnnotations;
213
476
  return cloned$1;
214
477
  }
215
478
  if (state instanceof RegExp) {
216
479
  const cloned$1 = new RegExp(state);
217
- cloned$1[annotationKey] = annotations;
480
+ cloned$1[annotationKey] = protectedAnnotations;
218
481
  return cloned$1;
219
482
  }
220
483
  const proto = Object.getPrototypeOf(state);
221
484
  if (proto === Object.prototype || proto === null) return {
222
485
  ...state,
223
- [annotationKey]: annotations
486
+ [annotationKey]: protectedAnnotations
224
487
  };
225
488
  const cloned = Object.create(proto, Object.getOwnPropertyDescriptors(state));
226
- cloned[annotationKey] = annotations;
489
+ cloned[annotationKey] = protectedAnnotations;
227
490
  return cloned;
228
491
  }
229
492
  /**
@@ -50,6 +50,20 @@ declare const annotationWrapperKey: unique symbol;
50
50
  * @since 0.10.0
51
51
  */
52
52
  type Annotations = Record<symbol, unknown>;
53
+ /**
54
+ * Read-only annotation view returned from parser state.
55
+ *
56
+ * Top-level annotation records are exposed as read-only objects, and supported
57
+ * nested container values (plain objects, arrays, `Map`, `Set`, `Date`,
58
+ * `RegExp`, `URL`, and `URLSearchParams`) are surfaced through protected
59
+ * views that throw on ordinary mutation attempts.
60
+ *
61
+ * Opaque live objects and functions remain reference-preserving.
62
+ *
63
+ * @since 1.0.0
64
+ */
65
+ type ReadonlyAnnotations = Readonly<Annotations>;
66
+ type AnnotationInput = Annotations | ReadonlyAnnotations;
53
67
  /**
54
68
  * Options for parse functions.
55
69
  * @since 0.10.0
@@ -58,6 +72,9 @@ interface ParseOptions {
58
72
  /**
59
73
  * Annotations to attach to the parsing session.
60
74
  * Parsers can access these annotations via getAnnotations(state).
75
+ *
76
+ * Optique treats these values as immutable input and exposes them back to
77
+ * parsers only through protected read-only views.
61
78
  */
62
79
  annotations?: Annotations;
63
80
  }
@@ -65,8 +82,11 @@ interface ParseOptions {
65
82
  * Extracts annotations from parser state.
66
83
  *
67
84
  * @param state Parser state that may contain annotations
68
- * @returns Annotations object or undefined if no annotations are present
85
+ * @returns Read-only annotations view or undefined if no annotations are
86
+ * present
69
87
  * @since 0.10.0
88
+ * @since 1.0.0 Returns protected read-only annotation views instead of
89
+ * caller-owned objects.
70
90
  *
71
91
  * @example
72
92
  * ```typescript
@@ -74,7 +94,7 @@ interface ParseOptions {
74
94
  * const myData = annotations?.[myDataKey];
75
95
  * ```
76
96
  */
77
- declare function getAnnotations(state: unknown): Annotations | undefined;
97
+ declare function getAnnotations(state: unknown): ReadonlyAnnotations | undefined;
78
98
  /**
79
99
  * Reattaches annotations to a freshly created array state.
80
100
  *
@@ -112,7 +132,7 @@ declare function inheritAnnotations<T>(source: unknown, target: T): T;
112
132
  * @returns `true` when the record has at least one own symbol key.
113
133
  * @internal
114
134
  */
115
- declare function hasMeaningfulAnnotations(annotations: Annotations | null | undefined): annotations is Annotations;
135
+ declare function hasMeaningfulAnnotations(annotations: AnnotationInput | null | undefined): annotations is AnnotationInput;
116
136
  /**
117
137
  * Injects annotations into parser state while preserving state shape.
118
138
  *
@@ -129,7 +149,7 @@ declare function hasMeaningfulAnnotations(annotations: Annotations | null | unde
129
149
  * @returns Annotated state.
130
150
  * @internal
131
151
  */
132
- declare function injectAnnotations<TState>(state: TState, annotations: Annotations): TState;
152
+ declare function injectAnnotations<TState>(state: TState, annotations: AnnotationInput): TState;
133
153
  /**
134
154
  * Unwraps a primitive-state annotation wrapper injected by Optique internals.
135
155
  *
@@ -149,4 +169,4 @@ declare function unwrapInjectedAnnotationWrapper<T>(value: T): T;
149
169
  */
150
170
  declare function isInjectedAnnotationWrapper(value: unknown): boolean;
151
171
  //#endregion
152
- export { Annotations, ParseOptions, annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper };
172
+ export { Annotations, ParseOptions, ReadonlyAnnotations, annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper };
@@ -50,6 +50,20 @@ declare const annotationWrapperKey: unique symbol;
50
50
  * @since 0.10.0
51
51
  */
52
52
  type Annotations = Record<symbol, unknown>;
53
+ /**
54
+ * Read-only annotation view returned from parser state.
55
+ *
56
+ * Top-level annotation records are exposed as read-only objects, and supported
57
+ * nested container values (plain objects, arrays, `Map`, `Set`, `Date`,
58
+ * `RegExp`, `URL`, and `URLSearchParams`) are surfaced through protected
59
+ * views that throw on ordinary mutation attempts.
60
+ *
61
+ * Opaque live objects and functions remain reference-preserving.
62
+ *
63
+ * @since 1.0.0
64
+ */
65
+ type ReadonlyAnnotations = Readonly<Annotations>;
66
+ type AnnotationInput = Annotations | ReadonlyAnnotations;
53
67
  /**
54
68
  * Options for parse functions.
55
69
  * @since 0.10.0
@@ -58,6 +72,9 @@ interface ParseOptions {
58
72
  /**
59
73
  * Annotations to attach to the parsing session.
60
74
  * Parsers can access these annotations via getAnnotations(state).
75
+ *
76
+ * Optique treats these values as immutable input and exposes them back to
77
+ * parsers only through protected read-only views.
61
78
  */
62
79
  annotations?: Annotations;
63
80
  }
@@ -65,8 +82,11 @@ interface ParseOptions {
65
82
  * Extracts annotations from parser state.
66
83
  *
67
84
  * @param state Parser state that may contain annotations
68
- * @returns Annotations object or undefined if no annotations are present
85
+ * @returns Read-only annotations view or undefined if no annotations are
86
+ * present
69
87
  * @since 0.10.0
88
+ * @since 1.0.0 Returns protected read-only annotation views instead of
89
+ * caller-owned objects.
70
90
  *
71
91
  * @example
72
92
  * ```typescript
@@ -74,7 +94,7 @@ interface ParseOptions {
74
94
  * const myData = annotations?.[myDataKey];
75
95
  * ```
76
96
  */
77
- declare function getAnnotations(state: unknown): Annotations | undefined;
97
+ declare function getAnnotations(state: unknown): ReadonlyAnnotations | undefined;
78
98
  /**
79
99
  * Reattaches annotations to a freshly created array state.
80
100
  *
@@ -112,7 +132,7 @@ declare function inheritAnnotations<T>(source: unknown, target: T): T;
112
132
  * @returns `true` when the record has at least one own symbol key.
113
133
  * @internal
114
134
  */
115
- declare function hasMeaningfulAnnotations(annotations: Annotations | null | undefined): annotations is Annotations;
135
+ declare function hasMeaningfulAnnotations(annotations: AnnotationInput | null | undefined): annotations is AnnotationInput;
116
136
  /**
117
137
  * Injects annotations into parser state while preserving state shape.
118
138
  *
@@ -129,7 +149,7 @@ declare function hasMeaningfulAnnotations(annotations: Annotations | null | unde
129
149
  * @returns Annotated state.
130
150
  * @internal
131
151
  */
132
- declare function injectAnnotations<TState>(state: TState, annotations: Annotations): TState;
152
+ declare function injectAnnotations<TState>(state: TState, annotations: AnnotationInput): TState;
133
153
  /**
134
154
  * Unwraps a primitive-state annotation wrapper injected by Optique internals.
135
155
  *
@@ -149,4 +169,4 @@ declare function unwrapInjectedAnnotationWrapper<T>(value: T): T;
149
169
  */
150
170
  declare function isInjectedAnnotationWrapper(value: unknown): boolean;
151
171
  //#endregion
152
- export { Annotations, ParseOptions, annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper };
172
+ export { Annotations, ParseOptions, ReadonlyAnnotations, annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper };
@@ -44,12 +44,274 @@ const annotationWrapperKeys = new Set([
44
44
  annotationWrapperKey
45
45
  ]);
46
46
  const injectedAnnotationWrappers = /* @__PURE__ */ new WeakSet();
47
+ const protectedAnnotationTargets = /* @__PURE__ */ new WeakMap();
48
+ const annotationProtectionCache = /* @__PURE__ */ new WeakMap();
49
+ function throwReadonlyAnnotationMutation() {
50
+ throw new TypeError("Cannot mutate read-only annotation data.");
51
+ }
52
+ function registerProtectedAnnotationView(target, view) {
53
+ annotationProtectionCache.set(target, view);
54
+ protectedAnnotationTargets.set(view, target);
55
+ return view;
56
+ }
57
+ function isProtectedAnnotationView(value) {
58
+ return value != null && typeof value === "object" && protectedAnnotationTargets.has(value);
59
+ }
60
+ function unwrapProtectedAnnotationTarget(value) {
61
+ if (value == null || typeof value !== "object") return value;
62
+ return protectedAnnotationTargets.get(value) ?? value;
63
+ }
64
+ function cacheProtectedMethod(cache, key, factory) {
65
+ const cached = cache.get(key);
66
+ if (cached !== void 0) return cached;
67
+ const created = factory();
68
+ cache.set(key, created);
69
+ return created;
70
+ }
71
+ function protectDescriptor(descriptor) {
72
+ if (descriptor == null || !("value" in descriptor)) return descriptor;
73
+ return {
74
+ ...descriptor,
75
+ value: protectAnnotationValue(descriptor.value)
76
+ };
77
+ }
78
+ function createProtectedObjectView(target) {
79
+ const view = new Proxy(target, {
80
+ get(target$1, key, receiver) {
81
+ return protectAnnotationValue(Reflect.get(target$1, key, receiver));
82
+ },
83
+ set() {
84
+ throwReadonlyAnnotationMutation();
85
+ },
86
+ defineProperty() {
87
+ throwReadonlyAnnotationMutation();
88
+ },
89
+ deleteProperty() {
90
+ throwReadonlyAnnotationMutation();
91
+ },
92
+ setPrototypeOf() {
93
+ throwReadonlyAnnotationMutation();
94
+ },
95
+ preventExtensions() {
96
+ throwReadonlyAnnotationMutation();
97
+ },
98
+ getOwnPropertyDescriptor(target$1, key) {
99
+ return protectDescriptor(Reflect.getOwnPropertyDescriptor(target$1, key));
100
+ }
101
+ });
102
+ return registerProtectedAnnotationView(target, view);
103
+ }
104
+ function createProtectedMapView(target) {
105
+ const methodCache = /* @__PURE__ */ new Map();
106
+ const view = new Proxy(target, {
107
+ get(target$1, key) {
108
+ if (key === "size") return target$1.size;
109
+ if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
110
+ if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup))));
111
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
112
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, mapKey) => {
113
+ callback.call(thisArg, protectAnnotationValue(value$1), protectAnnotationValue(mapKey), view);
114
+ }));
115
+ if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
116
+ for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1);
117
+ });
118
+ if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
119
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
120
+ });
121
+ if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
122
+ for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey), protectAnnotationValue(entryValue)];
123
+ });
124
+ const value = Reflect.get(target$1, key, target$1);
125
+ return typeof value === "function" ? value.bind(target$1) : value;
126
+ },
127
+ set() {
128
+ throwReadonlyAnnotationMutation();
129
+ },
130
+ defineProperty() {
131
+ throwReadonlyAnnotationMutation();
132
+ },
133
+ deleteProperty() {
134
+ throwReadonlyAnnotationMutation();
135
+ },
136
+ setPrototypeOf() {
137
+ throwReadonlyAnnotationMutation();
138
+ },
139
+ preventExtensions() {
140
+ throwReadonlyAnnotationMutation();
141
+ }
142
+ });
143
+ return registerProtectedAnnotationView(target, view);
144
+ }
145
+ function createProtectedSetView(target) {
146
+ const methodCache = /* @__PURE__ */ new Map();
147
+ const view = new Proxy(target, {
148
+ get(target$1, key) {
149
+ if (key === "size") return target$1.size;
150
+ if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
151
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
152
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1) => {
153
+ const protectedValue = protectAnnotationValue(value$1);
154
+ callback.call(thisArg, protectedValue, protectedValue, view);
155
+ }));
156
+ if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
157
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
158
+ });
159
+ if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
160
+ for (const value$1 of target$1.values()) {
161
+ const protectedValue = protectAnnotationValue(value$1);
162
+ yield [protectedValue, protectedValue];
163
+ }
164
+ });
165
+ const value = Reflect.get(target$1, key, target$1);
166
+ return typeof value === "function" ? value.bind(target$1) : value;
167
+ },
168
+ set() {
169
+ throwReadonlyAnnotationMutation();
170
+ },
171
+ defineProperty() {
172
+ throwReadonlyAnnotationMutation();
173
+ },
174
+ deleteProperty() {
175
+ throwReadonlyAnnotationMutation();
176
+ },
177
+ setPrototypeOf() {
178
+ throwReadonlyAnnotationMutation();
179
+ },
180
+ preventExtensions() {
181
+ throwReadonlyAnnotationMutation();
182
+ }
183
+ });
184
+ return registerProtectedAnnotationView(target, view);
185
+ }
186
+ function createProtectedDateView(target) {
187
+ const methodCache = /* @__PURE__ */ new Map();
188
+ const view = new Proxy(target, {
189
+ get(target$1, key) {
190
+ const value = Reflect.get(target$1, key, target$1);
191
+ if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
192
+ return typeof value === "function" ? value.bind(target$1) : value;
193
+ },
194
+ set() {
195
+ throwReadonlyAnnotationMutation();
196
+ },
197
+ defineProperty() {
198
+ throwReadonlyAnnotationMutation();
199
+ },
200
+ deleteProperty() {
201
+ throwReadonlyAnnotationMutation();
202
+ },
203
+ setPrototypeOf() {
204
+ throwReadonlyAnnotationMutation();
205
+ },
206
+ preventExtensions() {
207
+ throwReadonlyAnnotationMutation();
208
+ }
209
+ });
210
+ return registerProtectedAnnotationView(target, view);
211
+ }
212
+ function createProtectedRegExpView(target) {
213
+ const methodCache = /* @__PURE__ */ new Map();
214
+ const view = new Proxy(target, {
215
+ get(target$1, key) {
216
+ const value = Reflect.get(target$1, key, target$1);
217
+ if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
218
+ return typeof value === "function" ? value.bind(target$1) : value;
219
+ },
220
+ set() {
221
+ throwReadonlyAnnotationMutation();
222
+ },
223
+ defineProperty() {
224
+ throwReadonlyAnnotationMutation();
225
+ },
226
+ deleteProperty() {
227
+ throwReadonlyAnnotationMutation();
228
+ },
229
+ setPrototypeOf() {
230
+ throwReadonlyAnnotationMutation();
231
+ },
232
+ preventExtensions() {
233
+ throwReadonlyAnnotationMutation();
234
+ }
235
+ });
236
+ return registerProtectedAnnotationView(target, view);
237
+ }
238
+ function createProtectedURLSearchParamsView(target) {
239
+ const methodCache = /* @__PURE__ */ new Map();
240
+ const view = new Proxy(target, {
241
+ get(target$1, key) {
242
+ if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
243
+ const value = Reflect.get(target$1, key, target$1);
244
+ return typeof value === "function" ? value.bind(target$1) : value;
245
+ },
246
+ set() {
247
+ throwReadonlyAnnotationMutation();
248
+ },
249
+ defineProperty() {
250
+ throwReadonlyAnnotationMutation();
251
+ },
252
+ deleteProperty() {
253
+ throwReadonlyAnnotationMutation();
254
+ },
255
+ setPrototypeOf() {
256
+ throwReadonlyAnnotationMutation();
257
+ },
258
+ preventExtensions() {
259
+ throwReadonlyAnnotationMutation();
260
+ }
261
+ });
262
+ return registerProtectedAnnotationView(target, view);
263
+ }
264
+ function createProtectedURLView(target) {
265
+ const view = new Proxy(target, {
266
+ get(target$1, key) {
267
+ if (key === "searchParams") return protectAnnotationValue(target$1.searchParams);
268
+ const value = Reflect.get(target$1, key, target$1);
269
+ return typeof value === "function" ? value.bind(target$1) : value;
270
+ },
271
+ set() {
272
+ throwReadonlyAnnotationMutation();
273
+ },
274
+ defineProperty() {
275
+ throwReadonlyAnnotationMutation();
276
+ },
277
+ deleteProperty() {
278
+ throwReadonlyAnnotationMutation();
279
+ },
280
+ setPrototypeOf() {
281
+ throwReadonlyAnnotationMutation();
282
+ },
283
+ preventExtensions() {
284
+ throwReadonlyAnnotationMutation();
285
+ }
286
+ });
287
+ return registerProtectedAnnotationView(target, view);
288
+ }
289
+ function protectAnnotationValue(value) {
290
+ if (value == null || typeof value !== "object") return value;
291
+ const target = value;
292
+ if (isProtectedAnnotationView(value)) return value;
293
+ const cached = annotationProtectionCache.get(target);
294
+ if (cached !== void 0) return cached;
295
+ if (target instanceof Map) return createProtectedMapView(target);
296
+ if (target instanceof Set) return createProtectedSetView(target);
297
+ if (target instanceof Date) return createProtectedDateView(target);
298
+ if (target instanceof RegExp) return createProtectedRegExpView(target);
299
+ if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target);
300
+ if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target);
301
+ if (Array.isArray(target)) return createProtectedObjectView(target);
302
+ const proto = Object.getPrototypeOf(target);
303
+ if (proto === Object.prototype || proto === null) return createProtectedObjectView(target);
304
+ return value;
305
+ }
47
306
  /**
48
307
  * Extracts annotations from parser state.
49
308
  *
50
309
  * @param state Parser state that may contain annotations
51
- * @returns Annotations object or undefined if no annotations are present
310
+ * @returns Read-only annotations view or undefined if no annotations are
311
+ * present
52
312
  * @since 0.10.0
313
+ * @since 1.0.0 Returns protected read-only annotation views instead of
314
+ * caller-owned objects.
53
315
  *
54
316
  * @example
55
317
  * ```typescript
@@ -61,7 +323,7 @@ function getAnnotations(state) {
61
323
  if (state == null || typeof state !== "object") return void 0;
62
324
  const stateObj = state;
63
325
  const annotations = stateObj[annotationKey];
64
- if (annotations != null && typeof annotations === "object") return annotations;
326
+ if (annotations != null && typeof annotations === "object") return protectAnnotationValue(annotations);
65
327
  return void 0;
66
328
  }
67
329
  /**
@@ -162,11 +424,12 @@ function hasMeaningfulAnnotations(annotations) {
162
424
  */
163
425
  function injectAnnotations(state, annotations) {
164
426
  if (!hasMeaningfulAnnotations(annotations)) return state;
427
+ const protectedAnnotations = protectAnnotationValue(annotations);
165
428
  if (state == null || typeof state !== "object") {
166
429
  const wrapper = {};
167
430
  Object.defineProperties(wrapper, {
168
431
  [annotationKey]: {
169
- value: annotations,
432
+ value: protectedAnnotations,
170
433
  enumerable: true,
171
434
  writable: true,
172
435
  configurable: true
@@ -189,40 +452,40 @@ function injectAnnotations(state, annotations) {
189
452
  }
190
453
  if (Array.isArray(state)) {
191
454
  const cloned$1 = [...state];
192
- cloned$1[annotationKey] = annotations;
455
+ cloned$1[annotationKey] = protectedAnnotations;
193
456
  return cloned$1;
194
457
  }
195
458
  if (isInjectedAnnotationWrapper(state)) {
196
- state[annotationKey] = annotations;
459
+ state[annotationKey] = protectedAnnotations;
197
460
  return state;
198
461
  }
199
462
  if (state instanceof Date) {
200
463
  const cloned$1 = new Date(state.getTime());
201
- cloned$1[annotationKey] = annotations;
464
+ cloned$1[annotationKey] = protectedAnnotations;
202
465
  return cloned$1;
203
466
  }
204
467
  if (state instanceof Map) {
205
468
  const cloned$1 = new Map(state);
206
- cloned$1[annotationKey] = annotations;
469
+ cloned$1[annotationKey] = protectedAnnotations;
207
470
  return cloned$1;
208
471
  }
209
472
  if (state instanceof Set) {
210
473
  const cloned$1 = new Set(state);
211
- cloned$1[annotationKey] = annotations;
474
+ cloned$1[annotationKey] = protectedAnnotations;
212
475
  return cloned$1;
213
476
  }
214
477
  if (state instanceof RegExp) {
215
478
  const cloned$1 = new RegExp(state);
216
- cloned$1[annotationKey] = annotations;
479
+ cloned$1[annotationKey] = protectedAnnotations;
217
480
  return cloned$1;
218
481
  }
219
482
  const proto = Object.getPrototypeOf(state);
220
483
  if (proto === Object.prototype || proto === null) return {
221
484
  ...state,
222
- [annotationKey]: annotations
485
+ [annotationKey]: protectedAnnotations
223
486
  };
224
487
  const cloned = Object.create(proto, Object.getOwnPropertyDescriptors(state));
225
- cloned[annotationKey] = annotations;
488
+ cloned[annotationKey] = protectedAnnotations;
226
489
  return cloned;
227
490
  }
228
491
  /**
@@ -1,4 +1,4 @@
1
- import { Annotations } from "./annotations.cjs";
1
+ import { Annotations, ReadonlyAnnotations } from "./annotations.cjs";
2
2
 
3
3
  //#region src/context.d.ts
4
4
 
@@ -232,4 +232,4 @@ interface SourceContext<TRequiredOptions = void> {
232
232
  [Symbol.asyncDispose]?(): void | PromiseLike<void>;
233
233
  }
234
234
  //#endregion
235
- export { type Annotations, ParserValuePlaceholder, SourceContext, SourceContextPhase, SourceContextPhase1Request, SourceContextPhase2Request, SourceContextRequest };
235
+ export { type Annotations, ParserValuePlaceholder, type ReadonlyAnnotations, SourceContext, SourceContextPhase, SourceContextPhase1Request, SourceContextPhase2Request, SourceContextRequest };
package/dist/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Annotations } from "./annotations.js";
1
+ import { Annotations, ReadonlyAnnotations } from "./annotations.js";
2
2
 
3
3
  //#region src/context.d.ts
4
4
 
@@ -232,4 +232,4 @@ interface SourceContext<TRequiredOptions = void> {
232
232
  [Symbol.asyncDispose]?(): void | PromiseLike<void>;
233
233
  }
234
234
  //#endregion
235
- export { type Annotations, ParserValuePlaceholder, SourceContext, SourceContextPhase, SourceContextPhase1Request, SourceContextPhase2Request, SourceContextRequest };
235
+ export { type Annotations, ParserValuePlaceholder, type ReadonlyAnnotations, SourceContext, SourceContextPhase, SourceContextPhase1Request, SourceContextPhase2Request, SourceContextRequest };
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.cjs";
1
+ import { Annotations, ParseOptions, ReadonlyAnnotations, annotationKey, getAnnotations } from "./annotations.cjs";
2
2
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
4
4
  import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
@@ -12,4 +12,4 @@ import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
12
12
  import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.cjs";
13
13
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, singleDefaultValue, snapshotDefaultDependencyValues, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.cjs";
14
14
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, annotationWrapperRequiresSourceBindingKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, composeWrappedSourceMetadata, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createParserContext, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDelegatingSuggestRuntimeNodes, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, getSnapshottedDefaultDependencyValues, group, hostname, inheritParentAnnotationsKey, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, singleDefaultValue, snapshotDefaultDependencyValues, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, unmatchedNonCliDependencySourceStateMarker, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, type ReadonlyAnnotations, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, annotationWrapperRequiresSourceBindingKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, composeWrappedSourceMetadata, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createParserContext, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDelegatingSuggestRuntimeNodes, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, getSnapshottedDefaultDependencyValues, group, hostname, inheritParentAnnotationsKey, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, singleDefaultValue, snapshotDefaultDependencyValues, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, unmatchedNonCliDependencySourceStateMarker, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.js";
1
+ import { Annotations, ParseOptions, ReadonlyAnnotations, annotationKey, getAnnotations } from "./annotations.js";
2
2
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
4
4
  import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
@@ -12,4 +12,4 @@ import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
12
12
  import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.js";
13
13
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, singleDefaultValue, snapshotDefaultDependencyValues, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
14
14
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, annotationWrapperRequiresSourceBindingKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, composeWrappedSourceMetadata, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createParserContext, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDelegatingSuggestRuntimeNodes, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, getSnapshottedDefaultDependencyValues, group, hostname, inheritParentAnnotationsKey, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, singleDefaultValue, snapshotDefaultDependencyValues, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, unmatchedNonCliDependencySourceStateMarker, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, type ReadonlyAnnotations, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, annotationWrapperRequiresSourceBindingKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, composeWrappedSourceMetadata, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createParserContext, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDelegatingSuggestRuntimeNodes, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, getSnapshottedDefaultDependencyValues, group, hostname, inheritParentAnnotationsKey, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, singleDefaultValue, snapshotDefaultDependencyValues, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, unmatchedNonCliDependencySourceStateMarker, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1841+7b330b10",
3
+ "version": "1.0.0-dev.1842+3f55aecc",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",