masterrecord 0.3.68 → 1.0.1

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 (103) hide show
  1. package/.claude/settings.local.json +3 -1
  2. package/CHANGES.md +31 -2
  3. package/Cache/QueryCache.js +10 -4
  4. package/Cache/RedisQueryCache.js +3 -2
  5. package/Entity/entityModel.js +1 -1
  6. package/Entity/entityModelBuilder.js +2 -2
  7. package/Entity/entityTrackerModel.js +3 -3
  8. package/Entity/fieldTransformer.js +1 -1
  9. package/FOREIGN_KEY_STRING_FIX.md +2 -2
  10. package/MasterRecord.js +6 -43
  11. package/Migrations/cli.js +44 -113
  12. package/Migrations/dependencyGraph.js +1 -1
  13. package/Migrations/migrationMySQLQuery.js +1 -1
  14. package/Migrations/migrationPostgresQuery.js +1 -1
  15. package/Migrations/migrationSQLiteQuery.js +1 -1
  16. package/Migrations/migrationTemplate.js +8 -39
  17. package/Migrations/migrations.js +16 -14
  18. package/Migrations/pathUtils.js +2 -5
  19. package/Migrations/pathUtils.test.js +33 -49
  20. package/Migrations/schema.js +52 -89
  21. package/QueryLanguage/queryMethods.js +4 -4
  22. package/QueryLanguage/queryParameters.js +1 -1
  23. package/QueryLanguage/queryScript.js +4 -3
  24. package/SQLLiteEngine.js +30 -8
  25. package/Tools.js +10 -8
  26. package/context.js +43 -42
  27. package/deleteManager.js +2 -2
  28. package/docs/MIGRATIONS_GUIDE.md +237 -532
  29. package/docs/POSTGRESQL_SETUP.md +4 -4
  30. package/docs/QUERY_CACHING_GUIDE.md +8 -7
  31. package/eslint.config.js +40 -0
  32. package/insertManager.js +28 -20
  33. package/mySQLConnect.js +2 -2
  34. package/mySQLEngine.js +161 -16
  35. package/package.json +34 -5
  36. package/postgresEngine.js +74 -26
  37. package/postgresSyncConnect.js +5 -3
  38. package/prettier.config.js +22 -0
  39. package/readme.md +35 -27
  40. package/test/context-errors.test.js +43 -0
  41. package/test/count-chained-where.test.js +136 -0
  42. package/test/esm-imports.test.js +110 -0
  43. package/test/fixtures/count-chained-where/config/environments/env.countchained.json +1 -0
  44. package/test/fixtures/count-chained-where/db/countctx.sqlite +0 -0
  45. package/test/fixtures/new-setter-large-string/config/environments/env.newsetter.json +1 -0
  46. package/test/fixtures/new-setter-large-string/db/newsettercontext.sqlite +0 -0
  47. package/test/fixtures/query-builder-parity/config/environments/env.parity.json +1 -0
  48. package/test/fixtures/query-builder-parity/db/parityctx.sqlite +0 -0
  49. package/test/fixtures/sqlite-lifecycle/config/environments/env.test.json +1 -0
  50. package/test/fixtures/sqlite-lifecycle/db/lifecyclecontext.sqlite +0 -0
  51. package/test/migration-template.test.js +47 -0
  52. package/test/new-setter-large-string.test.js +191 -0
  53. package/test/pool-key.test.js +43 -0
  54. package/test/query-builder-parity.test.js +260 -0
  55. package/test/sqlite-lifecycle.test.js +76 -0
  56. package/.eslintrc.js +0 -290
  57. package/.prettierrc.js +0 -109
  58. package/test/anyCommaStringTest.js +0 -237
  59. package/test/anyMethodTest.js +0 -176
  60. package/test/attachDetached.test.js +0 -303
  61. package/test/bulk-operations-test.js +0 -235
  62. package/test/cache-toObject-test.js +0 -105
  63. package/test/cacheIntegration.test.js +0 -319
  64. package/test/config-glob-pattern-test.js +0 -232
  65. package/test/double-where-bug-test.js +0 -71
  66. package/test/ensure-ready-test.js +0 -251
  67. package/test/entity-deduplication-test.js +0 -174
  68. package/test/entity-methods-test.js +0 -269
  69. package/test/findByIdTest.js +0 -227
  70. package/test/foreign-key-string-value-test.js +0 -406
  71. package/test/global-model-registry-test.js +0 -538
  72. package/test/id-setting-validation.js +0 -202
  73. package/test/includesFeatureTest.js +0 -183
  74. package/test/includesTransformTest.js +0 -110
  75. package/test/index-bug-fix-test.js +0 -188
  76. package/test/insert-return-test.js +0 -39
  77. package/test/lifecycle-hooks-test.js +0 -258
  78. package/test/multiContextCache.test.js +0 -230
  79. package/test/new-entity-migration-test.js +0 -162
  80. package/test/newMethodTest.js +0 -330
  81. package/test/newMethodUnitTest.js +0 -320
  82. package/test/optInCache.test.js +0 -221
  83. package/test/parameterizedPlaceholderTest.js +0 -159
  84. package/test/pool-registry-test.js +0 -303
  85. package/test/post-insert-tracking-test.js +0 -258
  86. package/test/postgresEngineTest.js +0 -463
  87. package/test/postgresIntegrationTest.js +0 -381
  88. package/test/promise-detection-test.js +0 -290
  89. package/test/qa-context-pattern-test.js +0 -319
  90. package/test/query-helpers-test.js +0 -258
  91. package/test/query-isolation-test.js +0 -59
  92. package/test/queryCache.test.js +0 -148
  93. package/test/securityTest.js +0 -268
  94. package/test/seed-data-test.js +0 -212
  95. package/test/seed-deduplication-test.js +0 -313
  96. package/test/seed-features-integration-test.js +0 -418
  97. package/test/seed-migration-template-test.js +0 -220
  98. package/test/singleDollarPlaceholderTest.js +0 -238
  99. package/test/tablePrefixTest.js +0 -100
  100. package/test/transformerTest.js +0 -287
  101. package/test/v0.3.34-bug-fixes-test.js +0 -428
  102. package/test/validation-test.js +0 -302
  103. package/test/whereChainingTest.js +0 -88
