tarsec 0.1.6 → 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.
package/dist/trace.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ParserResult, Parser, PlainObject, CaptureParser } from "./types.js";
2
2
  export declare function setTraceHost(host: string): void;
3
3
  export declare function getTraceHost(): string;
4
+ export declare function setTraceId(id: string): void;
4
5
  /**
5
6
  * This function is used internally by the `trace` function to create the string for each step.
6
7
  * @param name - debug name for parser
package/dist/trace.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { escape, round, shorten } from "./utils.js";
2
2
  import process from "process";
3
+ import { execSync } from "child_process";
3
4
  const isNode = typeof process !== "undefined" &&
4
5
  process.versions != null &&
5
6
  process.versions.node != null;
@@ -12,12 +13,16 @@ let stepCount = 0;
12
13
  let stepLimit = -1;
13
14
  let debugMessages = [];
14
15
  let traceHost = "";
16
+ let traceId = "1";
15
17
  export function setTraceHost(host) {
16
18
  traceHost = host;
17
19
  }
18
20
  export function getTraceHost() {
19
21
  return traceHost;
20
22
  }
23
+ export function setTraceId(id) {
24
+ traceId = id;
25
+ }
21
26
  /**
22
27
  * This function is used internally by the `trace` function to create the string for each step.
23
28
  * @param name - debug name for parser
@@ -38,20 +43,14 @@ export function trace(name, parser) {
38
43
  if (debugFlag) {
39
44
  console.log(" ".repeat(level) + `🔍 ${name} -- input: ${shorten(escape(input))}`);
40
45
  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);
46
+ const json = JSON.stringify({
47
+ traceId,
48
+ name,
49
+ type: "start",
50
+ level,
51
+ timestamp: Date.now(),
54
52
  });
53
+ execSync(`curl -s -X POST -H "Content-Type: application/json" -d '${json}' ${traceHost}/api/logs`);
55
54
  }
56
55
  let result;
57
56
  const time = parserTime(() => {
@@ -70,21 +69,15 @@ export function trace(name, parser) {
70
69
  `⭐ ${name} -- captures: ${JSON.stringify(result.captures)}`);
71
70
  }
72
71
  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);
72
+ const json = JSON.stringify({
73
+ traceId,
74
+ name,
75
+ type: "end",
76
+ level,
77
+ timestamp: Date.now(),
78
+ result,
87
79
  });
80
+ execSync(`curl -s -X POST -H "Content-Type: application/json" -d '${json}' ${traceHost}/api/logs`);
88
81
  }
89
82
  return result;
90
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tarsec",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A parser combinator library for TypeScript, inspired by Parsec.",
5
5
  "homepage": "https://github.com/egonSchiele/tarsec",
6
6
  "scripts": {