typeorm 0.3.14-dev.0194f17 → 0.3.14
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 +0 -1
- package/browser/connection/ConnectionOptionsReader.d.ts +0 -1
- package/browser/connection/ConnectionOptionsReader.js +0 -15
- package/browser/connection/ConnectionOptionsReader.js.map +1 -1
- package/browser/globals.d.ts +1 -1
- package/browser/globals.js +2 -2
- package/browser/globals.js.map +1 -1
- package/commands/InitCommand.js +2 -2
- package/commands/InitCommand.js.map +1 -1
- package/connection/ConnectionOptionsReader.d.ts +0 -1
- package/connection/ConnectionOptionsReader.js +0 -15
- package/connection/ConnectionOptionsReader.js.map +1 -1
- package/globals.d.ts +1 -1
- package/globals.js +2 -2
- package/globals.js.map +1 -1
- package/package.json +268 -1
- package/browser/connection/options-reader/ConnectionOptionsXmlReader.d.ts +0 -16
- package/browser/connection/options-reader/ConnectionOptionsXmlReader.js +0 -66
- package/browser/connection/options-reader/ConnectionOptionsXmlReader.js.map +0 -1
- package/browser/connection/options-reader/ConnectionOptionsYmlReader.d.ts +0 -12
- package/browser/connection/options-reader/ConnectionOptionsYmlReader.js +0 -28
- package/browser/connection/options-reader/ConnectionOptionsYmlReader.js.map +0 -1
- package/connection/options-reader/ConnectionOptionsXmlReader.d.ts +0 -16
- package/connection/options-reader/ConnectionOptionsXmlReader.js +0 -70
- package/connection/options-reader/ConnectionOptionsXmlReader.js.map +0 -1
- package/connection/options-reader/ConnectionOptionsYmlReader.d.ts +0 -12
- package/connection/options-reader/ConnectionOptionsYmlReader.js +0 -33
- package/connection/options-reader/ConnectionOptionsYmlReader.js.map +0 -1
package/README.md
CHANGED
|
@@ -66,7 +66,6 @@ TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate
|
|
|
66
66
|
- Listeners and subscribers (hooks).
|
|
67
67
|
- Supports closure table pattern.
|
|
68
68
|
- Schema declaration in models or separate configuration files.
|
|
69
|
-
- Connection configuration in json / xml / yml / env formats.
|
|
70
69
|
- Supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / Oracle / SAP Hana / sql.js.
|
|
71
70
|
- Supports MongoDB NoSQL database.
|
|
72
71
|
- Works in NodeJS / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
|
2
2
|
/**
|
|
3
3
|
* Reads connection options from the ormconfig.
|
|
4
|
-
* Can read from multiple file extensions including env, json, js, xml and yml.
|
|
5
4
|
*/
|
|
6
5
|
export declare class ConnectionOptionsReader {
|
|
7
6
|
protected options?: {
|
|
@@ -2,14 +2,11 @@ import appRootPath from "app-root-path";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { PlatformTools } from "../platform/PlatformTools";
|
|
4
4
|
import { ConnectionOptionsEnvReader } from "./options-reader/ConnectionOptionsEnvReader";
|
|
5
|
-
import { ConnectionOptionsYmlReader } from "./options-reader/ConnectionOptionsYmlReader";
|
|
6
|
-
import { ConnectionOptionsXmlReader } from "./options-reader/ConnectionOptionsXmlReader";
|
|
7
5
|
import { TypeORMError } from "../error";
|
|
8
6
|
import { isAbsolute } from "../util/PathUtils";
|
|
9
7
|
import { importOrRequireFile } from "../util/ImportUtils";
|
|
10
8
|
/**
|
|
11
9
|
* Reads connection options from the ormconfig.
|
|
12
|
-
* Can read from multiple file extensions including env, json, js, xml and yml.
|
|
13
10
|
*/
|
|
14
11
|
export class ConnectionOptionsReader {
|
|
15
12
|
// -------------------------------------------------------------------------
|
|
@@ -70,9 +67,6 @@ export class ConnectionOptionsReader {
|
|
|
70
67
|
"mts",
|
|
71
68
|
"cts",
|
|
72
69
|
"json",
|
|
73
|
-
"yml",
|
|
74
|
-
"yaml",
|
|
75
|
-
"xml",
|
|
76
70
|
];
|
|
77
71
|
// Detect if baseFilePath contains file extension
|
|
78
72
|
const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf("."));
|
|
@@ -119,15 +113,6 @@ export class ConnectionOptionsReader {
|
|
|
119
113
|
else if (foundFileFormat === "json") {
|
|
120
114
|
connectionOptions = require(configFile);
|
|
121
115
|
}
|
|
122
|
-
else if (foundFileFormat === "yml") {
|
|
123
|
-
connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);
|
|
124
|
-
}
|
|
125
|
-
else if (foundFileFormat === "yaml") {
|
|
126
|
-
connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);
|
|
127
|
-
}
|
|
128
|
-
else if (foundFileFormat === "xml") {
|
|
129
|
-
connectionOptions = await new ConnectionOptionsXmlReader().read(configFile);
|
|
130
|
-
}
|
|
131
116
|
// normalize and return connection options
|
|
132
117
|
if (connectionOptions) {
|
|
133
118
|
return this.normalizeConnectionOptions(connectionOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAEzD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAChC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,OAWT;QAXS,YAAO,GAAP,OAAO,CAWhB;IACF,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IA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AA;QAElC,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\"\nimport path from \"path\"\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { ConnectionOptionsEnvReader } from \"./options-reader/ConnectionOptionsEnvReader\"\nimport { ConnectionOptionsYmlReader } from \"./options-reader/ConnectionOptionsYmlReader\"\nimport { ConnectionOptionsXmlReader } from \"./options-reader/ConnectionOptionsXmlReader\"\nimport { TypeORMError } from \"../error\"\nimport { isAbsolute } from \"../util/PathUtils\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Reads connection options from the ormconfig.\n * Can read from multiple file extensions including env, json, js, xml and yml.\n */\nexport class ConnectionOptionsReader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n },\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<DataSourceOptions[]> {\n const options = await this.load()\n if (!options)\n throw new TypeORMError(\n `No connection options were found in any orm configuration files.`,\n )\n\n return options\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<DataSourceOptions> {\n const allOptions = await this.all()\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n if (!targetOptions)\n throw new TypeORMError(\n `Cannot find connection ${name} because its not defined in any orm configuration files.`,\n )\n\n return targetOptions\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load()\n if (!allOptions) return false\n\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n return !!targetOptions\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<DataSourceOptions[] | undefined> {\n let connectionOptions:\n | DataSourceOptions\n | DataSourceOptions[]\n | undefined = undefined\n\n const fileFormats = [\n \"env\",\n \"js\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"mts\",\n \"cts\",\n \"json\",\n \"yml\",\n \"yaml\",\n \"xml\",\n ]\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(\n this.baseFilePath.lastIndexOf(\".\"),\n )\n const fileExtension = fileFormats.find(\n (extension) => `.${extension}` === possibleExtension,\n )\n\n // try to find any of following configuration formats\n const foundFileFormat =\n fileExtension ||\n fileFormats.find((format) => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format)\n })\n\n // Determine config file name\n const configFile = fileExtension\n ? this.baseFilePath\n : this.baseFilePath + \".\" + foundFileFormat\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile)\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\")\n }\n\n // try to find connection options from any of available sources of configuration\n if (\n PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") ||\n PlatformTools.getEnvVariable(\"TYPEORM_URL\")\n ) {\n connectionOptions = await new ConnectionOptionsEnvReader().read()\n } else if (\n foundFileFormat === \"js\" ||\n foundFileFormat === \"mjs\" ||\n foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" ||\n foundFileFormat === \"mts\" ||\n foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] =\n await importOrRequireFile(configFile)\n const configModule = await importOrRequireResult\n\n if (\n moduleSystem === \"esm\" ||\n (configModule &&\n \"__esModule\" in configModule &&\n \"default\" in configModule)\n ) {\n connectionOptions = configModule.default\n } else {\n connectionOptions = configModule\n }\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile)\n } else if (foundFileFormat === \"yml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(\n configFile,\n )\n } else if (foundFileFormat === \"yaml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(\n configFile,\n )\n } else if (foundFileFormat === \"xml\") {\n connectionOptions = await new ConnectionOptionsXmlReader().read(\n configFile,\n )\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions)\n }\n\n return undefined\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(\n connectionOptions: DataSourceOptions | DataSourceOptions[],\n ): DataSourceOptions[] {\n if (!Array.isArray(connectionOptions))\n connectionOptions = [connectionOptions]\n\n connectionOptions.forEach((options) => {\n options.baseDirectory = this.baseDirectory\n if (options.entities) {\n const entities = (options.entities as any[]).map((entity) => {\n if (\n typeof entity === \"string\" &&\n entity.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + entity\n\n return entity\n })\n Object.assign(connectionOptions, { entities: entities })\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(\n (subscriber) => {\n if (\n typeof subscriber === \"string\" &&\n subscriber.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + subscriber\n\n return subscriber\n },\n )\n Object.assign(connectionOptions, { subscribers: subscribers })\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(\n (migration) => {\n if (\n typeof migration === \"string\" &&\n migration.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + migration\n\n return migration\n },\n )\n Object.assign(connectionOptions, { migrations: migrations })\n }\n\n // make database path file in sqlite relative to package.json\n if (\n options.type === \"sqlite\" ||\n options.type === \"better-sqlite3\"\n ) {\n if (\n typeof options.database === \"string\" &&\n !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\"\n ) {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database,\n })\n }\n }\n })\n\n return connectionOptions\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName)\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root) return this.options.root\n\n return appRootPath.path\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName\n\n return \"ormconfig\"\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAEzD;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAChC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,OAWT;QAXS,YAAO,GAAP,OAAO,CAWhB;IACF,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,GAAG;QACL,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACjC,IAAI,CAAC,OAAO;YACR,MAAM,IAAI,YAAY,CAClB,kEAAkE,CACrE,CAAA;QAEL,O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AC,OAAO,EAAE;wBACnB,QAAQ,EAAE,IAAI,CAAC,aAAa,GAAG,GAAG,GAAG,OAAO,CAAC,QAAQ;qBACxD,CAAC,CAAA;iBACL;aACJ;QACL,CAAC,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAA;IAC5B,CAAC;IAED;;OAEG;IACH,IAAc,YAAY;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IAChE,CAAC;IAED;;OAEG;IACH,IAAc,aAAa;QACvB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;QAE/D,OAAO,WAAW,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,IAAc,cAAc;QACxB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU;YACvC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAA;QAElC,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\"\nimport path from \"path\"\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { ConnectionOptionsEnvReader } from \"./options-reader/ConnectionOptionsEnvReader\"\nimport { TypeORMError } from \"../error\"\nimport { isAbsolute } from \"../util/PathUtils\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Reads connection options from the ormconfig.\n */\nexport class ConnectionOptionsReader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n },\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<DataSourceOptions[]> {\n const options = await this.load()\n if (!options)\n throw new TypeORMError(\n `No connection options were found in any orm configuration files.`,\n )\n\n return options\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<DataSourceOptions> {\n const allOptions = await this.all()\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n if (!targetOptions)\n throw new TypeORMError(\n `Cannot find connection ${name} because its not defined in any orm configuration files.`,\n )\n\n return targetOptions\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load()\n if (!allOptions) return false\n\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n return !!targetOptions\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<DataSourceOptions[] | undefined> {\n let connectionOptions:\n | DataSourceOptions\n | DataSourceOptions[]\n | undefined = undefined\n\n const fileFormats = [\n \"env\",\n \"js\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"mts\",\n \"cts\",\n \"json\",\n ]\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(\n this.baseFilePath.lastIndexOf(\".\"),\n )\n const fileExtension = fileFormats.find(\n (extension) => `.${extension}` === possibleExtension,\n )\n\n // try to find any of following configuration formats\n const foundFileFormat =\n fileExtension ||\n fileFormats.find((format) => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format)\n })\n\n // Determine config file name\n const configFile = fileExtension\n ? this.baseFilePath\n : this.baseFilePath + \".\" + foundFileFormat\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile)\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\")\n }\n\n // try to find connection options from any of available sources of configuration\n if (\n PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") ||\n PlatformTools.getEnvVariable(\"TYPEORM_URL\")\n ) {\n connectionOptions = await new ConnectionOptionsEnvReader().read()\n } else if (\n foundFileFormat === \"js\" ||\n foundFileFormat === \"mjs\" ||\n foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" ||\n foundFileFormat === \"mts\" ||\n foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] =\n await importOrRequireFile(configFile)\n const configModule = await importOrRequireResult\n\n if (\n moduleSystem === \"esm\" ||\n (configModule &&\n \"__esModule\" in configModule &&\n \"default\" in configModule)\n ) {\n connectionOptions = configModule.default\n } else {\n connectionOptions = configModule\n }\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile)\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions)\n }\n\n return undefined\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(\n connectionOptions: DataSourceOptions | DataSourceOptions[],\n ): DataSourceOptions[] {\n if (!Array.isArray(connectionOptions))\n connectionOptions = [connectionOptions]\n\n connectionOptions.forEach((options) => {\n options.baseDirectory = this.baseDirectory\n if (options.entities) {\n const entities = (options.entities as any[]).map((entity) => {\n if (\n typeof entity === \"string\" &&\n entity.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + entity\n\n return entity\n })\n Object.assign(connectionOptions, { entities: entities })\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(\n (subscriber) => {\n if (\n typeof subscriber === \"string\" &&\n subscriber.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + subscriber\n\n return subscriber\n },\n )\n Object.assign(connectionOptions, { subscribers: subscribers })\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(\n (migration) => {\n if (\n typeof migration === \"string\" &&\n migration.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + migration\n\n return migration\n },\n )\n Object.assign(connectionOptions, { migrations: migrations })\n }\n\n // make database path file in sqlite relative to package.json\n if (\n options.type === \"sqlite\" ||\n options.type === \"better-sqlite3\"\n ) {\n if (\n typeof options.database === \"string\" &&\n !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\"\n ) {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database,\n })\n }\n }\n })\n\n return connectionOptions\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName)\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root) return this.options.root\n\n return appRootPath.path\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName\n\n return \"ormconfig\"\n }\n}\n"],"sourceRoot":".."}
|
package/browser/globals.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function createConnection(options: DataSourceOptions): Promise<Da
|
|
|
51
51
|
* Creates new connections and registers them in the manager.
|
|
52
52
|
*
|
|
53
53
|
* If connection options were not specified, then it will try to create connection automatically,
|
|
54
|
-
* based on content of ormconfig (json/js/
|
|
54
|
+
* based on content of ormconfig (json/js/env) file or environment variables.
|
|
55
55
|
* All connections from the ormconfig will be created.
|
|
56
56
|
*
|
|
57
57
|
* @deprecated
|
package/browser/globals.js
CHANGED
|
@@ -41,7 +41,7 @@ export function getConnectionManager() {
|
|
|
41
41
|
* Creates a new connection and registers it in the manager.
|
|
42
42
|
*
|
|
43
43
|
* If connection options were not specified, then it will try to create connection automatically,
|
|
44
|
-
* based on content of ormconfig (json/js/
|
|
44
|
+
* based on content of ormconfig (json/js/env) file or environment variables.
|
|
45
45
|
* Only one connection from ormconfig will be created (name "default" or connection without name).
|
|
46
46
|
*
|
|
47
47
|
* @deprecated
|
|
@@ -57,7 +57,7 @@ export async function createConnection(optionsOrName) {
|
|
|
57
57
|
* Creates new connections and registers them in the manager.
|
|
58
58
|
*
|
|
59
59
|
* If connection options were not specified, then it will try to create connection automatically,
|
|
60
|
-
* based on content of ormconfig (json/js/
|
|
60
|
+
* based on content of ormconfig (json/js/env) file or environment variables.
|
|
61
61
|
* All connections from the ormconfig will be created.
|
|
62
62
|
*
|
|
63
63
|
* @deprecated
|
package/browser/globals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/globals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAW9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD;;GAEG;AACH,MAAM,UAAU,sBAAsB;IAClC,8FAA8F;IAC9F,qGAAqG;IACrG,mGAAmG;IACnG,8EAA8E;IAC9E,6FAA6F;IAC7F,8FAA8F;IAC9F,iFAAiF;IACjF,4FAA4F;IAC5F,MAAM,WAAW,GAAG,aAAa,CAAC,iBAAiB,EAAE,CAAA;IACrD,IAAI,CAAC,WAAW,CAAC,0BAA0B;QACvC,WAAW,CAAC,0BAA0B,GAAG,IAAI,mBAAmB,EAAE,CAAA;IAEtE,OAAO,WAAW,CAAC,0BAA0B,CAAA;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,iBAAyB,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,OAAO,aAAa,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,kBAAkB,CAChE,KAAK,CACR,CAAA;KACJ;IAED,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC,kBAAkB,EAAE,CAAA;AAC7D,CAAC","file":"globals.js","sourcesContent":["import { MetadataArgsStorage } from \"./metadata-args/MetadataArgsStorage\"\nimport { PlatformTools } from \"./platform/PlatformTools\"\nimport { DataSourceOptions } from \"./data-source/DataSourceOptions\"\nimport { ConnectionOptionsReader } from \"./connection/ConnectionOptionsReader\"\nimport { ConnectionManager } from \"./connection/ConnectionManager\"\nimport { getFromContainer } from \"./container\"\nimport { DataSource } from \"./data-source/DataSource\"\nimport { EntityManager } from \"./entity-manager/EntityManager\"\nimport { MongoEntityManager } from \"./entity-manager/MongoEntityManager\"\nimport { SqljsEntityManager } from \"./entity-manager/SqljsEntityManager\"\nimport { EntityTarget } from \"./common/EntityTarget\"\nimport { Repository } from \"./repository/Repository\"\nimport { TreeRepository } from \"./repository/TreeRepository\"\nimport { ObjectType } from \"./common/ObjectType\"\nimport { MongoRepository } from \"./repository/MongoRepository\"\nimport { SelectQueryBuilder } from \"./query-builder/SelectQueryBuilder\"\nimport { ObjectUtils } from \"./util/ObjectUtils\"\nimport { ObjectLiteral } from \"./common/ObjectLiteral\"\n\n/**\n * Gets metadata args storage.\n */\nexport function getMetadataArgsStorage(): MetadataArgsStorage {\n // we should store metadata storage in a global variable otherwise it brings too much problems\n // one of the problem is that if any entity (or any other) will be imported before consumer will call\n // useContainer method with his own container implementation, that entity will be registered in the\n // old old container (default one post probably) and consumer will his entity.\n // calling useContainer before he imports any entity (or any other) is not always convenient.\n // another reason is that when we run migrations typeorm is being called from a global package\n // and it may load entities which register decorators in typeorm of local package\n // this leads to impossibility of usage of entities in migrations and cli related operations\n const globalScope = PlatformTools.getGlobalVariable()\n if (!globalScope.typeormMetadataArgsStorage)\n globalScope.typeormMetadataArgsStorage = new MetadataArgsStorage()\n\n return globalScope.typeormMetadataArgsStorage\n}\n\n/**\n * Reads connection options stored in ormconfig configuration file.\n *\n * @deprecated\n */\nexport async function getConnectionOptions(\n connectionName: string = \"default\",\n): Promise<DataSourceOptions> {\n return new ConnectionOptionsReader().get(connectionName)\n}\n\n/**\n * Gets a ConnectionManager which creates connections.\n *\n * @deprecated\n */\nexport function getConnectionManager(): ConnectionManager {\n return getFromContainer(ConnectionManager)\n}\n\n/**\n * Creates a new connection and registers it in the manager.\n * Only one connection from ormconfig will be created (name \"default\" or connection without name).\n *\n * @deprecated\n */\nexport async function createConnection(): Promise<DataSource>\n\n/**\n * Creates a new connection from the ormconfig file with a given name.\n *\n * @deprecated\n */\nexport async function createConnection(name: string): Promise<DataSource>\n\n/**\n * Creates a new connection and registers it in the manager.\n *\n * @deprecated\n */\nexport async function createConnection(\n options: DataSourceOptions,\n): Promise<DataSource>\n\n/**\n * Creates a new connection and registers it in the manager.\n *\n * If connection options were not specified, then it will try to create connection automatically,\n * based on content of ormconfig (json/js/yml/xml/env) file or environment variables.\n * Only one connection from ormconfig will be created (name \"default\" or connection without name).\n *\n * @deprecated\n */\nexport async function createConnection(\n optionsOrName?: any,\n): Promise<DataSource> {\n const connectionName =\n typeof optionsOrName === \"string\" ? optionsOrName : \"default\"\n const options = ObjectUtils.isObject(optionsOrName)\n ? (optionsOrName as DataSourceOptions)\n : await getConnectionOptions(connectionName)\n return getConnectionManager().create(options).connect()\n}\n\n/**\n * Creates new connections and registers them in the manager.\n *\n * If connection options were not specified, then it will try to create connection automatically,\n * based on content of ormconfig (json/js/yml/xml/env) file or environment variables.\n * All connections from the ormconfig will be created.\n *\n * @deprecated\n */\nexport async function createConnections(\n options?: DataSourceOptions[],\n): Promise<DataSource[]> {\n if (!options) options = await new ConnectionOptionsReader().all()\n const connections = options.map((options) =>\n getConnectionManager().create(options),\n )\n // Do not use Promise.all or test 8522 will produce a dangling sqlite connection\n for (const connection of connections) {\n await connection.connect()\n }\n return connections\n}\n\n/**\n * Gets connection from the connection manager.\n * If connection name wasn't specified, then \"default\" connection will be retrieved.\n *\n * @deprecated\n */\nexport function getConnection(connectionName: string = \"default\"): DataSource {\n return getConnectionManager().get(connectionName)\n}\n\n/**\n * Gets entity manager from the connection.\n * If connection name wasn't specified, then \"default\" connection will be retrieved.\n *\n * @deprecated\n */\nexport function getManager(connectionName: string = \"default\"): EntityManager {\n return getConnectionManager().get(connectionName).manager\n}\n\n/**\n * Gets MongoDB entity manager from the connection.\n * If connection name wasn't specified, then \"default\" connection will be retrieved.\n *\n * @deprecated\n */\nexport function getMongoManager(\n connectionName: string = \"default\",\n): MongoEntityManager {\n return getConnectionManager().get(connectionName)\n .manager as MongoEntityManager\n}\n\n/**\n * Gets Sqljs entity manager from connection name.\n * \"default\" connection is used, when no name is specified.\n * Only works when Sqljs driver is used.\n *\n * @deprecated\n */\nexport function getSqljsManager(\n connectionName: string = \"default\",\n): SqljsEntityManager {\n return getConnectionManager().get(connectionName)\n .manager as SqljsEntityManager\n}\n\n/**\n * Gets repository for the given entity class.\n *\n * @deprecated\n */\nexport function getRepository<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n connectionName: string = \"default\",\n): Repository<Entity> {\n return getConnectionManager()\n .get(connectionName)\n .getRepository<Entity>(entityClass)\n}\n\n/**\n * Gets tree repository for the given entity class.\n *\n * @deprecated\n */\nexport function getTreeRepository<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n connectionName: string = \"default\",\n): TreeRepository<Entity> {\n return getConnectionManager()\n .get(connectionName)\n .getTreeRepository<Entity>(entityClass)\n}\n\n/**\n * Gets tree repository for the given entity class.\n *\n * @deprecated\n */\nexport function getCustomRepository<T>(\n customRepository: ObjectType<T>,\n connectionName: string = \"default\",\n): T {\n return getConnectionManager()\n .get(connectionName)\n .getCustomRepository(customRepository)\n}\n\n/**\n * Gets mongodb repository for the given entity class or name.\n *\n * @deprecated\n */\nexport function getMongoRepository<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n connectionName: string = \"default\",\n): MongoRepository<Entity> {\n return getConnectionManager()\n .get(connectionName)\n .getMongoRepository<Entity>(entityClass)\n}\n\n/**\n * Creates a new query builder.\n *\n * @deprecated\n */\nexport function createQueryBuilder<Entity extends ObjectLiteral>(\n entityClass?: EntityTarget<Entity>,\n alias?: string,\n connectionName: string = \"default\",\n): SelectQueryBuilder<Entity> {\n if (entityClass) {\n return getRepository(entityClass, connectionName).createQueryBuilder(\n alias,\n )\n }\n\n return getConnection(connectionName).createQueryBuilder()\n}\n"],"sourceRoot":"."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/globals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAW9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD;;GAEG;AACH,MAAM,UAAU,sBAAsB;IAClC,8FAA8F;IAC9F,qGAAqG;IACrG,mGAAmG;IACnG,8EAA8E;IAC9E,6FAA6F;IAC7F,8FAA8F;IAC9F,iFAAiF;IACjF,4FAA4F;IAC5F,MAAM,WAAW,GAAG,aAAa,CAAC,iBAAiB,EAAE,CAAA;IACrD,IAAI,CAAC,WAAW,CAAC,0BAA0B;QACvC,WAAW,CAAC,0BAA0B,GAAG,IAAI,mBAAmB,EAAE,CAAA;IAEtE,OAAO,WAAW,CAAC,0BAA0B,CAAA;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,iBAAyB,SAAS;IAElC,OAAO,IAAI,uBAAuB,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;AAC5D,CAAC;AAED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OAAO,aAAa,CAAC,cAAc,CAAC,CAAC,kBAAkB,EAAE,CAAA;AAC7D,CAAC","file":"globals.js","sourcesContent":["import { MetadataArgsStorage } from \"./metadata-args/MetadataArgsStorage\"\nimport { PlatformTools } from \"./platform/PlatformTools\"\nimport { DataSourceOptions } from \"./data-source/DataSourceOptions\"\nimport { ConnectionOptionsReader } from \"./connection/ConnectionOptionsReader\"\nimport { ConnectionManager } from \"./connection/ConnectionManager\"\nimport { getFromContainer } from \"./container\"\nimport { DataSource } from \"./data-source/DataSource\"\nimport { EntityManager } from \"./entity-manager/EntityManager\"\nimport { MongoEntityManager } from \"./entity-manager/MongoEntityManager\"\nimport { SqljsEntityManager } from \"./entity-manager/SqljsEntityManager\"\nimport { EntityTarget } from \"./common/EntityTarget\"\nimport { Repository } from \"./repository/Repository\"\nimport { TreeRepository } from \"./repository/TreeRepository\"\nimport { ObjectType } from \"./common/ObjectType\"\nimport { MongoRepository } from \"./repository/MongoRepository\"\nimport { SelectQueryBuilder } from \"./query-builder/SelectQueryBuilder\"\nimport { ObjectUtils } from \"./util/ObjectUtils\"\nimport { ObjectLiteral } from \"./common/ObjectLiteral\"\n\n/**\n * Gets metadata args storage.\n */\nexport function getMetadataArgsStorage(): MetadataArgsStorage {\n // we should store metadata storage in a global variable otherwise it brings too much problems\n // one of the problem is that if any entity (or any other) will be imported before consumer will call\n // useContainer method with his own container implementation, that entity will be registered in the\n // old old container (default one post probably) and consumer will his entity.\n // calling useContainer before he imports any entity (or any other) is not always convenient.\n // another reason is that when we run migrations typeorm is being called from a global package\n // and it may load entities which register decorators in typeorm of local package\n // this leads to impossibility of usage of entities in migrations and cli related operations\n const globalScope = PlatformTools.getGlobalVariable()\n if (!globalScope.typeormMetadataArgsStorage)\n globalScope.typeormMetadataArgsStorage = new MetadataArgsStorage()\n\n return globalScope.typeormMetadataArgsStorage\n}\n\n/**\n * Reads connection options stored in ormconfig configuration file.\n *\n * @deprecated\n */\nexport async function getConnectionOptions(\n connectionName: string = \"default\",\n): Promise<DataSourceOptions> {\n return new ConnectionOptionsReader().get(connectionName)\n}\n\n/**\n * Gets a ConnectionManager which creates connections.\n *\n * @deprecated\n */\nexport function getConnectionManager(): ConnectionManager {\n return getFromContainer(ConnectionManager)\n}\n\n/**\n * Creates a new connection and registers it in the manager.\n * Only one connection from ormconfig will be created (name \"default\" or connection without name).\n *\n * @deprecated\n */\nexport async function createConnection(): Promise<DataSource>\n\n/**\n * Creates a new connection from the ormconfig file with a given name.\n *\n * @deprecated\n */\nexport async function createConnection(name: string): Promise<DataSource>\n\n/**\n * Creates a new connection and registers it in the manager.\n *\n * @deprecated\n */\nexport async function createConnection(\n options: DataSourceOptions,\n): Promise<DataSource>\n\n/**\n * Creates a new connection and registers it in the manager.\n *\n * If connection options were not specified, then it will try to create connection automatically,\n * based on content of ormconfig (json/js/env) file or environment variables.\n * Only one connection from ormconfig will be created (name \"default\" or connection without name).\n *\n * @deprecated\n */\nexport async function createConnection(\n optionsOrName?: any,\n): Promise<DataSource> {\n const connectionName =\n typeof optionsOrName === \"string\" ? optionsOrName : \"default\"\n const options = ObjectUtils.isObject(optionsOrName)\n ? (optionsOrName as DataSourceOptions)\n : await getConnectionOptions(connectionName)\n return getConnectionManager().create(options).connect()\n}\n\n/**\n * Creates new connections and registers them in the manager.\n *\n * If connection options were not specified, then it will try to create connection automatically,\n * based on content of ormconfig (json/js/env) file or environment variables.\n * All connections from the ormconfig will be created.\n *\n * @deprecated\n */\nexport async function createConnections(\n options?: DataSourceOptions[],\n): Promise<DataSource[]> {\n if (!options) options = await new ConnectionOptionsReader().all()\n const connections = options.map((options) =>\n getConnectionManager().create(options),\n )\n // Do not use Promise.all or test 8522 will produce a dangling sqlite connection\n for (const connection of connections) {\n await connection.connect()\n }\n return connections\n}\n\n/**\n * Gets connection from the connection manager.\n * If connection name wasn't specified, then \"default\" connection will be retrieved.\n *\n * @deprecated\n */\nexport function getConnection(connectionName: string = \"default\"): DataSource {\n return getConnectionManager().get(connectionName)\n}\n\n/**\n * Gets entity manager from the connection.\n * If connection name wasn't specified, then \"default\" connection will be retrieved.\n *\n * @deprecated\n */\nexport function getManager(connectionName: string = \"default\"): EntityManager {\n return getConnectionManager().get(connectionName).manager\n}\n\n/**\n * Gets MongoDB entity manager from the connection.\n * If connection name wasn't specified, then \"default\" connection will be retrieved.\n *\n * @deprecated\n */\nexport function getMongoManager(\n connectionName: string = \"default\",\n): MongoEntityManager {\n return getConnectionManager().get(connectionName)\n .manager as MongoEntityManager\n}\n\n/**\n * Gets Sqljs entity manager from connection name.\n * \"default\" connection is used, when no name is specified.\n * Only works when Sqljs driver is used.\n *\n * @deprecated\n */\nexport function getSqljsManager(\n connectionName: string = \"default\",\n): SqljsEntityManager {\n return getConnectionManager().get(connectionName)\n .manager as SqljsEntityManager\n}\n\n/**\n * Gets repository for the given entity class.\n *\n * @deprecated\n */\nexport function getRepository<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n connectionName: string = \"default\",\n): Repository<Entity> {\n return getConnectionManager()\n .get(connectionName)\n .getRepository<Entity>(entityClass)\n}\n\n/**\n * Gets tree repository for the given entity class.\n *\n * @deprecated\n */\nexport function getTreeRepository<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n connectionName: string = \"default\",\n): TreeRepository<Entity> {\n return getConnectionManager()\n .get(connectionName)\n .getTreeRepository<Entity>(entityClass)\n}\n\n/**\n * Gets tree repository for the given entity class.\n *\n * @deprecated\n */\nexport function getCustomRepository<T>(\n customRepository: ObjectType<T>,\n connectionName: string = \"default\",\n): T {\n return getConnectionManager()\n .get(connectionName)\n .getCustomRepository(customRepository)\n}\n\n/**\n * Gets mongodb repository for the given entity class or name.\n *\n * @deprecated\n */\nexport function getMongoRepository<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n connectionName: string = \"default\",\n): MongoRepository<Entity> {\n return getConnectionManager()\n .get(connectionName)\n .getMongoRepository<Entity>(entityClass)\n}\n\n/**\n * Creates a new query builder.\n *\n * @deprecated\n */\nexport function createQueryBuilder<Entity extends ObjectLiteral>(\n entityClass?: EntityTarget<Entity>,\n alias?: string,\n connectionName: string = \"default\",\n): SelectQueryBuilder<Entity> {\n if (entityClass) {\n return getRepository(entityClass, connectionName).createQueryBuilder(\n alias,\n )\n }\n\n return getConnection(connectionName).createQueryBuilder()\n}\n"],"sourceRoot":"."}
|
package/commands/InitCommand.js
CHANGED
|
@@ -314,7 +314,7 @@ export class UserController {
|
|
|
314
314
|
|
|
315
315
|
async one(request: Request, response: Response, next: NextFunction) {
|
|
316
316
|
const id = parseInt(request.params.id)
|
|
317
|
-
|
|
317
|
+
|
|
318
318
|
|
|
319
319
|
const user = await this.userRepository.findOne({
|
|
320
320
|
where: { id }
|
|
@@ -615,7 +615,7 @@ Steps to run this project:
|
|
|
615
615
|
packageJson.dependencies["oracledb"] = "^5.1.0";
|
|
616
616
|
break;
|
|
617
617
|
case "mssql":
|
|
618
|
-
packageJson.dependencies["mssql"] = "^
|
|
618
|
+
packageJson.dependencies["mssql"] = "^9.1.1";
|
|
619
619
|
break;
|
|
620
620
|
case "mongodb":
|
|
621
621
|
packageJson.dependencies["mongodb"] = "^3.0.8";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IA8tB3E,CAAC;IA5tBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,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AAU,CAAC,GAAG,QAAQ,CAAA;gBAC/C,MAAK;YACT,KAAK,OAAO;gBACR,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAA;gBAC5C,MAAK;YACT,KAAK,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAA;gBAC9C,MAAK;YACT,KAAK,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAAA;gBAC7D,MAAK;SACZ;QAED,IAAI,OAAO,EAAE;YACT,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;YAC/C,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;SACtD;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAnuBD,kCAmuBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { AppDataSource } from '../data-source'\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = AppDataSource.getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n \n\n const user = await this.userRepository.findOne({\n where: { id }\n })\n\n if (!user) {\n return \"unregistered user\"\n }\n return user\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n const { firstName, lastName, age } = request.body;\n\n const user = Object.assign(new User(), {\n firstName,\n lastName,\n age\n })\n\n return this.userRepository.save(user)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n let userToRemove = await this.userRepository.findOneBy({ id })\n\n if (!userToRemove) {\n return \"this user not exist\"\n }\n\n await this.userRepository.remove(userToRemove)\n\n return \"user has been removed\"\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:8.0.30\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.8.4\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:14.5\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v22.1.6\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:5.0.12\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^7.3.0\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACz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,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAnuBD,kCAmuBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { AppDataSource } from '../data-source'\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = AppDataSource.getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n\n const user = await this.userRepository.findOne({\n where: { id }\n })\n\n if (!user) {\n return \"unregistered user\"\n }\n return user\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n const { firstName, lastName, age } = request.body;\n\n const user = Object.assign(new User(), {\n firstName,\n lastName,\n age\n })\n\n return this.userRepository.save(user)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n let userToRemove = await this.userRepository.findOneBy({ id })\n\n if (!userToRemove) {\n return \"this user not exist\"\n }\n\n await this.userRepository.remove(userToRemove)\n\n return \"user has been removed\"\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:8.0.30\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.8.4\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:14.5\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v22.1.6\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:5.0.12\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^9.1.1\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
|
2
2
|
/**
|
|
3
3
|
* Reads connection options from the ormconfig.
|
|
4
|
-
* Can read from multiple file extensions including env, json, js, xml and yml.
|
|
5
4
|
*/
|
|
6
5
|
export declare class ConnectionOptionsReader {
|
|
7
6
|
protected options?: {
|
|
@@ -6,14 +6,11 @@ const app_root_path_1 = tslib_1.__importDefault(require("app-root-path"));
|
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
8
8
|
const ConnectionOptionsEnvReader_1 = require("./options-reader/ConnectionOptionsEnvReader");
|
|
9
|
-
const ConnectionOptionsYmlReader_1 = require("./options-reader/ConnectionOptionsYmlReader");
|
|
10
|
-
const ConnectionOptionsXmlReader_1 = require("./options-reader/ConnectionOptionsXmlReader");
|
|
11
9
|
const error_1 = require("../error");
|
|
12
10
|
const PathUtils_1 = require("../util/PathUtils");
|
|
13
11
|
const ImportUtils_1 = require("../util/ImportUtils");
|
|
14
12
|
/**
|
|
15
13
|
* Reads connection options from the ormconfig.
|
|
16
|
-
* Can read from multiple file extensions including env, json, js, xml and yml.
|
|
17
14
|
*/
|
|
18
15
|
class ConnectionOptionsReader {
|
|
19
16
|
// -------------------------------------------------------------------------
|
|
@@ -74,9 +71,6 @@ class ConnectionOptionsReader {
|
|
|
74
71
|
"mts",
|
|
75
72
|
"cts",
|
|
76
73
|
"json",
|
|
77
|
-
"yml",
|
|
78
|
-
"yaml",
|
|
79
|
-
"xml",
|
|
80
74
|
];
|
|
81
75
|
// Detect if baseFilePath contains file extension
|
|
82
76
|
const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf("."));
|
|
@@ -123,15 +117,6 @@ class ConnectionOptionsReader {
|
|
|
123
117
|
else if (foundFileFormat === "json") {
|
|
124
118
|
connectionOptions = require(configFile);
|
|
125
119
|
}
|
|
126
|
-
else if (foundFileFormat === "yml") {
|
|
127
|
-
connectionOptions = await new ConnectionOptionsYmlReader_1.ConnectionOptionsYmlReader().read(configFile);
|
|
128
|
-
}
|
|
129
|
-
else if (foundFileFormat === "yaml") {
|
|
130
|
-
connectionOptions = await new ConnectionOptionsYmlReader_1.ConnectionOptionsYmlReader().read(configFile);
|
|
131
|
-
}
|
|
132
|
-
else if (foundFileFormat === "xml") {
|
|
133
|
-
connectionOptions = await new ConnectionOptionsXmlReader_1.ConnectionOptionsXmlReader().read(configFile);
|
|
134
|
-
}
|
|
135
120
|
// normalize and return connection options
|
|
136
121
|
if (connectionOptions) {
|
|
137
122
|
return this.normalizeConnectionOptions(connectionOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,wDAAuB;AAEvB,6DAAyD;AACzD,4FAAwF;AACxF,4FAAwF;AACxF,4FAAwF;AACxF,oCAAuC;AACvC,iDAA8C;AAC9C,qDAAyD;AAEzD;;;GAGG;AACH,MAAa,uBAAuB;IAChC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,OAWT;QAXS,YAAO,GAAP,OAAO,CAWhB;IACF,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,GAAG;QACL,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACjC,IAAI,CAAC,OAAO;YACR,MAAM,IAAI,oBAAY,CAClB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\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { ConnectionOptionsEnvReader } from \"./options-reader/ConnectionOptionsEnvReader\"\nimport { ConnectionOptionsYmlReader } from \"./options-reader/ConnectionOptionsYmlReader\"\nimport { ConnectionOptionsXmlReader } from \"./options-reader/ConnectionOptionsXmlReader\"\nimport { TypeORMError } from \"../error\"\nimport { isAbsolute } from \"../util/PathUtils\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Reads connection options from the ormconfig.\n * Can read from multiple file extensions including env, json, js, xml and yml.\n */\nexport class ConnectionOptionsReader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n },\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<DataSourceOptions[]> {\n const options = await this.load()\n if (!options)\n throw new TypeORMError(\n `No connection options were found in any orm configuration files.`,\n )\n\n return options\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<DataSourceOptions> {\n const allOptions = await this.all()\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n if (!targetOptions)\n throw new TypeORMError(\n `Cannot find connection ${name} because its not defined in any orm configuration files.`,\n )\n\n return targetOptions\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load()\n if (!allOptions) return false\n\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n return !!targetOptions\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<DataSourceOptions[] | undefined> {\n let connectionOptions:\n | DataSourceOptions\n | DataSourceOptions[]\n | undefined = undefined\n\n const fileFormats = [\n \"env\",\n \"js\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"mts\",\n \"cts\",\n \"json\",\n \"yml\",\n \"yaml\",\n \"xml\",\n ]\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(\n this.baseFilePath.lastIndexOf(\".\"),\n )\n const fileExtension = fileFormats.find(\n (extension) => `.${extension}` === possibleExtension,\n )\n\n // try to find any of following configuration formats\n const foundFileFormat =\n fileExtension ||\n fileFormats.find((format) => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format)\n })\n\n // Determine config file name\n const configFile = fileExtension\n ? this.baseFilePath\n : this.baseFilePath + \".\" + foundFileFormat\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile)\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\")\n }\n\n // try to find connection options from any of available sources of configuration\n if (\n PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") ||\n PlatformTools.getEnvVariable(\"TYPEORM_URL\")\n ) {\n connectionOptions = await new ConnectionOptionsEnvReader().read()\n } else if (\n foundFileFormat === \"js\" ||\n foundFileFormat === \"mjs\" ||\n foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" ||\n foundFileFormat === \"mts\" ||\n foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] =\n await importOrRequireFile(configFile)\n const configModule = await importOrRequireResult\n\n if (\n moduleSystem === \"esm\" ||\n (configModule &&\n \"__esModule\" in configModule &&\n \"default\" in configModule)\n ) {\n connectionOptions = configModule.default\n } else {\n connectionOptions = configModule\n }\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile)\n } else if (foundFileFormat === \"yml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(\n configFile,\n )\n } else if (foundFileFormat === \"yaml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(\n configFile,\n )\n } else if (foundFileFormat === \"xml\") {\n connectionOptions = await new ConnectionOptionsXmlReader().read(\n configFile,\n )\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions)\n }\n\n return undefined\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(\n connectionOptions: DataSourceOptions | DataSourceOptions[],\n ): DataSourceOptions[] {\n if (!Array.isArray(connectionOptions))\n connectionOptions = [connectionOptions]\n\n connectionOptions.forEach((options) => {\n options.baseDirectory = this.baseDirectory\n if (options.entities) {\n const entities = (options.entities as any[]).map((entity) => {\n if (\n typeof entity === \"string\" &&\n entity.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + entity\n\n return entity\n })\n Object.assign(connectionOptions, { entities: entities })\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(\n (subscriber) => {\n if (\n typeof subscriber === \"string\" &&\n subscriber.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + subscriber\n\n return subscriber\n },\n )\n Object.assign(connectionOptions, { subscribers: subscribers })\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(\n (migration) => {\n if (\n typeof migration === \"string\" &&\n migration.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + migration\n\n return migration\n },\n )\n Object.assign(connectionOptions, { migrations: migrations })\n }\n\n // make database path file in sqlite relative to package.json\n if (\n options.type === \"sqlite\" ||\n options.type === \"better-sqlite3\"\n ) {\n if (\n typeof options.database === \"string\" &&\n !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\"\n ) {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database,\n })\n }\n }\n })\n\n return connectionOptions\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName)\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root) return this.options.root\n\n return appRootPath.path\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName\n\n return \"ormconfig\"\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,wDAAuB;AAEvB,6DAAyD;AACzD,4FAAwF;AACxF,oCAAuC;AACvC,iDAA8C;AAC9C,qDAAyD;AAEzD;;GAEG;AACH,MAAa,uBAAuB;IAChC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,OAWT;QAXS,YAAO,GAAP,OAAO,CAWhB;IACF,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,GAAG;QACL,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACjC,IAAI,CAAC,OAAO;YACR,MAAM,IAAI,oBAAY,CAClB,kEAAkE,CACrE,CAAA;QAEL,OAAO,OAAO,CAAA;IAClB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY;QAClB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,CAAA;QACnC,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CACjC,CAAC,OAAO,EAAE,EAAE,CACR,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CACrE,CAAA;QACD,IAAI,CAAC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IAED;;OAEG;IACH,IAAc,aAAa;QACvB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;QAE/D,OAAO,uBAAW,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,IAAc,cAAc;QACxB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU;YACvC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAA;QAElC,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ;AArQD,0DAqQC","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\"\nimport path from \"path\"\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { ConnectionOptionsEnvReader } from \"./options-reader/ConnectionOptionsEnvReader\"\nimport { TypeORMError } from \"../error\"\nimport { isAbsolute } from \"../util/PathUtils\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Reads connection options from the ormconfig.\n */\nexport class ConnectionOptionsReader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n },\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<DataSourceOptions[]> {\n const options = await this.load()\n if (!options)\n throw new TypeORMError(\n `No connection options were found in any orm configuration files.`,\n )\n\n return options\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<DataSourceOptions> {\n const allOptions = await this.all()\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n if (!targetOptions)\n throw new TypeORMError(\n `Cannot find connection ${name} because its not defined in any orm configuration files.`,\n )\n\n return targetOptions\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load()\n if (!allOptions) return false\n\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n return !!targetOptions\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<DataSourceOptions[] | undefined> {\n let connectionOptions:\n | DataSourceOptions\n | DataSourceOptions[]\n | undefined = undefined\n\n const fileFormats = [\n \"env\",\n \"js\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"mts\",\n \"cts\",\n \"json\",\n ]\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(\n this.baseFilePath.lastIndexOf(\".\"),\n )\n const fileExtension = fileFormats.find(\n (extension) => `.${extension}` === possibleExtension,\n )\n\n // try to find any of following configuration formats\n const foundFileFormat =\n fileExtension ||\n fileFormats.find((format) => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format)\n })\n\n // Determine config file name\n const configFile = fileExtension\n ? this.baseFilePath\n : this.baseFilePath + \".\" + foundFileFormat\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile)\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\")\n }\n\n // try to find connection options from any of available sources of configuration\n if (\n PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") ||\n PlatformTools.getEnvVariable(\"TYPEORM_URL\")\n ) {\n connectionOptions = await new ConnectionOptionsEnvReader().read()\n } else if (\n foundFileFormat === \"js\" ||\n foundFileFormat === \"mjs\" ||\n foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" ||\n foundFileFormat === \"mts\" ||\n foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] =\n await importOrRequireFile(configFile)\n const configModule = await importOrRequireResult\n\n if (\n moduleSystem === \"esm\" ||\n (configModule &&\n \"__esModule\" in configModule &&\n \"default\" in configModule)\n ) {\n connectionOptions = configModule.default\n } else {\n connectionOptions = configModule\n }\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile)\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions)\n }\n\n return undefined\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(\n connectionOptions: DataSourceOptions | DataSourceOptions[],\n ): DataSourceOptions[] {\n if (!Array.isArray(connectionOptions))\n connectionOptions = [connectionOptions]\n\n connectionOptions.forEach((options) => {\n options.baseDirectory = this.baseDirectory\n if (options.entities) {\n const entities = (options.entities as any[]).map((entity) => {\n if (\n typeof entity === \"string\" &&\n entity.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + entity\n\n return entity\n })\n Object.assign(connectionOptions, { entities: entities })\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(\n (subscriber) => {\n if (\n typeof subscriber === \"string\" &&\n subscriber.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + subscriber\n\n return subscriber\n },\n )\n Object.assign(connectionOptions, { subscribers: subscribers })\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(\n (migration) => {\n if (\n typeof migration === \"string\" &&\n migration.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + migration\n\n return migration\n },\n )\n Object.assign(connectionOptions, { migrations: migrations })\n }\n\n // make database path file in sqlite relative to package.json\n if (\n options.type === \"sqlite\" ||\n options.type === \"better-sqlite3\"\n ) {\n if (\n typeof options.database === \"string\" &&\n !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\"\n ) {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database,\n })\n }\n }\n })\n\n return connectionOptions\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName)\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root) return this.options.root\n\n return appRootPath.path\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName\n\n return \"ormconfig\"\n }\n}\n"],"sourceRoot":".."}
|
package/globals.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function createConnection(options: DataSourceOptions): Promise<Da
|
|
|
51
51
|
* Creates new connections and registers them in the manager.
|
|
52
52
|
*
|
|
53
53
|
* If connection options were not specified, then it will try to create connection automatically,
|
|
54
|
-
* based on content of ormconfig (json/js/
|
|
54
|
+
* based on content of ormconfig (json/js/env) file or environment variables.
|
|
55
55
|
* All connections from the ormconfig will be created.
|
|
56
56
|
*
|
|
57
57
|
* @deprecated
|
package/globals.js
CHANGED
|
@@ -47,7 +47,7 @@ exports.getConnectionManager = getConnectionManager;
|
|
|
47
47
|
* Creates a new connection and registers it in the manager.
|
|
48
48
|
*
|
|
49
49
|
* If connection options were not specified, then it will try to create connection automatically,
|
|
50
|
-
* based on content of ormconfig (json/js/
|
|
50
|
+
* based on content of ormconfig (json/js/env) file or environment variables.
|
|
51
51
|
* Only one connection from ormconfig will be created (name "default" or connection without name).
|
|
52
52
|
*
|
|
53
53
|
* @deprecated
|
|
@@ -64,7 +64,7 @@ exports.createConnection = createConnection;
|
|
|
64
64
|
* Creates new connections and registers them in the manager.
|
|
65
65
|
*
|
|
66
66
|
* If connection options were not specified, then it will try to create connection automatically,
|
|
67
|
-
* based on content of ormconfig (json/js/
|
|
67
|
+
* based on content of ormconfig (json/js/env) file or environment variables.
|
|
68
68
|
* All connections from the ormconfig will be created.
|
|
69
69
|
*
|
|
70
70
|
* @deprecated
|