@cogitator-ai/wasm-tools 0.5.11 → 0.6.0

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 (119) hide show
  1. package/README.md +84 -25
  2. package/dist/index.d.ts +22 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +81 -14
  5. package/dist/index.js.map +1 -1
  6. package/dist/manager/types.d.ts +2 -0
  7. package/dist/manager/types.d.ts.map +1 -1
  8. package/dist/manager/wasm-loader.d.ts.map +1 -1
  9. package/dist/manager/wasm-loader.js +11 -2
  10. package/dist/manager/wasm-loader.js.map +1 -1
  11. package/dist/manager/wasm-tool-manager.d.ts +1 -0
  12. package/dist/manager/wasm-tool-manager.d.ts.map +1 -1
  13. package/dist/manager/wasm-tool-manager.js +56 -13
  14. package/dist/manager/wasm-tool-manager.js.map +1 -1
  15. package/dist/runtime.d.ts +11 -0
  16. package/dist/runtime.d.ts.map +1 -0
  17. package/dist/runtime.js +104 -0
  18. package/dist/runtime.js.map +1 -0
  19. package/dist/wasm/base64.wasm +0 -0
  20. package/dist/wasm/calc.wasm +0 -0
  21. package/dist/wasm/compression.wasm +0 -0
  22. package/dist/wasm/csv.wasm +0 -0
  23. package/dist/wasm/datetime.wasm +0 -0
  24. package/dist/wasm/diff.wasm +0 -0
  25. package/dist/wasm/hash.wasm +0 -0
  26. package/dist/wasm/json.wasm +0 -0
  27. package/dist/wasm/markdown.wasm +0 -0
  28. package/dist/wasm/regex.wasm +0 -0
  29. package/dist/wasm/signing.wasm +0 -0
  30. package/dist/wasm/slug.wasm +0 -0
  31. package/dist/wasm/validation.wasm +0 -0
  32. package/dist/wasm/xml.wasm +0 -0
  33. package/package.json +5 -6
  34. package/dist/__tests__/file-watcher.test.d.ts +0 -2
  35. package/dist/__tests__/file-watcher.test.d.ts.map +0 -1
  36. package/dist/__tests__/file-watcher.test.js +0 -99
  37. package/dist/__tests__/file-watcher.test.js.map +0 -1
  38. package/dist/__tests__/index.test.d.ts +0 -2
  39. package/dist/__tests__/index.test.d.ts.map +0 -1
  40. package/dist/__tests__/index.test.js +0 -226
  41. package/dist/__tests__/index.test.js.map +0 -1
  42. package/dist/__tests__/wasm-loader.test.d.ts +0 -2
  43. package/dist/__tests__/wasm-loader.test.d.ts.map +0 -1
  44. package/dist/__tests__/wasm-loader.test.js +0 -68
  45. package/dist/__tests__/wasm-loader.test.js.map +0 -1
  46. package/dist/__tests__/wasm-tool-manager.test.d.ts +0 -2
  47. package/dist/__tests__/wasm-tool-manager.test.d.ts.map +0 -1
  48. package/dist/__tests__/wasm-tool-manager.test.js +0 -166
  49. package/dist/__tests__/wasm-tool-manager.test.js.map +0 -1
  50. package/dist/plugins/base64.d.ts +0 -12
  51. package/dist/plugins/base64.d.ts.map +0 -1
  52. package/dist/plugins/base64.js +0 -144
  53. package/dist/plugins/base64.js.map +0 -1
  54. package/dist/plugins/calc.d.ts +0 -12
  55. package/dist/plugins/calc.d.ts.map +0 -1
  56. package/dist/plugins/calc.js +0 -102
  57. package/dist/plugins/calc.js.map +0 -1
  58. package/dist/plugins/compression.d.ts +0 -2
  59. package/dist/plugins/compression.d.ts.map +0 -1
  60. package/dist/plugins/compression.js +0 -549
  61. package/dist/plugins/compression.js.map +0 -1
  62. package/dist/plugins/csv.d.ts +0 -2
  63. package/dist/plugins/csv.d.ts.map +0 -1
  64. package/dist/plugins/csv.js +0 -142
  65. package/dist/plugins/csv.js.map +0 -1
  66. package/dist/plugins/datetime.d.ts +0 -2
  67. package/dist/plugins/datetime.d.ts.map +0 -1
  68. package/dist/plugins/datetime.js +0 -199
  69. package/dist/plugins/datetime.js.map +0 -1
  70. package/dist/plugins/diff.d.ts +0 -2
  71. package/dist/plugins/diff.d.ts.map +0 -1
  72. package/dist/plugins/diff.js +0 -187
  73. package/dist/plugins/diff.js.map +0 -1
  74. package/dist/plugins/hash.d.ts +0 -12
  75. package/dist/plugins/hash.d.ts.map +0 -1
  76. package/dist/plugins/hash.js +0 -310
  77. package/dist/plugins/hash.js.map +0 -1
  78. package/dist/plugins/json.d.ts +0 -12
  79. package/dist/plugins/json.d.ts.map +0 -1
  80. package/dist/plugins/json.js +0 -70
  81. package/dist/plugins/json.js.map +0 -1
  82. package/dist/plugins/markdown.d.ts +0 -2
  83. package/dist/plugins/markdown.d.ts.map +0 -1
  84. package/dist/plugins/markdown.js +0 -213
  85. package/dist/plugins/markdown.js.map +0 -1
  86. package/dist/plugins/regex.d.ts +0 -2
  87. package/dist/plugins/regex.d.ts.map +0 -1
  88. package/dist/plugins/regex.js +0 -120
  89. package/dist/plugins/regex.js.map +0 -1
  90. package/dist/plugins/signing.d.ts +0 -2
  91. package/dist/plugins/signing.d.ts.map +0 -1
  92. package/dist/plugins/signing.js +0 -589
  93. package/dist/plugins/signing.js.map +0 -1
  94. package/dist/plugins/slug.d.ts +0 -2
  95. package/dist/plugins/slug.d.ts.map +0 -1
  96. package/dist/plugins/slug.js +0 -183
  97. package/dist/plugins/slug.js.map +0 -1
  98. package/dist/plugins/validation.d.ts +0 -2
  99. package/dist/plugins/validation.d.ts.map +0 -1
  100. package/dist/plugins/validation.js +0 -105
  101. package/dist/plugins/validation.js.map +0 -1
  102. package/dist/plugins/xml.d.ts +0 -2
  103. package/dist/plugins/xml.d.ts.map +0 -1
  104. package/dist/plugins/xml.js +0 -297
  105. package/dist/plugins/xml.js.map +0 -1
  106. package/dist/temp/base64.js +0 -149
  107. package/dist/temp/calc.js +0 -108
  108. package/dist/temp/compression.js +0 -742
  109. package/dist/temp/csv.js +0 -161
  110. package/dist/temp/datetime.js +0 -217
  111. package/dist/temp/diff.js +0 -198
  112. package/dist/temp/hash.js +0 -424
  113. package/dist/temp/json.js +0 -80
  114. package/dist/temp/markdown.js +0 -224
  115. package/dist/temp/regex.js +0 -141
  116. package/dist/temp/signing.js +0 -600
  117. package/dist/temp/slug.js +0 -201
  118. package/dist/temp/validation.js +0 -125
  119. package/dist/temp/xml.js +0 -295
