@coderzz/mocker-data-generator 3.0.5 → 3.0.7
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/CHANGELOG.md +43 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/build/main/array-includes.d.ts +0 -0
- package/build/main/array-includes.js +45 -45
- package/build/main/index.d.ts +7 -7
- package/build/main/index.js +12 -12
- package/build/main/index.spec.d.ts +1 -1
- package/build/main/index.spec.js +16 -16
- package/build/main/lib/Generator.d.ts +61 -61
- package/build/main/lib/Generator.js +134 -134
- package/build/main/lib/Mocker.d.ts +22 -22
- package/build/main/lib/Mocker.js +76 -76
- package/build/main/lib/Schema.d.ts +9 -9
- package/build/main/lib/Schema.js +210 -210
- package/build/main/lib/types.d.ts +8 -8
- package/build/main/lib/types.js +2 -2
- package/build/main/lib/utils.d.ts +10 -10
- package/build/main/lib/utils.js +222 -222
- package/build/main/tests/Generator.db.spec.d.ts +1 -1
- package/build/main/tests/Generator.db.spec.js +33 -33
- package/build/main/tests/Generator.eval.spec.d.ts +1 -1
- package/build/main/tests/Generator.eval.spec.js +21 -21
- package/build/main/tests/Generator.function.spec.d.ts +1 -1
- package/build/main/tests/Generator.function.spec.js +48 -48
- package/build/main/tests/Generator.generator.spec.d.ts +1 -1
- package/build/main/tests/Generator.generator.spec.js +187 -187
- package/build/main/tests/Generator.hasMany.spec.d.ts +1 -1
- package/build/main/tests/Generator.hasMany.spec.js +115 -115
- package/build/main/tests/Generator.hasOne.spec.d.ts +1 -1
- package/build/main/tests/Generator.hasOne.spec.js +146 -146
- package/build/main/tests/Generator.incrementalId.spec.d.ts +1 -1
- package/build/main/tests/Generator.incrementalId.spec.js +26 -26
- package/build/main/tests/Generator.self.spec.d.ts +1 -1
- package/build/main/tests/Generator.self.spec.js +24 -24
- package/build/main/tests/Generator.static.spec.d.ts +1 -1
- package/build/main/tests/Generator.static.spec.js +15 -15
- package/build/main/tests/Generator.values.spec.d.ts +1 -1
- package/build/main/tests/Generator.values.spec.js +16 -16
- package/build/main/tests/Mocker.build.spec.d.ts +1 -1
- package/build/main/tests/Mocker.build.spec.js +196 -196
- package/build/main/tests/Mocker.reset.spec.d.ts +1 -1
- package/build/main/tests/Mocker.reset.spec.js +17 -17
- package/build/main/tests/Mocker.restart.spec.d.ts +1 -1
- package/build/main/tests/Mocker.restart.spec.js +24 -24
- package/build/main/tests/Mocker.schema.spec.d.ts +1 -1
- package/build/main/tests/Mocker.schema.spec.js +18 -18
- package/build/main/tests/Mocker.seed.spec.d.ts +1 -1
- package/build/main/tests/Mocker.seed.spec.js +42 -42
- package/build/main/tests/Schema.Array.spec.d.ts +1 -1
- package/build/main/tests/Schema.Array.spec.js +332 -332
- package/build/main/tests/Schema.BuildSingle.spec.d.ts +1 -1
- package/build/main/tests/Schema.BuildSingle.spec.js +13 -13
- package/build/main/tests/mocker.spec.d.ts +1 -1
- package/build/main/tests/mocker.spec.js +405 -405
- package/build/module/array-includes.js +45 -45
- package/build/module/index.js +7 -7
- package/build/module/lib/Generator.js +131 -131
- package/build/module/lib/Mocker.js +73 -73
- package/build/module/lib/Schema.js +207 -207
- package/build/module/lib/types.js +1 -1
- package/build/module/lib/utils.js +209 -209
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,49 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
### [3.0.7](https://github.com/anyideaz/mocker-data-generator/compare/v3.0.6...v3.0.7) (2025-02-18)
|
6
|
+
|
7
|
+
### 3.0.6 (2025-02-18)
|
8
|
+
|
9
|
+
|
10
|
+
### Features
|
11
|
+
|
12
|
+
* add buildSync method to Mocker class ([772b20d](https://github.com/anyideaz/mocker-data-generator/commit/772b20da6f9ccaba98f20a1361babe5f55810d78))
|
13
|
+
* Added a way to obtain actual array while the generation, [@zamnuts](https://github.com/zamnuts) suggestion ([2588a34](https://github.com/anyideaz/mocker-data-generator/commit/2588a347749c0140bfe4dc328ade1f2282781097))
|
14
|
+
* Added length on the array function generator, thanks [@zamnuts](https://github.com/zamnuts) ([1f17519](https://github.com/anyideaz/mocker-data-generator/commit/1f17519ced60cf51cd06bb9385ac5c091b8725ad))
|
15
|
+
* added min max for value generation randomly with tests. thanks [@jhkim-novavin](https://github.com/jhkim-novavin) ([5eaa6f4](https://github.com/anyideaz/mocker-data-generator/commit/5eaa6f4692c9814e479edbadc0284076c900a11f))
|
16
|
+
* added PR [#16](https://github.com/anyideaz/mocker-data-generator/issues/16) Add parameter to hasMany generator, thanks [@justinbarry](https://github.com/justinbarry) ([71d947f](https://github.com/anyideaz/mocker-data-generator/commit/71d947f83486cf344e4a4c2bc754f7480629a037))
|
17
|
+
* **build:** new build using Typescript, breaking change in imports, adapted import to be used with es6 ([6114eaf](https://github.com/anyideaz/mocker-data-generator/commit/6114eaff5a560514b489100d14822ef79153bc39))
|
18
|
+
* **chore:** easy publish as minor shortcut ([fd1a87b](https://github.com/anyideaz/mocker-data-generator/commit/fd1a87bfe444817b75af88c91398929fab91b83c))
|
19
|
+
* **chore:** update chance and tslib, and some devDependencies ([59d0aea](https://github.com/anyideaz/mocker-data-generator/commit/59d0aea51fba7ef2e6b1ea153da4aa8007f07170))
|
20
|
+
* **fakerjs:** Added multilanguaje support ([0b94471](https://github.com/anyideaz/mocker-data-generator/commit/0b944711f6543394974eb9c6a240c18162fab1a8))
|
21
|
+
* **fakerjs:** Added tests for multilang support ([5078d24](https://github.com/anyideaz/mocker-data-generator/commit/5078d2488fdea636b8a9cd329020eaec8a309eab))
|
22
|
+
* **fakerjs:** Updates on the readme ([b79e88f](https://github.com/anyideaz/mocker-data-generator/commit/b79e88f43bb9558b15fe8718643f5f671294c5e0))
|
23
|
+
* **Mocker.seed:** add posibility to prepopulate the db. Thanks [@suspiciousfellow](https://github.com/suspiciousfellow) and [@marshallswain](https://github.com/marshallswain) for the idea and the code ([dfb2ad6](https://github.com/anyideaz/mocker-data-generator/commit/dfb2ad64fe002e4b55dfe71d1d65574d5054d6cc))
|
24
|
+
* **Mocker.seed:** add tests ([7faafab](https://github.com/anyideaz/mocker-data-generator/commit/7faafab779af49434c47ac63631aea9cebbc9be7))
|
25
|
+
* **Mocker.seed:** seed and schema and work together ([68970fc](https://github.com/anyideaz/mocker-data-generator/commit/68970fc3fe7a2072c99d58ed3b1ececd3b6909dd))
|
26
|
+
* update faker-js ([d9be8f6](https://github.com/anyideaz/mocker-data-generator/commit/d9be8f65505b5dba6389b7986ce26c270036ef1c))
|
27
|
+
|
28
|
+
|
29
|
+
### Bug Fixes
|
30
|
+
|
31
|
+
* **appveyor:** update matrix config to install defined node version ([703aa41](https://github.com/anyideaz/mocker-data-generator/commit/703aa41411b3813f3d1af6e79b6d2643a36dec56))
|
32
|
+
* Better error throwing and test covered ([20ca0a0](https://github.com/anyideaz/mocker-data-generator/commit/20ca0a07ebec52d425dcf91a6dc88415629a887f))
|
33
|
+
* **browserify:** fix browserify builds changing casual to browserify-casual ([de93262](https://github.com/anyideaz/mocker-data-generator/commit/de932625d885c3a39ed77c0d1e0a88ddccc96d4b))
|
34
|
+
* **builder:** fix tslint space identation ([b3f9f7c](https://github.com/anyideaz/mocker-data-generator/commit/b3f9f7c54d495ea56df98058ace52fbe62666ef2))
|
35
|
+
* Changelog ([8cc7b58](https://github.com/anyideaz/mocker-data-generator/commit/8cc7b58be9108f2da09b8c1a036be7f6a212f6a5))
|
36
|
+
* Changelog ([d598862](https://github.com/anyideaz/mocker-data-generator/commit/d59886218ca289c72f39446978fbbeaf5d368804))
|
37
|
+
* **docs-website:** added seed example ([d1fa143](https://github.com/anyideaz/mocker-data-generator/commit/d1fa143f20467cf69c87e5cc4a74657429550384))
|
38
|
+
* **fakerjs:** Better locale detector and better testing ([f05872d](https://github.com/anyideaz/mocker-data-generator/commit/f05872d4b5c7985604a044b95b58f5c578986f7a))
|
39
|
+
* **generation:** added fix when min = 0 in hasMany, now can produce empty array of data, by default is 1, so you have to specify minimum to 0 in order to have the chance to produce empty arrays ([7f97646](https://github.com/anyideaz/mocker-data-generator/commit/7f976460f6ef3e718667a52a90294ae9791d570e))
|
40
|
+
* **gh-pages:** add unpkg ([ca93d07](https://github.com/anyideaz/mocker-data-generator/commit/ca93d07684526af58a7641598c736ea531ca8966))
|
41
|
+
* **hasOne:** Issues with eval ([f1ab9e8](https://github.com/anyideaz/mocker-data-generator/commit/f1ab9e86d2c4c93b932f2b2fbde1a54eccfc6e73))
|
42
|
+
* JSON parse error ([3844225](https://github.com/anyideaz/mocker-data-generator/commit/384422548435728ba6126e7754d4dc58a0971a3a))
|
43
|
+
* **linter:** trying to use supported tslint rule ([5edac70](https://github.com/anyideaz/mocker-data-generator/commit/5edac701b0b3d5d7cc070e14b2bc08c6e9317098))
|
44
|
+
* **package:** update randexp to version 0.5.0 ([cfddafd](https://github.com/anyideaz/mocker-data-generator/commit/cfddafdc9527e43a78c6d9d1cf04ae0065390b9c))
|
45
|
+
* **test:** separate gh-pages generation modules from the mocker modules for development, some test fails ([2cc421e](https://github.com/anyideaz/mocker-data-generator/commit/2cc421eb04404fcecd8c882090dfc10450eb23c3))
|
46
|
+
* **updates:** Update libs to last releases ([a6ce60b](https://github.com/anyideaz/mocker-data-generator/commit/a6ce60bd14625ad1dd886299477cdb25e31dcfec))
|
47
|
+
|
5
48
|
### 3.0.4 (2025-02-15)
|
6
49
|
|
7
50
|
|
package/LICENSE
CHANGED
File without changes
|
package/README.md
CHANGED
File without changes
|
File without changes
|
@@ -1,45 +1,45 @@
|
|
1
|
-
if (!Array.prototype.includes) {
|
2
|
-
Object.defineProperty(Array.prototype, 'includes', {
|
3
|
-
value: function (searchElement, fromIndex) {
|
4
|
-
// 1. Let O be ? ToObject(this value).
|
5
|
-
if (this == null) {
|
6
|
-
throw new TypeError('"this" is null or not defined');
|
7
|
-
}
|
8
|
-
var o = Object(this);
|
9
|
-
// 2. Let len be ? ToLength(? Get(O, "length")).
|
10
|
-
var len = o.length >>> 0;
|
11
|
-
// 3. If len is 0, return false.
|
12
|
-
if (len === 0) {
|
13
|
-
return false;
|
14
|
-
}
|
15
|
-
// 4. Let n be ? ToInteger(fromIndex).
|
16
|
-
// (If fromIndex is undefined, this step produces the value 0.)
|
17
|
-
var n = fromIndex | 0;
|
18
|
-
// 5. If n ≥ 0, then
|
19
|
-
// a. Let k be n.
|
20
|
-
// 6. Else n < 0,
|
21
|
-
// a. Let k be len + n.
|
22
|
-
// b. If k < 0, let k be 0.
|
23
|
-
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
24
|
-
function sameValueZero(x, y) {
|
25
|
-
return (x === y ||
|
26
|
-
(typeof x === 'number' &&
|
27
|
-
typeof y === 'number' &&
|
28
|
-
isNaN(x) &&
|
29
|
-
isNaN(y)));
|
30
|
-
}
|
31
|
-
// 7. Repeat, while k < len
|
32
|
-
while (k < len) {
|
33
|
-
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
34
|
-
// b. If SameValueZero(searchElement, elementK) is true, return true.
|
35
|
-
// c. Increase k by 1.
|
36
|
-
if (sameValueZero(o[k], searchElement)) {
|
37
|
-
return true;
|
38
|
-
}
|
39
|
-
k++;
|
40
|
-
}
|
41
|
-
// 8. Return false
|
42
|
-
return false;
|
43
|
-
}
|
44
|
-
});
|
45
|
-
}
|
1
|
+
if (!Array.prototype.includes) {
|
2
|
+
Object.defineProperty(Array.prototype, 'includes', {
|
3
|
+
value: function (searchElement, fromIndex) {
|
4
|
+
// 1. Let O be ? ToObject(this value).
|
5
|
+
if (this == null) {
|
6
|
+
throw new TypeError('"this" is null or not defined');
|
7
|
+
}
|
8
|
+
var o = Object(this);
|
9
|
+
// 2. Let len be ? ToLength(? Get(O, "length")).
|
10
|
+
var len = o.length >>> 0;
|
11
|
+
// 3. If len is 0, return false.
|
12
|
+
if (len === 0) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
// 4. Let n be ? ToInteger(fromIndex).
|
16
|
+
// (If fromIndex is undefined, this step produces the value 0.)
|
17
|
+
var n = fromIndex | 0;
|
18
|
+
// 5. If n ≥ 0, then
|
19
|
+
// a. Let k be n.
|
20
|
+
// 6. Else n < 0,
|
21
|
+
// a. Let k be len + n.
|
22
|
+
// b. If k < 0, let k be 0.
|
23
|
+
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
24
|
+
function sameValueZero(x, y) {
|
25
|
+
return (x === y ||
|
26
|
+
(typeof x === 'number' &&
|
27
|
+
typeof y === 'number' &&
|
28
|
+
isNaN(x) &&
|
29
|
+
isNaN(y)));
|
30
|
+
}
|
31
|
+
// 7. Repeat, while k < len
|
32
|
+
while (k < len) {
|
33
|
+
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
34
|
+
// b. If SameValueZero(searchElement, elementK) is true, return true.
|
35
|
+
// c. Increase k by 1.
|
36
|
+
if (sameValueZero(o[k], searchElement)) {
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
k++;
|
40
|
+
}
|
41
|
+
// 8. Return false
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
});
|
45
|
+
}
|
package/build/main/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import './array-includes';
|
2
|
-
import { Mocker } from './lib/Mocker';
|
3
|
-
export * from './lib/Mocker';
|
4
|
-
export * from './lib/Schema';
|
5
|
-
export * from './lib/Generator';
|
6
|
-
export declare const mocker: (opts?: any) => Mocker;
|
7
|
-
export default mocker;
|
1
|
+
import './array-includes';
|
2
|
+
import { Mocker } from './lib/Mocker';
|
3
|
+
export * from './lib/Mocker';
|
4
|
+
export * from './lib/Schema';
|
5
|
+
export * from './lib/Generator';
|
6
|
+
export declare const mocker: (opts?: any) => Mocker;
|
7
|
+
export default mocker;
|
package/build/main/index.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.mocker = void 0;
|
4
|
-
var tslib_1 = require("tslib");
|
5
|
-
require("./array-includes");
|
6
|
-
var Mocker_1 = require("./lib/Mocker");
|
7
|
-
tslib_1.__exportStar(require("./lib/Mocker"), exports);
|
8
|
-
tslib_1.__exportStar(require("./lib/Schema"), exports);
|
9
|
-
tslib_1.__exportStar(require("./lib/Generator"), exports);
|
10
|
-
var mocker = function (opts) { return new Mocker_1.Mocker(opts); };
|
11
|
-
exports.mocker = mocker;
|
12
|
-
exports.default = exports.mocker;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.mocker = void 0;
|
4
|
+
var tslib_1 = require("tslib");
|
5
|
+
require("./array-includes");
|
6
|
+
var Mocker_1 = require("./lib/Mocker");
|
7
|
+
tslib_1.__exportStar(require("./lib/Mocker"), exports);
|
8
|
+
tslib_1.__exportStar(require("./lib/Schema"), exports);
|
9
|
+
tslib_1.__exportStar(require("./lib/Generator"), exports);
|
10
|
+
var mocker = function (opts) { return new Mocker_1.Mocker(opts); };
|
11
|
+
exports.mocker = mocker;
|
12
|
+
exports.default = exports.mocker;
|
@@ -1 +1 @@
|
|
1
|
-
export {};
|
1
|
+
export {};
|
package/build/main/index.spec.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
var ava_1 = require("ava");
|
4
|
-
var _1 = require("./"), lib = _1;
|
5
|
-
(0, ava_1.default)('functions can be used without es imports', function (t) {
|
6
|
-
t.true(typeof _1.default === 'function');
|
7
|
-
t.true(typeof lib.mocker === 'function');
|
8
|
-
t.true(typeof lib.Mocker === 'function');
|
9
|
-
t.true(typeof lib.Generator === 'function');
|
10
|
-
t.true(typeof lib.Schema === 'function');
|
11
|
-
});
|
12
|
-
(0, ava_1.default)('Mocker: exists all methods', function (t) {
|
13
|
-
var m = (0, _1.default)();
|
14
|
-
var methods = ['schema', 'build', 'reset', 'restart'];
|
15
|
-
methods.forEach(function (method) { return t.true(typeof m[method] === 'function'); });
|
16
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var ava_1 = require("ava");
|
4
|
+
var _1 = require("./"), lib = _1;
|
5
|
+
(0, ava_1.default)('functions can be used without es imports', function (t) {
|
6
|
+
t.true(typeof _1.default === 'function');
|
7
|
+
t.true(typeof lib.mocker === 'function');
|
8
|
+
t.true(typeof lib.Mocker === 'function');
|
9
|
+
t.true(typeof lib.Generator === 'function');
|
10
|
+
t.true(typeof lib.Schema === 'function');
|
11
|
+
});
|
12
|
+
(0, ava_1.default)('Mocker: exists all methods', function (t) {
|
13
|
+
var m = (0, _1.default)();
|
14
|
+
var methods = ['schema', 'build', 'reset', 'restart'];
|
15
|
+
methods.forEach(function (method) { return t.true(typeof m[method] === 'function'); });
|
16
|
+
});
|
@@ -1,61 +1,61 @@
|
|
1
|
-
import { CustomGeneratorRun } from './types';
|
2
|
-
export declare class Generator<T> {
|
3
|
-
name: string;
|
4
|
-
DB: {};
|
5
|
-
object: T;
|
6
|
-
schema: {
|
7
|
-
values: string[];
|
8
|
-
};
|
9
|
-
options: {
|
10
|
-
uniqueField: string;
|
11
|
-
max: number;
|
12
|
-
min: number;
|
13
|
-
};
|
14
|
-
virtualPaths: string[];
|
15
|
-
generators: {};
|
16
|
-
self(cfg: {
|
17
|
-
self: any;
|
18
|
-
eval?: boolean;
|
19
|
-
}): any;
|
20
|
-
db(cfg: {
|
21
|
-
eval?: boolean;
|
22
|
-
db: any;
|
23
|
-
}): any;
|
24
|
-
custom(cfg: {
|
25
|
-
generator: any;
|
26
|
-
input: string | RegExp;
|
27
|
-
run?: CustomGeneratorRun;
|
28
|
-
adapter?: (generator: any, input: string | RegExp) => any;
|
29
|
-
eval?: boolean;
|
30
|
-
}): any;
|
31
|
-
eval(cfg: {
|
32
|
-
eval: string;
|
33
|
-
}): any;
|
34
|
-
values(cfg: {
|
35
|
-
values: any[];
|
36
|
-
}): any;
|
37
|
-
function(cfg: {
|
38
|
-
function: any;
|
39
|
-
}, ...args: any[]): any;
|
40
|
-
static(cfg: {
|
41
|
-
static: any;
|
42
|
-
}): any;
|
43
|
-
incrementalId(cfg: {
|
44
|
-
incrementalId: number | true | string;
|
45
|
-
}): number;
|
46
|
-
hasOne(cfg: {
|
47
|
-
hasOne: string;
|
48
|
-
get?: string;
|
49
|
-
eval?: boolean;
|
50
|
-
uniqueDB?: any[];
|
51
|
-
}): null;
|
52
|
-
hasMany(cfg: {
|
53
|
-
min?: number;
|
54
|
-
max?: number;
|
55
|
-
hasMany: string;
|
56
|
-
amount?: number;
|
57
|
-
get?: string;
|
58
|
-
eval?: boolean;
|
59
|
-
unique?: boolean;
|
60
|
-
}): any;
|
61
|
-
}
|
1
|
+
import { CustomGeneratorRun } from './types';
|
2
|
+
export declare class Generator<T> {
|
3
|
+
name: string;
|
4
|
+
DB: {};
|
5
|
+
object: T;
|
6
|
+
schema: {
|
7
|
+
values: string[];
|
8
|
+
};
|
9
|
+
options: {
|
10
|
+
uniqueField: string;
|
11
|
+
max: number;
|
12
|
+
min: number;
|
13
|
+
};
|
14
|
+
virtualPaths: string[];
|
15
|
+
generators: {};
|
16
|
+
self(cfg: {
|
17
|
+
self: any;
|
18
|
+
eval?: boolean;
|
19
|
+
}): any;
|
20
|
+
db(cfg: {
|
21
|
+
eval?: boolean;
|
22
|
+
db: any;
|
23
|
+
}): any;
|
24
|
+
custom(cfg: {
|
25
|
+
generator: any;
|
26
|
+
input: string | RegExp;
|
27
|
+
run?: CustomGeneratorRun;
|
28
|
+
adapter?: (generator: any, input: string | RegExp) => any;
|
29
|
+
eval?: boolean;
|
30
|
+
}): any;
|
31
|
+
eval(cfg: {
|
32
|
+
eval: string;
|
33
|
+
}): any;
|
34
|
+
values(cfg: {
|
35
|
+
values: any[];
|
36
|
+
}): any;
|
37
|
+
function(cfg: {
|
38
|
+
function: any;
|
39
|
+
}, ...args: any[]): any;
|
40
|
+
static(cfg: {
|
41
|
+
static: any;
|
42
|
+
}): any;
|
43
|
+
incrementalId(cfg: {
|
44
|
+
incrementalId: number | true | string;
|
45
|
+
}): number;
|
46
|
+
hasOne(cfg: {
|
47
|
+
hasOne: string;
|
48
|
+
get?: string;
|
49
|
+
eval?: boolean;
|
50
|
+
uniqueDB?: any[];
|
51
|
+
}): null;
|
52
|
+
hasMany(cfg: {
|
53
|
+
min?: number;
|
54
|
+
max?: number;
|
55
|
+
hasMany: string;
|
56
|
+
amount?: number;
|
57
|
+
get?: string;
|
58
|
+
eval?: boolean;
|
59
|
+
unique?: boolean;
|
60
|
+
}): any;
|
61
|
+
}
|
@@ -1,134 +1,134 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Generator = void 0;
|
4
|
-
var tslib_1 = require("tslib");
|
5
|
-
var utils_1 = require("./utils");
|
6
|
-
var Generator = /** @class */ (function () {
|
7
|
-
function Generator() {
|
8
|
-
}
|
9
|
-
Generator.prototype.self = function (cfg) {
|
10
|
-
var object = this.object;
|
11
|
-
return cfg.eval
|
12
|
-
? eval('object.' + cfg.self)
|
13
|
-
: (0, utils_1.loopInside)(this.object, cfg.self);
|
14
|
-
};
|
15
|
-
Generator.prototype.db = function (cfg) {
|
16
|
-
var db = this.DB;
|
17
|
-
if (cfg.eval) {
|
18
|
-
return eval('db.' + cfg.db);
|
19
|
-
}
|
20
|
-
else {
|
21
|
-
return (0, utils_1.loopInside)(this.DB, cfg.db);
|
22
|
-
}
|
23
|
-
};
|
24
|
-
Generator.prototype.custom = function (cfg) {
|
25
|
-
var db = this.DB;
|
26
|
-
var object = this.object;
|
27
|
-
var re;
|
28
|
-
var matches;
|
29
|
-
var strFn;
|
30
|
-
var generator = cfg.generator;
|
31
|
-
if (cfg.run) {
|
32
|
-
return cfg.run(generator, cfg.input);
|
33
|
-
}
|
34
|
-
else if (cfg.eval) {
|
35
|
-
return eval('generator.' + cfg.input);
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
return utils_1.stringToPathOrCall.call(generator, 'generator', generator, cfg.input);
|
39
|
-
}
|
40
|
-
};
|
41
|
-
Generator.prototype.eval = function (cfg) {
|
42
|
-
var db = this.DB;
|
43
|
-
var object = this.object;
|
44
|
-
var generators = this.generators;
|
45
|
-
return eval(cfg.eval);
|
46
|
-
};
|
47
|
-
Generator.prototype.values = function (cfg) {
|
48
|
-
var i = Math.floor(cfg.values.length * Math.random());
|
49
|
-
return cfg.values[i];
|
50
|
-
};
|
51
|
-
Generator.prototype.function = function (cfg) {
|
52
|
-
var _a;
|
53
|
-
var args = [];
|
54
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
55
|
-
args[_i - 1] = arguments[_i];
|
56
|
-
}
|
57
|
-
var object = this.object;
|
58
|
-
var db = this.DB;
|
59
|
-
var generators = this.generators;
|
60
|
-
return (_a = cfg.function).call.apply(_a, tslib_1.__spreadArray([{ object: object, db: db, generators: generators }], args, false));
|
61
|
-
};
|
62
|
-
Generator.prototype.static = function (cfg) {
|
63
|
-
return cfg.static;
|
64
|
-
};
|
65
|
-
Generator.prototype.incrementalId = function (cfg) {
|
66
|
-
var n = 0;
|
67
|
-
var db = this.DB;
|
68
|
-
if (db[this.name] && db[this.name].length) {
|
69
|
-
n = db[this.name].length;
|
70
|
-
}
|
71
|
-
if (cfg.incrementalId === true) {
|
72
|
-
cfg.incrementalId = '0';
|
73
|
-
}
|
74
|
-
return n + parseInt(cfg.incrementalId, 10);
|
75
|
-
};
|
76
|
-
Generator.prototype.hasOne = function (cfg) {
|
77
|
-
var db = this.DB;
|
78
|
-
var entity = null;
|
79
|
-
if (cfg.uniqueDB) {
|
80
|
-
var dbString = JSON.stringify(cfg.uniqueDB);
|
81
|
-
for (var i = 0; i < db[cfg.hasOne].length; i++) {
|
82
|
-
var element = db[cfg.hasOne][i];
|
83
|
-
element = cfg.get
|
84
|
-
? cfg.eval
|
85
|
-
? eval('element.' + cfg.get)
|
86
|
-
: (0, utils_1.loopInside)(element, cfg.get)
|
87
|
-
: element;
|
88
|
-
if (cfg.uniqueDB.length === 0 ||
|
89
|
-
dbString.indexOf(JSON.stringify(element)) < 0) {
|
90
|
-
entity = element;
|
91
|
-
break;
|
92
|
-
}
|
93
|
-
}
|
94
|
-
if (entity === null) {
|
95
|
-
throw "Can\u00B4t get unique data. Source \"".concat(cfg.hasOne, "\" has not enough data");
|
96
|
-
}
|
97
|
-
}
|
98
|
-
else {
|
99
|
-
var i = Math.floor(db[cfg.hasOne].length * Math.random());
|
100
|
-
entity = db[cfg.hasOne][i];
|
101
|
-
entity = cfg.get
|
102
|
-
? cfg.eval
|
103
|
-
? eval('entity.' + cfg.get)
|
104
|
-
: (0, utils_1.loopInside)(entity, cfg.get)
|
105
|
-
: entity;
|
106
|
-
}
|
107
|
-
return entity;
|
108
|
-
};
|
109
|
-
Generator.prototype.hasMany = function (cfg) {
|
110
|
-
var _this = this;
|
111
|
-
var amount = 1;
|
112
|
-
var db = this.DB;
|
113
|
-
var min = cfg.min || cfg.min === 0 ? cfg.min : 1;
|
114
|
-
var max = cfg.max ? cfg.max : cfg.hasMany ? db[cfg.hasMany].length : 1;
|
115
|
-
if (cfg.amount) {
|
116
|
-
amount = cfg.amount;
|
117
|
-
}
|
118
|
-
else {
|
119
|
-
amount = Math.floor(Math.random() * (max - min + 1)) + min;
|
120
|
-
}
|
121
|
-
var newCfg = {
|
122
|
-
hasOne: cfg.hasMany,
|
123
|
-
get: cfg.get ? cfg.get : undefined,
|
124
|
-
eval: cfg.eval ? true : false
|
125
|
-
};
|
126
|
-
return cfg.unique
|
127
|
-
? Array.from(new Array(amount)).reduce(function (acc, val) { return tslib_1.__spreadArray(tslib_1.__spreadArray([], acc, true), [
|
128
|
-
_this.hasOne(tslib_1.__assign(tslib_1.__assign({}, newCfg), { uniqueDB: acc }))
|
129
|
-
], false); }, [])
|
130
|
-
: Array.from(new Array(amount)).map(function () { return _this.hasOne(newCfg); });
|
131
|
-
};
|
132
|
-
return Generator;
|
133
|
-
}());
|
134
|
-
exports.Generator = Generator;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Generator = void 0;
|
4
|
+
var tslib_1 = require("tslib");
|
5
|
+
var utils_1 = require("./utils");
|
6
|
+
var Generator = /** @class */ (function () {
|
7
|
+
function Generator() {
|
8
|
+
}
|
9
|
+
Generator.prototype.self = function (cfg) {
|
10
|
+
var object = this.object;
|
11
|
+
return cfg.eval
|
12
|
+
? eval('object.' + cfg.self)
|
13
|
+
: (0, utils_1.loopInside)(this.object, cfg.self);
|
14
|
+
};
|
15
|
+
Generator.prototype.db = function (cfg) {
|
16
|
+
var db = this.DB;
|
17
|
+
if (cfg.eval) {
|
18
|
+
return eval('db.' + cfg.db);
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
return (0, utils_1.loopInside)(this.DB, cfg.db);
|
22
|
+
}
|
23
|
+
};
|
24
|
+
Generator.prototype.custom = function (cfg) {
|
25
|
+
var db = this.DB;
|
26
|
+
var object = this.object;
|
27
|
+
var re;
|
28
|
+
var matches;
|
29
|
+
var strFn;
|
30
|
+
var generator = cfg.generator;
|
31
|
+
if (cfg.run) {
|
32
|
+
return cfg.run(generator, cfg.input);
|
33
|
+
}
|
34
|
+
else if (cfg.eval) {
|
35
|
+
return eval('generator.' + cfg.input);
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
return utils_1.stringToPathOrCall.call(generator, 'generator', generator, cfg.input);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
Generator.prototype.eval = function (cfg) {
|
42
|
+
var db = this.DB;
|
43
|
+
var object = this.object;
|
44
|
+
var generators = this.generators;
|
45
|
+
return eval(cfg.eval);
|
46
|
+
};
|
47
|
+
Generator.prototype.values = function (cfg) {
|
48
|
+
var i = Math.floor(cfg.values.length * Math.random());
|
49
|
+
return cfg.values[i];
|
50
|
+
};
|
51
|
+
Generator.prototype.function = function (cfg) {
|
52
|
+
var _a;
|
53
|
+
var args = [];
|
54
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
55
|
+
args[_i - 1] = arguments[_i];
|
56
|
+
}
|
57
|
+
var object = this.object;
|
58
|
+
var db = this.DB;
|
59
|
+
var generators = this.generators;
|
60
|
+
return (_a = cfg.function).call.apply(_a, tslib_1.__spreadArray([{ object: object, db: db, generators: generators }], args, false));
|
61
|
+
};
|
62
|
+
Generator.prototype.static = function (cfg) {
|
63
|
+
return cfg.static;
|
64
|
+
};
|
65
|
+
Generator.prototype.incrementalId = function (cfg) {
|
66
|
+
var n = 0;
|
67
|
+
var db = this.DB;
|
68
|
+
if (db[this.name] && db[this.name].length) {
|
69
|
+
n = db[this.name].length;
|
70
|
+
}
|
71
|
+
if (cfg.incrementalId === true) {
|
72
|
+
cfg.incrementalId = '0';
|
73
|
+
}
|
74
|
+
return n + parseInt(cfg.incrementalId, 10);
|
75
|
+
};
|
76
|
+
Generator.prototype.hasOne = function (cfg) {
|
77
|
+
var db = this.DB;
|
78
|
+
var entity = null;
|
79
|
+
if (cfg.uniqueDB) {
|
80
|
+
var dbString = JSON.stringify(cfg.uniqueDB);
|
81
|
+
for (var i = 0; i < db[cfg.hasOne].length; i++) {
|
82
|
+
var element = db[cfg.hasOne][i];
|
83
|
+
element = cfg.get
|
84
|
+
? cfg.eval
|
85
|
+
? eval('element.' + cfg.get)
|
86
|
+
: (0, utils_1.loopInside)(element, cfg.get)
|
87
|
+
: element;
|
88
|
+
if (cfg.uniqueDB.length === 0 ||
|
89
|
+
dbString.indexOf(JSON.stringify(element)) < 0) {
|
90
|
+
entity = element;
|
91
|
+
break;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
if (entity === null) {
|
95
|
+
throw "Can\u00B4t get unique data. Source \"".concat(cfg.hasOne, "\" has not enough data");
|
96
|
+
}
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
var i = Math.floor(db[cfg.hasOne].length * Math.random());
|
100
|
+
entity = db[cfg.hasOne][i];
|
101
|
+
entity = cfg.get
|
102
|
+
? cfg.eval
|
103
|
+
? eval('entity.' + cfg.get)
|
104
|
+
: (0, utils_1.loopInside)(entity, cfg.get)
|
105
|
+
: entity;
|
106
|
+
}
|
107
|
+
return entity;
|
108
|
+
};
|
109
|
+
Generator.prototype.hasMany = function (cfg) {
|
110
|
+
var _this = this;
|
111
|
+
var amount = 1;
|
112
|
+
var db = this.DB;
|
113
|
+
var min = cfg.min || cfg.min === 0 ? cfg.min : 1;
|
114
|
+
var max = cfg.max ? cfg.max : cfg.hasMany ? db[cfg.hasMany].length : 1;
|
115
|
+
if (cfg.amount) {
|
116
|
+
amount = cfg.amount;
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
amount = Math.floor(Math.random() * (max - min + 1)) + min;
|
120
|
+
}
|
121
|
+
var newCfg = {
|
122
|
+
hasOne: cfg.hasMany,
|
123
|
+
get: cfg.get ? cfg.get : undefined,
|
124
|
+
eval: cfg.eval ? true : false
|
125
|
+
};
|
126
|
+
return cfg.unique
|
127
|
+
? Array.from(new Array(amount)).reduce(function (acc, val) { return tslib_1.__spreadArray(tslib_1.__spreadArray([], acc, true), [
|
128
|
+
_this.hasOne(tslib_1.__assign(tslib_1.__assign({}, newCfg), { uniqueDB: acc }))
|
129
|
+
], false); }, [])
|
130
|
+
: Array.from(new Array(amount)).map(function () { return _this.hasOne(newCfg); });
|
131
|
+
};
|
132
|
+
return Generator;
|
133
|
+
}());
|
134
|
+
exports.Generator = Generator;
|