orange-orm 5.0.1-beta.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.
@@ -121,6 +121,14 @@ export interface ${Name}ExpressConfig {
121
121
  disableBulkDeletes?: boolean;
122
122
  }
123
123
 
124
+ export interface ${Name}HonoConfig {
125
+ baseFilter?: RawFilter | ((context: HonoContext) => RawFilter | Promise<RawFilter>);
126
+ customFilters?: Record<string, (context: HonoContext,...args: any[]) => RawFilter | Promise<RawFilter>>;
127
+ concurrency?: ${Name}Concurrency;
128
+ readonly?: boolean;
129
+ disableBulkDeletes?: boolean;
130
+ }
131
+
124
132
  export interface ${Name}CustomFilters {
125
133
  ${getCustomFilters(customFilters)}
126
134
  }
@@ -382,7 +390,7 @@ ${row}`;
382
390
  /* eslint-disable @typescript-eslint/no-unused-vars */
383
391
  /* eslint-disable @typescript-eslint/no-explicit-any */
384
392
  import type { AxiosInterceptorManager, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
385
- import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
393
+ import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Hono, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
386
394
  export { RequestHandler } from 'express';
387
395
  export { Concurrency, Filter, RawFilter, Config, TransactionOptions, Pool } from 'orange-orm';
388
396
  export = r;
@@ -395,7 +403,7 @@ declare function r(config: Config): r.RdbClient;
395
403
  /* eslint-disable @typescript-eslint/no-explicit-any */
396
404
  import schema from './schema';
397
405
  import type { AxiosInterceptorManager, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
398
- import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
406
+ import type { BooleanColumn, JSONColumn, UUIDColumn, DateColumn, NumberColumn, BinaryColumn, StringColumn, Concurrency, Filter, RawFilter, TransactionOptions, Pool, Express, Hono, Url, ColumnConcurrency, JsonPatch } from 'orange-orm';
399
407
  export default schema as RdbClient;`;
400
408
  }
401
409
 
@@ -425,6 +433,8 @@ declare namespace r {${getTables(isHttp)}
425
433
  const filter: Filter;
426
434
  function express(): Express;
427
435
  function express(config: ExpressConfig): Express;
436
+ function hono(): Hono;
437
+ function hono(config: HonoConfig): Hono;
428
438
  `;
429
439
  else
430
440
  result += `
@@ -468,12 +478,41 @@ export interface ExpressConfig {
468
478
  hooks?: ExpressHooks;
469
479
  }
470
480
 
481
+ export interface HonoConfig {
482
+ db?: Pool | (() => Pool);
483
+ tables?: HonoTables;
484
+ concurrency?: Concurrency;
485
+ readonly?: boolean;
486
+ disableBulkDeletes?: boolean;
487
+ hooks?: HonoHooks;
488
+ }
489
+
471
490
  export interface ExpressContext {
472
491
  request: import('express').Request;
473
492
  response: import('express').Response;
474
493
  client: RdbClient;
475
494
  }
476
495
 
496
+ export interface HonoRequest {
497
+ method: string;
498
+ query: Record<string, string>;
499
+ headers: Record<string, string>;
500
+ json(): Promise<unknown>;
501
+ }
502
+
503
+ export interface HonoResponse {
504
+ status(code: number): HonoResponse;
505
+ setHeader(name: string, value: string): HonoResponse;
506
+ json(value: unknown): unknown;
507
+ send(value: unknown): unknown;
508
+ }
509
+
510
+ export interface HonoContext {
511
+ request: HonoRequest;
512
+ response: HonoResponse;
513
+ client: RdbClient;
514
+ }
515
+
477
516
  export interface ExpressTransactionHooks {
478
517
  beforeBegin?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
479
518
  afterBegin?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
@@ -486,8 +525,23 @@ export interface ExpressHooks extends ExpressTransactionHooks {
486
525
  transaction?: ExpressTransactionHooks;
487
526
  }
488
527
 
528
+ export interface HonoTransactionHooks {
529
+ beforeBegin?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
530
+ afterBegin?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
531
+ beforeCommit?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
532
+ afterCommit?: (db: Pool, request: HonoRequest, response: HonoResponse) => void | Promise<void>;
533
+ afterRollback?: (db: Pool, request: HonoRequest, response: HonoResponse, error?: unknown) => void | Promise<void>;
534
+ }
535
+
536
+ export interface HonoHooks extends HonoTransactionHooks {
537
+ transaction?: HonoTransactionHooks;
538
+ }
539
+
489
540
  export interface ExpressTables {${getExpressTables()}
490
541
  }
542
+
543
+ export interface HonoTables {${getHonoTables()}
544
+ }
491
545
  `;
492
546
  function getConcurrencyTables() {
493
547
  let result = '';
@@ -537,6 +591,8 @@ export interface ExpressTables {${getExpressTables()}
537
591
  createPatch(original: any, modified: any): JsonPatch;
538
592
  express(): Express;
539
593
  express(config: ExpressConfig): Express;
594
+ hono(): Hono;
595
+ hono(config: HonoConfig): Hono;
540
596
  readonly metaData: MetaData;`;
541
597
  return result;
542
598
  }
@@ -550,6 +606,16 @@ export interface ExpressTables {${getExpressTables()}
550
606
  }
551
607
  return result;
552
608
  }
