drizzle-seed 0.1.2 → 0.1.3-e14a5a2

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 (122) hide show
  1. package/index.cjs +718 -307
  2. package/index.cjs.map +1 -1
  3. package/index.d.cts +52 -10
  4. package/index.d.mts +52 -10
  5. package/index.d.ts +52 -10
  6. package/index.mjs +718 -309
  7. package/index.mjs.map +1 -1
  8. package/package.json +3 -3
  9. package/services/GeneratorsWrappers.d.cts +232 -47
  10. package/services/GeneratorsWrappers.d.mts +232 -47
  11. package/services/GeneratorsWrappers.d.ts +232 -47
  12. package/services/SeedService.d.cts +80 -34
  13. package/services/SeedService.d.mts +80 -34
  14. package/services/SeedService.d.ts +80 -34
  15. package/services/utils.d.cts +2 -0
  16. package/services/utils.d.mts +2 -0
  17. package/services/utils.d.ts +2 -0
  18. package/types/seedService.d.cts +4 -0
  19. package/types/seedService.d.mts +4 -0
  20. package/types/seedService.d.ts +4 -0
  21. package/types/tables.d.cts +7 -0
  22. package/types/tables.d.mts +7 -0
  23. package/types/tables.d.ts +7 -0
  24. package/tests/benchmarks/generatorsBenchmark.d.cts +0 -1
  25. package/tests/benchmarks/generatorsBenchmark.d.mts +0 -1
  26. package/tests/benchmarks/generatorsBenchmark.d.ts +0 -1
  27. package/tests/mysql/allDataTypesTest/drizzle.config.d.cts +0 -2
  28. package/tests/mysql/allDataTypesTest/drizzle.config.d.mts +0 -2
  29. package/tests/mysql/allDataTypesTest/drizzle.config.d.ts +0 -2
  30. package/tests/mysql/allDataTypesTest/mysqlSchema.d.cts +0 -466
  31. package/tests/mysql/allDataTypesTest/mysqlSchema.d.mts +0 -466
  32. package/tests/mysql/allDataTypesTest/mysqlSchema.d.ts +0 -466
  33. package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.cts +0 -1
  34. package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.mts +0 -1
  35. package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.ts +0 -1
  36. package/tests/mysql/drizzle.config.d.cts +0 -2
  37. package/tests/mysql/drizzle.config.d.mts +0 -2
  38. package/tests/mysql/drizzle.config.d.ts +0 -2
  39. package/tests/mysql/generatorsTest/drizzle.config.d.cts +0 -2
  40. package/tests/mysql/generatorsTest/drizzle.config.d.mts +0 -2
  41. package/tests/mysql/generatorsTest/drizzle.config.d.ts +0 -2
  42. package/tests/mysql/generatorsTest/generators.test.d.cts +0 -1
  43. package/tests/mysql/generatorsTest/generators.test.d.mts +0 -1
  44. package/tests/mysql/generatorsTest/generators.test.d.ts +0 -1
  45. package/tests/mysql/generatorsTest/mysqlSchema.d.cts +0 -48
  46. package/tests/mysql/generatorsTest/mysqlSchema.d.mts +0 -48
  47. package/tests/mysql/generatorsTest/mysqlSchema.d.ts +0 -48
  48. package/tests/mysql/mysql.test.d.cts +0 -1
  49. package/tests/mysql/mysql.test.d.mts +0 -1
  50. package/tests/mysql/mysql.test.d.ts +0 -1
  51. package/tests/mysql/mysqlSchema.d.cts +0 -1130
  52. package/tests/mysql/mysqlSchema.d.mts +0 -1130
  53. package/tests/mysql/mysqlSchema.d.ts +0 -1130
  54. package/tests/northwind/mysqlSchema.d.cts +0 -1130
  55. package/tests/northwind/mysqlSchema.d.mts +0 -1130
  56. package/tests/northwind/mysqlSchema.d.ts +0 -1130
  57. package/tests/northwind/mysqlTest.d.cts +0 -1
  58. package/tests/northwind/mysqlTest.d.mts +0 -1
  59. package/tests/northwind/mysqlTest.d.ts +0 -1
  60. package/tests/northwind/pgSchema.d.cts +0 -1131
  61. package/tests/northwind/pgSchema.d.mts +0 -1131
  62. package/tests/northwind/pgSchema.d.ts +0 -1131
  63. package/tests/northwind/pgTest.d.cts +0 -1
  64. package/tests/northwind/pgTest.d.mts +0 -1
  65. package/tests/northwind/pgTest.d.ts +0 -1
  66. package/tests/northwind/sqliteSchema.d.cts +0 -1130
  67. package/tests/northwind/sqliteSchema.d.mts +0 -1130
  68. package/tests/northwind/sqliteSchema.d.ts +0 -1130
  69. package/tests/northwind/sqliteTest.d.cts +0 -1
  70. package/tests/northwind/sqliteTest.d.mts +0 -1
  71. package/tests/northwind/sqliteTest.d.ts +0 -1
  72. package/tests/pg/allDataTypesTest/drizzle.config.d.cts +0 -2
  73. package/tests/pg/allDataTypesTest/drizzle.config.d.mts +0 -2
  74. package/tests/pg/allDataTypesTest/drizzle.config.d.ts +0 -2
  75. package/tests/pg/allDataTypesTest/pgSchema.d.cts +0 -509
  76. package/tests/pg/allDataTypesTest/pgSchema.d.mts +0 -509
  77. package/tests/pg/allDataTypesTest/pgSchema.d.ts +0 -509
  78. package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.cts +0 -1
  79. package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.mts +0 -1
  80. package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.ts +0 -1
  81. package/tests/pg/drizzle.config.d.cts +0 -2
  82. package/tests/pg/drizzle.config.d.mts +0 -2
  83. package/tests/pg/drizzle.config.d.ts +0 -2
  84. package/tests/pg/generatorsTest/drizzle.config.d.cts +0 -2
  85. package/tests/pg/generatorsTest/drizzle.config.d.mts +0 -2
  86. package/tests/pg/generatorsTest/drizzle.config.d.ts +0 -2
  87. package/tests/pg/generatorsTest/generators.test.d.cts +0 -1
  88. package/tests/pg/generatorsTest/generators.test.d.mts +0 -1
  89. package/tests/pg/generatorsTest/generators.test.d.ts +0 -1
  90. package/tests/pg/generatorsTest/pgSchema.d.cts +0 -1136
  91. package/tests/pg/generatorsTest/pgSchema.d.mts +0 -1136
  92. package/tests/pg/generatorsTest/pgSchema.d.ts +0 -1136
  93. package/tests/pg/pg.test.d.cts +0 -1
  94. package/tests/pg/pg.test.d.mts +0 -1
  95. package/tests/pg/pg.test.d.ts +0 -1
  96. package/tests/pg/pgSchema.d.cts +0 -1189
  97. package/tests/pg/pgSchema.d.mts +0 -1189
  98. package/tests/pg/pgSchema.d.ts +0 -1189
  99. package/tests/sqlite/allDataTypesTest/sqliteSchema.d.cts +0 -194
  100. package/tests/sqlite/allDataTypesTest/sqliteSchema.d.mts +0 -194
  101. package/tests/sqlite/allDataTypesTest/sqliteSchema.d.ts +0 -194
  102. package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.cts +0 -1
  103. package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.mts +0 -1
  104. package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.ts +0 -1
  105. package/tests/sqlite/sqlite.test.d.cts +0 -1
  106. package/tests/sqlite/sqlite.test.d.mts +0 -1
  107. package/tests/sqlite/sqlite.test.d.ts +0 -1
  108. package/tests/sqlite/sqliteSchema.d.cts +0 -1130
  109. package/tests/sqlite/sqliteSchema.d.mts +0 -1130
  110. package/tests/sqlite/sqliteSchema.d.ts +0 -1130
  111. package/tests/vitest.config.d.cts +0 -2
  112. package/tests/vitest.config.d.mts +0 -2
  113. package/tests/vitest.config.d.ts +0 -2
  114. package/type-tests/mysql.d.cts +0 -1
  115. package/type-tests/mysql.d.mts +0 -1
  116. package/type-tests/mysql.d.ts +0 -1
  117. package/type-tests/pg.d.cts +0 -1
  118. package/type-tests/pg.d.mts +0 -1
  119. package/type-tests/pg.d.ts +0 -1
  120. package/type-tests/sqlite.d.cts +0 -1
  121. package/type-tests/sqlite.d.mts +0 -1
  122. package/type-tests/sqlite.d.ts +0 -1
package/index.cjs CHANGED
@@ -131192,6 +131192,19 @@ const fillTemplate = ({ template, placeholdersCount, values, defaultValue = ' '
131192
131192
  }
131193
131193
  return resultStr;
131194
131194
  };
131195
+ // is variable is object-like.
131196
+ // Example:
131197
+ // isObject({f: 4}) === true;
131198
+ // isObject([1,2,3]) === false;
131199
+ // isObject(new Set()) === false;
131200
+ const isObject = (value) => {
131201
+ if (value !== null && value !== undefined && value.constructor === Object)
131202
+ return true;
131203
+ return false;
131204
+ };
131205
+ const equalSets = (set1, set2) => {
131206
+ return set1.size === set2.size && [...set1].every((si) => set2.has(si));
131207
+ };
131195
131208
 
