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.
- package/.claude/settings.local.json +3 -1
- package/CHANGES.md +31 -2
- package/Cache/QueryCache.js +10 -4
- package/Cache/RedisQueryCache.js +3 -2
- package/Entity/entityModel.js +1 -1
- package/Entity/entityModelBuilder.js +2 -2
- package/Entity/entityTrackerModel.js +3 -3
- package/Entity/fieldTransformer.js +1 -1
- package/FOREIGN_KEY_STRING_FIX.md +2 -2
- package/MasterRecord.js +6 -43
- package/Migrations/cli.js +70 -83
- package/Migrations/dependencyGraph.js +1 -1
- package/Migrations/migrationMySQLQuery.js +1 -1
- package/Migrations/migrationPostgresQuery.js +1 -1
- package/Migrations/migrationSQLiteQuery.js +1 -1
- package/Migrations/migrationTemplate.js +10 -10
- package/Migrations/migrations.js +14 -12
- package/Migrations/pathUtils.js +2 -5
- package/Migrations/pathUtils.test.js +33 -49
- package/Migrations/schema.js +52 -89
- package/QueryLanguage/queryMethods.js +4 -4
- package/QueryLanguage/queryParameters.js +1 -1
- package/QueryLanguage/queryScript.js +4 -3
- package/SQLLiteEngine.js +26 -7
- package/Tools.js +10 -8
- package/context.js +43 -42
- package/deleteManager.js +2 -2
- package/docs/MIGRATIONS_GUIDE.md +237 -532
- package/docs/POSTGRESQL_SETUP.md +4 -4
- package/docs/QUERY_CACHING_GUIDE.md +8 -7
- package/eslint.config.js +40 -0
- package/insertManager.js +28 -20
- package/mySQLConnect.js +2 -2
- package/mySQLEngine.js +26 -6
- package/package.json +34 -5
- package/postgresEngine.js +29 -8
- package/postgresSyncConnect.js +5 -3
- package/prettier.config.js +22 -0
- package/readme.md +35 -27
- package/test/context-errors.test.js +43 -0
- package/test/esm-imports.test.js +110 -0
- package/test/fixtures/new-setter-large-string/config/environments/env.newsetter.json +1 -0
- package/test/fixtures/new-setter-large-string/db/newsettercontext.sqlite +0 -0
- package/test/fixtures/sqlite-lifecycle/config/environments/env.test.json +1 -0
- package/test/fixtures/sqlite-lifecycle/db/lifecyclecontext.sqlite +0 -0
- package/test/migration-template.test.js +47 -0
- package/test/new-setter-large-string.test.js +191 -0
- package/test/pool-key.test.js +43 -0
- package/test/sqlite-lifecycle.test.js +76 -0
- package/.eslintrc.js +0 -290
- package/.prettierrc.js +0 -109
- package/test/anyCommaStringTest.js +0 -237
- package/test/anyMethodTest.js +0 -176
- package/test/attachDetached.test.js +0 -303
- package/test/bulk-operations-test.js +0 -235
- package/test/cache-toObject-test.js +0 -105
- package/test/cacheIntegration.test.js +0 -319
- package/test/config-glob-pattern-test.js +0 -232
- package/test/double-where-bug-test.js +0 -71
- package/test/ensure-ready-test.js +0 -251
- package/test/entity-deduplication-test.js +0 -174
- package/test/entity-methods-test.js +0 -269
- package/test/findByIdTest.js +0 -227
- package/test/foreign-key-string-value-test.js +0 -406
- package/test/global-model-registry-test.js +0 -538
- package/test/id-setting-validation.js +0 -202
- package/test/includesFeatureTest.js +0 -183
- package/test/includesTransformTest.js +0 -110
- package/test/index-bug-fix-test.js +0 -188
- package/test/insert-return-test.js +0 -39
- package/test/lifecycle-hooks-test.js +0 -258
- package/test/multiContextCache.test.js +0 -230
- package/test/new-entity-migration-test.js +0 -162
- package/test/newMethodTest.js +0 -330
- package/test/newMethodUnitTest.js +0 -320
- package/test/optInCache.test.js +0 -221
- package/test/parameterizedPlaceholderTest.js +0 -159
- package/test/pool-registry-test.js +0 -303
- package/test/post-insert-tracking-test.js +0 -258
- package/test/postgresEngineTest.js +0 -463
- package/test/postgresIntegrationTest.js +0 -381
- package/test/promise-detection-test.js +0 -290
- package/test/qa-context-pattern-test.js +0 -319
- package/test/query-helpers-test.js +0 -258
- package/test/query-isolation-test.js +0 -59
- package/test/queryCache.test.js +0 -148
- package/test/securityTest.js +0 -268
- package/test/seed-data-test.js +0 -212
- package/test/seed-deduplication-test.js +0 -313
- package/test/seed-features-integration-test.js +0 -418
- package/test/seed-migration-template-test.js +0 -220
- package/test/singleDollarPlaceholderTest.js +0 -238
- package/test/tablePrefixTest.js +0 -100
- package/test/transformerTest.js +0 -287
- package/test/v0.3.34-bug-fixes-test.js +0 -428
- package/test/validation-test.js +0 -302
- 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
|
|
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
|
package/Cache/QueryCache.js
CHANGED
|
@@ -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
|
-
|
|
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);
|
|
175
|
+
}, 60000);
|
|
176
|
+
if (typeof timer.unref === 'function') timer.unref();
|
|
177
|
+
this._cleanupTimer = timer;
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
|
|
175
|
-
|
|
181
|
+
export default QueryCache;
|
package/Cache/RedisQueryCache.js
CHANGED
|
@@ -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
|
-
|
|
156
|
+
export default RedisQueryCache;
|
package/Entity/entityModel.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// version 0.0.3
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
105
|
+
export default EntityModelBuilder;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
// version : 0.0.9
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
526
|
+
export default EntityTrackerModel;
|
|
@@ -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
|
-
|
|
247
|
-
|
|
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
|
-
|
|
3
|
-
|
|
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();
|