@silverprotocol/core 0.8.0 → 0.10.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/src/wire.ts CHANGED
@@ -13,19 +13,40 @@ export function toWire(e: AgEvent): JsonValue {
13
13
  return w;
14
14
  }
15
15
 
16
+ /**
17
+ * A JSON round-trip of `v` (throws where `JSON.stringify` throws; see {@link toJsonValueSafe}).
18
+ *
19
+ * @beta
20
+ */
16
21
  export function toJsonValue(v: unknown): JsonValue {
17
22
  const w: JsonValue = JSON.parse(JSON.stringify(v));
18
23
  return w;
19
24
  }
20
25
 
21
- /** The value a cycle is replaced with by {@link toJsonValueSafe} (at the repeated node only). */
26
+ /**
27
+ * The value a cycle is replaced with by {@link toJsonValueSafe} (at the repeated node only).
28
+ *
29
+ * @beta
30
+ */
22
31
  export const JSON_SAFE_CIRCULAR = "[Circular]";
23
- /** The value a node nested deeper than {@link JSON_SAFE_MAX_DEPTH} is replaced with. */
32
+ /**
33
+ * The value a node nested deeper than {@link JSON_SAFE_MAX_DEPTH} is replaced with.
34
+ *
35
+ * @beta
36
+ */
24
37
  export const JSON_SAFE_MAX_DEPTH_MARK = "[MaxDepth]";
25
- /** The nesting depth past which the helpers stop descending (never reached by real data). */
38
+ /**
39
+ * The nesting depth past which the helpers stop descending (never reached by real data).
40
+ *
41
+ * @beta
42
+ */
26
43
  export const JSON_SAFE_MAX_DEPTH = 1000;
27
44
 
28
- /** Why {@link toJsonValueSafe} had to degrade a node that `JSON.stringify` would have thrown on. */
45
+ /**
46
+ * Why {@link toJsonValueSafe} had to degrade a node that `JSON.stringify` would have thrown on.
47
+ *
48
+ * @beta
49
+ */
29
50
  export type JsonSafeIssueKind =
30
51
  | "bigint" // converted to its decimal string
31
52
  | "circular" // replaced with JSON_SAFE_CIRCULAR
@@ -34,7 +55,11 @@ export type JsonSafeIssueKind =
34
55
  | "throwing-keys" // the node's keys could not be enumerated: node omitted
35
56
  | "max-depth"; // replaced with JSON_SAFE_MAX_DEPTH_MARK
36
57
 
37
- /** One degraded node: `path` is `$` for the top, then `.key` / `[index]` segments. */
58
+ /**
59
+ * One degraded node: `path` is `$` for the top, then `.key` / `[index]` segments.
60
+ *
61
+ * @beta
62
+ */
38
63
  export interface JsonSafeIssue {
39
64
  path: string;
40
65
  kind: JsonSafeIssueKind;
@@ -48,6 +73,8 @@ export interface JsonSafeIssue {
48
73
  * shallower than {@link JSON_SAFE_MAX_DEPTH}. Never throws (a throwing getter
49
74
  * or proxy trap answers `false`). The walk allocates nothing per node beyond
50
75
  * an ancestor stack, so a facet can afford it on every native event.
76
+ *
77
+ * @beta
51
78
  */
52
79
  export function isJsonValue(v: unknown): v is JsonValue {
53
80
  const ancestors: object[] = [];
@@ -155,6 +182,8 @@ export function isJsonValue(v: unknown): v is JsonValue {
155
182
  * inside emitted events. A caller that needs isolation copies the result
156
183
  * ({@link isJsonValue} is the cheap check). A facet must neither mutate the
157
184
  * returned value nor retain it past the `push()` that produced it.
185
+ *
186
+ * @beta
158
187
  */
159
188
  export function toJsonValueSafe(v: unknown): JsonValue {
160
189
  return toJsonValueSafeWithIssues(v).value;
@@ -175,6 +204,8 @@ function isErrorObject(o: object): boolean {
175
204
  * {@link toJsonValueSafe}, plus the list of nodes it had to degrade (empty when
176
205
  * the input was JSON-able). A consumer that must not forward an invented value
177
206
  * can branch on `issues.length > 0` instead of using `value`.
207
+ *
208
+ * @beta
178
209
  */
179
210
  export function toJsonValueSafeWithIssues(v: unknown): { value: JsonValue; issues: readonly JsonSafeIssue[] } {
180
211
  if (isJsonValue(v)) return { value: v, issues: [] };