@gent-js/gent 0.1.9 → 0.1.12

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 CHANGED
@@ -153,3 +153,7 @@ in meta file, specify output path with `out` key.
153
153
  ```
154
154
 
155
155
  moreover, you can use various output method and options in meta file. see [output](./docs/output.md) for details.
156
+
157
+ ## Development
158
+
159
+ [development](./docs/developing.md)
@@ -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.9";
4
+ readonly version: "0.1.12";
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.9",
5
+ version: "0.1.12",
6
6
  description: "template-based data generator."
7
7
  };
@@ -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.9",
3
+ "version": "0.1.12",
4
4
  "description": "template-based data generator.",
5
5
  "keywords": [
6
6
  "gent"
@@ -32,27 +32,28 @@
32
32
  "build:tsc": "tsc -p tsconfig.build.json",
33
33
  "generate:dts": "tsx scripts/generateParserCstDts.ts",
34
34
  "generate:package-env": "tsx scripts/generatePackageEnv.ts",
35
+ "lint": "echo \"Info: no lint specified\" && exit 0",
35
36
  "lint:tsc": "npm run build:tsc -- --noEmit",
36
37
  "prepare": "npm run build:publish",
37
38
  "start": "tsx src/cli.ts --template sample/syslog_RFC3164(ISO_Date).template.log --count 5 --out out/out.log --debug",
38
39
  "start-json": "tsx src/cli.ts --template sample/aws_CloudWatch.json --count 5 --out out/out.log --debug",
39
40
  "start-meta": "tsx src/cli.ts --meta sample/meta.json",
40
- "test": "echo \"Error: no test specified\" && exit 1",
41
+ "test": "echo \"Info: no test specified\" && exit 0",
41
42
  "version": "npm run generate:package-env"
42
43
  },
43
44
  "dependencies": {
44
- "@faker-js/faker": "~9",
45
+ "@faker-js/faker": "~10",
45
46
  "@types/luxon": "~3",
46
47
  "chevrotain": "~11",
47
- "commander": "~12",
48
- "glob": "~11",
48
+ "commander": "~14",
49
+ "glob": "~13",
49
50
  "luxon": "~3",
50
51
  "rotating-file-stream": "~3"
51
52
  },
52
53
  "devDependencies": {
53
- "@types/node": "~22",
54
+ "@types/node": "~25",
54
55
  "prettier": "~3",
55
56
  "tsx": "~4",
56
- "typescript": "~5.6"
57
+ "typescript": "~5.9"
57
58
  }
58
59
  }