toiljs 0.0.116 → 0.0.118

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 (337) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +16 -7
  3. package/build/backend/.tsbuildinfo +1 -1
  4. package/build/cli/.tsbuildinfo +1 -1
  5. package/build/cli/index.js +2375 -258
  6. package/build/client/.tsbuildinfo +1 -1
  7. package/build/client/auth.d.ts +3 -0
  8. package/build/client/auth.js +19 -10
  9. package/build/client/dev/devtools.js +1 -1
  10. package/build/client/dev/error-overlay.js +1 -1
  11. package/build/client/index.d.ts +1 -1
  12. package/build/client/index.js +1 -1
  13. package/build/client/navigation/navigation.js +28 -3
  14. package/build/client/routing/Router.js +5 -2
  15. package/build/client/routing/mount.js +1 -1
  16. package/build/compiler/.tsbuildinfo +1 -1
  17. package/build/compiler/auth-emails.js +7 -3
  18. package/build/compiler/emails.js +1 -1
  19. package/build/compiler/index.d.ts +1 -0
  20. package/build/compiler/index.js +26 -5
  21. package/build/compiler/pages.js +2 -3
  22. package/build/compiler/prerender.d.ts +3 -8
  23. package/build/compiler/prerender.js +88 -127
  24. package/build/compiler/ssg.js +3 -4
  25. package/build/compiler/template-build.js +3 -4
  26. package/build/compiler/toil-docs.generated.js +8 -7
  27. package/build/compiler/vite.js +4 -6
  28. package/build/devserver/.tsbuildinfo +1 -1
  29. package/build/devserver/db/database.js +7 -3
  30. package/build/devserver/db/types.js +1 -1
  31. package/build/devserver/production.js +4 -3
  32. package/build/devserver/runtime/crypto.d.ts +1 -1
  33. package/build/io/.tsbuildinfo +1 -1
  34. package/build/logger/.tsbuildinfo +1 -1
  35. package/build/shared/.tsbuildinfo +1 -1
  36. package/examples/basic/client/routes/analytics.tsx +7 -5
  37. package/examples/basic/client/routes/pq.tsx +2 -1
  38. package/examples/basic/server/tsconfig.json +1 -3
  39. package/package.json +45 -44
  40. package/presets/no-uint8array-tostring.js +120 -153
  41. package/presets/oxlint.d.ts +5 -0
  42. package/presets/oxlint.js +224 -0
  43. package/server/auth/AuthController.ts +53 -14
  44. package/server/auth/FactorSettings.ts +41 -0
  45. package/server/auth/SessionEpochs.ts +58 -0
  46. package/server/auth/SessionRevocations.ts +13 -0
  47. package/server/globals/auth.ts +27 -2
  48. package/server/runtime/tsconfig.json +1 -3
  49. package/tsconfig.json +2 -11
  50. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  51. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  52. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  53. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  54. package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
  55. package/.github/changelog-config.json +0 -45
  56. package/.github/dependabot.yml +0 -27
  57. package/.github/workflows/ci.yml +0 -222
  58. package/.vscode/settings.json +0 -10
  59. package/docs/README.md +0 -107
  60. package/docs/auth/README.md +0 -104
  61. package/docs/auth/configuration.md +0 -105
  62. package/docs/auth/emails.md +0 -92
  63. package/docs/auth/extending.md +0 -202
  64. package/docs/auth/how-it-works.md +0 -138
  65. package/docs/auth/usage.md +0 -188
  66. package/docs/backend/README.md +0 -143
  67. package/docs/backend/data.md +0 -351
  68. package/docs/backend/rest.md +0 -402
  69. package/docs/backend/rpc.md +0 -226
  70. package/docs/background/README.md +0 -114
  71. package/docs/background/daemons.md +0 -276
  72. package/docs/background/derive.md +0 -179
  73. package/docs/cli/README.md +0 -379
  74. package/docs/concepts/ai-guide.md +0 -132
  75. package/docs/concepts/config.md +0 -416
  76. package/docs/concepts/decorators.md +0 -127
  77. package/docs/concepts/security.md +0 -108
  78. package/docs/concepts/tiers.md +0 -166
  79. package/docs/concepts/types.md +0 -216
  80. package/docs/database/README.md +0 -143
  81. package/docs/database/capacity.md +0 -350
  82. package/docs/database/counters.md +0 -174
  83. package/docs/database/documents.md +0 -277
  84. package/docs/database/events.md +0 -307
  85. package/docs/database/membership.md +0 -246
  86. package/docs/database/setup.md +0 -155
  87. package/docs/database/unique.md +0 -216
  88. package/docs/database/views.md +0 -246
  89. package/docs/frontend/README.md +0 -104
  90. package/docs/frontend/components.md +0 -286
  91. package/docs/frontend/data-fetching.md +0 -260
  92. package/docs/frontend/images.md +0 -148
  93. package/docs/frontend/metadata.md +0 -344
  94. package/docs/frontend/navigation.md +0 -296
  95. package/docs/frontend/rendering.md +0 -236
  96. package/docs/frontend/routing.md +0 -346
  97. package/docs/frontend/scripts.md +0 -118
  98. package/docs/frontend/search.md +0 -191
  99. package/docs/frontend/styling.md +0 -147
  100. package/docs/frontend/toil-global.md +0 -216
  101. package/docs/getting-started/README.md +0 -81
  102. package/docs/getting-started/create-project.md +0 -131
  103. package/docs/getting-started/deploy.md +0 -101
  104. package/docs/getting-started/first-app.md +0 -215
  105. package/docs/getting-started/installation.md +0 -124
  106. package/docs/getting-started/migrating.md +0 -125
  107. package/docs/getting-started/project-structure.md +0 -163
  108. package/docs/introduction/README.md +0 -66
  109. package/docs/introduction/design-principles.md +0 -81
  110. package/docs/introduction/distributed.md +0 -91
  111. package/docs/introduction/how-it-works.md +0 -121
  112. package/docs/introduction/hyperscale.md +0 -70
  113. package/docs/introduction/modern-stack.md +0 -85
  114. package/docs/introduction/vs-other-frameworks.md +0 -64
  115. package/docs/introduction/why-toil.md +0 -99
  116. package/docs/llms.txt +0 -95
  117. package/docs/realtime/README.md +0 -102
  118. package/docs/realtime/channels.md +0 -211
  119. package/docs/realtime/streams.md +0 -369
  120. package/docs/services/README.md +0 -60
  121. package/docs/services/analytics.md +0 -279
  122. package/docs/services/caching.md +0 -175
  123. package/docs/services/cookies.md +0 -235
  124. package/docs/services/crypto.md +0 -209
  125. package/docs/services/email.md +0 -289
  126. package/docs/services/environment.md +0 -141
  127. package/docs/services/ratelimit.md +0 -174
  128. package/docs/services/time.md +0 -85
  129. package/eslint.config.js +0 -57
  130. package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
  131. package/presets/eslint.js +0 -88
  132. package/src/backend/index.ts +0 -204
  133. package/src/cli/configure.ts +0 -363
  134. package/src/cli/create.ts +0 -924
  135. package/src/cli/db.ts +0 -158
  136. package/src/cli/diagnostics.ts +0 -665
  137. package/src/cli/doctor.ts +0 -982
  138. package/src/cli/features.ts +0 -170
  139. package/src/cli/index.ts +0 -326
  140. package/src/cli/notify.ts +0 -120
  141. package/src/cli/proc.ts +0 -56
  142. package/src/cli/ui.ts +0 -169
  143. package/src/cli/update.ts +0 -248
  144. package/src/cli/updates.ts +0 -92
  145. package/src/cli/validate.ts +0 -31
  146. package/src/cli/version-check.ts +0 -125
  147. package/src/client/auth.ts +0 -869
  148. package/src/client/channel/channel.ts +0 -146
  149. package/src/client/components/Form.tsx +0 -65
  150. package/src/client/components/Image.tsx +0 -160
  151. package/src/client/components/Script.tsx +0 -113
  152. package/src/client/components/Slot.tsx +0 -21
  153. package/src/client/dev/devtools.tsx +0 -1089
  154. package/src/client/dev/error-overlay.tsx +0 -225
  155. package/src/client/errors.ts +0 -11
  156. package/src/client/head/head.ts +0 -182
  157. package/src/client/head/metadata.ts +0 -110
  158. package/src/client/index.ts +0 -130
  159. package/src/client/navigation/Link.tsx +0 -108
  160. package/src/client/navigation/NavLink.tsx +0 -86
  161. package/src/client/navigation/navigation.ts +0 -235
  162. package/src/client/navigation/prefetch.ts +0 -169
  163. package/src/client/navigation/scroll.ts +0 -53
  164. package/src/client/routing/Router.tsx +0 -216
  165. package/src/client/routing/action.ts +0 -122
  166. package/src/client/routing/error-boundary.tsx +0 -43
  167. package/src/client/routing/hooks.ts +0 -140
  168. package/src/client/routing/lazy.ts +0 -77
  169. package/src/client/routing/loader.ts +0 -381
  170. package/src/client/routing/match.ts +0 -47
  171. package/src/client/routing/mount.tsx +0 -90
  172. package/src/client/routing/params-context.ts +0 -10
  173. package/src/client/routing/slot-context.ts +0 -7
  174. package/src/client/rpc.ts +0 -97
  175. package/src/client/search/search.ts +0 -189
  176. package/src/client/search/use-page-search.ts +0 -73
  177. package/src/client/ssr/markers.tsx +0 -172
  178. package/src/client/stream/client.ts +0 -237
  179. package/src/client/types.ts +0 -73
  180. package/src/compiler/auth-emails.ts +0 -312
  181. package/src/compiler/config.ts +0 -369
  182. package/src/compiler/docs.ts +0 -127
  183. package/src/compiler/email-preview.ts +0 -314
  184. package/src/compiler/emails.ts +0 -404
  185. package/src/compiler/fonts.ts +0 -89
  186. package/src/compiler/generate.ts +0 -471
  187. package/src/compiler/image-blur.ts +0 -42
  188. package/src/compiler/image-report.ts +0 -88
  189. package/src/compiler/index.ts +0 -1362
  190. package/src/compiler/pages.ts +0 -49
  191. package/src/compiler/plugin.ts +0 -391
  192. package/src/compiler/prerender.ts +0 -263
  193. package/src/compiler/routes.ts +0 -170
  194. package/src/compiler/seo.ts +0 -415
  195. package/src/compiler/sri.ts +0 -144
  196. package/src/compiler/ssg.ts +0 -177
  197. package/src/compiler/ssr-codegen.ts +0 -85
  198. package/src/compiler/template-build.ts +0 -676
  199. package/src/compiler/template.ts +0 -262
  200. package/src/compiler/toil-docs.generated.ts +0 -77
  201. package/src/compiler/vite.ts +0 -245
  202. package/src/devserver/analytics/index.ts +0 -317
  203. package/src/devserver/config/dotenv.ts +0 -102
  204. package/src/devserver/config/env.ts +0 -30
  205. package/src/devserver/config/ratelimit.ts +0 -123
  206. package/src/devserver/daemon/catalog.ts +0 -120
  207. package/src/devserver/daemon/cron.ts +0 -87
  208. package/src/devserver/daemon/host.ts +0 -134
  209. package/src/devserver/daemon/index.ts +0 -369
  210. package/src/devserver/daemon/runtime.ts +0 -48
  211. package/src/devserver/db/catalog.ts +0 -109
  212. package/src/devserver/db/database.ts +0 -1834
  213. package/src/devserver/db/derives.ts +0 -121
  214. package/src/devserver/db/index.ts +0 -20
  215. package/src/devserver/db/routeKinds.ts +0 -191
  216. package/src/devserver/db/types.ts +0 -168
  217. package/src/devserver/email/caps.ts +0 -0
  218. package/src/devserver/email/config.ts +0 -141
  219. package/src/devserver/email/console.ts +0 -348
  220. package/src/devserver/email/index.ts +0 -155
  221. package/src/devserver/email/providers.ts +0 -131
  222. package/src/devserver/email/status.ts +0 -23
  223. package/src/devserver/email/validate.ts +0 -37
  224. package/src/devserver/email/wire.ts +0 -55
  225. package/src/devserver/http/cache.ts +0 -0
  226. package/src/devserver/http/envelope.ts +0 -157
  227. package/src/devserver/http/proxy.ts +0 -172
  228. package/src/devserver/http/runtime.ts +0 -387
  229. package/src/devserver/index.ts +0 -43
  230. package/src/devserver/production-ipc.ts +0 -63
  231. package/src/devserver/production-worker.ts +0 -83
  232. package/src/devserver/production.ts +0 -718
  233. package/src/devserver/runtime/crypto.ts +0 -587
  234. package/src/devserver/runtime/host.ts +0 -427
  235. package/src/devserver/runtime/module.ts +0 -442
  236. package/src/devserver/server.ts +0 -251
  237. package/src/devserver/ssr.ts +0 -208
  238. package/src/devserver/stream/catalog.ts +0 -106
  239. package/src/devserver/stream/host.ts +0 -42
  240. package/src/devserver/stream/index.ts +0 -301
  241. package/src/devserver/stream/manager.ts +0 -167
  242. package/src/devserver/stream/router.ts +0 -101
  243. package/src/devserver/stream/wire.ts +0 -58
  244. package/src/devserver/stream/ws.ts +0 -78
  245. package/src/devserver/wasm/sections.ts +0 -59
  246. package/src/devserver/wasm/surface.ts +0 -115
  247. package/src/io/FastMap.ts +0 -151
  248. package/src/io/FastSet.ts +0 -113
  249. package/src/io/codec.ts +0 -362
  250. package/src/io/index.ts +0 -10
  251. package/src/io/lengths.ts +0 -14
  252. package/src/io/types.ts +0 -19
  253. package/src/logger/index.ts +0 -22
  254. package/src/shared/index.ts +0 -46
  255. package/test/analytics-dev.test.ts +0 -113
  256. package/test/assembly/aspect-shim.ts +0 -33
  257. package/test/assembly/cookie.spec.ts +0 -303
  258. package/test/assembly/example.spec.ts +0 -22
  259. package/test/assembly/ssr.spec.ts +0 -95
  260. package/test/assembly.test.ts +0 -59
  261. package/test/auth-emails.test.ts +0 -118
  262. package/test/built-ssr.test.ts +0 -148
  263. package/test/channel.test.ts +0 -21
  264. package/test/config-host-port.test.ts +0 -59
  265. package/test/configure.test.ts +0 -94
  266. package/test/daemon-build.test.ts +0 -278
  267. package/test/daemon-catalog.test.ts +0 -349
  268. package/test/daemon-emulation.test.ts +0 -256
  269. package/test/db.test.ts +0 -0
  270. package/test/devserver-database.test.ts +0 -1102
  271. package/test/devserver-email.test.ts +0 -306
  272. package/test/devserver-pqauth.test.ts +0 -93
  273. package/test/devserver-secrets.test.ts +0 -63
  274. package/test/devserver.test.ts +0 -259
  275. package/test/doctor.test.ts +0 -298
  276. package/test/dom/Image.test.tsx +0 -144
  277. package/test/dom/Link.test.tsx +0 -67
  278. package/test/dom/NavLink.test.tsx +0 -37
  279. package/test/dom/Script.test.tsx +0 -48
  280. package/test/dom/action.test.tsx +0 -146
  281. package/test/dom/error-overlay.test.tsx +0 -44
  282. package/test/dom/loader.test.tsx +0 -121
  283. package/test/dom/navigation.test.ts +0 -59
  284. package/test/dom/revalidate.test.tsx +0 -38
  285. package/test/dom/route-head.test.tsx +0 -56
  286. package/test/dom/router-loading.test.tsx +0 -44
  287. package/test/dom/scroll.test.ts +0 -56
  288. package/test/dom/slot.test.tsx +0 -131
  289. package/test/dom/use-metadata.test.tsx +0 -58
  290. package/test/dom/view-transitions.test.tsx +0 -53
  291. package/test/dynamic-routing.test.ts +0 -132
  292. package/test/email-console.test.ts +0 -86
  293. package/test/email-preview.test.ts +0 -73
  294. package/test/emails.test.ts +0 -58
  295. package/test/errors.test.ts +0 -21
  296. package/test/example-guestbook.test.ts +0 -123
  297. package/test/features.test.ts +0 -149
  298. package/test/fixtures/bignum-wire/spec.ts +0 -25
  299. package/test/fixtures/daemon-app.ts +0 -65
  300. package/test/fixtures/stream-echo.ts +0 -26
  301. package/test/fixtures/stream-gate.ts +0 -28
  302. package/test/fixtures/stream-trap.ts +0 -18
  303. package/test/fixtures/stream-typed.ts +0 -41
  304. package/test/fonts.test.ts +0 -28
  305. package/test/global-setup.ts +0 -17
  306. package/test/head.test.ts +0 -42
  307. package/test/image-blur.test.ts +0 -50
  308. package/test/io.test.ts +0 -117
  309. package/test/metadata.test.ts +0 -40
  310. package/test/navlink.test.ts +0 -28
  311. package/test/pages.test.ts +0 -105
  312. package/test/placeholder.test.ts +0 -9
  313. package/test/pqauth-e2e.test.ts +0 -216
  314. package/test/pqauth-email.test.ts +0 -801
  315. package/test/prerender.test.ts +0 -116
  316. package/test/prettier-plugin.test.ts +0 -46
  317. package/test/routes.test.ts +0 -76
  318. package/test/rpc-bignum-wire.test.ts +0 -164
  319. package/test/rpc-dispatch.test.ts +0 -132
  320. package/test/rpc-kinds.test.ts +0 -18
  321. package/test/rpc.test.ts +0 -66
  322. package/test/search.test.ts +0 -114
  323. package/test/seo.test.ts +0 -175
  324. package/test/slot-layouts.test.ts +0 -69
  325. package/test/sri.test.ts +0 -129
  326. package/test/ssg.test.ts +0 -36
  327. package/test/ssr-hydration.test.tsx +0 -122
  328. package/test/ssr-render.test.ts +0 -197
  329. package/test/ssr-template.test.tsx +0 -482
  330. package/test/stream-emulation.test.ts +0 -479
  331. package/test/ui.test.ts +0 -40
  332. package/test/update.test.ts +0 -58
  333. package/test/validate.test.ts +0 -42
  334. package/test/version-check.test.ts +0 -130
  335. package/tests/data-parity/generated-parity.ts +0 -99
  336. package/tests/data-parity/parity.ts +0 -80
  337. package/tests/data-parity/spec.ts +0 -46
