@kalada/adapter-scheman 0.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/README.md +92 -0
- package/dist/index.cjs +1314 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +1308 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# `@kalada/adapter-scheman`
|
|
2
|
+
|
|
3
|
+
`@kalada/adapter-scheman` converts a public `@scheman/core` v2 `SchemaDocument` into an immutable
|
|
4
|
+
Kalada host environment. It requires `formatVersion: 1`. The input root exclusively drives the
|
|
5
|
+
editor graph; the output root exclusively drives the conservative semantic projection. Scheman node
|
|
6
|
+
IDs are retained as document-local evidence, never as cross-document fingerprints.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { adaptSchemanDocument } from "@kalada/adapter-scheman";
|
|
10
|
+
import { ingestSchemaDocument, jsonSchemaProvider } from "@scheman/core";
|
|
11
|
+
|
|
12
|
+
const { document } = ingestSchemaDocument(
|
|
13
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
14
|
+
{ provider: jsonSchemaProvider() },
|
|
15
|
+
);
|
|
16
|
+
const result = adaptSchemanDocument({
|
|
17
|
+
document,
|
|
18
|
+
mode: "sync",
|
|
19
|
+
providerId: "application.scheman",
|
|
20
|
+
providerVersion: "1",
|
|
21
|
+
configurationDigest: "sha256:application-configuration",
|
|
22
|
+
cacheable: true,
|
|
23
|
+
binding: { id: "value", name: "value", path: ["value"] },
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Conservative mapping
|
|
28
|
+
|
|
29
|
+
`SCHEMAN_SEMANTIC_MAPPING` is the closed normative mapping table and
|
|
30
|
+
`SCHEMAN_MAPPING_FIXTURE_MATRIX` names its test matrix. Primitive JSON domains map directly;
|
|
31
|
+
integer retains its constraints but projects as Kalada number. Arrays require a concrete item
|
|
32
|
+
projection. Proven JSON-safe object, record, tuple, and recursive local-ref graphs may project as
|
|
33
|
+
JSON. Every union/intersection branch must agree on one concrete projection. Unknown, opaque,
|
|
34
|
+
never, JS-unconstrained, non-JSON primitives, ambiguous wrappers, unresolved/external refs, and
|
|
35
|
+
unsupported applicators remain dynamic with diagnostics. Structural completeness is not validator
|
|
36
|
+
equivalence.
|
|
37
|
+
|
|
38
|
+
## Exact `x-kalada` policy
|
|
39
|
+
|
|
40
|
+
Only an own-data, node-local `x-kalada` key is recognized, either directly in trusted Scheman node
|
|
41
|
+
metadata or under JSON metadata's exact `extensions` bucket:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"x-kalada": {
|
|
46
|
+
"version": 1,
|
|
47
|
+
"type": { "kind": "primitive-type", "name": "number" },
|
|
48
|
+
"codec": "application-owned-codec-id",
|
|
49
|
+
"lossy": "safe-integer-bigint-to-number"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The exact keys are `version`, `type`, optional `codec`, and optional `lossy`. Codec IDs are bounded
|
|
55
|
+
descriptions, not registry or import keys. A conversion requires a caller-supplied codec capability
|
|
56
|
+
whose ID and mode match and whose version/configuration identity are explicit. The adapter records
|
|
57
|
+
mandatory final Kalada-type validation; safe-integer bigint conversion additionally records the
|
|
58
|
+
safe-integer range precondition. The only lossy policies are `safe-integer-bigint-to-number` and
|
|
59
|
+
`heterogeneous-union-to-json`. Explicit binding override wins over a valid node profile, which wins
|
|
60
|
+
over conservative mapping. Malformed, duplicate, misplaced, or incompatible policy is rejected.
|
|
61
|
+
|
|
62
|
+
## Execution boundary
|
|
63
|
+
|
|
64
|
+
The adapter never invokes validators or codecs while normalizing. The original Standard validator
|
|
65
|
+
is returned by identity, live and unfrozen, while normalized declarations and live callbacks remain
|
|
66
|
+
separated by `@kalada/host`. `DENY_SCHEMAN_EXECUTION_PERMISSIONS` documents the default: do not pass
|
|
67
|
+
Scheman's `allow` options for Zod shape/lazy/metadata or Standard JSON conversion. Opt-in belongs to
|
|
68
|
+
the trusted caller during Scheman ingestion; this adapter cannot escalate it and provides no
|
|
69
|
+
hostile-code isolation.
|
|
70
|
+
|
|
71
|
+
Same-document pointers, definitions, recursion, and local anchors are consumed from Scheman's graph.
|
|
72
|
+
External/multi-resource refs, nested `$id` rebasing, dynamic refs/anchors, unevaluated vocabularies,
|
|
73
|
+
and unsupported dialect evidence remain visible and unsupported. The adapter performs no network or
|
|
74
|
+
filesystem fetch.
|
|
75
|
+
|
|
76
|
+
Semantic and JSON-safety analysis is iterative and bounded by `analysisLimits` (`maxNodes: 2048`,
|
|
77
|
+
`maxEdges: 8192`, and `maxTypeDepth: 32` by default and as hard maxima). Reaching a limit produces
|
|
78
|
+
deterministic `SCHEMAN_ADAPTER_ANALYSIS_LIMIT`/dynamic evidence rather than recursion failure.
|
|
79
|
+
Editor admission uses the host's public `B/D/C/V/R/Q` cost model: total budget, definitions, children,
|
|
80
|
+
local-reference resolutions, roots, and emergency evidence capacity. Root/definition/resolution
|
|
81
|
+
backbones are admitted before optional native content; each child/local-reference pair is atomic,
|
|
82
|
+
relations follow native content, and truncation is provider evidence rather than a half-admitted ref.
|
|
83
|
+
Source retention and actual categorized host charging are reported separately. Definitions remain
|
|
84
|
+
deterministically prioritized, while properties, tuples, unions, intersections, records, wrappers,
|
|
85
|
+
relations, cycles, and local refs retain only prefixes whose normalized targets can resolve. Source
|
|
86
|
+
definition and diagnostic records are independently bounded to 512 records. Each object's required
|
|
87
|
+
names are bounded by `maxEdges`, with aggregate retained/total/truncated source accounting.
|
|
88
|
+
|
|
89
|
+
Runtime sequencing remains owned by the host execution layer. The adapter's capability wrappers only
|
|
90
|
+
translate synchronous Standard Schema outcomes to decoded values/failures and enforce the declared
|
|
91
|
+
safe-integer conversion precondition. Promise and thenable outputs pass untouched to the host's sync
|
|
92
|
+
guard; final canonical/Kalada-type validation and entry into core remain host-owned.
|