@slopware/sloppy-linux-x64 0.1.0-alpha.0

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 (434) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/bin/sloppy +0 -0
  4. package/bin/sloppyc +0 -0
  5. package/docs/KNOWN_LIMITATIONS.md +16 -0
  6. package/docs/LICENSES.md +6 -0
  7. package/docs/NOTICE.md +8 -0
  8. package/examples/README.md +140 -0
  9. package/examples/auth-api/README.md +20 -0
  10. package/examples/auth-api/app.js +61 -0
  11. package/examples/auth-api/appsettings.json +7 -0
  12. package/examples/auth-api/sloppy.json +5 -0
  13. package/examples/cache-basic/README.md +9 -0
  14. package/examples/cache-basic/app.js +32 -0
  15. package/examples/cache-hybrid-postgres/README.md +10 -0
  16. package/examples/cache-hybrid-postgres/app.js +27 -0
  17. package/examples/cache-output-api/README.md +10 -0
  18. package/examples/cache-output-api/app.js +35 -0
  19. package/examples/codec-base64-hex/README.md +14 -0
  20. package/examples/codec-base64-hex/app.js +15 -0
  21. package/examples/codec-checksums/README.md +15 -0
  22. package/examples/codec-checksums/app.js +8 -0
  23. package/examples/codec-compression/README.md +13 -0
  24. package/examples/codec-compression/app.js +9 -0
  25. package/examples/codec-streaming-compression/README.md +19 -0
  26. package/examples/codec-streaming-compression/app.js +16 -0
  27. package/examples/codec-text-binary/README.md +16 -0
  28. package/examples/codec-text-binary/app.js +17 -0
  29. package/examples/compiler-hello/README.md +71 -0
  30. package/examples/compiler-hello/app.js +7 -0
  31. package/examples/compiler-hello/expected/app.js +8 -0
  32. package/examples/compiler-hello/expected/app.js.map +53 -0
  33. package/examples/compiler-hello/expected/app.plan.json +229 -0
  34. package/examples/compiler-hello/expected/routes.slrt +0 -0
  35. package/examples/config-basic/README.md +13 -0
  36. package/examples/config-basic/app.js +13 -0
  37. package/examples/config-basic/appsettings.json +7 -0
  38. package/examples/config-secrets-redaction/README.md +9 -0
  39. package/examples/config-secrets-redaction/app.js +9 -0
  40. package/examples/config-secrets-redaction/appsettings.json +5 -0
  41. package/examples/config-strict-mode/README.md +7 -0
  42. package/examples/config-strict-mode/app.js +10 -0
  43. package/examples/config-strict-mode/appsettings.json +7 -0
  44. package/examples/configured-api/README.md +38 -0
  45. package/examples/configured-api/app.js +12 -0
  46. package/examples/configured-api/appsettings.Development.json +5 -0
  47. package/examples/configured-api/appsettings.json +6 -0
  48. package/examples/configured-api/sloppy.json +5 -0
  49. package/examples/core-config-secrets/README.md +10 -0
  50. package/examples/core-config-secrets/app.js +15 -0
  51. package/examples/core-fs-time-codec/README.md +9 -0
  52. package/examples/core-fs-time-codec/app.js +8 -0
  53. package/examples/core-network-time-codec/README.md +11 -0
  54. package/examples/core-network-time-codec/app.js +20 -0
  55. package/examples/core-policy-audit/README.md +7 -0
  56. package/examples/core-policy-audit/app.js +22 -0
  57. package/examples/core-process-time-codec/README.md +8 -0
  58. package/examples/core-process-time-codec/app.js +28 -0
  59. package/examples/core-worker-time/README.md +8 -0
  60. package/examples/core-worker-time/app.js +17 -0
  61. package/examples/crypto-hash-hmac/README.md +17 -0
  62. package/examples/crypto-hash-hmac/app.js +29 -0
  63. package/examples/crypto-password/README.md +21 -0
  64. package/examples/crypto-password/app.js +12 -0
  65. package/examples/crypto-random-token/README.md +16 -0
  66. package/examples/crypto-random-token/app.js +12 -0
  67. package/examples/crypto-secret-constant-time/README.md +21 -0
  68. package/examples/crypto-secret-constant-time/app.js +15 -0
  69. package/examples/data-foundation/README.md +39 -0
  70. package/examples/data-foundation/app.js +63 -0
  71. package/examples/dependency-graph/README.md +19 -0
  72. package/examples/dependency-graph/fixtures/graph-helper/index.js +3 -0
  73. package/examples/dependency-graph/fixtures/graph-helper/package.json +6 -0
  74. package/examples/dependency-graph/package.json +7 -0
  75. package/examples/dependency-graph/public/message.txt +1 -0
  76. package/examples/dependency-graph/sloppy.json +9 -0
  77. package/examples/dependency-graph/src/main.ts +8 -0
  78. package/examples/dogfood/README.md +23 -0
  79. package/examples/dogfood/dogfood.json +136 -0
  80. package/examples/dynamic-module-include/README.md +20 -0
  81. package/examples/dynamic-module-include/public/readme.txt +1 -0
  82. package/examples/dynamic-module-include/sloppy.json +12 -0
  83. package/examples/dynamic-module-include/src/main.ts +6 -0
  84. package/examples/dynamic-module-include/src/plugins/alpha.js +3 -0
  85. package/examples/dynamic-module-include/src/plugins/beta.js +3 -0
  86. package/examples/ergonomics/README.md +42 -0
  87. package/examples/ergonomics/app.js +38 -0
  88. package/examples/framework-controller/README.md +12 -0
  89. package/examples/framework-controller/app.js +31 -0
  90. package/examples/framework-di-services/README.md +17 -0
  91. package/examples/framework-di-services/app.ts +40 -0
  92. package/examples/framework-explicit-binding/README.md +12 -0
  93. package/examples/framework-explicit-binding/app.ts +34 -0
  94. package/examples/framework-hello/README.md +16 -0
  95. package/examples/framework-hello/app.ts +16 -0
  96. package/examples/framework-postgres-crud/README.md +73 -0
  97. package/examples/framework-postgres-crud/app.ts +64 -0
  98. package/examples/framework-sqlite-crud/README.md +52 -0
  99. package/examples/framework-sqlite-crud/app.ts +90 -0
  100. package/examples/framework-sqlite-crud/appsettings.json +11 -0
  101. package/examples/framework-sqlserver-crud/README.md +73 -0
  102. package/examples/framework-sqlserver-crud/app.ts +64 -0
  103. package/examples/framework-validation-errors/README.md +12 -0
  104. package/examples/framework-validation-errors/app.ts +16 -0
  105. package/examples/fs-basic/README.md +24 -0
  106. package/examples/fs-basic/app.js +12 -0
  107. package/examples/fs-roots-policy/README.md +14 -0
  108. package/examples/fs-roots-policy/app.js +4 -0
  109. package/examples/fs-streams/README.md +18 -0
  110. package/examples/fs-streams/app.js +11 -0
  111. package/examples/fs-watch/README.md +19 -0
  112. package/examples/fs-watch/app.js +11 -0
  113. package/examples/hello/README.md +63 -0
  114. package/examples/hello/app.js +19 -0
  115. package/examples/hello-minimal/README.md +51 -0
  116. package/examples/hello-minimal/sloppy.json +5 -0
  117. package/examples/hello-minimal/src/main.ts +9 -0
  118. package/examples/http-client-basic/README.md +11 -0
  119. package/examples/http-client-basic/app.js +46 -0
  120. package/examples/http-client-generated/README.md +22 -0
  121. package/examples/http-client-generated/openapi.json +45 -0
  122. package/examples/http-client-resilience/README.md +4 -0
  123. package/examples/http-client-resilience/app.js +38 -0
  124. package/examples/http-client-runtime-loopback/README.md +24 -0
  125. package/examples/http-client-testhost/README.md +4 -0
  126. package/examples/http-client-testhost/app.js +27 -0
  127. package/examples/http-client-testhost-package-mock/README.md +26 -0
  128. package/examples/http-client-typed/README.md +5 -0
  129. package/examples/http-client-typed/app.js +33 -0
  130. package/examples/modules-api/README.md +30 -0
  131. package/examples/modules-api/app.js +9 -0
  132. package/examples/modules-api/modules/routes.js +16 -0
  133. package/examples/modules-api/sloppy.json +5 -0
  134. package/examples/modules-basic/README.md +32 -0
  135. package/examples/modules-basic/app.js +41 -0
  136. package/examples/net-deadline-cancel/README.md +13 -0
  137. package/examples/net-deadline-cancel/app.js +34 -0
  138. package/examples/net-local-ipc/README.md +12 -0
  139. package/examples/net-local-ipc/app.js +46 -0
  140. package/examples/net-policy-strict/README.md +12 -0
  141. package/examples/net-policy-strict/app.js +34 -0
  142. package/examples/net-tcp-client/README.md +10 -0
  143. package/examples/net-tcp-client/app.js +23 -0
  144. package/examples/net-tcp-echo/README.md +11 -0
  145. package/examples/net-tcp-echo/app.js +45 -0
  146. package/examples/net-tcp-server/README.md +10 -0
  147. package/examples/net-tcp-server/app.js +28 -0
  148. package/examples/node-compat-path-events/README.md +15 -0
  149. package/examples/node-compat-path-events/sloppy.json +6 -0
  150. package/examples/node-compat-path-events/src/main.ts +15 -0
  151. package/examples/ops-compiler/README.md +9 -0
  152. package/examples/ops-compiler/app.js +26 -0
  153. package/examples/ops-health-metrics-management/README.md +14 -0
  154. package/examples/ops-health-metrics-management/app.js +24 -0
  155. package/examples/orm-basic/README.md +17 -0
  156. package/examples/orm-basic/app.js +82 -0
  157. package/examples/orm-cursor-export/README.md +16 -0
  158. package/examples/orm-cursor-export/app.js +28 -0
  159. package/examples/orm-migrations/README.md +14 -0
  160. package/examples/orm-migrations/migrations/.gitkeep +1 -0
  161. package/examples/orm-migrations/sloppy.json +9 -0
  162. package/examples/orm-migrations/src/app.ts +34 -0
  163. package/examples/orm-relations-includes/README.md +10 -0
  164. package/examples/orm-relations-includes/app.js +47 -0
  165. package/examples/orm-testservices/README.md +37 -0
  166. package/examples/orm-testservices/test.mjs +32 -0
  167. package/examples/os-runtime-api/README.md +11 -0
  168. package/examples/os-runtime-api/app.js +44 -0
  169. package/examples/package-zod-like/README.md +28 -0
  170. package/examples/package-zod-like/fixtures/zod-like/index.js +48 -0
  171. package/examples/package-zod-like/fixtures/zod-like/package.json +12 -0
  172. package/examples/package-zod-like/package.json +7 -0
  173. package/examples/package-zod-like/sloppy.json +6 -0
  174. package/examples/package-zod-like/src/main.ts +16 -0
  175. package/examples/postgres-basic/README.md +31 -0
  176. package/examples/postgres-basic/app.js +50 -0
  177. package/examples/prealpha-control-plane/README.md +50 -0
  178. package/examples/prealpha-control-plane/appsettings.Development.json +11 -0
  179. package/examples/prealpha-control-plane/appsettings.json +15 -0
  180. package/examples/prealpha-control-plane/sloppy.json +5 -0
  181. package/examples/prealpha-control-plane/src/db/schema.js +7 -0
  182. package/examples/prealpha-control-plane/src/db/seed.js +6 -0
  183. package/examples/prealpha-control-plane/src/main.js +21 -0
  184. package/examples/prealpha-control-plane/src/routes/apps.js +34 -0
  185. package/examples/prealpha-control-plane/src/routes/builds.js +25 -0
  186. package/examples/prealpha-control-plane/src/routes/deployments.js +19 -0
  187. package/examples/prealpha-control-plane/src/routes/diagnostics.js +11 -0
  188. package/examples/prealpha-control-plane/src/routes/health.js +27 -0
  189. package/examples/prealpha-control-plane/src/routes/projects.js +38 -0
  190. package/examples/prealpha-control-plane/src/services/diagnosticsSink.js +11 -0
  191. package/examples/prealpha-control-plane/src/services/repositories.js +9 -0
  192. package/examples/prealpha-control-plane/src/validation/schemas.js +6 -0
  193. package/examples/program-fs-process/README.md +31 -0
  194. package/examples/program-fs-process/sloppy.json +9 -0
  195. package/examples/program-fs-process/src/main.ts +27 -0
  196. package/examples/program-hello/README.md +32 -0
  197. package/examples/program-hello/main.ts +8 -0
  198. package/examples/program-hello/message.ts +1 -0
  199. package/examples/program-hello/sloppy.json +5 -0
  200. package/examples/rate-limit-auth/README.md +3 -0
  201. package/examples/rate-limit-auth/app.js +14 -0
  202. package/examples/rate-limit-basic/README.md +3 -0
  203. package/examples/rate-limit-basic/app.js +13 -0
  204. package/examples/rate-limit-redis/README.md +5 -0
  205. package/examples/rate-limit-redis/app.js +20 -0
  206. package/examples/rate-limit-testhost/README.md +4 -0
  207. package/examples/rate-limit-testhost/app.js +13 -0
  208. package/examples/rate-limit-websocket/README.md +3 -0
  209. package/examples/rate-limit-websocket/app.js +16 -0
  210. package/examples/realtime-auth/README.md +8 -0
  211. package/examples/realtime-auth/app.js +25 -0
  212. package/examples/realtime-auth/test.mjs +43 -0
  213. package/examples/realtime-chat/README.md +8 -0
  214. package/examples/realtime-chat/app.js +32 -0
  215. package/examples/realtime-chat/test.mjs +52 -0
  216. package/examples/realtime-dashboard/README.md +20 -0
  217. package/examples/realtime-dashboard/app.js +37 -0
  218. package/examples/realtime-presence/README.md +8 -0
  219. package/examples/realtime-presence/app.js +32 -0
  220. package/examples/realtime-presence/test.mjs +50 -0
  221. package/examples/realtime-testhost/README.md +8 -0
  222. package/examples/realtime-testhost/test.mjs +31 -0
  223. package/examples/redis-basic/README.md +17 -0
  224. package/examples/redis-basic/app.js +39 -0
  225. package/examples/redis-cache/README.md +14 -0
  226. package/examples/redis-cache/app.js +36 -0
  227. package/examples/redis-locks/README.md +13 -0
  228. package/examples/redis-locks/app.js +49 -0
  229. package/examples/request-context/README.md +32 -0
  230. package/examples/request-context/app.js +15 -0
  231. package/examples/sqlite-basic/README.md +52 -0
  232. package/examples/sqlite-basic/app.js +56 -0
  233. package/examples/sqlserver-basic/README.md +36 -0
  234. package/examples/sqlserver-basic/app.js +59 -0
  235. package/examples/static-files-basic/README.md +11 -0
  236. package/examples/static-files-basic/app.js +12 -0
  237. package/examples/static-files-basic/public/app.js +1 -0
  238. package/examples/static-files-basic/public/site.css +3 -0
  239. package/examples/static-files-package/README.md +12 -0
  240. package/examples/static-files-package/app.js +10 -0
  241. package/examples/static-files-package/public/index.html +2 -0
  242. package/examples/static-files-precompressed/README.md +12 -0
  243. package/examples/static-files-precompressed/app.js +11 -0
  244. package/examples/static-files-precompressed/public/app.js +1 -0
  245. package/examples/static-files-precompressed/public/app.js.br +0 -0
  246. package/examples/static-files-precompressed/public/app.js.gz +0 -0
  247. package/examples/static-files-spa/README.md +12 -0
  248. package/examples/static-files-spa/app.js +16 -0
  249. package/examples/static-files-spa/dist/assets/app.js +1 -0
  250. package/examples/static-files-spa/dist/index.html +4 -0
  251. package/examples/static-files-testhost/README.md +8 -0
  252. package/examples/static-files-testhost/app.js +13 -0
  253. package/examples/static-files-testhost/public/app.js +1 -0
  254. package/examples/static-files-testhost/public/app.js.gz +0 -0
  255. package/examples/static-files-testhost/test.mjs +38 -0
  256. package/examples/testhost-basic/README.md +26 -0
  257. package/examples/testhost-db/README.md +31 -0
  258. package/examples/testservices-postgres/README.md +68 -0
  259. package/examples/testservices-redis/README.md +71 -0
  260. package/examples/testservices-sqlserver/README.md +75 -0
  261. package/examples/time-basic/README.md +18 -0
  262. package/examples/time-basic/app.js +12 -0
  263. package/examples/time-deadline-cancellation/README.md +11 -0
  264. package/examples/time-deadline-cancellation/app.js +27 -0
  265. package/examples/time-fake-clock/README.md +14 -0
  266. package/examples/time-fake-clock/app.js +25 -0
  267. package/examples/time-interval-schedule/README.md +13 -0
  268. package/examples/time-interval-schedule/app.js +60 -0
  269. package/examples/users-api-sqlite/README.md +74 -0
  270. package/examples/users-api-sqlite/app.js +11 -0
  271. package/examples/users-api-sqlite/appsettings.Development.json +11 -0
  272. package/examples/users-api-sqlite/appsettings.json +11 -0
  273. package/examples/users-api-sqlite/modules/users.js +40 -0
  274. package/examples/users-api-sqlite/sloppy.json +5 -0
  275. package/examples/validation-errors/README.md +36 -0
  276. package/examples/validation-errors/app.js +14 -0
  277. package/examples/validation-errors/invalid-user.http +6 -0
  278. package/examples/validation-errors/sloppy.json +5 -0
  279. package/examples/web-dynamic-routes/README.md +17 -0
  280. package/examples/web-dynamic-routes/app.ts +27 -0
  281. package/examples/webhooks-basic/README.md +11 -0
  282. package/examples/webhooks-basic/app.js +48 -0
  283. package/examples/websocket-auth/README.md +8 -0
  284. package/examples/websocket-auth/app.js +16 -0
  285. package/examples/websocket-echo/README.md +9 -0
  286. package/examples/websocket-echo/app.js +36 -0
  287. package/examples/websocket-json-schema/README.md +5 -0
  288. package/examples/websocket-json-schema/app.js +25 -0
  289. package/examples/websocket-testhost/README.md +11 -0
  290. package/examples/websocket-testhost/test.mjs +49 -0
  291. package/examples/workers-background-service/README.md +7 -0
  292. package/examples/workers-background-service/app.js +16 -0
  293. package/examples/workers-js-isolate/README.md +8 -0
  294. package/examples/workers-js-isolate/app.js +19 -0
  295. package/examples/workers-js-isolate/workers/parser.ts +11 -0
  296. package/examples/workers-shutdown/README.md +6 -0
  297. package/examples/workers-shutdown/app.js +26 -0
  298. package/examples/workers-workerpool/README.md +6 -0
  299. package/examples/workers-workerpool/app.js +23 -0
  300. package/examples/workers-workqueue/README.md +8 -0
  301. package/examples/workers-workqueue/app.js +24 -0
  302. package/manifest.json +59 -0
  303. package/package.json +34 -0
  304. package/stdlib/sloppy/README.md +177 -0
  305. package/stdlib/sloppy/app.js +2142 -0
  306. package/stdlib/sloppy/auth.js +1813 -0
  307. package/stdlib/sloppy/bootstrap.manifest.json +83 -0
  308. package/stdlib/sloppy/cache.js +1542 -0
  309. package/stdlib/sloppy/codec.js +1153 -0
  310. package/stdlib/sloppy/config.js +61 -0
  311. package/stdlib/sloppy/crypto.js +312 -0
  312. package/stdlib/sloppy/data.js +2945 -0
  313. package/stdlib/sloppy/ffi.js +185 -0
  314. package/stdlib/sloppy/fs.js +795 -0
  315. package/stdlib/sloppy/health.js +603 -0
  316. package/stdlib/sloppy/http.js +1595 -0
  317. package/stdlib/sloppy/index.js +59 -0
  318. package/stdlib/sloppy/internal/bytes.js +31 -0
  319. package/stdlib/sloppy/internal/capabilities.js +155 -0
  320. package/stdlib/sloppy/internal/config.js +640 -0
  321. package/stdlib/sloppy/internal/disposable.js +31 -0
  322. package/stdlib/sloppy/internal/headers.js +63 -0
  323. package/stdlib/sloppy/internal/intrinsics.js +2 -0
  324. package/stdlib/sloppy/internal/json.js +20 -0
  325. package/stdlib/sloppy/internal/logging.js +278 -0
  326. package/stdlib/sloppy/internal/modules.js +405 -0
  327. package/stdlib/sloppy/internal/redaction.js +87 -0
  328. package/stdlib/sloppy/internal/routes.js +2279 -0
  329. package/stdlib/sloppy/internal/runtime-classic.js +19837 -0
  330. package/stdlib/sloppy/internal/services.js +690 -0
  331. package/stdlib/sloppy/internal/shared.js +32 -0
  332. package/stdlib/sloppy/internal/testhost-diagnostics.js +88 -0
  333. package/stdlib/sloppy/internal/testhost-http-server.js +238 -0
  334. package/stdlib/sloppy/internal/testhost-http.js +118 -0
  335. package/stdlib/sloppy/internal/testhost-loopback.js +50 -0
  336. package/stdlib/sloppy/internal/testservices-docker.js +154 -0
  337. package/stdlib/sloppy/internal/validation.js +117 -0
  338. package/stdlib/sloppy/metrics.js +427 -0
  339. package/stdlib/sloppy/net.js +5208 -0
  340. package/stdlib/sloppy/node/assert/strict.js +39 -0
  341. package/stdlib/sloppy/node/assert.js +228 -0
  342. package/stdlib/sloppy/node/buffer.js +247 -0
  343. package/stdlib/sloppy/node/console.js +33 -0
  344. package/stdlib/sloppy/node/constants.js +9 -0
  345. package/stdlib/sloppy/node/crypto.js +89 -0
  346. package/stdlib/sloppy/node/diagnostics_channel.js +41 -0
  347. package/stdlib/sloppy/node/events.js +113 -0
  348. package/stdlib/sloppy/node/fs/promises.js +27 -0
  349. package/stdlib/sloppy/node/fs.js +280 -0
  350. package/stdlib/sloppy/node/http.js +11 -0
  351. package/stdlib/sloppy/node/https.js +11 -0
  352. package/stdlib/sloppy/node/module.js +40 -0
  353. package/stdlib/sloppy/node/os.js +22 -0
  354. package/stdlib/sloppy/node/path.js +78 -0
  355. package/stdlib/sloppy/node/perf_hooks.js +12 -0
  356. package/stdlib/sloppy/node/process.js +129 -0
  357. package/stdlib/sloppy/node/querystring.js +21 -0
  358. package/stdlib/sloppy/node/stream/promises.js +3 -0
  359. package/stdlib/sloppy/node/stream.js +132 -0
  360. package/stdlib/sloppy/node/string_decoder.js +23 -0
  361. package/stdlib/sloppy/node/timers.js +26 -0
  362. package/stdlib/sloppy/node/tty.js +18 -0
  363. package/stdlib/sloppy/node/url.js +17 -0
  364. package/stdlib/sloppy/node/util.js +95 -0
  365. package/stdlib/sloppy/node/zlib.js +72 -0
  366. package/stdlib/sloppy/orm.js +2188 -0
  367. package/stdlib/sloppy/os.js +580 -0
  368. package/stdlib/sloppy/problem-details.js +29 -0
  369. package/stdlib/sloppy/providers/sqlite.js +26 -0
  370. package/stdlib/sloppy/rate-limit.js +856 -0
  371. package/stdlib/sloppy/realtime.js +1508 -0
  372. package/stdlib/sloppy/redis.js +1272 -0
  373. package/stdlib/sloppy/request-id.js +184 -0
  374. package/stdlib/sloppy/request-logging.js +101 -0
  375. package/stdlib/sloppy/results.js +933 -0
  376. package/stdlib/sloppy/schema.js +546 -0
  377. package/stdlib/sloppy/testing.js +4081 -0
  378. package/stdlib/sloppy/testservices.js +1041 -0
  379. package/stdlib/sloppy/time.js +894 -0
  380. package/stdlib/sloppy/webhooks.js +1330 -0
  381. package/stdlib/sloppy/workers.js +986 -0
  382. package/templates/api/README.md +82 -0
  383. package/templates/api/appsettings.Development.json +14 -0
  384. package/templates/api/appsettings.json +13 -0
  385. package/templates/api/data/.gitkeep +1 -0
  386. package/templates/api/gitignore +4 -0
  387. package/templates/api/migrations/0001_create_users.sql +1 -0
  388. package/templates/api/package.json +16 -0
  389. package/templates/api/public/hello.txt +1 -0
  390. package/templates/api/sloppy.json +14 -0
  391. package/templates/api/src/config.ts +1 -0
  392. package/templates/api/src/db/migrate.ts +14 -0
  393. package/templates/api/src/db/schema.ts +4 -0
  394. package/templates/api/src/db/usersRepository.ts +23 -0
  395. package/templates/api/src/main.ts +18 -0
  396. package/templates/api/src/models/user.ts +7 -0
  397. package/templates/api/src/routes/health.ts +20 -0
  398. package/templates/api/src/routes/users.ts +40 -0
  399. package/templates/api/src/services/usersService.ts +21 -0
  400. package/templates/api/tsconfig.json +15 -0
  401. package/templates/cli/README.md +16 -0
  402. package/templates/cli/gitignore +2 -0
  403. package/templates/cli/package.json +13 -0
  404. package/templates/cli/sloppy.json +6 -0
  405. package/templates/cli/src/commands/echo.ts +9 -0
  406. package/templates/cli/src/commands/inspect.ts +20 -0
  407. package/templates/cli/src/main.ts +50 -0
  408. package/templates/cli/tsconfig.json +15 -0
  409. package/templates/minimal-api/README.md +14 -0
  410. package/templates/minimal-api/gitignore +3 -0
  411. package/templates/minimal-api/package.json +14 -0
  412. package/templates/minimal-api/sloppy.json +5 -0
  413. package/templates/minimal-api/src/main.ts +9 -0
  414. package/templates/minimal-api/tsconfig.json +15 -0
  415. package/templates/node-compat/README.md +40 -0
  416. package/templates/node-compat/gitignore +2 -0
  417. package/templates/node-compat/package.json +11 -0
  418. package/templates/node-compat/sloppy.json +6 -0
  419. package/templates/node-compat/src/main.ts +40 -0
  420. package/templates/package-api/README.md +44 -0
  421. package/templates/package-api/fixtures/validator-lite/index.js +7 -0
  422. package/templates/package-api/fixtures/validator-lite/package.json +6 -0
  423. package/templates/package-api/gitignore +3 -0
  424. package/templates/package-api/package.json +17 -0
  425. package/templates/package-api/sloppy.json +5 -0
  426. package/templates/package-api/src/main.ts +10 -0
  427. package/templates/package-api/src/routes/health.ts +5 -0
  428. package/templates/package-api/src/routes/users.ts +12 -0
  429. package/templates/package-api/tsconfig.json +15 -0
  430. package/templates/program/README.md +12 -0
  431. package/templates/program/gitignore +1 -0
  432. package/templates/program/package.json +10 -0
  433. package/templates/program/sloppy.json +6 -0
  434. package/templates/program/src/main.ts +9 -0
