honertia 0.1.18 → 0.1.20
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.
- package/README.md +132 -84
- package/dist/effect/bridge.d.ts +2 -2
- package/dist/effect/bridge.d.ts.map +1 -1
- package/dist/effect/bridge.js +10 -5
- package/dist/effect/errors.d.ts +13 -1
- package/dist/effect/errors.d.ts.map +1 -1
- package/dist/effect/errors.js +6 -0
- package/dist/effect/index.d.ts +2 -2
- package/dist/effect/index.d.ts.map +1 -1
- package/dist/effect/index.js +2 -2
- package/dist/effect/services.d.ts +57 -3
- package/dist/effect/services.d.ts.map +1 -1
- package/dist/effect/services.js +21 -0
- package/dist/setup.d.ts +19 -6
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,12 +66,12 @@ Deploy the honertia-worker-demo repo to Cloudflare
|
|
|
66
66
|
import { Hono } from 'hono'
|
|
67
67
|
import { logger } from 'hono/logger'
|
|
68
68
|
import { setupHonertia, createTemplate, createVersion, registerErrorHandlers, vite } from 'honertia'
|
|
69
|
-
import { Context, Layer } from 'effect'
|
|
70
69
|
import manifest from '../dist/manifest.json'
|
|
71
70
|
|
|
72
71
|
import type { Env } from './types'
|
|
73
72
|
import { createDb } from './db/db'
|
|
74
73
|
import { createAuth } from './lib/auth'
|
|
74
|
+
import * as schema from './db/schema'
|
|
75
75
|
import { registerRoutes } from './routes'
|
|
76
76
|
|
|
77
77
|
const app = new Hono<Env>()
|
|
@@ -79,13 +79,8 @@ const assetVersion = createVersion(manifest)
|
|
|
79
79
|
const entry = manifest['src/main.tsx']
|
|
80
80
|
const assetPath = (path: string) => `/${path}`
|
|
81
81
|
|
|
82
|
-
class BindingsService extends Context.Tag('app/Bindings')<
|
|
83
|
-
BindingsService,
|
|
84
|
-
{ KV: KVNamespace }
|
|
85
|
-
>() {}
|
|
86
|
-
|
|
87
82
|
// Honertia bundles db/auth setup + core middleware + Effect runtime.
|
|
88
|
-
app.use('*', setupHonertia<Env
|
|
83
|
+
app.use('*', setupHonertia<Env>({
|
|
89
84
|
honertia: {
|
|
90
85
|
// Use your asset manifest hash so Inertia reloads on deploy.
|
|
91
86
|
version: assetVersion,
|
|
@@ -109,12 +104,6 @@ app.use('*', setupHonertia<Env, BindingsService>({
|
|
|
109
104
|
// Schema for route model binding (optional)
|
|
110
105
|
schema,
|
|
111
106
|
},
|
|
112
|
-
effect: {
|
|
113
|
-
// Custom Effect services (e.g., Cloudflare bindings)
|
|
114
|
-
services: (c) => Layer.succeed(BindingsService, {
|
|
115
|
-
KV: c.env.MY_KV,
|
|
116
|
-
}),
|
|
117
|
-
},
|
|
118
107
|
// Optional: extra Hono middleware in the same chain.
|
|
119
108
|
middleware: [
|
|
120
109
|
logger(),
|
|
@@ -780,95 +769,110 @@ Honertia provides these services via Effect's dependency injection:
|
|
|
780
769
|
| `DatabaseService` | Database client (from `c.var.db`) |
|
|
781
770
|
| `AuthService` | Auth instance (from `c.var.auth`) |
|
|
782
771
|
| `AuthUserService` | Authenticated user session |
|
|
772
|
+
| `BindingsService` | Environment bindings (Cloudflare KV, D1, R2, etc.) |
|
|
783
773
|
| `HonertiaService` | Page renderer |
|
|
784
774
|
| `RequestService` | Request context (params, query, body) |
|
|
785
775
|
| `ResponseFactoryService` | Response builders |
|
|
786
776
|
|
|
787
|
-
####
|
|
777
|
+
#### Accessing Cloudflare Bindings
|
|
778
|
+
|
|
779
|
+
Use `BindingsService` to access your Cloudflare bindings (KV, D1, R2, Queues, etc.):
|
|
780
|
+
|
|
781
|
+
```typescript
|
|
782
|
+
import { Effect } from 'effect'
|
|
783
|
+
import { BindingsService, json } from 'honertia/effect'
|
|
784
|
+
|
|
785
|
+
const getDataFromKV = Effect.gen(function* () {
|
|
786
|
+
const { KV } = yield* BindingsService
|
|
787
|
+
const value = yield* Effect.tryPromise(() => KV.get('my-key'))
|
|
788
|
+
return yield* json({ value })
|
|
789
|
+
})
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
For full type safety, add `HonertiaBindingsType` to your module augmentation (see [TypeScript](#typescript) section). You can reference the same `Bindings` type you use for Hono—no duplication needed.
|
|
788
793
|
|
|
789
|
-
|
|
794
|
+
#### Custom Effect Services
|
|
790
795
|
|
|
791
|
-
|
|
796
|
+
For more complex scenarios, use `effect.services` to create proper Effect services:
|
|
792
797
|
|
|
793
|
-
|
|
794
|
-
-
|
|
795
|
-
-
|
|
798
|
+
**When to use custom services instead of `request.env`:**
|
|
799
|
+
- Services that need initialization or cleanup logic
|
|
800
|
+
- Services you want to mock in tests
|
|
801
|
+
- Abstracting third-party APIs into a typed interface
|
|
802
|
+
- Services that combine multiple bindings with business logic
|
|
796
803
|
|
|
797
804
|
```typescript
|
|
798
805
|
import { Effect, Layer, Context } from 'effect'
|
|
799
|
-
import { setupHonertia
|
|
806
|
+
import { setupHonertia } from 'honertia'
|
|
800
807
|
|
|
801
|
-
//
|
|
802
|
-
|
|
803
|
-
|
|
808
|
+
// Example: A rate limiter service that combines KV with business logic
|
|
809
|
+
class RateLimiterService extends Context.Tag('app/RateLimiter')<
|
|
810
|
+
RateLimiterService,
|
|
804
811
|
{
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
DB: D1Database
|
|
812
|
+
check: (key: string, limit: number, windowSeconds: number) => Promise<boolean>
|
|
813
|
+
increment: (key: string) => Promise<void>
|
|
808
814
|
}
|
|
809
815
|
>() {}
|
|
810
816
|
|
|
811
|
-
//
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
817
|
+
// Create the service with initialization logic
|
|
818
|
+
const createRateLimiter = (kv: KVNamespace) => ({
|
|
819
|
+
check: async (key: string, limit: number, windowSeconds: number) => {
|
|
820
|
+
const count = parseInt(await kv.get(key) ?? '0')
|
|
821
|
+
return count < limit
|
|
816
822
|
},
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
ANALYTICS: c.env.ANALYTICS,
|
|
821
|
-
DB: c.env.DB,
|
|
822
|
-
}),
|
|
823
|
+
increment: async (key: string) => {
|
|
824
|
+
const count = parseInt(await kv.get(key) ?? '0')
|
|
825
|
+
await kv.put(key, String(count + 1), { expirationTtl: 60 })
|
|
823
826
|
},
|
|
824
|
-
})
|
|
827
|
+
})
|
|
825
828
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}
|
|
829
|
+
app.use('*', setupHonertia<Env, RateLimiterService>({
|
|
830
|
+
honertia: { version, render },
|
|
831
|
+
effect: {
|
|
832
|
+
services: (c) => Layer.succeed(
|
|
833
|
+
RateLimiterService,
|
|
834
|
+
createRateLimiter(c.env.RATE_LIMIT_KV)
|
|
835
|
+
),
|
|
836
|
+
},
|
|
834
837
|
}))
|
|
835
838
|
|
|
836
|
-
//
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
ANALYTICS: c.env.ANALYTICS,
|
|
841
|
-
DB: c.env.DB,
|
|
842
|
-
}),
|
|
843
|
-
}).group((route) => {
|
|
844
|
-
route.get('/data', getDataFromKV)
|
|
845
|
-
})
|
|
839
|
+
// Use in your action - clean, testable, typed
|
|
840
|
+
const createProject = Effect.gen(function* () {
|
|
841
|
+
const rateLimiter = yield* RateLimiterService
|
|
842
|
+
const auth = yield* authorize()
|
|
846
843
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
const bindings = yield* BindingsService
|
|
850
|
-
const value = yield* Effect.tryPromise(() =>
|
|
851
|
-
bindings.KV.get('my-key')
|
|
844
|
+
const allowed = yield* Effect.tryPromise(() =>
|
|
845
|
+
rateLimiter.check(`create:${auth.user.id}`, 10, 60)
|
|
852
846
|
)
|
|
853
|
-
|
|
847
|
+
if (!allowed) {
|
|
848
|
+
return yield* httpError(429, 'Rate limit exceeded')
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// ... create project ...
|
|
852
|
+
|
|
853
|
+
yield* Effect.tryPromise(() => rateLimiter.increment(`create:${auth.user.id}`))
|
|
854
|
+
return yield* redirect('/projects')
|
|
854
855
|
})
|
|
855
856
|
```
|
|
856
857
|
|
|
857
|
-
|
|
858
|
+
**Multiple services with `Layer.mergeAll`:**
|
|
858
859
|
|
|
859
860
|
```typescript
|
|
860
|
-
app.use('*',
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
),
|
|
861
|
+
app.use('*', setupHonertia<Env, RateLimiterService | QueueService>({
|
|
862
|
+
honertia: { version, render },
|
|
863
|
+
effect: {
|
|
864
|
+
services: (c) => Layer.mergeAll(
|
|
865
|
+
Layer.succeed(RateLimiterService, createRateLimiter(c.env.RATE_LIMIT_KV)),
|
|
866
|
+
Layer.succeed(QueueService, { queue: c.env.MY_QUEUE }),
|
|
867
|
+
),
|
|
868
|
+
},
|
|
869
869
|
}))
|
|
870
870
|
```
|
|
871
871
|
|
|
872
|
+
**Summary:**
|
|
873
|
+
- **Simple binding access**: Use `BindingsService` (automatically provided, typed via module augmentation)
|
|
874
|
+
- **Complex services**: Use `effect.services` when you need initialization, testability, or abstraction
|
|
875
|
+
|
|
872
876
|
### Routing
|
|
873
877
|
|
|
874
878
|
Use `effectRoutes` for Laravel-style route definitions:
|
|
@@ -1717,39 +1721,83 @@ const Layout: HonertiaPage<Props> = ({ auth, children }) => {
|
|
|
1717
1721
|
|
|
1718
1722
|
### Typed Services via Module Augmentation
|
|
1719
1723
|
|
|
1720
|
-
|
|
1724
|
+
Define your types once in `types.ts` and use them for both Hono and Effect services:
|
|
1721
1725
|
|
|
1722
1726
|
```typescript
|
|
1723
|
-
// src/types.
|
|
1727
|
+
// src/types.ts
|
|
1728
|
+
import type { D1Database } from '@cloudflare/workers-types'
|
|
1724
1729
|
import type { Database } from '~/db/db'
|
|
1725
|
-
import type {
|
|
1730
|
+
import type { Auth } from '~/lib/auth'
|
|
1726
1731
|
import * as schema from '~/db/schema'
|
|
1727
1732
|
|
|
1733
|
+
// Define bindings ONCE
|
|
1734
|
+
export type Bindings = {
|
|
1735
|
+
DB: D1Database
|
|
1736
|
+
BETTER_AUTH_SECRET: string
|
|
1737
|
+
ENVIRONMENT?: string
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
export type Variables = {
|
|
1741
|
+
db: Database
|
|
1742
|
+
auth: Auth
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
// Export for Hono
|
|
1746
|
+
export type Env = {
|
|
1747
|
+
Bindings: Bindings
|
|
1748
|
+
Variables: Variables
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
// Module augmentation references the same types
|
|
1728
1752
|
declare module 'honertia/effect' {
|
|
1729
1753
|
interface HonertiaDatabaseType {
|
|
1730
|
-
type: Database
|
|
1731
|
-
schema: typeof schema
|
|
1754
|
+
type: Database
|
|
1755
|
+
schema: typeof schema
|
|
1732
1756
|
}
|
|
1733
1757
|
|
|
1734
1758
|
interface HonertiaAuthType {
|
|
1735
|
-
type:
|
|
1759
|
+
type: Auth
|
|
1736
1760
|
}
|
|
1761
|
+
|
|
1762
|
+
interface HonertiaBindingsType {
|
|
1763
|
+
type: Bindings
|
|
1737
1764
|
}
|
|
1738
1765
|
```
|
|
1739
1766
|
|
|
1740
|
-
|
|
1767
|
+
Now use the `Env` type for Hono and get full type safety everywhere:
|
|
1741
1768
|
|
|
1742
1769
|
```typescript
|
|
1743
|
-
|
|
1770
|
+
// src/index.ts
|
|
1771
|
+
import type { Env } from './types'
|
|
1772
|
+
|
|
1773
|
+
const app = new Hono<Env>()
|
|
1774
|
+
|
|
1775
|
+
app.use('*', setupHonertia<Env>({
|
|
1776
|
+
honertia: {
|
|
1777
|
+
database: (c) => createDb(c.env.DB), // ✅ c.env.DB is typed
|
|
1778
|
+
auth: (c) => createAuth({
|
|
1779
|
+
db: c.var.db, // ✅ c.var.db is typed
|
|
1780
|
+
secret: c.env.BETTER_AUTH_SECRET,
|
|
1781
|
+
}),
|
|
1782
|
+
// ...
|
|
1783
|
+
},
|
|
1784
|
+
}))
|
|
1785
|
+
```
|
|
1786
|
+
|
|
1787
|
+
```typescript
|
|
1788
|
+
// In your actions
|
|
1789
|
+
import { DatabaseService, BindingsService } from 'honertia/effect'
|
|
1790
|
+
|
|
1791
|
+
const db = yield* DatabaseService // ✅ typed as Database
|
|
1792
|
+
const { DB } = yield* BindingsService // ✅ typed as Bindings
|
|
1744
1793
|
|
|
1745
|
-
// DatabaseService respects your module augmentation
|
|
1746
|
-
const db = yield* DatabaseService
|
|
1747
|
-
const auth = yield* AuthService
|
|
1748
1794
|
const projects = yield* Effect.tryPromise(() =>
|
|
1749
|
-
db.query.projects.findMany()
|
|
1795
|
+
db.query.projects.findMany() // ✅ full type safety
|
|
1750
1796
|
)
|
|
1751
1797
|
```
|
|
1752
1798
|
|
|
1799
|
+
One type definition, used everywhere—no duplication.
|
|
1800
|
+
|
|
1753
1801
|
## Architecture Notes
|
|
1754
1802
|
|
|
1755
1803
|
### Request-Scoped Services
|
package/dist/effect/bridge.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Layer, ManagedRuntime } from 'effect';
|
|
7
7
|
import type { Context as HonoContext, MiddlewareHandler, Env } from 'hono';
|
|
8
|
-
import { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService } from './services.js';
|
|
8
|
+
import { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService, BindingsService } from './services.js';
|
|
9
9
|
/**
|
|
10
10
|
* Configuration for the Effect bridge.
|
|
11
11
|
*
|
|
@@ -60,7 +60,7 @@ declare module 'hono' {
|
|
|
60
60
|
/**
|
|
61
61
|
* Build the Effect layer from Hono context.
|
|
62
62
|
*/
|
|
63
|
-
export declare function buildContextLayer<E extends Env, CustomServices = never>(c: HonoContext<E>, config?: EffectBridgeConfig<E, CustomServices>): Layer.Layer<RequestService | ResponseFactoryService | HonertiaService | DatabaseService | AuthService | AuthUserService | CustomServices, never, never>;
|
|
63
|
+
export declare function buildContextLayer<E extends Env, CustomServices = never>(c: HonoContext<E>, config?: EffectBridgeConfig<E, CustomServices>): Layer.Layer<RequestService | ResponseFactoryService | HonertiaService | DatabaseService | AuthService | AuthUserService | BindingsService | CustomServices, never, never>;
|
|
64
64
|
/**
|
|
65
65
|
* Get the Effect runtime from Hono context.
|
|
66
66
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/effect/bridge.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/effect/bridge.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAE9C,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAC1E,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,eAAe,EAQhB,MAAM,eAAe,CAAA;AAEtB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,GAAG,EAAE,cAAc,GAAG,KAAK;IACvE;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;IAC3E;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC;AAED;;GAEG;AACH,QAAA,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ErC"}
|
package/dist/effect/bridge.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Middleware that connects Hono's request handling to Effect's runtime.
|
|
5
5
|
*/
|
|
6
6
|
import { Layer, ManagedRuntime } from 'effect';
|
|
7
|
-
import {
|
|
7
|
+
import { HonertiaConfigurationError } from './errors.js';
|
|
8
|
+
import { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService, BindingsService, } from './services.js';
|
|
8
9
|
/**
|
|
9
10
|
* Symbol for storing Effect runtime in Hono context.
|
|
10
11
|
*/
|
|
@@ -25,9 +26,10 @@ function createUnconfiguredServiceProxy(serviceName, configPath, example) {
|
|
|
25
26
|
if (prop === 'then' || prop === Symbol.toStringTag || prop === Symbol.iterator) {
|
|
26
27
|
return undefined;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
throw new HonertiaConfigurationError({
|
|
30
|
+
message,
|
|
31
|
+
hint: `Example: ${example}`,
|
|
32
|
+
});
|
|
31
33
|
},
|
|
32
34
|
});
|
|
33
35
|
}
|
|
@@ -39,6 +41,7 @@ function createRequestContext(c) {
|
|
|
39
41
|
method: c.req.method,
|
|
40
42
|
url: c.req.url,
|
|
41
43
|
headers: c.req.raw.headers,
|
|
44
|
+
env: (c.env ?? {}),
|
|
42
45
|
param: (name) => c.req.param(name),
|
|
43
46
|
params: () => {
|
|
44
47
|
const params = c.req.param();
|
|
@@ -86,6 +89,8 @@ export function buildContextLayer(c, config) {
|
|
|
86
89
|
const requestLayer = Layer.succeed(RequestService, createRequestContext(c));
|
|
87
90
|
const responseLayer = Layer.succeed(ResponseFactoryService, createResponseFactory(c));
|
|
88
91
|
const honertiaLayer = Layer.succeed(HonertiaService, createHonertiaRenderer(c));
|
|
92
|
+
// Bindings layer - always available, typed via module augmentation
|
|
93
|
+
const bindingsLayer = Layer.succeed(BindingsService, (c.env ?? {}));
|
|
89
94
|
// Database layer - provide helpful error proxy if not configured
|
|
90
95
|
const db = c.var?.db;
|
|
91
96
|
const databaseLayer = Layer.succeed(DatabaseService, (db ??
|
|
@@ -94,7 +99,7 @@ export function buildContextLayer(c, config) {
|
|
|
94
99
|
const auth = c.var?.auth;
|
|
95
100
|
const authLayer = Layer.succeed(AuthService, (auth ??
|
|
96
101
|
createUnconfiguredServiceProxy('AuthService', 'auth: (c) => createAuth(...)', 'auth: (c) => betterAuth({ database: c.var.db, ... })')));
|
|
97
|
-
let baseLayer = Layer.mergeAll(requestLayer, responseLayer, honertiaLayer, databaseLayer, authLayer);
|
|
102
|
+
let baseLayer = Layer.mergeAll(requestLayer, responseLayer, honertiaLayer, bindingsLayer, databaseLayer, authLayer);
|
|
98
103
|
if (c.var?.authUser) {
|
|
99
104
|
baseLayer = Layer.merge(baseLayer, Layer.succeed(AuthUserService, c.var.authUser));
|
|
100
105
|
}
|
package/dist/effect/errors.d.ts
CHANGED
|
@@ -70,6 +70,18 @@ export declare class RouteConfigurationError extends RouteConfigurationError_bas
|
|
|
70
70
|
readonly hint?: string;
|
|
71
71
|
}> {
|
|
72
72
|
}
|
|
73
|
+
declare const HonertiaConfigurationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
74
|
+
readonly _tag: "HonertiaConfigurationError";
|
|
75
|
+
} & Readonly<A>;
|
|
76
|
+
/**
|
|
77
|
+
* Honertia Configuration Error - Missing or invalid setupHonertia configuration
|
|
78
|
+
* Thrown when a service (database, auth, schema) is not configured but accessed.
|
|
79
|
+
*/
|
|
80
|
+
export declare class HonertiaConfigurationError extends HonertiaConfigurationError_base<{
|
|
81
|
+
readonly message: string;
|
|
82
|
+
readonly hint?: string;
|
|
83
|
+
}> {
|
|
84
|
+
}
|
|
73
85
|
declare const Redirect_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
|
|
74
86
|
readonly _tag: "Redirect";
|
|
75
87
|
};
|
|
@@ -85,6 +97,6 @@ export declare class Redirect extends Redirect_base<{
|
|
|
85
97
|
/**
|
|
86
98
|
* Union of all application errors
|
|
87
99
|
*/
|
|
88
|
-
export type AppError = ValidationError | UnauthorizedError | NotFoundError | ForbiddenError | HttpError | RouteConfigurationError;
|
|
100
|
+
export type AppError = ValidationError | UnauthorizedError | NotFoundError | ForbiddenError | HttpError | RouteConfigurationError | HonertiaConfigurationError;
|
|
89
101
|
export {};
|
|
90
102
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/effect/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;AAIH;;GAEG;AACH,qBAAa,eAAgB,SAAQ,qBAAoC;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,uBAAsC;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,aAAc,SAAQ,mBAAkC;IACnE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAC9B,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,cAAe,SAAQ,oBAAmC;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,SAAU,SAAQ,eAA8B;IAC3D,QAAQ,CAAC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G;AACH,qBAAa,cAAe,SAAQ,oBAAmC;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,SAAU,SAAQ,eAA8B;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CACxB,CAAC;CAAG;;;;AAEL;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,6BAA4C;IACvF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB,CAAC;CAAG;;;;AAEL;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,gCAA+C;IAC7F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB,CAAC;CAAG;;;;AAEL;;;GAGG;AACH,qBAAa,QAAS,SAAQ,cAA6B;IACzD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAA;CAC3B,CAAC;CAAG;AAEL;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,eAAe,GACf,iBAAiB,GACjB,aAAa,GACb,cAAc,GACd,SAAS,GACT,uBAAuB,GACvB,0BAA0B,CAAA"}
|
package/dist/effect/errors.js
CHANGED
|
@@ -35,6 +35,12 @@ export class HttpError extends Data.TaggedError('HttpError') {
|
|
|
35
35
|
*/
|
|
36
36
|
export class RouteConfigurationError extends Data.TaggedError('RouteConfigurationError') {
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Honertia Configuration Error - Missing or invalid setupHonertia configuration
|
|
40
|
+
* Thrown when a service (database, auth, schema) is not configured but accessed.
|
|
41
|
+
*/
|
|
42
|
+
export class HonertiaConfigurationError extends Data.TaggedError('HonertiaConfigurationError') {
|
|
43
|
+
}
|
|
38
44
|
/**
|
|
39
45
|
* Redirect - Not an error, but uses same control flow
|
|
40
46
|
* This is a tagged class (not error) for redirects
|
package/dist/effect/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Re-exports all Effect-related functionality.
|
|
5
5
|
*/
|
|
6
|
-
export { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService, type AuthUser, type HonertiaRenderer, type RequestContext, type ResponseFactory, type HonertiaDatabaseType, type HonertiaAuthType, type DatabaseType, type SchemaType, type AuthType, } from './services.js';
|
|
7
|
-
export { ValidationError, UnauthorizedError, NotFoundError, ForbiddenError, HttpError, RouteConfigurationError, Redirect, type AppError, } from './errors.js';
|
|
6
|
+
export { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService, BindingsService, type AuthUser, type HonertiaRenderer, type RequestContext, type ResponseFactory, type HonertiaDatabaseType, type HonertiaAuthType, type HonertiaBindingsType, type DatabaseType, type SchemaType, type AuthType, type BindingsType, } from './services.js';
|
|
7
|
+
export { ValidationError, UnauthorizedError, NotFoundError, ForbiddenError, HttpError, RouteConfigurationError, HonertiaConfigurationError, Redirect, type AppError, } from './errors.js';
|
|
8
8
|
export * from './schema.js';
|
|
9
9
|
export { getValidationData, formatSchemaErrors, validate, validateRequest, asValidated, asTrusted, type Validated, type Trusted, } from './validation.js';
|
|
10
10
|
export { effectBridge, buildContextLayer, getEffectRuntime, getEffectSchema, type EffectBridgeConfig, } from './bridge.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/effect/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/effect/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EACf,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,YAAY,GAClB,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,SAAS,EACT,uBAAuB,EACvB,0BAA0B,EAC1B,QAAQ,EACR,KAAK,QAAQ,GACd,MAAM,aAAa,CAAA;AAGpB,cAAc,aAAa,CAAA;AAG3B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,KAAK,SAAS,EACd,KAAK,OAAO,GACb,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAA;AAGpB,OAAO,EACL,aAAa,EACb,MAAM,EACN,MAAM,EACN,eAAe,GAChB,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,MAAM,EACN,SAAS,EACT,UAAU,EACV,aAAa,EACb,KAAK,MAAM,GACZ,MAAM,aAAa,CAAA;AAGpB,OAAO,EACL,QAAQ,EACR,MAAM,EACN,gBAAgB,EAChB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,SAAS,EACT,WAAW,EACX,YAAY,EACZ,KAAK,GACN,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,GACxB,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,KAAK,EACL,SAAS,EACT,aAAa,EACb,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,QAAQ,EACR,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,WAAW,CAAA"}
|
package/dist/effect/index.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Re-exports all Effect-related functionality.
|
|
5
5
|
*/
|
|
6
6
|
// Services
|
|
7
|
-
export { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService, } from './services.js';
|
|
7
|
+
export { DatabaseService, AuthService, AuthUserService, HonertiaService, RequestService, ResponseFactoryService, BindingsService, } from './services.js';
|
|
8
8
|
// Errors
|
|
9
|
-
export { ValidationError, UnauthorizedError, NotFoundError, ForbiddenError, HttpError, RouteConfigurationError, Redirect, } from './errors.js';
|
|
9
|
+
export { ValidationError, UnauthorizedError, NotFoundError, ForbiddenError, HttpError, RouteConfigurationError, HonertiaConfigurationError, Redirect, } from './errors.js';
|
|
10
10
|
// Schema Validators
|
|
11
11
|
export * from './schema.js';
|
|
12
12
|
// Validation Helpers
|
|
@@ -72,6 +72,29 @@ interface AuthNotConfigured {
|
|
|
72
72
|
export type AuthType = HonertiaAuthType extends {
|
|
73
73
|
type: infer T;
|
|
74
74
|
} ? T : AuthNotConfigured;
|
|
75
|
+
/**
|
|
76
|
+
* Augmentable interface for environment bindings type.
|
|
77
|
+
* Users can extend this via module augmentation:
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* declare module 'honertia/effect' {
|
|
82
|
+
* interface HonertiaBindingsType {
|
|
83
|
+
* type: {
|
|
84
|
+
* DB: D1Database
|
|
85
|
+
* KV: KVNamespace
|
|
86
|
+
* ANALYTICS: AnalyticsEngineDataset
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export interface HonertiaBindingsType {
|
|
93
|
+
}
|
|
94
|
+
/** Extract bindings type from augmented interface, defaults to Record<string, unknown> if not configured */
|
|
95
|
+
export type BindingsType = HonertiaBindingsType extends {
|
|
96
|
+
type: infer T;
|
|
97
|
+
} ? T : Record<string, unknown>;
|
|
75
98
|
/**
|
|
76
99
|
* Database Service - Generic database client
|
|
77
100
|
*/
|
|
@@ -84,6 +107,27 @@ export declare class DatabaseService extends DatabaseService_base {
|
|
|
84
107
|
declare const AuthService_base: Context.TagClass<AuthService, 'honertia/Auth', AuthType>;
|
|
85
108
|
export declare class AuthService extends AuthService_base {
|
|
86
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Bindings Service - Environment bindings (Cloudflare D1, KV, R2, etc.)
|
|
112
|
+
*
|
|
113
|
+
* Automatically provided by setupHonertia. Use module augmentation for type safety:
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // In your types.d.ts
|
|
118
|
+
* declare module 'honertia/effect' {
|
|
119
|
+
* interface HonertiaBindingsType {
|
|
120
|
+
* type: { DB: D1Database; KV: KVNamespace }
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* // In your action
|
|
125
|
+
* const { KV, DB } = yield* BindingsService
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare const BindingsService_base: Context.TagClass<BindingsService, 'honertia/Bindings', BindingsType>;
|
|
129
|
+
export declare class BindingsService extends BindingsService_base {
|
|
130
|
+
}
|
|
87
131
|
/**
|
|
88
132
|
* Authenticated User - Session with user data
|
|
89
133
|
*/
|
|
@@ -121,12 +165,22 @@ declare const HonertiaService_base: Context.TagClass<HonertiaService, "honertia/
|
|
|
121
165
|
export declare class HonertiaService extends HonertiaService_base {
|
|
122
166
|
}
|
|
123
167
|
/**
|
|
124
|
-
* Request Context - HTTP request data
|
|
168
|
+
* Request Context - HTTP request data and environment bindings
|
|
125
169
|
*/
|
|
126
|
-
export interface RequestContext {
|
|
170
|
+
export interface RequestContext<Bindings = Record<string, unknown>> {
|
|
127
171
|
readonly method: string;
|
|
128
172
|
readonly url: string;
|
|
129
173
|
readonly headers: Headers;
|
|
174
|
+
/**
|
|
175
|
+
* Environment bindings (Cloudflare D1, KV, R2, etc.)
|
|
176
|
+
* Access via: `request.env.DB`, `request.env.KV`, etc.
|
|
177
|
+
*
|
|
178
|
+
* For full type safety, cast to your Bindings type:
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const { DB, KV } = request.env as Bindings
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
readonly env: Bindings;
|
|
130
184
|
param(name: string): string | undefined;
|
|
131
185
|
params(): Record<string, string>;
|
|
132
186
|
query(): Record<string, string>;
|
|
@@ -134,7 +188,7 @@ export interface RequestContext {
|
|
|
134
188
|
parseBody(): Promise<Record<string, unknown>>;
|
|
135
189
|
header(name: string): string | undefined;
|
|
136
190
|
}
|
|
137
|
-
declare const RequestService_base: Context.TagClass<RequestService, "honertia/Request", RequestContext
|
|
191
|
+
declare const RequestService_base: Context.TagClass<RequestService, "honertia/Request", RequestContext<Record<string, unknown>>>;
|
|
138
192
|
export declare class RequestService extends RequestService_base {
|
|
139
193
|
}
|
|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MAAM,GAAG,QAAQ,CAAA;IAC7C,QAAQ,IAAI,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CACzC;;AAED,qBAAa,sBAAuB,SAAQ,2BAGzC;CAAG"}
|
package/dist/effect/services.js
CHANGED
|
@@ -16,6 +16,27 @@ export class DatabaseService extends DatabaseService_base {
|
|
|
16
16
|
const AuthService_base = Context.Tag('honertia/Auth')();
|
|
17
17
|
export class AuthService extends AuthService_base {
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Bindings Service - Environment bindings (Cloudflare D1, KV, R2, etc.)
|
|
21
|
+
*
|
|
22
|
+
* Automatically provided by setupHonertia. Use module augmentation for type safety:
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // In your types.d.ts
|
|
27
|
+
* declare module 'honertia/effect' {
|
|
28
|
+
* interface HonertiaBindingsType {
|
|
29
|
+
* type: { DB: D1Database; KV: KVNamespace }
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // In your action
|
|
34
|
+
* const { KV, DB } = yield* BindingsService
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const BindingsService_base = Context.Tag('honertia/Bindings')();
|
|
38
|
+
export class BindingsService extends BindingsService_base {
|
|
39
|
+
}
|
|
19
40
|
export class AuthUserService extends Context.Tag('honertia/AuthUser')() {
|
|
20
41
|
}
|
|
21
42
|
export class HonertiaService extends Context.Tag('honertia/Honertia')() {
|
package/dist/setup.d.ts
CHANGED
|
@@ -9,8 +9,12 @@ import type { HonertiaConfig } from './types.js';
|
|
|
9
9
|
import { type EffectBridgeConfig } from './effect/bridge.js';
|
|
10
10
|
/**
|
|
11
11
|
* Extended Honertia configuration with database, auth, and schema.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam E - Hono environment type
|
|
14
|
+
* @typeParam DB - Database client type (inferred from database factory return type)
|
|
15
|
+
* @typeParam Auth - Auth client type (inferred from auth factory return type)
|
|
12
16
|
*/
|
|
13
|
-
export interface HonertiaFullConfig<E extends Env = Env> extends HonertiaConfig {
|
|
17
|
+
export interface HonertiaFullConfig<E extends Env = Env, DB = unknown, Auth = unknown> extends HonertiaConfig {
|
|
14
18
|
/**
|
|
15
19
|
* Database factory function.
|
|
16
20
|
* Creates the database client for each request.
|
|
@@ -20,7 +24,7 @@ export interface HonertiaFullConfig<E extends Env = Env> extends HonertiaConfig
|
|
|
20
24
|
* database: (c) => createDb(c.env.DATABASE_URL)
|
|
21
25
|
* ```
|
|
22
26
|
*/
|
|
23
|
-
database?: (c: Context<E>) =>
|
|
27
|
+
database?: (c: Context<E>) => DB;
|
|
24
28
|
/**
|
|
25
29
|
* Auth factory function.
|
|
26
30
|
* Creates the auth client for each request.
|
|
@@ -35,7 +39,11 @@ export interface HonertiaFullConfig<E extends Env = Env> extends HonertiaConfig
|
|
|
35
39
|
* })
|
|
36
40
|
* ```
|
|
37
41
|
*/
|
|
38
|
-
auth?: (c: Context<E
|
|
42
|
+
auth?: (c: Context<E & {
|
|
43
|
+
Variables: {
|
|
44
|
+
db: DB;
|
|
45
|
+
};
|
|
46
|
+
}>) => Auth;
|
|
39
47
|
/**
|
|
40
48
|
* Drizzle schema for route model binding.
|
|
41
49
|
* Required if using Laravel-style route model binding.
|
|
@@ -53,12 +61,17 @@ export interface HonertiaFullConfig<E extends Env = Env> extends HonertiaConfig
|
|
|
53
61
|
}
|
|
54
62
|
/**
|
|
55
63
|
* Configuration for Honertia setup.
|
|
64
|
+
*
|
|
65
|
+
* @typeParam E - Hono environment type
|
|
66
|
+
* @typeParam DB - Database client type (inferred from database factory)
|
|
67
|
+
* @typeParam Auth - Auth client type (inferred from auth factory)
|
|
68
|
+
* @typeParam CustomServices - Custom Effect services
|
|
56
69
|
*/
|
|
57
|
-
export interface HonertiaSetupConfig<E extends Env = Env, CustomServices = never> {
|
|
70
|
+
export interface HonertiaSetupConfig<E extends Env = Env, DB = unknown, Auth = unknown, CustomServices = never> {
|
|
58
71
|
/**
|
|
59
72
|
* Honertia core configuration including database, auth, and schema.
|
|
60
73
|
*/
|
|
61
|
-
honertia: HonertiaFullConfig<E>;
|
|
74
|
+
honertia: HonertiaFullConfig<E, DB, Auth>;
|
|
62
75
|
/**
|
|
63
76
|
* Effect bridge configuration (optional).
|
|
64
77
|
* Only needed for custom Effect services.
|
|
@@ -108,7 +121,7 @@ export interface HonertiaSetupConfig<E extends Env = Env, CustomServices = never
|
|
|
108
121
|
* }))
|
|
109
122
|
* ```
|
|
110
123
|
*/
|
|
111
|
-
export declare function setupHonertia<E extends Env, CustomServices = never>(config: HonertiaSetupConfig<E, CustomServices>): MiddlewareHandler<E>;
|
|
124
|
+
export declare function setupHonertia<E extends Env, DB = unknown, Auth = unknown, CustomServices = never>(config: HonertiaSetupConfig<E, DB, Auth, CustomServices>): MiddlewareHandler<E>;
|
|
112
125
|
/**
|
|
113
126
|
* Error handler configuration.
|
|
114
127
|
*/
|
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE1E
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CA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,EAAE,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,cAAc,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CA4ChF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,GAAG,EAAE,MAAM,GAAE,kBAAuB;kBAQ3D,OAAO,CAAC,CAAC,CAAC;mBAOT,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC;EAa3C;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,GAAG,EACjD,GAAG,EAAE;IAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IAAC,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAA;CAAE,EAC1E,MAAM,GAAE,kBAAuB,GAC9B,IAAI,CAIN"}
|
package/dist/setup.js
CHANGED
|
@@ -46,8 +46,9 @@ export function setupHonertia(config) {
|
|
|
46
46
|
if (database) {
|
|
47
47
|
c.set('db', database(c));
|
|
48
48
|
}
|
|
49
|
-
// Set up auth (can access c.var.db)
|
|
49
|
+
// Set up auth (can access c.var.db since database middleware ran first)
|
|
50
50
|
if (auth) {
|
|
51
|
+
// Cast c to include db in Variables since we just set it above
|
|
51
52
|
c.set('auth', auth(c));
|
|
52
53
|
}
|
|
53
54
|
await next();
|