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