arcadible 1.0.36 → 1.0.38

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 (69) hide show
  1. package/README.md +1 -1
  2. package/dist/action/build/tool.js +57 -8
  3. package/dist/action/function/logs.js +1 -1
  4. package/dist/action/login/flow.js +8 -1
  5. package/dist/action/pack/limits.js +28 -4
  6. package/dist/action/pack/tool.js +2 -1
  7. package/dist/action/secret/tool.js +3 -5
  8. package/dist/action/serve/tool.js +28 -21
  9. package/dist/action/value/tool.js +18 -12
  10. package/dist/action/wire/tool.js +1 -1
  11. package/dist/api.js +1 -1
  12. package/dist/arc.js +6 -2
  13. package/dist/cli/argv.js +3 -1
  14. package/dist/cli/command.js +12 -2
  15. package/dist/command/function/index.js +4 -5
  16. package/dist/command/function/logs.js +8 -1
  17. package/dist/command/function/pause.js +1 -1
  18. package/dist/command/function/resume.js +1 -1
  19. package/dist/command/function/run.js +1 -1
  20. package/dist/command/function/secret/index.js +1 -1
  21. package/dist/command/function/secret/remove.js +2 -2
  22. package/dist/command/function/secret/run.js +1 -1
  23. package/dist/command/function/secret/set.js +1 -1
  24. package/dist/command/{delete.js → game/delete.js} +14 -13
  25. package/dist/command/game/index.js +12 -0
  26. package/dist/command/login.js +1 -2
  27. package/dist/command/serve.js +9 -3
  28. package/dist/command/server/index.js +3 -4
  29. package/dist/command/server/key/create.js +1 -1
  30. package/dist/command/server/key/index.js +1 -1
  31. package/dist/command/server/key/revoke.js +1 -1
  32. package/dist/command/server/key/run.js +1 -1
  33. package/dist/command/unstable/index.js +23 -0
  34. package/dist/command/value/get.js +1 -1
  35. package/dist/command/value/index.js +6 -6
  36. package/dist/command/value/list.js +1 -1
  37. package/dist/command/value/remove.js +2 -2
  38. package/dist/command/value/set.js +1 -1
  39. package/dist/command/value/usage.js +5 -16
  40. package/dist/command/wire/index.js +4 -5
  41. package/dist/commands.js +3 -29
  42. package/dist/config/code.js +7 -3
  43. package/dist/config/limit.js +13 -0
  44. package/dist/phrase/deploy.js +1 -1
  45. package/dist/phrase/function.js +7 -7
  46. package/dist/phrase/game.js +1 -1
  47. package/dist/phrase/index.js +1 -0
  48. package/dist/phrase/pack.js +17 -0
  49. package/dist/phrase/serve.js +8 -3
  50. package/dist/phrase/server.js +5 -5
  51. package/dist/phrase/unstable.js +6 -0
  52. package/dist/phrase/value.js +30 -5
  53. package/dist/runner/bundle.js +13 -4
  54. package/dist/runner/entry.js +113 -17
  55. package/dist/runner/outbound.js +21 -5
  56. package/dist/schema/check/workflow.js +0 -21
  57. package/dist/schema/game.js +0 -32
  58. package/dist/schema/message.js +2 -3
  59. package/dist/schema/runner.js +8 -6
  60. package/dist/schema/workflow.js +6 -28
  61. package/dist/serve/page.js +1 -1
  62. package/dist/serve/remote.js +14 -6
  63. package/dist/serve/runner.js +89 -6
  64. package/dist/serve/server.js +8 -6
  65. package/dist/util/term.js +8 -0
  66. package/dist/util/zip.js +5 -0
  67. package/dist/wires/room.js +3 -3
  68. package/npm-shrinkwrap.json +33 -33
  69. package/package.json +1 -1
@@ -6,18 +6,27 @@
6
6
  // read only when a project has a [function] table.
7
7
  // [import]
8
8
  import cp, {} from "node:child_process";
