@optique/config 1.0.0-dev.783 → 1.0.0-dev.885
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 +130 -7
- package/dist/index.js +130 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -95,16 +95,143 @@ function containsDeferredPromptValues(value, seen = /* @__PURE__ */ new WeakSet(
|
|
|
95
95
|
}
|
|
96
96
|
return containsDeferredPromptValuesInOwnProperties(value, seen);
|
|
97
97
|
}
|
|
98
|
+
const SANITIZE_FAILED = Symbol("sanitizeFailed");
|
|
99
|
+
const activeSanitizations = /* @__PURE__ */ new WeakMap();
|
|
100
|
+
function callWithSanitizedOwnProperties(target, fn, args, strip, seen) {
|
|
101
|
+
let active = activeSanitizations.get(target);
|
|
102
|
+
if (active != null) active.count++;
|
|
103
|
+
else {
|
|
104
|
+
const saved = /* @__PURE__ */ new Map();
|
|
105
|
+
const sanitizedValues = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const key of Reflect.ownKeys(target)) {
|
|
107
|
+
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
108
|
+
if (desc != null && "value" in desc) {
|
|
109
|
+
let stripped;
|
|
110
|
+
try {
|
|
111
|
+
stripped = strip(desc.value, seen);
|
|
112
|
+
} catch {
|
|
113
|
+
for (const [k, d] of saved) try {
|
|
114
|
+
Object.defineProperty(target, k, d);
|
|
115
|
+
} catch {}
|
|
116
|
+
return SANITIZE_FAILED;
|
|
117
|
+
}
|
|
118
|
+
if (stripped !== desc.value) try {
|
|
119
|
+
Object.defineProperty(target, key, {
|
|
120
|
+
...desc,
|
|
121
|
+
value: stripped
|
|
122
|
+
});
|
|
123
|
+
saved.set(key, desc);
|
|
124
|
+
sanitizedValues.set(key, stripped);
|
|
125
|
+
} catch {
|
|
126
|
+
for (const [k, d] of saved) try {
|
|
127
|
+
Object.defineProperty(target, k, d);
|
|
128
|
+
} catch {}
|
|
129
|
+
return SANITIZE_FAILED;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
active = {
|
|
134
|
+
saved,
|
|
135
|
+
sanitizedValues,
|
|
136
|
+
count: 1
|
|
137
|
+
};
|
|
138
|
+
activeSanitizations.set(target, active);
|
|
139
|
+
}
|
|
140
|
+
function release() {
|
|
141
|
+
active.count--;
|
|
142
|
+
if (active.count === 0) {
|
|
143
|
+
activeSanitizations.delete(target);
|
|
144
|
+
for (const [key, desc] of active.saved) try {
|
|
145
|
+
const current = Object.getOwnPropertyDescriptor(target, key);
|
|
146
|
+
if (current == null) continue;
|
|
147
|
+
if ("value" in current && current.value !== active.sanitizedValues.get(key)) continue;
|
|
148
|
+
Object.defineProperty(target, key, desc);
|
|
149
|
+
} catch {}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
let result;
|
|
153
|
+
try {
|
|
154
|
+
result = fn.apply(target, args);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
release();
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
if (result instanceof Promise) return result.then((v) => {
|
|
160
|
+
release();
|
|
161
|
+
return strip(v, seen);
|
|
162
|
+
}, (e) => {
|
|
163
|
+
release();
|
|
164
|
+
throw e;
|
|
165
|
+
});
|
|
166
|
+
release();
|
|
167
|
+
return strip(result, seen);
|
|
168
|
+
}
|
|
169
|
+
function callMethodOnSanitizedTarget(fn, proxy, target, args, strip, seen) {
|
|
170
|
+
const result = callWithSanitizedOwnProperties(target, fn, args, strip, seen);
|
|
171
|
+
if (result !== SANITIZE_FAILED) return result;
|
|
172
|
+
const fallback = fn.apply(proxy, args);
|
|
173
|
+
if (fallback instanceof Promise) return fallback.then((v) => strip(v, seen));
|
|
174
|
+
return strip(fallback, seen);
|
|
175
|
+
}
|
|
98
176
|
function createSanitizedNonPlainView(value, seen) {
|
|
177
|
+
const methodCache = /* @__PURE__ */ new Map();
|
|
99
178
|
const proxy = new Proxy(value, {
|
|
100
179
|
get(target, key, receiver) {
|
|
101
180
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
102
|
-
if (descriptor != null && "value" in descriptor)
|
|
103
|
-
|
|
181
|
+
if (descriptor != null && "value" in descriptor) {
|
|
182
|
+
if (!descriptor.configurable && !descriptor.writable) return descriptor.value;
|
|
183
|
+
const val = stripDeferredPromptValues(descriptor.value, seen);
|
|
184
|
+
if (typeof val === "function") {
|
|
185
|
+
if (!descriptor.configurable && !descriptor.writable || /^class[\s{]/.test(Function.prototype.toString.call(val))) return val;
|
|
186
|
+
const cached = methodCache.get(key);
|
|
187
|
+
if (cached != null && cached.fn === val) return cached.wrapper;
|
|
188
|
+
const wrapper = function(...args) {
|
|
189
|
+
if (this !== proxy) return stripDeferredPromptValues(val.apply(this, args), seen);
|
|
190
|
+
return callMethodOnSanitizedTarget(val, proxy, target, args, stripDeferredPromptValues, seen);
|
|
191
|
+
};
|
|
192
|
+
methodCache.set(key, {
|
|
193
|
+
fn: val,
|
|
194
|
+
wrapper
|
|
195
|
+
});
|
|
196
|
+
return wrapper;
|
|
197
|
+
}
|
|
198
|
+
return val;
|
|
199
|
+
}
|
|
200
|
+
let isAccessor = false;
|
|
201
|
+
for (let proto = target; proto != null; proto = Object.getPrototypeOf(proto)) {
|
|
202
|
+
const d = Object.getOwnPropertyDescriptor(proto, key);
|
|
203
|
+
if (d != null) {
|
|
204
|
+
isAccessor = "get" in d;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const result = Reflect.get(target, key, receiver);
|
|
209
|
+
if (typeof result === "function") {
|
|
210
|
+
if (/^class[\s{]/.test(Function.prototype.toString.call(result))) return result;
|
|
211
|
+
if (!isAccessor) {
|
|
212
|
+
const cached = methodCache.get(key);
|
|
213
|
+
if (cached != null && cached.fn === result) return cached.wrapper;
|
|
214
|
+
const wrapper = function(...args) {
|
|
215
|
+
if (this !== proxy) return stripDeferredPromptValues(result.apply(this, args), seen);
|
|
216
|
+
return callMethodOnSanitizedTarget(result, proxy, target, args, stripDeferredPromptValues, seen);
|
|
217
|
+
};
|
|
218
|
+
methodCache.set(key, {
|
|
219
|
+
fn: result,
|
|
220
|
+
wrapper
|
|
221
|
+
});
|
|
222
|
+
return wrapper;
|
|
223
|
+
}
|
|
224
|
+
return function(...args) {
|
|
225
|
+
if (this !== proxy) return stripDeferredPromptValues(result.apply(this, args), seen);
|
|
226
|
+
return callMethodOnSanitizedTarget(result, proxy, target, args, stripDeferredPromptValues, seen);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return stripDeferredPromptValues(result, seen);
|
|
104
230
|
},
|
|
105
231
|
getOwnPropertyDescriptor(target, key) {
|
|
106
232
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
107
233
|
if (descriptor == null || !("value" in descriptor)) return descriptor;
|
|
234
|
+
if (!descriptor.configurable && !descriptor.writable) return descriptor;
|
|
108
235
|
return {
|
|
109
236
|
...descriptor,
|
|
110
237
|
value: stripDeferredPromptValues(descriptor.value, seen)
|
|
@@ -435,11 +562,7 @@ function getConfigOrDefault(state, options) {
|
|
|
435
562
|
configMeta = getActiveConfigMeta(contextId);
|
|
436
563
|
}
|
|
437
564
|
let configValue;
|
|
438
|
-
if (configData !== void 0 && configData !== null) if (typeof options.key === "function")
|
|
439
|
-
configValue = options.key(configData, configMeta);
|
|
440
|
-
} catch {
|
|
441
|
-
configValue = void 0;
|
|
442
|
-
}
|
|
565
|
+
if (configData !== void 0 && configData !== null) if (typeof options.key === "function") configValue = options.key(configData, configMeta);
|
|
443
566
|
else configValue = configData[options.key];
|
|
444
567
|
if (configValue !== void 0) return {
|
|
445
568
|
success: true,
|
package/dist/index.js
CHANGED
|
@@ -72,16 +72,143 @@ function containsDeferredPromptValues(value, seen = /* @__PURE__ */ new WeakSet(
|
|
|
72
72
|
}
|
|
73
73
|
return containsDeferredPromptValuesInOwnProperties(value, seen);
|
|
74
74
|
}
|
|
75
|
+
const SANITIZE_FAILED = Symbol("sanitizeFailed");
|
|
76
|
+
const activeSanitizations = /* @__PURE__ */ new WeakMap();
|
|
77
|
+
function callWithSanitizedOwnProperties(target, fn, args, strip, seen) {
|
|
78
|
+
let active = activeSanitizations.get(target);
|
|
79
|
+
if (active != null) active.count++;
|
|
80
|
+
else {
|
|
81
|
+
const saved = /* @__PURE__ */ new Map();
|
|
82
|
+
const sanitizedValues = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const key of Reflect.ownKeys(target)) {
|
|
84
|
+
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
85
|
+
if (desc != null && "value" in desc) {
|
|
86
|
+
let stripped;
|
|
87
|
+
try {
|
|
88
|
+
stripped = strip(desc.value, seen);
|
|
89
|
+
} catch {
|
|
90
|
+
for (const [k, d] of saved) try {
|
|
91
|
+
Object.defineProperty(target, k, d);
|
|
92
|
+
} catch {}
|
|
93
|
+
return SANITIZE_FAILED;
|
|
94
|
+
}
|
|
95
|
+
if (stripped !== desc.value) try {
|
|
96
|
+
Object.defineProperty(target, key, {
|
|
97
|
+
...desc,
|
|
98
|
+
value: stripped
|
|
99
|
+
});
|
|
100
|
+
saved.set(key, desc);
|
|
101
|
+
sanitizedValues.set(key, stripped);
|
|
102
|
+
} catch {
|
|
103
|
+
for (const [k, d] of saved) try {
|
|
104
|
+
Object.defineProperty(target, k, d);
|
|
105
|
+
} catch {}
|
|
106
|
+
return SANITIZE_FAILED;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
active = {
|
|
111
|
+
saved,
|
|
112
|
+
sanitizedValues,
|
|
113
|
+
count: 1
|
|
114
|
+
};
|
|
115
|
+
activeSanitizations.set(target, active);
|
|
116
|
+
}
|
|
117
|
+
function release() {
|
|
118
|
+
active.count--;
|
|
119
|
+
if (active.count === 0) {
|
|
120
|
+
activeSanitizations.delete(target);
|
|
121
|
+
for (const [key, desc] of active.saved) try {
|
|
122
|
+
const current = Object.getOwnPropertyDescriptor(target, key);
|
|
123
|
+
if (current == null) continue;
|
|
124
|
+
if ("value" in current && current.value !== active.sanitizedValues.get(key)) continue;
|
|
125
|
+
Object.defineProperty(target, key, desc);
|
|
126
|
+
} catch {}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let result;
|
|
130
|
+
try {
|
|
131
|
+
result = fn.apply(target, args);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
release();
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
if (result instanceof Promise) return result.then((v) => {
|
|
137
|
+
release();
|
|
138
|
+
return strip(v, seen);
|
|
139
|
+
}, (e) => {
|
|
140
|
+
release();
|
|
141
|
+
throw e;
|
|
142
|
+
});
|
|
143
|
+
release();
|
|
144
|
+
return strip(result, seen);
|
|
145
|
+
}
|
|
146
|
+
function callMethodOnSanitizedTarget(fn, proxy, target, args, strip, seen) {
|
|
147
|
+
const result = callWithSanitizedOwnProperties(target, fn, args, strip, seen);
|
|
148
|
+
if (result !== SANITIZE_FAILED) return result;
|
|
149
|
+
const fallback = fn.apply(proxy, args);
|
|
150
|
+
if (fallback instanceof Promise) return fallback.then((v) => strip(v, seen));
|
|
151
|
+
return strip(fallback, seen);
|
|
152
|
+
}
|
|
75
153
|
function createSanitizedNonPlainView(value, seen) {
|
|
154
|
+
const methodCache = /* @__PURE__ */ new Map();
|
|
76
155
|
const proxy = new Proxy(value, {
|
|
77
156
|
get(target, key, receiver) {
|
|
78
157
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
79
|
-
if (descriptor != null && "value" in descriptor)
|
|
80
|
-
|
|
158
|
+
if (descriptor != null && "value" in descriptor) {
|
|
159
|
+
if (!descriptor.configurable && !descriptor.writable) return descriptor.value;
|
|
160
|
+
const val = stripDeferredPromptValues(descriptor.value, seen);
|
|
161
|
+
if (typeof val === "function") {
|
|
162
|
+
if (!descriptor.configurable && !descriptor.writable || /^class[\s{]/.test(Function.prototype.toString.call(val))) return val;
|
|
163
|
+
const cached = methodCache.get(key);
|
|
164
|
+
if (cached != null && cached.fn === val) return cached.wrapper;
|
|
165
|
+
const wrapper = function(...args) {
|
|
166
|
+
if (this !== proxy) return stripDeferredPromptValues(val.apply(this, args), seen);
|
|
167
|
+
return callMethodOnSanitizedTarget(val, proxy, target, args, stripDeferredPromptValues, seen);
|
|
168
|
+
};
|
|
169
|
+
methodCache.set(key, {
|
|
170
|
+
fn: val,
|
|
171
|
+
wrapper
|
|
172
|
+
});
|
|
173
|
+
return wrapper;
|
|
174
|
+
}
|
|
175
|
+
return val;
|
|
176
|
+
}
|
|
177
|
+
let isAccessor = false;
|
|
178
|
+
for (let proto = target; proto != null; proto = Object.getPrototypeOf(proto)) {
|
|
179
|
+
const d = Object.getOwnPropertyDescriptor(proto, key);
|
|
180
|
+
if (d != null) {
|
|
181
|
+
isAccessor = "get" in d;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const result = Reflect.get(target, key, receiver);
|
|
186
|
+
if (typeof result === "function") {
|
|
187
|
+
if (/^class[\s{]/.test(Function.prototype.toString.call(result))) return result;
|
|
188
|
+
if (!isAccessor) {
|
|
189
|
+
const cached = methodCache.get(key);
|
|
190
|
+
if (cached != null && cached.fn === result) return cached.wrapper;
|
|
191
|
+
const wrapper = function(...args) {
|
|
192
|
+
if (this !== proxy) return stripDeferredPromptValues(result.apply(this, args), seen);
|
|
193
|
+
return callMethodOnSanitizedTarget(result, proxy, target, args, stripDeferredPromptValues, seen);
|
|
194
|
+
};
|
|
195
|
+
methodCache.set(key, {
|
|
196
|
+
fn: result,
|
|
197
|
+
wrapper
|
|
198
|
+
});
|
|
199
|
+
return wrapper;
|
|
200
|
+
}
|
|
201
|
+
return function(...args) {
|
|
202
|
+
if (this !== proxy) return stripDeferredPromptValues(result.apply(this, args), seen);
|
|
203
|
+
return callMethodOnSanitizedTarget(result, proxy, target, args, stripDeferredPromptValues, seen);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return stripDeferredPromptValues(result, seen);
|
|
81
207
|
},
|
|
82
208
|
getOwnPropertyDescriptor(target, key) {
|
|
83
209
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
84
210
|
if (descriptor == null || !("value" in descriptor)) return descriptor;
|
|
211
|
+
if (!descriptor.configurable && !descriptor.writable) return descriptor;
|
|
85
212
|
return {
|
|
86
213
|
...descriptor,
|
|
87
214
|
value: stripDeferredPromptValues(descriptor.value, seen)
|
|
@@ -412,11 +539,7 @@ function getConfigOrDefault(state, options) {
|
|
|
412
539
|
configMeta = getActiveConfigMeta(contextId);
|
|
413
540
|
}
|
|
414
541
|
let configValue;
|
|
415
|
-
if (configData !== void 0 && configData !== null) if (typeof options.key === "function")
|
|
416
|
-
configValue = options.key(configData, configMeta);
|
|
417
|
-
} catch {
|
|
418
|
-
configValue = void 0;
|
|
419
|
-
}
|
|
542
|
+
if (configData !== void 0 && configData !== null) if (typeof options.key === "function") configValue = options.key(configData, configMeta);
|
|
420
543
|
else configValue = configData[options.key];
|
|
421
544
|
if (configValue !== void 0) return {
|
|
422
545
|
success: true,
|
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.885+3300ebe1",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -59,7 +59,7 @@
|
|
|
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.885+3300ebe1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"tsdown": "^0.13.0",
|
|
68
68
|
"typescript": "^5.8.3",
|
|
69
69
|
"zod": "^3.25.0 || ^4.0.0",
|
|
70
|
-
"@optique/env": "1.0.0-dev.
|
|
70
|
+
"@optique/env": "1.0.0-dev.885+3300ebe1"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown",
|