@optique/config 1.0.0-dev.453 → 1.0.0-dev.459
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 +27 -55
- package/dist/index.js +27 -55
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -125,10 +125,11 @@ async function validateWithSchema(schema, rawData) {
|
|
|
125
125
|
* ```
|
|
126
126
|
*/
|
|
127
127
|
function createConfigContext(options) {
|
|
128
|
-
const contextId = Symbol
|
|
128
|
+
const contextId = Symbol(`@optique/config:${Math.random()}`);
|
|
129
129
|
return {
|
|
130
130
|
id: contextId,
|
|
131
131
|
schema: options.schema,
|
|
132
|
+
mode: "dynamic",
|
|
132
133
|
async getAnnotations(parsed, runtimeOptions) {
|
|
133
134
|
if (!parsed) return {};
|
|
134
135
|
const opts = runtimeOptions;
|
|
@@ -216,6 +217,10 @@ function createConfigContext(options) {
|
|
|
216
217
|
* ```
|
|
217
218
|
*/
|
|
218
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
|
+
}
|
|
219
224
|
return {
|
|
220
225
|
$mode: parser.$mode,
|
|
221
226
|
$valueType: parser.$valueType,
|
|
@@ -228,83 +233,50 @@ function bindConfig(parser, options) {
|
|
|
228
233
|
initialState: parser.initialState,
|
|
229
234
|
parse: (context) => {
|
|
230
235
|
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
success: true,
|
|
241
|
-
next: {
|
|
242
|
-
...result.next,
|
|
243
|
-
state: newState$1
|
|
244
|
-
},
|
|
245
|
-
consumed: result.consumed
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
const newState = {
|
|
249
|
-
hasCliValue: false,
|
|
250
|
-
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
251
|
-
};
|
|
252
|
-
return {
|
|
253
|
-
success: true,
|
|
254
|
-
next: {
|
|
255
|
-
...context,
|
|
256
|
-
state: newState
|
|
257
|
-
},
|
|
258
|
-
consumed: []
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
return result.then((res) => {
|
|
262
|
-
if (res.success) {
|
|
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;
|
|
263
244
|
const newState$1 = {
|
|
264
|
-
|
|
265
|
-
|
|
245
|
+
[configBindStateKey]: true,
|
|
246
|
+
hasCliValue: cliConsumed,
|
|
247
|
+
cliState: result$1.next.state,
|
|
266
248
|
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
267
249
|
};
|
|
268
250
|
return {
|
|
269
251
|
success: true,
|
|
270
252
|
next: {
|
|
271
|
-
...
|
|
253
|
+
...result$1.next,
|
|
272
254
|
state: newState$1
|
|
273
255
|
},
|
|
274
|
-
consumed:
|
|
256
|
+
consumed: result$1.consumed
|
|
275
257
|
};
|
|
276
258
|
}
|
|
259
|
+
if (result$1.consumed > 0) return result$1;
|
|
277
260
|
const newState = {
|
|
261
|
+
[configBindStateKey]: true,
|
|
278
262
|
hasCliValue: false,
|
|
279
263
|
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
280
264
|
};
|
|
281
265
|
return {
|
|
282
266
|
success: true,
|
|
283
267
|
next: {
|
|
284
|
-
...
|
|
268
|
+
...innerContext,
|
|
285
269
|
state: newState
|
|
286
270
|
},
|
|
287
271
|
consumed: []
|
|
288
272
|
};
|
|
289
|
-
}
|
|
273
|
+
};
|
|
274
|
+
const result = parser.parse(innerContext);
|
|
275
|
+
if (result instanceof Promise) return result.then(processResult);
|
|
276
|
+
return processResult(result);
|
|
290
277
|
},
|
|
291
278
|
complete: (state) => {
|
|
292
|
-
|
|
293
|
-
if (bindState?.hasCliValue && bindState.cliState !== void 0) {
|
|
294
|
-
const innerResult = parser.complete(bindState.cliState);
|
|
295
|
-
if (innerResult instanceof Promise) return innerResult.then((res) => {
|
|
296
|
-
if (res.success) return {
|
|
297
|
-
success: true,
|
|
298
|
-
value: res.value
|
|
299
|
-
};
|
|
300
|
-
return res;
|
|
301
|
-
});
|
|
302
|
-
if (innerResult.success) return {
|
|
303
|
-
success: true,
|
|
304
|
-
value: innerResult.value
|
|
305
|
-
};
|
|
306
|
-
return innerResult;
|
|
307
|
-
}
|
|
279
|
+
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
308
280
|
return getConfigOrDefault(state, options);
|
|
309
281
|
},
|
|
310
282
|
suggest: parser.suggest,
|
package/dist/index.js
CHANGED
|
@@ -102,10 +102,11 @@ async function validateWithSchema(schema, rawData) {
|
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
104
|
function createConfigContext(options) {
|
|
105
|
-
const contextId = Symbol
|
|
105
|
+
const contextId = Symbol(`@optique/config:${Math.random()}`);
|
|
106
106
|
return {
|
|
107
107
|
id: contextId,
|
|
108
108
|
schema: options.schema,
|
|
109
|
+
mode: "dynamic",
|
|
109
110
|
async getAnnotations(parsed, runtimeOptions) {
|
|
110
111
|
if (!parsed) return {};
|
|
111
112
|
const opts = runtimeOptions;
|
|
@@ -193,6 +194,10 @@ function createConfigContext(options) {
|
|
|
193
194
|
* ```
|
|
194
195
|
*/
|
|
195
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
|
+
}
|
|
196
201
|
return {
|
|
197
202
|
$mode: parser.$mode,
|
|
198
203
|
$valueType: parser.$valueType,
|
|
@@ -205,83 +210,50 @@ function bindConfig(parser, options) {
|
|
|
205
210
|
initialState: parser.initialState,
|
|
206
211
|
parse: (context) => {
|
|
207
212
|
const annotations = getAnnotations(context.state);
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
success: true,
|
|
218
|
-
next: {
|
|
219
|
-
...result.next,
|
|
220
|
-
state: newState$1
|
|
221
|
-
},
|
|
222
|
-
consumed: result.consumed
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
const newState = {
|
|
226
|
-
hasCliValue: false,
|
|
227
|
-
...annotations && { [annotationKey]: annotations }
|
|
228
|
-
};
|
|
229
|
-
return {
|
|
230
|
-
success: true,
|
|
231
|
-
next: {
|
|
232
|
-
...context,
|
|
233
|
-
state: newState
|
|
234
|
-
},
|
|
235
|
-
consumed: []
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return result.then((res) => {
|
|
239
|
-
if (res.success) {
|
|
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;
|
|
240
221
|
const newState$1 = {
|
|
241
|
-
|
|
242
|
-
|
|
222
|
+
[configBindStateKey]: true,
|
|
223
|
+
hasCliValue: cliConsumed,
|
|
224
|
+
cliState: result$1.next.state,
|
|
243
225
|
...annotations && { [annotationKey]: annotations }
|
|
244
226
|
};
|
|
245
227
|
return {
|
|
246
228
|
success: true,
|
|
247
229
|
next: {
|
|
248
|
-
...
|
|
230
|
+
...result$1.next,
|
|
249
231
|
state: newState$1
|
|
250
232
|
},
|
|
251
|
-
consumed:
|
|
233
|
+
consumed: result$1.consumed
|
|
252
234
|
};
|
|
253
235
|
}
|
|
236
|
+
if (result$1.consumed > 0) return result$1;
|
|
254
237
|
const newState = {
|
|
238
|
+
[configBindStateKey]: true,
|
|
255
239
|
hasCliValue: false,
|
|
256
240
|
...annotations && { [annotationKey]: annotations }
|
|
257
241
|
};
|
|
258
242
|
return {
|
|
259
243
|
success: true,
|
|
260
244
|
next: {
|
|
261
|
-
...
|
|
245
|
+
...innerContext,
|
|
262
246
|
state: newState
|
|
263
247
|
},
|
|
264
248
|
consumed: []
|
|
265
249
|
};
|
|
266
|
-
}
|
|
250
|
+
};
|
|
251
|
+
const result = parser.parse(innerContext);
|
|
252
|
+
if (result instanceof Promise) return result.then(processResult);
|
|
253
|
+
return processResult(result);
|
|
267
254
|
},
|
|
268
255
|
complete: (state) => {
|
|
269
|
-
|
|
270
|
-
if (bindState?.hasCliValue && bindState.cliState !== void 0) {
|
|
271
|
-
const innerResult = parser.complete(bindState.cliState);
|
|
272
|
-
if (innerResult instanceof Promise) return innerResult.then((res) => {
|
|
273
|
-
if (res.success) return {
|
|
274
|
-
success: true,
|
|
275
|
-
value: res.value
|
|
276
|
-
};
|
|
277
|
-
return res;
|
|
278
|
-
});
|
|
279
|
-
if (innerResult.success) return {
|
|
280
|
-
success: true,
|
|
281
|
-
value: innerResult.value
|
|
282
|
-
};
|
|
283
|
-
return innerResult;
|
|
284
|
-
}
|
|
256
|
+
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
285
257
|
return getConfigOrDefault(state, options);
|
|
286
258
|
},
|
|
287
259
|
suggest: parser.suggest,
|
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.459+c66b524d",
|
|
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.459+c66b524d"
|
|
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.459+c66b524d"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"build": "tsdown",
|