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.
@@ -1,3 +1,72 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_migrate = require("../migrate-BDE07ocG.cjs");
2
+ const require_util = require("../util-C5Jevn5B.cjs");
3
+ const require_src = require("../src-CdwAbJV0.cjs");
4
+ const require_migrate = require("../migrate-iJE4FjRh.cjs");
5
+ let node_fs = require("node:fs");
6
+ let node_path = require("node:path");
7
+ node_path = require_util.__toESM(node_path, 1);
8
+ let node_crypto = require("node:crypto");
9
+ //#region src/testing/readTestMigration.ts
10
+ async function readTestMigration() {
11
+ let d = readTestMigFile();
12
+ if (!d) {
13
+ const conf = require_util.config();
14
+ if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
15
+ const client = new require_src.MysqlClient({ ...require_util.config().migration.db ?? require_util.config().db });
16
+ await require_migrate.generateTestMigrationFile(client).catch(async (e) => {
17
+ await client.release();
18
+ require_migrate.Console.error(e);
19
+ process.exit(1);
20
+ });
21
+ await client.release();
22
+ d = readTestMigFile();
23
+ }
24
+ return JSON.parse(d.toString());
25
+ }
26
+ function readTestMigFile() {
27
+ return (0, node_fs.readFileSync)(node_path.default.join(require_util.config().migration.dir, "test.migration.json"));
28
+ }
29
+ //#endregion
30
+ //#region src/testing/testDBClient.ts
31
+ var TestDBClient = class extends require_src.MysqlClient {
32
+ static async create(data, logger) {
33
+ const c = new require_src.MysqlClient({
34
+ host: data.host,
35
+ port: data.port,
36
+ user: data.user
37
+ });
38
+ await c.rawQuery(`CREATE DATABASE ${data.database}`);
39
+ await c.release();
40
+ return new this({
41
+ ...data,
42
+ multipleStatements: true
43
+ }, logger);
44
+ }
45
+ constructor(connectionOption, logger) {
46
+ super(connectionOption, logger);
47
+ }
48
+ async release() {
49
+ await this.execSql(`DROP DATABASE ${this.connectionOption.database}`);
50
+ await super.release();
51
+ }
52
+ };
53
+ //#endregion
54
+ //#region src/testing/makeTestDB.ts
55
+ const S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
56
+ const N = 8;
57
+ async function makeTestDB(conf) {
58
+ const c = conf ?? require_util.config().db.testing ?? require_util.config().db;
59
+ const client = await TestDBClient.create({
60
+ host: c.host,
61
+ port: +c.port,
62
+ user: c.user,
63
+ password: c.password,
64
+ database: "sasat_test_" + Array.from((0, node_crypto.randomFillSync)(new Uint8Array(N))).map((n) => S[n % 62]).join("")
65
+ });
66
+ const migration = await readTestMigration();
67
+ await client.rawQuery(migration.join(";"));
68
+ return client;
69
+ }
70
+ //#endregion
71
+ exports.makeTestDB = makeTestDB;
3
72
  exports.migrate = require_migrate.migrate;
@@ -1,4 +1,5 @@
1
- import { n as DBClient } from "../dbClient-Bnk1JKBU.cjs";
1
+ import { d as SasatDBConfigBase, i as DBClient } from "../comparison-Bkk-qNRi.cjs";
2
+ import { z as MysqlClient } from "../index-lrk3IfPF.cjs";
2
3
 
3
4
  //#region src/cli/commands/migrate.d.ts
