masterrecord 0.3.67 → 1.0.0

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 (97) 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 +70 -83
  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 +10 -10
  17. package/Migrations/migrations.js +14 -12
  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 +26 -7
  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 +26 -6
  35. package/package.json +34 -5
  36. package/postgresEngine.js +29 -8
  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/esm-imports.test.js +110 -0
  42. package/test/fixtures/new-setter-large-string/config/environments/env.newsetter.json +1 -0
  43. package/test/fixtures/new-setter-large-string/db/newsettercontext.sqlite +0 -0
  44. package/test/fixtures/sqlite-lifecycle/config/environments/env.test.json +1 -0
  45. package/test/fixtures/sqlite-lifecycle/db/lifecyclecontext.sqlite +0 -0
  46. package/test/migration-template.test.js +47 -0
  47. package/test/new-setter-large-string.test.js +191 -0
  48. package/test/pool-key.test.js +43 -0
  49. package/test/sqlite-lifecycle.test.js +76 -0
  50. package/.eslintrc.js +0 -290
  51. package/.prettierrc.js +0 -109
  52. package/test/anyCommaStringTest.js +0 -237
  53. package/test/anyMethodTest.js +0 -176
  54. package/test/attachDetached.test.js +0 -303
  55. package/test/bulk-operations-test.js +0 -235
  56. package/test/cache-toObject-test.js +0 -105
  57. package/test/cacheIntegration.test.js +0 -319
  58. package/test/config-glob-pattern-test.js +0 -232
  59. package/test/double-where-bug-test.js +0 -71
  60. package/test/ensure-ready-test.js +0 -251
  61. package/test/entity-deduplication-test.js +0 -174
  62. package/test/entity-methods-test.js +0 -269
  63. package/test/findByIdTest.js +0 -227
  64. package/test/foreign-key-string-value-test.js +0 -406
  65. package/test/global-model-registry-test.js +0 -538
  66. package/test/id-setting-validation.js +0 -202
  67. package/test/includesFeatureTest.js +0 -183
  68. package/test/includesTransformTest.js +0 -110
  69. package/test/index-bug-fix-test.js +0 -188
  70. package/test/insert-return-test.js +0 -39
  71. package/test/lifecycle-hooks-test.js +0 -258
  72. package/test/multiContextCache.test.js +0 -230
  73. package/test/new-entity-migration-test.js +0 -162
  74. package/test/newMethodTest.js +0 -330
  75. package/test/newMethodUnitTest.js +0 -320
  76. package/test/optInCache.test.js +0 -221
  77. package/test/parameterizedPlaceholderTest.js +0 -159
  78. package/test/pool-registry-test.js +0 -303
  79. package/test/post-insert-tracking-test.js +0 -258
  80. package/test/postgresEngineTest.js +0 -463
  81. package/test/postgresIntegrationTest.js +0 -381
  82. package/test/promise-detection-test.js +0 -290
  83. package/test/qa-context-pattern-test.js +0 -319
  84. package/test/query-helpers-test.js +0 -258
  85. package/test/query-isolation-test.js +0 -59
  86. package/test/queryCache.test.js +0 -148
  87. package/test/securityTest.js +0 -268
  88. package/test/seed-data-test.js +0 -212
  89. package/test/seed-deduplication-test.js +0 -313
  90. package/test/seed-features-integration-test.js +0 -418
  91. package/test/seed-migration-template-test.js +0 -220
  92. package/test/singleDollarPlaceholderTest.js +0 -238
  93. package/test/tablePrefixTest.js +0 -100
  94. package/test/transformerTest.js +0 -287
  95. package/test/v0.3.34-bug-fixes-test.js +0 -428
  96. package/test/validation-test.js +0 -302
  97. package/test/whereChainingTest.js +0 -88
@@ -66,7 +66,9 @@
66
66
  "Bash(git -C /Users/alexanderrich/Documents/development/bookbaghq/bookbag-training log --oneline --all -- *MASTERRECORD_ISSUE*)",
67
67
  "Bash(npm ls -g masterrecord 2>&1 | head -5)",
68
68
  "Bash(gh pr:*)",
69
- "Read(//tmp/**)"
69
+ "Read(//tmp/**)",
70
+ "Bash(wait)",
71
+ "Bash(pkill -f \"node --test\")"
70
72
  ],
71
73
  "deny": [],
72
74
  "ask": []
