typeorm 0.3.26-dev.f351757 → 0.3.27-dev.22b26d1

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 (62) hide show
  1. package/README.md +16 -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/decorator/options/ColumnOptions.d.ts +6 -0
  6. package/browser/decorator/options/ColumnOptions.js.map +1 -1
  7. package/browser/decorator/options/VirtualColumnOptions.d.ts +5 -0
  8. package/browser/decorator/options/VirtualColumnOptions.js.map +1 -1
  9. package/browser/driver/cockroachdb/CockroachDriver.js +2 -2
  10. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  11. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +9 -9
  12. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  13. package/browser/driver/mysql/MysqlDriver.js +3 -1
  14. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  15. package/browser/driver/postgres/PostgresDriver.js +2 -2
  16. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  17. package/browser/driver/postgres/PostgresQueryRunner.js +1 -1
  18. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  19. package/browser/entity-schema/EntitySchemaColumnOptions.d.ts +10 -0
  20. package/browser/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
  21. package/browser/entity-schema/EntitySchemaTransformer.js +3 -0
  22. package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
  23. package/browser/error/DriverPackageNotInstalledError.js +1 -2
  24. package/browser/error/DriverPackageNotInstalledError.js.map +1 -1
  25. package/browser/platform/BrowserPlatformTools.js +7 -3
  26. package/browser/platform/BrowserPlatformTools.js.map +1 -1
  27. package/browser/query-builder/SelectQueryBuilder.js +3 -6
  28. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  29. package/browser/repository/SaveOptions.d.ts +1 -1
  30. package/browser/repository/SaveOptions.js.map +1 -1
  31. package/browser/util/ImportUtils.js +29 -1
  32. package/browser/util/ImportUtils.js.map +1 -1
  33. package/cache/RedisQueryResultCache.d.ts +13 -0
  34. package/cache/RedisQueryResultCache.js +105 -38
  35. package/cache/RedisQueryResultCache.js.map +1 -1
  36. package/decorator/options/ColumnOptions.d.ts +6 -0
  37. package/decorator/options/ColumnOptions.js.map +1 -1
  38. package/decorator/options/VirtualColumnOptions.d.ts +5 -0
  39. package/decorator/options/VirtualColumnOptions.js.map +1 -1
  40. package/driver/cockroachdb/CockroachDriver.js +2 -2
  41. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  42. package/driver/mongodb/MongoConnectionOptions.d.ts +9 -9
  43. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  44. package/driver/mysql/MysqlDriver.js +3 -1
  45. package/driver/mysql/MysqlDriver.js.map +1 -1
  46. package/driver/postgres/PostgresDriver.js +2 -2
  47. package/driver/postgres/PostgresDriver.js.map +1 -1
  48. package/driver/postgres/PostgresQueryRunner.js +1 -1
  49. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  50. package/entity-schema/EntitySchemaColumnOptions.d.ts +10 -0
  51. package/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
  52. package/entity-schema/EntitySchemaTransformer.js +3 -0
  53. package/entity-schema/EntitySchemaTransformer.js.map +1 -1
  54. package/error/DriverPackageNotInstalledError.js +1 -2
  55. package/error/DriverPackageNotInstalledError.js.map +1 -1
  56. package/package.json +1 -1
  57. package/query-builder/SelectQueryBuilder.js +3 -6
  58. package/query-builder/SelectQueryBuilder.js.map +1 -1
  59. package/repository/SaveOptions.d.ts +1 -1
  60. package/repository/SaveOptions.js.map +1 -1
  61. package/util/ImportUtils.js +29 -1
  62. package/util/ImportUtils.js.map +1 -1
