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

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,297 @@ 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 defineProtectedDataProperty(target, key, descriptor) {
73
+ const value = protectAnnotationValue(descriptor.value);
74
+ Object.defineProperty(target, key, {
75
+ configurable: descriptor.configurable,
76
+ enumerable: descriptor.enumerable,
77
+ get: () => value,
78
+ set: () => throwReadonlyAnnotationMutation()
79
+ });
80
+ }
81
+ function createProtectedObjectView(target) {
82
+ if (Array.isArray(target)) {
83
+ const view$1 = new Array(target.length);
84
+ for (const key of Reflect.ownKeys(target)) {
85
+ if (key === "length") continue;
86
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
87
+ if (descriptor == null) continue;
88
+ if ("value" in descriptor) {
89
+ defineProtectedDataProperty(view$1, key, descriptor);
90
+ continue;
91
+ }
92
+ Object.defineProperty(view$1, key, {
93
+ configurable: descriptor.configurable,
94
+ enumerable: descriptor.enumerable,
95
+ get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
96
+ set: () => throwReadonlyAnnotationMutation()
97
+ });
98
+ }
99
+ return registerProtectedAnnotationView(target, Object.freeze(view$1));
100
+ }
101
+ const view = Object.create(Object.getPrototypeOf(target));
102
+ for (const key of Reflect.ownKeys(target)) {
103
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
104
+ if (descriptor == null) continue;
105
+ if ("value" in descriptor) {
106
+ defineProtectedDataProperty(view, key, descriptor);
107
+ continue;
108
+ }
109
+ Object.defineProperty(view, key, {
110
+ configurable: descriptor.configurable,
111
+ enumerable: descriptor.enumerable,
112
+ get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
113
+ set: () => throwReadonlyAnnotationMutation()
114
+ });
115
+ }
116
+ return registerProtectedAnnotationView(target, Object.freeze(view));
117
+ }
118
+ function createProtectedMapView(target) {
119
+ const methodCache = /* @__PURE__ */ new Map();
120
+ const view = new Proxy(target, {
121
+ get(target$1, key) {
122
+ if (key === "size") return target$1.size;
123
+ if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
124
+ if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup))));
125
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
126
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, mapKey) => {
127
+ callback.call(thisArg, protectAnnotationValue(value$1), protectAnnotationValue(mapKey), view);
128
+ }));
129
+ if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
130
+ for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1);
131
+ });
132
+ if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
133
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
134
+ });
135
+ if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
136
+ for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey), protectAnnotationValue(entryValue)];
137
+ });
138
+ const value = Reflect.get(target$1, key, target$1);
139
+ return typeof value === "function" ? value.bind(target$1) : value;
140
+ },
141
+ set() {
142
+ throwReadonlyAnnotationMutation();
143
+ },
144
+ defineProperty() {
145
+ throwReadonlyAnnotationMutation();
146
+ },
147
+ deleteProperty() {
148
+ throwReadonlyAnnotationMutation();
149
+ },
150
+ setPrototypeOf() {
151
+ throwReadonlyAnnotationMutation();
152
+ },
153
+ preventExtensions() {
154
+ throwReadonlyAnnotationMutation();
155
+ }
156
+ });
157
+ return registerProtectedAnnotationView(target, view);
158
+ }
159
+ function createProtectedSetView(target) {
160
+ const methodCache = /* @__PURE__ */ new Map();
161
+ const view = new Proxy(target, {
162
+ get(target$1, key) {
163
+ if (key === "size") return target$1.size;
164
+ if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
165
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
166
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1) => {
167
+ const protectedValue = protectAnnotationValue(value$1);
168
+ callback.call(thisArg, protectedValue, protectedValue, view);
169
+ }));
170
+ if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
171
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
172
+ });
173
+ if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
174
+ for (const value$1 of target$1.values()) {
175
+ const protectedValue = protectAnnotationValue(value$1);
176
+ yield [protectedValue, protectedValue];
177
+ }
178
+ });
179
+ const value = Reflect.get(target$1, key, target$1);
180
+ return typeof value === "function" ? value.bind(target$1) : value;
181
+ },
182
+ set() {
183
+ throwReadonlyAnnotationMutation();
184
+ },
185
+ defineProperty() {
186
+ throwReadonlyAnnotationMutation();
187
+ },
188
+ deleteProperty() {
189
+ throwReadonlyAnnotationMutation();
190
+ },
191
+ setPrototypeOf() {
192
+ throwReadonlyAnnotationMutation();
193
+ },
194
+ preventExtensions() {
195
+ throwReadonlyAnnotationMutation();
196
+ }
197
+ });
198
+ return registerProtectedAnnotationView(target, view);
199
+ }
200
+ function createProtectedDateView(target) {
201
+ const methodCache = /* @__PURE__ */ new Map();
202
+ const view = new Proxy(target, {
203
+ get(target$1, key) {
204
+ const value = Reflect.get(target$1, key, target$1);
205
+ if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
206
+ return typeof value === "function" ? value.bind(target$1) : value;
207
+ },
208
+ set() {
209
+ throwReadonlyAnnotationMutation();
210
+ },
211
+ defineProperty() {
212
+ throwReadonlyAnnotationMutation();
213
+ },
214
+ deleteProperty() {
215
+ throwReadonlyAnnotationMutation();
216
+ },
217
+ setPrototypeOf() {
218
+ throwReadonlyAnnotationMutation();
219
+ },
220
+ preventExtensions() {
221
+ throwReadonlyAnnotationMutation();
222
+ }
223
+ });
224
+ return registerProtectedAnnotationView(target, view);
225
+ }
226
+ function createProtectedRegExpView(target) {
227
+ const methodCache = /* @__PURE__ */ new Map();
228
+ const view = new Proxy(target, {
229
+ get(target$1, key) {
230
+ const value = Reflect.get(target$1, key, target$1);
231
+ if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
232
+ return typeof value === "function" ? value.bind(target$1) : value;
233
+ },
234
+ set() {
235
+ throwReadonlyAnnotationMutation();
236
+ },
237
+ defineProperty() {
238
+ throwReadonlyAnnotationMutation();
239
+ },
240
+ deleteProperty() {
241
+ throwReadonlyAnnotationMutation();
242
+ },
243
+ setPrototypeOf() {
244
+ throwReadonlyAnnotationMutation();
245
+ },
246
+ preventExtensions() {
247
+ throwReadonlyAnnotationMutation();
248
+ }
249
+ });
250
+ return registerProtectedAnnotationView(target, view);
251
+ }
252
+ function createProtectedURLSearchParamsView(target) {
253
+ const methodCache = /* @__PURE__ */ new Map();
254
+ const view = new Proxy(target, {
255
+ get(target$1, key) {
256
+ if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
257
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, name) => {
258
+ callback.call(thisArg, value$1, name, view);
259
+ }));
260
+ if (key === "keys" || key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
261
+ const iterator = key === "keys" ? target$1.keys() : target$1.values();
262
+ for (const value$1 of iterator) yield value$1;
263
+ });
264
+ if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
265
+ for (const entry of target$1.entries()) yield entry;
266
+ });
267
+ const value = Reflect.get(target$1, key, target$1);
268
+ return typeof value === "function" ? value.bind(target$1) : value;
269
+ },
270
+ set() {
271
+ throwReadonlyAnnotationMutation();
272
+ },
273
+ defineProperty() {
274
+ throwReadonlyAnnotationMutation();
275
+ },
276
+ deleteProperty() {
277
+ throwReadonlyAnnotationMutation();
278
+ },
279
+ setPrototypeOf() {
280
+ throwReadonlyAnnotationMutation();
281
+ },
282
+ preventExtensions() {
283
+ throwReadonlyAnnotationMutation();
284
+ }
285
+ });
286
+ return registerProtectedAnnotationView(target, view);
287
+ }
288
+ function createProtectedURLView(target) {
289
+ const view = new Proxy(target, {
290
+ get(target$1, key) {
291
+ if (key === "searchParams") return protectAnnotationValue(target$1.searchParams);
292
+ const value = Reflect.get(target$1, key, target$1);
293
+ return typeof value === "function" ? value.bind(target$1) : value;
294
+ },
295
+ set() {
296
+ throwReadonlyAnnotationMutation();
297
+ },
298
+ defineProperty() {
299
+ throwReadonlyAnnotationMutation();
300
+ },
301
+ deleteProperty() {
302
+ throwReadonlyAnnotationMutation();
303
+ },
304
+ setPrototypeOf() {
305
+ throwReadonlyAnnotationMutation();
306
+ },
307
+ preventExtensions() {
308
+ throwReadonlyAnnotationMutation();
309
+ }
310
+ });
311
+ return registerProtectedAnnotationView(target, view);
312
+ }
313
+ function protectAnnotationValue(value) {
314
+ if (value == null || typeof value !== "object") return value;
315
+ const target = value;
316
+ if (isProtectedAnnotationView(value)) return value;
317
+ const cached = annotationProtectionCache.get(target);
318
+ if (cached !== void 0) return cached;
319
+ if (target instanceof Map) return createProtectedMapView(target);
320
+ if (target instanceof Set) return createProtectedSetView(target);
321
+ if (target instanceof Date) return createProtectedDateView(target);
322
+ if (target instanceof RegExp) return createProtectedRegExpView(target);
323
+ if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target);
324
+ if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target);
325
+ if (Array.isArray(target)) return createProtectedObjectView(target);
326
+ const proto = Object.getPrototypeOf(target);
327
+ if (proto === Object.prototype || proto === null) return createProtectedObjectView(target);
328
+ return value;
329
+ }
48
330
  /**
49
331
  * Extracts annotations from parser state.
50
332
  *
51
333
  * @param state Parser state that may contain annotations
52
- * @returns Annotations object or undefined if no annotations are present
334
+ * @returns Read-only annotations view or undefined if no annotations are
335
+ * present
53
336
  * @since 0.10.0
337
+ * @since 1.0.0 Returns protected read-only annotation views instead of
338
+ * caller-owned objects.
54
339
  *
55
340
  * @example
56
341
  * ```typescript
@@ -62,7 +347,7 @@ function getAnnotations(state) {
62
347
  if (state == null || typeof state !== "object") return void 0;
63
348
  const stateObj = state;
64
349
  const annotations = stateObj[annotationKey];
65
- if (annotations != null && typeof annotations === "object") return annotations;
350
+ if (annotations != null && typeof annotations === "object") return protectAnnotationValue(annotations);
66
351
  return void 0;
67
352
  }
68
353
  /**
@@ -163,11 +448,12 @@ function hasMeaningfulAnnotations(annotations) {
163
448
  */