package/CHANGES.md CHANGED
@@ -1,6 +1,35 @@
1
- # MasterRecord v1.0.0 - FAANG-Level Improvements
1
+ # MasterRecord Changelog
2
+
3
+ ## v1.0.0 — ESM-only
4
+
5
+ **BREAKING:** MasterRecord is now a pure ECMAScript Modules (ESM) package.
6
+
7
+ - `package.json` declares `"type": "module"` and publishes an `exports` map.
8
+ - Requires **Node.js 20 or newer**.
9
+ - All sources converted from `require` / `module.exports` to `import` / `export default`.
10
+ - `context.js` imports the SQLite driver (`better-sqlite3`) statically at the top of the module instead of `require(sqlName)` at runtime.
11
+ - Environment config files (`env.*.json`) and migration snapshot files (`*_contextSnapShot.json`) are now loaded with `fs.readFileSync` + `JSON.parse` instead of `require()`, keeping `context.env()` synchronous.
12
+ - User-authored migration files are loaded via `await import(pathToFileURL(file).href)` — `Migrations/cli.js` has always had this path; the CJS `Module.prototype.require` hook that aliased `require('masterrecord')` to the globally installed package has been removed. Host projects must install masterrecord as a local dependency.
13
+ - `Migrations/migrationTemplate.js` always emits ESM migrations (`import masterrecord from 'masterrecord'; … export default <Name>;`). The CJS branch and `moduleType` parameter are gone.
14
+ - `context.js` exports the default class plus named error classes (`ContextError`, `ConfigurationError`, `DatabaseConnectionError`, `EntityValidationError`) and the internal `_poolKey` helper.
15
+ - `Cache/QueryCache.js` background cleanup timer is now `.unref()`'d so it no longer keeps the Node event loop alive after user code finishes.
16
+ - `.eslintrc.js` / `.prettierrc.js` replaced with flat ESM configs (`eslint.config.js`, `prettier.config.js`).
17
+ - Test suite rewritten on top of Node's built-in `node --test` runner (`npm test`).
18
+ - Documentation (`readme.md`, `docs/MIGRATIONS_GUIDE.md`, `docs/POSTGRESQL_SETUP.md`, `docs/QUERY_CACHING_GUIDE.md`, `FOREIGN_KEY_STRING_FIX.md`) updated to ESM syntax throughout.
19
+
20
+ ### Migration guide for consumers
21
+
22
+ 1. Bump your Node.js runtime to 20+.
23
+ 2. Add `"type": "module"` to your application's `package.json`.
24
+ 3. Replace `const X = require('masterrecord/…')` with `import X from 'masterrecord/…'`.
25
+ 4. Replace `module.exports = MyContext` with `export default MyContext`.
26
+ 5. Add `.js` extensions to all relative import paths (ESM requires explicit extensions).
27
+ 6. Regenerate any existing migration files (or rewrite the top/bottom: `import masterrecord from 'masterrecord';` … `export default <Name>;`).
28
+
29
+ ---
30
+
31
+ ## Previous: v0.x — FAANG-Level Improvements
2
32
 
3
- ## Summary
4
33
  Updated `context.js` and `deleteManager.js` to meet Google/Meta/Amazon engineering standards with critical bug fixes, input validation, and performance improvements.
5
34
 
6
35
  ## Critical Fixes Applied
@@ -1,3 +1,5 @@
1
+ import crypto from 'node:crypto';
2
+
1
3
  /**
2
4
  * Production-Grade Query Result Cache
3
5
  * Similar to EF Core's EFCoreSecondLevelCacheInterceptor
@@ -20,7 +22,6 @@ class QueryCache {
20
22
  * Like Hibernate's query cache regions
21
23
  */
