arcadible 1.0.23 → 1.0.25

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 (320) hide show
  1. package/README.md +1 -0
  2. package/bin/arc.js +1 -85
  3. package/dist/account.js +197 -0
  4. package/dist/action/build/tool.js +61 -0
  5. package/dist/action/delete/tool.js +47 -0
  6. package/dist/action/deploy/rebuilt.js +25 -0
  7. package/dist/action/deploy/result.js +36 -0
  8. package/dist/action/deploy/timeout.js +18 -0
  9. package/dist/action/deploy/tool-git.js +49 -0
  10. package/dist/action/deploy/tool.js +49 -0
  11. package/dist/action/deploy/wait.js +104 -0
  12. package/dist/action/function/tool.js +127 -0
  13. package/dist/action/game.js +62 -0
  14. package/dist/action/init/manifest.js +64 -0
  15. package/dist/action/init/tool-patch.js +15 -0
  16. package/dist/action/init/tool.js +64 -0
  17. package/dist/action/inspect/tool.js +13 -0
  18. package/dist/action/key/tool.js +88 -0
  19. package/dist/action/login/flow.js +69 -0
  20. package/dist/action/login/tool.js +8 -0
  21. package/dist/action/logout/tool.js +8 -0
  22. package/dist/action/open/tool.js +30 -0
  23. package/dist/action/pack/limits.js +46 -0
  24. package/dist/action/pack/tool.js +148 -0
  25. package/dist/action/pack/unsound.js +51 -0
  26. package/dist/action/play/tool.js +84 -0
  27. package/dist/action/predeploy/ac.js +75 -0
  28. package/dist/action/predeploy/game.js +6 -0
  29. package/dist/action/predeploy/git.js +151 -0
  30. package/dist/action/predeploy/pm.js +20 -0
  31. package/dist/action/predeploy/published.js +54 -0
  32. package/dist/action/predeploy/secrets.js +35 -0
  33. package/dist/action/predeploy/tool-git.js +103 -0
  34. package/dist/action/predeploy/tool.js +14 -0
  35. package/dist/action/secret/tool.js +91 -0
  36. package/dist/action/serve/tool.js +270 -0
  37. package/dist/action/validate/checked.js +28 -0
  38. package/dist/action/validate/tool.js +56 -0
  39. package/dist/action/validate/unknown.js +58 -0
  40. package/dist/action/validate/unsound.js +99 -0
  41. package/dist/action/value/tool.js +216 -0
  42. package/dist/action/whoami/tool.js +7 -0
  43. package/dist/api.js +312 -0
  44. package/dist/arc.js +41 -0
  45. package/dist/cli/argv.js +61 -0
  46. package/dist/cli/channel.js +29 -0
  47. package/dist/cli/command.js +163 -0
  48. package/dist/cli/confirm.js +39 -0
  49. package/dist/cli/options.js +62 -0
  50. package/dist/cli/rc.js +103 -0
  51. package/dist/cli/yargs.js +40 -0
  52. package/dist/command/build.js +68 -0
  53. package/dist/command/delete.js +66 -0
  54. package/dist/command/deploy.js +308 -0
  55. package/dist/command/function/index.js +17 -0
  56. package/dist/command/function/pause.js +18 -0
  57. package/dist/command/function/resume.js +18 -0
  58. package/dist/command/function/run.js +41 -0
  59. package/dist/command/function/secret/index.js +15 -0
  60. package/dist/command/function/secret/list.js +27 -0
  61. package/dist/command/function/secret/name.js +8 -0
  62. package/dist/command/function/secret/remove.js +26 -0
  63. package/dist/command/function/secret/run.js +52 -0
  64. package/dist/command/function/secret/set.js +48 -0
  65. package/dist/command/function/status.js +40 -0
  66. package/dist/command/init.js +128 -0
  67. package/dist/command/inspect.js +39 -0
  68. package/dist/command/login.js +108 -0
  69. package/dist/command/logout.js +24 -0
  70. package/dist/command/open.js +49 -0
  71. package/dist/command/pack.js +90 -0
  72. package/dist/command/play.js +81 -0
  73. package/dist/command/serve.js +177 -0
  74. package/dist/command/server/index.js +17 -0
  75. package/dist/command/server/key/create.js +36 -0
  76. package/dist/command/server/key/index.js +15 -0
  77. package/dist/command/server/key/list.js +34 -0
  78. package/dist/command/server/key/revoke.js +24 -0
  79. package/dist/command/server/key/run.js +54 -0
  80. package/dist/command/validate.js +47 -0
  81. package/dist/command/value/get.js +21 -0
  82. package/dist/command/value/index.js +19 -0
  83. package/dist/command/value/key.js +8 -0
  84. package/dist/command/value/list.js +41 -0
  85. package/dist/command/value/remove.js +26 -0
  86. package/dist/command/value/set.js +62 -0
  87. package/dist/command/value/usage.js +69 -0
  88. package/dist/command/whoami.js +55 -0
  89. package/dist/commands.js +100 -0
  90. package/dist/config/ai.js +2 -0
  91. package/dist/config/art.js +13 -0
  92. package/dist/config/audience.js +2 -0
  93. package/dist/config/code.js +129 -0
  94. package/dist/config/file.js +13 -0
  95. package/dist/config/genre.js +19 -0
  96. package/{src → dist}/config/html.js +2 -7
  97. package/dist/config/image.js +5 -0
  98. package/dist/config/input.js +11 -0
  99. package/dist/config/json.js +23 -0
  100. package/dist/config/limit.js +14 -0
  101. package/dist/config/orientation.js +11 -0
  102. package/dist/config/package.js +8 -0
  103. package/dist/config/product.js +14 -0
  104. package/dist/config/template.js +37 -0
  105. package/dist/config/uri.js +18 -0
  106. package/dist/config/url.js +11 -0
  107. package/dist/config/video.js +5 -0
  108. package/dist/config/visibility.js +2 -0
  109. package/dist/config/workflow.js +7 -0
  110. package/dist/parser/env.js +61 -0
  111. package/dist/parser/given.js +8 -0
  112. package/dist/parser/manifest.js +45 -0
  113. package/dist/parser/media.js +57 -0
  114. package/dist/parser/project.js +129 -0
  115. package/dist/parser/readme-file.js +44 -0
  116. package/dist/parser/readme.js +70 -0
  117. package/dist/parser/sections.js +92 -0
  118. package/dist/parser/self.js +16 -0
  119. package/dist/phrase/account.js +35 -0
  120. package/dist/phrase/common.js +139 -0
  121. package/dist/phrase/deploy.js +192 -0
  122. package/dist/phrase/function.js +139 -0
  123. package/dist/phrase/game.js +27 -0
  124. package/dist/phrase/index.js +16 -0
  125. package/dist/phrase/init.js +53 -0
  126. package/dist/phrase/internal.js +61 -0
  127. package/dist/phrase/manifest.js +120 -0
  128. package/dist/phrase/media.js +90 -0
  129. package/dist/phrase/pack.js +69 -0
  130. package/dist/phrase/serve.js +84 -0
  131. package/dist/phrase/server.js +38 -0
  132. package/dist/phrase/value.js +55 -0
  133. package/dist/runner/bundle.js +45 -0
  134. package/dist/runner/entry.js +57 -0
  135. package/dist/runner/outbound.js +69 -0
  136. package/dist/schema/check/game.js +29 -0
  137. package/dist/schema/check/workflow.js +57 -0
  138. package/dist/schema/game.js +462 -0
  139. package/dist/schema/message.js +61 -0
  140. package/dist/schema/readme.js +27 -0
  141. package/dist/schema/runner.js +43 -0
  142. package/dist/schema/server.js +91 -0
  143. package/dist/schema/workflow.js +99 -0
  144. package/dist/serve/files.js +39 -0
  145. package/dist/serve/game.js +172 -0
  146. package/dist/serve/page.js +689 -0
  147. package/dist/serve/reload.js +55 -0
  148. package/dist/serve/remote.js +114 -0
  149. package/dist/serve/runner.js +303 -0
  150. package/dist/serve/server.js +169 -0
  151. package/dist/serve/ticket.js +232 -0
  152. package/dist/serve/values.js +317 -0
  153. package/dist/util/bytes.js +16 -0
  154. package/dist/util/chars.js +19 -0
  155. package/dist/util/command.js +11 -0
  156. package/dist/util/delay.js +36 -0
  157. package/dist/util/doc.js +59 -0
  158. package/dist/util/error.js +35 -0
  159. package/dist/util/http.js +13 -0
  160. package/dist/util/image.js +64 -0
  161. package/dist/util/links.js +45 -0
  162. package/dist/util/lockfile.js +17 -0
  163. package/dist/util/log.js +101 -0
  164. package/dist/util/md.js +37 -0
  165. package/dist/util/media.js +27 -0
  166. package/dist/util/objs.js +46 -0
  167. package/dist/util/os.js +13 -0
  168. package/dist/util/output.js +133 -0
  169. package/dist/util/paths.js +8 -0
  170. package/dist/util/progress.js +57 -0
  171. package/dist/util/promise.js +18 -0
  172. package/dist/util/request.js +103 -0
  173. package/dist/util/s3.js +67 -0
  174. package/dist/util/schema.js +151 -0
  175. package/dist/util/screenshot.js +24 -0
  176. package/dist/util/shape.js +49 -0
  177. package/dist/util/shell.js +64 -0
  178. package/dist/util/size.js +32 -0
  179. package/dist/util/spinner.js +35 -0
  180. package/dist/util/strs.js +46 -0
  181. package/dist/util/table.js +18 -0
  182. package/dist/util/term.js +21 -0
  183. package/dist/util/time.js +16 -0
  184. package/dist/util/toml.js +28 -0
  185. package/{src → dist}/util/uris.js +8 -14
  186. package/dist/util/video.js +113 -0
  187. package/dist/util/zip.js +62 -0
  188. package/npm-shrinkwrap.json +3256 -0
  189. package/package.json +41 -39
  190. package/bin/arc-build.js +0 -139
  191. package/bin/arc-default.js +0 -65
  192. package/bin/arc-deploy.js +0 -456
  193. package/bin/arc-init.js +0 -187
  194. package/bin/arc-inspect.js +0 -97
  195. package/bin/arc-login.js +0 -165
  196. package/bin/arc-logout.js +0 -75
  197. package/bin/arc-open.js +0 -104
  198. package/bin/arc-pack.js +0 -146
  199. package/bin/arc-play.js +0 -140
  200. package/bin/arc-serve.js +0 -214
  201. package/bin/arc-validate.js +0 -112
  202. package/bin/arc-whoami.js +0 -119
  203. package/src/account.js +0 -249
  204. package/src/action/build/tool.js +0 -80
  205. package/src/action/deploy/tool-git.js +0 -90
  206. package/src/action/deploy/tool.js +0 -88
  207. package/src/action/deploy/wait.js +0 -151
  208. package/src/action/init/manifest.js +0 -83
  209. package/src/action/init/tool-patch.js +0 -32
  210. package/src/action/init/tool.js +0 -97
  211. package/src/action/inspect/tool.js +0 -26
  212. package/src/action/login/flow.js +0 -101
  213. package/src/action/login/tool.js +0 -16
  214. package/src/action/logout/tool.js +0 -15
  215. package/src/action/open/tool.js +0 -38
  216. package/src/action/pack/limits.js +0 -51
  217. package/src/action/pack/tool.js +0 -171
  218. package/src/action/pack/unsound.js +0 -69
  219. package/src/action/play/tool.js +0 -109
  220. package/src/action/predeploy/ac.js +0 -112
  221. package/src/action/predeploy/git.js +0 -223
  222. package/src/action/predeploy/pm.js +0 -37
  223. package/src/action/predeploy/published.js +0 -82
  224. package/src/action/predeploy/tool-git.js +0 -154
  225. package/src/action/predeploy/tool.js +0 -29
  226. package/src/action/serve/tool.js +0 -209
  227. package/src/action/validate/checked.js +0 -37
  228. package/src/action/validate/tool.js +0 -67
  229. package/src/action/validate/unknown.js +0 -86
  230. package/src/action/validate/unsound.js +0 -138
  231. package/src/action/whoami/tool.js +0 -15
  232. package/src/api.js +0 -163
  233. package/src/cli/build.js +0 -15
  234. package/src/cli/deploy.js +0 -21
  235. package/src/cli/init.js +0 -17
  236. package/src/cli/inspect.js +0 -15
  237. package/src/cli/login.js +0 -15
  238. package/src/cli/logout.js +0 -15
  239. package/src/cli/open.js +0 -15
  240. package/src/cli/pack.js +0 -15
  241. package/src/cli/play.js +0 -15
  242. package/src/cli/predeploy.js +0 -21
  243. package/src/cli/serve.js +0 -15
  244. package/src/cli/validate.js +0 -15
  245. package/src/cli/whoami.js +0 -15
  246. package/src/config/ai.js +0 -5
  247. package/src/config/art.js +0 -16
  248. package/src/config/audience.js +0 -5
  249. package/src/config/code.js +0 -142
  250. package/src/config/file.js +0 -23
  251. package/src/config/genre.js +0 -22
  252. package/src/config/image.js +0 -7
  253. package/src/config/input.js +0 -14
  254. package/src/config/limit.js +0 -21
  255. package/src/config/orientation.js +0 -14
  256. package/src/config/package.js +0 -5
  257. package/src/config/product.js +0 -5
  258. package/src/config/template.js +0 -45
  259. package/src/config/uri.js +0 -27
  260. package/src/config/url.js +0 -20
  261. package/src/config/video.js +0 -7
  262. package/src/config/visibility.js +0 -5
  263. package/src/config/workflow.js +0 -18
  264. package/src/parser/env.js +0 -84
  265. package/src/parser/given.js +0 -17
  266. package/src/parser/manifest.js +0 -80
  267. package/src/parser/media.js +0 -90
  268. package/src/parser/project.js +0 -166
  269. package/src/parser/readme-file.js +0 -76
  270. package/src/parser/readme.js +0 -96
  271. package/src/parser/sections.js +0 -107
  272. package/src/parser/self.js +0 -27
  273. package/src/phrase.js +0 -1294
  274. package/src/schema/check/game.js +0 -61
  275. package/src/schema/check/workflow.js +0 -99
  276. package/src/schema/game.js +0 -649
  277. package/src/schema/message.js +0 -85
  278. package/src/schema/readme.js +0 -44
  279. package/src/schema/workflow.js +0 -150
  280. package/src/serve/files.js +0 -61
  281. package/src/serve/game.js +0 -191
  282. package/src/serve/page.js +0 -345
  283. package/src/serve/reload.js +0 -68
  284. package/src/serve/remote.js +0 -121
  285. package/src/serve/server.js +0 -128
  286. package/src/util/argv.js +0 -116
  287. package/src/util/bytes.js +0 -25
  288. package/src/util/chars.js +0 -30
  289. package/src/util/command.js +0 -18
  290. package/src/util/delay.js +0 -52
  291. package/src/util/doc.js +0 -72
  292. package/src/util/error.js +0 -50
  293. package/src/util/http.js +0 -25
  294. package/src/util/image.js +0 -93
  295. package/src/util/links.js +0 -78
  296. package/src/util/lockfile.js +0 -35
  297. package/src/util/log.js +0 -149
  298. package/src/util/md.js +0 -61
  299. package/src/util/media.js +0 -40
  300. package/src/util/objs.js +0 -45
  301. package/src/util/os.js +0 -27
  302. package/src/util/output.js +0 -174
  303. package/src/util/paths.js +0 -21
  304. package/src/util/progress.js +0 -85
  305. package/src/util/promise.js +0 -29
  306. package/src/util/rc.js +0 -144
  307. package/src/util/request.js +0 -89
  308. package/src/util/s3.js +0 -92
  309. package/src/util/schema.js +0 -189
  310. package/src/util/screenshot.js +0 -37
  311. package/src/util/shell.js +0 -84
  312. package/src/util/size.js +0 -53
  313. package/src/util/spinner.js +0 -52
  314. package/src/util/strs.js +0 -73
  315. package/src/util/term.js +0 -28
  316. package/src/util/time.js +0 -29
  317. package/src/util/toml.js +0 -14
  318. package/src/util/video.js +0 -157
  319. package/src/util/zip.js +0 -88
  320. /package/{src/serve → assets}/favicon.ico +0 -0
