@mark1russell7/coeval 0.7.0 → 0.7.1

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/src/types.ts CHANGED
@@ -54,6 +54,33 @@ export interface Domain {
54
54
  * a step with the key into a member reaches a member of the type. A key without a type gives `unknown`.
55
55
  */
56
56
  readonly steps?: Readonly<Record<string, ValueType>>;
57
+ /**
58
+ * The codec of the members: it writes a member as JSON and reads it again (D40). A document holds a member as the
59
+ * standard extension `ext.domain`. A domain without a codec has no such document.
60
+ */
61
+ readonly codec?: DomainCodec;
62
+ }
63
+
64
+ /**
65
+ * The codec of a domain: it writes a member of the domain as JSON, and it reads the JSON again (D40). Both functions
66
+ * must be pure. `decode(encode(v))` must equal `v` by `sameValue` (EXT.ROUNDTRIP). The codec must give one JSON
67
+ * value for each member, thus the same value has the same document in each language (D12).
68
+ */
69
+ export interface DomainCodec {
70
+ /**
71
+ * This function writes a member of the domain as JSON.
72
+ *
73
+ * @param value - A member of the domain.
74
+ * @returns The JSON of the member.
75
+ */
76
+ readonly encode: (value: unknown) => Json;
77
+ /**
78
+ * This function reads the JSON of a member again. It throws for JSON that does not write a member.
79
+ *
80
+ * @param data - The JSON that `encode` gave.
81
+ * @returns The member.
82
+ */
83
+ readonly decode: (data: Json) => unknown;
57
84
  }
58
85
 
59
86
  /** A problem of a value type: the keys from the root of the term to the problem, and the reason. */
@@ -102,7 +129,7 @@ const TOP: Form = { t: "top" };
102
129
  const BOTTOM: Form = { t: "bottom" };
103
130
 
104
131
  /** This function gives the domain of a base type: the domain of the machine, or else the domain of the kernel. */
105
- function domainOf(name: string, domains: Readonly<Record<string, Domain>> | undefined): Domain | undefined {
132
+ export function domainOf(name: string, domains: Readonly<Record<string, Domain>> | undefined): Domain | undefined {
106
133
  // The top and the bottom are not domains. A table entry with their names has no effect.
107
134
  if (name === "unknown" || name === "never") return undefined;
108
135
  const found = domains !== undefined && Object.hasOwn(domains, name) ? domains[name] : Object.hasOwn(STD_DOMAINS, name) ? STD_DOMAINS[name] : undefined;