spl2dql 0.0.0-stage → 0.1.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 (44) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +18 -0
  3. package/README.md +82 -2
  4. package/bin/spl2dql.js +20 -0
  5. package/dist/inputs.d.ts +21 -0
  6. package/dist/inputs.js +130 -0
  7. package/dist/main.d.ts +41 -0
  8. package/dist/main.js +650 -0
  9. package/dist/mapping.d.ts +18 -0
  10. package/dist/mapping.js +60 -0
  11. package/dist/report.d.ts +95 -0
  12. package/dist/report.js +285 -0
  13. package/dist/safe-fs.d.ts +7 -0
  14. package/dist/safe-fs.js +81 -0
  15. package/dist/serve/server.d.ts +47 -0
  16. package/dist/serve/server.js +195 -0
  17. package/package.json +64 -3
  18. package/web/404.html +27 -0
  19. package/web/THIRD-PARTY-NOTICES.txt +774 -0
  20. package/web/_headers +26 -0
  21. package/web/assets/BatchView-CJw9TDhQ.js +1 -0
  22. package/web/assets/DashboardsView-gW0FEoq7.js +1 -0
  23. package/web/assets/DropZone-CIbk77sc.js +492 -0
  24. package/web/assets/MappingView-Co21Vkp_.js +14 -0
  25. package/web/assets/ReferenceView-S1R-kCt6.js +2 -0
  26. package/web/assets/atkinson-hyperlegible-mono-latin-ext-wght-normal-CXgNM06D.woff2 +0 -0
  27. package/web/assets/atkinson-hyperlegible-mono-latin-wght-normal-CoA7y8X5.woff2 +0 -0
  28. package/web/assets/atkinson-hyperlegible-next-latin-ext-wght-normal-C6vrW8VD.woff2 +0 -0
  29. package/web/assets/atkinson-hyperlegible-next-latin-wght-normal-BcXVPD7q.woff2 +0 -0
  30. package/web/assets/dict-9ToLi8Te.js +1 -0
  31. package/web/assets/index-BO3AM1fZ.js +46 -0
  32. package/web/assets/index-DPywAY6M.css +2 -0
  33. package/web/assets/jsx-runtime-Wy9s6hX0.js +1 -0
  34. package/web/assets/mapping-text-B64_Oh2A.js +106 -0
  35. package/web/assets/translate.worker-C2M3Sf23.js +656 -0
  36. package/web/icon-180.png +0 -0
  37. package/web/icon-192.png +0 -0
  38. package/web/icon-512.png +0 -0
  39. package/web/icon.svg +1 -0
  40. package/web/index.html +63 -0
  41. package/web/manifest.webmanifest +15 -0
  42. package/web/robots.txt +2 -0
  43. package/web/social.png +0 -0
  44. package/web/sw.js +24 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,18 @@
