@rdlabo/workers-hono-kit 0.3.5 → 0.3.6
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/dist/db/index.d.ts +2 -2
- package/dist/db/index.js +1 -1
- package/dist/db/orm-config.d.ts +19 -0
- package/dist/db/orm-config.js +3 -1
- package/package.json +1 -1
- package/scripts/db-baseline.mjs +21 -8
- package/src/db/index.ts +2 -2
- package/src/db/orm-config.ts +12 -1
package/dist/db/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type { DzWriteResult } from './write-result.js';
|
|
|
17
17
|
export { hyperdriveConnectionOptions, withMysqlConnections } from './connection.js';
|
|
18
18
|
export type { HyperdriveLike, ExecutionContextLike } from './connection.js';
|
|
19
19
|
export { toJstDate, jstTimestampParams, jstDatetimeParams, jstDateParams } from './jst.js';
|
|
20
|
-
export { DRIZZLE_ORM_OPTIONS, honoDrizzleConfig } from './orm-config.js';
|
|
21
|
-
export type { HonoDrizzleConfigOptions } from './orm-config.js';
|
|
20
|
+
export { DRIZZLE_ORM_OPTIONS, honoDrizzleConfig, resolveDbSecret } from './orm-config.js';
|
|
21
|
+
export type { HonoDrizzleConfigOptions, ResolvedDbSecret } from './orm-config.js';
|
|
22
22
|
export { baselineMigrations, readBaselineEntry } from './migrate.js';
|
|
23
23
|
export type { BaselineMigrationsOptions, BaselineResult, BaselineEntry } from './migrate.js';
|
package/dist/db/index.js
CHANGED
|
@@ -14,5 +14,5 @@ export { createMysqlDatabase, createHyperdriveDatabase, databaseFrom } from './d
|
|
|
14
14
|
export { insertIdOf, affectedRowsOf, insertedIdsOf } from './write-result.js';
|
|
15
15
|
export { hyperdriveConnectionOptions, withMysqlConnections } from './connection.js';
|
|
16
16
|
export { toJstDate, jstTimestampParams, jstDatetimeParams, jstDateParams } from './jst.js';
|
|
17
|
-
export { DRIZZLE_ORM_OPTIONS, honoDrizzleConfig } from './orm-config.js';
|
|
17
|
+
export { DRIZZLE_ORM_OPTIONS, honoDrizzleConfig, resolveDbSecret } from './orm-config.js';
|
|
18
18
|
export { baselineMigrations, readBaselineEntry } from './migrate.js';
|
package/dist/db/orm-config.d.ts
CHANGED
|
@@ -102,3 +102,22 @@ export declare function honoDrizzleConfig(options: HonoDrizzleConfigOptions): {
|
|
|
102
102
|
out: string;
|
|
103
103
|
casing: "snake_case";
|
|
104
104
|
};
|
|
105
|
+
/** {@link resolveDbSecret} の戻り値(正規化済みの接続情報)。 */
|
|
106
|
+
export interface ResolvedDbSecret {
|
|
107
|
+
host: string;
|
|
108
|
+
port: number;
|
|
109
|
+
dbname: string;
|
|
110
|
+
username: string;
|
|
111
|
+
password: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* AWS RDS マネージド secret(`DB_SECRET` に入れた JSON 文字列)を解決する。
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* - `DB_SECRET` 未設定 → `undefined`(ローカル/`db:generate` の正常フォールバック)。
|
|
118
|
+
* - 設定されている場合は「完全な接続情報」であることを要求し、**不正 JSON / 必須キー欠損は throw**
|
|
119
|
+
* (静かに localhost へフォールバックして事故らせない)。`port` のみ欠損時は 3306 を補う。
|
|
120
|
+
*
|
|
121
|
+
* `honoDrizzleConfig`(db:migrate)と `workers-hono-kit-db-baseline` bin の双方が同じ解釈を使う。
|
|
122
|
+
*/
|
|
123
|
+
export declare function resolveDbSecret(): ResolvedDbSecret | undefined;
|
package/dist/db/orm-config.js
CHANGED
|
@@ -92,8 +92,10 @@ export function honoDrizzleConfig(options) {
|
|
|
92
92
|
* - `DB_SECRET` 未設定 → `undefined`(ローカル/`db:generate` の正常フォールバック)。
|
|
93
93
|
* - 設定されている場合は「完全な接続情報」であることを要求し、**不正 JSON / 必須キー欠損は throw**
|
|
94
94
|
* (静かに localhost へフォールバックして事故らせない)。`port` のみ欠損時は 3306 を補う。
|
|
95
|
+
*
|
|
96
|
+
* `honoDrizzleConfig`(db:migrate)と `workers-hono-kit-db-baseline` bin の双方が同じ解釈を使う。
|
|
95
97
|
*/
|
|
96
|
-
function resolveDbSecret() {
|
|
98
|
+
export function resolveDbSecret() {
|
|
97
99
|
const raw = process.env.DB_SECRET;
|
|
98
100
|
if (!raw) {
|
|
99
101
|
return undefined;
|
package/package.json
CHANGED
package/scripts/db-baseline.mjs
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// npx workers-hono-kit-db-baseline [--migrations ./drizzle]
|
|
16
16
|
import { createConnection } from 'mysql2/promise';
|
|
17
17
|
import { baselineMigrations } from '../dist/db/migrate.js';
|
|
18
|
+
import { resolveDbSecret } from '../dist/db/index.js';
|
|
18
19
|
|
|
19
20
|
function arg(name) {
|
|
20
21
|
const i = process.argv.indexOf(`--${name}`);
|
|
@@ -22,16 +23,28 @@ function arg(name) {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const migrationsFolder = arg('migrations') ?? process.env.MIGRATIONS_DIR ?? './drizzle';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
// db:migrate(honoDrizzleConfig)と同じ DB_SECRET 解釈を共有する。CI/本番は AWS Secrets Manager の
|
|
27
|
+
// RDS マネージド secret を DB_SECRET に渡す運用(不正/欠損は resolveDbSecret が throw)。未設定時は
|
|
28
|
+
// 従来の個別 DB_* env にフォールバック。
|
|
29
|
+
const secret = resolveDbSecret();
|
|
30
|
+
const conn = secret
|
|
31
|
+
? {
|
|
32
|
+
host: secret.host,
|
|
33
|
+
port: secret.port,
|
|
34
|
+
user: secret.username,
|
|
35
|
+
password: secret.password,
|
|
36
|
+
database: secret.dbname,
|
|
37
|
+
}
|
|
38
|
+
: {
|
|
39
|
+
host: process.env.DB_HOST ?? '127.0.0.1',
|
|
40
|
+
port: Number(process.env.DB_PORT ?? '3306'),
|
|
41
|
+
user: process.env.DB_USER ?? 'root',
|
|
42
|
+
password: process.env.DB_PASSWORD ?? 'root',
|
|
43
|
+
database: process.env.DB_NAME,
|
|
44
|
+
};
|
|
32
45
|
|
|
33
46
|
if (!conn.database) {
|
|
34
|
-
console.error('[db:baseline] DB_NAME is required.');
|
|
47
|
+
console.error('[db:baseline] DB_NAME (or DB_SECRET) is required.');
|
|
35
48
|
process.exit(1);
|
|
36
49
|
}
|
|
37
50
|
|
package/src/db/index.ts
CHANGED
|
@@ -32,8 +32,8 @@ export type { HyperdriveLike, ExecutionContextLike } from './connection.js';
|
|
|
32
32
|
|
|
33
33
|
export { toJstDate, jstTimestampParams, jstDatetimeParams, jstDateParams } from './jst.js';
|
|
34
34
|
|
|
35
|
-
export { DRIZZLE_ORM_OPTIONS, honoDrizzleConfig } from './orm-config.js';
|
|
36
|
-
export type { HonoDrizzleConfigOptions } from './orm-config.js';
|
|
35
|
+
export { DRIZZLE_ORM_OPTIONS, honoDrizzleConfig, resolveDbSecret } from './orm-config.js';
|
|
36
|
+
export type { HonoDrizzleConfigOptions, ResolvedDbSecret } from './orm-config.js';
|
|
37
37
|
|
|
38
38
|
export { baselineMigrations, readBaselineEntry } from './migrate.js';
|
|
39
39
|
export type { BaselineMigrationsOptions, BaselineResult, BaselineEntry } from './migrate.js';
|
package/src/db/orm-config.ts
CHANGED
|
@@ -128,6 +128,15 @@ export function honoDrizzleConfig(options: HonoDrizzleConfigOptions) {
|
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/** {@link resolveDbSecret} の戻り値(正規化済みの接続情報)。 */
|
|
132
|
+
export interface ResolvedDbSecret {
|
|
133
|
+
host: string;
|
|
134
|
+
port: number;
|
|
135
|
+
dbname: string;
|
|
136
|
+
username: string;
|
|
137
|
+
password: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
/**
|
|
132
141
|
* AWS RDS マネージド secret(`DB_SECRET` に入れた JSON 文字列)を解決する。
|
|
133
142
|
*
|
|
@@ -135,8 +144,10 @@ export function honoDrizzleConfig(options: HonoDrizzleConfigOptions) {
|
|
|
135
144
|
* - `DB_SECRET` 未設定 → `undefined`(ローカル/`db:generate` の正常フォールバック)。
|
|
136
145
|
* - 設定されている場合は「完全な接続情報」であることを要求し、**不正 JSON / 必須キー欠損は throw**
|
|
137
146
|
* (静かに localhost へフォールバックして事故らせない)。`port` のみ欠損時は 3306 を補う。
|
|
147
|
+
*
|
|
148
|
+
* `honoDrizzleConfig`(db:migrate)と `workers-hono-kit-db-baseline` bin の双方が同じ解釈を使う。
|
|
138
149
|
*/
|
|
139
|
-
function resolveDbSecret():
|
|
150
|
+
export function resolveDbSecret(): ResolvedDbSecret | undefined {
|
|
140
151
|
const raw = process.env.DB_SECRET;
|
|
141
152
|
if (!raw) {
|
|
142
153
|
return undefined;
|