typeorm 0.3.12 → 0.3.13-dev.07221a3
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/browser/driver/react-native/ReactNativeDriver.d.ts +219 -6
- package/browser/driver/react-native/ReactNativeDriver.js +662 -10
- package/browser/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/browser/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerDriver.js +7 -2
- package/browser/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerQueryRunner.d.ts +2 -1
- package/browser/driver/sqlserver/SqlServerQueryRunner.js +31 -9
- package/browser/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
- package/browser/platform/PlatformTools.d.ts +1 -1
- package/browser/platform/PlatformTools.js +5 -2
- package/browser/platform/PlatformTools.js.map +1 -1
- package/browser/query-runner/BaseQueryRunner.d.ts +2 -1
- package/browser/query-runner/BaseQueryRunner.js +5 -2
- package/browser/query-runner/BaseQueryRunner.js.map +1 -1
- package/browser/util/DateUtils.d.ts +12 -0
- package/browser/util/DateUtils.js +20 -16
- package/browser/util/DateUtils.js.map +1 -1
- package/driver/react-native/ReactNativeDriver.d.ts +219 -6
- package/driver/react-native/ReactNativeDriver.js +663 -11
- package/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/driver/sqlserver/SqlServerDriver.js +7 -2
- package/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/driver/sqlserver/SqlServerQueryRunner.d.ts +2 -1
- package/driver/sqlserver/SqlServerQueryRunner.js +31 -9
- package/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
- package/package.json +1 -273
- package/platform/PlatformTools.d.ts +1 -1
- package/platform/PlatformTools.js +5 -2
- package/platform/PlatformTools.js.map +1 -1
- package/query-runner/BaseQueryRunner.d.ts +2 -1
- package/query-runner/BaseQueryRunner.js +5 -2
- package/query-runner/BaseQueryRunner.js.map +1 -1
- package/util/DateUtils.d.ts +12 -0
- package/util/DateUtils.js +20 -16
- package/util/DateUtils.js.map +1 -1
|
@@ -20,7 +20,7 @@ export declare class PlatformTools {
|
|
|
20
20
|
*/
|
|
21
21
|
static load(name: string): any;
|
|
22
22
|
/**
|
|
23
|
-
* Normalizes given path. Does "path.normalize".
|
|
23
|
+
* Normalizes given path. Does "path.normalize" and replaces backslashes with forward slashes on Windows.
|
|
24
24
|
*/
|
|
25
25
|
static pathNormalize(pathStr: string): string;
|
|
26
26
|
/**
|
|
@@ -111,10 +111,13 @@ export class PlatformTools {
|
|
|
111
111
|
throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`);
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* Normalizes given path. Does "path.normalize".
|
|
114
|
+
* Normalizes given path. Does "path.normalize" and replaces backslashes with forward slashes on Windows.
|
|
115
115
|
*/
|
|
116
116
|
static pathNormalize(pathStr) {
|
|
117
|
-
|
|
117
|
+
let normalizedPath = path.normalize(pathStr);
|
|
118
|
+
if (process.platform === "win32")
|
|
119
|
+
normalizedPath = normalizedPath.replace(/\\/g, "/");
|
|
120
|
+
return normalizedPath;
|
|
118
121
|
}
|
|
119
122
|
/**
|
|
120
123
|
* Gets file extension. Does "path.extname".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/platform/PlatformTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,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,E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I,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import * as path from \"path\"\nimport * as 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 \"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\".\n */\n static pathNormalize(pathStr: string): string {\n return path.normalize(pathStr)\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 new Promise<void>((ok, fail) => {\n fs.writeFile(path, data, (err) => {\n if (err) fail(err)\n ok()\n })\n })\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":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/platform/PlatformTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,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,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;YACA,wEAAwE;YACxE,QA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AAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,MAAc,EAAE,KAAU;QACtC,OAAO,CAAC,GAAG,CAAC,KAAK,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,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,OAAe;QACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAS;QACjB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAU;QACnB,OAAO,KAAK,CAAC,GAAG,CAAC,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;;AAvPD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import * as path from \"path\"\nimport * as 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 \"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 new Promise<void>((ok, fail) => {\n fs.writeFile(path, data, (err) => {\n if (err) fail(err)\n ok()\n })\n })\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":".."}
|
|
@@ -179,7 +179,8 @@ export declare abstract class BaseQueryRunner {
|
|
|
179
179
|
* Checks if at least one of column properties was changed.
|
|
180
180
|
* Does not checks column type, length and autoincrement, because these properties changes separately.
|
|
181
181
|
*/
|
|
182
|
-
protected isColumnChanged(oldColumn: TableColumn, newColumn: TableColumn, checkDefault?: boolean, checkComment?: boolean): boolean;
|
|
182
|
+
protected isColumnChanged(oldColumn: TableColumn, newColumn: TableColumn, checkDefault?: boolean, checkComment?: boolean, checkEnum?: boolean): boolean;
|
|
183
|
+
protected isEnumChanged(oldColumn: TableColumn, newColumn: TableColumn): boolean;
|
|
183
184
|
/**
|
|
184
185
|
* Checks if column length is by default.
|
|
185
186
|
*/
|
|
@@ -294,7 +294,7 @@ export class BaseQueryRunner {
|
|
|
294
294
|
* Checks if at least one of column properties was changed.
|
|
295
295
|
* Does not checks column type, length and autoincrement, because these properties changes separately.
|
|
296
296
|
*/
|
|
297
|
-
isColumnChanged(oldColumn, newColumn, checkDefault, checkComment) {
|
|
297
|
+
isColumnChanged(oldColumn, newColumn, checkDefault, checkComment, checkEnum = true) {
|
|
298
298
|
// this logs need to debug issues in column change detection. Do not delete it!
|
|
299
299
|
// console.log("charset ---------------");
|
|
300
300
|
// console.log(oldColumn.charset !== newColumn.charset);
|
|
@@ -332,7 +332,10 @@ export class BaseQueryRunner {
|
|
|
332
332
|
oldColumn.onUpdate !== newColumn.onUpdate || // MySQL only
|
|
333
333
|
oldColumn.isNullable !== newColumn.isNullable ||
|
|
334
334
|
(checkComment && oldColumn.comment !== newColumn.comment) ||
|
|
335
|
-
|
|
335
|
+
(checkEnum && this.isEnumChanged(oldColumn, newColumn)));
|
|
336
|
+
}
|
|
337
|
+
isEnumChanged(oldColumn, newColumn) {
|
|
338
|
+
return !OrmUtils.isArraysEqual(oldColumn.enum || [], newColumn.enum || []);
|
|
336
339
|
}
|
|
337
340
|
/**
|
|
338
341
|
* Checks if column length is by default.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/query-runner/BaseQueryRunner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAUnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,OAAgB,eAAe;IAArC;QACI,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAY5E;;;WAGG;QACH,eAAU,GAAG,KAAK,CAAA;QAElB;;WAEG;QACH,wBAAmB,GAAG,KAAK,CAAA;QAE3B;;;WAGG;QACH,SAAI,GAAG,EAAE,CAAA;QAET;;WAEG;QACH,iBAAY,GAAY,EAAE,CAAA;QAE1B;;WAEG;QACH,gBAAW,GAAW,EAAE,CAAA;QAgBxB;;WAEG;QACO,kBAAa,GAAY,KAAK,CAAA;QAExC;;WAEG;QACO,gBAAW,GAAgB,IAAI,WAAW,EAAE,CAAA;QAStD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AI,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK;gBAC1D,KAAK,CACR,CAAA;QAEL,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,cAAc,CAC1B,SAA0B,EAC1B,WAA4B;QAE5B,IAAI,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,SAAS,GAAG,CAAC,SAAS,CAAC,CAAA;QAC/D,IAAI,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC;YAAE,WAAW,GAAG,CAAC,WAAW,CAAC,CAAA;QAErE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAA;QAC7C,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAA;QAEjD,8EAA8E;QAC9E,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI;YAC3B,OAAO,OAAO,CAAC,OAAO,EAAkB,CAAA;QAE5C,KAAK,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,SAAS,EAAE;YAC3C,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;SACtC;IACL,CAAC;IAED;;OAEG;IACO,iBAAiB,CACvB,KAAmB,EACnB,KAAiB;QAEjB,sFAAsF;QACtF,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,SAAS,CAC3C,KAAK,EACL,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,KAAK,CACd,CAAA;IACL,CAAC;CACJ","file":"BaseQueryRunner.js","sourcesContent":["import { PostgresConnectionOptions } from \"../driver/postgres/PostgresConnectionOptions\"\nimport { Query } from \"../driver/Query\"\nimport { SqlInMemory } from \"../driver/SqlInMemory\"\nimport { SqlServerConnectionOptions } from \"../driver/sqlserver/SqlServerConnectionOptions\"\nimport { TableIndex } from \"../schema-builder/table/TableIndex\"\nimport { View } from \"../schema-builder/view/View\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { TableColumn } from \"../schema-builder/table/TableColumn\"\nimport { Broadcaster } from \"../subscriber/Broadcaster\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error/TypeORMError\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { TableForeignKey } from \"../schema-builder/table/TableForeignKey\"\nimport { OrmUtils } from \"../util/OrmUtils\"\nimport { MetadataTableType } from \"../driver/types/MetadataTableType\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\nexport abstract class BaseQueryRunner {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used by this query runner.\n */\n connection: DataSource\n\n /**\n * Entity manager working only with current query runner.\n */\n manager: EntityManager\n\n /**\n * Indicates if connection for this query runner is released.\n * Once its released, query runner cannot run queries anymore.\n */\n isReleased = false\n\n /**\n * Indicates if transaction is in progress.\n */\n isTransactionActive = false\n\n /**\n * Stores temporarily user data.\n * Useful for sharing data with subscribers.\n */\n data = {}\n\n /**\n * All synchronized tables in the database.\n */\n loadedTables: Table[] = []\n\n /**\n * All synchronized views in the database.\n */\n loadedViews: View[] = []\n\n /**\n * Broadcaster used on this query runner to broadcast entity events.\n */\n broadcaster: Broadcaster\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Real database connection from a connection pool used to perform queries.\n */\n protected databaseConnection: any\n\n /**\n * Indicates if special query runner mode in which sql queries won't be executed is enabled.\n */\n protected sqlMemoryMode: boolean = false\n\n /**\n * Sql-s stored if \"sql in memory\" mode is enabled.\n */\n protected sqlInMemory: SqlInMemory = new SqlInMemory()\n\n /**\n * Mode in which query runner executes.\n * Used for replication.\n * If replication is not setup its value is ignored.\n */\n protected mode: ReplicationMode\n\n /**\n * current depth of transaction.\n * for transactionDepth > 0 will use SAVEPOINT to start and commit/rollback transaction blocks\n */\n protected transactionDepth = 0\n\n private cachedTablePaths: Record<string, string> = {}\n\n // -------------------------------------------------------------------------\n // Public Abstract Methods\n // -------------------------------------------------------------------------\n\n /**\n * Executes a given SQL query.\n */\n abstract query(\n query: string,\n parameters?: any[],\n useStructuredResult?: boolean,\n ): Promise<any>\n\n // -------------------------------------------------------------------------\n // Protected Abstract Methods\n // -------------------------------------------------------------------------\n\n protected abstract loadTables(tablePaths?: string[]): Promise<Table[]>\n\n protected abstract loadViews(tablePaths?: string[]): Promise<View[]>\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n // Do nothing\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n // Do nothing\n }\n\n /**\n * Loads given table's data from the database.\n */\n async getTable(tablePath: string): Promise<Table | undefined> {\n this.loadedTables = await this.loadTables([tablePath])\n return this.loadedTables.length > 0 ? this.loadedTables[0] : undefined\n }\n\n /**\n * Loads all tables (with given names) from the database.\n */\n async getTables(tableNames?: string[]): Promise<Table[]> {\n if (!tableNames) {\n // Don't cache in this case.\n // This is the new case & isn't used anywhere else anyway.\n return await this.loadTables(tableNames)\n }\n\n this.loadedTables = await this.loadTables(tableNames)\n return this.loadedTables\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getView(viewPath: string): Promise<View | undefined> {\n this.loadedViews = await this.loadViews([viewPath])\n return this.loadedViews.length > 0 ? this.loadedViews[0] : undefined\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getViews(viewPaths?: string[]): Promise<View[]> {\n this.loadedViews = await this.loadViews(viewPaths)\n return this.loadedViews\n }\n\n /**\n * Enables special query runner mode in which sql queries won't be executed,\n * instead they will be memorized into a special variable inside query runner.\n * You can get memorized sql using getMemorySql() method.\n */\n enableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory()\n this.sqlMemoryMode = true\n }\n\n /**\n * Disables special query runner mode in which sql queries won't be executed\n * started by calling enableSqlMemory() method.\n *\n * Previously memorized sql will be flushed.\n */\n disableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory()\n this.sqlMemoryMode = false\n }\n\n /**\n * Flushes all memorized sqls.\n */\n clearSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory()\n }\n\n /**\n * Gets sql stored in the memory. Parameters in the sql are already replaced.\n */\n getMemorySql(): SqlInMemory {\n return this.sqlInMemory\n }\n\n /**\n * Executes up sql queries.\n */\n async executeMemoryUpSql(): Promise<void> {\n for (const { query, parameters } of this.sqlInMemory.upQueries) {\n await this.query(query, parameters)\n }\n }\n\n /**\n * Executes down sql queries.\n */\n async executeMemoryDownSql(): Promise<void> {\n for (const {\n query,\n parameters,\n } of this.sqlInMemory.downQueries.reverse()) {\n await this.query(query, parameters)\n }\n }\n\n getReplicationMode(): ReplicationMode {\n return this.mode\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets view from previously loaded views, otherwise loads it from database.\n */\n protected async getCachedView(viewName: string): Promise<View> {\n const view = this.loadedViews.find((view) => view.name === viewName)\n if (view) return view\n\n const foundViews = await this.loadViews([viewName])\n if (foundViews.length > 0) {\n this.loadedViews.push(foundViews[0])\n return foundViews[0]\n } else {\n throw new TypeORMError(`View \"${viewName}\" does not exist.`)\n }\n }\n\n /**\n * Gets table from previously loaded tables, otherwise loads it from database.\n */\n protected async getCachedTable(tableName: string): Promise<Table> {\n if (tableName in this.cachedTablePaths) {\n const tablePath = this.cachedTablePaths[tableName]\n const table = this.loadedTables.find(\n (table) => this.getTablePath(table) === tablePath,\n )\n\n if (table) {\n return table\n }\n }\n\n const foundTables = await this.loadTables([tableName])\n\n if (foundTables.length > 0) {\n const foundTablePath = this.getTablePath(foundTables[0])\n\n const cachedTable = this.loadedTables.find(\n (table) => this.getTablePath(table) === foundTablePath,\n )\n\n if (!cachedTable) {\n this.cachedTablePaths[tableName] = this.getTablePath(\n foundTables[0],\n )\n this.loadedTables.push(foundTables[0])\n return foundTables[0]\n } else {\n return cachedTable\n }\n } else {\n throw new TypeORMError(`Table \"${tableName}\" does not exist.`)\n }\n }\n\n /**\n * Replaces loaded table with given changed table.\n */\n protected replaceCachedTable(table: Table, changedTable: Table): void {\n const oldTablePath = this.getTablePath(table)\n const foundTable = this.loadedTables.find(\n (loadedTable) => this.getTablePath(loadedTable) === oldTablePath,\n )\n\n // Clean up the lookup cache..\n for (const [key, cachedPath] of Object.entries(this.cachedTablePaths)) {\n if (cachedPath === oldTablePath) {\n this.cachedTablePaths[key] = this.getTablePath(changedTable)\n }\n }\n\n if (foundTable) {\n foundTable.database = changedTable.database\n foundTable.schema = changedTable.schema\n foundTable.name = changedTable.name\n foundTable.columns = changedTable.columns\n foundTable.indices = changedTable.indices\n foundTable.foreignKeys = changedTable.foreignKeys\n foundTable.uniques = changedTable.uniques\n foundTable.checks = changedTable.checks\n foundTable.justCreated = changedTable.justCreated\n foundTable.engine = changedTable.engine\n }\n }\n\n protected getTablePath(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): string {\n const parsed = this.connection.driver.parseTableName(target)\n\n return this.connection.driver.buildTableName(\n parsed.tableName,\n parsed.schema,\n parsed.database,\n )\n }\n\n protected getTypeormMetadataTableName(): string {\n const options = <\n SqlServerConnectionOptions | PostgresConnectionOptions\n >this.connection.driver.options\n return this.connection.driver.buildTableName(\n this.connection.metadataTableName,\n options.schema,\n options.database,\n )\n }\n\n /**\n * Generates SQL query to select record from typeorm metadata table.\n */\n protected selectTypeormMetadataSql({\n database,\n schema,\n table,\n type,\n name,\n }: {\n database?: string\n schema?: string\n table?: string\n type: MetadataTableType\n name: string\n }): Query {\n const qb = this.connection.createQueryBuilder()\n const selectQb = qb\n .select()\n .from(this.getTypeormMetadataTableName(), \"t\")\n .where(`${qb.escape(\"type\")} = :type`, { type })\n .andWhere(`${qb.escape(\"name\")} = :name`, { name })\n\n if (database) {\n selectQb.andWhere(`${qb.escape(\"database\")} = :database`, {\n database,\n })\n }\n\n if (schema) {\n selectQb.andWhere(`${qb.escape(\"schema\")} = :schema`, { schema })\n }\n\n if (table) {\n selectQb.andWhere(`${qb.escape(\"table\")} = :table`, { table })\n }\n\n const [query, parameters] = selectQb.getQueryAndParameters()\n return new Query(query, parameters)\n }\n\n /**\n * Generates SQL query to insert a record into typeorm metadata table.\n */\n protected insertTypeormMetadataSql({\n database,\n schema,\n table,\n type,\n name,\n value,\n }: {\n database?: string\n schema?: string\n table?: string\n type: MetadataTableType\n name: string\n value?: string\n }): Query {\n const [query, parameters] = this.connection\n .createQueryBuilder()\n .insert()\n .into(this.getTypeormMetadataTableName())\n .values({\n database: database,\n schema: schema,\n table: table,\n type: type,\n name: name,\n value: value,\n })\n .getQueryAndParameters()\n\n return new Query(query, parameters)\n }\n\n /**\n * Generates SQL query to delete a record from typeorm metadata table.\n */\n protected deleteTypeormMetadataSql({\n database,\n schema,\n table,\n type,\n name,\n }: {\n database?: string\n schema?: string\n table?: string\n type: MetadataTableType\n name: string\n }): Query {\n const qb = this.connection.createQueryBuilder()\n const deleteQb = qb\n .delete()\n .from(this.getTypeormMetadataTableName())\n .where(`${qb.escape(\"type\")} = :type`, { type })\n .andWhere(`${qb.escape(\"name\")} = :name`, { name })\n\n if (database) {\n deleteQb.andWhere(`${qb.escape(\"database\")} = :database`, {\n database,\n })\n }\n\n if (schema) {\n deleteQb.andWhere(`${qb.escape(\"schema\")} = :schema`, { schema })\n }\n\n if (table) {\n deleteQb.andWhere(`${qb.escape(\"table\")} = :table`, { table })\n }\n\n const [query, parameters] = deleteQb.getQueryAndParameters()\n return new Query(query, parameters)\n }\n\n /**\n * Checks if at least one of column properties was changed.\n * Does not checks column type, length and autoincrement, because these properties changes separately.\n */\n protected isColumnChanged(\n oldColumn: TableColumn,\n newColumn: TableColumn,\n checkDefault?: boolean,\n checkComment?: boolean,\n ): boolean {\n // this logs need to debug issues in column change detection. Do not delete it!\n\n // console.log(\"charset ---------------\");\n // console.log(oldColumn.charset !== newColumn.charset);\n // console.log(oldColumn.charset, newColumn.charset);\n // console.log(\"collation ---------------\");\n // console.log(oldColumn.collation !== newColumn.collation);\n // console.log(oldColumn.collation, newColumn.collation);\n // console.log(\"precision ---------------\");\n // console.log(oldColumn.precision !== newColumn.precision);\n // console.log(oldColumn.precision, newColumn.precision);\n // console.log(\"scale ---------------\");\n // console.log(oldColumn.scale !== newColumn.scale);\n // console.log(oldColumn.scale, newColumn.scale);\n // console.log(\"default ---------------\");\n // console.log((checkDefault && oldColumn.default !== newColumn.default));\n // console.log(oldColumn.default, newColumn.default);\n // console.log(\"isNullable ---------------\");\n // console.log(oldColumn.isNullable !== newColumn.isNullable);\n // console.log(oldColumn.isNullable, newColumn.isNullable);\n // console.log(\"comment ---------------\");\n // console.log((checkComment && oldColumn.comment !== newColumn.comment));\n // console.log(oldColumn.comment, newColumn.comment);\n // console.log(\"enum ---------------\");\n // console.log(!OrmUtils.isArraysEqual(oldColumn.enum || [], newColumn.enum || []));\n // console.log(oldColumn.enum, newColumn.enum);\n\n return (\n oldColumn.charset !== newColumn.charset ||\n oldColumn.collation !== newColumn.collation ||\n oldColumn.precision !== newColumn.precision ||\n oldColumn.scale !== newColumn.scale ||\n oldColumn.width !== newColumn.width || // MySQL only\n oldColumn.zerofill !== newColumn.zerofill || // MySQL only\n oldColumn.unsigned !== newColumn.unsigned || // MySQL only\n oldColumn.asExpression !== newColumn.asExpression ||\n (checkDefault && oldColumn.default !== newColumn.default) ||\n oldColumn.onUpdate !== newColumn.onUpdate || // MySQL only\n oldColumn.isNullable !== newColumn.isNullable ||\n (checkComment && oldColumn.comment !== newColumn.comment) ||\n !OrmUtils.isArraysEqual(oldColumn.enum || [], newColumn.enum || [])\n )\n }\n\n /**\n * Checks if column length is by default.\n */\n protected isDefaultColumnLength(\n table: Table,\n column: TableColumn,\n length: string,\n ): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name)\n const columnMetadata = metadata.findColumnWithDatabaseName(\n column.name,\n )\n\n if (columnMetadata) {\n const columnMetadataLength =\n this.connection.driver.getColumnLength(columnMetadata)\n if (columnMetadataLength) return false\n }\n }\n\n if (\n this.connection.driver.dataTypeDefaults &&\n this.connection.driver.dataTypeDefaults[column.type] &&\n this.connection.driver.dataTypeDefaults[column.type].length\n ) {\n return (\n this.connection.driver.dataTypeDefaults[\n column.type\n ].length!.toString() === length.toString()\n )\n }\n\n return false\n }\n\n /**\n * Checks if column precision is by default.\n */\n protected isDefaultColumnPrecision(\n table: Table,\n column: TableColumn,\n precision: number,\n ): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name)\n const columnMetadata = metadata.findColumnWithDatabaseName(\n column.name,\n )\n if (\n columnMetadata &&\n columnMetadata.precision !== null &&\n columnMetadata.precision !== undefined\n )\n return false\n }\n\n if (\n this.connection.driver.dataTypeDefaults &&\n this.connection.driver.dataTypeDefaults[column.type] &&\n this.connection.driver.dataTypeDefaults[column.type].precision !==\n null &&\n this.connection.driver.dataTypeDefaults[column.type].precision !==\n undefined\n )\n return (\n this.connection.driver.dataTypeDefaults[column.type]\n .precision === precision\n )\n\n return false\n }\n\n /**\n * Checks if column scale is by default.\n */\n protected isDefaultColumnScale(\n table: Table,\n column: TableColumn,\n scale: number,\n ): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name)\n const columnMetadata = metadata.findColumnWithDatabaseName(\n column.name,\n )\n if (\n columnMetadata &&\n columnMetadata.scale !== null &&\n columnMetadata.scale !== undefined\n )\n return false\n }\n\n if (\n this.connection.driver.dataTypeDefaults &&\n this.connection.driver.dataTypeDefaults[column.type] &&\n this.connection.driver.dataTypeDefaults[column.type].scale !==\n null &&\n this.connection.driver.dataTypeDefaults[column.type].scale !==\n undefined\n )\n return (\n this.connection.driver.dataTypeDefaults[column.type].scale ===\n scale\n )\n\n return false\n }\n\n /**\n * Executes sql used special for schema build.\n */\n protected async executeQueries(\n upQueries: Query | Query[],\n downQueries: Query | Query[],\n ): Promise<void> {\n if (InstanceChecker.isQuery(upQueries)) upQueries = [upQueries]\n if (InstanceChecker.isQuery(downQueries)) downQueries = [downQueries]\n\n this.sqlInMemory.upQueries.push(...upQueries)\n this.sqlInMemory.downQueries.push(...downQueries)\n\n // if sql-in-memory mode is enabled then simply store sql in memory and return\n if (this.sqlMemoryMode === true)\n return Promise.resolve() as Promise<any>\n\n for (const { query, parameters } of upQueries) {\n await this.query(query, parameters)\n }\n }\n\n /**\n * Generated an index name for a table and index\n */\n protected generateIndexName(\n table: Table | View,\n index: TableIndex,\n ): string {\n // new index may be passed without name. In this case we generate index name manually.\n return this.connection.namingStrategy.indexName(\n table,\n index.columnNames,\n index.where,\n )\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/query-runner/BaseQueryRunner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAUnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,OAAgB,eAAe;IAArC;QACI,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAY5E;;;WAGG;QACH,eAAU,GAAG,KAAK,CAAA;QAElB;;WAEG;QACH,wBAAmB,GAAG,KAAK,CAAA;QAE3B;;;WAGG;QACH,SAAI,GAAG,EAAE,CAAA;QAET;;WAEG;QACH,iBAAY,GAAY,EAAE,CAAA;QAE1B;;WAEG;QACH,gBAAW,GAAW,E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K,CAAC,WAAW,EACjB,KAAK,CAAC,KAAK,CACd,CAAA;IACL,CAAC;CACJ","file":"BaseQueryRunner.js","sourcesContent":["import { PostgresConnectionOptions } from \"../driver/postgres/PostgresConnectionOptions\"\nimport { Query } from \"../driver/Query\"\nimport { SqlInMemory } from \"../driver/SqlInMemory\"\nimport { SqlServerConnectionOptions } from \"../driver/sqlserver/SqlServerConnectionOptions\"\nimport { TableIndex } from \"../schema-builder/table/TableIndex\"\nimport { View } from \"../schema-builder/view/View\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { TableColumn } from \"../schema-builder/table/TableColumn\"\nimport { Broadcaster } from \"../subscriber/Broadcaster\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error/TypeORMError\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { TableForeignKey } from \"../schema-builder/table/TableForeignKey\"\nimport { OrmUtils } from \"../util/OrmUtils\"\nimport { MetadataTableType } from \"../driver/types/MetadataTableType\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\nexport abstract class BaseQueryRunner {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used by this query runner.\n */\n connection: DataSource\n\n /**\n * Entity manager working only with current query runner.\n */\n manager: EntityManager\n\n /**\n * Indicates if connection for this query runner is released.\n * Once its released, query runner cannot run queries anymore.\n */\n isReleased = false\n\n /**\n * Indicates if transaction is in progress.\n */\n isTransactionActive = false\n\n /**\n * Stores temporarily user data.\n * Useful for sharing data with subscribers.\n */\n data = {}\n\n /**\n * All synchronized tables in the database.\n */\n loadedTables: Table[] = []\n\n /**\n * All synchronized views in the database.\n */\n loadedViews: View[] = []\n\n /**\n * Broadcaster used on this query runner to broadcast entity events.\n */\n broadcaster: Broadcaster\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Real database connection from a connection pool used to perform queries.\n */\n protected databaseConnection: any\n\n /**\n * Indicates if special query runner mode in which sql queries won't be executed is enabled.\n */\n protected sqlMemoryMode: boolean = false\n\n /**\n * Sql-s stored if \"sql in memory\" mode is enabled.\n */\n protected sqlInMemory: SqlInMemory = new SqlInMemory()\n\n /**\n * Mode in which query runner executes.\n * Used for replication.\n * If replication is not setup its value is ignored.\n */\n protected mode: ReplicationMode\n\n /**\n * current depth of transaction.\n * for transactionDepth > 0 will use SAVEPOINT to start and commit/rollback transaction blocks\n */\n protected transactionDepth = 0\n\n private cachedTablePaths: Record<string, string> = {}\n\n // -------------------------------------------------------------------------\n // Public Abstract Methods\n // -------------------------------------------------------------------------\n\n /**\n * Executes a given SQL query.\n */\n abstract query(\n query: string,\n parameters?: any[],\n useStructuredResult?: boolean,\n ): Promise<any>\n\n // -------------------------------------------------------------------------\n // Protected Abstract Methods\n // -------------------------------------------------------------------------\n\n protected abstract loadTables(tablePaths?: string[]): Promise<Table[]>\n\n protected abstract loadViews(tablePaths?: string[]): Promise<View[]>\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n // Do nothing\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n // Do nothing\n }\n\n /**\n * Loads given table's data from the database.\n */\n async getTable(tablePath: string): Promise<Table | undefined> {\n this.loadedTables = await this.loadTables([tablePath])\n return this.loadedTables.length > 0 ? this.loadedTables[0] : undefined\n }\n\n /**\n * Loads all tables (with given names) from the database.\n */\n async getTables(tableNames?: string[]): Promise<Table[]> {\n if (!tableNames) {\n // Don't cache in this case.\n // This is the new case & isn't used anywhere else anyway.\n return await this.loadTables(tableNames)\n }\n\n this.loadedTables = await this.loadTables(tableNames)\n return this.loadedTables\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getView(viewPath: string): Promise<View | undefined> {\n this.loadedViews = await this.loadViews([viewPath])\n return this.loadedViews.length > 0 ? this.loadedViews[0] : undefined\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getViews(viewPaths?: string[]): Promise<View[]> {\n this.loadedViews = await this.loadViews(viewPaths)\n return this.loadedViews\n }\n\n /**\n * Enables special query runner mode in which sql queries won't be executed,\n * instead they will be memorized into a special variable inside query runner.\n * You can get memorized sql using getMemorySql() method.\n */\n enableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory()\n this.sqlMemoryMode = true\n }\n\n /**\n * Disables special query runner mode in which sql queries won't be executed\n * started by calling enableSqlMemory() method.\n *\n * Previously memorized sql will be flushed.\n */\n disableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory()\n this.sqlMemoryMode = false\n }\n\n /**\n * Flushes all memorized sqls.\n */\n clearSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory()\n }\n\n /**\n * Gets sql stored in the memory. Parameters in the sql are already replaced.\n */\n getMemorySql(): SqlInMemory {\n return this.sqlInMemory\n }\n\n /**\n * Executes up sql queries.\n */\n async executeMemoryUpSql(): Promise<void> {\n for (const { query, parameters } of this.sqlInMemory.upQueries) {\n await this.query(query, parameters)\n }\n }\n\n /**\n * Executes down sql queries.\n */\n async executeMemoryDownSql(): Promise<void> {\n for (const {\n query,\n parameters,\n } of this.sqlInMemory.downQueries.reverse()) {\n await this.query(query, parameters)\n }\n }\n\n getReplicationMode(): ReplicationMode {\n return this.mode\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets view from previously loaded views, otherwise loads it from database.\n */\n protected async getCachedView(viewName: string): Promise<View> {\n const view = this.loadedViews.find((view) => view.name === viewName)\n if (view) return view\n\n const foundViews = await this.loadViews([viewName])\n if (foundViews.length > 0) {\n this.loadedViews.push(foundViews[0])\n return foundViews[0]\n } else {\n throw new TypeORMError(`View \"${viewName}\" does not exist.`)\n }\n }\n\n /**\n * Gets table from previously loaded tables, otherwise loads it from database.\n */\n protected async getCachedTable(tableName: string): Promise<Table> {\n if (tableName in this.cachedTablePaths) {\n const tablePath = this.cachedTablePaths[tableName]\n const table = this.loadedTables.find(\n (table) => this.getTablePath(table) === tablePath,\n )\n\n if (table) {\n return table\n }\n }\n\n const foundTables = await this.loadTables([tableName])\n\n if (foundTables.length > 0) {\n const foundTablePath = this.getTablePath(foundTables[0])\n\n const cachedTable = this.loadedTables.find(\n (table) => this.getTablePath(table) === foundTablePath,\n )\n\n if (!cachedTable) {\n this.cachedTablePaths[tableName] = this.getTablePath(\n foundTables[0],\n )\n this.loadedTables.push(foundTables[0])\n return foundTables[0]\n } else {\n return cachedTable\n }\n } else {\n throw new TypeORMError(`Table \"${tableName}\" does not exist.`)\n }\n }\n\n /**\n * Replaces loaded table with given changed table.\n */\n protected replaceCachedTable(table: Table, changedTable: Table): void {\n const oldTablePath = this.getTablePath(table)\n const foundTable = this.loadedTables.find(\n (loadedTable) => this.getTablePath(loadedTable) === oldTablePath,\n )\n\n // Clean up the lookup cache..\n for (const [key, cachedPath] of Object.entries(this.cachedTablePaths)) {\n if (cachedPath === oldTablePath) {\n this.cachedTablePaths[key] = this.getTablePath(changedTable)\n }\n }\n\n if (foundTable) {\n foundTable.database = changedTable.database\n foundTable.schema = changedTable.schema\n foundTable.name = changedTable.name\n foundTable.columns = changedTable.columns\n foundTable.indices = changedTable.indices\n foundTable.foreignKeys = changedTable.foreignKeys\n foundTable.uniques = changedTable.uniques\n foundTable.checks = changedTable.checks\n foundTable.justCreated = changedTable.justCreated\n foundTable.engine = changedTable.engine\n }\n }\n\n protected getTablePath(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): string {\n const parsed = this.connection.driver.parseTableName(target)\n\n return this.connection.driver.buildTableName(\n parsed.tableName,\n parsed.schema,\n parsed.database,\n )\n }\n\n protected getTypeormMetadataTableName(): string {\n const options = <\n SqlServerConnectionOptions | PostgresConnectionOptions\n >this.connection.driver.options\n return this.connection.driver.buildTableName(\n this.connection.metadataTableName,\n options.schema,\n options.database,\n )\n }\n\n /**\n * Generates SQL query to select record from typeorm metadata table.\n */\n protected selectTypeormMetadataSql({\n database,\n schema,\n table,\n type,\n name,\n }: {\n database?: string\n schema?: string\n table?: string\n type: MetadataTableType\n name: string\n }): Query {\n const qb = this.connection.createQueryBuilder()\n const selectQb = qb\n .select()\n .from(this.getTypeormMetadataTableName(), \"t\")\n .where(`${qb.escape(\"type\")} = :type`, { type })\n .andWhere(`${qb.escape(\"name\")} = :name`, { name })\n\n if (database) {\n selectQb.andWhere(`${qb.escape(\"database\")} = :database`, {\n database,\n })\n }\n\n if (schema) {\n selectQb.andWhere(`${qb.escape(\"schema\")} = :schema`, { schema })\n }\n\n if (table) {\n selectQb.andWhere(`${qb.escape(\"table\")} = :table`, { table })\n }\n\n const [query, parameters] = selectQb.getQueryAndParameters()\n return new Query(query, parameters)\n }\n\n /**\n * Generates SQL query to insert a record into typeorm metadata table.\n */\n protected insertTypeormMetadataSql({\n database,\n schema,\n table,\n type,\n name,\n value,\n }: {\n database?: string\n schema?: string\n table?: string\n type: MetadataTableType\n name: string\n value?: string\n }): Query {\n const [query, parameters] = this.connection\n .createQueryBuilder()\n .insert()\n .into(this.getTypeormMetadataTableName())\n .values({\n database: database,\n schema: schema,\n table: table,\n type: type,\n name: name,\n value: value,\n })\n .getQueryAndParameters()\n\n return new Query(query, parameters)\n }\n\n /**\n * Generates SQL query to delete a record from typeorm metadata table.\n */\n protected deleteTypeormMetadataSql({\n database,\n schema,\n table,\n type,\n name,\n }: {\n database?: string\n schema?: string\n table?: string\n type: MetadataTableType\n name: string\n }): Query {\n const qb = this.connection.createQueryBuilder()\n const deleteQb = qb\n .delete()\n .from(this.getTypeormMetadataTableName())\n .where(`${qb.escape(\"type\")} = :type`, { type })\n .andWhere(`${qb.escape(\"name\")} = :name`, { name })\n\n if (database) {\n deleteQb.andWhere(`${qb.escape(\"database\")} = :database`, {\n database,\n })\n }\n\n if (schema) {\n deleteQb.andWhere(`${qb.escape(\"schema\")} = :schema`, { schema })\n }\n\n if (table) {\n deleteQb.andWhere(`${qb.escape(\"table\")} = :table`, { table })\n }\n\n const [query, parameters] = deleteQb.getQueryAndParameters()\n return new Query(query, parameters)\n }\n\n /**\n * Checks if at least one of column properties was changed.\n * Does not checks column type, length and autoincrement, because these properties changes separately.\n */\n protected isColumnChanged(\n oldColumn: TableColumn,\n newColumn: TableColumn,\n checkDefault?: boolean,\n checkComment?: boolean,\n checkEnum = true,\n ): boolean {\n // this logs need to debug issues in column change detection. Do not delete it!\n\n // console.log(\"charset ---------------\");\n // console.log(oldColumn.charset !== newColumn.charset);\n // console.log(oldColumn.charset, newColumn.charset);\n // console.log(\"collation ---------------\");\n // console.log(oldColumn.collation !== newColumn.collation);\n // console.log(oldColumn.collation, newColumn.collation);\n // console.log(\"precision ---------------\");\n // console.log(oldColumn.precision !== newColumn.precision);\n // console.log(oldColumn.precision, newColumn.precision);\n // console.log(\"scale ---------------\");\n // console.log(oldColumn.scale !== newColumn.scale);\n // console.log(oldColumn.scale, newColumn.scale);\n // console.log(\"default ---------------\");\n // console.log((checkDefault && oldColumn.default !== newColumn.default));\n // console.log(oldColumn.default, newColumn.default);\n // console.log(\"isNullable ---------------\");\n // console.log(oldColumn.isNullable !== newColumn.isNullable);\n // console.log(oldColumn.isNullable, newColumn.isNullable);\n // console.log(\"comment ---------------\");\n // console.log((checkComment && oldColumn.comment !== newColumn.comment));\n // console.log(oldColumn.comment, newColumn.comment);\n // console.log(\"enum ---------------\");\n // console.log(!OrmUtils.isArraysEqual(oldColumn.enum || [], newColumn.enum || []));\n // console.log(oldColumn.enum, newColumn.enum);\n\n return (\n oldColumn.charset !== newColumn.charset ||\n oldColumn.collation !== newColumn.collation ||\n oldColumn.precision !== newColumn.precision ||\n oldColumn.scale !== newColumn.scale ||\n oldColumn.width !== newColumn.width || // MySQL only\n oldColumn.zerofill !== newColumn.zerofill || // MySQL only\n oldColumn.unsigned !== newColumn.unsigned || // MySQL only\n oldColumn.asExpression !== newColumn.asExpression ||\n (checkDefault && oldColumn.default !== newColumn.default) ||\n oldColumn.onUpdate !== newColumn.onUpdate || // MySQL only\n oldColumn.isNullable !== newColumn.isNullable ||\n (checkComment && oldColumn.comment !== newColumn.comment) ||\n (checkEnum && this.isEnumChanged(oldColumn, newColumn))\n )\n }\n\n protected isEnumChanged(oldColumn: TableColumn, newColumn: TableColumn) {\n return !OrmUtils.isArraysEqual(\n oldColumn.enum || [],\n newColumn.enum || [],\n )\n }\n\n /**\n * Checks if column length is by default.\n */\n protected isDefaultColumnLength(\n table: Table,\n column: TableColumn,\n length: string,\n ): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name)\n const columnMetadata = metadata.findColumnWithDatabaseName(\n column.name,\n )\n\n if (columnMetadata) {\n const columnMetadataLength =\n this.connection.driver.getColumnLength(columnMetadata)\n if (columnMetadataLength) return false\n }\n }\n\n if (\n this.connection.driver.dataTypeDefaults &&\n this.connection.driver.dataTypeDefaults[column.type] &&\n this.connection.driver.dataTypeDefaults[column.type].length\n ) {\n return (\n this.connection.driver.dataTypeDefaults[\n column.type\n ].length!.toString() === length.toString()\n )\n }\n\n return false\n }\n\n /**\n * Checks if column precision is by default.\n */\n protected isDefaultColumnPrecision(\n table: Table,\n column: TableColumn,\n precision: number,\n ): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name)\n const columnMetadata = metadata.findColumnWithDatabaseName(\n column.name,\n )\n if (\n columnMetadata &&\n columnMetadata.precision !== null &&\n columnMetadata.precision !== undefined\n )\n return false\n }\n\n if (\n this.connection.driver.dataTypeDefaults &&\n this.connection.driver.dataTypeDefaults[column.type] &&\n this.connection.driver.dataTypeDefaults[column.type].precision !==\n null &&\n this.connection.driver.dataTypeDefaults[column.type].precision !==\n undefined\n )\n return (\n this.connection.driver.dataTypeDefaults[column.type]\n .precision === precision\n )\n\n return false\n }\n\n /**\n * Checks if column scale is by default.\n */\n protected isDefaultColumnScale(\n table: Table,\n column: TableColumn,\n scale: number,\n ): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name)\n const columnMetadata = metadata.findColumnWithDatabaseName(\n column.name,\n )\n if (\n columnMetadata &&\n columnMetadata.scale !== null &&\n columnMetadata.scale !== undefined\n )\n return false\n }\n\n if (\n this.connection.driver.dataTypeDefaults &&\n this.connection.driver.dataTypeDefaults[column.type] &&\n this.connection.driver.dataTypeDefaults[column.type].scale !==\n null &&\n this.connection.driver.dataTypeDefaults[column.type].scale !==\n undefined\n )\n return (\n this.connection.driver.dataTypeDefaults[column.type].scale ===\n scale\n )\n\n return false\n }\n\n /**\n * Executes sql used special for schema build.\n */\n protected async executeQueries(\n upQueries: Query | Query[],\n downQueries: Query | Query[],\n ): Promise<void> {\n if (InstanceChecker.isQuery(upQueries)) upQueries = [upQueries]\n if (InstanceChecker.isQuery(downQueries)) downQueries = [downQueries]\n\n this.sqlInMemory.upQueries.push(...upQueries)\n this.sqlInMemory.downQueries.push(...downQueries)\n\n // if sql-in-memory mode is enabled then simply store sql in memory and return\n if (this.sqlMemoryMode === true)\n return Promise.resolve() as Promise<any>\n\n for (const { query, parameters } of upQueries) {\n await this.query(query, parameters)\n }\n }\n\n /**\n * Generated an index name for a table and index\n */\n protected generateIndexName(\n table: Table | View,\n index: TableIndex,\n ): string {\n // new index may be passed without name. In this case we generate index name manually.\n return this.connection.namingStrategy.indexName(\n table,\n index.columnNames,\n index.where,\n )\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -55,4 +55,16 @@ export declare class DateUtils {
|
|
|
55
55
|
* Formats given number to "0x" format, e.g. if it is 1 then it will return "01".
|
|
56
56
|
*/
|
|
57
57
|
private static formatMilliseconds;
|
|
58
|
+
/**
|
|
59
|
+
* Parse a date without the UTC-offset of the device
|
|
60
|
+
*
|
|
61
|
+
* The problem here is with wrong timezone.
|
|
62
|
+
*
|
|
63
|
+
* For example:
|
|
64
|
+
*
|
|
65
|
+
* ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
|
|
66
|
+
* in my timezone, which is not true for my timezone (GMT-0300). It should
|
|
67
|
+
* be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
|
|
68
|
+
*/
|
|
69
|
+
private static parseDateAsISO;
|
|
58
70
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parseISO } from "date-fns";
|
|
2
1
|
/**
|
|
3
2
|
* Provides utilities to transform hydrated and persisted data.
|
|
4
3
|
*/
|
|
@@ -33,21 +32,9 @@ export class DateUtils {
|
|
|
33
32
|
* Converts given value into date object.
|
|
34
33
|
*/
|
|
35
34
|
static mixedDateToDate(mixedDate, toUtc = false, useMilliseconds = true) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
* The problem here is with wrong timezone.
|
|
41
|
-
*
|
|
42
|
-
* For example:
|
|
43
|
-
*
|
|
44
|
-
* ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
|
|
45
|
-
* in my timezone, which is not true for my timezone (GMT-0300). It should
|
|
46
|
-
* be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
|
|
47
|
-
*
|
|
48
|
-
* https://stackoverflow.com/a/2587398
|
|
49
|
-
*/
|
|
50
|
-
let date = typeof mixedDate === "string" ? parseISO(mixedDate) : mixedDate;
|
|
35
|
+
let date = typeof mixedDate === "string"
|
|
36
|
+
? DateUtils.parseDateAsISO(mixedDate)
|
|
37
|
+
: mixedDate;
|
|
51
38
|
if (toUtc)
|
|
52
39
|
date = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
|
|
53
40
|
if (!useMilliseconds)
|
|
@@ -217,6 +204,23 @@ export class DateUtils {
|
|
|
217
204
|
return String(value);
|
|
218
205
|
}
|
|
219
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Parse a date without the UTC-offset of the device
|
|
209
|
+
*
|
|
210
|
+
* The problem here is with wrong timezone.
|
|
211
|
+
*
|
|
212
|
+
* For example:
|
|
213
|
+
*
|
|
214
|
+
* ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
|
|
215
|
+
* in my timezone, which is not true for my timezone (GMT-0300). It should
|
|
216
|
+
* be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
|
|
217
|
+
*/
|
|
218
|
+
static parseDateAsISO(dateString) {
|
|
219
|
+
const date = new Date(dateString);
|
|
220
|
+
const offset = date.getTimezoneOffset() * 60 * 1000;
|
|
221
|
+
const utc = date.getTime() + offset;
|
|
222
|
+
return new Date(utc);
|
|
223
|
+
}
|
|
220
224
|
}
|
|
221
225
|
|
|
222
226
|
//# sourceMappingURL=DateUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/util/DateUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,OAAO,CACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAChD,GAAG;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O,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAChE,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,KAAU;QAChC,OAAO,EAAE,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,KAAU,EAAE,cAA8B;QAChE,IACI,cAAc,CAAC,IAAI;YACnB,CAAC,KAAK,CAAC,KAAK,CAAC;YACb,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EACnD;YACE,4DAA4D;YAC5D,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;SAC1B;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,4EAA4E;IAC5E,yBAAyB;IACzB,4EAA4E;IAE5E;;OAEG;IACK,MAAM,CAAC,mBAAmB,CAAC,KAAa,EAAE,WAAW,GAAG,CAAC;QAC7D,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QAEnC,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;CACJ","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { parseISO } from \"date-fns\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\" ? parseISO(mixedDate) : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot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AM,CAAC,WAAW,CAAC,CAAA;QAEnC,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACK,MAAM,CAAC,cAAc,CAAC,UAAkB;QAC5C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,CAAA;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;QACnD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAA;QAEnC,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;CACJ","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n let date =\n typeof mixedDate === \"string\"\n ? DateUtils.parseDateAsISO(mixedDate)\n : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n\n /**\n * Parse a date without the UTC-offset of the device\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n */\n private static parseDateAsISO(dateString: string): Date {\n const date = new Date(dateString)\n const offset = date.getTimezoneOffset() * 60 * 1000\n const utc = date.getTime() + offset\n\n return new Date(utc)\n }\n}\n"],"sourceRoot":".."}
|