@optique/config 1.0.0-dev.452 → 1.0.0-dev.454
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +36 -75
- package/dist/index.d.cts +1 -11
- package/dist/index.d.ts +1 -11
- package/dist/index.js +37 -74
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -28,16 +28,6 @@ const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
|
28
28
|
|
|
29
29
|
//#region src/index.ts
|
|
30
30
|
/**
|
|
31
|
-
* Unique symbol for config data in annotations.
|
|
32
|
-
* @since 0.10.0
|
|
33
|
-
*/
|
|
34
|
-
const configKey = Symbol.for("@optique/config");
|
|
35
|
-
/**
|
|
36
|
-
* Unique symbol for config metadata in annotations.
|
|
37
|
-
* @since 1.0.0
|
|
38
|
-
*/
|
|
39
|
-
const configMetaKey = Symbol.for("@optique/config/meta");
|
|
40
|
-
/**
|
|
41
31
|
* Internal registry for active config data during config context execution.
|
|
42
32
|
* This is a workaround for the limitation that object() doesn't propagate
|
|
43
33
|
* annotations to child field parsers.
|
|
@@ -135,10 +125,11 @@ async function validateWithSchema(schema, rawData) {
|
|
|
135
125
|
* ```
|
|
136
126
|
*/
|
|
137
127
|
function createConfigContext(options) {
|
|
138
|
-
const contextId = Symbol
|
|
128
|
+
const contextId = Symbol(`@optique/config:${Math.random()}`);
|
|
139
129
|
return {
|
|
140
130
|
id: contextId,
|
|
141
131
|
schema: options.schema,
|
|
132
|
+
mode: "dynamic",
|
|
142
133
|
async getAnnotations(parsed, runtimeOptions) {
|
|
143
134
|
if (!parsed) return {};
|
|
144
135
|
const opts = runtimeOptions;
|
|
@@ -179,12 +170,12 @@ function createConfigContext(options) {
|
|
|
179
170
|
setActiveConfig(contextId, configData);
|
|
180
171
|
if (configMeta !== void 0) {
|
|
181
172
|
setActiveConfigMeta(contextId, configMeta);
|
|
182
|
-
return {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
173
|
+
return { [contextId]: {
|
|
174
|
+
data: configData,
|
|
175
|
+
meta: configMeta
|
|
176
|
+
} };
|
|
186
177
|
}
|
|
187
|
-
return { [
|
|
178
|
+
return { [contextId]: { data: configData } };
|
|
188
179
|
}
|
|
189
180
|
return {};
|
|
190
181
|
},
|
|
@@ -226,6 +217,10 @@ function createConfigContext(options) {
|
|
|
226
217
|
* ```
|
|
227
218
|
*/
|
|
228
219
|
function bindConfig(parser, options) {
|
|
220
|
+
const configBindStateKey = Symbol("@optique/config/bindState");
|
|
221
|
+
function isConfigBindState(value) {
|
|
222
|
+
return value != null && typeof value === "object" && configBindStateKey in value;
|
|
223
|
+
}
|
|
229
224
|
return {
|
|
230
225
|
$mode: parser.$mode,
|
|
231
226
|
$valueType: parser.$valueType,
|
|
@@ -238,83 +233,50 @@ function bindConfig(parser, options) {
|
|
|
238
233
|
initialState: parser.initialState,
|
|
239
234
|
parse: (context) => {
|
|
240
235
|
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
236
|
+
const innerState = isConfigBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
|
|
237
|
+
const innerContext = innerState !== context.state ? {
|
|
238
|
+
...context,
|
|
239
|
+
state: innerState
|
|
240
|
+
} : context;
|
|
241
|
+
const processResult = (result$1) => {
|
|
242
|
+
if (result$1.success) {
|
|
243
|
+
const cliConsumed = result$1.consumed.length > 0;
|
|
244
244
|
const newState$1 = {
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
[configBindStateKey]: true,
|
|
246
|
+
hasCliValue: cliConsumed,
|
|
247
|
+
cliState: result$1.next.state,
|
|
247
248
|
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
248
249
|
};
|
|
249
250
|
return {
|
|
250
251
|
success: true,
|
|
251
252
|
next: {
|
|
252
|
-
...result.next,
|
|
253
|
+
...result$1.next,
|
|
253
254
|
state: newState$1
|
|
254
255
|
},
|
|
255
|
-
consumed: result.consumed
|
|
256
|
+
consumed: result$1.consumed
|
|
256
257
|
};
|
|
257
258
|
}
|
|
259
|
+
if (result$1.consumed > 0) return result$1;
|
|
258
260
|
const newState = {
|
|
261
|
+
[configBindStateKey]: true,
|
|
259
262
|
hasCliValue: false,
|
|
260
263
|
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
261
264
|
};
|
|
262
265
|
return {
|
|
263
266
|
success: true,
|
|
264
267
|
next: {
|
|
265
|
-
...
|
|
268
|
+
...innerContext,
|
|
266
269
|
state: newState
|
|
267
270
|
},
|
|
268
271
|
consumed: []
|
|
269
272
|
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
hasCliValue: true,
|
|
275
|
-
cliState: res.next.state,
|
|
276
|
-
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
277
|
-
};
|
|
278
|
-
return {
|
|
279
|
-
success: true,
|
|
280
|
-
next: {
|
|
281
|
-
...res.next,
|
|
282
|
-
state: newState$1
|
|
283
|
-
},
|
|
284
|
-
consumed: res.consumed
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const newState = {
|
|
288
|
-
hasCliValue: false,
|
|
289
|
-
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
290
|
-
};
|
|
291
|
-
return {
|
|
292
|
-
success: true,
|
|
293
|
-
next: {
|
|
294
|
-
...context,
|
|
295
|
-
state: newState
|
|
296
|
-
},
|
|
297
|
-
consumed: []
|
|
298
|
-
};
|
|
299
|
-
});
|
|
273
|
+
};
|
|
274
|
+
const result = parser.parse(innerContext);
|
|
275
|
+
if (result instanceof Promise) return result.then(processResult);
|
|
276
|
+
return processResult(result);
|
|
300
277
|
},
|
|
301
278
|
complete: (state) => {
|
|
302
|
-
|
|
303
|
-
if (bindState?.hasCliValue && bindState.cliState !== void 0) {
|
|
304
|
-
const innerResult = parser.complete(bindState.cliState);
|
|
305
|
-
if (innerResult instanceof Promise) return innerResult.then((res) => {
|
|
306
|
-
if (res.success) return {
|
|
307
|
-
success: true,
|
|
308
|
-
value: res.value
|
|
309
|
-
};
|
|
310
|
-
return res;
|
|
311
|
-
});
|
|
312
|
-
if (innerResult.success) return {
|
|
313
|
-
success: true,
|
|
314
|
-
value: innerResult.value
|
|
315
|
-
};
|
|
316
|
-
return innerResult;
|
|
317
|
-
}
|
|
279
|
+
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
318
280
|
return getConfigOrDefault(state, options);
|
|
319
281
|
},
|
|
320
282
|
suggest: parser.suggest,
|
|
@@ -332,10 +294,11 @@ function bindConfig(parser, options) {
|
|
|
332
294
|
*/
|
|
333
295
|
function getConfigOrDefault(state, options) {
|
|
334
296
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
335
|
-
|
|
336
|
-
|
|
297
|
+
const contextId = options.context.id;
|
|
298
|
+
const annotationValue = annotations?.[contextId];
|
|
299
|
+
let configData = annotationValue?.data;
|
|
300
|
+
let configMeta = annotationValue?.meta;
|
|
337
301
|
if (configData === void 0 || configData === null) {
|
|
338
|
-
const contextId = options.context.id;
|
|
339
302
|
configData = getActiveConfig(contextId);
|
|
340
303
|
configMeta = getActiveConfigMeta(contextId);
|
|
341
304
|
}
|
|
@@ -364,8 +327,6 @@ function getConfigOrDefault(state, options) {
|
|
|
364
327
|
exports.bindConfig = bindConfig;
|
|
365
328
|
exports.clearActiveConfig = clearActiveConfig;
|
|
366
329
|
exports.clearActiveConfigMeta = clearActiveConfigMeta;
|
|
367
|
-
exports.configKey = configKey;
|
|
368
|
-
exports.configMetaKey = configMetaKey;
|
|
369
330
|
exports.createConfigContext = createConfigContext;
|
|
370
331
|
exports.getActiveConfig = getActiveConfig;
|
|
371
332
|
exports.getActiveConfigMeta = getActiveConfigMeta;
|
package/dist/index.d.cts
CHANGED
|
@@ -4,16 +4,6 @@ import { Parser } from "@optique/core/parser";
|
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Unique symbol for config data in annotations.
|
|
9
|
-
* @since 0.10.0
|
|
10
|
-
*/
|
|
11
|
-
declare const configKey: unique symbol;
|
|
12
|
-
/**
|
|
13
|
-
* Unique symbol for config metadata in annotations.
|
|
14
|
-
* @since 1.0.0
|
|
15
|
-
*/
|
|
16
|
-
declare const configMetaKey: unique symbol;
|
|
17
7
|
/**
|
|
18
8
|
* Metadata about the loaded config source.
|
|
19
9
|
*
|
|
@@ -241,4 +231,4 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
241
231
|
*/
|
|
242
232
|
declare function bindConfig<M extends "sync" | "async", TValue, TState, T, TConfigMeta = ConfigMeta>(parser: Parser<M, TValue, TState>, options: BindConfigOptions<T, TValue, TConfigMeta>): Parser<M, TValue, TState>;
|
|
243
233
|
//#endregion
|
|
244
|
-
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, clearActiveConfig, clearActiveConfigMeta,
|
|
234
|
+
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, clearActiveConfig, clearActiveConfigMeta, createConfigContext, getActiveConfig, getActiveConfigMeta, setActiveConfig, setActiveConfigMeta };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,16 +4,6 @@ import { Parser } from "@optique/core/parser";
|
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Unique symbol for config data in annotations.
|
|
9
|
-
* @since 0.10.0
|
|
10
|
-
*/
|
|
11
|
-
declare const configKey: unique symbol;
|
|
12
|
-
/**
|
|
13
|
-
* Unique symbol for config metadata in annotations.
|
|
14
|
-
* @since 1.0.0
|
|
15
|
-
*/
|
|
16
|
-
declare const configMetaKey: unique symbol;
|
|
17
7
|
/**
|
|
18
8
|
* Metadata about the loaded config source.
|
|
19
9
|
*
|
|
@@ -241,4 +231,4 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
241
231
|
*/
|
|
242
232
|
declare function bindConfig<M extends "sync" | "async", TValue, TState, T, TConfigMeta = ConfigMeta>(parser: Parser<M, TValue, TState>, options: BindConfigOptions<T, TValue, TConfigMeta>): Parser<M, TValue, TState>;
|
|
243
233
|
//#endregion
|
|
244
|
-
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, clearActiveConfig, clearActiveConfigMeta,
|
|
234
|
+
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, clearActiveConfig, clearActiveConfigMeta, createConfigContext, getActiveConfig, getActiveConfigMeta, setActiveConfig, setActiveConfigMeta };
|
package/dist/index.js
CHANGED
|
@@ -5,16 +5,6 @@ import { message } from "@optique/core/message";
|
|
|
5
5
|
|
|
6
6
|
//#region src/index.ts
|
|
7
7
|
/**
|
|
8
|
-
* Unique symbol for config data in annotations.
|
|
9
|
-
* @since 0.10.0
|
|
10
|
-
*/
|
|
11
|
-
const configKey = Symbol.for("@optique/config");
|
|
12
|
-
/**
|
|
13
|
-
* Unique symbol for config metadata in annotations.
|
|
14
|
-
* @since 1.0.0
|
|
15
|
-
*/
|
|
16
|
-
const configMetaKey = Symbol.for("@optique/config/meta");
|
|
17
|
-
/**
|
|
18
8
|
* Internal registry for active config data during config context execution.
|
|
19
9
|
* This is a workaround for the limitation that object() doesn't propagate
|
|
20
10
|
* annotations to child field parsers.
|
|
@@ -112,10 +102,11 @@ async function validateWithSchema(schema, rawData) {
|
|
|
112
102
|
* ```
|
|
113
103
|
*/
|
|
114
104
|
function createConfigContext(options) {
|
|
115
|
-
const contextId = Symbol
|
|
105
|
+
const contextId = Symbol(`@optique/config:${Math.random()}`);
|
|
116
106
|
return {
|
|
117
107
|
id: contextId,
|
|
118
108
|
schema: options.schema,
|
|
109
|
+
mode: "dynamic",
|
|
119
110
|
async getAnnotations(parsed, runtimeOptions) {
|
|
120
111
|
if (!parsed) return {};
|
|
121
112
|
const opts = runtimeOptions;
|
|
@@ -156,12 +147,12 @@ function createConfigContext(options) {
|
|
|
156
147
|
setActiveConfig(contextId, configData);
|
|
157
148
|
if (configMeta !== void 0) {
|
|
158
149
|
setActiveConfigMeta(contextId, configMeta);
|
|
159
|
-
return {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
150
|
+
return { [contextId]: {
|
|
151
|
+
data: configData,
|
|
152
|
+
meta: configMeta
|
|
153
|
+
} };
|
|
163
154
|
}
|
|
164
|
-
return { [
|
|
155
|
+
return { [contextId]: { data: configData } };
|
|
165
156
|
}
|
|
166
157
|
return {};
|
|
167
158
|
},
|
|
@@ -203,6 +194,10 @@ function createConfigContext(options) {
|
|
|
203
194
|
* ```
|
|
204
195
|
*/
|
|
205
196
|
function bindConfig(parser, options) {
|
|
197
|
+
const configBindStateKey = Symbol("@optique/config/bindState");
|
|
198
|
+
function isConfigBindState(value) {
|
|
199
|
+
return value != null && typeof value === "object" && configBindStateKey in value;
|
|
200
|
+
}
|
|
206
201
|
return {
|
|
207
202
|
$mode: parser.$mode,
|
|
208
203
|
$valueType: parser.$valueType,
|
|
@@ -215,83 +210,50 @@ function bindConfig(parser, options) {
|
|
|
215
210
|
initialState: parser.initialState,
|
|
216
211
|
parse: (context) => {
|
|
217
212
|
const annotations = getAnnotations(context.state);
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
const innerState = isConfigBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
|
|
214
|
+
const innerContext = innerState !== context.state ? {
|
|
215
|
+
...context,
|
|
216
|
+
state: innerState
|
|
217
|
+
} : context;
|
|
218
|
+
const processResult = (result$1) => {
|
|
219
|
+
if (result$1.success) {
|
|
220
|
+
const cliConsumed = result$1.consumed.length > 0;
|
|
221
221
|
const newState$1 = {
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
[configBindStateKey]: true,
|
|
223
|
+
hasCliValue: cliConsumed,
|
|
224
|
+
cliState: result$1.next.state,
|
|
224
225
|
...annotations && { [annotationKey]: annotations }
|
|
225
226
|
};
|
|
226
227
|
return {
|
|
227
228
|
success: true,
|
|
228
229
|
next: {
|
|
229
|
-
...result.next,
|
|
230
|
+
...result$1.next,
|
|
230
231
|
state: newState$1
|
|
231
232
|
},
|
|
232
|
-
consumed: result.consumed
|
|
233
|
+
consumed: result$1.consumed
|
|
233
234
|
};
|
|
234
235
|
}
|
|
236
|
+
if (result$1.consumed > 0) return result$1;
|
|
235
237
|
const newState = {
|
|
238
|
+
[configBindStateKey]: true,
|
|
236
239
|
hasCliValue: false,
|
|
237
240
|
...annotations && { [annotationKey]: annotations }
|
|
238
241
|
};
|
|
239
242
|
return {
|
|
240
243
|
success: true,
|
|
241
244
|
next: {
|
|
242
|
-
...
|
|
245
|
+
...innerContext,
|
|
243
246
|
state: newState
|
|
244
247
|
},
|
|
245
248
|
consumed: []
|
|
246
249
|
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
hasCliValue: true,
|
|
252
|
-
cliState: res.next.state,
|
|
253
|
-
...annotations && { [annotationKey]: annotations }
|
|
254
|
-
};
|
|
255
|
-
return {
|
|
256
|
-
success: true,
|
|
257
|
-
next: {
|
|
258
|
-
...res.next,
|
|
259
|
-
state: newState$1
|
|
260
|
-
},
|
|
261
|
-
consumed: res.consumed
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
const newState = {
|
|
265
|
-
hasCliValue: false,
|
|
266
|
-
...annotations && { [annotationKey]: annotations }
|
|
267
|
-
};
|
|
268
|
-
return {
|
|
269
|
-
success: true,
|
|
270
|
-
next: {
|
|
271
|
-
...context,
|
|
272
|
-
state: newState
|
|
273
|
-
},
|
|
274
|
-
consumed: []
|
|
275
|
-
};
|
|
276
|
-
});
|
|
250
|
+
};
|
|
251
|
+
const result = parser.parse(innerContext);
|
|
252
|
+
if (result instanceof Promise) return result.then(processResult);
|
|
253
|
+
return processResult(result);
|
|
277
254
|
},
|
|
278
255
|
complete: (state) => {
|
|
279
|
-
|
|
280
|
-
if (bindState?.hasCliValue && bindState.cliState !== void 0) {
|
|
281
|
-
const innerResult = parser.complete(bindState.cliState);
|
|
282
|
-
if (innerResult instanceof Promise) return innerResult.then((res) => {
|
|
283
|
-
if (res.success) return {
|
|
284
|
-
success: true,
|
|
285
|
-
value: res.value
|
|
286
|
-
};
|
|
287
|
-
return res;
|
|
288
|
-
});
|
|
289
|
-
if (innerResult.success) return {
|
|
290
|
-
success: true,
|
|
291
|
-
value: innerResult.value
|
|
292
|
-
};
|
|
293
|
-
return innerResult;
|
|
294
|
-
}
|
|
256
|
+
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
295
257
|
return getConfigOrDefault(state, options);
|
|
296
258
|
},
|
|
297
259
|
suggest: parser.suggest,
|
|
@@ -309,10 +271,11 @@ function bindConfig(parser, options) {
|
|
|
309
271
|
*/
|
|
310
272
|
function getConfigOrDefault(state, options) {
|
|
311
273
|
const annotations = getAnnotations(state);
|
|
312
|
-
|
|
313
|
-
|
|
274
|
+
const contextId = options.context.id;
|
|
275
|
+
const annotationValue = annotations?.[contextId];
|
|
276
|
+
let configData = annotationValue?.data;
|
|
277
|
+
let configMeta = annotationValue?.meta;
|
|
314
278
|
if (configData === void 0 || configData === null) {
|
|
315
|
-
const contextId = options.context.id;
|
|
316
279
|
configData = getActiveConfig(contextId);
|
|
317
280
|
configMeta = getActiveConfigMeta(contextId);
|
|
318
281
|
}
|
|
@@ -338,4 +301,4 @@ function getConfigOrDefault(state, options) {
|
|
|
338
301
|
}
|
|
339
302
|
|
|
340
303
|
//#endregion
|
|
341
|
-
export { bindConfig, clearActiveConfig, clearActiveConfigMeta,
|
|
304
|
+
export { bindConfig, clearActiveConfig, clearActiveConfigMeta, createConfigContext, getActiveConfig, getActiveConfigMeta, setActiveConfig, setActiveConfigMeta };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/config",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.454+d2244c89",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -59,14 +59,15 @@
|
|
|
59
59
|
"@standard-schema/spec": "^1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@optique/core": "1.0.0-dev.
|
|
62
|
+
"@optique/core": "1.0.0-dev.454+d2244c89"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
66
66
|
"@types/node": "^20.19.9",
|
|
67
67
|
"tsdown": "^0.13.0",
|
|
68
68
|
"typescript": "^5.8.3",
|
|
69
|
-
"zod": "^3.25.0 || ^4.0.0"
|
|
69
|
+
"zod": "^3.25.0 || ^4.0.0",
|
|
70
|
+
"@optique/env": "1.0.0-dev.454+d2244c89"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"build": "tsdown",
|