typeorm 0.3.26-dev.d57fe3b → 0.3.26-dev.ec26eae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +15 -1110
  2. package/browser/cache/RedisQueryResultCache.d.ts +13 -0
  3. package/browser/cache/RedisQueryResultCache.js +105 -38
  4. package/browser/cache/RedisQueryResultCache.js.map +1 -1
  5. package/browser/driver/cockroachdb/CockroachDriver.js +2 -2
  6. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  7. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +9 -9
  8. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  9. package/browser/driver/postgres/PostgresDriver.js +2 -2
  10. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  11. package/browser/driver/postgres/PostgresQueryRunner.js +1 -1
  12. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  13. package/browser/error/DriverPackageNotInstalledError.js +1 -2
  14. package/browser/error/DriverPackageNotInstalledError.js.map +1 -1
  15. package/browser/platform/BrowserPlatformTools.js +7 -3
  16. package/browser/platform/BrowserPlatformTools.js.map +1 -1
  17. package/cache/RedisQueryResultCache.d.ts +13 -0
  18. package/cache/RedisQueryResultCache.js +105 -38
  19. package/cache/RedisQueryResultCache.js.map +1 -1
  20. package/driver/cockroachdb/CockroachDriver.js +2 -2
  21. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  22. package/driver/mongodb/MongoConnectionOptions.d.ts +9 -9
  23. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  24. package/driver/postgres/PostgresDriver.js +2 -2
  25. package/driver/postgres/PostgresDriver.js.map +1 -1
  26. package/driver/postgres/PostgresQueryRunner.js +1 -1
  27. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  28. package/error/DriverPackageNotInstalledError.js +1 -2
  29. package/error/DriverPackageNotInstalledError.js.map +1 -1
  30. package/package.json +1 -1
@@ -4,8 +4,7 @@ import { TypeORMError } from "./TypeORMError";
4
4
  */
5
5
  export class DriverPackageNotInstalledError extends TypeORMError {
6
6
  constructor(driverName, packageName) {
7
- super(`${driverName} package has not been found installed. ` +
8
- `Try to install it: npm install ${packageName} --save`);
7
+ super(`${driverName} package has not been found installed. Please run "npm install ${packageName}".`);
9
8
  }
10
9
  }
