sasat 0.21.13 → 0.21.14
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/cli.cjs +1 -1
- package/dist/cli/cli.mjs +1 -1
- package/dist/index.cjs +5 -4
- package/dist/index.d.cts +36 -1
- package/dist/index.d.mts +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.mjs +5 -5
- package/dist/shared/{sasat.CEngWMnG.cjs → sasat.Carpzdbu.cjs} +114 -105
- package/dist/shared/{sasat.CtwXwmHh.mjs → sasat.DaTBDAY7.mjs} +114 -106
- package/package.json +1 -1
package/dist/cli/cli.cjs
CHANGED
package/dist/cli/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cac } from 'cac';
|
|
3
|
-
import { S as SqlString, a as SasatError, c as config, r as readInitialSchema, g as getDbClient, m as mkDirIfNotExist, n as nonNullable, u as unique, C as Conditions, w as writeFileIfNotExist, b as writeCurrentSchema, d as writeYmlFile, e as defaultConf } from '../shared/sasat.
|
|
3
|
+
import { S as SqlString, a as SasatError, c as config, r as readInitialSchema, g as getDbClient, m as mkDirIfNotExist, n as nonNullable, u as unique, C as Conditions, w as writeFileIfNotExist, b as writeCurrentSchema, d as writeYmlFile, e as defaultConf } from '../shared/sasat.DaTBDAY7.mjs';
|
|
4
4
|
import 'pluralize';
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import fs__default from 'fs';
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const error = require('./shared/sasat.
|
|
4
|
-
const SqlString = require('sqlstring');
|
|
5
|
-
require('mysql2');
|
|
6
|
-
require('util');
|
|
3
|
+
const error = require('./shared/sasat.Carpzdbu.cjs');
|
|
7
4
|
require('path');
|
|
8
5
|
require('fs-extra');
|
|
9
6
|
require('js-yaml');
|
|
7
|
+
const SqlString = require('sqlstring');
|
|
8
|
+
require('mysql2');
|
|
9
|
+
require('util');
|
|
10
10
|
|
|
11
11
|
function _interopNamespaceCompat(e) {
|
|
12
12
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
@@ -1014,6 +1014,7 @@ exports.Conditions = error.Conditions;
|
|
|
1014
1014
|
exports.SqlString = error.SqlString;
|
|
1015
1015
|
exports.getDbClient = error.getDbClient;
|
|
1016
1016
|
exports.pick = error.pick;
|
|
1017
|
+
exports.setConfig = error.setConfig;
|
|
1017
1018
|
exports.CompositeCondition = CompositeCondition;
|
|
1018
1019
|
exports.Mutations = Mutations;
|
|
1019
1020
|
exports.QExpr = QExpr;
|
package/dist/index.d.cts
CHANGED
|
@@ -150,6 +150,41 @@ type Sort = {
|
|
|
150
150
|
|
|
151
151
|
declare const queryToSql: (query: Query) => string;
|
|
152
152
|
|
|
153
|
+
interface SasatConfigDb {
|
|
154
|
+
host: string;
|
|
155
|
+
port: number;
|
|
156
|
+
user: string;
|
|
157
|
+
password?: string;
|
|
158
|
+
database: string;
|
|
159
|
+
ssl?: {
|
|
160
|
+
ca?: string[];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
interface SasatConfigRedis {
|
|
164
|
+
host: string;
|
|
165
|
+
port: number;
|
|
166
|
+
password?: string;
|
|
167
|
+
}
|
|
168
|
+
interface SasatConfigMigration {
|
|
169
|
+
table: string;
|
|
170
|
+
dir: string;
|
|
171
|
+
out: string;
|
|
172
|
+
target?: string;
|
|
173
|
+
}
|
|
174
|
+
interface SasatConfigGenerator {
|
|
175
|
+
addJsExtToImportStatement: boolean;
|
|
176
|
+
gql: {
|
|
177
|
+
subscription: boolean;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
interface SasatConfig {
|
|
181
|
+
db: SasatConfigDb;
|
|
182
|
+
migration: SasatConfigMigration;
|
|
183
|
+
generator: SasatConfigGenerator;
|
|
184
|
+
redis: SasatConfigRedis;
|
|
185
|
+
}
|
|
186
|
+
declare function setConfig(update: Partial<SasatConfig>): SasatConfig;
|
|
187
|
+
|
|
153
188
|
type QueryResponse = Array<{
|
|
154
189
|
[key: string]: SqlValueType;
|
|
155
190
|
}>;
|
|
@@ -1092,5 +1127,5 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
|
1092
1127
|
|
|
1093
1128
|
type PagingOption = ListQueryOption;
|
|
1094
1129
|
|
|
1095
|
-
export { CompositeCondition, Conditions, Mutations, QExpr, Queries, SQLClient, SQLTransaction, SasatDBDatasource, Sql, SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql };
|
|
1130
|
+
export { CompositeCondition, Conditions, Mutations, QExpr, Queries, SQLClient, SQLTransaction, SasatDBDatasource, Sql, SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql, setConfig };
|
|
1096
1131
|
export type { BooleanValueExpression, CommandResponse, ComparisonOperators, CustomCondition, EntityResult, EntityType, Fields, ListQueryOption, LockMode, MigrationStore, PagingOption, Query, QueryOptions, QueryResponse, Relation, RelationMap, ResolverMiddleware, SQLExecutor, SasatMigration, TableInfo, TypeFieldDefinition };
|
package/dist/index.d.mts
CHANGED
|
@@ -150,6 +150,41 @@ type Sort = {
|
|
|
150
150
|
|
|
151
151
|
declare const queryToSql: (query: Query) => string;
|
|
152
152
|
|
|
153
|
+
interface SasatConfigDb {
|
|
154
|
+
host: string;
|
|
155
|
+
port: number;
|
|
156
|
+
user: string;
|
|
157
|
+
password?: string;
|
|
158
|
+
database: string;
|
|
159
|
+
ssl?: {
|
|
160
|
+
ca?: string[];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
interface SasatConfigRedis {
|
|
164
|
+
host: string;
|
|
165
|
+
port: number;
|
|
166
|
+
password?: string;
|
|
167
|
+
}
|
|
168
|
+
interface SasatConfigMigration {
|
|
169
|
+
table: string;
|
|
170
|
+
dir: string;
|
|
171
|
+
out: string;
|
|
172
|
+
target?: string;
|
|
173
|
+
}
|
|
174
|
+
interface SasatConfigGenerator {
|
|
175
|
+
addJsExtToImportStatement: boolean;
|
|
176
|
+
gql: {
|
|
177
|
+
subscription: boolean;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
interface SasatConfig {
|
|
181
|
+
db: SasatConfigDb;
|
|
182
|
+
migration: SasatConfigMigration;
|
|
183
|
+
generator: SasatConfigGenerator;
|
|
184
|
+
redis: SasatConfigRedis;
|
|
185
|
+
}
|
|
186
|
+
declare function setConfig(update: Partial<SasatConfig>): SasatConfig;
|
|
187
|
+
|
|
153
188
|
type QueryResponse = Array<{
|
|
154
189
|
[key: string]: SqlValueType;
|
|
155
190
|
}>;
|
|
@@ -1092,5 +1127,5 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
|
1092
1127
|
|
|
1093
1128
|
type PagingOption = ListQueryOption;
|
|
1094
1129
|
|
|
1095
|
-
export { CompositeCondition, Conditions, Mutations, QExpr, Queries, SQLClient, SQLTransaction, SasatDBDatasource, Sql, SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql };
|
|
1130
|
+
export { CompositeCondition, Conditions, Mutations, QExpr, Queries, SQLClient, SQLTransaction, SasatDBDatasource, Sql, SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql, setConfig };
|
|
1096
1131
|
export type { BooleanValueExpression, CommandResponse, ComparisonOperators, CustomCondition, EntityResult, EntityType, Fields, ListQueryOption, LockMode, MigrationStore, PagingOption, Query, QueryOptions, QueryResponse, Relation, RelationMap, ResolverMiddleware, SQLExecutor, SasatMigration, TableInfo, TypeFieldDefinition };
|
package/dist/index.d.ts
CHANGED
|
@@ -150,6 +150,41 @@ type Sort = {
|
|
|
150
150
|
|
|
151
151
|
declare const queryToSql: (query: Query) => string;
|
|
152
152
|
|
|
153
|
+
interface SasatConfigDb {
|
|
154
|
+
host: string;
|
|
155
|
+
port: number;
|
|
156
|
+
user: string;
|
|
157
|
+
password?: string;
|
|
158
|
+
database: string;
|
|
159
|
+
ssl?: {
|
|
160
|
+
ca?: string[];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
interface SasatConfigRedis {
|
|
164
|
+
host: string;
|
|
165
|
+
port: number;
|
|
166
|
+
password?: string;
|
|
167
|
+
}
|
|
168
|
+
interface SasatConfigMigration {
|
|
169
|
+
table: string;
|
|
170
|
+
dir: string;
|
|
171
|
+
out: string;
|
|
172
|
+
target?: string;
|
|
173
|
+
}
|
|
174
|
+
interface SasatConfigGenerator {
|
|
175
|
+
addJsExtToImportStatement: boolean;
|
|
176
|
+
gql: {
|
|
177
|
+
subscription: boolean;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
interface SasatConfig {
|
|
181
|
+
db: SasatConfigDb;
|
|
182
|
+
migration: SasatConfigMigration;
|
|
183
|
+
generator: SasatConfigGenerator;
|
|
184
|
+
redis: SasatConfigRedis;
|
|
185
|
+
}
|
|
186
|
+
declare function setConfig(update: Partial<SasatConfig>): SasatConfig;
|
|
187
|
+
|
|
153
188
|
type QueryResponse = Array<{
|
|
154
189
|
[key: string]: SqlValueType;
|
|
155
190
|
}>;
|
|
@@ -1092,5 +1127,5 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
|
1092
1127
|
|
|
1093
1128
|
type PagingOption = ListQueryOption;
|
|
1094
1129
|
|
|
1095
|
-
export { CompositeCondition, Conditions, Mutations, QExpr, Queries, SQLClient, SQLTransaction, SasatDBDatasource, Sql, SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql };
|
|
1130
|
+
export { CompositeCondition, Conditions, Mutations, QExpr, Queries, SQLClient, SQLTransaction, SasatDBDatasource, Sql, SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql, setConfig };
|
|
1096
1131
|
export type { BooleanValueExpression, CommandResponse, ComparisonOperators, CustomCondition, EntityResult, EntityType, Fields, ListQueryOption, LockMode, MigrationStore, PagingOption, Query, QueryOptions, QueryResponse, Relation, RelationMap, ResolverMiddleware, SQLExecutor, SasatMigration, TableInfo, TypeFieldDefinition };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { S as SqlString$1, n as nonNullable, u as unique, g as getDbClient, a as SasatError } from './shared/sasat.
|
|
2
|
-
export { C as Conditions, p as pick } from './shared/sasat.
|
|
3
|
-
import * as SqlString from 'sqlstring';
|
|
4
|
-
import 'mysql2';
|
|
5
|
-
import 'util';
|
|
1
|
+
import { S as SqlString$1, n as nonNullable, u as unique, g as getDbClient, a as SasatError } from './shared/sasat.DaTBDAY7.mjs';
|
|
2
|
+
export { C as Conditions, p as pick, s as setConfig } from './shared/sasat.DaTBDAY7.mjs';
|
|
6
3
|
import 'path';
|
|
7
4
|
import 'fs-extra';
|
|
8
5
|
import 'js-yaml';
|
|
6
|
+
import * as SqlString from 'sqlstring';
|
|
7
|
+
import 'mysql2';
|
|
8
|
+
import 'util';
|
|
9
9
|
|
|
10
10
|
var QueryNodeKind = /* @__PURE__ */ ((QueryNodeKind2) => {
|
|
11
11
|
QueryNodeKind2[QueryNodeKind2["Field"] = 0] = "Field";
|
|
@@ -33,6 +33,115 @@ const SqlString = {
|
|
|
33
33
|
escapeId: (name) => escapeId(name)
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
const readYmlFile = (filepath) => yaml__namespace.load(fs__default.readFileSync(filepath, "utf8"));
|
|
37
|
+
const mkDirIfNotExist = (path) => {
|
|
38
|
+
if (!fs__default.pathExistsSync(path)) fs__default.mkdirpSync(path);
|
|
39
|
+
};
|
|
40
|
+
const writeFileIfNotExist = (path, data) => {
|
|
41
|
+
if (fs__default.existsSync(path)) return Promise.resolve();
|
|
42
|
+
return fs__default.writeFile(path, data);
|
|
43
|
+
};
|
|
44
|
+
const writeYmlFile = (path$1, fileName, obj) => {
|
|
45
|
+
mkDirIfNotExist(path$1);
|
|
46
|
+
fs__default.writeFileSync(
|
|
47
|
+
path.join(path$1, fileName),
|
|
48
|
+
yaml__namespace.dump(obj, {
|
|
49
|
+
skipInvalid: true,
|
|
50
|
+
noRefs: true,
|
|
51
|
+
sortKeys: (a, b) => {
|
|
52
|
+
if (b === "tableName") return 1;
|
|
53
|
+
if (a === "tableName") return -1;
|
|
54
|
+
if (a > b) return 1;
|
|
55
|
+
if (a < b) return -1;
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
const readInitialSchema = () => {
|
|
62
|
+
return readYmlFile(path.join(config().migration.dir, "initialSchema.yml"));
|
|
63
|
+
};
|
|
64
|
+
const writeCurrentSchema = (schema) => {
|
|
65
|
+
writeYmlFile(config().migration.dir, "currentSchema.yml", schema);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
class SasatConfigLoader {
|
|
69
|
+
static loadConfig() {
|
|
70
|
+
const fileName = "sasat.yml";
|
|
71
|
+
const filepath = path__default.join(process.cwd(), fileName);
|
|
72
|
+
if (!fs__default.existsSync(filepath)) return defaultConf;
|
|
73
|
+
return readYmlFile(filepath);
|
|
74
|
+
}
|
|
75
|
+
conf;
|
|
76
|
+
constructor() {
|
|
77
|
+
const conf = this.readValue({
|
|
78
|
+
...defaultConf,
|
|
79
|
+
...SasatConfigLoader.loadConfig()
|
|
80
|
+
});
|
|
81
|
+
this.conf = {
|
|
82
|
+
...conf
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
getConfig() {
|
|
86
|
+
return this.conf;
|
|
87
|
+
}
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
readValue(value) {
|
|
90
|
+
if (!value) return value;
|
|
91
|
+
if (Array.isArray(value)) return value.map((it) => this.readValue(it));
|
|
92
|
+
if (typeof value === "string" && value.startsWith("$"))
|
|
93
|
+
return process.env[value.slice(1)];
|
|
94
|
+
if (typeof value === "object") {
|
|
95
|
+
for (const key in value) {
|
|
96
|
+
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
97
|
+
value[key] = this.readValue(value[key]);
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const defaultConfDb = {
|
|
106
|
+
host: "127.0.0.1",
|
|
107
|
+
port: 3306,
|
|
108
|
+
user: "root",
|
|
109
|
+
database: "sasat",
|
|
110
|
+
password: ""
|
|
111
|
+
};
|
|
112
|
+
const defaultCofRedis = {
|
|
113
|
+
host: "127.0.0.1",
|
|
114
|
+
port: 6379
|
|
115
|
+
};
|
|
116
|
+
const defaultConfMigration = {
|
|
117
|
+
table: "__migrate__",
|
|
118
|
+
dir: "migrations",
|
|
119
|
+
out: "sasat"
|
|
120
|
+
};
|
|
121
|
+
const defaultConf = {
|
|
122
|
+
db: defaultConfDb,
|
|
123
|
+
migration: defaultConfMigration,
|
|
124
|
+
generator: {
|
|
125
|
+
addJsExtToImportStatement: false,
|
|
126
|
+
gql: {
|
|
127
|
+
subscription: true
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
redis: defaultCofRedis
|
|
131
|
+
};
|
|
132
|
+
let conf;
|
|
133
|
+
const config = () => {
|
|
134
|
+
if (conf === void 0) conf = new SasatConfigLoader().getConfig();
|
|
135
|
+
return conf;
|
|
136
|
+
};
|
|
137
|
+
function setConfig(update) {
|
|
138
|
+
conf = {
|
|
139
|
+
...config(),
|
|
140
|
+
...update
|
|
141
|
+
};
|
|
142
|
+
return conf;
|
|
143
|
+
}
|
|
144
|
+
|
|
36
145
|
const parent = (field2) => ({
|
|
37
146
|
kind: "parent",
|
|
38
147
|
field: field2
|
|
@@ -240,115 +349,13 @@ class MySqlTransaction extends SQLTransaction {
|
|
|
240
349
|
}
|
|
241
350
|
}
|
|
242
351
|
|
|
243
|
-
const readYmlFile = (filepath) => yaml__namespace.load(fs__default.readFileSync(filepath, "utf8"));
|
|
244
|
-
const mkDirIfNotExist = (path) => {
|
|
245
|
-
if (!fs__default.pathExistsSync(path)) fs__default.mkdirpSync(path);
|
|
246
|
-
};
|
|
247
|
-
const writeFileIfNotExist = (path, data) => {
|
|
248
|
-
if (fs__default.existsSync(path)) return Promise.resolve();
|
|
249
|
-
return fs__default.writeFile(path, data);
|
|
250
|
-
};
|
|
251
|
-
const writeYmlFile = (path$1, fileName, obj) => {
|
|
252
|
-
mkDirIfNotExist(path$1);
|
|
253
|
-
fs__default.writeFileSync(
|
|
254
|
-
path.join(path$1, fileName),
|
|
255
|
-
yaml__namespace.dump(obj, {
|
|
256
|
-
skipInvalid: true,
|
|
257
|
-
noRefs: true,
|
|
258
|
-
sortKeys: (a, b) => {
|
|
259
|
-
if (b === "tableName") return 1;
|
|
260
|
-
if (a === "tableName") return -1;
|
|
261
|
-
if (a > b) return 1;
|
|
262
|
-
if (a < b) return -1;
|
|
263
|
-
return 0;
|
|
264
|
-
}
|
|
265
|
-
})
|
|
266
|
-
);
|
|
267
|
-
};
|
|
268
|
-
const readInitialSchema = () => {
|
|
269
|
-
return readYmlFile(path.join(config().migration.dir, "initialSchema.yml"));
|
|
270
|
-
};
|
|
271
|
-
const writeCurrentSchema = (schema) => {
|
|
272
|
-
writeYmlFile(config().migration.dir, "currentSchema.yml", schema);
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
class SasatConfigLoader {
|
|
276
|
-
static loadConfig() {
|
|
277
|
-
const fileName = "sasat.yml";
|
|
278
|
-
const filepath = path__default.join(process.cwd(), fileName);
|
|
279
|
-
if (!fs__default.existsSync(filepath)) return defaultConf;
|
|
280
|
-
return readYmlFile(filepath);
|
|
281
|
-
}
|
|
282
|
-
conf;
|
|
283
|
-
constructor() {
|
|
284
|
-
const conf = this.readValue({
|
|
285
|
-
...defaultConf,
|
|
286
|
-
...SasatConfigLoader.loadConfig()
|
|
287
|
-
});
|
|
288
|
-
this.conf = {
|
|
289
|
-
...conf
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
getConfig() {
|
|
293
|
-
return this.conf;
|
|
294
|
-
}
|
|
295
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
296
|
-
readValue(value) {
|
|
297
|
-
if (!value) return value;
|
|
298
|
-
if (Array.isArray(value)) return value.map((it) => this.readValue(it));
|
|
299
|
-
if (typeof value === "string" && value.startsWith("$"))
|
|
300
|
-
return process.env[value.slice(1)];
|
|
301
|
-
if (typeof value === "object") {
|
|
302
|
-
for (const key in value) {
|
|
303
|
-
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
304
|
-
value[key] = this.readValue(value[key]);
|
|
305
|
-
}
|
|
306
|
-
return value;
|
|
307
|
-
}
|
|
308
|
-
return value;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const defaultConfDb = {
|
|
313
|
-
host: "127.0.0.1",
|
|
314
|
-
port: 3306,
|
|
315
|
-
user: "root",
|
|
316
|
-
database: "sasat",
|
|
317
|
-
password: ""
|
|
318
|
-
};
|
|
319
|
-
const defaultCofRedis = {
|
|
320
|
-
host: "127.0.0.1",
|
|
321
|
-
port: 6379
|
|
322
|
-
};
|
|
323
|
-
const defaultConfMigration = {
|
|
324
|
-
table: "__migrate__",
|
|
325
|
-
dir: "migrations",
|
|
326
|
-
out: "sasat"
|
|
327
|
-
};
|
|
328
|
-
const defaultConf = {
|
|
329
|
-
db: defaultConfDb,
|
|
330
|
-
migration: defaultConfMigration,
|
|
331
|
-
generator: {
|
|
332
|
-
addJsExtToImportStatement: false,
|
|
333
|
-
gql: {
|
|
334
|
-
subscription: true
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
redis: defaultCofRedis
|
|
338
|
-
};
|
|
339
|
-
let conf;
|
|
340
|
-
const config = () => {
|
|
341
|
-
if (conf === void 0) conf = new SasatConfigLoader().getConfig();
|
|
342
|
-
return conf;
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const defaultConfig = { ...config().db, dateStrings: true };
|
|
346
352
|
class MysqlClient extends DBClient {
|
|
347
353
|
constructor(connectionOption, poolOption) {
|
|
348
354
|
super();
|
|
349
355
|
this.connectionOption = connectionOption;
|
|
350
356
|
this.pool = mysql__namespace.createPool({
|
|
351
|
-
...
|
|
357
|
+
...config().db,
|
|
358
|
+
dateStrings: true,
|
|
352
359
|
...connectionOption,
|
|
353
360
|
...poolOption
|
|
354
361
|
});
|
|
@@ -359,7 +366,8 @@ class MysqlClient extends DBClient {
|
|
|
359
366
|
};
|
|
360
367
|
async transaction() {
|
|
361
368
|
const connection = mysql__namespace.createConnection({
|
|
362
|
-
...
|
|
369
|
+
...config().db,
|
|
370
|
+
dateStrings: true,
|
|
363
371
|
...this.connectionOption
|
|
364
372
|
});
|
|
365
373
|
await util.promisify(connection.beginTransaction).bind(connection)();
|
|
@@ -400,6 +408,7 @@ exports.mkDirIfNotExist = mkDirIfNotExist;
|
|
|
400
408
|
exports.nonNullable = nonNullable;
|
|
401
409
|
exports.pick = pick;
|
|
402
410
|
exports.readInitialSchema = readInitialSchema;
|
|
411
|
+
exports.setConfig = setConfig;
|
|
403
412
|
exports.unique = unique;
|
|
404
413
|
exports.writeCurrentSchema = writeCurrentSchema;
|
|
405
414
|
exports.writeFileIfNotExist = writeFileIfNotExist;
|
|
@@ -11,6 +11,115 @@ const SqlString = {
|
|
|
11
11
|
escapeId: (name) => escapeId(name)
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const readYmlFile = (filepath) => yaml.load(fs.readFileSync(filepath, "utf8"));
|
|
15
|
+
const mkDirIfNotExist = (path) => {
|
|
16
|
+
if (!fs.pathExistsSync(path)) fs.mkdirpSync(path);
|
|
17
|
+
};
|
|
18
|
+
const writeFileIfNotExist = (path, data) => {
|
|
19
|
+
if (fs.existsSync(path)) return Promise.resolve();
|
|
20
|
+
return fs.writeFile(path, data);
|
|
21
|
+
};
|
|
22
|
+
const writeYmlFile = (path, fileName, obj) => {
|
|
23
|
+
mkDirIfNotExist(path);
|
|
24
|
+
fs.writeFileSync(
|
|
25
|
+
join(path, fileName),
|
|
26
|
+
yaml.dump(obj, {
|
|
27
|
+
skipInvalid: true,
|
|
28
|
+
noRefs: true,
|
|
29
|
+
sortKeys: (a, b) => {
|
|
30
|
+
if (b === "tableName") return 1;
|
|
31
|
+
if (a === "tableName") return -1;
|
|
32
|
+
if (a > b) return 1;
|
|
33
|
+
if (a < b) return -1;
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
const readInitialSchema = () => {
|
|
40
|
+
return readYmlFile(join(config().migration.dir, "initialSchema.yml"));
|
|
41
|
+
};
|
|
42
|
+
const writeCurrentSchema = (schema) => {
|
|
43
|
+
writeYmlFile(config().migration.dir, "currentSchema.yml", schema);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
class SasatConfigLoader {
|
|
47
|
+
static loadConfig() {
|
|
48
|
+
const fileName = "sasat.yml";
|
|
49
|
+
const filepath = path__default.join(process.cwd(), fileName);
|
|
50
|
+
if (!fs.existsSync(filepath)) return defaultConf;
|
|
51
|
+
return readYmlFile(filepath);
|
|
52
|
+
}
|
|
53
|
+
conf;
|
|
54
|
+
constructor() {
|
|
55
|
+
const conf = this.readValue({
|
|
56
|
+
...defaultConf,
|
|
57
|
+
...SasatConfigLoader.loadConfig()
|
|
58
|
+
});
|
|
59
|
+
this.conf = {
|
|
60
|
+
...conf
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
getConfig() {
|
|
64
|
+
return this.conf;
|
|
65
|
+
}
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
readValue(value) {
|
|
68
|
+
if (!value) return value;
|
|
69
|
+
if (Array.isArray(value)) return value.map((it) => this.readValue(it));
|
|
70
|
+
if (typeof value === "string" && value.startsWith("$"))
|
|
71
|
+
return process.env[value.slice(1)];
|
|
72
|
+
if (typeof value === "object") {
|
|
73
|
+
for (const key in value) {
|
|
74
|
+
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
75
|
+
value[key] = this.readValue(value[key]);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const defaultConfDb = {
|
|
84
|
+
host: "127.0.0.1",
|
|
85
|
+
port: 3306,
|
|
86
|
+
user: "root",
|
|
87
|
+
database: "sasat",
|
|
88
|
+
password: ""
|
|
89
|
+
};
|
|
90
|
+
const defaultCofRedis = {
|
|
91
|
+
host: "127.0.0.1",
|
|
92
|
+
port: 6379
|
|
93
|
+
};
|
|
94
|
+
const defaultConfMigration = {
|
|
95
|
+
table: "__migrate__",
|
|
96
|
+
dir: "migrations",
|
|
97
|
+
out: "sasat"
|
|
98
|
+
};
|
|
99
|
+
const defaultConf = {
|
|
100
|
+
db: defaultConfDb,
|
|
101
|
+
migration: defaultConfMigration,
|
|
102
|
+
generator: {
|
|
103
|
+
addJsExtToImportStatement: false,
|
|
104
|
+
gql: {
|
|
105
|
+
subscription: true
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
redis: defaultCofRedis
|
|
109
|
+
};
|
|
110
|
+
let conf;
|
|
111
|
+
const config = () => {
|
|
112
|
+
if (conf === void 0) conf = new SasatConfigLoader().getConfig();
|
|
113
|
+
return conf;
|
|
114
|
+
};
|
|
115
|
+
function setConfig(update) {
|
|
116
|
+
conf = {
|
|
117
|
+
...config(),
|
|
118
|
+
...update
|
|
119
|
+
};
|
|
120
|
+
return conf;
|
|
121
|
+
}
|
|
122
|
+
|
|
14
123
|
const parent = (field2) => ({
|
|
15
124
|
kind: "parent",
|
|
16
125
|
field: field2
|
|
@@ -218,115 +327,13 @@ class MySqlTransaction extends SQLTransaction {
|
|
|
218
327
|
}
|
|
219
328
|
}
|
|
220
329
|
|
|
221
|
-
const readYmlFile = (filepath) => yaml.load(fs.readFileSync(filepath, "utf8"));
|
|
222
|
-
const mkDirIfNotExist = (path) => {
|
|
223
|
-
if (!fs.pathExistsSync(path)) fs.mkdirpSync(path);
|
|
224
|
-
};
|
|
225
|
-
const writeFileIfNotExist = (path, data) => {
|
|
226
|
-
if (fs.existsSync(path)) return Promise.resolve();
|
|
227
|
-
return fs.writeFile(path, data);
|
|
228
|
-
};
|
|
229
|
-
const writeYmlFile = (path, fileName, obj) => {
|
|
230
|
-
mkDirIfNotExist(path);
|
|
231
|
-
fs.writeFileSync(
|
|
232
|
-
join(path, fileName),
|
|
233
|
-
yaml.dump(obj, {
|
|
234
|
-
skipInvalid: true,
|
|
235
|
-
noRefs: true,
|
|
236
|
-
sortKeys: (a, b) => {
|
|
237
|
-
if (b === "tableName") return 1;
|
|
238
|
-
if (a === "tableName") return -1;
|
|
239
|
-
if (a > b) return 1;
|
|
240
|
-
if (a < b) return -1;
|
|
241
|
-
return 0;
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
};
|
|
246
|
-
const readInitialSchema = () => {
|
|
247
|
-
return readYmlFile(join(config().migration.dir, "initialSchema.yml"));
|
|
248
|
-
};
|
|
249
|
-
const writeCurrentSchema = (schema) => {
|
|
250
|
-
writeYmlFile(config().migration.dir, "currentSchema.yml", schema);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
class SasatConfigLoader {
|
|
254
|
-
static loadConfig() {
|
|
255
|
-
const fileName = "sasat.yml";
|
|
256
|
-
const filepath = path__default.join(process.cwd(), fileName);
|
|
257
|
-
if (!fs.existsSync(filepath)) return defaultConf;
|
|
258
|
-
return readYmlFile(filepath);
|
|
259
|
-
}
|
|
260
|
-
conf;
|
|
261
|
-
constructor() {
|
|
262
|
-
const conf = this.readValue({
|
|
263
|
-
...defaultConf,
|
|
264
|
-
...SasatConfigLoader.loadConfig()
|
|
265
|
-
});
|
|
266
|
-
this.conf = {
|
|
267
|
-
...conf
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
getConfig() {
|
|
271
|
-
return this.conf;
|
|
272
|
-
}
|
|
273
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
274
|
-
readValue(value) {
|
|
275
|
-
if (!value) return value;
|
|
276
|
-
if (Array.isArray(value)) return value.map((it) => this.readValue(it));
|
|
277
|
-
if (typeof value === "string" && value.startsWith("$"))
|
|
278
|
-
return process.env[value.slice(1)];
|
|
279
|
-
if (typeof value === "object") {
|
|
280
|
-
for (const key in value) {
|
|
281
|
-
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
282
|
-
value[key] = this.readValue(value[key]);
|
|
283
|
-
}
|
|
284
|
-
return value;
|
|
285
|
-
}
|
|
286
|
-
return value;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const defaultConfDb = {
|
|
291
|
-
host: "127.0.0.1",
|
|
292
|
-
port: 3306,
|
|
293
|
-
user: "root",
|
|
294
|
-
database: "sasat",
|
|
295
|
-
password: ""
|
|
296
|
-
};
|
|
297
|
-
const defaultCofRedis = {
|
|
298
|
-
host: "127.0.0.1",
|
|
299
|
-
port: 6379
|
|
300
|
-
};
|
|
301
|
-
const defaultConfMigration = {
|
|
302
|
-
table: "__migrate__",
|
|
303
|
-
dir: "migrations",
|
|
304
|
-
out: "sasat"
|
|
305
|
-
};
|
|
306
|
-
const defaultConf = {
|
|
307
|
-
db: defaultConfDb,
|
|
308
|
-
migration: defaultConfMigration,
|
|
309
|
-
generator: {
|
|
310
|
-
addJsExtToImportStatement: false,
|
|
311
|
-
gql: {
|
|
312
|
-
subscription: true
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
redis: defaultCofRedis
|
|
316
|
-
};
|
|
317
|
-
let conf;
|
|
318
|
-
const config = () => {
|
|
319
|
-
if (conf === void 0) conf = new SasatConfigLoader().getConfig();
|
|
320
|
-
return conf;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const defaultConfig = { ...config().db, dateStrings: true };
|
|
324
330
|
class MysqlClient extends DBClient {
|
|
325
331
|
constructor(connectionOption, poolOption) {
|
|
326
332
|
super();
|
|
327
333
|
this.connectionOption = connectionOption;
|
|
328
334
|
this.pool = mysql.createPool({
|
|
329
|
-
...
|
|
335
|
+
...config().db,
|
|
336
|
+
dateStrings: true,
|
|
330
337
|
...connectionOption,
|
|
331
338
|
...poolOption
|
|
332
339
|
});
|
|
@@ -337,7 +344,8 @@ class MysqlClient extends DBClient {
|
|
|
337
344
|
};
|
|
338
345
|
async transaction() {
|
|
339
346
|
const connection = mysql.createConnection({
|
|
340
|
-
...
|
|
347
|
+
...config().db,
|
|
348
|
+
dateStrings: true,
|
|
341
349
|
...this.connectionOption
|
|
342
350
|
});
|
|
343
351
|
await promisify(connection.beginTransaction).bind(connection)();
|
|
@@ -368,4 +376,4 @@ class SasatError extends Error {
|
|
|
368
376
|
}
|
|
369
377
|
}
|
|
370
378
|
|
|
371
|
-
export { Conditions as C, SqlString as S, SasatError as a, writeCurrentSchema as b, config as c, writeYmlFile as d, defaultConf as e, getDbClient as g, mkDirIfNotExist as m, nonNullable as n, pick as p, readInitialSchema as r, unique as u, writeFileIfNotExist as w };
|
|
379
|
+
export { Conditions as C, SqlString as S, SasatError as a, writeCurrentSchema as b, config as c, writeYmlFile as d, defaultConf as e, getDbClient as g, mkDirIfNotExist as m, nonNullable as n, pick as p, readInitialSchema as r, setConfig as s, unique as u, writeFileIfNotExist as w };
|