Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: log messages for unique fields #828

Merged
merged 3 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/.vitepress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "ES2020"
}
}
67 changes: 64 additions & 3 deletions src/unique.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecated } from './internal/deprecated';
import type { RecordKey } from './utils/unique';
import * as uniqueExec from './utils/unique';

Expand All @@ -10,14 +11,74 @@ export class Unique {
*
* @deprecated Use options instead.
*/
maxTime = 10;
private _maxTime = 10;

/**
* Maximum time `unique.exec` will attempt to run before aborting.
*
* @deprecated Use options instead.
*/
get maxTime(): number {
deprecated({
deprecated: 'faker.unique.maxTime',
proposed: 'Options',
since: 'v6.2.0',
until: 'v7.0.0',
});
return this._maxTime;
}

/**
* Maximum time `unique.exec` will attempt to run before aborting.
*
* @deprecated Use options instead.
*/
set maxTime(value: number) {
deprecated({
deprecated: 'faker.unique.maxTime',
proposed: 'Options',
since: 'v6.2.0',
until: 'v7.0.0',
});
this._maxTime = value;
}

/**
* Maximum retries `unique.exec` will recurse before aborting (max loop depth).
*
* @deprecated Use options instead.
*/
maxRetries = 10;
private _maxRetries = 10;

/**
* Maximum retries `unique.exec` will recurse before aborting (max loop depth).
*
* @deprecated Use options instead.
*/
get maxRetries(): number {
deprecated({
deprecated: 'faker.unique.maxRetries',
proposed: 'Options',
since: 'v6.2.0',
until: 'v7.0.0',
});
return this._maxRetries;
}

/**
* Maximum retries `unique.exec` will recurse before aborting (max loop depth).
*
* @deprecated Use options instead.
*/
set maxRetries(value: number) {
deprecated({
deprecated: 'faker.unique.maxRetries',
proposed: 'Options',
since: 'v6.2.0',
until: 'v7.0.0',
});
this._maxRetries = value;
}

constructor() {
// Bind `this` so namespaced is working correctly
Expand Down Expand Up @@ -59,7 +120,7 @@ export class Unique {
compare?: (obj: Record<RecordKey, RecordKey>, key: RecordKey) => 0 | -1;
} = {}
): ReturnType<Method> {
const { maxTime = this.maxTime, maxRetries = this.maxRetries } = options;
const { maxTime = this._maxTime, maxRetries = this._maxRetries } = options;
return uniqueExec.exec(method, args, {
...options,
startTime: new Date().getTime(),
Expand Down
3 changes: 3 additions & 0 deletions test/scripts/apidoc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"compilerOptions": {
"target": "ES5"
},
"include": ["signature.example.ts"]
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"target": "ES5",
"rootDir": "src",
"outDir": "dist",
"declaration": true,
Expand Down