609
+ function getHonoTables() {
610
+ let result = '';
611
+ for (let name in tables) {
612
+ let Name = name.substring(0, 1).toUpperCase() + name.substring(1);
613
+ result +=
614
+ `
615
+ ${name}?: boolean | ${Name}HonoConfig;`;
616
+ }
617
+ return result;
618
+ }
553
619
  }
554
620
 
555
621
  getTSDefinition_1 = getTSDefinition;
@@ -741,6 +807,172 @@ function requireHostExpress () {
741
807
  return hostExpress_1;
742
808
  }
743
809
 
810
+ var hostHono_1;
811
+ var hasRequiredHostHono;
812
+
813
+ function requireHostHono () {
814
+ if (hasRequiredHostHono) return hostHono_1;
815
+ hasRequiredHostHono = 1;
816
+ const getTSDefinition = requireGetTSDefinition();
817
+ const getMeta = requireGetMeta();
818
+
819
+ function hostHono(hostLocal, client, options = {}) {
820
+ if ('db' in options && (options.db ?? undefined) === undefined || !client.db)
821
+ throw new Error('No db specified');
822
+ const dbOptions = { db: options.db || client.db };
823
+ let c = {};
824
+ const readonly = { readonly: options.readonly };
825
+ const sharedHooks = options.hooks;
826
+ for (let tableName in client.tables) {
827
+ const tableOptions = options[tableName] || {};
828
+ const hooks = tableOptions.hooks || sharedHooks;
829
+ c[tableName] = hostLocal({
830
+ ...dbOptions,
831
+ ...readonly,
832
+ ...tableOptions,
833
+ table: client.tables[tableName],
834
+ isHttp: true,
835
+ client,
836
+ hooks
837
+ });
838
+ }
839
+
840
+ async function handler(ctx) {
841
+ const request = createRequest(ctx);
842
+ const response = createResponse();
843
+
844
+ try {
845
+ if (request.method === 'POST')
846
+ return await post(request, response);
847
+ if (request.method === 'PATCH')
848
+ return await patch(request, response);
849
+ if (request.method === 'GET')
850
+ return get(request, response);
851
+ if (request.method === 'OPTIONS')
852
+ return handleOptions(response);
853
+ return response
854
+ .status(405)
855
+ .setHeader('Allow', 'GET, POST, PATCH, OPTIONS')
856
+ .send('Method Not Allowed');
857
+ }
858
+ catch (e) {
859
+ if (e.status === undefined)
860
+ return response.status(500).send(e.message || e);
861
+ return response.status(e.status).send(e.message);
862
+ }
863
+ }
864
+
865
+ handler.db = handler;
866
+ handler.dts = get;
867
+
868
+ function get(request, response) {
869
+ if (request.query.table) {
870
+ if (!(request.query.table in c)) {
871
+ let e = new Error('Table is not exposed or does not exist');
872
+ // @ts-ignore
873
+ e.status = 400;
874
+ throw e;
875
+ }
876
+
877
+ const result = getMeta(client.tables[request.query.table]);
878
+ response.setHeader('content-type', 'text/plain');
879
+ return response.status(200).send(result);
880
+ }
881
+ const isNamespace = request.query.isNamespace === 'true';
882
+ let tsArg = Object.keys(c).map(x => {
883
+ return { table: client.tables[x], customFilters: options?.tables?.[x].customFilters, name: x };
884
+ });
885
+ response.setHeader('content-type', 'text/plain');
886
+ return response.status(200).send(getTSDefinition(tsArg, { isNamespace, isHttp: true }));
887
+ }
888
+
889
+ async function patch(request, response) {
890
+ const table = request.query.table;
891
+ const body = await request.json();
892
+ return response.json(await c[table].patch(body, request, response));
893
+ }
894
+
895
+ async function post(request, response) {
896
+ if (!request.query.table) {
897
+ let e = new Error('Table not defined');
898
+ // @ts-ignore
899
+ e.status = 400;
900
+ throw e;
901
+ }
902
+ if (!(request.query.table in c)) {
903
+ let e = new Error('Table is not exposed or does not exist');
904
+ // @ts-ignore
905
+ e.status = 400;
906
+ throw e;
907
+ }
908
+
909
+ const body = await request.json();
910
+ return response.json(await c[request.query.table].post(body, request, response));
911
+ }
912
+
913
+ function handleOptions(response) {
914
+ response.setHeader('Access-Control-Allow-Origin', '*');
915
+ response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, OPTIONS');
916
+ response.setHeader('Access-Control-Allow-Headers', 'Content-Type');
917
+ response.setHeader('Access-Control-Max-Age', '86400');
918
+ return response.status(204).send('');
919
+ }
920
+
921
+ function createRequest(ctx) {
922
+ let bodyPromise;
923
+ const query = Object.fromEntries(new URL(ctx.req.url).searchParams.entries());
924
+ const headers = {};
925
+ for (const [name, value] of ctx.req.raw.headers.entries())
926
+ headers[name] = value;
927
+ return {
928
+ method: ctx.req.method,
929
+ query,
930
+ headers,
931
+ json: async () => {
932
+ if (!bodyPromise)
933
+ bodyPromise = ctx.req.json();
934
+ return bodyPromise;
935
+ }
936
+ };
937
+ }
938
+
939
+ function createResponse() {
940
+ let statusCode = 200;
941
+ const headers = new Headers();
942
+ return {
943
+ status(code) {
944
+ statusCode = code;
945
+ return this;
946
+ },
947
+ setHeader(name, value) {
948
+ headers.set(name, value);
949
+ return this;
950
+ },
951
+ json(value) {
952
+ if (!headers.has('content-type'))
953
+ headers.set('content-type', 'application/json');
954
+ return new Response(JSON.stringify(value), { status: statusCode, headers });
955
+ },
956
+ send(value) {
957
+ if (typeof value === 'string') {
958
+ if (!headers.has('content-type'))
959
+ headers.set('content-type', 'text/plain');
960
+ return new Response(value, { status: statusCode, headers });
961
+ }
962
+ if (!headers.has('content-type'))
963
+ headers.set('content-type', 'application/json');
964
+ return new Response(JSON.stringify(value), { status: statusCode, headers });
965
+ }
966
+ };
967
+ }
968
+
969
+ return handler;
970
+ }
971
+
972
+ hostHono_1 = hostHono;
973
+ return hostHono_1;
974
+ }
975
+
744
976
  var require$$0$3 = /*@__PURE__*/getDefaultExportFromNamespaceIfPresent(fastJsonPatch);
