@moku-labs/game 0.15.101 → 0.15.103

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 (36) hide show
  1. package/README.md +1 -1
  2. package/dist/app/page.d.mts +1 -1
  3. package/dist/app/page.mjs +1 -1
  4. package/dist/app/system.d.mts +3 -3
  5. package/dist/app.d.mts +3 -3
  6. package/dist/app.mjs +1 -1
  7. package/dist/assets.d.mts +1 -1
  8. package/dist/{commands-DFCBw6F2.d.mts → commands-TSyhs2-E.d.mts} +19 -10
  9. package/dist/control.d.mts +10 -6
  10. package/dist/control.mjs +2 -2
  11. package/dist/{define-6cjZwkJu.d.mts → define-DNF9A0ce.d.mts} +2 -2
  12. package/dist/{headless-WyPk3UrP.d.mts → headless-CEG1oR5D.d.mts} +1 -1
  13. package/dist/{index-Bz6p2alA.d.mts → index-DDZ9K9qO.d.mts} +24 -4
  14. package/dist/index.d.mts +5 -5
  15. package/dist/index.mjs +2 -2
  16. package/dist/inspect.d.mts +6 -6
  17. package/dist/inspect.mjs +2 -2
  18. package/dist/jsx-dev-runtime.d.mts +1 -1
  19. package/dist/jsx-runtime.d.mts +1 -1
  20. package/dist/{run-B5if0jxE.mjs → run-pCQlIaNP.mjs} +46 -3
  21. package/dist/{runtime-BDCv5mp-.d.mts → runtime-CcHPrVBm.d.mts} +1 -1
  22. package/dist/{session-D0AYRm5T.mjs → session-ClUqpGId.mjs} +138 -2
  23. package/dist/{sources-Cqqz-0-b.mjs → sources-BJyIJf_X.mjs} +1 -1
  24. package/dist/{src-DsyJR7Ds.mjs → src-DVJ0d04R.mjs} +433 -65
  25. package/dist/testing.d.mts +4 -4
  26. package/dist/testing.mjs +1 -1
  27. package/dist/{types-Co-6A6Y8.d.mts → types-BvgY7Ncf.d.mts} +23 -5
  28. package/dist/{types-Cx_-n0Ts.d.mts → types-C1B7-x7p.d.mts} +1 -1
  29. package/dist/{types-DyohsXF_.d.mts → types-C612npUH.d.mts} +2 -2
  30. package/dist/{types-Dx2qRDFg.d.mts → types-CMag4vDu.d.mts} +4 -4
  31. package/dist/{types-BzVQAaSX.d.mts → types-Ce5W0gZe.d.mts} +45 -7
  32. package/dist/{visual-D5L3ZtuQ.d.mts → visual-PsEr2KD-.d.mts} +6 -6
  33. package/dist/visual.d.mts +1 -1
  34. package/dist/visual.mjs +2 -2
  35. package/llms.txt +6 -6
  36. package/package.json +1 -1