package/src/io/FastMap.ts DELETED
@@ -1,151 +0,0 @@
1
- /** A key usable with {@link FastMap}: any `PropertyKey` plus `bigint`. */
2
- export type PropertyExtendedKey = PropertyKey | bigint;
3
-
4
- /**
5
- * Like Record, but supports bigint keys (which JS auto-converts to strings).
6
- * Reflects actual JavaScript behavior where obj[123n] becomes obj["123"].
7
- */
8
- export type FastRecord<V> = {
9
- [key: string]: V;
10
- };
11
-
12
- /** The string/number form a key takes once used to index the backing object. */
13
- export type IndexKey = string | number;
14
-
15
- /**
16
- * An insertion-ordered map backed by a key array plus a plain object, supporting
17
- * `bigint` keys (coerced to their string form, like native property access). Exposed
18
- * to the client as a global (no import). Implements `Disposable`, so a `using` binding
19
- * clears it on scope exit.
20
- */
21
- export class FastMap<K extends PropertyExtendedKey, V> implements Disposable {
22
- protected _keys: K[] = [];
23
- protected _values: FastRecord<V> = {};
24
-
25
- /** @param iterable - initial entries, or another FastMap to copy. */
26
- constructor(iterable?: ReadonlyArray<readonly [K, V]> | null | FastMap<K, V>) {
27
- if (iterable instanceof FastMap) {
28
- this.setAll(iterable);
29
- } else {
30
- if (iterable) {
31
- for (const [key, value] of iterable) {
32
- this.set(key, value);
33
- }
34
- }
35
- }
36
- }
37
-
38
- /** Number of entries. */
39
- public get size(): number {
40
- return this._keys.length;
41
- }
42
-
43
- /** Replaces all entries with a copy of `map`'s entries. */
44
- public setAll(map: FastMap<K, V>): void {
45
- this._keys = [...map._keys];
46
- this._values = { ...map._values };
47
- }
48
-
49
- /** Merges `map`'s entries into this one (existing keys are overwritten). */
50
- public addAll(map: FastMap<K, V>): void {
51
- for (const [key, value] of map.entries()) {
52
- this.set(key, value);
53
- }
54
- }
55
-
56
- /** Iterates the keys in insertion order. */
57
- public *keys(): IterableIterator<K> {
58
- yield* this._keys;
59
- }
60
-
61
- /** Iterates the values in key-insertion order. */
62
- public *values(): IterableIterator<V> {
63
- for (const key of this._keys) {
64
- yield this._values[key as IndexKey] as V;
65
- }
66
- }
67
-
68
- /** Iterates `[key, value]` pairs in insertion order. */
69
- public *entries(): IterableIterator<[K, V]> {
70
- for (const key of this._keys) {
71
- yield [key, this._values[key as IndexKey] as V];
72
- }
73
- }
74
-
75
- /** Sets `key` to `value` (appending the key if new), and returns `this` for chaining. */
76
- public set(key: K, value: V): this {
77
- if (!this.has(key)) {
78
- this._keys.push(key);
79
- }
80
-
81
- this._values[key as IndexKey] = value;
82
-
83
- return this;
84
- }
85
-
86
- /** Returns the insertion index of `key`, or -1 if absent. */
87
- public indexOf(key: K): number {
88
- if (!this.has(key)) {
89
- return -1;
90
- }
91
-
92
- for (let i = 0; i < this._keys.length; i++) {
93
- if (this._keys[i] === key) {
94
- return i;
95
- }
96
- }
97
-
98
- throw new Error('Key not found, this should not happen.');
99
- }
100
-
101
- /** Returns the value for `key`, or `undefined` if absent. */
102
- public get(key: K): V | undefined {
103
- return this._values[key as IndexKey];
104
- }
105
-
106
- /** Whether `key` is present. */
107
- public has(key: K): boolean {
108
- return Object.prototype.hasOwnProperty.call(this._values, key as IndexKey);
109
- }
110
-
111
- /** Removes `key`; returns true if it was present. */
112
- public delete(key: K): boolean {
113
- if (!this.has(key)) {
114
- return false;
115
- }
116
-
117
- const index = this.indexOf(key);
118
- this._keys.splice(index, 1);
119
-
120
- delete this._values[key as IndexKey];
121
- return true;
122
- }
123
-
124
- /** Removes all entries. */
125
- public clear(): void {
126
- this._keys = [];
127
- this._values = {};
128
- }
129
-
130
- /** `Disposable` hook: clears the map (so `using m = new FastMap()` frees it on scope exit). */
131
- public [Symbol.dispose](): void {
132
- this.clear();
133
- }
134
-
135
- /** Calls `callback(value, key, map)` for each entry in insertion order. */
136
- public forEach(
137
- callback: (value: V, key: K, map: FastMap<K, V>) => void,
138
- thisArg?: unknown,
139
- ): void {
140
- for (const key of this._keys) {
141
- callback.call(thisArg, this._values[key as IndexKey] as V, key, this);
142
- }
143
- }
144
-
145
- /** Default iterator: `[key, value]` pairs in insertion order. */
146
- *[Symbol.iterator](): IterableIterator<[K, V]> {
147
- for (const key of this._keys) {
148
- yield [key, this._values[key as IndexKey] as V];
149
- }
150
- }
151
- }
package/src/io/FastSet.ts DELETED
@@ -1,113 +0,0 @@
1
- import { type FastRecord, type IndexKey, type PropertyExtendedKey } from './FastMap.js';
2
-
3
- /**
4
- * The Set counterpart to {@link FastMap}: an insertion-ordered set backed by an array (for
5
- * iteration/ordering) plus a record index (for O(1) membership), with bigint-key support.
6
- *
7
- * Authored to match FastMap's design, the upstream package ships no `FastSet`. Implements
8
- * `Disposable`, so a `using` binding clears it on scope exit.
9
- */
10
- export class FastSet<T extends PropertyExtendedKey> implements Disposable {
11
- protected _values: T[] = [];
12
- protected _index: FastRecord<true> = {};
13
-
14
- /** @param iterable - initial values, or another FastSet to copy. */
15
- constructor(iterable?: Iterable<T> | null | FastSet<T>) {
16
- if (iterable instanceof FastSet) {
17
- this.addAll(iterable);
18
- } else if (iterable) {
19
- for (const value of iterable) {
20
- this.add(value);
21
- }
22
- }
23
- }
24
-
25
- /** Number of values. */
26
- public get size(): number {
27
- return this._values.length;
28
- }
29
-
30
- /** Adds `value` if not already present, and returns `this` for chaining. */
31
- public add(value: T): this {
32
- if (!this.has(value)) {
33
- this._values.push(value);
34
- this._index[value as IndexKey] = true;
35
- }
36
-
37
- return this;
38
- }
39
-
40
- /** Whether `value` is present (O(1)). */
41
- public has(value: T): boolean {
42
- return Object.prototype.hasOwnProperty.call(this._index, value as IndexKey);
43
- }
44
-
45
- /** Returns the insertion index of `value`, or -1 if absent. */
46
- public indexOf(value: T): number {
47
- for (let i = 0; i < this._values.length; i++) {
48
- if (this._values[i] === value) {
49
- return i;
50
- }
51
- }
52
-
53
- return -1;
54
- }
55
-
56
- /** Removes `value`; returns true if it was present. */
57
- public delete(value: T): boolean {
58
- if (!this.has(value)) {
59
- return false;
60
- }
61
-
62
- const index = this.indexOf(value);
63
- if (index !== -1) {
64
- this._values.splice(index, 1);
65
- }
66
-
67
- delete this._index[value as IndexKey];
68
- return true;
69
- }
70
-
71
- /** Adds every value from `set`. */
72
- public addAll(set: FastSet<T>): void {
73
- for (const value of set.values()) {
74
- this.add(value);
75
- }
76
- }
77
-
78
- /** Iterates the values in insertion order. */
79
- public *values(): IterableIterator<T> {
80
- yield* this._values;
81
- }
82
-
83
- /** Iterates the values in insertion order (alias of {@link values}, for Map-like parity). */
84
- public *keys(): IterableIterator<T> {
85
- yield* this._values;
86
- }
87
-
88
- /** Calls `callback(value, value, set)` for each value in insertion order. */
89
- public forEach(
90
- callback: (value: T, value2: T, set: FastSet<T>) => void,
91
- thisArg?: unknown,
92
- ): void {
93
- for (const value of this._values) {
94
- callback.call(thisArg, value, value, this);
95
- }
96
- }
97
-
98
- /** Removes all values. */
99
- public clear(): void {
100
- this._values = [];
101
- this._index = {};
102
- }
103
-
104
- /** `Disposable` hook: clears the set (so `using s = new FastSet()` frees it on scope exit). */
105
- public [Symbol.dispose](): void {
106
- this.clear();
107
- }
108
-
109
- /** Default iterator: the values in insertion order. */
110
- *[Symbol.iterator](): IterableIterator<T> {
111
- yield* this._values;
112
- }
113
- }
package/src/io/codec.ts DELETED
@@ -1,362 +0,0 @@
1
- /**
2
- * TypeScript side of the `@data` binary codec, byte-for-byte compatible with the
3
- * ToilScript `DataWriter`/`DataReader` in `std/assembly/data.ts`.
4
- *
5
- * Little-endian by default (wasm `store`/`load` are little-endian, so the ToilScript
6
- * side is near native and this matches it). Every multi-byte method takes an optional
7
- * `be` flag to read/write big-endian instead, for interop with big-endian wire
8
- * formats; the generated `@data` code never sets it, so the `@data` wire stays
9
- * little-endian. Strings and byte blobs are a `u32` byte-length prefix followed by the
10
- * bytes. `u128`/`i128` are two 64-bit limbs (low limb first in little-endian, high
11
- * limb first in big-endian), `u256`/`i256` four. The reader never throws: a read past
12
- * the end clears {@link DataReader.ok} and yields a zero/empty value.
13
- */
14
-
15
- const MASK64 = 0xffffffffffffffffn;
16
- const utf8Encoder = new TextEncoder();
17
- const utf8Decoder = new TextDecoder();
18
-
19
- /**
20
- * A growable little-endian (or big-endian, per the `be` flag) byte writer. Methods
21
- * return `this` so writes chain. The backing buffer doubles as needed; call
22
- * {@link toBytes} for an exact-length copy of what was written.
23
- */
24
- export class DataWriter {
25
- // `ArrayBuffer`-backed (not the `ArrayBufferLike` default) so `toBytes()` yields a
26
- // `Uint8Array<ArrayBuffer>`, which `fetch`/`Blob`/`Response` accept as a `BodyInit`.
27
- private buf: Uint8Array<ArrayBuffer>;
28
- private view: DataView;
29
- private off = 0;
30
-
31
- /** @param capacity - initial buffer size in bytes (grows automatically). */
32
- constructor(capacity = 64) {
33
- this.buf = new Uint8Array(capacity > 0 ? capacity : 1);
34
- this.view = new DataView(this.buf.buffer);
35
- }
36
-
37
- /** Writes an unsigned 8-bit byte (the low 8 bits of `v`). */
38
- writeU8(v: number): this {
39
- const at = this.reserve(1);
40
- this.view.setUint8(at, v & 0xff);
41
- return this;
42
- }
43
-
44
- /** Writes an unsigned 16-bit integer. @param be - big-endian if true (default little-endian). */
45
- writeU16(v: number, be?: boolean): this {
46
- const at = this.reserve(2);
47
- this.view.setUint16(at, v & 0xffff, !be);
48
- return this;
49
- }
50
-
51
- /** Writes an unsigned 32-bit integer. @param be - big-endian if true (default little-endian). */
52
- writeU32(v: number, be?: boolean): this {
53
- const at = this.reserve(4);
54
- this.view.setUint32(at, v >>> 0, !be);
55
- return this;
56
- }
57
-
58
- /** Writes an unsigned 64-bit integer (low 64 bits of `v`). @param be - big-endian if true. */
59
- writeU64(v: bigint, be?: boolean): this {
60
- const at = this.reserve(8);
61
- this.view.setBigUint64(at, v & MASK64, !be);
62
- return this;
63
- }
64
-
65
- /** Writes a signed 8-bit integer. */
66
- writeI8(v: number): this {
67
- const at = this.reserve(1);
68
- this.view.setInt8(at, v);
69
- return this;
70
- }
71
-
72
- /** Writes a signed 16-bit integer. @param be - big-endian if true (default little-endian). */
73
- writeI16(v: number, be?: boolean): this {
74
- const at = this.reserve(2);
75
- this.view.setInt16(at, v, !be);
76
- return this;
77
- }
78
-
79
- /** Writes a signed 32-bit integer. @param be - big-endian if true (default little-endian). */
80
- writeI32(v: number, be?: boolean): this {
81
- const at = this.reserve(4);
82
- this.view.setInt32(at, v | 0, !be);
83
- return this;
84
- }
85
-
86
- /** Writes a signed 64-bit integer. @param be - big-endian if true (default little-endian). */
87
- writeI64(v: bigint, be?: boolean): this {
88
- const at = this.reserve(8);
89
- this.view.setBigInt64(at, BigInt.asIntN(64, v), !be);
90
- return this;
91
- }
92
-
93
- /** Writes a 32-bit float. @param be - big-endian if true (default little-endian). */
94
- writeF32(v: number, be?: boolean): this {
95
- const at = this.reserve(4);
96
- this.view.setFloat32(at, v, !be);
97
- return this;
98
- }
99
-
100
- /** Writes a 64-bit float. @param be - big-endian if true (default little-endian). */
101
- writeF64(v: number, be?: boolean): this {
102
- const at = this.reserve(8);
103
- this.view.setFloat64(at, v, !be);
104
- return this;
105
- }
106
-
107
- /** Writes a boolean as one byte (1 or 0). */
108
- writeBool(v: boolean): this {
109
- return this.writeU8(v ? 1 : 0);
110
- }
111
-
112
- /** Writes a `u32` length prefix followed by the raw bytes. @param be - endianness of the prefix. */
113
- writeBytes(bytes: Uint8Array, be?: boolean): this {
114
- this.writeU32(bytes.length, be);
115
- if (bytes.length) {
116
- const at = this.reserve(bytes.length);
117
- this.buf.set(bytes, at);
118
- }
119
- return this;
120
- }
121
-
122
- /** Writes a `u32` byte-length prefix followed by the UTF-8 bytes. @param be - endianness of the prefix. */
123
- writeString(value: string, be?: boolean): this {
124
- const utf8 = utf8Encoder.encode(value);
125
- this.writeU32(utf8.length, be);
126
- if (utf8.length) {
127
- const at = this.reserve(utf8.length);
128
- this.buf.set(utf8, at);
129
- }
130
- return this;
131
- }
132
-
133
- /** Writes an unsigned 128-bit integer as two 64-bit limbs. @param be - big-endian if true. */
134
- writeU128(v: bigint, be?: boolean): this {
135
- return this.writeLimbs(BigInt.asUintN(128, v), 2, !!be);
136
- }
137
-
138
- /** Writes a signed 128-bit integer as two 64-bit limbs (two's complement). @param be - big-endian if true. */
139
- writeI128(v: bigint, be?: boolean): this {
140
- return this.writeLimbs(BigInt.asUintN(128, v), 2, !!be);
141
- }
142
-
143
- /** Writes an unsigned 256-bit integer as four 64-bit limbs. @param be - big-endian if true. */
144
- writeU256(v: bigint, be?: boolean): this {
145
- return this.writeLimbs(BigInt.asUintN(256, v), 4, !!be);
146
- }
147
-
148
- /** Writes a signed 256-bit integer as four 64-bit limbs (two's complement). @param be - big-endian if true. */
149
- writeI256(v: bigint, be?: boolean): this {
150
- return this.writeLimbs(BigInt.asUintN(256, v), 4, !!be);
151
- }
152
-
153
- /** Number of bytes written so far. */
154
- length(): number {
155
- return this.off;
156
- }
157
-
158
- /** A fresh copy of exactly the bytes written. */
159
- toBytes(): Uint8Array<ArrayBuffer> {
160
- return this.buf.slice(0, this.off);
161
- }
162
-
163
- /**
164
- * Ensures room for `extra` more bytes and returns the offset to write at. Grows
165
- * (doubling) when needed, reassigning `buf`/`view`. Callers MUST read the returned
166
- * offset into a local before touching `this.view`/`this.buf`, since a grow swaps
167
- * them out from under a stale receiver.
168
- */
169
- private reserve(extra: number): number {
170
- const need = this.off + extra;
171
- if (need > this.buf.length) {
172
- let n = this.buf.length;
173
- while (n < need) n <<= 1;
174
- const bigger = new Uint8Array(n);
175
- bigger.set(this.buf.subarray(0, this.off));
176
- this.buf = bigger;
177
- this.view = new DataView(this.buf.buffer);
178
- }
179
- const at = this.off;
180
- this.off += extra;
181
- return at;
182
- }
183
-
184
- /** Writes the `count` 64-bit limbs of `u` (low limb first in LE, high limb first in BE). */
185
- private writeLimbs(u: bigint, count: number, be: boolean): this {
186
- if (be) {
187
- for (let i = count - 1; i >= 0; i--)
188
- this.writeU64((u >> BigInt(i * 64)) & MASK64, true);
189
- } else {
190
- for (let i = 0; i < count; i++) this.writeU64((u >> BigInt(i * 64)) & MASK64, false);
191
- }
192
- return this;
193
- }
194
- }
195
-
196
- /**
197
- * Reads values written by {@link DataWriter}. Never throws: a read past the end
198
- * clears {@link ok} and returns a zero/empty value, so a truncated or hostile buffer
199
- * fails closed rather than crashing. Defaults to little-endian; pass `be` to match a
200
- * big-endian writer.
201
- */
202
- export class DataReader {
203
- /** Cleared to false if any read ran past the end of the buffer. */
204
- ok = true;
205
- private buf: Uint8Array;
206
- private view: DataView;
207
- private off = 0;
208
-
209
- /** @param bytes - the buffer to read from (its byteOffset/length are respected). */
210
- constructor(bytes: Uint8Array) {
211
- this.buf = bytes;
212
- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
213
- }
214
-
215
- /** Reads an unsigned 8-bit byte (0 past end). */
216
- readU8(): number {
217
- if (!this.has(1)) return 0;
218
- const v = this.view.getUint8(this.off);
219
- this.off += 1;
220
- return v;
221
- }
222
-
223
- /** Reads an unsigned 16-bit integer. @param be - big-endian if true (default little-endian). */
224
- readU16(be?: boolean): number {
225
- if (!this.has(2)) return 0;
226
- const v = this.view.getUint16(this.off, !be);
227
- this.off += 2;
228
- return v;
229
- }
230
-
231
- /** Reads an unsigned 32-bit integer. @param be - big-endian if true (default little-endian). */
232
- readU32(be?: boolean): number {
233
- if (!this.has(4)) return 0;
234
- const v = this.view.getUint32(this.off, !be);
235
- this.off += 4;
236
- return v >>> 0;
237
- }
238
-
239
- /** Reads an unsigned 64-bit integer. @param be - big-endian if true (default little-endian). */
240
- readU64(be?: boolean): bigint {
241
- if (!this.has(8)) return 0n;
242
- const v = this.view.getBigUint64(this.off, !be);
243
- this.off += 8;
244
- return v;
245
- }
246
-
247
- /** Reads a signed 8-bit integer (0 past end). */
248
- readI8(): number {
249
- if (!this.has(1)) return 0;
250
- const v = this.view.getInt8(this.off);
251
- this.off += 1;
252
- return v;
253
- }
254
-
255
- /** Reads a signed 16-bit integer. @param be - big-endian if true (default little-endian). */
256
- readI16(be?: boolean): number {
257
- if (!this.has(2)) return 0;
258
- const v = this.view.getInt16(this.off, !be);
259
- this.off += 2;
260
- return v;
261
- }
262
-
263
- /** Reads a signed 32-bit integer. @param be - big-endian if true (default little-endian). */
264
- readI32(be?: boolean): number {
265
- if (!this.has(4)) return 0;
266
- const v = this.view.getInt32(this.off, !be);
267
- this.off += 4;
268
- return v;
269
- }
270
-
271
- /** Reads a signed 64-bit integer. @param be - big-endian if true (default little-endian). */
272
- readI64(be?: boolean): bigint {
273
- if (!this.has(8)) return 0n;
274
- const v = this.view.getBigInt64(this.off, !be);
275
- this.off += 8;
276
- return v;
277
- }
278
-
279
- /** Reads a 32-bit float. @param be - big-endian if true (default little-endian). */
280
- readF32(be?: boolean): number {
281
- if (!this.has(4)) return 0;
282
- const v = this.view.getFloat32(this.off, !be);
283
- this.off += 4;
284
- return v;
285
- }
286
-
287
- /** Reads a 64-bit float. @param be - big-endian if true (default little-endian). */
288
- readF64(be?: boolean): number {
289
- if (!this.has(8)) return 0;
290
- const v = this.view.getFloat64(this.off, !be);
291
- this.off += 8;
292
- return v;
293
- }
294
-
295
- /** Reads a boolean (any non-zero byte is true). */
296
- readBool(): boolean {
297
- return this.readU8() !== 0;
298
- }
299
-
300
- /** Reads a `u32`-length-prefixed byte blob (empty past end). @param be - endianness of the prefix. */
301
- readBytes(be?: boolean): Uint8Array {
302
- const len = this.readU32(be);
303
- if (!this.has(len)) return new Uint8Array(0);
304
- const out = this.buf.slice(this.off, this.off + len);
305
- this.off += len;
306
- return out;
307
- }
308
-
309
- /** Reads a `u32`-byte-length-prefixed UTF-8 string (empty past end). @param be - endianness of the prefix. */
310
- readString(be?: boolean): string {
311
- const len = this.readU32(be);
312
- if (!this.has(len)) return '';
313
- const s = utf8Decoder.decode(this.buf.subarray(this.off, this.off + len));
314
- this.off += len;
315
- return s;
316
- }
317
-
318
- /** Reads an unsigned 128-bit integer. @param be - big-endian if true (default little-endian). */
319
- readU128(be?: boolean): bigint {
320
- return this.readLimbs(2, !!be);
321
- }
322
-
323
- /** Reads a signed 128-bit integer (two's complement). @param be - big-endian if true. */
324
- readI128(be?: boolean): bigint {
325
- return BigInt.asIntN(128, this.readLimbs(2, !!be));
326
- }
327
-
328
- /** Reads an unsigned 256-bit integer. @param be - big-endian if true (default little-endian). */
329
- readU256(be?: boolean): bigint {
330
- return this.readLimbs(4, !!be);
331
- }
332
-
333
- /** Reads a signed 256-bit integer (two's complement). @param be - big-endian if true. */
334
- readI256(be?: boolean): bigint {
335
- return BigInt.asIntN(256, this.readLimbs(4, !!be));
336
- }
337
-
338
- /** Bytes left to read. */
339
- remaining(): number {
340
- return this.buf.length - this.off;
341
- }
342
-
343
- /** Returns true (and leaves `off` advanceable) if `n` more bytes are available; else clears `ok`. */
344
- private has(n: number): boolean {
345
- if (n < 0 || this.off + n > this.buf.length) {
346
- this.ok = false;
347
- return false;
348
- }
349
- return true;
350
- }
351
-
352
- /** Reads `count` 64-bit limbs and recombines them (low limb first in LE, high first in BE). */
353
- private readLimbs(count: number, be: boolean): bigint {
354
- let result = 0n;
355
- if (be) {
356
- for (let i = count - 1; i >= 0; i--) result |= this.readU64(true) << BigInt(i * 64);
357
- } else {
358
- for (let i = 0; i < count; i++) result |= this.readU64(false) << BigInt(i * 64);
359
- }
360
- return result;
361
- }
362
- }
package/src/io/index.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * toiljs IO, native binary serialization + fast collections, exposed to the client both as
3
- * `toiljs/io` imports and as ambient globals (see the generated `.toil/toil-env.d.ts`).
4
- */
5
- export { FastMap } from './FastMap.js';
6
- export { FastSet } from './FastSet.js';
7
- export { DataWriter, DataReader } from './codec.js';
8
-
9
- export type { PropertyExtendedKey, FastRecord, IndexKey } from './FastMap.js';
10
- export type { i8, i16, i32, i64, u8, u16, u32, u64, Selector, BufferLike } from './types.js';
package/src/io/lengths.ts DELETED
@@ -1,14 +0,0 @@
1
- /** Byte widths for the fixed-size integer types written/read by the binary IO classes. */
2
- export const U8_BYTE_LENGTH = 1;
3
- export const U16_BYTE_LENGTH = 2;
4
- export const U32_BYTE_LENGTH = 4;
5
- export const U64_BYTE_LENGTH = 8;
6
-
7
- export const I8_BYTE_LENGTH = 1;
8
- export const I16_BYTE_LENGTH = 2;
9
- export const I32_BYTE_LENGTH = 4;
10
- export const I64_BYTE_LENGTH = 8;
11
-
12
- export const U128_BYTE_LENGTH = 16;
13
- export const I128_BYTE_LENGTH = 16;
14
- export const U256_BYTE_LENGTH = 32;
package/src/io/types.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Branded numeric width aliases used by the binary IO classes. They are plain `number`/`bigint`
3
- * at runtime, the names document intent.
4
- */
5
- export type i8 = number;
6
- export type i16 = number;
7
- export type i32 = number;
8
- export type i64 = bigint;
9
-
10
- export type u8 = number;
11
- export type u16 = number;
12
- export type u32 = number;
13
- export type u64 = bigint;
14
-
15
- /** A method/route selector encoded as a `u32` on the wire. */
16
- export type Selector = number;
17
-
18
- /** Anything that can back a {@link DataReader}. */
19
- export type BufferLike = Uint8Array;
@@ -1,22 +0,0 @@
1
- /**
2
- * Minimal logger placeholder for toiljs. Swapped for the real implementation later.
3
- */
4
-
5
- export enum LogLevel {
6
- Debug = 'debug',
7
- Info = 'info',
8
- Warn = 'warn',
9
- Error = 'error',
10
- }
11
-
12
- export class Logger {
13
- public constructor(private readonly scope: string = 'toil') {}
14
-
15
- public log(level: LogLevel, message: string): void {
16
- console.log(`[${this.scope}] ${level}: ${message}`);
17
- }
18
-
19
- public info(message: string): void {
20
- this.log(LogLevel.Info, message);
21
- }
22
- }