@nakafa/aksara-contracts 0.47.0 → 0.47.2

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 (81) hide show
  1. package/dist/content.d.ts +8 -6
  2. package/dist/content.js +8 -3
  3. package/dist/math/arc.js +5 -1
  4. package/dist/math/base.js +6 -6
  5. package/dist/math/collision.d.ts +4 -4
  6. package/dist/math/collision.js +15 -9
  7. package/dist/math/coordinate.d.ts +24 -13
  8. package/dist/math/coordinate.js +16 -2
  9. package/dist/math/extent.d.ts +26 -17
  10. package/dist/math/extent.js +18 -2
  11. package/dist/math/intersection.d.ts +21 -11
  12. package/dist/math/intersection.js +14 -1
  13. package/dist/math/precision.js +3 -3
  14. package/dist/math/proximity.d.ts +11 -7
  15. package/dist/math/proximity.js +21 -4
  16. package/dist/math/rational.d.ts +6 -5
  17. package/dist/math/rational.js +6 -1
  18. package/dist/math/resolution.d.ts +1 -1
  19. package/dist/math/resolution.js +12 -4
  20. package/dist/math/scene.d.ts +22 -3
  21. package/dist/preview/auth.js +2 -1
  22. package/dist/preview/target.js +7 -0
  23. package/dist/program/curriculum.js +2 -1
  24. package/dist/program/snapshot/digest.js +32 -31
  25. package/dist/program/snapshot/hash.js +2 -1
  26. package/dist/program/spec.js +2 -1
  27. package/dist/projection/article.js +2 -1
  28. package/dist/projection/material.js +2 -1
  29. package/dist/projection/page.js +2 -1
  30. package/dist/projection/question.d.ts +544 -17
  31. package/dist/projection/question.js +17 -3
  32. package/dist/projection/verify.d.ts +4 -3
  33. package/dist/projection/verify.js +14 -7
  34. package/dist/question/answer.d.ts +12 -6
  35. package/dist/question/answer.js +17 -2
  36. package/dist/question/item.js +5 -4
  37. package/dist/question/response.js +3 -3
  38. package/dist/question/rubric.js +2 -1
  39. package/dist/quran/identity.js +11 -0
  40. package/dist/quran/notes.js +13 -0
  41. package/dist/quran/provenance.js +3 -2
  42. package/dist/quran/snapshot/digest.js +4 -3
  43. package/dist/quran/snapshot/hash.js +2 -1
  44. package/dist/quran/snapshot/row/hash.js +5 -4
  45. package/dist/quran/snapshot/spec.js +3 -2
  46. package/dist/release/canonical.js +2 -1
  47. package/dist/release/head.js +2 -1
  48. package/dist/release/items.d.ts +5 -4
  49. package/dist/release/items.js +14 -9
  50. package/dist/release/result/digest.js +4 -4
  51. package/dist/release/rollback/spec.js +6 -5
  52. package/dist/release/route/spec.js +4 -3
  53. package/dist/release/route/verify.d.ts +4 -3
  54. package/dist/release/route/verify.js +9 -6
  55. package/dist/release/signing.js +2 -1
  56. package/dist/release/snapshot/data.js +3 -2
  57. package/dist/release/snapshot/evidence/tryout.js +6 -1
  58. package/dist/release/snapshot/spec.js +7 -6
  59. package/dist/release/snapshot/verify.d.ts +27 -4
  60. package/dist/release/snapshot/verify.js +13 -9
  61. package/dist/renderer/compatibility.js +8 -5
  62. package/dist/renderer/contract.js +5 -4
  63. package/dist/runtime/protected/limits.js +2 -1
  64. package/dist/runtime/protected/spec.js +3 -3
  65. package/dist/text/json.d.ts +5 -0
  66. package/dist/text/json.js +5 -0
  67. package/dist/transport/request.d.ts +108 -108
  68. package/dist/tryout/closure/accounting.d.ts +5 -3
  69. package/dist/tryout/closure/accounting.js +12 -10
  70. package/dist/tryout/closure/locale.js +32 -24
  71. package/dist/tryout/closure/placement.js +3 -2
  72. package/dist/tryout/hash/catalog.js +11 -10
  73. package/dist/tryout/hash/content.js +2 -1
  74. package/dist/tryout/hash/placement.js +2 -1
  75. package/dist/tryout/language.js +2 -4
  76. package/dist/tryout/runtime/canonical.js +2 -1
  77. package/dist/tryout/scoring.d.ts +13 -9
  78. package/dist/tryout/scoring.js +17 -8
  79. package/dist/tryout/snapshot/canonical.js +2 -1
  80. package/dist/tryout/snapshot/hash.js +2 -1
  81. package/package.json +1 -1
package/dist/content.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { type ContentKey, type PublicPath, Sha256HashSchema } from "#contracts/ids";
3
- import { type AppLocale, type ArtifactLocale } from "#contracts/locale";
2
+ import { type PublicPath, Sha256HashSchema } from "#contracts/ids";
3
+ import { type AppLocale } from "#contracts/locale";
4
4
  /** Published content families backed by real Aksara source registries. */
5
5
  export declare const ContentFamilySchema: Schema.Literals<readonly ["article", "material", "page", "question"]>;
