masterrecord 0.3.68 → 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 +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 +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
@@ -1,9 +1,8 @@
1
-
2
-
3
1
  // https://channel9.msdn.com/Blogs/EF/Migrations-Under-the-Hood
4
- // version 0.0.3
2
+ // version 0.0.4
3
+
4
+ import os from 'node:os';
5
5
 
6
- const os = require('os');
7
6
  class MigrationTemplate {
8
7
 
9
8
  constructor(name) {
@@ -14,17 +13,10 @@ class MigrationTemplate {
14
13
  #down = ''
15
14
 
16
15
  /**
17
- * Render the migration file source.
18
- *
19
- * @param {'esm'|'cjs'} [moduleType='cjs'] - Module type of the host project.
20
- * When 'esm' the file is emitted with ESM syntax so it can be loaded in
21
- * a `"type": "module"` project. When 'cjs' (default) it's emitted with
22
- * CJS syntax for backward compatibility with existing projects.
16
+ * Render the migration file source (ESM only).
23
17
  */
24
- get(moduleType = 'cjs'){
25
- if (moduleType === 'esm') {
26
- return `
27
- import masterrecord from 'masterrecord';
18
+ get(){
19
+ return `import masterrecord from 'masterrecord';
28
20
 
29
21
  class ${this.name} extends masterrecord.schema {
30
22
  constructor(context){
@@ -42,30 +34,7 @@ class ${this.name} extends masterrecord.schema {
42
34
  }
43
35
  }
44
36
  export default ${this.name};
45
- `;
46
- }
47
-
48
- return `
49
-
50
- var masterrecord = require('masterrecord');
51
-
52
- class ${this.name} extends masterrecord.schema {
53
- constructor(context){
54
- super(context);
55
- }
56
-
57
- async up(table){
58
- await this.init(table);
59
- ${this.#up}
60
- }
61
-
62
- async down(table){
63
- await this.init(table);
64
- ${this.#down}
65
- }
66
- }
67
- module.exports = ${this.name};
68
- `
37
+ `;
69
38
  }
70
39
 
71
40
  alterColumn(type, name, parent){
@@ -329,5 +298,5 @@ module.exports = ${this.name};
329
298
 
330
299
  }
331
300
 
332
- module.exports = MigrationTemplate;
301
+ export default MigrationTemplate;
333
302
 
@@ -1,12 +1,13 @@
1
- // version 0.0.10
1
+ // version 0.0.11
2
2
  // learn more about seeding info - https://www.pauric.blog/Database-Updates-and-Migrations-with-Entity-Framework/
3
3
 
4
- var fs = require('fs');
5
- var diff = require("deep-object-diff");
6
- var MigrationTemplate = require("./migrationTemplate");
7
- var globSearch = require("glob");
8
- var path = require('path');
9
- var { resolveMigrationsDirectory } = require('./pathUtils');
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { pathToFileURL } from 'node:url';
7
+ import * as diff from 'deep-object-diff';
8
+ import { globSync } from 'glob';
9
+ import MigrationTemplate from './migrationTemplate.js';
10
+ import { resolveMigrationsDirectory } from './pathUtils.js';
10
11
 
11
12
  // https://blog.tekspace.io/code-first-multiple-db-context-migration/
12
13
 
@@ -357,7 +358,7 @@ class Migrations{
357
358
 
358
359
 
359
360
  findContextFile(executedLocation, contextFileName){
360
- var files = globSearch.sync(`**/*${contextFileName}.js`, {
361
+ var files = globSync(`**/*${contextFileName}.js`, {
361
362
  cwd: executedLocation,
362
363
  dot: true,
363
364
  windowsPathsNoEscape: true
@@ -366,8 +367,8 @@ class Migrations{
366
367
  return file;
367
368
  }
368
369
 
369
- findContext(executedLocation, contextFileName){
370
- var files = globSearch.sync(`**/*${contextFileName}.js`, {
370
+ async findContext(executedLocation, contextFileName){
371
+ var files = globSync(`**/*${contextFileName}.js`, {
371
372
  cwd: executedLocation,
372
373
  dot: true,
373
374
  windowsPathsNoEscape: true
@@ -376,7 +377,8 @@ class Migrations{
376
377
  if(!file){
377
378
  return null;
378
379
  }
379
- var context = require(file);
380
+ const mod = await import(pathToFileURL(file).href);
381
+ const context = (mod && mod.default !== undefined) ? mod.default : mod;
380
382
  return {
381
383
  context : context,
382
384
  fileLocation : file
@@ -511,7 +513,7 @@ class Migrations{
511
513
  return false;
512
514
  }
513
515
 
514
- template(name, oldSchema, newSchema, newSeedData = {}, seedConfig = {}, currentEnv = null, moduleType = 'cjs'){
516
+ template(name, oldSchema, newSchema, newSeedData = {}, seedConfig = {}, currentEnv = null){
515
517
  var MT = new MigrationTemplate(name);
516
518
  // Determine current environment if not provided
517
519
  if (!currentEnv) {
@@ -578,9 +580,9 @@ class Migrations{
578
580
 
579
581
  });
580
582
 
581
- return MT.get(moduleType);
583
+ return MT.get();
582
584
  }
583
585
 
584
586
  }
585
587
 
586
- module.exports = Migrations;
588
+ export default Migrations;
@@ -3,7 +3,7 @@
3
3
  * Handles path resolution to prevent duplicate db/migrations in paths
4
4
  */
5
5
 
6
- const path = require('path');
6
+ import path from 'node:path';
7
7
 
8
8
  /**
9
9
  * Resolve migrations directory, avoiding duplicate db/migrations paths
@@ -70,7 +70,4 @@ function isInMigrationsDirectory(filePath) {
70
70
  return normalized.includes('/db/migrations') || normalized.includes('\\db\\migrations');
71
71
  }
72
72
 
73
- module.exports = {
74
- resolveMigrationsDirectory,
75
- isInMigrationsDirectory
76
- };
73
+ export { resolveMigrationsDirectory, isInMigrationsDirectory };
@@ -1,53 +1,37 @@
1
1
  /**
2
2
  * Tests for pathUtils.js - Path resolution for migrations
3
- *
4
- * Run with: node pathUtils.test.js
5
3
  */
6
4
 
7
- const path = require('path');
8
- const { resolveMigrationsDirectory, isInMigrationsDirectory } = require('./pathUtils');
9
-
10
- function assert(condition, message) {
11
- if (!condition) {
12
- throw new Error(`❌ Test failed: ${message}`);
13
- }
14
- console.log(`✓ ${message}`);
15
- }
16
-
17
- console.log('\n🧪 Running pathUtils tests...\n');
18
-
19
- // Test 1: Context NOT in migrations folder
20
- const test1 = resolveMigrationsDirectory('/app/models/Context.js');
21
- const expected1 = path.join('/app/models', 'db', 'migrations');
22
- assert(test1 === expected1,
23
- `Context NOT in migrations: Expected '${expected1}', got '${test1}'`);
24
-
25
- // Test 2: Context already IN migrations folder
26
- const test2 = resolveMigrationsDirectory('/app/models/db/migrations/Context.js');
27
- const expected2 = '/app/models/db/migrations';
28
- assert(test2 === expected2,
29
- `Context IN migrations: Expected '${expected2}', got '${test2}'`);
30
-
31
- // Test 3: Context in nested migrations folder
32
- const test3 = resolveMigrationsDirectory('/components/qa/app/models/db/migrations/qaContext.js');
33
- const expected3 = '/components/qa/app/models/db/migrations';
34
- assert(test3 === expected3,
35
- `Context in nested migrations: Expected '${expected3}', got '${test3}'`);
36
-
37
- // Test 4: isInMigrationsDirectory - true case
38
- const test4 = isInMigrationsDirectory('/app/models/db/migrations/Context.js');
39
- assert(test4 === true,
40
- 'isInMigrationsDirectory should return true for path with db/migrations');
41
-
42
- // Test 5: isInMigrationsDirectory - false case
43
- const test5 = isInMigrationsDirectory('/app/models/Context.js');
44
- assert(test5 === false,
45
- 'isInMigrationsDirectory should return false for path without db/migrations');
46
-
47
- // Test 6: Windows path with backslashes
48
- const test6Windows = '/app\\models\\db\\migrations\\Context.js'.replace(/\\/g, path.sep);
49
- const result6 = isInMigrationsDirectory(test6Windows);
50
- assert(result6 === true,
51
- 'isInMigrationsDirectory should handle Windows paths with backslashes');
52
-
53
- console.log('\n✅ All tests passed!\n');
5
+ import path from 'node:path';
6
+ import { test } from 'node:test';
7
+ import assert from 'node:assert/strict';
8
+ import { resolveMigrationsDirectory, isInMigrationsDirectory } from './pathUtils.js';
9
+
10
+ test('resolveMigrationsDirectory: context NOT in migrations folder', () => {
11
+ const result = resolveMigrationsDirectory('/app/models/Context.js');
12
+ const expected = path.join('/app/models', 'db', 'migrations');
13
+ assert.equal(result, expected);
14
+ });
15
+
16
+ test('resolveMigrationsDirectory: context already in migrations folder', () => {
17
+ const result = resolveMigrationsDirectory('/app/models/db/migrations/Context.js');
18
+ assert.equal(result, '/app/models/db/migrations');
19
+ });
20
+
21
+ test('resolveMigrationsDirectory: context in nested migrations folder', () => {
22
+ const result = resolveMigrationsDirectory('/components/qa/app/models/db/migrations/qaContext.js');
23
+ assert.equal(result, '/components/qa/app/models/db/migrations');
24
+ });
25
+
26
+ test('isInMigrationsDirectory: true for path with db/migrations', () => {
27
+ assert.equal(isInMigrationsDirectory('/app/models/db/migrations/Context.js'), true);
28
+ });
29
+
30
+ test('isInMigrationsDirectory: false for path without db/migrations', () => {
31
+ assert.equal(isInMigrationsDirectory('/app/models/Context.js'), false);
32
+ });
33
+
34
+ test('isInMigrationsDirectory: handles Windows paths', () => {
35
+ const winPath = '/app\\models\\db\\migrations\\Context.js'.replace(/\\/g, path.sep);
36
+ assert.equal(isInMigrationsDirectory(winPath), true);
37
+ });