1
+ spl2dql
2
+ Copyright 2026 the spl2dql contributors
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ It includes, under third_party/dynatrace-for-ai/, files from Dynatrace/dynatrace-for-ai
7
+ (https://github.com/Dynatrace/dynatrace-for-ai), Copyright Dynatrace LLC, licensed under the
8
+ Apache License, Version 2.0 (see third_party/dynatrace-for-ai/LICENSE). Those files are used at
9
+ build time to generate packages/core/src/dql/catalog.generated.ts, and as the reference for the
10
+ Dynatrace dashboard format (third_party/dynatrace-for-ai/dashboards/).
11
+
12
+ The web app that ships with the command-line tool and as the hosted page bundles third-party
13
+ libraries and fonts. Their licences are listed in THIRD-PARTY-NOTICES.txt, which is generated when
14
+ the app is built and travels with it.
15
+
16
+ This project is independent. It is not affiliated with, endorsed by or supported by Splunk Inc.,
17
+ Cisco or Dynatrace. Splunk, SPL, Dynatrace and DQL are trademarks of their respective owners and
18
+ are used only to describe what this tool works with.
package/README.md CHANGED
@@ -1,3 +1,83 @@
1
- # Temporary Holding Version
1
+ # spl2dql
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Move a Splunk app to Dynatrace from the terminal: saved searches to DQL, dashboards to Dynatrace
4
+ dashboards. Offline — it never connects to anything.
5
+
6
+ ```sh
7
+ npx spl2dql --help
8
+ echo 'index=web status>=500 | stats count by host | sort -count | head 10' | npx spl2dql translate
9
+ ```
10
+
11
+ ```dql
12
+ fetch logs
13
+ | filter status >= 500
14
+ | filter isNotNull(host.name)
15
+ | summarize count = count(), by:{host.name}
16
+ | sort count desc
17
+ | limit 10
18
+ ```
19
+
20
+ …plus notes on stderr, for example that index `web` has no entry in the mapping file yet. With a
21
+ mapping file (`spl2dql.mapping.yaml`) the same search reads only the right Grail bucket and uses
22
+ your real field names, such as `http.status`.
23
+
24
+ Every SPL stage is marked **Exact**, **Check** or **Not translated**, with a note and a stable code
25
+ (`spl2dql explain SPL3001`) saying what differs and what to do. A command with no DQL equivalent
26
+ becomes a `// not translated:` line; everything around it is still translated. The same search
27
+ always produces the same DQL — there is no AI in the translation path.
28
+
29
+ Requires Node.js 24 or later.
30
+
31
+ ## Commands
32
+
33
+ ```sh
34
+ spl2dql translate [file] # one search (stdin when omitted); -o dql | json | pretty
35
+ spl2dql batch <inputs...> --out dir # a Splunk app folder, searches, dashboards → .dql, dashboard JSON, HTML/JSON report
36
+ spl2dql dashboard <inputs...> # Splunk dashboards (Simple XML, Dashboard Studio) → Dynatrace dashboard files
37
+ spl2dql mapping init <inputs...> # a mapping skeleton, filled in from the app's .conf files
38
+ spl2dql mapping check <file> # validate a mapping file
39
+ spl2dql commands # the support matrix (109 SPL commands)
40
+ spl2dql explain <code> # what a note code means
41
+ spl2dql serve # the web app on 127.0.0.1 — everything runs in your browser
42
+ ```
43
+
44
+ A typical migration:
45
+
46
+ ```sh
47
+ spl2dql mapping init ./my_splunk_app > spl2dql.mapping.yaml # macros and extractions come from the app; add where the data lives
48
+ spl2dql batch ./my_splunk_app --out ./out --fail-on low
49
+ ```
50
+
51
+ `batch` reads what a Splunk app holds: `savedsearches.conf` (each search with its saved time range),
52
+ dashboards, and `macros.conf`, `props.conf`, `transforms.conf`, `eventtypes.conf` and `tags.conf`,
53
+ so macros, field extractions, eventtypes and tags resolve without retyping them. Data models
54
+ (`tstats … from datamodel=…`) are read through a `datamodels` section of the mapping file.
55
+
56
+ A dashboard panel becomes a live tile only when its search translated completely; otherwise the
57
+ tile keeps the Splunk search and says what is missing. Inputs become dashboard variables.
58
+
59
+ | Exit code | Meaning |
60
+ |---|---|
61
+ | 0 | success |
62
+ | 1 | confidence at or below `--fail-on` |
63
+ | 2 | usage error, unreadable input or invalid mapping file |
64
+
65
+ ## Privacy
66
+
67
+ spl2dql never opens a network connection, reads no credentials and sends no telemetry. Your
68
+ searches stay on your machine.
69
+
70
+ `spl2dql serve` listens on 127.0.0.1 only, accepts only GET and HEAD, checks the Host header, and
71
+ serves a fixed set of files; the web app translates in your browser.
72
+
73
+ It will stay that way: spl2dql does not connect to your Dynatrace tenant and has no AI in it. To load
74
+ a converted dashboard you use your own tool, with your own credentials (`dtctl apply -f <file>`).
75
+
76
+ ## Not affiliated
77
+
78
+ spl2dql is an independent open-source project. It is not affiliated with, endorsed by or supported
79
+ by Splunk Inc., Cisco or Dynatrace. Splunk, SPL, Dynatrace and DQL are trademarks of their
80
+ respective owners and are used only to describe what this tool works with. Provided without
81
+ warranty; check every translated query before relying on it.
82
+
83
+ Apache-2.0.
package/bin/spl2dql.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { run } from '../dist/main.js';
3
+
4
+ // A reader that closes early (`spl2dql commands | head`) is normal for a CLI: stop quietly
5
+ // instead of crashing with an unhandled EPIPE.
6
+ for (const stream of [process.stdout, process.stderr]) {
7
+ stream.on('error', (error) => {
8
+ if (error.code === 'EPIPE') process.exit(process.exitCode ?? 0);
9
+ throw error;
10
+ });
11
+ }
12
+
13
+ const code = await run(process.argv.slice(2), {
14
+ stdout: process.stdout,
15
+ stderr: process.stderr,
16
+ stdin: process.stdin,
17
+ env: process.env,
18
+ cwd: process.cwd(),
19
+ });
20
+ process.exitCode = code;
@@ -0,0 +1,21 @@
1
+ import { type ConfigFile, type DashboardSource, InputError, type SearchInput, safeFileName } from '@spl2dql/core';
2
+ export { InputError, type SearchInput, safeFileName };
3
+ /** Everything found in the files and directories given on the command line. */
4
+ export interface Inputs {
5
+ searches: SearchInput[];
6
+ /** Splunk dashboards: Simple XML, or a Dashboard Studio definition. */
7
+ dashboards: DashboardSource[];
8
+ /** macros.conf, props.conf, transforms.conf, eventtypes.conf, tags.conf — in path order. */
9
+ configs: ConfigFile[];
10
+ /** Files and folders inside a given folder that could not be read, as notes (ADR-029). */
11
+ skipped: string[];
12
+ }
13
+ /** All inputs of one run together (ADR-029). */
14
+ export declare const MAX_TOTAL_BYTES: number;
15
+ /**
16
+ * Reads searches, dashboards and Splunk configuration files. Directories are walked without
17
+ * following symbolic links (so a link cannot pull in files from elsewhere or loop). In a directory
18
+ * only files that are recognisably Splunk's are read: .spl and .txt searches, the known .conf
19
+ * files, and .xml/.json files that are dashboards. A file named on the command line is always read.
20
+ */
21
+ export declare function readInputs(paths: readonly string[], cwd: string, maxTotalBytes?: number): Inputs;
package/dist/inputs.js ADDED
@@ -0,0 +1,130 @@
1
+ import { lstatSync, readdirSync, readFileSync } from 'node:fs';
2
+ import { basename, extname, join, relative, resolve, sep } from 'node:path';
3
+ import { configKind, InputError, parseCsvSearches, parseSavedSearches, safeFileName, } from '@spl2dql/core';
4
+ export { InputError, safeFileName };
5
+ const MAX_FILE = 10 * 1024 * 1024;
6
+ const MAX_FILES = 50_000;
7
+ const MAX_SEARCHES = 100_000;
8
+ const MAX_DASHBOARDS = 10_000;
9
+ /** All inputs of one run together (ADR-029). */
10
+ export const MAX_TOTAL_BYTES = 500 * 1024 * 1024;
11
+ /**
12
+ * Reads searches, dashboards and Splunk configuration files. Directories are walked without
13
+ * following symbolic links (so a link cannot pull in files from elsewhere or loop). In a directory
14
+ * only files that are recognisably Splunk's are read: .spl and .txt searches, the known .conf
15
+ * files, and .xml/.json files that are dashboards. A file named on the command line is always read.
16
+ */
17
+ export function readInputs(paths, cwd, maxTotalBytes = MAX_TOTAL_BYTES) {
18
+ const out = { searches: [], dashboards: [], configs: [], skipped: [] };
19
+ const unreadable = (path, e) => {
20
+ const code = e?.code;
21
+ out.skipped.push(`${shown(path)} could not be read${code ? ` (${code})` : ''}; it was skipped.`);
22
+ };
23
+ let files = 0;
24
+ let bytes = 0;
25
+ // What reports call a file: its path from the input given on the command line (a folder keeps its
26
+ // own name in front), never an absolute path.
27
+ let root = '';
28
+ let label = '';
29
+ const shown = (path) => {
30
+ const rel = relative(root, path);
31
+ return (rel === '' ? label : `${label}/${rel}`).split(sep).join('/');
32
+ };
33
+ const visit = (path, explicit) => {
34
+ let st;
35
+ try {
36
+ st = lstatSync(path);
37
+ }
38
+ catch (e) {
39
+ if (!explicit)
40
+ return void unreadable(path, e);
41
+ throw new InputError(`Cannot read ${path}: it does not exist or is not accessible.`);
42
+ }
43
+ if (st.isSymbolicLink()) {
44
+ if (explicit)
45
+ throw new InputError(`${path} is a symbolic link; pass the file it points to.`);
46
+ return;
47
+ }
48
+ if (st.isDirectory()) {
49
+ let entries;
50
+ try {
51
+ entries = readdirSync(path).sort();
52
+ }
53
+ catch (e) {
54
+ // Inside a folder that was given, one that cannot be read is skipped with a note.
55
+ if (!explicit)
56
+ return void unreadable(path, e);
57
+ throw new InputError(`Cannot read the folder ${path}.`);
58
+ }
59
+ for (const entry of entries)
60
+ visit(join(path, entry), false);
61
+ return;
62
+ }
63
+ if (!st.isFile())
64
+ return;
65
+ const ext = extname(path).toLowerCase();
66
+ const name = basename(path);
67
+ const lower = name.toLowerCase();
68
+ const config = configKind(name) !== undefined;
69
+ const known = ext === '.spl' || ext === '.txt' || ext === '.xml' || ext === '.json' || config || lower === 'savedsearches.conf';
70
+ if (!explicit && !known)
71
+ return;
72
+ if (st.size > MAX_FILE) {
73
+ if (explicit)
74
+ throw new InputError(`${path} is larger than 10 MB.`);
75
+ return;
76
+ }
77
+ if (++files > MAX_FILES)
78
+ throw new InputError(`More than ${MAX_FILES} files; translate them in smaller batches.`);
79
+ bytes += st.size;
80
+ if (bytes > maxTotalBytes) {
81
+ throw new InputError(`The inputs are larger than ${Math.round(maxTotalBytes / 1024 / 1024)} MB in total; translate them in smaller batches.`);
82
+ }
83
+ let text;
84
+ try {
85
+ text = readFileSync(path, 'utf8');
86
+ }
87
+ catch (e) {
88
+ bytes -= st.size;
89
+ files--;
90
+ if (!explicit)
91
+ return void unreadable(path, e);
92
+ throw new InputError(`Cannot read ${path}.`);
93
+ }
94
+ const origin = shown(path);
95
+ if (config)
96
+ out.configs.push({ name: origin, text });
97
+ else if (lower === 'savedsearches.conf' || ext === '.conf')
98
+ for (const s of parseSavedSearches(text, origin))
99
+ out.searches.push(s);
100
+ else if (ext === '.csv')
101
+ for (const s of parseCsvSearches(text, origin))
102
+ out.searches.push(s);
103
+ else if (ext === '.xml' || ext === '.json') {
104
+ if (looksLikeDashboard(text, ext))
105
+ out.dashboards.push({ name: origin, text });
106
+ else if (explicit)
107
+ throw new InputError(`${path} is not a Splunk dashboard (Simple XML or a Dashboard Studio definition).`);
108
+ }
109
+ else
110
+ out.searches.push({ name: name.replace(/\.(spl|txt)$/i, ''), spl: text.trim(), origin });
111
+ if (out.searches.length > MAX_SEARCHES)
112
+ throw new InputError(`More than ${MAX_SEARCHES} searches; translate them in smaller batches.`);
113
+ if (out.dashboards.length > MAX_DASHBOARDS)
114
+ throw new InputError(`More than ${MAX_DASHBOARDS} dashboards; convert them in smaller batches.`);
115
+ };
116
+ for (const p of paths) {
117
+ root = resolve(cwd, p);
118
+ label = basename(root) || 'input';
119
+ visit(root, true);
120
+ }
121
+ return out;
122
+ }
123
+ /** A cheap look at the start of a file, so a folder walk does not pick up unrelated XML or JSON. */
124
+ function looksLikeDashboard(text, ext) {
125
+ const head = text.slice(0, 4000);
126
+ if (ext === '.xml')
127
+ return /<(dashboard|form)[\s>]/.test(head);
128
+ return text.includes('"dataSources"') || text.includes('"visualizations"');
129
+ }
130
+ //# sourceMappingURL=inputs.js.map
package/dist/main.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { type TranslateResult } from '@spl2dql/core';
2
+ export interface CliIO {
3
+ stdout: {
4
+ write(s: string): unknown;
5
+ isTTY?: boolean;
6
+ };
7
+ stderr: {
8
+ write(s: string): unknown;
9
+ isTTY?: boolean;
10
+ };
11
+ stdin: AsyncIterable<Buffer | string>;
12
+ env: Record<string, string | undefined>;
13
+ cwd: string;
14
+ /** Injected clock for report headers (tests). */
15
+ now?: () => Date;
16
+ /** The run's budgets; tests set small ones. Defaults MAX_RUN_OUTPUT, MAX_RUN_WORK, MAX_REPORT_DETAIL. */
17
+ maxRunOutput?: number;
18
+ maxRunWork?: number;
19
+ maxReportDetail?: number;
20
+ }
21
+ export declare const EXIT: {
22
+ readonly ok: 0;
23
+ readonly confidence: 1;
24
+ readonly usage: 2;
25
+ };
26
+ /** DQL one run may write, dashboards included (ADR-029). */
27
+ export declare const MAX_RUN_OUTPUT: number;
28
+ /** SPL one run may translate, after macro expansion (ADR-029). */
29
+ export declare const MAX_RUN_WORK: number;
30
+ /** Report text with per-search detail; past it, searches are listed without detail (ADR-029). */
31
+ export declare const MAX_REPORT_DETAIL: number;
32
+ /** Runs the CLI. Returns the exit code instead of exiting, so it can be tested in-process. */
33
+ export declare function run(argv: readonly string[], io: CliIO): Promise<number>;
34
+ /**
35
+ * Text from the input made safe for a terminal: every escape sequence (CSI such as colours, OSC,
36
+ * DCS and the other string controls, two-character escapes) is removed; a carriage return that
37
+ * is not part of CRLF (it would let a note overwrite its own line) and the Unicode bidirectional
38
+ * controls (which reorder what is shown) are removed; other control characters become "?".
39
+ */
40
+ export declare function safeText(s: string): string;
41
+ export type { TranslateResult };