@okfit/core 0.14.0 → 0.16.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/Actor.js +1 -1
- package/AttestedComputation.js +3 -3
- package/Bundle.js +114 -14
- package/Concept.js +40 -2
- package/ConfinedRead.js +113 -0
- package/Derive.js +80 -14
- package/Diagnostic.js +31 -4
- package/Generated.js +1 -1
- package/GeneratedAtFuture.js +43 -0
- package/Graph.js +47 -12
- package/IndexDocument.js +11 -2
- package/Integrity.js +13 -2
- package/LogDocument.js +3 -1
- package/OkfVersion.js +43 -0
- package/OkfitConfig.js +173 -18
- package/README.md +4 -2
- package/Source.js +2 -2
- package/Status.js +12 -1
- package/Timestamp.js +12 -5
- package/Validate.js +1 -0
- package/index.d.ts +416 -36
- package/index.js +8 -5
- package/internal/conceptDecode.js +245 -32
- package/internal/frontmatter.js +20 -7
- package/internal/linkScan.js +57 -0
- package/internal/links.js +10 -8
- package/internal/lintRules.js +178 -30
- package/internal/reserved.js +50 -9
- package/internal/templates.js +27 -5
- package/internal/tier.js +7 -0
- package/internal/walk.js +1 -0
- package/internal/yamlPathSpan.js +82 -4
- package/package.json +6 -6
- package/tsdoc-metadata.json +1 -1
package/index.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { Actor, ActorPattern } from "./Actor.js";
|
|
2
2
|
import { AttestedComputation, ComputationAttester, ComputationExecutor, ComputationParameter } from "./AttestedComputation.js";
|
|
3
3
|
import { Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, LoadedBundle, LoadedConcept } from "./Bundle.js";
|
|
4
|
-
import { ATTESTED_COMPUTATION_TYPE, Concept } from "./Concept.js";
|
|
4
|
+
import { ATTESTED_COMPUTATION_TYPE, Concept, EntryPaths } from "./Concept.js";
|
|
5
5
|
import { ConceptId } from "./ConceptId.js";
|
|
6
|
+
import { ConfinementError, changedWhileRead, readConfinedBytes, readConfinedString } from "./ConfinedRead.js";
|
|
6
7
|
import { Derive, Staleness, TrustTier } from "./Derive.js";
|
|
7
8
|
import { ConformanceCode, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, LintCode } from "./Diagnostic.js";
|
|
8
9
|
import { Generated } from "./Generated.js";
|
|
10
|
+
import { GENERATED_AT_TOLERANCE, GENERATED_AT_TOLERANCE_TEXT, generatedAtIsFuture, verificationBlockingRestamp } from "./GeneratedAtFuture.js";
|
|
9
11
|
import { Graph, GraphNodeKind, LinkGraph } from "./Graph.js";
|
|
10
12
|
import { IndexDocument, IndexEntry, IndexSection } from "./IndexDocument.js";
|
|
11
|
-
import { Digest, Integrity, IntegrityGenerated, IntegrityVerified } from "./Integrity.js";
|
|
13
|
+
import { Digest, INTEGRITY_KEY, Integrity, IntegrityGenerated, IntegrityVerified, OKFIT_KEY_PREFIX } from "./Integrity.js";
|
|
12
14
|
import { LogDocument, LogGroup, LogItem } from "./LogDocument.js";
|
|
13
15
|
import { CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigSchemaHost } from "./OkfitConfig.js";
|
|
16
|
+
import { OkfVersion } from "./OkfVersion.js";
|
|
14
17
|
import { Source, UsageWindow } from "./Source.js";
|
|
15
|
-
import { Status } from "./Status.js";
|
|
18
|
+
import { DerivedStatus, Status } from "./Status.js";
|
|
16
19
|
import { Timestamp } from "./Timestamp.js";
|
|
17
20
|
import { Validate } from "./Validate.js";
|
|
18
21
|
import { Verification } from "./Verification.js";
|
|
@@ -23,6 +26,6 @@ import { Verification } from "./Verification.js";
|
|
|
23
26
|
*
|
|
24
27
|
* @public
|
|
25
28
|
*/
|
|
26
|
-
const OKF_SPEC_VERSION = "0.
|
|
29
|
+
const OKF_SPEC_VERSION = "0.3";
|
|
27
30
|
|
|
28
|
-
export { ATTESTED_COMPUTATION_TYPE, Actor, ActorPattern, AttestedComputation, Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, CONFIG_SCHEMA_VERSION, ComputationAttester, ComputationExecutor, ComputationParameter, Concept, ConceptId, ConformanceCode, Derive, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, Digest, FieldDeclaration, Generated, Graph, GraphNodeKind, IndexDocument, IndexEntry, IndexSection, Integrity, IntegrityGenerated, IntegrityVerified, LinkGraph, LintCode, LintLevel, LintTable, LoadedBundle, LoadedConcept, LogDocument, LogGroup, LogItem, OKF_SPEC_VERSION, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, Source, StaleAfterDuration, Staleness, Status, TagDeclaration, Timestamp, TrustTier, TypeDeclaration, UsageWindow, Validate, Verification, okfitConfigDocumentFields, okfitConfigSchemaHost };
|
|
31
|
+
export { ATTESTED_COMPUTATION_TYPE, Actor, ActorPattern, AttestedComputation, Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, CONFIG_SCHEMA_VERSION, ComputationAttester, ComputationExecutor, ComputationParameter, Concept, ConceptId, ConfinementError, ConformanceCode, Derive, DerivedStatus, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, Digest, EntryPaths, FieldDeclaration, GENERATED_AT_TOLERANCE, GENERATED_AT_TOLERANCE_TEXT, Generated, Graph, GraphNodeKind, INTEGRITY_KEY, IndexDocument, IndexEntry, IndexSection, Integrity, IntegrityGenerated, IntegrityVerified, LinkGraph, LintCode, LintLevel, LintTable, LoadedBundle, LoadedConcept, LogDocument, LogGroup, LogItem, OKFIT_KEY_PREFIX, OKF_SPEC_VERSION, OkfVersion, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, Source, StaleAfterDuration, Staleness, Status, TagDeclaration, Timestamp, TrustTier, TypeDeclaration, UsageWindow, Validate, Verification, changedWhileRead, generatedAtIsFuture, okfitConfigDocumentFields, okfitConfigSchemaHost, readConfinedBytes, readConfinedString, verificationBlockingRestamp };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Result, Schema, SchemaIssue } from "effect";
|
|
2
|
-
import { AttestedComputation } from "../AttestedComputation.js";
|
|
3
|
-
import { ATTESTED_COMPUTATION_TYPE, Concept } from "../Concept.js";
|
|
2
|
+
import { AttestedComputation, ComputationAttester, ComputationExecutor, ComputationParameter } from "../AttestedComputation.js";
|
|
3
|
+
import { ATTESTED_COMPUTATION_TYPE, Concept, EntryPaths } from "../Concept.js";
|
|
4
4
|
import { Generated } from "../Generated.js";
|
|
5
|
-
import { Integrity } from "../Integrity.js";
|
|
5
|
+
import { INTEGRITY_KEY, Integrity } from "../Integrity.js";
|
|
6
6
|
import { Source, UsageWindow } from "../Source.js";
|
|
7
7
|
import { Status } from "../Status.js";
|
|
8
8
|
import { Timestamp } from "../Timestamp.js";
|
|
@@ -19,47 +19,189 @@ const COMPUTATION_KEYS = [
|
|
|
19
19
|
"executor",
|
|
20
20
|
"attester"
|
|
21
21
|
];
|
|
22
|
-
|
|
22
|
+
/** Scalar families: decoded whole through their schema; a failure reads as absent with `value-malformed`. */
|
|
23
|
+
const SCALAR_SCHEMAS = {
|
|
23
24
|
title: Schema.String,
|
|
24
25
|
description: Schema.String,
|
|
25
26
|
resource: Schema.String,
|
|
26
|
-
tags: Schema.Array(Schema.String),
|
|
27
|
-
sources: Schema.Array(Source),
|
|
28
|
-
usage_window: UsageWindow,
|
|
29
|
-
generated: Generated,
|
|
30
|
-
verified: Verification.List,
|
|
31
|
-
status: Status,
|
|
32
27
|
stale_after: Timestamp,
|
|
33
|
-
|
|
28
|
+
superseded_by: Schema.String
|
|
34
29
|
};
|
|
35
|
-
const FAMILY_KEYS = Object.keys(FAMILY_SCHEMAS);
|
|
36
30
|
const PARSE_OPTIONS = { errors: "all" };
|
|
37
31
|
const formatIssue = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
38
32
|
const isMapping = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
39
|
-
const
|
|
33
|
+
const leafMessages = (failure) => formatIssue(failure.issue).issues.map((leaf) => ({
|
|
34
|
+
path: (leaf.path ?? []).filter((segment) => typeof segment !== "symbol"),
|
|
35
|
+
message: leaf.message
|
|
36
|
+
}));
|
|
37
|
+
/** Decode a whole family through one schema, reporting every leaf under `prefix` with `code`. */
|
|
38
|
+
const decodeFamily = (schema, family, prefix, value, issues, code = "value-malformed") => {
|
|
40
39
|
const result = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)(value);
|
|
41
40
|
if (Result.isSuccess(result)) return result.success;
|
|
42
|
-
for (const leaf of
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
for (const leaf of leafMessages(result.failure)) issues.push({
|
|
42
|
+
code,
|
|
43
|
+
family,
|
|
44
|
+
path: [...prefix, ...leaf.path],
|
|
45
|
+
message: leaf.message
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Decode a mapping key by key against a class's declared fields (OKF 0.3 11.2 rule 3). Each
|
|
50
|
+
* declared key is decoded alone: a REQUIRED key that is missing or unreadable ignores the whole
|
|
51
|
+
* mapping (`entry-ignored`, returns `undefined`); any other key that is unreadable is dropped
|
|
52
|
+
* alone (`value-malformed` at `[...path, key]`). Keys the class does not declare are never read, so
|
|
53
|
+
* an unknown key never keeps a mapping present (see {@link decodeNested}). A key listed in `nested`
|
|
54
|
+
* is itself a declared mapping and is decoded key by key at `[...path, key]`, so one bad key inside
|
|
55
|
+
* it drops that key alone.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
const decodeMapping = (fields, required, value, path, family, issues, nested = {}) => {
|
|
60
|
+
if (!isMapping(value)) {
|
|
61
|
+
issues.push({
|
|
62
|
+
code: required.length > 0 ? "entry-ignored" : "value-malformed",
|
|
63
|
+
family,
|
|
64
|
+
path,
|
|
65
|
+
message: "expected a mapping"
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const out = {};
|
|
70
|
+
const dropped = [];
|
|
71
|
+
const ignore = (message) => {
|
|
72
|
+
issues.push({
|
|
73
|
+
code: "entry-ignored",
|
|
74
|
+
family,
|
|
75
|
+
path,
|
|
76
|
+
message
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
for (const key of Object.keys(fields)) {
|
|
80
|
+
const isRequired = required.includes(key);
|
|
81
|
+
const present = Object.hasOwn(value, key) && !Concept.isAbsent(value[key]);
|
|
82
|
+
if (isRequired && !present) return ignore(`\`${key}\` is required`);
|
|
83
|
+
const inner = Object.hasOwn(nested, key) ? nested[key] : void 0;
|
|
84
|
+
if (inner !== void 0) {
|
|
85
|
+
if (!present) continue;
|
|
86
|
+
const kept = decodeNested(inner.cls, inner.required, value[key], [...path, key], family, dropped);
|
|
87
|
+
if (kept !== void 0) out[key] = kept;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const schema = Schema.Struct({ [key]: fields[key] });
|
|
91
|
+
const result = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)(present ? { [key]: value[key] } : {});
|
|
92
|
+
if (Result.isSuccess(result)) {
|
|
93
|
+
const decoded = result.success;
|
|
94
|
+
if (Object.hasOwn(decoded, key)) out[key] = decoded[key];
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!present) continue;
|
|
98
|
+
const message = leafMessages(result.failure)[0]?.message ?? "unreadable";
|
|
99
|
+
if (isRequired) return ignore(`\`${key}\` is unreadable: ${message}`);
|
|
100
|
+
dropped.push({
|
|
101
|
+
code: "value-malformed",
|
|
102
|
+
family,
|
|
103
|
+
path: [...path, key],
|
|
104
|
+
message
|
|
105
|
+
});
|
|
106
|
+
const fromAbsence = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)({});
|
|
107
|
+
if (Result.isSuccess(fromAbsence)) {
|
|
108
|
+
const filled = fromAbsence.success;
|
|
109
|
+
if (Object.hasOwn(filled, key)) out[key] = filled[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
issues.push(...dropped);
|
|
113
|
+
return out;
|
|
114
|
+
};
|
|
115
|
+
/** Build a kept mapping; a throw (a value the per-key decode accepted but the class rejects) ignores the mapping. */
|
|
116
|
+
const build = (cls, decoded, path, family, issues) => {
|
|
117
|
+
try {
|
|
118
|
+
return cls.make(decoded);
|
|
119
|
+
} catch (error) {
|
|
45
120
|
issues.push({
|
|
46
|
-
code: "
|
|
121
|
+
code: "entry-ignored",
|
|
47
122
|
family,
|
|
48
123
|
path,
|
|
49
|
-
message:
|
|
124
|
+
message: error instanceof Error ? error.message : "unreadable"
|
|
50
125
|
});
|
|
126
|
+
return;
|
|
51
127
|
}
|
|
52
128
|
};
|
|
129
|
+
/** A list family's items (rule 2: a non-list is a list of one) and each item's YAML path. */
|
|
130
|
+
const itemsOf = (key, value) => Array.isArray(value) ? value.map((item, index) => ({
|
|
131
|
+
item,
|
|
132
|
+
path: [key, index]
|
|
133
|
+
})) : [{
|
|
134
|
+
item: value,
|
|
135
|
+
path: [key]
|
|
136
|
+
}];
|
|
137
|
+
/** Decode a list family of mappings; returns the kept values with their YAML paths, or `undefined` when none survive. */
|
|
138
|
+
const decodeMappingList = (key, family, value, cls, required, issues, nested = {}) => {
|
|
139
|
+
const values = [];
|
|
140
|
+
const paths = [];
|
|
141
|
+
for (const { item, path } of itemsOf(key, value)) {
|
|
142
|
+
const decoded = decodeMapping(cls.fields, required, item, path, family, issues, nested);
|
|
143
|
+
if (decoded === void 0) continue;
|
|
144
|
+
const built = build(cls, decoded, path, family, issues);
|
|
145
|
+
if (built === void 0) continue;
|
|
146
|
+
values.push(built);
|
|
147
|
+
paths.push(path);
|
|
148
|
+
}
|
|
149
|
+
return values.length === 0 ? void 0 : {
|
|
150
|
+
values,
|
|
151
|
+
paths
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Decode one mapping value key by key (a top-level family, or a declared mapping nested in another).
|
|
156
|
+
*
|
|
157
|
+
* "Emptied by dropped keys" counts only the class's declared keys: a mapping with at least one
|
|
158
|
+
* dropped key and no kept declared key reads as absent, whatever unknown keys it also has. A mapping
|
|
159
|
+
* with no dropped key is kept, even when it holds nothing but unknown keys (`{ x: 1 }`, like `{}`).
|
|
160
|
+
* Unknown keys stay in `raw` and are never read (OKF 0.3 11.2: never rejected).
|
|
161
|
+
*/
|
|
162
|
+
const decodeNested = (cls, required, value, path, family, issues) => {
|
|
163
|
+
const before = issues.length;
|
|
164
|
+
const decoded = decodeMapping(cls.fields, required, value, path, family, issues);
|
|
165
|
+
if (decoded === void 0) return void 0;
|
|
166
|
+
if (Object.keys(decoded).length === 0 && issues.length > before) return void 0;
|
|
167
|
+
return build(cls, decoded, path, family, issues);
|
|
168
|
+
};
|
|
169
|
+
/** Decode one single-mapping key; absent (rule 1) or unreadable reads as `undefined`. */
|
|
170
|
+
const decodeSingle = (key, family, raw, cls, required, issues) => Concept.isAbsent(raw[key]) ? void 0 : decodeNested(cls, required, raw[key], [key], family, issues);
|
|
171
|
+
/** Decode the computation keys independently (a bad `executor` no longer drops `runtime`). */
|
|
172
|
+
const decodeAttested = (raw, issues, entries) => {
|
|
173
|
+
const input = { parameters: [] };
|
|
174
|
+
for (const key of ["runtime", "computation"]) {
|
|
175
|
+
if (Concept.isAbsent(raw[key])) continue;
|
|
176
|
+
const decoded = decodeFamily(Schema.String, "attested", [key], raw[key], issues);
|
|
177
|
+
if (decoded !== void 0) input[key] = decoded;
|
|
178
|
+
}
|
|
179
|
+
if (!Concept.isAbsent(raw.parameters)) {
|
|
180
|
+
const list = decodeMappingList("parameters", "attested", raw.parameters, ComputationParameter, ["name", "type"], issues);
|
|
181
|
+
if (list !== void 0) {
|
|
182
|
+
input.parameters = list.values;
|
|
183
|
+
entries.parameters = list.paths;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const executor = decodeSingle("executor", "attested", raw, ComputationExecutor, [], issues);
|
|
187
|
+
if (executor !== void 0) input.executor = executor;
|
|
188
|
+
const attester = decodeSingle("attester", "attested", raw, ComputationAttester, [], issues);
|
|
189
|
+
if (attester !== void 0) input.attester = attester;
|
|
190
|
+
return AttestedComputation.make(input);
|
|
191
|
+
};
|
|
53
192
|
/**
|
|
54
193
|
* Decode a frontmatter value into a `Concept` without ever rejecting it for a
|
|
55
|
-
* bad family. `TypeMissing`
|
|
194
|
+
* bad family. `TypeMissing` (lint `type-missing`) and `NotMapping` (conformance
|
|
195
|
+
* `frontmatter-unparseable`) are the only failures. Reading is tolerant, key by key (OKF 0.3 11.2
|
|
196
|
+
* rules 1-4); only okfit's own `integrity` family keeps the whole-family `family-invalid` decode.
|
|
56
197
|
* @public
|
|
57
198
|
*/
|
|
58
199
|
const decodeConcept = (value) => {
|
|
59
|
-
if (
|
|
200
|
+
if (value === null || value === void 0) return {
|
|
60
201
|
_tag: "TypeMissing",
|
|
61
|
-
message: "frontmatter
|
|
202
|
+
message: "frontmatter has no `type`"
|
|
62
203
|
};
|
|
204
|
+
if (!isMapping(value)) return { _tag: "NotMapping" };
|
|
63
205
|
const raw = Object.fromEntries(Object.entries(value));
|
|
64
206
|
const type = raw.type;
|
|
65
207
|
if (typeof type !== "string") return {
|
|
@@ -74,7 +216,14 @@ const decodeConcept = (value) => {
|
|
|
74
216
|
const isComputation = type === ATTESTED_COMPUTATION_TYPE;
|
|
75
217
|
const known = /* @__PURE__ */ new Set([
|
|
76
218
|
"type",
|
|
77
|
-
...
|
|
219
|
+
...Object.keys(SCALAR_SCHEMAS),
|
|
220
|
+
"status",
|
|
221
|
+
"tags",
|
|
222
|
+
"sources",
|
|
223
|
+
"usage_window",
|
|
224
|
+
"generated",
|
|
225
|
+
"verified",
|
|
226
|
+
INTEGRITY_KEY,
|
|
78
227
|
...isComputation ? COMPUTATION_KEYS : []
|
|
79
228
|
]);
|
|
80
229
|
const fields = {
|
|
@@ -82,12 +231,77 @@ const decodeConcept = (value) => {
|
|
|
82
231
|
extensions: Object.fromEntries(Object.entries(raw).filter(([key]) => !known.has(key))),
|
|
83
232
|
raw
|
|
84
233
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
234
|
+
const out = fields;
|
|
235
|
+
const entries = {};
|
|
236
|
+
const present = (key) => key in raw && !Concept.isAbsent(raw[key]);
|
|
237
|
+
const scalar = (key) => {
|
|
238
|
+
if (!present(key)) return;
|
|
239
|
+
const decoded = decodeFamily(SCALAR_SCHEMAS[key], key, [key], raw[key], issues);
|
|
240
|
+
if (decoded !== void 0) out[key] = decoded;
|
|
241
|
+
};
|
|
242
|
+
for (const key of [
|
|
243
|
+
"title",
|
|
244
|
+
"description",
|
|
245
|
+
"resource"
|
|
246
|
+
]) scalar(key);
|
|
247
|
+
if (present("tags")) {
|
|
248
|
+
const kept = [];
|
|
249
|
+
const paths = [];
|
|
250
|
+
for (const { item, path } of itemsOf("tags", raw.tags)) {
|
|
251
|
+
if (typeof item !== "string") {
|
|
252
|
+
issues.push({
|
|
253
|
+
code: "value-malformed",
|
|
254
|
+
family: "tags",
|
|
255
|
+
path,
|
|
256
|
+
message: "expected a string"
|
|
257
|
+
});
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
kept.push(item);
|
|
261
|
+
paths.push(path);
|
|
262
|
+
}
|
|
263
|
+
if (kept.length > 0) {
|
|
264
|
+
out.tags = kept;
|
|
265
|
+
entries.tags = paths;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (present("sources")) {
|
|
269
|
+
const list = decodeMappingList("sources", "sources", raw.sources, Source, ["resource"], issues, { usage_window: {
|
|
270
|
+
cls: UsageWindow,
|
|
271
|
+
required: []
|
|
272
|
+
} });
|
|
273
|
+
if (list !== void 0) {
|
|
274
|
+
out.sources = list.values;
|
|
275
|
+
entries.sources = list.paths;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const usageWindow = decodeSingle("usage_window", "usage_window", raw, UsageWindow, [], issues);
|
|
279
|
+
if (usageWindow !== void 0) out.usage_window = usageWindow;
|
|
280
|
+
const generated = decodeSingle("generated", "generated", raw, Generated, ["by"], issues);
|
|
281
|
+
if (generated !== void 0) out.generated = generated;
|
|
282
|
+
if (present("verified")) {
|
|
283
|
+
const list = decodeMappingList("verified", "verified", raw.verified, Verification, ["by", "at"], issues);
|
|
284
|
+
if (list !== void 0) {
|
|
285
|
+
out.verified = list.values;
|
|
286
|
+
entries.verified = list.paths;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (present("status")) {
|
|
290
|
+
if (Schema.is(Status)(raw.status)) out.status = raw.status;
|
|
291
|
+
else issues.push({
|
|
292
|
+
code: "value-unknown",
|
|
293
|
+
family: "status",
|
|
294
|
+
path: ["status"],
|
|
295
|
+
message: "expected draft, stable or deprecated"
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
scalar("stale_after");
|
|
299
|
+
scalar("superseded_by");
|
|
300
|
+
if (present("x-okfit-integrity")) {
|
|
301
|
+
const integrity = decodeFamily(Integrity, INTEGRITY_KEY, [INTEGRITY_KEY], raw[INTEGRITY_KEY], issues, "family-invalid");
|
|
302
|
+
if (integrity !== void 0) out.integrity = integrity;
|
|
89
303
|
}
|
|
90
|
-
if (!("generated"
|
|
304
|
+
if (!present("generated") && present("timestamp")) {
|
|
91
305
|
const at = decodeFamily(Timestamp, "timestamp", ["timestamp"], raw.timestamp, issues);
|
|
92
306
|
if (at !== void 0) {
|
|
93
307
|
fields.generated = Generated.make({
|
|
@@ -103,16 +317,15 @@ const decodeConcept = (value) => {
|
|
|
103
317
|
}
|
|
104
318
|
}
|
|
105
319
|
if (isComputation) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (attested !== void 0) fields.attested = attested;
|
|
109
|
-
if (raw.runtime === void 0) issues.push({
|
|
320
|
+
fields.attested = decodeAttested(raw, issues, entries);
|
|
321
|
+
if (fields.attested.runtime === void 0) issues.push({
|
|
110
322
|
code: "computation-runtime-missing",
|
|
111
323
|
family: "attested",
|
|
112
324
|
path: [],
|
|
113
325
|
message: "`runtime` is required on an Attested Computation"
|
|
114
326
|
});
|
|
115
327
|
}
|
|
328
|
+
if (Object.keys(entries).length > 0) fields.entries = EntryPaths.make(entries);
|
|
116
329
|
return {
|
|
117
330
|
_tag: "Decoded",
|
|
118
331
|
concept: Concept.make(fields),
|
|
@@ -120,4 +333,4 @@ const decodeConcept = (value) => {
|
|
|
120
333
|
};
|
|
121
334
|
};
|
|
122
335
|
|
|
123
|
-
export { COMPUTATION_KEYS, decodeConcept };
|
|
336
|
+
export { COMPUTATION_KEYS, decodeConcept, decodeMapping };
|
package/internal/frontmatter.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { Option } from "effect";
|
|
2
2
|
import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
|
|
3
3
|
import { decodeConcept as decodeConcept$1 } from "./conceptDecode.js";
|
|
4
|
-
import {
|
|
4
|
+
import { frontmatterAnchorSpan } from "./yamlPathSpan.js";
|
|
5
5
|
|
|
6
6
|
// src/internal/frontmatter.ts
|
|
7
|
-
/** D-34 default severities for a `FamilyIssue`'s lint code
|
|
7
|
+
/** D-34 default severities for a `FamilyIssue`'s lint code. */
|
|
8
8
|
const FAMILY_ISSUE_SEVERITY = {
|
|
9
9
|
"family-invalid": "error",
|
|
10
10
|
"legacy-timestamp": "info",
|
|
11
|
-
"computation-runtime-missing": "error"
|
|
11
|
+
"computation-runtime-missing": "error",
|
|
12
|
+
"entry-ignored": "warning",
|
|
13
|
+
"value-malformed": "warning",
|
|
14
|
+
"value-unknown": "warning"
|
|
12
15
|
};
|
|
13
16
|
const spanToRange = (text, path, node) => {
|
|
14
|
-
const span =
|
|
17
|
+
const span = frontmatterAnchorSpan(text, node, path);
|
|
15
18
|
return DiagnosticRange.fromOffset(text, span.offset, span.length);
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
@@ -40,19 +43,29 @@ const toDiagnostic = (context, issue) => Diagnostic.make({
|
|
|
40
43
|
/**
|
|
41
44
|
* Group C's seam onto group B's two-stage decoder (decision 2): adapts B3's
|
|
42
45
|
* `decodeConcept(value): ConceptDecodeResult` into the `Option<Concept>` / `Diagnostic[]`
|
|
43
|
-
* shape `Bundle.ts` consumes. Never fails; a `TypeMissing` envelope reports `type-missing`
|
|
44
|
-
* with no concept and no range.
|
|
46
|
+
* shape `Bundle.ts` consumes. Never fails; a `TypeMissing` envelope reports the lint `type-missing`
|
|
47
|
+
* with no concept and no range, and a `NotMapping` one the conformance `frontmatter-unparseable` over the block.
|
|
45
48
|
*
|
|
46
49
|
* @public
|
|
47
50
|
*/
|
|
48
51
|
const decodeConcept = (raw, context) => {
|
|
49
52
|
const result = decodeConcept$1(raw);
|
|
53
|
+
if (result._tag === "NotMapping") return {
|
|
54
|
+
concept: Option.none(),
|
|
55
|
+
diagnostics: [Diagnostic.make({
|
|
56
|
+
file: context.file,
|
|
57
|
+
code: "frontmatter-unparseable",
|
|
58
|
+
severity: "error",
|
|
59
|
+
message: "frontmatter is not a mapping",
|
|
60
|
+
range: rangeFor(context, [])
|
|
61
|
+
})]
|
|
62
|
+
};
|
|
50
63
|
if (result._tag === "TypeMissing") return {
|
|
51
64
|
concept: Option.none(),
|
|
52
65
|
diagnostics: [Diagnostic.make({
|
|
53
66
|
file: context.file,
|
|
54
67
|
code: "type-missing",
|
|
55
|
-
severity: "
|
|
68
|
+
severity: "warning",
|
|
56
69
|
message: result.message
|
|
57
70
|
})]
|
|
58
71
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { confineReal } from "@effected/walker";
|
|
2
|
+
import { Effect, Path } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/internal/linkScan.ts
|
|
5
|
+
/** The words a `symlink-escape` message uses for a link that leaves the bundle root; one spelling for every site. */
|
|
6
|
+
const RESOLVES_OUTSIDE = "resolves outside the bundle root";
|
|
7
|
+
/** The words a `symlink-escape` message uses for a link that cannot be resolved (dangling, a loop, unreadable). */
|
|
8
|
+
const COULD_NOT_RESOLVE = "could not be resolved, so it cannot be shown to stay inside the bundle root";
|
|
9
|
+
const byPath = (a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : 0;
|
|
10
|
+
/**
|
|
11
|
+
* The walker's `links` report as `symlink-escape` findings: a link to a directory that resolves outside the bundle (the
|
|
12
|
+
* walker never enters one, wherever it points), and a link that does not resolve (dangling, whether it named a file or
|
|
13
|
+
* a directory). A directory link is decided on its REAL path with `confineReal`, so a link inside the bundle that points
|
|
14
|
+
* at a link leaving it is refused too; one that stays inside (or is the bundle root itself) is silent and never walked.
|
|
15
|
+
* Directory findings come first, then the unresolvable ones, each sorted by path.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* The walker reports links only from directories it reads, so a pruned directory, a hidden one and anything under them
|
|
19
|
+
* are never seen. It reports a dangling link whatever its own name, so a pruned or (without `includeHidden`) hidden name
|
|
20
|
+
* is dropped here to keep Q8: a pruned directory name is fully silent, and a hidden name is reported only with
|
|
21
|
+
* `includeHidden`. A file link with a pruned name is a file match, not a skipped link; `Bundle.load` drops it
|
|
22
|
+
* silently too (never read, never reported), so the prune list silences a name for files and directories alike.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
const scanLinks = (root, links, options) => Effect.gen(function* () {
|
|
27
|
+
const path = yield* Path.Path;
|
|
28
|
+
const silent = (link) => {
|
|
29
|
+
const name = link.slice(link.lastIndexOf("/") + 1);
|
|
30
|
+
return options.prune.has(name) || !options.includeHidden && name.startsWith(".");
|
|
31
|
+
};
|
|
32
|
+
const directories = [];
|
|
33
|
+
const unresolvable = [];
|
|
34
|
+
for (const link of links) {
|
|
35
|
+
if (silent(link.path)) continue;
|
|
36
|
+
if (link.kind === "special") continue;
|
|
37
|
+
if (link.kind === "dangling") {
|
|
38
|
+
unresolvable.push({
|
|
39
|
+
file: link.path,
|
|
40
|
+
message: `symbolic link ${COULD_NOT_RESOLVE}; it is not read and not part of the bundle`
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const reason = yield* confineReal(root, path.join(root, link.path)).pipe(Effect.match({
|
|
45
|
+
onFailure: (error) => error.reason,
|
|
46
|
+
onSuccess: () => void 0
|
|
47
|
+
}));
|
|
48
|
+
if (reason === void 0 || reason === "empty") continue;
|
|
49
|
+
directories.push({
|
|
50
|
+
file: link.path,
|
|
51
|
+
message: `symbolic link to a directory ${reason === "outside" ? RESOLVES_OUTSIDE : COULD_NOT_RESOLVE}; nothing under it is read or part of the bundle`
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return [...directories.sort(byPath), ...unresolvable.sort(byPath)];
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { COULD_NOT_RESOLVE, RESOLVES_OUTSIDE, scanLinks };
|
package/internal/links.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PosixPath } from "@effected/walker";
|
|
2
2
|
import { Option } from "effect";
|
|
3
|
+
import { Concept } from "../Concept.js";
|
|
3
4
|
import { findFrontmatterPathSpan } from "./yamlPathSpan.js";
|
|
4
5
|
|
|
5
6
|
// src/internal/links.ts
|
|
@@ -73,7 +74,7 @@ const resolveTarget = (from, raw, index) => {
|
|
|
73
74
|
if (escapes(fileRelative)) return { _tag: "external" };
|
|
74
75
|
const hitB = lookup(fileRelative, index, "file");
|
|
75
76
|
if (hitB !== void 0) return hitB;
|
|
76
|
-
if (!relative) {
|
|
77
|
+
if (!relative && index.rootFallback) {
|
|
77
78
|
const rootRelative = PosixPath.normalize(target);
|
|
78
79
|
if (escapes(rootRelative)) return { _tag: "external" };
|
|
79
80
|
const hitC = lookup(rootRelative, index, "root");
|
|
@@ -101,11 +102,7 @@ const pathFieldsOf = (concept) => {
|
|
|
101
102
|
for (const [index, source] of (concept.sources ?? []).entries()) out.push({
|
|
102
103
|
field: "sources.resource",
|
|
103
104
|
raw: source.resource,
|
|
104
|
-
path: [
|
|
105
|
-
"sources",
|
|
106
|
-
index,
|
|
107
|
-
"resource"
|
|
108
|
-
]
|
|
105
|
+
path: [...Concept.entryPath(concept, "sources", index), "resource"]
|
|
109
106
|
});
|
|
110
107
|
const attested = concept.attested;
|
|
111
108
|
if (attested?.computation !== void 0) out.push({
|
|
@@ -113,16 +110,21 @@ const pathFieldsOf = (concept) => {
|
|
|
113
110
|
raw: attested.computation,
|
|
114
111
|
path: ["computation"]
|
|
115
112
|
});
|
|
116
|
-
if (attested?.executor !== void 0) out.push({
|
|
113
|
+
if (attested?.executor?.resource !== void 0) out.push({
|
|
117
114
|
field: "executor.resource",
|
|
118
115
|
raw: attested.executor.resource,
|
|
119
116
|
path: ["executor", "resource"]
|
|
120
117
|
});
|
|
121
|
-
if (attested?.attester !== void 0) out.push({
|
|
118
|
+
if (attested?.attester?.resource !== void 0) out.push({
|
|
122
119
|
field: "attester.resource",
|
|
123
120
|
raw: attested.attester.resource,
|
|
124
121
|
path: ["attester", "resource"]
|
|
125
122
|
});
|
|
123
|
+
if (concept.superseded_by !== void 0) out.push({
|
|
124
|
+
field: "superseded_by",
|
|
125
|
+
raw: concept.superseded_by,
|
|
126
|
+
path: ["superseded_by"]
|
|
127
|
+
});
|
|
126
128
|
return out;
|
|
127
129
|
};
|
|
128
130
|
/**
|