6
6
  export type ContentFamily = typeof ContentFamilySchema.Type;
@@ -9,11 +9,12 @@ export declare const ContentAuthorSchema: Schema.Struct<{
9
9
  readonly name: Schema.String;
10
10
  }>;
11
11
  export type ContentAuthor = typeof ContentAuthorSchema.Type;
12
+ declare const ContentHeadIdentitySchema: Schema.Struct<{
13
+ readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
14
+ readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
15
+ }>;
12
16
  /** Stable language-specific identity shared by artifacts and content heads. */
13
- export interface ContentHeadIdentity {
14
- readonly artifactLocale: ArtifactLocale;
15
- readonly contentKey: ContentKey;
16
- }
17
+ export type ContentHeadIdentity = typeof ContentHeadIdentitySchema.Type;
17
18
  /** Builds the unambiguous key used for one language-specific content head. */
18
19
  export declare function headIdentity(input: ContentHeadIdentity): string;
19
20
  /** Builds the unambiguous key used for one application-localized route. */
@@ -126,3 +127,4 @@ export declare const decodeCompileDocumentSource: (input: unknown) => Effect.Eff
126
127
  readonly rendererDomain: "ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math";
127
128
  readonly sourcePath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraCorpusSourcePath">;
128
129
  }, import("./errors.js").ContractDecodeError, never>;
130
+ export {};
package/dist/content.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { decodeContract } from "#contracts/decode";
3
3
  import { ContentKeySchema, CorpusSourcePathSchema, Ed25519SignatureSchema, Sha256HashSchema, SigningKeyIdSchema, } from "#contracts/ids";
4
- import { ArtifactLocaleSchema, } from "#contracts/locale";
4
+ import { ArtifactLocaleSchema } from "#contracts/locale";
5
5
  import { RendererComponentsSchema } from "#contracts/renderer/component";
6
6
  import { RendererManifestEnvelopeSchema } from "#contracts/renderer/contract";
7
7
  import { RendererDomainSchema } from "#contracts/renderer/domain";
8
+ import { encodeJsonText } from "#contracts/text/json";
8
9
  import { compareCodeUnits } from "#contracts/text/order";
9
10
  /** Published content families backed by real Aksara source registries. */
