sasat 0.22.8 → 0.22.9

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.
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- const require_util = require("../util-IRlTD1y7.cjs");
3
- const require_getDbClient = require("../getDbClient-Dnkk-peb.cjs");
4
- const require_migrate = require("../migrate-COeYPag2.cjs");
2
+ const require_util = require("../util-C5Jevn5B.cjs");
3
+ const require_migrate = require("../migrate-iJE4FjRh.cjs");
5
4
  let node_fs = require("node:fs");
6
5
  node_fs = require_util.__toESM(node_fs, 1);
7
6
  let node_path = require("node:path");
@@ -473,7 +472,7 @@ const serializeCreateTable = (str) => {
473
472
  //#endregion
474
473
  //#region src/cli/commands/dumpDb.ts
475
474
  const dumpDB = async () => {
476
- const con = require_getDbClient.getDbClient();
475
+ const con = require_util.getDbClient();
477
476
  try {
478
477
  const tables = await con.rawQuery("show tables").then((it) => it.flatMap((it) => Object.values(it)));
479
478
  const serialized = await Promise.all(tables.map((table) => {
@@ -546,6 +545,20 @@ ${rel.join("\n")}
546
545
  `;
547
546
  }
548
547
  //#endregion
548
+ //#region src/cli/commands/generateTestMigFileCommand.ts
549
+ async function generateTestMigFileCommand({ silent }) {
550
+ const conf = require_util.config();
551
+ if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
552
+ const client = require_util.getDbClient();
553
+ await require_migrate.generateTestMigrationFile(client).catch(async (e) => {
554
+ await client.release();
555
+ require_migrate.Console.error(e);
556
+ process.exit(1);
557
+ });
558
+ await client.release();
559
+ if (!silent) require_migrate.Console.success("successfully generated");
560
+ }
561
+ //#endregion
549
562
  //#region src/cli/commands/generate.ts
550
563
  const generate = async () => {
551
564
  try {
@@ -556,6 +569,7 @@ const generate = async () => {
556
569
  const storeHandler = new require_migrate.DataStoreHandler(store);
557
570
  require_util.writeCurrentSchema(store);
558
571
  await new require_migrate.CodeGen_v2(storeHandler).generate();
572
+ await generateTestMigFileCommand({ silent: true });
559
573
  require_migrate.Console.success(`code generated. DIR: ${require_util.config().migration.out}\nmigration target: ${targetFile}`);
560
574
  } catch (e) {
561
575
  require_migrate.Console.error(e.message);
@@ -586,11 +600,12 @@ try {
586
600
  index.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").option("-b, --skipBuild", "skip compile migration files").action(async (options) => {
587
601
  const conf = require_util.config();
588
602
  if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
589
- const client = require_getDbClient.getDbClient();
603
+ const client = require_util.getDbClient();
590
604
  await require_migrate.migrate(client, options).catch((e) => {
591
605
  console.error(e);
592
606
  process.exit(1);
593
607
  });
608
+ if (options.generateFiles) await require_migrate.generateTestMigrationFile(client);
594
609
  await client.release();
595
610
  });
596
611
  index.command("migration:build", "compile migration files").action(migrationBuild);
@@ -599,6 +614,9 @@ try {
599
614
  index.command("migration:create [name]", "generate new migration file").action(createMigration);
600
615
  index.command("dump-db", "dump database schema").action(dumpDB);
601
616
  index.command("init").action(init);
617
+ index.command("generate:test", "generate migration file for testing").action(async () => {
618
+ await generateTestMigFileCommand({ silent: false });
619
+ });
602
620
  index.parse();
603
621
  if (!index.matchedCommand) index.outputHelp();
604
622
  } catch (e) {
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { a as SqlString, c as setConfig, d as writeCurrentSchema, l as mkDirIfNotExist, o as config, p as writeYmlFile, s as defaultConf } from "../util-BcMcffJ8.mjs";
3
- import { t as getDbClient } from "../getDbClient-CNcumqpO.mjs";
4
- import { a as getMigrationFileNames, c as defaultColumnOption, d as DBColumnTypes, f as Console, i as compileMigrationFiles, l as defaultGQLOption, m as capitalizeFirstLetter, n as CodeGen_v2, o as DataStoreHandler, p as camelize, r as createCurrentMigrationDataStore, s as Directory, t as migrate, u as columnTypeToGqlPrimitive } from "../migrate-mh3DLqgw.mjs";
2
+ import { _ as writeYmlFile, a as getDbClient, d as defaultConf, f as setConfig, h as writeCurrentSchema, l as SqlString, p as mkDirIfNotExist, u as config } from "../util-Dkw5bD7a.mjs";
3
+ import { a as compileMigrationFiles, c as Directory, d as columnTypeToGqlPrimitive, f as DBColumnTypes, h as capitalizeFirstLetter, i as createCurrentMigrationDataStore, l as defaultColumnOption, m as camelize, n as CodeGen_v2, o as getMigrationFileNames, p as Console, r as generateTestMigrationFile, s as DataStoreHandler, t as migrate, u as defaultGQLOption } from "../migrate-D-XR7Z0F.mjs";
5
4
  import * as fs$1 from "node:fs";
6
5
  import fs from "node:fs";
7
6
  import path, { join } from "node:path";
@@ -545,6 +544,20 @@ ${rel.join("\n")}
545
544
  `;
546
545
  }
547
546
  //#endregion
547
+ //#region src/cli/commands/generateTestMigFileCommand.ts
548
+ async function generateTestMigFileCommand({ silent }) {
549
+ const conf = config();
550
+ if (conf.migration.db) setConfig({ db: conf.migration.db });
551
+ const client = getDbClient();
552
+ await generateTestMigrationFile(client).catch(async (e) => {
553
+ await client.release();
554
+ Console.error(e);
555
+ process.exit(1);
556
+ });
557
+ await client.release();
558
+ if (!silent) Console.success("successfully generated");
559
+ }
560
+ //#endregion
548
561
  //#region src/cli/commands/generate.ts
549
562
  const generate = async () => {
550
563
  try {
@@ -555,6 +568,7 @@ const generate = async () => {
555
568
  const storeHandler = new DataStoreHandler(store);
556
569
  writeCurrentSchema(store);
557
570
  await new CodeGen_v2(storeHandler).generate();
571
+ await generateTestMigFileCommand({ silent: true });
558
572
  Console.success(`code generated. DIR: ${config().migration.out}\nmigration target: ${targetFile}`);
559
573
  } catch (e) {
560
574
  Console.error(e.message);
@@ -590,6 +604,7 @@ try {
590
604
  console.error(e);
591
605
  process.exit(1);
592
606
  });
607
+ if (options.generateFiles) await generateTestMigrationFile(client);
593
608
  await client.release();
594
609
  });
595
610
  index.command("migration:build", "compile migration files").action(migrationBuild);
@@ -598,6 +613,9 @@ try {
598
613
  index.command("migration:create [name]", "generate new migration file").action(createMigration);
599
614
  index.command("dump-db", "dump database schema").action(dumpDB);
600
615
  index.command("init").action(init);
616
+ index.command("generate:test", "generate migration file for testing").action(async () => {
617
+ await generateTestMigFileCommand({ silent: false });
618
+ });
601
619
  index.parse();
602
620
  if (!index.matchedCommand) index.outputHelp();
603
621
  } catch (e) {
@@ -0,0 +1,79 @@
1
+ //#region src/util/type.d.ts
2
+ type NestedPartial<T> = { [K in keyof T]?: T[K] extends Array<infer R> ? Array<NestedPartial<R>> : NestedPartial<T[K]> };
3
+ //#endregion
4
+ //#region src/config/config.d.ts
5
+ type SasatDBConfigBase = {
6
+ host: string;
7
+ port: number;
8
+ user: string;
9
+ password?: string;
10
+ database: string;
11
+ ssl?: {
12
+ ca?: string[];
13
+ };
14
+ };
15
+ type SasatConfigDB = SasatDBConfigBase & {
16
+ testing?: SasatDBConfigBase;
17
+ };
18
+ interface SasatConfigMigration {
19
+ table: string;
20
+ dir: string;
21
+ out: string;
22
+ target?: string;
23
+ db?: SasatConfigDB;
24
+ }
25
+ interface SasatConfigGenerator {
26
+ addJsExtToImportStatement: boolean;
27
+ gql: {
28
+ subscription: boolean;
29
+ };
30
+ }
31
+ interface SasatConfig {
32
+ db: SasatConfigDB;
33
+ migration: SasatConfigMigration;
34
+ generator: SasatConfigGenerator;
35
+ }
36
+ declare function setConfig(update: NestedPartial<SasatConfig>): SasatConfig;
37
+ //#endregion
38
+ //#region src/db/connectors/dbClient.d.ts
39
+ type QueryResponse = Array<{
40
+ [key: string]: SqlValueType;
41
+ }>;
42
+ interface CommandResponse {
43
+ insertId: number;
44
+ affectedRows: number;
45
+ changedRows: number;
46
+ }
47
+ type SqlValueType = string | number | boolean | null;
48
+ interface SQLExecutor {
49
+ rawQuery(sql: string): Promise<QueryResponse>;
50
+ rawCommand(sql: string): Promise<CommandResponse>;
51
+ }
52
+ declare abstract class SQLClient implements SQLExecutor {
53
+ protected logger: (query: string) => void;
54
+ rawQuery(sql: string): Promise<QueryResponse>;
55
+ rawCommand(sql: string): Promise<CommandResponse>;
56
+ query(templateString: TemplateStringsArray, ...params: any[]): Promise<QueryResponse>;
57
+ command(templateString: TemplateStringsArray, ...params: any[]): Promise<CommandResponse>;
58
+ protected abstract execSql(sql: string): Promise<QueryResponse | CommandResponse>;
59
+ }
60
+ declare abstract class SQLTransaction extends SQLClient {
61
+ abstract commit(): Promise<void>;
62
+ abstract rollback(): Promise<void>;
63
+ }
64
+ declare abstract class DBClient extends SQLClient {
65
+ protected _released: boolean;
66
+ protected constructor(logger?: (query: string) => void);
67
+ isReleased(): boolean;
68
+ abstract transaction(): Promise<SQLTransaction>;
69
+ abstract release(): Promise<void>;
70
+ }
71
+ //#endregion
72
+ //#region src/db/sql/expression/comparison.d.ts
73
+ type ComparisonOperators = "=" | ">" | "<" | ">=" | "<=" | "<>";
74
+ type AndOr = "AND" | "OR";
75
+ type ComparisonExpression<T> = Partial<{ [P in keyof T]: T[P] | [ComparisonOperators | "LIKE" | "NOT LIKE", T[P]] | ["BETWEEN", T[P], T[P]] | ["IN", ...T[P][]] | ["IS NULL"] | ["IS NOT NULL"] }> & {
76
+ __type?: AndOr;
77
+ };
78
+ //#endregion
79
+ export { QueryResponse as a, SQLTransaction as c, SasatDBConfigBase as d, setConfig as f, DBClient as i, SqlValueType as l, ComparisonOperators as n, SQLClient as o, NestedPartial as p, CommandResponse as r, SQLExecutor as s, ComparisonExpression as t, SasatConfig as u };
@@ -0,0 +1,79 @@
1
+ //#region src/util/type.d.ts
2
+ type NestedPartial<T> = { [K in keyof T]?: T[K] extends Array<infer R> ? Array<NestedPartial<R>> : NestedPartial<T[K]> };
3
+ //#endregion
4
+ //#region src/config/config.d.ts
5
+ type SasatDBConfigBase = {
6
+ host: string;
7
+ port: number;
8
+ user: string;
9
+ password?: string;
10
+ database: string;
11
+ ssl?: {
12
+ ca?: string[];
13
+ };
14
+ };
15
+ type SasatConfigDB = SasatDBConfigBase & {
16
+ testing?: SasatDBConfigBase;
17
+ };
18
+ interface SasatConfigMigration {
19
+ table: string;
20
+ dir: string;
21
+ out: string;
22
+ target?: string;
23
+ db?: SasatConfigDB;
24
+ }
25
+ interface SasatConfigGenerator {
26
+ addJsExtToImportStatement: boolean;
27
+ gql: {
28
+ subscription: boolean;
29
+ };
30
+ }
31
+ interface SasatConfig {
32
+ db: SasatConfigDB;
33
+ migration: SasatConfigMigration;
34
+ generator: SasatConfigGenerator;
35
+ }
36
+ declare function setConfig(update: NestedPartial<SasatConfig>): SasatConfig;
37
+ //#endregion
38
+ //#region src/db/connectors/dbClient.d.ts
39
+ type QueryResponse = Array<{
40
+ [key: string]: SqlValueType;
41
+ }>;
42
+ interface CommandResponse {
43
+ insertId: number;
44
+ affectedRows: number;
45
+ changedRows: number;
46
+ }
47
+ type SqlValueType = string | number | boolean | null;
48
+ interface SQLExecutor {
49
+ rawQuery(sql: string): Promise<QueryResponse>;
50
+ rawCommand(sql: string): Promise<CommandResponse>;
51
+ }
52
+ declare abstract class SQLClient implements SQLExecutor {
53
+ protected logger: (query: string) => void;
54
+ rawQuery(sql: string): Promise<QueryResponse>;
55
+ rawCommand(sql: string): Promise<CommandResponse>;
56
+ query(templateString: TemplateStringsArray, ...params: any[]): Promise<QueryResponse>;
57
+ command(templateString: TemplateStringsArray, ...params: any[]): Promise<CommandResponse>;
58
+ protected abstract execSql(sql: string): Promise<QueryResponse | CommandResponse>;
59
+ }
60
+ declare abstract class SQLTransaction extends SQLClient {
61
+ abstract commit(): Promise<void>;
62
+ abstract rollback(): Promise<void>;
63
+ }
64
+ declare abstract class DBClient extends SQLClient {
65
+ protected _released: boolean;
66
+ protected constructor(logger?: (query: string) => void);
67
+ isReleased(): boolean;
68
+ abstract transaction(): Promise<SQLTransaction>;
69
+ abstract release(): Promise<void>;
70
+ }
71
+ //#endregion
72
+ //#region src/db/sql/expression/comparison.d.ts
73
+ type ComparisonOperators = "=" | ">" | "<" | ">=" | "<=" | "<>";
74
+ type AndOr = "AND" | "OR";
75
+ type ComparisonExpression<T> = Partial<{ [P in keyof T]: T[P] | [ComparisonOperators | "LIKE" | "NOT LIKE", T[P]] | ["BETWEEN", T[P], T[P]] | ["IN", ...T[P][]] | ["IS NULL"] | ["IS NOT NULL"] }> & {
76
+ __type?: AndOr;
77
+ };
78
+ //#endregion
79
+ export { QueryResponse as a, SQLTransaction as c, SasatDBConfigBase as d, setConfig as f, DBClient as i, SqlValueType as l, ComparisonOperators as n, SQLClient as o, NestedPartial as p, CommandResponse as r, SQLExecutor as s, ComparisonExpression as t, SasatConfig as u };