@@ -0,0 +1,1153 @@
1
+ import { isPlainObject } from "./internal/validation.js";
2
+ const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3
+ const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
4
+ const HEX_ALPHABET = "0123456789abcdef";
5
+
6
+ class CodecError extends Error {
7
+ constructor(code, message) {
8
+ super(`${code}: ${message}`);
9
+ this.name = "CodecError";
10
+ this.code = code;
11
+ }
12
+ }
13
+
14
+ function codecError(code, message) {
15
+ return new CodecError(code, message);
16
+ }
17
+
18
+ function requireBytes(value, operation) {
19
+ if (!(value instanceof Uint8Array)) {
20
+ throw new TypeError(`${operation} requires Uint8Array bytes.`);
21
+ }
22
+ return value;
23
+ }
24
+
25
+ function requireString(value, operation) {
26
+ if (typeof value !== "string") {
27
+ throw new TypeError(`${operation} requires a string.`);
28
+ }
29
+ return value;
30
+ }
31
+
32
+ function validateOptionsObject(options, operation) {
33
+ if (options === undefined) {
34
+ return {};
35
+ }
36
+ if (!isPlainObject(options)) {
37
+ throw new TypeError(`${operation} options must be an object when provided.`);
38
+ }
39
+ return options;
40
+ }
41
+
42
+ function rejectUnknownOptions(options, allowed, operation) {
43
+ for (const key of Object.keys(options)) {
44
+ if (!allowed.has(key)) {
45
+ throw new TypeError(`${operation} does not support option ${key}.`);
46
+ }
47
+ }
48
+ }
49
+
50
+ function encodeBase64(bytes, alphabet, padding) {
51
+ requireBytes(bytes, "Base64.encode");
52
+ let output = "";
53
+ for (let offset = 0; offset < bytes.length; offset += 3) {
54
+ const b0 = bytes[offset];
55
+ const b1 = offset + 1 < bytes.length ? bytes[offset + 1] : 0;
56
+ const b2 = offset + 2 < bytes.length ? bytes[offset + 2] : 0;
57
+ const triple = (b0 << 16) | (b1 << 8) | b2;
58
+ output += alphabet[(triple >>> 18) & 0x3f];
59
+ output += alphabet[(triple >>> 12) & 0x3f];
60
+ output += offset + 1 < bytes.length ? alphabet[(triple >>> 6) & 0x3f] : "=";
61
+ output += offset + 2 < bytes.length ? alphabet[triple & 0x3f] : "=";
62
+ }
63
+ return padding ? output : output.replace(/=+$/u, "");
64
+ }
65
+
66
+ function makeAlphabetMap(alphabet) {
67
+ const map = new Map();
68
+ for (let index = 0; index < alphabet.length; index += 1) {
69
+ map.set(alphabet[index], index);
70
+ }
71
+ return map;
72
+ }
73
+
74
+ const BASE64_MAP = makeAlphabetMap(BASE64_ALPHABET);
75
+ const BASE64URL_MAP = makeAlphabetMap(BASE64URL_ALPHABET);
76
+
77
+ function normalizeBase64Input(text, kind, paddingMode) {
78
+ const code = kind === "base64url" ? "SLOPPY_E_CODEC_INVALID_BASE64URL" : "SLOPPY_E_CODEC_INVALID_BASE64";
79
+ if (text.length === 0) {
80
+ return text;
81
+ }
82
+ if (/\s/u.test(text)) {
83
+ throw codecError(code, `${kind} input must not contain whitespace.`);
84
+ }
85
+ const firstPadding = text.indexOf("=");
86
+ if (firstPadding !== -1 && !/^=+$/u.test(text.slice(firstPadding))) {
87
+ throw codecError(code, `${kind} padding must appear only at the end.`);
88
+ }
89
+ if (kind === "base64url") {
90
+ if (/[+/]/u.test(text)) {
91
+ throw codecError(code, "Base64Url input must use the URL-safe alphabet.");
92
+ }
93
+ if (paddingMode === "forbidden" && firstPadding !== -1) {
94
+ throw codecError(code, "Base64Url padding is forbidden for this decode.");
95
+ }
96
+ if (paddingMode === "required" && text.length % 4 !== 0) {
97
+ throw codecError(code, "Base64Url padding is required for this decode.");
98
+ }
99
+ } else if (/[-_]/u.test(text)) {
100
+ throw codecError(code, "Base64 input must use the standard alphabet.");
101
+ }
102
+ const paddingCount = firstPadding === -1 ? 0 : text.length - firstPadding;
103
+ if (paddingCount > 2) {
104
+ throw codecError(code, `${kind} input has invalid padding.`);
105
+ }
106
+ if (text.length % 4 === 1) {
107
+ throw codecError(code, `${kind} input length is impossible.`);
108
+ }
109
+ if (text.length % 4 !== 0) {
110
+ if (kind !== "base64url" || paddingMode === "required" || paddingCount !== 0) {
111
+ throw codecError(code, `${kind} input length is invalid.`);
112
+ }
113
+ return text.padEnd(text.length + (4 - (text.length % 4)), "=");
114
+ }
115
+ return text;
116
+ }
117
+
118
+ function decodeBase64(text, alphabetMap, kind, paddingMode) {
119
+ text = normalizeBase64Input(requireString(text, `${kind}.decode`), kind, paddingMode);
120
+ const code = kind === "base64url" ? "SLOPPY_E_CODEC_INVALID_BASE64URL" : "SLOPPY_E_CODEC_INVALID_BASE64";
121
+ const bytes = [];
122
+ for (let offset = 0; offset < text.length; offset += 4) {
123
+ const c0 = text[offset];
124
+ const c1 = text[offset + 1];
125
+ const c2 = text[offset + 2];
126
+ const c3 = text[offset + 3];
127
+ const p2 = c2 === "=";
128
+ const p3 = c3 === "=";
129
+ if (c0 === "=" || c1 === "=" || (p2 && !p3)) {
130
+ throw codecError(code, `${kind} input has invalid padding placement.`);
131
+ }
132
+ const v0 = alphabetMap.get(c0);
133
+ const v1 = alphabetMap.get(c1);
134
+ const v2 = p2 ? 0 : alphabetMap.get(c2);
135
+ const v3 = p3 ? 0 : alphabetMap.get(c3);
136
+ if (v0 === undefined || v1 === undefined || v2 === undefined || v3 === undefined) {
137
+ throw codecError(code, `${kind} input contains a non-alphabet character.`);
138
+ }
139
+ if (p2 && (v1 & 0x0f) !== 0) {
140
+ throw codecError(code, `${kind} input has non-canonical trailing bits.`);
141
+ }
142
+ if (!p2 && p3 && (v2 & 0x03) !== 0) {
143
+ throw codecError(code, `${kind} input has non-canonical trailing bits.`);
144
+ }
145
+ const triple = (v0 << 18) | (v1 << 12) | (v2 << 6) | v3;
146
+ bytes.push((triple >>> 16) & 0xff);
147
+ if (!p2) {
148
+ bytes.push((triple >>> 8) & 0xff);
149
+ }
150
+ if (!p3) {
151
+ bytes.push(triple & 0xff);
152
+ }
153
+ }
154
+ return new Uint8Array(bytes);
155
+ }
156
+
157
+ function parseBase64UrlEncodeOptions(options) {
158
+ options = validateOptionsObject(options, "Base64Url.encode");
159
+ rejectUnknownOptions(options, new Set(["padding"]), "Base64Url.encode");
160
+ if (options.padding === undefined) {
161
+ return false;
162
+ }
163
+ if (typeof options.padding !== "boolean") {
164
+ throw new TypeError("Base64Url.encode padding must be boolean.");
165
+ }
166
+ return options.padding;
167
+ }
168
+
169
+ function parseBase64UrlDecodeOptions(options) {
170
+ options = validateOptionsObject(options, "Base64Url.decode");
171
+ rejectUnknownOptions(options, new Set(["padding"]), "Base64Url.decode");
172
+ const padding = options.padding ?? "optional";
173
+ if (padding !== "optional" && padding !== "required" && padding !== "forbidden") {
174
+ throw new TypeError('Base64Url.decode padding must be "optional", "required", or "forbidden".');
175
+ }
176
+ return padding;
177
+ }
178
+
179
+ function decodeHexNibble(code) {
180
+ if (code >= 48 && code <= 57) {
181
+ return code - 48;
182
+ }
183
+ if (code >= 65 && code <= 70) {
184
+ return code - 55;
185
+ }
186
+ if (code >= 97 && code <= 102) {
187
+ return code - 87;
188
+ }
189
+ return -1;
190
+ }
191
+
192
+ function encodeUtf8(text) {
193
+ text = requireString(text, "Text.utf8.encode");
194
+ const bytes = [];
195
+ for (const char of text) {
196
+ let codePoint = char.codePointAt(0);
197
+ if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
198
+ codePoint = 0xfffd;
199
+ }
200
+ if (codePoint <= 0x7f) {
201
+ bytes.push(codePoint);
202
+ } else if (codePoint <= 0x7ff) {
203
+ bytes.push(0xc0 | (codePoint >>> 6), 0x80 | (codePoint & 0x3f));
204
+ } else if (codePoint <= 0xffff) {
205
+ bytes.push(0xe0 | (codePoint >>> 12), 0x80 | ((codePoint >>> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
206
+ } else {
207
+ bytes.push(
208
+ 0xf0 | (codePoint >>> 18),
209
+ 0x80 | ((codePoint >>> 12) & 0x3f),
210
+ 0x80 | ((codePoint >>> 6) & 0x3f),
211
+ 0x80 | (codePoint & 0x3f),
212
+ );
213
+ }
214
+ }
215
+ return new Uint8Array(bytes);
216
+ }
217
+
218
+ function utf8Malformed(fatal, message) {
219
+ if (fatal) {
220
+ throw codecError("SLOPPY_E_CODEC_MALFORMED_UTF8", message);
221
+ }
222
+ return "\uFFFD";
223
+ }
224
+
225
+ function isContinuation(byte) {
226
+ return byte >= 0x80 && byte <= 0xbf;
227
+ }
228
+
229
+ function decodeUtf8Bytes(bytes, options) {
230
+ const fatal = options.fatal;
231
+ const stream = options.stream;
232
+ let output = "";
233
+ let offset = 0;
234
+ while (offset < bytes.length) {
235
+ const b0 = bytes[offset];
236
+ if (b0 <= 0x7f) {
237
+ output += String.fromCodePoint(b0);
238
+ offset += 1;
239
+ continue;
240
+ }
241
+ let needed = 0;
242
+ let codePoint = 0;
243
+ let minSecond = 0x80;
244
+ let maxSecond = 0xbf;
245
+ if (b0 >= 0xc2 && b0 <= 0xdf) {
246
+ needed = 2;
247
+ codePoint = b0 & 0x1f;
248
+ } else if (b0 >= 0xe0 && b0 <= 0xef) {
249
+ needed = 3;
250
+ codePoint = b0 & 0x0f;
251
+ if (b0 === 0xe0) {
252
+ minSecond = 0xa0;
253
+ } else if (b0 === 0xed) {
254
+ maxSecond = 0x9f;
255
+ }
256
+ } else if (b0 >= 0xf0 && b0 <= 0xf4) {
257
+ needed = 4;
258
+ codePoint = b0 & 0x07;
259
+ if (b0 === 0xf0) {
260
+ minSecond = 0x90;
261
+ } else if (b0 === 0xf4) {
262
+ maxSecond = 0x8f;
263
+ }
264
+ } else {
265
+ output += utf8Malformed(fatal, "UTF-8 input contains an invalid leading byte.");
266
+ offset += 1;
267
+ continue;
268
+ }
269
+ if (offset + 1 >= bytes.length) {
270
+ if (stream) {
271
+ break;
272
+ }
273
+ output += utf8Malformed(fatal, "UTF-8 input ended with an incomplete sequence.");
274
+ offset = bytes.length;
275
+ break;
276
+ }
277
+ const b1 = bytes[offset + 1];
278
+ if (b1 < minSecond || b1 > maxSecond) {
279
+ output += utf8Malformed(fatal, "UTF-8 input contains an invalid continuation byte.");
280
+ offset += 1;
281
+ continue;
282
+ }
283
+ if (offset + needed > bytes.length) {
284
+ if (stream) {
285
+ break;
286
+ }
287
+ output += utf8Malformed(fatal, "UTF-8 input ended with an incomplete sequence.");
288
+ offset = bytes.length;
289
+ break;
290
+ }
291
+ codePoint = (codePoint << 6) | (b1 & 0x3f);
292
+ let valid = true;
293
+ let invalidIndex = 0;
294
+ for (let index = 2; index < needed; index += 1) {
295
+ const next = bytes[offset + index];
296
+ if (!isContinuation(next)) {
297
+ valid = false;
298
+ invalidIndex = index;
299
+ break;
300
+ }
301
+ codePoint = (codePoint << 6) | (next & 0x3f);
302
+ }
303
+ if (!valid) {
304
+ output += utf8Malformed(fatal, "UTF-8 input contains an invalid continuation byte.");
305
+ offset += invalidIndex;
306
+ continue;
307
+ }
308
+ output += String.fromCodePoint(codePoint);
309
+ offset += needed;
310
+ }
311
+ return { output, remaining: bytes.slice(offset) };
312
+ }
313
+
314
+ function parseUtf8Options(options, operation) {
315
+ options = validateOptionsObject(options, operation);
316
+ rejectUnknownOptions(options, new Set(["fatal"]), operation);
317
+ if (options.fatal !== undefined && typeof options.fatal !== "boolean") {
318
+ throw new TypeError(`${operation} fatal must be boolean.`);
319
+ }
320
+ return { fatal: options.fatal === true };
321
+ }
322
+
323
+ function parseDecodeChunkOptions(options) {
324
+ options = validateOptionsObject(options, "Text.utf8.decoder.decode");
325
+ rejectUnknownOptions(options, new Set(["stream"]), "Text.utf8.decoder.decode");
326
+ if (options.stream !== undefined && typeof options.stream !== "boolean") {
327
+ throw new TypeError("Text.utf8.decoder.decode stream must be boolean.");
328
+ }
329
+ return { stream: options.stream === true };
330
+ }
331
+
332
+ class Utf8StreamingDecoder {
333
+ constructor(options = undefined) {
334
+ this._fatal = parseUtf8Options(options, "Text.utf8.decoder").fatal;
335
+ this._pending = new Uint8Array(0);
336
+ }
337
+
338
+ decode(chunk, options = undefined) {
339
+ chunk = requireBytes(chunk, "Text.utf8.decoder.decode");
340
+ const { stream } = parseDecodeChunkOptions(options);
341
+ const input = new Uint8Array(this._pending.length + chunk.length);
342
+ input.set(this._pending, 0);
343
+ input.set(chunk, this._pending.length);
344
+ const decoded = decodeUtf8Bytes(input, { fatal: this._fatal, stream });
345
+ this._pending = decoded.remaining;
346
+ return decoded.output;
347
+ }
348
+
349
+ finish() {
350
+ const decoded = decodeUtf8Bytes(this._pending, { fatal: this._fatal, stream: false });
351
+ this._pending = new Uint8Array(0);
352
+ return decoded.output;
353
+ }
354
+ }
355
+
356
+ const Base64 = Object.freeze({
357
+ encode(bytes) {
358
+ return encodeBase64(requireBytes(bytes, "Base64.encode"), BASE64_ALPHABET, true);
359
+ },
360
+ decode(text) {
361
+ return decodeBase64(text, BASE64_MAP, "base64", "required");
362
+ },
363
+ });
364
+
365
+ const Base64Url = Object.freeze({
366
+ encode(bytes, options = undefined) {
367
+ return encodeBase64(requireBytes(bytes, "Base64Url.encode"), BASE64URL_ALPHABET, parseBase64UrlEncodeOptions(options));
368
+ },
369
+ decode(text, options = undefined) {
370
+ return decodeBase64(text, BASE64URL_MAP, "base64url", parseBase64UrlDecodeOptions(options));
371
+ },
372
+ });
373
+
374
+ const Hex = Object.freeze({
375
+ encode(bytes) {
376
+ bytes = requireBytes(bytes, "Hex.encode");
377
+ let output = "";
378
+ for (const byte of bytes) {
379
+ output += HEX_ALPHABET[byte >>> 4] + HEX_ALPHABET[byte & 0x0f];
380
+ }
381
+ return output;
382
+ },
383
+ decode(text) {
384
+ text = requireString(text, "Hex.decode");
385
+ if (text.length % 2 !== 0) {
386
+ throw codecError("SLOPPY_E_CODEC_INVALID_HEX", "Hex input must have an even digit count.");
387
+ }
388
+ const bytes = new Uint8Array(text.length / 2);
389
+ for (let offset = 0; offset < text.length; offset += 2) {
390
+ const hi = decodeHexNibble(text.charCodeAt(offset));
391
+ const lo = decodeHexNibble(text.charCodeAt(offset + 1));
392
+ if (hi < 0 || lo < 0) {
393
+ throw codecError("SLOPPY_E_CODEC_INVALID_HEX", "Hex input contains a non-hex digit.");
394
+ }
395
+ bytes[offset / 2] = (hi << 4) | lo;
396
+ }
397
+ return bytes;
398
+ },
399
+ });
400
+
401
+ const Text = Object.freeze({
402
+ utf8: Object.freeze({
403
+ encode: encodeUtf8,
404
+ decode(bytes, options = undefined) {
405
+ bytes = requireBytes(bytes, "Text.utf8.decode");
406
+ return decodeUtf8Bytes(bytes, { ...parseUtf8Options(options, "Text.utf8.decode"), stream: false }).output;
407
+ },
408
+ decoder(options = undefined) {
409
+ return new Utf8StreamingDecoder(options);
410
+ },
411
+ }),
412
+ });
413
+
414
+ const DEFAULT_BINARY_WRITER_CAPACITY = 64;
415
+ const DEFAULT_BINARY_WRITER_MAX_CAPACITY = 64 * 1024 * 1024;
416
+ const UINT64_MAX = (1n << 64n) - 1n;
417
+ const INT64_MIN = -(1n << 63n);
418
+ const INT64_MAX = (1n << 63n) - 1n;
419
+
420
+ function binaryBoundsError(message) {
421
+ return codecError("SLOPPY_E_CODEC_BINARY_READ_OUT_OF_BOUNDS", message);
422
+ }
423
+
424
+ function binaryFieldError(message) {
425
+ return codecError("SLOPPY_E_CODEC_BINARY_INVALID_ENDIAN_OR_FIELD_SIZE", message);
426
+ }
427
+
428
+ function requireNonNegativeInteger(value, operation) {
429
+ if (!Number.isSafeInteger(value) || value < 0) {
430
+ throw binaryFieldError(`${operation} requires a non-negative safe integer.`);
431
+ }
432
+ return value;
433
+ }
434
+
435
+ function requireBinaryCapacity(value, operation) {
436
+ value = requireNonNegativeInteger(value, operation);
437
+ if (value > DEFAULT_BINARY_WRITER_MAX_CAPACITY) {
438
+ throw binaryFieldError(`${operation} must not exceed the Binary.writer runtime maximum.`);
439
+ }
440
+ return value;
441
+ }
442
+
443
+ function requireIntegerInRange(value, min, max, operation) {
444
+ if (!Number.isInteger(value) || value < min || value > max) {
445
+ throw binaryFieldError(`${operation} value is outside the supported field range.`);
446
+ }
447
+ return value;
448
+ }
449
+
450
+ function requireBigIntInRange(value, min, max, operation) {
451
+ if (typeof value !== "bigint" || value < min || value > max) {
452
+ throw binaryFieldError(`${operation} value is outside the supported field range.`);
453
+ }
454
+ return value;
455
+ }
456
+
457
+ function readUnsignedNumber(bytes, offset, width, littleEndian) {
458
+ let value = 0;
459
+ for (let index = 0; index < width; index += 1) {
460
+ const byte = littleEndian ? bytes[offset + index] : bytes[offset + width - 1 - index];
461
+ value += byte * 2 ** (8 * index);
462
+ }
463
+ return value;
464
+ }
465
+
466
+ function readUnsignedBigInt(bytes, offset, width, littleEndian) {
467
+ let value = 0n;
468
+ if (littleEndian) {
469
+ for (let index = width - 1; index >= 0; index -= 1) {
470
+ value = (value << 8n) | BigInt(bytes[offset + index]);
471
+ }
472
+ } else {
473
+ for (let index = 0; index < width; index += 1) {
474
+ value = (value << 8n) | BigInt(bytes[offset + index]);
475
+ }
476
+ }
477
+ return value;
478
+ }
479
+
480
+ function writeUnsignedNumber(bytes, offset, width, value, littleEndian) {
481
+ for (let index = 0; index < width; index += 1) {
482
+ const byte = Math.floor(value / 2 ** (8 * index)) & 0xff;
483
+ bytes[offset + (littleEndian ? index : width - 1 - index)] = byte;
484
+ }
485
+ }
486
+
487
+ function writeUnsignedBigInt(bytes, offset, width, value, littleEndian) {
488
+ for (let index = 0; index < width; index += 1) {
489
+ const byte = Number((value >> (8n * BigInt(index))) & 0xffn);
490
+ bytes[offset + (littleEndian ? index : width - 1 - index)] = byte;
491
+ }
492
+ }
493
+
494
+ class BinaryReader {
495
+ #bytes;
496
+ #offset = 0;
497
+
498
+ constructor(bytes) {
499
+ this.#bytes = new Uint8Array(requireBytes(bytes, "Binary.reader"));
500
+ }
501
+
502
+ position() {
503
+ return this.#offset;
504
+ }
505
+
506
+ remaining() {
507
+ return this.#bytes.length - this.#offset;
508
+ }
509
+
510
+ seek(position) {
511
+ position = requireNonNegativeInteger(position, "BinaryReader.seek");
512
+ if (position > this.#bytes.length) {
513
+ throw binaryBoundsError("BinaryReader.seek moved beyond the input length.");
514
+ }
515
+ this.#offset = position;
516
+ return this;
517
+ }
518
+
519
+ bytes(length) {
520
+ length = requireNonNegativeInteger(length, "BinaryReader.bytes");
521
+ const offset = this.#reserve(length, "BinaryReader.bytes");
522
+ return this.#bytes.slice(offset, offset + length);
523
+ }
524
+
525
+ u8() {
526
+ return this.#readNumber(1, false, false, "BinaryReader.u8");
527
+ }
528
+
529
+ i8() {
530
+ return this.#readNumber(1, true, false, "BinaryReader.i8");
531
+ }
532
+
533
+ u16le() {
534
+ return this.#readNumber(2, false, true, "BinaryReader.u16le");
535
+ }
536
+
537
+ u16be() {
538
+ return this.#readNumber(2, false, false, "BinaryReader.u16be");
539
+ }
540
+
541
+ i16le() {
542
+ return this.#readNumber(2, true, true, "BinaryReader.i16le");
543
+ }
544
+
545
+ i16be() {
546
+ return this.#readNumber(2, true, false, "BinaryReader.i16be");
547
+ }
548
+
549
+ u32le() {
550
+ return this.#readNumber(4, false, true, "BinaryReader.u32le");
551
+ }
552
+
553
+ u32be() {
554
+ return this.#readNumber(4, false, false, "BinaryReader.u32be");
555
+ }
556
+
557
+ i32le() {
558
+ return this.#readNumber(4, true, true, "BinaryReader.i32le");
559
+ }
560
+
561
+ i32be() {
562
+ return this.#readNumber(4, true, false, "BinaryReader.i32be");
563
+ }
564
+
565
+ u64le() {
566
+ return this.#readBigInt(false, true, "BinaryReader.u64le");
567
+ }
568
+
569
+ u64be() {
570
+ return this.#readBigInt(false, false, "BinaryReader.u64be");
571
+ }
572
+
573
+ i64le() {
574
+ return this.#readBigInt(true, true, "BinaryReader.i64le");
575
+ }
576
+
577
+ i64be() {
578
+ return this.#readBigInt(true, false, "BinaryReader.i64be");
579
+ }
580
+
581
+ #reserve(length, operation) {
582
+ if (length > this.remaining()) {
583
+ throw binaryBoundsError(`${operation} requires ${length} byte(s), but only ${this.remaining()} remain.`);
584
+ }
585
+ const offset = this.#offset;
586
+ this.#offset += length;
587
+ return offset;
588
+ }
589
+
590
+ #readNumber(width, signed, littleEndian, operation) {
591
+ const offset = this.#reserve(width, operation);
592
+ const unsigned = readUnsignedNumber(this.#bytes, offset, width, littleEndian);
593
+ if (!signed) {
594
+ return unsigned;
595
+ }
596
+ const signBoundary = 2 ** (width * 8 - 1);
597
+ const fullRange = 2 ** (width * 8);
598
+ return unsigned >= signBoundary ? unsigned - fullRange : unsigned;
599
+ }
600
+
601
+ #readBigInt(signed, littleEndian, operation) {
602
+ const offset = this.#reserve(8, operation);
603
+ const unsigned = readUnsignedBigInt(this.#bytes, offset, 8, littleEndian);
604
+ if (!signed) {
605
+ return unsigned;
606
+ }
607
+ return unsigned > INT64_MAX ? unsigned - (1n << 64n) : unsigned;
608
+ }
609
+ }
610
+
611
+ class BinaryWriter {
612
+ #bytes;
613
+ #length = 0;
614
+ #maxCapacity;
615
+
616
+ constructor(options = {}) {
617
+ options = validateOptionsObject(options, "Binary.writer");
618
+ rejectUnknownOptions(options, new Set(["initialCapacity", "maxCapacity"]), "Binary.writer");
619
+ const initialCapacity = options.initialCapacity === undefined
620
+ ? DEFAULT_BINARY_WRITER_CAPACITY
621
+ : requireBinaryCapacity(options.initialCapacity, "Binary.writer initialCapacity");
622
+ this.#maxCapacity = options.maxCapacity === undefined
623
+ ? DEFAULT_BINARY_WRITER_MAX_CAPACITY
624
+ : requireBinaryCapacity(options.maxCapacity, "Binary.writer maxCapacity");
625
+ if (initialCapacity > this.#maxCapacity) {
626
+ throw binaryFieldError("Binary.writer initialCapacity must not exceed maxCapacity.");
627
+ }
628
+ try {
629
+ this.#bytes = new Uint8Array(initialCapacity);
630
+ } catch {
631
+ throw binaryFieldError("Binary.writer initialCapacity could not be allocated.");
632
+ }
633
+ }
634
+
635
+ position() {
636
+ return this.#length;
637
+ }
638
+
639
+ toBytes() {
640
+ return this.#bytes.slice(0, this.#length);
641
+ }
642
+
643
+ bytes(bytes) {
644
+ bytes = requireBytes(bytes, "BinaryWriter.bytes");
645
+ const offset = this.#reserve(bytes.length, "BinaryWriter.bytes");
646
+ this.#bytes.set(bytes, offset);
647
+ return this;
648
+ }
649
+
650
+ u8(value) {
651
+ return this.#writeNumber(1, requireIntegerInRange(value, 0, 0xff, "BinaryWriter.u8"), true, "BinaryWriter.u8");
652
+ }
653
+
654
+ i8(value) {
655
+ return this.#writeNumber(1, requireIntegerInRange(value, -0x80, 0x7f, "BinaryWriter.i8"), true, "BinaryWriter.i8");
656
+ }
657
+
658
+ u16le(value) {
659
+ return this.#writeNumber(2, requireIntegerInRange(value, 0, 0xffff, "BinaryWriter.u16le"), true, "BinaryWriter.u16le");
660
+ }
661
+
662
+ u16be(value) {
663
+ return this.#writeNumber(2, requireIntegerInRange(value, 0, 0xffff, "BinaryWriter.u16be"), false, "BinaryWriter.u16be");
664
+ }
665
+
666
+ i16le(value) {
667
+ return this.#writeNumber(2, requireIntegerInRange(value, -0x8000, 0x7fff, "BinaryWriter.i16le"), true, "BinaryWriter.i16le");
668
+ }
669
+
670
+ i16be(value) {
671
+ return this.#writeNumber(2, requireIntegerInRange(value, -0x8000, 0x7fff, "BinaryWriter.i16be"), false, "BinaryWriter.i16be");
672
+ }
673
+
674
+ u32le(value) {
675
+ return this.#writeNumber(4, requireIntegerInRange(value, 0, 0xffffffff, "BinaryWriter.u32le"), true, "BinaryWriter.u32le");
676
+ }
677
+
678
+ u32be(value) {
679
+ return this.#writeNumber(4, requireIntegerInRange(value, 0, 0xffffffff, "BinaryWriter.u32be"), false, "BinaryWriter.u32be");
680
+ }
681
+
682
+ i32le(value) {
683
+ return this.#writeNumber(4, requireIntegerInRange(value, -0x80000000, 0x7fffffff, "BinaryWriter.i32le"), true, "BinaryWriter.i32le");
684
+ }
685
+
686
+ i32be(value) {
687
+ return this.#writeNumber(4, requireIntegerInRange(value, -0x80000000, 0x7fffffff, "BinaryWriter.i32be"), false, "BinaryWriter.i32be");
688
+ }
689
+
690
+ u64le(value) {
691
+ return this.#writeBigInt(requireBigIntInRange(value, 0n, UINT64_MAX, "BinaryWriter.u64le"), true, "BinaryWriter.u64le");
692
+ }
693
+
694
+ u64be(value) {
695
+ return this.#writeBigInt(requireBigIntInRange(value, 0n, UINT64_MAX, "BinaryWriter.u64be"), false, "BinaryWriter.u64be");
696
+ }
697
+
698
+ i64le(value) {
699
+ value = requireBigIntInRange(value, INT64_MIN, INT64_MAX, "BinaryWriter.i64le");
700
+ return this.#writeBigInt(value < 0n ? value + (1n << 64n) : value, true, "BinaryWriter.i64le");
701
+ }
702
+
703
+ i64be(value) {
704
+ value = requireBigIntInRange(value, INT64_MIN, INT64_MAX, "BinaryWriter.i64be");
705
+ return this.#writeBigInt(value < 0n ? value + (1n << 64n) : value, false, "BinaryWriter.i64be");
706
+ }
707
+
708
+ #reserve(length, operation) {
709
+ if (length > this.#maxCapacity - this.#length) {
710
+ throw binaryFieldError(`${operation} would exceed Binary.writer maxCapacity.`);
711
+ }
712
+ const offset = this.#length;
713
+ const required = offset + length;
714
+ this.#ensureCapacity(required, operation);
715
+ this.#length = required;
716
+ return offset;
717
+ }
718
+
719
+ #ensureCapacity(required, operation) {
720
+ if (required <= this.#bytes.length) {
721
+ return;
722
+ }
723
+ let next = Math.max(1, this.#bytes.length);
724
+ while (next < required) {
725
+ next *= 2;
726
+ if (next > this.#maxCapacity) {
727
+ next = this.#maxCapacity;
728
+ break;
729
+ }
730
+ }
731
+ let grown;
732
+ try {
733
+ grown = new Uint8Array(next);
734
+ } catch {
735
+ throw binaryFieldError(`${operation} could not grow Binary.writer capacity.`);
736
+ }
737
+ grown.set(this.#bytes.subarray(0, this.#length));
738
+ this.#bytes = grown;
739
+ }
740
+
741
+ #writeNumber(width, value, littleEndian, operation) {
742
+ const bits = width * 8;
743
+ const unsigned = value < 0 ? value + 2 ** bits : value;
744
+ const offset = this.#reserve(width, operation);
745
+ writeUnsignedNumber(this.#bytes, offset, width, unsigned, littleEndian);
746
+ return this;
747
+ }
748
+
749
+ #writeBigInt(value, littleEndian, operation) {
750
+ const offset = this.#reserve(8, operation);
751
+ writeUnsignedBigInt(this.#bytes, offset, 8, value, littleEndian);
752
+ return this;
753
+ }
754
+ }
755
+
756
+ const Binary = Object.freeze({
757
+ reader(bytes) {
758
+ return new BinaryReader(bytes);
759
+ },
760
+ writer(options) {
761
+ return new BinaryWriter(options);
762
+ },
763
+ });
764
+
765
+ const DEFAULT_COMPRESSION_LEVEL = 6;
766
+ const MAX_COMPRESSION_INPUT_BYTES = 1024 * 1024;
767
+ const DEFAULT_DECOMPRESSION_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
768
+
769
+ function compressionBackendUnavailable(operation) {
770
+ throw codecError(
771
+ "SLOPPY_E_CODEC_COMPRESSION_BACKEND_UNAVAILABLE",
772
+ `${operation} requires the zlib-backed __sloppy.codec V8 bridge.`,
773
+ );
774
+ }
775
+
776
+ const COMPRESSION_BRIDGE_ERROR_CODES = new Set([
777
+ "SLOPPY_E_CODEC_COMPRESSION_BACKEND_UNAVAILABLE",
778
+ "SLOPPY_E_CODEC_DECOMPRESSION_LIMIT_EXCEEDED",
779
+ "SLOPPY_E_CODEC_COMPRESSED_STREAM_CORRUPT",
780
+ ]);
781
+
782
+ const COMPRESSION_BRIDGE_ERROR_MESSAGES = Object.freeze({
783
+ SLOPPY_E_CODEC_COMPRESSION_BACKEND_UNAVAILABLE: "Compression backend unavailable.",
784
+ SLOPPY_E_CODEC_DECOMPRESSION_LIMIT_EXCEEDED: "Decompression output limit exceeded.",
785
+ SLOPPY_E_CODEC_COMPRESSED_STREAM_CORRUPT: "Compressed stream is corrupt.",
786
+ });
787
+
788
+ function normalizeCompressionError(error) {
789
+ if (error instanceof CodecError) {
790
+ return error;
791
+ }
792
+ const message = typeof error?.message === "string" ? error.message : String(error);
793
+ const match = /\b(SLOPPY_E_CODEC_[A-Z_]+)\b(?::\s*)?(.*)$/u.exec(message);
794
+ if (match !== null && COMPRESSION_BRIDGE_ERROR_CODES.has(match[1])) {
795
+ const normalized = codecError(
796
+ match[1],
797
+ COMPRESSION_BRIDGE_ERROR_MESSAGES[match[1]] ?? "Compression backend failed.",
798
+ );
799
+ normalized.cause = error;
800
+ return normalized;
801
+ }
802
+ return error;
803
+ }
804
+
805
+ function nativeCodec(operation) {
806
+ const bridge = globalThis.__sloppy?.codec ?? null;
807
+ if (bridge === null) {
808
+ compressionBackendUnavailable(operation);
809
+ }
810
+ return bridge;
811
+ }
812
+
813
+ function nativeCompressionFunction(operation, name) {
814
+ const method = nativeCodec(operation)[name];
815
+ if (typeof method !== "function") {
816
+ compressionBackendUnavailable(operation);
817
+ }
818
+ return method;
819
+ }
820
+
821
+ function requireCompressionLevel(value, operation) {
822
+ if (!Number.isInteger(value) || value < 0 || value > 9) {
823
+ throw new TypeError(`${operation} level must be an integer from 0 to 9.`);
824
+ }
825
+ return value;
826
+ }
827
+
828
+ function requireCompressionLimit(value, operation, maximum) {
829
+ if (!Number.isSafeInteger(value) || value < 0 || value > maximum) {
830
+ throw new TypeError(`${operation} must be a non-negative safe integer no greater than ${maximum}.`);
831
+ }
832
+ return value;
833
+ }
834
+
835
+ function parseGzipOptions(options, operation) {
836
+ options = validateOptionsObject(options, operation);
837
+ rejectUnknownOptions(options, new Set(["level"]), operation);
838
+ return {
839
+ level: options.level === undefined ? DEFAULT_COMPRESSION_LEVEL : requireCompressionLevel(options.level, operation),
840
+ };
841
+ }
842
+
843
+ function parseGunzipOptions(options, operation) {
844
+ options = validateOptionsObject(options, operation);
845
+ rejectUnknownOptions(options, new Set(["maxOutputBytes"]), operation);
846
+ return {
847
+ maxOutputBytes:
848
+ options.maxOutputBytes === undefined
849
+ ? DEFAULT_DECOMPRESSION_MAX_OUTPUT_BYTES
850
+ : requireCompressionLimit(options.maxOutputBytes, `${operation} maxOutputBytes`, DEFAULT_DECOMPRESSION_MAX_OUTPUT_BYTES),
851
+ };
852
+ }
853
+
854
+ function parseCompressionStreamOptions(options, operation, allowedCodecOptions) {
855
+ options = validateOptionsObject(options, operation);
856
+ rejectUnknownOptions(options, new Set([...allowedCodecOptions, "signal", "deadline", "maxInputBytes"]), operation);
857
+ const maxInputBytes =
858
+ options.maxInputBytes === undefined
859
+ ? MAX_COMPRESSION_INPUT_BYTES
860
+ : requireCompressionLimit(options.maxInputBytes, `${operation} maxInputBytes`, MAX_COMPRESSION_INPUT_BYTES);
861
+ const codecOptions = {};
862
+ for (const key of allowedCodecOptions) {
863
+ if (Object.prototype.hasOwnProperty.call(options, key)) {
864
+ if (key === "level") {
865
+ codecOptions.level = requireCompressionLevel(options.level, operation);
866
+ } else if (key === "maxOutputBytes") {
867
+ codecOptions.maxOutputBytes = requireCompressionLimit(
868
+ options.maxOutputBytes,
869
+ `${operation} maxOutputBytes`,
870
+ DEFAULT_DECOMPRESSION_MAX_OUTPUT_BYTES,
871
+ );
872
+ }
873
+ }
874
+ }
875
+ return {
876
+ codecOptions,
877
+ signal: options.signal,
878
+ deadline: options.deadline,
879
+ maxInputBytes,
880
+ };
881
+ }
882
+
883
+ function normalizeCompressionResult(value, operation) {
884
+ if (!(value instanceof Uint8Array)) {
885
+ throw new TypeError(`${operation} native backend must return Uint8Array bytes.`);
886
+ }
887
+ return value.slice();
888
+ }
889
+
890
+ function isCancellationSignal(value) {
891
+ return (
892
+ value !== null &&
893
+ typeof value === "object" &&
894
+ typeof value.aborted === "boolean" &&
895
+ ("reason" in value || typeof value.addEventListener === "function")
896
+ );
897
+ }
898
+
899
+ function subscribeCancellation(signal, listener) {
900
+ if (!isCancellationSignal(signal)) {
901
+ return () => {};
902
+ }
903
+ if (signal.aborted) {
904
+ listener(signal.reason);
905
+ return () => {};
906
+ }
907
+ if (typeof signal._subscribe === "function") {
908
+ return signal._subscribe(listener);
909
+ }
910
+ if (typeof signal.addEventListener === "function") {
911
+ const wrapped = () => listener(signal.reason);
912
+ signal.addEventListener("abort", wrapped);
913
+ return () => signal.removeEventListener?.("abort", wrapped);
914
+ }
915
+ return () => {};
916
+ }
917
+
918
+ function compressionCancelledError(reason = undefined) {
919
+ const error = new Error("Sloppy codec compression operation was cancelled.");
920
+ error.name = "CancelledError";
921
+ if (reason !== undefined) {
922
+ error.reason = reason;
923
+ }
924
+ return error;
925
+ }
926
+
927
+ function compressionTimeoutError(reason = undefined) {
928
+ const error = new Error("Sloppy codec compression operation exceeded its deadline.");
929
+ error.name = "TimeoutError";
930
+ if (reason !== undefined) {
931
+ error.reason = reason;
932
+ }
933
+ return error;
934
+ }
935
+
936
+ function deadlineRemainingMs(deadline, operation) {
937
+ if (deadline === undefined || deadline === null) {
938
+ return Infinity;
939
+ }
940
+ if (typeof deadline.remainingMs !== "function") {
941
+ throw new TypeError(`${operation} deadline must come from Deadline.after, Deadline.at, or Deadline.never.`);
942
+ }
943
+ return deadline.remainingMs();
944
+ }
945
+
946
+ function checkCompressionTerminalOptions(options, operation) {
947
+ if (isCancellationSignal(options.signal) && options.signal.aborted) {
948
+ throw compressionCancelledError(options.signal.reason);
949
+ }
950
+ if (deadlineRemainingMs(options.deadline, operation) <= 0) {
951
+ throw compressionTimeoutError(options.deadline);
952
+ }
953
+ }
954
+
955
+ function raceCompressionTerminal(promise, options, operation) {
956
+ checkCompressionTerminalOptions(options, operation);
957
+ const signal = options.signal;
958
+ const remainingMs = deadlineRemainingMs(options.deadline, operation);
959
+ if (!isCancellationSignal(signal) && remainingMs === Infinity) {
960
+ return promise;
961
+ }
962
+ return new Promise((resolve, reject) => {
963
+ let finished = false;
964
+ let timeoutId;
965
+ let cleanupSignal = () => {};
966
+ const finish = (callback, value) => {
967
+ if (finished) {
968
+ return;
969
+ }
970
+ finished = true;
971
+ cleanupAll();
972
+ callback(value);
973
+ };
974
+ cleanupSignal = subscribeCancellation(signal, (reason) => {
975
+ finish(reject, compressionCancelledError(reason));
976
+ });
977
+ if (remainingMs !== Infinity) {
978
+ const setTimer = globalThis["setTimeout"];
979
+ const clearTimer = globalThis["clearTimeout"];
980
+ if (typeof setTimer !== "function" || typeof clearTimer !== "function") {
981
+ finish(reject, compressionTimeoutError(options.deadline));
982
+ return;
983
+ }
984
+ timeoutId = setTimer(
985
+ () => finish(reject, compressionTimeoutError(options.deadline)),
986
+ Math.min(Math.ceil(remainingMs), 0x7fffffff),
987
+ );
988
+ }
989
+ promise.then(
990
+ (value) => {
991
+ finish(resolve, value);
992
+ },
993
+ (error) => {
994
+ finish(reject, error);
995
+ },
996
+ );
997
+ function cleanupAll() {
998
+ cleanupSignal();
999
+ if (timeoutId !== undefined) {
1000
+ const clearTimer = globalThis["clearTimeout"];
1001
+ clearTimer(timeoutId);
1002
+ }
1003
+ }
1004
+ });
1005
+ }
1006
+
1007
+ function runCompression(operation, bytes, options, invoke) {
1008
+ try {
1009
+ bytes = requireBytes(bytes, operation);
1010
+ checkCompressionTerminalOptions({ signal: options?.signal, deadline: options?.deadline }, operation);
1011
+ if (bytes.byteLength > MAX_COMPRESSION_INPUT_BYTES) {
1012
+ throw new TypeError(`${operation} input exceeds the ${MAX_COMPRESSION_INPUT_BYTES} byte inline compression limit.`);
1013
+ }
1014
+ const promise = Promise.resolve(invoke(new Uint8Array(bytes))).then(
1015
+ (result) => normalizeCompressionResult(result, operation),
1016
+ (error) => Promise.reject(normalizeCompressionError(error)),
1017
+ );
1018
+ return raceCompressionTerminal(promise, options ?? {}, operation);
1019
+ } catch (error) {
1020
+ return Promise.reject(normalizeCompressionError(error));
1021
+ }
1022
+ }
1023
+
1024
+ function isIterable(value) {
1025
+ return value !== null && typeof value === "object" && (Symbol.asyncIterator in value || Symbol.iterator in value);
1026
+ }
1027
+
1028
+ async function* compressionStream(input, options, operation, parseOptions, invoke) {
1029
+ const parsed = parseOptions(options, operation);
1030
+ checkCompressionTerminalOptions(parsed, operation);
1031
+ let total = 0;
1032
+ const chunks = [];
1033
+ let terminal = false;
1034
+ const iterator =
1035
+ typeof input[Symbol.asyncIterator] === "function"
1036
+ ? input[Symbol.asyncIterator]()
1037
+ : input[Symbol.iterator]();
1038
+ try {
1039
+ while (true) {
1040
+ checkCompressionTerminalOptions(parsed, operation);
1041
+ const next = await raceCompressionTerminal(Promise.resolve(iterator.next()), parsed, operation);
1042
+ if (next.done === true) {
1043
+ break;
1044
+ }
1045
+ const chunk = next.value;
1046
+ const bytes = requireBytes(chunk, operation);
1047
+ if (bytes.byteLength > parsed.maxInputBytes - total) {
1048
+ throw new TypeError(`${operation} buffered input exceeds maxInputBytes.`);
1049
+ }
1050
+ chunks.push(new Uint8Array(bytes));
1051
+ total += bytes.byteLength;
1052
+ }
1053
+ checkCompressionTerminalOptions(parsed, operation);
1054
+ const inputBytes = new Uint8Array(total);
1055
+ let offset = 0;
1056
+ for (const chunk of chunks) {
1057
+ inputBytes.set(chunk, offset);
1058
+ offset += chunk.byteLength;
1059
+ }
1060
+ const nativeOutput = Promise.resolve(invoke(inputBytes, parsed.codecOptions)).catch((error) =>
1061
+ Promise.reject(normalizeCompressionError(error)),
1062
+ );
1063
+ const output = await raceCompressionTerminal(nativeOutput, parsed, operation);
1064
+ checkCompressionTerminalOptions(parsed, operation);
1065
+ terminal = true;
1066
+ yield output;
1067
+ } finally {
1068
+ if (!terminal && typeof iterator.return === "function") {
1069
+ try {
1070
+ await raceCompressionTerminal(Promise.resolve(iterator.return()), parsed, operation);
1071
+ } catch {
1072
+ }
1073
+ }
1074
+ chunks.length = 0;
1075
+ if (!terminal) {
1076
+ total = 0;
1077
+ }
1078
+ }
1079
+ }
1080
+
1081
+ const Compression = Object.freeze({
1082
+ gzip(bytes, options = undefined) {
1083
+ try {
1084
+ const parsed = parseGzipOptions(options, "Compression.gzip");
1085
+ return runCompression("Compression.gzip", bytes, {}, (input) =>
1086
+ nativeCompressionFunction("Compression.gzip", "gzip").call(undefined, input, parsed.level),
1087
+ );
1088
+ } catch (error) {
1089
+ return Promise.reject(error);
1090
+ }
1091
+ },
1092
+ gunzip(bytes, options = undefined) {
1093
+ try {
1094
+ const parsed = parseGunzipOptions(options, "Compression.gunzip");
1095
+ return runCompression("Compression.gunzip", bytes, {}, (input) =>
1096
+ nativeCompressionFunction("Compression.gunzip", "gunzip").call(undefined, input, parsed.maxOutputBytes),
1097
+ );
1098
+ } catch (error) {
1099
+ return Promise.reject(error);
1100
+ }
1101
+ },
1102
+ gzipStream(input, options = undefined) {
1103
+ if (!isIterable(input)) {
1104
+ throw new TypeError("Compression.gzipStream input must be an iterable or async iterable of Uint8Array chunks.");
1105
+ }
1106
+ return compressionStream(input, options, "Compression.gzipStream", (streamOptions, operation) =>
1107
+ parseCompressionStreamOptions(streamOptions, operation, ["level"]), (bytes, codecOptions) =>
1108
+ Compression.gzip(bytes, codecOptions),
1109
+ );
1110
+ },
1111
+ gunzipStream(input, options = undefined) {
1112
+ if (!isIterable(input)) {
1113
+ throw new TypeError("Compression.gunzipStream input must be an iterable or async iterable of Uint8Array chunks.");
1114
+ }
1115
+ return compressionStream(input, options, "Compression.gunzipStream", (streamOptions, operation) =>
1116
+ parseCompressionStreamOptions(streamOptions, operation, ["maxOutputBytes"]), (bytes, codecOptions) =>
1117
+ Compression.gunzip(bytes, codecOptions),
1118
+ );
1119
+ },
1120
+ });
1121
+
1122
+ function makeCrc32Table() {
1123
+ const table = new Uint32Array(256);
1124
+ for (let index = 0; index < table.length; index += 1) {
1125
+ let value = index;
1126
+ for (let bit = 0; bit < 8; bit += 1) {
1127
+ value = (value >>> 1) ^ (value & 1 ? CRC32_POLYNOMIAL_REFLECTED : 0);
1128
+ }
1129
+ table[index] = value >>> 0;
1130
+ }
1131
+ return table;
1132
+ }
1133
+
1134
+ // CRC-32/ISO-HDLC uses the reflected IEEE 802.3 polynomial, all-ones init, and final xor.
1135
+ const CRC32_POLYNOMIAL_REFLECTED = 0xedb88320;
1136
+ const CRC32_INITIAL = 0xffffffff;
1137
+ const CRC32_FINAL_XOR = 0xffffffff;
1138
+ const CRC32_TABLE = makeCrc32Table();
1139
+
1140
+ function crc32(bytes) {
1141
+ bytes = requireBytes(bytes, "Checksums.crc32");
1142
+ let crc = CRC32_INITIAL;
1143
+ for (let index = 0; index < bytes.byteLength; index += 1) {
1144
+ crc = (crc >>> 8) ^ CRC32_TABLE[(crc ^ bytes[index]) & 0xff];
1145
+ }
1146
+ return (crc ^ CRC32_FINAL_XOR) >>> 0;
1147
+ }
1148
+
1149
+ const Checksums = Object.freeze({
1150
+ crc32,
1151
+ });
1152
+
1153
+ export { Base64, Base64Url, Binary, Checksums, Compression, Hex, Text };