Skip to content

Commit 7db2063

Browse files
committed
chore: apply suggestions
1 parent a9f8376 commit 7db2063

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/unique.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export class Unique {
3737
* @param method The method used to generate the values.
3838
* @param args The arguments used to call the method.
3939
* @param options The optional options used to configure this method.
40-
* @param options.startTime The time this execution stared. This will be ignored/overwritten. Defaults to `new Date().getTime()`.
40+
* @param options.startTime This parameter does nothing.
4141
* @param options.maxTime The time in milliseconds this method may take before throwing an error. Defaults to `50`.
4242
* @param options.maxRetries The total number of attempts to try before throwing an error. Defaults to `50`.
43-
* @param options.currentIterations The current attempt. This will be ignored/overwritten. Defaults to `0`.
43+
* @param options.currentIterations This parameter does nothing.
4444
* @param options.exclude The value or values that should be excluded/skipped. Defaults to `[]`.
4545
* @param options.compare The function used to determine whether a value was already returned. Defaults to check the existence of the key.
4646
*
@@ -59,18 +59,13 @@ export class Unique {
5959
compare?: (obj: Record<RecordKey, RecordKey>, key: RecordKey) => 0 | -1;
6060
} = {}
6161
): ReturnType<Method> {
62-
const {
63-
startTime = new Date().getTime(),
64-
maxTime = this.maxTime,
65-
maxRetries = this.maxRetries,
66-
currentIterations = 0,
67-
} = options;
62+
const { maxTime = this.maxTime, maxRetries = this.maxRetries } = options;
6863
return uniqueExec.exec(method, args, {
6964
...options,
70-
startTime,
65+
startTime: new Date().getTime(),
7166
maxTime,
7267
maxRetries,
73-
currentIterations,
68+
currentIterations: 0,
7469
});
7570
}
7671
}

src/utils/unique.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ export type RecordKey = string | number | symbol;
44

55
/**
66
* Global store of unique values.
7-
* Uniqueness for entire faker instance.
8-
* This means that faker should *never* return duplicate values across all API methods when using `Faker.unique` without passing `options.store`.
7+
* This means that faker should *never* return duplicate values across all API methods when using `Faker.unique`.
98
*/
109
const GLOBAL_UNIQUE_STORE: Record<RecordKey, RecordKey> = {};
1110

@@ -72,10 +71,10 @@ Try adjusting maxTime or maxRetries parameters for faker.unique().`
7271
* @param method The method used to generate the values.
7372
* @param args The arguments used to call the method.
7473
* @param options The optional options used to configure this method.
75-
* @param options.startTime The time this execution stared. This will be ignored/overwritten. Defaults to `new Date().getTime()`.
74+
* @param options.startTime The time this execution stared. Defaults to `new Date().getTime()`.
7675
* @param options.maxTime The time in milliseconds this method may take before throwing an error. Defaults to `50`.
7776
* @param options.maxRetries The total number of attempts to try before throwing an error. Defaults to `50`.
78-
* @param options.currentIterations The current attempt. This will be ignored/overwritten. Defaults to `0`.
77+
* @param options.currentIterations The current attempt. Defaults to `0`.
7978
* @param options.exclude The value or values that should be excluded/skipped. Defaults to `[]`.
8079
* @param options.compare The function used to determine whether a value was already returned. Defaults to check the existence of the key.
8180
*/
@@ -134,6 +133,13 @@ export function exec<Method extends (...parameters) => RecordKey>(
134133
} else {
135134
// console.log('conflict', result);
136135
options.currentIterations++;
137-
return exec(method, args, options);
136+
return exec(method, args, {
137+
...options,
138+
startTime,
139+
maxTime,
140+
maxRetries,
141+
compare,
142+
exclude,
143+
});
138144
}
139145
}

0 commit comments

Comments
 (0)