package/src/util/rc.js DELETED
@@ -1,144 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const fs = require("node:fs");
6
- const os = require("node:os");
7
- const path = require("node:path");
8
-
9
- // [import]
10
-
11
- const ini = require("ini");
12
-
13
- // [import]
14
-
15
- const args = require("./argv");
16
- const cfgcode = require("../config/code");
17
- const error = require("./error");
18
- const output = require("./output");
19
- const phrase = require("../phrase");
20
-
21
- // [use]
22
-
23
- const abort = output.abort;
24
- const ArcError = error.ArcError;
25
- const cwd = args.cwd;
26
- const dirname = path.dirname;
27
- const existsSync = fs.existsSync; // eslint-disable-line no-sync
28
- const homedir = os.homedir;
29
- const join = path.join;
30
- const readFileSync = fs.readFileSync; // eslint-disable-line no-sync
31
- const resolve = path.resolve;
32
-
33
- // [function]
34
-
35
- // the project's rc file: .<cmd>rc in the directory -C or --cwd names.
36
- const config = function (cmd, argv) {
37
- return join(resolve(process.cwd(), cwd(argv.slice(2))), `.${cmd}rc`);
38
- };
39
-
40
- // [function]
41
-
42
- // the nearest .<cmd>rc in the working directory or above it. Options are read
43
- // when a command loads, so the files are read synchronously.
44
- const nearest = function (cmd) {
45
- let dir = process.cwd();
46
- for (;;) {
47
- const file = join(dir, `.${cmd}rc`);
48
- if (existsSync(file)) {
49
- return file;
50
- }
51
- if (dirname(dir) === dir) {
52
- return null;
53
- }
54
- dir = dirname(dir);
55
- }
56
- };
57
-
58
- // [function]
59
-
60
- // the files `rc` reads, the lowest precedence first: system, then home, then
61
- // the nearest one, then the project's.
62
- const files = function (cmd, argv) {
63
- const home = homedir();
64
- return [
65
- ...(process.platform === "win32"
66
- ? []
67
- : [join("/etc", cmd, "config"), join("/etc", `${cmd}rc`)]),
68
- join(home, ".config", cmd, "config"),
69
- join(home, `.${cmd}`, "config"),
70
- join(home, `.${cmd}rc`),
71
- nearest(cmd),
72
- config(cmd, argv),
73
- ].filter(Boolean);
74
- };
75
-
76
- // [function]
77
-
78
- // ini parses anything, so a section header with no closing bracket, such as
79
- // `[validate`, would become a key, and the options under it would be read
80
- // outside their section. The first one's problem, or null.
81
- const unclosedSection = function (str) {
82
- const lines = str.split(/\r?\n/u).map((line) => line.trim());
83
- const i = lines.findIndex(
84
- (text) => text.startsWith("[") && !/^\[[^\]]*\]$/u.test(text),
85
- );
86
- return i === -1
87
- ? null
88
- : `Line ${i + 1}: section header isn't closed: ${lines[i]}`;
89
- };
90
-
91
- // [function]
92
-
93
- // a file's sections, INI or JSON, or nothing when it can't be read. A file
94
- // that doesn't parse is `parse_failed`, naming the file.
95
- const read = function (file) {
96
- let str = null;
97
- try {
98
- str = readFileSync(file, "utf8");
99
- } catch {
100
- return {};
101
- }
102
- if (!/^\s*\{/u.test(str)) {
103
- const unclosed = unclosedSection(str);
104
- if (unclosed) {
105
- throw new ArcError(
106
- cfgcode.PARSE_FAILED,
107
- phrase.unableToParse(file, unclosed),
108
- );
109
- }
110
- return ini.parse(str);
111
- }
112
- try {
113
- return JSON.parse(str);
114
- } catch (ex) {
115
- throw new ArcError(
116
- cfgcode.PARSE_FAILED,
117
- phrase.unableToParse(file, ex.message),
118
- { cause: ex },
119
- );
120
- }
121
- };
122
-
123
- // [function]
124
-
125
- // a command's section of .<cmd>rc, merged from the files `rc` reads. Unlike
126
- // `rc`, environment variables and `--config` aren't read. Options are read as
127
- // the command loads, so a file that doesn't parse aborts the command here,
128
- // as `<Command> aborted.`.
129
- const findRc = function (cmd, subcmd, argv) {
130
- try {
131
- return [...new Set(files(cmd, argv))].reduce(
132
- (found, file) => ({ ...found, ...read(file)[subcmd] }),
133
- {},
134
- );
135
- } catch (ex) {
136
- return abort(phrase.aborted(subcmd), ex, {
137
- json: args.json(argv),
138
- });
139
- }
140
- };
141
-
142
- // [export]
143
-
144
- module.exports = { findRc };
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const cfgcode = require("../config/code");
6
- const cfgpackage = require("../config/package");
7
- const cfgproduct = require("../config/product");
8
- const error = require("./error");
9
- const http = require("./http");
10
- const phrase = require("../phrase");
11
-
12
- // [use]
13
-
14
- const ArcError = error.ArcError;
15
- const HttpError = http.HttpError;
16
-
17
- // [declare]
18
-
19
- const CLIENT = cfgproduct.client;
20
- const ID = cfgproduct.id;
21
- const VERSION = cfgpackage.version;
22
-
23
- // [function]
24
-
25
- // the body as JSON, or null when it isn't JSON, such as a proxy's error page.
26
- const json = function (resp) {
27
- return resp.text().then((text) => {
28
- try {
29
- return JSON.parse(text);
30
- } catch {
31
- return null;
32
- }
33
- });
34
- };
35
-
36
- // [function]
37
-
38
- // the response's data. An error rejects with an HttpError that keeps its
39
- // status, whatever the body is, and the API's message when there is one.
40
- const parse = function (resp) {
41
- return json(resp).then((body) => {
42
- if (!resp.ok) {
43
- throw new HttpError(resp.status, {
44
- title: resp.statusText,
45
- ...(body?.data ?? {}),
46
- });
47
- }
48
- return body?.data ?? null;
49
- });
50
- };
51
-
52
- // [function]
53
-
54
- // sends a request to a full URL. `headers` are added to the client's own, and
55
- // a form is sent as JSON. A request that gets no response, such as when
56
- // offline, rejects as api_unreachable.
57
- const send = function (method, url, form, headers = {}) {
58
- const all = {
59
- [`X-${CLIENT}-Client-Id`]: ID,
60
- [`X-${CLIENT}-Client-Version`]: VERSION,
61
- ...(form ? { "Content-Type": "application/json" } : {}),
62
- ...headers,
63
- };
64
- return fetch(url, {
65
- body: form ? JSON.stringify(Object.fromEntries(form)) : null,
66
- headers: all,
67
- method,
68
- }).then(parse, (ex) => {
69
- throw new ArcError(cfgcode.API_UNREACHABLE, phrase.unableToReach(), {
70
- cause: ex,
71
- });
72
- });
73
- };
74
-
75
- // [function]
76
-
77
- const get = function (url, headers) {
78
- return send("GET", url, null, headers);
79
- };
80
-
81
- // [function]
82
-
83
- const post = function (url, form, headers) {
84
- return send("POST", url, form, headers);
85
- };
86
-
87
- // [export]
88
-
89
- module.exports = { get, post };
package/src/util/s3.js DELETED
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const fs = require("node:fs");
6
- const https = require("node:https");
7
-
8
- // [import]
9
-
10
- const cfgcode = require("../config/code");
11
- const error = require("./error");
12
- const phrase = require("../phrase");
13
-
14
- // [use]
15
-
16
- const ArcError = error.ArcError;
17
- const createReadStream = fs.createReadStream;
18
- const request = https.request;
19
-
20
- // [declare]
21
-
22
- const CHECKSUM = "x-amz-checksum-sha256";
23
-
24
- // [function]
25
-
26
- // [function]
27
-
28
- // whether the upload link signs `header`, which must then be sent.
29
- const signs = function (url, header) {
30
- const signed = new URL(url).searchParams.get("X-Amz-SignedHeaders");
31
- return Boolean(signed?.split(";").includes(header));
32
- };
33
-
34
- // [function]
35
-
36
- // the zip's SHA-256 is sent when the link signs it, so S3 refuses a zip that
37
- // isn't the one the upload was asked for.
38
- const requestOpts = function (url, { sha256, size }) {
39
- return {
40
- headers: {
41
- "Content-Length": size,
42
- "Content-Type": "application/zip",
43
- ...(signs(url, CHECKSUM)
44
- ? { [CHECKSUM]: Buffer.from(sha256, "hex").toString("base64") }
45
- : {}),
46
- },
47
- method: "PUT",
48
- };
49
- };
50
-
51
- // [function]
52
-
53
- // puts the file to the upload link, and resolves once S3 accepts it. A
54
- // request that gets no response rejects as api_unreachable; a file that can't
55
- // be read rejects with its own error.
56
- const upload = function (url, { path, sha256, size }, onProgress) {
57
- return new Promise((resolve, reject) => {
58
- const req = request(url, requestOpts(url, { sha256, size }), (resp) => {
59
- resp.resume();
60
- const status = resp.statusCode;
61
- if (status >= 200 && status < 300) {
62
- resolve();
63
- return;
64
- }
65
- reject(new ArcError(cfgcode.UPLOAD_FAILED, phrase.uploadFailed(status)));
66
- });
67
- let readError = null;
68
- req.on("error", (ex) => {
69
- reject(
70
- readError ??
71
- new ArcError(cfgcode.API_UNREACHABLE, phrase.unableToReach(), {
72
- cause: ex,
73
- }),
74
- );
75
- });
76
- createReadStream(path)
77
- .on("data", (chunk) => {
78
- if (onProgress) {
79
- onProgress(chunk.length);
80
- }
81
- })
82
- .on("error", (err) => {
83
- readError = err;
84
- req.destroy(err);
85
- })
86
- .pipe(req);
87
- });
88
- };
89
-
90
- // [export]
91
-
92
- module.exports = { upload };
@@ -1,189 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const chalk = require("chalk");
6
-
7
- // [import]
8
-
9
- const cfgcode = require("../config/code");
10
- const schemaMessage = require("../schema/message");
11
- const strs = require("./strs");
12
-
13
- // [use]
14
-
15
- const indentLines = strs.indentLines;
16
- const ISSUE = cfgcode.ISSUE;
17
-
18
- // [declare]
19
-
20
- // how a value's kind is named, as TOML writes it.
21
- const KINDS = {
22
- array: "a list",
23
- boolean: "true or false",
24
- number: "a number",
25
- object: "a table",
26
- string: "a string",
27
- };
28
- const NUMBERS = new Set(["bigint", "int", "number"]);
29
-
30
- // [function]
31
-
32
- // a zod issue's code (config/code.js, ISSUE). Our own checks name theirs in
33
- // params; zod's built-in ones, which drop params, are named from what zod
34
- // reports. Anything else is `invalid`, so every issue has a code.
35
- const issueCodeOf = function (issue) {
36
- switch (issue.code) {
37
- case "custom":
38
- return issue.params?.code ?? ISSUE.INVALID;
39
- case "invalid_format":
40
- if (issue.format === "uuid") {
41
- return ISSUE.UUID_INVALID;
42
- }
43
- return issue.format === "regex"
44
- ? ISSUE.CHARACTERS_INVALID
45
- : ISSUE.INVALID;
46
- case "invalid_type":
47
- return typeof issue.input === "undefined"
48
- ? ISSUE.REQUIRED
49
- : ISSUE.TYPE_INVALID;
50
- case "invalid_union":
51
- // every branch refused the value's type, e.g. `build = 3`
52
- return issue.errors.every((branch) =>
53
- branch.every((each) => each.code === "invalid_type"),
54
- )
55
- ? ISSUE.TYPE_INVALID
56
- : ISSUE.INVALID;
57
- case "invalid_value":
58
- return ISSUE.OPTION_INVALID;
59
- case "too_big":
60
- if (NUMBERS.has(issue.origin)) {
61
- return ISSUE.OUT_OF_RANGE;
62
- }
63
- return issue.origin === "string" ? ISSUE.TOO_LONG : ISSUE.TOO_MANY;
64
- case "too_small":
65
- if (NUMBERS.has(issue.origin)) {
66
- return ISSUE.OUT_OF_RANGE;
67
- }
68
- return issue.minimum > 1 ? ISSUE.TOO_SHORT : ISSUE.EMPTY;
69
- default:
70
- return ISSUE.INVALID;
71
- }
72
- };
73
-
74
- // [function]
75
-
76
- // a value's kind, as TOML writes it: "a string", "a list", "a table".
77
- const kindOf = function (type) {
78
- return KINDS[type] ?? `a ${type}`;
79
- };
80
-
81
- // [function]
82
-
83
- // what zod reports itself (a value of the wrong type, or not one of the
84
- // options), in arc's words, as `{ message, details }`: "Must be a string, not
85
- // a number." Null for a message of our own.
86
- const zodMessage = function (issue) {
87
- if (issue.code === "invalid_value" && issue.values) {
88
- return { details: [issue.values.join(", ")], message: "Must be one of:" };
89
- }
90
- const given = Array.isArray(issue.input) ? "array" : typeof issue.input;
91
- if (issue.code === "invalid_type" && typeof issue.input !== "undefined") {
92
- return {
93
- details: [],
94
- message: `Must be ${kindOf(issue.expected)}, not ${kindOf(given)}.`,
95
- };
96
- }
97
- if (
98
- issue.code === "invalid_union" &&
99
- issue.errors.every((branch) =>
100
- branch.every((each) => each.code === "invalid_type"),
101
- )
102
- ) {
103
- const expected = [
104
- ...new Set(issue.errors.map((branch) => kindOf(branch[0].expected))),
105
- ];
106
- return {
107
- details: [],
108
- message: `Must be ${expected.join(" or ")}, not ${kindOf(given)}.`,
109
- };
110
- }
111
- return null;
112
- };
113
-
114
- // [function]
115
-
116
- // a zod issue as arc validate reports it: the field's path, the rule's code,
117
- // the message's first line and its details, and the link to the field's
118
- // rules, or null for a field the docs leave out.
119
- const toIssue = function (name, issue) {
120
- const parsed = schemaMessage.parse(issue.message);
121
- const { details, message } =
122
- (/^Invalid (input|option)\b/u.test(parsed.message) && zodMessage(issue)) ||
123
- parsed;
124
- return {
125
- code: issueCodeOf(issue),
126
- details,
127
- link: issue.path.length
128
- ? schemaMessage.link(name, String(issue.path[0]))
129
- : null,
130
- message,
131
- path: `${name}.${issue.path.join(".") || "value"}`,
132
- };
133
- };
134
-
135
- // [function]
136
-
137
- // an issue as it's printed: the path, the message, then its details and its
138
- // link, indented beneath it. `linked` false leaves the link out.
139
- const print = function ({ details, link, message, path }, linked = true) {
140
- const rest = [
141
- ...details,
142
- ...(linked && link ? [chalk.cyan.underline(link)] : []),
143
- ];
144
- const head = `${chalk.cyan(path)}: ${message}`;
145
- return rest.length ? `${head}\n${indentLines(rest.join("\n"))}` : head;
146
- };
147
-
148
- // [function]
149
-
150
- // the issues as printed without their links, and each link once, for arc
151
- // validate's list of references.
152
- const dereference = function (issues) {
153
- const references = [
154
- ...new Set(issues.map(({ link }) => link).filter(Boolean)),
155
- ].map((link) => chalk.cyan.underline(link));
156
- return [issues.map((issue) => print(issue, false)), references];
157
- };
158
-
159
- // [function]
160
-
161
- // orders issues by path, then message, as they're printed.
162
- const compare = function (a, b) {
163
- return `${a.path}: ${a.message}`.localeCompare(`${b.path}: ${b.message}`);
164
- };
165
-
166
- // [function]
167
-
168
- const validator = function (name, schema) {
169
- return (value, conf) => {
170
- const { error, success } = schema(value, conf).safeParse(value, {
171
- reportInput: true,
172
- });
173
- if (!success) {
174
- return { issues: error.issues.map((issue) => toIssue(name, issue)) };
175
- }
176
- return { issues: [] };
177
- };
178
- };
179
-
180
- // [export]
181
-
182
- module.exports = {
183
- compare,
184
- dereference,
185
- issueCodeOf,
186
- print,
187
- toIssue,
188
- validator,
189
- };
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const path = require("node:path");
6
-
7
- // [use]
8
-
9
- const posixBasename = path.posix.basename;
10
-
11
- // [declare]
12
-
13
- // a screenshot's name, as the store reads it (ui's `screenshots()`): its
14
- // number, and its qualifier, the platform it's for, if any.
15
- const SCREENSHOT = /^screenshot_(\d+)(?:_([^.]+))?\.[^.]+$/u;
16
-
17
- // [function]
18
-
19
- // the gallery's screenshots that share a number and a qualifier, such as
20
- // `screenshot_1.png` and `screenshot_01.png`, which the store can show only
21
- // one of, as lists of their file names; a number read as a number, so its
22
- // padding doesn't matter.
23
- const repeated = function (files) {
24
- const groups = {};
25
- for (const name of files.map((file) => posixBasename(file))) {
26
- const match = SCREENSHOT.exec(name);
27
- if (match) {
28
- const key = `${Number(match[1])}_${match[2] ?? ""}`;
29
- groups[key] = [...(groups[key] ?? []), name];
30
- }
31
- }
32
- return Object.values(groups).filter((group) => group.length > 1);
33
- };
34
-
35
- // [export]
36
-
37
- module.exports = { SCREENSHOT, repeated };
package/src/util/shell.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const cp = require("node:child_process");
6
-
7
- // [import]
8
-
9
- const open = require("open");
10
-
11
- // [use]
12
-
13
- const execFile = cp.execFile;
14
-
15
- // [declare]
16
-
17
- const APP = "app";
18
- const BROWSER = "browser";
19
-
20
- // [function]
21
-
22
- const canLaunch = function (scheme) {
23
- return new Promise((resolve) => {
24
- switch (process.platform) {
25
- case "darwin":
26
- execFile("open", ["-Ra", scheme], (err) => resolve(!err));
27
- break;
28
- case "win32":
29
- execFile("reg", ["query", `HKCR\\${scheme}`], (err) => resolve(!err));
30
- break;
31
- case "linux":
32
- execFile(
33
- "xdg-mime",
34
- ["query", "default", `x-scheme-handler/${scheme}`],
35
- (err, stdout) => resolve(!err && Boolean(stdout.trim())),
36
- );
37
- break;
38
- default:
39
- resolve(false);
40
- }
41
- });
42
- };
43
-
44
- // [function]
45
-
46
- // opens `target`, and resolves with `where`, or null when it couldn't.
47
- const openAs = function (target, where) {
48
- return open(target).then(
49
- () => where,
50
- () => null,
51
- );
52
- };
53
-
54
- // [function]
55
-
56
- // opens `uri` in the app for `scheme`, or `fallback` when there's none.
57
- const launchApp = function (uri, scheme, fallback) {
58
- return canLaunch(scheme)
59
- .then((can) => {
60
- if (can) {
61
- return openAs(uri, APP);
62
- }
63
- return fallback ? openAs(fallback, BROWSER) : null;
64
- })
65
- .catch(() => null);
66
- };
67
-
68
- // [function]
69
-
70
- // opens `uri`, or `fallback` when no app handles its scheme, and resolves
71
- // with where it opened: "app", "browser", or null when it couldn't. It
72
- // rejects when `uri` isn't a URL.
73
- const launch = function (uri, fallback) {
74
- return Promise.resolve(uri).then((target) => {
75
- const scheme = new URL(target).protocol.slice(0, -1);
76
- return scheme === "http" || scheme === "https"
77
- ? openAs(target, BROWSER)
78
- : launchApp(target, scheme, fallback);
79
- });
80
- };
81
-
82
- // [export]
83
-
84
- module.exports = { APP, BROWSER, launch };
package/src/util/size.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- // [function]
4
-
5
- const b = function (bytes) {
6
- return bytes;
7
- };
8
-
9
- // [function]
10
-
11
- const kb = function (bytes) {
12
- return b(bytes * 1024);
13
- };
14
-
15
- // [function]
16
-
17
- const mb = function (bytes) {
18
- return kb(bytes * 1024);
19
- };
20
-
21
- // [function]
22
-
23
- const gb = function (bytes) {
24
- return mb(bytes * 1024);
25
- };
26
-
27
- // [function]
28
-
29
- const toB = function (bytes) {
30
- return bytes;
31
- };
32
-
33
- // [function]
34
-
35
- const toKb = function (bytes) {
36
- return toB(bytes / 1024);
37
- };
38
-
39
- // [function]
40
-
41
- const toMb = function (bytes) {
42
- return toKb(bytes / 1024);
43
- };
44
-
45
- // [function]
46
-
47
- const toGb = function (bytes) {
48
- return toMb(bytes / 1024);
49
- };
50
-
51
- // [export]
52
-
53
- module.exports = { b, gb, kb, mb, toB, toGb, toKb, toMb };