131196
131209
  class AbstractGenerator {
131197
131210
  params;
@@ -131201,9 +131214,56 @@ class AbstractGenerator {
131201
131214
  uniqueVersionOfGen;
131202
131215
  dataType;
131203
131216
  timeSpent;
131217
+ arraySize;
131218
+ baseColumnDataType;
131204
131219
  constructor(params) {
131205
131220
  this.params = params;
131206
131221
  }
131222
+ init() {
131223
+ if (this.params.arraySize !== undefined) {
131224
+ this.arraySize = this.params.arraySize;
131225
+ }
131226
+ if (this.params.isUnique !== undefined) {
131227
+ if (this.params.isUnique === false && this.isUnique === true) {
131228
+ throw new Error('specifying non unique generator to unique column.');
131229
+ }
131230
+ this.isUnique = this.params.isUnique;
131231
+ }
131232
+ }
131233
+ getEntityKind() {
131234
+ const constructor = this.constructor;
131235
+ return constructor[drizzleOrm.entityKind];
131236
+ }
131237
+ replaceIfUnique({ count, seed }) {
131238
+ if (this.uniqueVersionOfGen !== undefined
131239
+ && this.isUnique === true) {
131240
+ const uniqueGen = new this.uniqueVersionOfGen({
131241
+ ...this.params,
131242
+ });
131243
+ uniqueGen.init({
131244
+ count,
131245
+ seed,
131246
+ });
131247
+ uniqueGen.isUnique = this.isUnique;
131248
+ uniqueGen.dataType = this.dataType;
131249
+ return uniqueGen;
131250
+ }
131251
+ return;
131252
+ }
131253
+ replaceIfArray({ count, seed }) {
131254
+ if (!(this.getEntityKind() === 'GenerateArray') && this.arraySize !== undefined) {
131255
+ const uniqueGen = this.replaceIfUnique({ count, seed });
131256
+ const baseColumnGen = uniqueGen === undefined ? this : uniqueGen;
131257
+ baseColumnGen.dataType = this.baseColumnDataType;
131258
+ const arrayGen = new GenerateArray({
131259
+ baseColumnGen,
131260
+ size: this.arraySize,
131261
+ });
131262
+ arrayGen.init({ count, seed });
131263
+ return arrayGen;
131264
+ }
131265
+ return;
131266
+ }
131207
131267
  }
131208
131268
  function createGenerator(generatorConstructor) {
131209
131269
  return (...args) => {
@@ -131214,6 +131274,22 @@ function createGenerator(generatorConstructor) {
131214
131274
  };
131215
131275
  }
131216
131276
  // Generators Classes -----------------------------------------------------------------------------------------------------------------------
131277
+ class GenerateArray extends AbstractGenerator {
131278
+ static [drizzleOrm.entityKind] = 'GenerateArray';
131279
+ arraySize = 10;
131280
+ init({ count, seed }) {
131281
+ super.init({ count, seed });
131282
+ this.arraySize = this.params.size === undefined ? this.arraySize : this.params.size;
131283
+ this.params.baseColumnGen.init({ count: count * this.arraySize, seed });
131284
+ }
131285
+ generate() {
131286
+ const array = [];
131287
+ for (let i = 0; i < this.arraySize; i++) {
131288
+ array.push(this.params.baseColumnGen.generate({ i }));
131289
+ }
131290
+ return array;
131291
+ }
131292
+ }
131217
131293
  class GenerateWeightedCount extends AbstractGenerator {
131218
131294
  static [drizzleOrm.entityKind] = 'GenerateWeightedCount';
131219
131295
  state;
@@ -131249,7 +131325,6 @@ class HollowGenerator extends AbstractGenerator {
131249
131325
  }
131250
131326
  class GenerateDefault extends AbstractGenerator {
131251
131327
  static [drizzleOrm.entityKind] = 'GenerateDefault';
131252
- init() { }
131253
131328
  generate() {
131254
131329
  return this.params.defaultValue;
131255
131330
  }
@@ -131266,7 +131341,7 @@ class GenerateValuesFromArray extends AbstractGenerator {
131266
131341
  if (values.length === 0) {
131267
131342
  throw new Error('Values length equals zero.');
131268
131343
  }
131269
- if (typeof values[0] === 'object'
131344
+ if (isObject(values[0])
131270
131345
  && !values.every((val) => val.values.length !== 0)) {
131271
131346
  throw new Error('One of weighted values length equals zero.');
131272
131347
  }
@@ -131278,14 +131353,14 @@ class GenerateValuesFromArray extends AbstractGenerator {
131278
131353
  throw new Error('maxRepeatedValuesCount should be greater than zero.');
131279
131354
  }
131280
131355
  let allValuesCount = values.length;
131281
- if (typeof values[0] === 'object') {
131356
+ if (isObject(values[0])) {
131282
131357
  allValuesCount = values.reduce((acc, currVal) => acc + currVal.values.length, 0);
131283
131358
  }
131284
131359
  if (notNull === true
131285
131360
  && maxRepeatedValuesCount !== undefined
131286
- && ((typeof values[0] !== 'object' && typeof maxRepeatedValuesCount === 'number'
131361
+ && ((!isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
131287
131362
  && maxRepeatedValuesCount * values.length < count)
131288
- || (typeof values[0] === 'object' && typeof maxRepeatedValuesCount === 'number'
131363
+ || (isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
131289
131364
  && maxRepeatedValuesCount * allValuesCount < count))) {
131290
131365
  throw new Error("Can't fill notNull column with null values.");
131291
131366
  }
@@ -131296,25 +131371,20 @@ class GenerateValuesFromArray extends AbstractGenerator {
131296
131371
  : obj.count.every((count) => count === 1))))) {
131297
131372
  throw new Error("Can't be greater than 1 if column is unique.");
131298
131373
  }
131299
- if (isUnique === true && notNull === true && ((typeof values[0] !== 'object' && values.length < count)
131300
- || (typeof values[0] === 'object' && allValuesCount < count))) {
131374
+ if (isUnique === true && notNull === true && ((!isObject(values[0]) && values.length < count)
131375
+ || (isObject(values[0]) && allValuesCount < count))) {
131301
131376
  // console.log(maxRepeatedValuesCount, values.length, allValuesCount, count)
131302
131377
  throw new Error('There are no enough values to fill unique column.');
131303
131378
  }
131304
131379
  }
131305
131380
  init({ count, seed }) {
131306
- if (this.params.isUnique !== undefined) {
131307
- if (this.params.isUnique === false && this.isUnique === true) {
131308
- throw new Error('Specifying non unique generator to unique column.');
131309
- }
131310
- this.isUnique = this.params.isUnique;
131311
- }
131381
+ super.init({ count, seed });
131312
131382
  this.checks({ count });
131313
131383
  let { maxRepeatedValuesCount } = this;
131314
131384
  const { params, isUnique, notNull, weightedCountSeed } = this;
131315
131385
  const values = params.values;
131316
131386
  let valuesWeightedIndices;
131317
- if (typeof values[0] === 'object') {
131387
+ if (isObject(values[0])) {
131318
131388
  valuesWeightedIndices = getWeightedIndices(values.map((val) => val.weight));
131319
131389
  if (isUnique === true && notNull === true) {
131320
131390
  let idx, valueIdx, rng = prand.xoroshiro128plus(seed);
@@ -131353,13 +131423,13 @@ class GenerateValuesFromArray extends AbstractGenerator {
131353
131423
  let genIndicesObj;
131354
131424
  let genIndicesObjList;
131355
131425
  if (maxRepeatedValuesCount !== undefined) {
131356
- if (typeof values[0] !== 'object') {
131426
+ if (!isObject(values[0])) {
131357
131427
  genIndicesObj = new GenerateUniqueInt({ minValue: 0, maxValue: values.length - 1 });
131358
131428
  genIndicesObj.genMaxRepeatedValuesCount = genMaxRepeatedValuesCount;
131359
131429
  genIndicesObj.skipCheck = true;
131360
131430
  genIndicesObj.init({ count, seed });
131361
131431
  }
131362
- else if (typeof values[0] === 'object') {
131432
+ else if (isObject(values[0])) {
131363
131433
  genIndicesObjList = [];
131364
131434
  for (const obj of values) {
131365
131435
  const genIndicesObj = new GenerateUniqueInt({ minValue: 0, maxValue: obj.values.length - 1 });
@@ -131454,15 +131524,8 @@ class GenerateNumber extends AbstractGenerator {
131454
131524
  static [drizzleOrm.entityKind] = 'GenerateNumber';
131455
131525
  state;
131456
131526
  uniqueVersionOfGen = GenerateUniqueNumber;
131457
- init({ seed }) {
131458
- if (this.params === undefined)
131459
- this.params = {};
131460
- if (this.params.isUnique !== undefined) {
131461
- if (this.params.isUnique === false && this.isUnique === true) {
131462
- throw new Error('specifying non unique generator to unique column.');
131463
- }
131464
- this.isUnique = this.params.isUnique;
131465
- }
131527
+ init({ count, seed }) {
131528
+ super.init({ count, seed });
131466
131529
  let { minValue, maxValue, precision } = this.params;
131467
131530
  if (precision === undefined) {
131468
131531
  precision = 100;
@@ -131496,8 +131559,6 @@ class GenerateUniqueNumber extends AbstractGenerator {
131496
131559
  state;
131497
131560
  isUnique = true;
131498
131561
  init({ count, seed }) {
131499
- if (this.params === undefined)
131500
- this.params = {};
131501
131562
  let { minValue, maxValue, precision } = this.params;
131502
131563
  if (precision === undefined) {
131503
131564
  precision = 100;
@@ -131530,13 +131591,8 @@ class GenerateInt extends AbstractGenerator {
131530
131591
  static [drizzleOrm.entityKind] = 'GenerateInt';
131531
131592
  state;
131532
131593
  uniqueVersionOfGen = GenerateUniqueInt;
131533
- init({ seed }) {
131534
- if (this.params.isUnique !== undefined) {
131535
- if (this.params.isUnique === false && this.isUnique === true) {
131536
- throw new Error('specifying non unique generator to unique column.');
131537
- }
131538
- this.isUnique = this.params.isUnique;
131539
- }
131594
+ init({ count, seed }) {
131595
+ super.init({ count, seed });
131540
131596
  let { minValue, maxValue } = this.params;
131541
131597
  if (maxValue === undefined) {
131542
131598
  maxValue = 1000;
@@ -131699,7 +131755,8 @@ class GenerateUniqueInt extends AbstractGenerator {
131699
131755
  class GenerateBoolean extends AbstractGenerator {
131700
131756
  static [drizzleOrm.entityKind] = 'GenerateBoolean';
131701
131757
  state;
131702
- init({ seed }) {
131758
+ init({ count, seed }) {
131759
+ super.init({ count, seed });
131703
131760
  const rng = prand.xoroshiro128plus(seed);
131704
131761
  this.state = { rng };
131705
131762
  }
@@ -131715,7 +131772,8 @@ class GenerateBoolean extends AbstractGenerator {
131715
131772
  class GenerateDate extends AbstractGenerator {
131716
131773
  static [drizzleOrm.entityKind] = 'GenerateDate';
131717
131774
  state;
131718
- init({ seed }) {
131775
+ init({ count, seed }) {
131776
+ super.init({ count, seed });
131719
131777
  const rng = prand.xoroshiro128plus(seed);
131720
131778
  let { minDate, maxDate } = this.params;
131721
131779
  const anchorDate = new Date('2024-05-08');
@@ -131756,7 +131814,8 @@ class GenerateDate extends AbstractGenerator {
131756
131814
  class GenerateTime extends AbstractGenerator {
131757
131815
  static [drizzleOrm.entityKind] = 'GenerateTime';
131758
131816
  state;
131759
- init({ seed }) {
131817
+ init({ count, seed }) {
131818
+ super.init({ count, seed });
131760
131819
  const rng = prand.xoroshiro128plus(seed);
131761
131820
  this.state = { rng };
131762
131821
  }
@@ -131776,7 +131835,8 @@ class GenerateTime extends AbstractGenerator {
131776
131835
  class GenerateTimestamp extends AbstractGenerator {
131777
131836
  static [drizzleOrm.entityKind] = 'GenerateTimestamp';
131778
131837
  state;
131779
- init({ seed }) {
131838
+ init({ count, seed }) {
131839
+ super.init({ count, seed });
131780
131840
  const rng = prand.xoroshiro128plus(seed);
131781
131841
  this.state = { rng };
131782
131842
  }
@@ -131802,7 +131862,8 @@ class GenerateTimestamp extends AbstractGenerator {
131802
131862
  class GenerateDatetime extends AbstractGenerator {
131803
131863
  static [drizzleOrm.entityKind] = 'GenerateDatetime';
131804
131864
  state;
131805
- init({ seed }) {
131865
+ init({ count, seed }) {
131866
+ super.init({ count, seed });
131806
131867
  const rng = prand.xoroshiro128plus(seed);
131807
131868
  this.state = { rng };
131808
131869
  }
@@ -131828,7 +131889,8 @@ class GenerateDatetime extends AbstractGenerator {
131828
131889
  class GenerateYear extends AbstractGenerator {
131829
131890
  static [drizzleOrm.entityKind] = 'GenerateYear';
131830
131891
  state;
131831
- init({ seed }) {
131892
+ init({ count, seed }) {
131893
+ super.init({ count, seed });
131832
131894
  const rng = prand.xoroshiro128plus(seed);
131833
131895
  this.state = { rng };
131834
131896
  }
@@ -131851,12 +131913,14 @@ class GenerateJson extends AbstractGenerator {
131851
131913
  static [drizzleOrm.entityKind] = 'GenerateJson';
131852
131914
  state;
131853
131915
  init({ count, seed }) {
131916
+ super.init({ count, seed });
131854
131917
  const emailGeneratorObj = new GenerateEmail({});
131855
131918
  emailGeneratorObj.init({ count, seed });
131856
131919
  const nameGeneratorObj = new GenerateFirstName({});
131857
- nameGeneratorObj.init({ seed });
131920
+ nameGeneratorObj.init({ count, seed });
131858
131921
  const booleanGeneratorObj = new GenerateBoolean({});
131859
131922
  booleanGeneratorObj.init({
131923
+ count,
131860
131924
  seed,
131861
131925
  });
131862
131926
  const salaryGeneratorObj = new GenerateInt({ minValue: 200, maxValue: 4000 });
@@ -131867,7 +131931,7 @@ class GenerateJson extends AbstractGenerator {
131867
131931
  });
131868
131932
  const dateGeneratorObj = new GenerateDate({});
131869
131933
  dateGeneratorObj.dataType = 'string';
131870
- dateGeneratorObj.init({ seed });
131934
+ dateGeneratorObj.init({ count, seed });
131871
131935
  const visitedCountriesNumberGeneratorObj = new GenerateInt({ minValue: 0, maxValue: 4 });
131872
131936
  visitedCountriesNumberGeneratorObj.init({ count, seed, ...visitedCountriesNumberGeneratorObj.params });
131873
131937
  this.state = {
@@ -131944,13 +132008,8 @@ class GenerateInterval extends AbstractGenerator {
131944
132008
  static [drizzleOrm.entityKind] = 'GenerateInterval';
131945
132009
  state;
131946
132010
  uniqueVersionOfGen = GenerateUniqueInterval;
131947
- init({ seed }) {
131948
- if (this.params.isUnique !== undefined) {
131949
- if (this.params.isUnique === false && this.isUnique === true) {
131950
- throw new Error('specifying non unique generator to unique column.');
131951
- }
131952
- this.isUnique = this.params.isUnique;
131953
- }
132011
+ init({ count, seed }) {
132012
+ super.init({ count, seed });
131954
132013
  const rng = prand.xoroshiro128plus(seed);
131955
132014
  this.state = { rng };
131956
132015
  }
@@ -131978,6 +132037,7 @@ class GenerateInterval extends AbstractGenerator {
131978
132037
  class GenerateUniqueInterval extends AbstractGenerator {
131979
132038
  static [drizzleOrm.entityKind] = 'GenerateUniqueInterval';
131980
132039
  state;
132040
+ isUnique = true;
131981
132041
  init({ count, seed }) {
131982
132042
  const maxUniqueIntervalsNumber = 6 * 13 * 29 * 25 * 61 * 61;
131983
132043
  if (count > maxUniqueIntervalsNumber) {
@@ -132018,13 +132078,8 @@ class GenerateString extends AbstractGenerator {
132018
132078
  static [drizzleOrm.entityKind] = 'GenerateString';
132019
132079
  state;
132020
132080
  uniqueVersionOfGen = GenerateUniqueString;
132021
- init({ seed }) {
132022
- if (this.params.isUnique !== undefined) {
132023
- if (this.params.isUnique === false && this.isUnique === true) {
132024
- throw new Error('specifying non unique generator to unique column.');
132025
- }
132026
- this.isUnique = this.params.isUnique;
132027
- }
132081
+ init({ count, seed }) {
132082
+ super.init({ count, seed });
132028
132083
  const rng = prand.xoroshiro128plus(seed);
132029
132084
  this.state = { rng };
132030
132085
  }
@@ -132072,18 +132127,44 @@ class GenerateUniqueString extends AbstractGenerator {
132072
132127
  return currStr.slice(0, 4) + uniqueStr + currStr.slice(4);
132073
132128
  }
132074
132129
  }
132130
+ class GenerateUUID extends AbstractGenerator {
132131
+ static [drizzleOrm.entityKind] = 'GenerateUUID';
132132
+ isUnique = true;
132133
+ state;
132134
+ init({ count, seed }) {
132135
+ super.init({ count, seed });
132136
+ const rng = prand.xoroshiro128plus(seed);
132137
+ this.state = { rng };
132138
+ }
132139
+ generate() {
132140
+ if (this.state === undefined) {
132141
+ throw new Error('state is not defined.');
132142
+ }
132143
+ // TODO generate uuid using string generator
132144
+ const stringChars = '1234567890abcdef';
132145
+ let idx, currStr;
132146
+ const strLength = 36;
132147
+ // uuid v4
132148
+ const uuidTemplate = '########-####-4###-####-############';
132149
+ currStr = '';
132150
+ for (let i = 0; i < strLength; i++) {
132151
+ [idx, this.state.rng] = prand.uniformIntDistribution(0, stringChars.length - 1, this.state.rng);
132152
+ if (uuidTemplate[i] === '#') {
132153
+ currStr += stringChars[idx];
132154
+ continue;
132155
+ }
132156
+ currStr += uuidTemplate[i];
132157
+ }
132158
+ return currStr;
132159
+ }
132160
+ }
132075
132161
  class GenerateFirstName extends AbstractGenerator {
132076
132162
  static [drizzleOrm.entityKind] = 'GenerateFirstName';
132077
132163
  timeSpent = 0;
132078
132164
  state;
132079
132165
  uniqueVersionOfGen = GenerateUniqueFirstName;
132080
- init({ seed }) {
132081
- if (this.params.isUnique !== undefined) {
132082
- if (this.params.isUnique === false && this.isUnique === true) {
132083
- throw new Error('specifying non unique generator to unique column.');
132084
- }
132085
- this.isUnique = this.params.isUnique;
132086
- }
132166
+ init({ count, seed }) {
132167
+ super.init({ count, seed });
132087
132168
  const rng = prand.xoroshiro128plus(seed);
132088
132169
  this.state = { rng };
132089
132170
  }
@@ -132125,13 +132206,8 @@ class GenerateLastName extends AbstractGenerator {
132125
132206
  static [drizzleOrm.entityKind] = 'GenerateLastName';
132126
132207
  state;
132127
132208
  uniqueVersionOfGen = GenerateUniqueLastName;
132128
- init({ seed }) {
132129
- if (this.params.isUnique !== undefined) {
132130
- if (this.params.isUnique === false && this.isUnique === true) {
132131
- throw new Error('specifying non unique generator to unique column.');
132132
- }
132133
- this.isUnique = this.params.isUnique;
132134
- }
132209
+ init({ count, seed }) {
132210
+ super.init({ count, seed });
132135
132211
  const rng = prand.xoroshiro128plus(seed);
132136
132212
  this.state = { rng };
132137
132213
  }
@@ -132169,13 +132245,8 @@ class GenerateFullName extends AbstractGenerator {
132169
132245
  static [drizzleOrm.entityKind] = 'GenerateFullName';
132170
132246
  state;
132171
132247
  uniqueVersionOfGen = GenerateUniqueFullName;
132172
- init({ seed }) {
132173
- if (this.params.isUnique !== undefined) {
132174
- if (this.params.isUnique === false && this.isUnique === true) {
132175
- throw new Error('specifying non unique generator to unique column.');
132176
- }
132177
- this.isUnique = this.params.isUnique;
132178
- }
132248
+ init({ count, seed }) {
132249
+ super.init({ count, seed });
132179
132250
  const rng = prand.xoroshiro128plus(seed);
132180
132251
  this.state = { rng };
132181
132252
  }
@@ -132235,6 +132306,7 @@ class GenerateEmail extends AbstractGenerator {
132235
132306
  timeSpent = 0;
132236
132307
  isUnique = true;
132237
132308
  init({ count, seed }) {
132309
+ super.init({ count, seed });
132238
132310
  const domainsArray = emailDomains;
132239
132311
  const adjectivesArray = adjectives;
132240
132312
  const namesArray = firstNames;
@@ -132268,6 +132340,7 @@ class GeneratePhoneNumber extends AbstractGenerator {
132268
132340
  state;
132269
132341
  isUnique = true;
132270
132342
  init({ count, seed }) {
132343
+ super.init({ count, seed });
132271
132344
  let { generatedDigitsNumbers } = this.params;
132272
132345
  const { prefixes, template } = this.params;
132273
132346
  const rng = prand.xoroshiro128plus(seed);
@@ -132384,13 +132457,8 @@ class GenerateCountry extends AbstractGenerator {
132384
132457
  static [drizzleOrm.entityKind] = 'GenerateCountry';
132385
132458
  state;
132386
132459
  uniqueVersionOfGen = GenerateUniqueCountry;
132387
- init({ seed }) {
132388
- if (this.params.isUnique !== undefined) {
132389
- if (this.params.isUnique === false && this.isUnique === true) {
132390
- throw new Error('specifying non unique generator to unique column.');
132391
- }
132392
- this.isUnique = this.params.isUnique;
132393
- }
132460
+ init({ count, seed }) {
132461
+ super.init({ count, seed });
132394
132462
  const rng = prand.xoroshiro128plus(seed);
132395
132463
  this.state = { rng };
132396
132464
  }
@@ -132428,7 +132496,8 @@ class GenerateUniqueCountry extends AbstractGenerator {
132428
132496
  class GenerateJobTitle extends AbstractGenerator {
132429
132497
  static [drizzleOrm.entityKind] = 'GenerateJobTitle';
132430
132498
  state;
132431
- init({ seed }) {
132499
+ init({ count, seed }) {
132500
+ super.init({ count, seed });
132432
132501
  const rng = prand.xoroshiro128plus(seed);
132433
132502
  this.state = { rng };
132434
132503
  }
@@ -132445,13 +132514,8 @@ class GenerateStreetAdddress extends AbstractGenerator {
132445
132514
  static [drizzleOrm.entityKind] = 'GenerateStreetAdddress';
132446
132515
  state;
132447
132516
  uniqueVersionOfGen = GenerateUniqueStreetAdddress;
132448
- init({ seed }) {
132449
- if (this.params.isUnique !== undefined) {
132450
- if (this.params.isUnique === false && this.isUnique === true) {
132451
- throw new Error('specifying non unique generator to unique column.');
132452
- }
132453
- this.isUnique = this.params.isUnique;
132454
- }
132517
+ init({ count, seed }) {
132518
+ super.init({ count, seed });
132455
132519
  const rng = prand.xoroshiro128plus(seed);
132456
132520
  const possStreetNames = [firstNames, lastNames];
132457
132521
  this.state = { rng, possStreetNames };
@@ -132472,6 +132536,7 @@ class GenerateStreetAdddress extends AbstractGenerator {
132472
132536
  class GenerateUniqueStreetAdddress extends AbstractGenerator {
132473
132537
  static [drizzleOrm.entityKind] = 'GenerateUniqueStreetAdddress';
132474
132538
  state;
132539
+ isUnique = true;
132475
132540
  init({ count, seed }) {
132476
132541
  const streetNumberStrs = Array.from({ length: 999 }, (_, i) => String(i + 1));
132477
132542
  const maxUniqueStreetnamesNumber = streetNumberStrs.length * firstNames.length * streetSuffix.length
@@ -132530,13 +132595,8 @@ class GenerateCity extends AbstractGenerator {
132530
132595
  static [drizzleOrm.entityKind] = 'GenerateCity';
132531
132596
  state;
132532
132597
  uniqueVersionOfGen = GenerateUniqueCity;
132533
- init({ seed }) {
132534
- if (this.params.isUnique !== undefined) {
132535
- if (this.params.isUnique === false && this.isUnique === true) {
132536
- throw new Error('specifying non unique generator to unique column.');
132537
- }
132538
- this.isUnique = this.params.isUnique;
132539
- }
132598
+ init({ count, seed }) {
132599
+ super.init({ count, seed });
132540
132600
  const rng = prand.xoroshiro128plus(seed);
132541
132601
  this.state = { rng };
132542
132602
  }
@@ -132574,13 +132634,8 @@ class GeneratePostcode extends AbstractGenerator {
132574
132634
  static [drizzleOrm.entityKind] = 'GeneratePostcode';
132575
132635
  state;
132576
132636
  uniqueVersionOfGen = GenerateUniquePostcode;
132577
- init({ seed }) {
132578
- if (this.params.isUnique !== undefined) {
132579
- if (this.params.isUnique === false && this.isUnique === true) {
132580
- throw new Error('specifying non unique generator to unique column.');
132581
- }
132582
- this.isUnique = this.params.isUnique;
132583
- }
132637
+ init({ count, seed }) {
132638
+ super.init({ count, seed });
132584
132639
  const rng = prand.xoroshiro128plus(seed);
132585
132640
  const templates = ['#####', '#####-####'];
132586
132641
  this.state = { rng, templates };
@@ -132607,6 +132662,7 @@ class GeneratePostcode extends AbstractGenerator {
132607
132662
  class GenerateUniquePostcode extends AbstractGenerator {
132608
132663
  static [drizzleOrm.entityKind] = 'GenerateUniquePostcode';
132609
132664
  state;
132665
+ isUnique = true;
132610
132666
  init({ count, seed }) {
132611
132667
  const maxUniquePostcodeNumber = Math.pow(10, 5) + Math.pow(10, 9);
132612
132668
  if (count > maxUniquePostcodeNumber) {
@@ -132660,7 +132716,8 @@ class GenerateUniquePostcode extends AbstractGenerator {
132660
132716
  class GenerateState extends AbstractGenerator {
132661
132717
  static [drizzleOrm.entityKind] = 'GenerateState';
132662
132718
  state;
132663
- init({ seed }) {
132719
+ init({ count, seed }) {
132720
+ super.init({ count, seed });
132664
132721
  const rng = prand.xoroshiro128plus(seed);
132665
132722
  this.state = { rng };
132666
132723
  }
@@ -132677,13 +132734,8 @@ class GenerateCompanyName extends AbstractGenerator {
132677
132734
  static [drizzleOrm.entityKind] = 'GenerateCompanyName';
132678
132735
  state;
132679
132736
  uniqueVersionOfGen = GenerateUniqueCompanyName;
132680
- init({ seed }) {
132681
- if (this.params.isUnique !== undefined) {
132682
- if (this.params.isUnique === false && this.isUnique === true) {
132683
- throw new Error('specifying non unique generator to unique column.');
132684
- }
132685
- this.isUnique = this.params.isUnique;
132686
- }
132737
+ init({ count, seed }) {
132738
+ super.init({ count, seed });
132687
132739
  const rng = prand.xoroshiro128plus(seed);
132688
132740
  const templates = [
132689
132741
  { template: '#', placeholdersCount: 1 },
@@ -132724,13 +132776,8 @@ class GenerateCompanyName extends AbstractGenerator {
132724
132776
  class GenerateUniqueCompanyName extends AbstractGenerator {
132725
132777
  static [drizzleOrm.entityKind] = 'GenerateUniqueCompanyName';
132726
132778
  state;
132779
+ isUnique = true;
132727
132780
  init({ count, seed }) {
132728
- if (this.params.isUnique !== undefined) {
132729
- if (this.params.isUnique === false && this.isUnique === true) {
132730
- throw new Error('specifying non unique generator to unique column.');
132731
- }
132732
- this.isUnique = this.params.isUnique;
132733
- }
132734
132781
  const maxUniqueCompanyNameNumber = lastNames.length * companyNameSuffixes.length + Math.pow(lastNames.length, 2)
132735
132782
  + Math.pow(lastNames.length, 2) + Math.pow(lastNames.length, 3);
132736
132783
  if (count > maxUniqueCompanyNameNumber) {
@@ -132803,7 +132850,8 @@ class GenerateUniqueCompanyName extends AbstractGenerator {
132803
132850
  class GenerateLoremIpsum extends AbstractGenerator {
132804
132851
  static [drizzleOrm.entityKind] = 'GenerateLoremIpsum';
132805
132852
  state;
132806
- init({ seed }) {
132853
+ init({ count, seed }) {
132854
+ super.init({ count, seed });
132807
132855
  const rng = prand.xoroshiro128plus(seed);
132808
132856
  if (this.params.sentencesCount === undefined)
132809
132857
  this.params.sentencesCount = 1;
@@ -132872,25 +132920,20 @@ class GeneratePoint extends AbstractGenerator {
132872
132920
  static [drizzleOrm.entityKind] = 'GeneratePoint';
132873
132921
  state;
132874
132922
  uniqueVersionOfGen = GenerateUniquePoint;
132875
- init({ seed }) {
132876
- if (this.params.isUnique !== undefined) {
132877
- if (this.params.isUnique === false && this.isUnique === true) {
132878
- throw new Error('specifying non unique generator to unique column.');
132879
- }
132880
- this.isUnique = this.params.isUnique;
132881
- }
132923
+ init({ count, seed }) {
132924
+ super.init({ count, seed });
132882
132925
  const xCoordinateGen = new GenerateNumber({
132883
132926
  minValue: this.params.minXValue,
132884
132927
  maxValue: this.params.maxXValue,
132885
132928
  precision: 10,
132886
132929
  });
132887
- xCoordinateGen.init({ seed });
132930
+ xCoordinateGen.init({ count, seed });
132888
132931
  const yCoordinateGen = new GenerateNumber({
132889
132932
  minValue: this.params.minYValue,
132890
132933
  maxValue: this.params.maxYValue,
132891
132934
  precision: 10,
132892
132935
  });
132893
- yCoordinateGen.init({ seed });
132936
+ yCoordinateGen.init({ count, seed });
132894
132937
  this.state = { xCoordinateGen, yCoordinateGen };
132895
132938
  }
132896
132939
  generate() {
@@ -132914,6 +132957,7 @@ class GeneratePoint extends AbstractGenerator {
132914
132957
  class GenerateUniquePoint extends AbstractGenerator {
132915
132958
  static [drizzleOrm.entityKind] = 'GenerateUniquePoint';
132916
132959
  state;
132960
+ isUnique = true;
132917
132961
  init({ count, seed }) {
132918
132962
  const xCoordinateGen = new GenerateUniqueNumber({
132919
132963
  minValue: this.params.minXValue,
@@ -132951,31 +132995,26 @@ class GenerateLine extends AbstractGenerator {
132951
132995
  static [drizzleOrm.entityKind] = 'GenerateLine';
132952
132996
  state;
132953
132997
  uniqueVersionOfGen = GenerateUniqueLine;
132954
- init({ seed }) {
132955
- if (this.params.isUnique !== undefined) {
132956
- if (this.params.isUnique === false && this.isUnique === true) {
132957
- throw new Error('specifying non unique generator to unique column.');
132958
- }
132959
- this.isUnique = this.params.isUnique;
132960
- }
132998
+ init({ count, seed }) {
132999
+ super.init({ count, seed });
132961
133000
  const aCoefficientGen = new GenerateNumber({
132962
133001
  minValue: this.params.minAValue,
132963
133002
  maxValue: this.params.maxAValue,
132964
133003
  precision: 10,
132965
133004
  });
132966
- aCoefficientGen.init({ seed });
133005
+ aCoefficientGen.init({ count, seed });
132967
133006
  const bCoefficientGen = new GenerateNumber({
132968
133007
  minValue: this.params.minBValue,
132969
133008
  maxValue: this.params.maxBValue,
132970
133009
  precision: 10,
132971
133010
  });
132972
- bCoefficientGen.init({ seed });
133011
+ bCoefficientGen.init({ count, seed });
132973
133012
  const cCoefficientGen = new GenerateNumber({
132974
133013
  minValue: this.params.minCValue,
132975
133014
  maxValue: this.params.maxCValue,
132976
133015
  precision: 10,
132977
133016
  });
132978
- cCoefficientGen.init({ seed });
133017
+ cCoefficientGen.init({ count, seed });
132979
133018
  this.state = { aCoefficientGen, bCoefficientGen, cCoefficientGen };
132980
133019
  }
132981
133020
  generate() {
@@ -133004,6 +133043,7 @@ class GenerateLine extends AbstractGenerator {
133004
133043
  class GenerateUniqueLine extends AbstractGenerator {
133005
133044
  static [drizzleOrm.entityKind] = 'GenerateUniqueLine';
133006
133045
  state;
133046
+ isUnique = true;
133007
133047
  init({ count, seed }) {
133008
133048
  const aCoefficientGen = new GenerateUniqueNumber({
133009
133049
  minValue: this.params.minAValue,
@@ -133052,6 +133092,7 @@ const generatorsFuncs = {
133052
133092
  /**
133053
133093
  * generates same given value each time the generator is called.
133054
133094
  * @param defaultValue - value you want to generate
133095
+ * @param arraySize - number of elements in each one-dimensional array.
133055
133096
  *
133056
133097
  * @example
133057
133098
  * ```ts
@@ -133069,6 +133110,7 @@ const generatorsFuncs = {
133069
133110
  * generates values from given array
133070
133111
  * @param values - array of values you want to generate. can be array of weighted values.
133071
133112
  * @param isUnique - property that controls if generated values gonna be unique or not.
133113
+ * @param arraySize - number of elements in each one-dimensional array.
133072
133114
  *
133073
133115
  * @example
133074
133116
  * ```ts
@@ -133128,6 +133170,7 @@ const generatorsFuncs = {
133128
133170
  * precision equals 10 means that values will be accurate to one tenth (1.2, 34.6);
133129
133171
  * precision equals 100 means that values will be accurate to one hundredth (1.23, 34.67).
133130
133172
  * @param isUnique - property that controls if generated values gonna be unique or not.
133173
+ * @param arraySize - number of elements in each one-dimensional array.
133131
133174
  *
133132
133175
  * @example
133133
133176
  * ```ts
@@ -133148,6 +133191,7 @@ const generatorsFuncs = {
133148
133191
  * @param minValue - lower border of range.
133149
133192
  * @param maxValue - upper border of range.
133150
133193
  * @param isUnique - property that controls if generated values gonna be unique or not.
133194
+ * @param arraySize - number of elements in each one-dimensional array.
133151
133195
  *
133152
133196
  * @example
133153
133197
  * ```ts
@@ -133165,6 +133209,7 @@ const generatorsFuncs = {
133165
133209
  // uniqueInt: createGenerator(GenerateUniqueInt),
133166
133210
  /**
133167
133211
  * generates boolean values(true or false)
133212
+ * @param arraySize - number of elements in each one-dimensional array.
133168
133213
  *
133169
133214
  * @example
133170
133215
  * ```ts
@@ -133183,6 +133228,7 @@ const generatorsFuncs = {
133183
133228
  * generates date within given range.
133184
133229
  * @param minDate - lower border of range.
133185
133230
  * @param maxDate - upper border of range.
133231
+ * @param arraySize - number of elements in each one-dimensional array.
133186
133232
  *
133187
133233
  * @example
133188
133234
  * ```ts
@@ -133199,6 +133245,8 @@ const generatorsFuncs = {
133199
133245
  date: createGenerator(GenerateDate),
133200
133246
  /**
133201
133247
  * generates time in 24 hours style.
133248
+ * @param arraySize - number of elements in each one-dimensional array.
133249
+ *
133202
133250
  * @example
133203
133251
  * ```ts
133204
133252
  * await seed(db, schema, { count: 1000 }).refine((funcs) => ({
@@ -133214,6 +133262,8 @@ const generatorsFuncs = {
133214
133262
  time: createGenerator(GenerateTime),
133215
133263
  /**
133216
133264
  * generates timestamps.
133265
+ * @param arraySize - number of elements in each one-dimensional array.
133266
+ *
133217
133267
  * @example
133218
133268
  * ```ts
133219
133269
  * await seed(db, schema, { count: 1000 }).refine((funcs) => ({
@@ -133229,6 +133279,8 @@ const generatorsFuncs = {
133229
133279
  timestamp: createGenerator(GenerateTimestamp),
133230
133280
  /**
133231
133281
  * generates datetime objects.
133282
+ * @param arraySize - number of elements in each one-dimensional array.
133283
+ *
133232
133284
  * @example
133233
133285
  * ```ts
133234
133286
  * await seed(db, schema, { count: 1000 }).refine((funcs) => ({
@@ -133244,6 +133296,8 @@ const generatorsFuncs = {
133244
133296
  datetime: createGenerator(GenerateDatetime),
133245
133297
  /**
133246
133298
  * generates years.
133299
+ * @param arraySize - number of elements in each one-dimensional array.
133300
+ *
133247
133301
  * @example
133248
133302
  * ```ts
133249
133303
  * await seed(db, schema, { count: 1000 }).refine((funcs) => ({
@@ -133259,6 +133313,7 @@ const generatorsFuncs = {
133259
133313
  year: createGenerator(GenerateYear),
133260
133314
  /**
133261
133315
  * generates json objects with fixed structure.
133316
+ * @param arraySize - number of elements in each one-dimensional array.
133262
133317
  *
133263
133318
  * json structure can equal this:
133264
133319
  * ```
@@ -133302,6 +133357,7 @@ const generatorsFuncs = {
133302
133357
  * interval example: "1 years 12 days 5 minutes"
133303
133358
  *
133304
133359
  * @param isUnique - property that controls if generated values gonna be unique or not.
133360
+ * @param arraySize - number of elements in each one-dimensional array.
133305
133361
  * @example
133306
133362
  * ```ts
133307
133363
  * await seed(db, schema, { count: 1000 }).refine((funcs) => ({
@@ -133318,6 +133374,7 @@ const generatorsFuncs = {
133318
133374
  /**
133319
133375
  * generates random strings.
133320
133376
  * @param isUnique - property that controls if generated values gonna be unique or not.
133377
+ * @param arraySize - number of elements in each one-dimensional array.
133321
133378
  *
133322
133379
  * @example
133323
133380
  * ```ts
@@ -133332,9 +133389,29 @@ const generatorsFuncs = {
133332
133389
  */
133333
133390
  string: createGenerator(GenerateString),
133334
133391
  // uniqueString: createGenerator(GenerateUniqueString),
133392
+ /**
133393
+ * generates v4 UUID strings if arraySize is not specified, or v4 UUID 1D arrays if it is.
133394
+ *
133395
+ * @param arraySize - number of elements in each one-dimensional array.
133396
+ *
133397
+ * @example
133398
+ * ```ts
133399
+ * await seed(db, schema, { count: 1000 }).refine((funcs) => ({
133400
+ * users: {
133401
+ * columns: {
133402
+ * uuid: funcs.uuid({
133403
+ * arraySize: 4
133404
+ * })
133405
+ * },
133406
+ * },
133407
+ * }));
133408
+ * ```
133409
+ */
133410
+ uuid: createGenerator(GenerateUUID),
133335
133411
  /**
133336
133412
  * generates person's first names.
133337
133413
  * @param isUnique - property that controls if generated values gonna be unique or not.
133414
+ * @param arraySize - number of elements in each one-dimensional array.
133338
133415
  *
133339
133416
  * @example
133340
133417
  * ```ts
@@ -133352,6 +133429,7 @@ const generatorsFuncs = {
133352
133429
  /**
133353
133430
  * generates person's last names.
133354
133431
  * @param isUnique - property that controls if generated values gonna be unique or not.
133432
+ * @param arraySize - number of elements in each one-dimensional array.
133355
133433
  *
133356
133434
  * @example
133357
133435
  * ```ts
@@ -133369,6 +133447,7 @@ const generatorsFuncs = {
133369
133447
  /**
133370
133448
  * generates person's full names.
133371
133449
  * @param isUnique - property that controls if generated values gonna be unique or not.
133450
+ * @param arraySize - number of elements in each one-dimensional array.
133372
133451
  *
133373
133452
  * @example
133374
133453
  * ```ts
@@ -133385,6 +133464,7 @@ const generatorsFuncs = {
133385
133464
  // uniqueFullName: createGenerator(GenerateUniqueFullName),
133386
133465
  /**
133387
133466
  * generates unique emails.
133467
+ * @param arraySize - number of elements in each one-dimensional array.
133388
133468
  *
133389
133469
  * @example
133390
133470
  * ```ts
@@ -133400,6 +133480,7 @@ const generatorsFuncs = {
133400
133480
  email: createGenerator(GenerateEmail),
133401
133481
  /**
133402
133482
  * generates unique phone numbers.
133483
+ * @param arraySize - number of elements in each one-dimensional array.
133403
133484
  *
133404
133485
  * @param template - phone number template, where all '#' symbols will be substituted with generated digits.
133405
133486
  * @param prefixes - array of any string you want to be your phone number prefixes.(not compatible with template property)
@@ -133439,6 +133520,7 @@ const generatorsFuncs = {
133439
133520
  /**
133440
133521
  * generates country's names.
133441
133522
  * @param isUnique - property that controls if generated values gonna be unique or not.
133523
+ * @param arraySize - number of elements in each one-dimensional array.
133442
133524
  *
133443
133525
  * @example
133444
133526
  * ```ts
@@ -133456,6 +133538,7 @@ const generatorsFuncs = {
133456
133538
  /**
133457
133539
  * generates city's names.
133458
133540
  * @param isUnique - property that controls if generated values gonna be unique or not.
133541
+ * @param arraySize - number of elements in each one-dimensional array.
133459
133542
  *
133460
133543
  * @example
133461
133544
  * ```ts
@@ -133473,6 +133556,7 @@ const generatorsFuncs = {
133473
133556
  /**
133474
133557
  * generates street address.
133475
133558
  * @param isUnique - property that controls if generated values gonna be unique or not.
133559
+ * @param arraySize - number of elements in each one-dimensional array.
133476
133560
  *
133477
133561
  * @example
133478
133562
  * ```ts
@@ -133489,6 +133573,7 @@ const generatorsFuncs = {
133489
133573
  // uniqueStreetAddress: createGenerator(GenerateUniqueStreetAdddress),
133490
133574
  /**
133491
133575
  * generates job titles.
133576
+ * @param arraySize - number of elements in each one-dimensional array.
133492
133577
  *
133493
133578
  * @example
133494
133579
  * ```ts
@@ -133506,6 +133591,7 @@ const generatorsFuncs = {
133506
133591
  * generates postal codes.
133507
133592
  *
133508
133593
  * @param isUnique - property that controls if generated values gonna be unique or not.
133594
+ * @param arraySize - number of elements in each one-dimensional array.
133509
133595
  *
133510
133596
  * @example
133511
133597
  * ```ts
@@ -133522,6 +133608,7 @@ const generatorsFuncs = {
133522
133608
  // uniquePostcoe: createGenerator(GenerateUniquePostcode),
133523
133609
  /**
133524
133610
  * generates states of America.
133611
+ * @param arraySize - number of elements in each one-dimensional array.
133525
133612
  *
133526
133613
  * @example
133527
133614
  * ```ts
@@ -133539,6 +133626,7 @@ const generatorsFuncs = {
133539
133626
  * generates company's names.
133540
133627
  *
133541
133628
  * @param isUnique - property that controls if generated values gonna be unique or not.
133629
+ * @param arraySize - number of elements in each one-dimensional array.
133542
133630
  *
133543
133631
  * @example
133544
133632
  * ```ts
@@ -133557,6 +133645,7 @@ const generatorsFuncs = {
133557
133645
  * generates 'lorem ipsum' text sentences.
133558
133646
  *
133559
133647
  * @param sentencesCount - number of sentences you want to generate as one generated value(string).
133648
+ * @param arraySize - number of elements in each one-dimensional array.
133560
133649
  *
133561
133650
  * @example
133562
133651
  * ```ts
@@ -133578,6 +133667,7 @@ const generatorsFuncs = {
133578
133667
  * @param maxXValue - upper bound of range for x coordinate.
133579
133668
  * @param minYValue - lower bound of range for y coordinate.
133580
133669
  * @param maxYValue - upper bound of range for y coordinate.
133670
+ * @param arraySize - number of elements in each one-dimensional array.
133581
133671
  *
133582
133672
  * @example
133583
133673
  * ```ts
@@ -133610,6 +133700,7 @@ const generatorsFuncs = {
133610
133700
  * @param maxBValue - upper bound of range for y parameter.
133611
133701
  * @param minCValue - lower bound of range for y parameter.
133612
133702
  * @param maxCValue - upper bound of range for y parameter.
133703
+ * @param arraySize - number of elements in each one-dimensional array.
133613
133704
  *
133614
133705
  * @example
133615
133706
  * ```ts
@@ -133665,15 +133756,20 @@ class SeedService {
133665
133756
  mysqlMaxParametersNumber = 100000;
133666
133757
  // SQLITE_MAX_VARIABLE_NUMBER, which by default equals to 999 for SQLite versions prior to 3.32.0 (2020-05-22) or 32766 for SQLite versions after 3.32.0.
133667
133758
  sqliteMaxParametersNumber = 32766;
133668
- generatePossibleGenerators = (connectionType, tables, relations, refinements, options) => {
133759
+ generatePossibleGenerators = (connectionType, tables, relations, tableRelations, refinements, options) => {
133669
133760
  let columnPossibleGenerator;
133670
133761
  let tablePossibleGenerators;
133671
133762
  const customSeed = options?.seed === undefined ? 0 : options.seed;
133672
133763
  // sorting table in order which they will be filled up (tables with foreign keys case)
133673
133764
  // relations = relations.filter(rel => rel.type === "one");
133674
- const tablesInOutRelations = this.getTablesInOutRelations(relations);
133765
+ const { tablesInOutRelations } = this.getInfoFromRelations(relations);
133675
133766
  const orderedTablesNames = this.getOrderedTablesList(tablesInOutRelations);
133676
133767
  tables = tables.sort((table1, table2) => {
133768
+ const rel = relations.find((rel) => rel.table === table1.name && rel.refTable === table2.name);
133769
+ if (rel?.isCyclic === true) {
133770
+ const reverseRel = relations.find((rel) => rel.table === table2.name && rel.refTable === table1.name);
133771
+ return this.cyclicTablesCompare(table1, table2, rel, reverseRel);
133772
+ }
133677
133773
  const table1Order = orderedTablesNames.indexOf(table1.name), table2Order = orderedTablesNames.indexOf(table2.name);
133678
133774
  return table1Order - table2Order;
133679
133775
  });
@@ -133745,37 +133841,54 @@ class SeedService {
133745
133841
  columnName: col.name,
133746
133842
  isUnique: col.isUnique,
133747
133843
  notNull: col.notNull,
133844
+ primary: col.primary,
133748
133845
  generatedIdentityType: col.generatedIdentityType,
133749
133846
  generator: undefined,
133847
+ isCyclic: false,
133848
+ wasDefinedBefore: false,
133849
+ wasRefined: false,
133750
133850
  };
133751
133851
  if (refinements !== undefined
133752
133852
  && refinements[table.name] !== undefined
133753
133853
  && refinements[table.name].columns !== undefined
133754
133854
  && refinements[table.name].columns[col.name] !== undefined) {
133755
133855
  const genObj = refinements[table.name].columns[col.name];
133756
- // for now only GenerateValuesFromArray support notNull property
133856
+ // TODO: for now only GenerateValuesFromArray support notNull property
133757
133857
  genObj.notNull = col.notNull;
133858
+ if (col.dataType === 'array') {
133859
+ if (col.baseColumn?.dataType === 'array' && col.baseColumn?.columnType === 'array') {
133860
+ throw new Error("for now you can't specify generators for columns of dimensition greater than 1.");
133861
+ }
133862
+ genObj.baseColumnDataType = col.baseColumn?.dataType;
133863
+ }
133758
133864
  columnPossibleGenerator.generator = genObj;
133865
+ columnPossibleGenerator.wasRefined = true;
133759
133866
  }
133760
133867
  else if (Object.hasOwn(foreignKeyColumns, col.name)) {
133761
133868
  // TODO: I might need to assign repeatedValuesCount to column there instead of doing so in generateTablesValues
133869
+ const cyclicRelation = tableRelations[table.name].find((rel) => rel.isCyclic === true
133870
+ && rel.columns.includes(col.name));
133871
+ if (cyclicRelation !== undefined) {
133872
+ columnPossibleGenerator.isCyclic = true;
133873
+ }
133874
+ const predicate = cyclicRelation !== undefined && col.notNull === false;
133875
+ if (predicate === true) {
133876
+ columnPossibleGenerator.generator = new GenerateDefault({ defaultValue: null });
133877
+ columnPossibleGenerator.wasDefinedBefore = true;
133878
+ }
133762
133879
  columnPossibleGenerator.generator = new HollowGenerator({});
133763
- }
133764
- else if (col.hasDefault && col.default !== undefined) {
133765
- columnPossibleGenerator.generator = new GenerateDefault({
133766
- defaultValue: col.default,
133767
- });
133768
133880
  } // TODO: rewrite pickGeneratorFor... using new col properties: isUnique and notNull
133769
133881
  else if (connectionType === 'postgresql') {
133770
- columnPossibleGenerator = this.pickGeneratorForPostgresColumn(columnPossibleGenerator, table, col);
133882
+ columnPossibleGenerator.generator = this.pickGeneratorForPostgresColumn(table, col);
133771
133883
  }
133772
133884
  else if (connectionType === 'mysql') {
133773
- columnPossibleGenerator = this.pickGeneratorForMysqlColumn(columnPossibleGenerator, table, col);
133885
+ columnPossibleGenerator.generator = this.pickGeneratorForMysqlColumn(table, col);
133774
133886
  }
133775
133887
  else if (connectionType === 'sqlite') {
133776
- columnPossibleGenerator = this.pickGeneratorForSqlite(columnPossibleGenerator, table, col);
133888
+ columnPossibleGenerator.generator = this.pickGeneratorForSqlite(table, col);
133777
133889
  }
133778
133890
  if (columnPossibleGenerator.generator === undefined) {
133891
+ console.log(col);
133779
133892
  throw new Error(`column with type ${col.columnType} is not supported for now.`);
133780
133893
  }
133781
133894
  columnPossibleGenerator.generator.isUnique = col.isUnique;
@@ -133785,6 +133898,27 @@ class SeedService {
133785
133898
  }
133786
133899
  return tablesPossibleGenerators;
133787
133900
  };
133901
+ cyclicTablesCompare = (table1, table2, relation, reverseRelation) => {
133902
+ // TODO: revise
133903
+ const hasTable1NotNullColumns = relation.columns.some((colIName) => table1.columns.find((colJ) => colJ.name === colIName)?.notNull === true);
133904
+ if (reverseRelation !== undefined) {
133905
+ const hasTable2NotNullColumns = reverseRelation.columns.some((colIName) => table2.columns.find((colJ) => colJ.name === colIName)?.notNull === true);
133906
+ if (hasTable1NotNullColumns && hasTable2NotNullColumns) {
133907
+ throw new Error(`The '${table1.name}' and '${table2.name}' tables have not null foreign keys. You can't seed cyclic tables with not null foreign key columns.`);
133908
+ }
133909
+ if (hasTable1NotNullColumns)
133910
+ return 1;
133911
+ else if (hasTable2NotNullColumns)
133912
+ return -1;
133913
+ return 0;
133914
+ }
133915
+ if (hasTable1NotNullColumns) {
133916
+ return 1;
133917
+ }
133918
+ return 0;
133919
+ // if (hasTable1NotNullColumns) return 1;
133920
+ // else if (hasTable2NotNullColumns) return -1;
133921
+ };
133788
133922
  getOrderedTablesList = (tablesInOutRelations) => {
133789
133923
  const leafTablesNames = Object.entries(tablesInOutRelations)
133790
133924
  .filter((tableRel) => tableRel[1].out === 0
@@ -133805,7 +133939,8 @@ class SeedService {
133805
133939
  for (const orderedTableName of orderedTablesNames) {
133806
133940
  tablesInOutRelations[parent].requiredTableNames.delete(orderedTableName);
133807
133941
  }
133808
- if (tablesInOutRelations[parent].requiredTableNames.size === 0) {
133942
+ if (tablesInOutRelations[parent].requiredTableNames.size === 0
133943
+ || equalSets(tablesInOutRelations[parent].requiredTableNames, tablesInOutRelations[parent].dependantTableNames)) {
133809
133944
  orderedTablesNames.push(parent);
133810
133945
  }
133811
133946
  else {
@@ -133817,9 +133952,13 @@ class SeedService {
133817
133952
  }
133818
133953
  return orderedTablesNames;
133819
133954
  };
133820
- getTablesInOutRelations = (relations) => {
133955
+ getInfoFromRelations = (relations) => {
133821
133956
  const tablesInOutRelations = {};
133957
+ // const cyclicRelations: { [cyclicTableName: string]: Relation & { isCyclic: boolean } } = {};
133822
133958
  for (const rel of relations) {
133959
+ // if (rel.isCyclic) {
133960
+ // cyclicRelations[rel.table] = rel;
133961
+ // }
133823
133962
  if (tablesInOutRelations[rel.table] === undefined) {
133824
133963
  tablesInOutRelations[rel.table] = {
133825
133964
  out: 0,
@@ -133851,7 +133990,7 @@ class SeedService {
133851
133990
  tablesInOutRelations[rel.refTable].dependantTableNames.add(rel.table);
133852
133991
  }
133853
133992
  }
133854
- return tablesInOutRelations;
133993
+ return { tablesInOutRelations };
133855
133994
  };
133856
133995
  getWeightedWithCount = (weightedCount, count, seed) => {
133857
133996
  const gen = new GenerateWeightedCount({});
@@ -133863,15 +134002,18 @@ class SeedService {
133863
134002
  return weightedWithCount;
133864
134003
  };
133865
134004
  // TODO: revise serial part generators
133866
- pickGeneratorForPostgresColumn = (columnPossibleGenerator, table, col) => {
134005
+ pickGeneratorForPostgresColumn = (table, col) => {
134006
+ let generator;
133867
134007
  // INT ------------------------------------------------------------------------------------------------------------
133868
134008
  if ((col.columnType.includes('serial')
133869
134009
  || col.columnType === 'integer'
133870
134010
  || col.columnType === 'smallint'
133871
134011
  || col.columnType.includes('bigint'))
133872
134012
  && table.primaryKeys.includes(col.name)) {
133873
- columnPossibleGenerator.generator = new GenerateIntPrimaryKey({});
133874
- return columnPossibleGenerator;
134013
+ generator = new GenerateIntPrimaryKey({});
134014
+ generator.isUnique = col.isUnique;
134015
+ generator.dataType = col.dataType;
134016
+ return generator;
133875
134017
  }
133876
134018
  let minValue;
133877
134019
  let maxValue;
@@ -133918,111 +134060,167 @@ class SeedService {
133918
134060
  if (col.columnType.includes('int')
133919
134061
  && !col.columnType.includes('interval')
133920
134062
  && !col.columnType.includes('point')) {
133921
- columnPossibleGenerator.generator = new GenerateInt({
134063
+ generator = new GenerateInt({
133922
134064
  minValue,
133923
134065
  maxValue,
133924
134066
  });
133925
- return columnPossibleGenerator;
134067
+ generator.isUnique = col.isUnique;
134068
+ generator.dataType = col.dataType;
134069
+ return generator;
133926
134070
  }
133927
134071
  if (col.columnType.includes('serial')) {
133928
- const genObj = new GenerateIntPrimaryKey({});
133929
- genObj.maxValue = maxValue;
133930
- columnPossibleGenerator.generator = genObj;
134072
+ generator = new GenerateIntPrimaryKey({});
134073
+ generator.maxValue = maxValue;
134074
+ generator.isUnique = col.isUnique;
134075
+ generator.dataType = col.dataType;
134076
+ return generator;
133931
134077
  }
133932
134078
  // NUMBER(real, double, decimal, numeric)
133933
134079
  if (col.columnType === 'real'
133934
134080
  || col.columnType === 'doubleprecision'
133935
134081
  || col.columnType === 'decimal'
133936
134082
  || col.columnType === 'numeric') {
133937
- columnPossibleGenerator.generator = new GenerateNumber({});
133938
- return columnPossibleGenerator;
134083
+ generator = new GenerateNumber({});
134084
+ generator.isUnique = col.isUnique;
134085
+ generator.dataType = col.dataType;
134086
+ return generator;
133939
134087
  }
133940
134088
  // STRING
133941
134089
  if ((col.columnType === 'text'
133942
134090
  || col.columnType === 'varchar'
133943
134091
  || col.columnType === 'char')
133944
134092
  && table.primaryKeys.includes(col.name)) {
133945
- columnPossibleGenerator.generator = new GenerateUniqueString({});
133946
- return columnPossibleGenerator;
134093
+ generator = new GenerateUniqueString({});
134094
+ generator.isUnique = col.isUnique;
134095
+ generator.dataType = col.dataType;
134096
+ return generator;
133947
134097
  }
133948
134098
  if ((col.columnType === 'text'
133949
134099
  || col.columnType === 'varchar'
133950
134100
  || col.columnType === 'char')
133951
134101
  && col.name.toLowerCase().includes('name')) {
133952
- columnPossibleGenerator.generator = new GenerateFirstName({});
133953
- return columnPossibleGenerator;
134102
+ generator = new GenerateFirstName({});
134103
+ generator.isUnique = col.isUnique;
134104
+ generator.dataType = col.dataType;
134105
+ return generator;
133954
134106
  }
133955
134107
  if ((col.columnType === 'text'
133956
134108
  || col.columnType === 'varchar'
133957
134109
  || col.columnType === 'char')
133958
134110
  && col.name.toLowerCase().includes('email')) {
133959
- columnPossibleGenerator.generator = new GenerateEmail({});
133960
- return columnPossibleGenerator;
134111
+ generator = new GenerateEmail({});
134112
+ generator.isUnique = col.isUnique;
134113
+ generator.dataType = col.dataType;
134114
+ return generator;
133961
134115
  }
133962
134116
  if (col.columnType === 'text'
133963
134117
  || col.columnType === 'varchar'
133964
134118
  || col.columnType === 'char') {
133965
134119
  // console.log(col, table)
133966
- columnPossibleGenerator.generator = new GenerateString({});
133967
- return columnPossibleGenerator;
134120
+ generator = new GenerateString({});
134121
+ generator.isUnique = col.isUnique;
134122
+ generator.dataType = col.dataType;
134123
+ return generator;
134124
+ }
134125
+ // UUID
134126
+ if (col.columnType === 'uuid') {
134127
+ generator = new GenerateUUID({});
134128
+ generator.isUnique = col.isUnique;
134129
+ generator.dataType = col.dataType;
134130
+ return generator;
133968
134131
  }
133969
134132
  // BOOLEAN
133970
134133
  if (col.columnType === 'boolean') {
133971
- columnPossibleGenerator.generator = new GenerateBoolean({});
133972
- return columnPossibleGenerator;
134134
+ generator = new GenerateBoolean({});
134135
+ generator.isUnique = col.isUnique;
134136
+ generator.dataType = col.dataType;
134137
+ return generator;
133973
134138
  }
133974
134139
  // DATE, TIME, TIMESTAMP
133975
134140
  if (col.columnType.includes('date')) {
133976
- columnPossibleGenerator.generator = new GenerateDate({});
133977
- return columnPossibleGenerator;
134141
+ generator = new GenerateDate({});
134142
+ generator.isUnique = col.isUnique;
134143
+ generator.dataType = col.dataType;
134144
+ return generator;
133978
134145
  }
133979
134146
  if (col.columnType === 'time') {
133980
- columnPossibleGenerator.generator = new GenerateTime({});
133981
- return columnPossibleGenerator;
134147
+ generator = new GenerateTime({});
134148
+ generator.isUnique = col.isUnique;
134149
+ generator.dataType = col.dataType;
134150
+ return generator;
133982
134151
  }
133983
134152
  if (col.columnType.includes('timestamp')) {
133984
- columnPossibleGenerator.generator = new GenerateTimestamp({});
133985
- return columnPossibleGenerator;
134153
+ generator = new GenerateTimestamp({});
134154
+ generator.isUnique = col.isUnique;
134155
+ generator.dataType = col.dataType;
134156
+ return generator;
133986
134157
  }
133987
134158
  // JSON, JSONB
133988
134159
  if (col.columnType === 'json' || col.columnType === 'jsonb') {
133989
- columnPossibleGenerator.generator = new GenerateJson({});
133990
- return columnPossibleGenerator;
134160
+ generator = new GenerateJson({});
134161
+ generator.isUnique = col.isUnique;
134162
+ generator.dataType = col.dataType;
134163
+ return generator;
133991
134164
  }
133992
134165
  // if (col.columnType === "jsonb") {
133993
- // columnPossibleGenerator.generator = new GenerateJsonb({});
133994
- // return columnPossibleGenerator;
134166
+ // const generator = new GenerateJsonb({});
134167
+ // return generator;
133995
134168
  // }
133996
134169
  // ENUM
133997
134170
  if (col.enumValues !== undefined) {
133998
- columnPossibleGenerator.generator = new GenerateEnum({
134171
+ generator = new GenerateEnum({
133999
134172
  enumValues: col.enumValues,
134000
134173
  });
134001
- return columnPossibleGenerator;
134174
+ generator.isUnique = col.isUnique;
134175
+ generator.dataType = col.dataType;
134176
+ return generator;
134002
134177
  }
134003
134178
  // INTERVAL
134004
134179
  if (col.columnType === 'interval') {
134005
- columnPossibleGenerator.generator = new GenerateInterval({});
134006
- return columnPossibleGenerator;
134180
+ generator = new GenerateInterval({});
134181
+ generator.isUnique = col.isUnique;
134182
+ generator.dataType = col.dataType;
134183
+ return generator;
134007
134184
  }
134008
134185
  // POINT, LINE
134009
134186
  if (col.columnType.includes('point')) {
134010
- columnPossibleGenerator.generator = new GeneratePoint({});
134011
- return columnPossibleGenerator;
134187
+ generator = new GeneratePoint({});
134188
+ generator.isUnique = col.isUnique;
134189
+ generator.dataType = col.dataType;
134190
+ return generator;
134012
134191
  }
134013
134192
  if (col.columnType.includes('line')) {
134014
- columnPossibleGenerator.generator = new GenerateLine({});
134015
- return columnPossibleGenerator;
134193
+ generator = new GenerateLine({});
134194
+ generator.isUnique = col.isUnique;
134195
+ generator.dataType = col.dataType;
134196
+ return generator;
134197
+ }
134198
+ // ARRAY
134199
+ if (col.columnType.includes('array') && col.baseColumn !== undefined) {
134200
+ const baseColumnGen = this.pickGeneratorForPostgresColumn(table, col.baseColumn);
134201
+ if (baseColumnGen === undefined) {
134202
+ throw new Error(`column with type ${col.baseColumn.columnType} is not supported for now.`);
134203
+ }
134204
+ generator = new GenerateArray({ baseColumnGen, size: col.size });
134205
+ generator.isUnique = col.isUnique;
134206
+ generator.dataType = col.dataType;
134207
+ return generator;
134208
+ }
134209
+ if (col.hasDefault && col.default !== undefined) {
134210
+ generator = new GenerateDefault({
134211
+ defaultValue: col.default,
134212
+ });
134213
+ return generator;
134016
134214
  }
134017
- return columnPossibleGenerator;
134215
+ return generator;
134018
134216
  };
134019
- pickGeneratorForMysqlColumn = (columnPossibleGenerator, table, col) => {
134217
+ pickGeneratorForMysqlColumn = (table, col) => {
134020
134218
  // console.log(col);
134021
134219
  // INT ------------------------------------------------------------------------------------------------------------
134022
134220
  if ((col.columnType.includes('serial') || col.columnType.includes('int'))
134023
134221
  && table.primaryKeys.includes(col.name)) {
134024
- columnPossibleGenerator.generator = new GenerateIntPrimaryKey({});
134025
- return columnPossibleGenerator;
134222
+ const generator = new GenerateIntPrimaryKey({});
134223
+ return generator;
134026
134224
  }
134027
134225
  let minValue;
134028
134226
  let maxValue;
@@ -134059,24 +134257,24 @@ class SeedService {
134059
134257
  }
134060
134258
  }
134061
134259
  if (col.columnType.includes('int')) {
134062
- columnPossibleGenerator.generator = new GenerateInt({
134260
+ const generator = new GenerateInt({
134063
134261
  minValue,
134064
134262
  maxValue,
134065
134263
  });
134066
- return columnPossibleGenerator;
134264
+ return generator;
134067
134265
  }
134068
134266
  if (col.columnType.includes('serial')) {
134069
- const genObj = new GenerateIntPrimaryKey({});
134070
- genObj.maxValue = maxValue;
134071
- columnPossibleGenerator.generator = genObj;
134267
+ const generator = new GenerateIntPrimaryKey({});
134268
+ generator.maxValue = maxValue;
134269
+ return generator;
134072
134270
  }
134073
134271
  // NUMBER(real, double, decimal, float)
134074
134272
  if (col.columnType === 'real'
134075
134273
  || col.columnType === 'double'
134076
134274
  || col.columnType === 'decimal'
134077
134275
  || col.columnType === 'float') {
134078
- columnPossibleGenerator.generator = new GenerateNumber({});
134079
- return columnPossibleGenerator;
134276
+ const generator = new GenerateNumber({});
134277
+ return generator;
134080
134278
  }
134081
134279
  // STRING
134082
134280
  if ((col.columnType === 'text'
@@ -134086,8 +134284,8 @@ class SeedService {
134086
134284
  || col.columnType.includes('binary')
134087
134285
  || col.columnType.includes('varbinary'))
134088
134286
  && table.primaryKeys.includes(col.name)) {
134089
- columnPossibleGenerator.generator = new GenerateUniqueString({});
134090
- return columnPossibleGenerator;
134287
+ const generator = new GenerateUniqueString({});
134288
+ return generator;
134091
134289
  }
134092
134290
  if ((col.columnType === 'text'
134093
134291
  || col.columnType === 'blob'
@@ -134096,8 +134294,8 @@ class SeedService {
134096
134294
  || col.columnType.includes('binary')
134097
134295
  || col.columnType.includes('varbinary'))
134098
134296
  && col.name.toLowerCase().includes('name')) {
134099
- columnPossibleGenerator.generator = new GenerateFirstName({});
134100
- return columnPossibleGenerator;
134297
+ const generator = new GenerateFirstName({});
134298
+ return generator;
134101
134299
  }
134102
134300
  if ((col.columnType === 'text'
134103
134301
  || col.columnType === 'blob'
@@ -134106,8 +134304,8 @@ class SeedService {
134106
134304
  || col.columnType.includes('binary')
134107
134305
  || col.columnType.includes('varbinary'))
134108
134306
  && col.name.toLowerCase().includes('email')) {
134109
- columnPossibleGenerator.generator = new GenerateEmail({});
134110
- return columnPossibleGenerator;
134307
+ const generator = new GenerateEmail({});
134308
+ return generator;
134111
134309
  }
134112
134310
  if (col.columnType === 'text'
134113
134311
  || col.columnType === 'blob'
@@ -134116,109 +134314,140 @@ class SeedService {
134116
134314
  || col.columnType.includes('binary')
134117
134315
  || col.columnType.includes('varbinary')) {
134118
134316
  // console.log(col, table);
134119
- columnPossibleGenerator.generator = new GenerateString({});
134120
- return columnPossibleGenerator;
134317
+ const generator = new GenerateString({});
134318
+ return generator;
134121
134319
  }
134122
134320
  // BOOLEAN
134123
134321
  if (col.columnType === 'boolean') {
134124
- columnPossibleGenerator.generator = new GenerateBoolean({});
134125
- return columnPossibleGenerator;
134322
+ const generator = new GenerateBoolean({});
134323
+ return generator;
134126
134324
  }
134127
134325
  // DATE, TIME, TIMESTAMP, DATETIME, YEAR
134128
134326
  if (col.columnType.includes('datetime')) {
134129
- columnPossibleGenerator.generator = new GenerateDatetime({});
134130
- return columnPossibleGenerator;
134327
+ const generator = new GenerateDatetime({});
134328
+ return generator;
134131
134329
  }
134132
134330
  if (col.columnType.includes('date')) {
134133
- columnPossibleGenerator.generator = new GenerateDate({});
134134
- return columnPossibleGenerator;
134331
+ const generator = new GenerateDate({});
134332
+ return generator;
134135
134333
  }
134136
134334
  if (col.columnType === 'time') {
134137
- columnPossibleGenerator.generator = new GenerateTime({});
134138
- return columnPossibleGenerator;
134335
+ const generator = new GenerateTime({});
134336
+ return generator;
134139
134337
  }
134140
134338
  if (col.columnType.includes('timestamp')) {
134141
- columnPossibleGenerator.generator = new GenerateTimestamp({});
134142
- return columnPossibleGenerator;
134339
+ const generator = new GenerateTimestamp({});
134340
+ return generator;
134143
134341
  }
134144
134342
  if (col.columnType === 'year') {
134145
- columnPossibleGenerator.generator = new GenerateYear({});
134146
- return columnPossibleGenerator;
134343
+ const generator = new GenerateYear({});
134344
+ return generator;
134147
134345
  }
134148
134346
  // JSON
134149
134347
  if (col.columnType === 'json') {
134150
- columnPossibleGenerator.generator = new GenerateJson({});
134151
- return columnPossibleGenerator;
134348
+ const generator = new GenerateJson({});
134349
+ return generator;
134152
134350
  }
134153
134351
  // ENUM
134154
134352
  if (col.enumValues !== undefined) {
134155
- columnPossibleGenerator.generator = new GenerateEnum({
134353
+ const generator = new GenerateEnum({
134156
134354
  enumValues: col.enumValues,
134157
134355
  });
134158
- return columnPossibleGenerator;
134356
+ return generator;
134159
134357
  }
134160
- return columnPossibleGenerator;
134358
+ if (col.hasDefault && col.default !== undefined) {
134359
+ const generator = new GenerateDefault({
134360
+ defaultValue: col.default,
134361
+ });
134362
+ return generator;
134363
+ }
134364
+ return;
134161
134365
  };
134162
- pickGeneratorForSqlite = (columnPossibleGenerator, table, col) => {
134366
+ pickGeneratorForSqlite = (table, col) => {
134163
134367
  // int section ---------------------------------------------------------------------------------------
134164
134368
  if ((col.columnType === 'integer' || col.columnType === 'numeric')
134165
134369
  && table.primaryKeys.includes(col.name)) {
134166
- columnPossibleGenerator.generator = new GenerateIntPrimaryKey({});
134167
- return columnPossibleGenerator;
134370
+ const generator = new GenerateIntPrimaryKey({});
134371
+ return generator;
134168
134372
  }
134169
134373
  if (col.columnType === 'integer'
134170
134374
  || col.columnType === 'numeric'
134171
134375
  || col.columnType === 'bigint') {
134172
- columnPossibleGenerator.generator = new GenerateInt({});
134173
- return columnPossibleGenerator;
134376
+ const generator = new GenerateInt({});
134377
+ return generator;
134174
134378
  }
134175
134379
  if (col.columnType === 'boolean') {
134176
- columnPossibleGenerator.generator = new GenerateBoolean({});
134177
- return columnPossibleGenerator;
134380
+ const generator = new GenerateBoolean({});
134381
+ return generator;
134178
134382
  }
134179
134383
  // number section ------------------------------------------------------------------------------------
134180
134384
  if (col.columnType === 'real' || col.columnType === 'numeric') {
134181
- columnPossibleGenerator.generator = new GenerateNumber({});
134182
- return columnPossibleGenerator;
134385
+ const generator = new GenerateNumber({});
134386
+ return generator;
134183
134387
  }
134184
134388
  // string section ------------------------------------------------------------------------------------
134185
134389
  if ((col.columnType === 'text'
134186
134390
  || col.columnType === 'numeric'
134187
134391
  || col.columnType === 'blob')
134188
134392
  && table.primaryKeys.includes(col.name)) {
134189
- columnPossibleGenerator.generator = new GenerateUniqueString({});
134190
- return columnPossibleGenerator;
134393
+ const generator = new GenerateUniqueString({});
134394
+ return generator;
134191
134395
  }
134192
134396
  if ((col.columnType === 'text'
134193
134397
  || col.columnType === 'numeric'
134194
134398
  || col.columnType === 'blob')
134195
134399
  && col.name.toLowerCase().includes('name')) {
134196
- columnPossibleGenerator.generator = new GenerateFirstName({});
134197
- return columnPossibleGenerator;
134400
+ const generator = new GenerateFirstName({});
134401
+ return generator;
134198
134402
  }
134199
134403
  if ((col.columnType === 'text'
134200
134404
  || col.columnType === 'numeric'
134201
134405
  || col.columnType === 'blob')
134202
134406
  && col.name.toLowerCase().includes('email')) {
134203
- columnPossibleGenerator.generator = new GenerateEmail({});
134204
- return columnPossibleGenerator;
134407
+ const generator = new GenerateEmail({});
134408
+ return generator;
134205
134409
  }
134206
134410
  if (col.columnType === 'text'
134207
134411
  || col.columnType === 'numeric'
134208
134412
  || col.columnType === 'blob'
134209
134413
  || col.columnType === 'blobbuffer') {
134210
- columnPossibleGenerator.generator = new GenerateString({});
134211
- return columnPossibleGenerator;
134414
+ const generator = new GenerateString({});
134415
+ return generator;
134212
134416
  }
134213
134417
  if (col.columnType === 'textjson' || col.columnType === 'blobjson') {
134214
- columnPossibleGenerator.generator = new GenerateJson({});
134215
- return columnPossibleGenerator;
134418
+ const generator = new GenerateJson({});
134419
+ return generator;
134216
134420
  }
134217
134421
  if (col.columnType === 'timestamp' || col.columnType === 'timestamp_ms') {
134218
- columnPossibleGenerator.generator = new GenerateTimestamp({});
134219
- return columnPossibleGenerator;
134422
+ const generator = new GenerateTimestamp({});
134423
+ return generator;
134220
134424
  }
134221
- return columnPossibleGenerator;
134425
+ if (col.hasDefault && col.default !== undefined) {
134426
+ const generator = new GenerateDefault({
134427
+ defaultValue: col.default,
134428
+ });
134429
+ return generator;
134430
+ }
134431
+ return;
134432
+ };
134433
+ filterCyclicTables = (tablesGenerators) => {
134434
+ const filteredTablesGenerators = tablesGenerators.filter((tableGen) => tableGen.columnsPossibleGenerators.some((columnGen) => columnGen.isCyclic === true && columnGen.wasDefinedBefore === true));
134435
+ const tablesUniqueNotNullColumn = {};
134436
+ for (const [idx, tableGen] of filteredTablesGenerators.entries()) {
134437
+ const uniqueNotNullColName = filteredTablesGenerators[idx].columnsPossibleGenerators.find((colGen) => colGen.primary === true
134438
+ || (colGen.isUnique === true
134439
+ && colGen.notNull === true))?.columnName;
134440
+ if (uniqueNotNullColName === undefined) {
134441
+ throw new Error(`Table '${tableGen.tableName}' does not have primary or (unique and notNull) column. Can't seed table with cyclic relation.`);
134442
+ }
134443
+ tablesUniqueNotNullColumn[tableGen.tableName] = { uniqueNotNullColName };
134444
+ filteredTablesGenerators[idx].columnsPossibleGenerators = tableGen.columnsPossibleGenerators.filter((colGen) => (colGen.isCyclic === true && colGen.wasDefinedBefore === true) || colGen.columnName === uniqueNotNullColName).map((colGen) => {
134445
+ const newColGen = { ...colGen };
134446
+ newColGen.wasDefinedBefore = false;
134447
+ return newColGen;
134448
+ });
134449
+ }
134450
+ return { filteredTablesGenerators, tablesUniqueNotNullColumn };
134222
134451
  };
134223
134452
  generateTablesValues = async (relations, tablesGenerators, db, schema, options) => {
134224
134453
  // console.time(
@@ -134229,17 +134458,21 @@ class SeedService {
134229
134458
  let columnsGenerators;
134230
134459
  let tableGenerators;
134231
134460
  let tableValues;
134232
- let tablesValues = [];
134461
+ let tablesValues = options?.tablesValues === undefined ? [] : options.tablesValues;
134233
134462
  let pRNGSeed;
134234
134463
  // relations = relations.filter(rel => rel.type === "one");
134235
134464
  let filteredRelations;
134236
- let preserveData, insertDataInDb = true;
134465
+ let preserveData, insertDataInDb = true, updateDataInDb = false;
134237
134466
  if (options?.preserveData !== undefined)
134238
134467
  preserveData = options.preserveData;
134239
134468
  if (options?.insertDataInDb !== undefined)
134240
134469
  insertDataInDb = options.insertDataInDb;
134470
+ if (options?.updateDataInDb !== undefined)
134471
+ updateDataInDb = options.updateDataInDb;
134472
+ if (updateDataInDb === true)
134473
+ insertDataInDb = false;
134241
134474
  // TODO: now I'm generating tablesInOutRelations twice, first time in generatePossibleGenerators and second time here. maybe should generate it once instead.
134242
- const tablesInOutRelations = this.getTablesInOutRelations(relations);
134475
+ const { tablesInOutRelations } = this.getInfoFromRelations(relations);
134243
134476
  for (const table of tablesGenerators) {
134244
134477
  tableCount = table.count === undefined ? options?.count || this.defaultCountForTable : table.count;
134245
134478
  tableGenerators = {};
@@ -134267,10 +134500,11 @@ class SeedService {
134267
134500
  }
134268
134501
  for (let colIdx = 0; colIdx < rel.columns.length; colIdx++) {
134269
134502
  let refColumnValues;
134270
- let hasSelfRelation;
134503
+ let hasSelfRelation = false;
134271
134504
  let repeatedValuesCount, weightedCountSeed;
134272
134505
  let genObj;
134273
- if (rel.table === rel.refTable) {
134506
+ if (rel.table === rel.refTable
134507
+ && tableGenerators[rel.columns[colIdx]]?.wasRefined === false) {
134274
134508
  const refColName = rel.refColumns[colIdx];
134275
134509
  pRNGSeed = generateHashFromString(`${table.tableName}.${refColName}`);
134276
134510
  const refColumnGenerator = {};
@@ -134289,11 +134523,11 @@ class SeedService {
134289
134523
  values: refColumnValues,
134290
134524
  });
134291
134525
  }
134292
- else {
134526
+ else if (tableGenerators[rel.columns[colIdx]]?.wasDefinedBefore === false
134527
+ && tableGenerators[rel.columns[colIdx]]?.wasRefined === false) {
134293
134528
  refColumnValues = tablesValues
134294
134529
  .find((val) => val.tableName === rel.refTable)
134295
134530
  .rows.map((row) => row[rel.refColumns[colIdx]]);
134296
- hasSelfRelation = false;
134297
134531
  if (table.withFromTable[rel.refTable] !== undefined
134298
134532
  && table.withFromTable[rel.refTable].repeatedValuesCount
134299
134533
  !== undefined) {
@@ -134306,7 +134540,9 @@ class SeedService {
134306
134540
  genObj.maxRepeatedValuesCount = repeatedValuesCount;
134307
134541
  }
134308
134542
  // console.log(rel.columns[colIdx], tableGenerators)
134309
- tableGenerators[rel.columns[colIdx]].generator = genObj;
134543
+ if (genObj !== undefined) {
134544
+ tableGenerators[rel.columns[colIdx]].generator = genObj;
134545
+ }
134310
134546
  tableGenerators[rel.columns[colIdx]] = {
134311
134547
  ...tableGenerators[rel.columns[colIdx]],
134312
134548
  hasSelfRelation,
@@ -134319,6 +134555,8 @@ class SeedService {
134319
134555
  && tablesInOutRelations[table.tableName]?.in === 0)
134320
134556
  ? false
134321
134557
  : true;
134558
+ preserveData = preserveData || (options?.preserveCyclicTablesData === true
134559
+ && table.columnsPossibleGenerators.some((colGen) => colGen.isCyclic === true));
134322
134560
  tableValues = await this.generateColumnsValuesByGenerators({
134323
134561
  tableGenerators,
134324
134562
  db,
@@ -134327,6 +134565,10 @@ class SeedService {
134327
134565
  count: tableCount,
134328
134566
  preserveData,
134329
134567
  insertDataInDb,
134568
+ updateDataInDb,
134569
+ uniqueNotNullColName: options?.tablesUniqueNotNullColumn === undefined
134570
+ ? undefined
134571
+ : options?.tablesUniqueNotNullColumn[table.tableName]?.uniqueNotNullColName,
134330
134572
  });
134331
134573
  if (preserveData === true) {
134332
134574
  tablesValues.push({
@@ -134346,10 +134588,13 @@ class SeedService {
134346
134588
  }
134347
134589
  return tablesValues;
134348
134590
  };
134349
- generateColumnsValuesByGenerators = async ({ tableGenerators, db, schema, tableName, count, preserveData = true, insertDataInDb = true, batchSize = 10000, }) => {
134591
+ generateColumnsValuesByGenerators = async ({ tableGenerators, db, schema, tableName, count, preserveData = true, insertDataInDb = true, updateDataInDb = false, uniqueNotNullColName, batchSize = 10000, }) => {
134350
134592
  if (count === undefined) {
134351
134593
  count = this.defaultCountForTable;
134352
134594
  }
134595
+ if (updateDataInDb === true) {
134596
+ batchSize = 1;
134597
+ }
134353
134598
  let columnGenerator;
134354
134599
  const columnsGenerators = {};
134355
134600
  let generatedValues = [];
@@ -134364,17 +134609,12 @@ class SeedService {
134364
134609
  count,
134365
134610
  seed: columnGenerator.pRNGSeed,
134366
134611
  });
134367
- if (columnsGenerators[columnName].uniqueVersionOfGen !== undefined
134368
- && columnsGenerators[columnName].isUnique === true) {
134369
- const uniqueGen = new columnsGenerators[columnName].uniqueVersionOfGen({
134370
- ...columnsGenerators[columnName].params,
134371
- });
134372
- uniqueGen.init({
134373
- count,
134374
- seed: columnGenerator.pRNGSeed,
134375
- });
134376
- uniqueGen.isUnique = columnsGenerators[columnName].isUnique;
134377
- uniqueGen.dataType = columnsGenerators[columnName].dataType;
134612
+ const arrayGen = columnsGenerators[columnName].replaceIfArray({ count, seed: columnGenerator.pRNGSeed });
134613
+ if (arrayGen !== undefined) {
134614
+ columnsGenerators[columnName] = arrayGen;
134615
+ }
134616
+ const uniqueGen = columnsGenerators[columnName].replaceIfUnique({ count, seed: columnGenerator.pRNGSeed });
134617
+ if (uniqueGen !== undefined) {
134378
134618
  columnsGenerators[columnName] = uniqueGen;
134379
134619
  }
134380
134620
  }
@@ -134394,7 +134634,7 @@ class SeedService {
134394
134634
  }
134395
134635
  const maxBatchSize = Math.floor(maxParametersNumber / columnsNumber);
134396
134636
  batchSize = batchSize > maxBatchSize ? maxBatchSize : batchSize;
134397
- if (insertDataInDb === true
134637
+ if ((insertDataInDb === true || updateDataInDb === true)
134398
134638
  && (db === undefined || schema === undefined || tableName === undefined)) {
134399
134639
  throw new Error('db or schema or tableName is undefined.');
134400
134640
  }
@@ -134410,27 +134650,49 @@ class SeedService {
134410
134650
  generatedValue = columnsGenerators[columnName].generate({ i });
134411
134651
  row[columnName] = generatedValue;
134412
134652
  }
134413
- if (insertDataInDb === true
134653
+ if ((insertDataInDb === true || updateDataInDb === true)
134414
134654
  && ((i + 1) % batchSize === 0 || i === count - 1)) {
134415
134655
  if (preserveData === false) {
134416
- await this.insertInDb({
134417
- generatedValues,
134418
- db: db,
134419
- schema: schema,
134420
- tableName: tableName,
134421
- override,
134422
- });
134656
+ if (insertDataInDb === true) {
134657
+ await this.insertInDb({
134658
+ generatedValues,
134659
+ db: db,
134660
+ schema: schema,
134661
+ tableName: tableName,
134662
+ override,
134663
+ });
134664
+ }
134665
+ else if (updateDataInDb === true) {
134666
+ await this.updateDb({
134667
+ generatedValues,
134668
+ db: db,
134669
+ schema: schema,
134670
+ tableName: tableName,
134671
+ uniqueNotNullColName: uniqueNotNullColName,
134672
+ });
134673
+ }
134423
134674
  generatedValues = [];
134424
134675
  }
134425
134676
  else {
134426
134677
  const batchCount = Math.floor(i / batchSize);
134427
- await this.insertInDb({
134428
- generatedValues: generatedValues.slice(batchSize * batchCount, batchSize * (batchCount + 1)),
134429
- db: db,
134430
- schema: schema,
134431
- tableName: tableName,
134432
- override,
134433
- });
134678
+ if (insertDataInDb === true) {
134679
+ await this.insertInDb({
134680
+ generatedValues: generatedValues.slice(batchSize * batchCount, batchSize * (batchCount + 1)),
134681
+ db: db,
134682
+ schema: schema,
134683
+ tableName: tableName,
134684
+ override,
134685
+ });
134686
+ }
134687
+ else if (updateDataInDb === true) {
134688
+ await this.updateDb({
134689
+ generatedValues: generatedValues.slice(batchSize * batchCount, batchSize * (batchCount + 1)),
134690
+ db: db,
134691
+ schema: schema,
134692
+ tableName: tableName,
134693
+ uniqueNotNullColName: uniqueNotNullColName,
134694
+ });
134695
+ }
134434
134696
  }
134435
134697
  }
134436
134698
  }
@@ -134455,6 +134717,21 @@ class SeedService {
134455
134717
  .values(generatedValues);
134456
134718
  }
134457
134719
  };
134720
+ updateDb = async ({ generatedValues, db, schema, tableName, uniqueNotNullColName, }) => {
134721
+ if (drizzleOrm.is(db, (pgCore.PgDatabase))) {
134722
+ const table = schema[tableName];
134723
+ const uniqueNotNullCol = table[uniqueNotNullColName];
134724
+ await db.update(table).set(generatedValues[0]).where(drizzleOrm.eq(uniqueNotNullCol, generatedValues[0][uniqueNotNullColName]));
134725
+ }
134726
+ else if (drizzleOrm.is(db, (mysqlCore.MySqlDatabase))) {
134727
+ const table = schema[tableName];
134728
+ await db.update(table).set(generatedValues[0]).where(drizzleOrm.eq(table[uniqueNotNullColName], generatedValues[0][uniqueNotNullColName]));
134729
+ }
134730
+ else if (drizzleOrm.is(db, (sqliteCore.BaseSQLiteDatabase))) {
134731
+ const table = schema[tableName];
134732
+ await db.update(table).set(generatedValues[0]).where(drizzleOrm.eq(table[uniqueNotNullColName], generatedValues[0][uniqueNotNullColName]));
134733
+ }
134734
+ };
134458
134735
  }
134459
134736
  var seedService = new SeedService();
134460
134737
 
@@ -134508,6 +134785,7 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
134508
134785
  hasDefault: col.default === undefined ? false : true,
134509
134786
  isUnique: col.isUnique === undefined ? false : col.isUnique,
134510
134787
  notNull: col.notNull,
134788
+ primary: col.primaryKey,
134511
134789
  }));
134512
134790
  tables.push({
134513
134791
  name: tableName,
@@ -134516,11 +134794,18 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
134516
134794
  });
134517
134795
  }
134518
134796
  relations = drizzleStudioRelations.filter((rel) => rel.schema === schemaName && rel.refSchema === schemaName);
134797
+ const isCyclicRelations = relations.map((reli) => {
134798
+ if (relations.some((relj) => reli.table === relj.refTable && reli.refTable === relj.table)) {
134799
+ return { ...reli, isCyclic: true };
134800
+ }
134801
+ return { ...reli, isCyclic: false };
134802
+ });
134519
134803
  refinements = schemasRefinements !== undefined && schemasRefinements[schemaName] !== undefined
134520
134804
  ? schemasRefinements[schemaName]
134521
134805
  : undefined;
134522
- const generatedTablesGenerators = seedService.generatePossibleGenerators(sqlDialect, tables, relations, refinements, options);
134523
- const generatedTables = await seedService.generateTablesValues(relations, generatedTablesGenerators, undefined, undefined, { ...options, preserveData: true, insertDataInDb: false });
134806
+ const generatedTablesGenerators = seedService.generatePossibleGenerators(sqlDialect, tables, isCyclicRelations, {}, // TODO: fix later
134807
+ refinements, options);
134808
+ const generatedTables = await seedService.generateTablesValues(isCyclicRelations, generatedTablesGenerators, undefined, undefined, { ...options, preserveData: true, insertDataInDb: false });
134524
134809
  generatedSchemas[schemaName] = { tables: generatedTables };
134525
134810
  }
134526
134811
  return generatedSchemas;
@@ -134659,7 +134944,7 @@ const resetPostgres = async (db, schema) => {
134659
134944
  const tablesToTruncate = Object.entries(schema).map(([_, table]) => {
134660
134945
  const config = pgCore.getTableConfig(table);
134661
134946
  config.schema = config.schema === undefined ? 'public' : config.schema;
134662
- return `${config.schema}.${config.name}`;
134947
+ return `"${config.schema}"."${config.name}"`;
134663
134948
  });
134664
134949
  await db.execute(drizzleOrm.sql.raw(`truncate ${tablesToTruncate.join(',')} cascade;`));
134665
134950
  };
@@ -134668,9 +134953,13 @@ const filterPgTables = (schema) => {
134668
134953
  return { pgSchema };
134669
134954
  };
134670
134955
  const seedPostgres = async (db, schema, options = {}, refinements) => {
134671
- const { tables, relations } = getPostgresInfo(schema);
134672
- const generatedTablesGenerators = seedService.generatePossibleGenerators('postgresql', tables, relations, refinements, options);
134673
- await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, options);
134956
+ const { tables, relations, tableRelations } = getPostgresInfo(schema);
134957
+ const generatedTablesGenerators = seedService.generatePossibleGenerators('postgresql', tables, relations, tableRelations, refinements, options);
134958
+ const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
134959
+ const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, { ...options, preserveCyclicTablesData });
134960
+ const { filteredTablesGenerators, tablesUniqueNotNullColumn } = seedService.filterCyclicTables(generatedTablesGenerators);
134961
+ const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
134962
+ await seedService.generateTablesValues(relations, filteredTablesGenerators, db, schema, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
134674
134963
  };
134675
134964
  const getPostgresInfo = (schema) => {
134676
134965
  let tableConfig;
@@ -134679,6 +134968,7 @@ const getPostgresInfo = (schema) => {
134679
134968
  const tables = [];
134680
134969
  const relations = [];
134681
134970
  const dbToTsColumnNamesMapGlobal = {};
134971
+ const tableRelations = {};
134682
134972
  const getDbToTsColumnNamesMap = (table) => {
134683
134973
  let dbToTsColumnNamesMap = {};
134684
134974
  const tableName = drizzleOrm.getTableName(table);
@@ -134699,10 +134989,14 @@ const getPostgresInfo = (schema) => {
134699
134989
  for (const [tsCol, col] of Object.entries(tableConfig.columns[0].table)) {
134700
134990
  dbToTsColumnNamesMap[col.name] = tsCol;
134701
134991
  }
134702
- relations.push(...tableConfig.foreignKeys.map((fk) => {
134992
+ // might be empty list
134993
+ const newRelations = tableConfig.foreignKeys.map((fk) => {
134703
134994
  const table = dbToTsTableNamesMap[tableConfig.name];
134704
134995
  const refTable = dbToTsTableNamesMap[drizzleOrm.getTableName(fk.reference().foreignTable)];
134705
134996
  const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(fk.reference().foreignTable);
134997
+ if (tableRelations[refTable] === undefined) {
134998
+ tableRelations[refTable] = [];
134999
+ }
134706
135000
  return {
134707
135001
  table,
134708
135002
  columns: fk
@@ -134712,27 +135006,94 @@ const getPostgresInfo = (schema) => {
134712
135006
  refColumns: fk
134713
135007
  .reference()
134714
135008
  .foreignColumns.map((fCol) => dbToTsColumnNamesMapForRefTable[fCol.name]),
135009
+ refTableRels: tableRelations[refTable],
134715
135010
  };
134716
- }));
135011
+ });
135012
+ relations.push(...newRelations);
135013
+ if (tableRelations[dbToTsTableNamesMap[tableConfig.name]] === undefined) {
135014
+ tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
135015
+ }
135016
+ tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
135017
+ const getAllBaseColumns = (baseColumn) => {
135018
+ const baseColumnResult = {
135019
+ name: baseColumn.name,
135020
+ columnType: baseColumn.columnType.replace('Pg', '').toLowerCase(),
135021
+ dataType: baseColumn.dataType,
135022
+ size: baseColumn.size,
135023
+ hasDefault: baseColumn.hasDefault,
135024
+ enumValues: baseColumn.enumValues,
135025
+ default: baseColumn.default,
135026
+ isUnique: baseColumn.isUnique,
135027
+ notNull: baseColumn.notNull,
135028
+ primary: baseColumn.primary,
135029
+ baseColumn: baseColumn.baseColumn === undefined ? undefined : getAllBaseColumns(baseColumn.baseColumn),
135030
+ };
135031
+ return baseColumnResult;
135032
+ };
135033
+ // console.log(tableConfig.columns);
134717
135034
  tables.push({
134718
135035
  name: dbToTsTableNamesMap[tableConfig.name],
134719
135036
  columns: tableConfig.columns.map((column) => ({
134720
135037
  name: dbToTsColumnNamesMap[column.name],
134721
135038
  columnType: column.columnType.replace('Pg', '').toLowerCase(),
134722
135039
  dataType: column.dataType,
135040
+ size: column.size,
134723
135041
  hasDefault: column.hasDefault,
134724
135042
  default: column.default,
134725
135043
  enumValues: column.enumValues,
134726
135044
  isUnique: column.isUnique,
134727
135045
  notNull: column.notNull,
135046
+ primary: column.primary,
134728
135047
  generatedIdentityType: column.generatedIdentity?.type,
135048
+ baseColumn: (column.baseColumn === undefined)
135049
+ ? undefined
135050
+ : getAllBaseColumns(column.baseColumn),
134729
135051
  })),
134730
135052
  primaryKeys: tableConfig.columns
134731
135053
  .filter((column) => column.primary)
134732
135054
  .map((column) => dbToTsColumnNamesMap[column.name]),
134733
135055
  });
134734
135056
  }
134735
- return { tables, relations };
135057
+ const isCyclicRelations = relations.map((relI) => {
135058
+ // if (relations.some((relj) => relI.table === relj.refTable && relI.refTable === relj.table)) {
135059
+ const tableRel = tableRelations[relI.table].find((relJ) => relJ.refTable === relI.refTable);
135060
+ if (isRelationCyclic(relI)) {
135061
+ tableRel['isCyclic'] = true;
135062
+ return { ...relI, isCyclic: true };
135063
+ }
135064
+ tableRel['isCyclic'] = false;
135065
+ return { ...relI, isCyclic: false };
135066
+ });
135067
+ return { tables, relations: isCyclicRelations, tableRelations };
135068
+ };
135069
+ const isRelationCyclic = (startRel) => {
135070
+ // self relation
135071
+ if (startRel.table === startRel.refTable)
135072
+ return false;
135073
+ // DFS
135074
+ const targetTable = startRel.table;
135075
+ const queue = [startRel];
135076
+ let path = [];
135077
+ while (queue.length !== 0) {
135078
+ const currRel = queue.shift();
135079
+ if (path.includes(currRel.table)) {
135080
+ const idx = path.indexOf(currRel.table);
135081
+ path = path.slice(0, idx);
135082
+ }
135083
+ path.push(currRel.table);
135084
+ for (const rel of currRel.refTableRels) {
135085
+ // self relation
135086
+ if (rel.table === rel.refTable)
135087
+ continue;
135088
+ if (rel.refTable === targetTable)
135089
+ return true;
135090
+ // found cycle, but not the one we are looking for
135091
+ if (path.includes(rel.refTable))
135092
+ continue;
135093
+ queue.unshift(rel);
135094
+ }
135095
+ }
135096
+ return false;
134736
135097
  };
134737
135098
  // MySql-----------------------------------------------------------------------------------------------------
134738
135099
  const resetMySql = async (db, schema) => {
@@ -134752,9 +135113,13 @@ const filterMySqlTables = (schema) => {
134752
135113
  return { mySqlSchema };
134753
135114
  };
134754
135115
  const seedMySql = async (db, schema, options = {}, refinements) => {
134755
- const { tables, relations } = getMySqlInfo(schema);
134756
- const generatedTablesGenerators = seedService.generatePossibleGenerators('mysql', tables, relations, refinements, options);
134757
- await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, options);
135116
+ const { tables, relations, tableRelations } = getMySqlInfo(schema);
135117
+ const generatedTablesGenerators = seedService.generatePossibleGenerators('mysql', tables, relations, tableRelations, refinements, options);
135118
+ const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
135119
+ const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, { ...options, preserveCyclicTablesData });
135120
+ const { filteredTablesGenerators, tablesUniqueNotNullColumn } = seedService.filterCyclicTables(generatedTablesGenerators);
135121
+ const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
135122
+ await seedService.generateTablesValues(relations, filteredTablesGenerators, db, schema, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
134758
135123
  };
134759
135124
  const getMySqlInfo = (schema) => {
134760
135125
  let tableConfig;
@@ -134763,6 +135128,7 @@ const getMySqlInfo = (schema) => {
134763
135128
  const tables = [];
134764
135129
  const relations = [];
134765
135130
  const dbToTsColumnNamesMapGlobal = {};
135131
+ const tableRelations = {};
134766
135132
  const getDbToTsColumnNamesMap = (table) => {
134767
135133
  let dbToTsColumnNamesMap = {};
134768
135134
  const tableName = drizzleOrm.getTableName(table);
@@ -134783,10 +135149,13 @@ const getMySqlInfo = (schema) => {
134783
135149
  for (const [tsCol, col] of Object.entries(tableConfig.columns[0].table)) {
134784
135150
  dbToTsColumnNamesMap[col.name] = tsCol;
134785
135151
  }
134786
- relations.push(...tableConfig.foreignKeys.map((fk) => {
135152
+ const newRelations = tableConfig.foreignKeys.map((fk) => {
134787
135153
  const table = dbToTsTableNamesMap[tableConfig.name];
134788
135154
  const refTable = dbToTsTableNamesMap[drizzleOrm.getTableName(fk.reference().foreignTable)];
134789
135155
  const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(fk.reference().foreignTable);
135156
+ if (tableRelations[refTable] === undefined) {
135157
+ tableRelations[refTable] = [];
135158
+ }
134790
135159
  return {
134791
135160
  table,
134792
135161
  columns: fk
@@ -134796,8 +135165,14 @@ const getMySqlInfo = (schema) => {
134796
135165
  refColumns: fk
134797
135166
  .reference()
134798
135167
  .foreignColumns.map((fCol) => dbToTsColumnNamesMapForRefTable[fCol.name]),
135168
+ refTableRels: tableRelations[refTable],
134799
135169
  };
134800
- }));
135170
+ });
135171
+ relations.push(...newRelations);
135172
+ if (tableRelations[dbToTsTableNamesMap[tableConfig.name]] === undefined) {
135173
+ tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
135174
+ }
135175
+ tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
134801
135176
  tables.push({
134802
135177
  name: dbToTsTableNamesMap[tableConfig.name],
134803
135178
  columns: tableConfig.columns.map((column) => ({
@@ -134809,13 +135184,23 @@ const getMySqlInfo = (schema) => {
134809
135184
  enumValues: column.enumValues,
134810
135185
  isUnique: column.isUnique,
134811
135186
  notNull: column.notNull,
135187
+ primary: column.primary,
134812
135188
  })),
134813
135189
  primaryKeys: tableConfig.columns
134814
135190
  .filter((column) => column.primary)
134815
135191
  .map((column) => dbToTsColumnNamesMap[column.name]),
134816
135192
  });
134817
135193
  }
134818
- return { tables, relations };
135194
+ const isCyclicRelations = relations.map((relI) => {
135195
+ const tableRel = tableRelations[relI.table].find((relJ) => relJ.refTable === relI.refTable);
135196
+ if (isRelationCyclic(relI)) {
135197
+ tableRel['isCyclic'] = true;
135198
+ return { ...relI, isCyclic: true };
135199
+ }
135200
+ tableRel['isCyclic'] = false;
135201
+ return { ...relI, isCyclic: false };
135202
+ });
135203
+ return { tables, relations: isCyclicRelations, tableRelations };
134819
135204
  };
134820
135205
  // Sqlite------------------------------------------------------------------------------------------------------------------------
134821
135206
  const resetSqlite = async (db, schema) => {
@@ -134835,9 +135220,13 @@ const filterSqliteTables = (schema) => {
134835
135220
  return { sqliteSchema };
134836
135221
  };
134837
135222
  const seedSqlite = async (db, schema, options = {}, refinements) => {
134838
- const { tables, relations } = getSqliteInfo(schema);
134839
- const generatedTablesGenerators = seedService.generatePossibleGenerators('sqlite', tables, relations, refinements, options);
134840
- await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, options);
135223
+ const { tables, relations, tableRelations } = getSqliteInfo(schema);
135224
+ const generatedTablesGenerators = seedService.generatePossibleGenerators('sqlite', tables, relations, tableRelations, refinements, options);
135225
+ const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
135226
+ const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, { ...options, preserveCyclicTablesData });
135227
+ const { filteredTablesGenerators, tablesUniqueNotNullColumn } = seedService.filterCyclicTables(generatedTablesGenerators);
135228
+ const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
135229
+ await seedService.generateTablesValues(relations, filteredTablesGenerators, db, schema, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
134841
135230
  };
134842
135231
  const getSqliteInfo = (schema) => {
134843
135232
  let tableConfig;
@@ -134846,6 +135235,7 @@ const getSqliteInfo = (schema) => {
134846
135235
  const tables = [];
134847
135236
  const relations = [];
134848
135237
  const dbToTsColumnNamesMapGlobal = {};
135238
+ const tableRelations = {};
134849
135239
  const getDbToTsColumnNamesMap = (table) => {
134850
135240
  let dbToTsColumnNamesMap = {};
134851
135241
  const tableName = drizzleOrm.getTableName(table);
@@ -134866,10 +135256,13 @@ const getSqliteInfo = (schema) => {
134866
135256
  for (const [tsCol, col] of Object.entries(tableConfig.columns[0].table)) {
134867
135257
  dbToTsColumnNamesMap[col.name] = tsCol;
134868
135258
  }
134869
- relations.push(...tableConfig.foreignKeys.map((fk) => {
135259
+ const newRelations = tableConfig.foreignKeys.map((fk) => {
134870
135260
  const table = dbToTsTableNamesMap[tableConfig.name];
134871
135261
  const refTable = dbToTsTableNamesMap[drizzleOrm.getTableName(fk.reference().foreignTable)];
134872
135262
  const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(fk.reference().foreignTable);
135263
+ if (tableRelations[refTable] === undefined) {
135264
+ tableRelations[refTable] = [];
135265
+ }
134873
135266
  return {
134874
135267
  table,
134875
135268
  columns: fk
@@ -134879,8 +135272,14 @@ const getSqliteInfo = (schema) => {
134879
135272
  refColumns: fk
134880
135273
  .reference()
134881
135274
  .foreignColumns.map((fCol) => dbToTsColumnNamesMapForRefTable[fCol.name]),
135275
+ refTableRels: tableRelations[refTable],
134882
135276
  };
134883
- }));
135277
+ });
135278
+ relations.push(...newRelations);
135279
+ if (tableRelations[dbToTsTableNamesMap[tableConfig.name]] === undefined) {
135280
+ tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
135281
+ }
135282
+ tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
134884
135283
  tables.push({
134885
135284
  name: dbToTsTableNamesMap[tableConfig.name],
134886
135285
  columns: tableConfig.columns.map((column) => ({
@@ -134892,15 +135291,27 @@ const getSqliteInfo = (schema) => {
134892
135291
  enumValues: column.enumValues,
134893
135292
  isUnique: column.isUnique,
134894
135293
  notNull: column.notNull,
135294
+ primary: column.primary,
134895
135295
  })),
134896
135296
  primaryKeys: tableConfig.columns
134897
135297
  .filter((column) => column.primary)
134898
135298
  .map((column) => dbToTsColumnNamesMap[column.name]),
134899
135299
  });
134900
135300
  }
134901
- return { tables, relations };
135301
+ const isCyclicRelations = relations.map((relI) => {
135302
+ const tableRel = tableRelations[relI.table].find((relJ) => relJ.refTable === relI.refTable);
135303
+ if (isRelationCyclic(relI)) {
135304
+ tableRel['isCyclic'] = true;
135305
+ return { ...relI, isCyclic: true };
135306
+ }
135307
+ tableRel['isCyclic'] = false;
135308
+ return { ...relI, isCyclic: false };
135309
+ });
135310
+ return { tables, relations: isCyclicRelations, tableRelations };
134902
135311
  };
134903
135312
 
135313
+ exports.cities = cityNames;
135314
+ exports.countries = countries;
134904
135315
  exports.firstNames = firstNames;
134905
135316
  exports.getGeneratorsFunctions = getGeneratorsFunctions;
134906
135317
  exports.lastNames = lastNames;