@joiner-platform/cli 0.1.15 → 0.1.17
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/package.json +2 -2
- package/skills/synced-store/SKILL.md +1 -1
- package/skills/synced-store/references/external-stores.md +10 -8
- package/skills/tile-creator/references/backend-api.md +1 -1
- package/skills/tile-creator/references/cli.md +4 -3
- package/skills/tile-creator/references/sandbox-limitations.md +1 -1
- package/src/commands/init/sdk-tarball-url.generated.ts +2 -2
- package/src/commands/schema-input-example.ts +142 -14
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joiner-platform/cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.17",
|
|
4
|
+
"gitHead": "960c0d76e00310125672a371eae2d31766a1af8a",
|
|
5
5
|
"description": "The Joiner CLI: create, test, and publish Joiner tiles, with agent skills for coding agents.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"joiner",
|
|
@@ -5,7 +5,7 @@ description: "Build apps that USE synced-store for real-time multiplayer state.
|
|
|
5
5
|
|
|
6
6
|
# Synced-Store Reference
|
|
7
7
|
|
|
8
|
-
Real-time sync engine (like Replicache). Each app instance = one server-side SQLite DB + per-client IndexedDB copies. Mutators run optimistically on the client and authoritatively on the server. Actions run server-only (randomness). Neither mutators nor actions can make HTTP requests: the backend runtime's `fetch` throws. Outbound work goes through `ctx.platform.call(...)` for platform services and `ctx.
|
|
8
|
+
Real-time sync engine (like Replicache). Each app instance = one server-side SQLite DB + per-client IndexedDB copies. Mutators run optimistically on the client and authoritatively on the server. Actions run server-only (randomness). Neither mutators nor actions can make HTTP requests: the backend runtime's `fetch` throws. Outbound work goes through `ctx.platform.call(...)` for platform services and `ctx.mutateExternal(...)` (mutators) / `ctx.externalStore(...)` (actions) for other stores; neither gives general HTTP access.
|
|
9
9
|
|
|
10
10
|
- Mutators and actions are portable store code, not normal browser/Node code: mutators run on the client and then on the backend, and actions run on the backend. Backend execution happens in a special store-function runtime where ambient timer APIs such as `setTimeout` / `clearTimeout` are not available.
|
|
11
11
|
- Never change a row you read. `get`, `scan` and `entries` on the client return the object the local cache holds, so an in-place edit (`row.step++`, `row.cells[i].owner = id`, `row.items.push(x)`) corrupts local state even without a `set`, while the server's pass reads a fresh copy and the two diverge. Write a new value instead: `set({ itemKey, value: { ...row, step: row.step + 1 } })`. Read types mark top-level properties `readonly`; nested objects and arrays are not checked, so copy those too.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# External Stores: Cross-App Reads & Writes
|
|
2
2
|
|
|
3
|
-
Mutators and actions can interact with other store instances on the server. Mutators can write via `ctx.mutateExternal(...)`;
|
|
3
|
+
Mutators and actions can interact with other store instances on the server. Mutators can write via `ctx.mutateExternal(...)`; actions can read via `ctx.externalStore(...)`. Mutators cannot read another store. Receiving code identifies the caller via `ctx.source`.
|
|
4
4
|
|
|
5
5
|
## External Mutations (Writes)
|
|
6
6
|
|
|
@@ -42,24 +42,27 @@ await store.mutate.notifyParent({
|
|
|
42
42
|
### Constraints
|
|
43
43
|
|
|
44
44
|
- Max 200 unique external mutation targets per commit (each target = `(storeTypeId, instanceId)` pair; multiple mutations to the same target count as one)
|
|
45
|
-
- Max depth of 1 — target mutators cannot trigger further external **writes** (`blockExternalMutations: true`)
|
|
45
|
+
- Max depth of 1 — target mutators cannot trigger further external **writes** (`blockExternalMutations: true`)
|
|
46
46
|
- External mutations expire after 5 minutes if not committed
|
|
47
47
|
|
|
48
48
|
## External Reads
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
An action can read from another store using `ctx.externalStore({ storeTypeId, instanceId })`. The handle exposes `.table(name)` with `get`, `scan`, and `entries` (read-only).
|
|
51
|
+
|
|
52
|
+
A mutator that needs another store's data gets it from that store instead: the other store sends it with `ctx.mutateExternal(...)`, and the receiving mutator trusts it because `ctx.source` names the sender. Send any data that decides whether a write is allowed (membership, ownership, a permission) this way.
|
|
53
|
+
|
|
54
|
+
An action can also read another store and pass the result to a mutator with `ctx.mutate`, but that input carries no trust: clients can call the same mutator directly with any input. Use this path only for data the mutator would accept from the caller anyway, never to gate a write.
|
|
51
55
|
|
|
52
56
|
```typescript
|
|
53
|
-
// In
|
|
57
|
+
// In an action:
|
|
54
58
|
const ext = ctx.externalStore({ storeTypeId: "emoji-prefs", instanceId: ctx.userId });
|
|
55
59
|
const favorites = await ext.table("preferences").get("favorites");
|
|
56
60
|
const recent = await ext.table("entries").scan({ limit: 50 }).values().toArray();
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
The handle also exposes `.action(name, input)` and `.getSchema()`.
|
|
60
64
|
|
|
61
65
|
```typescript
|
|
62
|
-
// In an action only:
|
|
63
66
|
const ext = ctx.externalStore({ storeTypeId: "chat", instanceId: "room-1" });
|
|
64
67
|
const result = await ext.action("summarize", { limit: 100 });
|
|
65
68
|
const schema = await ext.getSchema();
|
|
@@ -67,8 +70,7 @@ const schema = await ext.getSchema();
|
|
|
67
70
|
|
|
68
71
|
### Reads vs writes
|
|
69
72
|
|
|
70
|
-
- **
|
|
71
|
-
- **No depth limit**: reads are stateless (no commits, no broadcasts, no retries) and are allowed inside external dispatch targets and action-invoked mutators — unlike writes
|
|
73
|
+
- **No depth limit**: reads are stateless (no commits, no broadcasts, no retries), so an action may read any store its authorization allows — unlike writes
|
|
72
74
|
- **Bounded**: a single scan/list returns at most `MAX_EXTERNAL_READ_ITEMS` (1000) and `MAX_EXTERNAL_READ_BYTES` (1 MB). Response carries a `truncated` flag when limits were hit
|
|
73
75
|
- **Timeout**: `EXTERNAL_READ_TIMEOUT_MS` = 5s for the dispatch RPC
|
|
74
76
|
|
|
@@ -307,7 +307,7 @@ import { MAX_TABLE_PAGE_CURSOR_LENGTH } from "joiner-sdk/v1/shared.js";
|
|
|
307
307
|
|
|
308
308
|
- `EntryKey` has a required `itemKey` and optional `sortKey`. Within a table, `itemKey` identifies the row; `sortKey` controls ordering, not identity.
|
|
309
309
|
- `ExternalStoreTableReader<T>` is a read-only table interface without `pageByItemKey`. Its `getWithStoreVersion(key)` returns `{ value, storeVersion, synced }`: the value and target store version come from the same snapshot, even when the row is absent. `synced` indicates whether the target has completed at least one sync.
|
|
310
|
-
- In
|
|
310
|
+
- In an action, an external `scan` (`ctx.externalStore(...)`) reads one target snapshot per response. A scan with a `limit` gets up to 1,000 rows (and at most 1,048,576 bytes of JSON-serialized rows) per response; a scan without one gets 100 rows per response. If the target commits between two responses of the same scan, the scan throws a version conflict. To read a whole bounded table consistently, pass its maximum row count as the `limit`.
|
|
311
311
|
|
|
312
312
|
Server current-store table handles expose `pageByItemKey(options)`, using
|
|
313
313
|
`TablePageOptions`: required `maxPhysicalRows` (a positive safe integer) and
|
|
@@ -61,7 +61,7 @@ an older pin, so prefer the live result when upgrading:
|
|
|
61
61
|
|
|
62
62
|
<!-- begin: sdk-tarball-snippet (auto-generated by packages/poe-tiles-sdk/scripts/publish-tar.ts — do not edit by hand) -->
|
|
63
63
|
```json
|
|
64
|
-
"joiner-sdk": "https://misc-dev-uploads.quora-913.workers.dev/
|
|
64
|
+
"joiner-sdk": "https://misc-dev-uploads.quora-913.workers.dev/2ccea219f2bab1a49cd7f7f8bace347f4b248f916bc6db118833ae4ca0096c21"
|
|
65
65
|
```
|
|
66
66
|
<!-- end: sdk-tarball-snippet -->
|
|
67
67
|
|
|
@@ -485,8 +485,9 @@ table. It exits non-zero when the user is not an active member.
|
|
|
485
485
|
and prints CLI commands for checking access and dispatching each mutator and
|
|
486
486
|
action. Each dispatch command carries an example `--input` built from that
|
|
487
487
|
function's input schema: required fields only, with `"<fieldName>"` string
|
|
488
|
-
placeholders and numbers at
|
|
489
|
-
placeholders before running it. When the input schema can't be read,
|
|
488
|
+
placeholders and numbers at an allowed value near `0`. Replace the
|
|
489
|
+
placeholders before running it. When the input schema can't be read, no number
|
|
490
|
+
fits its bounds, the schema is too large or deeply nested to walk, or the
|
|
490
491
|
example would be too large for one shell argument (an array of more than 32
|
|
491
492
|
items, or more than 1 KiB of JSON), the command shows `--input '<json>'` and
|
|
492
493
|
its `--json` entry has no `inputExample`.
|
|
@@ -20,7 +20,7 @@ A tile cannot reach a host the creator chooses, anywhere its code runs. Direct a
|
|
|
20
20
|
|
|
21
21
|
| Need | Use |
|
|
22
22
|
| --- | --- |
|
|
23
|
-
| Talk to another tile's store | `ctx.externalStore({ storeTypeId, instanceId })` for reads and
|
|
23
|
+
| Talk to another tile's store | `ctx.externalStore({ storeTypeId, instanceId })` in actions for reads and `.action(name, input)`; `ctx.mutateExternal(...)` for writes from mutators (see [external stores](../../synced-store/references/external-stores.md)) |
|
|
24
24
|
| Read deployment settings | `env.get` |
|
|
25
25
|
| Open a web page for the user | `Poe.openExternalUrl({ url })` from client code (the user confirms any destination outside the platform) |
|
|
26
26
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Auto-generated by poe-tiles-sdk/scripts/publish-tar.ts — do not edit
|
|
2
|
-
// publishedAt: 2026-11-
|
|
2
|
+
// publishedAt: 2026-11-30T16:31:28.359Z
|
|
3
3
|
export const SDK_TARBALL_URL =
|
|
4
|
-
"https://misc-dev-uploads.quora-913.workers.dev/
|
|
4
|
+
"https://misc-dev-uploads.quora-913.workers.dev/2ccea219f2bab1a49cd7f7f8bace347f4b248f916bc6db118833ae4ca0096c21";
|
|
@@ -13,6 +13,16 @@ const NO_EXAMPLE = Symbol("no-example");
|
|
|
13
13
|
const MAX_EXAMPLE_JSON_BYTES = 1024;
|
|
14
14
|
const MAX_ITEMS = 32;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Store authors can pass raw JSON Schema through `jsonSchema()`, so a schema
|
|
18
|
+
* may repeat subtrees or nest arbitrarily deep. These cap the walk; past
|
|
19
|
+
* either, the command falls back to `'<json>'`.
|
|
20
|
+
*/
|
|
21
|
+
const MAX_VISITED_NODES = 10_000;
|
|
22
|
+
const MAX_DEPTH = 64;
|
|
23
|
+
|
|
24
|
+
type Walk = { visited: number };
|
|
25
|
+
|
|
16
26
|
/**
|
|
17
27
|
* Builds a minimal input that matches a mutator or action's JSON Schema, for
|
|
18
28
|
* the copy-paste commands `stores schema` prints. Required object properties
|
|
@@ -26,7 +36,7 @@ const MAX_ITEMS = 32;
|
|
|
26
36
|
export function exampleInputFromJsonSchema(
|
|
27
37
|
schema: unknown,
|
|
28
38
|
): JSONValue | undefined {
|
|
29
|
-
const example = withinLength(exampleFor(schema, "string"));
|
|
39
|
+
const example = withinLength(exampleFor(schema, "string", { visited: 0 }, 0));
|
|
30
40
|
return example === NO_EXAMPLE ? undefined : example;
|
|
31
41
|
}
|
|
32
42
|
|
|
@@ -43,7 +53,11 @@ function withinLength(
|
|
|
43
53
|
function exampleFor(
|
|
44
54
|
schema: unknown,
|
|
45
55
|
label: string,
|
|
56
|
+
walk: Walk,
|
|
57
|
+
depth: number,
|
|
46
58
|
): JSONValue | typeof NO_EXAMPLE {
|
|
59
|
+
walk.visited += 1;
|
|
60
|
+
if (walk.visited > MAX_VISITED_NODES || depth > MAX_DEPTH) return NO_EXAMPLE;
|
|
47
61
|
if (!isSchema(schema) || "def" in schema || "_zod" in schema) {
|
|
48
62
|
return NO_EXAMPLE;
|
|
49
63
|
}
|
|
@@ -53,8 +67,8 @@ function exampleFor(
|
|
|
53
67
|
return enumValues[0] as JSONValue;
|
|
54
68
|
}
|
|
55
69
|
const branch = firstBranch(schema);
|
|
56
|
-
if (branch !== undefined) return exampleFor(branch, label);
|
|
57
|
-
return typedExample(schema, label);
|
|
70
|
+
if (branch !== undefined) return exampleFor(branch, label, walk, depth + 1);
|
|
71
|
+
return typedExample(schema, label, walk, depth);
|
|
58
72
|
}
|
|
59
73
|
|
|
60
74
|
function firstBranch(schema: Schema): unknown {
|
|
@@ -68,6 +82,8 @@ function firstBranch(schema: Schema): unknown {
|
|
|
68
82
|
function typedExample(
|
|
69
83
|
schema: Schema,
|
|
70
84
|
label: string,
|
|
85
|
+
walk: Walk,
|
|
86
|
+
depth: number,
|
|
71
87
|
): JSONValue | typeof NO_EXAMPLE {
|
|
72
88
|
const type = Array.isArray(schema["type"])
|
|
73
89
|
? schema["type"][0]
|
|
@@ -83,16 +99,64 @@ function typedExample(
|
|
|
83
99
|
case "null":
|
|
84
100
|
return null;
|
|
85
101
|
case "array":
|
|
86
|
-
return arrayExample(schema, label);
|
|
102
|
+
return arrayExample(schema, label, walk, depth);
|
|
87
103
|
case "object":
|
|
88
|
-
return objectExample(schema);
|
|
104
|
+
return objectExample(schema, walk, depth);
|
|
89
105
|
default:
|
|
90
106
|
return NO_EXAMPLE;
|
|
91
107
|
}
|
|
92
108
|
}
|
|
93
109
|
|
|
94
|
-
/**
|
|
95
|
-
|
|
110
|
+
/**
|
|
111
|
+
* 0 moved inside `minimum` / `maximum` and their exclusive forms, else the
|
|
112
|
+
* midpoint of both bounds, each tried as is and snapped to `multipleOf`. No
|
|
113
|
+
* example when none of those satisfies every bound.
|
|
114
|
+
*/
|
|
115
|
+
function numberExample(
|
|
116
|
+
schema: Schema,
|
|
117
|
+
integer: boolean,
|
|
118
|
+
): number | typeof NO_EXAMPLE {
|
|
119
|
+
const multipleOf = numberField(schema, "multipleOf");
|
|
120
|
+
const candidates = [clampedZero(schema, integer), midpoint(schema, integer)]
|
|
121
|
+
.filter((value) => value !== undefined)
|
|
122
|
+
.flatMap((value) =>
|
|
123
|
+
multipleOf === undefined || multipleOf <= 0
|
|
124
|
+
? [value]
|
|
125
|
+
: [
|
|
126
|
+
value,
|
|
127
|
+
snap(Math.ceil(value / multipleOf), multipleOf),
|
|
128
|
+
snap(Math.floor(value / multipleOf), multipleOf),
|
|
129
|
+
snap(Math.round(value / multipleOf), multipleOf),
|
|
130
|
+
],
|
|
131
|
+
);
|
|
132
|
+
return (
|
|
133
|
+
candidates.find((value) => satisfiesNumber(schema, integer, value)) ??
|
|
134
|
+
NO_EXAMPLE
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** `steps * multipleOf`, without float noise such as 0.30000000000000004. */
|
|
139
|
+
function snap(steps: number, multipleOf: number): number {
|
|
140
|
+
const value = steps * multipleOf;
|
|
141
|
+
return Number.isInteger(value) ? value : Number(value.toPrecision(15));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Zod's own float-safe check (`floatSafeRemainder`): 0.3 / 0.1 is
|
|
146
|
+
* 2.9999999999999996, and the store accepts 0.3 as a multiple of 0.1.
|
|
147
|
+
* Integers are checked exactly, since that relative tolerance accepts any
|
|
148
|
+
* value once the step count nears 1e15.
|
|
149
|
+
*/
|
|
150
|
+
function isMultipleOf(value: number, multipleOf: number): boolean {
|
|
151
|
+
if (Number.isInteger(value) && Number.isInteger(multipleOf)) {
|
|
152
|
+
return value % multipleOf === 0;
|
|
153
|
+
}
|
|
154
|
+
const steps = value / multipleOf;
|
|
155
|
+
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(steps), 1);
|
|
156
|
+
return Math.abs(steps - Math.round(steps)) < tolerance;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function clampedZero(schema: Schema, integer: boolean): number {
|
|
96
160
|
const round = integer ? Math.ceil : (value: number) => value;
|
|
97
161
|
const roundDown = integer ? Math.floor : (value: number) => value;
|
|
98
162
|
const clamps: ReadonlyArray<
|
|
@@ -123,6 +187,52 @@ function numberExample(schema: Schema, integer: boolean): number {
|
|
|
123
187
|
}, 0);
|
|
124
188
|
}
|
|
125
189
|
|
|
190
|
+
function midpoint(schema: Schema, integer: boolean): number | undefined {
|
|
191
|
+
const lower = boundOf(schema, "minimum", "exclusiveMinimum", Math.max);
|
|
192
|
+
const upper = boundOf(schema, "maximum", "exclusiveMaximum", Math.min);
|
|
193
|
+
if (lower === undefined || upper === undefined) return undefined;
|
|
194
|
+
const middle = Number((lower + (upper - lower) / 2).toPrecision(15));
|
|
195
|
+
return integer ? Math.ceil(middle) : middle;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function boundOf(
|
|
199
|
+
schema: Schema,
|
|
200
|
+
inclusive: string,
|
|
201
|
+
exclusive: string,
|
|
202
|
+
tighter: (a: number, b: number) => number,
|
|
203
|
+
): number | undefined {
|
|
204
|
+
const bounds = [
|
|
205
|
+
numberField(schema, inclusive),
|
|
206
|
+
numberField(schema, exclusive),
|
|
207
|
+
].filter((bound) => bound !== undefined);
|
|
208
|
+
return bounds.length === 0 ? undefined : bounds.reduce(tighter);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function satisfiesNumber(
|
|
212
|
+
schema: Schema,
|
|
213
|
+
integer: boolean,
|
|
214
|
+
value: number,
|
|
215
|
+
): boolean {
|
|
216
|
+
const check = (key: string, ok: (bound: number) => boolean) => {
|
|
217
|
+
const bound = numberField(schema, key);
|
|
218
|
+
return bound === undefined || ok(bound);
|
|
219
|
+
};
|
|
220
|
+
return (
|
|
221
|
+
Number.isFinite(value) &&
|
|
222
|
+
(!integer || Number.isInteger(value)) &&
|
|
223
|
+
check("minimum", (bound) => value >= bound) &&
|
|
224
|
+
check("exclusiveMinimum", (bound) => value > bound) &&
|
|
225
|
+
check("maximum", (bound) => value <= bound) &&
|
|
226
|
+
check("exclusiveMaximum", (bound) => value < bound) &&
|
|
227
|
+
check("multipleOf", (bound) => bound > 0 && isMultipleOf(value, bound))
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function numberField(schema: Schema, key: string): number | undefined {
|
|
232
|
+
const value = schema[key];
|
|
233
|
+
return typeof value === "number" ? value : undefined;
|
|
234
|
+
}
|
|
235
|
+
|
|
126
236
|
/**
|
|
127
237
|
* One example per tuple position (`prefixItems`, or a draft-07 `items`
|
|
128
238
|
* array with `additionalItems` as the rest), then `items` examples up to `minItems`, or one when nothing else
|
|
@@ -131,9 +241,11 @@ function numberExample(schema: Schema, integer: boolean): number {
|
|
|
131
241
|
function arrayExample(
|
|
132
242
|
schema: Schema,
|
|
133
243
|
label: string,
|
|
244
|
+
walk: Walk,
|
|
245
|
+
depth: number,
|
|
134
246
|
): JSONValue | typeof NO_EXAMPLE {
|
|
135
247
|
const { prefix, rest } = arrayParts(schema);
|
|
136
|
-
const result = examplesFor(prefix, label);
|
|
248
|
+
const result = examplesFor(prefix, label, walk, depth);
|
|
137
249
|
if (result === NO_EXAMPLE) return NO_EXAMPLE;
|
|
138
250
|
const minItems =
|
|
139
251
|
typeof schema["minItems"] === "number" ? schema["minItems"] : 0;
|
|
@@ -146,7 +258,12 @@ function arrayExample(
|
|
|
146
258
|
return prefix.length === 0 && minItems === 0 ? [] : NO_EXAMPLE;
|
|
147
259
|
}
|
|
148
260
|
if (result.length + restCount > MAX_ITEMS) return NO_EXAMPLE;
|
|
149
|
-
const restExamples = examplesFor(
|
|
261
|
+
const restExamples = examplesFor(
|
|
262
|
+
Array(restCount).fill(rest),
|
|
263
|
+
label,
|
|
264
|
+
walk,
|
|
265
|
+
depth,
|
|
266
|
+
);
|
|
150
267
|
return restExamples === NO_EXAMPLE
|
|
151
268
|
? NO_EXAMPLE
|
|
152
269
|
: withinLength([...result, ...restExamples]);
|
|
@@ -166,25 +283,36 @@ function arrayParts(schema: Schema): { prefix: unknown[]; rest: unknown } {
|
|
|
166
283
|
function examplesFor(
|
|
167
284
|
schemas: readonly unknown[],
|
|
168
285
|
label: string,
|
|
286
|
+
walk: Walk,
|
|
287
|
+
depth: number,
|
|
169
288
|
): JSONValue[] | typeof NO_EXAMPLE {
|
|
170
289
|
if (schemas.length > MAX_ITEMS) return NO_EXAMPLE;
|
|
171
290
|
const result: JSONValue[] = [];
|
|
172
291
|
for (const itemSchema of schemas) {
|
|
173
|
-
const value = exampleFor(itemSchema, label);
|
|
292
|
+
const value = exampleFor(itemSchema, label, walk, depth + 1);
|
|
174
293
|
if (value === NO_EXAMPLE) return NO_EXAMPLE;
|
|
175
294
|
result.push(value);
|
|
176
295
|
}
|
|
177
296
|
return result;
|
|
178
297
|
}
|
|
179
298
|
|
|
180
|
-
function objectExample(
|
|
299
|
+
function objectExample(
|
|
300
|
+
schema: Schema,
|
|
301
|
+
walk: Walk,
|
|
302
|
+
depth: number,
|
|
303
|
+
): JSONValue | typeof NO_EXAMPLE {
|
|
181
304
|
const properties = isSchema(schema["properties"]) ? schema["properties"] : {};
|
|
182
|
-
const
|
|
183
|
-
? schema["required"]
|
|
305
|
+
const rawRequired = Array.isArray(schema["required"])
|
|
306
|
+
? schema["required"]
|
|
184
307
|
: [];
|
|
308
|
+
walk.visited += rawRequired.length;
|
|
309
|
+
if (walk.visited > MAX_VISITED_NODES) return NO_EXAMPLE;
|
|
310
|
+
const required = new Set(
|
|
311
|
+
rawRequired.filter((key) => typeof key === "string"),
|
|
312
|
+
);
|
|
185
313
|
const result: { [key: string]: JSONValue } = {};
|
|
186
314
|
for (const key of required) {
|
|
187
|
-
const value = exampleFor(properties[key], key);
|
|
315
|
+
const value = exampleFor(properties[key], key, walk, depth + 1);
|
|
188
316
|
if (value === NO_EXAMPLE) return NO_EXAMPLE;
|
|
189
317
|
result[key] = value;
|
|
190
318
|
}
|