bun-types 1.1.37-canary.20241124T140524 → 1.1.37

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 (272) hide show
  1. package/docs/api/binary-data.md +1028 -0
  2. package/docs/api/cc.md +197 -0
  3. package/docs/api/color.md +262 -0
  4. package/docs/api/console.md +38 -0
  5. package/docs/api/dns.md +113 -0
  6. package/docs/api/fetch.md +308 -0
  7. package/docs/api/ffi.md +536 -0
  8. package/docs/api/file-io.md +358 -0
  9. package/docs/api/file-system-router.md +112 -0
  10. package/docs/api/file.md +19 -0
  11. package/docs/api/glob.md +157 -0
  12. package/docs/api/globals.md +387 -0
  13. package/docs/api/hashing.md +314 -0
  14. package/docs/api/html-rewriter.md +31 -0
  15. package/docs/api/http.md +661 -0
  16. package/docs/api/import-meta.md +69 -0
  17. package/docs/api/node-api.md +16 -0
  18. package/docs/api/semver.md +52 -0
  19. package/docs/api/spawn.md +441 -0
  20. package/docs/api/sqlite.md +692 -0
  21. package/docs/api/streams.md +214 -0
  22. package/docs/api/tcp.md +221 -0
  23. package/docs/api/test.md +1 -0
  24. package/docs/api/transpiler.md +274 -0
  25. package/docs/api/udp.md +125 -0
  26. package/docs/api/utils.md +773 -0
  27. package/docs/api/websockets.md +547 -0
  28. package/docs/api/workers.md +230 -0
  29. package/docs/benchmarks.md +120 -0
  30. package/docs/bun-flavored-toml.md +42 -0
  31. package/docs/bundler/executables.md +291 -0
  32. package/docs/bundler/index.md +1543 -0
  33. package/docs/bundler/intro.md +75 -0
  34. package/docs/bundler/loaders.md +288 -0
  35. package/docs/bundler/macros.md +327 -0
  36. package/docs/bundler/plugins.md +30 -0
  37. package/docs/bundler/vs-esbuild.md +1127 -0
  38. package/docs/cli/add.md +163 -0
  39. package/docs/cli/bun-completions.md +3 -0
  40. package/docs/cli/bun-create.md +254 -0
  41. package/docs/cli/bun-dev.md +21 -0
  42. package/docs/cli/bun-install.md +255 -0
  43. package/docs/cli/bun-upgrade.md +39 -0
  44. package/docs/cli/bunx.md +80 -0
  45. package/docs/cli/filter.md +57 -0
  46. package/docs/cli/init.md +40 -0
  47. package/docs/cli/install.md +205 -0
  48. package/docs/cli/link.md +38 -0
  49. package/docs/cli/outdated.md +61 -0
  50. package/docs/cli/patch-commit.md +9 -0
  51. package/docs/cli/pm.md +150 -0
  52. package/docs/cli/publish.md +107 -0
  53. package/docs/cli/remove.md +5 -0
  54. package/docs/cli/run.md +196 -0
  55. package/docs/cli/test.md +247 -0
  56. package/docs/cli/unlink.md +7 -0
  57. package/docs/cli/update.md +34 -0
  58. package/docs/contributing/upgrading-webkit.md +57 -0
  59. package/docs/ecosystem/elysia.md +24 -0
  60. package/docs/ecosystem/express.md +37 -0
  61. package/docs/ecosystem/hono.md +18 -0
  62. package/docs/ecosystem/react.md +65 -0
  63. package/docs/ecosystem/stric.md +37 -0
  64. package/docs/guides/binary/arraybuffer-to-array.md +27 -0
  65. package/docs/guides/binary/arraybuffer-to-blob.md +24 -0
  66. package/docs/guides/binary/arraybuffer-to-buffer.md +25 -0
  67. package/docs/guides/binary/arraybuffer-to-string.md +15 -0
  68. package/docs/guides/binary/arraybuffer-to-typedarray.md +39 -0
  69. package/docs/guides/binary/blob-to-arraybuffer.md +14 -0
  70. package/docs/guides/binary/blob-to-dataview.md +14 -0
  71. package/docs/guides/binary/blob-to-stream.md +14 -0
  72. package/docs/guides/binary/blob-to-string.md +15 -0
  73. package/docs/guides/binary/blob-to-typedarray.md +14 -0
  74. package/docs/guides/binary/buffer-to-arraybuffer.md +14 -0
  75. package/docs/guides/binary/buffer-to-blob.md +14 -0
  76. package/docs/guides/binary/buffer-to-readablestream.md +41 -0
  77. package/docs/guides/binary/buffer-to-string.md +25 -0
  78. package/docs/guides/binary/buffer-to-typedarray.md +14 -0
  79. package/docs/guides/binary/dataview-to-string.md +15 -0
  80. package/docs/guides/binary/typedarray-to-arraybuffer.md +25 -0
  81. package/docs/guides/binary/typedarray-to-blob.md +16 -0
  82. package/docs/guides/binary/typedarray-to-buffer.md +14 -0
  83. package/docs/guides/binary/typedarray-to-dataview.md +14 -0
  84. package/docs/guides/binary/typedarray-to-readablestream.md +41 -0
  85. package/docs/guides/binary/typedarray-to-string.md +16 -0
  86. package/docs/guides/ecosystem/astro.md +72 -0
  87. package/docs/guides/ecosystem/discordjs.md +77 -0
  88. package/docs/guides/ecosystem/docker.md +140 -0
  89. package/docs/guides/ecosystem/drizzle.md +185 -0
  90. package/docs/guides/ecosystem/edgedb.md +228 -0
  91. package/docs/guides/ecosystem/elysia.md +31 -0
  92. package/docs/guides/ecosystem/express.md +40 -0
  93. package/docs/guides/ecosystem/hono.md +39 -0
  94. package/docs/guides/ecosystem/mongoose.md +87 -0
  95. package/docs/guides/ecosystem/neon-drizzle.md +220 -0
  96. package/docs/guides/ecosystem/neon-serverless-postgres.md +55 -0
  97. package/docs/guides/ecosystem/nextjs.md +38 -0
  98. package/docs/guides/ecosystem/nuxt.md +56 -0
  99. package/docs/guides/ecosystem/pm2.md +57 -0
  100. package/docs/guides/ecosystem/prisma.md +140 -0
  101. package/docs/guides/ecosystem/qwik.md +107 -0
  102. package/docs/guides/ecosystem/react.md +49 -0
  103. package/docs/guides/ecosystem/remix.md +78 -0
  104. package/docs/guides/ecosystem/render.md +79 -0
  105. package/docs/guides/ecosystem/sentry.md +52 -0
  106. package/docs/guides/ecosystem/solidstart.md +58 -0
  107. package/docs/guides/ecosystem/ssr-react.md +51 -0
  108. package/docs/guides/ecosystem/stric.md +55 -0
  109. package/docs/guides/ecosystem/sveltekit.md +125 -0
  110. package/docs/guides/ecosystem/systemd.md +113 -0
  111. package/docs/guides/ecosystem/vite.md +70 -0
  112. package/docs/guides/http/cluster.md +66 -0
  113. package/docs/guides/http/fetch-unix.md +33 -0
  114. package/docs/guides/http/fetch.md +24 -0
  115. package/docs/guides/http/file-uploads.md +94 -0
  116. package/docs/guides/http/hot.md +22 -0
  117. package/docs/guides/http/proxy.md +24 -0
  118. package/docs/guides/http/server.md +46 -0
  119. package/docs/guides/http/simple.md +18 -0
  120. package/docs/guides/http/stream-file.md +48 -0
  121. package/docs/guides/http/stream-iterator.md +47 -0
  122. package/docs/guides/http/stream-node-streams-in-bun.md +20 -0
  123. package/docs/guides/http/tls.md +30 -0
  124. package/docs/guides/install/add-dev.md +26 -0
  125. package/docs/guides/install/add-git.md +36 -0
  126. package/docs/guides/install/add-optional.md +25 -0
  127. package/docs/guides/install/add-peer.md +17 -0
  128. package/docs/guides/install/add-tarball.md +33 -0
  129. package/docs/guides/install/add.md +42 -0
  130. package/docs/guides/install/azure-artifacts.md +73 -0
  131. package/docs/guides/install/cicd.md +41 -0
  132. package/docs/guides/install/custom-registry.md +30 -0
  133. package/docs/guides/install/from-npm-install-to-bun-install.md +214 -0
  134. package/docs/guides/install/git-diff-bun-lockfile.md +38 -0
  135. package/docs/guides/install/jfrog-artifactory.md +28 -0
  136. package/docs/guides/install/npm-alias.md +23 -0
  137. package/docs/guides/install/registry-scope.md +36 -0
  138. package/docs/guides/install/trusted.md +48 -0
  139. package/docs/guides/install/workspaces.md +70 -0
  140. package/docs/guides/install/yarnlock.md +42 -0
  141. package/docs/guides/process/argv.md +57 -0
  142. package/docs/guides/process/ctrl-c.md +16 -0
  143. package/docs/guides/process/ipc.md +66 -0
  144. package/docs/guides/process/nanoseconds.md +13 -0
  145. package/docs/guides/process/os-signals.md +39 -0
  146. package/docs/guides/process/spawn-stderr.md +31 -0
  147. package/docs/guides/process/spawn-stdout.md +26 -0
  148. package/docs/guides/process/spawn.md +41 -0
  149. package/docs/guides/process/stdin.md +54 -0
  150. package/docs/guides/read-file/arraybuffer.md +28 -0
  151. package/docs/guides/read-file/buffer.md +19 -0
  152. package/docs/guides/read-file/exists.md +16 -0
  153. package/docs/guides/read-file/json.md +17 -0
  154. package/docs/guides/read-file/mime.md +20 -0
  155. package/docs/guides/read-file/stream.md +26 -0
  156. package/docs/guides/read-file/string.md +22 -0
  157. package/docs/guides/read-file/uint8array.md +21 -0
  158. package/docs/guides/read-file/watch.md +68 -0
  159. package/docs/guides/runtime/cicd.md +43 -0
  160. package/docs/guides/runtime/define-constant.md +145 -0
  161. package/docs/guides/runtime/import-html.md +15 -0
  162. package/docs/guides/runtime/import-json.md +44 -0
  163. package/docs/guides/runtime/import-toml.md +30 -0
  164. package/docs/guides/runtime/read-env.md +32 -0
  165. package/docs/guides/runtime/set-env.md +37 -0
  166. package/docs/guides/runtime/shell.md +40 -0
  167. package/docs/guides/runtime/timezone.md +35 -0
  168. package/docs/guides/runtime/tsconfig-paths.md +29 -0
  169. package/docs/guides/runtime/typescript.md +47 -0
  170. package/docs/guides/runtime/vscode-debugger.md +47 -0
  171. package/docs/guides/runtime/web-debugger.md +82 -0
  172. package/docs/guides/streams/node-readable-to-arraybuffer.md +11 -0
  173. package/docs/guides/streams/node-readable-to-blob.md +11 -0
  174. package/docs/guides/streams/node-readable-to-json.md +12 -0
  175. package/docs/guides/streams/node-readable-to-string.md +12 -0
  176. package/docs/guides/streams/node-readable-to-uint8array.md +11 -0
  177. package/docs/guides/streams/to-array.md +14 -0
  178. package/docs/guides/streams/to-arraybuffer.md +14 -0
  179. package/docs/guides/streams/to-blob.md +14 -0
  180. package/docs/guides/streams/to-buffer.md +15 -0
  181. package/docs/guides/streams/to-json.md +14 -0
  182. package/docs/guides/streams/to-string.md +14 -0
  183. package/docs/guides/streams/to-typedarray.md +22 -0
  184. package/docs/guides/test/bail.md +22 -0
  185. package/docs/guides/test/coverage-threshold.md +60 -0
  186. package/docs/guides/test/coverage.md +44 -0
  187. package/docs/guides/test/happy-dom.md +68 -0
  188. package/docs/guides/test/migrate-from-jest.md +110 -0
  189. package/docs/guides/test/mock-clock.md +48 -0
  190. package/docs/guides/test/mock-functions.md +68 -0
  191. package/docs/guides/test/rerun-each.md +14 -0
  192. package/docs/guides/test/run-tests.md +111 -0
  193. package/docs/guides/test/skip-tests.md +39 -0
  194. package/docs/guides/test/snapshot.md +99 -0
  195. package/docs/guides/test/spy-on.md +46 -0
  196. package/docs/guides/test/testing-library.md +87 -0
  197. package/docs/guides/test/timeout.md +15 -0
  198. package/docs/guides/test/todo-tests.md +67 -0
  199. package/docs/guides/test/update-snapshots.md +50 -0
  200. package/docs/guides/test/watch-mode.md +19 -0
  201. package/docs/guides/util/base64.md +15 -0
  202. package/docs/guides/util/deep-equals.md +39 -0
  203. package/docs/guides/util/deflate.md +18 -0
  204. package/docs/guides/util/detect-bun.md +23 -0
  205. package/docs/guides/util/entrypoint.md +17 -0
  206. package/docs/guides/util/escape-html.md +22 -0
  207. package/docs/guides/util/file-url-to-path.md +14 -0
  208. package/docs/guides/util/gzip.md +18 -0
  209. package/docs/guides/util/hash-a-password.md +54 -0
  210. package/docs/guides/util/import-meta-dir.md +13 -0
  211. package/docs/guides/util/import-meta-file.md +13 -0
  212. package/docs/guides/util/import-meta-path.md +13 -0
  213. package/docs/guides/util/main.md +32 -0
  214. package/docs/guides/util/path-to-file-url.md +14 -0
  215. package/docs/guides/util/sleep.md +22 -0
  216. package/docs/guides/util/version.md +21 -0
  217. package/docs/guides/util/which-path-to-executable-bin.md +15 -0
  218. package/docs/guides/websocket/compression.md +31 -0
  219. package/docs/guides/websocket/context.md +72 -0
  220. package/docs/guides/websocket/pubsub.md +38 -0
  221. package/docs/guides/websocket/simple.md +33 -0
  222. package/docs/guides/write-file/append.md +52 -0
  223. package/docs/guides/write-file/basic.md +44 -0
  224. package/docs/guides/write-file/blob.md +28 -0
  225. package/docs/guides/write-file/cat.md +17 -0
  226. package/docs/guides/write-file/file-cp.md +16 -0
  227. package/docs/guides/write-file/filesink.md +52 -0
  228. package/docs/guides/write-file/response.md +17 -0
  229. package/docs/guides/write-file/stdout.md +21 -0
  230. package/docs/guides/write-file/stream.md +17 -0
  231. package/docs/guides/write-file/unlink.md +23 -0
  232. package/docs/index.md +77 -0
  233. package/docs/install/cache.md +57 -0
  234. package/docs/install/index.md +202 -0
  235. package/docs/install/lifecycle.md +46 -0
  236. package/docs/install/lockfile.md +90 -0
  237. package/docs/install/npmrc.md +75 -0
  238. package/docs/install/overrides.md +73 -0
  239. package/docs/install/patch.md +57 -0
  240. package/docs/install/registries.md +30 -0
  241. package/docs/install/workspaces.md +70 -0
  242. package/docs/installation.md +289 -0
  243. package/docs/project/benchmarking.md +203 -0
  244. package/docs/project/building-windows.md +162 -0
  245. package/docs/project/internals/build-process-for-ci.md +75 -0
  246. package/docs/project/roadmap.md +87 -0
  247. package/docs/quickstart.md +144 -0
  248. package/docs/runtime/autoimport.md +94 -0
  249. package/docs/runtime/bun-apis.md +129 -0
  250. package/docs/runtime/bunfig.md +532 -0
  251. package/docs/runtime/debugger.md +325 -0
  252. package/docs/runtime/env.md +214 -0
  253. package/docs/runtime/hot.md +139 -0
  254. package/docs/runtime/index.md +309 -0
  255. package/docs/runtime/jsx.md +326 -0
  256. package/docs/runtime/loaders.md +127 -0
  257. package/docs/runtime/modules.md +298 -0
  258. package/docs/runtime/nodejs-apis.md +456 -0
  259. package/docs/runtime/plugins.md +605 -0
  260. package/docs/runtime/shell.md +537 -0
  261. package/docs/runtime/typescript.md +60 -0
  262. package/docs/runtime/web-apis.md +128 -0
  263. package/docs/test/coverage.md +91 -0
  264. package/docs/test/dom.md +75 -0
  265. package/docs/test/hot.md +15 -0
  266. package/docs/test/lifecycle.md +81 -0
  267. package/docs/test/mocks.md +236 -0
  268. package/docs/test/snapshots.md +15 -0
  269. package/docs/test/time.md +106 -0
  270. package/docs/test/writing.md +547 -0
  271. package/docs/typescript.md +51 -0
  272. package/package.json +5 -4
