bunderstack 0.21.0 → 0.22.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 (137) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +24 -8
  3. package/dist/api/builder.d.ts +2 -2
  4. package/dist/api/builder.js +1 -1
  5. package/dist/api/builder.js.map +1 -1
  6. package/dist/api/context.d.ts +1 -1
  7. package/dist/api/context.d.ts.map +1 -1
  8. package/dist/api/context.js.map +1 -1
  9. package/dist/auth.d.ts +8 -0
  10. package/dist/auth.d.ts.map +1 -1
  11. package/dist/auth.js +14 -0
  12. package/dist/auth.js.map +1 -1
  13. package/dist/backend-internals.d.ts +32 -0
  14. package/dist/backend-internals.d.ts.map +1 -0
  15. package/dist/backend-internals.js +2 -0
  16. package/dist/backend-internals.js.map +1 -0
  17. package/dist/backend.d.ts +26 -0
  18. package/dist/backend.d.ts.map +1 -0
  19. package/dist/backend.js +53 -0
  20. package/dist/backend.js.map +1 -0
  21. package/dist/blueprint-generator.d.ts.map +1 -1
  22. package/dist/blueprint-generator.js +41 -51
  23. package/dist/blueprint-generator.js.map +1 -1
  24. package/dist/config.d.ts +0 -6
  25. package/dist/config.d.ts.map +1 -1
  26. package/dist/config.js.map +1 -1
  27. package/dist/database/adapter.d.ts +10 -3
  28. package/dist/database/adapter.d.ts.map +1 -1
  29. package/dist/database/adapter.js.map +1 -1
  30. package/dist/database/bun-sql.d.ts.map +1 -1
  31. package/dist/database/bun-sql.js +1 -3
  32. package/dist/database/bun-sql.js.map +1 -1
  33. package/dist/database/bun-sqlite.d.ts +8 -0
  34. package/dist/database/bun-sqlite.d.ts.map +1 -0
  35. package/dist/database/bun-sqlite.js +56 -0
  36. package/dist/database/bun-sqlite.js.map +1 -0
  37. package/dist/database/libsql.d.ts.map +1 -1
  38. package/dist/database/libsql.js +25 -3
  39. package/dist/database/libsql.js.map +1 -1
  40. package/dist/database/pglite.d.ts.map +1 -1
  41. package/dist/database/pglite.js +25 -4
  42. package/dist/database/pglite.js.map +1 -1
  43. package/dist/database/postgres-js.d.ts.map +1 -1
  44. package/dist/database/postgres-js.js +1 -3
  45. package/dist/database/postgres-js.js.map +1 -1
  46. package/dist/db.d.ts +1 -2
  47. package/dist/db.d.ts.map +1 -1
  48. package/dist/db.js +5 -3
  49. package/dist/db.js.map +1 -1
  50. package/dist/email.d.ts +3 -1
  51. package/dist/email.d.ts.map +1 -1
  52. package/dist/email.js +9 -2
  53. package/dist/email.js.map +1 -1
  54. package/dist/env.d.ts +1 -1
  55. package/dist/env.d.ts.map +1 -1
  56. package/dist/env.js +1 -4
  57. package/dist/env.js.map +1 -1
  58. package/dist/index.d.ts +3 -108
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +1 -484
  61. package/dist/index.js.map +1 -1
  62. package/dist/jobs/define.d.ts +1 -1
  63. package/dist/jobs/define.d.ts.map +1 -1
  64. package/dist/jobs/define.js.map +1 -1
  65. package/dist/jobs/index.js +1 -1
  66. package/dist/jobs/index.js.map +1 -1
  67. package/dist/jobs/queue.d.ts +1 -1
  68. package/dist/jobs/queue.d.ts.map +1 -1
  69. package/dist/jobs/queue.js +1 -2
  70. package/dist/jobs/queue.js.map +1 -1
  71. package/dist/jobs/worker.d.ts +9 -0
  72. package/dist/jobs/worker.d.ts.map +1 -1
  73. package/dist/jobs/worker.js +32 -3
  74. package/dist/jobs/worker.js.map +1 -1
  75. package/dist/provision-internals.d.ts +1 -1
  76. package/dist/provision-internals.js +1 -1
  77. package/dist/provision-internals.js.map +1 -1
  78. package/dist/provision.d.ts +2 -0
  79. package/dist/provision.d.ts.map +1 -1
  80. package/dist/provision.js +24 -3
  81. package/dist/provision.js.map +1 -1
  82. package/dist/query/infer.d.ts +1 -1
  83. package/dist/query/infer.d.ts.map +1 -1
  84. package/dist/query/infer.js.map +1 -1
  85. package/dist/runtime.d.ts +149 -0
  86. package/dist/runtime.d.ts.map +1 -0
  87. package/dist/runtime.js +522 -0
  88. package/dist/runtime.js.map +1 -0
  89. package/dist/schema-export-pg.js +1 -1
  90. package/dist/schema-export-pg.js.map +1 -1
  91. package/dist/start/index.d.ts +3 -3
  92. package/dist/start/index.d.ts.map +1 -1
  93. package/dist/start/index.js +3 -3
  94. package/dist/start/index.js.map +1 -1
  95. package/dist/storage/background.d.ts +3 -0
  96. package/dist/storage/background.d.ts.map +1 -0
  97. package/dist/storage/background.js +3 -0
  98. package/dist/storage/background.js.map +1 -0
  99. package/dist/testing/auth.d.ts +57 -0
  100. package/dist/testing/auth.d.ts.map +1 -0
  101. package/dist/testing/auth.js +51 -0
  102. package/dist/testing/auth.js.map +1 -0
  103. package/dist/testing/client.d.ts +6 -0
  104. package/dist/testing/client.d.ts.map +1 -0
  105. package/dist/testing/client.js +9 -0
  106. package/dist/testing/client.js.map +1 -0
  107. package/dist/testing/database.d.ts +6 -0
  108. package/dist/testing/database.d.ts.map +1 -0
  109. package/dist/testing/database.js +8 -0
  110. package/dist/testing/database.js.map +1 -0
  111. package/dist/testing/email.d.ts +15 -0
  112. package/dist/testing/email.d.ts.map +1 -0
  113. package/dist/testing/email.js +32 -0
  114. package/dist/testing/email.js.map +1 -0
  115. package/dist/testing/fixture.d.ts +33 -0
  116. package/dist/testing/fixture.d.ts.map +1 -0
  117. package/dist/testing/fixture.js +125 -0
  118. package/dist/testing/fixture.js.map +1 -0
  119. package/dist/testing/jobs.d.ts +32 -0
  120. package/dist/testing/jobs.d.ts.map +1 -0
  121. package/dist/testing/jobs.js +67 -0
  122. package/dist/testing/jobs.js.map +1 -0
  123. package/dist/testing/storage.d.ts +7 -0
  124. package/dist/testing/storage.d.ts.map +1 -0
  125. package/dist/testing/storage.js +29 -0
  126. package/dist/testing/storage.js.map +1 -0
  127. package/dist/testing.d.ts +9 -26
  128. package/dist/testing.d.ts.map +1 -1
  129. package/dist/testing.js +3 -9
  130. package/dist/testing.js.map +1 -1
  131. package/llms.txt +43 -13
  132. package/package.json +23 -15
  133. package/skills/creating-bunderstack-apps/references/application-structure.md +16 -12
  134. package/skills/creating-bunderstack-apps/references/runtime-integrations.md +4 -1
  135. package/skills/migrating-to-bunderstack/SKILL.md +7 -6
  136. package/skills/migrating-to-bunderstack/references/audit-checklist.md +4 -4
  137. package/skills/migrating-to-bunderstack/references/runtime-replacements.md +55 -49
