sasat 0.20.5 → 0.21.1
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 +59 -44
- package/dist/cli/cli.mjs +57 -43
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +15 -12
package/dist/cli/cli.cjs
CHANGED
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const cac = require('cac');
|
|
5
|
+
const erDiagram = require('cli/commands/erDiagram');
|
|
5
6
|
const fs = require('fs');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const error = require('../shared/sasat.f544328b.cjs');
|
|
8
9
|
require('pluralize');
|
|
9
10
|
const chalk = require('chalk');
|
|
10
11
|
const console$1 = require('console');
|
|
11
|
-
const
|
|
12
|
+
const esbuild = require('esbuild');
|
|
12
13
|
const fs$1 = require('fs-extra');
|
|
13
14
|
require('js-yaml');
|
|
14
15
|
const prettier = require('prettier');
|
|
16
|
+
const typescript = require('typescript');
|
|
17
|
+
const getCurrentStore = require('cli/commands/getCurrentStore');
|
|
15
18
|
require('sqlstring');
|
|
16
19
|
require('mysql2');
|
|
17
20
|
require('util');
|
|
@@ -36,9 +39,10 @@ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
|
36
39
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
37
40
|
const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
38
41
|
const console__namespace = /*#__PURE__*/_interopNamespaceCompat(console$1);
|
|
39
|
-
const
|
|
42
|
+
const esbuild__namespace = /*#__PURE__*/_interopNamespaceCompat(esbuild);
|
|
40
43
|
const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
|
|
41
44
|
const prettier__namespace = /*#__PURE__*/_interopNamespaceCompat(prettier);
|
|
45
|
+
const typescript__default = /*#__PURE__*/_interopDefaultCompat(typescript);
|
|
42
46
|
|
|
43
47
|
const capitalizeFirstLetter = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
44
48
|
const lowercaseFirstLetter = (str) => str.slice(0, 1).toLowerCase() + str.slice(1);
|
|
@@ -54,7 +58,7 @@ const Console = {
|
|
|
54
58
|
error: (msg) => {
|
|
55
59
|
console__namespace.error(chalk__default.bold.red(msg));
|
|
56
60
|
},
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
62
|
log: (msg) => {
|
|
59
63
|
console__namespace.log(msg);
|
|
60
64
|
},
|
|
@@ -111,35 +115,6 @@ const getMigrationFileNames = () => {
|
|
|
111
115
|
return fs__default.readdirSync(getMigrationFileDir()).filter((it) => it.split(".").pop() === "ts");
|
|
112
116
|
};
|
|
113
117
|
|
|
114
|
-
const getTsConfig = () => {
|
|
115
|
-
const configFileName = ts__default.findConfigFile(
|
|
116
|
-
"./",
|
|
117
|
-
ts__default.sys.fileExists,
|
|
118
|
-
"tsconfig.json"
|
|
119
|
-
);
|
|
120
|
-
if (!configFileName)
|
|
121
|
-
return {
|
|
122
|
-
module: ts__default.ModuleKind.ESNext
|
|
123
|
-
};
|
|
124
|
-
const configFile = ts__default.readConfigFile(configFileName, ts__default.sys.readFile);
|
|
125
|
-
return {
|
|
126
|
-
...ts__default.parseJsonConfigFileContent(configFile.config, ts__default.sys, "./").options,
|
|
127
|
-
module: ts__default.ModuleKind.ESNext
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
|
|
131
|
-
const compileMigrationFiles = () => {
|
|
132
|
-
const tsFiles = getMigrationFileNames();
|
|
133
|
-
const compiles = tsFiles.map(async (fileName) => {
|
|
134
|
-
const filePath = path__default.join(getMigrationFileDir(), fileName);
|
|
135
|
-
const file = await fs__default$1.readFile(filePath);
|
|
136
|
-
const src = ts__default.transpile(file.toString(), getTsConfig()).trim();
|
|
137
|
-
await fs__default$1.outputFile(changeExtTsToJs(filePath), src);
|
|
138
|
-
return fileName;
|
|
139
|
-
});
|
|
140
|
-
return Promise.all(compiles);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
118
|
var Direction = /* @__PURE__ */ ((Direction2) => {
|
|
144
119
|
Direction2["Up"] = "up";
|
|
145
120
|
Direction2["Down"] = "down";
|
|
@@ -196,6 +171,36 @@ in migration history: ${run}`);
|
|
|
196
171
|
return runs[runs.length - 1];
|
|
197
172
|
};
|
|
198
173
|
|
|
174
|
+
const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
|
|
175
|
+
const compileMigrationFiles = () => {
|
|
176
|
+
const tsFiles = getMigrationFileNames();
|
|
177
|
+
const compiles = tsFiles.map(async (fileName) => {
|
|
178
|
+
const filePath = path__default.join(getMigrationFileDir(), fileName);
|
|
179
|
+
const r = await esbuild__namespace.build({
|
|
180
|
+
entryPoints: [filePath],
|
|
181
|
+
bundle: true,
|
|
182
|
+
// loader: 'ts',
|
|
183
|
+
outfile: changeExtTsToJs(filePath),
|
|
184
|
+
platform: "node",
|
|
185
|
+
format: "esm",
|
|
186
|
+
outExtension: {
|
|
187
|
+
".js": ".mjs"
|
|
188
|
+
},
|
|
189
|
+
banner: {
|
|
190
|
+
js: `
|
|
191
|
+
import { createRequire as topLevelCreateRequire } from 'module';
|
|
192
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
193
|
+
`
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (r.errors.length !== 0) {
|
|
197
|
+
throw r.errors;
|
|
198
|
+
}
|
|
199
|
+
return fileName;
|
|
200
|
+
});
|
|
201
|
+
return Promise.all(compiles);
|
|
202
|
+
};
|
|
203
|
+
|
|
199
204
|
const readMigration = async (store, tsFileName, direction) => {
|
|
200
205
|
const file = path__default.join(
|
|
201
206
|
process.cwd(),
|
|
@@ -1343,7 +1348,6 @@ var __publicField$l = (obj, key, value) => {
|
|
|
1343
1348
|
return value;
|
|
1344
1349
|
};
|
|
1345
1350
|
class StoreMigrator {
|
|
1346
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1347
1351
|
constructor() {
|
|
1348
1352
|
__publicField$l(this, "tables", []);
|
|
1349
1353
|
__publicField$l(this, "migrationQueue", []);
|
|
@@ -1417,7 +1421,7 @@ const createCurrentMigrationDataStore = async (targetMigrationName) => {
|
|
|
1417
1421
|
|
|
1418
1422
|
class MigrationController {
|
|
1419
1423
|
async migrate(options) {
|
|
1420
|
-
const fileNames =
|
|
1424
|
+
const fileNames = getMigrationFileNames();
|
|
1421
1425
|
const currentMigration = await getCurrentMigration(options);
|
|
1422
1426
|
Console.log("--current migration--: " + currentMigration);
|
|
1423
1427
|
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
@@ -3040,7 +3044,9 @@ const getHashIdArgs = (entity, query) => {
|
|
|
3040
3044
|
}
|
|
3041
3045
|
const getHashIdArg = (arg, field) => {
|
|
3042
3046
|
const columnName = field.column;
|
|
3043
|
-
const hashIdOpt = entity.fields.find(
|
|
3047
|
+
const hashIdOpt = entity.fields.find(
|
|
3048
|
+
(e) => e.columnName === columnName
|
|
3049
|
+
)?.hashId;
|
|
3044
3050
|
if (!hashIdOpt)
|
|
3045
3051
|
return null;
|
|
3046
3052
|
return {
|
|
@@ -4322,7 +4328,7 @@ const makeWithFilter = (event, filters) => {
|
|
|
4322
4328
|
);
|
|
4323
4329
|
};
|
|
4324
4330
|
|
|
4325
|
-
const { SyntaxKind: SyntaxKind$1 } =
|
|
4331
|
+
const { SyntaxKind: SyntaxKind$1 } = typescript__default;
|
|
4326
4332
|
const isImported = (sourceFile, type, paths) => {
|
|
4327
4333
|
const importDeclarations = sourceFile.statements.filter(
|
|
4328
4334
|
(it) => it.kind === SyntaxKind$1.ImportDeclaration
|
|
@@ -4344,7 +4350,7 @@ const isImported = (sourceFile, type, paths) => {
|
|
|
4344
4350
|
});
|
|
4345
4351
|
};
|
|
4346
4352
|
|
|
4347
|
-
const { SyntaxKind } =
|
|
4353
|
+
const { SyntaxKind } = typescript__default;
|
|
4348
4354
|
const getExportedVariables = (sourceFile) => {
|
|
4349
4355
|
return sourceFile.statements.filter(
|
|
4350
4356
|
(it) => it.kind === SyntaxKind.VariableStatement && it.modifiers?.some(
|
|
@@ -4353,7 +4359,7 @@ const getExportedVariables = (sourceFile) => {
|
|
|
4353
4359
|
);
|
|
4354
4360
|
};
|
|
4355
4361
|
|
|
4356
|
-
const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } =
|
|
4362
|
+
const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } = typescript__default;
|
|
4357
4363
|
const generateUserDefinedCondition = (root, content) => {
|
|
4358
4364
|
const customConditionNames = error.unique(
|
|
4359
4365
|
root.entities.flatMap((it) => [
|
|
@@ -4413,7 +4419,7 @@ const generateUserDefinedCondition = (root, content) => {
|
|
|
4413
4419
|
return context + condition + content + addition;
|
|
4414
4420
|
};
|
|
4415
4421
|
|
|
4416
|
-
const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } =
|
|
4422
|
+
const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } = typescript__default;
|
|
4417
4423
|
const hashIds = "HashIds";
|
|
4418
4424
|
const generateIDEncoder = (root, content) => {
|
|
4419
4425
|
const fields = root.entities.map((it) => it.fields.find((it2) => it2.column.option.autoIncrementHashId)).filter(error.nonNullable);
|
|
@@ -4456,7 +4462,7 @@ const generateIDEncoder = (root, content) => {
|
|
|
4456
4462
|
return imports + makeEncoder + content + addition;
|
|
4457
4463
|
};
|
|
4458
4464
|
|
|
4459
|
-
const { createSourceFile, ScriptTarget } =
|
|
4465
|
+
const { createSourceFile, ScriptTarget } = typescript__default;
|
|
4460
4466
|
const generateMiddlewares = (root, content) => {
|
|
4461
4467
|
const middlewares = error.unique(
|
|
4462
4468
|
root.entities.flatMap((it) => [
|
|
@@ -5201,6 +5207,7 @@ const migrate = async (options) => {
|
|
|
5201
5207
|
let current;
|
|
5202
5208
|
Console.log("--migration started--");
|
|
5203
5209
|
try {
|
|
5210
|
+
await compileMigrationFiles();
|
|
5204
5211
|
const migration = new MigrationController();
|
|
5205
5212
|
const result = await migration.migrate(options);
|
|
5206
5213
|
current = result.currentMigration;
|
|
@@ -5232,7 +5239,7 @@ const generate = async () => {
|
|
|
5232
5239
|
await compileMigrationFiles();
|
|
5233
5240
|
const files = getMigrationFileNames();
|
|
5234
5241
|
const targetFile = files.find((it) => it === error.config().migration.target) || files[files.length - 1];
|
|
5235
|
-
const store =
|
|
5242
|
+
const store = await getCurrentStore.getCurrentStore();
|
|
5236
5243
|
const storeHandler = new DataStoreHandler(store);
|
|
5237
5244
|
error.writeCurrentSchema(store);
|
|
5238
5245
|
await new CodeGen_v2(storeHandler).generate();
|
|
@@ -5782,15 +5789,23 @@ const dumpDB = async () => {
|
|
|
5782
5789
|
}
|
|
5783
5790
|
};
|
|
5784
5791
|
|
|
5792
|
+
const migrationBuild = async () => {
|
|
5793
|
+
Console.log("--migration build started--");
|
|
5794
|
+
await compileMigrationFiles();
|
|
5795
|
+
Console.success("Done!");
|
|
5796
|
+
};
|
|
5797
|
+
|
|
5785
5798
|
const cli = cac.cac();
|
|
5786
5799
|
try {
|
|
5787
|
-
cli.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").action(async (options) => {
|
|
5800
|
+
cli.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) => {
|
|
5788
5801
|
await migrate(options).catch((e) => {
|
|
5789
|
-
|
|
5802
|
+
console.error(e);
|
|
5790
5803
|
process.exit(1);
|
|
5791
5804
|
});
|
|
5792
5805
|
});
|
|
5806
|
+
cli.command("migration:build", "compile migration files").action(migrationBuild);
|
|
5793
5807
|
cli.command("generate", "generate files").action(generate);
|
|
5808
|
+
cli.command("generate:er", "generate mermaid er diagram").action(erDiagram.writeDiagram);
|
|
5794
5809
|
cli.command("migration:create [name]", "generate new migration file").action(createMigration);
|
|
5795
5810
|
cli.command("dump-db", "dump database schema").action(dumpDB);
|
|
5796
5811
|
cli.command("init").action(init);
|
|
@@ -5798,6 +5813,6 @@ try {
|
|
|
5798
5813
|
if (!cli.matchedCommand)
|
|
5799
5814
|
cli.outputHelp();
|
|
5800
5815
|
} catch (e) {
|
|
5801
|
-
|
|
5816
|
+
console.error(e);
|
|
5802
5817
|
process.exit(1);
|
|
5803
5818
|
}
|
package/dist/cli/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cac } from 'cac';
|
|
3
|
+
import { writeDiagram } from 'cli/commands/erDiagram';
|
|
3
4
|
import * as fs from 'fs';
|
|
4
5
|
import fs__default from 'fs';
|
|
5
6
|
import * as path from 'path';
|
|
@@ -8,10 +9,12 @@ import { c as config, m as mkDirIfNotExist, S as SqlString, g as getDbClient, a
|
|
|
8
9
|
import 'pluralize';
|
|
9
10
|
import chalk from 'chalk';
|
|
10
11
|
import * as console$1 from 'console';
|
|
11
|
-
import
|
|
12
|
+
import * as esbuild from 'esbuild';
|
|
12
13
|
import fs$1 from 'fs-extra';
|
|
13
14
|
import 'js-yaml';
|
|
14
15
|
import * as prettier from 'prettier';
|
|
16
|
+
import typescript from 'typescript';
|
|
17
|
+
import { getCurrentStore } from 'cli/commands/getCurrentStore';
|
|
15
18
|
import 'sqlstring';
|
|
16
19
|
import 'mysql2';
|
|
17
20
|
import 'util';
|
|
@@ -30,7 +33,7 @@ const Console = {
|
|
|
30
33
|
error: (msg) => {
|
|
31
34
|
console$1.error(chalk.bold.red(msg));
|
|
32
35
|
},
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
37
|
log: (msg) => {
|
|
35
38
|
console$1.log(msg);
|
|
36
39
|
},
|
|
@@ -87,35 +90,6 @@ const getMigrationFileNames = () => {
|
|
|
87
90
|
return fs__default.readdirSync(getMigrationFileDir()).filter((it) => it.split(".").pop() === "ts");
|
|
88
91
|
};
|
|
89
92
|
|
|
90
|
-
const getTsConfig = () => {
|
|
91
|
-
const configFileName = ts.findConfigFile(
|
|
92
|
-
"./",
|
|
93
|
-
ts.sys.fileExists,
|
|
94
|
-
"tsconfig.json"
|
|
95
|
-
);
|
|
96
|
-
if (!configFileName)
|
|
97
|
-
return {
|
|
98
|
-
module: ts.ModuleKind.ESNext
|
|
99
|
-
};
|
|
100
|
-
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
101
|
-
return {
|
|
102
|
-
...ts.parseJsonConfigFileContent(configFile.config, ts.sys, "./").options,
|
|
103
|
-
module: ts.ModuleKind.ESNext
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
|
|
107
|
-
const compileMigrationFiles = () => {
|
|
108
|
-
const tsFiles = getMigrationFileNames();
|
|
109
|
-
const compiles = tsFiles.map(async (fileName) => {
|
|
110
|
-
const filePath = path__default.join(getMigrationFileDir(), fileName);
|
|
111
|
-
const file = await fs$1.readFile(filePath);
|
|
112
|
-
const src = ts.transpile(file.toString(), getTsConfig()).trim();
|
|
113
|
-
await fs$1.outputFile(changeExtTsToJs(filePath), src);
|
|
114
|
-
return fileName;
|
|
115
|
-
});
|
|
116
|
-
return Promise.all(compiles);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
93
|
var Direction = /* @__PURE__ */ ((Direction2) => {
|
|
120
94
|
Direction2["Up"] = "up";
|
|
121
95
|
Direction2["Down"] = "down";
|
|
@@ -172,6 +146,36 @@ in migration history: ${run}`);
|
|
|
172
146
|
return runs[runs.length - 1];
|
|
173
147
|
};
|
|
174
148
|
|
|
149
|
+
const changeExtTsToJs = (fileName) => fileName.slice(0, -3) + ".mjs";
|
|
150
|
+
const compileMigrationFiles = () => {
|
|
151
|
+
const tsFiles = getMigrationFileNames();
|
|
152
|
+
const compiles = tsFiles.map(async (fileName) => {
|
|
153
|
+
const filePath = path__default.join(getMigrationFileDir(), fileName);
|
|
154
|
+
const r = await esbuild.build({
|
|
155
|
+
entryPoints: [filePath],
|
|
156
|
+
bundle: true,
|
|
157
|
+
// loader: 'ts',
|
|
158
|
+
outfile: changeExtTsToJs(filePath),
|
|
159
|
+
platform: "node",
|
|
160
|
+
format: "esm",
|
|
161
|
+
outExtension: {
|
|
162
|
+
".js": ".mjs"
|
|
163
|
+
},
|
|
164
|
+
banner: {
|
|
165
|
+
js: `
|
|
166
|
+
import { createRequire as topLevelCreateRequire } from 'module';
|
|
167
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
168
|
+
`
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
if (r.errors.length !== 0) {
|
|
172
|
+
throw r.errors;
|
|
173
|
+
}
|
|
174
|
+
return fileName;
|
|
175
|
+
});
|
|
176
|
+
return Promise.all(compiles);
|
|
177
|
+
};
|
|
178
|
+
|
|
175
179
|
const readMigration = async (store, tsFileName, direction) => {
|
|
176
180
|
const file = path__default.join(
|
|
177
181
|
process.cwd(),
|
|
@@ -1319,7 +1323,6 @@ var __publicField$l = (obj, key, value) => {
|
|
|
1319
1323
|
return value;
|
|
1320
1324
|
};
|
|
1321
1325
|
class StoreMigrator {
|
|
1322
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1323
1326
|
constructor() {
|
|
1324
1327
|
__publicField$l(this, "tables", []);
|
|
1325
1328
|
__publicField$l(this, "migrationQueue", []);
|
|
@@ -1393,7 +1396,7 @@ const createCurrentMigrationDataStore = async (targetMigrationName) => {
|
|
|
1393
1396
|
|
|
1394
1397
|
class MigrationController {
|
|
1395
1398
|
async migrate(options) {
|
|
1396
|
-
const fileNames =
|
|
1399
|
+
const fileNames = getMigrationFileNames();
|
|
1397
1400
|
const currentMigration = await getCurrentMigration(options);
|
|
1398
1401
|
Console.log("--current migration--: " + currentMigration);
|
|
1399
1402
|
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
@@ -3016,7 +3019,9 @@ const getHashIdArgs = (entity, query) => {
|
|
|
3016
3019
|
}
|
|
3017
3020
|
const getHashIdArg = (arg, field) => {
|
|
3018
3021
|
const columnName = field.column;
|
|
3019
|
-
const hashIdOpt = entity.fields.find(
|
|
3022
|
+
const hashIdOpt = entity.fields.find(
|
|
3023
|
+
(e) => e.columnName === columnName
|
|
3024
|
+
)?.hashId;
|
|
3020
3025
|
if (!hashIdOpt)
|
|
3021
3026
|
return null;
|
|
3022
3027
|
return {
|
|
@@ -4298,7 +4303,7 @@ const makeWithFilter = (event, filters) => {
|
|
|
4298
4303
|
);
|
|
4299
4304
|
};
|
|
4300
4305
|
|
|
4301
|
-
const { SyntaxKind: SyntaxKind$1 } =
|
|
4306
|
+
const { SyntaxKind: SyntaxKind$1 } = typescript;
|
|
4302
4307
|
const isImported = (sourceFile, type, paths) => {
|
|
4303
4308
|
const importDeclarations = sourceFile.statements.filter(
|
|
4304
4309
|
(it) => it.kind === SyntaxKind$1.ImportDeclaration
|
|
@@ -4320,7 +4325,7 @@ const isImported = (sourceFile, type, paths) => {
|
|
|
4320
4325
|
});
|
|
4321
4326
|
};
|
|
4322
4327
|
|
|
4323
|
-
const { SyntaxKind } =
|
|
4328
|
+
const { SyntaxKind } = typescript;
|
|
4324
4329
|
const getExportedVariables = (sourceFile) => {
|
|
4325
4330
|
return sourceFile.statements.filter(
|
|
4326
4331
|
(it) => it.kind === SyntaxKind.VariableStatement && it.modifiers?.some(
|
|
@@ -4329,7 +4334,7 @@ const getExportedVariables = (sourceFile) => {
|
|
|
4329
4334
|
);
|
|
4330
4335
|
};
|
|
4331
4336
|
|
|
4332
|
-
const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } =
|
|
4337
|
+
const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } = typescript;
|
|
4333
4338
|
const generateUserDefinedCondition = (root, content) => {
|
|
4334
4339
|
const customConditionNames = unique(
|
|
4335
4340
|
root.entities.flatMap((it) => [
|
|
@@ -4389,7 +4394,7 @@ const generateUserDefinedCondition = (root, content) => {
|
|
|
4389
4394
|
return context + condition + content + addition;
|
|
4390
4395
|
};
|
|
4391
4396
|
|
|
4392
|
-
const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } =
|
|
4397
|
+
const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } = typescript;
|
|
4393
4398
|
const hashIds = "HashIds";
|
|
4394
4399
|
const generateIDEncoder = (root, content) => {
|
|
4395
4400
|
const fields = root.entities.map((it) => it.fields.find((it2) => it2.column.option.autoIncrementHashId)).filter(nonNullable);
|
|
@@ -4432,7 +4437,7 @@ const generateIDEncoder = (root, content) => {
|
|
|
4432
4437
|
return imports + makeEncoder + content + addition;
|
|
4433
4438
|
};
|
|
4434
4439
|
|
|
4435
|
-
const { createSourceFile, ScriptTarget } =
|
|
4440
|
+
const { createSourceFile, ScriptTarget } = typescript;
|
|
4436
4441
|
const generateMiddlewares = (root, content) => {
|
|
4437
4442
|
const middlewares = unique(
|
|
4438
4443
|
root.entities.flatMap((it) => [
|
|
@@ -5177,6 +5182,7 @@ const migrate = async (options) => {
|
|
|
5177
5182
|
let current;
|
|
5178
5183
|
Console.log("--migration started--");
|
|
5179
5184
|
try {
|
|
5185
|
+
await compileMigrationFiles();
|
|
5180
5186
|
const migration = new MigrationController();
|
|
5181
5187
|
const result = await migration.migrate(options);
|
|
5182
5188
|
current = result.currentMigration;
|
|
@@ -5208,7 +5214,7 @@ const generate = async () => {
|
|
|
5208
5214
|
await compileMigrationFiles();
|
|
5209
5215
|
const files = getMigrationFileNames();
|
|
5210
5216
|
const targetFile = files.find((it) => it === config().migration.target) || files[files.length - 1];
|
|
5211
|
-
const store =
|
|
5217
|
+
const store = await getCurrentStore();
|
|
5212
5218
|
const storeHandler = new DataStoreHandler(store);
|
|
5213
5219
|
writeCurrentSchema(store);
|
|
5214
5220
|
await new CodeGen_v2(storeHandler).generate();
|
|
@@ -5758,15 +5764,23 @@ const dumpDB = async () => {
|
|
|
5758
5764
|
}
|
|
5759
5765
|
};
|
|
5760
5766
|
|
|
5767
|
+
const migrationBuild = async () => {
|
|
5768
|
+
Console.log("--migration build started--");
|
|
5769
|
+
await compileMigrationFiles();
|
|
5770
|
+
Console.success("Done!");
|
|
5771
|
+
};
|
|
5772
|
+
|
|
5761
5773
|
const cli = cac();
|
|
5762
5774
|
try {
|
|
5763
|
-
cli.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").action(async (options) => {
|
|
5775
|
+
cli.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) => {
|
|
5764
5776
|
await migrate(options).catch((e) => {
|
|
5765
|
-
console
|
|
5777
|
+
console.error(e);
|
|
5766
5778
|
process.exit(1);
|
|
5767
5779
|
});
|
|
5768
5780
|
});
|
|
5781
|
+
cli.command("migration:build", "compile migration files").action(migrationBuild);
|
|
5769
5782
|
cli.command("generate", "generate files").action(generate);
|
|
5783
|
+
cli.command("generate:er", "generate mermaid er diagram").action(writeDiagram);
|
|
5770
5784
|
cli.command("migration:create [name]", "generate new migration file").action(createMigration);
|
|
5771
5785
|
cli.command("dump-db", "dump database schema").action(dumpDB);
|
|
5772
5786
|
cli.command("init").action(init);
|
|
@@ -5774,6 +5788,6 @@ try {
|
|
|
5774
5788
|
if (!cli.matchedCommand)
|
|
5775
5789
|
cli.outputHelp();
|
|
5776
5790
|
} catch (e) {
|
|
5777
|
-
console
|
|
5791
|
+
console.error(e);
|
|
5778
5792
|
process.exit(1);
|
|
5779
5793
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1062,7 +1062,7 @@ declare const getTodayDateTimeString: (timeZoneHour?: number) => string;
|
|
|
1062
1062
|
declare const getDayRange: (date: Date, timeZoneHour?: number) => [string, string];
|
|
1063
1063
|
declare const getDayRangeQExpr: (date: Date, timeZoneHour?: number) => [Literal, Literal];
|
|
1064
1064
|
|
|
1065
|
-
declare const pick: <T extends object>(target: T, keys:
|
|
1065
|
+
declare const pick: <T extends object>(target: T, keys: Array<keyof T>) => {
|
|
1066
1066
|
[k: string]: T[keyof T];
|
|
1067
1067
|
};
|
|
1068
1068
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1062,7 +1062,7 @@ declare const getTodayDateTimeString: (timeZoneHour?: number) => string;
|
|
|
1062
1062
|
declare const getDayRange: (date: Date, timeZoneHour?: number) => [string, string];
|
|
1063
1063
|
declare const getDayRangeQExpr: (date: Date, timeZoneHour?: number) => [Literal, Literal];
|
|
1064
1064
|
|
|
1065
|
-
declare const pick: <T extends object>(target: T, keys:
|
|
1065
|
+
declare const pick: <T extends object>(target: T, keys: Array<keyof T>) => {
|
|
1066
1066
|
[k: string]: T[keyof T];
|
|
1067
1067
|
};
|
|
1068
1068
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1062,7 +1062,7 @@ declare const getTodayDateTimeString: (timeZoneHour?: number) => string;
|
|
|
1062
1062
|
declare const getDayRange: (date: Date, timeZoneHour?: number) => [string, string];
|
|
1063
1063
|
declare const getDayRangeQExpr: (date: Date, timeZoneHour?: number) => [Literal, Literal];
|
|
1064
1064
|
|
|
1065
|
-
declare const pick: <T extends object>(target: T, keys:
|
|
1065
|
+
declare const pick: <T extends object>(target: T, keys: Array<keyof T>) => {
|
|
1066
1066
|
[k: string]: T[keyof T];
|
|
1067
1067
|
};
|
|
1068
1068
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sasat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.1",
|
|
4
4
|
"repository": "https://github.com/nin138/sasat.git",
|
|
5
5
|
"author": "nin138 <ninian138@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"test:base": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
18
18
|
"resetdb": "docker-compose exec db sh -c \"mysql -u root < /docker-entrypoint-initdb.d/temp.sql\"",
|
|
19
19
|
"prepare": "yarn build && husky install",
|
|
20
|
-
"sasat": "yarn env-cmd
|
|
20
|
+
"sasat": "yarn env-cmd tsx ./src/cli/cli.ts",
|
|
21
21
|
"server": "yarn env-cmd ts-node-esm -r tsconfig-paths/register ./test/testServer.ts"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"cac": "^6.7.14",
|
|
25
25
|
"chalk": "^5.3.0",
|
|
26
|
+
"esbuild": "^0.21.5",
|
|
26
27
|
"fs-extra": "^11.1.1",
|
|
27
28
|
"graphql": "^16.8.1",
|
|
28
29
|
"graphql-subscriptions": "^2.0.0",
|
|
@@ -36,27 +37,29 @@
|
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@apollo/server": "^4.9.3",
|
|
40
|
+
"@eslint/js": "^9.4.0",
|
|
41
|
+
"@types/eslint__js": "^8.42.3",
|
|
39
42
|
"@types/fs-extra": "11.0.4",
|
|
40
43
|
"@types/jest": "29.5.12",
|
|
41
44
|
"@types/js-yaml": "4.0.9",
|
|
42
|
-
"@types/node": "20.
|
|
45
|
+
"@types/node": "20.14.2",
|
|
43
46
|
"@types/pluralize": "0.0.33",
|
|
44
|
-
"@types/prettier": "
|
|
47
|
+
"@types/prettier": "3.0.0",
|
|
45
48
|
"@types/sqlstring": "2.3.2",
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
47
|
-
"@typescript-eslint/parser": "6.21.0",
|
|
48
49
|
"env-cmd": "10.1.0",
|
|
49
|
-
"eslint": "
|
|
50
|
-
"eslint-config-prettier": "9.1.0",
|
|
50
|
+
"eslint": "^9.4.0",
|
|
51
|
+
"eslint-config-prettier": "^9.1.0",
|
|
51
52
|
"eslint-plugin-import": "^2.27.5",
|
|
52
|
-
"eslint-plugin-prettier": "5.1.3",
|
|
53
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
53
54
|
"husky": "8.0.3",
|
|
54
55
|
"jest": "29.7.0",
|
|
55
|
-
"lint-staged": "13.
|
|
56
|
-
"sasat": "link:./
|
|
56
|
+
"lint-staged": "13.3.0",
|
|
57
|
+
"sasat": "link:./dist",
|
|
57
58
|
"ts-jest": "29.1.4",
|
|
58
59
|
"ts-node": "10.9.2",
|
|
59
60
|
"tsconfig-paths": "4.2.0",
|
|
61
|
+
"tsx": "^4.15.2",
|
|
62
|
+
"typescript-eslint": "^7.13.0",
|
|
60
63
|
"unbuild": "^2.0.0"
|
|
61
64
|
},
|
|
62
65
|
"peerDependencies": {
|
|
@@ -69,7 +72,7 @@
|
|
|
69
72
|
]
|
|
70
73
|
},
|
|
71
74
|
"type": "module",
|
|
72
|
-
"packageManager": "yarn@3.
|
|
75
|
+
"packageManager": "yarn@3.8.2",
|
|
73
76
|
"exports": {
|
|
74
77
|
".": {
|
|
75
78
|
"import": "./dist/index.mjs",
|