honertia 0.1.4 → 0.1.5

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 CHANGED
@@ -1174,12 +1174,14 @@ export const searchProjects = action(
1174
1174
 
1175
1175
  #### `dbTransaction` - Database Transactions
1176
1176
 
1177
- Run multiple database operations in a transaction with automatic rollback on failure:
1177
+ Run multiple database operations in a transaction with automatic rollback on failure. The database instance is passed explicitly to keep the dependency visible and consistent with other service patterns:
1178
1178
 
1179
1179
  ```typescript
1180
- import { dbTransaction } from 'honertia/effect'
1180
+ import { DatabaseService, dbTransaction } from 'honertia/effect'
1181
1181
 
1182
- yield* dbTransaction(async (tx) => {
1182
+ const db = yield* DatabaseService
1183
+
1184
+ yield* dbTransaction(db, async (tx) => {
1183
1185
  await tx.insert(users).values({ name: 'Alice', email: 'alice@example.com' })
1184
1186
  await tx.update(accounts).set({ balance: 100 }).where(eq(accounts.userId, id))
1185
1187
  // If any operation fails, the entire transaction rolls back
@@ -5,7 +5,7 @@
5
5
  * Actions are fully opt-in - yield* only what you need.
6
6
  */
7
7
  import { Effect } from 'effect';
8
- import { DatabaseService, type AuthUser } from './services.js';
8
+ import { type AuthUser } from './services.js';
9
9
  import { UnauthorizedError, ForbiddenError, Redirect } from './errors.js';
10
10
  /**
11
11
  * Semantic wrapper for Effect actions.
@@ -57,11 +57,14 @@ export declare function authorize(check?: (user: AuthUser) => boolean): Effect.E
57
57
  * Automatically rolls back on any failure.
58
58
  *
59
59
  * @example
60
- * yield* dbTransaction(async (tx) => {
60
+ * const db = yield* DatabaseService
61
+ * yield* dbTransaction(db, async (tx) => {
61
62
  * await tx.insert(users).values({ name: 'Alice' })
62
63
  * await tx.update(accounts).set({ balance: 100 }).where(eq(accounts.userId, id))
63
64
  * return { success: true }
64
65
  * })
65
66
  */
66
- export declare function dbTransaction<T>(operations: (tx: unknown) => Promise<T>): Effect.Effect<T, Error, DatabaseService>;
67
+ export declare function dbTransaction<DB extends {
68
+ transaction: (fn: (tx: unknown) => Promise<T>) => Promise<T>;
69
+ }, T>(db: DB, operations: (tx: unknown) => Promise<T>): Effect.Effect<T, Error>;
67
70
  //# sourceMappingURL=action.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/effect/action.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,EACL,eAAe,EAEf,KAAK,QAAQ,EACd,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,GAChD,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAE1C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CACvB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,GAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,EAAE,KAAK,CAAC,CAoBpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,GACtC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAQ1C"}
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/effect/action.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,GAChD,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAE1C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CACvB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,GAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,EAAE,KAAK,CAAC,CAoBpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAAE,SAAS;IAAE,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CAAE,EAAE,CAAC,EAC1G,EAAE,EAAE,EAAE,EACN,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,GACtC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAKzB"}
@@ -5,7 +5,7 @@
5
5
  * Actions are fully opt-in - yield* only what you need.
6
6
  */
7
7
  import { Effect, Option } from 'effect';
8
- import { DatabaseService, AuthUserService, } from './services.js';
8
+ import { AuthUserService, } from './services.js';
9
9
  import { UnauthorizedError, ForbiddenError } from './errors.js';
10
10
  /**
11
11
  * Semantic wrapper for Effect actions.
@@ -74,18 +74,16 @@ export function authorize(check) {
74
74
  * Automatically rolls back on any failure.
75
75
  *
76
76
  * @example
77
- * yield* dbTransaction(async (tx) => {
77
+ * const db = yield* DatabaseService
78
+ * yield* dbTransaction(db, async (tx) => {
78
79
  * await tx.insert(users).values({ name: 'Alice' })
79
80
  * await tx.update(accounts).set({ balance: 100 }).where(eq(accounts.userId, id))
80
81
  * return { success: true }
81
82
  * })
82
83
  */
83
- export function dbTransaction(operations) {
84
- return Effect.gen(function* () {
85
- const db = yield* DatabaseService;
86
- return yield* Effect.tryPromise({
87
- try: () => db.transaction(operations),
88
- catch: (error) => error instanceof Error ? error : new Error(String(error)),
89
- });
84
+ export function dbTransaction(db, operations) {
85
+ return Effect.tryPromise({
86
+ try: () => db.transaction(operations),
87
+ catch: (error) => error instanceof Error ? error : new Error(String(error)),
90
88
  });
91
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honertia",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Inertia.js-style server-driven SPA adapter for Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",