@gent-js/gent 0.1.8 → 0.1.10

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.
@@ -1,6 +1,6 @@
1
1
  export declare const packageEnv: {
2
2
  readonly fullName: "@gent-js/gent";
3
3
  readonly name: "gent";
4
- readonly version: "0.1.8";
4
+ readonly version: "0.1.10";
5
5
  readonly description: "template-based data generator.";
6
6
  };
@@ -2,6 +2,6 @@
2
2
  export const packageEnv = {
3
3
  fullName: "@gent-js/gent",
4
4
  name: "gent",
5
- version: "0.1.8",
5
+ version: "0.1.10",
6
6
  description: "template-based data generator."
7
7
  };
package/dist/src/cli.js CHANGED
@@ -14,7 +14,7 @@ const outOption = new Option("-o --out <path>", "path to output files.").default
14
14
  const debugOption = new Option("-d --debug", "debug flat")
15
15
  .default(false)
16
16
  .hideHelp(true);
17
- async function main() {
17
+ function main() {
18
18
  const program = new Command();
19
19
  program
20
20
  .name(packageEnv.name)
@@ -41,7 +41,9 @@ async function main() {
41
41
  if (meta !== undefined) {
42
42
  const resolvedFilePath = parseAndResolveFilePath(meta, cwd);
43
43
  if (resolvedFilePath === undefined) {
44
- program.error(`failed to resolve meta file path.(${meta})`);
44
+ program.error(`failed to resolve meta file path.(${meta})`, {
45
+ exitCode: FAILED,
46
+ });
45
47
  return;
46
48
  }
47
49
  let fileContent;
@@ -52,7 +54,7 @@ async function main() {
52
54
  console.log(error);
53
55
  }
54
56
  if (fileContent === undefined) {
55
- program.error("failed to read meta file.");
57
+ program.error("failed to read meta file.", { exitCode: FAILED });
56
58
  return;
57
59
  }
58
60
  try {
@@ -63,7 +65,7 @@ async function main() {
63
65
  rawProgramOptions = undefined;
64
66
  }
65
67
  if (rawProgramOptions === undefined) {
66
- program.error("failed to parse meta file.");
68
+ program.error("failed to parse meta file.", { exitCode: FAILED });
67
69
  return;
68
70
  }
69
71
  }
@@ -97,6 +99,8 @@ async function main() {
97
99
  program.error("Command has failed", { exitCode: resultCode });
98
100
  }
99
101
  });
100
- await program.parseAsync(process.argv);
102
+ program.parseAsync(process.argv).catch((error) => {
103
+ console.error(error);
104
+ });
101
105
  }
102
- await main();
106
+ main();
@@ -1,8 +1,8 @@
1
1
  import type { NonTransparentFramingMethod, TcpFramingMethod } from "./types.js";
2
2
  export declare const DEFAULT_TEMPLATE_WEIGHT = 1;
3
3
  export declare const TemplateModes: readonly ["text", "json"];
4
- export declare const NetworkOutputTypes: readonly ["udp", "tcp"];
5
- export declare const OutputTypes: readonly ["file", "udp", "tcp"];
4
+ export declare const NetworkOutputTypes: readonly ["udp", "tcp", "tls"];
5
+ export declare const OutputTypes: readonly ["file", "udp", "tcp", "tls"];
6
6
  export declare const DefaultEps = 3000;
7
7
  export declare const MaxEps: number;
8
8
  export declare const OctetCounting: "octet-counting";
@@ -1,6 +1,6 @@
1
1
  export const DEFAULT_TEMPLATE_WEIGHT = 1;
2
2
  export const TemplateModes = ["text", "json"];
3
- export const NetworkOutputTypes = ["udp", "tcp"];
3
+ export const NetworkOutputTypes = ["udp", "tcp", "tls"];
4
4
  export const OutputTypes = ["file", ...NetworkOutputTypes];
5
5
  export const DefaultEps = 3000;
6
6
  export const MaxEps = Number.MAX_SAFE_INTEGER;
@@ -1,2 +1,3 @@
1
1
  import * as stream from "node:stream";
2
- export declare function createFileOutput(nonRotateOutputPath: string, rotateSize: string | undefined, rotateOutputPathGenerator: (additionalPhrase: string) => string): Promise<stream.Writable>;
2
+ import type { RotateOutputPathGenerator } from "./types.js";
3
+ export declare function createFileOutput(nonRotateOutputPath: string, rotateSize: string | undefined, rotateOutputPathGenerator: RotateOutputPathGenerator): Promise<stream.Writable>;
@@ -0,0 +1,3 @@
1
+ import * as stream from "node:stream";
2
+ import type { TlsOutputOptions } from "../types.js";
3
+ export declare function createTlsOutput(outputOptions: TlsOutputOptions): Promise<stream.Writable>;
@@ -0,0 +1,13 @@
1
+ import * as tls from "node:tls";
2
+ export async function createTlsOutput(outputOptions) {
3
+ const tlsOptions = {
4
+ host: outputOptions.address,
5
+ port: outputOptions.port,
6
+ rejectUnauthorized: false,
7
+ // key: fs.readFileSync(path.join(__dirname, 'client-key.pem')),
8
+ // cert: fs.readFileSync(path.join(__dirname, 'client-cert.pem')),
9
+ // ca: [fs.readFileSync(path.join(__dirname, 'ca-cert.pem'))]
10
+ };
11
+ const client = tls.connect(tlsOptions);
12
+ return client;
13
+ }
@@ -4,21 +4,29 @@ import * as nodePath from "node:path";
4
4
  import { assertNever } from "../utils.js";
5
5
  import { createFileOutput } from "./createFileOutput.js";
6
6
  import { createTcpOutput } from "./createTcpOutput.js";
7
+ import { createTlsOutput } from "./createTlsOutput.js";
7
8
  import { UdpDocumentStream } from "./udpDocumentStream.js";
8
9
  export async function initializeOutput(outputOptions) {
9
10
  // region clean dir
10
- const nonRotateOutputPath = outputOptions.path;
11
- const parsed = nodePath.parse(outputOptions.path);
12
- const rotateOutputPathGenerator = (additionalPhrase) => {
13
- const filename = `${parsed.name}.${additionalPhrase}${parsed.ext}`;
14
- return nodePath.join(parsed.dir, filename);
15
- };
16
- const nonRotateOutputGlobPath = nonRotateOutputPath.replaceAll("\\", "/");
17
- const rotateOutputGlobPath = rotateOutputPathGenerator("*").replaceAll("\\", "/");
18
- await cleanOutputDir(nonRotateOutputGlobPath, rotateOutputGlobPath);
11
+ const outputPath = outputOptions.path;
12
+ let rotateOutputPathGenerator;
13
+ if (outputPath !== undefined) {
14
+ // when output path is specified, clean dir.
15
+ const parsed = nodePath.parse(outputPath);
16
+ rotateOutputPathGenerator = (additionalPhrase) => {
17
+ const filename = `${parsed.name}.${additionalPhrase}${parsed.ext}`;
18
+ return nodePath.join(parsed.dir, filename);
19
+ };
20
+ const nonRotateOutputGlobPath = outputPath.replaceAll("\\", "/");
21
+ const rotateOutputGlobPath = rotateOutputPathGenerator("*").replaceAll("\\", "/");
22
+ await cleanOutputDir(nonRotateOutputGlobPath, rotateOutputGlobPath);
23
+ }
19
24
  // endregion
20
25
  if (outputOptions.type === "file") {
21
- return createFileOutput(nonRotateOutputPath, outputOptions.size, rotateOutputPathGenerator);
26
+ if (rotateOutputPathGenerator === undefined) {
27
+ throw new Error("rotateOutputPathGenerator should be initialized at this point.");
28
+ }
29
+ return createFileOutput(outputOptions.path, outputOptions.size, rotateOutputPathGenerator);
22
30
  }
23
31
  else if (outputOptions.type === "udp") {
24
32
  return new UdpDocumentStream(outputOptions);
@@ -26,6 +34,9 @@ export async function initializeOutput(outputOptions) {
26
34
  else if (outputOptions.type === "tcp") {
27
35
  return createTcpOutput(outputOptions);
28
36
  }
37
+ else if (outputOptions.type === "tls") {
38
+ return createTlsOutput(outputOptions);
39
+ }
29
40
  else {
30
41
  return assertNever(outputOptions);
31
42
  }
@@ -0,0 +1,3 @@
1
+ export interface RotateOutputPathGenerator {
2
+ (additionalPhrase: string): string;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/src/run.js CHANGED
@@ -8,45 +8,48 @@ import { MaxEps, TrailerMap } from "./consts.js";
8
8
  import { createDocumentFeeder } from "./createDocumentFeeder.js";
9
9
  import { createGeneratingDocumentStream } from "./createGeneratingDocumentStream.js";
10
10
  import { debugFileWriter } from "./debugFileWriter.js";
11
- import { initializeOutput } from "./output/initializeOutput.js";
12
11
  import { DocumentTransformStream } from "./documentTransformStream.js";
12
+ import { initializeOutput } from "./output/initializeOutput.js";
13
13
  import "./command/commands/index.js";
14
14
  export async function run(programOptions) {
15
15
  const { debug, count, out, templates } = programOptions;
16
16
  // region out path
17
17
  const outPath = out.path;
18
- const outDirPath = nodePath.dirname(outPath);
19
- let existsOutDir = false;
20
- try {
21
- const stats = await fsPromises.stat(outDirPath);
22
- if (stats.isDirectory()) {
23
- existsOutDir = true;
18
+ if (outPath !== undefined) {
19
+ // check permissions on out path when specified.
20
+ const outDirPath = nodePath.dirname(outPath);
21
+ let existsOutDir = false;
22
+ try {
23
+ const stats = await fsPromises.stat(outDirPath);
24
+ if (stats.isDirectory()) {
25
+ existsOutDir = true;
26
+ }
27
+ await fsPromises.access(outDirPath, fs.constants.W_OK);
28
+ }
29
+ catch (error) {
30
+ existsOutDir = false;
31
+ }
32
+ if (!existsOutDir) {
33
+ try {
34
+ await fsPromises.mkdir(outDirPath, { recursive: true });
35
+ }
36
+ catch (error) {
37
+ console.error(`failed to create out path directory. ${outDirPath}`);
38
+ console.log(error);
39
+ return FAILED;
40
+ }
24
41
  }
25
- await fsPromises.access(outDirPath, fs.constants.W_OK);
26
- }
27
- catch (error) {
28
- existsOutDir = false;
29
- }
30
- if (!existsOutDir) {
31
42
  try {
32
- await fsPromises.mkdir(outDirPath, { recursive: true });
43
+ await fsPromises.access(outDirPath, fs.constants.W_OK);
33
44
  }
34
45
  catch (error) {
35
- console.error(`failed to create out path directory. ${outDirPath}`);
46
+ console.error(`cannot access out directory. ${outDirPath}`);
36
47
  console.log(error);
37
48
  return FAILED;
38
49
  }
39
- }
40
- try {
41
- await fsPromises.access(outDirPath, fs.constants.W_OK);
42
- }
43
- catch (error) {
44
- console.error(`cannot access out directory. ${outDirPath}`);
45
- console.log(error);
46
- return FAILED;
47
- }
48
- if (debug) {
49
- debugFileWriter.setBaseDirectory(outDirPath);
50
+ if (debug) {
51
+ debugFileWriter.setBaseDirectory(outDirPath);
52
+ }
50
53
  }
51
54
  // endregion
52
55
  const documentFeeder = await createDocumentFeeder(templates, programOptions, commandManager);
@@ -67,7 +70,7 @@ export async function run(programOptions) {
67
70
  eps: out.eps,
68
71
  };
69
72
  }
70
- else if (out.type === "tcp") {
73
+ else if (out.type === "tcp" || out.type === "tls") {
71
74
  if (out.framing === "octet-counting") {
72
75
  documentTransformOptions = {
73
76
  transformMode: "buffer",
@@ -29,16 +29,17 @@ export interface TemplateOptions {
29
29
  readonly weight: number;
30
30
  }
31
31
  export type ShorthandOutputOptions = string;
32
- export type OutputOptions = FileOutputOptions | UdpOutputOptions | TcpOutputOptions;
32
+ export type OutputOptions = FileOutputOptions | UdpOutputOptions | TcpOutputOptions | TlsOutputOptions;
33
33
  export type OutputType = (typeof OutputTypes)[number];
34
34
  export type NetworkOutputType = (typeof NetworkOutputTypes)[number];
35
35
  interface PrimitiveOutputOptions {
36
36
  readonly type: OutputType;
37
- readonly path: string;
37
+ readonly path?: string | undefined;
38
38
  }
39
39
  export interface FileOutputOptions extends PrimitiveOutputOptions {
40
40
  readonly type: "file";
41
- readonly size?: string;
41
+ readonly path: string;
42
+ readonly size?: string | undefined;
42
43
  }
43
44
  interface NetworkOutputOptions extends PrimitiveOutputOptions {
44
45
  readonly type: NetworkOutputType;
@@ -56,13 +57,23 @@ interface PrimitiveTcpOutputOptions extends NetworkOutputOptions {
56
57
  readonly framing: TcpFramingMethod;
57
58
  }
58
59
  interface TcpOctetCountingOutputOptions extends PrimitiveTcpOutputOptions {
59
- readonly type: "tcp";
60
60
  readonly framing: "octet-counting";
61
61
  }
62
62
  interface TcpNonFramingOutputOptions extends PrimitiveTcpOutputOptions {
63
- readonly type: "tcp";
64
63
  readonly framing: NonTransparentFramingMethod;
65
64
  readonly trailerReplacer: string;
66
65
  }
67
66
  export type TcpOutputOptions = TcpOctetCountingOutputOptions | TcpNonFramingOutputOptions;
67
+ interface PrimitiveTlsOutputOptions extends NetworkOutputOptions {
68
+ readonly type: "tls";
69
+ readonly framing: TcpFramingMethod;
70
+ }
71
+ interface TlsOctetCountingOutputOptions extends PrimitiveTlsOutputOptions {
72
+ readonly framing: "octet-counting";
73
+ }
74
+ interface TlsNonFramingOutputOptions extends PrimitiveTlsOutputOptions {
75
+ readonly framing: NonTransparentFramingMethod;
76
+ readonly trailerReplacer: string;
77
+ }
78
+ export type TlsOutputOptions = TlsOctetCountingOutputOptions | TlsNonFramingOutputOptions;
68
79
  export {};
package/dist/src/utils.js CHANGED
@@ -207,25 +207,17 @@ function normalizeOutputOptions(possibleOutputOptions, basePath) {
207
207
  return undefined;
208
208
  }
209
209
  const possiblePath = parseAndResolveFilePath(possibleOutputOptions["path"], basePath);
210
- if (possiblePath === undefined) {
211
- console.error(`output path must be specified.(${possiblePath})`);
212
- return undefined;
213
- }
214
210
  if (possibleType == "file") {
215
- const possibleSize = parseString(possibleOutputOptions["size"]);
216
- if (possibleSize === undefined) {
217
- return {
218
- type: possibleType,
219
- path: possiblePath,
220
- };
221
- }
222
- else {
223
- return {
224
- type: possibleType,
225
- path: possiblePath,
226
- size: possibleSize,
227
- };
211
+ if (possiblePath === undefined) {
212
+ console.error(`output path must be specified.(${possiblePath})`);
213
+ return undefined;
228
214
  }
215
+ const possibleSize = parseString(possibleOutputOptions["size"]);
216
+ return {
217
+ type: possibleType,
218
+ path: possiblePath,
219
+ size: possibleSize,
220
+ };
229
221
  }
230
222
  else if (isNetworkOutputType(possibleType)) {
231
223
  const possibleAddress = parseString(possibleOutputOptions["address"]);
@@ -244,7 +236,7 @@ function normalizeOutputOptions(possibleOutputOptions, basePath) {
244
236
  eps: possibleEps,
245
237
  };
246
238
  }
247
- else if (possibleType === "tcp") {
239
+ else if (possibleType === "tcp" || possibleType === "tls") {
248
240
  const possibleFraming = parseString(possibleOutputOptions["framing"]) ??
249
241
  DefaultTcpFramingMethod;
250
242
  if (!isTcpFramingType(possibleFraming)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gent-js/gent",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "template-based data generator.",
5
5
  "keywords": [
6
6
  "gent"