@gent-js/gent 0.1.5 → 0.1.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.
Files changed (45) hide show
  1. package/README.md +18 -4
  2. package/dist/generated/packageEnv.d.ts +1 -1
  3. package/dist/generated/packageEnv.js +1 -1
  4. package/dist/src/command/commands/index.js +5 -0
  5. package/dist/src/command/commands/index.js.map +1 -1
  6. package/dist/src/command/commands/japan/hyakuninIsshu.d.ts +2 -0
  7. package/dist/src/command/commands/japan/hyakuninIsshu.js +1150 -0
  8. package/dist/src/command/commands/japan/hyakuninIsshu.js.map +1 -0
  9. package/dist/src/command/commands/japan/shogun.d.ts +2 -0
  10. package/dist/src/command/commands/japan/shogun.js +71 -0
  11. package/dist/src/command/commands/japan/shogun.js.map +1 -0
  12. package/dist/src/common/utils.d.ts +5 -0
  13. package/dist/src/common/utils.js +8 -0
  14. package/dist/src/common/utils.js.map +1 -0
  15. package/dist/src/json/abstractJsonable.d.ts +1 -2
  16. package/dist/src/json/abstractJsonable.js.map +1 -1
  17. package/dist/src/json/createJsonable.js +10 -1
  18. package/dist/src/json/createJsonable.js.map +1 -1
  19. package/dist/src/json/createJsonableTransformer.js +50 -12
  20. package/dist/src/json/createJsonableTransformer.js.map +1 -1
  21. package/dist/src/json/jsonTypes.d.ts +8 -1
  22. package/dist/src/json/jsonableClasses/arrayJsonable.d.ts +4 -4
  23. package/dist/src/json/jsonableClasses/arrayJsonable.js.map +1 -1
  24. package/dist/src/json/jsonableClasses/jsonStringJsonable.d.ts +10 -0
  25. package/dist/src/json/jsonableClasses/jsonStringJsonable.js +15 -0
  26. package/dist/src/json/jsonableClasses/jsonStringJsonable.js.map +1 -0
  27. package/dist/src/json/jsonableParametersTypes.d.ts +10 -3
  28. package/dist/src/json/jsonableTypes.d.ts +6 -3
  29. package/dist/src/json/stringifyJsonable.js +11 -2
  30. package/dist/src/json/stringifyJsonable.js.map +1 -1
  31. package/dist/src/json/utils.d.ts +1 -1
  32. package/dist/src/json/utils.js.map +1 -1
  33. package/package.json +2 -2
  34. package/dist/src/output/tcpDocumentStream.d.ts +0 -16
  35. package/dist/src/output/tcpDocumentStream.js +0 -107
  36. package/dist/src/output/tcpDocumentStream.js.map +0 -1
  37. package/dist/src/output/throttlingDocumentStream.d.ts +0 -21
  38. package/dist/src/output/throttlingDocumentStream.js +0 -69
  39. package/dist/src/output/throttlingDocumentStream.js.map +0 -1
  40. package/dist/src/template/documentTransformStream.d.ts +0 -19
  41. package/dist/src/template/documentTransformStream.js +0 -118
  42. package/dist/src/template/documentTransformStream.js.map +0 -1
  43. package/dist/src/template/documentTransformTypes.d.ts +0 -25
  44. package/dist/src/template/documentTransformTypes.js +0 -2
  45. package/dist/src/template/documentTransformTypes.js.map +0 -1
