fib-orm 1.4.1 → 2.0.0
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/License +1 -1
- package/README.md +53 -0
- package/lib/cli/commands/ddlFrom.d.ts +2 -0
- package/lib/cli/commands/ddlFrom.js +74 -0
- package/lib/cli/commands/dumpModel.d.ts +2 -0
- package/lib/cli/commands/dumpModel.js +106 -0
- package/lib/cli/commands/escape.d.ts +2 -0
- package/lib/cli/commands/escape.js +68 -0
- package/lib/cli/commands/spinner.d.ts +2 -0
- package/lib/cli/commands/spinner.js +36 -0
- package/lib/cli/commands/upgrade.d.ts +2 -0
- package/lib/cli/commands/upgrade.js +65 -0
- package/lib/cli/helpers/ddl.d.ts +17 -0
- package/lib/cli/helpers/ddl.js +55 -0
- package/lib/cli/helpers/package.d.ts +26 -0
- package/lib/cli/helpers/package.js +56 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +18 -0
- package/lib/codepoints-map.json +762 -0
- package/lib/db-driver/Typo.d.ts +112 -0
- package/lib/db-driver/Typo.js +1 -0
- package/lib/db-driver/built-ins/base.class.d.ts +96 -0
- package/lib/db-driver/built-ins/base.class.js +186 -0
- package/lib/db-driver/built-ins/driver-dm.d.ts +18 -0
- package/lib/db-driver/built-ins/driver-dm.js +53 -0
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +24 -0
- package/lib/db-driver/built-ins/driver-mongodb.js +46 -0
- package/lib/db-driver/built-ins/driver-mysql.d.ts +18 -0
- package/lib/db-driver/built-ins/driver-mysql.js +37 -0
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +22 -0
- package/lib/db-driver/built-ins/driver-postgresql.js +76 -0
- package/lib/db-driver/built-ins/driver-redis.d.ts +12 -0
- package/lib/db-driver/built-ins/driver-redis.js +35 -0
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +17 -0
- package/lib/db-driver/built-ins/driver-sqlite.js +34 -0
- package/lib/db-driver/index.d.ts +3 -0
- package/lib/db-driver/index.js +4 -0
- package/lib/db-driver/utils.d.ts +14 -0
- package/lib/db-driver/utils.js +187 -0
- package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +12 -0
- package/lib/knex/deps/tarn/dist/PendingOperation.js +48 -0
- package/lib/knex/deps/tarn/dist/Pool.d.ts +97 -0
- package/lib/knex/deps/tarn/dist/Pool.js +516 -0
- package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +16 -0
- package/lib/knex/deps/tarn/dist/PromiseInspection.js +21 -0
- package/lib/knex/deps/tarn/dist/Resource.d.ts +9 -0
- package/lib/knex/deps/tarn/dist/Resource.js +19 -0
- package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +2 -0
- package/lib/knex/deps/tarn/dist/TimeoutError.js +5 -0
- package/lib/knex/deps/tarn/dist/tarn.d.ts +3 -0
- package/lib/knex/deps/tarn/dist/tarn.js +10 -0
- package/lib/knex/deps/tarn/dist/utils.d.ts +14 -0
- package/lib/knex/deps/tarn/dist/utils.js +60 -0
- package/lib/knex/knex.d.ts +2 -0
- package/lib/knex/knex.js +3 -0
- package/lib/knex/sandbox.d.ts +4 -0
- package/lib/knex/sandbox.js +22 -0
- package/lib/orm/Adapters.d.ts +3 -0
- package/lib/orm/Adapters.js +44 -0
- package/lib/orm/AggregateFunctions.d.ts +3 -0
- package/lib/orm/AggregateFunctions.js +176 -0
- package/lib/orm/Associations/Extend.d.ts +22 -0
- package/lib/orm/Associations/Extend.js +274 -0
- package/lib/orm/Associations/Many.d.ts +17 -0
- package/lib/orm/Associations/Many.js +569 -0
- package/lib/orm/Associations/One.d.ts +16 -0
- package/lib/orm/Associations/One.js +310 -0
- package/lib/orm/Associations/_utils.d.ts +15 -0
- package/lib/orm/Associations/_utils.js +52 -0
- package/lib/orm/ChainFind.d.ts +3 -0
- package/lib/orm/ChainFind.js +327 -0
- package/lib/orm/ChainInstance.d.ts +6 -0
- package/lib/orm/ChainInstance.js +73 -0
- package/lib/orm/Debug.d.ts +2 -0
- package/lib/orm/Debug.js +17 -0
- package/lib/orm/Drivers/DB/base.d.ts +3 -0
- package/lib/orm/Drivers/DB/base.js +3 -0
- package/lib/orm/Drivers/DB/dm.d.ts +11 -0
- package/lib/orm/Drivers/DB/dm.js +23 -0
- package/lib/orm/Drivers/DB/mysql.d.ts +11 -0
- package/lib/orm/Drivers/DB/mysql.js +23 -0
- package/lib/orm/Drivers/DB/postgres.d.ts +11 -0
- package/lib/orm/Drivers/DB/postgres.js +22 -0
- package/lib/orm/Drivers/DB/sqlite3.d.ts +16 -0
- package/lib/orm/Drivers/DB/sqlite3.js +39 -0
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
- package/lib/orm/Drivers/DML/_ddl-sql.js +51 -0
- package/lib/orm/Drivers/DML/_dml-helpers.d.ts +19 -0
- package/lib/orm/Drivers/DML/_dml-helpers.js +51 -0
- package/lib/orm/Drivers/DML/_shared.d.ts +9 -0
- package/lib/orm/Drivers/DML/_shared.js +38 -0
- package/lib/orm/Drivers/DML/_utils.d.ts +8 -0
- package/lib/orm/Drivers/DML/_utils.js +67 -0
- package/lib/orm/Drivers/DML/constants.d.ts +3 -0
- package/lib/orm/Drivers/DML/constants.js +2 -0
- package/lib/orm/Drivers/DML/dm.d.ts +2 -0
- package/lib/orm/Drivers/DML/dm.js +293 -0
- package/lib/orm/Drivers/DML/index.d.ts +4 -0
- package/lib/orm/Drivers/DML/index.js +6 -0
- package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
- package/lib/orm/Drivers/DML/mysql.js +251 -0
- package/lib/orm/Drivers/DML/postgres.d.ts +3 -0
- package/lib/orm/Drivers/DML/postgres.js +276 -0
- package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
- package/lib/orm/Drivers/DML/sqlite.js +266 -0
- package/lib/orm/Error.d.ts +11 -0
- package/lib/orm/Error.js +40 -0
- package/lib/orm/Helpers.d.ts +35 -0
- package/lib/orm/Helpers.js +233 -0
- package/lib/orm/Hook.d.ts +13 -0
- package/lib/orm/Hook.js +99 -0
- package/lib/orm/Instance.d.ts +2 -0
- package/lib/orm/Instance.js +697 -0
- package/lib/orm/LazyLoad.d.ts +4 -0
- package/lib/orm/LazyLoad.js +76 -0
- package/lib/orm/Model.d.ts +7 -0
- package/lib/orm/Model.js +971 -0
- package/lib/orm/ORM.d.ts +37 -0
- package/lib/orm/ORM.js +241 -0
- package/lib/orm/Patch/fib-cache.d.ts +40 -0
- package/lib/orm/Patch/fib-cache.js +2 -0
- package/lib/orm/Patch/plugin.d.ts +4 -0
- package/lib/orm/Patch/plugin.js +13 -0
- package/lib/orm/Property.d.ts +9 -0
- package/lib/orm/Property.js +71 -0
- package/lib/orm/Settings.d.ts +42 -0
- package/lib/orm/Settings.js +119 -0
- package/lib/orm/Singleton.d.ts +5 -0
- package/lib/orm/Singleton.js +72 -0
- package/lib/orm/Typo/Adapter.d.ts +5 -0
- package/lib/orm/Typo/Adapter.js +1 -0
- package/lib/orm/Typo/DMLDriver.d.ts +210 -0
- package/lib/orm/Typo/DMLDriver.js +1 -0
- package/lib/orm/Typo/Db.d.ts +38 -0
- package/lib/orm/Typo/Db.js +1 -0
- package/lib/orm/Typo/Error.d.ts +31 -0
- package/lib/orm/Typo/Error.js +1 -0
- package/lib/orm/Typo/ORM.d.ts +233 -0
- package/lib/orm/Typo/ORM.js +3 -0
- package/lib/orm/Typo/Validators.d.ts +32 -0
- package/lib/orm/Typo/Validators.js +2 -0
- package/lib/orm/Typo/_common.d.ts +38 -0
- package/lib/orm/Typo/_common.js +1 -0
- package/lib/orm/Typo/assoc.d.ts +221 -0
- package/lib/orm/Typo/assoc.js +1 -0
- package/lib/orm/Typo/hook.d.ts +42 -0
- package/lib/orm/Typo/hook.js +1 -0
- package/lib/orm/Typo/instance.d.ts +157 -0
- package/lib/orm/Typo/instance.js +1 -0
- package/lib/orm/Typo/model.d.ts +313 -0
- package/lib/orm/Typo/model.js +6 -0
- package/lib/orm/Typo/patch.d.ts +31 -0
- package/lib/orm/Typo/patch.js +1 -0
- package/lib/orm/Typo/property.d.ts +57 -0
- package/lib/orm/Typo/property.js +1 -0
- package/lib/orm/Typo/query.d.ts +216 -0
- package/lib/orm/Typo/query.js +1 -0
- package/lib/orm/Typo/settings.d.ts +35 -0
- package/lib/orm/Typo/settings.js +5 -0
- package/lib/orm/Typo/synchronous.d.ts +47 -0
- package/lib/orm/Typo/synchronous.js +1 -0
- package/lib/orm/Utilities.d.ts +179 -0
- package/lib/orm/Utilities.js +975 -0
- package/lib/orm/Validators.d.ts +34 -0
- package/lib/orm/Validators.js +100 -0
- package/lib/orm/Where/common.d.ts +1 -0
- package/lib/orm/Where/common.js +7 -0
- package/lib/orm/Where/filterDate.d.ts +11 -0
- package/lib/orm/Where/filterDate.js +58 -0
- package/lib/orm/index.d.ts +68 -0
- package/lib/orm/index.js +157 -0
- package/lib/orm-core/callback.d.ts +12 -0
- package/lib/orm-core/callback.js +1 -0
- package/lib/orm-core/dialect.d.ts +80 -0
- package/lib/orm-core/dialect.js +1 -0
- package/lib/orm-core/error.d.ts +16 -0
- package/lib/orm-core/error.js +29 -0
- package/lib/orm-core/index.d.ts +6 -0
- package/lib/orm-core/index.js +6 -0
- package/lib/orm-core/sync.d.ts +12 -0
- package/lib/orm-core/sync.js +1 -0
- package/lib/orm-core/utils.d.ts +1 -0
- package/lib/orm-core/utils.js +5 -0
- package/lib/orm-property/Property.d.ts +78 -0
- package/lib/orm-property/Property.js +1 -0
- package/lib/orm-property/Utils.d.ts +9 -0
- package/lib/orm-property/Utils.js +13 -0
- package/lib/orm-property/customTypes.d.ts +2 -0
- package/lib/orm-property/customTypes.js +13 -0
- package/lib/orm-property/index.d.ts +10 -0
- package/lib/orm-property/index.js +22 -0
- package/lib/orm-property/transformer.d.ts +5 -0
- package/lib/orm-property/transformer.js +10 -0
- package/lib/orm-property/transformers/dm.d.ts +29 -0
- package/lib/orm-property/transformers/dm.js +237 -0
- package/lib/orm-property/transformers/index.d.ts +4 -0
- package/lib/orm-property/transformers/index.js +5 -0
- package/lib/orm-property/transformers/mysql.d.ts +102 -0
- package/lib/orm-property/transformers/mysql.js +261 -0
- package/lib/orm-property/transformers/postgresql.d.ts +54 -0
- package/lib/orm-property/transformers/postgresql.js +189 -0
- package/lib/orm-property/transformers/sqlite.d.ts +19 -0
- package/lib/orm-property/transformers/sqlite.js +171 -0
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +40 -0
- package/lib/sql-ddl-sync/Dialects/dm.js +296 -0
- package/lib/sql-ddl-sync/Dialects/index.d.ts +7 -0
- package/lib/sql-ddl-sync/Dialects/index.js +7 -0
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +39 -0
- package/lib/sql-ddl-sync/Dialects/mysql.js +240 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +40 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.js +286 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +44 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.js +256 -0
- package/lib/sql-ddl-sync/SQL.d.ts +12 -0
- package/lib/sql-ddl-sync/SQL.js +108 -0
- package/lib/sql-ddl-sync/Typo/Collection.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/Collection.js +1 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.js +1 -0
- package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
- package/lib/sql-ddl-sync/Typo/Dialect.js +1 -0
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
- package/lib/sql-ddl-sync/Typo/Driver.js +1 -0
- package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
- package/lib/sql-ddl-sync/Typo/Query.js +1 -0
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
- package/lib/sql-ddl-sync/Typo/SQL.js +1 -0
- package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
- package/lib/sql-ddl-sync/Typo/_common.js +1 -0
- package/lib/sql-ddl-sync/Utils.d.ts +40 -0
- package/lib/sql-ddl-sync/Utils.js +217 -0
- package/lib/sql-ddl-sync/index.d.ts +87 -0
- package/lib/sql-ddl-sync/index.js +371 -0
- package/lib/sql-query/Comparators.d.ts +3 -0
- package/lib/sql-query/Comparators.js +94 -0
- package/lib/sql-query/Create.d.ts +35 -0
- package/lib/sql-query/Create.js +77 -0
- package/lib/sql-query/Dialects/dm.d.ts +3 -0
- package/lib/sql-query/Dialects/dm.js +74 -0
- package/lib/sql-query/Dialects/index.d.ts +10 -0
- package/lib/sql-query/Dialects/index.js +12 -0
- package/lib/sql-query/Dialects/mssql.d.ts +3 -0
- package/lib/sql-query/Dialects/mssql.js +73 -0
- package/lib/sql-query/Dialects/mysql.d.ts +3 -0
- package/lib/sql-query/Dialects/mysql.js +100 -0
- package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
- package/lib/sql-query/Dialects/postgresql.js +76 -0
- package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
- package/lib/sql-query/Dialects/sqlite.js +61 -0
- package/lib/sql-query/Helpers.d.ts +38 -0
- package/lib/sql-query/Helpers.js +259 -0
- package/lib/sql-query/Insert.d.ts +12 -0
- package/lib/sql-query/Insert.js +33 -0
- package/lib/sql-query/Query.d.ts +29 -0
- package/lib/sql-query/Query.js +119 -0
- package/lib/sql-query/Remove.d.ts +16 -0
- package/lib/sql-query/Remove.js +93 -0
- package/lib/sql-query/Select.d.ts +62 -0
- package/lib/sql-query/Select.js +533 -0
- package/lib/sql-query/Set.d.ts +4 -0
- package/lib/sql-query/Set.js +16 -0
- package/lib/sql-query/Typo/Aggregation.d.ts +32 -0
- package/lib/sql-query/Typo/Aggregation.js +1 -0
- package/lib/sql-query/Typo/Comparators.d.ts +140 -0
- package/lib/sql-query/Typo/Comparators.js +1 -0
- package/lib/sql-query/Typo/Dialect.d.ts +39 -0
- package/lib/sql-query/Typo/Dialect.js +1 -0
- package/lib/sql-query/Typo/Field.d.ts +8 -0
- package/lib/sql-query/Typo/Field.js +1 -0
- package/lib/sql-query/Typo/Helper.d.ts +4 -0
- package/lib/sql-query/Typo/Helper.js +1 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.js +1 -0
- package/lib/sql-query/Typo/Query.d.ts +34 -0
- package/lib/sql-query/Typo/Query.js +16 -0
- package/lib/sql-query/Typo/Sql.d.ts +143 -0
- package/lib/sql-query/Typo/Sql.js +1 -0
- package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
- package/lib/sql-query/Typo/SubQuery.js +1 -0
- package/lib/sql-query/Typo/index.d.ts +9 -0
- package/lib/sql-query/Typo/index.js +1 -0
- package/lib/sql-query/Update.d.ts +15 -0
- package/lib/sql-query/Update.js +38 -0
- package/lib/sql-query/Where.d.ts +4 -0
- package/lib/sql-query/Where.js +280 -0
- package/package.json +72 -36
- package/.travis.yml +0 -14
- package/@types/index.d.ts +0 -193
- package/@types/orm_mirror/orm.d.ts +0 -275
- package/@types/orm_mirror/sql-query.d.ts +0 -79
- package/Readme.md +0 -843
- package/lib/index.js +0 -13
- package/lib/modules/mysql.js +0 -35
- package/lib/modules/sqlite3.js +0 -27
- package/lib/patch.js +0 -271
package/License
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2018 Richard and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
## fib-orm
|
|
2
|
+
|
|
3
|
+
ORM for [fibjs](https://fibjs.org) — a unified ORM package supporting SQLite, MySQL, and PostgreSQL.
|
|
4
|
+
|
|
5
|
+
### Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install fib-orm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Quick Start
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const ORM = require('fib-orm');
|
|
15
|
+
|
|
16
|
+
const db = ORM.connectSync('sqlite:test.db');
|
|
17
|
+
|
|
18
|
+
const User = db.define('user', {
|
|
19
|
+
name: String,
|
|
20
|
+
age: Number
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
db.syncSync();
|
|
24
|
+
|
|
25
|
+
User.createSync({ name: 'Alice', age: 30 });
|
|
26
|
+
const users = User.findSync();
|
|
27
|
+
console.log(users);
|
|
28
|
+
|
|
29
|
+
db.closeSync();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Build
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm run build
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Test
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# SQLite
|
|
42
|
+
ORM_PROTOCOL=sqlite fibjs test
|
|
43
|
+
|
|
44
|
+
# MySQL
|
|
45
|
+
ORM_PROTOCOL=mysql fibjs test
|
|
46
|
+
|
|
47
|
+
# PostgreSQL
|
|
48
|
+
ORM_PROTOCOL=postgres fibjs test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### License
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const make_cli_1 = require("@fibcli/make-cli");
|
|
5
|
+
const index_1 = require("../../db-driver/index");
|
|
6
|
+
const index_2 = require("../../sql-ddl-sync/index");
|
|
7
|
+
const ddl_1 = require("../helpers/ddl");
|
|
8
|
+
exports.default = (0, make_cli_1.wrapSubcommand)({
|
|
9
|
+
name: 'ddlFrom',
|
|
10
|
+
aliases: [
|
|
11
|
+
'ddlfrom'
|
|
12
|
+
],
|
|
13
|
+
inputs: {
|
|
14
|
+
required: '<connection>',
|
|
15
|
+
optional: [
|
|
16
|
+
'[tableName]'
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
examples: [
|
|
20
|
+
'orm ddlFrom mysql://root:@localhost:3306/test',
|
|
21
|
+
],
|
|
22
|
+
options: {
|
|
23
|
+
'-P, --pool [pool]': 'whether use connection pool or not',
|
|
24
|
+
'-O, --out [outPath]': 'path to output json file',
|
|
25
|
+
},
|
|
26
|
+
description: `read columns information from database, and generate ddl file`,
|
|
27
|
+
onAction: ([connection, [tableName]], options) => {
|
|
28
|
+
const driver = index_1.Driver.create(connection);
|
|
29
|
+
const sync = new index_2.Sync({ dbdriver: driver });
|
|
30
|
+
let outJson = '';
|
|
31
|
+
if (options.out) {
|
|
32
|
+
if (options.out === true) {
|
|
33
|
+
outJson = `./${driver.type}-${driver.config.database.replace(/[\.|\/]/g, '_')}.json`;
|
|
34
|
+
}
|
|
35
|
+
else if (typeof options.out === 'string') {
|
|
36
|
+
outJson = options.out;
|
|
37
|
+
}
|
|
38
|
+
if (outJson) {
|
|
39
|
+
outJson = path.resolve(process.cwd(), outJson);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let tableNames = [];
|
|
43
|
+
if (tableName) {
|
|
44
|
+
if (!sync.Dialect.hasCollectionSync(driver, tableName))
|
|
45
|
+
throw new Error(`[ddlFrom] table ${tableName} doen't exist!`);
|
|
46
|
+
tableNames = [tableName];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
switch (driver.type) {
|
|
50
|
+
case 'psql':
|
|
51
|
+
case 'mysql':
|
|
52
|
+
case 'sqlite':
|
|
53
|
+
tableNames = (0, ddl_1.getAllTableNames)(driver);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
if (!tableName) {
|
|
57
|
+
throw new Error('[ddlFrom] tableName is required!');
|
|
58
|
+
}
|
|
59
|
+
tableNames = [tableName];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const tableDDLs = (0, ddl_1.getTableDDLs)(sync, { tableNames });
|
|
63
|
+
if (outJson) {
|
|
64
|
+
console.notice(`[ddlFrom] try to write to ${outJson}...`);
|
|
65
|
+
fs.mkdir(path.dirname(outJson), { recursive: true });
|
|
66
|
+
fs.writeFile(outJson, JSON.stringify(tableDDLs, null, 2));
|
|
67
|
+
console.notice(`[ddlFrom] write json to ${outJson} success!`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console.log('[ddlFrom] tableDDLs:');
|
|
71
|
+
console.log(JSON.stringify(tableDDLs, null, 2));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const make_cli_1 = require("@fibcli/make-cli");
|
|
5
|
+
const ORM = require("../../orm/index");
|
|
6
|
+
const index_1 = require("../../sql-ddl-sync/index");
|
|
7
|
+
const Diff = require("diff");
|
|
8
|
+
const ddl_1 = require("../helpers/ddl");
|
|
9
|
+
function alphaBetKeySort(obj) {
|
|
10
|
+
if (!obj)
|
|
11
|
+
return obj;
|
|
12
|
+
return Object.keys(obj).sort().reduce((acc, key) => {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
acc[key] = obj[key];
|
|
15
|
+
return acc;
|
|
16
|
+
}, {});
|
|
17
|
+
}
|
|
18
|
+
exports.default = (0, make_cli_1.wrapSubcommand)({
|
|
19
|
+
name: 'dumpModel',
|
|
20
|
+
inputs: {
|
|
21
|
+
required: '<modelFile>',
|
|
22
|
+
optional: [
|
|
23
|
+
'[modelFile]'
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
examples: [],
|
|
27
|
+
options: {
|
|
28
|
+
'-O, --out [outPath]': 'path to output json file',
|
|
29
|
+
'--sync': 'sync user definition to database',
|
|
30
|
+
'--no-alphabet': 'sort properties alphabetically on patch',
|
|
31
|
+
},
|
|
32
|
+
description: `read columns information from database, and generate ddl file`,
|
|
33
|
+
onAction: ([modelFile], options) => {
|
|
34
|
+
modelFile = path.resolve(process.cwd(), modelFile);
|
|
35
|
+
const jsonDiffName = path.basename(modelFile, '.js') + '-dump.json';
|
|
36
|
+
const diffOutDir = path.dirname(modelFile);
|
|
37
|
+
const diffOutput = path.resolve(diffOutDir, jsonDiffName);
|
|
38
|
+
if (!fs.exists(modelFile)) {
|
|
39
|
+
throw new Error(`[dumpModel] model file not found: ${modelFile}`);
|
|
40
|
+
}
|
|
41
|
+
let modelFunc = require(modelFile);
|
|
42
|
+
if (typeof modelFunc !== 'function') {
|
|
43
|
+
if (typeof modelFunc.default === 'function')
|
|
44
|
+
modelFunc = modelFunc.default;
|
|
45
|
+
}
|
|
46
|
+
if (typeof modelFunc !== 'function') {
|
|
47
|
+
throw new Error(`[dumpModel] model function not found, it's typeof ${typeof modelFunc}`);
|
|
48
|
+
}
|
|
49
|
+
const { orm } = modelFunc(ORM);
|
|
50
|
+
if (options.sync) {
|
|
51
|
+
orm.syncSync();
|
|
52
|
+
}
|
|
53
|
+
const sync = new index_1.Sync({ dbdriver: orm.driver.sqlDriver });
|
|
54
|
+
const modelReports = {};
|
|
55
|
+
const modelByTable = {};
|
|
56
|
+
for (let k in orm.models) {
|
|
57
|
+
const model = orm.models[k];
|
|
58
|
+
modelByTable[model.table] = model;
|
|
59
|
+
}
|
|
60
|
+
(0, ddl_1.getTableDDLs)(sync, {
|
|
61
|
+
afterGetTableDDL: (ddl) => {
|
|
62
|
+
var _a;
|
|
63
|
+
const userDefinedProperties = ((_a = modelByTable[ddl.collection]) === null || _a === void 0 ? void 0 : _a.allProperties) || {};
|
|
64
|
+
const dataStoreProperties = ddl.properties;
|
|
65
|
+
const tPatchBaseName = `properties-for-t-[${ddl.collection}]`;
|
|
66
|
+
const tablePatchFile = path.resolve(diffOutDir, `./${tPatchBaseName}.patch`);
|
|
67
|
+
const propritiesDiff = Object.entries(dataStoreProperties).reduce((accu, [mapsTo, prop]) => {
|
|
68
|
+
let udP = userDefinedProperties[mapsTo] || null;
|
|
69
|
+
if (options.alphabet) {
|
|
70
|
+
udP = alphaBetKeySort(udP);
|
|
71
|
+
userDefinedProperties[mapsTo] = udP;
|
|
72
|
+
prop = alphaBetKeySort(prop);
|
|
73
|
+
dataStoreProperties[mapsTo] = prop;
|
|
74
|
+
}
|
|
75
|
+
const changes = Diff.diffJson(udP, prop);
|
|
76
|
+
const patchBaseName = `${tPatchBaseName}-p-${mapsTo}`;
|
|
77
|
+
const patch = Diff.createTwoFilesPatch(`${patchBaseName}-from-database.json`, `${patchBaseName}-user-defined.json`, JSON.stringify(prop, null, 2), JSON.stringify(udP, null, 2));
|
|
78
|
+
accu.push({
|
|
79
|
+
name: mapsTo,
|
|
80
|
+
mapsTo,
|
|
81
|
+
changes,
|
|
82
|
+
patch
|
|
83
|
+
});
|
|
84
|
+
return accu;
|
|
85
|
+
}, []);
|
|
86
|
+
const patch = Diff.createTwoFilesPatch(`${tPatchBaseName}-from-database.json`, `${tPatchBaseName}-user-defined.json`, JSON.stringify(dataStoreProperties, null, 2), JSON.stringify(userDefinedProperties, null, 2));
|
|
87
|
+
fs.writeFile(tablePatchFile, patch);
|
|
88
|
+
modelReports[ddl.collection] = {
|
|
89
|
+
propritiesDiff,
|
|
90
|
+
userDefinedProperties,
|
|
91
|
+
dataStoreProperties,
|
|
92
|
+
dataStoreRaw: ddl.rawColumns,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
const dumpObj = {
|
|
97
|
+
connection: sync.dbdriver.uri,
|
|
98
|
+
driverType: sync.dbdriver.type,
|
|
99
|
+
modelReports,
|
|
100
|
+
};
|
|
101
|
+
console.notice(`[dumpModel] try to write to ${diffOutput}...`);
|
|
102
|
+
fs.mkdir(path.dirname(diffOutput), { recursive: true });
|
|
103
|
+
fs.writeFile(diffOutput, JSON.stringify(dumpObj, null, 2));
|
|
104
|
+
console.notice(`[dumpModel] write json to ${diffOutput} success!`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
// import fs = require('fs');
|
|
3
|
+
// import path = require('path');
|
|
4
|
+
// import coroutine = require('coroutine');
|
|
5
|
+
const chalk = require("@fibjs/chalk");
|
|
6
|
+
const make_cli_1 = require("@fibcli/make-cli");
|
|
7
|
+
const Query_1 = require("../../sql-query/Query");
|
|
8
|
+
const VALID_DIALECTS = ['mysql', 'sqlite', 'postgresql', 'mssql', 'dm'];
|
|
9
|
+
const VALID_TYPES = ['sql', 'val', 'id'];
|
|
10
|
+
const cmd = (0, make_cli_1.wrapSubcommand)({
|
|
11
|
+
name: 'escapeSQL',
|
|
12
|
+
aliases: [
|
|
13
|
+
'escape'
|
|
14
|
+
],
|
|
15
|
+
inputs: {
|
|
16
|
+
required: '<sqlstring>',
|
|
17
|
+
rest: '[...args]'
|
|
18
|
+
},
|
|
19
|
+
examples: [],
|
|
20
|
+
options: {
|
|
21
|
+
'-d, --dialect-type [dialectType]': `dialect type, support ${VALID_DIALECTS.map(d => `'${d}'`).join(', ')}`,
|
|
22
|
+
'-t, --type [escapeType]': `escape type, support ${VALID_TYPES.map(t => `'${t}'`).join(', ')}`,
|
|
23
|
+
},
|
|
24
|
+
description: `escape SQL string with given arguments`,
|
|
25
|
+
onAction: ([sqlstring, , rest], options) => {
|
|
26
|
+
const dialectType = options.dialectType || 'mysql';
|
|
27
|
+
if (!VALID_DIALECTS.includes(dialectType)) {
|
|
28
|
+
throw new Error(`[escape] invalid dialect type: ${dialectType}`);
|
|
29
|
+
}
|
|
30
|
+
const escapeType = options.type || 'sql';
|
|
31
|
+
if (!VALID_TYPES.includes(escapeType)) {
|
|
32
|
+
throw new Error(`[escape] invalid escape type: ${escapeType}`);
|
|
33
|
+
}
|
|
34
|
+
VALID_TYPES;
|
|
35
|
+
const query = new Query_1.Query({ dialect: dialectType });
|
|
36
|
+
switch (escapeType) {
|
|
37
|
+
default:
|
|
38
|
+
case 'sql': {
|
|
39
|
+
const result = query.escape(sqlstring, rest);
|
|
40
|
+
console.log(`dialect-type: ${chalk.blue(dialectType)}`);
|
|
41
|
+
console.log(`args(${rest.length}): ${chalk.blue(rest.join(' '))}`);
|
|
42
|
+
console.log();
|
|
43
|
+
console.log(`input-sql: \t ${chalk.yellow(sqlstring)}`);
|
|
44
|
+
console.log(`escaped-sql:\t ${chalk.green(result)}`);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'val': {
|
|
48
|
+
const result = query.escapeVal(sqlstring);
|
|
49
|
+
console.log(`dialect-type: ${chalk.blue(dialectType)}`);
|
|
50
|
+
// console.log(`args(${rest.length}): ${chalk.blue(rest.join(' '))}`)
|
|
51
|
+
console.log();
|
|
52
|
+
console.log(`input-value: \t ${chalk.yellow(sqlstring)}`);
|
|
53
|
+
console.log(`escaped-value:\t ${chalk.green(result)}`);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'id': {
|
|
57
|
+
const result = query.escapeId(sqlstring);
|
|
58
|
+
console.log(`dialect-type: ${chalk.blue(dialectType)}`);
|
|
59
|
+
// console.log(`args(${rest.length}): ${chalk.blue(rest.join(' '))}`)
|
|
60
|
+
console.log();
|
|
61
|
+
console.log(`input-id: \t ${chalk.yellow(sqlstring)}`);
|
|
62
|
+
console.log(`escaped-id:\t ${chalk.green(result)}`);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
exports.default = cmd;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const logUpdate = require("@fibcli/log-update");
|
|
3
|
+
const cliSpinners = require("@fibcli/cli-spinners");
|
|
4
|
+
const make_cli_1 = require("@fibcli/make-cli");
|
|
5
|
+
const allSpinnerType = Object.keys(cliSpinners);
|
|
6
|
+
const DFLT_SPINNER_TYPE = 'dots';
|
|
7
|
+
exports.default = (0, make_cli_1.wrapSubcommand)({
|
|
8
|
+
name: 'spinner',
|
|
9
|
+
inputs: {
|
|
10
|
+
optional: [
|
|
11
|
+
'[text]'
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
examples: [],
|
|
15
|
+
options: {
|
|
16
|
+
'-s, --spinner-type [spinnerType]': {
|
|
17
|
+
desc: `type of spinner, valid keys: ${allSpinnerType.join(', ')}`,
|
|
18
|
+
default: DFLT_SPINNER_TYPE
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
description: `just run spinner`,
|
|
22
|
+
onAction: ([, [text]], options) => {
|
|
23
|
+
text = text || ' Unicorns';
|
|
24
|
+
let spinnerType = options.spinnerType;
|
|
25
|
+
if (!spinnerType || allSpinnerType.indexOf(spinnerType) === -1) {
|
|
26
|
+
console.warn(`[spinner] type '${spinnerType}' invalid, correct to ${DFLT_SPINNER_TYPE}`);
|
|
27
|
+
spinnerType = DFLT_SPINNER_TYPE;
|
|
28
|
+
}
|
|
29
|
+
const spinner = cliSpinners[spinnerType];
|
|
30
|
+
let i = 0;
|
|
31
|
+
setInterval(() => {
|
|
32
|
+
const { frames } = spinner;
|
|
33
|
+
logUpdate(`${frames[i = ++i % frames.length]}${text}`);
|
|
34
|
+
}, spinner.interval);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const child_process = require("child_process");
|
|
3
|
+
const chalk = require("@fibjs/chalk");
|
|
4
|
+
const ora_1 = require("@fibcli/ora");
|
|
5
|
+
const make_cli_1 = require("@fibcli/make-cli");
|
|
6
|
+
const package_1 = require("../helpers/package");
|
|
7
|
+
const LOGPREFIX = `[upgrade]`;
|
|
8
|
+
exports.default = (0, make_cli_1.wrapSubcommand)({
|
|
9
|
+
name: 'upgrade',
|
|
10
|
+
aliases: [],
|
|
11
|
+
inputs: {
|
|
12
|
+
optional: [],
|
|
13
|
+
},
|
|
14
|
+
examples: [],
|
|
15
|
+
options: {},
|
|
16
|
+
description: `check & upgrade orm cli to latest version.`,
|
|
17
|
+
onAction: ([]) => {
|
|
18
|
+
const pkgInfo = (0, package_1.parsePkgInfo)();
|
|
19
|
+
const checkResult = (0, package_1.checkUpgrade)({
|
|
20
|
+
pkgCurrentVersion: '1.3.0', // leave here to debug
|
|
21
|
+
// pkgCurrentVersion: pkgInfo.version,
|
|
22
|
+
});
|
|
23
|
+
if (checkResult.errCode) {
|
|
24
|
+
console.log(`${chalk.blue(LOGPREFIX)} check upgrade failed!`);
|
|
25
|
+
console.error(checkResult.message);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const result = checkResult.result;
|
|
29
|
+
console.log();
|
|
30
|
+
console.log(`${chalk.blue(LOGPREFIX)} local version : ${chalk.green(result.currentVersion)}`);
|
|
31
|
+
console.log(`${chalk.blue(LOGPREFIX)} latest version : ${chalk.green(result.latestVersion)}`);
|
|
32
|
+
if (result.needUpgrade) {
|
|
33
|
+
console.log();
|
|
34
|
+
let answer = console.readLine('will you upgrade to latest version for you, confirm? (Y/N)');
|
|
35
|
+
answer = answer || 'N';
|
|
36
|
+
const upgradeSpinner = (0, ora_1.default)({});
|
|
37
|
+
switch (answer) {
|
|
38
|
+
case 'Y':
|
|
39
|
+
case 'y':
|
|
40
|
+
case 'Yes':
|
|
41
|
+
console.log(`${chalk.blue(LOGPREFIX)} will upgrade for you...`);
|
|
42
|
+
console.log();
|
|
43
|
+
upgradeSpinner.color = 'green';
|
|
44
|
+
upgradeSpinner.text = `${chalk.blue(LOGPREFIX)} upgrading...`;
|
|
45
|
+
upgradeSpinner.start();
|
|
46
|
+
require('coroutine').sleep(1000);
|
|
47
|
+
child_process.run('npm i -g fib-orm');
|
|
48
|
+
upgradeSpinner.stop();
|
|
49
|
+
// need to upgrade to latest version
|
|
50
|
+
console.log();
|
|
51
|
+
console.log(`${chalk.blue(LOGPREFIX)} upgrade finished`);
|
|
52
|
+
break;
|
|
53
|
+
case 'N':
|
|
54
|
+
case 'n':
|
|
55
|
+
case 'No':
|
|
56
|
+
default:
|
|
57
|
+
console.log(`${chalk.blue(LOGPREFIX)} nothing to do.`);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log(chalk.green `${chalk.blue(LOGPREFIX)} orm-cli installation is up-to date!`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IDbDriver } from "../../db-driver/index";
|
|
2
|
+
import { Sync } from '../../sql-ddl-sync/index';
|
|
3
|
+
export declare function getAllTableNames(driver: IDbDriver.ISQLDriver): string[];
|
|
4
|
+
export type IModelProperties = ReturnType<Sync['Dialect']['getCollectionPropertiesSync']>;
|
|
5
|
+
export type IRawColumns = ReturnType<Sync['Dialect']['getCollectionColumnsSync']>;
|
|
6
|
+
export declare function getTableDDLs(sync: Sync, { tableNames, afterGetTableDDL }?: {
|
|
7
|
+
tableNames?: string[];
|
|
8
|
+
afterGetTableDDL?: (ddl: {
|
|
9
|
+
collection: string;
|
|
10
|
+
properties: IModelProperties;
|
|
11
|
+
rawColumns: IRawColumns;
|
|
12
|
+
}) => void;
|
|
13
|
+
}): {
|
|
14
|
+
collection: string;
|
|
15
|
+
rawColumns: unknown[];
|
|
16
|
+
properties: IModelProperties;
|
|
17
|
+
}[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.getTableDDLs = exports.getAllTableNames = void 0;
|
|
3
|
+
const coroutine = require("coroutine");
|
|
4
|
+
function getAllTableNames(driver) {
|
|
5
|
+
let tableNames = [];
|
|
6
|
+
switch (driver.type) {
|
|
7
|
+
case 'psql': {
|
|
8
|
+
const result = driver.execute('SELECT * FROM information_schema.tables');
|
|
9
|
+
result.forEach((x) => {
|
|
10
|
+
// skip system tables
|
|
11
|
+
if (x.table_name.startsWith('pg_'))
|
|
12
|
+
return;
|
|
13
|
+
// skip non public tables
|
|
14
|
+
if (x.table_schema !== 'public')
|
|
15
|
+
return;
|
|
16
|
+
tableNames.push(x.table_name);
|
|
17
|
+
});
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case 'mysql': {
|
|
21
|
+
const result = driver.execute('show tables;');
|
|
22
|
+
tableNames = result.reduce((accu, x) => (accu.push(Object.entries(x)[0][1]),
|
|
23
|
+
accu), []);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case 'sqlite': {
|
|
27
|
+
const result = driver.execute(`SELECT name FROM sqlite_schema WHERE type='table' ORDER BY name`);
|
|
28
|
+
result.forEach((x) => {
|
|
29
|
+
// skip system tables
|
|
30
|
+
if (x.name.startsWith('sqlite_'))
|
|
31
|
+
return;
|
|
32
|
+
tableNames.push(x.name);
|
|
33
|
+
});
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`[getAllTableNames] unsupported driver type: ${driver.type}`);
|
|
38
|
+
}
|
|
39
|
+
return tableNames;
|
|
40
|
+
}
|
|
41
|
+
exports.getAllTableNames = getAllTableNames;
|
|
42
|
+
function getTableDDLs(sync, { tableNames, afterGetTableDDL } = {}) {
|
|
43
|
+
tableNames = (tableNames === null || tableNames === void 0 ? void 0 : tableNames.length) ? tableNames : getAllTableNames(sync.dbdriver);
|
|
44
|
+
const tableDDLs = coroutine.parallel(tableNames, (tableName) => {
|
|
45
|
+
const ddl = {
|
|
46
|
+
collection: tableName,
|
|
47
|
+
properties: sync.Dialect.getCollectionPropertiesSync(sync.dbdriver, tableName),
|
|
48
|
+
rawColumns: sync.Dialect.getCollectionColumnsSync(sync.dbdriver, tableName),
|
|
49
|
+
};
|
|
50
|
+
afterGetTableDDL === null || afterGetTableDDL === void 0 ? void 0 : afterGetTableDDL(ddl);
|
|
51
|
+
return ddl;
|
|
52
|
+
});
|
|
53
|
+
return tableDDLs;
|
|
54
|
+
}
|
|
55
|
+
exports.getTableDDLs = getTableDDLs;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
export declare function parsePkgInfo(filepath?: string): Record<string, string | boolean | number | object> & {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getPackgageNpmInfo({ registry, pkgName }?: {
|
|
7
|
+
registry?: string;
|
|
8
|
+
pkgName?: string;
|
|
9
|
+
}): Class_HttpResponse;
|
|
10
|
+
export declare function checkUpgrade({ pkgCurrentVersion }: {
|
|
11
|
+
pkgCurrentVersion: string;
|
|
12
|
+
}): {
|
|
13
|
+
errCode: number;
|
|
14
|
+
message: string;
|
|
15
|
+
response: Class_HttpResponse;
|
|
16
|
+
result?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
errCode: number;
|
|
19
|
+
message: string;
|
|
20
|
+
result: {
|
|
21
|
+
latestVersion: string;
|
|
22
|
+
currentVersion: string;
|
|
23
|
+
needUpgrade: boolean;
|
|
24
|
+
};
|
|
25
|
+
response?: undefined;
|
|
26
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.checkUpgrade = exports.getPackgageNpmInfo = exports.parsePkgInfo = void 0;
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
const ssl = require("ssl");
|
|
7
|
+
ssl.loadRootCerts();
|
|
8
|
+
const semver = require("semver");
|
|
9
|
+
const PKGJSON_FILE = path.resolve(__dirname, '../../package.json');
|
|
10
|
+
function parsePkgInfo(filepath = PKGJSON_FILE) {
|
|
11
|
+
return JSON.parse(fs.readFile(filepath).toString());
|
|
12
|
+
}
|
|
13
|
+
exports.parsePkgInfo = parsePkgInfo;
|
|
14
|
+
const PKGJSON = parsePkgInfo();
|
|
15
|
+
function getPackgageNpmInfo({ registry = 'https://registry.npmjs.org', pkgName = PKGJSON.name } = {}) {
|
|
16
|
+
const pkgInfo = parsePkgInfo();
|
|
17
|
+
return http.get(`${registry}/${pkgName}`, {});
|
|
18
|
+
}
|
|
19
|
+
exports.getPackgageNpmInfo = getPackgageNpmInfo;
|
|
20
|
+
function checkUpgrade({ pkgCurrentVersion }) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
const response = getPackgageNpmInfo();
|
|
23
|
+
if (response.statusCode !== 200) {
|
|
24
|
+
return {
|
|
25
|
+
errCode: 1,
|
|
26
|
+
message: `statusCode(${response.statusCode}) error: ${response.statusMessage}`,
|
|
27
|
+
response
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const npmRepoInfo = response.json();
|
|
31
|
+
let latestVersion;
|
|
32
|
+
latestVersion = npmRepoInfo['dist-tags'].latest;
|
|
33
|
+
if (!latestVersion && npmRepoInfo['time']) {
|
|
34
|
+
latestVersion = (_b = (_a = Object.entries(npmRepoInfo['time'])
|
|
35
|
+
.filter(([k]) => ['created', 'modified'].includes(k))
|
|
36
|
+
.sort(([, d1], [, d2]) => {
|
|
37
|
+
return (new Date(d1)).getTime() - (new Date(d2)).getTime();
|
|
38
|
+
})) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0];
|
|
39
|
+
}
|
|
40
|
+
if (!latestVersion && npmRepoInfo['versions']) {
|
|
41
|
+
latestVersion = (_c = Object.keys(npmRepoInfo['versions'])
|
|
42
|
+
.sort((v1, v2) => {
|
|
43
|
+
return semver.gt(v1, v2) ? 1 : -1;
|
|
44
|
+
})) === null || _c === void 0 ? void 0 : _c[0];
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
errCode: 0,
|
|
48
|
+
message: 'ok',
|
|
49
|
+
result: {
|
|
50
|
+
latestVersion,
|
|
51
|
+
currentVersion: pkgCurrentVersion,
|
|
52
|
+
needUpgrade: !semver.gte(pkgCurrentVersion, latestVersion)
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.checkUpgrade = checkUpgrade;
|
package/lib/cli/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env fibjs
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pkg = require('../package.json');
|
|
4
|
+
const getCli = require("@fxjs/cli");
|
|
5
|
+
const upgrade_1 = require("./commands/upgrade");
|
|
6
|
+
const spinner_1 = require("./commands/spinner");
|
|
7
|
+
const ddlFrom_1 = require("./commands/ddlFrom");
|
|
8
|
+
const dumpModel_1 = require("./commands/dumpModel");
|
|
9
|
+
const escape_1 = require("./commands/escape");
|
|
10
|
+
const cli = getCli('orm-cli');
|
|
11
|
+
(0, upgrade_1.default)(cli);
|
|
12
|
+
(0, spinner_1.default)(cli);
|
|
13
|
+
(0, ddlFrom_1.default)(cli);
|
|
14
|
+
(0, dumpModel_1.default)(cli);
|
|
15
|
+
(0, escape_1.default)(cli);
|
|
16
|
+
cli.help();
|
|
17
|
+
cli.version(pkg.version);
|
|
18
|
+
cli.parse();
|