@@ -6,13 +6,12 @@ names; do not change the contracts.
6
6
  ## Modular entry
7
7
 
8
8
  A migrated application has enough configuration to justify `src/bunderstack/`
9
- with `index.ts`, `schema/`, `access.ts`, `auth.ts`, `env.ts`, `jobs/`, and
10
- `api/`. The entry is the only place that assembles them:
9
+ with `backend.ts`, `index.ts`, `schema/`, `access.ts`, `auth.ts`, `env.ts`,
10
+ `jobs/`, and `api/`. The declaration is the only place that assembles them:
11
11
 
12
12
  ```ts
13
- import { createBunderstack } from 'bunderstack'
14
- import { libsql } from 'bunderstack/database/libsql'
15
- import { provision } from 'bunderstack/provision'
13
+ import { bunderstack } from 'bunderstack'
14
+ import { libsql } from 'bunderstack/libsql'
16
15
  import { access } from './access'
17
16
  import { authConfig } from './auth'
18
17
  import { envSchema } from './env'
@@ -20,33 +19,31 @@ import { defineJobs } from './jobs'
20
19
  import { schema } from './schema'
21
20
  import * as v from 'valibot'
22
21
 
23
- export async function createApp(options: { databaseUrl?: string } = {}) {
24
- return createBunderstack({
25
- schema,
26
- access,
27
- env: envSchema,
28
- database: {
29
- adapter: libsql(),
30
- url: options.databaseUrl ?? process.env.DATABASE_URL ?? 'file:./data.db',
31
- },
32
- auth: authConfig,
33
- email: { from: process.env.EMAIL_FROM ?? 'App <no-reply@example.com>' },
34
- storage: {
35
- local: './uploads',
36
- defaultBucket: 'files',
37
- buckets: {
38
- files: {
39
- visibility: 'private',
40
- access: { create: 'authenticated', get: 'owner', delete: 'owner' },
41
- },
22
+ export const backend = bunderstack({
23
+ schema,
24
+ access,
25
+ env: envSchema,
26
+ database: {
27
+ adapter: libsql(),
28
+ url: 'file:./data.db',
29
+ },
30
+ auth: authConfig,
31
+ email: { from: 'App <no-reply@example.com>' },
32
+ storage: {
33
+ local: './uploads',
34
+ defaultBucket: 'files',
35
+ buckets: {
36
+ files: {
37
+ visibility: 'private',
38
+ access: { create: 'authenticated', get: 'owner', delete: 'owner' },
42
39
  },
43
40
  },
44
- realtime: process.env.REDIS_URL ? { redis: process.env.REDIS_URL } : true,
45
- jobs: defineJobs,
46
- middleware: [instrumentation],
47
- api,
48
- })
49
- }
41
+ },
42
+ realtime: true,
43
+ jobs: defineJobs,
44
+ middleware: [instrumentation],
45
+ api,
46
+ })
50
47
 
51
48
  // api/base.ts — the builder is a module value, so router modules import the
52
49
  // bases they need instead of receiving them through the config callback.
@@ -59,7 +56,11 @@ export async function createApp(options: { databaseUrl?: string } = {}) {
59
56
  //
60
57
  // export const api = { projects: projectsRouter }
61
58
 
62
- export const app = await createApp()
59
+ // index.ts
60
+ import { provision } from 'bunderstack/provision'
61
+ import { backend } from './backend'
62
+
63
+ export const app = await backend.start()
63
64
  export const { db, auth, env } = app
64
65
  export type App = typeof app
65
66
 
@@ -67,12 +68,9 @@ await provision(app)
67
68
  ```
