@rdlabo/workers-hono-kit 0.11.1 → 0.12.0-beta.pr48.sha371f5792ce8a

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 (56) hide show
  1. package/README.md +73 -37
  2. package/dist/aws/sts.d.ts +2 -2
  3. package/dist/aws/sts.js +4 -4
  4. package/dist/business-time/index.d.ts +68 -122
  5. package/dist/business-time/index.js +55 -222
  6. package/dist/container/middleware.d.ts +1 -2
  7. package/dist/container/middleware.js +1 -1
  8. package/dist/db/index.d.ts +95 -20
  9. package/dist/db/index.js +56 -15
  10. package/dist/db/payment-failed.d.ts +1 -1
  11. package/dist/db/payment-failed.js +1 -1
  12. package/dist/index.d.ts +0 -3
  13. package/dist/index.js +0 -3
  14. package/dist/mysql/index.d.ts +9 -0
  15. package/dist/mysql/index.js +8 -0
  16. package/dist/testing/auth.d.ts +1 -1
  17. package/dist/testing/db.d.ts +19 -106
  18. package/dist/testing/db.js +3 -95
  19. package/dist/testing/fakes.d.ts +15 -97
  20. package/dist/testing/fakes.js +12 -104
  21. package/dist/testing/index.d.ts +8 -3
  22. package/dist/testing/index.js +8 -2
  23. package/docs/api-business-time.md +47 -30
  24. package/docs/api-db.md +48 -29
  25. package/docs/api-offline.md +11 -15
  26. package/docs/api-root.md +64 -58
  27. package/docs/api-testing.md +41 -13
  28. package/docs/api.md +35 -12
  29. package/docs/cli.md +11 -7
  30. package/docs/data-layer.md +78 -6
  31. package/docs/development.md +125 -5
  32. package/docs/http-auth.md +15 -0
  33. package/docs/realtime-offline.md +15 -0
  34. package/docs/role-policies.md +4 -4
  35. package/docs/testing-operations.md +25 -2
  36. package/package.json +24 -18
  37. package/scripts/db-baseline.mjs +3 -68
  38. package/scripts/workspace-package-smoke.mjs +206 -0
  39. package/dist/business-time/types.d.ts +0 -9
  40. package/dist/business-time/types.js +0 -5
  41. package/dist/db/columns.d.ts +0 -38
  42. package/dist/db/columns.js +0 -38
  43. package/dist/db/connection.d.ts +0 -74
  44. package/dist/db/connection.js +0 -67
  45. package/dist/db/database.d.ts +0 -222
  46. package/dist/db/database.js +0 -146
  47. package/dist/db/jst.d.ts +0 -45
  48. package/dist/db/jst.js +0 -47
  49. package/dist/db/migrate.d.ts +0 -51
  50. package/dist/db/migrate.js +0 -109
  51. package/dist/db/orm-config.d.ts +0 -127
  52. package/dist/db/orm-config.js +0 -122
  53. package/dist/db/retry.d.ts +0 -28
  54. package/dist/db/retry.js +0 -44
  55. package/dist/db/write-result.d.ts +0 -39
  56. package/dist/db/write-result.js +0 -34