4
5
  type MigrateCommandOption = {
@@ -9,4 +10,20 @@ type MigrateCommandOption = {
9
10
  };
10
11
  declare const migrate: (client: DBClient, options: MigrateCommandOption) => Promise<void>;
11
12
  //#endregion
12
- export { migrate };
13
+ //#region src/testing/testDBClient.d.ts
14
+ declare class TestDBClient extends MysqlClient {
15
+ static create(data: {
16
+ host: string;
17
+ port: number;
18
+ user: string;
19
+ password?: string;
20
+ database: string;
21
+ }, logger?: (query: string) => void): Promise<TestDBClient>;
22
+ private constructor();
23
+ release(): Promise<void>;
24
+ }
25
+ //#endregion
26
+ //#region src/testing/makeTestDB.d.ts
27
+ declare function makeTestDB(conf?: SasatDBConfigBase): Promise<TestDBClient>;
28
+ //#endregion
29
+ export { makeTestDB, migrate };
@@ -1,4 +1,5 @@
1
- import { n as DBClient } from "../dbClient-2mFJTQw7.mjs";
1
+ import { d as SasatDBConfigBase, i as DBClient } from "../comparison-HpKmxsjs.mjs";
2
+ import { z as MysqlClient } from "../index-1a8KLRT7.mjs";
2
3
 
3
4
  //#region src/cli/commands/migrate.d.ts
4
5
  type MigrateCommandOption = {
@@ -9,4 +10,20 @@ type MigrateCommandOption = {
9
10
  };
10
11
  declare const migrate: (client: DBClient, options: MigrateCommandOption) => Promise<void>;
11
12
  //#endregion
12
- export { migrate };
13
+ //#region src/testing/testDBClient.d.ts
14
+ declare class TestDBClient extends MysqlClient {
15
+ static create(data: {
16
+ host: string;
17
+ port: number;
18
+ user: string;
19
+ password?: string;
20
+ database: string;
21
+ }, logger?: (query: string) => void): Promise<TestDBClient>;
22
+ private constructor();
23
+ release(): Promise<void>;
24
+ }
25
+ //#endregion
26
+ //#region src/testing/makeTestDB.d.ts
27
+ declare function makeTestDB(conf?: SasatDBConfigBase): Promise<TestDBClient>;
28
+ //#endregion
29
+ export { makeTestDB, migrate };
@@ -1,2 +1,69 @@
1
- import { t as migrate } from "../migrate-DnqBdQ6r.mjs";
2
- export { migrate };
1
+ import { f as setConfig, u as config } from "../util-Dkw5bD7a.mjs";
2
+ import { b as MysqlClient } from "../src-DebKrtYl.mjs";
3
+ import { p as Console, r as generateTestMigrationFile, t as migrate } from "../migrate-D-XR7Z0F.mjs";
4
+ import { readFileSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { randomFillSync } from "node:crypto";
7
+ //#region src/testing/readTestMigration.ts
8
+ async function readTestMigration() {
9
+ let d = readTestMigFile();
10
+ if (!d) {
11
+ const conf = config();
12
+ if (conf.migration.db) setConfig({ db: conf.migration.db });
13
+ const client = new MysqlClient({ ...config().migration.db ?? config().db });
14
+ await generateTestMigrationFile(client).catch(async (e) => {
15
+ await client.release();
16
+ Console.error(e);
17
+ process.exit(1);
18
+ });
19
+ await client.release();
20
+ d = readTestMigFile();
21
+ }
22
+ return JSON.parse(d.toString());
23
+ }
24
+ function readTestMigFile() {
25
+ return readFileSync(path.join(config().migration.dir, "test.migration.json"));
26
+ }
27
+ //#endregion
28
+ //#region src/testing/testDBClient.ts
29
+ var TestDBClient = class extends MysqlClient {
30
+ static async create(data, logger) {
31
+ const c = new MysqlClient({
32
+ host: data.host,
33
+ port: data.port,
34
+ user: data.user
35
+ });
36
+ await c.rawQuery(`CREATE DATABASE ${data.database}`);
37
+ await c.release();
38
+ return new this({
39
+ ...data,
40
+ multipleStatements: true
41
+ }, logger);
42
+ }
43
+ constructor(connectionOption, logger) {
44
+ super(connectionOption, logger);
45
+ }
46
+ async release() {
47
+ await this.execSql(`DROP DATABASE ${this.connectionOption.database}`);
48
+ await super.release();
49
+ }
50
+ };
51
+ //#endregion
52
+ //#region src/testing/makeTestDB.ts
53
+ const S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
54
+ const N = 8;
55
+ async function makeTestDB(conf) {
56
+ const c = conf ?? config().db.testing ?? config().db;
57
+ const client = await TestDBClient.create({
58
+ host: c.host,
59
+ port: +c.port,
60
+ user: c.user,
61
+ password: c.password,
62
+ database: "sasat_test_" + Array.from(randomFillSync(new Uint8Array(N))).map((n) => S[n % 62]).join("")
63
+ });
64
+ const migration = await readTestMigration();
65
+ await client.rawQuery(migration.join(";"));
66
+ return client;
67
+ }
68
+ //#endregion
69
+ export { makeTestDB, migrate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.22.7",
3
+ "version": "0.22.9",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",
@@ -1,42 +0,0 @@
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
- interface SasatConfigDb {
6
- host: string;
7
- port: number;
8
- user: string;
9
- password?: string;
10
- database: string;
11
- ssl?: {
12
- ca?: string[];
13
- };
14
- }
15
- interface SasatConfigMigration {
16
- table: string;
17
- dir: string;
18
- out: string;
19
- target?: string;
20
- db?: SasatConfigDb;
21
- }
22
- interface SasatConfigGenerator {
23
- addJsExtToImportStatement: boolean;
24
- gql: {
25
- subscription: boolean;
26
- };
27
- }
28
- interface SasatConfig {
29
- db: SasatConfigDb;
30
- migration: SasatConfigMigration;
31
- generator: SasatConfigGenerator;
32
- }
33
- declare function setConfig(update: NestedPartial<SasatConfig>): SasatConfig;
34
- //#endregion
35
- //#region src/db/sql/expression/comparison.d.ts
36
- type ComparisonOperators = "=" | ">" | "<" | ">=" | "<=" | "<>";
37
- type AndOr = "AND" | "OR";
38
- 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"] }> & {
39
- __type?: AndOr;
40
- };
41
- //#endregion
42
- export { NestedPartial as a, setConfig as i, ComparisonOperators as n, SasatConfig as r, ComparisonExpression as t };
@@ -1,42 +0,0 @@
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
- interface SasatConfigDb {
6
- host: string;
7
- port: number;
8
- user: string;
9
- password?: string;
10
- database: string;
11
- ssl?: {
12
- ca?: string[];
13
- };
14
- }
15
- interface SasatConfigMigration {
16
- table: string;
17
- dir: string;
18
- out: string;
19
- target?: string;
20
- db?: SasatConfigDb;
21
- }
22
- interface SasatConfigGenerator {
23
- addJsExtToImportStatement: boolean;
24
- gql: {
25
- subscription: boolean;
26
- };
27
- }
28
- interface SasatConfig {
29
- db: SasatConfigDb;
30
- migration: SasatConfigMigration;
31
- generator: SasatConfigGenerator;
32
- }
33
- declare function setConfig(update: NestedPartial<SasatConfig>): SasatConfig;
34
- //#endregion
35
- //#region src/db/sql/expression/comparison.d.ts
36
- type ComparisonOperators = "=" | ">" | "<" | ">=" | "<=" | "<>";
37
- type AndOr = "AND" | "OR";
38
- 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"] }> & {
39
- __type?: AndOr;
40
- };
41
- //#endregion
42
- export { NestedPartial as a, setConfig as i, ComparisonOperators as n, SasatConfig as r, ComparisonExpression as t };
@@ -1,35 +0,0 @@
1
- //#region src/db/connectors/dbClient.d.ts
2
- type QueryResponse = Array<{
3
- [key: string]: SqlValueType;
4
- }>;
5
- interface CommandResponse {
6
- insertId: number;
7
- affectedRows: number;
8
- changedRows: number;
9
- }
10
- type SqlValueType = string | number | boolean | null;
11
- interface SQLExecutor {
12
- rawQuery(sql: string): Promise<QueryResponse>;
13
- rawCommand(sql: string): Promise<CommandResponse>;
14
- }
15
- declare abstract class SQLClient implements SQLExecutor {
16
- protected logger: (query: string) => void;
17
- rawQuery(sql: string): Promise<QueryResponse>;
18
- rawCommand(sql: string): Promise<CommandResponse>;
19
- query(templateString: TemplateStringsArray, ...params: any[]): Promise<QueryResponse>;
20
- command(templateString: TemplateStringsArray, ...params: any[]): Promise<CommandResponse>;
21
- protected abstract execSql(sql: string): Promise<QueryResponse | CommandResponse>;
22
- }
23
- declare abstract class SQLTransaction extends SQLClient {
24
- abstract commit(): Promise<void>;
25
- abstract rollback(): Promise<void>;
26
- }
27
- declare abstract class DBClient extends SQLClient {
28
- protected _released: boolean;
29
- protected constructor(logger?: (query: string) => void);
30
- isReleased(): boolean;
31
- abstract transaction(): Promise<SQLTransaction>;
32
- abstract release(): Promise<void>;
33
- }
34
- //#endregion
35
- export { SQLExecutor as a, SQLClient as i, DBClient as n, SQLTransaction as o, QueryResponse as r, SqlValueType as s, CommandResponse as t };
@@ -1,35 +0,0 @@
1
- //#region src/db/connectors/dbClient.d.ts
2
- type QueryResponse = Array<{
3
- [key: string]: SqlValueType;
4
- }>;
5
- interface CommandResponse {
6
- insertId: number;
7
- affectedRows: number;
8
- changedRows: number;
9
- }
10
- type SqlValueType = string | number | boolean | null;
11
- interface SQLExecutor {
12
- rawQuery(sql: string): Promise<QueryResponse>;
13
- rawCommand(sql: string): Promise<CommandResponse>;
14
- }
15
- declare abstract class SQLClient implements SQLExecutor {
16
- protected logger: (query: string) => void;
17
- rawQuery(sql: string): Promise<QueryResponse>;
18
- rawCommand(sql: string): Promise<CommandResponse>;
19
- query(templateString: TemplateStringsArray, ...params: any[]): Promise<QueryResponse>;
20
- command(templateString: TemplateStringsArray, ...params: any[]): Promise<CommandResponse>;
21
- protected abstract execSql(sql: string): Promise<QueryResponse | CommandResponse>;
22
- }
23
- declare abstract class SQLTransaction extends SQLClient {
24
- abstract commit(): Promise<void>;
25
- abstract rollback(): Promise<void>;
26
- }
27
- declare abstract class DBClient extends SQLClient {
28
- protected _released: boolean;
29
- protected constructor(logger?: (query: string) => void);
30
- isReleased(): boolean;
31
- abstract transaction(): Promise<SQLTransaction>;
32
- abstract release(): Promise<void>;
33
- }
34
- //#endregion
35
- export { SQLExecutor as a, SQLClient as i, DBClient as n, SQLTransaction as o, QueryResponse as r, SqlValueType as s, CommandResponse as t };