11
10
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/error/DriverPackageNotInstalledError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,YAAY;IAC5D,YAAY,UAAkB,EAAE,WAAmB;QAC/C,KAAK,CACD,GAAG,UAAU,yCAAyC;YAClD,kCAAkC,WAAW,SAAS,CAC7D,CAAA;IACL,CAAC;CACJ","file":"DriverPackageNotInstalledError.js","sourcesContent":["import { TypeORMError } from \"./TypeORMError\"\n\n/**\n * Thrown when required driver's package is not installed.\n */\nexport class DriverPackageNotInstalledError extends TypeORMError {\n constructor(driverName: string, packageName: string) {\n super(\n `${driverName} package has not been found installed. ` +\n `Try to install it: npm install ${packageName} --save`,\n )\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/error/DriverPackageNotInstalledError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,YAAY;IAC5D,YAAY,UAAkB,EAAE,WAAmB;QAC/C,KAAK,CACD,GAAG,UAAU,kEAAkE,WAAW,IAAI,CACjG,CAAA;IACL,CAAC;CACJ","file":"DriverPackageNotInstalledError.js","sourcesContent":["import { TypeORMError } from \"./TypeORMError\"\n\n/**\n * Thrown when required driver's package is not installed.\n */\nexport class DriverPackageNotInstalledError extends TypeORMError {\n constructor(driverName: string, packageName: string) {\n super(\n `${driverName} package has not been found installed. Please run \"npm install ${packageName}\".`,\n )\n }\n}\n"],"sourceRoot":".."}
@@ -14,10 +14,11 @@ export class PlatformTools {
14
14
  if (typeof window !== "undefined") {
15
15
  return window;
16
16
  }
17
- else {
18
- // NativeScript uses global, not window
19
- return global;
17
+ if (typeof globalThis !== "undefined") {
18
+ return globalThis;
20
19
  }
20
+ // NativeScript uses global, not window
21
+ return global;
21
22
  }
22
23
  /**
23
24
  * Loads ("require"-s) given file or package.
@@ -128,6 +129,9 @@ export class Writable {
128
129
  if (typeof window !== "undefined") {
129
130
  window.Buffer = Buffer;
130
131
  }
132
+ if (typeof globalThis !== "undefined") {
133
+ globalThis.Buffer = Buffer;
134
+ }
131
135
  // NativeScript uses global, not window
132
136
  if (typeof global !== "undefined" && typeof require !== "undefined") {
133
137
  global.Buffer = require("buffer/").Buffer;
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,aAAa;IAOtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,MAAM,CAAA;QACjB,CAAC;aAAM,CAAC;YACJ,uCAAuC;YACvC,OAAO,MAAM,CAAA;QACjB,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,gGAAgG,IAAI,KAAK,CAAC,CAAC;QAE/H,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAe;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,uGAAuG,OAAO,KAAK,CAAC,CAAC;QAEzI,OAAO,EAAE,CAAC;IACd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AAC,CAAC,MAAM,CAAC;AAC9C,CAAC","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nimport { Buffer } from \"buffer\";\n\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n } else {\n // NativeScript uses global, not window\n return global\n }\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without ANSI colors)\n */\n static logInfo(prefix: string, info: any) {\n console.info(prefix + \" \", info);\n }\n\n static logError(prefix: string, error: any) {\n console.error(prefix + \" \", error);\n }\n\n static logWarn(prefix: string, warning: any) {\n console.warn(prefix + \" \", warning);\n }\n\n static log(message: string) {\n console.log(message);\n }\n\n static warn(message: string) {\n return message;\n }\n}\n\n/**\n * These classes are needed for stream operations or\n * in the mongodb driver. Both aren't supported in the browser.\n */\nexport class EventEmitter {}\n\nexport class Readable {}\n\nexport class Writable {}\n\nexport interface ReadStream {}\n\n/**\n * This loads a polyfill to enable Buffers in the browser.\n */\ninterface Window {\n Buffer: any;\n}\n\ndeclare var window: Window;\nif (typeof window !== \"undefined\") {\n window.Buffer = Buffer;\n}\n// NativeScript uses global, not window\nif (typeof global !== \"undefined\" && typeof require !== \"undefined\") {\n global.Buffer = require(\"buffer/\").Buffer;\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM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,CAAC,MAAc,EAAE,OAAY;QACvC,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,OAAe;QACtB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe;QACvB,OAAO,OAAO,CAAC;IACnB,CAAC;;AAjID;;GAEG;AACI,kBAAI,GAAqB,SAAS,CAAC;AAiI9C;;;GAGG;AACH,MAAM,OAAO,YAAY;CAAG;AAE5B,MAAM,OAAO,QAAQ;CAAG;AAExB,MAAM,OAAO,QAAQ;CAAG;AAYxB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAChC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;AAC3B,CAAC;AACD,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE,CAAC;IACpC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC;AAC/B,CAAC;AACD,uCAAuC;AACvC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;IAClE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nimport { Buffer } from \"buffer\";\n\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n }\n if (typeof globalThis !== \"undefined\") {\n return globalThis\n }\n // NativeScript uses global, not window\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without ANSI colors)\n */\n static logInfo(prefix: string, info: any) {\n console.info(prefix + \" \", info);\n }\n\n static logError(prefix: string, error: any) {\n console.error(prefix + \" \", error);\n }\n\n static logWarn(prefix: string, warning: any) {\n console.warn(prefix + \" \", warning);\n }\n\n static log(message: string) {\n console.log(message);\n }\n\n static warn(message: string) {\n return message;\n }\n}\n\n/**\n * These classes are needed for stream operations or\n * in the mongodb driver. Both aren't supported in the browser.\n */\nexport class EventEmitter {}\n\nexport class Readable {}\n\nexport class Writable {}\n\nexport interface ReadStream {}\n\n/**\n * This loads a polyfill to enable Buffers in the browser.\n */\ninterface Window {\n Buffer: any;\n}\n\ndeclare var window: Window;\nif (typeof window !== \"undefined\") {\n window.Buffer = Buffer;\n}\nif (typeof globalThis !== \"undefined\") {\n globalThis.Buffer = Buffer;\n}\n// NativeScript uses global, not window\nif (typeof global !== \"undefined\" && typeof require !== \"undefined\") {\n global.Buffer = require(\"buffer/\").Buffer;\n}\n"],"sourceRoot":".."}
@@ -19,6 +19,10 @@ export declare class RedisQueryResultCache implements QueryResultCache {
19
19
  * Type of the Redis Client (redis or ioredis).
20
20
  */
21
21
  protected clientType: "redis" | "ioredis" | "ioredis/cluster";
22
+ /**
23
+ * Redis major version number
24
+ */
25
+ protected redisMajorVersion: number | undefined;
22
26
  constructor(connection: DataSource, clientType: "redis" | "ioredis" | "ioredis/cluster");
23
27
  /**
24
28
  * Creates a connection with given cache provider.
@@ -62,4 +66,13 @@ export declare class RedisQueryResultCache implements QueryResultCache {
62
66
  * Loads redis dependency.
63
67
  */
64
68
  protected loadRedis(): any;
69
+ /**
70
+ * Detects the Redis version based on the connected client's API characteristics
71
+ * without creating test keys in the database
72
+ */
73
+ private detectRedisVersion;
74
+ /**
75
+ * Checks if Redis version is 5.x or higher
76
+ */
77
+ private isRedis5OrHigher;
65
78
  }
@@ -24,19 +24,32 @@ class RedisQueryResultCache {
24
24
  async connect() {
25
25
  const cacheOptions = this.connection.options.cache;
26
26
  if (this.clientType === "redis") {
27
- this.client = this.redis.createClient({
27
+ const clientOptions = {
28
28
  ...cacheOptions?.options,
29
- legacyMode: true,
30
- });
29
+ };
30
+ // Create initial client to test Redis version
31
+ let tempClient = this.redis.createClient(clientOptions);
32
+ const isRedis4Plus = typeof tempClient.connect === "function";
33
+ if (isRedis4Plus) {
34
+ // Redis 4+ detected, recreate with legacyMode for Redis 4.x
35
+ // (Redis 5 will ignore legacyMode if not needed)
36
+ clientOptions.legacyMode = true;
37
+ tempClient = this.redis.createClient(clientOptions);
38
+ }
39
+ // Set as the main client
40
+ this.client = tempClient;
31
41
  if (typeof this.connection.options.cache === "object" &&
32
42
  this.connection.options.cache.ignoreErrors) {
33
43
  this.client.on("error", (err) => {
34
44
  this.connection.logger.log("warn", err);
35
45
  });
36
46
  }
37
- if ("connect" in this.client) {
47
+ // Connect if Redis 4+
48
+ if (typeof this.client.connect === "function") {
38
49
  await this.client.connect();
39
50
  }
51
+ // Detect precise version after connection is established
52
+ this.detectRedisVersion();
40
53
  }
41
54
  else if (this.clientType === "ioredis") {
42
55
  if (cacheOptions && cacheOptions.port) {
@@ -74,6 +87,13 @@ class RedisQueryResultCache {
74
87
  * Disconnects the connection
75
88
  */
76
89
  async disconnect() {
90
+ if (this.isRedis5OrHigher()) {
91
+ // Redis 5+ uses quit() that returns a Promise
92
+ await this.client.quit();
93
+ this.client = undefined;
94
+ return;
95
+ }
96
+ // Redis 3/4 callback style
77
97
  return new Promise((ok, fail) => {
78
98
  this.client.quit((err, result) => {
79
99
  if (err)
@@ -93,24 +113,22 @@ class RedisQueryResultCache {
93
113
  * Returns undefined if result is not cached.
94
114
  */
95
115
  getFromCache(options, queryRunner) {
116
+ const key = options.identifier || options.query;
117
+ if (!key)
118
+ return Promise.resolve(undefined);
119
+ if (this.isRedis5OrHigher()) {
120
+ // Redis 5+ Promise-based API
121
+ return this.client.get(key).then((result) => {
122
+ return result ? JSON.parse(result) : undefined;
123
+ });
124
+ }
125
+ // Redis 3/4 callback-based API
96
126
  return new Promise((ok, fail) => {
97
- if (options.identifier) {
98
- this.client.get(options.identifier, (err, result) => {
99
- if (err)
100
- return fail(err);
101
- ok(JSON.parse(result));
102
- });
103
- }
104
- else if (options.query) {
105
- this.client.get(options.query, (err, result) => {
106
- if (err)
107
- return fail(err);
108
- ok(JSON.parse(result));
109
- });
110
- }
111
- else {
112
- ok(undefined);
113
- }
127
+ this.client.get(key, (err, result) => {
128
+ if (err)
129
+ return fail(err);
130
+ ok(result ? JSON.parse(result) : undefined);
131
+ });
114
132
  });
115
133
  }
116
134
  /**
@@ -123,27 +141,37 @@ class RedisQueryResultCache {
123
141
  * Stores given query result in the cache.
124
142
  */
125
143
  async storeInCache(options, savedCache, queryRunner) {
144
+ const key = options.identifier || options.query;
145
+ if (!key)
146
+ return;
147
+ const value = JSON.stringify(options);
148
+ const duration = options.duration;
149
+ if (this.isRedis5OrHigher()) {
150
+ // Redis 5+ Promise-based API with PX option
151
+ await this.client.set(key, value, {
152
+ PX: duration,
153
+ });
154
+ return;
155
+ }
156
+ // Redis 3/4 callback-based API
126
157
  return new Promise((ok, fail) => {
127
- if (options.identifier) {
128
- this.client.set(options.identifier, JSON.stringify(options), "PX", options.duration, (err, result) => {
129
- if (err)
130
- return fail(err);
131
- ok();
132
- });
133
- }
134
- else if (options.query) {
135
- this.client.set(options.query, JSON.stringify(options), "PX", options.duration, (err, result) => {
136
- if (err)
137
- return fail(err);
138
- ok();
139
- });
140
- }
158
+ this.client.set(key, value, "PX", duration, (err, result) => {
159
+ if (err)
160
+ return fail(err);
161
+ ok();
162
+ });
141
163
  });
142
164
  }
143
165
  /**
144
166
  * Clears everything stored in the cache.
145
167
  */
146
168
  async clear(queryRunner) {
169
+ if (this.isRedis5OrHigher()) {
170
+ // Redis 5+ Promise-based API
171
+ await this.client.flushDb();
172
+ return;
173
+ }
174
+ // Redis 3/4 callback-based API
147
175
  return new Promise((ok, fail) => {
148
176
  this.client.flushdb((err, result) => {
149
177
  if (err)
@@ -166,7 +194,13 @@ class RedisQueryResultCache {
166
194
  /**
167
195
  * Removes a single key from redis database.
168
196
  */
169
- deleteKey(key) {
197
+ async deleteKey(key) {
198
+ if (this.isRedis5OrHigher()) {
199
+ // Redis 5+ Promise-based API
200
+ await this.client.del(key);
201
+ return;
202
+ }
203
+ // Redis 3/4 callback-based API
170
204
  return new Promise((ok, fail) => {
171
205
  this.client.del(key, (err, result) => {
172
206
  if (err)
@@ -187,10 +221,43 @@ class RedisQueryResultCache {
187
221
  return PlatformTools_1.PlatformTools.load(this.clientType);
188
222
  }
189
223
  }
190
- catch (e) {
191
- throw new TypeORMError_1.TypeORMError(`Cannot use cache because ${this.clientType} is not installed. Please run "npm i ${this.clientType} --save".`);
224
+ catch {
225
+ throw new TypeORMError_1.TypeORMError(`Cannot use cache because ${this.clientType} is not installed. Please run "npm i ${this.clientType}".`);
192
226
  }
193
227
  }
228
+ /**
229
+ * Detects the Redis version based on the connected client's API characteristics
230
+ * without creating test keys in the database
231
+ */
232
+ detectRedisVersion() {
233
+ if (this.clientType !== "redis")
234
+ return;
235
+ try {
236
+ // Detect version by examining the client's method signatures
237
+ // This avoids creating test keys in the database
238
+ const setMethod = this.client.set;
239
+ if (setMethod && setMethod.length <= 3) {
240
+ // Redis 5+ set method accepts fewer parameters (key, value, options)
241
+ this.redisMajorVersion = 5;
242
+ }
243
+ else {
244
+ // Redis 3/4 set method requires more parameters (key, value, flag, duration, callback)
245
+ this.redisMajorVersion = 3;
246
+ }
247
+ }
248
+ catch {
249
+ // Default to Redis 3/4 for maximum compatibility
250
+ this.redisMajorVersion = 3;
251
+ }
252
+ }
253
+ /**
254
+ * Checks if Redis version is 5.x or higher
255
+ */
256
+ isRedis5OrHigher() {
257
+ if (this.clientType !== "redis")
258
+ return false;
259
+ return (this.redisMajorVersion !== undefined && this.redisMajorVersion >= 5);
260
+ }
194
261
  }
195
262
  exports.RedisQueryResultCache = RedisQueryResultCache;
196
263
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cache/RedisQueryResultCache.ts"],"names":[],"mappings":";;;AAEA,6DAAyD;AAGzD,wDAAoD;AAEpD;;GAEG;AACH,MAAa,qBAAqB;IAoB9B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EAChC,UAAmD;QADzC,eAAU,GAAV,UAAU,CAAY;QAGhC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;IACjC,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,OAAO;QACT,MAAM,YAAY,GAAQ,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAA;QACvD,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;gBAClC,GAAG,YAAY,EAAE,OAAO;gBACxB,UAAU,EAAE,IAAI;aACnB,CAAC,CAAA;YACF,IACI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;gBACjD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,EAC5C,CAAC;gBACC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAQ,EAAE,EAAE;oBACjC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;gBAC3C,CAAC,CAAC,CAAA;YACN,CAAC;YACD,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC3B,MAAM,IAA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AO,CAAC,EAAE,CAAC;YACT,MAAM,IAAI,2BAAY,CAClB,4BAA4B,IAAI,CAAC,UAAU,wCAAwC,IAAI,CAAC,UAAU,WAAW,CAChH,CAAA;QACL,CAAC;IACL,CAAC;CACJ;AAhPD,sDAgPC","file":"RedisQueryResultCache.js","sourcesContent":["import { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { TypeORMError } from \"../error/TypeORMError\"\n\n/**\n * Caches query result into Redis database.\n */\nexport class RedisQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Redis module instance loaded dynamically.\n */\n protected redis: any\n\n /**\n * Connected redis client.\n */\n protected client: any\n\n /**\n * Type of the Redis Client (redis or ioredis).\n */\n protected clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\"\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected connection: DataSource,\n clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\",\n ) {\n this.clientType = clientType\n this.redis = this.loadRedis()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {\n const cacheOptions: any = this.connection.options.cache\n if (this.clientType === \"redis\") {\n this.client = this.redis.createClient({\n ...cacheOptions?.options,\n legacyMode: true,\n })\n if (\n typeof this.connection.options.cache === \"object\" &&\n this.connection.options.cache.ignoreErrors\n ) {\n this.client.on(\"error\", (err: any) => {\n this.connection.logger.log(\"warn\", err)\n })\n }\n if (\"connect\" in this.client) {\n await this.client.connect()\n }\n } else if (this.clientType === \"ioredis\") {\n if (cacheOptions && cacheOptions.port) {\n if (cacheOptions.options) {\n this.client = new this.redis(\n cacheOptions.port,\n cacheOptions.options,\n )\n } else {\n this.client = new this.redis(cacheOptions.port)\n }\n } else if (cacheOptions && cacheOptions.options) {\n this.client = new this.redis(cacheOptions.options)\n } else {\n this.client = new this.redis()\n }\n } else if (this.clientType === \"ioredis/cluster\") {\n if (\n cacheOptions &&\n cacheOptions.options &&\n Array.isArray(cacheOptions.options)\n ) {\n this.client = new this.redis.Cluster(cacheOptions.options)\n } else if (\n cacheOptions &&\n cacheOptions.options &&\n cacheOptions.options.startupNodes\n ) {\n this.client = new this.redis.Cluster(\n cacheOptions.options.startupNodes,\n cacheOptions.options.options,\n )\n } else {\n throw new TypeORMError(\n `options.startupNodes required for ${this.clientType}.`,\n )\n }\n }\n }\n\n /**\n * Disconnects the connection\n */\n async disconnect(): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.quit((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n this.client = undefined\n })\n })\n }\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner: QueryRunner): Promise<void> {}\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n return new Promise<QueryResultCacheOptions | undefined>((ok, fail) => {\n if (options.identifier) {\n this.client.get(options.identifier, (err: any, result: any) => {\n if (err) return fail(err)\n ok(JSON.parse(result))\n })\n } else if (options.query) {\n this.client.get(options.query, (err: any, result: any) => {\n if (err) return fail(err)\n ok(JSON.parse(result))\n })\n } else {\n ok(undefined)\n }\n })\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n return savedCache.time! + savedCache.duration < Date.now()\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n return new Promise<void>((ok, fail) => {\n if (options.identifier) {\n this.client.set(\n options.identifier,\n JSON.stringify(options),\n \"PX\",\n options.duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n } else if (options.query) {\n this.client.set(\n options.query,\n JSON.stringify(options),\n \"PX\",\n options.duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n }\n })\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner?: QueryRunner): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.flushdb((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n await Promise.all(\n identifiers.map((identifier) => {\n return this.deleteKey(identifier)\n }),\n )\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Removes a single key from redis database.\n */\n protected deleteKey(key: string): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.client.del(key, (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Loads redis dependency.\n */\n protected loadRedis(): any {\n try {\n if (this.clientType === \"ioredis/cluster\") {\n return PlatformTools.load(\"ioredis\")\n } else {\n return PlatformTools.load(this.clientType)\n }\n } catch (e) {\n throw new TypeORMError(\n `Cannot use cache because ${this.clientType} is not installed. Please run \"npm i ${this.clientType} --save\".`,\n )\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/cache/RedisQueryResultCache.ts"],"names":[],"mappings":";;;AAEA,6DAAyD;AAGzD,wDAAoD;AAEpD;;GAEG;AACH,MAAa,qBAAqB;IAyB9B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EAChC,UAAmD;QADzC,eAAU,GAAV,UAAU,CAAY;QAGhC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,K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iBAAiB,GAAG,CAAC,CAAA;QAC9B,CAAC;IACL,CAAC;IAED;;OAEG;IACK,gBAAgB;QACpB,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO;YAAE,OAAO,KAAK,CAAA;QAC7C,OAAO,CACH,IAAI,CAAC,iBAAiB,KAAK,SAAS,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,CACtE,CAAA;IACL,CAAC;CACJ;AApUD,sDAoUC","file":"RedisQueryResultCache.js","sourcesContent":["import { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { TypeORMError } from \"../error/TypeORMError\"\n\n/**\n * Caches query result into Redis database.\n */\nexport class RedisQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Redis module instance loaded dynamically.\n */\n protected redis: any\n\n /**\n * Connected redis client.\n */\n protected client: any\n\n /**\n * Type of the Redis Client (redis or ioredis).\n */\n protected clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\"\n\n /**\n * Redis major version number\n */\n protected redisMajorVersion: number | undefined\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected connection: DataSource,\n clientType: \"redis\" | \"ioredis\" | \"ioredis/cluster\",\n ) {\n this.clientType = clientType\n this.redis = this.loadRedis()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {\n const cacheOptions: any = this.connection.options.cache\n if (this.clientType === \"redis\") {\n const clientOptions = {\n ...cacheOptions?.options,\n }\n\n // Create initial client to test Redis version\n let tempClient = this.redis.createClient(clientOptions)\n const isRedis4Plus = typeof tempClient.connect === \"function\"\n\n if (isRedis4Plus) {\n // Redis 4+ detected, recreate with legacyMode for Redis 4.x\n // (Redis 5 will ignore legacyMode if not needed)\n clientOptions.legacyMode = true\n tempClient = this.redis.createClient(clientOptions)\n }\n\n // Set as the main client\n this.client = tempClient\n\n if (\n typeof this.connection.options.cache === \"object\" &&\n this.connection.options.cache.ignoreErrors\n ) {\n this.client.on(\"error\", (err: any) => {\n this.connection.logger.log(\"warn\", err)\n })\n }\n\n // Connect if Redis 4+\n if (typeof this.client.connect === \"function\") {\n await this.client.connect()\n }\n\n // Detect precise version after connection is established\n this.detectRedisVersion()\n } else if (this.clientType === \"ioredis\") {\n if (cacheOptions && cacheOptions.port) {\n if (cacheOptions.options) {\n this.client = new this.redis(\n cacheOptions.port,\n cacheOptions.options,\n )\n } else {\n this.client = new this.redis(cacheOptions.port)\n }\n } else if (cacheOptions && cacheOptions.options) {\n this.client = new this.redis(cacheOptions.options)\n } else {\n this.client = new this.redis()\n }\n } else if (this.clientType === \"ioredis/cluster\") {\n if (\n cacheOptions &&\n cacheOptions.options &&\n Array.isArray(cacheOptions.options)\n ) {\n this.client = new this.redis.Cluster(cacheOptions.options)\n } else if (\n cacheOptions &&\n cacheOptions.options &&\n cacheOptions.options.startupNodes\n ) {\n this.client = new this.redis.Cluster(\n cacheOptions.options.startupNodes,\n cacheOptions.options.options,\n )\n } else {\n throw new TypeORMError(\n `options.startupNodes required for ${this.clientType}.`,\n )\n }\n }\n }\n\n /**\n * Disconnects the connection\n */\n async disconnect(): Promise<void> {\n if (this.isRedis5OrHigher()) {\n // Redis 5+ uses quit() that returns a Promise\n await this.client.quit()\n this.client = undefined\n return\n }\n\n // Redis 3/4 callback style\n return new Promise<void>((ok, fail) => {\n this.client.quit((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n this.client = undefined\n })\n })\n }\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner: QueryRunner): Promise<void> {}\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n const key = options.identifier || options.query\n if (!key) return Promise.resolve(undefined)\n\n if (this.isRedis5OrHigher()) {\n // Redis 5+ Promise-based API\n return this.client.get(key).then((result: any) => {\n return result ? JSON.parse(result) : undefined\n })\n }\n\n // Redis 3/4 callback-based API\n return new Promise<QueryResultCacheOptions | undefined>((ok, fail) => {\n this.client.get(key, (err: any, result: any) => {\n if (err) return fail(err)\n ok(result ? JSON.parse(result) : undefined)\n })\n })\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n return savedCache.time! + savedCache.duration < Date.now()\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const key = options.identifier || options.query\n if (!key) return\n\n const value = JSON.stringify(options)\n const duration = options.duration\n\n if (this.isRedis5OrHigher()) {\n // Redis 5+ Promise-based API with PX option\n await this.client.set(key, value, {\n PX: duration,\n })\n return\n }\n\n // Redis 3/4 callback-based API\n return new Promise<void>((ok, fail) => {\n this.client.set(\n key,\n value,\n \"PX\",\n duration,\n (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n },\n )\n })\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner?: QueryRunner): Promise<void> {\n if (this.isRedis5OrHigher()) {\n // Redis 5+ Promise-based API\n await this.client.flushDb()\n return\n }\n\n // Redis 3/4 callback-based API\n return new Promise<void>((ok, fail) => {\n this.client.flushdb((err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n await Promise.all(\n identifiers.map((identifier) => {\n return this.deleteKey(identifier)\n }),\n )\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Removes a single key from redis database.\n */\n protected async deleteKey(key: string): Promise<void> {\n if (this.isRedis5OrHigher()) {\n // Redis 5+ Promise-based API\n await this.client.del(key)\n return\n }\n\n // Redis 3/4 callback-based API\n return new Promise<void>((ok, fail) => {\n this.client.del(key, (err: any, result: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n\n /**\n * Loads redis dependency.\n */\n protected loadRedis(): any {\n try {\n if (this.clientType === \"ioredis/cluster\") {\n return PlatformTools.load(\"ioredis\")\n } else {\n return PlatformTools.load(this.clientType)\n }\n } catch {\n throw new TypeORMError(\n `Cannot use cache because ${this.clientType} is not installed. Please run \"npm i ${this.clientType}\".`,\n )\n }\n }\n\n /**\n * Detects the Redis version based on the connected client's API characteristics\n * without creating test keys in the database\n */\n private detectRedisVersion(): void {\n if (this.clientType !== \"redis\") return\n\n try {\n // Detect version by examining the client's method signatures\n // This avoids creating test keys in the database\n const setMethod = this.client.set\n if (setMethod && setMethod.length <= 3) {\n // Redis 5+ set method accepts fewer parameters (key, value, options)\n this.redisMajorVersion = 5\n } else {\n // Redis 3/4 set method requires more parameters (key, value, flag, duration, callback)\n this.redisMajorVersion = 3\n }\n } catch {\n // Default to Redis 3/4 for maximum compatibility\n this.redisMajorVersion = 3\n }\n }\n\n /**\n * Checks if Redis version is 5.x or higher\n */\n private isRedis5OrHigher(): boolean {\n if (this.clientType !== \"redis\") return false\n return (\n this.redisMajorVersion !== undefined && this.redisMajorVersion >= 5\n )\n }\n}\n"],"sourceRoot":".."}
@@ -783,9 +783,9 @@ class CockroachDriver {
783
783
  try {
784
784
  return PlatformTools_1.PlatformTools.load("pg-query-stream");
785
785
  }
786
- catch (e) {
786
+ catch {
787
787
  // todo: better error for browser env
788
- throw new error_1.TypeORMError(`To use streams you should install pg-query-stream package. Please run npm i pg-query-stream --save command.`);
788
+ throw new error_1.TypeORMError(`To use streams you should install pg-query-stream package. Please run "npm i pg-query-stream".`);
789
789
  }
790
790
  }
791
791
  // -------------------------------------------------------------------------