@c9up/ream 0.2.28 → 0.2.30

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 (293) hide show
  1. package/README.md +5 -6
  2. package/dist/Codemods.d.ts +24 -0
  3. package/dist/Codemods.d.ts.map +1 -1
  4. package/dist/Codemods.js +211 -1
  5. package/dist/Codemods.js.map +1 -1
  6. package/dist/HttpKernel.d.ts.map +1 -1
  7. package/dist/HttpKernel.js +17 -5
  8. package/dist/HttpKernel.js.map +1 -1
  9. package/dist/Ignitor.d.ts +15 -2
  10. package/dist/Ignitor.d.ts.map +1 -1
  11. package/dist/Ignitor.js +33 -23
  12. package/dist/Ignitor.js.map +1 -1
  13. package/dist/bodyparser/BodyParserMiddleware.d.ts +4 -4
  14. package/dist/bodyparser/BodyParserMiddleware.d.ts.map +1 -1
  15. package/dist/bodyparser/BodyParserMiddleware.js +41 -11
  16. package/dist/bodyparser/BodyParserMiddleware.js.map +1 -1
  17. package/dist/bodyparser/MultipartFile.d.ts +21 -15
  18. package/dist/bodyparser/MultipartFile.d.ts.map +1 -1
  19. package/dist/bodyparser/MultipartFile.js +40 -58
  20. package/dist/bodyparser/MultipartFile.js.map +1 -1
  21. package/dist/bodyparser/parseSize.d.ts +7 -4
  22. package/dist/bodyparser/parseSize.d.ts.map +1 -1
  23. package/dist/bodyparser/parseSize.js +12 -17
  24. package/dist/bodyparser/parseSize.js.map +1 -1
  25. package/dist/bodyparser/qsParse.d.ts +20 -1
  26. package/dist/bodyparser/qsParse.d.ts.map +1 -1
  27. package/dist/bodyparser/qsParse.js +78 -25
  28. package/dist/bodyparser/qsParse.js.map +1 -1
  29. package/dist/codemods/source.d.ts +57 -0
  30. package/dist/codemods/source.d.ts.map +1 -0
  31. package/dist/codemods/source.js +282 -0
  32. package/dist/codemods/source.js.map +1 -0
  33. package/dist/console/prompts.d.ts.map +1 -1
  34. package/dist/console/prompts.js +3 -1
  35. package/dist/console/prompts.js.map +1 -1
  36. package/dist/container/Container.d.ts.map +1 -1
  37. package/dist/container/Container.js +61 -71
  38. package/dist/container/Container.js.map +1 -1
  39. package/dist/events/Emitter.d.ts +12 -0
  40. package/dist/events/Emitter.d.ts.map +1 -1
  41. package/dist/events/Emitter.js +36 -9
  42. package/dist/events/Emitter.js.map +1 -1
  43. package/dist/events/helix/helpers.d.ts.map +1 -1
  44. package/dist/events/helix/helpers.js +19 -9
  45. package/dist/events/helix/helpers.js.map +1 -1
  46. package/dist/graphql/GraphQLEngine.d.ts +8 -0
  47. package/dist/graphql/GraphQLEngine.d.ts.map +1 -1
  48. package/dist/graphql/GraphQLEngine.js +79 -12
  49. package/dist/graphql/GraphQLEngine.js.map +1 -1
  50. package/dist/helpers/MessageBuilder.d.ts +4 -2
  51. package/dist/helpers/MessageBuilder.d.ts.map +1 -1
  52. package/dist/helpers/MessageBuilder.js +4 -2
  53. package/dist/helpers/MessageBuilder.js.map +1 -1
  54. package/dist/helpers/errors.d.ts +11 -0
  55. package/dist/helpers/errors.d.ts.map +1 -0
  56. package/dist/helpers/errors.js +17 -0
  57. package/dist/helpers/errors.js.map +1 -0
  58. package/dist/helpers/napi-loader.d.ts.map +1 -1
  59. package/dist/helpers/napi-loader.js +3 -2
  60. package/dist/helpers/napi-loader.js.map +1 -1
  61. package/dist/http/Exception.d.ts +14 -1
  62. package/dist/http/Exception.d.ts.map +1 -1
  63. package/dist/http/Exception.js +10 -2
  64. package/dist/http/Exception.js.map +1 -1
  65. package/dist/http/HttpContext.d.ts +31 -2
  66. package/dist/http/HttpContext.d.ts.map +1 -1
  67. package/dist/http/HttpContext.js +12 -5
  68. package/dist/http/HttpContext.js.map +1 -1
  69. package/dist/http/RedirectBuilder.d.ts +9 -3
  70. package/dist/http/RedirectBuilder.d.ts.map +1 -1
  71. package/dist/http/RedirectBuilder.js +43 -37
  72. package/dist/http/RedirectBuilder.js.map +1 -1
  73. package/dist/http/Request.d.ts +42 -17
  74. package/dist/http/Request.d.ts.map +1 -1
  75. package/dist/http/Request.js +80 -58
  76. package/dist/http/Request.js.map +1 -1
  77. package/dist/http/Response.d.ts +7 -4
  78. package/dist/http/Response.d.ts.map +1 -1
  79. package/dist/http/Response.js +14 -6
  80. package/dist/http/Response.js.map +1 -1
  81. package/dist/http/SseStream.js +6 -7
  82. package/dist/http/SseStream.js.map +1 -1
  83. package/dist/http/permissions.d.ts +25 -0
  84. package/dist/http/permissions.d.ts.map +1 -0
  85. package/dist/http/permissions.js +38 -0
  86. package/dist/http/permissions.js.map +1 -0
  87. package/dist/http-client/HttpClient.d.ts +111 -0
  88. package/dist/http-client/HttpClient.d.ts.map +1 -0
  89. package/dist/http-client/HttpClient.js +386 -0
  90. package/dist/http-client/HttpClient.js.map +1 -0
  91. package/dist/http-client/addresses.d.ts +14 -0
  92. package/dist/http-client/addresses.d.ts.map +1 -0
  93. package/dist/http-client/addresses.js +57 -0
  94. package/dist/http-client/addresses.js.map +1 -0
  95. package/dist/http-client/fake.d.ts +50 -0
  96. package/dist/http-client/fake.d.ts.map +1 -0
  97. package/dist/http-client/fake.js +95 -0
  98. package/dist/http-client/fake.js.map +1 -0
  99. package/dist/http-client/index.d.ts +7 -0
  100. package/dist/http-client/index.d.ts.map +1 -0
  101. package/dist/http-client/index.js +7 -0
  102. package/dist/http-client/index.js.map +1 -0
  103. package/dist/index.d.ts +4 -3
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +1 -1
  106. package/dist/index.js.map +1 -1
  107. package/dist/middleware/Pipeline.d.ts.map +1 -1
  108. package/dist/middleware/Pipeline.js +6 -3
  109. package/dist/middleware/Pipeline.js.map +1 -1
  110. package/dist/native/generated.d.ts +93 -36
  111. package/dist/native/generated.d.ts.map +1 -1
  112. package/dist/profiler/Profiler.d.ts.map +1 -1
  113. package/dist/profiler/Profiler.js +4 -1
  114. package/dist/profiler/Profiler.js.map +1 -1
  115. package/dist/profiler/client.generated.d.ts +5 -0
  116. package/dist/profiler/client.generated.d.ts.map +1 -0
  117. package/dist/profiler/client.generated.js +6 -0
  118. package/dist/profiler/client.generated.js.map +1 -0
  119. package/dist/profiler/collectors.d.ts +92 -13
  120. package/dist/profiler/collectors.d.ts.map +1 -1
  121. package/dist/profiler/collectors.js +106 -19
  122. package/dist/profiler/collectors.js.map +1 -1
  123. package/dist/profiler/endpoint.d.ts +2 -1
  124. package/dist/profiler/endpoint.d.ts.map +1 -1
  125. package/dist/profiler/endpoint.js +25 -1
  126. package/dist/profiler/endpoint.js.map +1 -1
  127. package/dist/profiler/index.d.ts +8 -4
  128. package/dist/profiler/index.d.ts.map +1 -1
  129. package/dist/profiler/index.js +11 -4
  130. package/dist/profiler/index.js.map +1 -1
  131. package/dist/profiler/middleware.d.ts.map +1 -1
  132. package/dist/profiler/middleware.js +76 -10
  133. package/dist/profiler/middleware.js.map +1 -1
  134. package/dist/profiler/preview.d.ts +17 -0
  135. package/dist/profiler/preview.d.ts.map +1 -0
  136. package/dist/profiler/preview.js +100 -0
  137. package/dist/profiler/preview.js.map +1 -0
  138. package/dist/profiler/toolbar.d.ts +15 -23
  139. package/dist/profiler/toolbar.d.ts.map +1 -1
  140. package/dist/profiler/toolbar.js +25 -91
  141. package/dist/profiler/toolbar.js.map +1 -1
  142. package/dist/profiler/types.d.ts +6 -1
  143. package/dist/profiler/types.d.ts.map +1 -1
  144. package/dist/router/Router.d.ts +6 -0
  145. package/dist/router/Router.d.ts.map +1 -1
  146. package/dist/router/Router.js +115 -12
  147. package/dist/router/Router.js.map +1 -1
  148. package/dist/rpc/RpcProvider.d.ts +6 -0
  149. package/dist/rpc/RpcProvider.d.ts.map +1 -1
  150. package/dist/rpc/RpcProvider.js +4 -1
  151. package/dist/rpc/RpcProvider.js.map +1 -1
  152. package/dist/rpc/RpcRouter.d.ts +27 -14
  153. package/dist/rpc/RpcRouter.d.ts.map +1 -1
  154. package/dist/rpc/RpcRouter.js +97 -40
  155. package/dist/rpc/RpcRouter.js.map +1 -1
  156. package/dist/scheduler/Scheduler.js +1 -1
  157. package/dist/scheduler/Scheduler.js.map +1 -1
  158. package/dist/scheduler/locks/RedisLockBackend.d.ts.map +1 -1
  159. package/dist/scheduler/locks/RedisLockBackend.js +13 -2
  160. package/dist/scheduler/locks/RedisLockBackend.js.map +1 -1
  161. package/dist/security/CookieSigner.d.ts.map +1 -1
  162. package/dist/security/CookieSigner.js +32 -8
  163. package/dist/security/CookieSigner.js.map +1 -1
  164. package/dist/security/SignedUrl.d.ts.map +1 -1
  165. package/dist/security/SignedUrl.js +16 -19
  166. package/dist/security/SignedUrl.js.map +1 -1
  167. package/dist/server/Server.d.ts +44 -12
  168. package/dist/server/Server.d.ts.map +1 -1
  169. package/dist/server/Server.js +31 -10
  170. package/dist/server/Server.js.map +1 -1
  171. package/dist/server/nativeGrpc.d.ts +27 -0
  172. package/dist/server/nativeGrpc.d.ts.map +1 -0
  173. package/dist/server/nativeGrpc.js +47 -0
  174. package/dist/server/nativeGrpc.js.map +1 -0
  175. package/dist/server/nativeLimits.d.ts +57 -0
  176. package/dist/server/nativeLimits.d.ts.map +1 -0
  177. package/dist/server/nativeLimits.js +75 -0
  178. package/dist/server/nativeLimits.js.map +1 -0
  179. package/dist/session/Session.d.ts +12 -0
  180. package/dist/session/Session.d.ts.map +1 -1
  181. package/dist/session/Session.js +13 -4
  182. package/dist/session/Session.js.map +1 -1
  183. package/dist/session/SessionMiddleware.d.ts.map +1 -1
  184. package/dist/session/SessionMiddleware.js +28 -9
  185. package/dist/session/SessionMiddleware.js.map +1 -1
  186. package/dist/session/config.d.ts +5 -0
  187. package/dist/session/config.d.ts.map +1 -1
  188. package/dist/session/config.js +8 -0
  189. package/dist/session/config.js.map +1 -1
  190. package/dist/session/drivers/MemoryDriver.d.ts.map +1 -1
  191. package/dist/session/drivers/MemoryDriver.js +26 -7
  192. package/dist/session/drivers/MemoryDriver.js.map +1 -1
  193. package/dist/session/errors.d.ts +17 -0
  194. package/dist/session/errors.d.ts.map +1 -1
  195. package/dist/session/errors.js +21 -0
  196. package/dist/session/errors.js.map +1 -1
  197. package/dist/session/templateTags.d.ts +14 -0
  198. package/dist/session/templateTags.d.ts.map +1 -1
  199. package/dist/session/templateTags.js +45 -17
  200. package/dist/session/templateTags.js.map +1 -1
  201. package/dist/storage/StaticMiddleware.d.ts.map +1 -1
  202. package/dist/storage/StaticMiddleware.js +49 -27
  203. package/dist/storage/StaticMiddleware.js.map +1 -1
  204. package/dist/testing/ApiResponse.d.ts.map +1 -1
  205. package/dist/testing/ApiResponse.js +7 -1
  206. package/dist/testing/ApiResponse.js.map +1 -1
  207. package/dist/testing/TestClient.d.ts.map +1 -1
  208. package/dist/testing/TestClient.js +16 -4
  209. package/dist/testing/TestClient.js.map +1 -1
  210. package/dist/utils/Macroable.d.ts +1 -1
  211. package/dist/utils/Macroable.js +2 -2
  212. package/dist/utils/Macroable.js.map +1 -1
  213. package/events.darwin-arm64.node +0 -0
  214. package/events.darwin-x64.node +0 -0
  215. package/events.linux-arm64-gnu.node +0 -0
  216. package/events.linux-x64-gnu.node +0 -0
  217. package/events.win32-x64-msvc.node +0 -0
  218. package/index.darwin-arm64.node +0 -0
  219. package/index.darwin-x64.node +0 -0
  220. package/index.linux-arm64-gnu.node +0 -0
  221. package/index.linux-x64-gnu.node +0 -0
  222. package/index.win32-x64-msvc.node +0 -0
  223. package/package.json +11 -3
  224. package/scheduler.darwin-arm64.node +0 -0
  225. package/scheduler.darwin-x64.node +0 -0
  226. package/scheduler.linux-arm64-gnu.node +0 -0
  227. package/scheduler.linux-x64-gnu.node +0 -0
  228. package/scheduler.win32-x64-msvc.node +0 -0
  229. package/src/Codemods.ts +314 -3
  230. package/src/HttpKernel.ts +18 -7
  231. package/src/Ignitor.ts +58 -26
  232. package/src/bodyparser/BodyParserMiddleware.ts +45 -16
  233. package/src/bodyparser/MultipartFile.ts +46 -67
  234. package/src/bodyparser/parseSize.ts +17 -17
  235. package/src/bodyparser/qsParse.ts +96 -26
  236. package/src/codemods/source.ts +303 -0
  237. package/src/console/prompts.ts +3 -1
  238. package/src/container/Container.ts +97 -81
  239. package/src/events/Emitter.ts +37 -10
  240. package/src/events/helix/helpers.ts +24 -19
  241. package/src/graphql/GraphQLEngine.ts +91 -14
  242. package/src/helpers/MessageBuilder.ts +4 -2
  243. package/src/helpers/errors.ts +16 -0
  244. package/src/helpers/napi-loader.ts +3 -2
  245. package/src/http/Exception.ts +17 -2
  246. package/src/http/HttpContext.ts +34 -5
  247. package/src/http/RedirectBuilder.ts +51 -37
  248. package/src/http/Request.ts +102 -58
  249. package/src/http/Response.ts +15 -7
  250. package/src/http/SseStream.ts +6 -7
  251. package/src/http/permissions.ts +47 -0
  252. package/src/http-client/HttpClient.ts +505 -0
  253. package/src/http-client/addresses.ts +58 -0
  254. package/src/http-client/fake.ts +141 -0
  255. package/src/http-client/index.ts +21 -0
  256. package/src/index.ts +6 -1
  257. package/src/middleware/Pipeline.ts +7 -3
  258. package/src/native/generated.ts +106 -48
  259. package/src/profiler/Profiler.ts +4 -1
  260. package/src/profiler/client/toolbar.css +595 -0
  261. package/src/profiler/client/toolbar.js +1299 -0
  262. package/src/profiler/client.generated.ts +7 -0
  263. package/src/profiler/collectors.ts +156 -19
  264. package/src/profiler/endpoint.ts +27 -1
  265. package/src/profiler/index.ts +17 -3
  266. package/src/profiler/middleware.ts +74 -9
  267. package/src/profiler/preview.ts +104 -0
  268. package/src/profiler/toolbar.ts +28 -91
  269. package/src/profiler/types.ts +6 -1
  270. package/src/router/Router.ts +136 -13
  271. package/src/rpc/RpcProvider.ts +10 -1
  272. package/src/rpc/RpcRouter.ts +129 -45
  273. package/src/scheduler/Scheduler.ts +1 -1
  274. package/src/scheduler/locks/RedisLockBackend.ts +12 -4
  275. package/src/security/CookieSigner.ts +30 -8
  276. package/src/security/SignedUrl.ts +18 -17
  277. package/src/server/Server.ts +60 -12
  278. package/src/server/nativeGrpc.ts +59 -0
  279. package/src/server/nativeLimits.ts +111 -0
  280. package/src/session/Session.ts +29 -4
  281. package/src/session/SessionMiddleware.ts +30 -10
  282. package/src/session/config.ts +7 -0
  283. package/src/session/drivers/MemoryDriver.ts +26 -7
  284. package/src/session/errors.ts +31 -0
  285. package/src/session/templateTags.ts +57 -0
  286. package/src/storage/StaticMiddleware.ts +46 -27
  287. package/src/testing/ApiResponse.ts +7 -1
  288. package/src/testing/TestClient.ts +14 -5
  289. package/src/utils/Macroable.ts +2 -2
  290. package/scripts/build-napi-types.mjs +0 -69
  291. package/scripts/copy-napi.mjs +0 -121
  292. package/scripts/generate-mime.mjs +0 -119
  293. package/scripts/generate-napi-types.mjs +0 -187
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Regenerate `src/native/generated.ts` from the Rust.
4
- *
5
- * Node rather than a shell script because this runs inside `build:napi`, and
6
- * that runs on the Windows prebuild runner too: a bash `mktemp` there hands
7
- * cargo a `/tmp/...` path the native proc-macro cannot write to, so the
8
- * type-def file comes back empty and the build fails for no visible reason.
9
- *
10
- * One crate at a time on purpose: with napi-derive 2 the writes all went to a
11
- * single `TYPE_DEF_TMP_PATH` and a parallel build interleaved them
12
- * while cargo compiles, and a parallel build interleaves the writes —
13
- * definitions go missing, silently, and the generated file comes out short.
14
- */
15
-
16
- import { execFileSync } from 'node:child_process'
17
- import { createRequire } from 'node:module'
18
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
19
- import { tmpdir } from 'node:os'
20
- import { dirname, join } from 'node:path'
21
- import { fileURLToPath } from 'node:url'
22
-
23
- const CRATES = ['ream-events-napi', 'ream-http-napi', 'ream-scheduler-napi']
24
-
25
- const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
26
- const output = join('src', 'native', 'generated.ts')
27
- const scratch = mkdtempSync(join(tmpdir(), 'napi-types-'))
28
-
29
- try {
30
- const lines = []
31
- for (const crate of CRATES) {
32
- const perCrate = join(scratch, crate)
33
- writeFileSync(perCrate, '')
34
- execFileSync('cargo', ['build', '-p', crate], {
35
- cwd: packageRoot,
36
- env: { ...process.env, NAPI_TYPE_DEF_TMP_FOLDER: scratch },
37
- stdio: ['ignore', 'ignore', 'inherit'],
38
- })
39
- const emitted = readFileSync(perCrate, 'utf8').split('\n').filter(Boolean)
40
- if (emitted.length === 0) {
41
- throw new Error(
42
- `[napi-types] ${crate} emitted nothing — is napi-derive's "type-def" feature on?`,
43
- )
44
- }
45
- lines.push(...emitted)
46
- }
47
-
48
- const combined = join(scratch, 'combined.jsonl')
49
- writeFileSync(combined, `${lines.join('\n')}\n`)
50
-
51
- execFileSync(
52
- process.execPath,
53
- [join('scripts', 'generate-napi-types.mjs'), combined, output],
54
- { cwd: packageRoot, stdio: 'inherit' },
55
- )
56
-
57
- // Formatted here rather than excluded from the linter: the file is checked
58
- // in, so it should read like the rest of the tree — and formatting it at
59
- // generation means it never shows up as a diff someone has to fix by hand.
60
- // Resolved through the package entry rather than `node_modules/.bin`, whose
61
- // shim is a shell script the Windows runner cannot execute directly.
62
- const biome = createRequire(import.meta.url).resolve('@biomejs/biome/bin/biome')
63
- execFileSync(process.execPath, [biome, 'format', '--write', output], {
64
- cwd: packageRoot,
65
- stdio: ['ignore', 'ignore', 'inherit'],
66
- })
67
- } finally {
68
- rmSync(scratch, { recursive: true, force: true })
69
- }
@@ -1,121 +0,0 @@
1
- // Copy every freshly-built Ream NAPI cdylib out of cargo's target
2
- // directory and into the package root with the platform-suffix naming
3
- // convention used by `napi-loader.ts`:
4
- //
5
- // packages/ream/index.linux-x64-gnu.node (ream-http-napi)
6
- // packages/ream/scheduler.linux-x64-gnu.node (ream-scheduler-napi)
7
- // packages/ream/index.darwin-arm64.node
8
- // ...
9
- //
10
- // The TS loader walks two upper directories from each `loadNapi` caller
11
- // to find these files, so the binaries MUST live at the package root
12
- // (not under target/) to be discovered at runtime.
13
- //
14
- // Usage:
15
- //
16
- // pnpm --filter @c9up/ream build:rust # cargo build --release
17
- // pnpm --filter @c9up/ream build:napi # build:rust + this script
18
- //
19
- // The package.json script chains both steps. CI / npm publish runs
20
- // `build:napi` once per platform during the matrix build — every
21
- // crate listed in `NAPI_CRATES` ships in the tarball.
22
-
23
- import { copyFileSync, existsSync } from 'node:fs'
24
- import { dirname, join, resolve } from 'node:path'
25
- import { arch, env, platform } from 'node:process'
26
- import { fileURLToPath } from 'node:url'
27
-
28
- const here = dirname(fileURLToPath(import.meta.url))
29
- const root = join(here, '..')
30
-
31
- // Rust target triple -> { suffix, os }. Set CARGO_BUILD_TARGET to cross-compile
32
- // (e.g. build the x86_64-apple-darwin binary on an arm64 macOS runner so we
33
- // don't depend on the scarce macos-13 Intel runners). When unset we fall back
34
- // to the host platform/arch and the default target/release dir.
35
- const TRIPLE_MAP = {
36
- 'x86_64-unknown-linux-gnu': { suffix: 'linux-x64-gnu', os: 'linux' },
37
- 'aarch64-unknown-linux-gnu': { suffix: 'linux-arm64-gnu', os: 'linux' },
38
- 'x86_64-apple-darwin': { suffix: 'darwin-x64', os: 'darwin' },
39
- 'aarch64-apple-darwin': { suffix: 'darwin-arm64', os: 'darwin' },
40
- 'x86_64-pc-windows-msvc': { suffix: 'win32-x64-msvc', os: 'win32' },
41
- }
42
-
43
- const HOST_SUFFIX_MAP = {
44
- 'linux-x64': 'linux-x64-gnu',
45
- 'linux-arm64': 'linux-arm64-gnu',
46
- 'darwin-x64': 'darwin-x64',
47
- 'darwin-arm64': 'darwin-arm64',
48
- 'win32-x64': 'win32-x64-msvc',
49
- }
50
-
51
- // Cargo writes its artifacts under CARGO_TARGET_DIR when that is set — a
52
- // shared cache, a CI mount — so they are not under this package's `target/` at
53
- // all. A relative value is resolved against the directory cargo ran in, which
54
- // is this package root.
55
- const targetDir = env.CARGO_TARGET_DIR
56
- ? resolve(root, env.CARGO_TARGET_DIR)
57
- : join(root, 'target')
58
-
59
- const triple = env.CARGO_BUILD_TARGET ?? ''
60
- let suffix
61
- let os
62
- let releaseDir
63
- if (triple) {
64
- const entry = TRIPLE_MAP[triple]
65
- if (!entry) {
66
- throw new Error(`[ream:napi] unsupported CARGO_BUILD_TARGET: ${triple}`)
67
- }
68
- suffix = entry.suffix
69
- os = entry.os
70
- releaseDir = join(targetDir, triple, 'release')
71
- } else {
72
- suffix = HOST_SUFFIX_MAP[`${platform}-${arch}`]
73
- os = platform
74
- releaseDir = join(targetDir, 'release')
75
- if (!suffix) {
76
- throw new Error(`[ream:napi] unsupported platform/arch: ${platform}-${arch}`)
77
- }
78
- }
79
-
80
- // Every NAPI crate shipped from the @c9up/ream package. `crateLib` is the
81
- // underscore-suffixed name cargo produces under `target/release/`;
82
- // `targetName` is what `loadNapi({ binaryName })` expects at the package
83
- // root (see `napi-loader.ts` — the binary lookup prefix matches the
84
- // `binaryName` option passed by each TS consumer).
85
- const NAPI_CRATES = [
86
- { crateLib: 'ream_http_napi', targetName: 'index' },
87
- { crateLib: 'ream_scheduler_napi', targetName: 'scheduler' },
88
- { crateLib: 'ream_events_napi', targetName: 'events' },
89
- ]
90
-
91
- // `crate-type = ["cdylib"]` settles on the platform-conventional file
92
- // name. Linux + macOS prepend `lib`; Windows drops the prefix and uses
93
- // `.dll`. Check both Windows shapes so we degrade gracefully if upstream
94
- // cargo ever switches naming.
95
- function buildCandidates(crateLib) {
96
- if (os === 'win32') {
97
- return [
98
- join(releaseDir, `${crateLib}.dll`),
99
- join(releaseDir, `lib${crateLib}.dll`),
100
- ]
101
- }
102
- if (os === 'darwin') {
103
- return [join(releaseDir, `lib${crateLib}.dylib`)]
104
- }
105
- return [join(releaseDir, `lib${crateLib}.so`)]
106
- }
107
-
108
- for (const { crateLib, targetName } of NAPI_CRATES) {
109
- const candidates = buildCandidates(crateLib)
110
- const source = candidates.find((candidate) => existsSync(candidate))
111
- if (!source) {
112
- throw new Error(
113
- `[ream:napi] native library for '${crateLib}' not found. Looked for:\n${candidates
114
- .map((p) => `- ${p}`)
115
- .join('\n')}\nRun 'pnpm --filter @c9up/ream build:rust' first.`,
116
- )
117
- }
118
- const target = join(root, `${targetName}.${suffix}.node`)
119
- copyFileSync(source, target)
120
- console.log(`[ream:napi] copied ${source} -> ${target}`)
121
- }
@@ -1,119 +0,0 @@
1
- /**
2
- * Regenerate `src/http/mime.ts` from mime-db.
3
- *
4
- * The table is data, not logic, and hand-maintaining it is how `.yaml` and
5
- * `.sql` went missing. `mime-types` reads the same two fields out of mime-db —
6
- * the resolved extension map and the per-type `charset` — so generating from
7
- * there keeps `contentType()` answering exactly what the package answered.
8
- *
9
- * mime-db and mime-types are dev-only: they are read HERE, at generation time,
10
- * and never imported by the framework.
11
- *
12
- * node scripts/generate-mime.mjs
13
- */
14
-
15
- import { createRequire } from 'node:module'
16
- import { writeFile } from 'node:fs/promises'
17
- import { fileURLToPath } from 'node:url'
18
- import { dirname, join } from 'node:path'
19
-
20
- const require = createRequire(import.meta.url)
21
- const mimeTypes = require('mime-types')
22
- const db = require('mime-db')
23
- const dbVersion = require('mime-db/package.json').version
24
-
25
- const here = dirname(fileURLToPath(import.meta.url))
26
- const target = join(here, '..', 'src', 'http', 'mime.ts')
27
-
28
- /**
29
- * Emitted in the package's own style — single quotes, no semicolons — so a
30
- * regenerated file is already what `biome check` wants and the diff after a
31
- * regeneration is the data that changed, nothing else.
32
- */
33
- const quote = (value) => `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`
34
- /** An identifier when it is one, a quoted key otherwise (`7z`, `3gp`…). */
35
- const key = (ext) => (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(ext) ? ext : quote(ext))
36
-
37
- const extensions = Object.keys(mimeTypes.types).sort()
38
- const rows = extensions.map((e) => ` ${key(e)}: ${quote(mimeTypes.types[e])},`).join('\n')
39
-
40
- const charsets = Object.entries(db)
41
- .filter(([, entry]) => entry.charset)
42
- .sort(([a], [b]) => a.localeCompare(b))
43
- .map(([type, entry]) => ` ${quote(type)}: ${quote(entry.charset.toLowerCase())},`)
44
- .join('\n')
45
-
46
- await writeFile(target, render({ rows, charsets, dbVersion, count: extensions.length }))
47
- process.stdout.write(`mime.ts: ${extensions.length} extensions from mime-db ${dbVersion}\n`)
48
-
49
- function render({ rows, charsets, dbVersion, count }) {
50
- return `/**
51
- * Content types for a response, resolved here rather than pulled in.
52
- *
53
- * \`response.type("txt")\` has to become \`text/plain; charset=utf-8\`, which is a
54
- * lookup table and one charset rule — the same job \`@c9up/archive\` already
55
- * does in its own table, so the framework was carrying a dependency for work
56
- * the ecosystem already owned.
57
- *
58
- * A hand-written table is what made that a regression rather than a saving:
59
- * it knew the extensions someone thought of, so \`.yaml\`, \`.sql\`, \`.opus\` and
60
- * \`.xhtml\` fell through and the caller's own string went out as the content
61
- * type. The tables below are GENERATED from mime-db instead, which is where
62
- * \`mime-types\` reads them too, so the resolution is the same one and stays
63
- * the same one.
64
- *
65
- * Regenerate with:
66
- *
67
- * node scripts/generate-mime.mjs
68
- *
69
- * Do not edit {@link TYPES} or {@link CHARSETS} by hand.
70
- *
71
- * @generated from mime-db ${dbVersion} (${count} extensions)
72
- */
73
-
74
- /** Extension → type. No leading dot; lowercase. */
75
- const TYPES: Record<string, string> = {
76
- ${rows}
77
- }
78
-
79
- /**
80
- * Types that declare a charset of their own, lowercased.
81
- *
82
- * Everything else under \`text/\` defaults to utf-8; everything else has none.
83
- * That is mime-db's \`charset\` field plus \`mime-types\`' \`text/*\` fallback.
84
- */
85
- const CHARSETS: Record<string, string> = {
86
- ${charsets}
87
- }
88
-
89
- /** The charset for a type, or \`undefined\` when it carries none. */
90
- function charsetFor(type: string): string | undefined {
91
- const base = type.split(';')[0].trim().toLowerCase()
92
- const declared = CHARSETS[base]
93
- if (declared !== undefined) return declared
94
- return base.startsWith('text/') ? 'utf-8' : undefined
95
- }
96
-
97
- /** The type for a bare extension, or \`undefined\` when it is not one we know. */
98
- export function lookupType(extension: string): string | undefined {
99
- const ext = extension.replace(/^.*\\./, '').toLowerCase()
100
- return TYPES[ext]
101
- }
102
-
103
- /**
104
- * A full \`Content-Type\` for an extension or a type (\`mime-types.contentType\`).
105
- *
106
- * Returns \`false\` for something it cannot resolve, as the package did, so the
107
- * caller keeps its existing fallback rather than writing \`content-type: false\`.
108
- */
109
- export function contentType(input: string): string | false {
110
- if (input.length === 0) return false
111
- // Already a type — possibly with parameters the caller set itself.
112
- const type = input.includes('/') ? input : lookupType(input)
113
- if (type === undefined) return false
114
- if (type.includes('charset=')) return type
115
- const charset = charsetFor(type)
116
- return charset === undefined ? type : \`\${type}; charset=\${charset}\`
117
- }
118
- `
119
- }
@@ -1,187 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Generate the TypeScript surface of the native modules FROM the Rust.
4
- *
5
- * `napi-derive`'s `type-def` feature emits one JSON line per exported item
6
- * while cargo compiles. Those lines are the source of truth: they are derived
7
- * from the `#[napi]` items themselves, so a signature cannot drift from the
8
- * Rust without this file changing.
9
- *
10
- * Hand-written interfaces are what we had before, and they DID drift — making
11
- * `Bus::on_request` synchronous changed the Rust with nothing on the TypeScript
12
- * side to notice.
13
- *
14
- * One thing napi-rs cannot infer: the shape of a `JsFunction` callback. It
15
- * emits `(...args: any[]) => any`. Those few are refined below, by name, and
16
- * the script fails if a refinement no longer matches anything — so the table
17
- * cannot rot either.
18
- *
19
- * TYPE_DEF_TMP_PATH=<file> cargo build -p <crates…>
20
- * node scripts/generate-napi-types.mjs <file> <out.d.ts>
21
- */
22
-
23
- import { readFileSync, writeFileSync } from 'node:fs'
24
-
25
- /**
26
- * Callback signatures napi-rs erases to `any`, restored here.
27
- *
28
- * Keyed by `<owner>.<method>`; the value replaces the whole parameter. Every
29
- * entry must match, or the script fails: a stale refinement is how a hand
30
- * annotation quietly stops describing the Rust.
31
- */
32
- /**
33
- * napi-derive 3 emits `callback: (arg: unknown) => unknown` where 2 emitted
34
- * `(...args: any[]) => any` — better, since it no longer reaches for `any`,
35
- * but a different string to match on. These refinements exist because the
36
- * generated shape says nothing about what the callback actually receives.
37
- */
38
- const CALLBACK_REFINEMENTS = {
39
- 'EventBus.subscribe': {
40
- from: 'callback: (arg: unknown) => unknown',
41
- to: 'callback: (eventJson: string) => void',
42
- },
43
- 'EventBus.onRequest': {
44
- from: 'callback: (arg: unknown) => unknown',
45
- to: 'callback: (eventJson: string, reply: (response: string) => void) => void',
46
- },
47
- 'HyperServer.onRequest': {
48
- // Only the argument is named. The `to` used to say
49
- // `(request: string) => Promise<string> | string`, which described the
50
- // boundary as it was BEFORE it stopped serialising: the Rust hands the
51
- // handler a JsObject and awaits a `NapiResponse`, and napi's own output
52
- // already said so. The refinement was overwriting a correct shape with a
53
- // stale one, and nothing noticed because every caller of `onRequest` was
54
- // outside the typecheck.
55
- from: 'callback: (arg: unknown) => Promise<NapiResponse>',
56
- to: 'callback: (request: Record<string, unknown>) => Promise<NapiResponse>',
57
- },
58
- 'HyperServer.onStreamDisconnect': {
59
- from: 'callback: (arg: unknown) => unknown',
60
- to: 'callback: (streamId: string) => void',
61
- },
62
- // The Rust hands over a serialised JsTaskPayload — `{ task_name,
63
- // scheduled_for_ms }` renamed to camelCase by serde.
64
- 'RustScheduler.register': {
65
- from: 'callback: (arg: unknown) => unknown',
66
- to: 'callback: (invocation: { taskName: string; scheduledForMs: number }) => void',
67
- },
68
- }
69
-
70
- const [input, output] = process.argv.slice(2)
71
- if (!input || !output) {
72
- console.error('usage: generate-napi-types.mjs <type-def file> <out.d.ts>')
73
- process.exit(2)
74
- }
75
-
76
- const entries = readFileSync(input, 'utf8')
77
- .split('\n')
78
- .map((l) => l.trim())
79
- .filter(Boolean)
80
- .map((l) => JSON.parse(l))
81
-
82
- const used = new Set()
83
-
84
- /** Apply the refinements that belong to `owner`, tracking which ones matched. */
85
- function refine(owner, body) {
86
- let out = body
87
- for (const [key, { from, to }] of Object.entries(CALLBACK_REFINEMENTS)) {
88
- const [entryOwner] = key.split('.')
89
- if (entryOwner !== owner) continue
90
- if (out.includes(from)) {
91
- out = out.replace(from, to)
92
- used.add(key)
93
- }
94
- }
95
- return out
96
- }
97
-
98
- /**
99
- * JSDoc as emitted by napi-derive, indented to sit above its member.
100
- *
101
- * `*` followed by `/` inside the text closes the comment early — a Rust doc
102
- * example holding a cron expression (`0 *​/5 * * *`) is enough to do it, and
103
- * the generated file then fails to parse. Escaped rather than stripped, so the
104
- * example still reads correctly.
105
- */
106
- function docBlock(doc, indent = '') {
107
- if (!doc) return ''
108
- // Escape every `*/` EXCEPT the one that closes the block. A Rust doc example
109
- // holding a cron expression (`0 */5 * * *`) closes the comment early
110
- // otherwise, and the generated file stops parsing — but escaping the closer
111
- // too breaks it just as thoroughly, whether the block spans one line or many.
112
- const closer = doc.lastIndexOf('*/')
113
- const escaped =
114
- closer === -1
115
- ? doc
116
- : doc.slice(0, closer).replaceAll('*/', '*\\/') + doc.slice(closer)
117
- return (
118
- escaped
119
- .split('\n')
120
- .filter((l) => l.length > 0)
121
- .map((l) => `${indent}${l}`)
122
- .join('\n') + '\n'
123
- )
124
- }
125
-
126
- const interfaces = entries.filter((e) => e.kind === 'interface')
127
- const structs = entries.filter((e) => e.kind === 'struct')
128
- const impls = new Map(entries.filter((e) => e.kind === 'impl').map((e) => [e.name, e]))
129
- const fns = entries.filter((e) => e.kind === 'fn')
130
-
131
- const out = [
132
- '// GENERATED FROM THE RUST — do not edit.',
133
- '//',
134
- '// Produced by scripts/generate-napi-types.mjs from napi-derive\'s type-def',
135
- '// output. Editing this file by hand puts it back where it started: a',
136
- '// description that can disagree with the code it describes.',
137
- '',
138
- ]
139
-
140
- for (const iface of interfaces) {
141
- out.push(docBlock(iface.js_doc))
142
- out.push(`export interface ${iface.name} {`)
143
- for (const line of iface.def.split('\n')) {
144
- out.push(line ? ` ${line.trim()}` : '')
145
- }
146
- out.push('}', '')
147
- }
148
-
149
- for (const struct of structs) {
150
- const impl = impls.get(struct.name)
151
- out.push(docBlock(struct.js_doc))
152
- out.push(`export declare class ${struct.name} {`)
153
- if (impl) {
154
- for (const line of refine(struct.name, impl.def).split('\n')) {
155
- out.push(line ? ` ${line.trim()}` : '')
156
- }
157
- }
158
- out.push('}', '')
159
- }
160
-
161
- for (const fn of fns) {
162
- out.push(docBlock(fn.js_doc))
163
- // napi-derive emits the whole declaration for a function, unlike a struct
164
- // where `def` holds only the members.
165
- const declaration = fn.def.trim()
166
- // napi-derive 3 emits a bare `function name(...)` where 2 emitted the
167
- // signature after the name; concatenating onto the former produced
168
- // `function xfunction x(...)`.
169
- const rendered = declaration.startsWith('export declare function')
170
- ? declaration
171
- : declaration.startsWith('function ')
172
- ? `export declare ${declaration}`
173
- : `export declare function ${fn.name}${declaration}`
174
- out.push(`${rendered};`, '')
175
- }
176
-
177
- const stale = Object.keys(CALLBACK_REFINEMENTS).filter((k) => !used.has(k))
178
- if (stale.length > 0) {
179
- console.error(
180
- `[napi-types] refinement(s) that matched nothing: ${stale.join(', ')}\n` +
181
- '[napi-types] the Rust changed under them — update or remove the entry.',
182
- )
183
- process.exit(1)
184
- }
185
-
186
- writeFileSync(output, out.join('\n'))
187
- console.log(`[napi-types] ${output} — ${interfaces.length} interface(s), ${structs.length} class(es), ${fns.length} function(s)`)