745
977
 
746
978
  var dateToISOString_1;
@@ -2289,6 +2521,7 @@ function requireHostLocal () {
2289
2521
  let executeQuery = requireQuery();
2290
2522
  let executeSqliteFunction = requireSqliteFunction();
2291
2523
  let hostExpress = requireHostExpress();
2524
+ let hostHono = requireHostHono();
2292
2525
  const readonlyOps = ['getManyDto', 'getMany', 'aggregate', 'count'];
2293
2526
  // { db, table, defaultConcurrency,
2294
2527
  // concurrency,
@@ -2303,7 +2536,7 @@ function requireHostLocal () {
2303
2536
  const getTransactionHook = (name) =>
2304
2537
  (transactionHooks && transactionHooks[name]) || (hooks && hooks[name]);
2305
2538
 
2306
- let c = { get, post, patch, query, sqliteFunction, express };
2539
+ let c = { get, post, patch, query, sqliteFunction, express, hono };
2307
2540
 
2308
2541
  function get() {
2309
2542
  return getMeta(table);
@@ -2452,6 +2685,10 @@ function requireHostLocal () {
2452
2685
  return hostExpress(hostLocal, client, options);
2453
2686
  }
2454
2687
 
2688
+ function hono(client, options) {
2689
+ return hostHono(hostLocal, client, options);
2690
+ }
2691
+
2455
2692
  return c;
2456
2693
  }
2457
2694
 
@@ -2945,6 +3182,7 @@ function requireClient () {
2945
3182
  client.http = onProvider.bind(null, 'http');//todo
2946
3183
  client.mysql = onProvider.bind(null, 'mysql');
2947
3184
  client.express = express;
3185
+ client.hono = hono;
2948
3186
  client.close = close;
2949
3187
 
2950
3188
  function close() {
@@ -3032,6 +3270,14 @@ function requireClient () {
3032
3270
  throw new Error('Cannot host express clientside');
3033
3271
  }
3034
3272
 
3273
+ function hono(arg) {
3274
+ if (providers.hono) {
3275
+ return providers.hono(client, { ...options, ...arg });
3276
+ }
3277
+ else
3278
+ throw new Error('Cannot host hono clientside');
3279
+ }
3280
+
3035
3281
 
3036
3282
 
3037
3283
  function _createPatch(original, modified, ...restArgs) {
@@ -12925,6 +13171,7 @@ function requireCreateProviders () {
12925
13171
  });
12926
13172
 
12927
13173
  dbMap.express = index.express;
13174
+ dbMap.hono = index.hono;
12928
13175
 
12929
13176
  function createPool(providerName, ...args) {
12930
13177
  const provider = index[providerName];
@@ -15132,6 +15379,7 @@ function requireNewDatabase$2 () {
15132
15379
  let rollback = requireRollback();
15133
15380
  let newPool = requireNewPool$2();
15134
15381
  let express = requireHostExpress();
15382
+ let hono = requireHostHono();
15135
15383
  let hostLocal = requireHostLocal();
15136
15384
  let doQuery = requireQuery();
15137
15385
  let releaseDbClient = requireReleaseDbClient();
@@ -15142,7 +15390,7 @@ function requireNewDatabase$2 () {
15142
15390
  poolOptions = poolOptions || { min: 1 };
15143
15391
  var pool = newPool(d1Database, poolOptions);
15144
15392
 
15145
- let c = {poolFactory: pool, hostLocal, express};
15393
+ let c = { poolFactory: pool, hostLocal, express, hono };
15146
15394
 
15147
15395
  c.transaction = function(options, fn) {
15148
15396
  if ((arguments.length === 1) && (typeof options === 'function')) {
@@ -15883,6 +16131,7 @@ function requireNewDatabase$1 () {
15883
16131
  let lock = requireLock();
15884
16132
  let executeSchema = requireSchema();
15885
16133
  let express = requireHostExpress();
16134
+ let hono = requireHostHono();
15886
16135
  let hostLocal = requireHostLocal();
15887
16136
  let doQuery = requireQuery();
15888
16137
  let releaseDbClient = requireReleaseDbClient();
@@ -15891,7 +16140,7 @@ function requireNewDatabase$1 () {
15891
16140
  poolOptions = poolOptions || { min: 1 };
15892
16141
  var pool = newPool(connectionString, poolOptions);
15893
16142
 
15894
- let c = { poolFactory: pool, hostLocal, express };
16143
+ let c = { poolFactory: pool, hostLocal, express, hono };
15895
16144
 
15896
16145
  c.transaction = function(options, fn) {
15897
16146
  if ((arguments.length === 1) && (typeof options === 'function')) {
@@ -16425,6 +16674,7 @@ function requireNewDatabase () {
16425
16674
  let lock = requireLock();
16426
16675
  let executeSchema = requireSchema();
16427
16676
  let express = requireHostExpress();
16677
+ let hono = requireHostHono();
16428
16678
  let hostLocal = requireHostLocal();
16429
16679
  let doQuery = requireQuery();
16430
16680
  let releaseDbClient = requireReleaseDbClient();
@@ -16435,7 +16685,7 @@ function requireNewDatabase () {
16435
16685
  poolOptions = poolOptions || { min: 1 };
16436
16686
  var pool = newPool(connectionString, poolOptions);
16437
16687
 
16438
- let c = { poolFactory: pool, hostLocal, express };
16688
+ let c = { poolFactory: pool, hostLocal, express, hono };
16439
16689
 
16440
16690
  c.transaction = function(options, fn) {
16441
16691
  if ((arguments.length === 1) && (typeof options === 'function')) {
@@ -16548,6 +16798,7 @@ function requireIndexBrowser () {
16548
16798
  if (hasRequiredIndexBrowser) return indexBrowser$1;
16549
16799
  hasRequiredIndexBrowser = 1;
16550
16800
  const hostExpress = requireHostExpress();
16801
+ const hostHono = requireHostHono();
16551
16802
  const hostLocal = requireHostLocal();
16552
16803
  const client = requireClient();
16553
16804
  const map = requireMap();
@@ -16612,6 +16863,7 @@ function requireIndexBrowser () {
16612
16863
 
16613
16864
 
16614
16865
  connectViaPool.express = hostExpress.bind(null, hostLocal);
16866
+ connectViaPool.hono = hostHono.bind(null, hostLocal);
16615
16867
 
16616
16868
  indexBrowser$1 = connectViaPool;
16617
16869
  return indexBrowser$1;