@akanjs/test 0.0.34 → 0.0.35
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.js +626 -21
- package/package.json +10 -57
- package/README.md +0 -11
- package/index.d.ts +0 -1
- package/src/index.d.ts +0 -2
- package/src/index.js +0 -30
- package/src/jest.config.base.d.ts +0 -2
- package/src/jest.config.base.js +0 -56
- package/src/jest.config.base.ts +0 -32
- package/src/jest.globalSetup.d.ts +0 -4
- package/src/jest.globalSetup.js +0 -38
- package/src/jest.globalSetup.ts +0 -26
- package/src/jest.globalTeardown.d.ts +0 -3
- package/src/jest.globalTeardown.js +0 -30
- package/src/jest.globalTeardown.ts +0 -12
- package/src/jest.setupFilesAfterEnv.d.ts +0 -1
- package/src/jest.setupFilesAfterEnv.js +0 -10
- package/src/jest.setupFilesAfterEnv.ts +0 -17
- package/src/jest.testServer.d.ts +0 -11
- package/src/jest.testServer.js +0 -139
- package/src/jest.testServer.ts +0 -104
- package/src/playwright.config.base.d.ts +0 -9
- package/src/playwright.config.base.js +0 -80
- package/src/playwright.config.base.ts +0 -71
- package/src/playwright.pageAgent.d.ts +0 -13
- package/src/playwright.pageAgent.js +0 -67
- package/src/playwright.pageAgent.ts +0 -42
- package/src/sample.d.ts +0 -14
- package/src/sample.js +0 -45
- package/src/sampleOf.d.ts +0 -6
- package/src/sampleOf.js +0 -80
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var playwright_config_base_exports = {};
|
|
19
|
-
__export(playwright_config_base_exports, {
|
|
20
|
-
withBase: () => withBase
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(playwright_config_base_exports);
|
|
23
|
-
var import_devkit = require("@nx/devkit");
|
|
24
|
-
var import_preset = require("@nx/playwright/preset");
|
|
25
|
-
var import_test = require("@playwright/test");
|
|
26
|
-
const baseURL = process.env.BASE_URL ?? "http://127.0.0.1:4200";
|
|
27
|
-
const projectName = process.env.NX_TASK_TARGET_PROJECT ?? "unknown";
|
|
28
|
-
const withBase = (filename, config = {}) => (0, import_test.defineConfig)({
|
|
29
|
-
...(0, import_preset.nxE2EPreset)(filename, { testDir: "./app" }),
|
|
30
|
-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
31
|
-
use: {
|
|
32
|
-
baseURL,
|
|
33
|
-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
34
|
-
trace: "on-first-retry"
|
|
35
|
-
},
|
|
36
|
-
/* Run your local dev server before starting the tests */
|
|
37
|
-
webServer: {
|
|
38
|
-
command: `nx serve ${projectName}`,
|
|
39
|
-
url: "http://127.0.0.1:4200",
|
|
40
|
-
reuseExistingServer: !process.env.CI,
|
|
41
|
-
cwd: import_devkit.workspaceRoot
|
|
42
|
-
},
|
|
43
|
-
projects: [
|
|
44
|
-
{
|
|
45
|
-
name: "chromium",
|
|
46
|
-
use: { ...import_test.devices["Desktop Chrome"] }
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "firefox",
|
|
50
|
-
use: { ...import_test.devices["Desktop Firefox"] }
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: "webkit",
|
|
54
|
-
use: { ...import_test.devices["Desktop Safari"] }
|
|
55
|
-
}
|
|
56
|
-
// Uncomment for mobile browsers support
|
|
57
|
-
/* {
|
|
58
|
-
name: 'Mobile Chrome',
|
|
59
|
-
use: { ...devices['Pixel 5'] },
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'Mobile Safari',
|
|
63
|
-
use: { ...devices['iPhone 12'] },
|
|
64
|
-
}, */
|
|
65
|
-
// Uncomment for branded browsers
|
|
66
|
-
/* {
|
|
67
|
-
name: 'Microsoft Edge',
|
|
68
|
-
use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'Google Chrome',
|
|
72
|
-
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
73
|
-
} */
|
|
74
|
-
],
|
|
75
|
-
...config
|
|
76
|
-
});
|
|
77
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 && (module.exports = {
|
|
79
|
-
withBase
|
|
80
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { workspaceRoot } from "@nx/devkit";
|
|
2
|
-
import { nxE2EPreset } from "@nx/playwright/preset";
|
|
3
|
-
import { defineConfig, devices, type PlaywrightTestConfig } from "@playwright/test";
|
|
4
|
-
|
|
5
|
-
// For CI, you may want to set BASE_URL to the deployed application.
|
|
6
|
-
const baseURL = process.env.BASE_URL ?? "http://127.0.0.1:4200";
|
|
7
|
-
const projectName = process.env.NX_TASK_TARGET_PROJECT ?? "unknown";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Read environment variables from file.
|
|
11
|
-
* https://github.com/motdotla/dotenv
|
|
12
|
-
*/
|
|
13
|
-
// require('dotenv').config();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* See https://playwright.dev/docs/test-configuration.
|
|
17
|
-
*/
|
|
18
|
-
export const withBase = (filename: string, config: PlaywrightTestConfig = {}) =>
|
|
19
|
-
defineConfig({
|
|
20
|
-
...nxE2EPreset(filename, { testDir: "./app" }),
|
|
21
|
-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
22
|
-
use: {
|
|
23
|
-
baseURL,
|
|
24
|
-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
25
|
-
trace: "on-first-retry",
|
|
26
|
-
},
|
|
27
|
-
/* Run your local dev server before starting the tests */
|
|
28
|
-
webServer: {
|
|
29
|
-
command: `nx serve ${projectName}`,
|
|
30
|
-
url: "http://127.0.0.1:4200",
|
|
31
|
-
reuseExistingServer: !process.env.CI,
|
|
32
|
-
cwd: workspaceRoot,
|
|
33
|
-
},
|
|
34
|
-
projects: [
|
|
35
|
-
{
|
|
36
|
-
name: "chromium",
|
|
37
|
-
use: { ...devices["Desktop Chrome"] },
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
name: "firefox",
|
|
42
|
-
use: { ...devices["Desktop Firefox"] },
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
name: "webkit",
|
|
47
|
-
use: { ...devices["Desktop Safari"] },
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
// Uncomment for mobile browsers support
|
|
51
|
-
/* {
|
|
52
|
-
name: 'Mobile Chrome',
|
|
53
|
-
use: { ...devices['Pixel 5'] },
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'Mobile Safari',
|
|
57
|
-
use: { ...devices['iPhone 12'] },
|
|
58
|
-
}, */
|
|
59
|
-
|
|
60
|
-
// Uncomment for branded browsers
|
|
61
|
-
/* {
|
|
62
|
-
name: 'Microsoft Edge',
|
|
63
|
-
use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'Google Chrome',
|
|
67
|
-
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
68
|
-
} */
|
|
69
|
-
],
|
|
70
|
-
...config,
|
|
71
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type Page } from "@playwright/test";
|
|
2
|
-
import { test } from "@playwright/test";
|
|
3
|
-
export { expect } from "@playwright/test";
|
|
4
|
-
export { test };
|
|
5
|
-
export declare class PageAgent {
|
|
6
|
-
#private;
|
|
7
|
-
readonly page: Page;
|
|
8
|
-
constructor(page: Page);
|
|
9
|
-
goto(path: string): Promise<void>;
|
|
10
|
-
waitForPathChange(path?: string): Promise<unknown>;
|
|
11
|
-
wait(ms?: number): Promise<void>;
|
|
12
|
-
url(): string;
|
|
13
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var playwright_pageAgent_exports = {};
|
|
19
|
-
__export(playwright_pageAgent_exports, {
|
|
20
|
-
PageAgent: () => PageAgent,
|
|
21
|
-
expect: () => import_test3.expect,
|
|
22
|
-
test: () => import_test2.test
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(playwright_pageAgent_exports);
|
|
25
|
-
var import_test2 = require("@playwright/test");
|
|
26
|
-
var import_test3 = require("@playwright/test");
|
|
27
|
-
class PageAgent {
|
|
28
|
-
page;
|
|
29
|
-
#defaultWaitMs = 500;
|
|
30
|
-
#isInitialized = false;
|
|
31
|
-
constructor(page) {
|
|
32
|
-
this.page = page;
|
|
33
|
-
}
|
|
34
|
-
async goto(path) {
|
|
35
|
-
await Promise.all([this.page.goto(path), this.waitForPathChange(path)]);
|
|
36
|
-
if (!this.#isInitialized) {
|
|
37
|
-
this.#isInitialized = true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async waitForPathChange(path) {
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
const timeout = setTimeout(() => {
|
|
43
|
-
reject(new Error("Timeout waiting for pathChange message"));
|
|
44
|
-
}, 3e4);
|
|
45
|
-
this.page.on("console", (msg) => {
|
|
46
|
-
if (msg.type() === "log" && msg.text().startsWith(`%cpathChange-finished:${path ?? ""}`)) {
|
|
47
|
-
clearInterval(timeout);
|
|
48
|
-
setTimeout(() => {
|
|
49
|
-
resolve(true);
|
|
50
|
-
}, this.#defaultWaitMs);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async wait(ms = this.#defaultWaitMs) {
|
|
56
|
-
await this.page.waitForTimeout(ms);
|
|
57
|
-
}
|
|
58
|
-
url() {
|
|
59
|
-
return "/" + this.page.url().split("/").slice(4).join("/");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
-
0 && (module.exports = {
|
|
64
|
-
PageAgent,
|
|
65
|
-
expect,
|
|
66
|
-
test
|
|
67
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type Page } from "@playwright/test";
|
|
2
|
-
import { test } from "@playwright/test";
|
|
3
|
-
|
|
4
|
-
export { expect } from "@playwright/test";
|
|
5
|
-
export { test };
|
|
6
|
-
|
|
7
|
-
export class PageAgent {
|
|
8
|
-
readonly page: Page;
|
|
9
|
-
readonly #defaultWaitMs = 500;
|
|
10
|
-
#isInitialized = false;
|
|
11
|
-
constructor(page: Page) {
|
|
12
|
-
this.page = page;
|
|
13
|
-
}
|
|
14
|
-
async goto(path: string) {
|
|
15
|
-
await Promise.all([this.page.goto(path), this.waitForPathChange(path)]);
|
|
16
|
-
if (!this.#isInitialized) {
|
|
17
|
-
// await this.page.waitForEvent("websocket");
|
|
18
|
-
this.#isInitialized = true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async waitForPathChange(path?: string) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const timeout = setTimeout(() => {
|
|
24
|
-
reject(new Error("Timeout waiting for pathChange message"));
|
|
25
|
-
}, 30000);
|
|
26
|
-
this.page.on("console", (msg) => {
|
|
27
|
-
if (msg.type() === "log" && msg.text().startsWith(`%cpathChange-finished:${path ?? ""}`)) {
|
|
28
|
-
clearInterval(timeout);
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
resolve(true);
|
|
31
|
-
}, this.#defaultWaitMs);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async wait(ms = this.#defaultWaitMs) {
|
|
37
|
-
await this.page.waitForTimeout(ms);
|
|
38
|
-
}
|
|
39
|
-
url() {
|
|
40
|
-
return "/" + this.page.url().split("/").slice(4).join("/");
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/sample.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Dayjs } from "@akanjs/base";
|
|
2
|
-
export declare const sample: Chance.Chance & {
|
|
3
|
-
dayjs: (opt?: {
|
|
4
|
-
string?: boolean | undefined;
|
|
5
|
-
american?: boolean | undefined;
|
|
6
|
-
year?: number | undefined;
|
|
7
|
-
month?: number | undefined;
|
|
8
|
-
day?: number | undefined;
|
|
9
|
-
min?: Dayjs | undefined;
|
|
10
|
-
max?: Dayjs | undefined;
|
|
11
|
-
}) => Dayjs;
|
|
12
|
-
pick: <T = any>(arr: T[] | readonly T[]) => T;
|
|
13
|
-
picks: <T>(arr: T[] | readonly T[], count?: number, allowDuplicate?: boolean) => T[];
|
|
14
|
-
};
|
package/src/sample.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var sample_exports = {};
|
|
29
|
-
__export(sample_exports, {
|
|
30
|
-
sample: () => sample
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(sample_exports);
|
|
33
|
-
var import_base = require("@akanjs/base");
|
|
34
|
-
var import_common = require("@akanjs/common");
|
|
35
|
-
var import_chance = __toESM(require("chance"));
|
|
36
|
-
const chance = new import_chance.default();
|
|
37
|
-
const sample = Object.assign(chance, {
|
|
38
|
-
dayjs: (opt) => (0, import_base.dayjs)(chance.date({ ...opt, min: opt?.min?.toDate(), max: opt?.max?.toDate() })),
|
|
39
|
-
pick: import_common.randomPick,
|
|
40
|
-
picks: import_common.randomPicks
|
|
41
|
-
});
|
|
42
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
-
0 && (module.exports = {
|
|
44
|
-
sample
|
|
45
|
-
});
|
package/src/sampleOf.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BaseObject, Type } from "@akanjs/base";
|
|
2
|
-
import { DocumentModel } from "@akanjs/constant";
|
|
3
|
-
export type SampleOf<Model> = DocumentModel<{
|
|
4
|
-
[K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>;
|
|
5
|
-
}>;
|
|
6
|
-
export declare const sampleOf: <Model>(modelRef: Type<Model>) => DocumentModel<{ [K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>; }>;
|
package/src/sampleOf.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var sampleOf_exports = {};
|
|
19
|
-
__export(sampleOf_exports, {
|
|
20
|
-
sampleOf: () => sampleOf
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(sampleOf_exports);
|
|
23
|
-
var import_base = require("@akanjs/base");
|
|
24
|
-
var import_common = require("@akanjs/common");
|
|
25
|
-
var import_constant = require("@akanjs/constant");
|
|
26
|
-
var import_sample = require("./sample");
|
|
27
|
-
const getFieldTypeExample = {
|
|
28
|
-
email: () => import_sample.sample.email(),
|
|
29
|
-
password: () => import_sample.sample.string({ length: 8 }),
|
|
30
|
-
url: () => import_sample.sample.url()
|
|
31
|
-
};
|
|
32
|
-
const scalarSampleMap = /* @__PURE__ */ new Map([
|
|
33
|
-
[import_base.ID, () => import_sample.sample.hash({ length: 24 })],
|
|
34
|
-
[import_base.Int, () => import_sample.sample.integer({ min: -1e4, max: 1e4 })],
|
|
35
|
-
[import_base.Float, () => import_sample.sample.floating({ min: -1e4, max: 1e4 })],
|
|
36
|
-
[String, () => import_sample.sample.string({ length: 100 })],
|
|
37
|
-
[Boolean, () => import_sample.sample.bool()],
|
|
38
|
-
[Date, () => import_sample.sample.dayjs()],
|
|
39
|
-
[import_base.Upload, () => "FileUpload"],
|
|
40
|
-
[import_base.JSON, () => ({})]
|
|
41
|
-
]);
|
|
42
|
-
const getScalarSample = (ref, fieldMeta) => {
|
|
43
|
-
if (fieldMeta.type) {
|
|
44
|
-
return getFieldTypeExample[fieldMeta.type]();
|
|
45
|
-
} else if (typeof fieldMeta.min === "number") {
|
|
46
|
-
return fieldMeta.min;
|
|
47
|
-
} else if (typeof fieldMeta.max === "number") {
|
|
48
|
-
return fieldMeta.max;
|
|
49
|
-
} else {
|
|
50
|
-
return scalarSampleMap.get(ref)?.() ?? null;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const makeSample = (fieldMeta) => {
|
|
54
|
-
if (fieldMeta.default)
|
|
55
|
-
return typeof fieldMeta.default === "function" ? fieldMeta.default() : fieldMeta.default;
|
|
56
|
-
else if (fieldMeta.enum)
|
|
57
|
-
return (0, import_common.randomPick)([...fieldMeta.enum.values]);
|
|
58
|
-
if ((0, import_base.isGqlScalar)(fieldMeta.modelRef))
|
|
59
|
-
return getScalarSample(fieldMeta.modelRef, fieldMeta);
|
|
60
|
-
return Object.fromEntries(
|
|
61
|
-
(0, import_constant.getFieldMetas)(fieldMeta.modelRef).map(
|
|
62
|
-
(fieldMeta2) => [
|
|
63
|
-
fieldMeta2.key,
|
|
64
|
-
fieldMeta2.arrDepth ? [] : fieldMeta2.isClass && !fieldMeta2.isScalar ? null : makeSample(fieldMeta2)
|
|
65
|
-
]
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
const sampleOf = (modelRef) => {
|
|
70
|
-
return Object.fromEntries(
|
|
71
|
-
(0, import_constant.getFieldMetas)(modelRef).map((fieldMeta) => [
|
|
72
|
-
fieldMeta.key,
|
|
73
|
-
fieldMeta.arrDepth ? [] : fieldMeta.isClass && !fieldMeta.isScalar ? null : makeSample(fieldMeta)
|
|
74
|
-
])
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 && (module.exports = {
|
|
79
|
-
sampleOf
|
|
80
|
-
});
|