typeorm 0.3.21-dev.79960e1 → 0.3.21-dev.7a384be
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/README.md +2 -2
- package/browser/platform/BrowserPlatformTools.d.ts +5 -1
- package/browser/platform/BrowserPlatformTools.js +7 -1
- package/browser/platform/BrowserPlatformTools.js.map +1 -1
- package/browser/platform/PlatformTools.d.ts +5 -1
- package/browser/platform/PlatformTools.js +17 -3
- package/browser/platform/PlatformTools.js.map +1 -1
- package/commands/QueryCommand.js +1 -5
- package/commands/QueryCommand.js.map +1 -1
- package/commands/SchemaLogCommand.js +2 -1
- package/commands/SchemaLogCommand.js.map +1 -1
- package/package.json +1 -1
- package/platform/PlatformTools.d.ts +5 -1
- package/platform/PlatformTools.js +17 -3
- package/platform/PlatformTools.js.map +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
<br>
|
|
6
6
|
<br>
|
|
7
|
-
<a href="https://
|
|
8
|
-
<img src="https://
|
|
7
|
+
<a href="https://app.circleci.com/pipelines/github/typeorm/typeorm">
|
|
8
|
+
<img src="https://circleci.com/gh/typeorm/typeorm/tree/master.svg?style=shield">
|
|
9
9
|
</a>
|
|
10
10
|
<a href="https://badge.fury.io/js/typeorm">
|
|
11
11
|
<img src="https://badge.fury.io/js/typeorm.svg">
|
|
@@ -37,9 +37,13 @@ export declare class PlatformTools {
|
|
|
37
37
|
static appendFileSync(filename: string, data: any): void;
|
|
38
38
|
static writeFile(path: string, data: any): Promise<void>;
|
|
39
39
|
/**
|
|
40
|
-
* Highlights sql string to be
|
|
40
|
+
* Highlights sql string to be print in the console.
|
|
41
41
|
*/
|
|
42
42
|
static highlightSql(sql: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Highlights json string to be print in the console.
|
|
45
|
+
*/
|
|
46
|
+
static highlightJson(json: string): string;
|
|
43
47
|
/**
|
|
44
48
|
* Logging functions needed by AdvancedConsoleLogger (but here without chalk)
|
|
45
49
|
*/
|
|
@@ -87,11 +87,17 @@ export class PlatformTools {
|
|
|
87
87
|
return Promise.reject(null);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
* Highlights sql string to be
|
|
90
|
+
* Highlights sql string to be print in the console.
|
|
91
91
|
*/
|
|
92
92
|
static highlightSql(sql) {
|
|
93
93
|
return sql;
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Highlights json string to be print in the console.
|
|
97
|
+
*/
|
|
98
|
+
static highlightJson(json) {
|
|
99
|
+
return json;
|
|
100
|
+
}
|
|
95
101
|
/**
|
|
96
102
|
* Logging functions needed by AdvancedConsoleLogger (but here without chalk)
|
|
97
103
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,aAAa;IAOtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,MAAM,CAAA;QACjB,CAAC;aAAM,CAAC;YACJ,uCAAuC;YACvC,OAAO,MAAM,CAAA;QACjB,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,gGAAgG,IAAI,KAAK,CAAC,CAAC;QAE/H,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAe;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,uGAAuG,OAAO,KAAK,CAAC,CAAC;QAEzI,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IAC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;AACI,kBAAI,GAAqB,SAAS,CAAC;AAsI9C;;;GAGG;AACH,MAAM,OAAO,YAAY;CAAG;AAE5B,MAAM,OAAO,QAAQ;CAAG;AAExB,MAAM,OAAO,QAAQ;CAAG;AAYxB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAChC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;AAC3B,CAAC;AACD,uCAAuC;AACvC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;IAClE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nimport { Buffer } from \"buffer\";\n\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n } else {\n // NativeScript uses global, not window\n return global\n }\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be print in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Highlights json string to be print in the console.\n */\n static highlightJson(json: string) {\n return json;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without chalk)\n */\n static logInfo(prefix: string, info: any) {\n console.info(prefix + \" \", info);\n }\n\n static logError(prefix: string, error: any) {\n console.error(prefix + \" \", error);\n }\n\n static logWarn(prefix: string, warning: any) {\n console.warn(prefix + \" \", warning);\n }\n\n static log(message: string) {\n console.log(message);\n }\n\n static warn(message: string) {\n return message;\n }\n}\n\n/**\n * These classes are needed for stream operations or\n * in the mongodb driver. Both aren't supported in the browser.\n */\nexport class EventEmitter {}\n\nexport class Readable {}\n\nexport class Writable {}\n\nexport interface ReadStream {}\n\n/**\n * This loads a polyfill to enable Buffers in the browser.\n */\ninterface Window {\n Buffer: any;\n}\n\ndeclare var window: Window;\nif (typeof window !== \"undefined\") {\n window.Buffer = Buffer;\n}\n// NativeScript uses global, not window\nif (typeof global !== \"undefined\" && typeof require !== \"undefined\") {\n global.Buffer = require(\"buffer/\").Buffer;\n}\n"],"sourceRoot":".."}
|
|
@@ -48,9 +48,13 @@ export declare class PlatformTools {
|
|
|
48
48
|
*/
|
|
49
49
|
static getEnvVariable(name: string): any;
|
|
50
50
|
/**
|
|
51
|
-
* Highlights sql string to be
|
|
51
|
+
* Highlights sql string to be print in the console.
|
|
52
52
|
*/
|
|
53
53
|
static highlightSql(sql: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Highlights json string to be print in the console.
|
|
56
|
+
*/
|
|
57
|
+
static highlightJson(json: string): string;
|
|
54
58
|
/**
|
|
55
59
|
* Logging functions needed by AdvancedConsoleLogger
|
|
56
60
|
*/
|
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
4
|
import chalk from "chalk";
|
|
5
|
-
import { highlight } from "
|
|
5
|
+
import { highlight } from "cli-highlight";
|
|
6
6
|
export { ReadStream } from "fs";
|
|
7
7
|
export { EventEmitter } from "events";
|
|
8
8
|
export { Readable, Writable } from "stream";
|
|
@@ -163,10 +163,24 @@ export class PlatformTools {
|
|
|
163
163
|
return process.env[name];
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
|
-
* Highlights sql string to be
|
|
166
|
+
* Highlights sql string to be print in the console.
|
|
167
167
|
*/
|
|
168
168
|
static highlightSql(sql) {
|
|
169
|
-
|
|
169
|
+
const theme = {
|
|
170
|
+
keyword: chalk.blueBright,
|
|
171
|
+
literal: chalk.blueBright,
|
|
172
|
+
string: chalk.white,
|
|
173
|
+
type: chalk.magentaBright,
|
|
174
|
+
built_in: chalk.magentaBright,
|
|
175
|
+
comment: chalk.gray,
|
|
176
|
+
};
|
|
177
|
+
return highlight(sql, { theme: theme, language: "sql" });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Highlights json string to be print in the console.
|
|
181
|
+
*/
|
|
182
|
+
static highlightJson(json) {
|
|
183
|
+
return highlight(json, { language: "json" });
|
|
170
184
|
}
|
|
171
185
|
/**
|
|
172
186
|
* Logging functions needed by AdvancedConsoleLogger
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/platform/PlatformTools.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAE3C;;GAEG;AACH,MAAM,OAAO,aAAa;IAMtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,OAAO,MAAM,CAAA;IACjB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,2HAA2H;QAC3H,8FAA8F;QAC9F,kCAAkC;QAElC,IAAI,CAAC;YACD,wEAAwE;YACxE,QAAQ,IAAI,EAAE,CAAC;gBACX;;mBAEG;gBACH,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAA;gBAE3C;;mBAEG;gBACH,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,SAAS,CAAC,CAAA;gB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KAAK,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe;QACvB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAc,EAAE,GAAS;QACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACtC,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;;AAtOD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport dotenv from \"dotenv\"\nimport chalk from \"chalk\"\nimport { highlight } from \"sql-highlight\"\n\nexport { ReadStream } from \"fs\"\nexport { EventEmitter } from \"events\"\nexport { Readable, Writable } from \"stream\"\n\n/**\n * Platform-specific tools.\n */\nexport class PlatformTools {\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\" | \"node\" = \"node\"\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in\n // this is useful when we are using typeorm package globally installed and it accesses drivers\n // that are not installed globally\n\n try {\n // switch case to explicit require statements for webpack compatibility.\n switch (name) {\n /**\n * spanner\n */\n case \"spanner\":\n return require(\"@google-cloud/spanner\")\n\n /**\n * mongodb\n */\n case \"mongodb\":\n return require(\"mongodb\")\n\n /**\n * hana\n */\n case \"@sap/hana-client\":\n return require(\"@sap/hana-client\")\n\n case \"@sap/hana-client/extension/Stream\":\n return require(\"@sap/hana-client/extension/Stream\")\n\n case \"hdb-pool\":\n return require(\"hdb-pool\")\n\n /**\n * mysql\n */\n case \"mysql\":\n return require(\"mysql\")\n\n case \"mysql2\":\n return require(\"mysql2\")\n\n /**\n * oracle\n */\n case \"oracledb\":\n return require(\"oracledb\")\n\n /**\n * postgres\n */\n case \"pg\":\n return require(\"pg\")\n\n case \"pg-native\":\n return require(\"pg-native\")\n\n case \"pg-query-stream\":\n return require(\"pg-query-stream\")\n\n case \"typeorm-aurora-data-api-driver\":\n return require(\"typeorm-aurora-data-api-driver\")\n\n /**\n * redis\n */\n case \"redis\":\n return require(\"redis\")\n\n case \"ioredis\":\n return require(\"ioredis\")\n\n /**\n * better-sqlite3\n */\n case \"better-sqlite3\":\n return require(\"better-sqlite3\")\n\n /**\n * sqlite\n */\n case \"sqlite3\":\n return require(\"sqlite3\")\n\n /**\n * sql.js\n */\n case \"sql.js\":\n return require(\"sql.js\")\n\n /**\n * sqlserver\n */\n case \"mssql\":\n return require(\"mssql\")\n\n /**\n * react-native-sqlite\n */\n case \"react-native-sqlite-storage\":\n return require(\"react-native-sqlite-storage\")\n }\n } catch (err) {\n return require(path.resolve(\n process.cwd() + \"/node_modules/\" + name,\n ))\n }\n\n // If nothing above matched and we get here, the package was not listed within PlatformTools\n // and is an Invalid Package. To make it explicit that this is NOT the intended use case for\n // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw\n // an error.\n throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\" and replaces backslashes with forward slashes on Windows.\n */\n static pathNormalize(pathStr: string): string {\n let normalizedPath = path.normalize(pathStr)\n if (process.platform === \"win32\")\n normalizedPath = normalizedPath.replace(/\\\\/g, \"/\")\n return normalizedPath\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n return path.extname(pathStr)\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n return path.resolve(pathStr)\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n return fs.existsSync(pathStr)\n }\n\n static readFileSync(filename: string): Buffer {\n return fs.readFileSync(filename)\n }\n\n static appendFileSync(filename: string, data: any): void {\n fs.appendFileSync(filename, data)\n }\n\n static async writeFile(path: string, data: any): Promise<void> {\n return fs.promises.writeFile(path, data)\n }\n\n /**\n * Loads a dotenv file into the environment variables.\n *\n * @param path The file to load as a dotenv configuration\n */\n static dotenv(pathStr: string): void {\n dotenv.config({ path: pathStr })\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n return process.env[name]\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return highlight(sql)\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger\n */\n static logInfo(prefix: string, info: any) {\n console.log(chalk.gray.underline(prefix), info)\n }\n\n static logError(prefix: string, error: any) {\n console.log(chalk.underline.red(prefix), error)\n }\n\n static logWarn(prefix: string, warning: any) {\n console.log(chalk.underline.yellow(prefix), warning)\n }\n\n static log(message: string) {\n console.log(chalk.underline(message))\n }\n\n static info(info: any) {\n return chalk.gray(info)\n }\n\n static error(error: any) {\n return chalk.red(error)\n }\n\n static warn(message: string) {\n return chalk.yellow(message)\n }\n\n static logCmdErr(prefix: string, err?: any) {\n console.log(chalk.black.bgRed(prefix))\n if (err) console.error(err)\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/platform/PlatformTools.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAS,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,C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AC;;AArPD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport dotenv from \"dotenv\"\nimport chalk from \"chalk\"\nimport { highlight, Theme } from \"cli-highlight\"\n\nexport { ReadStream } from \"fs\"\nexport { EventEmitter } from \"events\"\nexport { Readable, Writable } from \"stream\"\n\n/**\n * Platform-specific tools.\n */\nexport class PlatformTools {\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\" | \"node\" = \"node\"\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in\n // this is useful when we are using typeorm package globally installed and it accesses drivers\n // that are not installed globally\n\n try {\n // switch case to explicit require statements for webpack compatibility.\n switch (name) {\n /**\n * spanner\n */\n case \"spanner\":\n return require(\"@google-cloud/spanner\")\n\n /**\n * mongodb\n */\n case \"mongodb\":\n return require(\"mongodb\")\n\n /**\n * hana\n */\n case \"@sap/hana-client\":\n return require(\"@sap/hana-client\")\n\n case \"@sap/hana-client/extension/Stream\":\n return require(\"@sap/hana-client/extension/Stream\")\n\n case \"hdb-pool\":\n return require(\"hdb-pool\")\n\n /**\n * mysql\n */\n case \"mysql\":\n return require(\"mysql\")\n\n case \"mysql2\":\n return require(\"mysql2\")\n\n /**\n * oracle\n */\n case \"oracledb\":\n return require(\"oracledb\")\n\n /**\n * postgres\n */\n case \"pg\":\n return require(\"pg\")\n\n case \"pg-native\":\n return require(\"pg-native\")\n\n case \"pg-query-stream\":\n return require(\"pg-query-stream\")\n\n case \"typeorm-aurora-data-api-driver\":\n return require(\"typeorm-aurora-data-api-driver\")\n\n /**\n * redis\n */\n case \"redis\":\n return require(\"redis\")\n\n case \"ioredis\":\n return require(\"ioredis\")\n\n /**\n * better-sqlite3\n */\n case \"better-sqlite3\":\n return require(\"better-sqlite3\")\n\n /**\n * sqlite\n */\n case \"sqlite3\":\n return require(\"sqlite3\")\n\n /**\n * sql.js\n */\n case \"sql.js\":\n return require(\"sql.js\")\n\n /**\n * sqlserver\n */\n case \"mssql\":\n return require(\"mssql\")\n\n /**\n * react-native-sqlite\n */\n case \"react-native-sqlite-storage\":\n return require(\"react-native-sqlite-storage\")\n }\n } catch (err) {\n return require(path.resolve(\n process.cwd() + \"/node_modules/\" + name,\n ))\n }\n\n // If nothing above matched and we get here, the package was not listed within PlatformTools\n // and is an Invalid Package. To make it explicit that this is NOT the intended use case for\n // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw\n // an error.\n throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\" and replaces backslashes with forward slashes on Windows.\n */\n static pathNormalize(pathStr: string): string {\n let normalizedPath = path.normalize(pathStr)\n if (process.platform === \"win32\")\n normalizedPath = normalizedPath.replace(/\\\\/g, \"/\")\n return normalizedPath\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n return path.extname(pathStr)\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n return path.resolve(pathStr)\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n return fs.existsSync(pathStr)\n }\n\n static readFileSync(filename: string): Buffer {\n return fs.readFileSync(filename)\n }\n\n static appendFileSync(filename: string, data: any): void {\n fs.appendFileSync(filename, data)\n }\n\n static async writeFile(path: string, data: any): Promise<void> {\n return fs.promises.writeFile(path, data)\n }\n\n /**\n * Loads a dotenv file into the environment variables.\n *\n * @param path The file to load as a dotenv configuration\n */\n static dotenv(pathStr: string): void {\n dotenv.config({ path: pathStr })\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n return process.env[name]\n }\n\n /**\n * Highlights sql string to be print in the console.\n */\n static highlightSql(sql: string) {\n const theme: Theme = {\n keyword: chalk.blueBright,\n literal: chalk.blueBright,\n string: chalk.white,\n type: chalk.magentaBright,\n built_in: chalk.magentaBright,\n comment: chalk.gray,\n }\n return highlight(sql, { theme: theme, language: \"sql\" })\n }\n\n /**\n * Highlights json string to be print in the console.\n */\n static highlightJson(json: string) {\n return highlight(json, { language: \"json\" })\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger\n */\n static logInfo(prefix: string, info: any) {\n console.log(chalk.gray.underline(prefix), info)\n }\n\n static logError(prefix: string, error: any) {\n console.log(chalk.underline.red(prefix), error)\n }\n\n static logWarn(prefix: string, warning: any) {\n console.log(chalk.underline.yellow(prefix), warning)\n }\n\n static log(message: string) {\n console.log(chalk.underline(message))\n }\n\n static info(info: any) {\n return chalk.gray(info)\n }\n\n static error(error: any) {\n return chalk.red(error)\n }\n\n static warn(message: string) {\n return chalk.yellow(message)\n }\n\n static logCmdErr(prefix: string, err?: any) {\n console.log(chalk.black.bgRed(prefix))\n if (err) console.error(err)\n }\n}\n"],"sourceRoot":".."}
|
package/commands/QueryCommand.js
CHANGED
|
@@ -50,11 +50,7 @@ class QueryCommand {
|
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
52
|
console.log(chalk_1.default.green("Query has been executed. Result: "));
|
|
53
|
-
console.
|
|
54
|
-
breakLength: Infinity,
|
|
55
|
-
compact: false,
|
|
56
|
-
depth: null,
|
|
57
|
-
});
|
|
53
|
+
console.log(PlatformTools_1.PlatformTools.highlightJson(JSON.stringify(queryResult, undefined, 2)));
|
|
58
54
|
}
|
|
59
55
|
await queryRunner.release();
|
|
60
56
|
await dataSource.destroy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AAEzD,0DAAyB;AACzB,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,YAAY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K,GAAG,IAAI,CAAC,KAAe,CAAA;YAClC,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC;gBAC1B,6BAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CACxC,CAAA;YACD,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAElD,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;gBACrC,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CACP,kDAAkD,CACrD,CACJ,CAAA;YACL,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAA;gBAC7D,OAAO,CAAC,GAAG,CACP,6BAAa,CAAC,aAAa,CACvB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAC5C,CACJ,CAAA;YACL,CAAC;YAED,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;YAC3B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,6BAAa,CAAC,SAAS,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;YAE7D,IAAI,WAAW;gBAAE,MAAO,WAA2B,CAAC,OAAO,EAAE,CAAA;YAC7D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;CACJ;AAtED,oCAsEC","file":"QueryCommand.js","sourcesContent":["import { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Executes an SQL query on the given dataSource.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\"\n describe =\n \"Executes given SQL query on a default dataSource. Specify connection name to run query on a specific dataSource.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\",\n })\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let queryRunner: QueryRunner | undefined = undefined\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n // create a query runner and execute query using it\n queryRunner = dataSource.createQueryRunner()\n const query = args.query as string\n console.log(\n chalk.green(\"Running query: \") +\n PlatformTools.highlightSql(query),\n )\n const queryResult = await queryRunner.query(query)\n\n if (typeof queryResult === \"undefined\") {\n console.log(\n chalk.green(\n \"Query has been executed. No result was returned.\",\n ),\n )\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"))\n console.log(\n PlatformTools.highlightJson(\n JSON.stringify(queryResult, undefined, 2),\n ),\n )\n }\n\n await queryRunner.release()\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during query execution:\", err)\n\n if (queryRunner) await (queryRunner as QueryRunner).release()\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SchemaLogCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const cli_highlight_1 = require("cli-highlight");
|
|
5
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
7
|
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
7
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -57,7 +58,7 @@ class SchemaLogCommand {
|
|
|
57
58
|
sqlString.substr(-1) === ";"
|
|
58
59
|
? sqlString
|
|
59
60
|
: sqlString + ";";
|
|
60
|
-
console.log(
|
|
61
|
+
console.log((0, cli_highlight_1.highlight)(sqlString));
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
await dataSource.destroy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/SchemaLogCommand.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../../src/commands/SchemaLogCommand.ts"],"names":[],"mappings":";;;;AACA,iDAAyC;AAEzC,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,gBAAgB;IAA7B;QACI,YAAO,GAAG,YAAY,CAAA;QACtB,aAAQ,GACJ,sGAAsG;YACtG,+DAA+D,CAAA;IAgFvE,CAAC;IA9EG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI,CAAC;YACD,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,E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C,GAAG,CAAC,IAAA,yBAAS,EAAC,SAAS,CAAC,CAAC,CAAA;gBACrC,CAAC,CAAC,CAAA;YACN,CAAC;YACD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,UAAU;gBACV,6BAAa,CAAC,SAAS,CACnB,sCAAsC,EACtC,GAAG,CACN,CAAA;YACL,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;CACJ;AApFD,4CAoFC","file":"SchemaLogCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport { highlight } from \"cli-highlight\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows sql to be executed by schema:sync command.\n */\nexport class SchemaLogCommand implements yargs.CommandModule {\n command = \"schema:log\"\n describe =\n \"Shows sql to be executed by schema:sync command. It shows sql log only for your default dataSource. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (sqlInMemory.upQueries.length === 0) {\n console.log(\n chalk.yellow(\n \"Your schema is up to date - there are no queries to be executed by schema synchronization.\",\n ),\n )\n } else {\n const lengthSeparators = String(sqlInMemory.upQueries.length)\n .split(\"\")\n .map((char) => \"-\")\n .join(\"\")\n console.log(\n chalk.yellow(\n \"---------------------------------------------------------------\" +\n lengthSeparators,\n ),\n )\n console.log(\n chalk.yellow.bold(\n `-- Schema synchronization will execute following sql queries (${chalk.white(\n sqlInMemory.upQueries.length.toString(),\n )}):`,\n ),\n )\n console.log(\n chalk.yellow(\n \"---------------------------------------------------------------\" +\n lengthSeparators,\n ),\n )\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n let sqlString = upQuery.query\n sqlString = sqlString.trim()\n sqlString =\n sqlString.substr(-1) === \";\"\n ? sqlString\n : sqlString + \";\"\n console.log(highlight(sqlString))\n })\n }\n await dataSource.destroy()\n } catch (err) {\n if (dataSource)\n PlatformTools.logCmdErr(\n \"Error during schema synchronization:\",\n err,\n )\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "typeorm", "private": false, "version": "0.3.21-dev.
|
|
1
|
+
{ "name": "typeorm", "private": false, "version": "0.3.21-dev.7a384be", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">=16.13.0" }, "exports": { ".": { "types": "./index.d.ts", "node": { "import": "./index.mjs", "require": "./index.js", "types": "./index.d.ts" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": { "types": "./index.d.ts", "default": "./browser/index.js" }, "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/bson.typings.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/typings.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "homepage": "https://typeorm.io", "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "spanner", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm", "cloud-spanner", "cloud-spanner-orm" ], "devDependencies": { "@eslint/js": "^9.17.0", "@tsconfig/node16": "^16.1.1", "@types/chai": "^4.3.4", "@types/chai-as-promised": "^7.1.5", "@types/debug": "^4.1.7", "@types/gulp-rename": "^2.0.6", "@types/gulp-sourcemaps": "^0.0.38", "@types/mocha": "^10.0.1", "@types/node": "^18.13.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^10.0.13", "@types/source-map-support": "^0.5.6", "@types/uuid": "^9.0.0", "@types/yargs": "^17.0.22", "better-sqlite3": "^8.1.0", "chai": "^4.3.7", "chai-as-promised": "^7.1.1", "class-transformer": "^0.5.1", "conventional-changelog-angular": "^5.0.13", "conventional-changelog-cli": "^2.2.2", "eslint": "^9.17.0", "globals": "^15.14.0", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^10.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.1.4", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^8.0.3", "mocha": "^10.8.2", "mongodb": "^6.3.0", "mssql": "^10.0.1", "mysql": "^2.18.1", "mysql2": "^3.9.7", "nyc": "^17.1.0", "pg": "^8.9.0", "pg-query-stream": "^4.3.0", "prettier": "^2.8.8", "redis": "^4.6.4", "remap-istanbul": "^0.13.0", "rimraf": "^5.0.10", "sinon": "^15.0.1", "sinon-chai": "^3.7.0", "source-map-support": "^0.5.21", "sql.js": "^1.8.0", "sqlite3": "^5.1.4", "ts-node": "^10.9.2", "typeorm-aurora-data-api-driver": "^2.4.4", "typescript": "^5.7.2", "typescript-eslint": "^8.18.1" }, "peerDependencies": { "@google-cloud/spanner": "^5.18.0", "@sap/hana-client": "^2.12.25", "better-sqlite3": "^8.0.0 || ^9.0.0", "hdb-pool": "^0.1.6", "ioredis": "^5.0.4", "mongodb": "^5.8.0", "mssql": "^9.1.1 || ^10.0.1", "mysql2": "^2.2.5 || ^3.0.1", "oracledb": "^6.3.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1 || ^4.0.0", "reflect-metadata": "^0.1.14 || ^0.2.0", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@google-cloud/spanner": { "optional": true }, "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.5", "app-root-path": "^3.1.0", "buffer": "^6.0.3", "chalk": "^4.1.2", "cli-highlight": "^2.1.11", "dayjs": "^1.11.9", "debug": "^4.3.4", "dotenv": "^16.0.3", "glob": "^10.4.5", "sha.js": "^2.4.11", "tslib": "^2.5.0", "uuid": "^9.0.0", "yargs": "^17.6.2" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 90000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 90000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "eslint .", "format": "prettier --write --end-of-line auto \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" } }
|
|
@@ -48,9 +48,13 @@ export declare class PlatformTools {
|
|
|
48
48
|
*/
|
|
49
49
|
static getEnvVariable(name: string): any;
|
|
50
50
|
/**
|
|
51
|
-
* Highlights sql string to be
|
|
51
|
+
* Highlights sql string to be print in the console.
|
|
52
52
|
*/
|
|
53
53
|
static highlightSql(sql: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Highlights json string to be print in the console.
|
|
56
|
+
*/
|
|
57
|
+
static highlightJson(json: string): string;
|
|
54
58
|
/**
|
|
55
59
|
* Logging functions needed by AdvancedConsoleLogger
|
|
56
60
|
*/
|
|
@@ -6,7 +6,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
6
6
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
7
|
const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
|
|
8
8
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
-
const
|
|
9
|
+
const cli_highlight_1 = require("cli-highlight");
|
|
10
10
|
var fs_2 = require("fs");
|
|
11
11
|
Object.defineProperty(exports, "ReadStream", { enumerable: true, get: function () { return fs_2.ReadStream; } });
|
|
12
12
|
var events_1 = require("events");
|
|
@@ -171,10 +171,24 @@ class PlatformTools {
|
|
|
171
171
|
return process.env[name];
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
|
-
* Highlights sql string to be
|
|
174
|
+
* Highlights sql string to be print in the console.
|
|
175
175
|
*/
|
|
176
176
|
static highlightSql(sql) {
|
|
177
|
-
|
|
177
|
+
const theme = {
|
|
178
|
+
keyword: chalk_1.default.blueBright,
|
|
179
|
+
literal: chalk_1.default.blueBright,
|
|
180
|
+
string: chalk_1.default.white,
|
|
181
|
+
type: chalk_1.default.magentaBright,
|
|
182
|
+
built_in: chalk_1.default.magentaBright,
|
|
183
|
+
comment: chalk_1.default.gray,
|
|
184
|
+
};
|
|
185
|
+
return (0, cli_highlight_1.highlight)(sql, { theme: theme, language: "sql" });
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Highlights json string to be print in the console.
|
|
189
|
+
*/
|
|
190
|
+
static highlightJson(json) {
|
|
191
|
+
return (0, cli_highlight_1.highlight)(json, { language: "json" });
|
|
178
192
|
}
|
|
179
193
|
/**
|
|
180
194
|
* Logging functions needed by AdvancedConsoleLogger
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/platform/PlatformTools.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,oDAAmB;AACnB,4DAA2B;AAC3B,0DAAyB;AACzB,iDAAyC;AAEzC,yBAA+B;AAAtB,gGAAA,UAAU,OAAA;AACnB,iCAAqC;AAA5B,sGAAA,YAAY,OAAA;AACrB,iCAA2C;AAAlC,kGAAA,QAAQ,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAE3B;;GAEG;AACH,MAAa,aAAa;IAMtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,OAAO,MAAM,CAAA;IACjB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,2HAA2H;QAC3H,8FAA8F;QAC9F,kCAAkC;QAElC,IAAI,CAAC;YACD,wEAAwE;YACxE,QAAQ,IAAI,EAAE,CAAC;gBACX;;mBAEG;gBACH,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAA;gBAE3C;;mBAEG;gBACH,KAAK,SAAS;oBACV,OAAO,OAAO,CAAC,SAAS,CAAC,CAAA;gBAE7B;;mBAEG;gBACH,KAAK,kBAAkB;oBACnB,OAAO,OAAO,CAAC,kBAAkB,CAAC,CAAA;gBAEtC,KAAK,mCAAmC;oBACpC,OAA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O,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAc,EAAE,GAAS;QACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACtC,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;;AAvOL,sCAwOC;AAvOG;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport dotenv from \"dotenv\"\nimport chalk from \"chalk\"\nimport { highlight } from \"sql-highlight\"\n\nexport { ReadStream } from \"fs\"\nexport { EventEmitter } from \"events\"\nexport { Readable, Writable } from \"stream\"\n\n/**\n * Platform-specific tools.\n */\nexport class PlatformTools {\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\" | \"node\" = \"node\"\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in\n // this is useful when we are using typeorm package globally installed and it accesses drivers\n // that are not installed globally\n\n try {\n // switch case to explicit require statements for webpack compatibility.\n switch (name) {\n /**\n * spanner\n */\n case \"spanner\":\n return require(\"@google-cloud/spanner\")\n\n /**\n * mongodb\n */\n case \"mongodb\":\n return require(\"mongodb\")\n\n /**\n * hana\n */\n case \"@sap/hana-client\":\n return require(\"@sap/hana-client\")\n\n case \"@sap/hana-client/extension/Stream\":\n return require(\"@sap/hana-client/extension/Stream\")\n\n case \"hdb-pool\":\n return require(\"hdb-pool\")\n\n /**\n * mysql\n */\n case \"mysql\":\n return require(\"mysql\")\n\n case \"mysql2\":\n return require(\"mysql2\")\n\n /**\n * oracle\n */\n case \"oracledb\":\n return require(\"oracledb\")\n\n /**\n * postgres\n */\n case \"pg\":\n return require(\"pg\")\n\n case \"pg-native\":\n return require(\"pg-native\")\n\n case \"pg-query-stream\":\n return require(\"pg-query-stream\")\n\n case \"typeorm-aurora-data-api-driver\":\n return require(\"typeorm-aurora-data-api-driver\")\n\n /**\n * redis\n */\n case \"redis\":\n return require(\"redis\")\n\n case \"ioredis\":\n return require(\"ioredis\")\n\n /**\n * better-sqlite3\n */\n case \"better-sqlite3\":\n return require(\"better-sqlite3\")\n\n /**\n * sqlite\n */\n case \"sqlite3\":\n return require(\"sqlite3\")\n\n /**\n * sql.js\n */\n case \"sql.js\":\n return require(\"sql.js\")\n\n /**\n * sqlserver\n */\n case \"mssql\":\n return require(\"mssql\")\n\n /**\n * react-native-sqlite\n */\n case \"react-native-sqlite-storage\":\n return require(\"react-native-sqlite-storage\")\n }\n } catch (err) {\n return require(path.resolve(\n process.cwd() + \"/node_modules/\" + name,\n ))\n }\n\n // If nothing above matched and we get here, the package was not listed within PlatformTools\n // and is an Invalid Package. To make it explicit that this is NOT the intended use case for\n // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw\n // an error.\n throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\" and replaces backslashes with forward slashes on Windows.\n */\n static pathNormalize(pathStr: string): string {\n let normalizedPath = path.normalize(pathStr)\n if (process.platform === \"win32\")\n normalizedPath = normalizedPath.replace(/\\\\/g, \"/\")\n return normalizedPath\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n return path.extname(pathStr)\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n return path.resolve(pathStr)\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n return fs.existsSync(pathStr)\n }\n\n static readFileSync(filename: string): Buffer {\n return fs.readFileSync(filename)\n }\n\n static appendFileSync(filename: string, data: any): void {\n fs.appendFileSync(filename, data)\n }\n\n static async writeFile(path: string, data: any): Promise<void> {\n return fs.promises.writeFile(path, data)\n }\n\n /**\n * Loads a dotenv file into the environment variables.\n *\n * @param path The file to load as a dotenv configuration\n */\n static dotenv(pathStr: string): void {\n dotenv.config({ path: pathStr })\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n return process.env[name]\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return highlight(sql)\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger\n */\n static logInfo(prefix: string, info: any) {\n console.log(chalk.gray.underline(prefix), info)\n }\n\n static logError(prefix: string, error: any) {\n console.log(chalk.underline.red(prefix), error)\n }\n\n static logWarn(prefix: string, warning: any) {\n console.log(chalk.underline.yellow(prefix), warning)\n }\n\n static log(message: string) {\n console.log(chalk.underline(message))\n }\n\n static info(info: any) {\n return chalk.gray(info)\n }\n\n static error(error: any) {\n return chalk.red(error)\n }\n\n static warn(message: string) {\n return chalk.yellow(message)\n }\n\n static logCmdErr(prefix: string, err?: any) {\n console.log(chalk.black.bgRed(prefix))\n if (err) console.error(err)\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/platform/PlatformTools.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,oDAAmB;AACnB,4DAA2B;AAC3B,0DAAyB;AACzB,iDAAgD;AAEhD,yBAA+B;AAAtB,gGAAA,UAAU,OAAA;AACnB,iCAAqC;AAA5B,sGAAA,YAAY,OAAA;AACrB,iCAA2C;AAAlC,kGAAA,QAAQ,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAE3B;;GAEG;AACH,MAAa,aAAa;IAMtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,OAAO,MAAM,CAAA;IACjB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,2HAA2H;QAC3H,8FAA8F;QAC9F,kCAAkC;QAElC,IAAI,CAAC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AC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,MAAc,EAAE,KAAU;QACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAA;IACnD,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,OAAY;QACvC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,OAAe;QACtB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAS;QACjB,OAAO,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAU;QACnB,OAAO,eAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe;QACvB,OAAO,eAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAc,EAAE,GAAS;QACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACtC,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;;AAtPL,sCAuPC;AAtPG;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport dotenv from \"dotenv\"\nimport chalk from \"chalk\"\nimport { highlight, Theme } from \"cli-highlight\"\n\nexport { ReadStream } from \"fs\"\nexport { EventEmitter } from \"events\"\nexport { Readable, Writable } from \"stream\"\n\n/**\n * Platform-specific tools.\n */\nexport class PlatformTools {\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\" | \"node\" = \"node\"\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in\n // this is useful when we are using typeorm package globally installed and it accesses drivers\n // that are not installed globally\n\n try {\n // switch case to explicit require statements for webpack compatibility.\n switch (name) {\n /**\n * spanner\n */\n case \"spanner\":\n return require(\"@google-cloud/spanner\")\n\n /**\n * mongodb\n */\n case \"mongodb\":\n return require(\"mongodb\")\n\n /**\n * hana\n */\n case \"@sap/hana-client\":\n return require(\"@sap/hana-client\")\n\n case \"@sap/hana-client/extension/Stream\":\n return require(\"@sap/hana-client/extension/Stream\")\n\n case \"hdb-pool\":\n return require(\"hdb-pool\")\n\n /**\n * mysql\n */\n case \"mysql\":\n return require(\"mysql\")\n\n case \"mysql2\":\n return require(\"mysql2\")\n\n /**\n * oracle\n */\n case \"oracledb\":\n return require(\"oracledb\")\n\n /**\n * postgres\n */\n case \"pg\":\n return require(\"pg\")\n\n case \"pg-native\":\n return require(\"pg-native\")\n\n case \"pg-query-stream\":\n return require(\"pg-query-stream\")\n\n case \"typeorm-aurora-data-api-driver\":\n return require(\"typeorm-aurora-data-api-driver\")\n\n /**\n * redis\n */\n case \"redis\":\n return require(\"redis\")\n\n case \"ioredis\":\n return require(\"ioredis\")\n\n /**\n * better-sqlite3\n */\n case \"better-sqlite3\":\n return require(\"better-sqlite3\")\n\n /**\n * sqlite\n */\n case \"sqlite3\":\n return require(\"sqlite3\")\n\n /**\n * sql.js\n */\n case \"sql.js\":\n return require(\"sql.js\")\n\n /**\n * sqlserver\n */\n case \"mssql\":\n return require(\"mssql\")\n\n /**\n * react-native-sqlite\n */\n case \"react-native-sqlite-storage\":\n return require(\"react-native-sqlite-storage\")\n }\n } catch (err) {\n return require(path.resolve(\n process.cwd() + \"/node_modules/\" + name,\n ))\n }\n\n // If nothing above matched and we get here, the package was not listed within PlatformTools\n // and is an Invalid Package. To make it explicit that this is NOT the intended use case for\n // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw\n // an error.\n throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\" and replaces backslashes with forward slashes on Windows.\n */\n static pathNormalize(pathStr: string): string {\n let normalizedPath = path.normalize(pathStr)\n if (process.platform === \"win32\")\n normalizedPath = normalizedPath.replace(/\\\\/g, \"/\")\n return normalizedPath\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n return path.extname(pathStr)\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n return path.resolve(pathStr)\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n return fs.existsSync(pathStr)\n }\n\n static readFileSync(filename: string): Buffer {\n return fs.readFileSync(filename)\n }\n\n static appendFileSync(filename: string, data: any): void {\n fs.appendFileSync(filename, data)\n }\n\n static async writeFile(path: string, data: any): Promise<void> {\n return fs.promises.writeFile(path, data)\n }\n\n /**\n * Loads a dotenv file into the environment variables.\n *\n * @param path The file to load as a dotenv configuration\n */\n static dotenv(pathStr: string): void {\n dotenv.config({ path: pathStr })\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n return process.env[name]\n }\n\n /**\n * Highlights sql string to be print in the console.\n */\n static highlightSql(sql: string) {\n const theme: Theme = {\n keyword: chalk.blueBright,\n literal: chalk.blueBright,\n string: chalk.white,\n type: chalk.magentaBright,\n built_in: chalk.magentaBright,\n comment: chalk.gray,\n }\n return highlight(sql, { theme: theme, language: \"sql\" })\n }\n\n /**\n * Highlights json string to be print in the console.\n */\n static highlightJson(json: string) {\n return highlight(json, { language: \"json\" })\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger\n */\n static logInfo(prefix: string, info: any) {\n console.log(chalk.gray.underline(prefix), info)\n }\n\n static logError(prefix: string, error: any) {\n console.log(chalk.underline.red(prefix), error)\n }\n\n static logWarn(prefix: string, warning: any) {\n console.log(chalk.underline.yellow(prefix), warning)\n }\n\n static log(message: string) {\n console.log(chalk.underline(message))\n }\n\n static info(info: any) {\n return chalk.gray(info)\n }\n\n static error(error: any) {\n return chalk.red(error)\n }\n\n static warn(message: string) {\n return chalk.yellow(message)\n }\n\n static logCmdErr(prefix: string, err?: any) {\n console.log(chalk.black.bgRed(prefix))\n if (err) console.error(err)\n }\n}\n"],"sourceRoot":".."}
|