10
11
  export const ContentFamilySchema = Schema.Literals([
@@ -15,6 +16,10 @@ export const ContentFamilySchema = Schema.Literals([
15
16
  ]);
16
17
  /** Exact authored person identity exposed by Nakafa content metadata. */
17
18
  export const ContentAuthorSchema = Schema.Struct({ name: Schema.String });
19
+ const ContentHeadIdentitySchema = Schema.Struct({
20
+ artifactLocale: ArtifactLocaleSchema,
21
+ contentKey: ContentKeySchema,
22
+ });
18
23
  /** Builds the unambiguous key used for one language-specific content head. */
19
24
  export function headIdentity(input) {
20
25
  return `${input.contentKey}\0${input.artifactLocale}`;
@@ -72,7 +77,7 @@ export const SignedContentArtifactSchema = Schema.Struct({
72
77
  const CONTENT_ARTIFACT_SIGNATURE_DOMAIN = "nakafa.aksara.content-artifact";
73
78
  /** Serializes a compiled payload with stable field and component order. */
74
79
  export function canonicalizeCompiledContentPayload(payload) {
75
- return JSON.stringify({
80
+ return encodeJsonText({
76
81
  artifactLocale: payload.artifactLocale,
77
82
  byteLength: payload.byteLength,
78
83
  compiledCode: payload.compiledCode,
@@ -94,7 +99,7 @@ export function canonicalizeContentArtifactSigningInput(artifactHash, payload) {
94
99
  }
95
100
  /** Serializes a complete signed artifact with deterministic wire field order. */
96
101
  export function canonicalizeSignedContentArtifact(artifact) {
97
- return `{"artifactHash":${JSON.stringify(artifact.artifactHash)},"keyId":${JSON.stringify(artifact.keyId)},"payload":${canonicalizeCompiledContentPayload(artifact.payload)},"signature":${JSON.stringify(artifact.signature)}}`;
102
+ return `{"artifactHash":${encodeJsonText(artifact.artifactHash)},"keyId":${encodeJsonText(artifact.keyId)},"payload":${canonicalizeCompiledContentPayload(artifact.payload)},"signature":${encodeJsonText(artifact.signature)}}`;
98
103
  }
99
104
  /** Decodes unknown compiler input without throwing parser exceptions. */
100
105
  export const decodeCompileDocumentRequest = Effect.fn("AksaraContracts.decodeCompileDocumentRequest")((input) => decodeContract(CompileDocumentRequestSchema, "CompileDocumentRequest", input));
package/dist/math/arc.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BigDecimal } from "effect";
1
+ import { BigDecimal, Schema } from "effect";
2
2
  import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
3
3
  import { decimal } from "#contracts/math/rational";
4
4
  const PI = BigDecimal.fromStringUnsafe("3.1415926535897932384626433832795028841971693993751");
@@ -9,6 +9,10 @@ const THREE_SIXTY = BigDecimal.fromBigInt(360n);
9
9
  const SEVEN_TWENTY = BigDecimal.fromBigInt(720n);
10
10
  const TRIGONOMETRIC_ERROR = decimal(GEOMETRY_TOLERANCE);
11
11
  const MINIMUM_ERROR = decimal(Number.MIN_VALUE);
12
+ const BoundedDecimalSchema = Schema.Struct({
13
+ error: Schema.BigDecimal,
14
+ value: Schema.BigDecimal,
15
+ });
12
16
  /** Bounds a sine estimate for an angle that may fall below Number.MIN_VALUE. */
13
17
  function stableSine(exactRadians, numericRadians) {
14
18
  const value = BigDecimal.isZero(exactRadians) || numericRadians === 0
package/dist/math/base.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { HashSet, MutableHashSet, Schema } from "effect";
2
2
  const KEY_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
3
3
  /** Relative floating-point tolerance used by normalized geometry predicates. */
4
4
  export const GEOMETRY_TOLERANCE = Number.EPSILON * 128;
@@ -66,22 +66,22 @@ export function sameSpacePoint(left, right) {
66
66
  }
67
67
  /** Returns every repeated-key index after its first authored occurrence. */
68
68
  function duplicateKeyIndexes(values, keyOf) {
69
- const seen = new Set();
69
+ const seen = MutableHashSet.empty();
70
70
  const duplicates = [];
71
71
  for (const [index, value] of values.entries()) {
72
72
  const key = keyOf(value);
73
- if (seen.has(key)) {
73
+ if (MutableHashSet.has(seen, key)) {
74
74
  duplicates.push(index);
75
75
  }
76
76
  else {
77
- seen.add(key);
77
+ MutableHashSet.add(seen, key);
78
78
  }
79
79
  }
80
80
  return duplicates;
81
81
  }
82
82
  /** Reports every repeated scene identity at its exact authored key path. */
83
83
  export function mathVisualIdentityIssues(objects, labels) {
84
- const objectIds = new Set(objects.map(({ id }) => id));
84
+ const objectIds = HashSet.fromIterable(objects.map(({ id }) => id));
85
85
  return [
86
86
  ...duplicateKeyIndexes(objects, ({ id }) => id).map((index) => ({
87
87
  issue: "Expected a unique mathematical object id.",
@@ -91,7 +91,7 @@ export function mathVisualIdentityIssues(objects, labels) {
91
91
  issue: "Expected a unique mathematical label key.",
92
92
  path: ["labels", index, "key"],
93
93
  })),
94
- ...labels.flatMap((label, index) => objectIds.has(label.objectId)
94
+ ...labels.flatMap((label, index) => HashSet.has(objectIds, label.objectId)
95
95
  ? []
96
96
  : [
97
97
  {
@@ -1,7 +1,7 @@
1
- import type { BigDecimal } from "effect";
2
- import type { SceneCoordinate, ScenePath } from "#contracts/math/coordinate";
1
+ import { type BigDecimal } from "effect";
2
+ import type { SceneCoordinate } from "#contracts/math/coordinate";
3
3
  import type { PlaneMathObject } from "#contracts/math/plane";
4
4
  /** Finds reportable scene coordinates that collapse on the same axis. */
5
- export declare function coordinateCollisionPaths(coordinates: readonly SceneCoordinate[], threshold: BigDecimal.BigDecimal): ScenePath[];
5
+ export declare function coordinateCollisionPaths(coordinates: readonly SceneCoordinate[], threshold: BigDecimal.BigDecimal): (string | number)[][];
6
6
  /** Finds non-zero radius deltas between concentric circles or arcs. */
7
- export declare function concentricRadiusCollisionPaths(objects: readonly PlaneMathObject[], threshold: BigDecimal.BigDecimal): ScenePath[];
7
+ export declare function concentricRadiusCollisionPaths(objects: readonly PlaneMathObject[], threshold: BigDecimal.BigDecimal): (string | number)[][];
@@ -1,11 +1,15 @@
1
+ import { Array as Arr, MutableHashMap, MutableHashSet, Option, } from "effect";
1
2
  import { unresolvedProximityIndexes } from "#contracts/math/proximity";
2
3
  import { numberRatio } from "#contracts/math/rational";
3
4
  import { radialGeometryPath } from "#contracts/math/scene";
5
+ import { encodeJsonText } from "#contracts/text/json";
4
6
  /** Keeps one authored issue path for each exact path value. */
5
7
  function uniquePaths(paths) {
6
- return [
7
- ...new Map(paths.map((path) => [JSON.stringify(path), path])).values(),
8
- ];
8
+ const byText = MutableHashMap.empty();
9
+ for (const path of paths) {
10
+ MutableHashMap.set(byText, encodeJsonText(path), path);
11
+ }
12
+ return Arr.fromIterable(MutableHashMap.values(byText));
9
13
  }
10
14
  /** Finds reportable scene coordinates that collapse on the same axis. */
11
15
  export function coordinateCollisionPaths(coordinates, threshold) {
@@ -13,26 +17,28 @@ export function coordinateCollisionPaths(coordinates, threshold) {
13
17
  return uniquePaths(axes.flatMap((axis) => {
14
18
  const entries = coordinates.filter((entry) => entry.axis === axis);
15
19
  const unresolved = unresolvedProximityIndexes(entries, threshold);
16
- return entries.flatMap((entry, index) => entry.reportable && unresolved.has(index) ? [entry.path] : []);
20
+ return entries.flatMap((entry, index) => entry.reportable && MutableHashSet.has(unresolved, index)
21
+ ? [entry.path]
22
+ : []);
17
23
  }));
18
24
  }
19
25
  /** Finds non-zero radius deltas between concentric circles or arcs. */
20
26
  export function concentricRadiusCollisionPaths(objects, threshold) {
21
- const groups = new Map();
27
+ const groups = MutableHashMap.empty();
22
28
  for (const [index, object] of objects.entries()) {
23
29
  if (object.kind !== "arc" && object.kind !== "circle") {
24
30
  continue;
25
31
  }
26
32
  const key = `${object.center.x}:${object.center.y}`;
27
- const group = groups.get(key) ?? [];
33
+ const group = Option.getOrUndefined(MutableHashMap.get(groups, key)) ?? [];
28
34
  group.push({ index, kind: object.kind, value: numberRatio(object.radius) });
29
- groups.set(key, group);
35
+ MutableHashMap.set(groups, key, group);
30
36
  }
31
37
  const paths = [];
32
- for (const group of groups.values()) {
38
+ for (const group of MutableHashMap.values(groups)) {
33
39
  const unresolved = unresolvedProximityIndexes(group, threshold);
34
40
  for (const [entryIndex, entry] of group.entries()) {
35
- if (unresolved.has(entryIndex)) {
41
+ if (MutableHashSet.has(unresolved, entryIndex)) {
36
42
  paths.push(radialGeometryPath(entry.kind, entry.index));
37
43
  }
38
44
  }
@@ -1,24 +1,35 @@
1
- import type { BigDecimal } from "effect";
1
+ import { type BigDecimal, Schema } from "effect";
2
2
  import type { PlanePoint, SpacePoint } from "#contracts/math/base";
3
- import { type AxisTraversal } from "#contracts/math/intersection";
4
3
  import type { PlaneMathFrame } from "#contracts/math/plane";
5
4
  import { type RenderThreshold } from "#contracts/math/precision";
6
5
  import { type ExactRatio } from "#contracts/math/rational";
7
6
  import type { SpaceMathFrame } from "#contracts/math/space";
8
7
  export type SceneAxis = "x" | "y" | "z";
9
- export type ScenePath = Array<number | string>;
8
+ export declare const ScenePathSchema: Schema.mutable<Schema.$Array<Schema.Union<readonly [Schema.Finite, Schema.String]>>>;
9
+ export type ScenePath = typeof ScenePathSchema.Type;
10
10
  /** One ordered exact coordinate projected from a complete visual scene. */
11
- export interface SceneCoordinate {
12
- readonly axis: SceneAxis;
13
- readonly error?: BigDecimal.BigDecimal;
14
- readonly path: ScenePath;
15
- readonly reportable: boolean;
16
- readonly value: ExactRatio;
17
- }
11
+ declare const SceneCoordinateSchema: Schema.Struct<{
12
+ readonly axis: Schema.Literals<readonly ["x", "y", "z"]>;
13
+ readonly error: Schema.optionalKey<Schema.BigDecimal>;
14
+ readonly path: Schema.mutable<Schema.$Array<Schema.Union<readonly [Schema.Finite, Schema.String]>>>;
15
+ readonly reportable: Schema.Boolean;
16
+ readonly value: Schema.Struct<{
17
+ readonly denominator: Schema.BigDecimal;
18
+ readonly numerator: Schema.BigDecimal;
19
+ }>;
20
+ }>;
21
+ export type SceneCoordinate = typeof SceneCoordinateSchema.Type;
18
22
  export type SceneFrame = PlaneMathFrame | SpaceMathFrame;
19
- interface SceneAxisTraversal extends AxisTraversal {
20
- readonly axis: SceneAxis;
21
- }
23
+ declare const SceneAxisTraversalSchema: Schema.Struct<{
24
+ readonly range: Schema.Struct<{
25
+ readonly max: Schema.Finite;
26
+ readonly min: Schema.Finite;
27
+ }>;
28
+ readonly start: Schema.Finite;
29
+ readonly through: Schema.Finite;
30
+ readonly axis: Schema.Literals<readonly ["x", "y", "z"]>;
31
+ }>;
32
+ type SceneAxisTraversal = typeof SceneAxisTraversalSchema.Type;
22
33
  /** Creates one reportable exact scene coordinate. */
23
34
  export declare function sceneCoordinate(axis: SceneAxis, path: ScenePath, value: ExactRatio, reportable?: boolean, error?: BigDecimal.BigDecimal): SceneCoordinate;
24
35
  /** Projects every axis of one finite point in authored order. */
@@ -1,6 +1,20 @@
1
- import { infinitePathInterval, } from "#contracts/math/intersection";
1
+ import { Schema } from "effect";
2
+ import { AxisTraversalSchema, infinitePathInterval, } from "#contracts/math/intersection";
2
3
  import { visiblePathResolvable, } from "#contracts/math/precision";
3
- import { affineRatio, numberRatio, } from "#contracts/math/rational";
4
+ import { affineRatio, ExactRatioSchema, numberRatio, } from "#contracts/math/rational";
5
+ export const ScenePathSchema = Schema.mutable(Schema.Array(Schema.Union([Schema.Finite, Schema.String])));
6
+ /** One ordered exact coordinate projected from a complete visual scene. */
7
+ const SceneCoordinateSchema = Schema.Struct({
8
+ axis: Schema.Literals(["x", "y", "z"]),
9
+ error: Schema.optionalKey(Schema.BigDecimal),
10
+ path: ScenePathSchema,
11
+ reportable: Schema.Boolean,
12
+ value: ExactRatioSchema,
13
+ });
14
+ const SceneAxisTraversalSchema = Schema.Struct({
15
+ ...AxisTraversalSchema.fields,
16
+ axis: Schema.Literals(["x", "y", "z"]),
17
+ });
4
18
  /** Creates one reportable exact scene coordinate. */
5
19
  export function sceneCoordinate(axis, path, value, reportable = true, error) {
6
20
  return error === undefined
@@ -1,15 +1,15 @@
1
- import { BigDecimal } from "effect";
1
+ import { Schema } from "effect";
2
2
  import type { PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
3
- import { type ExactRatio } from "#contracts/math/rational";
4
3
  import type { SpaceMathFrame, SpaceMathObject } from "#contracts/math/space";
5
4
  export type AxisRange = PlaneMathFrame["x"];
6
5
  /** Checks one finite coordinate against its inclusive authored range. */
7
6
  export declare function axisContains(range: AxisRange, coordinate: number): boolean;
8
- export interface RadialOffset {
9
- readonly error: BigDecimal.BigDecimal;
10
- readonly x: BigDecimal.BigDecimal;
11
- readonly y: BigDecimal.BigDecimal;
12
- }
7
+ declare const RadialOffsetSchema: Schema.Struct<{
8
+ readonly error: Schema.BigDecimal;
9
+ readonly x: Schema.BigDecimal;
10
+ readonly y: Schema.BigDecimal;
11
+ }>;
12
+ export type RadialOffset = typeof RadialOffsetSchema.Type;
13
13
  /** Returns every endpoint or cardinal offset that bounds one radial object. */
14
14
  export declare function radialOffsets(object: Extract<PlaneMathObject, {
15
15
  readonly kind: "arc" | "circle";
@@ -23,10 +23,17 @@ export declare function circleContained(frame: PlaneMathFrame, object: Extract<P
23
23
  readonly kind: "circle";
24
24
  }>): boolean;
25
25
  /** One exact input and output pair at a quadratic domain extremum. */
26
- export interface QuadraticExtremum {
27
- readonly input: ExactRatio;
28
- readonly output: ExactRatio;
29
- }
26
+ declare const QuadraticExtremumSchema: Schema.Struct<{
27
+ readonly input: Schema.Struct<{
28
+ readonly denominator: Schema.BigDecimal;
29
+ readonly numerator: Schema.BigDecimal;
30
+ }>;
31
+ readonly output: Schema.Struct<{
32
+ readonly denominator: Schema.BigDecimal;
33
+ readonly numerator: Schema.BigDecimal;
34
+ }>;
35
+ }>;
36
+ export type QuadraticExtremum = typeof QuadraticExtremumSchema.Type;
30
37
  /** Returns both domain endpoints and the in-domain vertex of one quadratic. */
31
38
  export declare function quadraticExtrema(object: Extract<PlaneMathObject, {
32
39
  readonly kind: "quadratic";
@@ -35,12 +42,13 @@ export declare function quadraticExtrema(object: Extract<PlaneMathObject, {
35
42
  export declare function quadraticContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
36
43
  readonly kind: "quadratic";
37
44
  }>): boolean;
38
- export interface CuboidExtent {
39
- readonly axis: "x" | "y" | "z";
40
- readonly center: number;
41
- readonly dimension: "height" | "length" | "width";
42
- readonly extent: BigDecimal.BigDecimal;
43
- }
45
+ declare const CuboidExtentSchema: Schema.Struct<{
46
+ readonly axis: Schema.Literals<readonly ["x", "y", "z"]>;
47
+ readonly center: Schema.Finite;
48
+ readonly dimension: Schema.Literals<readonly ["height", "length", "width"]>;
49
+ readonly extent: Schema.BigDecimal;
50
+ }>;
51
+ export type CuboidExtent = typeof CuboidExtentSchema.Type;
44
52
  /** Returns the exact positive half-extent on every cuboid axis. */
45
53
  export declare function cuboidExtents(object: Extract<SpaceMathObject, {
46
54
  readonly kind: "cuboid";
@@ -49,3 +57,4 @@ export declare function cuboidExtents(object: Extract<SpaceMathObject, {
49
57
  export declare function cuboidContained(frame: SpaceMathFrame, object: Extract<SpaceMathObject, {
50
58
  readonly kind: "cuboid";
51
59
  }>): boolean;
60
+ export {};
@@ -1,6 +1,6 @@
1
- import { BigDecimal } from "effect";
1
+ import { BigDecimal, Schema } from "effect";
2
2
  import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
3
- import { decimal, decimalRatio, makeRatio, numberRatio, ratioInRange, } from "#contracts/math/rational";
3
+ import { decimal, decimalRatio, ExactRatioSchema, makeRatio, numberRatio, ratioInRange, } from "#contracts/math/rational";
4
4
  const ZERO = BigDecimal.fromBigInt(0n);
5
5
  /** Checks one finite coordinate against its inclusive authored range. */
6
6
  export function axisContains(range, coordinate) {
@@ -26,6 +26,11 @@ function arcContainsAngle(start, sweep, angle) {
26
26
  ? normalizeDegrees(angle - start) <= sweep
27
27
  : normalizeDegrees(start - angle) <= -sweep;
28
28
  }
29
+ const RadialOffsetSchema = Schema.Struct({
30
+ error: Schema.BigDecimal,
31
+ x: Schema.BigDecimal,
32
+ y: Schema.BigDecimal,
33
+ });
29
34
  /** Resolves exact cardinals or a trig offset with its renderer error envelope. */
30
35
  function arcOffset(radius, angle) {
31
36
  const normalized = normalizeDegrees(angle);
@@ -87,6 +92,11 @@ function quadraticValue(object, input) {
87
92
  decimal(c),
88
93
  ]);
89
94
  }
95
+ /** One exact input and output pair at a quadratic domain extremum. */
96
+ const QuadraticExtremumSchema = Schema.Struct({
97
+ input: ExactRatioSchema,
98
+ output: ExactRatioSchema,
99
+ });
90
100
  /** Returns both domain endpoints and the in-domain vertex of one quadratic. */
91
101
  export function quadraticExtrema(object) {
92
102
  const endpoints = [object.domain.min, object.domain.max].map((input) => ({
@@ -112,6 +122,12 @@ export function quadraticContained(frame, object) {
112
122
  }
113
123
  return quadraticExtrema(object).every(({ output }) => ratioInRange(output, outputRange.min, outputRange.max));
114
124
  }
125
+ const CuboidExtentSchema = Schema.Struct({
126
+ axis: Schema.Literals(["x", "y", "z"]),
127
+ center: Schema.Finite,
128
+ dimension: Schema.Literals(["height", "length", "width"]),
129
+ extent: Schema.BigDecimal,
130
+ });
115
131
  /** Returns the exact positive half-extent on every cuboid axis. */
116
132
  export function cuboidExtents(object) {
117
133
  const half = decimal(0.5);
@@ -1,17 +1,27 @@
1
- import { type AxisRange } from "#contracts/math/extent";
2
- import { type ExactRatio } from "#contracts/math/rational";
1
+ import { Schema } from "effect";
3
2
  /** One Cartesian slab traversed by the same parametric path. */
4
- export interface AxisTraversal {
5
- readonly range: AxisRange;
6
- readonly start: number;
7
- readonly through: number;
8
- }
3
+ export declare const AxisTraversalSchema: Schema.Struct<{
4
+ readonly range: Schema.Struct<{
5
+ readonly max: Schema.Finite;
6
+ readonly min: Schema.Finite;
7
+ }>;
8
+ readonly start: Schema.Finite;
9
+ readonly through: Schema.Finite;
10
+ }>;
11
+ export type AxisTraversal = typeof AxisTraversalSchema.Type;
9
12
  type InfinitePathKind = "line" | "ray";
10
13
  /** Exact finite sides of one clipped infinite path parameter interval. */
11
- export interface InfinitePathInterval {
12
- readonly entry: ExactRatio | undefined;
13
- readonly exit: ExactRatio | undefined;
14
- }
14
+ declare const InfinitePathIntervalSchema: Schema.Struct<{
15
+ readonly entry: Schema.UndefinedOr<Schema.Struct<{
16
+ readonly denominator: Schema.BigDecimal;
17
+ readonly numerator: Schema.BigDecimal;
18
+ }>>;
19
+ readonly exit: Schema.UndefinedOr<Schema.Struct<{
20
+ readonly denominator: Schema.BigDecimal;
21
+ readonly numerator: Schema.BigDecimal;
22
+ }>>;
23
+ }>;
24
+ export type InfinitePathInterval = typeof InfinitePathIntervalSchema.Type;
15
25
  /** Clips one infinite line or ray against an inclusive axis-aligned box. */
16
26
  export declare function infinitePathInterval(kind: InfinitePathKind, axes: readonly AxisTraversal[]): InfinitePathInterval | undefined;
17
27
  /** Checks whether one infinite line or ray intersects an inclusive axis-aligned box. */
@@ -1,5 +1,18 @@
1
+ import { Schema } from "effect";
2
+ import { MathAxisRangeSchema } from "#contracts/math/base";
1
3
  import { axisContains } from "#contracts/math/extent";
2
- import { compareRatios, differenceRatio, numberRatio, } from "#contracts/math/rational";
4
+ import { compareRatios, differenceRatio, ExactRatioSchema, numberRatio, } from "#contracts/math/rational";
5
+ /** One Cartesian slab traversed by the same parametric path. */
6
+ export const AxisTraversalSchema = Schema.Struct({
7
+ range: MathAxisRangeSchema,
8
+ start: Schema.Finite,
9
+ through: Schema.Finite,
10
+ });
11
+ /** Exact finite sides of one clipped infinite path parameter interval. */
12
+ const InfinitePathIntervalSchema = Schema.Struct({
13
+ entry: Schema.UndefinedOr(ExactRatioSchema),
14
+ exit: Schema.UndefinedOr(ExactRatioSchema),
15
+ });
3
16
  /** Keeps the greater finite side of one lower parameter boundary. */
4
17
  function later(current, candidate) {
5
18
  return current === undefined || compareRatios(current, candidate) < 0
@@ -1,4 +1,4 @@
1
- import { BigDecimal, Array as EffectArray } from "effect";
1
+ import { BigDecimal, Array as EffectArray, Record as Rec } from "effect";
2
2
  import { infinitePathInterval, } from "#contracts/math/intersection";
3
3
  import { decimal, makeRatio } from "#contracts/math/rational";
4
4
  const FLOAT32_RESOLUTION = BigDecimal.fromStringUnsafe("0.00000011920928955078125");
@@ -96,11 +96,11 @@ export function polygonAltitudeUnresolved(vertices, threshold) {
96
96
  y: BigDecimal.subtract(BigDecimal.multiply(baseline.z, offset.x), BigDecimal.multiply(baseline.x, offset.z)),
97
97
  z: BigDecimal.subtract(BigDecimal.multiply(baseline.x, offset.y), BigDecimal.multiply(baseline.y, offset.x)),
98
98
  };
99
- const crossSquared = BigDecimal.sumAll(Object.values(cross).map((value) => BigDecimal.multiply(value, value)));
99
+ const crossSquared = BigDecimal.sumAll(Rec.values(cross).map((value) => BigDecimal.multiply(value, value)));
100
100
  if (BigDecimal.isZero(crossSquared)) {
101
101
  continue;
102
102
  }
103
- const baselineSquared = BigDecimal.sumAll(Object.values(baseline).map((value) => BigDecimal.multiply(value, value)));
103
+ const baselineSquared = BigDecimal.sumAll(Rec.values(baseline).map((value) => BigDecimal.multiply(value, value)));
104
104
  if (BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared))) {
105
105
  return true;
106
106
  }
@@ -1,12 +1,16 @@
1
- import { BigDecimal } from "effect";
2
- import { type ExactRatio } from "#contracts/math/rational";
1
+ import { BigDecimal, MutableHashSet, Schema } from "effect";
3
2
  /** One exact rational coordinate participating in a proximity comparison. */
4
- export interface ExactProximityEntry {
5
- readonly error?: BigDecimal.BigDecimal;
6
- readonly value: ExactRatio;
7
- }
3
+ declare const ExactProximityEntrySchema: Schema.Struct<{
4
+ readonly error: Schema.optionalKey<Schema.BigDecimal>;
5
+ readonly value: Schema.Struct<{
6
+ readonly denominator: Schema.BigDecimal;
7
+ readonly numerator: Schema.BigDecimal;
8
+ }>;
9
+ }>;
10
+ export type ExactProximityEntry = typeof ExactProximityEntrySchema.Type;
8
11
  /**
9
12
  * Finds later-authored coordinates whose disjoint error intervals prove a
10
13
  * distinct gap below one threshold in O(n log n).
11
14
  */
12
- export declare function unresolvedProximityIndexes(entries: readonly ExactProximityEntry[], threshold: BigDecimal.BigDecimal): Set<number>;
15
+ export declare function unresolvedProximityIndexes(entries: readonly ExactProximityEntry[], threshold: BigDecimal.BigDecimal): MutableHashSet.MutableHashSet<number>;
16
+ export {};
@@ -1,5 +1,22 @@
1
- import { BigDecimal, Array as EffectArray } from "effect";
2
- import { compareRatios, makeRatio, } from "#contracts/math/rational";
1
+ import { BigDecimal, Array as EffectArray, MutableHashSet, Schema, } from "effect";
2
+ import { compareRatios, ExactRatioSchema, makeRatio, } from "#contracts/math/rational";
3
+ /** One exact rational coordinate participating in a proximity comparison. */
4
+ const ExactProximityEntrySchema = Schema.Struct({
5
+ error: Schema.optionalKey(Schema.BigDecimal),
6
+ value: ExactRatioSchema,
7
+ });
8
+ const ExactIntervalSchema = Schema.Struct({
9
+ lower: ExactRatioSchema,
10
+ upper: ExactRatioSchema,
11
+ });
12
+ const RankedRatiosSchema = Schema.Struct({
13
+ ranks: Schema.Array(Schema.Finite),
14
+ values: Schema.Array(ExactRatioSchema),
15
+ });
16
+ const RatioTreeSchema = Schema.Struct({
17
+ base: Schema.Finite,
18
+ values: Schema.mutableKey(Schema.mutable(Schema.Array(Schema.UndefinedOr(ExactRatioSchema)))),
19
+ });
3
20
  const ZERO = BigDecimal.fromBigInt(0n);
4
21
  /** Translates one rational coordinate by an exact decimal measurement. */
5
22
  function translate(value, offset, direction) {
@@ -117,7 +134,7 @@ export function unresolvedProximityIndexes(entries, threshold) {
117
134
  const upper = rankRatios(intervals.map((entry) => entry.upper));
118
135
  const leftTree = makeTree(upper.values.length);
119
136
  const rightTree = makeTree(lower.values.length);
120
- const unresolved = new Set();
137
+ const unresolved = MutableHashSet.empty();
121
138
  for (const [sourceIndex, interval] of intervals.entries()) {
122
139
  const leftEnd = firstRank(upper.values, interval.lower, false);
123
140
  const closestLeft = queryTree(leftTree, 0, leftEnd, greaterRatio);
@@ -129,7 +146,7 @@ export function unresolvedProximityIndexes(entries, threshold) {
129
146
  compareRatios(leftThreshold, closestLeft) < 0) ||
130
147
  (closestRight !== undefined &&
131
148
  compareRatios(closestRight, rightThreshold) < 0)) {
132
- unresolved.add(sourceIndex);
149
+ MutableHashSet.add(unresolved, sourceIndex);
133
150
  }
134
151
  updateTree(leftTree, EffectArray.getUnsafe(upper.ranks, sourceIndex), interval.lower, greaterRatio);
135
152
  updateTree(rightTree, EffectArray.getUnsafe(lower.ranks, sourceIndex), interval.upper, lesserRatio);
@@ -1,9 +1,10 @@
1
- import { BigDecimal } from "effect";
1
+ import { BigDecimal, Schema } from "effect";
2
2
  /** Exact quotient whose denominator is normalized to a positive value. */
3
- export interface ExactRatio {
4
- readonly denominator: BigDecimal.BigDecimal;
5
- readonly numerator: BigDecimal.BigDecimal;
6
- }
3
+ export declare const ExactRatioSchema: Schema.Struct<{
4
+ readonly denominator: Schema.BigDecimal;
5
+ readonly numerator: Schema.BigDecimal;
6
+ }>;
7
+ export type ExactRatio = typeof ExactRatioSchema.Type;
7
8
  /** Creates one exact decimal from a schema-validated finite number. */
8
9
  export declare function decimal(value: number): BigDecimal.BigDecimal;
9
10
  /** Lifts one exact decimal into the shared rational coordinate form. */
@@ -1,4 +1,9 @@
1
- import { BigDecimal } from "effect";
1
+ import { BigDecimal, Schema } from "effect";
2
+ /** Exact quotient whose denominator is normalized to a positive value. */
3
+ export const ExactRatioSchema = Schema.Struct({
4
+ denominator: Schema.BigDecimal,
5
+ numerator: Schema.BigDecimal,
6
+ });
2
7
  const unit = BigDecimal.fromBigInt(1n);
3
8
  /** Creates one exact decimal from a schema-validated finite number. */
4
9
  export function decimal(value) {
@@ -1,4 +1,4 @@
1
- import type { Schema } from "effect";
1
+ import { Schema } from "effect";
2
2
  import type { PlaneLabelAnchor, PlaneMathFrame, PlaneMathObject, PlaneMathView } from "#contracts/math/plane";
3
3
  import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject, SpaceMathView } from "#contracts/math/space";
4
4
  /** One stable authoring failure for geometry below renderer resolution. */
@@ -1,19 +1,27 @@
1
+ import { Array as Arr, MutableHashMap, Schema } from "effect";
1
2
  import { arcCurvatureUnresolved, arcEndpointAxesUnresolved, arcEndpointsUnresolved, } from "#contracts/math/arc";
2
3
  import { concentricRadiusCollisionPaths, coordinateCollisionPaths, } from "#contracts/math/collision";
3
- import { pathAxes } from "#contracts/math/coordinate";
4
+ import { pathAxes, ScenePathSchema, } from "#contracts/math/coordinate";
4
5
  import { axisEnvelopePairs, axisSpan, measureUnresolved, polygonAltitudeUnresolved, quadraticCurvatureUnresolved, renderThreshold, spanUnresolved, visiblePathResolvable, } from "#contracts/math/precision";
5
6
  import { planeSceneCoordinates, spaceSceneCoordinates, } from "#contracts/math/scene";
7
+ import { encodeJsonText } from "#contracts/text/json";
6
8
  /** One stable authoring failure for geometry below renderer resolution. */
7
9
  export const MATH_VISUAL_RESOLUTION_MESSAGE = "Expected every non-zero mathematical visual delta to be at least 2^-23 of its combined render envelope.";
10
+ const ResolutionIssueSchema = Schema.Struct({
11
+ issue: Schema.Literal(MATH_VISUAL_RESOLUTION_MESSAGE),
12
+ path: ScenePathSchema,
13
+ });
8
14
  /** Places the shared resolution failure at one authored schema path. */
9
15
  function issue(path) {
10
16
  return { issue: MATH_VISUAL_RESOLUTION_MESSAGE, path };
11
17
  }
12
18
  /** Removes repeated issue paths while preserving first-cause order. */
13
19
  function uniqueIssues(issues) {
14
- return [
15
- ...new Map(issues.map((candidate) => [JSON.stringify(candidate.path), candidate])).values(),
16
- ];
20
+ const byPath = MutableHashMap.empty();
21
+ for (const candidate of issues) {
22
+ MutableHashMap.set(byPath, encodeJsonText(candidate.path), candidate);
23
+ }
24
+ return Arr.fromIterable(MutableHashMap.values(byPath));
17
25
  }
18
26
  /** Reports one non-zero authored measure below the scene threshold. */
19
27
  function measureIssue(value, threshold, path) {