sasat 0.22.7 → 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.
- package/dist/cli/index.cjs +24 -3
- package/dist/cli/index.mjs +25 -4
- package/dist/comparison-Bkk-qNRi.d.cts +79 -0
- package/dist/comparison-HpKmxsjs.d.mts +79 -0
- package/dist/index-1a8KLRT7.d.mts +495 -0
- package/dist/index-lrk3IfPF.d.cts +495 -0
- package/dist/index.cjs +22 -825
- package/dist/index.d.cts +3 -495
- package/dist/index.d.mts +3 -495
- package/dist/index.mjs +2 -804
- package/dist/{migrate-DnqBdQ6r.mjs → migrate-D-XR7Z0F.mjs} +93 -71
- package/dist/{migrate-BDE07ocG.cjs → migrate-iJE4FjRh.cjs} +96 -68
- package/dist/migration/index.cjs +1 -1
- package/dist/migration/index.d.cts +2 -2
- package/dist/migration/index.d.mts +2 -2
- package/dist/migration/index.mjs +1 -1
- package/dist/src-CdwAbJV0.cjs +926 -0
- package/dist/src-DebKrtYl.mjs +806 -0
- package/dist/testing/index.cjs +70 -1
- package/dist/testing/index.d.cts +19 -2
- package/dist/testing/index.d.mts +19 -2
- package/dist/testing/index.mjs +69 -2
- package/package.json +1 -1
- package/dist/comparison-BpTtc1iD.d.mts +0 -42
- package/dist/comparison-CIb9xu5T.d.cts +0 -42
- package/dist/dbClient-2mFJTQw7.d.mts +0 -35
- package/dist/dbClient-Bnk1JKBU.d.cts +0 -35
- /package/dist/{makeCondition-3MdYUm5k.mjs → makeCondition-BQj-Av95.mjs} +0 -0
- /package/dist/{makeCondition-DKSyAkri.cjs → makeCondition-DljWZv_v.cjs} +0 -0
package/dist/cli/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const require_util = require("../util-C5Jevn5B.cjs");
|
|
3
|
-
const require_migrate = require("../migrate-
|
|
3
|
+
const require_migrate = require("../migrate-iJE4FjRh.cjs");
|
|
4
4
|
let node_fs = require("node:fs");
|
|
5
5
|
node_fs = require_util.__toESM(node_fs, 1);
|
|
6
6
|
let node_path = require("node:path");
|
|
7
7
|
node_path = require_util.__toESM(node_path, 1);
|
|
8
8
|
let cac = require("cac");
|
|
9
9
|
//#region src/cli/commands/createMigration.ts
|
|
10
|
-
const getMigrationFile = (className) => `import {
|
|
10
|
+
const getMigrationFile = (className) => `import type { MigrationStore, SasatMigration } from "sasat/migration";
|
|
11
11
|
|
|
12
12
|
export default class ${require_migrate.capitalizeFirstLetter(className)} implements SasatMigration {
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ export default class ${require_migrate.capitalizeFirstLetter(className)} impleme
|
|
|
15
15
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
down: (store: MigrationStore) => void =
|
|
18
|
+
down: (store: MigrationStore) => void = () => {
|
|
19
19
|
throw new Error('Down is not implemented on ${className}');
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -545,6 +545,20 @@ ${rel.join("\n")}
|
|
|
545
545
|
`;
|
|
546
546
|
}
|
|
547
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
|
|
548
562
|
//#region src/cli/commands/generate.ts
|
|
549
563
|
const generate = async () => {
|
|
550
564
|
try {
|
|
@@ -555,6 +569,7 @@ const generate = async () => {
|
|
|
555
569
|
const storeHandler = new require_migrate.DataStoreHandler(store);
|
|
556
570
|
require_util.writeCurrentSchema(store);
|
|
557
571
|
await new require_migrate.CodeGen_v2(storeHandler).generate();
|
|
572
|
+
await generateTestMigFileCommand({ silent: true });
|
|
558
573
|
require_migrate.Console.success(`code generated. DIR: ${require_util.config().migration.out}\nmigration target: ${targetFile}`);
|
|
559
574
|
} catch (e) {
|
|
560
575
|
require_migrate.Console.error(e.message);
|
|
@@ -583,11 +598,14 @@ const migrationBuild = async () => {
|
|
|
583
598
|
const index = (0, cac.cac)();
|
|
584
599
|
try {
|
|
585
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) => {
|
|
601
|
+
const conf = require_util.config();
|
|
602
|
+
if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
|
|
586
603
|
const client = require_util.getDbClient();
|
|
587
604
|
await require_migrate.migrate(client, options).catch((e) => {
|
|
588
605
|
console.error(e);
|
|
589
606
|
process.exit(1);
|
|
590
607
|
});
|
|
608
|
+
if (options.generateFiles) await require_migrate.generateTestMigrationFile(client);
|
|
591
609
|
await client.release();
|
|
592
610
|
});
|
|
593
611
|
index.command("migration:build", "compile migration files").action(migrationBuild);
|
|
@@ -596,6 +614,9 @@ try {
|
|
|
596
614
|
index.command("migration:create [name]", "generate new migration file").action(createMigration);
|
|
597
615
|
index.command("dump-db", "dump database schema").action(dumpDB);
|
|
598
616
|
index.command("init").action(init);
|
|
617
|
+
index.command("generate:test", "generate migration file for testing").action(async () => {
|
|
618
|
+
await generateTestMigFileCommand({ silent: false });
|
|
619
|
+
});
|
|
599
620
|
index.parse();
|
|
600
621
|
if (!index.matchedCommand) index.outputHelp();
|
|
601
622
|
} catch (e) {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as writeYmlFile, a as getDbClient, d as defaultConf, h as writeCurrentSchema, l as SqlString, p as mkDirIfNotExist, u as config } from "../util-Dkw5bD7a.mjs";
|
|
3
|
-
import { a as
|
|
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";
|
|
4
4
|
import * as fs$1 from "node:fs";
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path, { join } from "node:path";
|
|
7
7
|
import { cac } from "cac";
|
|
8
8
|
//#region src/cli/commands/createMigration.ts
|
|
9
|
-
const getMigrationFile = (className) => `import {
|
|
9
|
+
const getMigrationFile = (className) => `import type { MigrationStore, SasatMigration } from "sasat/migration";
|
|
10
10
|
|
|
11
11
|
export default class ${capitalizeFirstLetter(className)} implements SasatMigration {
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export default class ${capitalizeFirstLetter(className)} implements SasatMigrati
|
|
|
14
14
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
down: (store: MigrationStore) => void =
|
|
17
|
+
down: (store: MigrationStore) => void = () => {
|
|
18
18
|
throw new Error('Down is not implemented on ${className}');
|
|
19
19
|
};
|
|
20
20
|
}
|
|
@@ -544,6 +544,20 @@ ${rel.join("\n")}
|
|
|
544
544
|
`;
|
|
545
545
|
}
|
|
546
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
|
|
547
561
|
//#region src/cli/commands/generate.ts
|
|
548
562
|
const generate = async () => {
|
|
549
563
|
try {
|
|
@@ -554,6 +568,7 @@ const generate = async () => {
|
|
|
554
568
|
const storeHandler = new DataStoreHandler(store);
|
|
555
569
|
writeCurrentSchema(store);
|
|
556
570
|
await new CodeGen_v2(storeHandler).generate();
|
|
571
|
+
await generateTestMigFileCommand({ silent: true });
|
|
557
572
|
Console.success(`code generated. DIR: ${config().migration.out}\nmigration target: ${targetFile}`);
|
|
558
573
|
} catch (e) {
|
|
559
574
|
Console.error(e.message);
|
|
@@ -582,11 +597,14 @@ const migrationBuild = async () => {
|
|
|
582
597
|
const index = cac();
|
|
583
598
|
try {
|
|
584
599
|
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) => {
|
|
600
|
+
const conf = config();
|
|
601
|
+
if (conf.migration.db) setConfig({ db: conf.migration.db });
|
|
585
602
|
const client = getDbClient();
|
|
586
603
|
await migrate(client, options).catch((e) => {
|
|
587
604
|
console.error(e);
|
|
588
605
|
process.exit(1);
|
|
589
606
|
});
|
|
607
|
+
if (options.generateFiles) await generateTestMigrationFile(client);
|
|
590
608
|
await client.release();
|
|
591
609
|
});
|
|
592
610
|
index.command("migration:build", "compile migration files").action(migrationBuild);
|
|
@@ -595,6 +613,9 @@ try {
|
|
|
595
613
|
index.command("migration:create [name]", "generate new migration file").action(createMigration);
|
|
596
614
|
index.command("dump-db", "dump database schema").action(dumpDB);
|
|
597
615
|
index.command("init").action(init);
|
|
616
|
+
index.command("generate:test", "generate migration file for testing").action(async () => {
|
|
617
|
+
await generateTestMigFileCommand({ silent: false });
|
|
618
|
+
});
|
|
598
619
|
index.parse();
|
|
599
620
|
if (!index.matchedCommand) index.outputHelp();
|
|
600
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 };
|