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.
- 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 +44 -113
- 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 +8 -39
- package/Migrations/migrations.js +16 -14
- 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 +30 -8
- 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 +161 -16
- package/package.json +34 -5
- package/postgresEngine.js +74 -26
- 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/count-chained-where.test.js +136 -0
- package/test/esm-imports.test.js +110 -0
- package/test/fixtures/count-chained-where/config/environments/env.countchained.json +1 -0
- package/test/fixtures/count-chained-where/db/countctx.sqlite +0 -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/query-builder-parity/config/environments/env.parity.json +1 -0
- package/test/fixtures/query-builder-parity/db/parityctx.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/query-builder-parity.test.js +260 -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
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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 =
|
|
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
|
-
//
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
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
|
-
|
|
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
|
-
|
|
179
|
+
export default DeleteManager;
|