package/dist/db/retry.js DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * Run an async unit of work, retrying it on MySQL deadlock errors with exponential backoff.
3
- *
4
- * Retries are triggered only by the `ER_LOCK_DEADLOCK` error code. Each failed attempt waits
5
- * `delay * attempt` milliseconds (linear growth of the base delay) before the next try, and any
6
- * non-deadlock error is rethrown immediately without retrying.
7
- *
8
- * @remarks
9
- * MySQL rolls back the entire transaction when it detects a deadlock, so re-running the same unit
10
- * of work is safe. Pass a `fn` that represents one complete unit — a single statement or an entire
11
- * transaction — because the whole `fn` is re-executed on each retry.
12
- *
13
- * @typeParam T - resolved value produced by `fn`.
14
- * @param fn - the unit of work to execute; it is invoked again from scratch on each retry.
15
- * @param retries - maximum number of attempts (default `3`).
16
- * @param delay - base backoff in milliseconds; attempt N waits `delay * N` (default `100`).
17
- * @returns the value resolved by the first successful call to `fn`.
18
- * @throws the last error thrown by `fn` once retries are exhausted, or any non-deadlock error on
19
- * the first occurrence.
20
- * @example
21
- * ```ts
22
- * await retryWhenDeadlock(() => db.transaction(async (tx) => {
23
- * await tx.insert(orders).values(order);
24
- * await tx.update(stock).set({ qty: sql`qty - 1` }).where(eq(stock.id, order.itemId));
25
- * }));
26
- * ```
27
- */
28
- export async function retryWhenDeadlock(fn, retries = 3, delay = 100) {
29
- for (let attempt = 0; attempt < retries; attempt++) {
30
- const invoke = async () => fn();
31
- const outcome = await invoke().then((value) => ({ ok: true, value }), (error) => ({ ok: false, error }));
32
- if (outcome.ok) {
33
- return outcome.value;
34
- }
35
- const code = outcome.error.code;
36
- if (code === 'ER_LOCK_DEADLOCK' && attempt < retries - 1) {
37
- await new Promise((resolve) => setTimeout(resolve, delay * (attempt + 1)));
38
- continue;
39
- }
40
- throw outcome.error;
41
- }
42
- // Unreachable: the loop returns on success and throws on the final failed attempt.
43
- throw new Error('retryWhenDeadlock: exhausted retries');
44
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * Shape of a Drizzle (mysql2) write result, narrowed to the fields callers actually read.
3
- *
4
- * @remarks
5
- * A mysql2 INSERT/UPDATE/DELETE result is the tuple `[ResultSetHeader, FieldPacket[]]`. Typing the
6
- * result this way lets repositories extract the common values without exposing the raw query
7
- * builder or the full `ResultSetHeader` to the rest of the codebase.
8
- */
9
- export type DzWriteResult = readonly [{
10
- insertId: number;
11
- affectedRows: number;
12
- }, ...unknown[]];
13
- /**
14
- * Extract the auto-increment `insertId` from a write result.
15
- *
16
- * @param result - the result of a Drizzle (mysql2) INSERT/UPDATE/DELETE.
17
- * @returns the `insertId` reported by mysql2 (the id of the first inserted row).
18
- */
19
- export declare function insertIdOf(result: DzWriteResult): number;
20
- /**
21
- * Extract the number of affected rows from a write result.
22
- *
23
- * @param result - the result of a Drizzle (mysql2) INSERT/UPDATE/DELETE.
24
- * @returns the `affectedRows` count reported by mysql2.
25
- */
26
- export declare function affectedRowsOf(result: DzWriteResult): number;
27
- /**
28
- * Reconstruct the auto-increment ids assigned by a bulk INSERT.
29
- *
30
- * @remarks
31
- * mysql2 reports only the first `insertId` for a multi-row INSERT, so the remaining ids are derived
32
- * by assuming a contiguous sequence (`base`, `base + 1`, …). This holds for tables with a standard
33
- * `AUTO_INCREMENT` column and the default `innodb_autoinc_lock_mode`.
34
- *
35
- * @param result - the result of a bulk INSERT.
36
- * @param count - the number of rows that were inserted.
37
- * @returns an array of the `count` auto-increment ids, starting at the reported `insertId`.
38
- */
39
- export declare function insertedIdsOf(result: DzWriteResult, count: number): number[];
@@ -1,34 +0,0 @@
1
- /**
2
- * Extract the auto-increment `insertId` from a write result.
3
- *
4
- * @param result - the result of a Drizzle (mysql2) INSERT/UPDATE/DELETE.
5
- * @returns the `insertId` reported by mysql2 (the id of the first inserted row).
6
- */
7
- export function insertIdOf(result) {
8
- return result[0].insertId;
9
- }
10
- /**
11
- * Extract the number of affected rows from a write result.
12
- *
13
- * @param result - the result of a Drizzle (mysql2) INSERT/UPDATE/DELETE.
14
- * @returns the `affectedRows` count reported by mysql2.
15
- */
16
- export function affectedRowsOf(result) {
17
- return result[0].affectedRows;
18
- }
19
- /**
20
- * Reconstruct the auto-increment ids assigned by a bulk INSERT.
21
- *
22
- * @remarks
23
- * mysql2 reports only the first `insertId` for a multi-row INSERT, so the remaining ids are derived
24
- * by assuming a contiguous sequence (`base`, `base + 1`, …). This holds for tables with a standard
25
- * `AUTO_INCREMENT` column and the default `innodb_autoinc_lock_mode`.
26
- *
27
- * @param result - the result of a bulk INSERT.
28
- * @param count - the number of rows that were inserted.
29
- * @returns an array of the `count` auto-increment ids, starting at the reported `insertId`.
30
- */
31
- export function insertedIdsOf(result, count) {
32
- const base = result[0].insertId;
33
- return Array.from({ length: count }, (_, i) => base + i);
34
- }