@okfit/core 0.14.0 → 0.15.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 +87 -11
- package/Concept.js +30 -2
- package/Derive.js +80 -14
- package/Diagnostic.js +16 -3
- package/Generated.js +1 -1
- package/GeneratedAtFuture.js +33 -0
- package/Graph.js +47 -12
- package/IndexDocument.js +8 -1
- package/Integrity.js +13 -2
- package/OkfVersion.js +40 -0
- package/OkfitConfig.js +162 -15
- 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 +314 -35
- package/index.js +7 -5
- package/internal/conceptDecode.js +230 -32
- package/internal/frontmatter.js +18 -5
- package/internal/links.js +10 -8
- package/internal/lintRules.js +153 -24
- package/internal/reserved.js +31 -7
- package/internal/templates.js +27 -5
- package/internal/tier.js +7 -0
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
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
6
|
import { Derive, Staleness, TrustTier } from "./Derive.js";
|
|
7
7
|
import { ConformanceCode, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, LintCode } from "./Diagnostic.js";
|
|
8
8
|
import { Generated } from "./Generated.js";
|
|
9
|
+
import { GENERATED_AT_TOLERANCE, generatedAtIsFuture, verificationBlockingRestamp } from "./GeneratedAtFuture.js";
|
|
9
10
|
import { Graph, GraphNodeKind, LinkGraph } from "./Graph.js";
|
|
10
11
|
import { IndexDocument, IndexEntry, IndexSection } from "./IndexDocument.js";
|
|
11
|
-
import { Digest, Integrity, IntegrityGenerated, IntegrityVerified } from "./Integrity.js";
|
|
12
|
+
import { Digest, INTEGRITY_KEY, Integrity, IntegrityGenerated, IntegrityVerified, OKFIT_KEY_PREFIX } from "./Integrity.js";
|
|
12
13
|
import { LogDocument, LogGroup, LogItem } from "./LogDocument.js";
|
|
13
14
|
import { CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigSchemaHost } from "./OkfitConfig.js";
|
|
15
|
+
import { OkfVersion } from "./OkfVersion.js";
|
|
14
16
|
import { Source, UsageWindow } from "./Source.js";
|
|
15
|
-
import { Status } from "./Status.js";
|
|
17
|
+
import { DerivedStatus, Status } from "./Status.js";
|
|
16
18
|
import { Timestamp } from "./Timestamp.js";
|
|
17
19
|
import { Validate } from "./Validate.js";
|
|
18
20
|
import { Verification } from "./Verification.js";
|
|
@@ -23,6 +25,6 @@ import { Verification } from "./Verification.js";
|
|
|
23
25
|
*
|
|
24
26
|
* @public
|
|
25
27
|
*/
|
|
26
|
-
const OKF_SPEC_VERSION = "0.
|
|
28
|
+
const OKF_SPEC_VERSION = "0.3";
|
|
27
29
|
|
|
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 };
|
|
30
|
+
export { ATTESTED_COMPUTATION_TYPE, Actor, ActorPattern, AttestedComputation, Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, CONFIG_SCHEMA_VERSION, ComputationAttester, ComputationExecutor, ComputationParameter, Concept, ConceptId, ConformanceCode, Derive, DerivedStatus, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, Digest, EntryPaths, FieldDeclaration, GENERATED_AT_TOLERANCE, 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, generatedAtIsFuture, okfitConfigDocumentFields, okfitConfigSchemaHost, 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,177 @@ 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
|
-
|
|
33
|
+
/**
|
|
34
|
+
* OKF 0.3 11.2 rule 1: `null`, an empty string and an empty list read as absent.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
const isAbsent = (value) => value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
39
|
+
const leafMessages = (failure) => formatIssue(failure.issue).issues.map((leaf) => ({
|
|
40
|
+
path: (leaf.path ?? []).filter((segment) => typeof segment !== "symbol"),
|
|
41
|
+
message: leaf.message
|
|
42
|
+
}));
|
|
43
|
+
/** Decode a whole family through one schema, reporting every leaf under `prefix` with `code`. */
|
|
44
|
+
const decodeFamily = (schema, family, prefix, value, issues, code = "value-malformed") => {
|
|
40
45
|
const result = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)(value);
|
|
41
46
|
if (Result.isSuccess(result)) return result.success;
|
|
42
|
-
for (const leaf of
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
for (const leaf of leafMessages(result.failure)) issues.push({
|
|
48
|
+
code,
|
|
49
|
+
family,
|
|
50
|
+
path: [...prefix, ...leaf.path],
|
|
51
|
+
message: leaf.message
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Decode a mapping key by key against a class's declared fields (OKF 0.3 11.2 rule 3). Each
|
|
56
|
+
* declared key is decoded alone: a REQUIRED key that is missing or unreadable ignores the whole
|
|
57
|
+
* mapping (`entry-ignored`, returns `undefined`); any other key that is unreadable is dropped
|
|
58
|
+
* alone (`value-malformed` at `[...path, key]`). Keys the class does not declare are never read.
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
const decodeMapping = (fields, required, value, path, family, issues) => {
|
|
63
|
+
if (!isMapping(value)) {
|
|
64
|
+
issues.push({
|
|
65
|
+
code: required.length > 0 ? "entry-ignored" : "value-malformed",
|
|
66
|
+
family,
|
|
67
|
+
path,
|
|
68
|
+
message: "expected a mapping"
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const out = {};
|
|
73
|
+
const dropped = [];
|
|
74
|
+
const ignore = (message) => {
|
|
45
75
|
issues.push({
|
|
46
|
-
code: "
|
|
76
|
+
code: "entry-ignored",
|
|
47
77
|
family,
|
|
48
78
|
path,
|
|
49
|
-
message
|
|
79
|
+
message
|
|
50
80
|
});
|
|
81
|
+
};
|
|
82
|
+
for (const key of Object.keys(fields)) {
|
|
83
|
+
const isRequired = required.includes(key);
|
|
84
|
+
const present = Object.hasOwn(value, key) && !isAbsent(value[key]);
|
|
85
|
+
if (isRequired && !present) return ignore(`\`${key}\` is required`);
|
|
86
|
+
const schema = Schema.Struct({ [key]: fields[key] });
|
|
87
|
+
const result = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)(present ? { [key]: value[key] } : {});
|
|
88
|
+
if (Result.isSuccess(result)) {
|
|
89
|
+
const decoded = result.success;
|
|
90
|
+
if (Object.hasOwn(decoded, key)) out[key] = decoded[key];
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (!present) continue;
|
|
94
|
+
const message = leafMessages(result.failure)[0]?.message ?? "unreadable";
|
|
95
|
+
if (isRequired) return ignore(`\`${key}\` is unreadable: ${message}`);
|
|
96
|
+
dropped.push({
|
|
97
|
+
code: "value-malformed",
|
|
98
|
+
family,
|
|
99
|
+
path: [...path, key],
|
|
100
|
+
message
|
|
101
|
+
});
|
|
102
|
+
const fromAbsence = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)({});
|
|
103
|
+
if (Result.isSuccess(fromAbsence)) {
|
|
104
|
+
const filled = fromAbsence.success;
|
|
105
|
+
if (Object.hasOwn(filled, key)) out[key] = filled[key];
|
|
106
|
+
}
|
|
51
107
|
}
|
|
108
|
+
issues.push(...dropped);
|
|
109
|
+
return out;
|
|
110
|
+
};
|
|
111
|
+
/** Build a kept mapping; a throw (a value the per-key decode accepted but the class rejects) ignores the mapping. */
|
|
112
|
+
const build = (cls, decoded, path, family, issues) => {
|
|
113
|
+
try {
|
|
114
|
+
return cls.make(decoded);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
issues.push({
|
|
117
|
+
code: "entry-ignored",
|
|
118
|
+
family,
|
|
119
|
+
path,
|
|
120
|
+
message: error instanceof Error ? error.message : "unreadable"
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/** A list family's items (rule 2: a non-list is a list of one) and each item's YAML path. */
|
|
126
|
+
const itemsOf = (key, value) => Array.isArray(value) ? value.map((item, index) => ({
|
|
127
|
+
item,
|
|
128
|
+
path: [key, index]
|
|
129
|
+
})) : [{
|
|
130
|
+
item: value,
|
|
131
|
+
path: [key]
|
|
132
|
+
}];
|
|
133
|
+
/** Decode a list family of mappings; returns the kept values with their YAML paths, or `undefined` when none survive. */
|
|
134
|
+
const decodeMappingList = (key, family, value, cls, required, issues) => {
|
|
135
|
+
const values = [];
|
|
136
|
+
const paths = [];
|
|
137
|
+
for (const { item, path } of itemsOf(key, value)) {
|
|
138
|
+
const decoded = decodeMapping(cls.fields, required, item, path, family, issues);
|
|
139
|
+
if (decoded === void 0) continue;
|
|
140
|
+
const built = build(cls, decoded, path, family, issues);
|
|
141
|
+
if (built === void 0) continue;
|
|
142
|
+
values.push(built);
|
|
143
|
+
paths.push(path);
|
|
144
|
+
}
|
|
145
|
+
return values.length === 0 ? void 0 : {
|
|
146
|
+
values,
|
|
147
|
+
paths
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
/** Decode one single-mapping key; absent (rule 1) or unreadable reads as `undefined`. */
|
|
151
|
+
const decodeSingle = (key, family, raw, cls, required, issues) => {
|
|
152
|
+
if (isAbsent(raw[key])) return void 0;
|
|
153
|
+
const before = issues.length;
|
|
154
|
+
const decoded = decodeMapping(cls.fields, required, raw[key], [key], family, issues);
|
|
155
|
+
if (decoded === void 0) return void 0;
|
|
156
|
+
if (Object.keys(decoded).length === 0 && issues.length > before) return void 0;
|
|
157
|
+
return build(cls, decoded, [key], family, issues);
|
|
158
|
+
};
|
|
159
|
+
/** Decode the computation keys independently (a bad `executor` no longer drops `runtime`). */
|
|
160
|
+
const decodeAttested = (raw, issues, entries) => {
|
|
161
|
+
const input = { parameters: [] };
|
|
162
|
+
for (const key of ["runtime", "computation"]) {
|
|
163
|
+
if (isAbsent(raw[key])) continue;
|
|
164
|
+
const decoded = decodeFamily(Schema.String, "attested", [key], raw[key], issues);
|
|
165
|
+
if (decoded !== void 0) input[key] = decoded;
|
|
166
|
+
}
|
|
167
|
+
if (!isAbsent(raw.parameters)) {
|
|
168
|
+
const list = decodeMappingList("parameters", "attested", raw.parameters, ComputationParameter, ["name", "type"], issues);
|
|
169
|
+
if (list !== void 0) {
|
|
170
|
+
input.parameters = list.values;
|
|
171
|
+
entries.parameters = list.paths;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const executor = decodeSingle("executor", "attested", raw, ComputationExecutor, [], issues);
|
|
175
|
+
if (executor !== void 0) input.executor = executor;
|
|
176
|
+
const attester = decodeSingle("attester", "attested", raw, ComputationAttester, [], issues);
|
|
177
|
+
if (attester !== void 0) input.attester = attester;
|
|
178
|
+
return AttestedComputation.make(input);
|
|
52
179
|
};
|
|
53
180
|
/**
|
|
54
181
|
* Decode a frontmatter value into a `Concept` without ever rejecting it for a
|
|
55
|
-
* bad family. `TypeMissing`
|
|
182
|
+
* bad family. `TypeMissing` (lint `type-missing`) and `NotMapping` (conformance
|
|
183
|
+
* `frontmatter-unparseable`) are the only failures. Reading is tolerant, key by key (OKF 0.3 11.2
|
|
184
|
+
* rules 1-4); only okfit's own `integrity` family keeps the whole-family `family-invalid` decode.
|
|
56
185
|
* @public
|
|
57
186
|
*/
|
|
58
187
|
const decodeConcept = (value) => {
|
|
59
|
-
if (
|
|
188
|
+
if (value === null || value === void 0) return {
|
|
60
189
|
_tag: "TypeMissing",
|
|
61
|
-
message: "frontmatter
|
|
190
|
+
message: "frontmatter has no `type`"
|
|
62
191
|
};
|
|
192
|
+
if (!isMapping(value)) return { _tag: "NotMapping" };
|
|
63
193
|
const raw = Object.fromEntries(Object.entries(value));
|
|
64
194
|
const type = raw.type;
|
|
65
195
|
if (typeof type !== "string") return {
|
|
@@ -74,7 +204,14 @@ const decodeConcept = (value) => {
|
|
|
74
204
|
const isComputation = type === ATTESTED_COMPUTATION_TYPE;
|
|
75
205
|
const known = /* @__PURE__ */ new Set([
|
|
76
206
|
"type",
|
|
77
|
-
...
|
|
207
|
+
...Object.keys(SCALAR_SCHEMAS),
|
|
208
|
+
"status",
|
|
209
|
+
"tags",
|
|
210
|
+
"sources",
|
|
211
|
+
"usage_window",
|
|
212
|
+
"generated",
|
|
213
|
+
"verified",
|
|
214
|
+
INTEGRITY_KEY,
|
|
78
215
|
...isComputation ? COMPUTATION_KEYS : []
|
|
79
216
|
]);
|
|
80
217
|
const fields = {
|
|
@@ -82,12 +219,74 @@ const decodeConcept = (value) => {
|
|
|
82
219
|
extensions: Object.fromEntries(Object.entries(raw).filter(([key]) => !known.has(key))),
|
|
83
220
|
raw
|
|
84
221
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
222
|
+
const out = fields;
|
|
223
|
+
const entries = {};
|
|
224
|
+
const present = (key) => key in raw && !isAbsent(raw[key]);
|
|
225
|
+
const scalar = (key) => {
|
|
226
|
+
if (!present(key)) return;
|
|
227
|
+
const decoded = decodeFamily(SCALAR_SCHEMAS[key], key, [key], raw[key], issues);
|
|
228
|
+
if (decoded !== void 0) out[key] = decoded;
|
|
229
|
+
};
|
|
230
|
+
for (const key of [
|
|
231
|
+
"title",
|
|
232
|
+
"description",
|
|
233
|
+
"resource"
|
|
234
|
+
]) scalar(key);
|
|
235
|
+
if (present("tags")) {
|
|
236
|
+
const kept = [];
|
|
237
|
+
const paths = [];
|
|
238
|
+
for (const { item, path } of itemsOf("tags", raw.tags)) {
|
|
239
|
+
if (typeof item !== "string") {
|
|
240
|
+
issues.push({
|
|
241
|
+
code: "value-malformed",
|
|
242
|
+
family: "tags",
|
|
243
|
+
path,
|
|
244
|
+
message: "expected a string"
|
|
245
|
+
});
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
kept.push(item);
|
|
249
|
+
paths.push(path);
|
|
250
|
+
}
|
|
251
|
+
if (kept.length > 0) {
|
|
252
|
+
out.tags = kept;
|
|
253
|
+
entries.tags = paths;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (present("sources")) {
|
|
257
|
+
const list = decodeMappingList("sources", "sources", raw.sources, Source, ["resource"], issues);
|
|
258
|
+
if (list !== void 0) {
|
|
259
|
+
out.sources = list.values;
|
|
260
|
+
entries.sources = list.paths;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const usageWindow = decodeSingle("usage_window", "usage_window", raw, UsageWindow, [], issues);
|
|
264
|
+
if (usageWindow !== void 0) out.usage_window = usageWindow;
|
|
265
|
+
const generated = decodeSingle("generated", "generated", raw, Generated, ["by"], issues);
|
|
266
|
+
if (generated !== void 0) out.generated = generated;
|
|
267
|
+
if (present("verified")) {
|
|
268
|
+
const list = decodeMappingList("verified", "verified", raw.verified, Verification, ["by", "at"], issues);
|
|
269
|
+
if (list !== void 0) {
|
|
270
|
+
out.verified = list.values;
|
|
271
|
+
entries.verified = list.paths;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (present("status")) {
|
|
275
|
+
if (Schema.is(Status)(raw.status)) out.status = raw.status;
|
|
276
|
+
else issues.push({
|
|
277
|
+
code: "value-unknown",
|
|
278
|
+
family: "status",
|
|
279
|
+
path: ["status"],
|
|
280
|
+
message: "expected draft, stable or deprecated"
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
scalar("stale_after");
|
|
284
|
+
scalar("superseded_by");
|
|
285
|
+
if (present("x-okfit-integrity")) {
|
|
286
|
+
const integrity = decodeFamily(Integrity, INTEGRITY_KEY, [INTEGRITY_KEY], raw[INTEGRITY_KEY], issues, "family-invalid");
|
|
287
|
+
if (integrity !== void 0) out.integrity = integrity;
|
|
89
288
|
}
|
|
90
|
-
if (!("generated"
|
|
289
|
+
if (!present("generated") && present("timestamp")) {
|
|
91
290
|
const at = decodeFamily(Timestamp, "timestamp", ["timestamp"], raw.timestamp, issues);
|
|
92
291
|
if (at !== void 0) {
|
|
93
292
|
fields.generated = Generated.make({
|
|
@@ -103,16 +302,15 @@ const decodeConcept = (value) => {
|
|
|
103
302
|
}
|
|
104
303
|
}
|
|
105
304
|
if (isComputation) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (attested !== void 0) fields.attested = attested;
|
|
109
|
-
if (raw.runtime === void 0) issues.push({
|
|
305
|
+
fields.attested = decodeAttested(raw, issues, entries);
|
|
306
|
+
if (fields.attested.runtime === void 0) issues.push({
|
|
110
307
|
code: "computation-runtime-missing",
|
|
111
308
|
family: "attested",
|
|
112
309
|
path: [],
|
|
113
310
|
message: "`runtime` is required on an Attested Computation"
|
|
114
311
|
});
|
|
115
312
|
}
|
|
313
|
+
if (Object.keys(entries).length > 0) fields.entries = EntryPaths.make(entries);
|
|
116
314
|
return {
|
|
117
315
|
_tag: "Decoded",
|
|
118
316
|
concept: Concept.make(fields),
|
|
@@ -120,4 +318,4 @@ const decodeConcept = (value) => {
|
|
|
120
318
|
};
|
|
121
319
|
};
|
|
122
320
|
|
|
123
|
-
export { COMPUTATION_KEYS, decodeConcept };
|
|
321
|
+
export { COMPUTATION_KEYS, decodeConcept, decodeMapping, isAbsent };
|
package/internal/frontmatter.js
CHANGED
|
@@ -4,11 +4,14 @@ import { decodeConcept as decodeConcept$1 } from "./conceptDecode.js";
|
|
|
4
4
|
import { frontmatterPathSpan } 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
17
|
const span = frontmatterPathSpan(text, node, path);
|
|
@@ -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
|
};
|
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
|
/**
|