package/context.js CHANGED
@@ -13,24 +13,28 @@
13
13
  * @license MIT
14
14
  */
15
15
 
16
- 'use strict';
17
-
18
16
  // Core dependencies
19
- const modelBuilder = require('./Entity/entityModelBuilder');
20
- const query = require('masterrecord/QueryLanguage/queryMethods');
21
- const tools = require('./Tools');
22
- const SQLLiteEngine = require('masterrecord/SQLLiteEngine');
23
- const MySQLEngine = require('masterrecord/mySQLEngine');
24
- const PostgresEngine = require('masterrecord/postgresEngine');
25
- const insertManager = require('./insertManager');
26
- const deleteManager = require('./deleteManager');
27
- const globSearch = require('glob');
28
- const fs = require('fs');
29
- const path = require('path');
30
- const appRoot = require('app-root-path');
31
- const MySQLAsyncClient = require('masterrecord/mySQLConnect');
32
- const PostgresClient = require('masterrecord/postgresSyncConnect');
33
- const QueryCache = require('./Cache/QueryCache');
17
+ import modelBuilder from './Entity/entityModelBuilder.js';
18
+ import query from './QueryLanguage/queryMethods.js';
19
+ import tools from './Tools.js';
20
+ import SQLLiteEngine from './SQLLiteEngine.js';
21
+ import MySQLEngine from './mySQLEngine.js';
22
+ import PostgresEngine from './postgresEngine.js';
23
+ import insertManager from './insertManager.js';
24
+ import deleteManager from './deleteManager.js';
25
+ import { globSync } from 'glob';
26
+ import fs from 'node:fs';
27
+ import path from 'node:path';
28
+ import { fileURLToPath } from 'node:url';
29
+ import appRoot from 'app-root-path';
30
+ import Database from 'better-sqlite3';
31
+ import MySQLAsyncClient from './mySQLConnect.js';
32
+ import PostgresClient from './postgresSyncConnect.js';
33
+ import QueryCache from './Cache/QueryCache.js';
34
+ import DependencyGraph from './Migrations/dependencyGraph.js';
35
+
36
+ const __filename = fileURLToPath(import.meta.url);
37
+ const __dirname = path.dirname(__filename);
34
38
 
35
39
  // ============================================================================
36
40
  // GLOBAL POOL REGISTRY - One pool per database, shared across all contexts
