@nakafa/aksara-contracts 0.51.0 → 1.0.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.
@@ -997,12 +997,25 @@ export declare const PublicationRollbackSuccessSchema: Schema.Struct<{
997
997
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
998
998
  readonly payload: Schema.Struct<{
999
999
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
1000
- readonly byteLength: Schema.Finite;
1001
- readonly compiledCode: Schema.String;
1002
1000
  readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
1003
- readonly compilerVersion: Schema.Literal<"0.1.0">;
1001
+ readonly compilerVersion: Schema.Literal<"0.2.0">;
1004
1002
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
1005
- readonly format: Schema.Literal<"mdx-function-body">;
1003
+ readonly contentTree: Schema.Codec<{
1004
+ readonly $node: "element";
1005
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
1006
+ readonly name: import("../tree.js").ContentTreeElementName;
1007
+ readonly props: {
1008
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
1009
+ };
1010
+ }, {
1011
+ readonly $node: "element";
1012
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
1013
+ readonly name: import("../tree.js").ContentTreeElementName;
1014
+ readonly props: {
1015
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
1016
+ };
1017
+ }, never, never>;
1018
+ readonly format: Schema.Literal<"content-tree">;
1006
1019
  readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
1007
1020
  readonly plainText: Schema.String;
1008
1021
  readonly rawMdx: Schema.String;
@@ -1241,12 +1254,25 @@ export declare const PublicationRollbackSuccessSchema: Schema.Struct<{
1241
1254
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
1242
1255
  readonly payload: Schema.Struct<{
1243
1256
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
1244
- readonly byteLength: Schema.Finite;
1245
- readonly compiledCode: Schema.String;
1246
1257
  readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
1247
- readonly compilerVersion: Schema.Literal<"0.1.0">;
1258
+ readonly compilerVersion: Schema.Literal<"0.2.0">;
1248
1259
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
1249
- readonly format: Schema.Literal<"mdx-function-body">;
1260
+ readonly contentTree: Schema.Codec<{
1261
+ readonly $node: "element";
1262
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
1263
+ readonly name: import("../tree.js").ContentTreeElementName;
1264
+ readonly props: {
1265
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
1266
+ };
1267
+ }, {
1268
+ readonly $node: "element";
1269
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
1270
+ readonly name: import("../tree.js").ContentTreeElementName;
1271
+ readonly props: {
1272
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
1273
+ };
1274
+ }, never, never>;
1275
+ readonly format: Schema.Literal<"content-tree">;
1250
1276
  readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
1251
1277
  readonly plainText: Schema.String;
1252
1278
  readonly rawMdx: Schema.String;
@@ -2439,12 +2465,25 @@ export declare const PublicationSuccessSchema: Schema.Union<readonly [Schema.Str
2439
2465
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
2440
2466
  readonly payload: Schema.Struct<{
2441
2467
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
2442
- readonly byteLength: Schema.Finite;
2443
- readonly compiledCode: Schema.String;
2444
2468
  readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
2445
- readonly compilerVersion: Schema.Literal<"0.1.0">;
2469
+ readonly compilerVersion: Schema.Literal<"0.2.0">;
2446
2470
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
2447
- readonly format: Schema.Literal<"mdx-function-body">;
2471
+ readonly contentTree: Schema.Codec<{
2472
+ readonly $node: "element";
2473
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
2474
+ readonly name: import("../tree.js").ContentTreeElementName;
2475
+ readonly props: {
2476
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
2477
+ };
2478
+ }, {
2479
+ readonly $node: "element";
2480
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
2481
+ readonly name: import("../tree.js").ContentTreeElementName;
2482
+ readonly props: {
2483
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
2484
+ };
2485
+ }, never, never>;
2486
+ readonly format: Schema.Literal<"content-tree">;
2448
2487
  readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
2449
2488
  readonly plainText: Schema.String;
2450
2489
  readonly rawMdx: Schema.String;
@@ -2683,12 +2722,25 @@ export declare const PublicationSuccessSchema: Schema.Union<readonly [Schema.Str
2683
2722
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
2684
2723
  readonly payload: Schema.Struct<{
2685
2724
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
2686
- readonly byteLength: Schema.Finite;
2687
- readonly compiledCode: Schema.String;
2688
2725
  readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
2689
- readonly compilerVersion: Schema.Literal<"0.1.0">;
2726
+ readonly compilerVersion: Schema.Literal<"0.2.0">;
2690
2727
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
2691
- readonly format: Schema.Literal<"mdx-function-body">;
2728
+ readonly contentTree: Schema.Codec<{
2729
+ readonly $node: "element";
2730
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
2731
+ readonly name: import("../tree.js").ContentTreeElementName;
2732
+ readonly props: {
2733
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
2734
+ };
2735
+ }, {
2736
+ readonly $node: "element";
2737
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
2738
+ readonly name: import("../tree.js").ContentTreeElementName;
2739
+ readonly props: {
2740
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
2741
+ };
2742
+ }, never, never>;
2743
+ readonly format: Schema.Literal<"content-tree">;
2692
2744
  readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
2693
2745
  readonly plainText: Schema.String;
2694
2746
  readonly rawMdx: Schema.String;
@@ -3947,12 +3999,25 @@ export declare const PublicationResponseSchema: Schema.Union<readonly [Schema.Un
3947
3999
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
3948
4000
  readonly payload: Schema.Struct<{
3949
4001
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
3950
- readonly byteLength: Schema.Finite;
3951
- readonly compiledCode: Schema.String;
3952
4002
  readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
3953
- readonly compilerVersion: Schema.Literal<"0.1.0">;
4003
+ readonly compilerVersion: Schema.Literal<"0.2.0">;
3954
4004
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
3955
- readonly format: Schema.Literal<"mdx-function-body">;
4005
+ readonly contentTree: Schema.Codec<{
4006
+ readonly $node: "element";
4007
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
4008
+ readonly name: import("../tree.js").ContentTreeElementName;
4009
+ readonly props: {
4010
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
4011
+ };
4012
+ }, {
4013
+ readonly $node: "element";
4014
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
4015
+ readonly name: import("../tree.js").ContentTreeElementName;
4016
+ readonly props: {
4017
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
4018
+ };
4019
+ }, never, never>;
4020
+ readonly format: Schema.Literal<"content-tree">;
3956
4021
  readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
3957
4022
  readonly plainText: Schema.String;
3958
4023
  readonly rawMdx: Schema.String;
@@ -4191,12 +4256,25 @@ export declare const PublicationResponseSchema: Schema.Union<readonly [Schema.Un
4191
4256
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
4192
4257
  readonly payload: Schema.Struct<{
4193
4258
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
4194
- readonly byteLength: Schema.Finite;
4195
- readonly compiledCode: Schema.String;
4196
4259
  readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
4197
- readonly compilerVersion: Schema.Literal<"0.1.0">;
4260
+ readonly compilerVersion: Schema.Literal<"0.2.0">;
4198
4261
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
4199
- readonly format: Schema.Literal<"mdx-function-body">;
4262
+ readonly contentTree: Schema.Codec<{
4263
+ readonly $node: "element";
4264
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
4265
+ readonly name: import("../tree.js").ContentTreeElementName;
4266
+ readonly props: {
4267
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
4268
+ };
4269
+ }, {
4270
+ readonly $node: "element";
4271
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
4272
+ readonly name: import("../tree.js").ContentTreeElementName;
4273
+ readonly props: {
4274
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
4275
+ };
4276
+ }, never, never>;
4277
+ readonly format: Schema.Literal<"content-tree">;
4200
4278
  readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
4201
4279
  readonly plainText: Schema.String;
4202
4280
  readonly rawMdx: Schema.String;
@@ -5266,12 +5344,18 @@ export declare const decodePublicationResponse: (input: unknown) => Effect.Effec
5266
5344
  readonly keyId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSigningKeyId">;
5267
5345
  readonly payload: {
5268
5346
  readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
5269
- readonly byteLength: number;
5270
- readonly compiledCode: string;
5271
5347
  readonly compilerConfigHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
5272
- readonly compilerVersion: "0.1.0";
5348
+ readonly compilerVersion: "0.2.0";
5273
5349
  readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
5274
- readonly format: "mdx-function-body";
5350
+ readonly contentTree: {
5351
+ readonly $node: "element";
5352
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
5353
+ readonly name: import("../tree.js").ContentTreeElementName;
5354
+ readonly props: {
5355
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
5356
+ };
5357
+ };
5358
+ readonly format: "content-tree";
5275
5359
  readonly mdxCompilerVersion: "3.1.1";
5276
5360
  readonly plainText: string;
5277
5361
  readonly rawMdx: string;
@@ -5518,12 +5602,18 @@ export declare const decodePublicationResponse: (input: unknown) => Effect.Effec
5518
5602
  readonly keyId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSigningKeyId">;
5519
5603
  readonly payload: {
5520
5604
  readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
5521
- readonly byteLength: number;
5522
- readonly compiledCode: string;
5523
5605
  readonly compilerConfigHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
5524
- readonly compilerVersion: "0.1.0";
5606
+ readonly compilerVersion: "0.2.0";
5525
5607
  readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
5526
- readonly format: "mdx-function-body";
5608
+ readonly contentTree: {
5609
+ readonly $node: "element";
5610
+ readonly children: readonly import("../tree.js").ContentTreeChild[];
5611
+ readonly name: import("../tree.js").ContentTreeElementName;
5612
+ readonly props: {
5613
+ readonly [key: string]: import("../tree.js").ContentTreeValue;
5614
+ };
5615
+ };
5616
+ readonly format: "content-tree";
5527
5617
  readonly mdxCompilerVersion: "3.1.1";
5528
5618
  readonly plainText: string;
5529
5619
  readonly rawMdx: string;
package/dist/tree.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { Schema } from "effect";
2
+ /** Intrinsic HTML tags that the Markdown and MDX pipeline may emit, in code-unit order. */
3
+ export declare const CONTENT_TREE_INTRINSIC_TAGS: readonly ["a", "blockquote", "br", "code", "del", "div", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "input", "li", "ol", "p", "pre", "section", "strong", "sub", "sup", "table", "tbody", "td", "th", "thead", "tr", "ul"];
4
+ /** One intrinsic HTML tag from the allowed pipeline list. */
5
+ export declare const ContentTreeIntrinsicTagSchema: Schema.Literals<readonly ["a", "blockquote", "br", "code", "del", "div", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "input", "li", "ol", "p", "pre", "section", "strong", "sub", "sup", "table", "tbody", "td", "th", "thead", "tr", "ul"]>;
6
+ /** The element name of one tree node: the fragment, an intrinsic tag, or a renderer component. */
7
+ export declare const ContentTreeElementNameSchema: Schema.Union<readonly [Schema.Literal<"fragment">, Schema.Literals<readonly ["a", "blockquote", "br", "code", "del", "div", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "input", "li", "ol", "p", "pre", "section", "strong", "sub", "sup", "table", "tbody", "td", "th", "thead", "tr", "ul"]>, Schema.String]>;
8
+ export type ContentTreeElementName = typeof ContentTreeElementNameSchema.Type;
9
+ /**
10
+ * A value a prop or a list may hold: JSON data, an element of the tree, or a
11
+ * plain JSON object whose values are tree values. The recursive shapes are
12
+ * object members of this union, which is how the repository names recursive
13
+ * Schema types, so the element and props names below are derived from it.
14
+ */
15
+ export type ContentTreeValue = null | boolean | number | string | readonly ContentTreeValue[] | {
16
+ readonly $node: "element";
17
+ readonly children: readonly ContentTreeChild[];
18
+ readonly name: ContentTreeElementName;
19
+ readonly props: {
20
+ readonly [key: string]: ContentTreeValue;
21
+ };
22
+ } | {
23
+ readonly [key: string]: ContentTreeValue;
24
+ };
25
+ /** One rendered node: its name, its props, and its ordered children. */
26
+ export type ContentTreeElement = Extract<ContentTreeValue, {
27
+ readonly $node: "element";
28
+ }>;
29
+ /** Named props of one element, each a JSON value or an element of the tree. */
30
+ export type ContentTreeProps = ContentTreeElement["props"];
31
+ /** Text, or one element in the order React would render it. */
32
+ export type ContentTreeChild = string | ContentTreeElement;
33
+ /** The signed content tree: the fragment that Nakafa renders with its component map. */
34
+ export declare const ContentTreeSchema: Schema.Codec<{
35
+ readonly $node: "element";
36
+ readonly children: readonly ContentTreeChild[];
37
+ readonly name: ContentTreeElementName;
38
+ readonly props: {
39
+ readonly [key: string]: ContentTreeValue;
40
+ };
41
+ }, {
42
+ readonly $node: "element";
43
+ readonly children: readonly ContentTreeChild[];
44
+ readonly name: ContentTreeElementName;
45
+ readonly props: {
46
+ readonly [key: string]: ContentTreeValue;
47
+ };
48
+ }, never, never>;
49
+ /** Serializes the tree as the exact JSON text that hashes and signatures cover. */
50
+ export declare function canonicalizeContentTree(tree: ContentTreeElement): string;
51
+ /** Lists the renderer components that one tree uses, once each, in first-use order. */
52
+ export declare function contentTreeComponentNames(tree: ContentTreeElement): readonly string[];
package/dist/tree.js ADDED
@@ -0,0 +1,162 @@
1
+ import { Array as Arr, Order, Predicate, Record as Rec, Schema } from "effect";
2
+ import { encodeJsonText } from "#contracts/text/json";
3
+ /** Key that only an element may carry, so a plain JSON object can never imitate one. */
4
+ const ELEMENT_KEY = "$node";
5
+ /** Name of the element that renders its children without an element of its own. */
6
+ const FRAGMENT_NAME = "fragment";
7
+ /** Renderer components are capitalized JSX names, never intrinsic tags. */
8
+ const COMPONENT_NAME_PATTERN = /^[A-Z][A-Za-z0-9]*$/;
9
+ /** Intrinsic HTML tags that the Markdown and MDX pipeline may emit, in code-unit order. */
10
+ export const CONTENT_TREE_INTRINSIC_TAGS = [
11
+ "a",
12
+ "blockquote",
13
+ "br",
14
+ "code",
15
+ "del",
16
+ "div",
17
+ "em",
18
+ "h1",
19
+ "h2",
20
+ "h3",
21
+ "h4",
22
+ "h5",
23
+ "h6",
24
+ "hr",
25
+ "img",
26
+ "input",
27
+ "li",
28
+ "ol",
29
+ "p",
30
+ "pre",
31
+ "section",
32
+ "strong",
33
+ "sub",
34
+ "sup",
35
+ "table",
36
+ "tbody",
37
+ "td",
38
+ "th",
39
+ "thead",
40
+ "tr",
41
+ "ul",
42
+ ];
43
+ /** One intrinsic HTML tag from the allowed pipeline list. */
44
+ export const ContentTreeIntrinsicTagSchema = Schema.Literals(CONTENT_TREE_INTRINSIC_TAGS);
45
+ /** The element name of one tree node: the fragment, an intrinsic tag, or a renderer component. */
46
+ export const ContentTreeElementNameSchema = Schema.Union([
47
+ Schema.Literal(FRAGMENT_NAME),
48
+ ContentTreeIntrinsicTagSchema,
49
+ Schema.String.check(Schema.isPattern(COMPONENT_NAME_PATTERN)),
50
+ ]);
51
+ /** Rejects a props object that uses the reserved element key. */
52
+ function hasNoElementKey(props) {
53
+ return !Predicate.hasProperty(props, ELEMENT_KEY);
54
+ }
55
+ /** Any prop value: JSON data or a nested element. */
56
+ const ContentTreeValueSchema = Schema.suspend(() => Schema.Union([
57
+ Schema.Null,
58
+ Schema.Boolean,
59
+ Schema.Finite,
60
+ Schema.String,
61
+ Schema.Array(ContentTreeValueSchema),
62
+ ContentTreeElementSchema,
63
+ ContentTreePropsSchema,
64
+ ]));
65
+ /** Props of one element or one plain JSON object, never carrying the element key. */
66
+ const ContentTreePropsSchema = Schema.suspend(() => Schema.Record(Schema.String, ContentTreeValueSchema).check(Schema.makeFilter(hasNoElementKey, {
67
+ message: "Expected props without the reserved element key.",
68
+ })));
69
+ /** Text or a nested element. */
70
+ const ContentTreeChildSchema = Schema.suspend(() => Schema.Union([Schema.String, ContentTreeElementSchema]));
71
+ /**
72
+ * One element of the tree, with its reserved marker and its exact fields. The
73
+ * signed bytes come from canonicalizeContentTree, never from the key order of a
74
+ * decoded object, which the repository's formatter keeps alphabetical.
75
+ */
76
+ const ContentTreeElementSchema = Schema.Struct({
77
+ $node: Schema.Literal("element"),
78
+ children: Schema.Array(ContentTreeChildSchema),
79
+ name: ContentTreeElementNameSchema,
80
+ props: ContentTreePropsSchema,
81
+ });
82
+ /** The signed content tree: the fragment that Nakafa renders with its component map. */
83
+ export const ContentTreeSchema = ContentTreeElementSchema.check(Schema.makeFilter((tree) => tree.name === FRAGMENT_NAME, {
84
+ message: "Expected the fragment as the content tree root.",
85
+ }));
86
+ /** Checks whether a tree value is an element rather than JSON data. */
87
+ function isElement(value) {
88
+ return (Predicate.isObject(value) &&
89
+ !Arr.isArray(value) &&
90
+ Predicate.hasProperty(value, ELEMENT_KEY));
91
+ }
92
+ /** Checks whether a tree value is a list of tree values. */
93
+ function isList(value) {
94
+ return Arr.isArray(value);
95
+ }
96
+ /** Checks whether a tree value is a plain props object. */
97
+ function isProps(value) {
98
+ return Predicate.isObject(value);
99
+ }
100
+ /**
101
+ * Writes one props object as JSON text with its keys in code-unit order. The
102
+ * text is assembled by hand, so no formatter or key sort can change its bytes.
103
+ */
104
+ function canonicalPropsText(props) {
105
+ const entries = Arr.sortWith(Rec.toEntries(props), ([key]) => key, Order.String);
106
+ const texts = Arr.map(entries, ([key, value]) => `${encodeJsonText(key)}:${canonicalValueText(value)}`);
107
+ return `{${Arr.join(texts, ",")}}`;
108
+ }
109
+ /** Writes one tree value as JSON text in the one canonical form. */
110
+ function canonicalValueText(value) {
111
+ if (isElement(value)) {
112
+ return canonicalElementText(value);
113
+ }
114
+ if (isList(value)) {
115
+ return `[${Arr.join(Arr.map(value, canonicalValueText), ",")}]`;
116
+ }
117
+ if (isProps(value)) {
118
+ return canonicalPropsText(value);
119
+ }
120
+ return encodeJsonText(value);
121
+ }
122
+ /** Writes one element as JSON text with its fields in the declared order. */
123
+ function canonicalElementText(element) {
124
+ const children = Arr.join(Arr.map(element.children, (child) => typeof child === "string"
125
+ ? encodeJsonText(child)
126
+ : canonicalElementText(child)), ",");
127
+ return `{"$node":"element","name":${encodeJsonText(element.name)},"props":${canonicalPropsText(element.props)},"children":[${children}]}`;
128
+ }
129
+ /** Serializes the tree as the exact JSON text that hashes and signatures cover. */
130
+ export function canonicalizeContentTree(tree) {
131
+ return canonicalElementText(tree);
132
+ }
133
+ /** Checks whether an element name is a renderer component, not the fragment or an intrinsic tag. */
134
+ function isComponentElementName(name) {
135
+ return (name !== FRAGMENT_NAME && !Schema.is(ContentTreeIntrinsicTagSchema)(name));
136
+ }
137
+ /** Collects the component names of one element and of every element nested beneath it. */
138
+ function componentNamesOfElement(element) {
139
+ const own = isComponentElementName(element.name) ? [element.name] : [];
140
+ return [
141
+ ...own,
142
+ ...Arr.flatMap(element.children, (child) => typeof child === "string" ? [] : componentNamesOfElement(child)),
143
+ ...Arr.flatMap(Rec.values(element.props), componentNamesOfValue),
144
+ ];
145
+ }
146
+ /** Collects the component names of one prop value, which may hold lists, objects, and elements. */
147
+ function componentNamesOfValue(value) {
148
+ if (isElement(value)) {
149
+ return componentNamesOfElement(value);
150
+ }
151
+ if (isList(value)) {
152
+ return Arr.flatMap(value, componentNamesOfValue);
153
+ }
154
+ if (isProps(value)) {
155
+ return Arr.flatMap(Rec.values(value), componentNamesOfValue);
156
+ }
157
+ return [];
158
+ }
159
+ /** Lists the renderer components that one tree uses, once each, in first-use order. */
160
+ export function contentTreeComponentNames(tree) {
161
+ return Arr.dedupe(componentNamesOfElement(tree));
162
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakafa/aksara-contracts",
3
- "version": "0.51.0",
3
+ "version": "1.0.0",
4
4
  "description": "Schemas and verification contracts for Nakafa content releases.",
5
5
  "homepage": "https://github.com/nakafaai/aksara#readme",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/content.d.ts",
29
29
  "import": "./dist/content.js"
30
30
  },
31
+ "./tree": {
32
+ "types": "./dist/tree.d.ts",
33
+ "import": "./dist/tree.js"
34
+ },
31
35
  "./country": {
32
36
  "types": "./dist/country.d.ts",
33
37
  "import": "./dist/country.js"