164
449
  function injectAnnotations(state, annotations) {
165
450
  if (!hasMeaningfulAnnotations(annotations)) return state;
451
+ const protectedAnnotations = protectAnnotationValue(annotations);
166
452
  if (state == null || typeof state !== "object") {
167
453
  const wrapper = {};
168
454
  Object.defineProperties(wrapper, {
169
455
  [annotationKey]: {
170
- value: annotations,
456
+ value: protectedAnnotations,
171
457
  enumerable: true,
172
458
  writable: true,
173
459
  configurable: true
@@ -190,40 +476,40 @@ function injectAnnotations(state, annotations) {
190
476
  }
191
477
  if (Array.isArray(state)) {
192
478
  const cloned$1 = [...state];
193
- cloned$1[annotationKey] = annotations;
479
+ cloned$1[annotationKey] = protectedAnnotations;
194
480
  return cloned$1;
195
481
  }
196
482
  if (isInjectedAnnotationWrapper(state)) {
197
- state[annotationKey] = annotations;
483
+ state[annotationKey] = protectedAnnotations;
198
484
  return state;
199
485
  }
200
486
  if (state instanceof Date) {
201
487
  const cloned$1 = new Date(state.getTime());
202
- cloned$1[annotationKey] = annotations;
488
+ cloned$1[annotationKey] = protectedAnnotations;
203
489
  return cloned$1;
204
490
  }
205
491
  if (state instanceof Map) {
206
492
  const cloned$1 = new Map(state);
207
- cloned$1[annotationKey] = annotations;
493
+ cloned$1[annotationKey] = protectedAnnotations;
208
494
  return cloned$1;
209
495
  }
210
496
  if (state instanceof Set) {
211
497
  const cloned$1 = new Set(state);
212
- cloned$1[annotationKey] = annotations;
498
+ cloned$1[annotationKey] = protectedAnnotations;
213
499
  return cloned$1;
214
500
  }
215
501
  if (state instanceof RegExp) {
216
502
  const cloned$1 = new RegExp(state);
217
- cloned$1[annotationKey] = annotations;
503
+ cloned$1[annotationKey] = protectedAnnotations;
218
504
  return cloned$1;
219
505
  }
220
506
  const proto = Object.getPrototypeOf(state);
221
507
  if (proto === Object.prototype || proto === null) return {
222
508
  ...state,
223
- [annotationKey]: annotations
509
+ [annotationKey]: protectedAnnotations
224
510
  };
225
511
  const cloned = Object.create(proto, Object.getOwnPropertyDescriptors(state));
226
- cloned[annotationKey] = annotations;
512
+ cloned[annotationKey] = protectedAnnotations;
227
513
  return cloned;
228
514
  }
229
515
  /**
@@ -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,297 @@ 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 defineProtectedDataProperty(target, key, descriptor) {
72
+ const value = protectAnnotationValue(descriptor.value);
73
+ Object.defineProperty(target, key, {
74
+ configurable: descriptor.configurable,
75
+ enumerable: descriptor.enumerable,
76
+ get: () => value,
77
+ set: () => throwReadonlyAnnotationMutation()
78
+ });
79
+ }
80
+ function createProtectedObjectView(target) {
81
+ if (Array.isArray(target)) {
82
+ const view$1 = new Array(target.length);
83
+ for (const key of Reflect.ownKeys(target)) {
84
+ if (key === "length") continue;
85
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
86
+ if (descriptor == null) continue;
87
+ if ("value" in descriptor) {
88
+ defineProtectedDataProperty(view$1, key, descriptor);
89
+ continue;
90
+ }
91
+ Object.defineProperty(view$1, key, {
92
+ configurable: descriptor.configurable,
93
+ enumerable: descriptor.enumerable,
94
+ get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
95
+ set: () => throwReadonlyAnnotationMutation()
96
+ });
97
+ }
98
+ return registerProtectedAnnotationView(target, Object.freeze(view$1));
99
+ }
100
+ const view = Object.create(Object.getPrototypeOf(target));
101
+ for (const key of Reflect.ownKeys(target)) {
102
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
103
+ if (descriptor == null) continue;
104
+ if ("value" in descriptor) {
105
+ defineProtectedDataProperty(view, key, descriptor);
106
+ continue;
107
+ }
108
+ Object.defineProperty(view, key, {
109
+ configurable: descriptor.configurable,
110
+ enumerable: descriptor.enumerable,
111
+ get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target)),
112
+ set: () => throwReadonlyAnnotationMutation()
113
+ });
114
+ }
115
+ return registerProtectedAnnotationView(target, Object.freeze(view));
116
+ }
117
+ function createProtectedMapView(target) {
118
+ const methodCache = /* @__PURE__ */ new Map();
119
+ const view = new Proxy(target, {
120
+ get(target$1, key) {
121
+ if (key === "size") return target$1.size;
122
+ if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
123
+ if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => protectAnnotationValue(target$1.get(unwrapProtectedAnnotationTarget(lookup))));
124
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
125
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, mapKey) => {
126
+ callback.call(thisArg, protectAnnotationValue(value$1), protectAnnotationValue(mapKey), view);
127
+ }));
128
+ if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
129
+ for (const value$1 of target$1.keys()) yield protectAnnotationValue(value$1);
130
+ });
131
+ if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
132
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
133
+ });
134
+ if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
135
+ for (const [entryKey, entryValue] of target$1.entries()) yield [protectAnnotationValue(entryKey), protectAnnotationValue(entryValue)];
136
+ });
137
+ const value = Reflect.get(target$1, key, target$1);
138
+ return typeof value === "function" ? value.bind(target$1) : value;
139
+ },
140
+ set() {
141
+ throwReadonlyAnnotationMutation();
142
+ },
143
+ defineProperty() {
144
+ throwReadonlyAnnotationMutation();
145
+ },
146
+ deleteProperty() {
147
+ throwReadonlyAnnotationMutation();
148
+ },
149
+ setPrototypeOf() {
150
+ throwReadonlyAnnotationMutation();
151
+ },
152
+ preventExtensions() {
153
+ throwReadonlyAnnotationMutation();
154
+ }
155
+ });
156
+ return registerProtectedAnnotationView(target, view);
157
+ }
158
+ function createProtectedSetView(target) {
159
+ const methodCache = /* @__PURE__ */ new Map();
160
+ const view = new Proxy(target, {
161
+ get(target$1, key) {
162
+ if (key === "size") return target$1.size;
163
+ if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
164
+ if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => target$1.has(unwrapProtectedAnnotationTarget(lookup)));
165
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1) => {
166
+ const protectedValue = protectAnnotationValue(value$1);
167
+ callback.call(thisArg, protectedValue, protectedValue, view);
168
+ }));
169
+ if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
170
+ for (const value$1 of target$1.values()) yield protectAnnotationValue(value$1);
171
+ });
172
+ if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
173
+ for (const value$1 of target$1.values()) {
174
+ const protectedValue = protectAnnotationValue(value$1);
175
+ yield [protectedValue, protectedValue];
176
+ }
177
+ });
178
+ const value = Reflect.get(target$1, key, target$1);
179
+ return typeof value === "function" ? value.bind(target$1) : value;
180
+ },
181
+ set() {
182
+ throwReadonlyAnnotationMutation();
183
+ },
184
+ defineProperty() {
185
+ throwReadonlyAnnotationMutation();
186
+ },
187
+ deleteProperty() {
188
+ throwReadonlyAnnotationMutation();
189
+ },
190
+ setPrototypeOf() {
191
+ throwReadonlyAnnotationMutation();
192
+ },
193
+ preventExtensions() {
194
+ throwReadonlyAnnotationMutation();
195
+ }
196
+ });
197
+ return registerProtectedAnnotationView(target, view);
198
+ }
199
+ function createProtectedDateView(target) {
200
+ const methodCache = /* @__PURE__ */ new Map();
201
+ const view = new Proxy(target, {
202
+ get(target$1, key) {
203
+ const value = Reflect.get(target$1, key, target$1);
204
+ if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
205
+ return typeof value === "function" ? value.bind(target$1) : value;
206
+ },
207
+ set() {
208
+ throwReadonlyAnnotationMutation();
209
+ },
210
+ defineProperty() {
211
+ throwReadonlyAnnotationMutation();
212
+ },
213
+ deleteProperty() {
214
+ throwReadonlyAnnotationMutation();
215
+ },
216
+ setPrototypeOf() {
217
+ throwReadonlyAnnotationMutation();
218
+ },
219
+ preventExtensions() {
220
+ throwReadonlyAnnotationMutation();
221
+ }
222
+ });
223
+ return registerProtectedAnnotationView(target, view);
224
+ }
225
+ function createProtectedRegExpView(target) {
226
+ const methodCache = /* @__PURE__ */ new Map();
227
+ const view = new Proxy(target, {
228
+ get(target$1, key) {
229
+ const value = Reflect.get(target$1, key, target$1);
230
+ if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
231
+ return typeof value === "function" ? value.bind(target$1) : value;
232
+ },
233
+ set() {
234
+ throwReadonlyAnnotationMutation();
235
+ },
236
+ defineProperty() {
237
+ throwReadonlyAnnotationMutation();
238
+ },
239
+ deleteProperty() {
240
+ throwReadonlyAnnotationMutation();
241
+ },
242
+ setPrototypeOf() {
243
+ throwReadonlyAnnotationMutation();
244
+ },
245
+ preventExtensions() {
246
+ throwReadonlyAnnotationMutation();
247
+ }
248
+ });
249
+ return registerProtectedAnnotationView(target, view);
250
+ }
251
+ function createProtectedURLSearchParamsView(target) {
252
+ const methodCache = /* @__PURE__ */ new Map();
253
+ const view = new Proxy(target, {
254
+ get(target$1, key) {
255
+ if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
256
+ if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => target$1.forEach((value$1, name) => {
257
+ callback.call(thisArg, value$1, name, view);
258
+ }));
259
+ if (key === "keys" || key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
260
+ const iterator = key === "keys" ? target$1.keys() : target$1.values();
261
+ for (const value$1 of iterator) yield value$1;
262
+ });
263
+ if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
264
+ for (const entry of target$1.entries()) yield entry;
265
+ });
266
+ const value = Reflect.get(target$1, key, target$1);
267
+ return typeof value === "function" ? value.bind(target$1) : value;
268
+ },
269
+ set() {
270
+ throwReadonlyAnnotationMutation();
271
+ },
272
+ defineProperty() {
273
+ throwReadonlyAnnotationMutation();
274
+ },
275
+ deleteProperty() {
276
+ throwReadonlyAnnotationMutation();
277
+ },
278
+ setPrototypeOf() {
279
+ throwReadonlyAnnotationMutation();
280
+ },
281
+ preventExtensions() {
282
+ throwReadonlyAnnotationMutation();
283
+ }
284
+ });
285
+ return registerProtectedAnnotationView(target, view);
286
+ }
287
+ function createProtectedURLView(target) {
288
+ const view = new Proxy(target, {
289
+ get(target$1, key) {
290
+ if (key === "searchParams") return protectAnnotationValue(target$1.searchParams);
291
+ const value = Reflect.get(target$1, key, target$1);
292
+ return typeof value === "function" ? value.bind(target$1) : value;
293
+ },
294
+ set() {
295
+ throwReadonlyAnnotationMutation();
296
+ },
297
+ defineProperty() {
298
+ throwReadonlyAnnotationMutation();
299
+ },
300
+ deleteProperty() {
301
+ throwReadonlyAnnotationMutation();
302
+ },
303
+ setPrototypeOf() {
304
+ throwReadonlyAnnotationMutation();
305
+ },
306
+ preventExtensions() {
307
+ throwReadonlyAnnotationMutation();
308
+ }
309
+ });
310
+ return registerProtectedAnnotationView(target, view);
311
+ }
312
+ function protectAnnotationValue(value) {
313
+ if (value == null || typeof value !== "object") return value;
314
+ const target = value;
315
+ if (isProtectedAnnotationView(value)) return value;
316
+ const cached = annotationProtectionCache.get(target);
317
+ if (cached !== void 0) return cached;
318
+ if (target instanceof Map) return createProtectedMapView(target);
319
+ if (target instanceof Set) return createProtectedSetView(target);
320
+ if (target instanceof Date) return createProtectedDateView(target);
321
+ if (target instanceof RegExp) return createProtectedRegExpView(target);
322
+ if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target);
323
+ if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target);
324
+ if (Array.isArray(target)) return createProtectedObjectView(target);
325
+ const proto = Object.getPrototypeOf(target);
326
+ if (proto === Object.prototype || proto === null) return createProtectedObjectView(target);
327
+ return value;
328
+ }
47
329
  /**
48
330
  * Extracts annotations from parser state.
49
331
  *
50
332
  * @param state Parser state that may contain annotations
51
- * @returns Annotations object or undefined if no annotations are present
333
+ * @returns Read-only annotations view or undefined if no annotations are
334
+ * present
52
335
  * @since 0.10.0
336
+ * @since 1.0.0 Returns protected read-only annotation views instead of
337
+ * caller-owned objects.
53
338
  *
54
339
  * @example
55
340
  * ```typescript
@@ -61,7 +346,7 @@ function getAnnotations(state) {
61
346
  if (state == null || typeof state !== "object") return void 0;
62
347
  const stateObj = state;
63
348
  const annotations = stateObj[annotationKey];
64
- if (annotations != null && typeof annotations === "object") return annotations;
349
+ if (annotations != null && typeof annotations === "object") return protectAnnotationValue(annotations);
65
350
  return void 0;
66
351
  }
67
352
  /**
@@ -162,11 +447,12 @@ function hasMeaningfulAnnotations(annotations) {
162
447
  */