@@ -166,7 +166,143 @@ const noInput = Object.freeze({});
166
166
  * ```
167
167
  */
168
168
  function inputOrEmpty(input) {
169
- return input ?? noInput;
169
+ return input === void 0 ? noInput : input;
170
+ }
171
+ /**
172
+ * Tells whether a value is of an input kind: a string, a finite number, a boolean, or for `json`
173
+ * anything but `undefined`. Pure.
174
+ *
175
+ * @param kind - The kind, without its `?`.
176
+ * @param value - The value, not `undefined`.
177
+ * @returns True when the value fits the kind.
178
+ * @example
179
+ * ```ts
180
+ * fitsKind("number", Number.NaN); // false
181
+ * ```
182
+ */
183
+ function fitsKind(kind, value) {
184
+ if (kind === "number") return typeof value === "number" && Number.isFinite(value);
185
+ if (kind === "json") return true;
186
+ return typeof value === kind;
187
+ }
188
+ /**
189
+ * Shows a given value in a message: a number as it prints, so `NaN` stays `NaN`, anything else as
190
+ * JSON. Pure.
191
+ *
192
+ * @param value - The value.
193
+ * @returns The value as text.
194
+ * @example
195
+ * ```ts
196
+ * shown(Number.NaN); // "NaN"
197
+ * ```
198
+ */
199
+ function shown(value) {
200
+ return typeof value === "number" ? String(value) : JSON.stringify(value) ?? String(value);
201
+ }
202
+ /**
203
+ * Names a kind in a message. Pure.
204
+ *
205
+ * @param kind - The kind.
206
+ * @returns The kind with its article.
207
+ * @example
208
+ * ```ts
209
+ * kindName("number"); // "a finite number"
210
+ * ```
211
+ */
212
+ function kindName(kind) {
213
+ return kind === "number" ? "a finite number" : `a ${kind}`;
214
+ }
215
+ /**
216
+ * Lists the fields a schema takes, for a message: `key (string), to (number)`. Pure.
217
+ *
218
+ * @param schema - The schema.
219
+ * @returns The fields with their kinds, or `nothing` for an empty schema.
220
+ * @example
221
+ * ```ts
222
+ * fieldList({ key: "string", to: "number" }); // "key (string), to (number)"
223
+ * ```
224
+ */
225
+ function fieldList(schema) {
226
+ const fields = Object.keys(schema).map((name) => `${name} (${schema[name] ?? ""})`);
227
+ return fields.length === 0 ? "nothing" : fields.join(", ");
228
+ }
229
+ /**
230
+ * Builds the error of an input that does not fit the schema of its command.
231
+ *
232
+ * @param id - The id of the command.
233
+ * @param problem - What is wrong, one clause.
234
+ * @param schema - The schema, for the fix.
235
+ * @returns The error, ready to throw.
236
+ */
237
+ function inputError(id, problem, schema) {
238
+ return /* @__PURE__ */ new TypeError(`[game] The command ${id} got ${problem}.\n It takes ${fieldList(schema)}; a field ending in ? may be left out.`);
239
+ }
240
+ /**
241
+ * Splits a declared kind into its kind and whether it is optional. Pure.
242
+ *
243
+ * @param declared - The kind as the schema writes it.
244
+ * @returns The kind without its `?`, and whether it had one.
245
+ * @example
246
+ * ```ts
247
+ * splitKind("number?"); // { kind: "number", optional: true }
248
+ * ```
249
+ */
250
+ function splitKind(declared) {
251
+ const optional = declared.endsWith("?");
252
+ return {
253
+ kind: optional ? declared.slice(0, -1) : declared,
254
+ optional
255
+ };
256
+ }
257
+ /**
258
+ * Checks one field of the schema against its given value.
259
+ *
260
+ * @param id - The id of the command, for the message.
261
+ * @param schema - The schema of the command.
262
+ * @param name - The field.
263
+ * @param value - Its given value, `undefined` when left out.
264
+ * @throws {TypeError} When a field without `?` is left out, or the value is of another kind.
265
+ */
266
+ function checkField(id, schema, name, value) {
267
+ const { kind, optional } = splitKind(schema[name] ?? "json?");
268
+ if (value === void 0 && optional) return;
269
+ if (value === void 0) throw inputError(id, `no "${name}", which it needs`, schema);
270
+ if (!fitsKind(kind, value)) throw inputError(id, `${shown(value)} for "${name}", not ${kindName(kind)}`, schema);
271
+ }
272
+ /**
273
+ * Tells whether a value is an object a call can read field by field: not `null`, not an array. Pure.
274
+ *
275
+ * @param value - The value.
276
+ * @returns True for a plain object.
277
+ * @example
278
+ * ```ts
279
+ * isPlainObject([true]); // false
280
+ * ```
281
+ */
282
+ function isPlainObject(value) {
283
+ return typeof value === "object" && value !== null && !Array.isArray(value);
284
+ }
285
+ /**
286
+ * Checks a given input against the schema of its command before the command runs: an object, no
287
+ * field the schema does not name, every field without `?` given, and every given value of its
288
+ * kind. A field with `?` may be left out or be `undefined`. A door call, never a frame path.
289
+ *
290
+ * @param id - The id of the command, for the message.
291
+ * @param schema - The schema of the command.
292
+ * @param input - The input of the call, as it came: an editor or a visual test sends plain JSON.
293
+ * @throws {TypeError} Naming the first field that does not fit, and the fields the command takes.
294
+ * @example
295
+ * ```ts
296
+ * checkInput("game.scroll", { key: "string", to: "number" }, { key: "strip", to: 318 }); // passes
297
+ * checkInput("game.scroll", { key: "string", to: "number" }, { key: "strip", dy: 10 });
298
+ * // throws '[game] The command game.scroll got the field "dy", which it does not take.\n It takes key (string), to (number); …'
299
+ * ```
300
+ */
301
+ function checkInput(id, schema, input) {
302
+ if (!isPlainObject(input)) throw inputError(id, "an input that is not an object", schema);
303
+ const given = input;
304
+ for (const name of Object.keys(given)) if (!Object.hasOwn(schema, name)) throw inputError(id, `the field "${name}", which it does not take`, schema);
305
+ for (const name of Object.keys(schema)) checkField(id, schema, name, given[name]);
170
306
  }
171
307
  //#endregion
172
308
  //#region src/plugins/input/target.ts
@@ -254,4 +390,4 @@ function recordCheat(app, id, input, frame) {
254
390
  sessions.set(app, session);
255
391
  }
256
392
  //#endregion
257
- export { readTarget as a, defineSource as c, isProjectionTarget as i, inputSchema as l, isTainted as n, inputOrEmpty as o, recordCheat as r, defineCommand as s, cheatsOf as t };
393
+ export { readTarget as a, defineCommand as c, isProjectionTarget as i, defineSource as l, isTainted as n, checkInput as o, recordCheat as r, inputOrEmpty as s, cheatsOf as t, inputSchema as u };
@@ -1,6 +1,6 @@
1
1
  import { $ as Shape, H as parentOf, K as rootPoseOf, Y as NineSlice, i as drawnRect, ot as Layer, p as Box } from "./visual-DhqD6W3v.mjs";
2
2
  import { o as notInstalled } from "./dev-BNndV-hU.mjs";
3
- import { a as readTarget, c as defineSource, l as inputSchema, n as isTainted, o as inputOrEmpty, t as cheatsOf } from "./session-D0AYRm5T.mjs";
3
+ import { a as readTarget, l as defineSource, n as isTainted, s as inputOrEmpty, t as cheatsOf, u as inputSchema } from "./session-ClUqpGId.mjs";
4
4
  //#region src/plugins/flow/doors/read.ts
5
5
  /**
6
6
  * @file flow/doors — `read` and `watch`, the `/inspect` side. Neither changes the game.