@@ -28,7 +28,7 @@ export interface SaveOptions {
28
28
  * Flag to determine whether the entity that is being persisted
29
29
  * should be reloaded during the persistence operation.
30
30
  *
31
- * It will work only on databases which does not support RETURNING / OUTPUT statement.
31
+ * It will work only on databases which do not support RETURNING / OUTPUT statement.
32
32
  * Enabled by default.
33
33
  */
34
34
  reload?: boolean;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/repository/SaveOptions.ts"],"names":[],"mappings":"","file":"SaveOptions.js","sourcesContent":["/**\n * Special options passed to Repository#save, Repository#insert and Repository#update methods.\n */\nexport interface SaveOptions {\n /**\n * Additional data to be passed with persist method.\n * This data can be used in subscribers then.\n */\n data?: any\n\n /**\n * Indicates if listeners and subscribers are called for this operation.\n * By default they are enabled, you can disable them by setting { listeners: false } in save/remove options.\n */\n listeners?: boolean\n\n /**\n * By default transactions are enabled and all queries in persistence operation are wrapped into the transaction.\n * You can disable this behaviour by setting { transaction: false } in the persistence options.\n */\n transaction?: boolean\n\n /**\n * Breaks save execution into chunks of a given size.\n * For example, if you want to save 100,000 objects but you have issues with saving them,\n * you can break them into 10 groups of 10,000 objects (by setting { chunk: 10000 }) and save each group separately.\n * This option is needed to perform very big insertions when you have issues with underlying driver parameter number limitation.\n */\n chunk?: number\n\n /**\n * Flag to determine whether the entity that is being persisted\n * should be reloaded during the persistence operation.\n *\n * It will work only on databases which does not support RETURNING / OUTPUT statement.\n * Enabled by default.\n */\n reload?: boolean\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/repository/SaveOptions.ts"],"names":[],"mappings":"","file":"SaveOptions.js","sourcesContent":["/**\n * Special options passed to Repository#save, Repository#insert and Repository#update methods.\n */\nexport interface SaveOptions {\n /**\n * Additional data to be passed with persist method.\n * This data can be used in subscribers then.\n */\n data?: any\n\n /**\n * Indicates if listeners and subscribers are called for this operation.\n * By default they are enabled, you can disable them by setting { listeners: false } in save/remove options.\n */\n listeners?: boolean\n\n /**\n * By default transactions are enabled and all queries in persistence operation are wrapped into the transaction.\n * You can disable this behaviour by setting { transaction: false } in the persistence options.\n */\n transaction?: boolean\n\n /**\n * Breaks save execution into chunks of a given size.\n * For example, if you want to save 100,000 objects but you have issues with saving them,\n * you can break them into 10 groups of 10,000 objects (by setting { chunk: 10000 }) and save each group separately.\n * This option is needed to perform very big insertions when you have issues with underlying driver parameter number limitation.\n */\n chunk?: number\n\n /**\n * Flag to determine whether the entity that is being persisted\n * should be reloaded during the persistence operation.\n *\n * It will work only on databases which do not support RETURNING / OUTPUT statement.\n * Enabled by default.\n */\n reload?: boolean\n}\n"],"sourceRoot":".."}
@@ -39,10 +39,32 @@ async function importOrRequireFile(filePath) {
39
39
  }
40
40
  return tryToRequire();
41
41
  }
42
+ const packageJsonCache = new Map();
43
+ const MAX_CACHE_SIZE = 1000;
44
+ function setPackageJsonCache(paths, packageJson) {
45
+ for (const path of paths) {
46
+ // Simple LRU-like behavior: if we're at capacity, remove oldest entry
47
+ if (packageJsonCache.size >= MAX_CACHE_SIZE &&
48
+ !packageJsonCache.has(path)) {
49
+ const firstKey = packageJsonCache.keys().next().value;
50
+ if (firstKey)
51
+ packageJsonCache.delete(firstKey);
52
+ }
53
+ packageJsonCache.set(path, packageJson);
54
+ }
55
+ }
42
56
  async function getNearestPackageJson(filePath) {
43
57
  let currentPath = filePath;
58
+ const paths = [];
44
59
  while (currentPath !== path_1.default.dirname(currentPath)) {
45
60
  currentPath = path_1.default.dirname(currentPath);
61
+ // Check if we have already cached the package.json for this path
62
+ if (packageJsonCache.has(currentPath)) {
63
+ setPackageJsonCache(paths, packageJsonCache.get(currentPath));
64
+ return packageJsonCache.get(currentPath);
65
+ }
66
+ // Add the current path to the list of paths to cache
67
+ paths.push(currentPath);
46
68
  const potentialPackageJson = path_1.default.join(currentPath, "package.json");
47
69
  try {
48
70
  const stats = await promises_1.default.stat(potentialPackageJson);
@@ -50,9 +72,14 @@ async function getNearestPackageJson(filePath) {
50
72
  continue;
51
73
  }
52
74
  try {
53
- return JSON.parse(await promises_1.default.readFile(potentialPackageJson, "utf8"));
75
+ const parsedPackage = JSON.parse(await promises_1.default.readFile(potentialPackageJson, "utf8"));
76
+ // Cache the parsed package.json object and return it
77
+ setPackageJsonCache(paths, parsedPackage);
78
+ return parsedPackage;
54
79
  }
55
80
  catch {
81
+ // If parsing fails, we still cache null to avoid repeated attempts
82
+ setPackageJsonCache(paths, null);
56
83
  return null;
57
84
  }
58
85
  }
@@ -61,6 +88,7 @@ async function getNearestPackageJson(filePath) {
61
88
  }
62
89
  }
63
90
  // the top of the file tree is reached
91
+ setPackageJsonCache(paths, null);
64
92
  return null;
65
93
  }
66
94
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/ImportUtils.ts"],"names":[],"mappings":";;AAIA,kDAoCC;;AAxCD,mEAA4B;AAC5B,wDAAuB;AACvB,6BAAmC;AAE5B,KAAK,UAAU,mBAAmB,CACrC,QAAgB;IAEhB,MAAM,WAAW,GAAG,KAAK,IAA2B,EAAE;QAClD,qFAAqF;QACrF,oDAAoD;QACpD,OAAO;YACH,8DAA8D;YAC9D,MAAM,QAAQ,CAAC,qCAAqC,CAAC,EAAE,CACnD,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;gBAC1B,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAC3C;YACD,KAAK;SACR,CAAA;IACL,CAAC,CAAA;IACD,MAAM,YAAY,GAAG,GAAsB,EAAE;QACzC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAA;IAC1C,CAAC,CAAA;IAED,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;IAE5E,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,WAAW,EAAE,CAAA;SAC/D,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,YAAY,EAAE,CAAA;SACrE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nimport { pathToFileURL } from \"url\"\n\nexport async function importOrRequireFile(\n filePath: string,\n): Promise<[any, \"esm\" | \"commonjs\"]> {\n const tryToImport = async (): Promise<[any, \"esm\"]> => {\n // `Function` is required to make sure the `import` statement wil stay `import` after\n // transpilation and won't be converted to `require`\n return [\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n await Function(\"return filePath => import(filePath)\")()(\n filePath.startsWith(\"file://\")\n ? filePath\n : pathToFileURL(filePath).toString(),\n ),\n \"esm\",\n ]\n }\n const tryToRequire = (): [any, \"commonjs\"] => {\n return [require(filePath), \"commonjs\"]\n }\n\n const extension = filePath.substring(filePath.lastIndexOf(\".\") + \".\".length)\n\n if (extension === \"mjs\" || extension === \"mts\") return tryToImport()\n else if (extension === \"cjs\" || extension === \"cts\") return tryToRequire()\n else if (extension === \"js\" || extension === \"ts\") {\n const packageJson = await getNearestPackageJson(filePath)\n\n if (packageJson != null) {\n const isModule = (packageJson as any)?.type === \"module\"\n\n if (isModule) return tryToImport()\n else return tryToRequire()\n } else return tryToRequire()\n }\n\n return tryToRequire()\n}\n\nasync function getNearestPackageJson(filePath: string): Promise<object | null> {\n let currentPath = filePath\n\n while (currentPath !== path.dirname(currentPath)) {\n currentPath = path.dirname(currentPath)\n const potentialPackageJson = path.join(currentPath, \"package.json\")\n\n try {\n const stats = await fs.stat(potentialPackageJson)\n if (!stats.isFile()) {\n continue\n }\n\n try {\n return JSON.parse(\n await fs.readFile(potentialPackageJson, \"utf8\"),\n )\n } catch {\n return null\n }\n } catch {\n continue\n }\n }\n\n // the top of the file tree is reached\n return null\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/util/ImportUtils.ts"],"names":[],"mappings":";;AAIA,kDAoCC;;AAxCD,mEAA4B;AAC5B,wDAAuB;AACvB,6BAAmC;AAE5B,KAAK,UAAU,mBAAmB,CACrC,QAAgB;IAEhB,MAAM,WAAW,GAAG,KAAK,IAA2B,EAAE;QAClD,qFAAqF;QACrF,oDAAoD;Q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;gBACD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAC5B,MAAM,kBAAE,CAAC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAClD,CAAA;gBACD,qDAAqD;gBACrD,mBAAmB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;gBACzC,OAAO,aAAa,CAAA;YACxB,CAAC;YAAC,MAAM,CAAC;gBACL,mEAAmE;gBACnE,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBAChC,OAAO,IAAI,CAAA;YACf,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACL,SAAQ;QACZ,CAAC;IACL,CAAC;IAED,sCAAsC;IACtC,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAChC,OAAO,IAAI,CAAA;AACf,CAAC","file":"ImportUtils.js","sourcesContent":["import fs from \"fs/promises\"\nimport path from \"path\"\nimport { pathToFileURL } from \"url\"\n\nexport async function importOrRequireFile(\n filePath: string,\n): Promise<[any, \"esm\" | \"commonjs\"]> {\n const tryToImport = async (): Promise<[any, \"esm\"]> => {\n // `Function` is required to make sure the `import` statement wil stay `import` after\n // transpilation and won't be converted to `require`\n return [\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n await Function(\"return filePath => import(filePath)\")()(\n filePath.startsWith(\"file://\")\n ? filePath\n : pathToFileURL(filePath).toString(),\n ),\n \"esm\",\n ]\n }\n const tryToRequire = (): [any, \"commonjs\"] => {\n return [require(filePath), \"commonjs\"]\n }\n\n const extension = filePath.substring(filePath.lastIndexOf(\".\") + \".\".length)\n\n if (extension === \"mjs\" || extension === \"mts\") return tryToImport()\n else if (extension === \"cjs\" || extension === \"cts\") return tryToRequire()\n else if (extension === \"js\" || extension === \"ts\") {\n const packageJson = await getNearestPackageJson(filePath)\n\n if (packageJson != null) {\n const isModule = (packageJson as any)?.type === \"module\"\n\n if (isModule) return tryToImport()\n else return tryToRequire()\n } else return tryToRequire()\n }\n\n return tryToRequire()\n}\n\nconst packageJsonCache = new Map<string, object | null>()\nconst MAX_CACHE_SIZE = 1000\n\nfunction setPackageJsonCache(paths: string[], packageJson: object | null) {\n for (const path of paths) {\n // Simple LRU-like behavior: if we're at capacity, remove oldest entry\n if (\n packageJsonCache.size >= MAX_CACHE_SIZE &&\n !packageJsonCache.has(path)\n ) {\n const firstKey = packageJsonCache.keys().next().value\n if (firstKey) packageJsonCache.delete(firstKey)\n }\n packageJsonCache.set(path, packageJson)\n }\n}\n\nasync function getNearestPackageJson(filePath: string): Promise<object | null> {\n let currentPath = filePath\n const paths: string[] = []\n\n while (currentPath !== path.dirname(currentPath)) {\n currentPath = path.dirname(currentPath)\n\n // Check if we have already cached the package.json for this path\n if (packageJsonCache.has(currentPath)) {\n setPackageJsonCache(paths, packageJsonCache.get(currentPath)!)\n return packageJsonCache.get(currentPath)!\n }\n\n // Add the current path to the list of paths to cache\n paths.push(currentPath)\n\n const potentialPackageJson = path.join(currentPath, \"package.json\")\n\n try {\n const stats = await fs.stat(potentialPackageJson)\n if (!stats.isFile()) {\n continue\n }\n\n try {\n const parsedPackage = JSON.parse(\n await fs.readFile(potentialPackageJson, \"utf8\"),\n )\n // Cache the parsed package.json object and return it\n setPackageJsonCache(paths, parsedPackage)\n return parsedPackage\n } catch {\n // If parsing fails, we still cache null to avoid repeated attempts\n setPackageJsonCache(paths, null)\n return null\n }\n } catch {\n continue\n }\n }\n\n // the top of the file tree is reached\n setPackageJsonCache(paths, null)\n return null\n}\n"],"sourceRoot":".."}