miqro 2.0.2 → 3.0.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.
Files changed (71) hide show
  1. package/README.md +18 -36
  2. package/build/cli.js +6 -0
  3. package/build/cmd-map.d.ts +79 -0
  4. package/{dist/cli.js → build/cmd-map.js} +22 -49
  5. package/{dist → build}/cmds/doc-json.d.ts +1 -1
  6. package/{dist → build}/cmds/doc-json.js +3 -3
  7. package/build/cmds/doc-md.d.ts +2 -0
  8. package/build/cmds/doc-md.js +17 -0
  9. package/{dist → build}/cmds/handler-main-new.js +23 -15
  10. package/build/cmds/help.d.ts +1 -0
  11. package/build/cmds/help.js +9 -0
  12. package/{dist → build}/cmds/new-test.js +13 -2
  13. package/{dist → build}/cmds/new.js +20 -15
  14. package/{dist → build}/cmds/serve.d.ts +1 -1
  15. package/{dist → build}/cmds/serve.js +12 -7
  16. package/build/utils/doc/json.d.ts +6 -0
  17. package/{dist/utils/doc/index.js → build/utils/doc/json.js} +2 -3
  18. package/build/utils/doc/md.d.ts +18 -0
  19. package/build/utils/doc/md.js +129 -0
  20. package/{dist → build}/utils/index.d.ts +7 -4
  21. package/{dist → build}/utils/index.js +20 -14
  22. package/package.json +13 -14
  23. package/dist/cmds/db-console.d.ts +0 -2
  24. package/dist/cmds/db-console.js +0 -38
  25. package/dist/cmds/db-createmodel.d.ts +0 -2
  26. package/dist/cmds/db-createmodel.js +0 -37
  27. package/dist/cmds/db-dump-data.d.ts +0 -2
  28. package/dist/cmds/db-dump-data.js +0 -43
  29. package/dist/cmds/db-init.d.ts +0 -2
  30. package/dist/cmds/db-init.js +0 -38
  31. package/dist/cmds/db-makemigrations.d.ts +0 -2
  32. package/dist/cmds/db-makemigrations.js +0 -14
  33. package/dist/cmds/db-migrate.d.ts +0 -2
  34. package/dist/cmds/db-migrate.js +0 -12
  35. package/dist/cmds/db-push-data.d.ts +0 -2
  36. package/dist/cmds/db-push-data.js +0 -79
  37. package/dist/cmds/db-sync-makemigrations.d.ts +0 -2
  38. package/dist/cmds/db-sync-makemigrations.js +0 -14
  39. package/dist/cmds/test.d.ts +0 -2
  40. package/dist/cmds/test.js +0 -15
  41. package/dist/utils/db/automigrations/index.d.ts +0 -2
  42. package/dist/utils/db/automigrations/index.js +0 -121
  43. package/dist/utils/db/automigrations/migrate.d.ts +0 -45
  44. package/dist/utils/db/automigrations/migrate.js +0 -750
  45. package/dist/utils/db/index.d.ts +0 -20
  46. package/dist/utils/db/index.js +0 -127
  47. package/dist/utils/doc/index.d.ts +0 -7
  48. /package/{dist → build}/cli.d.ts +0 -0
  49. /package/{dist → build}/cmds/config-bash.d.ts +0 -0
  50. /package/{dist → build}/cmds/config-bash.js +0 -0
  51. /package/{dist → build}/cmds/config-env.d.ts +0 -0
  52. /package/{dist → build}/cmds/config-env.js +0 -0
  53. /package/{dist → build}/cmds/config-init.d.ts +0 -0
  54. /package/{dist → build}/cmds/config-init.js +0 -0
  55. /package/{dist → build}/cmds/config.d.ts +0 -0
  56. /package/{dist → build}/cmds/config.js +0 -0
  57. /package/{dist → build}/cmds/handler-apiroute-new.d.ts +0 -0
  58. /package/{dist → build}/cmds/handler-apiroute-new.js +0 -0
  59. /package/{dist → build}/cmds/handler-main-new.d.ts +0 -0
  60. /package/{dist → build}/cmds/new-test.d.ts +0 -0
  61. /package/{dist → build}/cmds/new.d.ts +0 -0
  62. /package/{dist → build}/cmds/start.d.ts +0 -0
  63. /package/{dist → build}/cmds/start.js +0 -0
  64. /package/{dist → build}/cmds/watch.d.ts +0 -0
  65. /package/{dist → build}/cmds/watch.js +0 -0
  66. /package/{dist → build}/cmds/wc-new.d.ts +0 -0
  67. /package/{dist → build}/cmds/wc-new.js +0 -0
  68. /package/{dist → build}/index.d.ts +0 -0
  69. /package/{dist → build}/index.js +0 -0
  70. /package/{dist → build}/utils/templates.d.ts +0 -0
  71. /package/{dist → build}/utils/templates.js +0 -0
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makemigrationsImpl = exports.syncMakeMigrationsImpl = void 0;
4
- const core_1 = require("@miqro/core");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- const __1 = require("..");
8
- const migrate_1 = require("./migrate");
9
- const syncMakeMigrationsImpl = () => {
10
- // Windows support
11
- if (!process.env.PWD) {
12
- process.env.PWD = process.cwd();
13
- }
14
- const sequelizeRC = (0, __1.loadSequelizeRC)();
15
- // noinspection SpellCheckingInspection
16
- const logger = (0, core_1.getLogger)("makemigrations");
17
- try {
18
- if (!(0, fs_1.existsSync)(sequelizeRC["models-path"])) {
19
- logger.error("Can't find models directory. Use `sequelize init` to create it");
20
- return;
21
- }
22
- if (!(0, fs_1.existsSync)(sequelizeRC["migrations-path"])) {
23
- logger.error("Can't find migrations directory. Use `sequelize init` to create it");
24
- return;
25
- }
26
- // load last state
27
- let previousState;
28
- try {
29
- previousState = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")).toString());
30
- }
31
- catch (e) {
32
- previousState = {
33
- revision: 0,
34
- tables: {}
35
- };
36
- }
37
- const { modelsModule } = (0, __1.loadModels)({ ["models-path"]: sequelizeRC["models-path"] });
38
- // current state
39
- const currentState = {
40
- revision: previousState.revision + 1,
41
- tables: (0, migrate_1.reverseModels)(modelsModule.Sequelize, modelsModule.sequelize, modelsModule.sequelize.models, logger)
42
- };
43
- // backup _current file
44
- if ((0, fs_1.existsSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"))) {
45
- (0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current_bak.json"), (0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")));
46
- }
47
- // save current state
48
- currentState.revision = previousState.revision + 1;
49
- (0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"), JSON.stringify(currentState, null, 4));
50
- }
51
- catch (e) {
52
- logger.error(e);
53
- throw e;
54
- }
55
- };
56
- exports.syncMakeMigrationsImpl = syncMakeMigrationsImpl;
57
- // noinspection SpellCheckingInspection
58
- const makemigrationsImpl = () => {
59
- // Windows support
60
- if (!process.env.PWD) {
61
- process.env.PWD = process.cwd();
62
- }
63
- const sequelizeRC = (0, __1.loadSequelizeRC)();
64
- // noinspection SpellCheckingInspection
65
- const logger = (0, core_1.getLogger)("makemigrations");
66
- try {
67
- if (!(0, fs_1.existsSync)(sequelizeRC["models-path"])) {
68
- logger.error("Can't find models directory. Use `sequelize init` to create it");
69
- return;
70
- }
71
- if (!(0, fs_1.existsSync)(sequelizeRC["migrations-path"])) {
72
- logger.error("Can't find migrations directory. Use `sequelize init` to create it");
73
- return;
74
- }
75
- // load last state
76
- let previousState;
77
- try {
78
- previousState = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")).toString());
79
- }
80
- catch (e) {
81
- previousState = {
82
- revision: 0,
83
- tables: {}
84
- };
85
- }
86
- const { modelsModule } = (0, __1.loadModels)({ ["models-path"]: sequelizeRC["models-path"] });
87
- // current state
88
- const currentState = {
89
- revision: previousState.revision + 1,
90
- tables: (0, migrate_1.reverseModels)(modelsModule.Sequelize, modelsModule.sequelize, modelsModule.sequelize.models, logger)
91
- };
92
- const actions = (0, migrate_1.parseDifference)(previousState.tables, currentState.tables, logger);
93
- // sort actions
94
- (0, migrate_1.sortActions)(actions);
95
- const migration = (0, migrate_1.getMigration)(actions);
96
- if (migration.commandsUp.length === 0) {
97
- logger.info("No changes found");
98
- return null;
99
- }
100
- // log migration actions
101
- migration.consoleOut.forEach((v) => {
102
- logger.info("[Actions] " + v);
103
- });
104
- // backup _current file
105
- if ((0, fs_1.existsSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"))) {
106
- (0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current_bak.json"), (0, fs_1.readFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json")));
107
- }
108
- // save current state
109
- currentState.revision = previousState.revision + 1;
110
- (0, fs_1.writeFileSync)((0, path_1.join)(sequelizeRC["migrations-path"], "_current.json"), JSON.stringify(currentState, null, 4));
111
- // write migration to file
112
- const info = (0, migrate_1.writeMigration)(currentState.revision, migration, sequelizeRC["migrations-path"], "noname", "");
113
- logger.info(`New migration to revision ${currentState.revision} has been saved to file '${info.filename}'`);
114
- return info.filename;
115
- }
116
- catch (e) {
117
- logger.error(e);
118
- throw e;
119
- }
120
- };
121
- exports.makemigrationsImpl = makemigrationsImpl;
@@ -1,45 +0,0 @@
1
- interface TableMap {
2
- [tableName: string]: {
3
- tableName: string;
4
- schema: any;
5
- indexes: any;
6
- model?: any;
7
- options?: any;
8
- fields?: any[];
9
- };
10
- }
11
- export interface MigrationState {
12
- tables: TableMap;
13
- revision: number;
14
- }
15
- export declare const reverseModels: (sequelizeModule: any, sequelize: any, realModels: {
16
- [model: string]: any;
17
- }, logger: any) => TableMap;
18
- interface DiffAction {
19
- actionType: string;
20
- columnName?: string;
21
- attributeName?: any;
22
- fields?: string[];
23
- tableName?: any;
24
- attributes?: any;
25
- options?: any;
26
- depends?: any;
27
- }
28
- export declare const parseDifference: (previousState: TableMap, currentState: TableMap, logger: any) => DiffAction[];
29
- export declare const sortActions: (actions: DiffAction[]) => void;
30
- interface Migration {
31
- commandsUp: string[];
32
- consoleOut: string[];
33
- }
34
- export declare const getMigration: (actions: DiffAction[]) => Migration;
35
- interface WritenMigration {
36
- filename: string;
37
- info: {
38
- revision: number;
39
- name: string;
40
- created: Date;
41
- comment: string;
42
- };
43
- }
44
- export declare const writeMigration: (revision: number, migration: Migration, migrationsDir: string, name?: string, comment?: string) => WritenMigration;
45
- export {};