9
+ import fs from "node:fs";
9
10
  import { copyFile, mkdir, mkdtemp, readFile, rm, writeFile, } from "node:fs/promises";
10
11
  import http from "node:http";
11
12
  import net from "node:net";
12
13
  import os from "node:os";
13
- import { join } from "node:path";
14
+ import { dirname, join } from "node:path";
14
15
  // [import]
15
16
  import { bundle } from "../runner/bundle.js";
16
17
  import { ENTRY, ENTRY_MODULE, FUNCTION_MODULE } from "../runner/entry.js";
17
18
  // [declare]
18
19
  // where a runner answers on the game's origin, as on Arcadible, where the
19
- // folder is Arcadible's own on every build's site.
20
- export const PREFIX = "/arcadible/runner";
20
+ // folder is Arcadible's own on every build's site: the path itself, and
21
+ // anything under it.
22
+ export const PREFIX = "/arcadible/function";
23
+ // the function's own path for a request under PREFIX, as the dispatcher
24
+ // passes it on: `/arcadible/function/move` is `/move`, and the path itself
25
+ // is `/`, its query kept.
26
+ export function innerPath(url) {
27
+ const rest = url.slice(PREFIX.length);
28
+ return rest.startsWith("/") ? rest : `/${rest}`;
29
+ }
21
30
  // the header a runner reads who's asking from (the Server SDK's
22
31
  // players.primary): the player's id, or empty for a guest. Whatever a request
23
32
  // brings by that name is dropped.
@@ -268,8 +277,66 @@ async function bodyOf(req) {
268
277
  }
269
278
  return Buffer.concat(parts);
270
279
  }
280
+ // [declare]
281
+ // how long the code's files must stop changing before it's run again, as
282
+ // deploy_dir's reload waits (./reload.ts).
283
+ const SETTLE = 100;
271
284
  // [function]
272
- // a game's runner, running. `main` is its code's path, `dir` where the
285
+ // watches the files a function's bundle was made from, wherever they are
286
+ // (`main`'s folder and beyond: a game's rules its function imports), and
287
+ // calls `onChange` once they've stopped changing. `files(paths)` sets what's
288
+ // watched, after each bundle; until the first, `main` alone. Each folder
289
+ // holding one is watched, not recursively, and only its own files count.
290
+ export function watchInputs(main, onChange) {
291
+ let inputs = new Set([main]);
292
+ let timer;
293
+ const watchers = new Map();
294
+ const sync = function () {
295
+ const dirs = new Set([...inputs].map((path) => dirname(path)));
296
+ for (const [dir, watcher] of watchers) {
297
+ if (!dirs.has(dir)) {
298
+ watcher.close();
299
+ watchers.delete(dir);
300
+ }
301
+ }
302
+ for (const dir of dirs) {
303
+ if (watchers.has(dir))
304
+ continue;
305
+ try {
306
+ const watcher = fs.watch(dir, (_event, name) => {
307
+ if (name !== null && !inputs.has(join(dir, name)))
308
+ return;
309
+ clearTimeout(timer);
310
+ timer = setTimeout(onChange, SETTLE);
311
+ });
312
+ // a folder removed while it's watched: stop watching it
313
+ watcher.on("error", () => {
314
+ watcher.close();
315
+ watchers.delete(dir);
316
+ });
317
+ watchers.set(dir, watcher);
318
+ }
319
+ catch {
320
+ // a folder that isn't there (yet) isn't watched
321
+ }
322
+ }
323
+ };
324
+ sync();
325
+ return {
326
+ close() {
327
+ clearTimeout(timer);
328
+ for (const watcher of watchers.values())
329
+ watcher.close();
330
+ watchers.clear();
331
+ },
332
+ files(paths) {
333
+ inputs = new Set([main, ...paths]);
334
+ sync();
335
+ },
336
+ };
337
+ }
338
+ // [function]
339
+ // a game's function, running. `main` is its code's path, `dir` where the
273
340
  // runtime is kept, `origin` the game's own origin (a ticket for the runner