22
24
  generateKey(query, params, tableName) {
23
- const crypto = require('crypto');
24
25
  const normalizedQuery = query.trim().toLowerCase().replace(/\s+/g, ' ');
25
26
  const keyData = {
26
27
  query: normalizedQuery,
@@ -154,7 +155,10 @@ class QueryCache {
154
155
  * Background cleanup of expired entries
155
156
  */
156
157
  _startCleanupTimer() {
157
- setInterval(() => {
158
+ // .unref() so the interval does not keep the Node process alive
159
+ // after user code finishes — callers should not have to explicitly
160
+ // stop the cleanup timer to let their script exit.
161
+ const timer = setInterval(() => {
158
162
  const now = Date.now();
159
163
  let cleaned = 0;
160
164
 
@@ -168,8 +172,10 @@ class QueryCache {
168
172
  if (cleaned > 0 && process.env.NODE_ENV !== 'production') {
169
173
  console.debug(`[QueryCache CLEANUP] Removed ${cleaned} expired entries`);
170
174
  }
171
- }, 60000); // Run every minute
175
+ }, 60000);
176
+ if (typeof timer.unref === 'function') timer.unref();
177
+ this._cleanupTimer = timer;
172
178
  }
173
179
  }
174
180
 
175
- module.exports = QueryCache;
181
+ export default QueryCache;
@@ -1,3 +1,5 @@
1
+ import crypto from 'node:crypto';
2
+
1
3
  /**
2
4
  * Distributed Query Cache using Redis
3
5
  * For multi-process/clustered deployments
@@ -15,7 +17,6 @@ class RedisQueryCache {
15
17
  }
16
18
 
17
19
  generateKey(query, params, tableName) {
18
- const crypto = require('crypto');
19
20
  const hash = crypto.createHash('sha256')
20
21
  .update(JSON.stringify({query, params}))
21
22
  .digest('hex');
@@ -152,4 +153,4 @@ class RedisQueryCache {
152
153
  }
153
154
  }
154
155
 
155
- module.exports = RedisQueryCache;
156
+ export default RedisQueryCache;
@@ -384,4 +384,4 @@ class EntityModel {
384
384
  return this;
385
385
  }
386
386
  }
387
- module.exports = EntityModel;
387
+ export default EntityModel;
@@ -1,6 +1,6 @@
1
1
  // version 0.0.3
2
2
 
3
- var modelDB = require('./entityModel');
3
+ import modelDB from './entityModel.js';
4
4
 
5
5
  // creates new instance if entity model and calls inner functions to build out a valid entity
6
6
  class EntityModelBuilder {
@@ -102,4 +102,4 @@ class EntityModelBuilder {
102
102
 
103
103
  }
104
104
 
105
- module.exports = EntityModelBuilder;
105
+ export default EntityModelBuilder;
@@ -1,7 +1,7 @@
1
1
 
2
2
  // version : 0.0.9
3
- var tools = require('../Tools');
4
- var FieldTransformer = require('./fieldTransformer');
3
+ import tools from '../Tools.js';
4
+ import FieldTransformer from './fieldTransformer.js';
5
5
 
6
6
  class EntityTrackerModel {
7
7
 
@@ -523,4 +523,4 @@ class EntityTrackerModel {
523
523
 
524
524
  }
525
525
 
526
- module.exports = EntityTrackerModel;
526
+ export default EntityTrackerModel;
@@ -263,4 +263,4 @@ class FieldTransformer {
263
263
  }
264
264
  }
265
265
 
266
- module.exports = FieldTransformer;
266
+ export default FieldTransformer;
@@ -243,8 +243,8 @@ This bug was reported by Bookbag.ai Engineering Team and affects any application
243
243
  To verify the fix works with your code:
244
244
 
245
245
  ```javascript
246
- const UserOrganizationRole = require('./models/userOrganizationRole');
247
- const userContext = require('./models/userContext');
246
+ import UserOrganizationRole from './models/userOrganizationRole.js';
247
+ import userContext from './models/userContext.js';
248
248
 
249
249
  async function testFix() {
250
250
  const ctx = new userContext();
package/MasterRecord.js CHANGED
@@ -1,49 +1,12 @@
1
+ // version 1.1.0
2
+ import context from './context.js';
3
+ import schema from './Migrations/schema.js';
1
4
 
2
- // https://github.com/kriasoft/node-sqlite
3
- // https://www.learnentityframeworkcore.com/dbset/deleting-data
4
- // version 1.0.20
5
- var context = require("./context");
6
- var schema = require("./Migrations/schema");
7
-
8
- class masterrecord{
9
-
10
- constructor(){
5
+ class masterrecord {
6
+ constructor() {
11
7
  this.context = context;
12
8
  this.schema = schema;
13
9
  }
14
10
  }
15
11
 
16
-
17
- module.exports = new masterrecord();
18
-
19
-
20
-
21
- /*
22
-
23
- //Create new standard
24
- var standard = new Standard();
25
- standard.StandardName = "Standard1";
26
-
27
- //create three new teachers
28
- var teacher1 = new Teacher();
29
- teacher1.TeacherName = "New Teacher1";
30
-
31
- var teacher2 = new Teacher();
32
- teacher2.TeacherName = "New Teacher2";
33
-
34
- var teacher3 = new Teacher();
35
- teacher3.TeacherName = "New Teacher3";
36
-
37
- //add teachers for new standard
38
- standard.Teachers.Add(teacher1);
39
- standard.Teachers.Add(teacher2);
40
- standard.Teachers.Add(teacher3);
41
-
42
- using (var dbCtx = new SchoolDBEntities())
43
- {
44
- //add standard entity into standards entitySet
45
- dbCtx.Standards.Add(standard);
46
- //Save whole entity graph to the database
47
- dbCtx.SaveChanges();
48
- }
49
- */
12
+ export default new masterrecord();