@book000/pixivts-db-mysql 0.64.1-beta.9 → 0.65.0-beta.1
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 +3 -3
- package/dist/index.cjs +13 -39
- package/dist/index.d.cts +23 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +23 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -34
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/package.json +6 -6
- package/dist/rolldown-runtime-D7D4PA-g.js +0 -13
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
MySQL response recorder for [`@book000/pixivts`](https://www.npmjs.com/package/@book000/pixivts).
|
|
4
4
|
|
|
5
|
-
Persists every pixiv API response to a MySQL database using [Drizzle ORM](https://orm.drizzle.team/).
|
|
5
|
+
Persists every successful (2xx) pixiv API response to a MySQL database using [Drizzle ORM](https://orm.drizzle.team/).
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -37,7 +37,7 @@ const client = await PixivClient.of(process.env.PIXIV_REFRESH_TOKEN!, {
|
|
|
37
37
|
onResponse: interceptor,
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
// Every API call is now recorded to MySQL automatically
|
|
40
|
+
// Every successful API call is now recorded to MySQL automatically
|
|
41
41
|
const result = await client.illusts.detail({ illustId: 12345 })
|
|
42
42
|
|
|
43
43
|
// Close the pool when done
|
|
@@ -101,7 +101,7 @@ The `responses` table stores one row per API call:
|
|
|
101
101
|
| `response_body` | `LONGTEXT` | NO | Raw response body |
|
|
102
102
|
| `created_at` | `DATETIME(3)` | NO | Timestamp (millisecond precision) |
|
|
103
103
|
|
|
104
|
-
Duplicate rows (same method + endpoint + statusCode +
|
|
104
|
+
Duplicate rows (same method + endpoint + statusCode + urlHash) are silently ignored via `ON DUPLICATE KEY UPDATE`, so the first recorded response for a given URL is kept.
|
|
105
105
|
|
|
106
106
|
## Database Migration
|
|
107
107
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __exportAll = (all,
|
|
10
|
-
let target = {};
|
|
9
|
+
var __exportAll = (all, flags) => {
|
|
10
|
+
let target = Object.setPrototypeOf({}, null);
|
|
11
11
|
for (var name in all) __defProp(target, name, {
|
|
12
12
|
get: all[name],
|
|
13
13
|
enumerable: true
|
|
14
14
|
});
|
|
15
|
-
if (!
|
|
16
|
-
return target;
|
|
15
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
17
17
|
};
|
|
18
18
|
var __copyProps = (to, from, except, desc) => {
|
|
19
19
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -29,7 +29,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
value: mod,
|
|
30
30
|
enumerable: true
|
|
31
31
|
}) : target, mod));
|
|
32
|
-
//#endregion
|
|
33
32
|
let drizzle_orm_mysql2 = require("drizzle-orm/mysql2");
|
|
34
33
|
let mysql2_promise = require("mysql2/promise");
|
|
35
34
|
mysql2_promise = __toESM(mysql2_promise, 1);
|
|
@@ -37,7 +36,7 @@ let drizzle_orm_mysql_core = require("drizzle-orm/mysql-core");
|
|
|
37
36
|
let node_crypto = require("node:crypto");
|
|
38
37
|
node_crypto = __toESM(node_crypto, 1);
|
|
39
38
|
let drizzle_orm = require("drizzle-orm");
|
|
40
|
-
|
|
39
|
+
// src/schema.ts
|
|
41
40
|
/**
|
|
42
41
|
* Drizzle ORM schema for the `responses` table.
|
|
43
42
|
*
|
|
@@ -46,7 +45,7 @@ let drizzle_orm = require("drizzle-orm");
|
|
|
46
45
|
*/
|
|
47
46
|
var schema_exports = /* @__PURE__ */ __exportAll({ responsesTable: () => responsesTable });
|
|
48
47
|
/**
|
|
49
|
-
* The `responses` table stores every HTTP response returned by the pixiv API.
|
|
48
|
+
* The `responses` table stores every successful (2xx) HTTP response returned by the pixiv API.
|
|
50
49
|
*
|
|
51
50
|
* A unique composite index on (method, endpoint, status_code, url_hash) ensures
|
|
52
51
|
* that each unique request/response combination is stored only once, regardless
|
|
@@ -81,8 +80,7 @@ const responsesTable = (0, drizzle_orm_mysql_core.mysqlTable)("responses", {
|
|
|
81
80
|
fsp: 3
|
|
82
81
|
}).notNull()
|
|
83
82
|
}, (table) => [(0, drizzle_orm_mysql_core.uniqueIndex)("idx_unique").on(table.method, table.endpoint, table.statusCode, table.urlHash)]);
|
|
84
|
-
|
|
85
|
-
//#region src/connection.ts
|
|
83
|
+
// src/connection.ts
|
|
86
84
|
/**
|
|
87
85
|
* MySQL connection factory for @book000/pixivts-db-mysql.
|
|
88
86
|
*
|
|
@@ -119,8 +117,7 @@ function createDbConnection(opts) {
|
|
|
119
117
|
})
|
|
120
118
|
};
|
|
121
119
|
}
|
|
122
|
-
|
|
123
|
-
//#region src/migrations.ts
|
|
120
|
+
// src/migrations.ts
|
|
124
121
|
/**
|
|
125
122
|
* Schema bootstrapping for @book000/pixivts-db-mysql.
|
|
126
123
|
*
|
|
@@ -158,8 +155,7 @@ async function bootstrapSchema(db) {
|
|
|
158
155
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
159
156
|
`);
|
|
160
157
|
}
|
|
161
|
-
|
|
162
|
-
//#region src/recorder.ts
|
|
158
|
+
// src/recorder.ts
|
|
163
159
|
/**
|
|
164
160
|
* Response recorder for @book000/pixivts-db-mysql.
|
|
165
161
|
*
|
|
@@ -171,24 +167,6 @@ async function bootstrapSchema(db) {
|
|
|
171
167
|
* The recorder uses Drizzle ORM's `onDuplicateKeyUpdate` to silently ignore
|
|
172
168
|
* duplicate entries (same method + endpoint + statusCode + urlHash).
|
|
173
169
|
*/
|
|
174
|
-
/**
|
|
175
|
-
* Creates a response recorder that persists every pixiv API response to MySQL.
|
|
176
|
-
*
|
|
177
|
-
* @param opts - Connection and bootstrapping options
|
|
178
|
-
* @returns `{ interceptor, db, close }`
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```ts
|
|
182
|
-
* const { interceptor, close } = await createResponseRecorder({
|
|
183
|
-
* host: 'localhost',
|
|
184
|
-
* database: 'pixivts',
|
|
185
|
-
* bootstrap: true,
|
|
186
|
-
* })
|
|
187
|
-
* const client = await PixivClient.of(token, { onResponse: interceptor })
|
|
188
|
-
* // ...
|
|
189
|
-
* await close()
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
170
|
function ninetyDaysAgo() {
|
|
193
171
|
return /* @__PURE__ */ new Date(Date.now() - 7776e6);
|
|
194
172
|
}
|
|
@@ -235,7 +213,7 @@ function createRecorderBundle(db, close) {
|
|
|
235
213
|
};
|
|
236
214
|
}
|
|
237
215
|
/**
|
|
238
|
-
* Creates a response recorder that persists every pixiv API response to MySQL.
|
|
216
|
+
* Creates a response recorder that persists every successful (2xx) pixiv API response to MySQL.
|
|
239
217
|
*
|
|
240
218
|
* @param opts - Connection and bootstrapping options
|
|
241
219
|
* @returns `{ interceptor, db, close }`
|
|
@@ -291,17 +269,13 @@ async function getResponseCount(db, filter) {
|
|
|
291
269
|
*/
|
|
292
270
|
async function getEndpoints(db) {
|
|
293
271
|
const since = ninetyDaysAgo();
|
|
294
|
-
return
|
|
272
|
+
return await db.select({
|
|
295
273
|
method: responsesTable.method,
|
|
296
274
|
endpoint: responsesTable.endpoint,
|
|
297
275
|
statusCode: responsesTable.statusCode,
|
|
298
276
|
count: (0, drizzle_orm.count)()
|
|
299
|
-
}).from(responsesTable).where((0, drizzle_orm.gte)(responsesTable.createdAt, since)).groupBy(responsesTable.method, responsesTable.endpoint, responsesTable.statusCode).orderBy((0, drizzle_orm.desc)((0, drizzle_orm.count)()))
|
|
300
|
-
...r,
|
|
301
|
-
count: r.count
|
|
302
|
-
}));
|
|
277
|
+
}).from(responsesTable).where((0, drizzle_orm.gte)(responsesTable.createdAt, since)).groupBy(responsesTable.method, responsesTable.endpoint, responsesTable.statusCode).orderBy((0, drizzle_orm.desc)((0, drizzle_orm.count)()));
|
|
303
278
|
}
|
|
304
|
-
//#endregion
|
|
305
279
|
exports.addResponse = addResponse;
|
|
306
280
|
exports.bootstrapSchema = bootstrapSchema;
|
|
307
281
|
exports.createDbConnection = createDbConnection;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @book000/pixivts-db-mysql — MySQL response recorder for @book000/pixivts
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { createResponseRecorder } from '@book000/pixivts-db-mysql'
|
|
7
|
+
* import { PixivClient } from '@book000/pixivts'
|
|
8
|
+
*
|
|
9
|
+
* const { interceptor, close } = await createResponseRecorder({
|
|
10
|
+
* host: process.env.DB_HOST,
|
|
11
|
+
* database: 'pixivts',
|
|
12
|
+
* bootstrap: true,
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* const client = await PixivClient.of(process.env.PIXIV_REFRESH_TOKEN!, {
|
|
16
|
+
* onResponse: interceptor,
|
|
17
|
+
* })
|
|
18
|
+
* // ... make API calls, responses are persisted automatically ...
|
|
19
|
+
* await close()
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
1
22
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
2
23
|
import mysql from "mysql2/promise";
|
|
3
24
|
import { ResponseInterceptor, ResponseRecord } from "@book000/pixivts";
|
|
@@ -11,7 +32,7 @@ declare namespace schema_d_exports {
|
|
|
11
32
|
* so that existing databases can be used without migration.
|
|
12
33
|
*/
|
|
13
34
|
/**
|
|
14
|
-
* The `responses` table stores every HTTP response returned by the pixiv API.
|
|
35
|
+
* The `responses` table stores every successful (2xx) HTTP response returned by the pixiv API.
|
|
15
36
|
*
|
|
16
37
|
* A unique composite index on (method, endpoint, status_code, url_hash) ensures
|
|
17
38
|
* that each unique request/response combination is stored only once, regardless
|
|
@@ -232,8 +253,6 @@ export declare const responsesTable: import("drizzle-orm/mysql-core").MySqlTable
|
|
|
232
253
|
type NewResponse = typeof responsesTable.$inferInsert;
|
|
233
254
|
/** Type for a selected response record. */
|
|
234
255
|
type ResponseRow = typeof responsesTable.$inferSelect;
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/connection.d.ts
|
|
237
256
|
/** Options for establishing a MySQL connection. */
|
|
238
257
|
interface ConnectionOptions {
|
|
239
258
|
/**
|
|
@@ -279,8 +298,6 @@ export declare function createDbConnection(opts: ConnectionOptions): {
|
|
|
279
298
|
pool: mysql.Pool;
|
|
280
299
|
db: DbInstance;
|
|
281
300
|
};
|
|
282
|
-
//#endregion
|
|
283
|
-
//#region src/recorder.d.ts
|
|
284
301
|
/** The object returned by `createResponseRecorder()`. */
|
|
285
302
|
interface RecorderBundle {
|
|
286
303
|
/**
|
|
@@ -323,7 +340,7 @@ export declare function addResponse(db: DbInstance, record: ResponseRecord): Pro
|
|
|
323
340
|
*/
|
|
324
341
|
export declare function createRecorderBundle(db: DbInstance, close: () => Promise<void>): RecorderBundle;
|
|
325
342
|
/**
|
|
326
|
-
* Creates a response recorder that persists every pixiv API response to MySQL.
|
|
343
|
+
* Creates a response recorder that persists every successful (2xx) pixiv API response to MySQL.
|
|
327
344
|
*
|
|
328
345
|
* @param opts - Connection and bootstrapping options
|
|
329
346
|
* @returns `{ interceptor, db, close }`
|
|
@@ -393,8 +410,6 @@ interface EndpointWithCount {
|
|
|
393
410
|
* @returns Endpoints sorted by count descending
|
|
394
411
|
*/
|
|
395
412
|
export declare function getEndpoints(db: DbInstance): Promise<EndpointWithCount[]>;
|
|
396
|
-
//#endregion
|
|
397
|
-
//#region src/migrations.d.ts
|
|
398
413
|
/**
|
|
399
414
|
* Creates the `responses` table if it does not already exist.
|
|
400
415
|
*
|
|
@@ -404,6 +419,5 @@ export declare function getEndpoints(db: DbInstance): Promise<EndpointWithCount[
|
|
|
404
419
|
* @param db - Drizzle ORM database instance
|
|
405
420
|
*/
|
|
406
421
|
export declare function bootstrapSchema(db: DbInstance): Promise<void>;
|
|
407
|
-
//#endregion
|
|
408
422
|
export type { ConnectionOptions, DbInstance, EndpointWithCount, NewResponse, RangeOptions, RecorderBundle, RecorderOptions, ResponseFilter, ResponseRow };
|
|
409
423
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["schema"],"sources":["../src/schema.ts","../src/connection.ts","../src/recorder.ts","../src/migrations.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["schema"],"sources":["../src/schema.ts","../src/connection.ts","../src/recorder.ts","../src/migrations.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwBa,iDAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAuCf,qBAAqB,eAAe;;KAGpC,qBAAqB,eAAe;;UCvD/B;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;;;KAQU,aAAa,kBAAkB,eAAeA;;;;;;;;wBAe1C,mBAAmB,MAAM;EACvC,MAAM,MAAM;EACZ,IAAI;;;UCrCW;;;;;EAKf,aAAa;;EAGb,IAAI;;EAGJ,SAAS;;;UAQM,wBAAwB;;;;;;;EAOvC;;;;;;;;;;;wBAwBoB,YACpB,IAAI,YACJ,QAAQ,iBACP;;;;;;;;;wBA+Ba,qBACd,IAAI,YACJ,aAAa,gBACZ;;;;;;;;;;;;;;;;;;;wBAwBmB,uBACpB,MAAM,kBACL,QAAQ;;UAeM;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;;;;;;;;;wBAWoB,aACpB,IAAI,YACJ,SAAS,gBACT,QAAQ,eACP,QAAQ;;;;;;;;wBAgCW,iBACpB,IAAI,YACJ,SAAS,iBACR;;UAqBc;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;;wBAUoB,aACpB,IAAI,aACH,QAAQ;;;;;;;;;wBC/OW,gBAAgB,IAAI,aAAa"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @book000/pixivts-db-mysql — MySQL response recorder for @book000/pixivts
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { createResponseRecorder } from '@book000/pixivts-db-mysql'
|
|
7
|
+
* import { PixivClient } from '@book000/pixivts'
|
|
8
|
+
*
|
|
9
|
+
* const { interceptor, close } = await createResponseRecorder({
|
|
10
|
+
* host: process.env.DB_HOST,
|
|
11
|
+
* database: 'pixivts',
|
|
12
|
+
* bootstrap: true,
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* const client = await PixivClient.of(process.env.PIXIV_REFRESH_TOKEN!, {
|
|
16
|
+
* onResponse: interceptor,
|
|
17
|
+
* })
|
|
18
|
+
* // ... make API calls, responses are persisted automatically ...
|
|
19
|
+
* await close()
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
1
22
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
2
23
|
import mysql from "mysql2/promise";
|
|
3
24
|
import { ResponseInterceptor, ResponseRecord } from "@book000/pixivts";
|
|
@@ -11,7 +32,7 @@ declare namespace schema_d_exports {
|
|
|
11
32
|
* so that existing databases can be used without migration.
|
|
12
33
|
*/
|
|
13
34
|
/**
|
|
14
|
-
* The `responses` table stores every HTTP response returned by the pixiv API.
|
|
35
|
+
* The `responses` table stores every successful (2xx) HTTP response returned by the pixiv API.
|
|
15
36
|
*
|
|
16
37
|
* A unique composite index on (method, endpoint, status_code, url_hash) ensures
|
|
17
38
|
* that each unique request/response combination is stored only once, regardless
|
|
@@ -232,8 +253,6 @@ export declare const responsesTable: import("drizzle-orm/mysql-core").MySqlTable
|
|
|
232
253
|
type NewResponse = typeof responsesTable.$inferInsert;
|
|
233
254
|
/** Type for a selected response record. */
|
|
234
255
|
type ResponseRow = typeof responsesTable.$inferSelect;
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/connection.d.ts
|
|
237
256
|
/** Options for establishing a MySQL connection. */
|
|
238
257
|
interface ConnectionOptions {
|
|
239
258
|
/**
|
|
@@ -279,8 +298,6 @@ export declare function createDbConnection(opts: ConnectionOptions): {
|
|
|
279
298
|
pool: mysql.Pool;
|
|
280
299
|
db: DbInstance;
|
|
281
300
|
};
|
|
282
|
-
//#endregion
|
|
283
|
-
//#region src/recorder.d.ts
|
|
284
301
|
/** The object returned by `createResponseRecorder()`. */
|
|
285
302
|
interface RecorderBundle {
|
|
286
303
|
/**
|
|
@@ -323,7 +340,7 @@ export declare function addResponse(db: DbInstance, record: ResponseRecord): Pro
|
|
|
323
340
|
*/
|
|
324
341
|
export declare function createRecorderBundle(db: DbInstance, close: () => Promise<void>): RecorderBundle;
|
|
325
342
|
/**
|
|
326
|
-
* Creates a response recorder that persists every pixiv API response to MySQL.
|
|
343
|
+
* Creates a response recorder that persists every successful (2xx) pixiv API response to MySQL.
|
|
327
344
|
*
|
|
328
345
|
* @param opts - Connection and bootstrapping options
|
|
329
346
|
* @returns `{ interceptor, db, close }`
|
|
@@ -393,8 +410,6 @@ interface EndpointWithCount {
|
|
|
393
410
|
* @returns Endpoints sorted by count descending
|
|
394
411
|
*/
|
|
395
412
|
export declare function getEndpoints(db: DbInstance): Promise<EndpointWithCount[]>;
|
|
396
|
-
//#endregion
|
|
397
|
-
//#region src/migrations.d.ts
|
|
398
413
|
/**
|
|
399
414
|
* Creates the `responses` table if it does not already exist.
|
|
400
415
|
*
|
|
@@ -404,6 +419,5 @@ export declare function getEndpoints(db: DbInstance): Promise<EndpointWithCount[
|
|
|
404
419
|
* @param db - Drizzle ORM database instance
|
|
405
420
|
*/
|
|
406
421
|
export declare function bootstrapSchema(db: DbInstance): Promise<void>;
|
|
407
|
-
//#endregion
|
|
408
422
|
export type { ConnectionOptions, DbInstance, EndpointWithCount, NewResponse, RangeOptions, RecorderBundle, RecorderOptions, ResponseFilter, ResponseRow };
|
|
409
423
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["schema"],"sources":["../src/schema.ts","../src/connection.ts","../src/recorder.ts","../src/migrations.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["schema"],"sources":["../src/schema.ts","../src/connection.ts","../src/recorder.ts","../src/migrations.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwBa,iDAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAuCf,qBAAqB,eAAe;;KAGpC,qBAAqB,eAAe;;UCvD/B;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;;;KAQU,aAAa,kBAAkB,eAAeA;;;;;;;;wBAe1C,mBAAmB,MAAM;EACvC,MAAM,MAAM;EACZ,IAAI;;;UCrCW;;;;;EAKf,aAAa;;EAGb,IAAI;;EAGJ,SAAS;;;UAQM,wBAAwB;;;;;;;EAOvC;;;;;;;;;;;wBAwBoB,YACpB,IAAI,YACJ,QAAQ,iBACP;;;;;;;;;wBA+Ba,qBACd,IAAI,YACJ,aAAa,gBACZ;;;;;;;;;;;;;;;;;;;wBAwBmB,uBACpB,MAAM,kBACL,QAAQ;;UAeM;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;;;;;;;;;wBAWoB,aACpB,IAAI,YACJ,SAAS,gBACT,QAAQ,eACP,QAAQ;;;;;;;;wBAgCW,iBACpB,IAAI,YACJ,SAAS,iBACR;;UAqBc;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;;wBAUoB,aACpB,IAAI,aACH,QAAQ;;;;;;;;;wBC/OW,gBAAgB,IAAI,aAAa"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.js";
|
|
2
2
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
3
3
|
import mysql from "mysql2/promise";
|
|
4
4
|
import { datetime, int, longtext, mysqlTable, text, uniqueIndex, varchar } from "drizzle-orm/mysql-core";
|
|
5
5
|
import crypto from "node:crypto";
|
|
6
6
|
import { and, count, desc, eq, gte, sql } from "drizzle-orm";
|
|
7
|
-
|
|
7
|
+
// src/schema.ts
|
|
8
8
|
/**
|
|
9
9
|
* Drizzle ORM schema for the `responses` table.
|
|
10
10
|
*
|
|
@@ -13,7 +13,7 @@ import { and, count, desc, eq, gte, sql } from "drizzle-orm";
|
|
|
13
13
|
*/
|
|
14
14
|
var schema_exports = /* @__PURE__ */ __exportAll({ responsesTable: () => responsesTable });
|
|
15
15
|
/**
|
|
16
|
-
* The `responses` table stores every HTTP response returned by the pixiv API.
|
|
16
|
+
* The `responses` table stores every successful (2xx) HTTP response returned by the pixiv API.
|
|
17
17
|
*
|
|
18
18
|
* A unique composite index on (method, endpoint, status_code, url_hash) ensures
|
|
19
19
|
* that each unique request/response combination is stored only once, regardless
|
|
@@ -48,8 +48,7 @@ const responsesTable = mysqlTable("responses", {
|
|
|
48
48
|
fsp: 3
|
|
49
49
|
}).notNull()
|
|
50
50
|
}, (table) => [uniqueIndex("idx_unique").on(table.method, table.endpoint, table.statusCode, table.urlHash)]);
|
|
51
|
-
|
|
52
|
-
//#region src/connection.ts
|
|
51
|
+
// src/connection.ts
|
|
53
52
|
/**
|
|
54
53
|
* MySQL connection factory for @book000/pixivts-db-mysql.
|
|
55
54
|
*
|
|
@@ -86,8 +85,7 @@ function createDbConnection(opts) {
|
|
|
86
85
|
})
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
|
|
90
|
-
//#region src/migrations.ts
|
|
88
|
+
// src/migrations.ts
|
|
91
89
|
/**
|
|
92
90
|
* Schema bootstrapping for @book000/pixivts-db-mysql.
|
|
93
91
|
*
|
|
@@ -125,8 +123,7 @@ async function bootstrapSchema(db) {
|
|
|
125
123
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
126
124
|
`);
|
|
127
125
|
}
|
|
128
|
-
|
|
129
|
-
//#region src/recorder.ts
|
|
126
|
+
// src/recorder.ts
|
|
130
127
|
/**
|
|
131
128
|
* Response recorder for @book000/pixivts-db-mysql.
|
|
132
129
|
*
|
|
@@ -138,24 +135,6 @@ async function bootstrapSchema(db) {
|
|
|
138
135
|
* The recorder uses Drizzle ORM's `onDuplicateKeyUpdate` to silently ignore
|
|
139
136
|
* duplicate entries (same method + endpoint + statusCode + urlHash).
|
|
140
137
|
*/
|
|
141
|
-
/**
|
|
142
|
-
* Creates a response recorder that persists every pixiv API response to MySQL.
|
|
143
|
-
*
|
|
144
|
-
* @param opts - Connection and bootstrapping options
|
|
145
|
-
* @returns `{ interceptor, db, close }`
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* const { interceptor, close } = await createResponseRecorder({
|
|
150
|
-
* host: 'localhost',
|
|
151
|
-
* database: 'pixivts',
|
|
152
|
-
* bootstrap: true,
|
|
153
|
-
* })
|
|
154
|
-
* const client = await PixivClient.of(token, { onResponse: interceptor })
|
|
155
|
-
* // ...
|
|
156
|
-
* await close()
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
138
|
function ninetyDaysAgo() {
|
|
160
139
|
return /* @__PURE__ */ new Date(Date.now() - 7776e6);
|
|
161
140
|
}
|
|
@@ -202,7 +181,7 @@ function createRecorderBundle(db, close) {
|
|
|
202
181
|
};
|
|
203
182
|
}
|
|
204
183
|
/**
|
|
205
|
-
* Creates a response recorder that persists every pixiv API response to MySQL.
|
|
184
|
+
* Creates a response recorder that persists every successful (2xx) pixiv API response to MySQL.
|
|
206
185
|
*
|
|
207
186
|
* @param opts - Connection and bootstrapping options
|
|
208
187
|
* @returns `{ interceptor, db, close }`
|
|
@@ -258,17 +237,13 @@ async function getResponseCount(db, filter) {
|
|
|
258
237
|
*/
|
|
259
238
|
async function getEndpoints(db) {
|
|
260
239
|
const since = ninetyDaysAgo();
|
|
261
|
-
return
|
|
240
|
+
return await db.select({
|
|
262
241
|
method: responsesTable.method,
|
|
263
242
|
endpoint: responsesTable.endpoint,
|
|
264
243
|
statusCode: responsesTable.statusCode,
|
|
265
244
|
count: count()
|
|
266
|
-
}).from(responsesTable).where(gte(responsesTable.createdAt, since)).groupBy(responsesTable.method, responsesTable.endpoint, responsesTable.statusCode).orderBy(desc(count()))
|
|
267
|
-
...r,
|
|
268
|
-
count: r.count
|
|
269
|
-
}));
|
|
245
|
+
}).from(responsesTable).where(gte(responsesTable.createdAt, since)).groupBy(responsesTable.method, responsesTable.endpoint, responsesTable.statusCode).orderBy(desc(count()));
|
|
270
246
|
}
|
|
271
|
-
//#endregion
|
|
272
247
|
export { addResponse, bootstrapSchema, createDbConnection, createRecorderBundle, createResponseRecorder, getEndpoints, getResponseCount, getResponses, responsesTable };
|
|
273
248
|
|
|
274
249
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/schema.ts","../src/connection.ts","../src/migrations.ts","../src/recorder.ts"],"sourcesContent":["/**\n * Drizzle ORM schema for the `responses` table.\n *\n * Column names are kept in snake_case to match the legacy TypeORM schema\n * so that existing databases can be used without migration.\n */\n\nimport {\n int,\n datetime,\n longtext,\n mysqlTable,\n text,\n varchar,\n uniqueIndex,\n} from 'drizzle-orm/mysql-core'\n\n/**\n * The `responses` table stores every HTTP response returned by the pixiv API.\n *\n * A unique composite index on (method, endpoint, status_code, url_hash) ensures\n * that each unique request/response combination is stored only once, regardless\n * of when it was recorded.\n */\nexport const responsesTable = mysqlTable(\n 'responses',\n {\n /** Auto-increment primary key. */\n id: int('id').autoincrement().primaryKey(),\n /** HTTP method (GET or POST). */\n method: varchar('method', { length: 10 }).notNull(),\n /** API endpoint path (e.g. /v1/illust/detail). */\n endpoint: varchar('endpoint', { length: 255 }).notNull(),\n /** Full request URL (may be null for internal requests). */\n url: text('url'),\n /** SHA-256 hash of the request URL for deduplication. */\n urlHash: varchar('url_hash', { length: 255 }).notNull(),\n /** Serialised request headers (JSON string). */\n requestHeaders: longtext('request_headers'),\n /** Request body (URL-encoded string for POST, null for GET). */\n requestBody: longtext('request_body'),\n /** Response content type (\"JSON\" or \"TEXT\"). */\n responseType: varchar('response_type', { length: 10 }).notNull(),\n /** HTTP response status code. */\n statusCode: int('status_code').notNull(),\n /** Serialised response headers (JSON string). */\n responseHeaders: longtext('response_headers'),\n /** Raw response body. */\n responseBody: longtext('response_body').notNull(),\n /** Timestamp when the record was created. */\n createdAt: datetime('created_at', { mode: 'date', fsp: 3 }).notNull(),\n },\n (table) => [\n uniqueIndex('idx_unique').on(\n table.method,\n table.endpoint,\n table.statusCode,\n table.urlHash\n ),\n ]\n)\n\n/** Type for inserting a new response record. */\nexport type NewResponse = typeof responsesTable.$inferInsert\n\n/** Type for a selected response record. */\nexport type ResponseRow = typeof responsesTable.$inferSelect\n","/**\n * MySQL connection factory for @book000/pixivts-db-mysql.\n *\n * Creates a mysql2 connection pool and wraps it in a Drizzle ORM instance.\n */\n\nimport { drizzle } from 'drizzle-orm/mysql2'\nimport mysql from 'mysql2/promise'\nimport * as schema from './schema'\n\n/** Options for establishing a MySQL connection. */\nexport interface ConnectionOptions {\n /**\n * Database hostname.\n * Falls back to the `RESPONSE_DB_HOSTNAME` environment variable.\n */\n host?: string\n\n /**\n * Database port.\n * Falls back to the `RESPONSE_DB_PORT` environment variable (default: 3306).\n */\n port?: number\n\n /**\n * Database username.\n * Falls back to the `RESPONSE_DB_USERNAME` environment variable.\n */\n user?: string\n\n /**\n * Database password.\n * Falls back to the `RESPONSE_DB_PASSWORD` environment variable.\n */\n password?: string\n\n /**\n * Database name.\n * Falls back to the `RESPONSE_DB_DATABASE` environment variable.\n */\n database?: string\n}\n\n/**\n * The Drizzle ORM database instance type returned by `createConnection`.\n *\n * Typed with the `schema` so that relational queries are available.\n */\nexport type DbInstance = ReturnType<typeof drizzle<typeof schema>>\n\nfunction parsePort(value: string | undefined): number {\n if (!value) return 3306\n const parsed = Number.parseInt(value, 10)\n return Number.isNaN(parsed) ? 3306 : parsed\n}\n\n/**\n * Creates a mysql2 connection pool and returns both the raw pool and the\n * Drizzle ORM wrapper.\n *\n * @param opts - Connection options (fall back to environment variables)\n * @returns `{ pool, db }` — raw pool for `close()`, db for queries\n */\nexport function createDbConnection(opts: ConnectionOptions): {\n pool: mysql.Pool\n db: DbInstance\n} {\n const pool = mysql.createPool({\n host: opts.host ?? process.env.RESPONSE_DB_HOSTNAME ?? 'localhost',\n port: opts.port ?? parsePort(process.env.RESPONSE_DB_PORT),\n user: opts.user ?? process.env.RESPONSE_DB_USERNAME,\n password: opts.password ?? process.env.RESPONSE_DB_PASSWORD,\n database: opts.database ?? process.env.RESPONSE_DB_DATABASE,\n timezone: '+09:00',\n supportBigNumbers: true,\n bigNumberStrings: true,\n })\n\n // Type assertion required: pnpm's peer-dep resolution for the patched drizzle-orm\n // creates a structurally-incompatible Pool type for the $client property.\n // The runtime value is correct; only the declaration paths differ.\n const db = drizzle(pool, { schema, mode: 'default' }) as unknown as DbInstance\n return { pool, db }\n}\n","/**\n * Schema bootstrapping for @book000/pixivts-db-mysql.\n *\n * Provides a `CREATE TABLE IF NOT EXISTS` helper that can be used at startup\n * without requiring drizzle-kit to be installed in production.\n *\n * For full migrations, use:\n * pnpm drizzle-kit generate\n * pnpm drizzle-kit migrate\n */\n\nimport { sql } from 'drizzle-orm'\nimport type { DbInstance } from './connection'\n\n/**\n * Creates the `responses` table if it does not already exist.\n *\n * This is a lightweight alternative to running drizzle-kit migrations in\n * environments where the table has not been set up yet.\n *\n * @param db - Drizzle ORM database instance\n */\nexport async function bootstrapSchema(db: DbInstance): Promise<void> {\n await db.execute(sql`\n CREATE TABLE IF NOT EXISTS responses (\n id INT AUTO_INCREMENT PRIMARY KEY COMMENT 'Response ID',\n method VARCHAR(10) NOT NULL COMMENT 'HTTP method',\n endpoint VARCHAR(255) NOT NULL COMMENT 'API endpoint path',\n url TEXT NULL COMMENT 'Full request URL',\n url_hash VARCHAR(255) NOT NULL COMMENT 'SHA-256 hash of the request URL',\n request_headers LONGTEXT NULL COMMENT 'Request headers (JSON)',\n request_body LONGTEXT NULL COMMENT 'Request body',\n response_type VARCHAR(10) NOT NULL COMMENT 'Response content type',\n status_code INT NOT NULL COMMENT 'HTTP status code',\n response_headers LONGTEXT NULL COMMENT 'Response headers (JSON)',\n response_body LONGTEXT NOT NULL COMMENT 'Response body',\n created_at DATETIME(3) NOT NULL COMMENT 'Record creation timestamp',\n UNIQUE INDEX idx_unique (method, endpoint, status_code, url_hash)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci\n `)\n}\n","/**\n * Response recorder for @book000/pixivts-db-mysql.\n *\n * `createResponseRecorder()` returns a `{ interceptor, db, close }` bundle:\n * - `interceptor` — pass to `PixivClient.of(token, { onResponse: interceptor })`\n * - `db` — the raw Drizzle instance for custom queries\n * - `close()` — shuts down the connection pool\n *\n * The recorder uses Drizzle ORM's `onDuplicateKeyUpdate` to silently ignore\n * duplicate entries (same method + endpoint + statusCode + urlHash).\n */\n\nimport crypto from 'node:crypto'\nimport { and, count, desc, eq, gte, sql } from 'drizzle-orm'\nimport type { ResponseInterceptor, ResponseRecord } from '@book000/pixivts'\nimport {\n createDbConnection,\n type ConnectionOptions,\n type DbInstance,\n} from './connection'\nimport { responsesTable, type ResponseRow } from './schema'\nimport { bootstrapSchema } from './migrations'\n\n// ---------------------------------------------------------------------------\n// Result bundle\n// ---------------------------------------------------------------------------\n\n/** The object returned by `createResponseRecorder()`. */\nexport interface RecorderBundle {\n /**\n * Response interceptor — pass directly to `PixivClient.of()` as\n * the `onResponse` option.\n */\n interceptor: ResponseInterceptor\n\n /** Drizzle ORM database instance for custom queries. */\n db: DbInstance\n\n /** Closes the underlying connection pool. */\n close(): Promise<void>\n}\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/** Options for `createResponseRecorder()`. */\nexport interface RecorderOptions extends ConnectionOptions {\n /**\n * If `true`, runs `CREATE TABLE IF NOT EXISTS` before returning.\n * Useful for first-run bootstrapping without a separate migration step.\n *\n * @default false\n */\n bootstrap?: boolean\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a response recorder that persists every pixiv API response to MySQL.\n *\n * @param opts - Connection and bootstrapping options\n * @returns `{ interceptor, db, close }`\n *\n * @example\n * ```ts\n * const { interceptor, close } = await createResponseRecorder({\n * host: 'localhost',\n * database: 'pixivts',\n * bootstrap: true,\n * })\n * const client = await PixivClient.of(token, { onResponse: interceptor })\n * // ...\n * await close()\n * ```\n */\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction ninetyDaysAgo(): Date {\n return new Date(Date.now() - 90 * 24 * 60 * 60 * 1000)\n}\n\n// ---------------------------------------------------------------------------\n// Core DB helpers (exported for testing)\n// ---------------------------------------------------------------------------\n\n/**\n * Inserts a response record into the database.\n *\n * If the unique composite index fires (duplicate method + endpoint + statusCode\n * + urlHash), the insert is silently ignored via `ON DUPLICATE KEY UPDATE id = id`.\n *\n * @param db - Drizzle ORM database instance\n * @param record - Response record from the HTTP client interceptor\n */\nexport async function addResponse(\n db: DbInstance,\n record: ResponseRecord\n): Promise<void> {\n // Hash the URL if present; fall back to \"method:endpoint\" so the column is never empty.\n const urlToHash = record.url ?? `${record.method}:${record.endpoint}`\n const urlHash = crypto.createHash('sha256').update(urlToHash).digest('hex')\n\n await db\n .insert(responsesTable)\n .values({\n method: record.method,\n endpoint: record.endpoint,\n url: record.url,\n urlHash,\n requestHeaders: record.requestHeaders,\n requestBody: record.requestBody,\n responseType: record.responseType,\n statusCode: record.statusCode,\n responseHeaders: record.responseHeaders,\n responseBody: record.responseBody,\n createdAt: new Date(),\n })\n .onDuplicateKeyUpdate({ set: { id: sql`id` } })\n}\n\n/**\n * Creates a `RecorderBundle` from an existing Drizzle instance.\n *\n * Useful for testing — pass a mock `db` and a no-op `close`.\n *\n * @param db - Drizzle ORM database instance\n * @param close - Function that closes the underlying connection\n */\nexport function createRecorderBundle(\n db: DbInstance,\n close: () => Promise<void>\n): RecorderBundle {\n const interceptor: ResponseInterceptor = (record) => addResponse(db, record)\n\n return { interceptor, db, close }\n}\n\n/**\n * Creates a response recorder that persists every pixiv API response to MySQL.\n *\n * @param opts - Connection and bootstrapping options\n * @returns `{ interceptor, db, close }`\n *\n * @example\n * ```ts\n * const { interceptor, close } = await createResponseRecorder({\n * host: 'localhost',\n * database: 'pixivts',\n * bootstrap: true,\n * })\n * const client = await PixivClient.of(token, { onResponse: interceptor })\n * // ...\n * await close()\n * ```\n */\nexport async function createResponseRecorder(\n opts: RecorderOptions\n): Promise<RecorderBundle> {\n const { pool, db } = createDbConnection(opts)\n\n if (opts.bootstrap) {\n await bootstrapSchema(db)\n }\n\n return createRecorderBundle(db, () => pool.end())\n}\n\n// ---------------------------------------------------------------------------\n// Query helpers\n// ---------------------------------------------------------------------------\n\n/** Filter criteria for response queries. */\nexport interface ResponseFilter {\n /** HTTP method to filter by (e.g. `\"GET\"`). Omit to match all methods. */\n method?: string\n /** API endpoint path to filter by (e.g. `\"/v1/illust/detail\"`). Omit to match all endpoints. */\n endpoint?: string\n /** HTTP status code to filter by (e.g. `200`). Omit to match all status codes. */\n statusCode?: number\n}\n\n/** Pagination options for `getResponses`. */\nexport interface RangeOptions {\n /** 1-based page number (default: 1). */\n page?: number\n /** Items per page (default: 100). */\n limit?: number\n}\n\n/**\n * Retrieves response records from the last 90 days.\n *\n * @param db - Drizzle ORM database instance\n * @param filter - Optional filter criteria\n * @param range - Optional pagination options\n * @returns Array of response rows, newest first\n */\nexport async function getResponses(\n db: DbInstance,\n filter?: ResponseFilter,\n range?: RangeOptions\n): Promise<ResponseRow[]> {\n const since = ninetyDaysAgo()\n const limit = range?.limit ?? 100\n const offset = ((range?.page ?? 1) - 1) * limit\n\n return db\n .select()\n .from(responsesTable)\n .where(\n and(\n gte(responsesTable.createdAt, since),\n filter?.method ? eq(responsesTable.method, filter.method) : undefined,\n filter?.endpoint\n ? eq(responsesTable.endpoint, filter.endpoint)\n : undefined,\n filter?.statusCode\n ? eq(responsesTable.statusCode, filter.statusCode)\n : undefined\n )\n )\n .orderBy(desc(responsesTable.createdAt))\n .limit(limit)\n .offset(offset)\n}\n\n/**\n * Returns the total count of response records from the last 90 days.\n *\n * @param db - Drizzle ORM database instance\n * @param filter - Optional filter criteria\n * @returns Total row count matching the filter\n */\nexport async function getResponseCount(\n db: DbInstance,\n filter?: ResponseFilter\n): Promise<number> {\n const since = ninetyDaysAgo()\n const rows = await db\n .select({ value: count() })\n .from(responsesTable)\n .where(\n and(\n gte(responsesTable.createdAt, since),\n filter?.method ? eq(responsesTable.method, filter.method) : undefined,\n filter?.endpoint\n ? eq(responsesTable.endpoint, filter.endpoint)\n : undefined,\n filter?.statusCode\n ? eq(responsesTable.statusCode, filter.statusCode)\n : undefined\n )\n )\n return rows[0]?.value ?? 0\n}\n\n/** An endpoint with its response count. */\nexport interface EndpointWithCount {\n /** HTTP method (e.g. `\"GET\"` or `\"POST\"`). */\n method: string\n /** API endpoint path (e.g. `\"/v1/illust/detail\"`). */\n endpoint: string\n /** HTTP status code returned by the endpoint. */\n statusCode: number\n /** Number of recorded responses for this (method, endpoint, statusCode) combination. */\n count: number\n}\n\n/**\n * Returns all unique (method, endpoint, statusCode) combinations seen in the\n * last 90 days, along with the count of matching records.\n *\n * @param db - Drizzle ORM database instance\n * @returns Endpoints sorted by count descending\n */\nexport async function getEndpoints(\n db: DbInstance\n): Promise<EndpointWithCount[]> {\n const since = ninetyDaysAgo()\n const rows = await db\n .select({\n method: responsesTable.method,\n endpoint: responsesTable.endpoint,\n statusCode: responsesTable.statusCode,\n count: count(),\n })\n .from(responsesTable)\n .where(gte(responsesTable.createdAt, since))\n .groupBy(\n responsesTable.method,\n responsesTable.endpoint,\n responsesTable.statusCode\n )\n .orderBy(desc(count()))\n\n return rows.map((r) => ({ ...r, count: r.count }))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,iBAAiB,WAC5B,aACA;;CAEE,IAAI,IAAI,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,WAAW;;CAEzC,QAAQ,QAAQ,UAAU,EAAE,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+
{"version":3,"file":"index.js","names":[],"sources":["../src/schema.ts","../src/connection.ts","../src/migrations.ts","../src/recorder.ts"],"sourcesContent":["/**\n * Drizzle ORM schema for the `responses` table.\n *\n * Column names are kept in snake_case to match the legacy TypeORM schema\n * so that existing databases can be used without migration.\n */\n\nimport {\n int,\n datetime,\n longtext,\n mysqlTable,\n text,\n varchar,\n uniqueIndex,\n} from 'drizzle-orm/mysql-core'\n\n/**\n * The `responses` table stores every successful (2xx) HTTP response returned by the pixiv API.\n *\n * A unique composite index on (method, endpoint, status_code, url_hash) ensures\n * that each unique request/response combination is stored only once, regardless\n * of when it was recorded.\n */\nexport const responsesTable = mysqlTable(\n 'responses',\n {\n /** Auto-increment primary key. */\n id: int('id').autoincrement().primaryKey(),\n /** HTTP method (GET or POST). */\n method: varchar('method', { length: 10 }).notNull(),\n /** API endpoint path (e.g. /v1/illust/detail). */\n endpoint: varchar('endpoint', { length: 255 }).notNull(),\n /** Full request URL (may be null for internal requests). */\n url: text('url'),\n /** SHA-256 hash of the request URL for deduplication. */\n urlHash: varchar('url_hash', { length: 255 }).notNull(),\n /** Serialised request headers (JSON string). */\n requestHeaders: longtext('request_headers'),\n /** Request body (URL-encoded string for POST, null for GET). */\n requestBody: longtext('request_body'),\n /** Response content type (\"JSON\" or \"TEXT\"). */\n responseType: varchar('response_type', { length: 10 }).notNull(),\n /** HTTP response status code. */\n statusCode: int('status_code').notNull(),\n /** Serialised response headers (JSON string). */\n responseHeaders: longtext('response_headers'),\n /** Raw response body. */\n responseBody: longtext('response_body').notNull(),\n /** Timestamp when the record was created. */\n createdAt: datetime('created_at', { mode: 'date', fsp: 3 }).notNull(),\n },\n (table) => [\n uniqueIndex('idx_unique').on(\n table.method,\n table.endpoint,\n table.statusCode,\n table.urlHash\n ),\n ]\n)\n\n/** Type for inserting a new response record. */\nexport type NewResponse = typeof responsesTable.$inferInsert\n\n/** Type for a selected response record. */\nexport type ResponseRow = typeof responsesTable.$inferSelect\n","/**\n * MySQL connection factory for @book000/pixivts-db-mysql.\n *\n * Creates a mysql2 connection pool and wraps it in a Drizzle ORM instance.\n */\n\nimport { drizzle } from 'drizzle-orm/mysql2'\nimport mysql from 'mysql2/promise'\nimport * as schema from './schema'\n\n/** Options for establishing a MySQL connection. */\nexport interface ConnectionOptions {\n /**\n * Database hostname.\n * Falls back to the `RESPONSE_DB_HOSTNAME` environment variable.\n */\n host?: string\n\n /**\n * Database port.\n * Falls back to the `RESPONSE_DB_PORT` environment variable (default: 3306).\n */\n port?: number\n\n /**\n * Database username.\n * Falls back to the `RESPONSE_DB_USERNAME` environment variable.\n */\n user?: string\n\n /**\n * Database password.\n * Falls back to the `RESPONSE_DB_PASSWORD` environment variable.\n */\n password?: string\n\n /**\n * Database name.\n * Falls back to the `RESPONSE_DB_DATABASE` environment variable.\n */\n database?: string\n}\n\n/**\n * The Drizzle ORM database instance type returned by `createConnection`.\n *\n * Typed with the `schema` so that relational queries are available.\n */\nexport type DbInstance = ReturnType<typeof drizzle<typeof schema>>\n\nfunction parsePort(value: string | undefined): number {\n if (!value) return 3306\n const parsed = Number.parseInt(value, 10)\n return Number.isNaN(parsed) ? 3306 : parsed\n}\n\n/**\n * Creates a mysql2 connection pool and returns both the raw pool and the\n * Drizzle ORM wrapper.\n *\n * @param opts - Connection options (fall back to environment variables)\n * @returns `{ pool, db }` — raw pool for `close()`, db for queries\n */\nexport function createDbConnection(opts: ConnectionOptions): {\n pool: mysql.Pool\n db: DbInstance\n} {\n const pool = mysql.createPool({\n host: opts.host ?? process.env.RESPONSE_DB_HOSTNAME ?? 'localhost',\n port: opts.port ?? parsePort(process.env.RESPONSE_DB_PORT),\n user: opts.user ?? process.env.RESPONSE_DB_USERNAME,\n password: opts.password ?? process.env.RESPONSE_DB_PASSWORD,\n database: opts.database ?? process.env.RESPONSE_DB_DATABASE,\n timezone: '+09:00',\n supportBigNumbers: true,\n bigNumberStrings: true,\n })\n\n // Type assertion required: pnpm's peer-dep resolution for the patched drizzle-orm\n // creates a structurally-incompatible Pool type for the $client property.\n // The runtime value is correct; only the declaration paths differ.\n const db = drizzle(pool, { schema, mode: 'default' }) as unknown as DbInstance\n return { pool, db }\n}\n","/**\n * Schema bootstrapping for @book000/pixivts-db-mysql.\n *\n * Provides a `CREATE TABLE IF NOT EXISTS` helper that can be used at startup\n * without requiring drizzle-kit to be installed in production.\n *\n * For full migrations, use:\n * pnpm drizzle-kit generate\n * pnpm drizzle-kit migrate\n */\n\nimport { sql } from 'drizzle-orm'\nimport type { DbInstance } from './connection'\n\n/**\n * Creates the `responses` table if it does not already exist.\n *\n * This is a lightweight alternative to running drizzle-kit migrations in\n * environments where the table has not been set up yet.\n *\n * @param db - Drizzle ORM database instance\n */\nexport async function bootstrapSchema(db: DbInstance): Promise<void> {\n await db.execute(sql`\n CREATE TABLE IF NOT EXISTS responses (\n id INT AUTO_INCREMENT PRIMARY KEY COMMENT 'Response ID',\n method VARCHAR(10) NOT NULL COMMENT 'HTTP method',\n endpoint VARCHAR(255) NOT NULL COMMENT 'API endpoint path',\n url TEXT NULL COMMENT 'Full request URL',\n url_hash VARCHAR(255) NOT NULL COMMENT 'SHA-256 hash of the request URL',\n request_headers LONGTEXT NULL COMMENT 'Request headers (JSON)',\n request_body LONGTEXT NULL COMMENT 'Request body',\n response_type VARCHAR(10) NOT NULL COMMENT 'Response content type',\n status_code INT NOT NULL COMMENT 'HTTP status code',\n response_headers LONGTEXT NULL COMMENT 'Response headers (JSON)',\n response_body LONGTEXT NOT NULL COMMENT 'Response body',\n created_at DATETIME(3) NOT NULL COMMENT 'Record creation timestamp',\n UNIQUE INDEX idx_unique (method, endpoint, status_code, url_hash)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci\n `)\n}\n","/**\n * Response recorder for @book000/pixivts-db-mysql.\n *\n * `createResponseRecorder()` returns a `{ interceptor, db, close }` bundle:\n * - `interceptor` — pass to `PixivClient.of(token, { onResponse: interceptor })`\n * - `db` — the raw Drizzle instance for custom queries\n * - `close()` — shuts down the connection pool\n *\n * The recorder uses Drizzle ORM's `onDuplicateKeyUpdate` to silently ignore\n * duplicate entries (same method + endpoint + statusCode + urlHash).\n */\n\nimport crypto from 'node:crypto'\nimport { and, count, desc, eq, gte, sql } from 'drizzle-orm'\nimport type { ResponseInterceptor, ResponseRecord } from '@book000/pixivts'\nimport {\n createDbConnection,\n type ConnectionOptions,\n type DbInstance,\n} from './connection'\nimport { responsesTable, type ResponseRow } from './schema'\nimport { bootstrapSchema } from './migrations'\n\n// ---------------------------------------------------------------------------\n// Result bundle\n// ---------------------------------------------------------------------------\n\n/** The object returned by `createResponseRecorder()`. */\nexport interface RecorderBundle {\n /**\n * Response interceptor — pass directly to `PixivClient.of()` as\n * the `onResponse` option.\n */\n interceptor: ResponseInterceptor\n\n /** Drizzle ORM database instance for custom queries. */\n db: DbInstance\n\n /** Closes the underlying connection pool. */\n close(): Promise<void>\n}\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/** Options for `createResponseRecorder()`. */\nexport interface RecorderOptions extends ConnectionOptions {\n /**\n * If `true`, runs `CREATE TABLE IF NOT EXISTS` before returning.\n * Useful for first-run bootstrapping without a separate migration step.\n *\n * @default false\n */\n bootstrap?: boolean\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction ninetyDaysAgo(): Date {\n return new Date(Date.now() - 90 * 24 * 60 * 60 * 1000)\n}\n\n// ---------------------------------------------------------------------------\n// Core DB helpers (exported for testing)\n// ---------------------------------------------------------------------------\n\n/**\n * Inserts a response record into the database.\n *\n * If the unique composite index fires (duplicate method + endpoint + statusCode\n * + urlHash), the insert is silently ignored via `ON DUPLICATE KEY UPDATE id = id`.\n *\n * @param db - Drizzle ORM database instance\n * @param record - Response record from the HTTP client interceptor\n */\nexport async function addResponse(\n db: DbInstance,\n record: ResponseRecord\n): Promise<void> {\n // Hash the URL if present; fall back to \"method:endpoint\" so the column is never empty.\n const urlToHash = record.url ?? `${record.method}:${record.endpoint}`\n const urlHash = crypto.createHash('sha256').update(urlToHash).digest('hex')\n\n await db\n .insert(responsesTable)\n .values({\n method: record.method,\n endpoint: record.endpoint,\n url: record.url,\n urlHash,\n requestHeaders: record.requestHeaders,\n requestBody: record.requestBody,\n responseType: record.responseType,\n statusCode: record.statusCode,\n responseHeaders: record.responseHeaders,\n responseBody: record.responseBody,\n createdAt: new Date(),\n })\n .onDuplicateKeyUpdate({ set: { id: sql`id` } })\n}\n\n/**\n * Creates a `RecorderBundle` from an existing Drizzle instance.\n *\n * Useful for testing — pass a mock `db` and a no-op `close`.\n *\n * @param db - Drizzle ORM database instance\n * @param close - Function that closes the underlying connection\n */\nexport function createRecorderBundle(\n db: DbInstance,\n close: () => Promise<void>\n): RecorderBundle {\n const interceptor: ResponseInterceptor = (record) => addResponse(db, record)\n\n return { interceptor, db, close }\n}\n\n/**\n * Creates a response recorder that persists every successful (2xx) pixiv API response to MySQL.\n *\n * @param opts - Connection and bootstrapping options\n * @returns `{ interceptor, db, close }`\n *\n * @example\n * ```ts\n * const { interceptor, close } = await createResponseRecorder({\n * host: 'localhost',\n * database: 'pixivts',\n * bootstrap: true,\n * })\n * const client = await PixivClient.of(token, { onResponse: interceptor })\n * // ...\n * await close()\n * ```\n */\nexport async function createResponseRecorder(\n opts: RecorderOptions\n): Promise<RecorderBundle> {\n const { pool, db } = createDbConnection(opts)\n\n if (opts.bootstrap) {\n await bootstrapSchema(db)\n }\n\n return createRecorderBundle(db, () => pool.end())\n}\n\n// ---------------------------------------------------------------------------\n// Query helpers\n// ---------------------------------------------------------------------------\n\n/** Filter criteria for response queries. */\nexport interface ResponseFilter {\n /** HTTP method to filter by (e.g. `\"GET\"`). Omit to match all methods. */\n method?: string\n /** API endpoint path to filter by (e.g. `\"/v1/illust/detail\"`). Omit to match all endpoints. */\n endpoint?: string\n /** HTTP status code to filter by (e.g. `200`). Omit to match all status codes. */\n statusCode?: number\n}\n\n/** Pagination options for `getResponses`. */\nexport interface RangeOptions {\n /** 1-based page number (default: 1). */\n page?: number\n /** Items per page (default: 100). */\n limit?: number\n}\n\n/**\n * Retrieves response records from the last 90 days.\n *\n * @param db - Drizzle ORM database instance\n * @param filter - Optional filter criteria\n * @param range - Optional pagination options\n * @returns Array of response rows, newest first\n */\nexport async function getResponses(\n db: DbInstance,\n filter?: ResponseFilter,\n range?: RangeOptions\n): Promise<ResponseRow[]> {\n const since = ninetyDaysAgo()\n const limit = range?.limit ?? 100\n const offset = ((range?.page ?? 1) - 1) * limit\n\n return db\n .select()\n .from(responsesTable)\n .where(\n and(\n gte(responsesTable.createdAt, since),\n filter?.method ? eq(responsesTable.method, filter.method) : undefined,\n filter?.endpoint\n ? eq(responsesTable.endpoint, filter.endpoint)\n : undefined,\n filter?.statusCode\n ? eq(responsesTable.statusCode, filter.statusCode)\n : undefined\n )\n )\n .orderBy(desc(responsesTable.createdAt))\n .limit(limit)\n .offset(offset)\n}\n\n/**\n * Returns the total count of response records from the last 90 days.\n *\n * @param db - Drizzle ORM database instance\n * @param filter - Optional filter criteria\n * @returns Total row count matching the filter\n */\nexport async function getResponseCount(\n db: DbInstance,\n filter?: ResponseFilter\n): Promise<number> {\n const since = ninetyDaysAgo()\n const rows = await db\n .select({ value: count() })\n .from(responsesTable)\n .where(\n and(\n gte(responsesTable.createdAt, since),\n filter?.method ? eq(responsesTable.method, filter.method) : undefined,\n filter?.endpoint\n ? eq(responsesTable.endpoint, filter.endpoint)\n : undefined,\n filter?.statusCode\n ? eq(responsesTable.statusCode, filter.statusCode)\n : undefined\n )\n )\n return rows[0]?.value ?? 0\n}\n\n/** An endpoint with its response count. */\nexport interface EndpointWithCount {\n /** HTTP method (e.g. `\"GET\"` or `\"POST\"`). */\n method: string\n /** API endpoint path (e.g. `\"/v1/illust/detail\"`). */\n endpoint: string\n /** HTTP status code returned by the endpoint. */\n statusCode: number\n /** Number of recorded responses for this (method, endpoint, statusCode) combination. */\n count: number\n}\n\n/**\n * Returns all unique (method, endpoint, statusCode) combinations seen in the\n * last 90 days, along with the count of matching records.\n *\n * @param db - Drizzle ORM database instance\n * @returns Endpoints sorted by count descending\n */\nexport async function getEndpoints(\n db: DbInstance\n): Promise<EndpointWithCount[]> {\n const since = ninetyDaysAgo()\n const rows = await db\n .select({\n method: responsesTable.method,\n endpoint: responsesTable.endpoint,\n statusCode: responsesTable.statusCode,\n count: count(),\n })\n .from(responsesTable)\n .where(gte(responsesTable.createdAt, since))\n .groupBy(\n responsesTable.method,\n responsesTable.endpoint,\n responsesTable.statusCode\n )\n .orderBy(desc(count()))\n\n return rows\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,iBAAiB,WAC5B,aACA;;CAEE,IAAI,IAAI,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,WAAW;;CAEzC,QAAQ,QAAQ,UAAU,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,QAAQ;;CAElD,UAAU,QAAQ,YAAY,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ;;CAEvD,KAAK,KAAK,KAAK;;CAEf,SAAS,QAAQ,YAAY,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ;;CAEtD,gBAAgB,SAAS,iBAAiB;;CAE1C,aAAa,SAAS,cAAc;;CAEpC,cAAc,QAAQ,iBAAiB,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,QAAQ;;CAE/D,YAAY,IAAI,aAAa,CAAC,CAAC,QAAQ;;CAEvC,iBAAiB,SAAS,kBAAkB;;CAE5C,cAAc,SAAS,eAAe,CAAC,CAAC,QAAQ;;CAEhD,WAAW,SAAS,cAAc;EAAE,MAAM;EAAQ,KAAK;CAAE,CAAC,CAAC,CAAC,QAAQ;AACtE,IACC,UAAU,CACT,YAAY,YAAY,CAAC,CAAC,GACxB,MAAM,QACN,MAAM,UACN,MAAM,YACN,MAAM,OACR,CACF,CACF;;;;;;;ACVA,SAAS,UAAU,OAAmC;CACpD,I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AG,eAAe,YAAY,OAAO,UAAU,IAC/C,KAAA,CACN,CACF,EAAA,CACU,EAAE,EAAE,SAAS;AAC3B;;;;;;;;AAqBA,eAAsB,aACpB,IAC8B;CAC9B,MAAM,QAAQ,cAAc;CAiB5B,OAAO,MAhBY,GAChB,OAAO;EACN,QAAQ,eAAe;EACvB,UAAU,eAAe;EACzB,YAAY,eAAe;EAC3B,OAAO,MAAM;CACf,CAAC,CAAC,CACD,KAAK,cAAc,CAAC,CACpB,MAAM,IAAI,eAAe,WAAW,KAAK,CAAC,CAAC,CAC3C,QACC,eAAe,QACf,eAAe,UACf,eAAe,UACjB,CAAC,CACA,QAAQ,KAAK,MAAM,CAAC,CAAC;AAG1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, flags) => {
|
|
4
|
+
let target = Object.setPrototypeOf({}, null);
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@book000/pixivts-db-mysql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.0-beta.1",
|
|
4
4
|
"description": "MySQL response recorder for @book000/pixivts (Drizzle ORM)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pixiv",
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"mysql2": "3.24.6"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@book000/pixivts": "0.
|
|
49
|
+
"@book000/pixivts": "0.65.0-beta.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "
|
|
53
|
-
"@vitest/coverage-v8": "5.0
|
|
52
|
+
"@types/node": "26.6.6",
|
|
53
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
54
54
|
"drizzle-kit": "0.31.11",
|
|
55
|
-
"tsdown": "0.23.
|
|
55
|
+
"tsdown": "0.23.7",
|
|
56
56
|
"typescript": "6.0.3",
|
|
57
|
-
"vitest": "5.0
|
|
57
|
+
"vitest": "5.1.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsdown",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll as t };
|