@vrplatform/kysely 1.2.25 → 1.2.26

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.2.25",
6
+ "version": "1.2.26",
7
7
  "description": "",
8
8
  "main": "build/main/index.js",
9
9
  "module": "build/module/index.js",
@@ -43,9 +43,10 @@
43
43
  ],
44
44
  "scripts": {
45
45
  "pub": "bun run build && cp .data.tar build/ && pnpm publish --no-git-checks",
46
+ "generate": "bun pgdump && bun run generate:v1 && bun run generate:v2",
46
47
  "generate:v1": "kysely-codegen --env-file ../../.env --out-file ./src/v1.generated.ts --default-schema=xxx --camel-case",
47
- "generate:v2": "rm -f .data.tar && bun src/test.ts",
48
- "pg-dump": "dotenvx run -f ../../.env -- bun pg-dump:run",
48
+ "generate:v2": "rm -f .data.tar && bun setup.ts",
49
+ "pgdump": "dotenvx run -f ../../.env -- bun pg-dump:run && bun pg-dump:rm && bun pg-dump:fix-uuid",
49
50
  "pg-dump:run": "pg_dump --clean --schema-only --if-exists --no-owner --no-acl $DATABASE_URL > initial/0000000000000-init.sql",
50
51
  "pg-dump:rm": "sed -i '' '/EXTENSION/d' initial/0000000000000-init.sql",
51
52
  "pg-dump:fix-uuid": "sed -i '' 's/public\\.gen_random_uuid()/gen_random_uuid()/g' initial/0000000000000-init.sql",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { serializeError } from '@finalytic/utils';
2
- import { CamelCasePlugin, Kysely as K } from 'kysely';
2
+ import { CamelCasePlugin, Kysely as K, type Transaction as T } from 'kysely';
3
3
  import { PostgresJSDialect } from 'kysely-postgres-js';
4
4
  import postgres, { type Sql } from 'postgres';
5
5
 
@@ -21,16 +21,18 @@ export * from './v1.generated';
21
21
  import { join, relative } from 'node:path';
22
22
  import type { DB } from './v1.generated';
23
23
 
24
+ export type Transaction = T<DB>;
24
25
  export { sql } from 'kysely';
25
26
 
26
27
  export type Kysely = K<DB>;
27
28
  export type Postgres = Sql;
28
- export function useKysely(postgres: Sql) {
29
+ export function useKysely(postgres: Sql, options: { log?: boolean } = {}) {
29
30
  return new K<DB>({
30
31
  dialect: new PostgresJSDialect({
31
32
  postgres,
32
33
  }),
33
34
  plugins: [new CamelCasePlugin()],
35
+ log: options?.log ? ['query', 'error'] : undefined,
34
36
  });
35
37
  }
36
38
 
@@ -68,7 +70,8 @@ export async function useAsyncKysely(connectionString: string, ssl?: boolean) {
68
70
  }
69
71
 
70
72
  const connections: postgres.Sql<any>[] = [];
71
- export function usePostgres(connectionString: string, ssl?: boolean) {
73
+ export function usePostgres(connectionString?: string, ssl?: boolean) {
74
+ if (!connectionString) throw new Error('No connection string');
72
75
  const pg = postgres(connectionString, {
73
76
  ssl: ssl ? 'require' : false,
74
77
  });
@@ -76,8 +79,17 @@ export function usePostgres(connectionString: string, ssl?: boolean) {
76
79
  return pg;
77
80
  }
78
81
 
79
- export async function forceCloseAllPostgres() {
80
- await Promise.all(connections.map((pg) => pg.end().catch(() => undefined)));
82
+ export async function forceCloseAllPostgres(timeoutMs = 5000) {
83
+ await Promise.allSettled(
84
+ connections.map((pg) =>
85
+ Promise.race([
86
+ pg.end(),
87
+ new Promise((_, reject) =>
88
+ setTimeout(() => reject(new Error('end timeout')), timeoutMs)
89
+ ),
90
+ ]).catch(() => undefined)
91
+ )
92
+ );
81
93
  }
82
94
 
83
95
  export class DatabaseError extends Error {
package/src/local.ts CHANGED
@@ -38,7 +38,10 @@ async function migrateKysely(kysely: Kysely<any>) {
38
38
  });
39
39
 
40
40
  console.log('migrating kysely ....');
41
- const { error, results } = await migrator.migrateToLatest();
41
+ const { error, results } = await migrator.migrateToLatest().catch(() => {
42
+ console.error('failed to migrate');
43
+ process.exit(1);
44
+ });
42
45
 
43
46
  for (const it of results ?? []) {
44
47
  if (it.status === 'Success') {
@@ -57,26 +60,47 @@ async function migrateKysely(kysely: Kysely<any>) {
57
60
 
58
61
  const dumpPath = join(root, '.data.tar');
59
62
  const dumpFile = (async () => {
60
- const dataExists = await exists(dumpPath);
63
+ const dataExists = await exists(dumpPath).catch(() => false);
61
64
  if (!dataExists) {
62
65
  console.log('Creating initial dump');
63
66
  const main = new PGlite();
64
- await migrate(main);
67
+ await migrate(main).catch(async (err) => {
68
+ console.error('failed to migrate initial dump');
69
+ await Bun.write(
70
+ '../logs/migrate-initial-dump.json',
71
+ JSON.stringify(err as any, null, 2)
72
+ );
73
+ process.exit(1);
74
+ });
65
75
  const { dialect } = new KyselyPGlite(main);
66
76
  const kysely = new Kysely<DB>({
67
77
  dialect,
68
78
  plugins: [new CamelCasePlugin()],
69
79
  });
70
- await migrateKysely(kysely);
71
- await codegen.generate({
72
- db: kysely,
73
- outFile: path.join(root, 'src/v1.generated.ts'),
74
- defaultSchemas: ['xxx'],
75
- camelCase: true,
76
- dialect: codegen.getDialect('postgres'),
80
+ await migrateKysely(kysely).catch(() => {
81
+ console.error('failed to migrate kysely');
82
+ process.exit(1);
83
+ });
84
+ await codegen
85
+ .generate({
86
+ db: kysely,
87
+ outFile: path.join(root, 'src/v1.generated.ts'),
88
+ defaultSchemas: ['xxx'],
89
+ camelCase: true,
90
+ dialect: codegen.getDialect('postgres'),
91
+ })
92
+ .catch(() => {
93
+ console.error('failed to generate kysely');
94
+ process.exit(1);
95
+ });
96
+ const content = await main.dumpDataDir('none').catch(() => {
97
+ console.error('failed to dump data');
98
+ process.exit(1);
99
+ });
100
+ await Bun.write(dumpPath, content).catch(() => {
101
+ console.error('failed to write dump');
102
+ process.exit(1);
77
103
  });
78
- const content = await main.dumpDataDir('none');
79
- await Bun.write(dumpPath, content);
80
104
  return content;
81
105
  }
82
106
  return Bun.file(dumpPath);
package/src/test.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  import { afterAll } from 'bun:test';
2
2
  import { useLocalKysely } from './local';
3
3
 
4
- export async function useTestKysely() {
4
+ export async function useTestKysely(
5
+ cleanupStrategy: 'afterAll' | 'using' | 'manual'
6
+ ) {
5
7
  const kysely = await useLocalKysely();
6
8
 
7
- afterAll(async () => {
8
- await kysely.destroy();
9
- });
10
- return kysely;
9
+ if (cleanupStrategy === 'afterAll')
10
+ afterAll(async () => {
11
+ await kysely.destroy();
12
+ });
13
+ return {
14
+ kysely,
15
+ [Symbol.dispose]: async () => {
16
+ await kysely.destroy();
17
+ },
18
+ };
11
19
  }
@@ -332,32 +332,6 @@ export interface AccountingTransactionType {
332
332
  name: string;
333
333
  }
334
334
 
335
- export interface CoreAction {
336
- appId: string | null;
337
- automationId: string | null;
338
- connectionId: string | null;
339
- createdAt: Generated<Timestamp | null>;
340
- id: Generated<string>;
341
- inputJson: Json | null;
342
- isCurrent: boolean | null;
343
- jobId: string | null;
344
- jobIndex: number | null;
345
- jobPageId: string | null;
346
- jobPlanId: string | null;
347
- objectId: string | null;
348
- opId: string | null;
349
- outputJson: Json | null;
350
- refs: Json | null;
351
- schemaId: string | null;
352
- sourceId: string | null;
353
- status: string | null;
354
- tenantId: string | null;
355
- title: string | null;
356
- type: string | null;
357
- uniqueRef: string | null;
358
- updatedAt: Generated<Timestamp | null>;
359
- }
360
-
361
335
  export interface CoreActiveStatus {
362
336
  name: string;
363
337
  }
@@ -420,36 +394,6 @@ export interface CoreChangeType {
420
394
  name: string;
421
395
  }
422
396
 
423
- export interface CoreIssue {
424
- actionId: string | null;
425
- automationId: string | null;
426
- code: string | null;
427
- connectionId: string | null;
428
- createdAt: Generated<Timestamp | null>;
429
- extractId: string | null;
430
- extractPageId: string | null;
431
- id: Generated<string>;
432
- jobId: string | null;
433
- jobPageId: string | null;
434
- jobPlanId: string | null;
435
- kind: string | null;
436
- message: string | null;
437
- metadata: Generated<Json | null>;
438
- refId: Generated<string | null>;
439
- refType: string | null;
440
- refValue: string | null;
441
- status: string | null;
442
- subType: string | null;
443
- tenantId: string | null;
444
- type: string | null;
445
- uniqueRef: string | null;
446
- updatedAt: Generated<Timestamp | null>;
447
- }
448
-
449
- export interface CoreIssueKind {
450
- name: string;
451
- }
452
-
453
397
  export interface CoreIssueMessageOverwrite {
454
398
  createdAt: Generated<Timestamp | null>;
455
399
  id: Generated<string>;
@@ -458,107 +402,6 @@ export interface CoreIssueMessageOverwrite {
458
402
  updatedAt: Generated<Timestamp | null>;
459
403
  }
460
404
 
461
- export interface CoreIssueStatus {
462
- name: string;
463
- }
464
-
465
- export interface CoreIssueType {
466
- name: string;
467
- }
468
-
469
- export interface CoreJob {
470
- automationId: string | null;
471
- connectionId: string | null;
472
- createdAt: Generated<Timestamp | null>;
473
- id: Generated<string>;
474
- kind: string | null;
475
- metadata: Generated<Json | null>;
476
- params: Json | null;
477
- planId: string | null;
478
- rangeEnd: Timestamp | null;
479
- rangeStart: Timestamp | null;
480
- schemaId: string | null;
481
- status: Generated<string>;
482
- tenantId: string | null;
483
- title: string | null;
484
- type: string | null;
485
- updatedAt: Generated<Timestamp | null>;
486
- workflowId: string | null;
487
- }
488
-
489
- export interface CoreJobPage {
490
- createdAt: Generated<Timestamp | null>;
491
- cursor: string | null;
492
- id: Generated<string>;
493
- jobId: string | null;
494
- params: Json | null;
495
- status: Generated<string>;
496
- tenantId: string | null;
497
- title: string | null;
498
- updatedAt: Generated<Timestamp | null>;
499
- }
500
-
501
- export interface CoreJobPlan {
502
- automationId: string | null;
503
- connectionId: string | null;
504
- createdAt: Generated<Timestamp>;
505
- hypervisorRef: string | null;
506
- id: Generated<string>;
507
- isCurrentOnConnection: Generated<boolean | null>;
508
- params: Json | null;
509
- rangeEnd: Timestamp | null;
510
- rangeStart: Timestamp | null;
511
- status: Generated<string>;
512
- tenantId: string;
513
- title: string | null;
514
- triggeredByUserId: string | null;
515
- type: string | null;
516
- updatedAt: Generated<Timestamp>;
517
- workflowId: string | null;
518
- }
519
-
520
- export interface CoreSchema {
521
- appId: string | null;
522
- createdAt: Generated<Timestamp | null>;
523
- hasExternalLinks: boolean | null;
524
- id: Generated<string>;
525
- indexSchema: Json | null;
526
- jsonSchema: Json | null;
527
- kind: string | null;
528
- uniqueRef: string | null;
529
- updatedAt: Generated<Timestamp | null>;
530
- }
531
-
532
- export interface CoreSchemaKind {
533
- name: string;
534
- }
535
-
536
- export interface CoreSourceAction {
537
- actionId: string;
538
- createdAt: Generated<Timestamp>;
539
- id: Generated<string>;
540
- opId: string | null;
541
- sourceId: string;
542
- tenantId: string | null;
543
- updatedAt: Generated<Timestamp>;
544
- }
545
-
546
- export interface CoreSourceOp {
547
- actionId: string | null;
548
- createdAt: Generated<Timestamp | null>;
549
- fields: Generated<Json>;
550
- id: Generated<string>;
551
- jobId: string | null;
552
- jobPageId: string | null;
553
- jobPlanId: string | null;
554
- json: Json | null;
555
- kind: string;
556
- sourceId: string;
557
- tenantId: string;
558
- updatedAt: Generated<Timestamp | null>;
559
- version: Generated<number | null>;
560
- }
561
-
562
405
  export interface CoreSync {
563
406
  automationId: string | null;
564
407
  connectionId: string | null;
@@ -731,28 +574,6 @@ export interface PublicAccountCollectionType {
731
574
  name: string;
732
575
  }
733
576
 
734
- export interface PublicAction {
735
- automationId: string | null;
736
- automationTaskId: string | null;
737
- connectionId: string | null;
738
- createdAt: Generated<Timestamp>;
739
- id: Generated<string>;
740
- inputFileId: string | null;
741
- jobTaskId: string | null;
742
- outputFileId: string | null;
743
- processTaskId: string | null;
744
- status: string | null;
745
- taskId: string | null;
746
- tenantId: string | null;
747
- type: string | null;
748
- uniqueRef: string | null;
749
- updatedAt: Generated<Timestamp>;
750
- }
751
-
752
- export interface PublicActionStatus {
753
- name: string;
754
- }
755
-
756
577
  export interface PublicAddress {
757
578
  city: string | null;
758
579
  country: string | null;
@@ -904,23 +725,6 @@ export interface PublicConnectionStatusTemporary {
904
725
  name: string;
905
726
  }
906
727
 
907
- export interface PublicCsvLine {
908
- connectionId: string;
909
- createdAt: Generated<Timestamp | null>;
910
- csv: string;
911
- date: Timestamp;
912
- fileId: string | null;
913
- fileUniqueRef: string | null;
914
- headers: string | null;
915
- id: Generated<string>;
916
- index: number | null;
917
- json: Json | null;
918
- tenantId: string;
919
- type: string;
920
- uniqueRef: string;
921
- updatedAt: Generated<Timestamp | null>;
922
- }
923
-
924
728
  export interface PublicCurrency {
925
729
  name: string;
926
730
  }
@@ -1146,20 +950,6 @@ export interface PublicListingStatus {
1146
950
  name: string;
1147
951
  }
1148
952
 
1149
- export interface PublicMetric {
1150
- connectionId: string;
1151
- createdAt: Generated<Timestamp>;
1152
- date: Timestamp;
1153
- id: Generated<string>;
1154
- listingConnectionId: string | null;
1155
- metadata: Generated<Json>;
1156
- tenantId: string;
1157
- type: string;
1158
- uniqueRef: string | null;
1159
- updatedAt: Generated<Timestamp>;
1160
- value: number | null;
1161
- }
1162
-
1163
953
  export interface PublicOwner {
1164
954
  addressId: string | null;
1165
955
  companyType: string | null;
@@ -1194,9 +984,12 @@ export interface PublicOwnerStatement {
1194
984
  centAccountingBalanceStart: number | null;
1195
985
  centBalanceEnd: Int8 | null;
1196
986
  centBalanceStart: Int8 | null;
987
+ centExpenses: Int8 | null;
988
+ centNetRevenue: Int8 | null;
1197
989
  centPayedOut: number | null;
1198
990
  centRentalRevenue: number | null;
1199
991
  centTotal: Int8 | null;
992
+ centTransfer: Int8 | null;
1200
993
  createdAt: Generated<Timestamp>;
1201
994
  currency: string | null;
1202
995
  endAt: Timestamp;
@@ -1217,17 +1010,6 @@ export interface PublicOwnerStatement {
1217
1010
  updatedAt: Generated<Timestamp>;
1218
1011
  }
1219
1012
 
1220
- export interface PublicOwnerStatementIssue {
1221
- id: Generated<string>;
1222
- level: Generated<string>;
1223
- lineId: string | null;
1224
- message: string;
1225
- statementId: string | null;
1226
- tenantId: string;
1227
- type: string;
1228
- uniqueRef: string;
1229
- }
1230
-
1231
1013
  export interface PublicOwnerStatementLayout {
1232
1014
  automationId: string | null;
1233
1015
  connectionId: string | null;
@@ -1608,23 +1390,6 @@ export interface PublicReservationWithOccupancyStatus {
1608
1390
  userdata: Json | null;
1609
1391
  }
1610
1392
 
1611
- export interface PublicScheduledEvent {
1612
- createdAt: Generated<Timestamp>;
1613
- id: Generated<string>;
1614
- message: string | null;
1615
- objectId: string;
1616
- op: string;
1617
- scheduledAt: Timestamp | null;
1618
- status: Generated<string | null>;
1619
- tableName: string;
1620
- tenantId: string;
1621
- updatedAt: Generated<Timestamp>;
1622
- }
1623
-
1624
- export interface PublicScheduledEventStatus {
1625
- name: string;
1626
- }
1627
-
1628
1393
  export interface PublicSetting {
1629
1394
  automationId: string | null;
1630
1395
  connectionId: string | null;
@@ -1679,7 +1444,6 @@ export interface PublicSource {
1679
1444
  parentId: string | null;
1680
1445
  remoteId: string | null;
1681
1446
  reservationId: string | null;
1682
- schemaId: string | null;
1683
1447
  status: Generated<string | null>;
1684
1448
  tenantId: string;
1685
1449
  transformJson: Json | null;
@@ -2036,7 +1800,6 @@ export interface DB {
2036
1800
  "accounting.transaction": AccountingTransaction;
2037
1801
  "accounting.transactionLine": AccountingTransactionLine;
2038
1802
  "accounting.transactionType": AccountingTransactionType;
2039
- "core.action": CoreAction;
2040
1803
  "core.activeStatus": CoreActiveStatus;
2041
1804
  "core.change": CoreChange;
2042
1805
  "core.changeEntityType": CoreChangeEntityType;
@@ -2045,18 +1808,7 @@ export interface DB {
2045
1808
  "core.changeStatus": CoreChangeStatus;
2046
1809
  "core.changeSyncType": CoreChangeSyncType;
2047
1810
  "core.changeType": CoreChangeType;
2048
- "core.issue": CoreIssue;
2049
- "core.issueKind": CoreIssueKind;
2050
1811
  "core.issueMessageOverwrite": CoreIssueMessageOverwrite;
2051
- "core.issueStatus": CoreIssueStatus;
2052
- "core.issueType": CoreIssueType;
2053
- "core.job": CoreJob;
2054
- "core.jobPage": CoreJobPage;
2055
- "core.jobPlan": CoreJobPlan;
2056
- "core.schema": CoreSchema;
2057
- "core.schemaKind": CoreSchemaKind;
2058
- "core.sourceAction": CoreSourceAction;
2059
- "core.sourceOp": CoreSourceOp;
2060
1812
  "core.sync": CoreSync;
2061
1813
  "core.syncStatus": CoreSyncStatus;
2062
1814
  "core.syncSubtask": CoreSyncSubtask;
@@ -2075,8 +1827,6 @@ export interface DB {
2075
1827
  "hdbCatalog.hdbVersion": HdbCatalogHdbVersion;
2076
1828
  "public.accountCollection": PublicAccountCollection;
2077
1829
  "public.accountCollectionType": PublicAccountCollectionType;
2078
- "public.action": PublicAction;
2079
- "public.actionStatus": PublicActionStatus;
2080
1830
  "public.address": PublicAddress;
2081
1831
  "public.app": PublicApp;
2082
1832
  "public.auditLog": PublicAuditLog;
@@ -2087,7 +1837,6 @@ export interface DB {
2087
1837
  "public.bookingChannel": PublicBookingChannel;
2088
1838
  "public.connection": PublicConnection;
2089
1839
  "public.connectionStatusTemporary": PublicConnectionStatusTemporary;
2090
- "public.csvLine": PublicCsvLine;
2091
1840
  "public.currency": PublicCurrency;
2092
1841
  "public.duplicateEmails": PublicDuplicateEmails;
2093
1842
  "public.emailTemplate": PublicEmailTemplate;
@@ -2111,11 +1860,9 @@ export interface DB {
2111
1860
  "public.listingOwnershipPeriodMember": PublicListingOwnershipPeriodMember;
2112
1861
  "public.listingPmsStatus": PublicListingPmsStatus;
2113
1862
  "public.listingStatus": PublicListingStatus;
2114
- "public.metric": PublicMetric;
2115
1863
  "public.owner": PublicOwner;
2116
1864
  "public.ownerPmsStatus": PublicOwnerPmsStatus;
2117
1865
  "public.ownerStatement": PublicOwnerStatement;
2118
- "public.ownerStatementIssue": PublicOwnerStatementIssue;
2119
1866
  "public.ownerStatementLayout": PublicOwnerStatementLayout;
2120
1867
  "public.ownerStatementLayoutAccount": PublicOwnerStatementLayoutAccount;
2121
1868
  "public.ownerStatementLayoutListing": PublicOwnerStatementLayoutListing;
@@ -2143,8 +1890,6 @@ export interface DB {
2143
1890
  "public.reservation": PublicReservation;
2144
1891
  "public.reservationStatus": PublicReservationStatus;
2145
1892
  "public.reservationWithOccupancyStatus": PublicReservationWithOccupancyStatus;
2146
- "public.scheduledEvent": PublicScheduledEvent;
2147
- "public.scheduledEventStatus": PublicScheduledEventStatus;
2148
1893
  "public.setting": PublicSetting;
2149
1894
  "public.source": PublicSource;
2150
1895
  "public.task": PublicTask;