163
448
  function injectAnnotations(state, annotations) {
164
449
  if (!hasMeaningfulAnnotations(annotations)) return state;
450
+ const protectedAnnotations = protectAnnotationValue(annotations);
165
451
  if (state == null || typeof state !== "object") {
166
452
  const wrapper = {};
167
453
  Object.defineProperties(wrapper, {
168
454
  [annotationKey]: {
169
- value: annotations,
455
+ value: protectedAnnotations,
170
456
  enumerable: true,
171
457
  writable: true,
172
458
  configurable: true
@@ -189,40 +475,40 @@ function injectAnnotations(state, annotations) {
189
475
  }
190
476
  if (Array.isArray(state)) {
191
477
  const cloned$1 = [...state];
192
- cloned$1[annotationKey] = annotations;
478
+ cloned$1[annotationKey] = protectedAnnotations;
193
479
  return cloned$1;
194
480
  }
195
481
  if (isInjectedAnnotationWrapper(state)) {
196
- state[annotationKey] = annotations;
482
+ state[annotationKey] = protectedAnnotations;
197
483
  return state;
198
484
  }
199
485
  if (state instanceof Date) {
200
486
  const cloned$1 = new Date(state.getTime());
201
- cloned$1[annotationKey] = annotations;
487
+ cloned$1[annotationKey] = protectedAnnotations;
202
488
  return cloned$1;
203
489
  }
204
490
  if (state instanceof Map) {
205
491
  const cloned$1 = new Map(state);
206
- cloned$1[annotationKey] = annotations;
492
+ cloned$1[annotationKey] = protectedAnnotations;
207
493
  return cloned$1;
208
494
  }
209
495
  if (state instanceof Set) {
210
496
  const cloned$1 = new Set(state);
211
- cloned$1[annotationKey] = annotations;
497
+ cloned$1[annotationKey] = protectedAnnotations;
212
498
  return cloned$1;
213
499
  }
214
500
  if (state instanceof RegExp) {
215
501
  const cloned$1 = new RegExp(state);
216
- cloned$1[annotationKey] = annotations;
502
+ cloned$1[annotationKey] = protectedAnnotations;
217
503
  return cloned$1;
218
504
  }
219
505
  const proto = Object.getPrototypeOf(state);
220
506
  if (proto === Object.prototype || proto === null) return {
221
507
  ...state,
222
- [annotationKey]: annotations
508
+ [annotationKey]: protectedAnnotations
223
509
  };
224
510
  const cloned = Object.create(proto, Object.getOwnPropertyDescriptors(state));
225
- cloned[annotationKey] = annotations;
511
+ cloned[annotationKey] = protectedAnnotations;
226
512
  return cloned;
227
513
  }
228
514
  /**
@@ -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.1846+e6b02260",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",