tarsec 0.1.5 → 0.1.6

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/dist/trace.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { ParserResult, Parser, PlainObject, CaptureParser } from "./types.js";
2
+ export declare function setTraceHost(host: string): void;
3
+ export declare function getTraceHost(): string;
2
4
  /**
3
5
  * This function is used internally by the `trace` function to create the string for each step.
4
6
  * @param name - debug name for parser
package/dist/trace.js CHANGED
@@ -11,6 +11,13 @@ let debugFlag = isNode ? !!process.env.DEBUG : false;
11
11
  let stepCount = 0;
12
12
  let stepLimit = -1;
13
13
  let debugMessages = [];
14
+ let traceHost = "";
15
+ export function setTraceHost(host) {
16
+ traceHost = host;
17
+ }
18
+ export function getTraceHost() {
19
+ return traceHost;
20
+ }
14
21
  /**
15
22
  * This function is used internally by the `trace` function to create the string for each step.
16
23
  * @param name - debug name for parser
@@ -30,6 +37,22 @@ export function trace(name, parser) {
30
37
  return (input) => {
31
38
  if (debugFlag) {
32
39
  console.log(" ".repeat(level) + `🔍 ${name} -- input: ${shorten(escape(input))}`);
40
+ if (traceHost && traceHost.length > 0) {
41
+ fetch(`${traceHost}/api/logs`, {
42
+ method: "POST",
43
+ headers: {
44
+ "Content-Type": "application/json",
45
+ },
46
+ body: JSON.stringify({
47
+ name,
48
+ type: "start",
49
+ level,
50
+ timestamp: Date.now(),
51
+ }),
52
+ }).catch((err) => {
53
+ console.error("Failed to send logs to server:", err);
54
+ });
55
+ }
33
56
  let result;
34
57
  const time = parserTime(() => {
35
58
  level += STEP;
@@ -46,6 +69,23 @@ export function trace(name, parser) {
46
69
  console.log(" ".repeat(level) +
47
70
  `⭐ ${name} -- captures: ${JSON.stringify(result.captures)}`);
48
71
  }
72
+ if (traceHost && traceHost.length > 0) {
73
+ fetch(`${traceHost}/api/logs`, {
74
+ method: "POST",
75
+ headers: {
76
+ "Content-Type": "application/json",
77
+ },
78
+ body: JSON.stringify({
79
+ name,
80
+ type: "end",
81
+ level,
82
+ timestamp: Date.now(),
83
+ result,
84
+ }),
85
+ }).catch((err) => {
86
+ console.error("Failed to send logs to server:", err);
87
+ });
88
+ }
49
89
  return result;
50
90
  }
51
91
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tarsec",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A parser combinator library for TypeScript, inspired by Parsec.",
5
5
  "homepage": "https://github.com/egonSchiele/tarsec",
6
6
  "scripts": {