@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.
Files changed (95) hide show
  1. package/LICENSE +126 -0
  2. package/README.md +34 -2
  3. package/dist/base64url.d.ts +4 -0
  4. package/dist/base64url.d.ts.map +1 -0
  5. package/dist/base64url.js +36 -0
  6. package/dist/base64url.js.map +1 -0
  7. package/dist/behavior.d.ts +164 -0
  8. package/dist/behavior.d.ts.map +1 -0
  9. package/dist/behavior.js +493 -0
  10. package/dist/behavior.js.map +1 -0
  11. package/dist/coverage.d.ts +44 -0
  12. package/dist/coverage.d.ts.map +1 -0
  13. package/dist/coverage.js +43 -0
  14. package/dist/coverage.js.map +1 -0
  15. package/dist/declarations.d.ts +53 -0
  16. package/dist/declarations.d.ts.map +1 -0
  17. package/dist/declarations.js +45 -0
  18. package/dist/declarations.js.map +1 -0
  19. package/dist/ed25519.d.ts +8 -0
  20. package/dist/ed25519.d.ts.map +1 -0
  21. package/dist/ed25519.js +128 -0
  22. package/dist/ed25519.js.map +1 -0
  23. package/dist/encodings.d.ts +9 -0
  24. package/dist/encodings.d.ts.map +1 -0
  25. package/dist/encodings.js +75 -0
  26. package/dist/encodings.js.map +1 -0
  27. package/dist/fields.d.ts +29 -0
  28. package/dist/fields.d.ts.map +1 -0
  29. package/dist/fields.js +76 -0
  30. package/dist/fields.js.map +1 -0
  31. package/dist/findings.d.ts +189 -0
  32. package/dist/findings.d.ts.map +1 -0
  33. package/dist/findings.js +195 -0
  34. package/dist/findings.js.map +1 -0
  35. package/dist/footprint.d.ts +67 -0
  36. package/dist/footprint.d.ts.map +1 -0
  37. package/dist/footprint.js +78 -0
  38. package/dist/footprint.js.map +1 -0
  39. package/dist/graph.d.ts +111 -0
  40. package/dist/graph.d.ts.map +1 -0
  41. package/dist/graph.js +390 -0
  42. package/dist/graph.js.map +1 -0
  43. package/dist/index.d.ts +38 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +38 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/lint.d.ts +35 -0
  48. package/dist/lint.d.ts.map +1 -0
  49. package/dist/lint.js +260 -0
  50. package/dist/lint.js.map +1 -0
  51. package/dist/mapping.d.ts +28 -0
  52. package/dist/mapping.d.ts.map +1 -0
  53. package/dist/mapping.js +282 -0
  54. package/dist/mapping.js.map +1 -0
  55. package/dist/normalize.d.ts +27 -0
  56. package/dist/normalize.d.ts.map +1 -0
  57. package/dist/normalize.js +56 -0
  58. package/dist/normalize.js.map +1 -0
  59. package/dist/plan.d.ts +240 -0
  60. package/dist/plan.d.ts.map +1 -0
  61. package/dist/plan.js +746 -0
  62. package/dist/plan.js.map +1 -0
  63. package/dist/readiness.d.ts +146 -0
  64. package/dist/readiness.d.ts.map +1 -0
  65. package/dist/readiness.js +346 -0
  66. package/dist/readiness.js.map +1 -0
  67. package/dist/reference.d.ts +39 -0
  68. package/dist/reference.d.ts.map +1 -0
  69. package/dist/reference.js +74 -0
  70. package/dist/reference.js.map +1 -0
  71. package/dist/scenario.d.ts +114 -0
  72. package/dist/scenario.d.ts.map +1 -0
  73. package/dist/scenario.js +117 -0
  74. package/dist/scenario.js.map +1 -0
  75. package/dist/select.d.ts +41 -0
  76. package/dist/select.d.ts.map +1 -0
  77. package/dist/select.js +71 -0
  78. package/dist/select.js.map +1 -0
  79. package/dist/trust.d.ts +237 -0
  80. package/dist/trust.d.ts.map +1 -0
  81. package/dist/trust.js +511 -0
  82. package/dist/trust.js.map +1 -0
  83. package/dist/types.d.ts +130 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/types.js +19 -0
  86. package/dist/types.js.map +1 -0
  87. package/dist/units.d.ts +20 -0
  88. package/dist/units.d.ts.map +1 -0
  89. package/dist/units.js +47 -0
  90. package/dist/units.js.map +1 -0
  91. package/dist/verification.d.ts +54 -0
  92. package/dist/verification.d.ts.map +1 -0
  93. package/dist/verification.js +115 -0
  94. package/dist/verification.js.map +1 -0
  95. package/package.json +28 -4
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `@appport/integration`: pure helpers for AppPort's integration contract.
3
+ *
4
+ * - **Mappings** (`appport.mapping/1`): parse, lint against published manifests, apply, run vectors.
5
+ * - **References**: verify an artifact against its immutable identity and digest; pin identities.
6
+ * - **Verification**: plan the declared probes and turn observations into evidence.
7
+ * - **Footprints**: lay out what a capability consumes, produces, changes and depends on.
8
+ * - **Graph**: derive dependency, data-flow, effect and verification edges from published contracts, with the
9
+ * provenance of every edge (declared, inferred, observed) and an explicit list of what is unknown.
10
+ * - **Replacement readiness**: given a proposed replacement, report affected consumers, incompatibilities, shared
11
+ * state, changed effects, missing verification and required tests. A readiness assessment, never an approval.
12
+ *
13
+ * No I/O, no clocks beyond an injectable `now`, no registry, no code execution. Whatever
14
+ * is not in a published contract is not guessed here.
15
+ */
16
+ export * from "./types.js";
17
+ export * from "./units.js";
18
+ export * from "./encodings.js";
19
+ export * from "./mapping.js";
20
+ export * from "./lint.js";
21
+ export * from "./reference.js";
22
+ export * from "./verification.js";
23
+ export * from "./footprint.js";
24
+ export * from "./findings.js";
25
+ export * from "./graph.js";
26
+ export * from "./readiness.js";
27
+ export * from "./declarations.js";
28
+ export * from "./select.js";
29
+ export * from "./fields.js";
30
+ export * from "./plan.js";
31
+ export * from "./coverage.js";
32
+ export * from "./base64url.js";
33
+ export * from "./trust.js";
34
+ export * from "./scenario.js";
35
+ export * from "./normalize.js";
36
+ export * from "./behavior.js";
37
+ export * from "./ed25519.js";
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
package/dist/lint.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { type AppPortManifest, type JSONSchema } from "@appport/protocol";
2
+ import type { Endpoint, LintIssue, MappingArtifact } from "./types.js";
3
+ /**
4
+ * The identity of a schema for mapping purposes: SHA-256 of its canonical JSON
5
+ * with descriptive prose removed. Editing a `description` does not change it;
6
+ * changing a type, enum, bound, annotation or `required` does, which is exactly
7
+ * when a mapping written against the schema may no longer be correct.
8
+ */
9
+ export declare function schemaIdentity(schema: JSONSchema): string;
10
+ export interface ResolvedEndpoint {
11
+ /** The capability schema the endpoint addresses (input or output). */
12
+ root: JSONSchema;
13
+ /** The record schema inside it. */
14
+ record: JSONSchema;
15
+ }
16
+ /** Resolves an endpoint against an application's published manifest. */
17
+ export declare function resolveEndpoint(manifest: AppPortManifest, endpoint: Endpoint): ResolvedEndpoint | string;
18
+ /**
19
+ * Statically checks a mapping against the two applications' published manifests.
20
+ * An `error` means the mapping must not be used; a `warning` needs a decision.
21
+ *
22
+ * What it proves: the mapping was written against the schemas as they are now
23
+ * (digest), every pointer exists, source and target fields carry the same declared
24
+ * meaning (concept, unit, encoding, enum-value concepts) or the difference is
25
+ * declared as a relation and as loss, nothing the target requires is missing, and
26
+ * no source field is silently dropped. What it cannot prove: that a business rule
27
+ * holds, or that the annotations themselves are true.
28
+ */
29
+ export declare function lintMapping(mapping: MappingArtifact, manifests: {
30
+ from: AppPortManifest;
31
+ to: AppPortManifest;
32
+ }, options?: {
33
+ requireConcepts?: boolean;
34
+ }): LintIssue[];
35
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,UAAU,EAEhB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAQ,MAAM,YAAY,CAAC;AAI7E;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CASzD;AAED,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,IAAI,EAAE,UAAU,CAAC;IACjB,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,gBAAgB,GAAG,MAAM,CASxG;AA4BD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,EAAE,EAAE,eAAe,CAAA;CAAE,EACzD,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,SAAS,EAAE,CAgGb"}
package/dist/lint.js ADDED
@@ -0,0 +1,260 @@
1
+ import { SEMANTIC_KEYWORDS, digestOf, isRequiredAt, schemaAt } from "@appport/protocol";
2
+ import { isKnownUnit, unitProblem } from "./units.js";
3
+ const PROSE = new Set(["description", "title", "examples", "$comment", "deprecated"]);
4
+ /**
5
+ * The identity of a schema for mapping purposes: SHA-256 of its canonical JSON
6
+ * with descriptive prose removed. Editing a `description` does not change it;
7
+ * changing a type, enum, bound, annotation or `required` does, which is exactly
8
+ * when a mapping written against the schema may no longer be correct.
9
+ */
10
+ export function schemaIdentity(schema) {
11
+ const strip = (value) => {
12
+ if (Array.isArray(value))
13
+ return value.map(strip);
14
+ if (value !== null && typeof value === "object") {
15
+ return Object.fromEntries(Object.entries(value).filter(([key]) => !PROSE.has(key)).map(([key, v]) => [key, strip(v)]));
16
+ }
17
+ return value;
18
+ };
19
+ return digestOf(strip(schema));
20
+ }
21
+ /** Resolves an endpoint against an application's published manifest. */
22
+ export function resolveEndpoint(manifest, endpoint) {
23
+ if (manifest.application.id !== endpoint.application)
24
+ return `the manifest is for ${manifest.application.id}, not ${endpoint.application}`;
25
+ const [name, version] = endpoint.capability.split("@");
26
+ const definition = manifest.capabilities.find((c) => c.name === name)?.definitions.find((d) => d.version === Number(version));
27
+ if (!definition)
28
+ return `${endpoint.capability} is not declared by ${endpoint.application}`;
29
+ const root = endpoint.side === "input" ? definition.inputSchema : definition.outputSchema;
30
+ const record = schemaAt(root, endpoint.path ?? "");
31
+ if (!record)
32
+ return `${endpoint.path ?? ""} is not declared by the ${endpoint.side} schema of ${endpoint.capability}`;
33
+ return { root, record };
34
+ }
35
+ /** The addressable leaves of a record schema: properties of objects, recursively; everything else is a leaf. */
36
+ function leaves(schema, root, prefix = "", out = []) {
37
+ const node = schemaAt(schema, "", root) ?? schema;
38
+ if (node.properties && (node.type === undefined || node.type === "object")) {
39
+ for (const [key, child] of Object.entries(node.properties)) {
40
+ leaves(child, root, `${prefix}/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`, out);
41
+ }
42
+ return out;
43
+ }
44
+ if (prefix !== "")
45
+ out.push({ pointer: prefix, schema: node });
46
+ return out;
47
+ }
48
+ const annotation = (schema, key) => schema?.[key];
49
+ const primitiveTypes = (schema) => {
50
+ const type = schema?.type;
51
+ if (!type)
52
+ return [];
53
+ return (Array.isArray(type) ? type : [type]).map((t) => (t === "integer" ? "number" : t));
54
+ };
55
+ const covers = (pointers, pointer) => [...pointers].some((p) => p === pointer || pointer.startsWith(`${p}/`) || p.startsWith(`${pointer}/`));
56
+ /**
57
+ * Statically checks a mapping against the two applications' published manifests.
58
+ * An `error` means the mapping must not be used; a `warning` needs a decision.
59
+ *
60
+ * What it proves: the mapping was written against the schemas as they are now
61
+ * (digest), every pointer exists, source and target fields carry the same declared
62
+ * meaning (concept, unit, encoding, enum-value concepts) or the difference is
63
+ * declared as a relation and as loss, nothing the target requires is missing, and
64
+ * no source field is silently dropped. What it cannot prove: that a business rule
65
+ * holds, or that the annotations themselves are true.
66
+ */
67
+ export function lintMapping(mapping, manifests, options = {}) {
68
+ const requireConcepts = options.requireConcepts ?? true;
69
+ const issues = [];
70
+ const error = (path, message) => issues.push({ level: "error", path, message });
71
+ const warn = (path, message) => issues.push({ level: "warning", path, message });
72
+ if (mapping.origin === "generated")
73
+ warn("origin", "generated mappings are untrusted until their vectors pass and local policy accepts them");
74
+ const from = resolveEndpoint(manifests.from, mapping.from);
75
+ const to = resolveEndpoint(manifests.to, mapping.to);
76
+ if (typeof from === "string")
77
+ error("from", from);
78
+ if (typeof to === "string")
79
+ error("to", to);
80
+ if (typeof from === "string" || typeof to === "string")
81
+ return issues;
82
+ for (const [path, endpoint, resolved] of [["from", mapping.from, from], ["to", mapping.to, to]]) {
83
+ if (schemaIdentity(resolved.record) !== endpoint.schemaDigest) {
84
+ error(`${path}.schemaDigest`, `${endpoint.capability} ${endpoint.side} schema no longer matches the one this mapping was written against; the mapping must be re-validated or re-published`);
85
+ }
86
+ }
87
+ const lossy = mapping.lossy;
88
+ const lossFor = (pointer, kinds) => lossy.some((entry) => (Array.isArray(entry.from) ? entry.from : [entry.from]).includes(pointer) && (!kinds || kinds.includes(entry.kind)));
89
+ const sourcePointers = new Set();
90
+ const targetPointers = new Set();
91
+ mapping.rules.forEach((rule, index) => {
92
+ const path = `rules[${index}]`;
93
+ const target = schemaAt(to.record, rule.to, to.root);
94
+ if (!target)
95
+ error(`${path}.to`, `${rule.to} is not declared by the target schema`);
96
+ targetPointers.add(rule.to);
97
+ if (rule.op === "const") {
98
+ if (target && !constAllowed(target, rule.value))
99
+ error(`${path}.value`, "the constant is not allowed by the target schema");
100
+ return;
101
+ }
102
+ const source = schemaAt(from.record, rule.from, from.root);
103
+ if (!source)
104
+ error(`${path}.from`, `${rule.from} is not declared by the source schema`);
105
+ sourcePointers.add(rule.from);
106
+ if (!source || !target)
107
+ return;
108
+ // Meaning: the concept both sides declare.
109
+ const [sourceConcept, targetConcept] = [annotation(source, SEMANTIC_KEYWORDS.concept), annotation(target, SEMANTIC_KEYWORDS.concept)];
110
+ if (requireConcepts && (sourceConcept === undefined || targetConcept === undefined)) {
111
+ error(path, `${sourceConcept === undefined ? rule.from : rule.to} declares no ${SEMANTIC_KEYWORDS.concept}, so the mapping's meaning cannot be checked`);
112
+ }
113
+ else if (sourceConcept !== targetConcept) {
114
+ if (!rule.conceptRelation)
115
+ error(path, `source concept ${String(sourceConcept)} differs from target concept ${String(targetConcept)}; declare conceptRelation`);
116
+ else if (rule.conceptRelation !== "exact" && !lossFor(rule.from))
117
+ error(path, `conceptRelation "${rule.conceptRelation}" loses meaning; declare it in lossy`);
118
+ else if (rule.conceptRelation === "exact")
119
+ warn(path, "different concept IRIs are asserted to be exactly equivalent");
120
+ }
121
+ const [sourceUnit, targetUnit] = [annotation(source, SEMANTIC_KEYWORDS.unit), annotation(target, SEMANTIC_KEYWORDS.unit)];
122
+ const [sourceEncoding, targetEncoding] = [annotation(source, SEMANTIC_KEYWORDS.encoding), annotation(target, SEMANTIC_KEYWORDS.encoding)];
123
+ if (rule.op === "copy") {
124
+ if (sourceUnit !== targetUnit)
125
+ error(path, `copy between different units (${String(sourceUnit)} → ${String(targetUnit)}); use a unit rule`);
126
+ if (sourceEncoding !== targetEncoding)
127
+ error(path, `copy between different encodings (${String(sourceEncoding)} → ${String(targetEncoding)}); use an encoding rule`);
128
+ const [a, b] = [primitiveTypes(source), primitiveTypes(target)];
129
+ if (a.length && b.length && !a.some((t) => b.includes(t)))
130
+ error(path, `copy between incompatible types (${a.join("|")} → ${b.join("|")})`);
131
+ if (!isRequiredAt(from.record, rule.from, from.root) && isRequiredAt(to.record, rule.to, to.root) && rule.default === undefined) {
132
+ error(path, `${rule.from} is optional but ${rule.to} is required and no default is declared`);
133
+ }
134
+ if (rule.default !== undefined && !constAllowed(target, rule.default))
135
+ error(`${path}.default`, "the default is not allowed by the target schema");
136
+ }
137
+ if (rule.op === "unit") {
138
+ if (sourceUnit !== rule.fromUnit)
139
+ error(path, `${rule.from} declares unit ${String(sourceUnit)}, the rule assumes ${rule.fromUnit}`);
140
+ if (targetUnit !== rule.toUnit)
141
+ error(path, `${rule.to} declares unit ${String(targetUnit)}, the rule produces ${rule.toUnit}`);
142
+ const problem = unitProblem(rule.fromUnit, rule.toUnit);
143
+ if (problem)
144
+ error(path, problem);
145
+ else if (!isKnownUnit(rule.fromUnit))
146
+ error(path, "unknown unit");
147
+ }
148
+ if (rule.op === "encoding") {
149
+ if (sourceEncoding !== rule.fromEncoding)
150
+ error(path, `${rule.from} declares encoding ${String(sourceEncoding)}, the rule assumes ${rule.fromEncoding}`);
151
+ if (targetEncoding !== rule.toEncoding)
152
+ error(path, `${rule.to} declares encoding ${String(targetEncoding)}, the rule produces ${rule.toEncoding}`);
153
+ if (rule.truncate && !lossFor(rule.from, ["truncation"]))
154
+ error(path, "truncate loses precision; declare a lossy entry of kind truncation");
155
+ }
156
+ if (rule.op === "enum")
157
+ lintEnum(rule, index, source, target, error, warn, lossFor);
158
+ });
159
+ // The target must be fully produced.
160
+ for (const leaf of leaves(to.record, to.root)) {
161
+ if (isRequiredChain(to.record, leaf.pointer, to.root) && !covers(targetPointers, leaf.pointer)) {
162
+ error("rules", `required target field ${leaf.pointer} is not produced by any rule`);
163
+ }
164
+ }
165
+ // Nothing in the source may vanish without being declared.
166
+ for (const leaf of leaves(from.record, from.root)) {
167
+ if (!covers(sourcePointers, leaf.pointer) && !coveredByLoss(lossy, leaf.pointer)) {
168
+ error("lossy", `source field ${leaf.pointer} is not mapped and not declared as lost; add a lossy entry of kind "dropped"`);
169
+ }
170
+ }
171
+ lossy.forEach((entry, index) => {
172
+ for (const pointer of Array.isArray(entry.from) ? entry.from : [entry.from]) {
173
+ if (!schemaAt(from.record, pointer, from.root))
174
+ error(`lossy[${index}].from`, `${pointer} is not declared by the source schema`);
175
+ }
176
+ });
177
+ return issues;
178
+ }
179
+ function coveredByLoss(lossy, pointer) {
180
+ return lossy.some((entry) => (Array.isArray(entry.from) ? entry.from : [entry.from]).some((p) => p === pointer || pointer.startsWith(`${p}/`)));
181
+ }
182
+ function isRequiredChain(record, pointer, root) {
183
+ const segments = pointer.split("/").slice(1);
184
+ let path = "";
185
+ for (const segment of segments) {
186
+ path += `/${segment}`;
187
+ if (!isRequiredAt(record, path, root))
188
+ return false;
189
+ }
190
+ return true;
191
+ }
192
+ function constAllowed(schema, value) {
193
+ if (schema.enum)
194
+ return schema.enum.some((candidate) => JSON.stringify(candidate) === JSON.stringify(value));
195
+ if (schema.const !== undefined)
196
+ return JSON.stringify(schema.const) === JSON.stringify(value);
197
+ const types = primitiveTypes(schema);
198
+ if (!types.length)
199
+ return true;
200
+ const actual = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
201
+ return types.includes(actual) || (actual === "number" && schema.type === "integer" && Number.isInteger(value));
202
+ }
203
+ function lintEnum(rule, index, source, target, error, warn, lossFor) {
204
+ const path = `rules[${index}]`;
205
+ const sourceValues = (source.enum ?? []).map(String);
206
+ const targetValues = new Set((target.enum ?? []).map(String));
207
+ if (!source.enum)
208
+ error(path, `${rule.from} declares no enum, so the table cannot be checked`);
209
+ if (!target.enum)
210
+ error(path, `${rule.to} declares no enum, so the table cannot be checked`);
211
+ for (const key of Object.keys(rule.table))
212
+ if (source.enum && !sourceValues.includes(key))
213
+ error(`${path}.table`, `"${key}" is not a declared value of ${rule.from}`);
214
+ for (const value of sourceValues) {
215
+ if (!(value in rule.table)) {
216
+ warn(`${path}.table`, `${rule.from} value "${value}" has no entry; it will be ${rule.unmapped === "reject" ? "rejected" : "omitted"}`);
217
+ }
218
+ }
219
+ const reached = new Map();
220
+ let ambiguous = false;
221
+ for (const [key, entry] of Object.entries(rule.table)) {
222
+ const candidates = entry !== null && typeof entry === "object" ? entry.ambiguous : [entry];
223
+ if (candidates.length > 1)
224
+ ambiguous = true;
225
+ for (const candidate of candidates) {
226
+ if (target.enum && !targetValues.has(String(candidate)))
227
+ error(`${path}.table`, `"${String(candidate)}" is not a declared value of ${rule.to}`);
228
+ reached.set(String(candidate), [...(reached.get(String(candidate)) ?? []), key]);
229
+ }
230
+ }
231
+ const manyToOne = [...reached.values()].some((keys) => keys.length > 1);
232
+ const [sourceConcepts, targetConcepts] = [
233
+ (annotation(source, SEMANTIC_KEYWORDS.enumConcepts) ?? {}),
234
+ (annotation(target, SEMANTIC_KEYWORDS.enumConcepts) ?? {})
235
+ ];
236
+ let conceptDrift = false;
237
+ for (const [key, entry] of Object.entries(rule.table)) {
238
+ const candidates = entry !== null && typeof entry === "object" ? entry.ambiguous : [entry];
239
+ for (const candidate of candidates) {
240
+ const [a, b] = [sourceConcepts[key], targetConcepts[String(candidate)]];
241
+ if (a === undefined || b === undefined) {
242
+ if (Object.keys(sourceConcepts).length || Object.keys(targetConcepts).length)
243
+ warn(`${path}.table`, `"${key}" → "${String(candidate)}": value meaning is not declared on both sides`);
244
+ }
245
+ else if (a !== b)
246
+ conceptDrift = true;
247
+ }
248
+ }
249
+ const loses = manyToOne || ambiguous || conceptDrift;
250
+ if (rule.relation === "exact" && loses) {
251
+ error(path, `relation "exact" but the table is ${manyToOne ? "many-to-one" : ambiguous ? "ambiguous" : "not concept-preserving"}`);
252
+ }
253
+ if (manyToOne && rule.relation !== "broader" && rule.relation !== "related")
254
+ error(path, 'a many-to-one table must declare relation "broader" or "related"');
255
+ if (ambiguous && rule.relation !== "narrower" && rule.relation !== "related")
256
+ error(path, 'an ambiguous table must declare relation "narrower" or "related"');
257
+ if (loses && !lossFor(rule.from))
258
+ error(path, `the table loses meaning; declare ${rule.from} in lossy`);
259
+ }
260
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,YAAY,EACZ,QAAQ,EAIT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGtD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;AAEtF;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAkB;IAC/C,MAAM,KAAK,GAAG,CAAC,KAAc,EAAW,EAAE;QACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAc,CAAC,CAAC;AAC9C,CAAC;AASD,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAAC,QAAyB,E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AI,SAAS,IAAI,YAAY,CAAC;IACrD,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,KAAK,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,EAAE,qCAAqC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACrI,CAAC;IACD,IAAI,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,EAAE,kEAAkE,CAAC,CAAC;IAC7J,IAAI,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,EAAE,kEAAkE,CAAC,CAAC;IAC9J,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,EAAE,oCAAoC,IAAI,CAAC,IAAI,WAAW,CAAC,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { parsePointer, type JSONSchema, type JsonValue } from "@appport/protocol";
2
+ import { type ApplyResult, type Endpoint, type MappingArtifact, type Rule, type Scalar } from "./types.js";
3
+ /** Structural validation of an untrusted artifact. Throws `INVALID_MAPPING` listing every problem found. */
4
+ export declare function parseMapping(value: unknown): MappingArtifact;
5
+ /** The immutable identity digest of an artifact: SHA-256 of its RFC 8785 canonical JSON. */
6
+ export declare function mappingDigest(artifact: MappingArtifact | JsonValue): string;
7
+ /**
8
+ * Applies a mapping to one record. Pure and total over its input: every outcome
9
+ * is an output or a typed {@link MappingError}; nothing is inferred or defaulted
10
+ * beyond what a rule declares. An ambiguous value is refused unless the caller
11
+ * supplies `choices[targetPointer]` from the declared alternatives, and the
12
+ * choice is recorded in the trace.
13
+ */
14
+ export declare function applyMapping(mapping: MappingArtifact, source: unknown, options?: {
15
+ choices?: Record<string, Scalar>;
16
+ }): ApplyResult;
17
+ /** The records a mapping's `from` endpoint addresses inside a document: the document, a member, or each element of an array. */
18
+ export declare function selectRecords(document: unknown, endpoint: Pick<Endpoint, "path">): unknown[];
19
+ /** Applies a mapping and checks the result against the target's *published* schema. */
20
+ export declare function applyAndValidate(mapping: MappingArtifact, source: unknown, targetSchema: JSONSchema, options?: {
21
+ choices?: Record<string, Scalar>;
22
+ }): ApplyResult;
23
+ /** Runs the artifact's own vectors. Returns one message per failing vector. */
24
+ export declare function runVectors(mapping: MappingArtifact): string[];
25
+ /** Pointers a rule reads and writes; `const` reads nothing. */
26
+ export declare function ruleSources(rule: Rule): string[];
27
+ export { parsePointer };
28
+ //# sourceMappingURL=mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,YAAY,EAGZ,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,KAAK,MAAM,EAEZ,MAAM,YAAY,CAAC;AAQpB,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAqG5D;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,CAE3E;AAQD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,OAAO,EACf,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,GACjD,WAAW,CAkEb;AAED,gIAAgI;AAChI,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ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