@@ -298,7 +302,6 @@ class context {
298
302
  */
299
303
  __SQLiteInit(env, sqlName) {
300
304
  try {
301
- const sqlite3 = require(sqlName);
302
305
  const dbAddress = env.completeConnection;
303
306
 
304
307
  // Validate database path
@@ -311,7 +314,7 @@ class context {
311
314
  }
312
315
 
313
316
  // Create database connection with validated path
314
- const db = new sqlite3(dbAddress, env);
317
+ const db = new Database(dbAddress, env);
315
318
  db.__name = sqlName;
316
319
  this._SQLEngine = new SQLLiteEngine();
317
320
 
@@ -599,7 +602,7 @@ class context {
599
602
 
600
603
  let files = [];
601
604
  for (const pattern of patterns) {
602
- files = globSearch.sync(pattern, {
605
+ files = globSync(pattern, {
603
606
  cwd: currentRoot,
604
607
  dot: true,
605
608
  nocase: true,
@@ -611,7 +614,6 @@ class context {
611
614
  // Return first match
612
615
  if (files && files.length > 0) {
613
616
  const rel = files[0];
614
- // Ensure absolute path for require()
615
617
  const abs = path.isAbsolute(rel) ? rel : path.resolve(currentRoot, rel);
616
618
 
617
619
  // Find actual project root by looking for package.json or .git
@@ -678,12 +680,14 @@ class context {
678
680
  throw new ConfigurationError('Database connection path is required for SQLite');
679
681
  }
680
682
 
681
- // Treat leading project-style paths ('/components/...') as project-root relative
682
- const looksProjectRootRelative = dbPath.startsWith('/') || dbPath.startsWith('\\');
683
- const isAbsoluteFsPath = path.isAbsolute(dbPath);
684
-
685
- if (looksProjectRootRelative || !isAbsoluteFsPath) {
686
- // Normalize leading separators to avoid duplicating separators on Windows
683
+ // If the path is already an absolute filesystem path, use it as-is.
684
+ // On Windows, `path.isAbsolute('C:\\foo')` → true; on POSIX,
685
+ // `path.isAbsolute('/foo')` → true. Do NOT treat POSIX-absolute paths
686
+ // as "project-root relative" — that used to cause the root folder to
687
+ // be prepended to an already-absolute path, producing a doubled-up
688
+ // path like "/Users/x/project/Users/x/project/db/...".
689
+ if (!path.isAbsolute(dbPath)) {
690
+ // Normalize any leading separators so `path.join` doesn't duplicate them
687
691
  const trimmed = dbPath.replace(/^[/\\]+/, '');
688
692
  dbPath = path.join(rootFolder, trimmed);
689
693
  }
@@ -790,9 +794,9 @@ class context {
790
794
  );
791
795
  }
792
796
 
793
- // Always require absolute file path to avoid module root ambiguity on global installs/Windows
797
+ // Always use absolute file path to avoid module root ambiguity on global installs/Windows
794
798
  const settingsPath = path.isAbsolute(file.file) ? file.file : path.resolve(file.rootFolder, file.file);
795
- const settings = require(settingsPath);
799
+ const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
796
800
  const options = settings[contextName];
797
801
 
798
802
  if (!options || typeof options !== 'object') {
@@ -971,7 +975,7 @@ class context {
971
975
  }
972
976
  const contextName = this.__name;
973
977
  const file = this.__findSettings(root, rootFolderLocation, envType);
974
- const settings = require(file.file);
978
+ const settings = JSON.parse(fs.readFileSync(file.file, 'utf8'));
975
979
  const options = settings[contextName];
976
980
 
977
981
  if (!options || typeof options !== 'object') {
@@ -1135,7 +1139,7 @@ class context {
1135
1139
  const contextName = this.__name;
1136
1140
  const root = appRoot.path;
1137
1141
  const file = this.__findSettings(root, rootFolderLocation, envType);
1138
- const settings = require(file.file);
1142
+ const settings = JSON.parse(fs.readFileSync(file.file, 'utf8'));
1139
1143
  const options = settings[contextName];
1140
1144
 
1141
1145
  if (!options || typeof options !== 'object') {
@@ -1534,7 +1538,6 @@ class context {
1534
1538
  return {};
1535
1539
  }
1536
1540
 
1537
- const DependencyGraph = require('./Migrations/dependencyGraph');
1538
1541
  const graph = new DependencyGraph(this.__entities);
1539
1542
  graph.buildFromEntities();
1540
1543
 
@@ -2396,13 +2399,11 @@ class context {
2396
2399
  // EXPORTS
2397
2400
  // ============================================================================
2398
2401
 
2399
- module.exports = context;
2400
-
2401
- // Export custom error classes for advanced error handling
2402
- module.exports.ContextError = ContextError;
2403
- module.exports.ConfigurationError = ConfigurationError;
2404
- module.exports.DatabaseConnectionError = DatabaseConnectionError;
2405
- module.exports.EntityValidationError = EntityValidationError;
2406
-
2407
- // Export pool key generator for use by schema.js (single source of truth)
2408
- module.exports._poolKey = _poolKey;
2402
+ export {
2403
+ ContextError,
2404
+ ConfigurationError,
2405
+ DatabaseConnectionError,
2406
+ EntityValidationError,
2407
+ _poolKey
2408
+ };
2409
+ export default context;
package/deleteManager.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // version 1.0.0 - FAANG-Level Refactored
2
- const tools = require('./Tools');
2
+ import tools from './Tools.js';
3
3
 
4
4
  // Constants for relationship types
5
5
  const RELATIONSHIP_TYPES = {
@@ -176,4 +176,4 @@ class DeleteManager {
176
176
  }
177
177
  }
178
178
 
179
- module.exports = DeleteManager;
179
+ export default DeleteManager;