orange-orm 5.0.0 → 5.1.0
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/bin/build.js +84 -11
- package/dist/index.browser.mjs +258 -6
- package/dist/index.mjs +276 -15
- package/docs/changelog.md +5 -0
- package/package.json +5 -6
- package/src/bunPg/newDatabase.js +2 -1
- package/src/bunSqlite/newDatabase.js +2 -1
- package/src/client/createProviders.js +2 -1
- package/src/client/index.js +9 -0
- package/src/d1/newDatabase.js +2 -1
- package/src/getTSDefinition.js +68 -2
- package/src/hostHono.js +157 -0
- package/src/hostLocal.js +6 -1
- package/src/index.d.ts +30 -3
- package/src/index.js +3 -1
- package/src/indexBrowser.js +3 -1
- package/src/map2.d.ts +57 -2
- package/src/mssql/newDatabase.js +2 -1
- package/src/mySql/newDatabase.js +2 -1
- package/src/nodeSqlite/newDatabase.js +2 -1
- package/src/oracle/newDatabase.js +2 -1
- package/src/pg/newDatabase.js +2 -1
- package/src/pglite/newDatabase.js +2 -1
- package/src/sap/newDatabase.js +2 -1
- package/src/sqlite3/newDatabase.js +2 -1
- package/src/tedious/newDatabase.js +2 -1
package/src/client/index.js
CHANGED
|
@@ -66,6 +66,7 @@ function rdbClient(options = {}) {
|
|
|
66
66
|
client.http = onProvider.bind(null, 'http');//todo
|
|
67
67
|
client.mysql = onProvider.bind(null, 'mysql');
|
|
68
68
|
client.express = express;
|
|
69
|
+
client.hono = hono;
|
|
69
70
|
client.close = close;
|
|
70
71
|
|
|
71
72
|
function close() {
|
|
@@ -153,6 +154,14 @@ function rdbClient(options = {}) {
|
|
|
153
154
|
throw new Error('Cannot host express clientside');
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
function hono(arg) {
|
|
158
|
+
if (providers.hono) {
|
|
159
|
+
return providers.hono(client, { ...options, ...arg });
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
throw new Error('Cannot host hono clientside');
|
|
163
|
+
}
|
|
164
|
+
|
|
156
165
|
|
|
157
166
|
|
|
158
167
|
function _createPatch(original, modified, ...restArgs) {
|
package/src/d1/newDatabase.js
CHANGED
|
@@ -5,6 +5,7 @@ let commit = require('../table/commit');
|
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
8
9
|
let hostLocal = require('../hostLocal');
|
|
9
10
|
let doQuery = require('../query');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -15,7 +16,7 @@ function newDatabase(d1Database, poolOptions) {
|
|
|
15
16
|
poolOptions = poolOptions || { min: 1 };
|
|
16
17
|
var pool = newPool(d1Database, poolOptions);
|
|
17
18
|
|
|
18
|
-
let c = {poolFactory: pool, hostLocal, express};
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
19
20
|
|
|
20
21
|
c.transaction = function(options, fn) {
|
|
21
22
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
package/src/getTSDefinition.js
CHANGED
|
@@ -97,6 +97,14 @@ export interface ${Name}ExpressConfig {
|
|
|
97
97
|
disableBulkDeletes?: boolean;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
export interface ${Name}HonoConfig {
|
|
101
|
+
baseFilter?: RawFilter | ((context: HonoContext) => RawFilter | Promise<RawFilter>);
|
|
102
|
+
customFilters?: Record<string, (context: HonoContext,...args: any[]) => RawFilter | Promise<RawFilter>>;
|
|
103
|
+
concurrency?: ${Name}Concurrency;
|
|
104
|
+
readonly?: boolean;
|
|
105
|
+
disableBulkDeletes?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
100
108
|
export interface ${Name}CustomFilters {
|
|
101
109
|
${getCustomFilters(customFilters)}
|
|
102
110
|
}
|
|
@@ -358,7 +366,7 @@ function getPrefixTs(isNamespace) {
|
|
|
358
366
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
359
367
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
360
368
|
import type { AxiosInterceptorManager, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
361
|
-
import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
|
|
369
|
+
import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Hono, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
|
|
362
370
|
export { RequestHandler } from 'express';
|
|
363
371
|
export { Concurrency, Filter, RawFilter, Config, TransactionOptions, Pool } from 'orange-orm';
|
|
364
372
|
export = r;
|
|
@@ -371,7 +379,7 @@ declare function r(config: Config): r.RdbClient;
|
|
|
371
379
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
372
380
|
import schema from './schema';
|
|
373
381
|
import type { AxiosInterceptorManager, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
374
|
-
import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
|
|
382
|
+
import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Hono, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
|
|
375
383
|
export default schema as RdbClient;`;
|
|
376
384
|
}
|
|
377
385
|
|
|
@@ -401,6 +409,8 @@ declare namespace r {${getTables(isHttp)}
|
|
|
401
409
|
const filter: Filter;
|
|
402
410
|
function express(): Express;
|
|
403
411
|
function express(config: ExpressConfig): Express;
|
|
412
|
+
function hono(): Hono;
|
|
413
|
+
function hono(config: HonoConfig): Hono;
|
|
404
414
|
`;
|
|
405
415
|
else
|
|
406
416
|
result += `
|
|
@@ -444,12 +454,41 @@ export interface ExpressConfig {
|
|
|
444
454
|
hooks?: ExpressHooks;
|
|
445
455
|
}
|
|
446
456
|
|
|
457
|
+
export interface HonoConfig {
|
|
458
|
+
db?: Pool | (() => Pool);
|
|
459
|
+
tables?: HonoTables;
|
|
460
|
+
concurrency?: Concurrency;
|
|
461
|
+
readonly?: boolean;
|
|
462
|
+
disableBulkDeletes?: boolean;
|
|
463
|
+
hooks?: HonoHooks;
|
|
464
|
+
}
|
|
465
|
+
|
|
447
466
|
export interface ExpressContext {
|
|
448
467
|
request: import('express').Request;
|
|
449
468
|
response: import('express').Response;
|
|
450
469
|
client: RdbClient;
|
|
451
470
|
}
|
|
452
471
|
|
|
472
|
+
export interface HonoRequest {
|
|
473
|
+
method: string;
|
|
474
|
+
query: Record<string, string>;
|
|
475
|
+
headers: Record<string, string>;
|
|
476
|
+
json(): Promise<unknown>;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export interface HonoResponse {
|
|
480
|
+
status(code: number): HonoResponse;
|
|
481
|
+
setHeader(name: string, value: string): HonoResponse;
|
|
482
|
+
json(value: unknown): unknown;
|
|
483
|
+
send(value: unknown): unknown;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface HonoContext {
|
|
487
|
+
request: HonoRequest;
|
|
488
|
+
response: HonoResponse;
|
|
489
|
+
client: RdbClient;
|
|
490
|
+
}
|
|
491
|
+
|
|
453
492
|
export interface ExpressTransactionHooks {
|
|
454
493
|
beforeBegin?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
|
|
455
494
|
afterBegin?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
|
|
@@ -462,8 +501,23 @@ export interface ExpressHooks extends ExpressTransactionHooks {
|
|
|
462
501
|
transaction?: ExpressTransactionHooks;
|
|
463
502
|
}
|
|
464
503
|
|
|
504
|
+
export interface HonoTransactionHooks {
|
|
505
|
+
beforeBegin?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
|
|
506
|
+
afterBegin?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
|
|
507
|
+
beforeCommit?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
|
|
508
|
+
afterCommit?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
|
|
509
|
+
afterRollback?: (db: Pool, request: HonoRequest, response: HonoResponse, error?: unknown) => void | Promise<void>;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
export interface HonoHooks extends HonoTransactionHooks {
|
|
513
|
+
transaction?: HonoTransactionHooks;
|
|
514
|
+
}
|
|
515
|
+
|
|
465
516
|
export interface ExpressTables {${getExpressTables()}
|
|
466
517
|
}
|
|
518
|
+
|
|
519
|
+
export interface HonoTables {${getHonoTables()}
|
|
520
|
+
}
|
|
467
521
|
`;
|
|
468
522
|
function getConcurrencyTables() {
|
|
469
523
|
let result = '';
|
|
@@ -513,6 +567,8 @@ export interface ExpressTables {${getExpressTables()}
|
|
|
513
567
|
createPatch(original: any, modified: any): JsonPatch;
|
|
514
568
|
express(): Express;
|
|
515
569
|
express(config: ExpressConfig): Express;
|
|
570
|
+
hono(): Hono;
|
|
571
|
+
hono(config: HonoConfig): Hono;
|
|
516
572
|
readonly metaData: MetaData;`;
|
|
517
573
|
return result;
|
|
518
574
|
}
|
|
@@ -526,6 +582,16 @@ export interface ExpressTables {${getExpressTables()}
|
|
|
526
582
|
}
|
|
527
583
|
return result;
|
|
528
584
|
}
|
|
585
|
+
function getHonoTables() {
|
|
586
|
+
let result = '';
|
|
587
|
+
for (let name in tables) {
|
|
588
|
+
let Name = name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
589
|
+
result +=
|
|
590
|
+
`
|
|
591
|
+
${name}?: boolean | ${Name}HonoConfig;`;
|
|
592
|
+
}
|
|
593
|
+
return result;
|
|
594
|
+
}
|
|
529
595
|
}
|
|
530
596
|
|
|
531
597
|
module.exports = getTSDefinition;
|
package/src/hostHono.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
const getTSDefinition = require('./getTSDefinition');
|
|
2
|
+
const getMeta = require('./hostExpress/getMeta');
|
|
3
|
+
|
|
4
|
+
function hostHono(hostLocal, client, options = {}) {
|
|
5
|
+
if ('db' in options && (options.db ?? undefined) === undefined || !client.db)
|
|
6
|
+
throw new Error('No db specified');
|
|
7
|
+
const dbOptions = { db: options.db || client.db };
|
|
8
|
+
let c = {};
|
|
9
|
+
const readonly = { readonly: options.readonly };
|
|
10
|
+
const sharedHooks = options.hooks;
|
|
11
|
+
for (let tableName in client.tables) {
|
|
12
|
+
const tableOptions = options[tableName] || {};
|
|
13
|
+
const hooks = tableOptions.hooks || sharedHooks;
|
|
14
|
+
c[tableName] = hostLocal({
|
|
15
|
+
...dbOptions,
|
|
16
|
+
...readonly,
|
|
17
|
+
...tableOptions,
|
|
18
|
+
table: client.tables[tableName],
|
|
19
|
+
isHttp: true,
|
|
20
|
+
client,
|
|
21
|
+
hooks
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function handler(ctx) {
|
|
26
|
+
const request = createRequest(ctx);
|
|
27
|
+
const response = createResponse();
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (request.method === 'POST')
|
|
31
|
+
return await post(request, response);
|
|
32
|
+
if (request.method === 'PATCH')
|
|
33
|
+
return await patch(request, response);
|
|
34
|
+
if (request.method === 'GET')
|
|
35
|
+
return get(request, response);
|
|
36
|
+
if (request.method === 'OPTIONS')
|
|
37
|
+
return handleOptions(response);
|
|
38
|
+
return response
|
|
39
|
+
.status(405)
|
|
40
|
+
.setHeader('Allow', 'GET, POST, PATCH, OPTIONS')
|
|
41
|
+
.send('Method Not Allowed');
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e.status === undefined)
|
|
45
|
+
return response.status(500).send(e.message || e);
|
|
46
|
+
return response.status(e.status).send(e.message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
handler.db = handler;
|
|
51
|
+
handler.dts = get;
|
|
52
|
+
|
|
53
|
+
function get(request, response) {
|
|
54
|
+
if (request.query.table) {
|
|
55
|
+
if (!(request.query.table in c)) {
|
|
56
|
+
let e = new Error('Table is not exposed or does not exist');
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
e.status = 400;
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const result = getMeta(client.tables[request.query.table]);
|
|
63
|
+
response.setHeader('content-type', 'text/plain');
|
|
64
|
+
return response.status(200).send(result);
|
|
65
|
+
}
|
|
66
|
+
const isNamespace = request.query.isNamespace === 'true';
|
|
67
|
+
let tsArg = Object.keys(c).map(x => {
|
|
68
|
+
return { table: client.tables[x], customFilters: options?.tables?.[x].customFilters, name: x };
|
|
69
|
+
});
|
|
70
|
+
response.setHeader('content-type', 'text/plain');
|
|
71
|
+
return response.status(200).send(getTSDefinition(tsArg, { isNamespace, isHttp: true }));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function patch(request, response) {
|
|
75
|
+
const table = request.query.table;
|
|
76
|
+
const body = await request.json();
|
|
77
|
+
return response.json(await c[table].patch(body, request, response));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function post(request, response) {
|
|
81
|
+
if (!request.query.table) {
|
|
82
|
+
let e = new Error('Table not defined');
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
e.status = 400;
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
87
|
+
if (!(request.query.table in c)) {
|
|
88
|
+
let e = new Error('Table is not exposed or does not exist');
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
e.status = 400;
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const body = await request.json();
|
|
95
|
+
return response.json(await c[request.query.table].post(body, request, response));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handleOptions(response) {
|
|
99
|
+
response.setHeader('Access-Control-Allow-Origin', '*');
|
|
100
|
+
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, OPTIONS');
|
|
101
|
+
response.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
102
|
+
response.setHeader('Access-Control-Max-Age', '86400');
|
|
103
|
+
return response.status(204).send('');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function createRequest(ctx) {
|
|
107
|
+
let bodyPromise;
|
|
108
|
+
const query = Object.fromEntries(new URL(ctx.req.url).searchParams.entries());
|
|
109
|
+
const headers = {};
|
|
110
|
+
for (const [name, value] of ctx.req.raw.headers.entries())
|
|
111
|
+
headers[name] = value;
|
|
112
|
+
return {
|
|
113
|
+
method: ctx.req.method,
|
|
114
|
+
query,
|
|
115
|
+
headers,
|
|
116
|
+
json: async () => {
|
|
117
|
+
if (!bodyPromise)
|
|
118
|
+
bodyPromise = ctx.req.json();
|
|
119
|
+
return bodyPromise;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function createResponse() {
|
|
125
|
+
let statusCode = 200;
|
|
126
|
+
const headers = new Headers();
|
|
127
|
+
return {
|
|
128
|
+
status(code) {
|
|
129
|
+
statusCode = code;
|
|
130
|
+
return this;
|
|
131
|
+
},
|
|
132
|
+
setHeader(name, value) {
|
|
133
|
+
headers.set(name, value);
|
|
134
|
+
return this;
|
|
135
|
+
},
|
|
136
|
+
json(value) {
|
|
137
|
+
if (!headers.has('content-type'))
|
|
138
|
+
headers.set('content-type', 'application/json');
|
|
139
|
+
return new Response(JSON.stringify(value), { status: statusCode, headers });
|
|
140
|
+
},
|
|
141
|
+
send(value) {
|
|
142
|
+
if (typeof value === 'string') {
|
|
143
|
+
if (!headers.has('content-type'))
|
|
144
|
+
headers.set('content-type', 'text/plain');
|
|
145
|
+
return new Response(value, { status: statusCode, headers });
|
|
146
|
+
}
|
|
147
|
+
if (!headers.has('content-type'))
|
|
148
|
+
headers.set('content-type', 'application/json');
|
|
149
|
+
return new Response(JSON.stringify(value), { status: statusCode, headers });
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return handler;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = hostHono;
|
package/src/hostLocal.js
CHANGED
|
@@ -4,6 +4,7 @@ let setSessionSingleton = require('./table/setSessionSingleton');
|
|
|
4
4
|
let executeQuery = require('./query');
|
|
5
5
|
let executeSqliteFunction = require('./sqliteFunction');
|
|
6
6
|
let hostExpress = require('./hostExpress');
|
|
7
|
+
let hostHono = require('./hostHono');
|
|
7
8
|
const readonlyOps = ['getManyDto', 'getMany', 'aggregate', 'count'];
|
|
8
9
|
// { db, table, defaultConcurrency,
|
|
9
10
|
// concurrency,
|
|
@@ -18,7 +19,7 @@ function hostLocal() {
|
|
|
18
19
|
const getTransactionHook = (name) =>
|
|
19
20
|
(transactionHooks && transactionHooks[name]) || (hooks && hooks[name]);
|
|
20
21
|
|
|
21
|
-
let c = { get, post, patch, query, sqliteFunction, express };
|
|
22
|
+
let c = { get, post, patch, query, sqliteFunction, express, hono };
|
|
22
23
|
|
|
23
24
|
function get() {
|
|
24
25
|
return getMeta(table);
|
|
@@ -167,6 +168,10 @@ function hostLocal() {
|
|
|
167
168
|
return hostExpress(hostLocal, client, options);
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
function hono(client, options) {
|
|
172
|
+
return hostHono(hostLocal, client, options);
|
|
173
|
+
}
|
|
174
|
+
|
|
170
175
|
return c;
|
|
171
176
|
}
|
|
172
177
|
|
package/src/index.d.ts
CHANGED
|
@@ -168,6 +168,33 @@ declare namespace r {
|
|
|
168
168
|
dts: import('express').RequestHandler
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
export interface Hono {
|
|
172
|
+
(context: HonoContextLike): unknown | Promise<unknown>;
|
|
173
|
+
db: (context: HonoContextLike) => unknown | Promise<unknown>;
|
|
174
|
+
dts: (request: HonoRequestLike, response: HonoResponseLike) => unknown | Promise<unknown>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface HonoRequestLike {
|
|
178
|
+
method: string;
|
|
179
|
+
url: string;
|
|
180
|
+
header(name: string): string | undefined;
|
|
181
|
+
json(): Promise<unknown>;
|
|
182
|
+
raw: {
|
|
183
|
+
headers: Iterable<[string, string]>;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface HonoContextLike {
|
|
188
|
+
req: HonoRequestLike;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface HonoResponseLike {
|
|
192
|
+
status(code: number): HonoResponseLike;
|
|
193
|
+
setHeader(name: string, value: string): HonoResponseLike;
|
|
194
|
+
json(value: unknown): unknown;
|
|
195
|
+
send(value: unknown): unknown;
|
|
196
|
+
}
|
|
197
|
+
|
|
171
198
|
export interface CustomFilters {
|
|
172
199
|
[key: string]: (...args: any[]) => RawFilter | CustomFilters
|
|
173
200
|
}
|
|
@@ -254,7 +281,7 @@ declare namespace r {
|
|
|
254
281
|
*/
|
|
255
282
|
ge(value: TType | null): Filter;
|
|
256
283
|
between(from: TType, to: TType | null): Filter;
|
|
257
|
-
in(values: TType[] | null): Filter;
|
|
284
|
+
in(values: readonly TType[] | null): Filter;
|
|
258
285
|
}
|
|
259
286
|
|
|
260
287
|
interface ColumnBase2<TType, TType2> {
|
|
@@ -289,7 +316,7 @@ declare namespace r {
|
|
|
289
316
|
*/
|
|
290
317
|
ge(value: TType | TType2 | null): Filter;
|
|
291
318
|
between(from: TType | TType2, to: TType | TType2): Filter;
|
|
292
|
-
in(values:
|
|
319
|
+
in(values: readonly (TType | TType2)[] | null): Filter;
|
|
293
320
|
}
|
|
294
321
|
|
|
295
322
|
export interface TransactionOptions {
|
|
@@ -314,4 +341,4 @@ declare namespace r {
|
|
|
314
341
|
|
|
315
342
|
}
|
|
316
343
|
|
|
317
|
-
export = r;
|
|
344
|
+
export = r;
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const hostExpress = require('./hostExpress');
|
|
2
|
+
const hostHono = require('./hostHono');
|
|
2
3
|
const hostLocal = require('./hostLocal');
|
|
3
4
|
const client = require('./client/index.js');
|
|
4
5
|
const map = require('./client/map');
|
|
@@ -142,5 +143,6 @@ Object.defineProperty(connectViaPool, 'oracle', {
|
|
|
142
143
|
});
|
|
143
144
|
|
|
144
145
|
connectViaPool.express = hostExpress.bind(null, hostLocal);
|
|
146
|
+
connectViaPool.hono = hostHono.bind(null, hostLocal);
|
|
145
147
|
|
|
146
|
-
module.exports = connectViaPool;
|
|
148
|
+
module.exports = connectViaPool;
|
package/src/indexBrowser.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const hostExpress = require('./hostExpress');
|
|
2
|
+
const hostHono = require('./hostHono');
|
|
2
3
|
const hostLocal = require('./hostLocal');
|
|
3
4
|
const client = require('./client/index.js');
|
|
4
5
|
const map = require('./client/map');
|
|
@@ -63,5 +64,6 @@ Object.defineProperty(connectViaPool, 'pg', {
|
|
|
63
64
|
|
|
64
65
|
|
|
65
66
|
connectViaPool.express = hostExpress.bind(null, hostLocal);
|
|
67
|
+
connectViaPool.hono = hostHono.bind(null, hostLocal);
|
|
66
68
|
|
|
67
|
-
module.exports = connectViaPool;
|
|
69
|
+
module.exports = connectViaPool;
|
package/src/map2.d.ts
CHANGED
|
@@ -99,9 +99,9 @@ export type ColumnFilterType<Val, ColumnType = any> = {
|
|
|
99
99
|
gt(value: Val | null | undefined): Filter;
|
|
100
100
|
greaterThanOrEqual(value: Val | null | undefined): Filter;
|
|
101
101
|
ge(value: Val | null | undefined): Filter;
|
|
102
|
-
in(values: (Val | null | undefined)[]): Filter;
|
|
102
|
+
in(values: readonly (Val | null | undefined)[]): Filter;
|
|
103
103
|
between(from: Val | null | undefined, to: Val | null | undefined): Filter;
|
|
104
|
-
notIn(values: (Val | null | undefined)[]): Filter;
|
|
104
|
+
notIn(values: readonly (Val | null | undefined)[]): Filter;
|
|
105
105
|
} & (ColumnType extends 'string' ? StringOnlyMethods : {});
|
|
106
106
|
|
|
107
107
|
export type JsonArray = Array<JsonValue>;
|
|
@@ -921,11 +921,43 @@ export type DBClient<M extends Record<string, TableDefinition<M>>> = {
|
|
|
921
921
|
): Promise<TR>;
|
|
922
922
|
express(): import('express').RequestHandler;
|
|
923
923
|
express(config: ExpressConfig<M>): import('express').RequestHandler;
|
|
924
|
+
hono(): HonoHandler;
|
|
925
|
+
hono(config: HonoConfig<M>): HonoHandler;
|
|
924
926
|
readonly metaData: DbConcurrency<M>;
|
|
925
927
|
|
|
926
928
|
interceptors: WithInterceptors;
|
|
927
929
|
} & WithInterceptors & DbConnectable<M>;
|
|
928
930
|
|
|
931
|
+
type HonoRequest = {
|
|
932
|
+
method: string;
|
|
933
|
+
query: Record<string, string>;
|
|
934
|
+
headers: Record<string, string>;
|
|
935
|
+
json(): Promise<unknown>;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
type HonoResponse = {
|
|
939
|
+
status(code: number): HonoResponse;
|
|
940
|
+
setHeader(name: string, value: string): HonoResponse;
|
|
941
|
+
json(value: unknown): unknown;
|
|
942
|
+
send(value: unknown): unknown;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
type HonoRawRequest = {
|
|
946
|
+
method: string;
|
|
947
|
+
url: string;
|
|
948
|
+
header(name: string): string | undefined;
|
|
949
|
+
json(): Promise<unknown>;
|
|
950
|
+
raw: {
|
|
951
|
+
headers: Iterable<[string, string]>;
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
type HonoContextLike = {
|
|
956
|
+
req: HonoRawRequest;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
type HonoHandler = (context: HonoContextLike) => unknown | Promise<unknown>;
|
|
960
|
+
|
|
929
961
|
type ExpressConfig<M extends Record<string, TableDefinition<M>>> = {
|
|
930
962
|
[TableName in keyof M]?: ExpressTableConfig<M>;
|
|
931
963
|
} & {
|
|
@@ -933,10 +965,21 @@ type ExpressConfig<M extends Record<string, TableDefinition<M>>> = {
|
|
|
933
965
|
hooks?: ExpressHooks<M>;
|
|
934
966
|
}
|
|
935
967
|
|
|
968
|
+
type HonoConfig<M extends Record<string, TableDefinition<M>>> = {
|
|
969
|
+
[TableName in keyof M]?: HonoTableConfig<M>;
|
|
970
|
+
} & {
|
|
971
|
+
db?: Pool | ((connectors: Connectors) => Pool | Promise<Pool>);
|
|
972
|
+
hooks?: HonoHooks<M>;
|
|
973
|
+
}
|
|
974
|
+
|
|
936
975
|
type ExpressTableConfig<M extends Record<string, TableDefinition<M>>> = {
|
|
937
976
|
baseFilter?: RawFilter | ((db: DBClient<M>, req: import('express').Request, res: import('express').Response) => RawFilter);
|
|
938
977
|
}
|
|
939
978
|
|
|
979
|
+
type HonoTableConfig<M extends Record<string, TableDefinition<M>>> = {
|
|
980
|
+
baseFilter?: RawFilter | ((db: DBClient<M>, req: HonoRequest, res: HonoResponse) => RawFilter);
|
|
981
|
+
}
|
|
982
|
+
|
|
940
983
|
type ExpressTransactionHooks<M extends Record<string, TableDefinition<M>>> = {
|
|
941
984
|
beforeBegin?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response) => void | Promise<void>;
|
|
942
985
|
afterBegin?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response) => void | Promise<void>;
|
|
@@ -945,10 +988,22 @@ type ExpressTransactionHooks<M extends Record<string, TableDefinition<M>>> = {
|
|
|
945
988
|
afterRollback?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response, error?: unknown) => void | Promise<void>;
|
|
946
989
|
}
|
|
947
990
|
|
|
991
|
+
type HonoTransactionHooks<M extends Record<string, TableDefinition<M>>> = {
|
|
992
|
+
beforeBegin?: (db: DBClient<M>, req: HonoRequest, res: HonoResponse) => void | Promise<void>;
|
|
993
|
+
afterBegin?: (db: DBClient<M>, req: HonoRequest, res: HonoResponse) => void | Promise<void>;
|
|
994
|
+
beforeCommit?: (db: DBClient<M>, req: HonoRequest, res: HonoResponse) => void | Promise<void>;
|
|
995
|
+
afterCommit?: (db: DBClient<M>, req: HonoRequest, res: HonoResponse) => void | Promise<void>;
|
|
996
|
+
afterRollback?: (db: DBClient<M>, req: HonoRequest, res: HonoResponse, error?: unknown) => void | Promise<void>;
|
|
997
|
+
}
|
|
998
|
+
|
|
948
999
|
type ExpressHooks<M extends Record<string, TableDefinition<M>>> = ExpressTransactionHooks<M> & {
|
|
949
1000
|
transaction?: ExpressTransactionHooks<M>;
|
|
950
1001
|
}
|
|
951
1002
|
|
|
1003
|
+
type HonoHooks<M extends Record<string, TableDefinition<M>>> = HonoTransactionHooks<M> & {
|
|
1004
|
+
transaction?: HonoTransactionHooks<M>;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
952
1007
|
export type DeepExpand<T> =
|
|
953
1008
|
T extends Date ? T :
|
|
954
1009
|
T extends Array<infer U> ? Array<DeepExpand<U>> :
|
package/src/mssql/newDatabase.js
CHANGED
|
@@ -5,6 +5,7 @@ let commit = require('../table/commit');
|
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
8
9
|
let hostLocal = require('../hostLocal');
|
|
9
10
|
let doQuery = require('../query');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -15,7 +16,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
15
16
|
poolOptions = poolOptions || { min: 1 };
|
|
16
17
|
var pool = newPool(connectionString, poolOptions);
|
|
17
18
|
|
|
18
|
-
let c = { poolFactory: pool, hostLocal, express };
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
19
20
|
|
|
20
21
|
c.transaction = function(options, fn) {
|
|
21
22
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
package/src/mySql/newDatabase.js
CHANGED
|
@@ -5,6 +5,7 @@ let commit = require('../table/commit');
|
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
8
9
|
let hostLocal = require('../hostLocal');
|
|
9
10
|
let doQuery = require('../query');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -15,7 +16,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
15
16
|
poolOptions = poolOptions || { min: 1 };
|
|
16
17
|
var pool = newPool(connectionString, poolOptions);
|
|
17
18
|
|
|
18
|
-
let c = { poolFactory: pool, hostLocal, express };
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
19
20
|
|
|
20
21
|
c.transaction = function(options, fn) {
|
|
21
22
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
@@ -5,6 +5,7 @@ let commit = require('../table/commit');
|
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
8
9
|
let hostLocal = require('../hostLocal');
|
|
9
10
|
let doQuery = require('../query');
|
|
10
11
|
let doSqliteFunction = require('../sqliteFunction');
|
|
@@ -16,7 +17,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
16
17
|
poolOptions = poolOptions || { min: 1 };
|
|
17
18
|
var pool = newPool(connectionString, poolOptions);
|
|
18
19
|
|
|
19
|
-
let c = {poolFactory: pool, hostLocal, express};
|
|
20
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
20
21
|
|
|
21
22
|
c.transaction = function(options, fn) {
|
|
22
23
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
@@ -5,6 +5,7 @@ let commit = require('../table/commit');
|
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
8
9
|
let hostLocal = require('../hostLocal');
|
|
9
10
|
let doQuery = require('../query');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -15,7 +16,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
15
16
|
poolOptions = poolOptions || { min: 1 };
|
|
16
17
|
var pool = newPool(connectionString, poolOptions);
|
|
17
18
|
|
|
18
|
-
let c = { poolFactory: pool, hostLocal, express };
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
19
20
|
|
|
20
21
|
c.transaction = function(options, fn) {
|
|
21
22
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
package/src/pg/newDatabase.js
CHANGED
|
@@ -7,6 +7,7 @@ let newPool = require('./newPool');
|
|
|
7
7
|
let lock = require('../lock');
|
|
8
8
|
let executeSchema = require('./schema');
|
|
9
9
|
let express = require('../hostExpress');
|
|
10
|
+
let hono = require('../hostHono');
|
|
10
11
|
let hostLocal = require('../hostLocal');
|
|
11
12
|
let doQuery = require('../query');
|
|
12
13
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -17,7 +18,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
17
18
|
poolOptions = poolOptions || { min: 1 };
|
|
18
19
|
var pool = newPool(connectionString, poolOptions);
|
|
19
20
|
|
|
20
|
-
let c = { poolFactory: pool, hostLocal, express };
|
|
21
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
21
22
|
|
|
22
23
|
c.transaction = function(options, fn) {
|
|
23
24
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
@@ -7,6 +7,7 @@ let newPool = require('./newPool');
|
|
|
7
7
|
let lock = require('../lock');
|
|
8
8
|
let executeSchema = require('../pg/schema');
|
|
9
9
|
let express = require('../hostExpress');
|
|
10
|
+
let hono = require('../hostHono');
|
|
10
11
|
let hostLocal = require('../hostLocal');
|
|
11
12
|
let doQuery = require('../query');
|
|
12
13
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -15,7 +16,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
15
16
|
poolOptions = poolOptions || { min: 1 };
|
|
16
17
|
var pool = newPool(connectionString, poolOptions);
|
|
17
18
|
|
|
18
|
-
let c = { poolFactory: pool, hostLocal, express };
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
19
20
|
|
|
20
21
|
c.transaction = function(options, fn) {
|
|
21
22
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|
package/src/sap/newDatabase.js
CHANGED
|
@@ -5,6 +5,7 @@ let commit = require('../table/commit');
|
|
|
5
5
|
let rollback = require('../table/rollback');
|
|
6
6
|
let newPool = require('./newPool');
|
|
7
7
|
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
8
9
|
let hostLocal = require('../hostLocal');
|
|
9
10
|
let doQuery = require('../query');
|
|
10
11
|
let releaseDbClient = require('../table/releaseDbClient');
|
|
@@ -15,7 +16,7 @@ function newDatabase(connectionString, poolOptions) {
|
|
|
15
16
|
poolOptions = poolOptions || { min: 1 };
|
|
16
17
|
var pool = newPool(connectionString, poolOptions);
|
|
17
18
|
|
|
18
|
-
let c = {poolFactory: pool, hostLocal, express};
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
19
20
|
|
|
20
21
|
c.transaction = function(options, fn) {
|
|
21
22
|
if ((arguments.length === 1) && (typeof options === 'function')) {
|