drizzle-seed 0.4.0-dd6ee88 → 0.4.0-e6bdce6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SeedService.d.cts +1 -0
- package/SeedService.d.mts +1 -0
- package/SeedService.d.ts +1 -0
- package/cockroach-core/index.d.cts +3 -5
- package/cockroach-core/index.d.mts +3 -5
- package/cockroach-core/index.d.ts +3 -5
- package/common.d.cts +3 -5
- package/common.d.mts +3 -5
- package/common.d.ts +3 -5
- package/generators/GeneratorFuncs.d.cts +888 -28
- package/generators/GeneratorFuncs.d.mts +888 -28
- package/generators/GeneratorFuncs.d.ts +888 -28
- package/generators/Generators.d.cts +147 -42
- package/generators/Generators.d.mts +147 -42
- package/generators/Generators.d.ts +147 -42
- package/generators/apiVersion.d.cts +1 -1
- package/generators/apiVersion.d.mts +1 -1
- package/generators/apiVersion.d.ts +1 -1
- package/generators/versioning/v2.d.cts +11 -4
- package/generators/versioning/v2.d.mts +11 -4
- package/generators/versioning/v2.d.ts +11 -4
- package/generators/versioning/v3.d.cts +10 -0
- package/generators/versioning/v3.d.mts +10 -0
- package/generators/versioning/v3.d.ts +10 -0
- package/index.cjs +764 -282
- package/index.cjs.map +1 -1
- package/index.d.cts +8 -20
- package/index.d.mts +8 -20
- package/index.d.ts +8 -20
- package/index.mjs +764 -282
- package/index.mjs.map +1 -1
- package/mysql-core/index.d.cts +3 -5
- package/mysql-core/index.d.mts +3 -5
- package/mysql-core/index.d.ts +3 -5
- package/package.json +108 -107
- package/pg-core/index.d.cts +3 -5
- package/pg-core/index.d.mts +3 -5
- package/pg-core/index.d.ts +3 -5
- package/singlestore-core/index.d.cts +3 -5
- package/singlestore-core/index.d.mts +3 -5
- package/singlestore-core/index.d.ts +3 -5
- package/sqlite-core/index.d.cts +3 -5
- package/sqlite-core/index.d.mts +3 -5
- package/sqlite-core/index.d.ts +3 -5
- package/types/seedService.d.cts +1 -1
- package/types/seedService.d.mts +1 -1
- package/types/seedService.d.ts +1 -1
- package/types/tables.d.cts +9 -6
- package/types/tables.d.mts +9 -6
- package/types/tables.d.ts +9 -6
- package/utils.d.cts +0 -1
- package/utils.d.mts +0 -1
- package/utils.d.ts +0 -1
package/index.mjs
CHANGED
|
@@ -37,16 +37,6 @@ const isRelationCyclic = (startRel) => {
|
|
|
37
37
|
}
|
|
38
38
|
return false;
|
|
39
39
|
};
|
|
40
|
-
const generateHashFromString = (s) => {
|
|
41
|
-
let hash = 0;
|
|
42
|
-
// p and m are prime numbers
|
|
43
|
-
const p = 53;
|
|
44
|
-
const m = 28871271685163;
|
|
45
|
-
for (let i = 0; i < s.length; i++) {
|
|
46
|
-
hash += ((s.codePointAt(i) || 0) * Math.pow(p, i)) % m;
|
|
47
|
-
}
|
|
48
|
-
return hash;
|
|
49
|
-
};
|
|
50
40
|
const equalSets = (set1, set2) => {
|
|
51
41
|
return set1.size === set2.size && [...set1].every((si) => set2.has(si));
|
|
52
42
|
};
|
|
@@ -114,7 +104,7 @@ const transformFromDrizzleRelation = (schema, getDbToTsColumnNamesMap, tableRela
|
|
|
114
104
|
}
|
|
115
105
|
return relations;
|
|
116
106
|
};
|
|
117
|
-
const getSchemaInfo = (drizzleTablesAndRelations, drizzleTables,
|
|
107
|
+
const getSchemaInfo = (drizzleTablesAndRelations, drizzleTables, mapColumns) => {
|
|
118
108
|
let tableConfig;
|
|
119
109
|
let dbToTsColumnNamesMap;
|
|
120
110
|
const dbToTsTableNamesMap = Object.fromEntries(Object.entries(drizzleTables).map(([key, value]) => [getTableName(value), key]));
|
|
@@ -165,8 +155,25 @@ const getSchemaInfo = (drizzleTablesAndRelations, drizzleTables, mapTable) => {
|
|
|
165
155
|
tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
|
|
166
156
|
}
|
|
167
157
|
tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
|
|
168
|
-
|
|
169
|
-
|
|
158
|
+
const stringsSet = [];
|
|
159
|
+
const uniqueConstraints = [];
|
|
160
|
+
for (const uniCon of tableConfig.uniqueConstraints) {
|
|
161
|
+
const uniConColumns = uniCon.columns.map((col) => dbToTsColumnNamesMap[col.name]);
|
|
162
|
+
const uniConColumnsStr = JSON.stringify(uniConColumns);
|
|
163
|
+
if (!stringsSet.includes(uniConColumnsStr)) {
|
|
164
|
+
stringsSet.push(uniConColumnsStr);
|
|
165
|
+
uniqueConstraints.push(uniConColumns);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const mappedTable = {
|
|
169
|
+
name: dbToTsTableNamesMap[tableConfig.name],
|
|
170
|
+
uniqueConstraints,
|
|
171
|
+
primaryKeys: tableConfig.columns
|
|
172
|
+
.filter((column) => column.primary)
|
|
173
|
+
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
174
|
+
columns: mapColumns(tableConfig, dbToTsColumnNamesMap),
|
|
175
|
+
};
|
|
176
|
+
tables.push(mappedTable);
|
|
170
177
|
}
|
|
171
178
|
const transformedDrizzleRelations = transformFromDrizzleRelation(drizzleTablesAndRelations, getDbToTsColumnNamesMap, tableRelations);
|
|
172
179
|
relations.push(...transformedDrizzleRelations);
|
|
@@ -131448,10 +131455,12 @@ const isObject = (value) => {
|
|
|
131448
131455
|
class AbstractGenerator {
|
|
131449
131456
|
static entityKind = 'AbstractGenerator';
|
|
131450
131457
|
static version = 1;
|
|
131458
|
+
isGeneratorUnique = false;
|
|
131451
131459
|
isUnique = false;
|
|
131452
131460
|
notNull = false;
|
|
131453
131461
|
// param for generators which have a unique version of themselves
|
|
131454
131462
|
uniqueVersionOfGen;
|
|
131463
|
+
maxUniqueCount = -1;
|
|
131455
131464
|
dataType;
|
|
131456
131465
|
timeSpent;
|
|
131457
131466
|
//
|
|
@@ -131463,6 +131472,7 @@ class AbstractGenerator {
|
|
|
131463
131472
|
weightedCountSeed;
|
|
131464
131473
|
maxRepeatedValuesCount;
|
|
131465
131474
|
typeParams = {};
|
|
131475
|
+
uniqueKey;
|
|
131466
131476
|
params;
|
|
131467
131477
|
constructor(params) {
|
|
131468
131478
|
this.params = params === undefined ? {} : params;
|
|
@@ -131485,9 +131495,13 @@ class AbstractGenerator {
|
|
|
131485
131495
|
const constructor = this.constructor;
|
|
131486
131496
|
return constructor.entityKind;
|
|
131487
131497
|
}
|
|
131498
|
+
getMaxUniqueCount() {
|
|
131499
|
+
// override if you need to initialize this.maxUniqueCount after constructor
|
|
131500
|
+
return this.maxUniqueCount;
|
|
131501
|
+
}
|
|
131488
131502
|
replaceIfUnique() {
|
|
131489
131503
|
this.updateParams();
|
|
131490
|
-
if (this.uniqueVersionOfGen !== undefined
|
|
131504
|
+
if ((this.uniqueVersionOfGen !== undefined)
|
|
131491
131505
|
&& this.isUnique === true) {
|
|
131492
131506
|
const uniqueGen = new this.uniqueVersionOfGen({
|
|
131493
131507
|
...this.params,
|
|
@@ -131518,6 +131532,20 @@ class AbstractGenerator {
|
|
|
131518
131532
|
}
|
|
131519
131533
|
}
|
|
131520
131534
|
// Generators Classes -----------------------------------------------------------------------------------------------------------------------
|
|
131535
|
+
class GenerateHashFromString extends AbstractGenerator {
|
|
131536
|
+
static entityKind = 'GenerateHashFromString';
|
|
131537
|
+
init() { }
|
|
131538
|
+
generate({ input }) {
|
|
131539
|
+
let hash = 0;
|
|
131540
|
+
// p and m are prime numbers
|
|
131541
|
+
const p = 53;
|
|
131542
|
+
const m = 28871271685163;
|
|
131543
|
+
for (let i = 0; i < input.length; i++) {
|
|
131544
|
+
hash += ((input.codePointAt(i) || 0) * Math.pow(p, i)) % m;
|
|
131545
|
+
}
|
|
131546
|
+
return hash;
|
|
131547
|
+
}
|
|
131548
|
+
}
|
|
131521
131549
|
class GenerateArray extends AbstractGenerator {
|
|
131522
131550
|
static entityKind = 'GenerateArray';
|
|
131523
131551
|
arraySize = 10;
|
|
@@ -131577,6 +131605,23 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131577
131605
|
static entityKind = 'GenerateValuesFromArray';
|
|
131578
131606
|
state;
|
|
131579
131607
|
timeSpent = 0;
|
|
131608
|
+
maxUniqueCount;
|
|
131609
|
+
allValuesCount = 0; // TODO rewrite generator
|
|
131610
|
+
constructor(params) {
|
|
131611
|
+
super(params);
|
|
131612
|
+
this.allValuesCount = this.params.values.length;
|
|
131613
|
+
if (isObject(this.params.values[0])) {
|
|
131614
|
+
this.allValuesCount = this.params.values.reduce((acc, currVal) => acc + currVal.values.length, 0);
|
|
131615
|
+
}
|
|
131616
|
+
this.maxUniqueCount = this.allValuesCount;
|
|
131617
|
+
}
|
|
131618
|
+
getMaxUniqueCount() {
|
|
131619
|
+
this.allValuesCount = this.params.values.length;
|
|
131620
|
+
if (isObject(this.params.values[0])) {
|
|
131621
|
+
this.allValuesCount = this.params.values.reduce((acc, currVal) => acc + currVal.values.length, 0);
|
|
131622
|
+
}
|
|
131623
|
+
return this.allValuesCount;
|
|
131624
|
+
}
|
|
131580
131625
|
checks({ count }) {
|
|
131581
131626
|
const { values } = this.params;
|
|
131582
131627
|
const { maxRepeatedValuesCount, notNull, isUnique } = this;
|
|
@@ -131594,16 +131639,13 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131594
131639
|
: obj.count.every((count) => count > 0))))) {
|
|
131595
131640
|
throw new Error('maxRepeatedValuesCount should be greater than zero.');
|
|
131596
131641
|
}
|
|
131597
|
-
let allValuesCount = values.length;
|
|
131598
|
-
if (isObject(values[0])) {
|
|
131599
|
-
allValuesCount = values.reduce((acc, currVal) => acc + currVal.values.length, 0);
|
|
131600
|
-
}
|
|
131601
131642
|
if (notNull === true
|
|
131602
131643
|
&& maxRepeatedValuesCount !== undefined
|
|
131603
131644
|
&& ((!isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
|
|
131604
131645
|
&& maxRepeatedValuesCount * values.length < count)
|
|
131605
131646
|
|| (isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
|
|
131606
|
-
|
|
131647
|
+
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
131648
|
+
&& maxRepeatedValuesCount * this.allValuesCount < count))) {
|
|
131607
131649
|
throw new Error("Can't fill notNull column with null values.");
|
|
131608
131650
|
}
|
|
131609
131651
|
if (isUnique === true && maxRepeatedValuesCount !== undefined && ((typeof maxRepeatedValuesCount === 'number' && maxRepeatedValuesCount > 1)
|
|
@@ -131614,7 +131656,8 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131614
131656
|
throw new Error("Can't be greater than 1 if column is unique.");
|
|
131615
131657
|
}
|
|
131616
131658
|
if (isUnique === true && notNull === true && ((!isObject(values[0]) && values.length < count)
|
|
131617
|
-
|
|
131659
|
+
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
131660
|
+
|| (isObject(values[0]) && this.allValuesCount < count))) {
|
|
131618
131661
|
// console.log(maxRepeatedValuesCount, values.length, allValuesCount, count)
|
|
131619
131662
|
throw new Error('There are no enough values to fill unique column.');
|
|
131620
131663
|
}
|
|
@@ -131750,6 +131793,8 @@ class GenerateSelfRelationsValuesFromArray extends AbstractGenerator {
|
|
|
131750
131793
|
class GenerateIntPrimaryKey extends AbstractGenerator {
|
|
131751
131794
|
static entityKind = 'GenerateIntPrimaryKey';
|
|
131752
131795
|
maxValue;
|
|
131796
|
+
maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
131797
|
+
isGeneratorUnique = true;
|
|
131753
131798
|
init({ count }) {
|
|
131754
131799
|
if (this.maxValue !== undefined && count > this.maxValue) {
|
|
131755
131800
|
throw new Error('count exceeds max number for this column type.');
|
|
@@ -131800,14 +131845,39 @@ class GenerateNumber extends AbstractGenerator {
|
|
|
131800
131845
|
class GenerateUniqueNumber extends AbstractGenerator {
|
|
131801
131846
|
static entityKind = 'GenerateUniqueNumber';
|
|
131802
131847
|
state;
|
|
131803
|
-
|
|
131804
|
-
|
|
131848
|
+
precision;
|
|
131849
|
+
isGeneratorUnique = true;
|
|
131850
|
+
maxUniqueCount;
|
|
131851
|
+
constructor(params) {
|
|
131852
|
+
super(params);
|
|
131853
|
+
let { minValue, maxValue } = this.params;
|
|
131854
|
+
const { precision } = this.params;
|
|
131855
|
+
this.precision = precision ?? 100;
|
|
131856
|
+
if (maxValue === undefined) {
|
|
131857
|
+
this.maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
131858
|
+
return;
|
|
131859
|
+
}
|
|
131860
|
+
else {
|
|
131861
|
+
maxValue *= this.precision;
|
|
131862
|
+
}
|
|
131863
|
+
if (minValue === undefined) {
|
|
131864
|
+
minValue = -maxValue;
|
|
131865
|
+
}
|
|
131866
|
+
else {
|
|
131867
|
+
minValue *= this.precision;
|
|
131868
|
+
}
|
|
131869
|
+
this.maxUniqueCount = maxValue - minValue + 1;
|
|
131870
|
+
}
|
|
131871
|
+
getMaxUniqueCount() {
|
|
131872
|
+
if (this.maxUniqueCount !== undefined)
|
|
131873
|
+
return this.maxUniqueCount;
|
|
131805
131874
|
let { minValue, maxValue, precision } = this.params;
|
|
131806
131875
|
if (precision === undefined) {
|
|
131807
131876
|
precision = 100;
|
|
131808
131877
|
}
|
|
131809
131878
|
if (maxValue === undefined) {
|
|
131810
|
-
|
|
131879
|
+
this.maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
131880
|
+
return this.maxUniqueCount;
|
|
131811
131881
|
}
|
|
131812
131882
|
else {
|
|
131813
131883
|
maxValue *= precision;
|
|
@@ -131818,9 +131888,26 @@ class GenerateUniqueNumber extends AbstractGenerator {
|
|
|
131818
131888
|
else {
|
|
131819
131889
|
minValue *= precision;
|
|
131820
131890
|
}
|
|
131891
|
+
this.maxUniqueCount = maxValue - minValue + 1;
|
|
131892
|
+
return this.maxUniqueCount;
|
|
131893
|
+
}
|
|
131894
|
+
init({ count, seed }) {
|
|
131895
|
+
let { minValue, maxValue } = this.params;
|
|
131896
|
+
if (maxValue === undefined) {
|
|
131897
|
+
maxValue = count * this.precision;
|
|
131898
|
+
}
|
|
131899
|
+
else {
|
|
131900
|
+
maxValue *= this.precision;
|
|
131901
|
+
}
|
|
131902
|
+
if (minValue === undefined) {
|
|
131903
|
+
minValue = -maxValue;
|
|
131904
|
+
}
|
|
131905
|
+
else {
|
|
131906
|
+
minValue *= this.precision;
|
|
131907
|
+
}
|
|
131821
131908
|
const genUniqueIntObj = new GenerateUniqueInt({ minValue, maxValue });
|
|
131822
131909
|
genUniqueIntObj.init({ count, seed });
|
|
131823
|
-
this.state = { genUniqueIntObj, minValue, maxValue, precision };
|
|
131910
|
+
this.state = { genUniqueIntObj, minValue, maxValue, precision: this.precision };
|
|
131824
131911
|
}
|
|
131825
131912
|
generate() {
|
|
131826
131913
|
if (this.state === undefined) {
|
|
@@ -131875,8 +131962,48 @@ class GenerateUniqueInt extends AbstractGenerator {
|
|
|
131875
131962
|
genMaxRepeatedValuesCount;
|
|
131876
131963
|
skipCheck = false;
|
|
131877
131964
|
state;
|
|
131878
|
-
|
|
131965
|
+
isGeneratorUnique = true;
|
|
131879
131966
|
timeSpent = 0;
|
|
131967
|
+
maxUniqueCount;
|
|
131968
|
+
constructor(params) {
|
|
131969
|
+
super(params);
|
|
131970
|
+
let minValue = this.params.minValue, maxValue = this.params.maxValue;
|
|
131971
|
+
if (maxValue === undefined) {
|
|
131972
|
+
this.maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
131973
|
+
return;
|
|
131974
|
+
}
|
|
131975
|
+
if (minValue === undefined) {
|
|
131976
|
+
minValue = -maxValue;
|
|
131977
|
+
}
|
|
131978
|
+
if (typeof minValue === 'number' && typeof maxValue === 'number') {
|
|
131979
|
+
minValue = minValue >= 0 ? Math.ceil(minValue) : Math.floor(minValue);
|
|
131980
|
+
maxValue = maxValue >= 0 ? Math.floor(maxValue) : Math.ceil(maxValue);
|
|
131981
|
+
this.maxUniqueCount = Number(maxValue - minValue) + 1;
|
|
131982
|
+
}
|
|
131983
|
+
else if (typeof minValue === 'bigint' && typeof maxValue === 'bigint') {
|
|
131984
|
+
this.maxUniqueCount = Number(maxValue - minValue) + 1;
|
|
131985
|
+
}
|
|
131986
|
+
else
|
|
131987
|
+
this.maxUniqueCount = Number(Number(maxValue) - Number(minValue)) + 1; // error should be triggered in init method
|
|
131988
|
+
}
|
|
131989
|
+
getMaxUniqueCount() {
|
|
131990
|
+
if (this.maxUniqueCount !== undefined)
|
|
131991
|
+
return this.maxUniqueCount;
|
|
131992
|
+
let minValue = this.params.minValue, maxValue = this.params.maxValue;
|
|
131993
|
+
if (maxValue === undefined) {
|
|
131994
|
+
this.maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
131995
|
+
return this.maxUniqueCount;
|
|
131996
|
+
}
|
|
131997
|
+
if (minValue === undefined) {
|
|
131998
|
+
minValue = -maxValue;
|
|
131999
|
+
}
|
|
132000
|
+
if (typeof minValue === 'number' && typeof maxValue === 'number') {
|
|
132001
|
+
minValue = minValue >= 0 ? Math.ceil(minValue) : Math.floor(minValue);
|
|
132002
|
+
maxValue = maxValue >= 0 ? Math.floor(maxValue) : Math.ceil(maxValue);
|
|
132003
|
+
}
|
|
132004
|
+
this.maxUniqueCount = Number(maxValue - minValue) + 1;
|
|
132005
|
+
return this.maxUniqueCount;
|
|
132006
|
+
}
|
|
131880
132007
|
init({ count, seed }) {
|
|
131881
132008
|
const rng = prand.xoroshiro128plus(seed);
|
|
131882
132009
|
let { minValue, maxValue } = this.params;
|
|
@@ -132306,11 +132433,10 @@ class GenerateInterval extends AbstractGenerator {
|
|
|
132306
132433
|
return interval;
|
|
132307
132434
|
}
|
|
132308
132435
|
}
|
|
132309
|
-
// has a newer version
|
|
132310
132436
|
class GenerateUniqueInterval extends AbstractGenerator {
|
|
132311
132437
|
static 'entityKind' = 'GenerateUniqueInterval';
|
|
132312
132438
|
state;
|
|
132313
|
-
|
|
132439
|
+
isGeneratorUnique = true;
|
|
132314
132440
|
config = {
|
|
132315
132441
|
year: {
|
|
132316
132442
|
from: 0,
|
|
@@ -132337,6 +132463,47 @@ class GenerateUniqueInterval extends AbstractGenerator {
|
|
|
132337
132463
|
to: 60,
|
|
132338
132464
|
},
|
|
132339
132465
|
};
|
|
132466
|
+
maxUniqueCount;
|
|
132467
|
+
constructor(params) {
|
|
132468
|
+
super(params);
|
|
132469
|
+
const allFields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
|
|
132470
|
+
let fieldsToGenerate = allFields;
|
|
132471
|
+
if (this.params.fields !== undefined && this.params.fields?.includes(' to ')) {
|
|
132472
|
+
const tokens = this.params.fields.split(' to ');
|
|
132473
|
+
const endIdx = allFields.indexOf(tokens[1]);
|
|
132474
|
+
fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
132475
|
+
}
|
|
132476
|
+
else if (this.params.fields !== undefined) {
|
|
132477
|
+
const endIdx = allFields.indexOf(this.params.fields);
|
|
132478
|
+
fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
132479
|
+
}
|
|
132480
|
+
this.maxUniqueCount = 1;
|
|
132481
|
+
for (const field of fieldsToGenerate) {
|
|
132482
|
+
const from = this.config[field].from, to = this.config[field].to;
|
|
132483
|
+
this.maxUniqueCount *= from - to + 1;
|
|
132484
|
+
}
|
|
132485
|
+
}
|
|
132486
|
+
getMaxUniqueCount() {
|
|
132487
|
+
if (this.maxUniqueCount !== undefined)
|
|
132488
|
+
return this.maxUniqueCount;
|
|
132489
|
+
const allFields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
|
|
132490
|
+
let fieldsToGenerate = allFields;
|
|
132491
|
+
if (this.params.fields !== undefined && this.params.fields?.includes(' to ')) {
|
|
132492
|
+
const tokens = this.params.fields.split(' to ');
|
|
132493
|
+
const endIdx = allFields.indexOf(tokens[1]);
|
|
132494
|
+
fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
132495
|
+
}
|
|
132496
|
+
else if (this.params.fields !== undefined) {
|
|
132497
|
+
const endIdx = allFields.indexOf(this.params.fields);
|
|
132498
|
+
fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
132499
|
+
}
|
|
132500
|
+
this.maxUniqueCount = 1;
|
|
132501
|
+
for (const field of fieldsToGenerate) {
|
|
132502
|
+
const from = this.config[field].from, to = this.config[field].to;
|
|
132503
|
+
this.maxUniqueCount *= from - to + 1;
|
|
132504
|
+
}
|
|
132505
|
+
return this.maxUniqueCount;
|
|
132506
|
+
}
|
|
132340
132507
|
init({ count, seed }) {
|
|
132341
132508
|
const allFields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
|
|
132342
132509
|
let fieldsToGenerate = allFields;
|
|
@@ -132414,7 +132581,11 @@ class GenerateString extends AbstractGenerator {
|
|
|
132414
132581
|
class GenerateUniqueString extends AbstractGenerator {
|
|
132415
132582
|
static entityKind = 'GenerateUniqueString';
|
|
132416
132583
|
state;
|
|
132417
|
-
|
|
132584
|
+
isGeneratorUnique = true;
|
|
132585
|
+
maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
132586
|
+
getMaxUniqueCount() {
|
|
132587
|
+
return Number.POSITIVE_INFINITY;
|
|
132588
|
+
}
|
|
132418
132589
|
init({ seed }) {
|
|
132419
132590
|
const rng = prand.xoroshiro128plus(seed);
|
|
132420
132591
|
this.state = { rng };
|
|
@@ -132443,8 +132614,12 @@ class GenerateUniqueString extends AbstractGenerator {
|
|
|
132443
132614
|
}
|
|
132444
132615
|
class GenerateUUID extends AbstractGenerator {
|
|
132445
132616
|
static entityKind = 'GenerateUUID';
|
|
132446
|
-
|
|
132617
|
+
isGeneratorUnique = true;
|
|
132618
|
+
maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
132447
132619
|
state;
|
|
132620
|
+
getMaxUniqueCount() {
|
|
132621
|
+
return Number.POSITIVE_INFINITY;
|
|
132622
|
+
}
|
|
132448
132623
|
init({ count, seed }) {
|
|
132449
132624
|
super.init({ count, seed });
|
|
132450
132625
|
const rng = prand.xoroshiro128plus(seed);
|
|
@@ -132499,9 +132674,16 @@ class GenerateFirstName extends AbstractGenerator {
|
|
|
132499
132674
|
class GenerateUniqueFirstName extends AbstractGenerator {
|
|
132500
132675
|
static entityKind = 'GenerateUniqueFirstName';
|
|
132501
132676
|
state;
|
|
132502
|
-
|
|
132677
|
+
isGeneratorUnique = true;
|
|
132678
|
+
maxUniqueCount = firstNames.length;
|
|
132679
|
+
getMaxUniqueCount() {
|
|
132680
|
+
if (this.maxUniqueCount !== undefined)
|
|
132681
|
+
return this.maxUniqueCount;
|
|
132682
|
+
this.maxUniqueCount = firstNames.length;
|
|
132683
|
+
return firstNames.length;
|
|
132684
|
+
}
|
|
132503
132685
|
init({ count, seed }) {
|
|
132504
|
-
if (count >
|
|
132686
|
+
if (count > this.getMaxUniqueCount()) {
|
|
132505
132687
|
throw new Error('count exceeds max number of unique first names.');
|
|
132506
132688
|
}
|
|
132507
132689
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < maxStringLength$5) {
|
|
@@ -132545,9 +132727,16 @@ class GenerateLastName extends AbstractGenerator {
|
|
|
132545
132727
|
class GenerateUniqueLastName extends AbstractGenerator {
|
|
132546
132728
|
static entityKind = 'GenerateUniqueLastName';
|
|
132547
132729
|
state;
|
|
132548
|
-
|
|
132730
|
+
isGeneratorUnique = true;
|
|
132731
|
+
maxUniqueCount = lastNames.length;
|
|
132732
|
+
getMaxUniqueCount() {
|
|
132733
|
+
if (this.maxUniqueCount !== undefined)
|
|
132734
|
+
return this.maxUniqueCount;
|
|
132735
|
+
this.maxUniqueCount = lastNames.length;
|
|
132736
|
+
return lastNames.length;
|
|
132737
|
+
}
|
|
132549
132738
|
init({ count, seed }) {
|
|
132550
|
-
if (count >
|
|
132739
|
+
if (count > this.getMaxUniqueCount()) {
|
|
132551
132740
|
throw new Error('count exceeds max number of unique last names.');
|
|
132552
132741
|
}
|
|
132553
132742
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < maxStringLength$3) {
|
|
@@ -132594,13 +132783,19 @@ class GenerateFullName extends AbstractGenerator {
|
|
|
132594
132783
|
class GenerateUniqueFullName extends AbstractGenerator {
|
|
132595
132784
|
static entityKind = 'GenerateUniqueFullName';
|
|
132596
132785
|
state;
|
|
132597
|
-
|
|
132786
|
+
isGeneratorUnique = true;
|
|
132598
132787
|
timeSpent = 0;
|
|
132788
|
+
maxUniqueCount = firstNames.length * lastNames.length;
|
|
132789
|
+
getMaxUniqueCount() {
|
|
132790
|
+
if (this.maxUniqueCount !== undefined)
|
|
132791
|
+
return this.maxUniqueCount;
|
|
132792
|
+
this.maxUniqueCount = firstNames.length * lastNames.length;
|
|
132793
|
+
return this.maxUniqueCount;
|
|
132794
|
+
}
|
|
132599
132795
|
init({ count, seed }) {
|
|
132600
132796
|
const t0 = new Date();
|
|
132601
|
-
|
|
132602
|
-
|
|
132603
|
-
throw new RangeError(`count exceeds max number of unique full names(${maxUniqueFullNamesNumber}).`);
|
|
132797
|
+
if (count > this.getMaxUniqueCount()) {
|
|
132798
|
+
throw new RangeError(`count exceeds max number of unique full names(${this.getMaxUniqueCount()}).`);
|
|
132604
132799
|
}
|
|
132605
132800
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < (maxStringLength$5 + maxStringLength$3 + 1)) {
|
|
132606
132801
|
throw new Error(`You can't use full name generator with a db column length restriction of ${this.typeParams?.length}. Set the maximum string length to at least ${maxStringLength$5 + maxStringLength$3 + 1}.`);
|
|
@@ -132635,13 +132830,17 @@ class GenerateEmail extends AbstractGenerator {
|
|
|
132635
132830
|
static entityKind = 'GenerateEmail';
|
|
132636
132831
|
state;
|
|
132637
132832
|
timeSpent = 0;
|
|
132638
|
-
|
|
132833
|
+
isGeneratorUnique = true;
|
|
132834
|
+
maxUniqueCount = adjectives.length * firstNames.length * emailDomains.length;
|
|
132835
|
+
getMaxUniqueCount() {
|
|
132836
|
+
if (this.maxUniqueCount !== undefined)
|
|
132837
|
+
return this.maxUniqueCount;
|
|
132838
|
+
this.maxUniqueCount = adjectives.length * firstNames.length * emailDomains.length;
|
|
132839
|
+
return this.maxUniqueCount;
|
|
132840
|
+
}
|
|
132639
132841
|
init({ count, seed }) {
|
|
132640
132842
|
super.init({ count, seed });
|
|
132641
|
-
const
|
|
132642
|
-
const adjectivesArray = adjectives;
|
|
132643
|
-
const namesArray = firstNames;
|
|
132644
|
-
const maxUniqueEmailsNumber = adjectivesArray.length * namesArray.length * domainsArray.length;
|
|
132843
|
+
const maxUniqueEmailsNumber = adjectives.length * firstNames.length * emailDomains.length;
|
|
132645
132844
|
if (count > maxUniqueEmailsNumber) {
|
|
132646
132845
|
throw new RangeError(`count exceeds max number of unique emails(${maxUniqueEmailsNumber}).`);
|
|
132647
132846
|
}
|
|
@@ -132649,7 +132848,7 @@ class GenerateEmail extends AbstractGenerator {
|
|
|
132649
132848
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < maxEmailLength) {
|
|
132650
132849
|
throw new Error(`You can't use email generator with a db column length restriction of ${this.typeParams?.length}. Set the maximum string length to at least ${maxEmailLength}.`);
|
|
132651
132850
|
}
|
|
132652
|
-
const arraysToGenerateFrom = [
|
|
132851
|
+
const arraysToGenerateFrom = [adjectives, firstNames, emailDomains];
|
|
132653
132852
|
const genIndicesObj = new GenerateUniqueInt({
|
|
132654
132853
|
minValue: 0,
|
|
132655
132854
|
maxValue: maxUniqueEmailsNumber - 1,
|
|
@@ -132673,20 +132872,75 @@ class GenerateEmail extends AbstractGenerator {
|
|
|
132673
132872
|
class GeneratePhoneNumber extends AbstractGenerator {
|
|
132674
132873
|
static entityKind = 'GeneratePhoneNumber';
|
|
132675
132874
|
state;
|
|
132676
|
-
|
|
132875
|
+
isGeneratorUnique = true;
|
|
132876
|
+
maxUniqueCount;
|
|
132877
|
+
constructor(params) {
|
|
132878
|
+
super(params);
|
|
132879
|
+
const { template } = this.params;
|
|
132880
|
+
if (template === undefined) {
|
|
132881
|
+
const { generatedDigitsNumbers } = this.prepareWithoutTemplate();
|
|
132882
|
+
this.maxUniqueCount = generatedDigitsNumbers.reduce((a, b) => a + Math.pow(10, b), 0);
|
|
132883
|
+
}
|
|
132884
|
+
else {
|
|
132885
|
+
const { placeholdersCount } = this.prepareWithTemplate();
|
|
132886
|
+
this.maxUniqueCount = Math.pow(10, placeholdersCount);
|
|
132887
|
+
}
|
|
132888
|
+
}
|
|
132889
|
+
prepareWithTemplate() {
|
|
132890
|
+
const { template } = this.params;
|
|
132891
|
+
const iterArray = [...template.matchAll(/#/g)];
|
|
132892
|
+
const placeholdersCount = iterArray.length;
|
|
132893
|
+
return { placeholdersCount };
|
|
132894
|
+
}
|
|
132895
|
+
prepareWithoutTemplate() {
|
|
132896
|
+
let { generatedDigitsNumbers, prefixes } = this.params;
|
|
132897
|
+
if (prefixes === undefined || prefixes.length === 0) {
|
|
132898
|
+
prefixes = phonesInfo.map((phoneInfo) => phoneInfo.split(',').slice(0, -1).join(' '));
|
|
132899
|
+
generatedDigitsNumbers = phonesInfo.map((phoneInfo) => {
|
|
132900
|
+
// tokens = ["380","99","9"] =
|
|
132901
|
+
// = ["country prefix", "operator prefix", "number length including operator prefix and excluding country prefix"]
|
|
132902
|
+
const tokens = phoneInfo.split(',');
|
|
132903
|
+
const operatorPrefixLength = tokens[1].replaceAll(' ', '').length;
|
|
132904
|
+
return Number(tokens[2]) - operatorPrefixLength;
|
|
132905
|
+
});
|
|
132906
|
+
}
|
|
132907
|
+
else {
|
|
132908
|
+
if (typeof generatedDigitsNumbers === 'number') {
|
|
132909
|
+
generatedDigitsNumbers = Array.from({ length: prefixes.length }).fill(generatedDigitsNumbers);
|
|
132910
|
+
}
|
|
132911
|
+
else if (generatedDigitsNumbers === undefined
|
|
132912
|
+
|| generatedDigitsNumbers.length === 0) {
|
|
132913
|
+
generatedDigitsNumbers = Array.from({ length: prefixes.length }).fill(7);
|
|
132914
|
+
}
|
|
132915
|
+
}
|
|
132916
|
+
return { prefixes, generatedDigitsNumbers };
|
|
132917
|
+
}
|
|
132918
|
+
getMaxUniqueCount() {
|
|
132919
|
+
if (this.maxUniqueCount !== undefined)
|
|
132920
|
+
return this.maxUniqueCount;
|
|
132921
|
+
const { template } = this.params;
|
|
132922
|
+
if (template === undefined) {
|
|
132923
|
+
const { generatedDigitsNumbers } = this.prepareWithoutTemplate();
|
|
132924
|
+
this.maxUniqueCount = generatedDigitsNumbers.reduce((a, b) => a + Math.pow(10, b), 0);
|
|
132925
|
+
return this.maxUniqueCount;
|
|
132926
|
+
}
|
|
132927
|
+
else {
|
|
132928
|
+
const { placeholdersCount } = this.prepareWithTemplate();
|
|
132929
|
+
this.maxUniqueCount = Math.pow(10, placeholdersCount);
|
|
132930
|
+
return this.maxUniqueCount;
|
|
132931
|
+
}
|
|
132932
|
+
}
|
|
132677
132933
|
init({ count, seed }) {
|
|
132678
132934
|
super.init({ count, seed });
|
|
132679
|
-
|
|
132680
|
-
const { prefixes, template } = this.params;
|
|
132935
|
+
const { template } = this.params;
|
|
132681
132936
|
const rng = prand.xoroshiro128plus(seed);
|
|
132682
132937
|
if (template !== undefined) {
|
|
132683
132938
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < template.length) {
|
|
132684
132939
|
throw new Error(`Length of phone number template is shorter than db column length restriction: ${this.typeParams?.length}.
|
|
132685
132940
|
Set the maximum string length to at least ${template.length}.`);
|
|
132686
132941
|
}
|
|
132687
|
-
const
|
|
132688
|
-
const
|
|
132689
|
-
const maxUniquePhoneNumbersCount = Math.pow(10, placeholdersCount);
|
|
132942
|
+
const { placeholdersCount } = this.prepareWithTemplate();
|
|
132943
|
+
const maxUniquePhoneNumbersCount = this.getMaxUniqueCount();
|
|
132690
132944
|
if (maxUniquePhoneNumbersCount < count) {
|
|
132691
132945
|
throw new RangeError(`count exceeds max number of unique phone numbers(${maxUniquePhoneNumbersCount}).`);
|
|
132692
132946
|
}
|
|
@@ -132703,27 +132957,8 @@ class GeneratePhoneNumber extends AbstractGenerator {
|
|
|
132703
132957
|
this.state = { rng, placeholdersCount, generatorsMap, prefixesArray, generatedDigitsNumbers, phoneNumbersSet };
|
|
132704
132958
|
return;
|
|
132705
132959
|
}
|
|
132706
|
-
|
|
132707
|
-
|
|
132708
|
-
prefixesArray = phonesInfo.map((phoneInfo) => phoneInfo.split(',').slice(0, -1).join(' '));
|
|
132709
|
-
generatedDigitsNumbers = phonesInfo.map((phoneInfo) => {
|
|
132710
|
-
// tokens = ["380","99","9"] =
|
|
132711
|
-
// = ["country prefix", "operator prefix", "number length including operator prefix and excluding country prefix"]
|
|
132712
|
-
const tokens = phoneInfo.split(',');
|
|
132713
|
-
const operatorPrefixLength = tokens[1].replaceAll(' ', '').length;
|
|
132714
|
-
return Number(tokens[2]) - operatorPrefixLength;
|
|
132715
|
-
});
|
|
132716
|
-
}
|
|
132717
|
-
else {
|
|
132718
|
-
prefixesArray = prefixes;
|
|
132719
|
-
if (typeof generatedDigitsNumbers === 'number') {
|
|
132720
|
-
generatedDigitsNumbers = Array.from({ length: prefixes.length }).fill(generatedDigitsNumbers);
|
|
132721
|
-
}
|
|
132722
|
-
else if (generatedDigitsNumbers === undefined
|
|
132723
|
-
|| generatedDigitsNumbers.length === 0) {
|
|
132724
|
-
generatedDigitsNumbers = Array.from({ length: prefixes.length }).fill(7);
|
|
132725
|
-
}
|
|
132726
|
-
}
|
|
132960
|
+
const { generatedDigitsNumbers, prefixes } = this.prepareWithoutTemplate();
|
|
132961
|
+
const prefixesArray = [...prefixes];
|
|
132727
132962
|
const maxPrefixLength = Math.max(...prefixesArray.map((prefix) => prefix.length));
|
|
132728
132963
|
const maxGeneratedDigits = Math.max(...generatedDigitsNumbers);
|
|
132729
132964
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < (maxPrefixLength + maxGeneratedDigits)) {
|
|
@@ -132732,7 +132967,7 @@ class GeneratePhoneNumber extends AbstractGenerator {
|
|
|
132732
132967
|
if (new Set(prefixesArray).size !== prefixesArray.length) {
|
|
132733
132968
|
throw new Error('prefixes are not unique.');
|
|
132734
132969
|
}
|
|
132735
|
-
const maxUniquePhoneNumbersCount =
|
|
132970
|
+
const maxUniquePhoneNumbersCount = this.getMaxUniqueCount();
|
|
132736
132971
|
if (maxUniquePhoneNumbersCount < count) {
|
|
132737
132972
|
throw new RangeError(`count exceeds max number of unique phone numbers(${maxUniquePhoneNumbersCount}).`);
|
|
132738
132973
|
}
|
|
@@ -132822,9 +133057,16 @@ class GenerateCountry extends AbstractGenerator {
|
|
|
132822
133057
|
class GenerateUniqueCountry extends AbstractGenerator {
|
|
132823
133058
|
static entityKind = 'GenerateUniqueCountry';
|
|
132824
133059
|
state;
|
|
132825
|
-
|
|
133060
|
+
isGeneratorUnique = true;
|
|
133061
|
+
maxUniqueCount = countries.length;
|
|
133062
|
+
getMaxUniqueCount() {
|
|
133063
|
+
if (this.maxUniqueCount !== undefined)
|
|
133064
|
+
return this.maxUniqueCount;
|
|
133065
|
+
this.maxUniqueCount = countries.length;
|
|
133066
|
+
return this.maxUniqueCount;
|
|
133067
|
+
}
|
|
132826
133068
|
init({ count, seed }) {
|
|
132827
|
-
if (count >
|
|
133069
|
+
if (count > this.getMaxUniqueCount()) {
|
|
132828
133070
|
throw new Error('count exceeds max number of unique countries.');
|
|
132829
133071
|
}
|
|
132830
133072
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < maxStringLength$7) {
|
|
@@ -132893,11 +133135,17 @@ class GenerateStreetAddress extends AbstractGenerator {
|
|
|
132893
133135
|
class GenerateUniqueStreetAddress extends AbstractGenerator {
|
|
132894
133136
|
static entityKind = 'GenerateUniqueStreetAddress';
|
|
132895
133137
|
state;
|
|
132896
|
-
|
|
133138
|
+
isGeneratorUnique = true;
|
|
133139
|
+
streetNumbersCount = 999;
|
|
133140
|
+
maxUniqueCount = this.streetNumbersCount * (firstNames.length + lastNames.length)
|
|
133141
|
+
* streetSuffix.length;
|
|
133142
|
+
getMaxUniqueCount() {
|
|
133143
|
+
return this.maxUniqueCount;
|
|
133144
|
+
}
|
|
132897
133145
|
init({ count, seed }) {
|
|
132898
|
-
const streetNumberStrs = Array.from({ length:
|
|
132899
|
-
const maxUniqueStreetnamesNumber = streetNumberStrs.length * firstNames.length
|
|
132900
|
-
|
|
133146
|
+
const streetNumberStrs = Array.from({ length: this.streetNumbersCount }, (_, i) => String(i + 1));
|
|
133147
|
+
const maxUniqueStreetnamesNumber = streetNumberStrs.length * (firstNames.length + lastNames.length)
|
|
133148
|
+
* streetSuffix.length;
|
|
132901
133149
|
if (count > maxUniqueStreetnamesNumber) {
|
|
132902
133150
|
throw new RangeError(`count exceeds max number of unique street names(${maxUniqueStreetnamesNumber}).`);
|
|
132903
133151
|
}
|
|
@@ -132922,7 +133170,7 @@ class GenerateUniqueStreetAddress extends AbstractGenerator {
|
|
|
132922
133170
|
minValue: 0,
|
|
132923
133171
|
maxValue: streetNumberStrs.length * lastNames.length * streetSuffix.length - 1,
|
|
132924
133172
|
}),
|
|
132925
|
-
maxUniqueStreetNamesNumber: streetNumberStrs.length *
|
|
133173
|
+
maxUniqueStreetNamesNumber: streetNumberStrs.length * lastNames.length * streetSuffix.length,
|
|
132926
133174
|
count: 0,
|
|
132927
133175
|
arraysToChooseFrom: [streetNumberStrs, lastNames, streetSuffix],
|
|
132928
133176
|
},
|
|
@@ -132976,9 +133224,10 @@ class GenerateCity extends AbstractGenerator {
|
|
|
132976
133224
|
class GenerateUniqueCity extends AbstractGenerator {
|
|
132977
133225
|
static entityKind = 'GenerateUniqueCity';
|
|
132978
133226
|
state;
|
|
132979
|
-
|
|
133227
|
+
isGeneratorUnique = true;
|
|
133228
|
+
maxUniqueCount = cityNames.length;
|
|
132980
133229
|
init({ count, seed }) {
|
|
132981
|
-
if (count >
|
|
133230
|
+
if (count > this.maxUniqueCount) {
|
|
132982
133231
|
throw new Error('count exceeds max number of unique cities.');
|
|
132983
133232
|
}
|
|
132984
133233
|
if (this.typeParams?.length !== undefined && this.typeParams?.length < maxStringLength$9) {
|
|
@@ -133033,11 +133282,11 @@ class GeneratePostcode extends AbstractGenerator {
|
|
|
133033
133282
|
class GenerateUniquePostcode extends AbstractGenerator {
|
|
133034
133283
|
static entityKind = 'GenerateUniquePostcode';
|
|
133035
133284
|
state;
|
|
133036
|
-
|
|
133285
|
+
isGeneratorUnique = true;
|
|
133286
|
+
maxUniqueCount = Math.pow(10, 5) + Math.pow(10, 9);
|
|
133037
133287
|
init({ count, seed }) {
|
|
133038
|
-
|
|
133039
|
-
|
|
133040
|
-
throw new RangeError(`count exceeds max number of unique postcodes(${maxUniquePostcodeNumber}).`);
|
|
133288
|
+
if (count > this.maxUniqueCount) {
|
|
133289
|
+
throw new RangeError(`count exceeds max number of unique postcodes(${this.maxUniqueCount}).`);
|
|
133041
133290
|
}
|
|
133042
133291
|
const rng = prand.xoroshiro128plus(seed);
|
|
133043
133292
|
const templates = [
|
|
@@ -133159,12 +133408,12 @@ class GenerateCompanyName extends AbstractGenerator {
|
|
|
133159
133408
|
class GenerateUniqueCompanyName extends AbstractGenerator {
|
|
133160
133409
|
static entityKind = 'GenerateUniqueCompanyName';
|
|
133161
133410
|
state;
|
|
133162
|
-
|
|
133411
|
+
isGeneratorUnique = true;
|
|
133412
|
+
maxUniqueCount = lastNames.length * companyNameSuffixes.length + Math.pow(lastNames.length, 2)
|
|
133413
|
+
+ Math.pow(lastNames.length, 2) + Math.pow(lastNames.length, 3);
|
|
133163
133414
|
init({ count, seed }) {
|
|
133164
|
-
|
|
133165
|
-
|
|
133166
|
-
if (count > maxUniqueCompanyNameNumber) {
|
|
133167
|
-
throw new RangeError(`count exceeds max number of unique company names(${maxUniqueCompanyNameNumber}).`);
|
|
133415
|
+
if (count > this.maxUniqueCount) {
|
|
133416
|
+
throw new RangeError(`count exceeds max number of unique company names(${this.maxUniqueCount}).`);
|
|
133168
133417
|
}
|
|
133169
133418
|
// max( { template: '#', placeholdersCount: 1 }, { template: '#, # and #', placeholdersCount: 3 } )
|
|
133170
133419
|
const maxCompanyNameLength = Math.max(maxStringLength$3 + maxStringLength$8 + 1, 3 * maxStringLength$3 + 7);
|
|
@@ -133350,22 +133599,29 @@ class GeneratePoint extends AbstractGenerator {
|
|
|
133350
133599
|
class GenerateUniquePoint extends AbstractGenerator {
|
|
133351
133600
|
static entityKind = 'GenerateUniquePoint';
|
|
133352
133601
|
state;
|
|
133353
|
-
|
|
133354
|
-
|
|
133355
|
-
|
|
133356
|
-
|
|
133602
|
+
isGeneratorUnique = true;
|
|
133603
|
+
xCoordinateGen;
|
|
133604
|
+
yCoordinateGen;
|
|
133605
|
+
maxUniqueCount;
|
|
133606
|
+
constructor(params) {
|
|
133607
|
+
super(params);
|
|
133608
|
+
this.xCoordinateGen = new GenerateUniqueNumber({
|
|
133357
133609
|
minValue: this.params.minXValue,
|
|
133358
133610
|
maxValue: this.params.maxXValue,
|
|
133359
133611
|
precision: 10,
|
|
133360
133612
|
});
|
|
133361
|
-
|
|
133362
|
-
const yCoordinateGen = new GenerateUniqueNumber({
|
|
133613
|
+
this.yCoordinateGen = new GenerateUniqueNumber({
|
|
133363
133614
|
minValue: this.params.minYValue,
|
|
133364
133615
|
maxValue: this.params.maxYValue,
|
|
133365
133616
|
precision: 10,
|
|
133366
133617
|
});
|
|
133367
|
-
|
|
133368
|
-
|
|
133618
|
+
this.maxUniqueCount = Math.min(this.xCoordinateGen.maxUniqueCount, this.yCoordinateGen.maxUniqueCount);
|
|
133619
|
+
}
|
|
133620
|
+
init({ count, seed }) {
|
|
133621
|
+
// TODO: rewrite the unique generator to use fastCartesianProduct for generating unique points.
|
|
133622
|
+
this.xCoordinateGen.init({ count, seed });
|
|
133623
|
+
this.yCoordinateGen.init({ count, seed });
|
|
133624
|
+
this.state = { xCoordinateGen: this.xCoordinateGen, yCoordinateGen: this.yCoordinateGen };
|
|
133369
133625
|
}
|
|
133370
133626
|
generate() {
|
|
133371
133627
|
if (this.state === undefined) {
|
|
@@ -133437,28 +133693,40 @@ class GenerateLine extends AbstractGenerator {
|
|
|
133437
133693
|
class GenerateUniqueLine extends AbstractGenerator {
|
|
133438
133694
|
static entityKind = 'GenerateUniqueLine';
|
|
133439
133695
|
state;
|
|
133440
|
-
|
|
133441
|
-
|
|
133442
|
-
|
|
133443
|
-
|
|
133696
|
+
isGeneratorUnique = true;
|
|
133697
|
+
maxUniqueCount;
|
|
133698
|
+
aCoefficientGen;
|
|
133699
|
+
bCoefficientGen;
|
|
133700
|
+
cCoefficientGen;
|
|
133701
|
+
constructor(params) {
|
|
133702
|
+
super(params);
|
|
133703
|
+
this.aCoefficientGen = new GenerateUniqueNumber({
|
|
133444
133704
|
minValue: this.params.minAValue,
|
|
133445
133705
|
maxValue: this.params.maxAValue,
|
|
133446
133706
|
precision: 10,
|
|
133447
133707
|
});
|
|
133448
|
-
|
|
133449
|
-
const bCoefficientGen = new GenerateUniqueNumber({
|
|
133708
|
+
this.bCoefficientGen = new GenerateUniqueNumber({
|
|
133450
133709
|
minValue: this.params.minBValue,
|
|
133451
133710
|
maxValue: this.params.maxBValue,
|
|
133452
133711
|
precision: 10,
|
|
133453
133712
|
});
|
|
133454
|
-
|
|
133455
|
-
const cCoefficientGen = new GenerateUniqueNumber({
|
|
133713
|
+
this.cCoefficientGen = new GenerateUniqueNumber({
|
|
133456
133714
|
minValue: this.params.minCValue,
|
|
133457
133715
|
maxValue: this.params.maxCValue,
|
|
133458
133716
|
precision: 10,
|
|
133459
133717
|
});
|
|
133460
|
-
|
|
133461
|
-
|
|
133718
|
+
this.maxUniqueCount = Math.min(this.aCoefficientGen.maxUniqueCount, this.bCoefficientGen.maxUniqueCount, this.cCoefficientGen.maxUniqueCount);
|
|
133719
|
+
}
|
|
133720
|
+
init({ count, seed }) {
|
|
133721
|
+
// TODO: rewrite the unique generator to use fastCartesianProduct for generating unique triplets(liens).
|
|
133722
|
+
this.aCoefficientGen.init({ count, seed });
|
|
133723
|
+
this.bCoefficientGen.init({ count, seed });
|
|
133724
|
+
this.cCoefficientGen.init({ count, seed });
|
|
133725
|
+
this.state = {
|
|
133726
|
+
aCoefficientGen: this.aCoefficientGen,
|
|
133727
|
+
bCoefficientGen: this.bCoefficientGen,
|
|
133728
|
+
cCoefficientGen: this.cCoefficientGen,
|
|
133729
|
+
};
|
|
133462
133730
|
}
|
|
133463
133731
|
generate() {
|
|
133464
133732
|
if (this.state === undefined) {
|
|
@@ -133516,7 +133784,15 @@ class GenerateUniqueBitString extends AbstractGenerator {
|
|
|
133516
133784
|
static entityKind = 'GenerateUniqueBitString';
|
|
133517
133785
|
dimensions = 11;
|
|
133518
133786
|
state;
|
|
133519
|
-
|
|
133787
|
+
isGeneratorUnique = true;
|
|
133788
|
+
getMaxUniqueCount() {
|
|
133789
|
+
if (this.maxUniqueCount >= 0)
|
|
133790
|
+
return this.maxUniqueCount;
|
|
133791
|
+
this.dimensions = this.params.dimensions ?? this.typeParams?.length ?? this.dimensions;
|
|
133792
|
+
this.maxUniqueCount = Math.pow(2, this.dimensions);
|
|
133793
|
+
// TODO revise: will work incorrect with this.dimensions > 53, due to node js number limitations
|
|
133794
|
+
return this.maxUniqueCount;
|
|
133795
|
+
}
|
|
133520
133796
|
init({ count, seed }) {
|
|
133521
133797
|
this.dimensions = this.params.dimensions ?? this.typeParams?.length ?? this.dimensions;
|
|
133522
133798
|
let intGen;
|
|
@@ -133587,18 +133863,35 @@ class GenerateInet extends AbstractGenerator {
|
|
|
133587
133863
|
}
|
|
133588
133864
|
}
|
|
133589
133865
|
}
|
|
133590
|
-
// TODO: add defaults to js doc
|
|
133591
133866
|
class GenerateUniqueInet extends AbstractGenerator {
|
|
133592
133867
|
static entityKind = 'GenerateUniqueInet';
|
|
133593
133868
|
ipAddress = 'ipv4';
|
|
133594
133869
|
includeCidr = true;
|
|
133595
133870
|
delimiter = '.';
|
|
133596
133871
|
state;
|
|
133597
|
-
|
|
133598
|
-
|
|
133872
|
+
isGeneratorUnique = true;
|
|
133873
|
+
maxUniqueCount;
|
|
133874
|
+
constructor(params) {
|
|
133875
|
+
super(params);
|
|
133599
133876
|
this.ipAddress = this.params.ipAddress ?? this.ipAddress;
|
|
133600
|
-
this.delimiter = this.ipAddress === 'ipv4' ? '.' : ':';
|
|
133601
133877
|
this.includeCidr = this.params.includeCidr ?? this.includeCidr;
|
|
133878
|
+
if (this.ipAddress === 'ipv4') {
|
|
133879
|
+
this.maxUniqueCount = 256 ** 4;
|
|
133880
|
+
if (this.includeCidr) {
|
|
133881
|
+
this.maxUniqueCount *= 33;
|
|
133882
|
+
}
|
|
133883
|
+
}
|
|
133884
|
+
else {
|
|
133885
|
+
// this.ipAddress === 'ipv6'
|
|
133886
|
+
// TODO revise: this.maxUniqueCount can exceed Number.MAX_SAFE_INTEGER
|
|
133887
|
+
this.maxUniqueCount = 65535 ** 8;
|
|
133888
|
+
if (this.includeCidr) {
|
|
133889
|
+
this.maxUniqueCount *= 129;
|
|
133890
|
+
}
|
|
133891
|
+
}
|
|
133892
|
+
}
|
|
133893
|
+
init({ count, seed }) {
|
|
133894
|
+
this.delimiter = this.ipAddress === 'ipv4' ? '.' : ':';
|
|
133602
133895
|
// maxValue - number of combinations for cartesian product: {0…255} × {0…255} × {0…255} × {0…255} × {0…32}
|
|
133603
133896
|
// where pattern for ipv4 ip is {0–255}.{0–255}.{0–255}.{0–255}[/{0–32}?]
|
|
133604
133897
|
// or number of combinations for cartesian product: {0…65535} × {0…65535} × {0…65535} × {0…65535} × {0…65535} × {0…65535} × {0…65535} × {0…65535} × {0…128}
|
|
@@ -133714,11 +134007,42 @@ class GenerateUniqueGeometry extends AbstractGenerator {
|
|
|
133714
134007
|
srid = 4326;
|
|
133715
134008
|
decimalPlaces = 6;
|
|
133716
134009
|
state;
|
|
133717
|
-
|
|
133718
|
-
|
|
134010
|
+
isGeneratorUnique = true;
|
|
134011
|
+
maxUniqueCount;
|
|
134012
|
+
constructor(params) {
|
|
134013
|
+
super(params);
|
|
133719
134014
|
this.type = this.params.type ?? this.type;
|
|
133720
134015
|
this.srid = this.params.srid ?? this.srid;
|
|
133721
134016
|
this.decimalPlaces = this.params.decimalPlaces ?? this.decimalPlaces;
|
|
134017
|
+
let minXValue, maxXValue, minYValue, maxYValue, denominator;
|
|
134018
|
+
if (this.type === 'point') {
|
|
134019
|
+
if (this.srid === 4326) {
|
|
134020
|
+
// Degrees (latitude / longitude)
|
|
134021
|
+
denominator = 10 ** this.decimalPlaces;
|
|
134022
|
+
minXValue = -180 * denominator;
|
|
134023
|
+
maxXValue = 180 * denominator;
|
|
134024
|
+
minYValue = -90 * denominator;
|
|
134025
|
+
maxYValue = 90 * denominator;
|
|
134026
|
+
}
|
|
134027
|
+
else {
|
|
134028
|
+
// this.srid === 3857
|
|
134029
|
+
// Meters (projected X / Y)
|
|
134030
|
+
denominator = 1;
|
|
134031
|
+
minXValue = -20026376;
|
|
134032
|
+
maxXValue = 20026376;
|
|
134033
|
+
minYValue = -20048966;
|
|
134034
|
+
maxYValue = 20048966;
|
|
134035
|
+
}
|
|
134036
|
+
}
|
|
134037
|
+
else {
|
|
134038
|
+
// error should be triggered in init method
|
|
134039
|
+
this.maxUniqueCount = -1;
|
|
134040
|
+
return;
|
|
134041
|
+
}
|
|
134042
|
+
// TODO revise: can lose accuracy due to exceeding Number.MAX_SAFE_INTEGER
|
|
134043
|
+
this.maxUniqueCount = Number(BigInt(maxXValue - minXValue + 1) * BigInt(maxYValue - minYValue + 1));
|
|
134044
|
+
}
|
|
134045
|
+
init({ count, seed }) {
|
|
133722
134046
|
let minXValue, maxXValue, minYValue, maxYValue, denominator;
|
|
133723
134047
|
if (this.type === 'point') {
|
|
133724
134048
|
if (this.srid === 4326) {
|
|
@@ -133825,11 +134149,10 @@ class GenerateUniqueVector extends AbstractGenerator {
|
|
|
133825
134149
|
maxValue = 1000;
|
|
133826
134150
|
decimalPlaces = 2;
|
|
133827
134151
|
state;
|
|
133828
|
-
|
|
133829
|
-
|
|
133830
|
-
|
|
134152
|
+
isGeneratorUnique = true;
|
|
134153
|
+
constructor(params) {
|
|
134154
|
+
super(params);
|
|
133831
134155
|
this.decimalPlaces = this.params.decimalPlaces ?? this.decimalPlaces;
|
|
133832
|
-
const denominator = 10 ** this.decimalPlaces;
|
|
133833
134156
|
this.minValue = this.params.minValue ?? this.minValue;
|
|
133834
134157
|
this.maxValue = this.params.maxValue ?? this.maxValue;
|
|
133835
134158
|
if (this.minValue > this.maxValue) {
|
|
@@ -133839,6 +134162,18 @@ class GenerateUniqueVector extends AbstractGenerator {
|
|
|
133839
134162
|
if (this.decimalPlaces < 0) {
|
|
133840
134163
|
throw new Error(`decimalPlaces value must be greater than or equal to zero.`);
|
|
133841
134164
|
}
|
|
134165
|
+
}
|
|
134166
|
+
getMaxUniqueCount() {
|
|
134167
|
+
if (this.maxUniqueCount >= 0)
|
|
134168
|
+
return this.maxUniqueCount;
|
|
134169
|
+
this.dimensions = this.params.dimensions ?? this.typeParams.length ?? this.dimensions;
|
|
134170
|
+
const denominator = 10 ** this.decimalPlaces;
|
|
134171
|
+
this.maxUniqueCount = (this.maxValue * denominator - this.minValue * denominator + 1) ** this.dimensions;
|
|
134172
|
+
return this.maxUniqueCount;
|
|
134173
|
+
}
|
|
134174
|
+
init({ count, seed }) {
|
|
134175
|
+
this.dimensions = this.params.dimensions ?? this.typeParams.length ?? this.dimensions;
|
|
134176
|
+
const denominator = 10 ** this.decimalPlaces;
|
|
133842
134177
|
if (abs(BigInt(this.minValue) * BigInt(denominator)) > Number.MAX_SAFE_INTEGER
|
|
133843
134178
|
|| abs(BigInt(this.maxValue) * BigInt(denominator)) > Number.MAX_SAFE_INTEGER) {
|
|
133844
134179
|
console.warn(`vector generator: minValue or maxValue multiplied by 10^decimalPlaces exceeds Number.MAX_SAFE_INTEGER (2^53 -1).\n`
|
|
@@ -133874,13 +134209,80 @@ class GenerateUniqueVector extends AbstractGenerator {
|
|
|
133874
134209
|
return vector;
|
|
133875
134210
|
}
|
|
133876
134211
|
}
|
|
134212
|
+
class GenerateCompositeUniqueKey extends AbstractGenerator {
|
|
134213
|
+
static entityKind = 'GenerateCompositeUniqueKey';
|
|
134214
|
+
columnGenerators = [];
|
|
134215
|
+
isInitialized = false;
|
|
134216
|
+
state;
|
|
134217
|
+
addGenerator(columnName, generator) {
|
|
134218
|
+
this.columnGenerators.push({ columnName, generator });
|
|
134219
|
+
}
|
|
134220
|
+
init({ count, seed }) {
|
|
134221
|
+
if (this.isInitialized)
|
|
134222
|
+
return;
|
|
134223
|
+
if (this.columnGenerators.length === 0) {
|
|
134224
|
+
throw new Error(`composite unique key generator has no generators to work with.`);
|
|
134225
|
+
}
|
|
134226
|
+
let countPerGen = Math.ceil(count ** (1 / this.columnGenerators.length));
|
|
134227
|
+
// const gensMaxUniqueCount: { columnName: string; count: number; maxUniqueCount: number }[] = [];
|
|
134228
|
+
for (const colGen of this.columnGenerators) {
|
|
134229
|
+
colGen.maxUniqueCount = colGen.generator.getMaxUniqueCount();
|
|
134230
|
+
}
|
|
134231
|
+
this.columnGenerators.sort((a, b) => a.maxUniqueCount - b.maxUniqueCount);
|
|
134232
|
+
let currCount = count;
|
|
134233
|
+
let canGenerate = false;
|
|
134234
|
+
for (const [idx, colGen] of this.columnGenerators.entries()) {
|
|
134235
|
+
if (colGen.maxUniqueCount < countPerGen) {
|
|
134236
|
+
colGen.count = colGen.maxUniqueCount;
|
|
134237
|
+
currCount /= colGen.count;
|
|
134238
|
+
countPerGen = Math.ceil(currCount ** (1 / (this.columnGenerators.length - idx - 1)));
|
|
134239
|
+
canGenerate = false;
|
|
134240
|
+
}
|
|
134241
|
+
else {
|
|
134242
|
+
colGen.count = countPerGen;
|
|
134243
|
+
canGenerate = true;
|
|
134244
|
+
}
|
|
134245
|
+
}
|
|
134246
|
+
if (!canGenerate) {
|
|
134247
|
+
const colGensCountInfo = this.columnGenerators.map((colGen) => `generator:${colGen.generator.getEntityKind()};count:${colGen.count}`).join('\n');
|
|
134248
|
+
throw new Error(`There are no enough unique values in each generator to generate ${count} values; \n${colGensCountInfo}`);
|
|
134249
|
+
}
|
|
134250
|
+
const sets = [];
|
|
134251
|
+
for (const colGen of this.columnGenerators) {
|
|
134252
|
+
colGen.generator.init({ count: colGen.count, seed });
|
|
134253
|
+
const setI = [];
|
|
134254
|
+
for (let i = 0; i < countPerGen; i++) {
|
|
134255
|
+
setI.push(colGen.generator.generate({ i }));
|
|
134256
|
+
}
|
|
134257
|
+
sets.push(setI);
|
|
134258
|
+
}
|
|
134259
|
+
this.state = { sets, currI: -1, currValue: {} };
|
|
134260
|
+
this.isInitialized = true;
|
|
134261
|
+
}
|
|
134262
|
+
generate({ i, columnName }) {
|
|
134263
|
+
if (this.state === undefined) {
|
|
134264
|
+
throw new Error('state is not defined.');
|
|
134265
|
+
}
|
|
134266
|
+
if (i > this.state.currI) {
|
|
134267
|
+
const rowI = fastCartesianProduct(this.state.sets, i);
|
|
134268
|
+
const newCurrValue = {};
|
|
134269
|
+
for (const [idx, colGen] of this.columnGenerators.entries()) {
|
|
134270
|
+
newCurrValue[colGen.columnName] = rowI[idx];
|
|
134271
|
+
}
|
|
134272
|
+
this.state.currValue = newCurrValue;
|
|
134273
|
+
this.state.currI = i;
|
|
134274
|
+
}
|
|
134275
|
+
return this.state.currValue[columnName];
|
|
134276
|
+
}
|
|
134277
|
+
}
|
|
133877
134278
|
|
|
133878
134279
|
/* eslint-disable drizzle-internal/require-entity-kind */
|
|
133879
134280
|
class GenerateUniqueIntervalV2 extends AbstractGenerator {
|
|
133880
134281
|
static 'entityKind' = 'GenerateUniqueInterval';
|
|
133881
134282
|
static version = 2;
|
|
133882
134283
|
state;
|
|
133883
|
-
|
|
134284
|
+
isGeneratorUnique = true;
|
|
134285
|
+
maxUniqueCount;
|
|
133884
134286
|
config = {
|
|
133885
134287
|
year: {
|
|
133886
134288
|
from: 0,
|
|
@@ -133907,29 +134309,33 @@ class GenerateUniqueIntervalV2 extends AbstractGenerator {
|
|
|
133907
134309
|
to: 59,
|
|
133908
134310
|
},
|
|
133909
134311
|
};
|
|
133910
|
-
|
|
134312
|
+
fieldsToGenerate;
|
|
134313
|
+
constructor(params) {
|
|
134314
|
+
super(params);
|
|
133911
134315
|
const allFields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
|
|
133912
|
-
|
|
134316
|
+
this.fieldsToGenerate = allFields;
|
|
133913
134317
|
if (this.params.fields !== undefined && this.params.fields?.includes(' to ')) {
|
|
133914
134318
|
const tokens = this.params.fields.split(' to ');
|
|
133915
134319
|
const endIdx = allFields.indexOf(tokens[1]);
|
|
133916
|
-
fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
134320
|
+
this.fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
133917
134321
|
}
|
|
133918
134322
|
else if (this.params.fields !== undefined) {
|
|
133919
134323
|
const endIdx = allFields.indexOf(this.params.fields);
|
|
133920
|
-
fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
134324
|
+
this.fieldsToGenerate = allFields.slice(0, endIdx + 1);
|
|
133921
134325
|
}
|
|
133922
|
-
|
|
133923
|
-
for (const field of fieldsToGenerate) {
|
|
134326
|
+
this.maxUniqueCount = 1;
|
|
134327
|
+
for (const field of this.fieldsToGenerate) {
|
|
133924
134328
|
const from = this.config[field].from, to = this.config[field].to;
|
|
133925
|
-
|
|
134329
|
+
this.maxUniqueCount *= from - to + 1;
|
|
133926
134330
|
}
|
|
133927
|
-
|
|
133928
|
-
|
|
134331
|
+
}
|
|
134332
|
+
init({ count, seed }) {
|
|
134333
|
+
if (count > this.maxUniqueCount) {
|
|
134334
|
+
throw new RangeError(`count exceeds max number of unique intervals(${this.maxUniqueCount})`);
|
|
133929
134335
|
}
|
|
133930
134336
|
const rng = prand.xoroshiro128plus(seed);
|
|
133931
134337
|
const intervalSet = new Set();
|
|
133932
|
-
this.state = { rng, fieldsToGenerate, intervalSet };
|
|
134338
|
+
this.state = { rng, fieldsToGenerate: this.fieldsToGenerate, intervalSet };
|
|
133933
134339
|
}
|
|
133934
134340
|
generate() {
|
|
133935
134341
|
if (this.state === undefined) {
|
|
@@ -133951,6 +134357,7 @@ class GenerateUniqueIntervalV2 extends AbstractGenerator {
|
|
|
133951
134357
|
return interval;
|
|
133952
134358
|
}
|
|
133953
134359
|
}
|
|
134360
|
+
// TODO need to rework this generator
|
|
133954
134361
|
class GenerateStringV2 extends AbstractGenerator {
|
|
133955
134362
|
static 'entityKind' = 'GenerateString';
|
|
133956
134363
|
static version = 2;
|
|
@@ -133992,21 +134399,27 @@ class GenerateUniqueStringV2 extends AbstractGenerator {
|
|
|
133992
134399
|
static 'entityKind' = 'GenerateUniqueString';
|
|
133993
134400
|
static version = 2;
|
|
133994
134401
|
state;
|
|
133995
|
-
|
|
134402
|
+
isGeneratorUnique = true;
|
|
134403
|
+
maxStringLength = 20;
|
|
134404
|
+
minStringLength = 7;
|
|
134405
|
+
getMaxUniqueCount() {
|
|
134406
|
+
if (this.maxUniqueCount >= 0)
|
|
134407
|
+
return this.maxUniqueCount;
|
|
134408
|
+
this.maxStringLength = this.typeParams?.length ?? this.maxStringLength;
|
|
134409
|
+
this.maxUniqueCount = Number.parseInt('f'.repeat(this.maxStringLength), 16);
|
|
134410
|
+
return this.maxUniqueCount;
|
|
134411
|
+
}
|
|
133996
134412
|
init({ seed, count }) {
|
|
133997
134413
|
const rng = prand.xoroshiro128plus(seed);
|
|
133998
|
-
let minStringLength = 7;
|
|
133999
|
-
let maxStringLength = 20;
|
|
134000
134414
|
// TODO: revise later
|
|
134001
|
-
|
|
134002
|
-
|
|
134003
|
-
|
|
134004
|
-
minStringLength = maxStringLength;
|
|
134415
|
+
this.maxStringLength = this.typeParams?.length ?? this.maxStringLength;
|
|
134416
|
+
if (this.maxStringLength === 1 || this.maxStringLength < this.minStringLength) {
|
|
134417
|
+
this.minStringLength = this.maxStringLength;
|
|
134005
134418
|
}
|
|
134006
|
-
if (
|
|
134007
|
-
throw new Error(`You can't generate ${count} unique strings, with a maximum string length of ${maxStringLength}.`);
|
|
134419
|
+
if (count > this.getMaxUniqueCount()) {
|
|
134420
|
+
throw new Error(`You can't generate ${count} unique strings, with a maximum string length of ${this.maxStringLength}.`);
|
|
134008
134421
|
}
|
|
134009
|
-
this.state = { rng, minStringLength, maxStringLength };
|
|
134422
|
+
this.state = { rng, minStringLength: this.minStringLength, maxStringLength: this.maxStringLength };
|
|
134010
134423
|
}
|
|
134011
134424
|
generate({ i }) {
|
|
134012
134425
|
if (this.state === undefined) {
|
|
@@ -134029,6 +134442,25 @@ class GenerateUniqueStringV2 extends AbstractGenerator {
|
|
|
134029
134442
|
}
|
|
134030
134443
|
}
|
|
134031
134444
|
|
|
134445
|
+
/* eslint-disable drizzle-internal/require-entity-kind */
|
|
134446
|
+
class GenerateHashFromStringV3 extends AbstractGenerator {
|
|
134447
|
+
static entityKind = 'GenerateHashFromString';
|
|
134448
|
+
static version = 3;
|
|
134449
|
+
init() { }
|
|
134450
|
+
generate({ input }) {
|
|
134451
|
+
let hash = 0n;
|
|
134452
|
+
// p and m are prime numbers
|
|
134453
|
+
const p = 53n;
|
|
134454
|
+
const m = 28871271685163n; // < 2^53
|
|
134455
|
+
let power = 1n; // will track p^i, where i is character index
|
|
134456
|
+
for (const ch of input) {
|
|
134457
|
+
hash = (hash + (BigInt(ch.codePointAt(0) || 0) * power)) % m;
|
|
134458
|
+
power = (power * p) % m;
|
|
134459
|
+
}
|
|
134460
|
+
return Number(hash);
|
|
134461
|
+
}
|
|
134462
|
+
}
|
|
134463
|
+
|
|
134032
134464
|
function createGenerator(generatorConstructor) {
|
|
134033
134465
|
return (...args) => {
|
|
134034
134466
|
let params = args[0];
|
|
@@ -134824,7 +135256,14 @@ const generatorsFuncs = {
|
|
|
134824
135256
|
const generatorsFuncsV2 = {
|
|
134825
135257
|
...generatorsFuncs,
|
|
134826
135258
|
};
|
|
135259
|
+
({
|
|
135260
|
+
...generatorsFuncs,
|
|
135261
|
+
});
|
|
134827
135262
|
const generatorsMap = {
|
|
135263
|
+
GenerateHashFromString: [
|
|
135264
|
+
GenerateHashFromString,
|
|
135265
|
+
GenerateHashFromStringV3,
|
|
135266
|
+
],
|
|
134828
135267
|
HollowGenerator: [
|
|
134829
135268
|
HollowGenerator,
|
|
134830
135269
|
],
|
|
@@ -135002,6 +135441,9 @@ const generatorsMap = {
|
|
|
135002
135441
|
GenerateUniqueVector: [
|
|
135003
135442
|
GenerateUniqueVector,
|
|
135004
135443
|
],
|
|
135444
|
+
GenerateCompositeUniqueKey: [
|
|
135445
|
+
GenerateCompositeUniqueKey,
|
|
135446
|
+
],
|
|
135005
135447
|
};
|
|
135006
135448
|
|
|
135007
135449
|
// TODO: revise serial part generators
|
|
@@ -135220,7 +135662,7 @@ const selectGeneratorForCockroachColumn = (table, col) => {
|
|
|
135220
135662
|
return generator;
|
|
135221
135663
|
};
|
|
135222
135664
|
|
|
135223
|
-
const latestVersion =
|
|
135665
|
+
const latestVersion = 3;
|
|
135224
135666
|
|
|
135225
135667
|
const selectGeneratorForMssqlColumn = (table, col) => {
|
|
135226
135668
|
const pickGenerator = (table, col) => {
|
|
@@ -136069,6 +136511,7 @@ class SeedService {
|
|
|
136069
136511
|
sqliteMaxParametersNumber = 32766;
|
|
136070
136512
|
mssqlMaxParametersNumber = 2100;
|
|
136071
136513
|
version;
|
|
136514
|
+
hashFromStringGenerator;
|
|
136072
136515
|
generatePossibleGenerators = (connectionType, tables, relations, refinements, options) => {
|
|
136073
136516
|
let columnPossibleGenerator;
|
|
136074
136517
|
let tablePossibleGenerators;
|
|
@@ -136077,6 +136520,7 @@ class SeedService {
|
|
|
136077
136520
|
if (Number.isNaN(this.version) || this.version < 1 || this.version > latestVersion) {
|
|
136078
136521
|
throw new Error(`Version should be in range [1, ${latestVersion}].`);
|
|
136079
136522
|
}
|
|
136523
|
+
this.hashFromStringGenerator = this.selectVersionOfGenerator(new generatorsMap.GenerateHashFromString[0]());
|
|
136080
136524
|
// sorting table in order which they will be filled up (tables with foreign keys case)
|
|
136081
136525
|
const { tablesInOutRelations } = this.getInfoFromRelations(relations);
|
|
136082
136526
|
const orderedTablesNames = this.getOrderedTablesList(tablesInOutRelations);
|
|
@@ -136096,6 +136540,7 @@ class SeedService {
|
|
|
136096
136540
|
withFromTable: {},
|
|
136097
136541
|
}));
|
|
136098
136542
|
for (const [i, table] of tables.entries()) {
|
|
136543
|
+
const compositeUniqueKeyGenMap = {};
|
|
136099
136544
|
// get foreignKey columns relations
|
|
136100
136545
|
const foreignKeyColumns = {};
|
|
136101
136546
|
for (const rel of relations
|
|
@@ -136137,7 +136582,7 @@ class SeedService {
|
|
|
136137
136582
|
const weightedRepeatedValuesCount = refinements[table.name]
|
|
136138
136583
|
.with[fkTableName];
|
|
136139
136584
|
weightedCountSeed = customSeed
|
|
136140
|
-
+
|
|
136585
|
+
+ this.hashFromStringGenerator.generate({ input: `${table.name}.${fkTableName}` });
|
|
136141
136586
|
newTableWithCount = this.getWeightedWithCount(weightedRepeatedValuesCount, (tablesPossibleGenerators[i].withCount
|
|
136142
136587
|
|| tablesPossibleGenerators[i].count), weightedCountSeed);
|
|
136143
136588
|
}
|
|
@@ -136173,6 +136618,18 @@ class SeedService {
|
|
|
136173
136618
|
&& refinements[table.name].columns !== undefined
|
|
136174
136619
|
&& refinements[table.name].columns[col.name] !== undefined) {
|
|
136175
136620
|
const genObj = refinements[table.name].columns[col.name];
|
|
136621
|
+
if (genObj === false) {
|
|
136622
|
+
if (col.notNull === true && col.hasDefault === false) {
|
|
136623
|
+
throw new Error(`You cannot set the '${col.name}' column in the '${table.name}' table to false in your refinements.`
|
|
136624
|
+
+ `\nDoing so will result in a null value being inserted into the '${col.name}' column,`
|
|
136625
|
+
+ `\nwhich will cause an error because the column has a not null constraint and no default value.`);
|
|
136626
|
+
}
|
|
136627
|
+
// Generating undefined as a value for a column and then inserting it via drizzle-orm
|
|
136628
|
+
// will result in the value not being inserted into that column.
|
|
136629
|
+
columnPossibleGenerator.generator = new generatorsMap.GenerateDefault[0]({ defaultValue: undefined });
|
|
136630
|
+
columnPossibleGenerator.wasRefined = true;
|
|
136631
|
+
continue;
|
|
136632
|
+
}
|
|
136176
136633
|
if (col.columnType.match(/\[\w*]/g) !== null) {
|
|
136177
136634
|
if ((col.baseColumn?.dataType === 'array' && col.baseColumn.columnType.match(/\[\w*]/g) !== null)
|
|
136178
136635
|
// studio case
|
|
@@ -136244,16 +136701,66 @@ class SeedService {
|
|
|
136244
136701
|
columnPossibleGenerator.generator = arrayGen;
|
|
136245
136702
|
}
|
|
136246
136703
|
columnPossibleGenerator.generator.isUnique = col.isUnique;
|
|
136704
|
+
// composite unique keys handling
|
|
136705
|
+
let compositeKeyColumnNames = table.uniqueConstraints.filter((colNames) => colNames.includes(col.name));
|
|
136706
|
+
if (compositeKeyColumnNames.some((colNames) => colNames.length === 1)) {
|
|
136707
|
+
// composite unique key contains only one column, therefore it equals to just unique column
|
|
136708
|
+
columnPossibleGenerator.generator.isUnique = true;
|
|
136709
|
+
}
|
|
136710
|
+
// removing column from composite unique keys if current column is unique
|
|
136711
|
+
if (columnPossibleGenerator.generator.isUnique && compositeKeyColumnNames.length > 0) {
|
|
136712
|
+
const newUniqueConstraints = [];
|
|
136713
|
+
for (const colNames of table.uniqueConstraints) {
|
|
136714
|
+
if (colNames.includes(col.name)) {
|
|
136715
|
+
const newColNames = colNames.filter((colName) => colName !== col.name);
|
|
136716
|
+
if (newColNames.length === 0)
|
|
136717
|
+
continue;
|
|
136718
|
+
newUniqueConstraints.push(newColNames);
|
|
136719
|
+
}
|
|
136720
|
+
else {
|
|
136721
|
+
newUniqueConstraints.push(colNames);
|
|
136722
|
+
}
|
|
136723
|
+
}
|
|
136724
|
+
table.uniqueConstraints = newUniqueConstraints;
|
|
136725
|
+
}
|
|
136726
|
+
compositeKeyColumnNames = table.uniqueConstraints.filter((colNames) => colNames.includes(col.name));
|
|
136727
|
+
if (compositeKeyColumnNames.length > 1) {
|
|
136728
|
+
throw new Error('Currently, multiple composite unique keys that share the same column are not supported.');
|
|
136729
|
+
}
|
|
136730
|
+
// to handle composite unique key generation, I will need a unique generator for each column in the composite key
|
|
136731
|
+
if (compositeKeyColumnNames.length === 1) {
|
|
136732
|
+
if (columnPossibleGenerator.generator.params.isUnique === false) {
|
|
136733
|
+
throw new Error(`To handle the composite unique key on columns: ${compositeKeyColumnNames[0]}, `
|
|
136734
|
+
+ `column: ${col.name} should either be assigned a generator with isUnique set to true, or have isUnique omitted.`);
|
|
136735
|
+
}
|
|
136736
|
+
columnPossibleGenerator.generator.params.isUnique = true;
|
|
136737
|
+
}
|
|
136247
136738
|
const uniqueGen = columnPossibleGenerator.generator.replaceIfUnique();
|
|
136248
136739
|
if (uniqueGen !== undefined) {
|
|
136249
136740
|
columnPossibleGenerator.generator = uniqueGen;
|
|
136250
136741
|
}
|
|
136742
|
+
if (compositeKeyColumnNames.length === 1 && !columnPossibleGenerator.generator.isGeneratorUnique
|
|
136743
|
+
&& !(columnPossibleGenerator.generator.getEntityKind() === 'GenerateValuesFromArray')) {
|
|
136744
|
+
throw new Error(`To handle the composite unique key on columns: ${compositeKeyColumnNames[0]}, `
|
|
136745
|
+
+ `column: ${col.name} should be assigned a generator with its own unique version.`);
|
|
136746
|
+
}
|
|
136251
136747
|
// selecting version of generator
|
|
136252
136748
|
columnPossibleGenerator.generator = this.selectVersionOfGenerator(columnPossibleGenerator.generator);
|
|
136253
136749
|
// TODO: for now only GenerateValuesFromArray support notNull property
|
|
136254
136750
|
columnPossibleGenerator.generator.notNull = col.notNull;
|
|
136255
136751
|
columnPossibleGenerator.generator.dataType = col.dataType;
|
|
136256
|
-
//
|
|
136752
|
+
// assigning composite key generator
|
|
136753
|
+
if (compositeKeyColumnNames.length === 1) {
|
|
136754
|
+
const key = compositeKeyColumnNames[0].join('_');
|
|
136755
|
+
if (compositeUniqueKeyGenMap[key] === undefined) {
|
|
136756
|
+
let compositeUniqueKeyGen = new generatorsMap.GenerateCompositeUniqueKey[0]();
|
|
136757
|
+
compositeUniqueKeyGen.uniqueKey = key;
|
|
136758
|
+
compositeUniqueKeyGen = this.selectVersionOfGenerator(compositeUniqueKeyGen);
|
|
136759
|
+
compositeUniqueKeyGenMap[key] = compositeUniqueKeyGen;
|
|
136760
|
+
}
|
|
136761
|
+
compositeUniqueKeyGenMap[key].addGenerator(col.name, columnPossibleGenerator.generator);
|
|
136762
|
+
columnPossibleGenerator.generator = compositeUniqueKeyGenMap[key];
|
|
136763
|
+
}
|
|
136257
136764
|
tablePossibleGenerators.columnsPossibleGenerators.push(columnPossibleGenerator);
|
|
136258
136765
|
}
|
|
136259
136766
|
}
|
|
@@ -136282,6 +136789,7 @@ class SeedService {
|
|
|
136282
136789
|
newGenerator.dataType = generator.dataType;
|
|
136283
136790
|
// newGenerator.stringLength = generator.stringLength;
|
|
136284
136791
|
newGenerator.typeParams = generator.typeParams ?? newGenerator.typeParams;
|
|
136792
|
+
newGenerator.uniqueKey = generator.uniqueKey;
|
|
136285
136793
|
return newGenerator;
|
|
136286
136794
|
};
|
|
136287
136795
|
cyclicTablesCompare = (table1, table2, relation, reverseRelation) => {
|
|
@@ -136442,8 +136950,13 @@ class SeedService {
|
|
|
136442
136950
|
const columnRelations = filteredRelations.filter((rel) => rel.columns.includes(col.columnName));
|
|
136443
136951
|
pRNGSeed = (columnRelations.length !== 0
|
|
136444
136952
|
&& columnRelations[0].columns.length >= 2)
|
|
136445
|
-
? (customSeed
|
|
136446
|
-
|
|
136953
|
+
? (customSeed
|
|
136954
|
+
+ this.hashFromStringGenerator.generate({
|
|
136955
|
+
input: `${columnRelations[0].table}.${columnRelations[0].columns.join('_')}`,
|
|
136956
|
+
}))
|
|
136957
|
+
: col.generator?.uniqueKey === undefined
|
|
136958
|
+
? (customSeed + this.hashFromStringGenerator.generate({ input: `${table.tableName}.${col.columnName}` }))
|
|
136959
|
+
: (customSeed + this.hashFromStringGenerator.generate({ input: col.generator.uniqueKey }));
|
|
136447
136960
|
tableGenerators[col.columnName] = {
|
|
136448
136961
|
pRNGSeed,
|
|
136449
136962
|
...col,
|
|
@@ -136465,7 +136978,9 @@ class SeedService {
|
|
|
136465
136978
|
if (rel.table === rel.refTable
|
|
136466
136979
|
&& tableGenerators[rel.columns[colIdx]]?.wasRefined === false) {
|
|
136467
136980
|
const refColName = rel.refColumns[colIdx];
|
|
136468
|
-
pRNGSeed =
|
|
136981
|
+
pRNGSeed = this.hashFromStringGenerator.generate({
|
|
136982
|
+
input: `${table.tableName}.${refColName}`,
|
|
136983
|
+
});
|
|
136469
136984
|
const refColumnGenerator = {};
|
|
136470
136985
|
refColumnGenerator[refColName] = {
|
|
136471
136986
|
...tableGenerators[refColName],
|
|
@@ -136614,11 +137129,7 @@ class SeedService {
|
|
|
136614
137129
|
row = {};
|
|
136615
137130
|
generatedValues.push(row);
|
|
136616
137131
|
for (const columnName of Object.keys(columnsGenerators)) {
|
|
136617
|
-
|
|
136618
|
-
// | string
|
|
136619
|
-
// | number
|
|
136620
|
-
// | boolean;
|
|
136621
|
-
generatedValue = columnsGenerators[columnName].generate({ i });
|
|
137132
|
+
generatedValue = columnsGenerators[columnName].generate({ i, columnName });
|
|
136622
137133
|
row[columnName] = generatedValue;
|
|
136623
137134
|
}
|
|
136624
137135
|
if ((insertDataInDb === true || updateDataInDb === true)
|
|
@@ -136765,7 +137276,7 @@ const filterCockroachSchema = (schema) => {
|
|
|
136765
137276
|
const seedCockroach = async (db, schema, options = {}, refinements) => {
|
|
136766
137277
|
const seedService = new SeedService();
|
|
136767
137278
|
const { cockroachSchema, cockroachTables } = filterCockroachSchema(schema);
|
|
136768
|
-
const { tables, relations } = getSchemaInfo(cockroachSchema, cockroachTables,
|
|
137279
|
+
const { tables, relations } = getSchemaInfo(cockroachSchema, cockroachTables, mapCockroachColumns);
|
|
136769
137280
|
const generatedTablesGenerators = seedService.generatePossibleGenerators('cockroach', tables, relations, refinements, options);
|
|
136770
137281
|
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
136771
137282
|
const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, cockroachTables, { ...options, preserveCyclicTablesData });
|
|
@@ -136773,7 +137284,7 @@ const seedCockroach = async (db, schema, options = {}, refinements) => {
|
|
|
136773
137284
|
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
136774
137285
|
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, cockroachTables, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
136775
137286
|
};
|
|
136776
|
-
const
|
|
137287
|
+
const mapCockroachColumns = (tableConfig, dbToTsColumnNamesMap) => {
|
|
136777
137288
|
const getAllBaseColumns = (baseColumn) => {
|
|
136778
137289
|
const baseColumnResult = {
|
|
136779
137290
|
name: baseColumn.name,
|
|
@@ -136825,30 +137336,24 @@ const mapCockroachTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNamesMa
|
|
|
136825
137336
|
}
|
|
136826
137337
|
return typeParams;
|
|
136827
137338
|
};
|
|
136828
|
-
|
|
136829
|
-
|
|
136830
|
-
|
|
136831
|
-
|
|
136832
|
-
|
|
136833
|
-
|
|
136834
|
-
|
|
136835
|
-
|
|
136836
|
-
|
|
136837
|
-
|
|
136838
|
-
|
|
136839
|
-
|
|
136840
|
-
|
|
136841
|
-
|
|
136842
|
-
|
|
136843
|
-
|
|
136844
|
-
|
|
136845
|
-
|
|
136846
|
-
: getAllBaseColumns(column.baseColumn),
|
|
136847
|
-
})),
|
|
136848
|
-
primaryKeys: tableConfig.columns
|
|
136849
|
-
.filter((column) => column.primary)
|
|
136850
|
-
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
136851
|
-
};
|
|
137339
|
+
const mappedColumns = tableConfig.columns.map((column) => ({
|
|
137340
|
+
name: dbToTsColumnNamesMap[column.name],
|
|
137341
|
+
columnType: column.getSQLType(),
|
|
137342
|
+
typeParams: getTypeParams(column.getSQLType()),
|
|
137343
|
+
dataType: column.dataType.split(' ')[0],
|
|
137344
|
+
size: column.length,
|
|
137345
|
+
hasDefault: column.hasDefault,
|
|
137346
|
+
default: column.default,
|
|
137347
|
+
enumValues: column.enumValues,
|
|
137348
|
+
isUnique: column.isUnique,
|
|
137349
|
+
notNull: column.notNull,
|
|
137350
|
+
primary: column.primary,
|
|
137351
|
+
generatedIdentityType: column.generatedIdentity?.type,
|
|
137352
|
+
baseColumn: (column.baseColumn === undefined)
|
|
137353
|
+
? undefined
|
|
137354
|
+
: getAllBaseColumns(column.baseColumn),
|
|
137355
|
+
}));
|
|
137356
|
+
return mappedColumns;
|
|
136852
137357
|
};
|
|
136853
137358
|
|
|
136854
137359
|
// MySql-----------------------------------------------------------------------------------------------------
|
|
@@ -136937,7 +137442,7 @@ const filterMsSqlTables = (schema) => {
|
|
|
136937
137442
|
};
|
|
136938
137443
|
const seedMsSql = async (db, schema, options = {}, refinements) => {
|
|
136939
137444
|
const { mssqlSchema, mssqlTables } = filterMsSqlTables(schema);
|
|
136940
|
-
const { tables, relations } = getSchemaInfo(mssqlSchema, mssqlTables,
|
|
137445
|
+
const { tables, relations } = getSchemaInfo(mssqlSchema, mssqlTables, mapMsSqlColumns);
|
|
136941
137446
|
const seedService = new SeedService();
|
|
136942
137447
|
const generatedTablesGenerators = seedService.generatePossibleGenerators('mssql', tables, relations, refinements, options);
|
|
136943
137448
|
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
@@ -136946,7 +137451,7 @@ const seedMsSql = async (db, schema, options = {}, refinements) => {
|
|
|
136946
137451
|
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
136947
137452
|
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, mssqlTables, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
136948
137453
|
};
|
|
136949
|
-
const
|
|
137454
|
+
const mapMsSqlColumns = (tableConfig, dbToTsColumnNamesMap) => {
|
|
136950
137455
|
// TODO: rewrite
|
|
136951
137456
|
const getTypeParams = (sqlType) => {
|
|
136952
137457
|
// get type params and set only type
|
|
@@ -136971,25 +137476,20 @@ const mapMsSqlTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNamesMap) =
|
|
|
136971
137476
|
}
|
|
136972
137477
|
return typeParams;
|
|
136973
137478
|
};
|
|
136974
|
-
|
|
136975
|
-
name:
|
|
136976
|
-
|
|
136977
|
-
|
|
136978
|
-
|
|
136979
|
-
|
|
136980
|
-
|
|
136981
|
-
|
|
136982
|
-
|
|
136983
|
-
|
|
136984
|
-
|
|
136985
|
-
|
|
136986
|
-
|
|
136987
|
-
|
|
136988
|
-
})),
|
|
136989
|
-
primaryKeys: tableConfig.columns
|
|
136990
|
-
.filter((column) => column.primary)
|
|
136991
|
-
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
136992
|
-
};
|
|
137479
|
+
const mappedColumns = tableConfig.columns.map((column) => ({
|
|
137480
|
+
name: dbToTsColumnNamesMap[column.name],
|
|
137481
|
+
columnType: column.getSQLType(),
|
|
137482
|
+
typeParams: getTypeParams(column.getSQLType()),
|
|
137483
|
+
dataType: column.dataType.split(' ')[0],
|
|
137484
|
+
hasDefault: column.hasDefault,
|
|
137485
|
+
default: column.default,
|
|
137486
|
+
enumValues: column.enumValues,
|
|
137487
|
+
isUnique: column.isUnique,
|
|
137488
|
+
notNull: column.notNull,
|
|
137489
|
+
primary: column.primary,
|
|
137490
|
+
identity: column.identity ? true : false,
|
|
137491
|
+
}));
|
|
137492
|
+
return mappedColumns;
|
|
136993
137493
|
};
|
|
136994
137494
|
|
|
136995
137495
|
// MySql-----------------------------------------------------------------------------------------------------
|
|
@@ -137012,7 +137512,7 @@ const filterMysqlTables = (schema) => {
|
|
|
137012
137512
|
};
|
|
137013
137513
|
const seedMySql = async (db, schema, options = {}, refinements) => {
|
|
137014
137514
|
const { mysqlSchema, mysqlTables } = filterMysqlTables(schema);
|
|
137015
|
-
const { tables, relations } = getSchemaInfo(mysqlSchema, mysqlTables,
|
|
137515
|
+
const { tables, relations } = getSchemaInfo(mysqlSchema, mysqlTables, mapMySqlColumns);
|
|
137016
137516
|
const seedService = new SeedService();
|
|
137017
137517
|
const generatedTablesGenerators = seedService.generatePossibleGenerators('mysql', tables, relations, refinements, options);
|
|
137018
137518
|
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
@@ -137021,7 +137521,7 @@ const seedMySql = async (db, schema, options = {}, refinements) => {
|
|
|
137021
137521
|
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
137022
137522
|
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, mysqlTables, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
137023
137523
|
};
|
|
137024
|
-
const
|
|
137524
|
+
const mapMySqlColumns = (tableConfig, dbToTsColumnNamesMap) => {
|
|
137025
137525
|
const getTypeParams = (sqlType) => {
|
|
137026
137526
|
// get type params and set only type
|
|
137027
137527
|
const typeParams = {};
|
|
@@ -137046,24 +137546,19 @@ const mapMySqlTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNamesMap) =
|
|
|
137046
137546
|
}
|
|
137047
137547
|
return typeParams;
|
|
137048
137548
|
};
|
|
137049
|
-
|
|
137050
|
-
name:
|
|
137051
|
-
|
|
137052
|
-
|
|
137053
|
-
|
|
137054
|
-
|
|
137055
|
-
|
|
137056
|
-
|
|
137057
|
-
|
|
137058
|
-
|
|
137059
|
-
|
|
137060
|
-
|
|
137061
|
-
|
|
137062
|
-
})),
|
|
137063
|
-
primaryKeys: tableConfig.columns
|
|
137064
|
-
.filter((column) => column.primary)
|
|
137065
|
-
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
137066
|
-
};
|
|
137549
|
+
const mappedColumns = tableConfig.columns.map((column) => ({
|
|
137550
|
+
name: dbToTsColumnNamesMap[column.name],
|
|
137551
|
+
columnType: column.getSQLType(),
|
|
137552
|
+
typeParams: getTypeParams(column.getSQLType()),
|
|
137553
|
+
dataType: column.dataType.split(' ')[0],
|
|
137554
|
+
hasDefault: column.hasDefault,
|
|
137555
|
+
default: column.default,
|
|
137556
|
+
enumValues: column.enumValues,
|
|
137557
|
+
isUnique: column.isUnique,
|
|
137558
|
+
notNull: column.notNull,
|
|
137559
|
+
primary: column.primary,
|
|
137560
|
+
}));
|
|
137561
|
+
return mappedColumns;
|
|
137067
137562
|
};
|
|
137068
137563
|
|
|
137069
137564
|
// Postgres-----------------------------------------------------------------------------------------------------------
|
|
@@ -137083,7 +137578,7 @@ const filterPgSchema = (schema) => {
|
|
|
137083
137578
|
const seedPostgres = async (db, schema, options = {}, refinements) => {
|
|
137084
137579
|
const seedService = new SeedService();
|
|
137085
137580
|
const { pgSchema, pgTables } = filterPgSchema(schema);
|
|
137086
|
-
const { tables, relations } = getSchemaInfo(pgSchema, pgTables,
|
|
137581
|
+
const { tables, relations } = getSchemaInfo(pgSchema, pgTables, mapPgColumns);
|
|
137087
137582
|
// const { tables, relations } = getPostgresInfo(pgSchema, pgTables);
|
|
137088
137583
|
const generatedTablesGenerators = seedService.generatePossibleGenerators('postgresql', tables, relations, refinements, options);
|
|
137089
137584
|
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
@@ -137092,7 +137587,7 @@ const seedPostgres = async (db, schema, options = {}, refinements) => {
|
|
|
137092
137587
|
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
137093
137588
|
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, pgTables, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
137094
137589
|
};
|
|
137095
|
-
const
|
|
137590
|
+
const mapPgColumns = (tableConfig, dbToTsColumnNamesMap) => {
|
|
137096
137591
|
const getAllBaseColumns = (baseColumn) => {
|
|
137097
137592
|
const baseColumnResult = {
|
|
137098
137593
|
name: baseColumn.name,
|
|
@@ -137145,29 +137640,24 @@ const mapPgTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNamesMap) => {
|
|
|
137145
137640
|
}
|
|
137146
137641
|
return typeParams;
|
|
137147
137642
|
};
|
|
137148
|
-
|
|
137149
|
-
name:
|
|
137150
|
-
|
|
137151
|
-
|
|
137152
|
-
|
|
137153
|
-
|
|
137154
|
-
|
|
137155
|
-
|
|
137156
|
-
|
|
137157
|
-
|
|
137158
|
-
|
|
137159
|
-
|
|
137160
|
-
|
|
137161
|
-
|
|
137162
|
-
|
|
137163
|
-
|
|
137164
|
-
|
|
137165
|
-
|
|
137166
|
-
})),
|
|
137167
|
-
primaryKeys: tableConfig.columns
|
|
137168
|
-
.filter((column) => column.primary)
|
|
137169
|
-
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
137170
|
-
};
|
|
137643
|
+
const mappedColumns = tableConfig.columns.map((column) => ({
|
|
137644
|
+
name: dbToTsColumnNamesMap[column.name],
|
|
137645
|
+
columnType: column.getSQLType(),
|
|
137646
|
+
typeParams: getTypeParams(column.getSQLType()),
|
|
137647
|
+
dataType: column.dataType.split(' ')[0],
|
|
137648
|
+
size: column.length,
|
|
137649
|
+
hasDefault: column.hasDefault,
|
|
137650
|
+
default: column.default,
|
|
137651
|
+
enumValues: column.enumValues,
|
|
137652
|
+
isUnique: column.isUnique,
|
|
137653
|
+
notNull: column.notNull,
|
|
137654
|
+
primary: column.primary,
|
|
137655
|
+
generatedIdentityType: column.generatedIdentity?.type,
|
|
137656
|
+
baseColumn: (column.baseColumn === undefined)
|
|
137657
|
+
? undefined
|
|
137658
|
+
: getAllBaseColumns(column.baseColumn),
|
|
137659
|
+
}));
|
|
137660
|
+
return mappedColumns;
|
|
137171
137661
|
};
|
|
137172
137662
|
|
|
137173
137663
|
// SingleStore-----------------------------------------------------------------------------------------------------
|
|
@@ -137190,7 +137680,7 @@ const filterSingleStoreTables = (schema) => {
|
|
|
137190
137680
|
};
|
|
137191
137681
|
const seedSingleStore = async (db, schema, options = {}, refinements) => {
|
|
137192
137682
|
const { singleStoreSchema, singleStoreTables } = filterSingleStoreTables(schema);
|
|
137193
|
-
const { tables, relations } = getSchemaInfo(singleStoreSchema, singleStoreTables,
|
|
137683
|
+
const { tables, relations } = getSchemaInfo(singleStoreSchema, singleStoreTables, mapSingleStoreColumns);
|
|
137194
137684
|
const seedService = new SeedService();
|
|
137195
137685
|
const generatedTablesGenerators = seedService.generatePossibleGenerators('singlestore', tables, relations, refinements, options);
|
|
137196
137686
|
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
@@ -137199,7 +137689,7 @@ const seedSingleStore = async (db, schema, options = {}, refinements) => {
|
|
|
137199
137689
|
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
137200
137690
|
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, singleStoreTables, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
137201
137691
|
};
|
|
137202
|
-
const
|
|
137692
|
+
const mapSingleStoreColumns = (tableConfig, dbToTsColumnNamesMap) => {
|
|
137203
137693
|
const getTypeParams = (sqlType) => {
|
|
137204
137694
|
// get type params and set only type
|
|
137205
137695
|
const typeParams = {};
|
|
@@ -137215,6 +137705,7 @@ const mapSingleStoreTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNames
|
|
|
137215
137705
|
}
|
|
137216
137706
|
else if (sqlType.startsWith('char')
|
|
137217
137707
|
|| sqlType.startsWith('varchar')
|
|
137708
|
+
|| sqlType.startsWith('text')
|
|
137218
137709
|
|| sqlType.startsWith('binary')
|
|
137219
137710
|
|| sqlType.startsWith('varbinary')) {
|
|
137220
137711
|
const match = sqlType.match(/\((\d+)\)/);
|
|
@@ -137231,24 +137722,19 @@ const mapSingleStoreTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNames
|
|
|
137231
137722
|
}
|
|
137232
137723
|
return typeParams;
|
|
137233
137724
|
};
|
|
137234
|
-
|
|
137235
|
-
name:
|
|
137236
|
-
|
|
137237
|
-
|
|
137238
|
-
|
|
137239
|
-
|
|
137240
|
-
|
|
137241
|
-
|
|
137242
|
-
|
|
137243
|
-
|
|
137244
|
-
|
|
137245
|
-
|
|
137246
|
-
|
|
137247
|
-
})),
|
|
137248
|
-
primaryKeys: tableConfig.columns
|
|
137249
|
-
.filter((column) => column.primary)
|
|
137250
|
-
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
137251
|
-
};
|
|
137725
|
+
const mappedColumns = tableConfig.columns.map((column) => ({
|
|
137726
|
+
name: dbToTsColumnNamesMap[column.name],
|
|
137727
|
+
columnType: column.getSQLType(),
|
|
137728
|
+
typeParams: getTypeParams(column.getSQLType()),
|
|
137729
|
+
dataType: column.dataType.split(' ')[0],
|
|
137730
|
+
hasDefault: column.hasDefault,
|
|
137731
|
+
default: column.default,
|
|
137732
|
+
enumValues: column.enumValues,
|
|
137733
|
+
isUnique: column.isUnique,
|
|
137734
|
+
notNull: column.notNull,
|
|
137735
|
+
primary: column.primary,
|
|
137736
|
+
}));
|
|
137737
|
+
return mappedColumns;
|
|
137252
137738
|
};
|
|
137253
137739
|
|
|
137254
137740
|
// Sqlite------------------------------------------------------------------------------------------------------------------------
|
|
@@ -137271,7 +137757,7 @@ const filterSqliteTables = (schema) => {
|
|
|
137271
137757
|
};
|
|
137272
137758
|
const seedSqlite = async (db, schema, options = {}, refinements) => {
|
|
137273
137759
|
const { sqliteSchema, sqliteTables } = filterSqliteTables(schema);
|
|
137274
|
-
const { tables, relations } = getSchemaInfo(sqliteSchema, sqliteTables,
|
|
137760
|
+
const { tables, relations } = getSchemaInfo(sqliteSchema, sqliteTables, mapSqliteColumns);
|
|
137275
137761
|
const seedService = new SeedService();
|
|
137276
137762
|
const generatedTablesGenerators = seedService.generatePossibleGenerators('sqlite', tables, relations, refinements, options);
|
|
137277
137763
|
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
@@ -137280,7 +137766,7 @@ const seedSqlite = async (db, schema, options = {}, refinements) => {
|
|
|
137280
137766
|
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
137281
137767
|
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, sqliteTables, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
137282
137768
|
};
|
|
137283
|
-
const
|
|
137769
|
+
const mapSqliteColumns = (tableConfig, dbToTsColumnNamesMap) => {
|
|
137284
137770
|
const getTypeParams = (sqlType) => {
|
|
137285
137771
|
// get type params and set only type
|
|
137286
137772
|
const typeParams = {};
|
|
@@ -137301,24 +137787,19 @@ const mapSqliteTable = (tableConfig, dbToTsTableNamesMap, dbToTsColumnNamesMap)
|
|
|
137301
137787
|
}
|
|
137302
137788
|
return typeParams;
|
|
137303
137789
|
};
|
|
137304
|
-
|
|
137305
|
-
name:
|
|
137306
|
-
|
|
137307
|
-
|
|
137308
|
-
|
|
137309
|
-
|
|
137310
|
-
|
|
137311
|
-
|
|
137312
|
-
|
|
137313
|
-
|
|
137314
|
-
|
|
137315
|
-
|
|
137316
|
-
|
|
137317
|
-
})),
|
|
137318
|
-
primaryKeys: tableConfig.columns
|
|
137319
|
-
.filter((column) => column.primary)
|
|
137320
|
-
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
137321
|
-
};
|
|
137790
|
+
const mappedColumns = tableConfig.columns.map((column) => ({
|
|
137791
|
+
name: dbToTsColumnNamesMap[column.name],
|
|
137792
|
+
columnType: column.getSQLType(),
|
|
137793
|
+
typeParams: getTypeParams(column.getSQLType()),
|
|
137794
|
+
dataType: column.dataType.split(' ')[0],
|
|
137795
|
+
hasDefault: column.hasDefault,
|
|
137796
|
+
default: column.default,
|
|
137797
|
+
enumValues: column.enumValues,
|
|
137798
|
+
isUnique: column.isUnique,
|
|
137799
|
+
notNull: column.notNull,
|
|
137800
|
+
primary: column.primary,
|
|
137801
|
+
}));
|
|
137802
|
+
return mappedColumns;
|
|
137322
137803
|
};
|
|
137323
137804
|
|
|
137324
137805
|
/* eslint-disable drizzle-internal/require-entity-kind */
|
|
@@ -137382,6 +137863,7 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
137382
137863
|
name: tableName,
|
|
137383
137864
|
columns,
|
|
137384
137865
|
primaryKeys: drizzleStudioColumns.filter((col) => col.primaryKey === true).map((col) => col.name),
|
|
137866
|
+
uniqueConstraints: [], // TODO change later
|
|
137385
137867
|
});
|
|
137386
137868
|
}
|
|
137387
137869
|
relations = drizzleStudioRelations.filter((rel) => rel.schema === schemaName && rel.refSchema === schemaName);
|