@@ -0,0 +1,72 @@
1
+ ---
2
+ name: Build an app with Astro and Bun
3
+ ---
4
+
5
+ Initialize a fresh Astro app with `bun create astro`. The `create-astro` package detects when you are using `bunx` and will automatically install dependencies using `bun`.
6
+
7
+ ```sh
8
+ $ bun create astro
9
+ ╭─────╮ Houston:
10
+ │ ◠ ◡ ◠ We're glad to have you on board.
11
+ ╰─────╯
12
+
13
+ astro v3.1.4 Launch sequence initiated.
14
+
15
+ dir Where should we create your new project?
16
+ ./fumbling-field
17
+
18
+ tmpl How would you like to start your new project?
19
+ Use blog template
20
+ ✔ Template copied
21
+
22
+ deps Install dependencies?
23
+ Yes
24
+ ✔ Dependencies installed
25
+
26
+ ts Do you plan to write TypeScript?
27
+ Yes
28
+
29
+ use How strict should TypeScript be?
30
+ Strict
31
+ ✔ TypeScript customized
32
+
33
+ git Initialize a new git repository?
34
+ Yes
35
+ ✔ Git initialized
36
+
37
+ next Liftoff confirmed. Explore your project!
38
+
39
+ Enter your project directory using cd ./fumbling-field
40
+ Run `bun run dev` to start the dev server. CTRL+C to stop.
41
+ Add frameworks like react or tailwind using astro add.
42
+
43
+ Stuck? Join us at https://astro.build/chat
44
+
45
+ ╭─────╮ Houston:
46
+ │ ◠ ◡ ◠ Good luck out there, astronaut! 🚀
47
+ ╰─────╯
48
+ ```
49
+
50
+ ---
51
+
52
+ Start the dev server with `bunx`.
53
+
54
+ By default, Bun will run the dev server with Node.js. To use the Bun runtime instead, use the `--bun` flag.
55
+
56
+ ```sh
57
+ $ bunx --bun astro dev
58
+ 🚀 astro v3.1.4 started in 200ms
59
+
60
+ ┃ Local http://localhost:4321/
61
+ ┃ Network use --host to expose
62
+ ```
63
+
64
+ ---
65
+
66
+ Open [http://localhost:4321](http://localhost:4321) with your browser to see the result. Astro will hot-reload your app as you edit your source files.
67
+
68
+ {% image src="https://i.imgur.com/Dswiu6w.png" caption="An Astro v3 starter app running on Bun" %}
69
+
70
+ ---
71
+
72
+ Refer to the [Astro docs](https://docs.astro.build/en/getting-started/) for complete documentation.
@@ -0,0 +1,77 @@
1
+ ---
2
+ name: Create a Discord bot
3
+ ---
4
+
5
+ Discord.js works out of the box with Bun. Let's write a simple bot. First create a directory and initialize it with `bun init`.
6
+
7
+ ```bash
8
+ mkdir my-bot
9
+ cd my-bot
10
+ bun init
11
+ ```
12
+
13
+ ---
14
+
15
+ Now install Discord.js.
16
+
17
+ ```bash
18
+ bun add discord.js
19
+ ```
20
+
21
+ ---
22
+
23
+ Before we go further, we need to go to the [Discord developer portal](https://discord.com/developers/applications), login/signup, create a new _Application_, then create a new _Bot_ within that application. Follow the [official guide](https://discordjs.guide/preparations/setting-up-a-bot-application.html#creating-your-bot) for step-by-step instructions.
24
+
25
+ ---
26
+
27
+ Once complete, you'll be presented with your bot's _private key_. Let's add this to a file called `.env.local`. Bun automatically reads this file and loads it into `process.env`.
28
+
29
+ {% callout %}
30
+ This is an example token that has already been invalidated.
31
+ {% /callout %}
32
+
33
+ ```txt#.env.local
34
+ DISCORD_TOKEN=NzkyNzE1NDU0MTk2MDg4ODQy.X-hvzA.Ovy4MCQywSkoMRRclStW4xAYK7I
35
+ ```
36
+
37
+ ---
38
+
39
+ Be sure to add `.env.local` to your `.gitignore`! It is dangerous to check your bot's private key into version control.
40
+
41
+ ```txt#.gitignore
42
+ node_modules
43
+ .env.local
44
+ ```
45
+
46
+ ---
47
+
48
+ Now let's actually write our bot in a new file called `bot.ts`.
49
+
50
+ ```ts#bot.ts
51
+ // import discord.js
52
+ import {Client, Events, GatewayIntentBits} from 'discord.js';
53
+
54
+ // create a new Client instance
55
+ const client = new Client({intents: [GatewayIntentBits.Guilds]});
56
+
57
+ // listen for the client to be ready
58
+ client.once(Events.ClientReady, (c) => {
59
+ console.log(`Ready! Logged in as ${c.user.tag}`);
60
+ });
61
+
62
+ // login with the token from .env.local
63
+ client.login(process.env.DISCORD_TOKEN);
64
+ ```
65
+
66
+ ---
67
+
68
+ Now we can run our bot with `bun run`. It may take a several seconds for the client to initialize the first time you run the file.
69
+
70
+ ```bash
71
+ $ bun run bot.ts
72
+ Ready! Logged in as my-bot#1234
73
+ ```
74
+
75
+ ---
76
+
77
+ You're up and running with a bare-bones Discord.js bot! This is a basic guide to setting up your bot with Bun; we recommend the [official discord.js docs](https://discordjs.guide/) for complete information on the `discord.js` API.
@@ -0,0 +1,140 @@
1
+ ---
2
+ name: Containerize a Bun application with Docker
3
+ ---
4
+
5
+ {% callout %}
6
+ This guide assumes you already have [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed.
7
+ {% /callout %}
8
+
9
+ [Docker](https://www.docker.com) is a platform for packaging and running an application as a lightweight, portable _container_ that encapsulates all the necessary dependencies.
10
+
11
+ ---
12
+
13
+ To _containerize_ our application, we define a `Dockerfile`. This file contains a list of instructions to initialize the container, copy our local project files into it, install dependencies, and starts the application.
14
+
15
+ ```docker#Dockerfile
16
+ # use the official Bun image
17
+ # see all versions at https://hub.docker.com/r/oven/bun/tags
18
+ FROM oven/bun:1 AS base
19
+ WORKDIR /usr/src/app
20
+
21
+ # install dependencies into temp directory
22
+ # this will cache them and speed up future builds
23
+ FROM base AS install
24
+ RUN mkdir -p /temp/dev
25
+ COPY package.json bun.lockb /temp/dev/
26
+ RUN cd /temp/dev && bun install --frozen-lockfile
27
+
28
+ # install with --production (exclude devDependencies)
29
+ RUN mkdir -p /temp/prod
30
+ COPY package.json bun.lockb /temp/prod/
31
+ RUN cd /temp/prod && bun install --frozen-lockfile --production
32
+
33
+ # copy node_modules from temp directory
34
+ # then copy all (non-ignored) project files into the image
35
+ FROM base AS prerelease
36
+ COPY --from=install /temp/dev/node_modules node_modules
37
+ COPY . .
38
+
39
+ # [optional] tests & build
40
+ ENV NODE_ENV=production
41
+ RUN bun test
42
+ RUN bun run build
43
+
44
+ # copy production dependencies and source code into final image
45
+ FROM base AS release
46
+ COPY --from=install /temp/prod/node_modules node_modules
47
+ COPY --from=prerelease /usr/src/app/index.ts .
48
+ COPY --from=prerelease /usr/src/app/package.json .
49
+
50
+ # run the app
51
+ USER bun
52
+ EXPOSE 3000/tcp
53
+ ENTRYPOINT [ "bun", "run", "index.ts" ]
54
+ ```
55
+
56
+ ---
57
+
58
+ Now that you have your docker image, let's look at `.dockerignore` which has the same syntax as `.gitignore`, here you need to specify the files/directories that must not go in any stage of the docker build. An example for a ignore file is
59
+
60
+ ```txt#.dockerignore
61
+ node_modules
62
+ Dockerfile*
63
+ docker-compose*
64
+ .dockerignore
65
+ .git
66
+ .gitignore
67
+ README.md
68
+ LICENSE
69
+ .vscode
70
+ Makefile
71
+ helm-charts
72
+ .env
73
+ .editorconfig
74
+ .idea
75
+ coverage*
76
+ ```
77
+
78
+ ---
79
+
80
+ We'll now use `docker build` to convert this `Dockerfile` into a _Docker image_, a self-contained template containing all the dependencies and configuration required to run the application.
81
+
82
+ The `-t` flag lets us specify a name for the image, and `--pull` tells Docker to automatically download the latest version of the base image (`oven/bun`). The initial build will take longer, as Docker will download all the base images and dependencies.
83
+
84
+ ```bash
85
+ $ docker build --pull -t bun-hello-world .
86
+ [+] Building 0.9s (21/21) FINISHED
87
+ => [internal] load build definition from Dockerfile 0.0s
88
+ => => transferring dockerfile: 37B 0.0s
89
+ => [internal] load .dockerignore 0.0s
90
+ => => transferring context: 35B 0.0s
91
+ => [internal] load metadata for docker.io/oven/bun:1 0.8s
92
+ => [auth] oven/bun:pull token for registry-1.docker.io 0.0s
93
+ => [base 1/2] FROM docker.io/oven/bun:1@sha256:373265748d3cd3624cb3f3ee6004f45b1fc3edbd07a622aeeec17566d2756997 0.0s
94
+ => [internal] load build context 0.0s
95
+ => => transferring context: 155B 0.0s
96
+ # ...lots of commands...
97
+ => exporting to image 0.0s
98
+ => => exporting layers 0.0s
99
+ => => writing image sha256:360663f7fdcd6f11e8e94761d5592e2e4dfc8d167f034f15cd5a863d5dc093c4 0.0s
100
+ => => naming to docker.io/library/bun-hello-world 0.0s
101
+ ```
102
+
103
+ ---
104
+
105
+ We've built a new _Docker image_. Now let's use that image to spin up an actual, running _container_.
106
+
107
+ We'll use `docker run` to start a new container using the `bun-hello-world` image. It will be run in _detached_ mode (`-d`) and we'll map the container's port 3000 to our local machine's port 3000 (`-p 3000:3000`).
108
+
109
+ The `run` command prints a string representing the _container ID_.
110
+
111
+ ```sh
112
+ $ docker run -d -p 3000:3000 bun-hello-world
113
+ 7f03e212a15ede8644379bce11a13589f563d3909a9640446c5bbefce993678d
114
+ ```
115
+
116
+ ---
117
+
118
+ The container is now running in the background. Visit [localhost:3000](http://localhost:3000). You should see a `Hello, World!` message.
119
+
120
+ ---
121
+
122
+ To stop the container, we'll use `docker stop <container-id>`.
123
+
124
+ ```sh
125
+ $ docker stop 7f03e212a15ede8644379bce11a13589f563d3909a9640446c5bbefce993678d
126
+ ```
127
+
128
+ ---
129
+
130
+ If you can't find the container ID, you can use `docker ps` to list all running containers.
131
+
132
+ ```sh
133
+ $ docker ps
134
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
135
+ 7f03e212a15e bun-hello-world "bun run index.ts" 2 minutes ago Up 2 minutes 0.0.0.0:3000->3000/tcp flamboyant_cerf
136
+ ```
137
+
138
+ ---
139
+
140
+ That's it! Refer to the [Docker documentation](https://docs.docker.com/) for more advanced usage.
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: Use Drizzle ORM with Bun
3
+ ---
4
+
5
+ Drizzle is an ORM that supports both a SQL-like "query builder" API and an ORM-like [Queries API](https://orm.drizzle.team/docs/rqb). It supports the `bun:sqlite` built-in module.
6
+
7
+ ---
8
+
9
+ Let's get started by creating a fresh project with `bun init` and installing Drizzle.
10
+
11
+ ```sh
12
+ $ bun init -y
13
+ $ bun add drizzle-orm
14
+ $ bun add -D drizzle-kit
15
+ ```
16
+
17
+ ---
18
+
19
+ Then we'll connect to a SQLite database using the `bun:sqlite` module and create the Drizzle database instance.
20
+
21
+ ```ts#db.ts
22
+ import { drizzle } from "drizzle-orm/bun-sqlite";
23
+ import { Database } from "bun:sqlite";
24
+
25
+ const sqlite = new Database("sqlite.db");
26
+ export const db = drizzle(sqlite);
27
+ ```
28
+
29
+ ---
30
+
31
+ To see the database in action, add these lines to `index.ts`.
32
+
33
+ ```ts#index.ts
34
+ import { db } from "./db";
35
+ import { sql } from "drizzle-orm";
36
+
37
+ const query = sql`select "hello world" as text`;
38
+ const result = db.get<{ text: string }>(query);
39
+ console.log(result);
40
+ ```
41
+
42
+ ---
43
+
44
+ Then run `index.ts` with Bun. Bun will automatically create `sqlite.db` and execute the query.
45
+
46
+ ```sh
47
+ $ bun run index.ts
48
+ {
49
+ text: "hello world"
50
+ }
51
+ ```
52
+
53
+ ---
54
+
55
+ Lets give our database a proper schema. Create a `schema.ts` file and define a `movies` table.
56
+
57
+ ```ts#schema.ts
58
+ import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
59
+
60
+ export const movies = sqliteTable("movies", {
61
+ id: integer("id").primaryKey(),
62
+ title: text("name"),
63
+ releaseYear: integer("release_year"),
64
+ });
65
+ ```
66
+
67
+ ---
68
+
69
+ We can use the `drizzle-kit` CLI to generate an initial SQL migration.
70
+
71
+ ```sh
72
+ $ bunx drizzle-kit generate --dialect sqlite --schema ./schema.ts
73
+ ```
74
+
75
+ ---
76
+
77
+ This creates a new `drizzle` directory containing a `.sql` migration file and `meta` directory.
78
+
79
+ ```txt
80
+ drizzle
81
+ ├── 0000_ordinary_beyonder.sql
82
+ └── meta
83
+ ├── 0000_snapshot.json
84
+ └── _journal.json
85
+ ```
86
+
87
+ ---
88
+
89
+ We can execute these migrations with a simple `migrate.ts` script.
90
+
91
+ This script creates a new connection to a SQLite database that writes to `sqlite.db`, then executes all unexecuted migrations in the `drizzle` directory.
92
+
93
+ ```ts#migrate.ts
94
+ import { migrate } from "drizzle-orm/bun-sqlite/migrator";
95
+
96
+ import { drizzle } from "drizzle-orm/bun-sqlite";
97
+ import { Database } from "bun:sqlite";
98
+
99
+ const sqlite = new Database("sqlite.db");
100
+ const db = drizzle(sqlite);
101
+ await migrate(db, { migrationsFolder: "./drizzle" });
102
+ ```
103
+
104
+ ---
105
+
106
+ We can run this script with `bun` to execute the migration.
107
+
108
+ ```sh
109
+ $ bun run migrate.ts
110
+ ```
111
+
112
+ ---
113
+
114
+ Now that we have a database, let's add some data to it. Create a `seed.ts` file with the following contents.
115
+
116
+ ```ts#seed.ts
117
+ import { db } from "./db";
118
+ import * as schema from "./schema";
119
+
120
+ await db.insert(schema.movies).values([
121
+ {
122
+ title: "The Matrix",
123
+ releaseYear: 1999,
124
+ },
125
+ {
126
+ title: "The Matrix Reloaded",
127
+ releaseYear: 2003,
128
+ },
129
+ {
130
+ title: "The Matrix Revolutions",
131
+ releaseYear: 2003,
132
+ },
133
+ ]);
134
+
135
+ console.log(`Seeding complete.`);
136
+ ```
137
+
138
+ ---
139
+
140
+ Then run this file.
141
+
142
+ ```sh
143
+ $ bun run seed.ts
144
+ Seeding complete.
145
+ ```
146
+
147
+ ---
148
+
149
+ We finally have a database with a schema and some sample data. Let's use Drizzle to query it. Replace the contents of `index.ts` with the following.
150
+
151
+ ```ts#index.ts
152
+ import * as schema from "./schema";
153
+ import { db } from "./db";
154
+
155
+ const result = await db.select().from(schema.movies);
156
+ console.log(result);
157
+ ```
158
+
159
+ ---
160
+
161
+ Then run the file. You should see the three movies we inserted.
162
+
163
+ ```sh
164
+ $ bun run index.ts
165
+ bun run index.ts
166
+ [
167
+ {
168
+ id: 1,
169
+ title: "The Matrix",
170
+ releaseYear: 1999
171
+ }, {
172
+ id: 2,
173
+ title: "The Matrix Reloaded",
174
+ releaseYear: 2003
175
+ }, {
176
+ id: 3,
177
+ title: "The Matrix Revolutions",
178
+ releaseYear: 2003
179
+ }
180
+ ]
181
+ ```
182
+
183
+ ---
184
+
185
+ Refer to the [Drizzle website](https://orm.drizzle.team/docs/overview) for complete documentation.
@@ -0,0 +1,228 @@
1
+ ---
2
+ name: Use EdgeDB with Bun
3
+ ---
4
+
5
+ EdgeDB is a graph-relational database powered by Postgres under the hood. It provides a declarative schema language, migrations system, and object-oriented query language, in addition to supporting raw SQL queries. It solves the object-relational mapping problem at the database layer, eliminating the need for an ORM library in your application code.
6
+
7
+ ---
8
+
9
+ First, [install EdgeDB](https://www.edgedb.com/install) if you haven't already.
10
+
11
+ {% codetabs %}
12
+
13
+ ```sh#Linux/macOS
14
+ $ curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
15
+ ```
16
+
17
+ ```sh#Windows
18
+ $ iwr https://ps1.edgedb.com -useb | iex
19
+ ```
20
+
21
+ {% /codetabs %}
22
+
23
+ ---
24
+
25
+ Use `bun init` to create a fresh project.
26
+
27
+ ```sh
28
+ $ mkdir my-edgedb-app
29
+ $ cd my-edgedb-app
30
+ $ bun init -y
31
+ ```
32
+
33
+ ---
34
+
35
+ We'll use the EdgeDB CLI to initialize an EdgeDB instance for our project. This creates an `edgedb.toml` file in our project root.
36
+
37
+ ```sh
38
+ $ edgedb project init
39
+ No `edgedb.toml` found in `/Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app` or above
40
+ Do you want to initialize a new project? [Y/n]
41
+ > Y
42
+ Specify the name of EdgeDB instance to use with this project [default: my_edgedb_app]:
43
+ > my_edgedb_app
44
+ Checking EdgeDB versions...
45
+ Specify the version of EdgeDB to use with this project [default: x.y]:
46
+ > x.y
47
+ ┌─────────────────────┬────────────────────────────────────────────────────────────────────────┐
48
+ │ Project directory │ /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app │
49
+ │ Project config │ /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app/edgedb.toml │
50
+ │ Schema dir (empty) │ /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app/dbschema │
51
+ │ Installation method │ portable package │
52
+ │ Version │ x.y+6d5921b │
53
+ │ Instance name │ my_edgedb_app │
54
+ └─────────────────────┴────────────────────────────────────────────────────────────────────────┘
55
+ Version x.y+6d5921b is already downloaded
56
+ Initializing EdgeDB instance...
57
+ Applying migrations...
58
+ Everything is up to date. Revision initial
59
+ Project initialized.
60
+ To connect to my_edgedb_app, run `edgedb`
61
+ ```
62
+
63
+ ---
64
+
65
+ To see if the database is running, let's open a REPL and run a simple query.
66
+
67
+ Then run `\quit` to exit the REPL.
68
+
69
+ ```sh
70
+ $ edgedb
71
+ edgedb> select 1 + 1;
72
+ 2
73
+ edgedb> \quit
74
+ ```
75
+
76
+ ---
77
+
78
+ With the project initialized, we can define a schema. The `edgedb project init` command already created a `dbschema/default.esdl` file to contain our schema.
79
+
80
+ ```txt
81
+ dbschema
82
+ ├── default.esdl
83
+ └── migrations
84
+ ```
85
+
86
+ ---
87
+
88
+ Open that file and paste the following contents.
89
+
90
+ ```txt
91
+ module default {
92
+ type Movie {
93
+ required title: str;
94
+ releaseYear: int64;
95
+ }
96
+ };
97
+ ```
98
+
99
+ ---
100
+
101
+ Then generate and apply an initial migration.
102
+
103
+ ```sh
104
+ $ edgedb migration create
105
+ Created /Users/colinmcd94/Documents/bun/fun/examples/my-edgedb-app/dbschema/migrations/00001.edgeql, id: m1uwekrn4ni4qs7ul7hfar4xemm5kkxlpswolcoyqj3xdhweomwjrq
106
+ $ edgedb migrate
107
+ Applied m1uwekrn4ni4qs7ul7hfar4xemm5kkxlpswolcoyqj3xdhweomwjrq (00001.edgeql)
108
+ ```
109
+
110
+ ---
111
+
112
+ With our schema applied, let's execute some queries using EdgeDB's JavaScript client library. We'll install the client library and EdgeDB's codegen CLI, and create a `seed.ts`.file.
113
+
114
+ ```sh
115
+ $ bun add edgedb
116
+ $ bun add -D @edgedb/generate
117
+ $ touch seed.ts
118
+ ```
119
+
120
+ ---
121
+
122
+ Paste the following code into `seed.ts`.
123
+
124
+ The client auto-connects to the database. We insert a couple movies using the `.execute()` method. We will use EdgeQL's `for` expression to turn this bulk insert into a single optimized query.
125
+
126
+ ```ts
127
+ import { createClient } from "edgedb";
128
+
129
+ const client = createClient();
130
+
131
+ const INSERT_MOVIE = `
132
+ with movies := <array<tuple<title: str, year: int64>>>$movies
133
+ for movie in array_unpack(movies) union (
134
+ insert Movie {
135
+ title := movie.title,
136
+ releaseYear := movie.year,
137
+ }
138
+ )
139
+ `;
140
+
141
+ const movies = [
142
+ { title: "The Matrix", year: 1999 },
143
+ { title: "The Matrix Reloaded", year: 2003 },
144
+ { title: "The Matrix Revolutions", year: 2003 },
145
+ ];
146
+
147
+ await client.execute(INSERT_MOVIE, { movies });
148
+
149
+ console.log(`Seeding complete.`);
150
+ process.exit();
151
+ ```
152
+
153
+ ---
154
+
155
+ Then run this file with Bun.
156
+
157
+ ```sh
158
+ $ bun run seed.ts
159
+ Seeding complete.
160
+ ```
161
+
162
+ ---
163
+
164
+ EdgeDB implements a number of code generation tools for TypeScript. To query our newly seeded database in a typesafe way, we'll use `@edgedb/generate` to code-generate the EdgeQL query builder.
165
+
166
+ ```sh
167
+ $ bunx @edgedb/generate edgeql-js
168
+ Generating query builder...
169
+ Detected tsconfig.json, generating TypeScript files.
170
+ To override this, use the --target flag.
171
+ Run `npx @edgedb/generate --help` for full options.
172
+ Introspecting database schema...
173
+ Writing files to ./dbschema/edgeql-js
174
+ Generation complete! 🤘
175
+ Checking the generated query builder into version control
176
+ is not recommended. Would you like to update .gitignore to ignore
177
+ the query builder directory? The following line will be added:
178
+
179
+ dbschema/edgeql-js
180
+
181
+ [y/n] (leave blank for "y")
182
+ > y
183
+ ```
184
+
185
+ ---
186
+
187
+ In `index.ts`, we can import the generated query builder from `./dbschema/edgeql-js` and write a simple select query.
188
+
189
+ ```ts
190
+ import { createClient } from "edgedb";
191
+ import e from "./dbschema/edgeql-js";
192
+
193
+ const client = createClient();
194
+
195
+ const query = e.select(e.Movie, () => ({
196
+ title: true,
197
+ releaseYear: true,
198
+ }));
199
+
200
+ const results = await query.run(client);
201
+ console.log(results);
202
+
203
+ results; // { title: string, releaseYear: number | null }[]
204
+ ```
205
+
206
+ ---
207
+
208
+ Running the file with Bun, we can see the list of movies we inserted.
209
+
210
+ ```sh
211
+ $ bun run index.ts
212
+ [
213
+ {
214
+ title: "The Matrix",
215
+ releaseYear: 1999
216
+ }, {
217
+ title: "The Matrix Reloaded",
218
+ releaseYear: 2003
219
+ }, {
220
+ title: "The Matrix Revolutions",
221
+ releaseYear: 2003
222
+ }
223
+ ]
224
+ ```
225
+
226
+ ---
227
+
228
+ For complete documentation, refer to the [EdgeDB docs](https://www.edgedb.com/docs).