drizzle-seed 0.3.2-61ab0d9 → 0.3.2-905c951
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/index.cjs +201 -46
- package/index.cjs.map +1 -1
- package/index.d.cts +8 -1
- package/index.d.mts +8 -1
- package/index.d.ts +8 -1
- package/index.mjs +201 -47
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/services/GeneratorFuncs.d.cts +30 -6
- package/services/GeneratorFuncs.d.mts +30 -6
- package/services/GeneratorFuncs.d.ts +30 -6
- package/services/Generators.d.cts +27 -0
- package/services/Generators.d.mts +27 -0
- package/services/Generators.d.ts +27 -0
- package/services/utils.d.cts +1 -0
- package/services/utils.d.mts +1 -0
- package/services/utils.d.ts +1 -0
- package/types/seedService.d.cts +1 -1
- package/types/seedService.d.mts +1 -1
- package/types/seedService.d.ts +1 -1
package/index.d.cts
CHANGED
|
@@ -10,6 +10,7 @@ import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js
|
|
|
10
10
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
11
11
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
12
12
|
import type { RefinementsType } from './types/seedService.js';
|
|
13
|
+
export { AbstractGenerator } from './services/Generators.js';
|
|
13
14
|
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
14
15
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
15
16
|
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
@@ -18,7 +19,7 @@ type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any>
|
|
|
18
19
|
[table in keyof SCHEMA as SCHEMA[table] extends PgTable ? table : never]?: {
|
|
19
20
|
count?: number;
|
|
20
21
|
columns?: {
|
|
21
|
-
[column in keyof SCHEMA[table] as SCHEMA[table][column] extends PgColumn ? column : never]?: AbstractGenerator<any
|
|
22
|
+
[column in keyof SCHEMA[table] as SCHEMA[table][column] extends PgColumn ? column : never]?: AbstractGenerator<any> | false;
|
|
22
23
|
};
|
|
23
24
|
with?: {
|
|
24
25
|
[refTable in keyof SCHEMA as SCHEMA[refTable] extends PgTable ? refTable : never]?: number | {
|
|
@@ -113,12 +114,18 @@ export declare function getGeneratorsFunctions(): {
|
|
|
113
114
|
arraySize?: number;
|
|
114
115
|
}]) => import("./services/Generators.js").GenerateDate;
|
|
115
116
|
time: (...args: [] | [{
|
|
117
|
+
minTime?: string | Date;
|
|
118
|
+
maxTime?: string | Date;
|
|
116
119
|
arraySize?: number;
|
|
117
120
|
}]) => import("./services/Generators.js").GenerateTime;
|
|
118
121
|
timestamp: (...args: [] | [{
|
|
122
|
+
minTimestamp?: string | Date;
|
|
123
|
+
maxTimestamp?: string | Date;
|
|
119
124
|
arraySize?: number;
|
|
120
125
|
}]) => import("./services/Generators.js").GenerateTimestamp;
|
|
121
126
|
datetime: (...args: [] | [{
|
|
127
|
+
minDatetime?: string | Date;
|
|
128
|
+
maxDatetime?: string | Date;
|
|
122
129
|
arraySize?: number;
|
|
123
130
|
}]) => import("./services/Generators.js").GenerateDatetime;
|
|
124
131
|
year: (...args: [] | [{
|
package/index.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js
|
|
|
10
10
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
11
11
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
12
12
|
import type { RefinementsType } from './types/seedService.js';
|
|
13
|
+
export { AbstractGenerator } from './services/Generators.js';
|
|
13
14
|
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
14
15
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
15
16
|
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
@@ -18,7 +19,7 @@ type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any>
|
|
|
18
19
|
[table in keyof SCHEMA as SCHEMA[table] extends PgTable ? table : never]?: {
|
|
19
20
|
count?: number;
|
|
20
21
|
columns?: {
|
|
21
|
-
[column in keyof SCHEMA[table] as SCHEMA[table][column] extends PgColumn ? column : never]?: AbstractGenerator<any
|
|
22
|
+
[column in keyof SCHEMA[table] as SCHEMA[table][column] extends PgColumn ? column : never]?: AbstractGenerator<any> | false;
|
|
22
23
|
};
|
|
23
24
|
with?: {
|
|
24
25
|
[refTable in keyof SCHEMA as SCHEMA[refTable] extends PgTable ? refTable : never]?: number | {
|
|
@@ -113,12 +114,18 @@ export declare function getGeneratorsFunctions(): {
|
|
|
113
114
|
arraySize?: number;
|
|
114
115
|
}]) => import("./services/Generators.js").GenerateDate;
|
|
115
116
|
time: (...args: [] | [{
|
|
117
|
+
minTime?: string | Date;
|
|
118
|
+
maxTime?: string | Date;
|
|
116
119
|
arraySize?: number;
|
|
117
120
|
}]) => import("./services/Generators.js").GenerateTime;
|
|
118
121
|
timestamp: (...args: [] | [{
|
|
122
|
+
minTimestamp?: string | Date;
|
|
123
|
+
maxTimestamp?: string | Date;
|
|
119
124
|
arraySize?: number;
|
|
120
125
|
}]) => import("./services/Generators.js").GenerateTimestamp;
|
|
121
126
|
datetime: (...args: [] | [{
|
|
127
|
+
minDatetime?: string | Date;
|
|
128
|
+
maxDatetime?: string | Date;
|
|
122
129
|
arraySize?: number;
|
|
123
130
|
}]) => import("./services/Generators.js").GenerateDatetime;
|
|
124
131
|
year: (...args: [] | [{
|
package/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js
|
|
|
10
10
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
11
11
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
12
12
|
import type { RefinementsType } from './types/seedService.js';
|
|
13
|
+
export { AbstractGenerator } from './services/Generators.js';
|
|
13
14
|
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
14
15
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
15
16
|
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
@@ -18,7 +19,7 @@ type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any>
|
|
|
18
19
|
[table in keyof SCHEMA as SCHEMA[table] extends PgTable ? table : never]?: {
|
|
19
20
|
count?: number;
|
|
20
21
|
columns?: {
|
|
21
|
-
[column in keyof SCHEMA[table] as SCHEMA[table][column] extends PgColumn ? column : never]?: AbstractGenerator<any
|
|
22
|
+
[column in keyof SCHEMA[table] as SCHEMA[table][column] extends PgColumn ? column : never]?: AbstractGenerator<any> | false;
|
|
22
23
|
};
|
|
23
24
|
with?: {
|
|
24
25
|
[refTable in keyof SCHEMA as SCHEMA[refTable] extends PgTable ? refTable : never]?: number | {
|
|
@@ -113,12 +114,18 @@ export declare function getGeneratorsFunctions(): {
|
|
|
113
114
|
arraySize?: number;
|
|
114
115
|
}]) => import("./services/Generators.js").GenerateDate;
|
|
115
116
|
time: (...args: [] | [{
|
|
117
|
+
minTime?: string | Date;
|
|
118
|
+
maxTime?: string | Date;
|
|
116
119
|
arraySize?: number;
|
|
117
120
|
}]) => import("./services/Generators.js").GenerateTime;
|
|
118
121
|
timestamp: (...args: [] | [{
|
|
122
|
+
minTimestamp?: string | Date;
|
|
123
|
+
maxTimestamp?: string | Date;
|
|
119
124
|
arraySize?: number;
|
|
120
125
|
}]) => import("./services/Generators.js").GenerateTimestamp;
|
|
121
126
|
datetime: (...args: [] | [{
|
|
127
|
+
minDatetime?: string | Date;
|
|
128
|
+
maxDatetime?: string | Date;
|
|
122
129
|
arraySize?: number;
|
|
123
130
|
}]) => import("./services/Generators.js").GenerateDatetime;
|
|
124
131
|
year: (...args: [] | [{
|
package/index.mjs
CHANGED
|
@@ -131214,6 +131214,9 @@ const isObject = (value) => {
|
|
|
131214
131214
|
const equalSets = (set1, set2) => {
|
|
131215
131215
|
return set1.size === set2.size && [...set1].every((si) => set2.has(si));
|
|
131216
131216
|
};
|
|
131217
|
+
const isValidDate = (date) => {
|
|
131218
|
+
return !Number.isNaN(date.getTime());
|
|
131219
|
+
};
|
|
131217
131220
|
|
|
131218
131221
|
/* eslint-disable drizzle-internal/require-entity-kind */
|
|
131219
131222
|
class AbstractGenerator {
|
|
@@ -131785,13 +131788,20 @@ class GenerateDate extends AbstractGenerator {
|
|
|
131785
131788
|
const rng = prand.xoroshiro128plus(seed);
|
|
131786
131789
|
let { minDate, maxDate } = this.params;
|
|
131787
131790
|
const anchorDate = new Date('2024-05-08');
|
|
131791
|
+
// 4 years in milliseconds
|
|
131788
131792
|
const deltaMilliseconds = 4 * 31536000000;
|
|
131789
131793
|
if (typeof minDate === 'string') {
|
|
131790
131794
|
minDate = new Date(minDate);
|
|
131791
131795
|
}
|
|
131796
|
+
if (typeof minDate === 'object' && !isValidDate(minDate)) {
|
|
131797
|
+
throw new Error('Invalid Date was provided for the minDate parameter.');
|
|
131798
|
+
}
|
|
131792
131799
|
if (typeof maxDate === 'string') {
|
|
131793
131800
|
maxDate = new Date(maxDate);
|
|
131794
131801
|
}
|
|
131802
|
+
if (typeof maxDate === 'object' && !isValidDate(maxDate)) {
|
|
131803
|
+
throw new Error('Invalid Date was provided for the maxDate parameter.');
|
|
131804
|
+
}
|
|
131795
131805
|
if (minDate === undefined) {
|
|
131796
131806
|
if (maxDate === undefined) {
|
|
131797
131807
|
minDate = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
@@ -131804,6 +131814,9 @@ class GenerateDate extends AbstractGenerator {
|
|
|
131804
131814
|
if (maxDate === undefined) {
|
|
131805
131815
|
maxDate = new Date(minDate.getTime() + (2 * deltaMilliseconds));
|
|
131806
131816
|
}
|
|
131817
|
+
if (minDate > maxDate) {
|
|
131818
|
+
throw new Error(`The minDate parameter must be less than or equal to the maxDate parameter.`);
|
|
131819
|
+
}
|
|
131807
131820
|
this.state = { rng, minDate, maxDate };
|
|
131808
131821
|
}
|
|
131809
131822
|
generate() {
|
|
@@ -131825,18 +131838,83 @@ class GenerateTime extends AbstractGenerator {
|
|
|
131825
131838
|
init({ count, seed }) {
|
|
131826
131839
|
super.init({ count, seed });
|
|
131827
131840
|
const rng = prand.xoroshiro128plus(seed);
|
|
131828
|
-
|
|
131841
|
+
let { minTime, maxTime } = this.params;
|
|
131842
|
+
if (minTime === undefined && maxTime === undefined) {
|
|
131843
|
+
// TODO: maybe need to change in major version release
|
|
131844
|
+
// This is required to ensure that this generator remains deterministic when used without minTime, maxTime parameters.
|
|
131845
|
+
const oneDayInMilliseconds = 86400000;
|
|
131846
|
+
minTime = new Date(new Date('2024-05-08T12:00:00.000Z').getTime() - oneDayInMilliseconds);
|
|
131847
|
+
maxTime = new Date(new Date('2024-05-08T12:00:00.000Z').getTime() + oneDayInMilliseconds);
|
|
131848
|
+
this.state = { rng, minTime, maxTime };
|
|
131849
|
+
return;
|
|
131850
|
+
}
|
|
131851
|
+
if (minTime === undefined) {
|
|
131852
|
+
if (maxTime === undefined) {
|
|
131853
|
+
minTime = '00:00:00.000Z';
|
|
131854
|
+
maxTime = '23:59:59.999Z';
|
|
131855
|
+
}
|
|
131856
|
+
else {
|
|
131857
|
+
minTime = '00:00:00.000Z';
|
|
131858
|
+
}
|
|
131859
|
+
}
|
|
131860
|
+
if (maxTime === undefined) {
|
|
131861
|
+
maxTime = '23:59:59.999Z';
|
|
131862
|
+
new Date().toISOString();
|
|
131863
|
+
}
|
|
131864
|
+
const anchorDate = new Date('2024-05-08');
|
|
131865
|
+
const anchorDateString0 = anchorDate.toISOString().replace(/T\d{2}:\d{2}:\d{2}.\d{3}Z/, '');
|
|
131866
|
+
if (typeof minTime === 'string') {
|
|
131867
|
+
// const timeMatch0 = minTime.match(/^\d{2}:\d{2}:\d{2}.\d{1,3}Z?$/);
|
|
131868
|
+
const timeMatch1 = minTime.match(/^\d{2}:\d{2}:\d{2}Z?$/);
|
|
131869
|
+
const timeMatch2 = minTime.match(/^\d{2}:\d{2}Z?$/);
|
|
131870
|
+
if (
|
|
131871
|
+
// timeMatch0 === null
|
|
131872
|
+
timeMatch1 === null
|
|
131873
|
+
&& timeMatch2 === null) {
|
|
131874
|
+
throw new Error(`You're using the wrong format for the minTime parameter.`
|
|
131875
|
+
+ `\nPlease use one of these formats: 'HH:mm:ss', 'HH:mm' (with or without a trailing 'Z')`);
|
|
131876
|
+
}
|
|
131877
|
+
minTime = minTime.at(-1) === 'Z' ? minTime : minTime + 'Z';
|
|
131878
|
+
minTime = new Date(anchorDate.toISOString().replace(/\d{2}:\d{2}:\d{2}.\d{3}Z/, minTime));
|
|
131879
|
+
}
|
|
131880
|
+
if (typeof minTime === 'object') {
|
|
131881
|
+
if (!isValidDate(minTime)) {
|
|
131882
|
+
throw new Error('Invalid Date was provided for the minTime parameter.');
|
|
131883
|
+
}
|
|
131884
|
+
minTime = new Date(minTime.toISOString().replace(/\d{4}-\d{2}-\d{2}/, anchorDateString0));
|
|
131885
|
+
}
|
|
131886
|
+
if (typeof maxTime === 'string') {
|
|
131887
|
+
// const timeMatch0 = maxTime.match(/^\d{2}:\d{2}:\d{2}.\d{1,3}Z?$/);
|
|
131888
|
+
const timeMatch1 = maxTime.match(/^\d{2}:\d{2}:\d{2}Z?$/);
|
|
131889
|
+
const timeMatch2 = maxTime.match(/^\d{2}:\d{2}Z?$/);
|
|
131890
|
+
if (
|
|
131891
|
+
// timeMatch0 === null
|
|
131892
|
+
timeMatch1 === null
|
|
131893
|
+
&& timeMatch2 === null) {
|
|
131894
|
+
throw new Error(`You're using the wrong format for the maxTime parameter.`
|
|
131895
|
+
+ `\nPlease use one of these formats: 'HH:mm:ss', 'HH:mm' (with or without a trailing 'Z').`);
|
|
131896
|
+
}
|
|
131897
|
+
maxTime = maxTime.at(-1) === 'Z' ? maxTime : maxTime + 'Z';
|
|
131898
|
+
maxTime = new Date(anchorDate.toISOString().replace(/\d{2}:\d{2}:\d{2}.\d{3}Z/, maxTime));
|
|
131899
|
+
}
|
|
131900
|
+
if (typeof maxTime === 'object') {
|
|
131901
|
+
if (!isValidDate(maxTime)) {
|
|
131902
|
+
throw new Error('Invalid Date was provided for the maxTime parameter.');
|
|
131903
|
+
}
|
|
131904
|
+
maxTime = new Date(maxTime.toISOString().replace(/\d{4}-\d{2}-\d{2}/, anchorDateString0));
|
|
131905
|
+
}
|
|
131906
|
+
if (minTime > maxTime) {
|
|
131907
|
+
throw new Error(`The minTime parameter must be less than or equal to the maxTime parameter.`);
|
|
131908
|
+
}
|
|
131909
|
+
this.state = { rng, minTime, maxTime };
|
|
131829
131910
|
}
|
|
131830
131911
|
generate() {
|
|
131831
131912
|
if (this.state === undefined) {
|
|
131832
131913
|
throw new Error('state is not defined.');
|
|
131833
131914
|
}
|
|
131834
|
-
const anchorDateTime = new Date('2024-05-08T12:00:00.000Z');
|
|
131835
|
-
const oneDayInMilliseconds = 86400000;
|
|
131836
|
-
let date = new Date();
|
|
131837
131915
|
let milliseconds;
|
|
131838
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
131839
|
-
date = new Date(
|
|
131916
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minTime.getTime(), this.state.maxTime.getTime(), this.state.rng);
|
|
131917
|
+
const date = new Date(milliseconds);
|
|
131840
131918
|
return date.toISOString().replace(/(\d{4}-\d{2}-\d{2}T)|(\.\d{3}Z)/g, '');
|
|
131841
131919
|
}
|
|
131842
131920
|
}
|
|
@@ -131846,18 +131924,46 @@ class GenerateTimestamp extends AbstractGenerator {
|
|
|
131846
131924
|
init({ count, seed }) {
|
|
131847
131925
|
super.init({ count, seed });
|
|
131848
131926
|
const rng = prand.xoroshiro128plus(seed);
|
|
131849
|
-
|
|
131927
|
+
let { minTimestamp, maxTimestamp } = this.params;
|
|
131928
|
+
const anchorDate = new Date('2024-05-08');
|
|
131929
|
+
// 2 years in milliseconds
|
|
131930
|
+
const deltaMilliseconds = 2 * 31536000000;
|
|
131931
|
+
if (typeof minTimestamp === 'string') {
|
|
131932
|
+
minTimestamp = new Date(minTimestamp);
|
|
131933
|
+
}
|
|
131934
|
+
if (typeof minTimestamp === 'object' && !isValidDate(minTimestamp)) {
|
|
131935
|
+
throw new Error('Invalid Date was provided for the minTimestamp parameter.');
|
|
131936
|
+
}
|
|
131937
|
+
if (typeof maxTimestamp === 'string') {
|
|
131938
|
+
maxTimestamp = new Date(maxTimestamp);
|
|
131939
|
+
}
|
|
131940
|
+
if (typeof maxTimestamp === 'object' && !isValidDate(maxTimestamp)) {
|
|
131941
|
+
throw new Error('Invalid Date was provided for the maxTimestamp parameter.');
|
|
131942
|
+
}
|
|
131943
|
+
if (minTimestamp === undefined) {
|
|
131944
|
+
if (maxTimestamp === undefined) {
|
|
131945
|
+
minTimestamp = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
131946
|
+
maxTimestamp = new Date(anchorDate.getTime() + deltaMilliseconds);
|
|
131947
|
+
}
|
|
131948
|
+
else {
|
|
131949
|
+
minTimestamp = new Date(maxTimestamp.getTime() - (2 * deltaMilliseconds));
|
|
131950
|
+
}
|
|
131951
|
+
}
|
|
131952
|
+
if (maxTimestamp === undefined) {
|
|
131953
|
+
maxTimestamp = new Date(minTimestamp.getTime() + (2 * deltaMilliseconds));
|
|
131954
|
+
}
|
|
131955
|
+
if (minTimestamp > maxTimestamp) {
|
|
131956
|
+
throw new Error(`The minTimestamp parameter must be less than or equal to the maxTimestamp parameter.`);
|
|
131957
|
+
}
|
|
131958
|
+
this.state = { rng, minTimestamp, maxTimestamp };
|
|
131850
131959
|
}
|
|
131851
131960
|
generate() {
|
|
131852
131961
|
if (this.state === undefined) {
|
|
131853
131962
|
throw new Error('state is not defined.');
|
|
131854
131963
|
}
|
|
131855
|
-
const anchorTimestamp = new Date('2024-05-08');
|
|
131856
|
-
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
131857
|
-
let date = new Date();
|
|
131858
131964
|
let milliseconds;
|
|
131859
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
131860
|
-
date = new Date(
|
|
131965
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minTimestamp.getTime(), this.state.maxTimestamp.getTime(), this.state.rng);
|
|
131966
|
+
const date = new Date(milliseconds);
|
|
131861
131967
|
if (this.dataType === 'string') {
|
|
131862
131968
|
return date
|
|
131863
131969
|
.toISOString()
|
|
@@ -131873,18 +131979,46 @@ class GenerateDatetime extends AbstractGenerator {
|
|
|
131873
131979
|
init({ count, seed }) {
|
|
131874
131980
|
super.init({ count, seed });
|
|
131875
131981
|
const rng = prand.xoroshiro128plus(seed);
|
|
131876
|
-
|
|
131982
|
+
let { minDatetime, maxDatetime } = this.params;
|
|
131983
|
+
const anchorDate = new Date('2024-05-08');
|
|
131984
|
+
// 2 years in milliseconds
|
|
131985
|
+
const deltaMilliseconds = 2 * 31536000000;
|
|
131986
|
+
if (typeof minDatetime === 'string') {
|
|
131987
|
+
minDatetime = new Date(minDatetime);
|
|
131988
|
+
}
|
|
131989
|
+
if (typeof minDatetime === 'object' && !isValidDate(minDatetime)) {
|
|
131990
|
+
throw new Error('Invalid Date was provided for the minDatetime parameter.');
|
|
131991
|
+
}
|
|
131992
|
+
if (typeof maxDatetime === 'string') {
|
|
131993
|
+
maxDatetime = new Date(maxDatetime);
|
|
131994
|
+
}
|
|
131995
|
+
if (typeof maxDatetime === 'object' && !isValidDate(maxDatetime)) {
|
|
131996
|
+
throw new Error('Invalid Date was provided for the maxDatetime parameter.');
|
|
131997
|
+
}
|
|
131998
|
+
if (minDatetime === undefined) {
|
|
131999
|
+
if (maxDatetime === undefined) {
|
|
132000
|
+
minDatetime = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
132001
|
+
maxDatetime = new Date(anchorDate.getTime() + deltaMilliseconds);
|
|
132002
|
+
}
|
|
132003
|
+
else {
|
|
132004
|
+
minDatetime = new Date(maxDatetime.getTime() - (2 * deltaMilliseconds));
|
|
132005
|
+
}
|
|
132006
|
+
}
|
|
132007
|
+
if (maxDatetime === undefined) {
|
|
132008
|
+
maxDatetime = new Date(minDatetime.getTime() + (2 * deltaMilliseconds));
|
|
132009
|
+
}
|
|
132010
|
+
if (minDatetime > maxDatetime) {
|
|
132011
|
+
throw new Error(`The minDatetime parameter must be less than or equal to the maxDatetime parameter.`);
|
|
132012
|
+
}
|
|
132013
|
+
this.state = { rng, minDatetime, maxDatetime };
|
|
131877
132014
|
}
|
|
131878
132015
|
generate() {
|
|
131879
132016
|
if (this.state === undefined) {
|
|
131880
132017
|
throw new Error('state is not defined.');
|
|
131881
132018
|
}
|
|
131882
|
-
const anchorDate = new Date('2024-05-08');
|
|
131883
|
-
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
131884
|
-
let date = new Date();
|
|
131885
132019
|
let milliseconds;
|
|
131886
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
131887
|
-
date = new Date(
|
|
132020
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minDatetime.getTime(), this.state.maxDatetime.getTime(), this.state.rng);
|
|
132021
|
+
const date = new Date(milliseconds);
|
|
131888
132022
|
if (this.dataType === 'string') {
|
|
131889
132023
|
return date
|
|
131890
132024
|
.toISOString()
|
|
@@ -133557,6 +133691,8 @@ const generatorsFuncs = {
|
|
|
133557
133691
|
date: createGenerator(GenerateDate),
|
|
133558
133692
|
/**
|
|
133559
133693
|
* generates time in 24 hours style.
|
|
133694
|
+
* @param minTime - lower border of range.
|
|
133695
|
+
* @param maxTime - upper border of range.
|
|
133560
133696
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
133561
133697
|
*
|
|
133562
133698
|
* @example
|
|
@@ -133564,7 +133700,7 @@ const generatorsFuncs = {
|
|
|
133564
133700
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133565
133701
|
* users: {
|
|
133566
133702
|
* columns: {
|
|
133567
|
-
* birthTime: funcs.time()
|
|
133703
|
+
* birthTime: funcs.time({ minTime: "11:12:13.141", maxTime: "15:16:17.181" })
|
|
133568
133704
|
* },
|
|
133569
133705
|
* },
|
|
133570
133706
|
* }));
|
|
@@ -133574,6 +133710,8 @@ const generatorsFuncs = {
|
|
|
133574
133710
|
time: createGenerator(GenerateTime),
|
|
133575
133711
|
/**
|
|
133576
133712
|
* generates timestamps.
|
|
133713
|
+
* @param minTimestamp - lower border of range.
|
|
133714
|
+
* @param maxTimestamp - upper border of range.
|
|
133577
133715
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
133578
133716
|
*
|
|
133579
133717
|
* @example
|
|
@@ -133581,7 +133719,7 @@ const generatorsFuncs = {
|
|
|
133581
133719
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133582
133720
|
* orders: {
|
|
133583
133721
|
* columns: {
|
|
133584
|
-
* shippedDate: funcs.timestamp()
|
|
133722
|
+
* shippedDate: funcs.timestamp({ minTimestamp: "2025-03-07T11:12:13.141", maxTimestamp: "2025-03-08T15:16:17.181" })
|
|
133585
133723
|
* },
|
|
133586
133724
|
* },
|
|
133587
133725
|
* }));
|
|
@@ -133591,6 +133729,8 @@ const generatorsFuncs = {
|
|
|
133591
133729
|
timestamp: createGenerator(GenerateTimestamp),
|
|
133592
133730
|
/**
|
|
133593
133731
|
* generates datetime objects.
|
|
133732
|
+
* @param minDatetime - lower border of range.
|
|
133733
|
+
* @param maxDatetime - upper border of range.
|
|
133594
133734
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
133595
133735
|
*
|
|
133596
133736
|
* @example
|
|
@@ -133598,7 +133738,7 @@ const generatorsFuncs = {
|
|
|
133598
133738
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133599
133739
|
* orders: {
|
|
133600
133740
|
* columns: {
|
|
133601
|
-
* shippedDate: funcs.datetime()
|
|
133741
|
+
* shippedDate: funcs.datetime({ minDatetime: "2025-03-07T11:12:13.141", maxDatetime: "2025-03-08T15:16:17.181" })
|
|
133602
133742
|
* },
|
|
133603
133743
|
* },
|
|
133604
133744
|
* }));
|
|
@@ -134059,7 +134199,7 @@ const generatorsFuncs = {
|
|
|
134059
134199
|
*/
|
|
134060
134200
|
weightedRandom: createGenerator(WeightedRandomGenerator),
|
|
134061
134201
|
};
|
|
134062
|
-
// so far, version changes don’t
|
|
134202
|
+
// so far, version changes don’t change generator parameters.
|
|
134063
134203
|
const generatorsFuncsV2 = {
|
|
134064
134204
|
...generatorsFuncs,
|
|
134065
134205
|
};
|
|
@@ -134270,6 +134410,7 @@ class SeedService {
|
|
|
134270
134410
|
};
|
|
134271
134411
|
}
|
|
134272
134412
|
}
|
|
134413
|
+
// handling refinements (count, with)
|
|
134273
134414
|
if (refinements !== undefined && refinements[table.name] !== undefined) {
|
|
134274
134415
|
if (refinements[table.name].count !== undefined) {
|
|
134275
134416
|
tablesPossibleGenerators[i].count = refinements[table.name].count;
|
|
@@ -134330,11 +134471,24 @@ class SeedService {
|
|
|
134330
134471
|
wasDefinedBefore: false,
|
|
134331
134472
|
wasRefined: false,
|
|
134332
134473
|
};
|
|
134474
|
+
// handling refinements (columnGenerator)
|
|
134333
134475
|
if (refinements !== undefined
|
|
134334
134476
|
&& refinements[table.name] !== undefined
|
|
134335
134477
|
&& refinements[table.name].columns !== undefined
|
|
134336
134478
|
&& refinements[table.name].columns[col.name] !== undefined) {
|
|
134337
134479
|
const genObj = refinements[table.name].columns[col.name];
|
|
134480
|
+
if (genObj === false) {
|
|
134481
|
+
if (col.notNull === true && col.hasDefault === false) {
|
|
134482
|
+
throw new Error(`You cannot set the '${col.name}' column in the '${table.name}' table to false in your refinements.`
|
|
134483
|
+
+ `\nDoing so will result in a null value being inserted into the '${col.name}' column,`
|
|
134484
|
+
+ `\nwhich will cause an error because the column has a not null constraint and no default value.`);
|
|
134485
|
+
}
|
|
134486
|
+
// Generating undefined as a value for a column and then inserting it via drizzle-orm
|
|
134487
|
+
// will result in the value not being inserted into that column.
|
|
134488
|
+
columnPossibleGenerator.generator = new generatorsMap.GenerateDefault[0]({ defaultValue: undefined });
|
|
134489
|
+
columnPossibleGenerator.wasRefined = true;
|
|
134490
|
+
continue;
|
|
134491
|
+
}
|
|
134338
134492
|
if (col.columnType.match(/\[\w*]/g) !== null) {
|
|
134339
134493
|
if ((col.baseColumn?.dataType === 'array' && col.baseColumn.columnType.match(/\[\w*]/g) !== null)
|
|
134340
134494
|
// studio case
|
|
@@ -134646,8 +134800,8 @@ class SeedService {
|
|
|
134646
134800
|
// NUMBER(real, double, decimal, numeric)
|
|
134647
134801
|
if (col.columnType === 'real'
|
|
134648
134802
|
|| col.columnType === 'double precision'
|
|
134649
|
-
|| col.columnType.match(/^decimal(\(\d
|
|
134650
|
-
|| col.columnType.match(/^numeric(\(\d
|
|
134803
|
+
|| col.columnType.match(/^decimal(\(\d{1,6}(, ?-?\d{0,5})?\))?$/) !== null
|
|
134804
|
+
|| col.columnType.match(/^numeric(\(\d{1,6}(, ?-?\d{0,5})?\))?$/) !== null) {
|
|
134651
134805
|
if (col.typeParams.precision !== undefined) {
|
|
134652
134806
|
const precision = col.typeParams.precision;
|
|
134653
134807
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -134823,8 +134977,8 @@ class SeedService {
|
|
|
134823
134977
|
if (col.columnType === 'real'
|
|
134824
134978
|
|| col.columnType === 'double'
|
|
134825
134979
|
|| col.columnType === 'float'
|
|
134826
|
-
|| col.columnType.
|
|
134827
|
-
|| col.columnType.
|
|
134980
|
+
|| col.columnType.startsWith('decimal')
|
|
134981
|
+
|| col.columnType.startsWith('numeric')) {
|
|
134828
134982
|
if (col.typeParams.precision !== undefined) {
|
|
134829
134983
|
const precision = col.typeParams.precision;
|
|
134830
134984
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -134842,40 +134996,40 @@ class SeedService {
|
|
|
134842
134996
|
// STRING
|
|
134843
134997
|
if ((col.columnType === 'text'
|
|
134844
134998
|
|| col.columnType === 'blob'
|
|
134845
|
-
|| col.columnType.
|
|
134846
|
-
|| col.columnType.
|
|
134847
|
-
|| col.columnType.
|
|
134848
|
-
|| col.columnType.
|
|
134999
|
+
|| col.columnType.startsWith('char')
|
|
135000
|
+
|| col.columnType.startsWith('varchar')
|
|
135001
|
+
|| col.columnType.startsWith('binary')
|
|
135002
|
+
|| col.columnType.startsWith('varbinary'))
|
|
134849
135003
|
&& table.primaryKeys.includes(col.name)) {
|
|
134850
135004
|
const generator = new generatorsMap.GenerateUniqueString[0]();
|
|
134851
135005
|
return generator;
|
|
134852
135006
|
}
|
|
134853
135007
|
if ((col.columnType === 'text'
|
|
134854
135008
|
|| col.columnType === 'blob'
|
|
134855
|
-
|| col.columnType.
|
|
134856
|
-
|| col.columnType.
|
|
134857
|
-
|| col.columnType.
|
|
134858
|
-
|| col.columnType.
|
|
135009
|
+
|| col.columnType.startsWith('char')
|
|
135010
|
+
|| col.columnType.startsWith('varchar')
|
|
135011
|
+
|| col.columnType.startsWith('binary')
|
|
135012
|
+
|| col.columnType.startsWith('varbinary'))
|
|
134859
135013
|
&& col.name.toLowerCase().includes('name')) {
|
|
134860
135014
|
const generator = new generatorsMap.GenerateFirstName[0]();
|
|
134861
135015
|
return generator;
|
|
134862
135016
|
}
|
|
134863
135017
|
if ((col.columnType === 'text'
|
|
134864
135018
|
|| col.columnType === 'blob'
|
|
134865
|
-
|| col.columnType.
|
|
134866
|
-
|| col.columnType.
|
|
134867
|
-
|| col.columnType.
|
|
134868
|
-
|| col.columnType.
|
|
135019
|
+
|| col.columnType.startsWith('char')
|
|
135020
|
+
|| col.columnType.startsWith('varchar')
|
|
135021
|
+
|| col.columnType.startsWith('binary')
|
|
135022
|
+
|| col.columnType.startsWith('varbinary'))
|
|
134869
135023
|
&& col.name.toLowerCase().includes('email')) {
|
|
134870
135024
|
const generator = new generatorsMap.GenerateEmail[0]();
|
|
134871
135025
|
return generator;
|
|
134872
135026
|
}
|
|
134873
135027
|
if (col.columnType === 'text'
|
|
134874
135028
|
|| col.columnType === 'blob'
|
|
134875
|
-
|| col.columnType.
|
|
134876
|
-
|| col.columnType.
|
|
134877
|
-
|| col.columnType.
|
|
134878
|
-
|| col.columnType.
|
|
135029
|
+
|| col.columnType.startsWith('char')
|
|
135030
|
+
|| col.columnType.startsWith('varchar')
|
|
135031
|
+
|| col.columnType.startsWith('binary')
|
|
135032
|
+
|| col.columnType.startsWith('varbinary')) {
|
|
134879
135033
|
const generator = new generatorsMap.GenerateString[0]();
|
|
134880
135034
|
return generator;
|
|
134881
135035
|
}
|
|
@@ -134885,7 +135039,7 @@ class SeedService {
|
|
|
134885
135039
|
return generator;
|
|
134886
135040
|
}
|
|
134887
135041
|
// DATE, TIME, TIMESTAMP, DATETIME, YEAR
|
|
134888
|
-
if (col.columnType.
|
|
135042
|
+
if (col.columnType.startsWith('datetime')) {
|
|
134889
135043
|
const generator = new generatorsMap.GenerateDatetime[0]();
|
|
134890
135044
|
return generator;
|
|
134891
135045
|
}
|
|
@@ -134897,7 +135051,7 @@ class SeedService {
|
|
|
134897
135051
|
const generator = new generatorsMap.GenerateTime[0]();
|
|
134898
135052
|
return generator;
|
|
134899
135053
|
}
|
|
134900
|
-
if (col.columnType.
|
|
135054
|
+
if (col.columnType.startsWith('timestamp')) {
|
|
134901
135055
|
const generator = new generatorsMap.GenerateTimestamp[0]();
|
|
134902
135056
|
return generator;
|
|
134903
135057
|
}
|
|
@@ -134950,8 +135104,8 @@ class SeedService {
|
|
|
134950
135104
|
return generator;
|
|
134951
135105
|
}
|
|
134952
135106
|
// number section ------------------------------------------------------------------------------------
|
|
134953
|
-
if (col.columnType.
|
|
134954
|
-
|| col.columnType.
|
|
135107
|
+
if (col.columnType.startsWith('real')
|
|
135108
|
+
|| col.columnType.startsWith('numeric')) {
|
|
134955
135109
|
if (col.typeParams.precision !== undefined) {
|
|
134956
135110
|
const precision = col.typeParams.precision;
|
|
134957
135111
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -136143,5 +136297,5 @@ const getSqliteInfo = (sqliteSchema, sqliteTables) => {
|
|
|
136143
136297
|
return { tables, relations: isCyclicRelations, tableRelations };
|
|
136144
136298
|
};
|
|
136145
136299
|
|
|
136146
|
-
export { SeedService, cityNames as cities, countries, firstNames, getGeneratorsFunctions, lastNames, reset, seed, seedForDrizzleStudio };
|
|
136300
|
+
export { AbstractGenerator, SeedService, cityNames as cities, countries, firstNames, getGeneratorsFunctions, lastNames, reset, seed, seedForDrizzleStudio };
|
|
136147
136301
|
//# sourceMappingURL=index.mjs.map
|