sasat 0.21.0 → 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 CHANGED
@@ -2,17 +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 ts = require('typescript');
12
12
  const esbuild = require('esbuild');
13
13
  const fs$1 = require('fs-extra');
14
14
  require('js-yaml');
15
15
  const prettier = require('prettier');
16
+ const typescript = require('typescript');
17
+ const getCurrentStore = require('cli/commands/getCurrentStore');
16
18
  require('sqlstring');
17
19
  require('mysql2');
18
20
  require('util');
@@ -37,10 +39,10 @@ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
37
39
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
38
40
  const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
39
41
  const console__namespace = /*#__PURE__*/_interopNamespaceCompat(console$1);
40
- const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
41
42
  const esbuild__namespace = /*#__PURE__*/_interopNamespaceCompat(esbuild);
42
43
  const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
43
44
  const prettier__namespace = /*#__PURE__*/_interopNamespaceCompat(prettier);
45
+ const typescript__default = /*#__PURE__*/_interopDefaultCompat(typescript);
44
46
 
45
47
  const capitalizeFirstLetter = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);
46
48
  const lowercaseFirstLetter = (str) => str.slice(0, 1).toLowerCase() + str.slice(1);
@@ -56,7 +58,7 @@ const Console = {
56
58
  error: (msg) => {
57
59
  console__namespace.error(chalk__default.bold.red(msg));
58
60
  },
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
62
  log: (msg) => {
61
63
  console__namespace.log(msg);
62
64
  },
@@ -1346,7 +1348,6 @@ var __publicField$l = (obj, key, value) => {
1346
1348
  return value;
1347
1349
  };
1348
1350
  class StoreMigrator {
1349
- // eslint-disable-next-line @typescript-eslint/no-empty-function
1350
1351
  constructor() {
1351
1352
  __publicField$l(this, "tables", []);
1352
1353
  __publicField$l(this, "migrationQueue", []);
@@ -3043,7 +3044,9 @@ const getHashIdArgs = (entity, query) => {
3043
3044
  }
3044
3045
  const getHashIdArg = (arg, field) => {
3045
3046
  const columnName = field.column;
3046
- const hashIdOpt = entity.fields.find((e) => e.columnName === columnName)?.hashId;
3047
+ const hashIdOpt = entity.fields.find(
3048
+ (e) => e.columnName === columnName
3049
+ )?.hashId;
3047
3050
  if (!hashIdOpt)
3048
3051
  return null;
3049
3052
  return {
@@ -4325,7 +4328,7 @@ const makeWithFilter = (event, filters) => {
4325
4328
  );
4326
4329
  };
4327
4330
 
4328
- const { SyntaxKind: SyntaxKind$1 } = ts__default;
4331
+ const { SyntaxKind: SyntaxKind$1 } = typescript__default;
4329
4332
  const isImported = (sourceFile, type, paths) => {
4330
4333
  const importDeclarations = sourceFile.statements.filter(
4331
4334
  (it) => it.kind === SyntaxKind$1.ImportDeclaration
@@ -4347,7 +4350,7 @@ const isImported = (sourceFile, type, paths) => {
4347
4350
  });
4348
4351
  };
4349
4352
 
4350
- const { SyntaxKind } = ts__default;
4353
+ const { SyntaxKind } = typescript__default;
4351
4354
  const getExportedVariables = (sourceFile) => {
4352
4355
  return sourceFile.statements.filter(
4353
4356
  (it) => it.kind === SyntaxKind.VariableStatement && it.modifiers?.some(
@@ -4356,7 +4359,7 @@ const getExportedVariables = (sourceFile) => {
4356
4359
  );
4357
4360
  };
4358
4361
 
4359
- const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } = ts__default;
4362
+ const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } = typescript__default;
4360
4363
  const generateUserDefinedCondition = (root, content) => {
4361
4364
  const customConditionNames = error.unique(
4362
4365
  root.entities.flatMap((it) => [
@@ -4416,7 +4419,7 @@ const generateUserDefinedCondition = (root, content) => {
4416
4419
  return context + condition + content + addition;
4417
4420
  };
4418
4421
 
4419
- const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } = ts__default;
4422
+ const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } = typescript__default;
4420
4423
  const hashIds = "HashIds";
4421
4424
  const generateIDEncoder = (root, content) => {
4422
4425
  const fields = root.entities.map((it) => it.fields.find((it2) => it2.column.option.autoIncrementHashId)).filter(error.nonNullable);
@@ -4459,7 +4462,7 @@ const generateIDEncoder = (root, content) => {
4459
4462
  return imports + makeEncoder + content + addition;
4460
4463
  };
4461
4464
 
4462
- const { createSourceFile, ScriptTarget } = ts__default;
4465
+ const { createSourceFile, ScriptTarget } = typescript__default;
4463
4466
  const generateMiddlewares = (root, content) => {
4464
4467
  const middlewares = error.unique(
4465
4468
  root.entities.flatMap((it) => [
@@ -5236,7 +5239,7 @@ const generate = async () => {
5236
5239
  await compileMigrationFiles();
5237
5240
  const files = getMigrationFileNames();
5238
5241
  const targetFile = files.find((it) => it === error.config().migration.target) || files[files.length - 1];
5239
- const store = (await createCurrentMigrationDataStore(targetFile)).serialize();
5242
+ const store = await getCurrentStore.getCurrentStore();
5240
5243
  const storeHandler = new DataStoreHandler(store);
5241
5244
  error.writeCurrentSchema(store);
5242
5245
  await new CodeGen_v2(storeHandler).generate();
@@ -5802,6 +5805,7 @@ try {
5802
5805
  });
5803
5806
  cli.command("migration:build", "compile migration files").action(migrationBuild);
5804
5807
  cli.command("generate", "generate files").action(generate);
5808
+ cli.command("generate:er", "generate mermaid er diagram").action(erDiagram.writeDiagram);
5805
5809
  cli.command("migration:create [name]", "generate new migration file").action(createMigration);
5806
5810
  cli.command("dump-db", "dump database schema").action(dumpDB);
5807
5811
  cli.command("init").action(init);
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,11 +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 ts from 'typescript';
12
12
  import * as esbuild from 'esbuild';
13
13
  import fs$1 from 'fs-extra';
14
14
  import 'js-yaml';
15
15
  import * as prettier from 'prettier';
16
+ import typescript from 'typescript';
17
+ import { getCurrentStore } from 'cli/commands/getCurrentStore';
16
18
  import 'sqlstring';
17
19
  import 'mysql2';
18
20
  import 'util';
@@ -31,7 +33,7 @@ const Console = {
31
33
  error: (msg) => {
32
34
  console$1.error(chalk.bold.red(msg));
33
35
  },
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
37
  log: (msg) => {
36
38
  console$1.log(msg);
37
39
  },
@@ -1321,7 +1323,6 @@ var __publicField$l = (obj, key, value) => {
1321
1323
  return value;
1322
1324
  };
1323
1325
  class StoreMigrator {
1324
- // eslint-disable-next-line @typescript-eslint/no-empty-function
1325
1326
  constructor() {
1326
1327
  __publicField$l(this, "tables", []);
1327
1328
  __publicField$l(this, "migrationQueue", []);
@@ -3018,7 +3019,9 @@ const getHashIdArgs = (entity, query) => {
3018
3019
  }
3019
3020
  const getHashIdArg = (arg, field) => {
3020
3021
  const columnName = field.column;
3021
- const hashIdOpt = entity.fields.find((e) => e.columnName === columnName)?.hashId;
3022
+ const hashIdOpt = entity.fields.find(
3023
+ (e) => e.columnName === columnName
3024
+ )?.hashId;
3022
3025
  if (!hashIdOpt)
3023
3026
  return null;
3024
3027
  return {
@@ -4300,7 +4303,7 @@ const makeWithFilter = (event, filters) => {
4300
4303
  );
4301
4304
  };
4302
4305
 
4303
- const { SyntaxKind: SyntaxKind$1 } = ts;
4306
+ const { SyntaxKind: SyntaxKind$1 } = typescript;
4304
4307
  const isImported = (sourceFile, type, paths) => {
4305
4308
  const importDeclarations = sourceFile.statements.filter(
4306
4309
  (it) => it.kind === SyntaxKind$1.ImportDeclaration
@@ -4322,7 +4325,7 @@ const isImported = (sourceFile, type, paths) => {
4322
4325
  });
4323
4326
  };
4324
4327
 
4325
- const { SyntaxKind } = ts;
4328
+ const { SyntaxKind } = typescript;
4326
4329
  const getExportedVariables = (sourceFile) => {
4327
4330
  return sourceFile.statements.filter(
4328
4331
  (it) => it.kind === SyntaxKind.VariableStatement && it.modifiers?.some(
@@ -4331,7 +4334,7 @@ const getExportedVariables = (sourceFile) => {
4331
4334
  );
4332
4335
  };
4333
4336
 
4334
- const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } = ts;
4337
+ const { createSourceFile: createSourceFile$2, ScriptTarget: ScriptTarget$2 } = typescript;
4335
4338
  const generateUserDefinedCondition = (root, content) => {
4336
4339
  const customConditionNames = unique(
4337
4340
  root.entities.flatMap((it) => [
@@ -4391,7 +4394,7 @@ const generateUserDefinedCondition = (root, content) => {
4391
4394
  return context + condition + content + addition;
4392
4395
  };
4393
4396
 
4394
- const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } = ts;
4397
+ const { createSourceFile: createSourceFile$1, ScriptTarget: ScriptTarget$1 } = typescript;
4395
4398
  const hashIds = "HashIds";
4396
4399
  const generateIDEncoder = (root, content) => {
4397
4400
  const fields = root.entities.map((it) => it.fields.find((it2) => it2.column.option.autoIncrementHashId)).filter(nonNullable);
@@ -4434,7 +4437,7 @@ const generateIDEncoder = (root, content) => {
4434
4437
  return imports + makeEncoder + content + addition;
4435
4438
  };
4436
4439
 
4437
- const { createSourceFile, ScriptTarget } = ts;
4440
+ const { createSourceFile, ScriptTarget } = typescript;
4438
4441
  const generateMiddlewares = (root, content) => {
4439
4442
  const middlewares = unique(
4440
4443
  root.entities.flatMap((it) => [
@@ -5211,7 +5214,7 @@ const generate = async () => {
5211
5214
  await compileMigrationFiles();
5212
5215
  const files = getMigrationFileNames();
5213
5216
  const targetFile = files.find((it) => it === config().migration.target) || files[files.length - 1];
5214
- const store = (await createCurrentMigrationDataStore(targetFile)).serialize();
5217
+ const store = await getCurrentStore();
5215
5218
  const storeHandler = new DataStoreHandler(store);
5216
5219
  writeCurrentSchema(store);
5217
5220
  await new CodeGen_v2(storeHandler).generate();
@@ -5777,6 +5780,7 @@ try {
5777
5780
  });
5778
5781
  cli.command("migration:build", "compile migration files").action(migrationBuild);
5779
5782
  cli.command("generate", "generate files").action(generate);
5783
+ cli.command("generate:er", "generate mermaid er diagram").action(writeDiagram);
5780
5784
  cli.command("migration:create [name]", "generate new migration file").action(createMigration);
5781
5785
  cli.command("dump-db", "dump database schema").action(dumpDB);
5782
5786
  cli.command("init").action(init);
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: (keyof T)[]) => {
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: (keyof T)[]) => {
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: (keyof T)[]) => {
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.21.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",
@@ -37,28 +37,29 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@apollo/server": "^4.9.3",
40
+ "@eslint/js": "^9.4.0",
41
+ "@types/eslint__js": "^8.42.3",
40
42
  "@types/fs-extra": "11.0.4",
41
43
  "@types/jest": "29.5.12",
42
44
  "@types/js-yaml": "4.0.9",
43
- "@types/node": "20.10.5",
45
+ "@types/node": "20.14.2",
44
46
  "@types/pluralize": "0.0.33",
45
- "@types/prettier": "2.7.3",
47
+ "@types/prettier": "3.0.0",
46
48
  "@types/sqlstring": "2.3.2",
47
- "@typescript-eslint/eslint-plugin": "6.21.0",
48
- "@typescript-eslint/parser": "6.21.0",
49
49
  "env-cmd": "10.1.0",
50
- "eslint": "8.56.0",
51
- "eslint-config-prettier": "9.1.0",
50
+ "eslint": "^9.4.0",
51
+ "eslint-config-prettier": "^9.1.0",
52
52
  "eslint-plugin-import": "^2.27.5",
53
- "eslint-plugin-prettier": "5.1.3",
53
+ "eslint-plugin-prettier": "^5.1.3",
54
54
  "husky": "8.0.3",
55
55
  "jest": "29.7.0",
56
- "lint-staged": "13.2.3",
56
+ "lint-staged": "13.3.0",
57
57
  "sasat": "link:./dist",
58
58
  "ts-jest": "29.1.4",
59
59
  "ts-node": "10.9.2",
60
60
  "tsconfig-paths": "4.2.0",
61
61
  "tsx": "^4.15.2",
62
+ "typescript-eslint": "^7.13.0",
62
63
  "unbuild": "^2.0.0"
63
64
  },
64
65
  "peerDependencies": {
@@ -71,7 +72,7 @@
71
72
  ]
72
73
  },
73
74
  "type": "module",
74
- "packageManager": "yarn@3.6.1",
75
+ "packageManager": "yarn@3.8.2",
75
76
  "exports": {
76
77
  ".": {
77
78
  "import": "./dist/index.mjs",