274
341
  // is for it), `serve` arc serve's page (where Arcadible is, here), `hosts`
275
342
  // the hosts its manifest declares, the only ones it may call, `secrets` the
@@ -282,6 +349,12 @@ export async function runner({ dir, handler, hosts = [], main, origin, secrets =
282
349
  let child = null;
283
350
  let port = null;
284
351
  let failed = null;
352
+ // what the bundle was made from, watched: a change to any of it runs the
353
+ // new code, set after each bundle that builds (one that doesn't keeps
354
+ // what was watched, so fixing it runs it)
355
+ const watched = watchInputs(main, () => {
356
+ void start();
357
+ });
285
358
  const stop = function () {
286
359
  if (child) {
287
360
  child.kill();
@@ -296,7 +369,13 @@ export async function runner({ dir, handler, hosts = [], main, origin, secrets =
296
369
  const began = Date.now();
297
370
  // the developer's code, and Arcadible's entry beside it, where the
298
371
  // script starts, as the pipeline uploads a build's
299
- await bundle({ main, outfile: join(work, FUNCTION_MODULE) });
372
+ await bundle({
373
+ main,
374
+ onInputs: (paths) => {
375
+ watched.files(paths);
376
+ },
377
+ outfile: join(work, FUNCTION_MODULE),
378
+ });
300
379
  await writeFile(join(work, ENTRY_MODULE), ENTRY);
301
380
  const free = await freePort();
302
381
  port = free;
@@ -372,6 +451,9 @@ export async function runner({ dir, handler, hosts = [], main, origin, secrets =
372
451
  ...Object.fromEntries(Object.entries(req.headers).filter(([name]) => !dropped.includes(name))),
373
452
  [PLAYER]: typeof player === "string" ? player : "",
374
453
  [GUEST]: typeof guest === "string" ? guest : "",
454
+ // the game's origin, as on Arcadible, where the code's request.url is
455
+ // its site's: never the runtime's own port
456
+ host: new URL(origin).host,
375
457
  };
376
458
  if (body !== true) {
377
459
  delete headers["transfer-encoding"];
@@ -382,7 +464,7 @@ export async function runner({ dir, handler, hosts = [], main, origin, secrets =
382
464
  headers,
383
465
  host: "127.0.0.1",
384
466
  method: req.method,
385
- path: (req.url ?? "").slice(PREFIX.length) || "/",
467
+ path: innerPath(req.url ?? ""),
386
468
  port,
387
469
  }, (answer) => {
388
470
  res.writeHead(answer.statusCode ?? 502, { ...answer.headers, ...CORS });
@@ -397,6 +479,7 @@ export async function runner({ dir, handler, hosts = [], main, origin, secrets =
397
479
  await start();
398
480
  return {
399
481
  close() {
482
+ watched.close();
400
483
  stop();
401
484
  rm(work, { force: true, recursive: true }).catch(() => null);
402
485
  },
@@ -15,7 +15,7 @@ import { PREFIX as WIRES, wires as wiresFor } from "./wires.js";
15
15
  // [declare]
16
16
  // the hostnames a browser may use for the page, on IPv4 and IPv6. `localhost`
17
17
  // is IPv6's ::1 on some systems, so both are listened on.
18
- const LOOPBACK = ["127.0.0.1", "::1"];
18
+ export const LOOPBACK = ["127.0.0.1", "::1"];
19
19
  // [function]
20
20
  // listens on `port` at `address`, resolving with the server, or rejecting with
21
21
  // the listen error, such as EADDRINUSE.
@@ -64,7 +64,7 @@ export async function serve({ art, files, hostFile = null, icon, info, keyFile,
64
64
  if (tickets) {
65
65
  tickets.remember(player);
66
66
  }
67
- // the game's runner, when the project has one: on the game's own origin,
67
+ // the game's function, when the project has one: on the game's own origin,
68
68
  // behind a ticket check, as on Arcadible
69
69
  const runner = runs && tickets
70
70
  ? await startRunner({
@@ -120,12 +120,14 @@ export async function serve({ art, files, hostFile = null, icon, info, keyFile,
120
120
  const host = req.headers.host;
121
121
  const onGame = host === `127.0.0.1:${port}`;
122
122
  const pathname = pathOf(req);
123
- // what's under the runner's folder, as Arcadible's edge sends it on:
124
- // /arcadible/runner itself, like /arcadible/runnerx, is a file of
125
- // Arcadible's, like any other there, and isn't found.
123
+ // the function's path, and what's under it, as Arcadible's edge sends
124
+ // them on: /arcadible/functionx is a file of Arcadible's, like any
125
+ // other there, and isn't found.
126
126
  // A project with no function is answered as Arcadible answers a build
127
127
  // with none.
128
- const forRunner = onGame && pathname !== null && pathname.startsWith(`${RUNNER}/`)
128
+ const forRunner = onGame &&
129
+ pathname !== null &&
130
+ (pathname === RUNNER || pathname.startsWith(`${RUNNER}/`))
129
131
  ? (runner?.handle ?? noFunction)
130
132
  : null;
131
133
  // a game opens a wire at Arcadible's path on its own origin, whether
package/dist/util/term.js CHANGED
@@ -19,3 +19,11 @@ export function configureColor() {
19
19
  chalkStderr.level = 0;
20
20
  }
21
21
  }
22
+ // [function]
23
+ // a Ctrl+C in a terminal leaves `^C` with the cursor after it, so whatever
24
+ // comes next, the shell's prompt included, starts on a new line.
25
+ export function interrupted() {
26
+ if (interactive()) {
27
+ process.stderr.write("\n");
28
+ }
29
+ }
package/dist/util/zip.js CHANGED
@@ -51,6 +51,11 @@ export class Zip {
51
51
  }));
52
52
  }
53
53
  // [method]
54
+ // every entry in the zip, files and folders.
55
+ count() {
56
+ return this.zip.getEntries().length;
57
+ }
58
+ // [method]
54
59
  has(name) {
55
60
  return this.zip.getEntry(join(this.prefix, name)) !== null;
56
61
  }
@@ -157,10 +157,10 @@ export function createRoom(options) {
157
157
  left(member) {
158
158
  // their last connection: the rest hear they went
159
159
  const still = options.list().some((each) => each.member.id === member.id);
160
- if (!still) {
161
- sends.delete(member.id);
160
+ // their rate is kept, so leaving and coming back never starts it full
161
+ // (servers:21a)
162
+ if (!still)
162
163
  all({ leave: member });
163
- }
164
164
  },
165
165
  said(key, text) {
166
166
  const mine = options.list().find((each) => each.key === key);
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "license": "Apache-2.0",
46
46
  "name": "arcadible",
47
- "version": "1.0.36"
47
+ "version": "1.0.38"
48
48
  },
49
49
  "node_modules/@asamuzakjp/css-color": {
50
50
  "dependencies": {
@@ -884,20 +884,6 @@
884
884
  "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-10.3.2.tgz",
885
885
  "version": "10.3.2"
886
886
  },
887
- "node_modules/@inquirer/core/node_modules/wrap-ansi": {
888
- "dependencies": {
889
- "ansi-styles": "^4.0.0",
890
- "string-width": "^4.1.0",
891
- "strip-ansi": "^6.0.0"
892
- },
893
- "engines": {
894
- "node": ">=8"
895
- },
896
- "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
897
- "license": "MIT",
898
- "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
899
- "version": "6.2.0"
900
- },
901
887
  "node_modules/@inquirer/editor": {
902
888
  "dependencies": {
903
889
  "@inquirer/core": "^10.3.2",
@@ -1247,10 +1233,10 @@
1247
1233
  "engines": {
1248
1234
  "node": ">= 4"
1249
1235
  },
1250
- "integrity": "sha512-wCBiZ77u1tuWde6G/nfOtLaCTYcFDU5yCzARzK10y+rLhzYoL7a7yEemcopcc2Mzow7gZOIjnV2ym1NYmdiJOQ==",
1236
+ "integrity": "sha512-52N+Y4HRMOJmbLmr+DqO4iSRyyB7N52gm7PWCT6h0p978+oKbqHCB7gIJIwZvBUsjlSdWbrBFqUSmIFNZMpn0A==",
1251
1237
  "license": "MIT",
1252
- "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.14.tgz",
1253
- "version": "7.0.14"
1238
+ "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.16.tgz",
1239
+ "version": "7.0.16"
1254
1240
  },
1255
1241
  "node_modules/@typescript-eslint/parser": {
1256
1242
  "dependencies": {
@@ -1645,6 +1631,23 @@
1645
1631
  "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
1646
1632
  "version": "8.0.1"
1647
1633
  },
1634
+ "node_modules/cliui/node_modules/wrap-ansi": {
1635
+ "dependencies": {
1636
+ "ansi-styles": "^4.0.0",
1637
+ "string-width": "^4.1.0",
1638
+ "strip-ansi": "^6.0.0"
1639
+ },
1640
+ "engines": {
1641
+ "node": ">=10"
1642
+ },
1643
+ "funding": {
1644
+ "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
1645
+ },
1646
+ "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
1647
+ "license": "MIT",
1648
+ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
1649
+ "version": "7.0.0"
1650
+ },
1648
1651
  "node_modules/color-convert": {
1649
1652
  "dependencies": {
1650
1653
  "color-name": "~1.1.4"
@@ -2158,10 +2161,10 @@
2158
2161
  "version": "6.0.2"
2159
2162
  },
2160
2163
  "node_modules/graceful-fs": {
2161
- "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
2162
- "license": "ISC",
2163
- "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
2164
- "version": "4.2.11"
2164
+ "integrity": "sha512-iuyGF2E4oafQfPsRrG2wtY2ILupMhvtdrhzrxB+0VcjsPpSPttpfYdjnGFGsTi5MaJFjI1jOKHPQ6UTbTj9TAw==",
2165
+ "license": "BlueOak-1.0.0",
2166
+ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.12.tgz",
2167
+ "version": "4.2.12"
2165
2168
  },
2166
2169
  "node_modules/hashery": {
2167
2170
  "dependencies": {
@@ -2540,10 +2543,10 @@
2540
2543
  "funding": {
2541
2544
  "url": "https://github.com/sponsors/isaacs"
2542
2545
  },
2543
- "integrity": "sha512-nFQuYSTVrGvysVBps5Ih+0BdnYFN/Cj3C816r6+p7yK+FHrVLGE4O4N9AFwykrlNlvM2HYt+Rad1Uiro6h88Ig==",
2546
+ "integrity": "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q==",
2544
2547
  "license": "BlueOak-1.0.0",
2545
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.8.tgz",
2546
- "version": "11.0.8"
2548
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.9.tgz",
2549
+ "version": "11.0.9"
2547
2550
  },
2548
2551
  "node_modules/mp4box": {
2549
2552
  "engines": {
@@ -3134,15 +3137,12 @@
3134
3137
  "strip-ansi": "^6.0.0"
3135
3138
  },
3136
3139
  "engines": {
3137
- "node": ">=10"
3138
- },
3139
- "funding": {
3140
- "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
3140
+ "node": ">=8"
3141
3141
  },
3142
- "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
3142
+ "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
3143
3143
  "license": "MIT",
3144
- "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
3145
- "version": "7.0.0"
3144
+ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
3145
+ "version": "6.2.0"
3146
3146
  },
3147
3147
  "node_modules/ws": {
3148
3148
  "engines": {
@@ -3267,5 +3267,5 @@
3267
3267
  }
3268
3268
  },
3269
3269
  "requires": true,
3270
- "version": "1.0.36"
3270
+ "version": "1.0.38"
3271
3271
  }
package/package.json CHANGED
@@ -68,5 +68,5 @@
68
68
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
69
69
  },
70
70
  "type": "module",
71
- "version": "1.0.36"
71
+ "version": "1.0.38"
72
72
  }