@@ -1,224 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/plugins/markdown.ts
21
- var markdown_exports = {};
22
- __export(markdown_exports, {
23
- markdown: () => markdown
24
- });
25
- module.exports = __toCommonJS(markdown_exports);
26
- function escapeHtml(text) {
27
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
28
- }
29
- function parseInline(text, sanitize) {
30
- let result = sanitize ? escapeHtml(text) : text;
31
- result = result.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1">');
32
- result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
33
- result = result.replace(/`([^`]+)`/g, "<code>$1</code>");
34
- result = result.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
35
- result = result.replace(/__([^_]+)__/g, "<strong>$1</strong>");
36
- result = result.replace(/\*([^*]+)\*/g, "<em>$1</em>");
37
- result = result.replace(/_([^_]+)_/g, "<em>$1</em>");
38
- result = result.replace(/~~([^~]+)~~/g, "<del>$1</del>");
39
- return result;
40
- }
41
- function parseMarkdown(md, sanitize, gfm) {
42
- const lines = md.split("\n");
43
- const html = [];
44
- let inCodeBlock = false;
45
- let codeBlockContent = [];
46
- let codeBlockLang = "";
47
- let inList = false;
48
- let listType = "ul";
49
- let inBlockquote = false;
50
- let blockquoteContent = [];
51
- let inParagraph = false;
52
- let paragraphContent = [];
53
- const flushParagraph = () => {
54
- if (inParagraph && paragraphContent.length > 0) {
55
- html.push(`<p>${parseInline(paragraphContent.join(" "), sanitize)}</p>`);
56
- paragraphContent = [];
57
- inParagraph = false;
58
- }
59
- };
60
- const flushBlockquote = () => {
61
- if (inBlockquote && blockquoteContent.length > 0) {
62
- html.push(
63
- `<blockquote><p>${parseInline(blockquoteContent.join(" "), sanitize)}</p></blockquote>`
64
- );
65
- blockquoteContent = [];
66
- inBlockquote = false;
67
- }
68
- };
69
- const flushList = () => {
70
- if (inList) {
71
- html.push(listType === "ul" ? "</ul>" : "</ol>");
72
- inList = false;
73
- }
74
- };
75
- for (let i = 0; i < lines.length; i++) {
76
- const line = lines[i];
77
- if (line.startsWith("```")) {
78
- if (inCodeBlock) {
79
- const content = sanitize ? escapeHtml(codeBlockContent.join("\n")) : codeBlockContent.join("\n");
80
- html.push(
81
- `<pre><code${codeBlockLang ? ` class="language-${codeBlockLang}"` : ""}>${content}</code></pre>`
82
- );
83
- codeBlockContent = [];
84
- codeBlockLang = "";
85
- inCodeBlock = false;
86
- } else {
87
- flushParagraph();
88
- flushBlockquote();
89
- flushList();
90
- codeBlockLang = line.slice(3).trim();
91
- inCodeBlock = true;
92
- }
93
- continue;
94
- }
95
- if (inCodeBlock) {
96
- codeBlockContent.push(line);
97
- continue;
98
- }
99
- if (line.trim() === "") {
100
- flushParagraph();
101
- flushBlockquote();
102
- flushList();
103
- continue;
104
- }
105
- const headerMatch = /^(#{1,6})\s+(.+)$/.exec(line);
106
- if (headerMatch) {
107
- flushParagraph();
108
- flushBlockquote();
109
- flushList();
110
- const level = headerMatch[1].length;
111
- const content = parseInline(headerMatch[2], sanitize);
112
- html.push(`<h${level}>${content}</h${level}>`);
113
- continue;
114
- }
115
- if (/^(-{3,}|\*{3,}|_{3,})$/.test(line.trim())) {
116
- flushParagraph();
117
- flushBlockquote();
118
- flushList();
119
- html.push("<hr>");
120
- continue;
121
- }
122
- const blockquoteMatch = /^>\s?(.*)$/.exec(line);
123
- if (blockquoteMatch) {
124
- flushParagraph();
125
- flushList();
126
- inBlockquote = true;
127
- blockquoteContent.push(blockquoteMatch[1]);
128
- continue;
129
- }
130
- const ulMatch = /^[-*+]\s+(.+)$/.exec(line);
131
- if (ulMatch) {
132
- flushParagraph();
133
- flushBlockquote();
134
- if (!inList || listType !== "ul") {
135
- flushList();
136
- html.push("<ul>");
137
- inList = true;
138
- listType = "ul";
139
- }
140
- html.push(`<li>${parseInline(ulMatch[1], sanitize)}</li>`);
141
- continue;
142
- }
143
- const olMatch = /^\d+\.\s+(.+)$/.exec(line);
144
- if (olMatch) {
145
- flushParagraph();
146
- flushBlockquote();
147
- if (!inList || listType !== "ol") {
148
- flushList();
149
- html.push("<ol>");
150
- inList = true;
151
- listType = "ol";
152
- }
153
- html.push(`<li>${parseInline(olMatch[1], sanitize)}</li>`);
154
- continue;
155
- }
156
- if (gfm && line.includes("|")) {
157
- flushParagraph();
158
- flushBlockquote();
159
- flushList();
160
- const tableLines = [line];
161
- while (i + 1 < lines.length && lines[i + 1].includes("|")) {
162
- i++;
163
- tableLines.push(lines[i]);
164
- }
165
- if (tableLines.length >= 2) {
166
- const headerCells = tableLines[0].split("|").map((c) => c.trim()).filter((c) => c);
167
- const rows = tableLines.slice(2);
168
- html.push("<table>");
169
- html.push("<thead><tr>");
170
- for (const cell of headerCells) {
171
- html.push(`<th>${parseInline(cell, sanitize)}</th>`);
172
- }
173
- html.push("</tr></thead>");
174
- if (rows.length > 0) {
175
- html.push("<tbody>");
176
- for (const row of rows) {
177
- const cells = row.split("|").map((c) => c.trim()).filter((c) => c);
178
- html.push("<tr>");
179
- for (const cell of cells) {
180
- html.push(`<td>${parseInline(cell, sanitize)}</td>`);
181
- }
182
- html.push("</tr>");
183
- }
184
- html.push("</tbody>");
185
- }
186
- html.push("</table>");
187
- }
188
- continue;
189
- }
190
- flushBlockquote();
191
- flushList();
192
- inParagraph = true;
193
- paragraphContent.push(line.trim());
194
- }
195
- flushParagraph();
196
- flushBlockquote();
197
- flushList();
198
- if (inCodeBlock) {
199
- const content = sanitize ? escapeHtml(codeBlockContent.join("\n")) : codeBlockContent.join("\n");
200
- html.push(`<pre><code>${content}</code></pre>`);
201
- }
202
- return html.join("\n");
203
- }
204
- function markdown() {
205
- try {
206
- const inputStr = Host.inputString();
207
- const input = JSON.parse(inputStr);
208
- const sanitize = input.options?.sanitize ?? true;
209
- const gfm = input.options?.gfm ?? true;
210
- const htmlResult = parseMarkdown(input.markdown, sanitize, gfm);
211
- const output = {
212
- html: htmlResult
213
- };
214
- Host.outputString(JSON.stringify(output));
215
- return 0;
216
- } catch (error) {
217
- const output = {
218
- html: "",
219
- error: error instanceof Error ? error.message : String(error)
220
- };
221
- Host.outputString(JSON.stringify(output));
222
- return 1;
223
- }
224
- }
@@ -1,141 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/plugins/regex.ts
21
- var regex_exports = {};
22
- __export(regex_exports, {
23
- regex: () => regex
24
- });
25
- module.exports = __toCommonJS(regex_exports);
26
- var MAX_ITERATIONS = 1e5;
27
- var DANGEROUS_PATTERNS = [
28
- /\(\?[^)]*\)\+\+/,
29
- /\(\.\*\)\+/,
30
- /\(\.\+\)\+/,
31
- /\([^)]+\+\)\+/,
32
- /\([^)]+\*\)\*/
33
- ];
34
- function isDangerousPattern(pattern) {
35
- for (const dangerous of DANGEROUS_PATTERNS) {
36
- if (dangerous.test(pattern)) {
37
- return true;
38
- }
39
- }
40
- let depth = 0;
41
- let quantifiers = 0;
42
- for (const char of pattern) {
43
- if (char === "(") depth++;
44
- if (char === ")") depth--;
45
- if ((char === "+" || char === "*") && depth > 0) quantifiers++;
46
- }
47
- return quantifiers > 3;
48
- }
49
- function safeMatch(text, regex2) {
50
- const match = regex2.exec(text);
51
- if (!match) return null;
52
- return {
53
- match: match[0],
54
- index: match.index,
55
- groups: match.groups
56
- };
57
- }
58
- function safeMatchAll(text, regex2, limit) {
59
- const results = [];
60
- let iterations = 0;
61
- const globalRegex = new RegExp(
62
- regex2.source,
63
- regex2.flags.includes("g") ? regex2.flags : regex2.flags + "g"
64
- );
65
- let match;
66
- while ((match = globalRegex.exec(text)) !== null) {
67
- results.push({
68
- match: match[0],
69
- index: match.index,
70
- groups: match.groups
71
- });
72
- iterations++;
73
- if (iterations >= limit || iterations >= MAX_ITERATIONS) break;
74
- if (match[0].length === 0) {
75
- globalRegex.lastIndex++;
76
- }
77
- }
78
- return results;
79
- }
80
- function safeReplace(text, regex2, replacement) {
81
- return text.replace(regex2, replacement);
82
- }
83
- function safeSplit(text, regex2, limit) {
84
- return text.split(regex2, limit);
85
- }
86
- function safeTest(text, regex2) {
87
- return regex2.test(text);
88
- }
89
- function regex() {
90
- try {
91
- const inputStr = Host.inputString();
92
- const input = JSON.parse(inputStr);
93
- if (isDangerousPattern(input.pattern)) {
94
- throw new Error("Pattern may cause ReDoS - nested quantifiers detected");
95
- }
96
- const flags = input.flags ?? "";
97
- const regex2 = new RegExp(input.pattern, flags);
98
- const limit = input.limit ?? 1e3;
99
- let result;
100
- let matchCount;
101
- switch (input.operation) {
102
- case "test":
103
- result = safeTest(input.text, regex2);
104
- break;
105
- case "match":
106
- result = safeMatch(input.text, regex2);
107
- matchCount = result ? 1 : 0;
108
- break;
109
- case "matchAll": {
110
- const matches = safeMatchAll(input.text, regex2, limit);
111
- result = matches;
112
- matchCount = matches.length;
113
- break;
114
- }
115
- case "replace":
116
- if (input.replacement === void 0) {
117
- throw new Error("replacement is required for replace operation");
118
- }
119
- result = safeReplace(input.text, regex2, input.replacement);
120
- break;
121
- case "split":
122
- result = safeSplit(input.text, regex2, input.limit);
123
- break;
124
- default:
125
- throw new Error(`Unknown operation: ${input.operation}`);
126
- }
127
- const output = {
128
- result,
129
- matchCount
130
- };
131
- Host.outputString(JSON.stringify(output));
132
- return 0;
133
- } catch (error) {
134
- const output = {
135
- result: null,
136
- error: error instanceof Error ? error.message : String(error)
137
- };
138
- Host.outputString(JSON.stringify(output));
139
- return 1;
140
- }
141
- }