@burojs/config 0.2.0 → 0.5.0
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/README.md +52 -17
- package/dist/index.cjs +466 -510
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -59
- package/dist/index.d.ts +69 -59
- package/dist/index.js +463 -506
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/dist/index.cjs
CHANGED
|
@@ -1,563 +1,519 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
["validator", "validator"],
|
|
25
|
-
["validators", "validator"]
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _burojs_core = require("@burojs/core");
|
|
3
|
+
let _burojs_core_internal = require("@burojs/core/internal");
|
|
4
|
+
let yaml = require("yaml");
|
|
5
|
+
//#region src/source-policy.ts
|
|
6
|
+
const MAX_SOURCE_DEPTH = _burojs_core.DEFAULT_COMPILER_LIMITS.maxPortableDepth;
|
|
7
|
+
const SCREEN_SOURCE_LIMITS = Object.freeze({
|
|
8
|
+
maxBytes: 256e3,
|
|
9
|
+
maxDeclarations: 64,
|
|
10
|
+
maxDepth: MAX_SOURCE_DEPTH,
|
|
11
|
+
maxNodes: 5e3,
|
|
12
|
+
maxStringLength: 4096,
|
|
13
|
+
maxDiagnostics: 32
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/parse.ts
|
|
17
|
+
const LAYER_KEYS = new Set([
|
|
18
|
+
"id",
|
|
19
|
+
"priority",
|
|
20
|
+
"defaultNamespace",
|
|
21
|
+
"revision",
|
|
22
|
+
"declarations",
|
|
23
|
+
"transforms"
|
|
26
24
|
]);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"declarations",
|
|
33
|
-
"transforms"
|
|
25
|
+
const DECLARATION_KEYS = new Set([
|
|
26
|
+
"kind",
|
|
27
|
+
"ref",
|
|
28
|
+
"schemaVersion",
|
|
29
|
+
"value"
|
|
34
30
|
]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
const TRANSFORM_KEYS = new Set([
|
|
32
|
+
"id",
|
|
33
|
+
"scope",
|
|
34
|
+
"select",
|
|
35
|
+
"operation"
|
|
36
|
+
]);
|
|
37
|
+
const SELECTOR_KEYS = new Set([
|
|
38
|
+
"kinds",
|
|
39
|
+
"namespaces",
|
|
40
|
+
"layers",
|
|
41
|
+
"refs",
|
|
42
|
+
"excludeRefs",
|
|
43
|
+
"tags"
|
|
44
|
+
]);
|
|
45
|
+
const OPERATION_KEYS = {
|
|
46
|
+
merge: new Set(["op", "value"]),
|
|
47
|
+
replace: new Set([
|
|
48
|
+
"op",
|
|
49
|
+
"value",
|
|
50
|
+
"ifMissing"
|
|
51
|
+
]),
|
|
52
|
+
disable: new Set(["op", "reason"]),
|
|
53
|
+
delete: new Set(["op"])
|
|
43
54
|
};
|
|
44
|
-
|
|
55
|
+
const ATTACHMENT_TAG = "@burojs/core/trusted-attachment";
|
|
45
56
|
var Diagnostics = class {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
limit;
|
|
58
|
+
values = [];
|
|
59
|
+
limited = false;
|
|
60
|
+
constructor(limit) {
|
|
61
|
+
this.limit = limit;
|
|
62
|
+
}
|
|
63
|
+
add(code) {
|
|
64
|
+
if (this.limited) return;
|
|
65
|
+
if (this.values.length + 1 < this.limit) {
|
|
66
|
+
this.values.push(Object.freeze({
|
|
67
|
+
code,
|
|
68
|
+
message: messageFor(code)
|
|
69
|
+
}));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.limited = true;
|
|
73
|
+
this.values.push(Object.freeze({
|
|
74
|
+
code: "source.diagnostic-limit",
|
|
75
|
+
message: messageFor("source.diagnostic-limit")
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
66
78
|
};
|
|
67
79
|
function messageFor(code) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
case "source.forbidden-namespace":
|
|
102
|
-
return "The source requests a forbidden namespace.";
|
|
103
|
-
case "source.forbidden-transform-op":
|
|
104
|
-
return "The source requests a forbidden transform operation.";
|
|
105
|
-
case "source.forbidden-transform-scope":
|
|
106
|
-
return "The source requests a forbidden transform scope.";
|
|
107
|
-
case "source.forbidden-capability":
|
|
108
|
-
return "The source requests a forbidden capability.";
|
|
109
|
-
case "source.forbidden-action":
|
|
110
|
-
return "The source requests a forbidden action binding.";
|
|
111
|
-
case "source.forbidden-provider":
|
|
112
|
-
return "The source requests a forbidden provider binding.";
|
|
113
|
-
case "source.forbidden-mapper":
|
|
114
|
-
return "The source requests a forbidden mapper binding.";
|
|
115
|
-
case "source.forbidden-service":
|
|
116
|
-
return "The source requests a forbidden service value.";
|
|
117
|
-
case "source.forbidden-credential":
|
|
118
|
-
return "The source requests a forbidden credential value.";
|
|
119
|
-
case "source.forbidden-schema":
|
|
120
|
-
return "The source requests a forbidden schema value.";
|
|
121
|
-
case "source.forbidden-component":
|
|
122
|
-
return "The source requests a forbidden component value.";
|
|
123
|
-
case "source.forbidden-attachment":
|
|
124
|
-
return "The source requests a forbidden attachment value.";
|
|
125
|
-
case "source.forbidden-validator":
|
|
126
|
-
return "The source requests a forbidden validator value.";
|
|
127
|
-
default:
|
|
128
|
-
return "The source is invalid.";
|
|
129
|
-
}
|
|
80
|
+
switch (code) {
|
|
81
|
+
case "source.invalid-json": return "The source is not valid JSON.";
|
|
82
|
+
case "source.invalid-yaml": return "The source is not valid YAML.";
|
|
83
|
+
case "source.invalid-policy": return "The source policy is invalid.";
|
|
84
|
+
case "source.byte-limit": return "The source exceeds its byte limit.";
|
|
85
|
+
case "source.declaration-limit": return "The source exceeds its declaration limit.";
|
|
86
|
+
case "source.depth-limit": return "The source exceeds its nesting-depth limit.";
|
|
87
|
+
case "source.node-limit": return "The source exceeds its value-count limit.";
|
|
88
|
+
case "source.string-limit": return "The source contains an overlong string.";
|
|
89
|
+
case "source.diagnostic-limit": return "Additional source diagnostics were omitted.";
|
|
90
|
+
case "source.unknown-key": return "The source contains an unknown key.";
|
|
91
|
+
case "source.reserved-key": return "The source contains a reserved key.";
|
|
92
|
+
case "source.accessor": return "The source must use data properties.";
|
|
93
|
+
case "source.cyclic-value": return "The source must not contain cyclic values.";
|
|
94
|
+
case "source.invalid-layer": return "The source layer is invalid.";
|
|
95
|
+
case "source.invalid-declaration": return "The source declaration is invalid.";
|
|
96
|
+
case "source.invalid-transform": return "The source transform is invalid.";
|
|
97
|
+
case "source.forbidden-kind": return "The source requests a forbidden declaration kind.";
|
|
98
|
+
case "source.forbidden-namespace": return "The source requests a forbidden namespace.";
|
|
99
|
+
case "source.forbidden-transform-op": return "The source requests a forbidden transform operation.";
|
|
100
|
+
case "source.forbidden-transform-scope": return "The source requests a forbidden transform scope.";
|
|
101
|
+
case "source.forbidden-capability": return "The source requests a forbidden capability.";
|
|
102
|
+
case "source.forbidden-action": return "The source requests a forbidden action binding; a resource's flows are written under toolbar.";
|
|
103
|
+
case "source.forbidden-provider": return "The source requests a forbidden provider binding.";
|
|
104
|
+
case "source.forbidden-mapper": return "The source requests a forbidden mapper binding.";
|
|
105
|
+
case "source.forbidden-service": return "The source requests a forbidden service value.";
|
|
106
|
+
case "source.forbidden-credential": return "The source requests a forbidden credential value.";
|
|
107
|
+
case "source.forbidden-schema": return "The source requests a forbidden schema value.";
|
|
108
|
+
case "source.forbidden-component": return "The source requests a forbidden component value.";
|
|
109
|
+
case "source.forbidden-attachment": return "The source requests a forbidden attachment value.";
|
|
110
|
+
case "source.forbidden-validator": return "The source requests a forbidden validator value.";
|
|
111
|
+
default: return "The source is invalid.";
|
|
112
|
+
}
|
|
130
113
|
}
|
|
114
|
+
const LIMIT_KEYS = [
|
|
115
|
+
"maxBytes",
|
|
116
|
+
"maxDeclarations",
|
|
117
|
+
"maxDepth",
|
|
118
|
+
"maxNodes",
|
|
119
|
+
"maxStringLength",
|
|
120
|
+
"maxDiagnostics"
|
|
121
|
+
];
|
|
122
|
+
const LIMIT_KEY_SET = new Set(LIMIT_KEYS);
|
|
131
123
|
function validLimits(limits) {
|
|
132
|
-
|
|
124
|
+
return plainObject(limits) && Object.keys(limits).every((key) => LIMIT_KEY_SET.has(key)) && LIMIT_KEYS.every((key) => Number.isSafeInteger(limits[key]) && limits[key] > 0);
|
|
133
125
|
}
|
|
134
126
|
function validCapabilities(value) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Object.values(value).every((capabilities) => Array.isArray(capabilities) && capabilities.every((capability) => typeof capability === "string"));
|
|
128
|
+
}
|
|
129
|
+
function grantsError(policy) {
|
|
130
|
+
try {
|
|
131
|
+
(0, _burojs_core.normalizeLayerGrants)(policy.grants);
|
|
132
|
+
return;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return error instanceof TypeError ? error.message : "";
|
|
135
|
+
}
|
|
138
136
|
}
|
|
139
|
-
function
|
|
140
|
-
|
|
137
|
+
function policyDiagnostic(policy) {
|
|
138
|
+
const generic = messageFor("source.invalid-policy");
|
|
139
|
+
const stray = strayPolicyKey(policy);
|
|
140
|
+
if (stray !== void 0) return Object.freeze({
|
|
141
|
+
code: "source.invalid-policy",
|
|
142
|
+
message: `The source policy is invalid: it carries ${stray} at the top level; a policy is { grants, allowedCapabilities, limits }, with every grant field inside grants.`
|
|
143
|
+
});
|
|
144
|
+
if (!validPolicyShape(policy)) return Object.freeze({
|
|
145
|
+
code: "source.invalid-policy",
|
|
146
|
+
message: generic
|
|
147
|
+
});
|
|
148
|
+
const reason = grantsError(policy);
|
|
149
|
+
if (reason === void 0) return void 0;
|
|
150
|
+
return Object.freeze({
|
|
151
|
+
code: "source.invalid-policy",
|
|
152
|
+
message: reason === "" ? generic : `The source policy is invalid: ${reason}`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const POLICY_KEYS = new Set([
|
|
156
|
+
"grants",
|
|
157
|
+
"allowedCapabilities",
|
|
158
|
+
"limits"
|
|
159
|
+
]);
|
|
160
|
+
function strayPolicyKey(policy) {
|
|
161
|
+
return plainObject(policy) ? Object.keys(policy).find((key) => !POLICY_KEYS.has(key)) : void 0;
|
|
162
|
+
}
|
|
163
|
+
function validPolicyShape(policy) {
|
|
164
|
+
return plainObject(policy) && plainObject(policy.grants) && validCapabilities(policy.allowedCapabilities) && validLimits(policy.limits);
|
|
165
|
+
}
|
|
166
|
+
function ownedPolicy(policy) {
|
|
167
|
+
const invalid = policyDiagnostic(policy);
|
|
168
|
+
if (invalid !== void 0) throw new TypeError(invalid.message);
|
|
169
|
+
const capabilities = Object.create(null);
|
|
170
|
+
for (const [kind, values] of Object.entries(policy.allowedCapabilities)) capabilities[kind] = Object.freeze([...values]);
|
|
171
|
+
return Object.freeze({
|
|
172
|
+
grants: (0, _burojs_core.normalizeLayerGrants)(policy.grants),
|
|
173
|
+
allowedCapabilities: Object.freeze(capabilities),
|
|
174
|
+
limits: Object.freeze({ ...policy.limits })
|
|
175
|
+
});
|
|
141
176
|
}
|
|
142
177
|
function failure(diagnostics) {
|
|
143
|
-
|
|
178
|
+
return {
|
|
179
|
+
ok: false,
|
|
180
|
+
diagnostics: Object.freeze(diagnostics.values)
|
|
181
|
+
};
|
|
144
182
|
}
|
|
145
183
|
function plainObject(value) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
185
|
+
const prototype = Object.getPrototypeOf(value);
|
|
186
|
+
return prototype === Object.prototype || prototype === null;
|
|
149
187
|
}
|
|
150
188
|
function ownData(value, key) {
|
|
151
|
-
|
|
152
|
-
|
|
189
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
190
|
+
return descriptor !== void 0 && "value" in descriptor ? descriptor.value : void 0;
|
|
153
191
|
}
|
|
154
192
|
function hasData(value, key) {
|
|
155
|
-
|
|
156
|
-
|
|
193
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
194
|
+
return descriptor !== void 0 && "value" in descriptor;
|
|
195
|
+
}
|
|
196
|
+
const MAX_ENVELOPE_DEPTH = 8;
|
|
197
|
+
function childRole(role, key) {
|
|
198
|
+
switch (role) {
|
|
199
|
+
case "root": return key === "declarations" ? "declarations" : key === "transforms" ? "transforms" : "envelope";
|
|
200
|
+
case "declarations": return "declaration";
|
|
201
|
+
case "transforms": return "transform";
|
|
202
|
+
case "declaration": return key === "value" ? "value" : "envelope";
|
|
203
|
+
case "transform": return key === "operation" ? "operation" : "envelope";
|
|
204
|
+
case "operation": return key === "value" ? "value" : "envelope";
|
|
205
|
+
default: return role;
|
|
206
|
+
}
|
|
157
207
|
}
|
|
158
208
|
function clonePortable(value, limits, diagnostics) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
209
|
+
const ancestors = new WeakSet();
|
|
210
|
+
const maxDepth = Math.min(limits.maxDepth, MAX_SOURCE_DEPTH);
|
|
211
|
+
let nodes = 0;
|
|
212
|
+
let nodesExceeded = false;
|
|
213
|
+
function overNodeBudget(children) {
|
|
214
|
+
if (children <= limits.maxNodes - nodes) return false;
|
|
215
|
+
if (!nodesExceeded) diagnostics.add("source.node-limit");
|
|
216
|
+
nodesExceeded = true;
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
function copy(current, depth, role) {
|
|
220
|
+
nodes += 1;
|
|
221
|
+
if (nodes > limits.maxNodes) {
|
|
222
|
+
if (!nodesExceeded) diagnostics.add("source.node-limit");
|
|
223
|
+
nodesExceeded = true;
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
if (depth > (role === "value" ? maxDepth : MAX_ENVELOPE_DEPTH)) {
|
|
227
|
+
diagnostics.add("source.depth-limit");
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
if (current === null || typeof current === "boolean" || typeof current === "number") return current;
|
|
231
|
+
if (typeof current === "string") {
|
|
232
|
+
if ([...current].length > limits.maxStringLength) diagnostics.add("source.string-limit");
|
|
233
|
+
return current;
|
|
234
|
+
}
|
|
235
|
+
if (typeof current !== "object") {
|
|
236
|
+
diagnostics.add("source.invalid-layer");
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
if (ancestors.has(current)) {
|
|
240
|
+
diagnostics.add("source.cyclic-value");
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
ancestors.add(current);
|
|
244
|
+
if (Array.isArray(current)) {
|
|
245
|
+
const output = [];
|
|
246
|
+
const length = ownData(current, "length");
|
|
247
|
+
const arrayLength = typeof length === "number" && Number.isSafeInteger(length) && length >= 0 ? length : void 0;
|
|
248
|
+
if (arrayLength !== void 0 && overNodeBudget(arrayLength)) {
|
|
249
|
+
ancestors.delete(current);
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
for (const key of Reflect.ownKeys(current)) {
|
|
253
|
+
if (typeof key !== "string" || key !== "length" && !/^(0|[1-9]\d*)$/u.test(key)) {
|
|
254
|
+
diagnostics.add("source.invalid-layer");
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (key === "length") continue;
|
|
258
|
+
if (!hasData(current, key)) diagnostics.add("source.accessor");
|
|
259
|
+
}
|
|
260
|
+
if (arrayLength === void 0) diagnostics.add("source.invalid-layer");
|
|
261
|
+
else for (let index = 0; index < arrayLength && !nodesExceeded; index += 1) {
|
|
262
|
+
if (!hasData(current, String(index))) diagnostics.add("source.accessor");
|
|
263
|
+
output.push(copy(ownData(current, String(index)), depth + 1, childRole(role, void 0)));
|
|
264
|
+
}
|
|
265
|
+
ancestors.delete(current);
|
|
266
|
+
return Object.freeze(output);
|
|
267
|
+
}
|
|
268
|
+
if (!plainObject(current)) diagnostics.add("source.invalid-layer");
|
|
269
|
+
const output = Object.create(null);
|
|
270
|
+
const keys = Reflect.ownKeys(current);
|
|
271
|
+
if (overNodeBudget(keys.length)) {
|
|
272
|
+
ancestors.delete(current);
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
for (const key of keys) {
|
|
276
|
+
if (nodesExceeded) break;
|
|
277
|
+
if (typeof key !== "string") {
|
|
278
|
+
diagnostics.add("source.invalid-layer");
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if ((0, _burojs_core_internal.isReservedSegment)(key)) diagnostics.add("source.reserved-key");
|
|
282
|
+
if ([...key].length > limits.maxStringLength) diagnostics.add("source.string-limit");
|
|
283
|
+
if (!hasData(current, key)) {
|
|
284
|
+
diagnostics.add("source.accessor");
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const next = childRole(role, key);
|
|
288
|
+
const nextDepth = next === "value" && role !== "value" ? 0 : depth + 1;
|
|
289
|
+
output[key] = copy(ownData(current, key), nextDepth, next);
|
|
290
|
+
}
|
|
291
|
+
ancestors.delete(current);
|
|
292
|
+
return Object.freeze(output);
|
|
293
|
+
}
|
|
294
|
+
return copy(value, 0, "root");
|
|
220
295
|
}
|
|
221
296
|
function unknownKeys(value, allowed, diagnostics) {
|
|
222
|
-
|
|
223
|
-
if (!allowed.has(key)) diagnostics.add("source.unknown-key");
|
|
297
|
+
for (const key of Object.keys(value)) if (!allowed.has(key)) diagnostics.add("source.unknown-key");
|
|
224
298
|
}
|
|
225
299
|
function allowedNamespace(value, policy, diagnostics) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
300
|
+
if (typeof value !== "string" || !policy.grants.allowedNamespaces.includes(value)) {
|
|
301
|
+
diagnostics.add("source.forbidden-namespace");
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
return true;
|
|
231
305
|
}
|
|
232
306
|
function namespaceFor(ref, defaultNamespace, diagnostics) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return typeof namespace === "string" ? namespace : void 0;
|
|
307
|
+
if (typeof ref === "string") {
|
|
308
|
+
const separator = ref.indexOf(":");
|
|
309
|
+
return separator === -1 ? defaultNamespace : ref.slice(0, separator);
|
|
310
|
+
}
|
|
311
|
+
if (!plainObject(ref) || !hasData(ref, "id")) {
|
|
312
|
+
diagnostics.add("source.invalid-declaration");
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
for (const key of Object.keys(ref)) if (key !== "id" && key !== "namespace") diagnostics.add("source.unknown-key");
|
|
316
|
+
const namespace = hasData(ref, "namespace") ? ownData(ref, "namespace") : defaultNamespace;
|
|
317
|
+
if (typeof namespace !== "string") diagnostics.add("source.invalid-declaration");
|
|
318
|
+
return typeof namespace === "string" ? namespace : void 0;
|
|
246
319
|
}
|
|
247
320
|
function validateValue(value, kind, policy, diagnostics) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function scopeRank(scope) {
|
|
267
|
-
return scope === "layer" ? 0 : scope === "namespace" ? 1 : 2;
|
|
321
|
+
if (value === null || typeof value !== "object") return;
|
|
322
|
+
if (Array.isArray(value)) {
|
|
323
|
+
for (const item of value) validateValue(item, kind, policy, diagnostics);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (!plainObject(value)) return;
|
|
327
|
+
if (value.$buro === ATTACHMENT_TAG) {
|
|
328
|
+
const capability = ownData(value, "capability");
|
|
329
|
+
const allowed = Object.hasOwn(policy.allowedCapabilities, kind) ? policy.allowedCapabilities[kind] : void 0;
|
|
330
|
+
if (typeof capability !== "string" || !allowed?.includes(capability)) diagnostics.add("source.forbidden-capability");
|
|
331
|
+
}
|
|
332
|
+
for (const key of Object.keys(value)) {
|
|
333
|
+
const category = (0, _burojs_core_internal.blacklistedKeyCategory)(key);
|
|
334
|
+
if (category !== void 0) diagnostics.add(`source.forbidden-${category}`);
|
|
335
|
+
validateValue(ownData(value, key), kind, policy, diagnostics);
|
|
336
|
+
}
|
|
268
337
|
}
|
|
269
338
|
function transformOperation(value) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
339
|
+
if (!plainObject(value)) return void 0;
|
|
340
|
+
const operation = ownData(value, "op");
|
|
341
|
+
return operation === "merge" || operation === "replace" || operation === "disable" || operation === "delete" ? operation : void 0;
|
|
273
342
|
}
|
|
274
343
|
function validateSelectorRefs(value, defaultNamespace, policy, diagnostics) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
344
|
+
if (value === void 0) return;
|
|
345
|
+
if (!Array.isArray(value)) {
|
|
346
|
+
diagnostics.add("source.invalid-transform");
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
for (const ref of value) {
|
|
350
|
+
const namespace = namespaceFor(ref, defaultNamespace, diagnostics);
|
|
351
|
+
if (namespace !== void 0) allowedNamespace(namespace, policy, diagnostics);
|
|
352
|
+
}
|
|
284
353
|
}
|
|
285
354
|
function validateTransforms(value, defaultNamespace, policy, diagnostics) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
else {
|
|
331
|
-
if (!policy.allowedTransformOps.includes(op))
|
|
332
|
-
diagnostics.add("source.forbidden-transform-op");
|
|
333
|
-
if (plainObject(operation)) {
|
|
334
|
-
unknownKeys(operation, OPERATION_KEYS[op], diagnostics);
|
|
335
|
-
if (hasData(operation, "value"))
|
|
336
|
-
validateValue(ownData(operation, "value"), "", policy, diagnostics);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
355
|
+
if (value === void 0) return;
|
|
356
|
+
if (!Array.isArray(value)) {
|
|
357
|
+
diagnostics.add("source.invalid-transform");
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
for (const transform of value) {
|
|
361
|
+
if (!plainObject(transform)) {
|
|
362
|
+
diagnostics.add("source.invalid-transform");
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
unknownKeys(transform, TRANSFORM_KEYS, diagnostics);
|
|
366
|
+
const scope = ownData(transform, "scope") ?? "layer";
|
|
367
|
+
if (scope !== "layer" && scope !== "application") diagnostics.add("source.invalid-transform");
|
|
368
|
+
else if ((0, _burojs_core_internal.scopeRank)(scope) > (0, _burojs_core_internal.scopeRank)(policy.grants.maxTransformScope)) diagnostics.add("source.forbidden-transform-scope");
|
|
369
|
+
const select = ownData(transform, "select");
|
|
370
|
+
if (!plainObject(select)) diagnostics.add("source.invalid-transform");
|
|
371
|
+
else {
|
|
372
|
+
unknownKeys(select, SELECTOR_KEYS, diagnostics);
|
|
373
|
+
const selectedKinds = ownData(select, "kinds");
|
|
374
|
+
if (selectedKinds !== void 0) {
|
|
375
|
+
if (!Array.isArray(selectedKinds)) diagnostics.add("source.invalid-transform");
|
|
376
|
+
else for (const kind of selectedKinds) if (typeof kind !== "string") diagnostics.add("source.invalid-transform");
|
|
377
|
+
else if (!policy.grants.allowedKinds.includes(kind)) diagnostics.add("source.forbidden-kind");
|
|
378
|
+
}
|
|
379
|
+
const selectedNamespaces = ownData(select, "namespaces");
|
|
380
|
+
if (selectedNamespaces !== void 0) {
|
|
381
|
+
if (!Array.isArray(selectedNamespaces)) diagnostics.add("source.invalid-transform");
|
|
382
|
+
else for (const namespace of selectedNamespaces) allowedNamespace(namespace, policy, diagnostics);
|
|
383
|
+
}
|
|
384
|
+
validateSelectorRefs(ownData(select, "refs"), defaultNamespace, policy, diagnostics);
|
|
385
|
+
validateSelectorRefs(ownData(select, "excludeRefs"), defaultNamespace, policy, diagnostics);
|
|
386
|
+
}
|
|
387
|
+
const operation = ownData(transform, "operation");
|
|
388
|
+
const op = transformOperation(operation);
|
|
389
|
+
if (typeof (plainObject(operation) ? ownData(operation, "op") : void 0) === "string" && op === void 0) diagnostics.add("source.forbidden-transform-op");
|
|
390
|
+
else if (op === void 0) diagnostics.add("source.invalid-transform");
|
|
391
|
+
else {
|
|
392
|
+
if (!policy.grants.allowedTransformOps.includes(op)) diagnostics.add("source.forbidden-transform-op");
|
|
393
|
+
if (plainObject(operation)) {
|
|
394
|
+
unknownKeys(operation, OPERATION_KEYS[op], diagnostics);
|
|
395
|
+
if (hasData(operation, "value")) validateValue(ownData(operation, "value"), "", policy, diagnostics);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
340
399
|
}
|
|
341
400
|
function validateLayerValue(value, policy) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
);
|
|
388
|
-
if (namespace !== void 0) allowedNamespace(namespace, policy, diagnostics);
|
|
389
|
-
if (!Number.isSafeInteger(ownData(declaration, "schemaVersion")) || !hasData(declaration, "value")) {
|
|
390
|
-
diagnostics.add("source.invalid-declaration");
|
|
391
|
-
}
|
|
392
|
-
if (typeof kind === "string" && hasData(declaration, "value")) {
|
|
393
|
-
validateValue(ownData(declaration, "value"), kind, policy, diagnostics);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
validateTransforms(
|
|
397
|
-
ownData(cloned, "transforms"),
|
|
398
|
-
typeof defaultNamespace === "string" ? defaultNamespace : "default",
|
|
399
|
-
policy,
|
|
400
|
-
diagnostics
|
|
401
|
-
);
|
|
402
|
-
if (diagnostics.values.length > 0) return failure(diagnostics);
|
|
403
|
-
return { ok: true, value: cloned };
|
|
401
|
+
const invalidPolicy = policyDiagnostic(policy);
|
|
402
|
+
if (invalidPolicy !== void 0) return {
|
|
403
|
+
ok: false,
|
|
404
|
+
diagnostics: Object.freeze([invalidPolicy])
|
|
405
|
+
};
|
|
406
|
+
const diagnostics = new Diagnostics(policy.limits.maxDiagnostics);
|
|
407
|
+
const cloned = clonePortable(value, policy.limits, diagnostics);
|
|
408
|
+
if (diagnostics.values.length > 0) return failure(diagnostics);
|
|
409
|
+
if (!plainObject(cloned)) {
|
|
410
|
+
diagnostics.add("source.invalid-layer");
|
|
411
|
+
return failure(diagnostics);
|
|
412
|
+
}
|
|
413
|
+
unknownKeys(cloned, LAYER_KEYS, diagnostics);
|
|
414
|
+
const id = ownData(cloned, "id");
|
|
415
|
+
const priority = ownData(cloned, "priority");
|
|
416
|
+
const declarations = ownData(cloned, "declarations");
|
|
417
|
+
if (typeof id !== "string" || !Number.isSafeInteger(priority) || !Array.isArray(declarations)) {
|
|
418
|
+
diagnostics.add("source.invalid-layer");
|
|
419
|
+
return failure(diagnostics);
|
|
420
|
+
}
|
|
421
|
+
if (declarations.length > policy.limits.maxDeclarations) diagnostics.add("source.declaration-limit");
|
|
422
|
+
const rawDefaultNamespace = ownData(cloned, "defaultNamespace");
|
|
423
|
+
const defaultNamespace = rawDefaultNamespace === void 0 ? "default" : rawDefaultNamespace;
|
|
424
|
+
if (typeof defaultNamespace !== "string") diagnostics.add("source.invalid-layer");
|
|
425
|
+
else allowedNamespace(defaultNamespace, policy, diagnostics);
|
|
426
|
+
for (const declaration of declarations) {
|
|
427
|
+
if (!plainObject(declaration)) {
|
|
428
|
+
diagnostics.add("source.invalid-declaration");
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
unknownKeys(declaration, DECLARATION_KEYS, diagnostics);
|
|
432
|
+
const kind = ownData(declaration, "kind");
|
|
433
|
+
if (typeof kind !== "string") diagnostics.add("source.invalid-declaration");
|
|
434
|
+
else if (!policy.grants.allowedKinds.includes(kind)) diagnostics.add("source.forbidden-kind");
|
|
435
|
+
const namespace = namespaceFor(ownData(declaration, "ref"), typeof defaultNamespace === "string" ? defaultNamespace : "default", diagnostics);
|
|
436
|
+
if (namespace !== void 0) allowedNamespace(namespace, policy, diagnostics);
|
|
437
|
+
if (!Number.isSafeInteger(ownData(declaration, "schemaVersion")) || !hasData(declaration, "value")) diagnostics.add("source.invalid-declaration");
|
|
438
|
+
if (typeof kind === "string" && hasData(declaration, "value")) validateValue(ownData(declaration, "value"), kind, policy, diagnostics);
|
|
439
|
+
}
|
|
440
|
+
validateTransforms(ownData(cloned, "transforms"), typeof defaultNamespace === "string" ? defaultNamespace : "default", policy, diagnostics);
|
|
441
|
+
if (diagnostics.values.length > 0) return failure(diagnostics);
|
|
442
|
+
return {
|
|
443
|
+
ok: true,
|
|
444
|
+
value: (0, _burojs_core_internal.createParsedLayer)(cloned, (0, _burojs_core.normalizeLayerGrants)(policy.grants))
|
|
445
|
+
};
|
|
404
446
|
}
|
|
405
447
|
function byteLength(value) {
|
|
406
|
-
|
|
448
|
+
return new TextEncoder().encode(value).byteLength;
|
|
407
449
|
}
|
|
408
450
|
function parseSource(source, policy, format) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
451
|
+
if (policyDiagnostic(policy) !== void 0) return validateLayerValue(null, policy);
|
|
452
|
+
const diagnostics = new Diagnostics(policy.limits.maxDiagnostics);
|
|
453
|
+
if (byteLength(source) > policy.limits.maxBytes) {
|
|
454
|
+
diagnostics.add("source.byte-limit");
|
|
455
|
+
return failure(diagnostics);
|
|
456
|
+
}
|
|
457
|
+
try {
|
|
458
|
+
if (format === "json") return validateLayerValue(JSON.parse(source), policy);
|
|
459
|
+
const document = (0, yaml.parseDocument)(source, {
|
|
460
|
+
prettyErrors: false,
|
|
461
|
+
strict: true,
|
|
462
|
+
uniqueKeys: true
|
|
463
|
+
});
|
|
464
|
+
if (document.errors.length > 0) {
|
|
465
|
+
diagnostics.add("source.invalid-yaml");
|
|
466
|
+
return failure(diagnostics);
|
|
467
|
+
}
|
|
468
|
+
return validateLayerValue(document.toJS({ maxAliasCount: 0 }), policy);
|
|
469
|
+
} catch {
|
|
470
|
+
diagnostics.add(format === "json" ? "source.invalid-json" : "source.invalid-yaml");
|
|
471
|
+
return failure(diagnostics);
|
|
472
|
+
}
|
|
427
473
|
}
|
|
428
474
|
function parseJsonLayer(source, policy) {
|
|
429
|
-
|
|
475
|
+
return parseSource(source, policy, "json");
|
|
430
476
|
}
|
|
431
477
|
function parseYamlLayer(source, policy) {
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// src/adapter.ts
|
|
436
|
-
function diagnostic(code, message) {
|
|
437
|
-
return Object.freeze({ code, message });
|
|
438
|
-
}
|
|
439
|
-
function diagnosticLimit(policy) {
|
|
440
|
-
const candidate = policy?.limits?.maxDiagnostics;
|
|
441
|
-
return typeof candidate === "number" && Number.isSafeInteger(candidate) && candidate > 0 ? candidate : 1;
|
|
442
|
-
}
|
|
443
|
-
function frozenPolicy(policy) {
|
|
444
|
-
const capabilities = /* @__PURE__ */ Object.create(null);
|
|
445
|
-
for (const [kind, values] of Object.entries(policy.allowedCapabilities)) {
|
|
446
|
-
capabilities[kind] = Object.freeze([...values]);
|
|
447
|
-
}
|
|
448
|
-
const limits = Object.freeze({ ...policy.limits });
|
|
449
|
-
return Object.freeze({
|
|
450
|
-
allowedKinds: Object.freeze([...policy.allowedKinds]),
|
|
451
|
-
allowedNamespaces: Object.freeze([...policy.allowedNamespaces]),
|
|
452
|
-
allowedTransformOps: Object.freeze([...policy.allowedTransformOps]),
|
|
453
|
-
maxTransformScope: policy.maxTransformScope,
|
|
454
|
-
allowedCapabilities: Object.freeze(capabilities),
|
|
455
|
-
limits
|
|
456
|
-
});
|
|
478
|
+
return parseSource(source, policy, "yaml");
|
|
457
479
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
return diagnostic(
|
|
466
|
-
"source.invalid-adapter-diagnostic",
|
|
467
|
-
"The source adapter returned an invalid diagnostic."
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
function adaptRawConfig(input, adapter, policy) {
|
|
471
|
-
const policyValidation = validateLayerValue(null, policy);
|
|
472
|
-
if (!policyValidation.ok && policyValidation.diagnostics.some((entry) => entry.code === "source.invalid-policy")) {
|
|
473
|
-
return policyValidation;
|
|
474
|
-
}
|
|
475
|
-
const ownedPolicy = frozenPolicy(policy);
|
|
476
|
-
const diagnostics = [];
|
|
477
|
-
const maxDiagnostics = diagnosticLimit(ownedPolicy);
|
|
478
|
-
let limited = false;
|
|
479
|
-
const add = (value) => {
|
|
480
|
-
if (limited) return;
|
|
481
|
-
if (diagnostics.length + 1 < maxDiagnostics) {
|
|
482
|
-
diagnostics.push(value);
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
limited = true;
|
|
486
|
-
diagnostics.push(
|
|
487
|
-
diagnostic("source.diagnostic-limit", "Additional source diagnostics were omitted.")
|
|
488
|
-
);
|
|
489
|
-
};
|
|
490
|
-
const context = Object.freeze({
|
|
491
|
-
policy: ownedPolicy,
|
|
492
|
-
limits: ownedPolicy.limits,
|
|
493
|
-
diagnose(code, message) {
|
|
494
|
-
add(copyDiagnostic({ code, message }));
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
const result = adapter.adapt(input, context);
|
|
498
|
-
if (result === null || typeof result !== "object") {
|
|
499
|
-
add(
|
|
500
|
-
diagnostic("source.invalid-adapter-result", "The source adapter returned an invalid result.")
|
|
501
|
-
);
|
|
502
|
-
} else if (result.diagnostics !== void 0) {
|
|
503
|
-
if (!Array.isArray(result.diagnostics)) {
|
|
504
|
-
add(
|
|
505
|
-
diagnostic(
|
|
506
|
-
"source.invalid-adapter-result",
|
|
507
|
-
"The source adapter returned an invalid result."
|
|
508
|
-
)
|
|
509
|
-
);
|
|
510
|
-
} else {
|
|
511
|
-
for (const entry of result.diagnostics) add(copyDiagnostic(entry));
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
if (diagnostics.length > 0) {
|
|
515
|
-
return { ok: false, diagnostics: Object.freeze(diagnostics) };
|
|
516
|
-
}
|
|
517
|
-
if (result === null || typeof result !== "object" || result.layer === void 0) {
|
|
518
|
-
return {
|
|
519
|
-
ok: false,
|
|
520
|
-
diagnostics: Object.freeze([
|
|
521
|
-
diagnostic(
|
|
522
|
-
"source.invalid-adapter-result",
|
|
523
|
-
"The source adapter did not return a declaration layer."
|
|
524
|
-
)
|
|
525
|
-
])
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
return validateLayerValue(result.layer, ownedPolicy);
|
|
529
|
-
}
|
|
530
|
-
var parseResultAdapter = Object.freeze({
|
|
531
|
-
adapt(input) {
|
|
532
|
-
return input.ok ? { layer: input.value } : { diagnostics: input.diagnostics };
|
|
533
|
-
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/runtime-source.ts
|
|
482
|
+
const INVALID_FORMAT = Object.freeze({
|
|
483
|
+
code: "source.invalid-format",
|
|
484
|
+
message: "The source format must be json or yaml."
|
|
534
485
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
});
|
|
486
|
+
function rejection(diagnostics) {
|
|
487
|
+
return Object.freeze({
|
|
488
|
+
status: "rejected",
|
|
489
|
+
diagnostics: Object.freeze(diagnostics.map((entry) => Object.freeze({
|
|
490
|
+
code: entry.code,
|
|
491
|
+
message: entry.message
|
|
492
|
+
})))
|
|
493
|
+
});
|
|
544
494
|
}
|
|
545
|
-
function createConfigRuntimeSource(id,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
495
|
+
function createConfigRuntimeSource(id, options) {
|
|
496
|
+
const policy = ownedPolicy(options.policy);
|
|
497
|
+
const { load } = options;
|
|
498
|
+
const source = Object.freeze({
|
|
499
|
+
id,
|
|
500
|
+
async load(context) {
|
|
501
|
+
const raw = await load(context);
|
|
502
|
+
const parsed = raw.format === "json" ? parseJsonLayer(raw.text, policy) : raw.format === "yaml" ? parseYamlLayer(raw.text, policy) : void 0;
|
|
503
|
+
if (parsed === void 0) return rejection([INVALID_FORMAT]);
|
|
504
|
+
return parsed.ok ? parsed.value : rejection(parsed.diagnostics);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return Object.freeze({
|
|
508
|
+
source,
|
|
509
|
+
trust: policy.grants
|
|
510
|
+
});
|
|
555
511
|
}
|
|
556
|
-
|
|
557
|
-
exports.
|
|
512
|
+
//#endregion
|
|
513
|
+
exports.MAX_SOURCE_DEPTH = MAX_SOURCE_DEPTH;
|
|
514
|
+
exports.SCREEN_SOURCE_LIMITS = SCREEN_SOURCE_LIMITS;
|
|
558
515
|
exports.createConfigRuntimeSource = createConfigRuntimeSource;
|
|
559
516
|
exports.parseJsonLayer = parseJsonLayer;
|
|
560
|
-
exports.parseResultAdapter = parseResultAdapter;
|
|
561
517
|
exports.parseYamlLayer = parseYamlLayer;
|
|
562
|
-
|
|
518
|
+
|
|
563
519
|
//# sourceMappingURL=index.cjs.map
|