@plurnk/plurnk-mimetypes 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.
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/SPEC.md +187 -0
- package/bin/plurnk-mimetypes-compile.js +7 -0
- package/dist/AntlrExtractor.d.ts +8 -0
- package/dist/AntlrExtractor.d.ts.map +1 -0
- package/dist/AntlrExtractor.js +31 -0
- package/dist/AntlrExtractor.js.map +1 -0
- package/dist/BaseHandler.d.ts +13 -0
- package/dist/BaseHandler.d.ts.map +1 -0
- package/dist/BaseHandler.js +28 -0
- package/dist/BaseHandler.js.map +1 -0
- package/dist/Mimetypes.d.ts +33 -0
- package/dist/Mimetypes.d.ts.map +1 -0
- package/dist/Mimetypes.js +131 -0
- package/dist/Mimetypes.js.map +1 -0
- package/dist/compile.d.ts +9 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +92 -0
- package/dist/compile.js.map +1 -0
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +11 -0
- package/dist/defaults.js.map +1 -0
- package/dist/detect.d.ts +4 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +53 -0
- package/dist/detect.js.map +1 -0
- package/dist/discover.d.ts +3 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +89 -0
- package/dist/discover.js.map +1 -0
- package/dist/fit.d.ts +4 -0
- package/dist/fit.d.ts.map +1 -0
- package/dist/fit.js +59 -0
- package/dist/fit.js.map +1 -0
- package/dist/format.d.ts +11 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +85 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/withExtractor.d.ts +15 -0
- package/dist/withExtractor.d.ts.map +1 -0
- package/dist/withExtractor.js +41 -0
- package/dist/withExtractor.js.map +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PossumTech Laboratories
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @plurnk/plurnk-mimetypes
|
|
2
|
+
|
|
3
|
+
Framework + detection service for the `@plurnk/plurnk-mimetypes-*` handler family. Sits between [plurnk-service](https://github.com/plurnk/plurnk-service) (the engine) and individual per-mimetype handler repos (the implementations).
|
|
4
|
+
|
|
5
|
+
plurnk-service hands a path or content blob to `Mimetypes.process(...)` and gets back `{ mimetype, symbols, preview, ok }`. The service stays mimetype-illiterate; this helper owns detection, discovery, handler instantiation, outline formatting, token-budgeted preview truncation, the duck contract spec, and the build utilities handler repos consume.
|
|
6
|
+
|
|
7
|
+
## install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @plurnk/plurnk-mimetypes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node ≥ 25 (native TypeScript support, ESM only).
|
|
14
|
+
|
|
15
|
+
## use — orchestrator (plurnk-service side)
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Mimetypes } from "@plurnk/plurnk-mimetypes";
|
|
19
|
+
|
|
20
|
+
const mimetypes = new Mimetypes({
|
|
21
|
+
tokenize: async (text) => myProviderTokenizer(text),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const result = await mimetypes.process(
|
|
25
|
+
{ path: "src/main.py" },
|
|
26
|
+
{ budget: 256 },
|
|
27
|
+
);
|
|
28
|
+
// result.mimetype === "text/x-python"
|
|
29
|
+
// result.symbols === structural outline (string)
|
|
30
|
+
// result.preview === bounded outline within budget tokens
|
|
31
|
+
// result.ok === true
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Without a budget the preview is unbounded — equivalent to `symbols`. plurnk-service supplies the real budget (sourced from `PLURNK_ENTRY_SIZE_DEFAULT_TOKENS`).
|
|
35
|
+
|
|
36
|
+
Pipeline failure modes are documented in [SPEC.md](SPEC.md#error-policy).
|
|
37
|
+
|
|
38
|
+
## use — handler authors
|
|
39
|
+
|
|
40
|
+
A handler is a class extending `BaseHandler` (or `AntlrExtractor` for grammar-backed extraction). The framework derives `symbols`, `preview`, and `validate` from your single `extract(content)` method.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { BaseHandler } from "@plurnk/plurnk-mimetypes";
|
|
44
|
+
import type { MimeSymbol } from "@plurnk/plurnk-mimetypes";
|
|
45
|
+
|
|
46
|
+
export default class TextSomething extends BaseHandler {
|
|
47
|
+
extract(content: string): MimeSymbol[] {
|
|
48
|
+
// return structural declarations as MimeSymbol[]
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Discovery: declare yourself in `package.json`.
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"plurnk": {
|
|
59
|
+
"kind": "mimetype",
|
|
60
|
+
"name": "text/something",
|
|
61
|
+
"glyph": "✨",
|
|
62
|
+
"extensions": [".sth"]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Reference handler: [plurnk/plurnk-mimetypes-text-markdown](https://github.com/plurnk/plurnk-mimetypes-text-markdown). Fork and adapt for new mimetypes — it's a real production handler, not a synthetic skeleton.
|
|
68
|
+
|
|
69
|
+
For grammar-backed handlers, vendor your `.g4` files in `grammar/`, run `npx plurnk-mimetypes-compile`, and switch the parent class to `AntlrExtractor`. ANTLR handlers add the runtime and compiler to their own devDependencies (the framework declares both as optional peer deps so consumers who only use `BaseHandler`/`Mimetypes` don't pay):
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
npm install --save-dev antlr-ng@^1.0.10 antlr4ng@^3.0.0
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
See [SPEC.md](SPEC.md#9-antlr-extractor) for the full handler wiring.
|
|
76
|
+
|
|
77
|
+
## public API
|
|
78
|
+
|
|
79
|
+
The package exposes its full primitive surface for tools building on top of it:
|
|
80
|
+
|
|
81
|
+
| Export | Purpose |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `Mimetypes` | top-level pipeline orchestrator (`process`, `detect`, `getHandler`, `ready`) |
|
|
84
|
+
| `BaseHandler` | base class for handlers (default export) |
|
|
85
|
+
| `AntlrExtractor` | base class for ANTLR-backed handlers |
|
|
86
|
+
| `withExtractor(BaseVisitor)` | mixin that adds symbol-collection state to any antlr4ng visitor |
|
|
87
|
+
| `detect(input, registry)` | path/ext/hint/content → mimetype resolver |
|
|
88
|
+
| `discover(options)` | scan installed `@plurnk/plurnk-mimetypes-*` packages |
|
|
89
|
+
| `emptyRegistry()` | construct an empty `Registry` |
|
|
90
|
+
| `format(symbols)` | `MimeSymbol[]` → indented outline string |
|
|
91
|
+
| `fit(symbols, budget, tokenize)` | drop-deepest-first token-budget truncation |
|
|
92
|
+
| `fitContent(content, budget, tokenize)` | raw-content token-budget truncation |
|
|
93
|
+
| `buildTree(symbols)` | flat `MimeSymbol[]` → nested `TreeNode[]` |
|
|
94
|
+
| `renderTree(nodes)` | `TreeNode[]` → outline string |
|
|
95
|
+
| `maxDepth(nodes)` | tree's maximum nesting depth |
|
|
96
|
+
| `pruneToMaxDepth(nodes, limit)` | drop nodes deeper than `limit` |
|
|
97
|
+
| `runCompile(opts)` | invoke antlr-ng + post-process imports |
|
|
98
|
+
| `rewriteImports(dir)` | rewrite `.js` import extensions to `.ts` |
|
|
99
|
+
| `defaultTokenize` | fallback heuristic (`text.length / 2`); biased toward safety |
|
|
100
|
+
|
|
101
|
+
Public types: `MimeSymbol`, `SymbolKind`, `HandlerMetadata`, `HandlerOptions`, `TokenizeFn`, `ExtractionVisitor`, `Registry`, `DetectInput`, `HandlerInfo`, `Discovery`, `DiscoverOptions`, `TreeNode`, `CompileOptions`, `HandlerLoader`, `MimetypesOptions`, `ProcessInput`, `ProcessOptions`, `ProcessResult`.
|
|
102
|
+
|
|
103
|
+
## cli
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
plurnk-mimetypes-compile compile grammar/ → src/generated/ via antlr-ng
|
|
107
|
+
and rewrite .js import extensions to .ts
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Run from a handler repo's root directory.
|
|
111
|
+
|
|
112
|
+
## development
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
npm install
|
|
116
|
+
npm run build
|
|
117
|
+
npm test
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`test:lint`, `test:unit`, `test:intg` separately if needed. No biome / eslint — `tsc --noEmit` is lint.
|
|
121
|
+
|
|
122
|
+
## license
|
|
123
|
+
|
|
124
|
+
MIT.
|
package/SPEC.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# @plurnk/plurnk-mimetypes — Specification
|
|
2
|
+
|
|
3
|
+
This document defines the duck contract, pipeline, data shapes, and policies that the framework owns. Per-mimetype handler repos consume this spec; plurnk-service consumes the pipeline.
|
|
4
|
+
|
|
5
|
+
The eventual home for the formal version of this contract is JSON Schema in [`@plurnk/plurnk-grammar`](https://github.com/plurnk/plurnk-grammar). Until then, this plain-text spec is authoritative.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Duck contract
|
|
10
|
+
|
|
11
|
+
A handler is any class instance whose shape matches:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
interface Handler {
|
|
15
|
+
readonly mimetype: string;
|
|
16
|
+
readonly glyph: string;
|
|
17
|
+
readonly extensions: readonly string[];
|
|
18
|
+
extract(content: string): MimeSymbol[];
|
|
19
|
+
validate(content: string): void;
|
|
20
|
+
symbols(content: string): string;
|
|
21
|
+
preview(content: string, budget: number): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
In practice handlers extend `BaseHandler` (or `AntlrExtractor`), which provides every method derived from a single `extract(content) → MimeSymbol[]`. Subclasses normally implement `extract` only. Identity (`mimetype`, `glyph`, `extensions`) is injected at construction time from the handler's `package.json` `plurnk` block.
|
|
26
|
+
|
|
27
|
+
## 2. `package.json` `plurnk` discovery block
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"plurnk": {
|
|
32
|
+
"kind": "mimetype",
|
|
33
|
+
"name": "text/x-python",
|
|
34
|
+
"glyph": "🐍",
|
|
35
|
+
"extensions": [".py", ".pyw"]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Field | Type | Required | Notes |
|
|
41
|
+
|---|---|---|---|
|
|
42
|
+
| `kind` | `"mimetype"` | yes | Distinguishes mimetype handlers from `"provider"` and `"scheme"` siblings in the plurnk family |
|
|
43
|
+
| `name` | string | yes | The canonical mimetype (`text/markdown`, `application/json`, `text/x-python`, …) |
|
|
44
|
+
| `glyph` | string | no | Single-character display marker; defaults to empty string |
|
|
45
|
+
| `extensions` | string[] | no | Mixed list: entries beginning with `.` are file extensions (lowercased on match); other entries are special filenames matched verbatim (`Dockerfile`, `Makefile`) |
|
|
46
|
+
|
|
47
|
+
`discover()` scans `node_modules/@plurnk/` for packages with `plurnk.kind === "mimetype"`. Last-loaded wins on mimetype or extension conflicts.
|
|
48
|
+
|
|
49
|
+
## 3. `MimeSymbol` and `SymbolKind`
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
interface MimeSymbol {
|
|
53
|
+
name: string;
|
|
54
|
+
kind: SymbolKind;
|
|
55
|
+
line: number; // 1-indexed start
|
|
56
|
+
endLine: number; // 1-indexed end (== line for single-line symbols)
|
|
57
|
+
params?: string[]; // present on functions and methods when names are available
|
|
58
|
+
level?: number; // present on heading kinds; 1-6
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type SymbolKind =
|
|
62
|
+
| "class" | "function" | "method" | "field"
|
|
63
|
+
| "interface" | "enum" | "type" | "module"
|
|
64
|
+
| "variable" | "constant" | "heading";
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Inclusion policy
|
|
68
|
+
|
|
69
|
+
Handlers include symbols that are **defined in the content and not confirmed invisible outside their declaring scope**.
|
|
70
|
+
|
|
71
|
+
- Include: classes, functions, methods, fields, interfaces, enums, types, modules, exported variables/constants, markdown headings.
|
|
72
|
+
- Exclude: imports, exports as standalone symbols, local variables inside function bodies, unexported module-scope variables (in languages with module privacy), function calls, control flow, comments, magic numbers, anonymous declarations.
|
|
73
|
+
- Class members (methods, fields) are always included — they're the API surface even though syntactically inside a class body.
|
|
74
|
+
- When in doubt, include. Only exclude when the language semantics *confirm* the symbol is inaccessible from outside the file.
|
|
75
|
+
|
|
76
|
+
### Parameters
|
|
77
|
+
|
|
78
|
+
Functions and methods include `params` when the grammar exposes them:
|
|
79
|
+
|
|
80
|
+
- Plain names: `["source", "options"]`
|
|
81
|
+
- Destructured: `["{host, port}"]` (raw text)
|
|
82
|
+
- Rest: `["...args"]`
|
|
83
|
+
- Defaults: `["entryRule=\"program\""]` (included in the assignable text)
|
|
84
|
+
|
|
85
|
+
Omit `params` entirely when the language doesn't expose named parameters.
|
|
86
|
+
|
|
87
|
+
## 4. Outline format (`symbols` / `format`)
|
|
88
|
+
|
|
89
|
+
The framework owns outline rendering. Handlers produce structured `MimeSymbol[]`; `format(symbols)` turns it into a string.
|
|
90
|
+
|
|
91
|
+
**Tree hierarchy:**
|
|
92
|
+
- Heading symbols: nested by `level` field (1–6).
|
|
93
|
+
- Other symbols: nested by line-range containment. A symbol whose `[line, endLine]` is fully inside another's is its child.
|
|
94
|
+
|
|
95
|
+
**Line rendering:**
|
|
96
|
+
- Heading: `<indent># Name [line]` (hash count = level, indent = tree depth).
|
|
97
|
+
- Other: `<indent>kind name(params)? [line-endLine]` (kind prefix, params if present, range collapses to `[N]` when single-line).
|
|
98
|
+
- Indent unit: two spaces per depth level.
|
|
99
|
+
|
|
100
|
+
Example:
|
|
101
|
+
```
|
|
102
|
+
class Parser [5-47]
|
|
103
|
+
method parse(source) [10-20]
|
|
104
|
+
method load(dir) [22-45]
|
|
105
|
+
function topLevel(a, b) [50-60]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 5. `preview` — token-budgeted truncation
|
|
109
|
+
|
|
110
|
+
`Mimetypes.process` accepts `{ budget?: number }`. When unspecified, budget is `Number.POSITIVE_INFINITY` (no truncation — preview equals symbols). The helper does NOT invent a magic default; plurnk-service supplies the real budget per call.
|
|
111
|
+
|
|
112
|
+
**Budget unit is tokens, never characters.** The tokenize function is injected at `Mimetypes` construction time. The default fallback (`defaultTokenize`) is `Math.ceil(text.length / 2)` — conservative; biased toward overestimation, not the industry-standard `/4` heuristic.
|
|
113
|
+
|
|
114
|
+
**Truncation strategy (`fit`):**
|
|
115
|
+
1. Render full outline. If it fits, return it.
|
|
116
|
+
2. Drop deepest tree level. Render. Repeat until fits or only roots remain.
|
|
117
|
+
3. If even all-roots overflows, drop trailing root symbols one at a time until fits.
|
|
118
|
+
4. If even a single root overflows, return empty string (surrender — caller may invoke `fitContent` to substitute a raw-content fragment).
|
|
119
|
+
|
|
120
|
+
**Raw content fallback (`fitContent`):**
|
|
121
|
+
- Used when `extract()` returns `[]` (empty symbols) but the content is non-empty.
|
|
122
|
+
- Iteratively shrinks the content slice to fit `budget` tokens via the same tokenize function, with safety margin and max-iterations clamp.
|
|
123
|
+
|
|
124
|
+
## 6. `validate`
|
|
125
|
+
|
|
126
|
+
Default: no-op. Override only for mimetypes with a real syntax check that can fail (e.g., `application/json` throws on malformed JSON).
|
|
127
|
+
|
|
128
|
+
When `validate` throws inside `Mimetypes.process`, the error propagates to the caller per the error policy (§7).
|
|
129
|
+
|
|
130
|
+
## 7. Error policy
|
|
131
|
+
|
|
132
|
+
| Failure | Behavior |
|
|
133
|
+
|---|---|
|
|
134
|
+
| Detection returns null | `{ mimetype: null, symbols: "", preview: "", ok: false }` |
|
|
135
|
+
| Content read fails (path missing/unreadable) | `{ mimetype, symbols: "", preview: "", ok: false }` |
|
|
136
|
+
| Handler package not loadable | `{ mimetype, symbols: "", preview: <raw fallback>, ok: false }` |
|
|
137
|
+
| `validate()` throws | **Propagates** to the caller — contract violation |
|
|
138
|
+
| `extract()` throws | Contained inside `AntlrExtractor` → empty `MimeSymbol[]` → raw-content fallback |
|
|
139
|
+
| `extract()` returns `[]` with non-empty content | Symbols string empty; preview falls back to `fitContent(content, budget)` |
|
|
140
|
+
|
|
141
|
+
## 8. Detection priority
|
|
142
|
+
|
|
143
|
+
`detect({ path?, ext?, hint?, content? }, registry)` resolves in strict priority order, highest wins:
|
|
144
|
+
|
|
145
|
+
1. `hint` — caller asserts a mimetype directly.
|
|
146
|
+
2. `path` basename matches a registered filename (`Dockerfile`, `Makefile`).
|
|
147
|
+
3. `ext` (explicit) or `extname(path)` matches a registered extension (case-insensitive, leading-dot enforced on lookup).
|
|
148
|
+
4. `content` — magic-byte sniffing. **Future hook**; no implementation in v0.1.
|
|
149
|
+
|
|
150
|
+
Returns the resolved mimetype string or `null`.
|
|
151
|
+
|
|
152
|
+
## 9. ANTLR extractor
|
|
153
|
+
|
|
154
|
+
For grammar-backed handlers:
|
|
155
|
+
|
|
156
|
+
1. Vendor `.g4` files in `grammar/` at the handler repo root.
|
|
157
|
+
2. Add the compiler and runtime to your own devDependencies (the framework declares both as optional peer deps; only ANTLR-backed handlers need them):
|
|
158
|
+
```
|
|
159
|
+
npm install --save-dev antlr-ng@^1.0.10 antlr4ng@^3.0.0
|
|
160
|
+
```
|
|
161
|
+
3. Run `npx plurnk-mimetypes-compile` — invokes `antlr-ng -D language=TypeScript -o src/generated --generate-visitor true --generate-listener false grammar/*.g4` and post-processes the output to rewrite `.js` import extensions to `.ts` (so Node's native TS strip works without a separate build pass). Invoke via `npx` so node_modules/.bin/ is on PATH when the spawn happens.
|
|
162
|
+
4. Extend `AntlrExtractor` instead of `BaseHandler`.
|
|
163
|
+
5. Implement `parseTree(content)` (return a parser rule context) and `createVisitor()` (return an `ExtractionVisitor`).
|
|
164
|
+
6. Build the visitor by extending `withExtractor(GeneratedVisitor)` — the mixin adds `symbols`, `inBody`, `addSymbol(kind, name, ctx, params?, extra?)`, and `gateBody(ctx)` to the antlr4ng visitor.
|
|
165
|
+
|
|
166
|
+
Parse failures and visit-time exceptions are caught by `AntlrExtractor.extract()` and converted to an empty `MimeSymbol[]`, allowing the orchestrator's raw-content fallback to take over.
|
|
167
|
+
|
|
168
|
+
## 10. Tokenization architecture
|
|
169
|
+
|
|
170
|
+
The helper never reads any environment variable. Tokenization is a runtime injection from plurnk-service:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
plurnk-providers-* plurnk-service @plurnk/plurnk-mimetypes
|
|
174
|
+
───────────────── ────────────── ────────────────────────
|
|
175
|
+
exports tokenize(text) ─→ registers from active ─→ receives at construction
|
|
176
|
+
provider via { tokenize }
|
|
177
|
+
caches by SHA256(text)
|
|
178
|
+
budget per call sourced
|
|
179
|
+
from PLURNK_ENTRY_SIZE_
|
|
180
|
+
DEFAULT_TOKENS env (256)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Handlers never see the tokenize function. The framework uses it internally for `preview` only.
|
|
184
|
+
|
|
185
|
+
## 11. Public API stability
|
|
186
|
+
|
|
187
|
+
All exports from `@plurnk/plurnk-mimetypes/index` are stable from `v0.1.0` onward under semver. Internal modules (those not re-exported from `index.ts`) are not part of the stable API and may change between minor versions.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import BaseHandler from "./BaseHandler.ts";
|
|
2
|
+
import type { ExtractionVisitor, MimeSymbol } from "./types.ts";
|
|
3
|
+
export default abstract class AntlrExtractor extends BaseHandler {
|
|
4
|
+
protected abstract parseTree(content: string): unknown;
|
|
5
|
+
protected abstract createVisitor(): ExtractionVisitor;
|
|
6
|
+
extract(content: string): MimeSymbol[];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=AntlrExtractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AntlrExtractor.d.ts","sourceRoot":"","sources":["../src/AntlrExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAUhE,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,cAAe,SAAQ,WAAW;IAC5D,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IACtD,SAAS,CAAC,QAAQ,CAAC,aAAa,IAAI,iBAAiB;IAErD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE;CAiBzC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import BaseHandler from "./BaseHandler.js";
|
|
2
|
+
// Abstract base for grammar-backed mimetype handlers. Subclasses supply two
|
|
3
|
+
// methods:
|
|
4
|
+
// parseTree(content) — construct lexer/parser, return the entry-rule tree.
|
|
5
|
+
// createVisitor() — return an ExtractionVisitor (typically built via
|
|
6
|
+
// withExtractor(GeneratedVisitor)).
|
|
7
|
+
// extract() orchestrates: parseTree -> createVisitor -> visit -> visitor.symbols.
|
|
8
|
+
// Parse and visit errors are caught and converted to an empty symbol list;
|
|
9
|
+
// callers fall back to a raw-content preview when extraction yields nothing.
|
|
10
|
+
export default class AntlrExtractor extends BaseHandler {
|
|
11
|
+
extract(content) {
|
|
12
|
+
let tree;
|
|
13
|
+
try {
|
|
14
|
+
tree = this.parseTree(content);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
if (tree === null || tree === undefined)
|
|
20
|
+
return [];
|
|
21
|
+
const visitor = this.createVisitor();
|
|
22
|
+
try {
|
|
23
|
+
visitor.visit(tree);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
return visitor.symbols;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=AntlrExtractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AntlrExtractor.js","sourceRoot":"","sources":["../src/AntlrExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAG3C,4EAA4E;AAC5E,WAAW;AACX,6EAA6E;AAC7E,0EAA0E;AAC1E,2DAA2D;AAC3D,kFAAkF;AAClF,2EAA2E;AAC3E,6EAA6E;AAC7E,MAAM,CAAC,OAAO,OAAgB,cAAe,SAAQ,WAAW;IAI5D,OAAO,CAAC,OAAe;QACnB,IAAI,IAAa,CAAC;QAClB,IAAI,CAAC;YACD,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,EAAE,CAAC;QACd,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QAEnD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACrC,IAAI,CAAC;YACD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,EAAE,CAAC;QACd,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC;IAC3B,CAAC;CACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HandlerMetadata, HandlerOptions, MimeSymbol } from "./types.ts";
|
|
2
|
+
export default class BaseHandler {
|
|
3
|
+
#private;
|
|
4
|
+
readonly mimetype: string;
|
|
5
|
+
readonly glyph: string;
|
|
6
|
+
readonly extensions: readonly string[];
|
|
7
|
+
constructor(metadata: HandlerMetadata, options?: HandlerOptions);
|
|
8
|
+
extract(_content: string): MimeSymbol[];
|
|
9
|
+
validate(_content: string): void;
|
|
10
|
+
symbols(content: string): string;
|
|
11
|
+
preview(content: string, budget: number): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=BaseHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseHandler.d.ts","sourceRoot":"","sources":["../src/BaseHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAE1F,MAAM,CAAC,OAAO,OAAO,WAAW;;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;gBAG3B,QAAQ,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB;IAOnE,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE;IAIvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIhC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAI1B,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGlE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defaultTokenize } from "./defaults.js";
|
|
2
|
+
import { format } from "./format.js";
|
|
3
|
+
import { fit } from "./fit.js";
|
|
4
|
+
export default class BaseHandler {
|
|
5
|
+
mimetype;
|
|
6
|
+
glyph;
|
|
7
|
+
extensions;
|
|
8
|
+
#tokenize;
|
|
9
|
+
constructor(metadata, options = {}) {
|
|
10
|
+
this.mimetype = metadata.mimetype;
|
|
11
|
+
this.glyph = metadata.glyph;
|
|
12
|
+
this.extensions = Object.freeze([...metadata.extensions]);
|
|
13
|
+
this.#tokenize = options.tokenize ?? defaultTokenize;
|
|
14
|
+
}
|
|
15
|
+
extract(_content) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
validate(_content) {
|
|
19
|
+
// Default: anything is valid. Override for mimetypes with real syntax.
|
|
20
|
+
}
|
|
21
|
+
symbols(content) {
|
|
22
|
+
return format(this.extract(content));
|
|
23
|
+
}
|
|
24
|
+
async preview(content, budget) {
|
|
25
|
+
return fit(this.extract(content), budget, this.#tokenize);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=BaseHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseHandler.js","sourceRoot":"","sources":["../src/BaseHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,MAAM,CAAC,OAAO,OAAO,WAAW;IACnB,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,UAAU,CAAoB;IAC9B,SAAS,CAAa;IAE/B,YAAY,QAAyB,EAAE,UAA0B,EAAE;QAC/D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;QAC1D,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC;IACzD,CAAC;IAED,OAAO,CAAC,QAAgB;QACpB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,QAAgB;QACrB,uEAAuE;IAC3E,CAAC;IAED,OAAO,CAAC,OAAe;QACnB,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAe,EAAE,MAAc;QACzC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type BaseHandler from "./BaseHandler.ts";
|
|
2
|
+
import type { DetectInput, DiscoverOptions, Discovery, TokenizeFn } from "./types.ts";
|
|
3
|
+
export type HandlerLoader = (packageName: string) => Promise<unknown>;
|
|
4
|
+
export interface MimetypesOptions {
|
|
5
|
+
tokenize?: TokenizeFn;
|
|
6
|
+
discoverOptions?: DiscoverOptions;
|
|
7
|
+
discovery?: Discovery;
|
|
8
|
+
loader?: HandlerLoader;
|
|
9
|
+
}
|
|
10
|
+
export interface ProcessInput {
|
|
11
|
+
path?: string;
|
|
12
|
+
content?: string;
|
|
13
|
+
ext?: string;
|
|
14
|
+
hint?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ProcessOptions {
|
|
17
|
+
budget?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ProcessResult {
|
|
20
|
+
mimetype: string | null;
|
|
21
|
+
symbols: string;
|
|
22
|
+
preview: string;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
}
|
|
25
|
+
export default class Mimetypes {
|
|
26
|
+
#private;
|
|
27
|
+
constructor(options?: MimetypesOptions);
|
|
28
|
+
ready(): Promise<void>;
|
|
29
|
+
detect(input: DetectInput): Promise<string | null>;
|
|
30
|
+
getHandler(mimetype: string): Promise<BaseHandler | null>;
|
|
31
|
+
process(input: ProcessInput, options?: ProcessOptions): Promise<ProcessResult>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=Mimetypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mimetypes.d.ts","sourceRoot":"","sources":["../src/Mimetypes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EACR,WAAW,EACX,eAAe,EACf,SAAS,EAGT,UAAU,EACb,MAAM,YAAY,CAAC;AAapB,MAAM,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAItE,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAGlC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,OAAO,CAAC;CACf;AAMD,MAAM,CAAC,OAAO,OAAO,SAAS;;gBAQd,OAAO,GAAE,gBAAqB;IAUpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKlD,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAuCzD,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;CAwC3F"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import fs from "node:fs/promises";
|
|
10
|
+
import { defaultTokenize } from "./defaults.js";
|
|
11
|
+
import { detect } from "./detect.js";
|
|
12
|
+
import { discover } from "./discover.js";
|
|
13
|
+
import { fitContent } from "./fit.js";
|
|
14
|
+
// No default budget in the helper. plurnk-service owns the real default
|
|
15
|
+
// (PLURNK_ENTRY_SIZE_DEFAULT_TOKENS, runtime env, currently 256 tokens for the
|
|
16
|
+
// channel preview portal) and passes it per call. When budget is unspecified
|
|
17
|
+
// here, preview is unbounded — equivalent to symbols. Baking a fallback number
|
|
18
|
+
// would silently shadow the env var and create drift when plurnk-service
|
|
19
|
+
// changes its default.
|
|
20
|
+
const UNBOUNDED_BUDGET = Number.POSITIVE_INFINITY;
|
|
21
|
+
const defaultLoader = (packageName) => import(__rewriteRelativeImportExtension(packageName));
|
|
22
|
+
// Top-level orchestrator. Plurnk-service constructs one of these at boot,
|
|
23
|
+
// injecting its tokenize function. process(path) is the primary entry point;
|
|
24
|
+
// detect() and getHandler() are exposed for callers that want to drive the
|
|
25
|
+
// pipeline manually.
|
|
26
|
+
export default class Mimetypes {
|
|
27
|
+
#tokenize;
|
|
28
|
+
#discoverOptions;
|
|
29
|
+
#loader;
|
|
30
|
+
#handlerInstances = new Map();
|
|
31
|
+
#discovery = null;
|
|
32
|
+
#readyPromise = null;
|
|
33
|
+
constructor(options = {}) {
|
|
34
|
+
this.#tokenize = options.tokenize ?? defaultTokenize;
|
|
35
|
+
this.#discoverOptions = options.discoverOptions ?? {};
|
|
36
|
+
this.#loader = options.loader ?? defaultLoader;
|
|
37
|
+
if (options.discovery !== undefined)
|
|
38
|
+
this.#discovery = options.discovery;
|
|
39
|
+
}
|
|
40
|
+
// Eagerly run discovery. Safe to call multiple times — subsequent calls
|
|
41
|
+
// share the same in-flight promise. Optional: every public method that
|
|
42
|
+
// needs discovery awaits this internally.
|
|
43
|
+
async ready() {
|
|
44
|
+
if (this.#discovery !== null)
|
|
45
|
+
return;
|
|
46
|
+
if (this.#readyPromise !== null)
|
|
47
|
+
return this.#readyPromise;
|
|
48
|
+
this.#readyPromise = (async () => {
|
|
49
|
+
this.#discovery = await discover(this.#discoverOptions);
|
|
50
|
+
})();
|
|
51
|
+
return this.#readyPromise;
|
|
52
|
+
}
|
|
53
|
+
async detect(input) {
|
|
54
|
+
await this.ready();
|
|
55
|
+
return detect(input, this.#discovery.registry);
|
|
56
|
+
}
|
|
57
|
+
async getHandler(mimetype) {
|
|
58
|
+
await this.ready();
|
|
59
|
+
const cached = this.#handlerInstances.get(mimetype);
|
|
60
|
+
if (cached !== undefined)
|
|
61
|
+
return cached;
|
|
62
|
+
const info = this.#discovery.handlers.get(mimetype);
|
|
63
|
+
if (info === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
let mod;
|
|
66
|
+
try {
|
|
67
|
+
mod = await this.#loader(info.packageName);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (typeof mod !== "object" || mod === null)
|
|
73
|
+
return null;
|
|
74
|
+
const HandlerClass = mod.default;
|
|
75
|
+
if (typeof HandlerClass !== "function")
|
|
76
|
+
return null;
|
|
77
|
+
const metadata = {
|
|
78
|
+
mimetype: info.mimetype,
|
|
79
|
+
glyph: info.glyph,
|
|
80
|
+
extensions: info.extensions,
|
|
81
|
+
};
|
|
82
|
+
const handlerOptions = { tokenize: this.#tokenize };
|
|
83
|
+
const Ctor = HandlerClass;
|
|
84
|
+
const handler = new Ctor(metadata, handlerOptions);
|
|
85
|
+
this.#handlerInstances.set(mimetype, handler);
|
|
86
|
+
return handler;
|
|
87
|
+
}
|
|
88
|
+
// The pipeline. Detection -> content read -> handler resolve -> validate ->
|
|
89
|
+
// extract -> symbols -> preview. Errors are routed per policy:
|
|
90
|
+
// * detection fails or content read fails -> ok:false, empty strings
|
|
91
|
+
// * handler missing -> ok:false, raw-content preview as fallback
|
|
92
|
+
// * validate throws -> propagates (caller's contract; bug in content or handler)
|
|
93
|
+
// * extract throws -> contained inside handler -> empty symbols -> raw fallback
|
|
94
|
+
async process(input, options = {}) {
|
|
95
|
+
const budget = options.budget ?? UNBOUNDED_BUDGET;
|
|
96
|
+
const mimetype = await this.detect(input);
|
|
97
|
+
if (mimetype === null) {
|
|
98
|
+
return { mimetype: null, symbols: "", preview: "", ok: false };
|
|
99
|
+
}
|
|
100
|
+
const content = await this.#resolveContent(input);
|
|
101
|
+
if (content === null) {
|
|
102
|
+
return { mimetype, symbols: "", preview: "", ok: false };
|
|
103
|
+
}
|
|
104
|
+
const handler = await this.getHandler(mimetype);
|
|
105
|
+
if (handler === null) {
|
|
106
|
+
const preview = await fitContent(content, budget, this.#tokenize);
|
|
107
|
+
return { mimetype, symbols: "", preview, ok: false };
|
|
108
|
+
}
|
|
109
|
+
// Validate errors propagate per error policy — caller's contract.
|
|
110
|
+
handler.validate(content);
|
|
111
|
+
const symbols = handler.symbols(content);
|
|
112
|
+
let preview = await handler.preview(content, budget);
|
|
113
|
+
if (preview === "" && content !== "") {
|
|
114
|
+
preview = await fitContent(content, budget, this.#tokenize);
|
|
115
|
+
}
|
|
116
|
+
return { mimetype, symbols, preview, ok: true };
|
|
117
|
+
}
|
|
118
|
+
async #resolveContent(input) {
|
|
119
|
+
if (input.content !== undefined)
|
|
120
|
+
return input.content;
|
|
121
|
+
if (input.path === undefined || input.path === "")
|
|
122
|
+
return null;
|
|
123
|
+
try {
|
|
124
|
+
return await fs.readFile(input.path, "utf-8");
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=Mimetypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mimetypes.js","sourceRoot":"","sources":["../src/Mimetypes.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAA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OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;QACzD,CAAC;QAED,kEAAkE;QAClE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE1B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;YACnC,OAAO,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,KAAmB;QACrC,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC;QACtD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QAC/D,IAAI,CAAC;YACD,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CompileOptions {
|
|
2
|
+
grammarDir?: string;
|
|
3
|
+
outDir?: string;
|
|
4
|
+
cwd?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function runCompile(opts?: CompileOptions): Promise<void>;
|
|
7
|
+
export declare function rewriteImports(dir: string): Promise<void>;
|
|
8
|
+
export declare function cli(argv: string[]): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAQD,wBAAsB,UAAU,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BzE;AA6BD,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB/D;AAED,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAavD"}
|