@appport/integration 0.0.0-stage → 1.1.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/LICENSE +126 -0
- package/README.md +34 -2
- package/dist/base64url.d.ts +4 -0
- package/dist/base64url.d.ts.map +1 -0
- package/dist/base64url.js +36 -0
- package/dist/base64url.js.map +1 -0
- package/dist/behavior.d.ts +164 -0
- package/dist/behavior.d.ts.map +1 -0
- package/dist/behavior.js +493 -0
- package/dist/behavior.js.map +1 -0
- package/dist/coverage.d.ts +44 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +43 -0
- package/dist/coverage.js.map +1 -0
- package/dist/declarations.d.ts +53 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +45 -0
- package/dist/declarations.js.map +1 -0
- package/dist/ed25519.d.ts +8 -0
- package/dist/ed25519.d.ts.map +1 -0
- package/dist/ed25519.js +128 -0
- package/dist/ed25519.js.map +1 -0
- package/dist/encodings.d.ts +9 -0
- package/dist/encodings.d.ts.map +1 -0
- package/dist/encodings.js +75 -0
- package/dist/encodings.js.map +1 -0
- package/dist/fields.d.ts +29 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +76 -0
- package/dist/fields.js.map +1 -0
- package/dist/findings.d.ts +189 -0
- package/dist/findings.d.ts.map +1 -0
- package/dist/findings.js +195 -0
- package/dist/findings.js.map +1 -0
- package/dist/footprint.d.ts +67 -0
- package/dist/footprint.d.ts.map +1 -0
- package/dist/footprint.js +78 -0
- package/dist/footprint.js.map +1 -0
- package/dist/graph.d.ts +111 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +390 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lint.d.ts +35 -0
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +260 -0
- package/dist/lint.js.map +1 -0
- package/dist/mapping.d.ts +28 -0
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.js +282 -0
- package/dist/mapping.js.map +1 -0
- package/dist/normalize.d.ts +27 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +56 -0
- package/dist/normalize.js.map +1 -0
- package/dist/plan.d.ts +240 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +746 -0
- package/dist/plan.js.map +1 -0
- package/dist/readiness.d.ts +146 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +346 -0
- package/dist/readiness.js.map +1 -0
- package/dist/reference.d.ts +39 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +74 -0
- package/dist/reference.js.map +1 -0
- package/dist/scenario.d.ts +114 -0
- package/dist/scenario.d.ts.map +1 -0
- package/dist/scenario.js +117 -0
- package/dist/scenario.js.map +1 -0
- package/dist/select.d.ts +41 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +71 -0
- package/dist/select.js.map +1 -0
- package/dist/trust.d.ts +237 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +511 -0
- package/dist/trust.js.map +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +20 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +47 -0
- package/dist/units.js.map +1 -0
- package/dist/verification.d.ts +54 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +115 -0
- package/dist/verification.js.map +1 -0
- package/package.json +28 -4
package/dist/mapping.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { MAPPING_ORIGINS, SEMANTIC_ENCODINGS, digestOf, isDigest, isPointer, parsePointer, readPointer, writePointer } from "@appport/protocol";
|
|
2
|
+
import { fromJSONSchema } from "@appport/schema";
|
|
3
|
+
import { convertEncoding } from "./encodings.js";
|
|
4
|
+
import { convertUnit } from "./units.js";
|
|
5
|
+
import { LOSSY_KINDS, MAPPING_FORMAT, MappingError, RELATIONS } from "./types.js";
|
|
6
|
+
const IRI = /^[A-Za-z][A-Za-z0-9+.-]*:[^\s]+$/;
|
|
7
|
+
const NAME_VERSION = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+@[1-9][0-9]*$/;
|
|
8
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
9
|
+
const isScalar = (value) => value === null || ["string", "number", "boolean"].includes(typeof value);
|
|
10
|
+
const RULE_OPS = ["copy", "const", "enum", "unit", "encoding"];
|
|
11
|
+
/** Structural validation of an untrusted artifact. Throws `INVALID_MAPPING` listing every problem found. */
|
|
12
|
+
export function parseMapping(value) {
|
|
13
|
+
const problems = [];
|
|
14
|
+
const bad = (path, message) => problems.push(`${path}: ${message}`);
|
|
15
|
+
if (!isObject(value))
|
|
16
|
+
throw new MappingError("INVALID_MAPPING", "a mapping must be a JSON object");
|
|
17
|
+
if (value["format"] !== MAPPING_FORMAT)
|
|
18
|
+
bad("format", `must be "${MAPPING_FORMAT}"`);
|
|
19
|
+
if (value["kind"] !== "declarative")
|
|
20
|
+
bad("kind", 'must be "declarative"; executable transformations are not part of appport.mapping/1');
|
|
21
|
+
if (typeof value["id"] !== "string" || !IRI.test(value["id"]))
|
|
22
|
+
bad("id", "must be an absolute IRI");
|
|
23
|
+
if (!Number.isInteger(value["version"]) || value["version"] < 1)
|
|
24
|
+
bad("version", "must be a positive integer");
|
|
25
|
+
if (!MAPPING_ORIGINS.includes(value["origin"]))
|
|
26
|
+
bad("origin", `must be one of ${MAPPING_ORIGINS.join(", ")}`);
|
|
27
|
+
for (const side of ["from", "to"]) {
|
|
28
|
+
const endpoint = value[side];
|
|
29
|
+
if (!isObject(endpoint)) {
|
|
30
|
+
bad(side, "must be an endpoint object");
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (typeof endpoint["application"] !== "string" || !endpoint["application"])
|
|
34
|
+
bad(`${side}.application`, "required");
|
|
35
|
+
if (typeof endpoint["capability"] !== "string" || !NAME_VERSION.test(endpoint["capability"]))
|
|
36
|
+
bad(`${side}.capability`, "must be name@version");
|
|
37
|
+
if (endpoint["side"] !== "input" && endpoint["side"] !== "output")
|
|
38
|
+
bad(`${side}.side`, "must be input or output");
|
|
39
|
+
if (endpoint["path"] !== undefined && (typeof endpoint["path"] !== "string" || !isPointer(endpoint["path"])))
|
|
40
|
+
bad(`${side}.path`, "must be a JSON pointer");
|
|
41
|
+
if (!isDigest(endpoint["schemaDigest"]))
|
|
42
|
+
bad(`${side}.schemaDigest`, "must be sha256:<64 hex>");
|
|
43
|
+
}
|
|
44
|
+
const rules = value["rules"];
|
|
45
|
+
const targets = [];
|
|
46
|
+
if (!Array.isArray(rules) || rules.length === 0)
|
|
47
|
+
bad("rules", "must be a non-empty array");
|
|
48
|
+
else {
|
|
49
|
+
rules.forEach((rule, index) => {
|
|
50
|
+
const path = `rules[${index}]`;
|
|
51
|
+
if (!isObject(rule) || !RULE_OPS.includes(rule["op"]))
|
|
52
|
+
return bad(path, `op must be one of ${RULE_OPS.join(", ")}`);
|
|
53
|
+
const op = rule["op"];
|
|
54
|
+
const pointer = (key) => {
|
|
55
|
+
const v = rule[key];
|
|
56
|
+
if (typeof v !== "string" || !isPointer(v) || v === "" || v.includes("/*"))
|
|
57
|
+
bad(`${path}.${key}`, "must be a non-root JSON pointer without *");
|
|
58
|
+
return typeof v === "string" ? v : "";
|
|
59
|
+
};
|
|
60
|
+
const to = pointer("to");
|
|
61
|
+
if (op !== "const")
|
|
62
|
+
pointer("from");
|
|
63
|
+
for (const earlier of targets) {
|
|
64
|
+
if (earlier === to || earlier.startsWith(`${to}/`) || to.startsWith(`${earlier}/`))
|
|
65
|
+
bad(`${path}.to`, `overlaps another rule's target ${earlier}`);
|
|
66
|
+
}
|
|
67
|
+
targets.push(to);
|
|
68
|
+
if (rule["conceptRelation"] !== undefined && !RELATIONS.includes(rule["conceptRelation"]))
|
|
69
|
+
bad(`${path}.conceptRelation`, "invalid relation");
|
|
70
|
+
const allowed = {
|
|
71
|
+
copy: ["op", "from", "to", "default", "conceptRelation"],
|
|
72
|
+
const: ["op", "to", "value", "conceptRelation"],
|
|
73
|
+
enum: ["op", "from", "to", "table", "relation", "unmapped", "conceptRelation"],
|
|
74
|
+
unit: ["op", "from", "to", "fromUnit", "toUnit", "conceptRelation"],
|
|
75
|
+
encoding: ["op", "from", "to", "fromEncoding", "toEncoding", "truncate", "conceptRelation"]
|
|
76
|
+
};
|
|
77
|
+
for (const key of Object.keys(rule))
|
|
78
|
+
if (!allowed[op].includes(key))
|
|
79
|
+
bad(`${path}.${key}`, `not allowed on ${op}`);
|
|
80
|
+
if (op === "const" && !("value" in rule))
|
|
81
|
+
bad(`${path}.value`, "required");
|
|
82
|
+
if (op === "enum") {
|
|
83
|
+
if (!isObject(rule["table"]) || Object.keys(rule["table"]).length === 0)
|
|
84
|
+
bad(`${path}.table`, "must be a non-empty object");
|
|
85
|
+
else {
|
|
86
|
+
for (const [key, entry] of Object.entries(rule["table"])) {
|
|
87
|
+
const ok = isScalar(entry) || (isObject(entry) && Object.keys(entry).length === 1 && Array.isArray(entry["ambiguous"]) && entry["ambiguous"].length >= 2 && entry["ambiguous"].every(isScalar));
|
|
88
|
+
if (!ok)
|
|
89
|
+
bad(`${path}.table.${key}`, "must be a scalar or { ambiguous: [two or more scalars] }");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!RELATIONS.includes(rule["relation"]))
|
|
93
|
+
bad(`${path}.relation`, "required: exact, broader, narrower or related");
|
|
94
|
+
if (rule["unmapped"] !== "reject" && rule["unmapped"] !== "omit")
|
|
95
|
+
bad(`${path}.unmapped`, 'must be "reject" or "omit"');
|
|
96
|
+
}
|
|
97
|
+
if (op === "unit") {
|
|
98
|
+
for (const key of ["fromUnit", "toUnit"])
|
|
99
|
+
if (typeof rule[key] !== "string" || !rule[key] || /\s/.test(rule[key]))
|
|
100
|
+
bad(`${path}.${key}`, "must be a unit code");
|
|
101
|
+
}
|
|
102
|
+
if (op === "encoding") {
|
|
103
|
+
for (const key of ["fromEncoding", "toEncoding"])
|
|
104
|
+
if (!SEMANTIC_ENCODINGS.includes(rule[key]))
|
|
105
|
+
bad(`${path}.${key}`, `must be one of ${SEMANTIC_ENCODINGS.join(", ")}`);
|
|
106
|
+
if (rule["truncate"] !== undefined && typeof rule["truncate"] !== "boolean")
|
|
107
|
+
bad(`${path}.truncate`, "must be a boolean");
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (!Array.isArray(value["lossy"]))
|
|
112
|
+
bad("lossy", "must be an array (use [] if nothing is lost)");
|
|
113
|
+
else {
|
|
114
|
+
value["lossy"].forEach((entry, index) => {
|
|
115
|
+
const path = `lossy[${index}]`;
|
|
116
|
+
if (!isObject(entry))
|
|
117
|
+
return bad(path, "must be an object");
|
|
118
|
+
const from = entry["from"];
|
|
119
|
+
const pointers = Array.isArray(from) ? from : [from];
|
|
120
|
+
if (!pointers.length || !pointers.every((p) => typeof p === "string" && isPointer(p) && p !== ""))
|
|
121
|
+
bad(`${path}.from`, "must be a pointer or a non-empty array of pointers");
|
|
122
|
+
if (!LOSSY_KINDS.includes(entry["kind"]))
|
|
123
|
+
bad(`${path}.kind`, `must be one of ${LOSSY_KINDS.join(", ")}`);
|
|
124
|
+
if (typeof entry["note"] !== "string" || !entry["note"])
|
|
125
|
+
bad(`${path}.note`, "required");
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (!Array.isArray(value["vectors"]))
|
|
129
|
+
bad("vectors", "must be an array");
|
|
130
|
+
else {
|
|
131
|
+
value["vectors"].forEach((vector, index) => {
|
|
132
|
+
const path = `vectors[${index}]`;
|
|
133
|
+
if (!isObject(vector) || !("source" in vector))
|
|
134
|
+
return bad(path, "needs a source");
|
|
135
|
+
if (("target" in vector) === ("rejects" in vector))
|
|
136
|
+
bad(path, "give exactly one of target / rejects");
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
for (const key of Object.keys(value)) {
|
|
140
|
+
if (!["format", "kind", "id", "version", "description", "origin", "from", "to", "rules", "lossy", "vectors"].includes(key))
|
|
141
|
+
bad(key, "unknown member");
|
|
142
|
+
}
|
|
143
|
+
if (problems.length)
|
|
144
|
+
throw new MappingError("INVALID_MAPPING", `invalid mapping: ${problems[0]}${problems.length > 1 ? ` (+${problems.length - 1} more)` : ""}`, { issues: problems });
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
/** The immutable identity digest of an artifact: SHA-256 of its RFC 8785 canonical JSON. */
|
|
148
|
+
export function mappingDigest(artifact) {
|
|
149
|
+
return digestOf(artifact);
|
|
150
|
+
}
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
function sourceValue(source, pointer) {
|
|
153
|
+
return readPointer(source, pointer);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Applies a mapping to one record. Pure and total over its input: every outcome
|
|
157
|
+
* is an output or a typed {@link MappingError}; nothing is inferred or defaulted
|
|
158
|
+
* beyond what a rule declares. An ambiguous value is refused unless the caller
|
|
159
|
+
* supplies `choices[targetPointer]` from the declared alternatives, and the
|
|
160
|
+
* choice is recorded in the trace.
|
|
161
|
+
*/
|
|
162
|
+
export function applyMapping(mapping, source, options = {}) {
|
|
163
|
+
const output = {};
|
|
164
|
+
const trace = [];
|
|
165
|
+
const lossyFrom = new Set(mapping.lossy.flatMap((entry) => (Array.isArray(entry.from) ? entry.from : [entry.from])));
|
|
166
|
+
mapping.rules.forEach((rule, index) => {
|
|
167
|
+
const base = { rule: index, op: rule.op, to: rule.to };
|
|
168
|
+
if (rule.op === "const") {
|
|
169
|
+
writePointer(output, rule.to, rule.value);
|
|
170
|
+
trace.push({ ...base });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const value = sourceValue(source, rule.from);
|
|
174
|
+
const lossy = lossyFrom.has(rule.from) ? { lossy: true } : {};
|
|
175
|
+
if (value === undefined) {
|
|
176
|
+
if (rule.op === "copy" && rule.default !== undefined) {
|
|
177
|
+
writePointer(output, rule.to, rule.default);
|
|
178
|
+
trace.push({ ...base, from: rule.from });
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
trace.push({ ...base, from: rule.from, skipped: "source-absent" });
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
switch (rule.op) {
|
|
186
|
+
case "copy":
|
|
187
|
+
writePointer(output, rule.to, value);
|
|
188
|
+
trace.push({ ...base, from: rule.from, ...lossy });
|
|
189
|
+
return;
|
|
190
|
+
case "unit":
|
|
191
|
+
writePointer(output, rule.to, convertUnit(value, rule.fromUnit, rule.toUnit, rule.from));
|
|
192
|
+
trace.push({ ...base, from: rule.from, ...lossy });
|
|
193
|
+
return;
|
|
194
|
+
case "encoding":
|
|
195
|
+
writePointer(output, rule.to, convertEncoding(value, rule.fromEncoding, rule.toEncoding, rule.from, rule.truncate ?? false));
|
|
196
|
+
trace.push({ ...base, from: rule.from, ...lossy });
|
|
197
|
+
return;
|
|
198
|
+
case "enum": {
|
|
199
|
+
if (!isScalar(value))
|
|
200
|
+
throw new MappingError("INVALID_VALUE", "expected a scalar enum value", { pointer: rule.from });
|
|
201
|
+
const entry = Object.prototype.hasOwnProperty.call(rule.table, String(value)) ? rule.table[String(value)] : undefined;
|
|
202
|
+
if (entry === undefined) {
|
|
203
|
+
if (rule.unmapped === "omit") {
|
|
204
|
+
trace.push({ ...base, from: rule.from, skipped: "unmapped-omitted" });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
throw new MappingError("UNMAPPED_VALUE", `${JSON.stringify(value)} has no mapping`, { pointer: rule.from });
|
|
208
|
+
}
|
|
209
|
+
if (entry !== null && typeof entry === "object") {
|
|
210
|
+
const chosen = options.choices?.[rule.to];
|
|
211
|
+
if (chosen === undefined || !entry.ambiguous.some((candidate) => candidate === chosen)) {
|
|
212
|
+
throw new MappingError("AMBIGUOUS_VALUE", `${JSON.stringify(value)} maps to ${entry.ambiguous.map((a) => JSON.stringify(a)).join(" or ")}; the caller must choose one for ${rule.to}`, { pointer: rule.from });
|
|
213
|
+
}
|
|
214
|
+
writePointer(output, rule.to, chosen);
|
|
215
|
+
trace.push({ ...base, from: rule.from, choice: { options: entry.ambiguous, chose: chosen }, lossy: true });
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
writePointer(output, rule.to, entry);
|
|
219
|
+
trace.push({ ...base, from: rule.from, ...lossy });
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return { output, trace };
|
|
225
|
+
}
|
|
226
|
+
/** The records a mapping's `from` endpoint addresses inside a document: the document, a member, or each element of an array. */
|
|
227
|
+
export function selectRecords(document, endpoint) {
|
|
228
|
+
const path = endpoint.path ?? "";
|
|
229
|
+
if (!path.endsWith("/*")) {
|
|
230
|
+
const value = path === "" ? document : readPointer(document, path);
|
|
231
|
+
return value === undefined ? [] : [value];
|
|
232
|
+
}
|
|
233
|
+
const list = readPointer(document, path.slice(0, -2));
|
|
234
|
+
if (!Array.isArray(list))
|
|
235
|
+
throw new MappingError("INVALID_VALUE", `expected an array at ${path.slice(0, -2) || "the document root"}`, { pointer: path });
|
|
236
|
+
return list;
|
|
237
|
+
}
|
|
238
|
+
/** Applies a mapping and checks the result against the target's *published* schema. */
|
|
239
|
+
export function applyAndValidate(mapping, source, targetSchema, options = {}) {
|
|
240
|
+
const result = applyMapping(mapping, source, options);
|
|
241
|
+
const validation = fromJSONSchema(targetSchema).validate(result.output);
|
|
242
|
+
if (!validation.ok) {
|
|
243
|
+
const issues = validation.issues.map((issue) => `${issue.path.join("/") || "/"}: ${issue.message}`);
|
|
244
|
+
throw new MappingError("INVALID_VALUE", `the mapped value does not satisfy the target schema: ${issues[0]}`, { issues });
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
/** Runs the artifact's own vectors. Returns one message per failing vector. */
|
|
249
|
+
export function runVectors(mapping) {
|
|
250
|
+
const failures = [];
|
|
251
|
+
mapping.vectors.forEach((vector, index) => {
|
|
252
|
+
const label = vector.name ?? `vector ${index}`;
|
|
253
|
+
try {
|
|
254
|
+
const { output } = applyMapping(mapping, vector.source, vector.choices ? { choices: vector.choices } : {});
|
|
255
|
+
if (vector.rejects)
|
|
256
|
+
failures.push(`${label}: expected ${vector.rejects}, got a result`);
|
|
257
|
+
else if (JSON.stringify(sortKeys(output)) !== JSON.stringify(sortKeys(vector.target))) {
|
|
258
|
+
failures.push(`${label}: expected ${JSON.stringify(vector.target)}, got ${JSON.stringify(output)}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (!(error instanceof MappingError))
|
|
263
|
+
throw error;
|
|
264
|
+
if (vector.rejects !== error.code)
|
|
265
|
+
failures.push(`${label}: ${vector.rejects ? `expected ${vector.rejects}` : "expected a result"}, got ${error.code}`);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
return failures;
|
|
269
|
+
}
|
|
270
|
+
function sortKeys(value) {
|
|
271
|
+
if (Array.isArray(value))
|
|
272
|
+
return value.map(sortKeys);
|
|
273
|
+
if (isObject(value))
|
|
274
|
+
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortKeys(value[key])]));
|
|
275
|
+
return value;
|
|
276
|
+
}
|
|
277
|
+
/** Pointers a rule reads and writes; `const` reads nothing. */
|
|
278
|
+
export function ruleSources(rule) {
|
|
279
|
+
return rule.op === "const" ? [] : [rule.from];
|
|
280
|
+
}
|
|
281
|
+
export { parsePointer };
|
|
282
|
+
//# sourceMappingURL=mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,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3
|
+
* with the published unit, encoding and enum value-concept annotations. Fields with no concept are compared only by position
|
|
4
|
+
* and are reported as such: they are never silently treated as equal.
|
|
5
|
+
*/
|
|
6
|
+
import { type JsonValue } from "@appport/protocol";
|
|
7
|
+
import type { FieldFootprint } from "./footprint.js";
|
|
8
|
+
export interface NormalizedLeaf {
|
|
9
|
+
/** The concept IRI, or `pointer:<pointer>` for a field that declares none. */
|
|
10
|
+
key: string;
|
|
11
|
+
conceptual: boolean;
|
|
12
|
+
pointer: string;
|
|
13
|
+
value: JsonValue;
|
|
14
|
+
}
|
|
15
|
+
/** Normalizes one value in the units and encoding stated for it. `undefined` when it cannot be normalized. */
|
|
16
|
+
export declare function normalizeValue(value: unknown, annotations: {
|
|
17
|
+
unit?: string;
|
|
18
|
+
encoding?: string;
|
|
19
|
+
enumConcepts?: Record<string, string>;
|
|
20
|
+
}): JsonValue | undefined;
|
|
21
|
+
/** Concept-keyed leaves of an observed value. Array-valued fields are not flattened; they are returned in `skipped`. */
|
|
22
|
+
export declare function normalizeObservation(fields: readonly FieldFootprint[], value: unknown): {
|
|
23
|
+
leaves: NormalizedLeaf[];
|
|
24
|
+
skipped: string[];
|
|
25
|
+
};
|
|
26
|
+
export declare const same: (a: unknown, b: unknown) => boolean;
|
|
27
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIrD,MAAM,WAAW,cAAc;IAC7B,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,8GAA8G;AAC9G,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,GAAG,SAAS,CAoB9J;AAED,wHAAwH;AACxH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG;IAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAYvI;AAED,eAAO,MAAM,IAAI,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,OAA8C,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparing meaning, not representation. Values are keyed by the concept the contract publishes for the field and normalized
|
|
3
|
+
* with the published unit, encoding and enum value-concept annotations. Fields with no concept are compared only by position
|
|
4
|
+
* and are reported as such: they are never silently treated as equal.
|
|
5
|
+
*/
|
|
6
|
+
import { canonicalize, readPointer } from "@appport/protocol";
|
|
7
|
+
import { convertEncoding } from "./encodings.js";
|
|
8
|
+
import { UNITS, isKnownUnit } from "./units.js";
|
|
9
|
+
/** Normalizes one value in the units and encoding stated for it. `undefined` when it cannot be normalized. */
|
|
10
|
+
export function normalizeValue(value, annotations) {
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (annotations.enumConcepts && (typeof value === "string" || typeof value === "number")) {
|
|
14
|
+
const concept = annotations.enumConcepts[String(value)];
|
|
15
|
+
return concept === undefined ? undefined : concept;
|
|
16
|
+
}
|
|
17
|
+
if (annotations.unit !== undefined) {
|
|
18
|
+
if (typeof value !== "number" || !isKnownUnit(annotations.unit))
|
|
19
|
+
return undefined;
|
|
20
|
+
const u = UNITS[annotations.unit];
|
|
21
|
+
const base = (value * u.num) / u.den;
|
|
22
|
+
return `${u.dimension}:${Number(base.toPrecision(12))}`;
|
|
23
|
+
}
|
|
24
|
+
if (annotations.encoding !== undefined) {
|
|
25
|
+
try {
|
|
26
|
+
return convertEncoding(value, annotations.encoding, "epoch-milliseconds", "");
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
/** Concept-keyed leaves of an observed value. Array-valued fields are not flattened; they are returned in `skipped`. */
|
|
35
|
+
export function normalizeObservation(fields, value) {
|
|
36
|
+
const leaves = [];
|
|
37
|
+
const skipped = [];
|
|
38
|
+
for (const field of fields) {
|
|
39
|
+
if (field.pointer.includes("*")) {
|
|
40
|
+
skipped.push(field.pointer);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const raw = readPointer(value, field.pointer);
|
|
44
|
+
if (raw === undefined)
|
|
45
|
+
continue;
|
|
46
|
+
const normalized = normalizeValue(raw, field);
|
|
47
|
+
if (normalized === undefined) {
|
|
48
|
+
skipped.push(field.pointer);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
leaves.push({ key: field.concept ?? `pointer:${field.pointer}`, conceptual: field.concept !== undefined, pointer: field.pointer, value: normalized });
|
|
52
|
+
}
|
|
53
|
+
return { leaves: leaves.sort((a, b) => a.key.localeCompare(b.key)), skipped: skipped.sort() };
|
|
54
|
+
}
|
|
55
|
+
export const same = (a, b) => canonicalize(a) === canonicalize(b);
|
|
56
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,C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,CAAC,CAAC"}
|
package/dist/plan.d.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration planning: from a stated task and the *published* contracts of the applications
|
|
3
|
+
* involved, produce a deterministic, machine-readable account of whether an integration can be
|
|
4
|
+
* attempted, what it would involve, and what stands in the way.
|
|
5
|
+
*
|
|
6
|
+
* What a plan is not: an authorization (`authorization.granted` is always false), an execution
|
|
7
|
+
* (nothing is called), or a claim that anything works. It is only as good as the contracts, and
|
|
8
|
+
* every place where a contract is silent becomes a finding rather than a default.
|
|
9
|
+
*
|
|
10
|
+
* Statuses, in precedence order:
|
|
11
|
+
* - `blocked`: a published fact stops the integration (incompatible, unauthorized, stale). Not fixable by acknowledging.
|
|
12
|
+
* - `needs_input`: the contracts are silent or ambiguous where the caller can supply or accept something.
|
|
13
|
+
* - `unverifiable`: it could be attempted, but its outcome could not be confirmed from published evidence.
|
|
14
|
+
* - `ready`: every decision rests on a published declaration or on a recorded acknowledgement, and verification exists.
|
|
15
|
+
* `ready` means "nothing in the contracts prevents attempting this", not "this will work".
|
|
16
|
+
*/
|
|
17
|
+
import { type AppPortManifest, type JsonValue } from "@appport/protocol";
|
|
18
|
+
import { type ObservationCoverage } from "./coverage.js";
|
|
19
|
+
import { type DeclarationFacts, type Facet, type InformationState, type RetryDisposition } from "./declarations.js";
|
|
20
|
+
import { type FieldPairing } from "./fields.js";
|
|
21
|
+
import { type DiscoveryFinding } from "./findings.js";
|
|
22
|
+
import { type CapabilityMatch, type Selector } from "./select.js";
|
|
23
|
+
import type { MappingTrustAssessment, MappingTrustResult } from "./trust.js";
|
|
24
|
+
export declare const PLAN_FORMAT: "appport.integration-plan/1";
|
|
25
|
+
export type PlanStatus = "ready" | "blocked" | "needs_input" | "unverifiable";
|
|
26
|
+
export type FindingSeverity = "blocker" | "input" | "unverifiable" | "note";
|
|
27
|
+
export type PlanTask = {
|
|
28
|
+
kind: "invoke";
|
|
29
|
+
description?: string;
|
|
30
|
+
target: Selector;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "transfer";
|
|
33
|
+
description?: string;
|
|
34
|
+
source: Selector;
|
|
35
|
+
target: Selector;
|
|
36
|
+
tolerateLossy?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export interface PlanInput {
|
|
39
|
+
task: PlanTask;
|
|
40
|
+
/** Manifests the consumer fetched. Which applications to fetch is the consumer's decision: AppPort has no registry. */
|
|
41
|
+
manifests: readonly AppPortManifest[];
|
|
42
|
+
/** Mapping artifacts the consumer fetched, matched to references by digest. */
|
|
43
|
+
artifacts?: readonly unknown[];
|
|
44
|
+
caller?: {
|
|
45
|
+
/** Scopes the caller states it holds, per application id. Compared by exact string; never verified here. */
|
|
46
|
+
scopes?: Record<string, string[]>;
|
|
47
|
+
/** `application/name@version` keys the caller states it holds an approval for. Never verified here. */
|
|
48
|
+
approvals?: string[];
|
|
49
|
+
};
|
|
50
|
+
/** Target input pointers the caller will supply itself. */
|
|
51
|
+
provide?: string[];
|
|
52
|
+
/** Target pointer → source pointer, when the caller resolves an ambiguous pairing. */
|
|
53
|
+
bindings?: Record<string, string>;
|
|
54
|
+
/** Target pointers for which the caller will choose among ambiguous enum values. */
|
|
55
|
+
choices?: string[];
|
|
56
|
+
/** Finding ids the caller explicitly accepts. Only acknowledgeable findings honour this. */
|
|
57
|
+
acknowledge?: string[];
|
|
58
|
+
/** Evidence from outside the contract (telemetry, analysis). Provenance is kept. */
|
|
59
|
+
findings?: readonly DiscoveryFinding[];
|
|
60
|
+
/** Contract digests the plan was made against earlier, by application id. */
|
|
61
|
+
pins?: Record<string, string>;
|
|
62
|
+
/** Earlier versions of manifests; breaking changes affecting the plan block it. */
|
|
63
|
+
previous?: readonly AppPortManifest[];
|
|
64
|
+
/**
|
|
65
|
+
* The outcome of `assessMappingTrust` for the supplied artifacts. Planning stays synchronous and pure; signature
|
|
66
|
+
* verification is asynchronous and happens there. Without it no mapping is treated as trusted: each one a plan would use
|
|
67
|
+
* is reported as not assessed. Pins are checked there, never recorded.
|
|
68
|
+
*/
|
|
69
|
+
trust?: MappingTrustAssessment;
|
|
70
|
+
/** What the runtime evidence in `findings` could have seen (see `ObservationCoverage`). Never read as completeness. */
|
|
71
|
+
coverage?: readonly ObservationCoverage[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* How a mapping the plan would use stands, from the five separate checks. Only `eligible` and `accepted-locally` make a mapping usable;
|
|
75
|
+
* `accepted-locally` means the caller explicitly acknowledged the finding(s) that stood in the way. It is not trust.
|
|
76
|
+
*/
|
|
77
|
+
export declare const MAPPING_DISPOSITIONS: readonly ["eligible", "accepted-locally", "needs-local-acceptance", "unsigned", "untrusted", "rejected", "invalid", "unverifiable", "policy-unavailable", "trust-not-assessed", "pin-missing", "pin-conflict", "incompatible", "artifact-missing", "not-needed"];
|
|
78
|
+
export type MappingDisposition = (typeof MAPPING_DISPOSITIONS)[number];
|
|
79
|
+
export interface MappingAssessment {
|
|
80
|
+
id: string;
|
|
81
|
+
version: number;
|
|
82
|
+
direction: "inbound" | "outbound";
|
|
83
|
+
/** `name@version` of the capability the reference serves. */
|
|
84
|
+
for: string;
|
|
85
|
+
origin: string;
|
|
86
|
+
/** Whether the plan needed a mapping for this pair (some required target field was not a direct match). */
|
|
87
|
+
needed: boolean;
|
|
88
|
+
expectedDigest: string;
|
|
89
|
+
actualDigest?: string;
|
|
90
|
+
publisher?: string;
|
|
91
|
+
keyId?: string;
|
|
92
|
+
authenticity?: MappingTrustResult["authenticity"]["status"];
|
|
93
|
+
integrity?: MappingTrustResult["integrity"]["status"];
|
|
94
|
+
trust?: {
|
|
95
|
+
status: MappingTrustResult["trust"]["status"];
|
|
96
|
+
rule: string;
|
|
97
|
+
};
|
|
98
|
+
semantic?: "valid" | "invalid" | "unchecked";
|
|
99
|
+
pins?: MappingTrustResult["pins"]["status"];
|
|
100
|
+
/** The verifier's own verdict: all five checks succeeded. Independent of local acceptance. */
|
|
101
|
+
eligible: boolean;
|
|
102
|
+
disposition: MappingDisposition;
|
|
103
|
+
acceptedLocally: boolean;
|
|
104
|
+
/** Stable reason codes from the trust verifier plus the planner's own. */
|
|
105
|
+
reasons: string[];
|
|
106
|
+
}
|
|
107
|
+
/** One capability's requirements restated from its published contract, each facet with its information state. */
|
|
108
|
+
export interface CapabilityRequirements {
|
|
109
|
+
capability: string;
|
|
110
|
+
role: "source" | "target";
|
|
111
|
+
purpose: Facet<string>;
|
|
112
|
+
authority: Facet<string>;
|
|
113
|
+
authorization: DeclarationFacts["authorization"];
|
|
114
|
+
approval: DeclarationFacts["approval"];
|
|
115
|
+
effect: DeclarationFacts["effect"];
|
|
116
|
+
declaredEffects: Facet<string[]>;
|
|
117
|
+
emits: string[];
|
|
118
|
+
access: {
|
|
119
|
+
state: InformationState;
|
|
120
|
+
reads: string[];
|
|
121
|
+
changes: Array<{
|
|
122
|
+
resource: string;
|
|
123
|
+
operations?: string[];
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
126
|
+
idempotency: DeclarationFacts["idempotency"];
|
|
127
|
+
retry: RetryDisposition;
|
|
128
|
+
failures: Array<{
|
|
129
|
+
code: string;
|
|
130
|
+
retry: string;
|
|
131
|
+
effect: string;
|
|
132
|
+
}>;
|
|
133
|
+
preconditions: string[];
|
|
134
|
+
verification: {
|
|
135
|
+
state: InformationState;
|
|
136
|
+
methods: Array<{
|
|
137
|
+
id: string;
|
|
138
|
+
kind: string;
|
|
139
|
+
}>;
|
|
140
|
+
evidence: string;
|
|
141
|
+
};
|
|
142
|
+
dependencies: {
|
|
143
|
+
state: InformationState;
|
|
144
|
+
required: string[];
|
|
145
|
+
optional: string[];
|
|
146
|
+
};
|
|
147
|
+
/** Facets the contract leaves unknown or that only observation could answer. */
|
|
148
|
+
unknowns: string[];
|
|
149
|
+
}
|
|
150
|
+
export interface PlanCondition {
|
|
151
|
+
kind: "approval" | "scope" | "precondition" | "idempotency-key" | "mapping" | "acknowledged" | "verification-after";
|
|
152
|
+
capability?: string;
|
|
153
|
+
detail: string;
|
|
154
|
+
}
|
|
155
|
+
export interface NextAction {
|
|
156
|
+
finding: string;
|
|
157
|
+
severity: FindingSeverity;
|
|
158
|
+
action: string;
|
|
159
|
+
}
|
|
160
|
+
export interface PlanFinding {
|
|
161
|
+
/** Deterministic. Pass it in `acknowledge` to accept an acknowledgeable finding. */
|
|
162
|
+
id: string;
|
|
163
|
+
severity: FindingSeverity;
|
|
164
|
+
code: string;
|
|
165
|
+
state: InformationState;
|
|
166
|
+
message: string;
|
|
167
|
+
/** `application/name@version` */
|
|
168
|
+
capabilities: string[];
|
|
169
|
+
missing: string[];
|
|
170
|
+
hints: string[];
|
|
171
|
+
acknowledgeable: boolean;
|
|
172
|
+
acknowledged?: true;
|
|
173
|
+
}
|
|
174
|
+
export interface PlanDecision {
|
|
175
|
+
id: string;
|
|
176
|
+
question: string;
|
|
177
|
+
state: InformationState;
|
|
178
|
+
answer?: JsonValue;
|
|
179
|
+
/** Where in a published contract the answer comes from. Absent only when `findings` explains why. */
|
|
180
|
+
source?: string;
|
|
181
|
+
provenance: "declared" | "inferred" | "observed" | "caller";
|
|
182
|
+
/** Ids of the findings that explain a state other than `declared` / `declared-absence`. */
|
|
183
|
+
findings: string[];
|
|
184
|
+
}
|
|
185
|
+
export interface PlanStep {
|
|
186
|
+
order: number;
|
|
187
|
+
action: "check-precondition" | "obtain-approval" | "invoke" | "map" | "verify";
|
|
188
|
+
application: string;
|
|
189
|
+
capability?: string;
|
|
190
|
+
detail: Record<string, JsonValue>;
|
|
191
|
+
}
|
|
192
|
+
export interface IntegrationPlan {
|
|
193
|
+
format: typeof PLAN_FORMAT;
|
|
194
|
+
status: PlanStatus;
|
|
195
|
+
task: JsonValue;
|
|
196
|
+
/** What the plan was made from. Re-fetch and compare before relying on it. */
|
|
197
|
+
basis: {
|
|
198
|
+
contracts: Record<string, string>;
|
|
199
|
+
mappings: Array<{
|
|
200
|
+
id: string;
|
|
201
|
+
version: number;
|
|
202
|
+
digest: string;
|
|
203
|
+
}>;
|
|
204
|
+
};
|
|
205
|
+
selected: {
|
|
206
|
+
source?: CapabilityMatch;
|
|
207
|
+
target?: CapabilityMatch;
|
|
208
|
+
candidates: CapabilityMatch[];
|
|
209
|
+
};
|
|
210
|
+
decisions: PlanDecision[];
|
|
211
|
+
findings: PlanFinding[];
|
|
212
|
+
fields: FieldPairing[];
|
|
213
|
+
/** Declared dependencies only (`provenance` is always `declared`): observed or inferred dependencies are findings, never entries here. */
|
|
214
|
+
dependencies: Array<{
|
|
215
|
+
from: string;
|
|
216
|
+
relationship: string;
|
|
217
|
+
target: string;
|
|
218
|
+
required: boolean;
|
|
219
|
+
resolved: boolean;
|
|
220
|
+
provenance: "declared";
|
|
221
|
+
}>;
|
|
222
|
+
/** Every transformation the contracts publish for this pair, with the verification outcome of each. */
|
|
223
|
+
mappings: MappingAssessment[];
|
|
224
|
+
requirements: CapabilityRequirements[];
|
|
225
|
+
/** Feasibility is not authorization. `feasible`: nothing published prevents it. `undetermined`: the caller or the contracts must supply something. */
|
|
226
|
+
feasibility: "feasible" | "undetermined" | "not-feasible";
|
|
227
|
+
/** What must hold or be done before the steps may be attempted, and what is accepted on the caller's word. */
|
|
228
|
+
conditions: PlanCondition[];
|
|
229
|
+
/** For each open finding, what to do about it. */
|
|
230
|
+
nextActions: NextAction[];
|
|
231
|
+
steps: PlanStep[];
|
|
232
|
+
authorization: {
|
|
233
|
+
granted: false;
|
|
234
|
+
note: string;
|
|
235
|
+
};
|
|
236
|
+
limits: string[];
|
|
237
|
+
}
|
|
238
|
+
export declare const PLAN_LIMITS: readonly string[];
|
|
239
|
+
export declare function planIntegration(input: PlanInput): IntegrationPlan;
|
|
240
|
+
//# sourceMappingURL=plan.d.ts.map
|