@@ -1,107 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- import * as dnsPromises from "node:dns/promises";
3
- import * as net from "node:net";
4
- import { TrailerMap } from "../consts.js";
5
- import { ThrottlingDocumentStream } from "./throttlingDocumentStream.js";
6
- const SP = " ";
7
- export class TcpDocumentStream extends ThrottlingDocumentStream {
8
- address;
9
- port;
10
- framing;
11
- trailerReplacer;
12
- family;
13
- client;
14
- constructor(options) {
15
- super(options.eps);
16
- this.address = options.address;
17
- this.port = options.port;
18
- if (options.framing === "octet-counting") {
19
- this.framing = options.framing;
20
- }
21
- else {
22
- this.framing = options.framing;
23
- this.trailerReplacer = options.trailerReplacer;
24
- }
25
- }
26
- _construct(callback) {
27
- dnsPromises
28
- .lookup(this.address, {
29
- verbatim: true,
30
- })
31
- .then((lookupAddress) => {
32
- this.family = lookupAddress.family;
33
- callback();
34
- })
35
- .catch((reason) => callback(reason));
36
- }
37
- _throttledWrite(chunk, encoding, callback) {
38
- const family = this.family;
39
- if (family === undefined) {
40
- callback(new Error("called write before family has not been determined."));
41
- return;
42
- }
43
- let client = this.client;
44
- if (client === undefined) {
45
- const tcpOptions = {
46
- host: this.address,
47
- port: this.port,
48
- family: this.family,
49
- };
50
- client = net.connect(tcpOptions);
51
- this.client = client;
52
- }
53
- const outputString = chunk.stamp();
54
- let output;
55
- if (this.framing === "lf") {
56
- const trailerReplacer = this.trailerReplacer;
57
- if (trailerReplacer !== undefined) {
58
- const trailer = TrailerMap[this.framing];
59
- output = outputString.replaceAll(trailer, trailerReplacer) + trailer;
60
- }
61
- else {
62
- const trailer = TrailerMap[this.framing];
63
- output = outputString + trailer;
64
- }
65
- }
66
- else if (this.framing === "octet-counting") {
67
- const messageBuf8 = Buffer.from(outputString, "utf-8");
68
- const lengthCount = messageBuf8.length.toString();
69
- const lengthBuf8 = Buffer.from(lengthCount + SP, "utf-8");
70
- output = Buffer.concat([lengthBuf8, messageBuf8]);
71
- }
72
- else {
73
- callback(new Error(`unexpected framing type ${this.framing}`));
74
- return;
75
- }
76
- client.write(output, (error) => {
77
- if (error !== null) {
78
- callback(error);
79
- return;
80
- }
81
- callback();
82
- });
83
- }
84
- _throttledFinal(callback) {
85
- const client = this.client;
86
- if (client === undefined) {
87
- callback();
88
- return;
89
- }
90
- client.end(callback);
91
- }
92
- _throttledDestroy(error, callback) {
93
- const client = this.client;
94
- if (client === undefined) {
95
- callback(error);
96
- return;
97
- }
98
- if (error !== null) {
99
- client.destroy(error);
100
- }
101
- else {
102
- client.destroy();
103
- }
104
- callback(error);
105
- }
106
- }
107
- //# sourceMappingURL=tcpDocumentStream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tcpDocumentStream.js","sourceRoot":"","sources":["../../../src/output/tcpDocumentStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,EAAE,GAAG,GAAY,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aAAM,CAAC;YACN,QAAQ,CAAC,IAAI,KAAK,CAAC,2BAA2B,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC/D,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAC7B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAChB,OAAO;YACT,CAAC;YACD,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAES,eAAe,CAAC,QAAwC;QAChE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,QAAQ,EAAE,CAAC;YACX,OAAO;QACT,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;IAES,iBAAiB,CACzB,KAAmB,EACnB,QAAwC;QAExC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QACD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;CACF"}
@@ -1,21 +0,0 @@
1
- import * as stream from "node:stream";
2
- import { GeneratingDocument } from "../document/index.js";
3
- export declare abstract class ThrottlingDocumentStream extends stream.Writable {
4
- private readonly window;
5
- private readonly eventPerWindow;
6
- private readonly windowInternalTimeout;
7
- private eventInCurrentWindow;
8
- private pendingWriteTasks;
9
- private nThWindow;
10
- private totalNumOfEvent;
11
- protected constructor(eps: number, debug?: boolean);
12
- private debugReport;
13
- _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
14
- protected abstract _throttledWrite(chunk: GeneratingDocument, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
15
- private _flushPendingWriteTasks;
16
- private _clearWindowInternal;
17
- _final(callback: (error?: Error | null) => void): void;
18
- protected abstract _throttledFinal(callback: (error?: Error | null) => void): void;
19
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
20
- protected abstract _throttledDestroy(error: Error | null, callback: (error?: Error | null) => void): void;
21
- }
@@ -1,69 +0,0 @@
1
- import * as stream from "node:stream";
2
- import { GeneratingDocument } from "../document/index.js";
3
- const Per1000Window = 1000;
4
- const Per100Window = 100;
5
- export class ThrottlingDocumentStream extends stream.Writable {
6
- window;
7
- eventPerWindow;
8
- windowInternalTimeout;
9
- eventInCurrentWindow;
10
- pendingWriteTasks = [];
11
- nThWindow = 0;
12
- totalNumOfEvent = 0;
13
- constructor(eps, debug = false) {
14
- super({
15
- objectMode: true,
16
- });
17
- if (eps < Per100Window) {
18
- this.window = Per1000Window;
19
- }
20
- else {
21
- this.window = Per100Window;
22
- }
23
- this.eventPerWindow = Math.ceil(eps * (this.window / 1000));
24
- this.eventInCurrentWindow = 0;
25
- this.windowInternalTimeout = setInterval(() => {
26
- this._flushPendingWriteTasks();
27
- if (debug) {
28
- this.debugReport();
29
- }
30
- this.eventInCurrentWindow = 0;
31
- }, this.window);
32
- }
33
- debugReport() {
34
- this.totalNumOfEvent = this.totalNumOfEvent + this.eventInCurrentWindow;
35
- this.nThWindow = this.nThWindow + 1;
36
- console.log(`[${this.nThWindow}] => ${this.eventInCurrentWindow}/${this.totalNumOfEvent}`);
37
- }
38
- _write(chunk, encoding, callback) {
39
- if (!(chunk instanceof GeneratingDocument)) {
40
- callback(new Error(`Unexpected chunk type(${typeof chunk}). Cannot process any chunk type except Document.`));
41
- return;
42
- }
43
- if (this.eventInCurrentWindow < this.eventPerWindow) {
44
- this._throttledWrite(chunk, encoding, callback);
45
- this.eventInCurrentWindow = this.eventInCurrentWindow + 1;
46
- return;
47
- }
48
- this.pendingWriteTasks.push([chunk, encoding, callback]);
49
- }
50
- _flushPendingWriteTasks() {
51
- const tasks = this.pendingWriteTasks;
52
- this.pendingWriteTasks = [];
53
- tasks.forEach(([chunk, encoding, callback]) => this._throttledWrite(chunk, encoding, callback));
54
- }
55
- _clearWindowInternal() {
56
- clearInterval(this.windowInternalTimeout);
57
- }
58
- _final(callback) {
59
- this._flushPendingWriteTasks();
60
- this._clearWindowInternal();
61
- this._throttledFinal(callback);
62
- }
63
- _destroy(error, callback) {
64
- this._flushPendingWriteTasks();
65
- this._clearWindowInternal();
66
- this._throttledDestroy(error, callback);
67
- }
68
- }
69
- //# sourceMappingURL=throttlingDocumentStream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"throttlingDocumentStream.js","sourceRoot":"","sources":["../../../src/output/throttlingDocumentStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,YAAY,GAAG,GAAG,CAAC;AASzB,MAAM,OAAgB,wBAAyB,SAAQ,MAAM,CAAC,QAAQ;IACnD,MAAM,CAAS;IACf,cAAc,CAAS;IAEvB,qBAAqB,CAAC;IAE/B,oBAAoB,CAAS;IAC7B,iBAAiB,GAAgB,EAAE,CAAC;IAEpC,SAAS,GAAG,CAAC,CAAC;IACd,eAAe,GAAG,CAAC,CAAC;IAE5B,YAAsB,GAAW,EAAE,QAAiB,KAAK;QACvD,KAAK,CAAC;YACJ,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,IAAI,GAAG,GAAG,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG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AC,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAQO,uBAAuB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC;QACrC,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE,CAC5C,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAChD,CAAC;IACJ,CAAC;IAEO,oBAAoB;QAC1B,aAAa,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAC5C,CAAC;IAEe,MAAM,CAAC,QAAwC;QAC7D,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAMe,QAAQ,CACtB,KAAmB,EACnB,QAAwC;QAExC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;CAMF"}
@@ -1,19 +0,0 @@
1
- import * as stream from "node:stream";
2
- import type { DocumentTransformOptions } from "./documentTransformTypes.js";
3
- export declare class DocumentTransformStream extends stream.Transform {
4
- private readonly documentTransformer;
5
- private readonly timeWindow;
6
- private readonly numOfEventPerTimeWindow;
7
- private readonly timeWindowIntervalTimeout;
8
- private numOfEventInCurrentTimeWindow;
9
- private pendingTransformTasks;
10
- private nThTimeWindow;
11
- private totalNumOfEvent;
12
- constructor(options: DocumentTransformOptions, debug?: boolean);
13
- private debugReport;
14
- _transform(chunk: any, encoding: BufferEncoding, callback: stream.TransformCallback): void;
15
- _flush(callback: stream.TransformCallback): void;
16
- private __transformDocument;
17
- private __flushPendingTransformTasks;
18
- private __clearWindowInternal;
19
- }
@@ -1,118 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- import * as stream from "node:stream";
3
- import { GeneratingDocument } from "../document/index.js";
4
- const Per1000Window = 1000;
5
- const Per100Window = 100;
6
- export class DocumentTransformStream extends stream.Transform {
7
- documentTransformer;
8
- timeWindow;
9
- numOfEventPerTimeWindow;
10
- timeWindowIntervalTimeout;
11
- numOfEventInCurrentTimeWindow;
12
- pendingTransformTasks = [];
13
- nThTimeWindow = 0;
14
- totalNumOfEvent = 0;
15
- constructor(options, debug = false) {
16
- super({
17
- highWaterMark: 0,
18
- objectMode: true,
19
- });
20
- const transformMode = options.transformMode;
21
- if (transformMode === "object") {
22
- this.documentTransformer = undefined;
23
- }
24
- else if (transformMode === "buffer") {
25
- const framing = options.framing;
26
- if (framing === "octet-counting") {
27
- this.documentTransformer = transformDocumentIntoOctetCountingBuffer;
28
- }
29
- else if (framing === "non-transparent") {
30
- this.documentTransformer = createNonTransparentDocumentTransformer(options.trailer, options.trailerReplacer);
31
- }
32
- else {
33
- throw new Error(`Unexpected framingMethod: ${framing}`);
34
- }
35
- }
36
- else {
37
- throw new Error(`Unexpected transferMode: ${transformMode}`);
38
- }
39
- if (options.eps < Per100Window) {
40
- this.timeWindow = Per1000Window;
41
- }
42
- else {
43
- this.timeWindow = Per100Window;
44
- }
45
- this.numOfEventPerTimeWindow = Math.ceil(options.eps * (this.timeWindow / 1000));
46
- this.numOfEventInCurrentTimeWindow = 0;
47
- this.timeWindowIntervalTimeout = setInterval(() => {
48
- this.__flushPendingTransformTasks();
49
- if (debug) {
50
- this.debugReport();
51
- }
52
- this.numOfEventInCurrentTimeWindow = 0;
53
- }, this.timeWindow);
54
- }
55
- debugReport() {
56
- this.totalNumOfEvent =
57
- this.totalNumOfEvent + this.numOfEventInCurrentTimeWindow;
58
- this.nThTimeWindow = this.nThTimeWindow + 1;
59
- console.log(`[${this.nThTimeWindow}] => ${this.numOfEventInCurrentTimeWindow}/${this.totalNumOfEvent}`);
60
- }
61
- _transform(chunk, encoding, callback) {
62
- if (!(chunk instanceof GeneratingDocument)) {
63
- callback(new Error(`Unexpected chunk type(${typeof chunk}). Cannot process any chunk type except Document.`));
64
- return;
65
- }
66
- if (this.numOfEventInCurrentTimeWindow < this.numOfEventPerTimeWindow) {
67
- this.numOfEventInCurrentTimeWindow =
68
- this.numOfEventInCurrentTimeWindow + 1;
69
- this.__transformDocument(chunk, encoding, callback);
70
- return;
71
- }
72
- this.pendingTransformTasks.push([chunk, encoding, callback]);
73
- }
74
- _flush(callback) {
75
- this.__flushPendingTransformTasks();
76
- this.__clearWindowInternal();
77
- callback();
78
- }
79
- __transformDocument(document, encoding, callback) {
80
- const documentTransformer = this.documentTransformer;
81
- if (documentTransformer === undefined) {
82
- callback(null, document);
83
- return;
84
- }
85
- const bufferArray = documentTransformer(document, encoding);
86
- bufferArray.forEach((buffer) => this.push(buffer, encoding));
87
- callback();
88
- }
89
- __flushPendingTransformTasks() {
90
- const tasks = this.pendingTransformTasks;
91
- this.pendingTransformTasks = [];
92
- tasks.forEach(([document, encoding, callback]) => this.__transformDocument(document, encoding, callback));
93
- }
94
- __clearWindowInternal() {
95
- clearInterval(this.timeWindowIntervalTimeout);
96
- }
97
- }
98
- const SP = " ";
99
- function transformDocumentIntoOctetCountingBuffer(document, encoding) {
100
- const outputString = document.stamp();
101
- const messageBuf8 = Buffer.from(outputString, encoding);
102
- const lengthCount = messageBuf8.length.toString();
103
- const lengthBuf8 = Buffer.from(lengthCount + SP, encoding);
104
- return [lengthBuf8, messageBuf8];
105
- }
106
- function createNonTransparentDocumentTransformer(trailer, trailerReplacer) {
107
- return (document, encoding) => {
108
- let outputString = document.stamp();
109
- if (trailerReplacer !== undefined) {
110
- outputString = outputString.replaceAll(trailer, trailerReplacer);
111
- }
112
- return [
113
- Buffer.from(outputString, encoding),
114
- Buffer.from(trailer, encoding),
115
- ];
116
- };
117
- }
118
- //# sourceMappingURL=documentTransformStream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentTransformStream.js","sourceRoot":"","sources":["../../../src/template/documentTransformStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,YAAY,GAAG,GAAG,CAAC;AAYzB,MAAM,OAAO,uBAAwB,SAAQ,MAAM,CAAC,SAAS;IAC1C,mBAAmB,CAAkC;IAErD,UAAU,CAAS;IACnB,uBAAuB,CAAS;IAEhC,yBAAyB,CAAC;IAEnC,6BAA6B,CAAS;IACtC,qBAAqB,GAAoB,EAAE,CAAC;IAE5C,aAAa,GAAG,CAAC,CAAC;IAClB,eAAe,GAAG,CAAC,CAAC;IAE5B,YAAY,OAAiC,EAAE,QAAiB,KAAK;QACnE,KAAK,CAAC;YACJ,aAAa,EAAE,CAAC;YAChB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QACH,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC5C,IAAI,aAAa,KAAK,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;QACvC,CAAC;aAAM,IAAI,aAAa,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAChC,IAAI,OAAO,KAAK,gBAAgB,EAAE,CAAC;gBACjC,IAAI,CAAC,mBAAmB,GAAG,wCAAwC,CAAC;YACtE,CAAC;iBAAM,IAAI,OAAO,KAAK,iBAAiB,EAAE,CAAC;gBACzC,IAAI,CAAC,mBAAmB,GAAG,uCAAuC,CAChE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,eAAe,CACxB,CAAC;YACJ,C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AQ,CAAC,EAAE,EAAE,CAC/C,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CACvD,CAAC;IACJ,CAAC;IAEO,qBAAqB;QAC3B,aAAa,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAChD,CAAC;CACF;AAED,MAAM,EAAE,GAAG,GAAG,CAAC;AAEf,SAAS,wCAAwC,CAC/C,QAA4B,EAC5B,QAAwB;IAExB,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC3D,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,uCAAuC,CAC9C,OAAe,EACf,eAAmC;IAEnC,OAAO,CACL,QAA4B,EAC5B,QAAwB,EACL,EAAE;QACrB,IAAI,YAAY,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QACnE,CAAC;QACD,OAAO;YACL,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;SAC/B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,25 +0,0 @@
1
- export type TransformMode = "object" | "buffer";
2
- interface PrimitiveDocumentTransformOptions {
3
- readonly transformMode: TransformMode;
4
- readonly eps: number;
5
- }
6
- export interface DocumentObjectTransformOptions extends PrimitiveDocumentTransformOptions {
7
- readonly transformMode: "object";
8
- }
9
- export type FramingMethod = "octet-counting" | "non-transparent";
10
- interface DocumentBufferTransformOptions extends PrimitiveDocumentTransformOptions {
11
- readonly transformMode: "buffer";
12
- readonly framing: FramingMethod;
13
- }
14
- export interface DocumentOctetCountingTransformOptions extends DocumentBufferTransformOptions {
15
- readonly transformMode: "buffer";
16
- readonly framing: "octet-counting";
17
- }
18
- export interface DocumentNonTransparentTransformOptions extends DocumentBufferTransformOptions {
19
- readonly transformMode: "buffer";
20
- readonly framing: "non-transparent";
21
- readonly trailer: string;
22
- readonly trailerReplacer: string | undefined;
23
- }
24
- export type DocumentTransformOptions = DocumentObjectTransformOptions | DocumentOctetCountingTransformOptions | DocumentNonTransparentTransformOptions;
25
- export {};
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=documentTransformTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentTransformTypes.js","sourceRoot":"","sources":["../../../src/template/documentTransformTypes.ts"],"names":[],"mappings":""}