nestia 3.0.17 → 3.1.1-dev.20221015
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/README.md +10 -0
- package/lib/executable/internal/NestiaStarter.d.ts +3 -0
- package/lib/executable/internal/NestiaStarter.js +61 -0
- package/lib/executable/internal/NestiaStarter.js.map +1 -0
- package/lib/executable/nestia.js +5 -2
- package/lib/executable/nestia.js.map +1 -1
- package/package.json +1 -1
- package/template/.github/workflows/build.yml +18 -0
- package/template/.vscode/launch.json +19 -0
- package/template/.vscode/settings.json +10 -0
- package/template/LICENSE +21 -0
- package/template/README.md +131 -0
- package/template/nestia.config.ts +12 -0
- package/template/package.json +62 -0
- package/template/packages/api/LICENSE +21 -0
- package/template/packages/api/README.md +66 -0
- package/template/packages/api/package.json +21 -0
- package/template/src/Backend.ts +65 -0
- package/template/src/Configuration.ts +11 -0
- package/template/src/api/HttpError.ts +1 -0
- package/template/src/api/IConnection.ts +1 -0
- package/template/src/api/Primitive.ts +1 -0
- package/template/src/api/__internal/AesPkcs5.ts +1 -0
- package/template/src/api/__internal/Fetcher.ts +1 -0
- package/template/src/api/functional/bbs/articles/index.ts +166 -0
- package/template/src/api/functional/bbs/index.ts +7 -0
- package/template/src/api/functional/index.ts +7 -0
- package/template/src/api/index.ts +4 -0
- package/template/src/api/module.ts +5 -0
- package/template/src/api/structures/bbs/IBbsArticle.ts +142 -0
- package/template/src/api/structures/common/IAttachmentFile.ts +5 -0
- package/template/src/api/structures/common/IPage.ts +75 -0
- package/template/src/controllers/BbsArticlesController.ts +46 -0
- package/template/src/providers/bbs/BbsArticleProvider.ts +217 -0
- package/template/src/test/features/api/bbs/test_api_bbs_article_at.ts +52 -0
- package/template/src/test/features/api/bbs/test_api_bbs_article_index_search.ts +82 -0
- package/template/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts +49 -0
- package/template/src/test/features/api/bbs/test_api_bbs_article_store.ts +44 -0
- package/template/src/test/features/api/bbs/test_api_bbs_article_update.ts +66 -0
- package/template/src/test/index.ts +45 -0
- package/template/src/test/internal/DynamicImportIterator.ts +119 -0
- package/template/src/test/internal/GaffComparator.ts +48 -0
- package/template/src/test/internal/IPointer.ts +3 -0
- package/template/src/test/internal/RandomGenerator.ts +72 -0
- package/template/src/test/internal/StopWatch.ts +16 -0
- package/template/src/test/internal/exception_must_be_thrown.ts +11 -0
- package/template/src/test/internal/validate_index.ts +29 -0
- package/template/src/test/internal/validate_index_sort.ts +39 -0
- package/template/src/utils/ArrayUtil.ts +86 -0
- package/template/src/utils/MapUtil.ts +14 -0
- package/template/tsconfig.api.json +15 -0
- package/template/tsconfig.json +118 -0
- package/tsconfig.json +82 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import TSON from "typescript-json";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import api from "@ORGANIZATION/PROJECT-api/lib/index";
|
|
5
|
+
import { IBbsArticle } from "@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle";
|
|
6
|
+
|
|
7
|
+
import { exception_must_be_thrown } from "../../../internal/exception_must_be_thrown";
|
|
8
|
+
|
|
9
|
+
export async function test_api_bbs_article_at(
|
|
10
|
+
connection: api.IConnection,
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
// STORE A NEW ARTICLE
|
|
13
|
+
const stored: IBbsArticle = await api.functional.bbs.articles.store(
|
|
14
|
+
connection,
|
|
15
|
+
"general",
|
|
16
|
+
{
|
|
17
|
+
writer: "Robot",
|
|
18
|
+
title: "Hello, world!",
|
|
19
|
+
body: "Hello, I'm test automation robot",
|
|
20
|
+
format: "txt",
|
|
21
|
+
files: [
|
|
22
|
+
{
|
|
23
|
+
name: "logo",
|
|
24
|
+
extension: "png",
|
|
25
|
+
url: "https://somewhere.com/logo.png",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
password: "1234",
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
TSON.assertEquals(stored);
|
|
32
|
+
|
|
33
|
+
// READ IT
|
|
34
|
+
const read: IBbsArticle = await api.functional.bbs.articles.at(
|
|
35
|
+
connection,
|
|
36
|
+
stored.section,
|
|
37
|
+
stored.id,
|
|
38
|
+
);
|
|
39
|
+
TSON.assertEquals(read);
|
|
40
|
+
|
|
41
|
+
// CHECK EQUALITY
|
|
42
|
+
if (api.Primitive.equal_to(stored, read) === false)
|
|
43
|
+
throw new Error("Bug on BbsArticleProvider.at(): different data.");
|
|
44
|
+
|
|
45
|
+
// TRY 404 ERRORS
|
|
46
|
+
await exception_must_be_thrown("wrong section", () =>
|
|
47
|
+
api.functional.bbs.articles.at(connection, v4(), stored.id),
|
|
48
|
+
);
|
|
49
|
+
await exception_must_be_thrown("wrong id", () =>
|
|
50
|
+
api.functional.bbs.articles.at(connection, stored.section, v4()),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import TSON from "typescript-json";
|
|
2
|
+
|
|
3
|
+
import api from "@ORGANIZATION/PROJECT-api/lib/index";
|
|
4
|
+
import { IBbsArticle } from "@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle";
|
|
5
|
+
import { IPage } from "@ORGANIZATION/PROJECT-api/lib/structures/common/IPage";
|
|
6
|
+
|
|
7
|
+
import { ArrayUtil } from "../../../../utils/ArrayUtil";
|
|
8
|
+
import { RandomGenerator } from "../../../internal/RandomGenerator";
|
|
9
|
+
import { validate_index } from "../../../internal/validate_index";
|
|
10
|
+
|
|
11
|
+
export async function test_api_bbs_article_index_search(
|
|
12
|
+
connection: api.IConnection,
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
// GENERATE 100 ARTICLES
|
|
15
|
+
const section: string = "general";
|
|
16
|
+
const articles: IBbsArticle[] = await ArrayUtil.asyncRepeat(100, () =>
|
|
17
|
+
api.functional.bbs.articles.store(connection, section, {
|
|
18
|
+
writer: RandomGenerator.name(),
|
|
19
|
+
title: RandomGenerator.paragraph(),
|
|
20
|
+
body: RandomGenerator.content(),
|
|
21
|
+
format: "txt",
|
|
22
|
+
files: [],
|
|
23
|
+
password: RandomGenerator.alphabets(8),
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
TSON.assertEquals(articles);
|
|
27
|
+
|
|
28
|
+
// DO SEARCH
|
|
29
|
+
const validator = search(connection, articles);
|
|
30
|
+
await validator(
|
|
31
|
+
"writer",
|
|
32
|
+
(x) => x.writer,
|
|
33
|
+
(elem, word) => elem.writer.indexOf(word) !== -1,
|
|
34
|
+
);
|
|
35
|
+
await validator(
|
|
36
|
+
"title",
|
|
37
|
+
(x) => x.contents.at(-1)!.title,
|
|
38
|
+
(elem, word) => elem.contents.at(-1)!.title.indexOf(word) !== -1,
|
|
39
|
+
);
|
|
40
|
+
await validator(
|
|
41
|
+
"body",
|
|
42
|
+
(x) => x.contents.at(-1)!.body,
|
|
43
|
+
(elem, word) => elem.contents.at(-1)!.body.indexOf(word) !== -1,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const search =
|
|
48
|
+
(connection: api.IConnection, total: IBbsArticle[]) =>
|
|
49
|
+
async (
|
|
50
|
+
field: string,
|
|
51
|
+
getter: (
|
|
52
|
+
record: IBbsArticle,
|
|
53
|
+
input: IBbsArticle.IRequest.ISearch,
|
|
54
|
+
) => string,
|
|
55
|
+
filter: (record: IBbsArticle, word: string) => boolean,
|
|
56
|
+
): Promise<void> => {
|
|
57
|
+
const input: IBbsArticle.IRequest = {
|
|
58
|
+
limit: total.length,
|
|
59
|
+
search: {},
|
|
60
|
+
};
|
|
61
|
+
const value: string = getter(
|
|
62
|
+
RandomGenerator.pick(total),
|
|
63
|
+
input.search!,
|
|
64
|
+
);
|
|
65
|
+
const matched: IBbsArticle[] = total.filter((elem) =>
|
|
66
|
+
filter(elem, value),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const page: IPage<IBbsArticle.ISummary> =
|
|
70
|
+
await api.functional.bbs.articles.index(
|
|
71
|
+
connection,
|
|
72
|
+
"general",
|
|
73
|
+
input,
|
|
74
|
+
);
|
|
75
|
+
TSON.assertEquals(page);
|
|
76
|
+
|
|
77
|
+
validate_index(
|
|
78
|
+
`BbsArticleProvider.index() with ${field} searching`,
|
|
79
|
+
matched,
|
|
80
|
+
page.data,
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import TSON from "typescript-json";
|
|
2
|
+
|
|
3
|
+
import api from "@ORGANIZATION/PROJECT-api/lib/index";
|
|
4
|
+
import { IBbsArticle } from "@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle";
|
|
5
|
+
|
|
6
|
+
import { ArrayUtil } from "../../../../utils/ArrayUtil";
|
|
7
|
+
import { GaffComparator } from "../../../internal/GaffComparator";
|
|
8
|
+
import { RandomGenerator } from "../../../internal/RandomGenerator";
|
|
9
|
+
import { validate_index_sort } from "../../../internal/validate_index_sort";
|
|
10
|
+
|
|
11
|
+
export async function test_api_bbs_article_index_sort(
|
|
12
|
+
connection: api.IConnection,
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
// GENERATE 100 ARTICLES
|
|
15
|
+
const section: string = "general";
|
|
16
|
+
const articles: IBbsArticle[] = await ArrayUtil.asyncRepeat(100, () =>
|
|
17
|
+
api.functional.bbs.articles.store(connection, section, {
|
|
18
|
+
writer: RandomGenerator.name(),
|
|
19
|
+
title: RandomGenerator.paragraph(),
|
|
20
|
+
body: RandomGenerator.content(),
|
|
21
|
+
format: "txt",
|
|
22
|
+
files: [],
|
|
23
|
+
password: RandomGenerator.alphabets(8),
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
TSON.assertEquals(articles);
|
|
27
|
+
|
|
28
|
+
// PREPARE VALIDATOR
|
|
29
|
+
const validator = validate_index_sort("BbsArticleProvider.idex()")(
|
|
30
|
+
(input: IBbsArticle.IRequest) =>
|
|
31
|
+
api.functional.bbs.articles.index(connection, section, input),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// DO VALIDATE
|
|
35
|
+
const components = [
|
|
36
|
+
validator("created_at")(GaffComparator.dates((x) => x.created_at)),
|
|
37
|
+
validator("updated_at")(GaffComparator.dates((x) => x.updated_at)),
|
|
38
|
+
validator("title")(GaffComparator.strings((x) => x.title)),
|
|
39
|
+
validator("writer")(GaffComparator.strings((x) => x.writer)),
|
|
40
|
+
validator(
|
|
41
|
+
"writer",
|
|
42
|
+
"title",
|
|
43
|
+
)(GaffComparator.strings((x) => [x.writer, x.title])),
|
|
44
|
+
];
|
|
45
|
+
for (const comp of components) {
|
|
46
|
+
await comp("+");
|
|
47
|
+
await comp("-");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import TSON from "typescript-json";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import api from "@ORGANIZATION/PROJECT-api/lib/index";
|
|
5
|
+
import { IBbsArticle } from "@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle";
|
|
6
|
+
|
|
7
|
+
import { RandomGenerator } from "../../../internal/RandomGenerator";
|
|
8
|
+
|
|
9
|
+
export async function test_api_bbs_article_store(
|
|
10
|
+
connection: api.IConnection,
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
// STORE A NEW ARTICLE
|
|
13
|
+
const stored: IBbsArticle = await api.functional.bbs.articles.store(
|
|
14
|
+
connection,
|
|
15
|
+
"general",
|
|
16
|
+
{
|
|
17
|
+
writer: RandomGenerator.name(),
|
|
18
|
+
title: RandomGenerator.paragraph(),
|
|
19
|
+
body: RandomGenerator.content(),
|
|
20
|
+
format: "txt",
|
|
21
|
+
files: [
|
|
22
|
+
{
|
|
23
|
+
name: "logo",
|
|
24
|
+
extension: "png",
|
|
25
|
+
url: "https://somewhere.com/logo.png",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
password: v4(),
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
TSON.assertEquals(stored);
|
|
32
|
+
|
|
33
|
+
// READ THE DATA AGAIN
|
|
34
|
+
const read: IBbsArticle = await api.functional.bbs.articles.at(
|
|
35
|
+
connection,
|
|
36
|
+
stored.section,
|
|
37
|
+
stored.id,
|
|
38
|
+
);
|
|
39
|
+
TSON.assertEquals(read);
|
|
40
|
+
|
|
41
|
+
// CHECK EXISTENCE
|
|
42
|
+
if (read.id !== stored.id)
|
|
43
|
+
throw new Error("Bug on BbsArticleProvider.store(): failed to store.");
|
|
44
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import TSON from "typescript-json";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import api from "@ORGANIZATION/PROJECT-api/lib/index";
|
|
5
|
+
import { IBbsArticle } from "@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle";
|
|
6
|
+
|
|
7
|
+
import { RandomGenerator } from "../../../internal/RandomGenerator";
|
|
8
|
+
import { exception_must_be_thrown } from "../../../internal/exception_must_be_thrown";
|
|
9
|
+
|
|
10
|
+
export async function test_api_bbs_article_update(
|
|
11
|
+
connection: api.IConnection,
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
// STORE A NEW ARTICLE
|
|
14
|
+
const password: string = v4();
|
|
15
|
+
const article: IBbsArticle = await api.functional.bbs.articles.store(
|
|
16
|
+
connection,
|
|
17
|
+
"general",
|
|
18
|
+
{
|
|
19
|
+
writer: RandomGenerator.name(),
|
|
20
|
+
title: RandomGenerator.paragraph(),
|
|
21
|
+
body: RandomGenerator.content(),
|
|
22
|
+
format: "txt",
|
|
23
|
+
files: [
|
|
24
|
+
{
|
|
25
|
+
name: "logo",
|
|
26
|
+
extension: "png",
|
|
27
|
+
url: "https://somewhere.com/logo.png",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
password,
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
TSON.assertEquals(article);
|
|
34
|
+
|
|
35
|
+
// UPDATE WITH EXACT PASSWORD
|
|
36
|
+
const content: IBbsArticle.IContent =
|
|
37
|
+
await api.functional.bbs.articles.update(
|
|
38
|
+
connection,
|
|
39
|
+
article.section,
|
|
40
|
+
article.id,
|
|
41
|
+
{
|
|
42
|
+
title: RandomGenerator.paragraph(),
|
|
43
|
+
body: RandomGenerator.content(),
|
|
44
|
+
format: "txt",
|
|
45
|
+
files: [],
|
|
46
|
+
password,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
article.contents.push(TSON.assertEquals(content));
|
|
50
|
+
|
|
51
|
+
// TRY UPDATE WITH WRONG PASSWORD
|
|
52
|
+
await exception_must_be_thrown("update with wrong password", () =>
|
|
53
|
+
api.functional.bbs.articles.update(
|
|
54
|
+
connection,
|
|
55
|
+
article.section,
|
|
56
|
+
article.id,
|
|
57
|
+
{
|
|
58
|
+
title: RandomGenerator.paragraph(),
|
|
59
|
+
body: RandomGenerator.content(),
|
|
60
|
+
format: "txt",
|
|
61
|
+
files: [],
|
|
62
|
+
password: v4(),
|
|
63
|
+
},
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { sleep_for } from "tstl/thread/global";
|
|
2
|
+
|
|
3
|
+
import api from "@ORGANIZATION/PROJECT-api";
|
|
4
|
+
|
|
5
|
+
import { Backend } from "../Backend";
|
|
6
|
+
import { Configuration } from "../Configuration";
|
|
7
|
+
import { DynamicImportIterator } from "./internal/DynamicImportIterator";
|
|
8
|
+
|
|
9
|
+
async function main(): Promise<void> {
|
|
10
|
+
// BACKEND SERVER
|
|
11
|
+
const backend: Backend = new Backend();
|
|
12
|
+
await backend.open();
|
|
13
|
+
|
|
14
|
+
//----
|
|
15
|
+
// CLINET CONNECTOR
|
|
16
|
+
//----
|
|
17
|
+
// DO TEST
|
|
18
|
+
const connection: api.IConnection = {
|
|
19
|
+
host: `http://127.0.0.1:${await Configuration.API_PORT()}`,
|
|
20
|
+
encryption: await Configuration.ENCRYPTION_PASSWORD(),
|
|
21
|
+
};
|
|
22
|
+
const exceptions: Error[] = await DynamicImportIterator.force(
|
|
23
|
+
__dirname + "/features",
|
|
24
|
+
{
|
|
25
|
+
prefix: "test",
|
|
26
|
+
parameters: () => [connection],
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// WAIT FOR A WHILE FOR THE EVENTS
|
|
31
|
+
await sleep_for(2500);
|
|
32
|
+
|
|
33
|
+
// TERMINATE
|
|
34
|
+
await backend.close();
|
|
35
|
+
|
|
36
|
+
if (exceptions.length === 0) console.log("Success");
|
|
37
|
+
else {
|
|
38
|
+
for (const exp of exceptions) console.log(exp);
|
|
39
|
+
process.exit(-1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
main().catch((exp) => {
|
|
43
|
+
console.log(exp);
|
|
44
|
+
process.exit(-1);
|
|
45
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import cli from "cli";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
import { IPointer } from "./IPointer";
|
|
6
|
+
import { StopWatch } from "./StopWatch";
|
|
7
|
+
|
|
8
|
+
const EXTENSION = __filename.substr(-2);
|
|
9
|
+
if (EXTENSION === "js") require("source-map-support/register");
|
|
10
|
+
|
|
11
|
+
interface ICommand {
|
|
12
|
+
include?: string;
|
|
13
|
+
exclude?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export namespace DynamicImportIterator {
|
|
17
|
+
export type Closure<Arguments extends any[], Ret = any> = (
|
|
18
|
+
...args: Arguments
|
|
19
|
+
) => Promise<Ret>;
|
|
20
|
+
type Module<Arguments extends any[]> = {
|
|
21
|
+
[key: string]: Closure<Arguments>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface IOptions<Parameters extends any[], Ret = any> {
|
|
25
|
+
prefix: string;
|
|
26
|
+
parameters: (name: string) => Parameters;
|
|
27
|
+
wrapper?: (
|
|
28
|
+
name: string,
|
|
29
|
+
closure: Closure<Parameters, Ret>,
|
|
30
|
+
) => Promise<any>;
|
|
31
|
+
counter?: IPointer<number>;
|
|
32
|
+
showElapsedTime?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function main<Arguments extends any[]>(
|
|
36
|
+
path: string,
|
|
37
|
+
options: IOptions<Arguments>,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const command: ICommand = cli.parse();
|
|
40
|
+
await iterate(options, command, path);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function force<Arguments extends any[]>(
|
|
44
|
+
path: string,
|
|
45
|
+
options: IOptions<Arguments>,
|
|
46
|
+
): Promise<Error[]> {
|
|
47
|
+
const command: ICommand = cli.parse();
|
|
48
|
+
const exceptions: Error[] = [];
|
|
49
|
+
|
|
50
|
+
await iterate(options, command, path, exceptions);
|
|
51
|
+
return exceptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function iterate<Arguments extends any[]>(
|
|
55
|
+
options: IOptions<Arguments>,
|
|
56
|
+
command: ICommand,
|
|
57
|
+
path: string,
|
|
58
|
+
exceptions?: Error[],
|
|
59
|
+
): Promise<void> {
|
|
60
|
+
const directory: string[] = await fs.promises.readdir(path);
|
|
61
|
+
for (const file of directory) {
|
|
62
|
+
const current: string = `${path}/${file}`;
|
|
63
|
+
const stats: fs.Stats = await fs.promises.lstat(current);
|
|
64
|
+
|
|
65
|
+
if (stats.isDirectory() === true) {
|
|
66
|
+
await iterate(options, command, current, exceptions);
|
|
67
|
+
continue;
|
|
68
|
+
} else if (file.substr(-3) !== `.${EXTENSION}`) continue;
|
|
69
|
+
|
|
70
|
+
const external: Module<Arguments> = await import(current);
|
|
71
|
+
await execute(options, command, external, exceptions);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function execute<Arguments extends any[]>(
|
|
76
|
+
options: IOptions<Arguments>,
|
|
77
|
+
command: ICommand,
|
|
78
|
+
external: Module<Arguments>,
|
|
79
|
+
exceptions?: Error[],
|
|
80
|
+
): Promise<void> {
|
|
81
|
+
for (const key in external) {
|
|
82
|
+
if (command.exclude && key.indexOf(command.exclude) !== -1)
|
|
83
|
+
continue;
|
|
84
|
+
else if (command.include && key.indexOf(command.include) === -1)
|
|
85
|
+
continue;
|
|
86
|
+
else if (key.substr(0, options.prefix.length) !== options.prefix)
|
|
87
|
+
continue;
|
|
88
|
+
else if (!(external[key] instanceof Function)) continue;
|
|
89
|
+
|
|
90
|
+
const closure: Closure<Arguments> = external[key];
|
|
91
|
+
const func = async () => {
|
|
92
|
+
if (options.wrapper !== undefined)
|
|
93
|
+
await options.wrapper(key, closure);
|
|
94
|
+
else await closure(...options.parameters(key));
|
|
95
|
+
};
|
|
96
|
+
const label: string = chalk.greenBright(key);
|
|
97
|
+
try {
|
|
98
|
+
if (options.counter) ++options.counter.value;
|
|
99
|
+
if (options.showElapsedTime === false) {
|
|
100
|
+
await func();
|
|
101
|
+
console.log(` - ${label}`);
|
|
102
|
+
} else {
|
|
103
|
+
const time: number = await StopWatch.measure(func);
|
|
104
|
+
console.log(
|
|
105
|
+
` - ${label}: ${chalk.yellowBright(
|
|
106
|
+
time.toLocaleString(),
|
|
107
|
+
)} ms`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
} catch (exp) {
|
|
111
|
+
if (!(exp instanceof Error)) return;
|
|
112
|
+
|
|
113
|
+
console.log(` - ${label} -> ${chalk.redBright(exp.name)}`);
|
|
114
|
+
if (exceptions !== undefined) exceptions.push(exp);
|
|
115
|
+
else throw exp;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
export namespace GaffComparator {
|
|
4
|
+
export const strings =
|
|
5
|
+
<T>(closure: (input: T) => string | string[]) =>
|
|
6
|
+
(x: T, y: T) => {
|
|
7
|
+
const alpha: string[] = wrap(closure(x));
|
|
8
|
+
const beta: string[] = wrap(closure(y));
|
|
9
|
+
|
|
10
|
+
for (let i: number = 0; i < alpha.length; ++i)
|
|
11
|
+
if (alpha[i] !== beta[i]) return compare(alpha[i], beta[i]);
|
|
12
|
+
return 0;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const dates =
|
|
16
|
+
<T>(closure: (input: T) => string | string[]) =>
|
|
17
|
+
(x: T, y: T) => {
|
|
18
|
+
const alpha: number[] = wrap(closure(x)).map((str) =>
|
|
19
|
+
new Date(str).getTime(),
|
|
20
|
+
);
|
|
21
|
+
const beta: number[] = wrap(closure(y)).map((str) =>
|
|
22
|
+
new Date(str).getTime(),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
for (let i: number = 0; i < alpha.length; ++i)
|
|
26
|
+
if (alpha[i] !== beta[i]) return alpha[i] - beta[i];
|
|
27
|
+
return 0;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const numbers =
|
|
31
|
+
<T>(closure: (input: T) => number | number[]) =>
|
|
32
|
+
(x: T, y: T) => {
|
|
33
|
+
const alpha: number[] = wrap(closure(x));
|
|
34
|
+
const beta: number[] = wrap(closure(y));
|
|
35
|
+
|
|
36
|
+
for (let i: number = 0; i < alpha.length; ++i)
|
|
37
|
+
if (alpha[i] !== beta[i]) return alpha[i] - beta[i];
|
|
38
|
+
return 0;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function compare(x: string, y: string) {
|
|
42
|
+
return x.localeCompare(y);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function wrap<T>(elem: T | T[]): T[] {
|
|
46
|
+
return Array.isArray(elem) ? elem : [elem];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { randint } from "tstl/algorithm/random";
|
|
2
|
+
import { sample as _Sample } from "tstl/ranges/algorithm/random";
|
|
3
|
+
|
|
4
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
5
|
+
|
|
6
|
+
export namespace RandomGenerator {
|
|
7
|
+
/* ----------------------------------------------------------------
|
|
8
|
+
IDENTIFICATIONS
|
|
9
|
+
---------------------------------------------------------------- */
|
|
10
|
+
const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
11
|
+
|
|
12
|
+
export function alphabets(length: number): string {
|
|
13
|
+
return new Array(length)
|
|
14
|
+
.fill("")
|
|
15
|
+
.map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
|
|
16
|
+
.join("");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function name(length: number = 3): string {
|
|
20
|
+
return paragraph(length);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function paragraph(
|
|
24
|
+
sentences: number = randint(2, 5),
|
|
25
|
+
wordMin: number = 3,
|
|
26
|
+
wordMax: number = 7,
|
|
27
|
+
): string {
|
|
28
|
+
return ArrayUtil.repeat(sentences, () =>
|
|
29
|
+
alphabets(randint(wordMin, wordMax)),
|
|
30
|
+
).join(" ");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function content(
|
|
34
|
+
paragraphes: number = randint(3, 8),
|
|
35
|
+
sentenceMin: number = 10,
|
|
36
|
+
sentenceMax: number = 40,
|
|
37
|
+
wordMin: number = 1,
|
|
38
|
+
wordMax: number = 7,
|
|
39
|
+
): string {
|
|
40
|
+
return ArrayUtil.repeat(paragraphes, () =>
|
|
41
|
+
paragraph(randint(sentenceMin, sentenceMax), wordMin, wordMax),
|
|
42
|
+
).join("\n\n");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function partial(content: string): string {
|
|
46
|
+
const first: number = randint(0, content.length - 1);
|
|
47
|
+
const last: number = randint(first + 1, content.length);
|
|
48
|
+
|
|
49
|
+
return content.substring(first, last).trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function mobile(): string {
|
|
53
|
+
return `010${digit(3, 4)}${digit(4, 4)}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function digit(minC: number, maxC: number): string {
|
|
57
|
+
const val: number = randint(0, Math.pow(10.0, maxC) - 1);
|
|
58
|
+
const log10: number = val ? Math.floor(Math.log10(val)) + 1 : 0;
|
|
59
|
+
const prefix: string = "0".repeat(Math.max(0, minC - log10));
|
|
60
|
+
|
|
61
|
+
return prefix + val.toString();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function date(from: Date, range: number): Date {
|
|
65
|
+
const time: number = from.getTime() + randint(0, range);
|
|
66
|
+
return new Date(time);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function pick<T>(array: T[]): T {
|
|
70
|
+
return array[randint(0, array.length - 1)];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export namespace StopWatch {
|
|
2
|
+
export type Task = () => Promise<void>;
|
|
3
|
+
|
|
4
|
+
export async function measure(task: Task): Promise<number> {
|
|
5
|
+
const time: number = Date.now();
|
|
6
|
+
await task();
|
|
7
|
+
return Date.now() - time;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function trace(title: string, task: Task): Promise<void> {
|
|
11
|
+
process.stdout.write(` - ${title}: `);
|
|
12
|
+
const time: number = await measure(task);
|
|
13
|
+
|
|
14
|
+
console.log(`${time.toLocaleString()} ms`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { equal } from "tstl/ranges/algorithm/iterations";
|
|
2
|
+
|
|
3
|
+
interface IEntity {
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function get_ids<Entity extends IEntity>(entities: Entity[]): string[] {
|
|
8
|
+
return entities.map((entity) => entity.id).sort((x, y) => (x < y ? -1 : 1));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function validate_index<
|
|
12
|
+
Solution extends IEntity,
|
|
13
|
+
Summary extends IEntity,
|
|
14
|
+
>(symbol: string, solution: Solution[], summaries: Summary[]): void {
|
|
15
|
+
const length: number = Math.min(solution.length, summaries.length);
|
|
16
|
+
const xIds: string[] = get_ids(solution).slice(0, length);
|
|
17
|
+
const yIds: string[] = get_ids(summaries)
|
|
18
|
+
.filter((id) => id >= xIds[0])
|
|
19
|
+
.slice(0, length);
|
|
20
|
+
|
|
21
|
+
if (equal(xIds, yIds) === true) return;
|
|
22
|
+
|
|
23
|
+
console.log(xIds);
|
|
24
|
+
console.log(yIds);
|
|
25
|
+
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Bug on ${symbol}: result of the index is different with manual aggregation.`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { is_sorted } from "tstl/ranges/algorithm/sorting";
|
|
2
|
+
|
|
3
|
+
import { IPage } from "@ORGANIZATION/PROJECT-api/lib/structures/common/IPage";
|
|
4
|
+
|
|
5
|
+
export const validate_index_sort =
|
|
6
|
+
(method: string) =>
|
|
7
|
+
<T extends object, Fields extends string>(
|
|
8
|
+
getter: (
|
|
9
|
+
input: IPage.IRequest & {
|
|
10
|
+
sort?: IPage.IRequest.Sort<Fields>;
|
|
11
|
+
},
|
|
12
|
+
) => Promise<IPage<T>>,
|
|
13
|
+
) =>
|
|
14
|
+
(...fields: Fields[]) =>
|
|
15
|
+
(comp: (x: T, y: T) => number, filter?: (elem: T) => boolean) =>
|
|
16
|
+
async (direction: "+" | "-") => {
|
|
17
|
+
const page: IPage<T> = await getter({
|
|
18
|
+
limit: 100,
|
|
19
|
+
sort: fields.map((field) => `${direction}${field}` as const),
|
|
20
|
+
});
|
|
21
|
+
if (filter) page.data = page.data.filter(filter);
|
|
22
|
+
|
|
23
|
+
const reversed: typeof comp =
|
|
24
|
+
direction === "+" ? comp : (x, y) => comp(y, x);
|
|
25
|
+
if (is_sorted(page.data, (x, y) => reversed(x, y) < 0) === false) {
|
|
26
|
+
console.log(direction, ...fields);
|
|
27
|
+
if (
|
|
28
|
+
fields.length === 1 &&
|
|
29
|
+
page.data.length &&
|
|
30
|
+
(page.data as any)[0][fields[0]] !== undefined
|
|
31
|
+
)
|
|
32
|
+
console.log(page.data.map((elem) => (elem as any)[fields[0]]));
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Bug on ${method}: wrong sorting on ${direction}(${fields.join(
|
|
35
|
+
", ",
|
|
36
|
+
)}).`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
};
|