68
69
 
69
70
  The database adapter is imported explicitly; there is no implicit driver. Keep
70
- the factory for tests that need an isolated `file::memory:` database.
71
-
72
- Keep unrelated external side effects out of this import graph. The blueprint
73
- command imports the entry with `BUNDERSTACK_INTROSPECT=1`, so a module that
74
- connects to a queue or calls a third-party API at import time breaks
75
- introspection.
71
+ unrelated external side effects out of the backend import graph. The blueprint
72
+ imports the declaration and reads `backend.manifest`; it never starts the app,
73
+ connects to a queue, or needs a special environment flag.
76
74
 
77
75
  Aggregate every domain, Better Auth, plugin, and internal table in the schema
78
76
  object, including `export * from 'bunderstack/schema'`, so migrations cover the
@@ -116,8 +114,11 @@ Production queue work is its own process:
116
114
 
117
115
  ```ts
118
116
  // src/worker.ts
119
- import { app } from './bunderstack'
117
+ import { backend } from './bunderstack/backend'
120
118
 
119
+ const app = await backend.start({
120
+ env: { ...process.env, BUNDERSTACK_ROLE: 'web' },
121
+ })
121
122
  await app.runWorker()
122
123
  ```
123
124
 
@@ -224,7 +225,7 @@ const url = await app.storage.getUrl(key, { expiresIn: 3600 })
224
225
  await app.storage.delete(fileId)
225
226
  ```
226
227
 
227
- Buckets are declared in `createBunderstack()` with their own visibility and
228
+ Buckets are declared in `bunderstack()` with their own visibility and
228
229
  access rules. Delete the AWS or Tigris wrapper and uninstall the SDK. A custom
229
230
  multipart upload route is replaced by the bucket's own upload route unless it
230
231
  performs domain work that cannot move into a job.
@@ -241,7 +242,7 @@ Standard `fetch`, so the `resend` package is uninstalled.
241
242
 
242
243
  ## Env
243
244
 
244
- Pass `envSchema` to `createBunderstack({ env: envSchema })` and read `app.env`
245
+ Pass `envSchema` to `bunderstack({ env: envSchema })` and read `app.env`
245
246
  or `ctx.env`. Remove `@t3-oss/env-core` `createEnv()` calls and `dotenv`; Bun
246
247
  loads `.env` itself. Server variables must not use the `PUBLIC_` prefix, and
247
248
  browser-safe variables must. Declared env appears in the deployment blueprint,
@@ -256,7 +257,7 @@ commit migrations before production:
256
257
 
257
258
  ```json
258
259
  {
259
- "bunderstack": { "entry": "src/bunderstack/index.ts" },
260
+ "bunderstack": { "entry": "src/bunderstack/backend.ts" },
260
261
  "scripts": {
261
262
  "worker": "bun src/worker.ts",
262
263
  "db:generate": "drizzle-kit generate",
@@ -273,14 +274,19 @@ or build output.
273
274
 
274
275
  ## Test and script ownership
275
276
 
276
- A test or script that constructs its own app owns its lifetime:
277
+ A test or script owns its fixture lexically:
277
278
 
278
279
  ```ts
279
- const app = await createApp({ databaseUrl: 'file::memory:' })
280
- try {
281
- await provision(app, { force: true })
282
- // ...
283
- } finally {
284
- await app.close()
285
- }
280
+ await using t = await backend.test({ database: { schema: 'push' } })
281
+ const identity = t.auth.mockSession({
282
+ id: 'user-1',
283
+ email: 'dev@example.com',
284
+ name: 'Developer',
285
+ })
286
+ const client = t.client(identity)
287
+ // ...
286
288
  ```
289
+
290
+ The fixture isolates database, email, storage, realtime, and queue state and is
291
+ disposed at the end of the block. Keep application-specific organization setup
292
+ in a typed helper layered on top of the base user/session auth helper.