@plurnk/plurnk-contracts 1.4.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 +119 -0
- package/SPEC.md +954 -0
- package/bin/plurnk-contracts.js +43 -0
- package/dist/plurnk.gbnf +394 -0
- package/dist/schema/ClientDisplayCapabilities.json +54 -0
- package/dist/schema/ClientStatement.json +68 -0
- package/dist/schema/EntryReadResult.json +101 -0
- package/dist/schema/LineMarker.json +16 -0
- package/dist/schema/LoopFlags.json +16 -0
- package/dist/schema/MatcherBody.json +84 -0
- package/dist/schema/Notice.json +67 -0
- package/dist/schema/OperationResult.json +44 -0
- package/dist/schema/ParsedPath.json +64 -0
- package/dist/schema/PlurnkStatement.json +264 -0
- package/dist/schema/Position.json +20 -0
- package/dist/schema/ProblemDetails.json +51 -0
- package/dist/schema/ProposalDisposition.json +26 -0
- package/dist/schema/ProposalProjection.json +44 -0
- package/dist/schema/ProviderCost.json +69 -0
- package/dist/schema/ResourceSelection.json +20 -0
- package/dist/schema/SendBody.json +13 -0
- package/dist/schema/TextRegion.json +31 -0
- package/dist/src/AstBuilder.d.ts +24 -0
- package/dist/src/AstBuilder.d.ts.map +1 -0
- package/dist/src/AstBuilder.js +609 -0
- package/dist/src/AstBuilder.js.map +1 -0
- package/dist/src/PathSyntax.d.ts +9 -0
- package/dist/src/PathSyntax.d.ts.map +1 -0
- package/dist/src/PathSyntax.js +36 -0
- package/dist/src/PathSyntax.js.map +1 -0
- package/dist/src/PlurnkErrorStrategy.d.ts +10 -0
- package/dist/src/PlurnkErrorStrategy.d.ts.map +1 -0
- package/dist/src/PlurnkErrorStrategy.js +147 -0
- package/dist/src/PlurnkErrorStrategy.js.map +1 -0
- package/dist/src/PlurnkParseError.d.ts +17 -0
- package/dist/src/PlurnkParseError.d.ts.map +1 -0
- package/dist/src/PlurnkParseError.js +24 -0
- package/dist/src/PlurnkParseError.js.map +1 -0
- package/dist/src/PlurnkParser.d.ts +9 -0
- package/dist/src/PlurnkParser.d.ts.map +1 -0
- package/dist/src/PlurnkParser.js +396 -0
- package/dist/src/PlurnkParser.js.map +1 -0
- package/dist/src/Problems.d.ts +8 -0
- package/dist/src/Problems.d.ts.map +1 -0
- package/dist/src/Problems.js +23 -0
- package/dist/src/Problems.js.map +1 -0
- package/dist/src/RecordingListener.d.ts +9 -0
- package/dist/src/RecordingListener.d.ts.map +1 -0
- package/dist/src/RecordingListener.js +19 -0
- package/dist/src/RecordingListener.js.map +1 -0
- package/dist/src/Validator.d.ts +49 -0
- package/dist/src/Validator.d.ts.map +1 -0
- package/dist/src/Validator.js +211 -0
- package/dist/src/Validator.js.map +1 -0
- package/dist/src/generated/plurnkLexer.d.ts +129 -0
- package/dist/src/generated/plurnkLexer.d.ts.map +1 -0
- package/dist/src/generated/plurnkLexer.js +808 -0
- package/dist/src/generated/plurnkLexer.js.map +1 -0
- package/dist/src/generated/plurnkParser.d.ts +525 -0
- package/dist/src/generated/plurnkParser.d.ts.map +1 -0
- package/dist/src/generated/plurnkParser.js +3896 -0
- package/dist/src/generated/plurnkParser.js.map +1 -0
- package/dist/src/generated/plurnkParserVisitor.d.ts +298 -0
- package/dist/src/generated/plurnkParserVisitor.d.ts.map +1 -0
- package/dist/src/generated/plurnkParserVisitor.js +257 -0
- package/dist/src/generated/plurnkParserVisitor.js.map +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +29 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.generated.d.ts +450 -0
- package/dist/src/types.generated.d.ts.map +1 -0
- package/dist/src/types.generated.js +4 -0
- package/dist/src/types.generated.js.map +1 -0
- package/dist/src/types.js +23 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +87 -0
- package/plurnk.md +220 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { CharStream, CommonTokenStream } from "antlr4ng";
|
|
2
|
+
import { plurnkLexer } from "./generated/plurnkLexer.js";
|
|
3
|
+
import { plurnkParser } from "./generated/plurnkParser.js";
|
|
4
|
+
import AstBuilder from "./AstBuilder.js";
|
|
5
|
+
import PlurnkParseError from "./PlurnkParseError.js";
|
|
6
|
+
import PlurnkErrorStrategy from "./PlurnkErrorStrategy.js";
|
|
7
|
+
import RecordingListener from "./RecordingListener.js";
|
|
8
|
+
import { PLURNK_OPS } from "./types.js";
|
|
9
|
+
// Statement-bearing contexts the extraction builds into items. `statement` (statementSeq) and
|
|
10
|
+
// `midStatement` (mid-turn ops) each wrap one op; PLAN and the terminal SEND attach as direct
|
|
11
|
+
// `planStatement`/`sendStatement` children of a turn; `clientStatement` wraps one op in the
|
|
12
|
+
// client tier.
|
|
13
|
+
const STATEMENT_RULES = new Set([
|
|
14
|
+
plurnkParser.RULE_statement,
|
|
15
|
+
plurnkParser.RULE_midStatement,
|
|
16
|
+
plurnkParser.RULE_planStatement,
|
|
17
|
+
plurnkParser.RULE_sendStatement,
|
|
18
|
+
plurnkParser.RULE_clientStatement,
|
|
19
|
+
]);
|
|
20
|
+
// Container rules whose children hold the statements - extraction recurses through these.
|
|
21
|
+
// `turnStatement` is the `<<TURN…:…:TURN` wrapper (log); `turnContent` is the sandwich inside
|
|
22
|
+
// it (and document's single turn). Recursing both flattens a wrapped log to its ops in order.
|
|
23
|
+
const CONTAINER_RULES = new Set([
|
|
24
|
+
plurnkParser.RULE_turnContent,
|
|
25
|
+
plurnkParser.RULE_turnStatement,
|
|
26
|
+
]);
|
|
27
|
+
export default class PlurnkParser {
|
|
28
|
+
// Parse one PLAN-anchored model turn ending in a disposition SEND. Tolerated
|
|
29
|
+
// interstatement TEXT remains an ordered item without language semantics. {§turn-shape}
|
|
30
|
+
static parse(input) {
|
|
31
|
+
const result = PlurnkParser.#run(input, (parser) => parser.document());
|
|
32
|
+
// Value-adds layered on ANTLR's own diagnostics (we own syntax errors end to end):
|
|
33
|
+
// near-miss op advisories on swallowed prose, then turn-shape imperatives while the
|
|
34
|
+
// document boundary remains trustworthy. Neither changes what parsed.
|
|
35
|
+
PlurnkParser.#flagNearMissOps(result.items);
|
|
36
|
+
PlurnkParser.#flagOpsInPlanBody(result.items);
|
|
37
|
+
PlurnkParser.#flagMisplacedTarget(result.items);
|
|
38
|
+
if (result.unparsedTail === undefined) {
|
|
39
|
+
PlurnkParser.#imperativeTurnShape(result.items);
|
|
40
|
+
PlurnkParser.#imperativeMidTermination(result.items);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
// Terminal disposition alphabet. {§waitpid-dispositions} {§wait-obligation-matrix}
|
|
45
|
+
static #DISPOSITIONS = new Set([102, 200, 202, 300, 499]);
|
|
46
|
+
// Curated op-name confusions (semantic + dead-verb), NOT edit-distance - a full
|
|
47
|
+
// `<<Word…:Word` heredoc carrying one of these is unambiguously an intended op, so the
|
|
48
|
+
// false-positive rate is ~0. Bodies are never scanned (only DEFAULT-mode text items), so
|
|
49
|
+
// the model's legitimate suffixed/embedded code is immune by construction.
|
|
50
|
+
static #OP_CONFUSABLES = {
|
|
51
|
+
CLOSE: "`<<FOLD`", HIDE: "`<<FOLD`", COLLAPSE: "`<<FOLD`",
|
|
52
|
+
SHOW: "`<<OPEN`", EXPAND: "`<<OPEN`",
|
|
53
|
+
DELETE: "`<<KILL`", REMOVE: "`<<KILL`", DROP: "`<<KILL`",
|
|
54
|
+
GET: "`<<READ`", FETCH: "`<<READ`", CAT: "`<<READ`",
|
|
55
|
+
WRITE: "`<<EDIT`", CREATE: "`<<EDIT`", UPDATE: "`<<EDIT`", SET: "`<<EDIT`",
|
|
56
|
+
LIST: "`<<FIND`", SEARCH: "`<<FIND`", GREP: "`<<FIND`", QUERY: "`<<FIND`",
|
|
57
|
+
RUN: "`<<EXEC`", SHELL: "`<<EXEC`",
|
|
58
|
+
SPAWN: "`<<WORK(worker://name)` to spawn a worker", DELEGATE: "`<<WORK(worker://name)` to spawn a worker",
|
|
59
|
+
};
|
|
60
|
+
// Surface near-miss ops that the forgiving parser swallowed as prose: a `<<Word…:Word`
|
|
61
|
+
// heredoc whose keyword is a known confusion (`<<CLOSE`, `<<DELETE`, …). Emits a WARNING
|
|
62
|
+
// (never an error - the input parsed), so a silent swallow becomes a steer toward canon.
|
|
63
|
+
static #flagNearMissOps(items) {
|
|
64
|
+
const additions = [];
|
|
65
|
+
items.forEach((item, idx) => {
|
|
66
|
+
if (item.kind !== "text")
|
|
67
|
+
return;
|
|
68
|
+
const text = item.text;
|
|
69
|
+
const opener = /<<([A-Za-z]+)/g;
|
|
70
|
+
let m;
|
|
71
|
+
while ((m = opener.exec(text)) !== null) {
|
|
72
|
+
const suggestion = PlurnkParser.#OP_CONFUSABLES[m[1].toUpperCase()];
|
|
73
|
+
if (!suggestion)
|
|
74
|
+
continue;
|
|
75
|
+
// Op-shape gate: require a matching close `:Word` in the same run, so a bare
|
|
76
|
+
// prose mention without a heredoc close is never flagged.
|
|
77
|
+
if (!new RegExp(":" + m[1] + "\\b").test(text))
|
|
78
|
+
continue;
|
|
79
|
+
const position = PlurnkParser.#advancePosition(item.position, text.slice(0, m.index));
|
|
80
|
+
additions.push({
|
|
81
|
+
at: idx,
|
|
82
|
+
item: {
|
|
83
|
+
kind: "error",
|
|
84
|
+
error: new PlurnkParseError(position.line, position.column, "parser", `\`<<${m[1]}\` is not a Plurnk operation, so it was read as text; did you mean ${suggestion}?`, "warning"),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
// Insert each advisory right after its text item (reverse order keeps indices valid).
|
|
90
|
+
for (const { at, item } of additions.reverse())
|
|
91
|
+
items.splice(at + 1, 0, item);
|
|
92
|
+
}
|
|
93
|
+
// Replace ANTLR's generic structure errors with the turn-shape imperative when the
|
|
94
|
+
// PLAN-anchored sandwich is broken. PLAN-first takes precedence: with no PLAN we cannot
|
|
95
|
+
// judge the terminal SEND (it never reached statement position), so we only direct the
|
|
96
|
+
// model to the anchor; a present-PLAN, absent-SEND turn gets the terminator imperative.
|
|
97
|
+
static #imperativeTurnShape(items) {
|
|
98
|
+
const hasPlan = items.some((i) => i.kind === "statement" && i.statement.op === "PLAN");
|
|
99
|
+
// A mid-comms SEND does not satisfy the terminal requirement.
|
|
100
|
+
const hasSend = items.some((i) => i.kind === "statement" && i.statement.op === "SEND" && PlurnkParser.#DISPOSITIONS.has(i.statement.signal));
|
|
101
|
+
if (hasPlan && hasSend)
|
|
102
|
+
return;
|
|
103
|
+
const isStructErr = (i) => i.kind === "error" && i.error.source === "parser" && i.error.severity === "error";
|
|
104
|
+
const structErrors = items.filter(isStructErr);
|
|
105
|
+
if (structErrors.length === 0)
|
|
106
|
+
return;
|
|
107
|
+
const anchor = structErrors[0].error;
|
|
108
|
+
// Drop the generic parser structure errors (downstream noise from the broken shape);
|
|
109
|
+
// keep statements, text, near-miss warnings, and lexer/visitor errors.
|
|
110
|
+
const kept = items.filter((i) => !isStructErr(i));
|
|
111
|
+
items.length = 0;
|
|
112
|
+
items.push(...kept);
|
|
113
|
+
// Only add the anchor imperative when the shape is CLEANLY incomplete. If a bounded lexer
|
|
114
|
+
// or visitor error is present, the turn derailed within an operation, so the
|
|
115
|
+
// missing PLAN/SEND is a parse artifact, not the real fix - that specific bounded error
|
|
116
|
+
// is the actionable guidance, and an imperative would mislead.
|
|
117
|
+
const hasSpecificError = items.some((i) => i.kind === "error" && i.error.severity === "error" && i.error.source !== "parser");
|
|
118
|
+
if (hasSpecificError)
|
|
119
|
+
return;
|
|
120
|
+
const fix = !hasPlan
|
|
121
|
+
? "a turn must begin with `<<PLAN:…:PLAN` (the required first operation)"
|
|
122
|
+
: "a turn must end with a terminal `<<SEND[code]:…:SEND`";
|
|
123
|
+
items.push({ kind: "error", error: new PlurnkParseError(anchor.line, anchor.column, "parser", fix) });
|
|
124
|
+
}
|
|
125
|
+
// Lift the mid-turn-termination error. A disposition-coded SEND
|
|
126
|
+
// (102/200/202/300/499) ends the turn, so a following operation is an error.
|
|
127
|
+
// Rewrite ANTLR's generic structure message to that rule. {§send-mid-reservation}
|
|
128
|
+
// Runs after the begin/end imperative (which handles the incomplete-shape case and, for a
|
|
129
|
+
// complete-but-trailing turn, returns early leaving this error in place to rewrite).
|
|
130
|
+
static #imperativeMidTermination(items) {
|
|
131
|
+
// If a bounded lexer/visitor error derailed the turn, any recovered disposition SEND is
|
|
132
|
+
// suspect; don't mislabel its fallout as a mid-termination. Boundary loss never reaches
|
|
133
|
+
// this pass. Mirrors #imperativeTurnShape's guard.
|
|
134
|
+
if (items.some((i) => i.kind === "error" && i.error.severity === "error" && i.error.source !== "parser"))
|
|
135
|
+
return;
|
|
136
|
+
const terminal = items.find((i) => i.kind === "statement" && i.statement.op === "SEND" && PlurnkParser.#DISPOSITIONS.has(i.statement.signal));
|
|
137
|
+
if (!terminal)
|
|
138
|
+
return;
|
|
139
|
+
const t = terminal.statement.position;
|
|
140
|
+
for (const i of items) {
|
|
141
|
+
if (i.kind !== "error" || i.error.source !== "parser" || i.error.severity !== "error")
|
|
142
|
+
continue;
|
|
143
|
+
const after = i.error.line > t.line || (i.error.line === t.line && i.error.column > t.column);
|
|
144
|
+
if (!after)
|
|
145
|
+
continue;
|
|
146
|
+
i.error = new PlurnkParseError(i.error.line, i.error.column, "parser", "a disposition SEND ends the turn - nothing may follow it");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Collapse a lexer per-character cascade: the SIGNAL/TARGET modes emit one 'unrecognized
|
|
150
|
+
// character' error PER bad char, so a single malformed `[signal]` floods 10+ near-identical
|
|
151
|
+
// rows. Keep the first of each consecutive same-context run (adjacent columns, same mode
|
|
152
|
+
// context) - the model needs one steer to the fix, not a per-character wall. Mutates in place.
|
|
153
|
+
static #dedupeLexerCascade(errors) {
|
|
154
|
+
for (let i = errors.length - 1; i >= 1; i--) {
|
|
155
|
+
const cur = errors[i];
|
|
156
|
+
const prev = errors[i - 1];
|
|
157
|
+
if (cur.source !== "lexer" || prev.source !== "lexer")
|
|
158
|
+
continue;
|
|
159
|
+
if (cur.line !== prev.line || cur.column !== prev.column + 1)
|
|
160
|
+
continue;
|
|
161
|
+
if (PlurnkParser.#lexerContext(cur.message) !== PlurnkParser.#lexerContext(prev.message))
|
|
162
|
+
continue;
|
|
163
|
+
errors.splice(i, 1);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// The mode-context tail of a lexer message (the part after `unrecognized character <ch> `),
|
|
167
|
+
// e.g. `in signal - expected integer for SEND/KILL, then \`]\``. Two adjacent chars sharing
|
|
168
|
+
// it belong to the same cascade.
|
|
169
|
+
static #lexerContext(message) {
|
|
170
|
+
const m = /unrecognized character (?:'[^']*'|end of input) (.+)$/.exec(message);
|
|
171
|
+
return m ? m[1] : message;
|
|
172
|
+
}
|
|
173
|
+
// Parse a bare sequence of statements - teaching-example collections, single ops,
|
|
174
|
+
// documentation snippets. Strict: statements only (whitespace is hidden), no prose,
|
|
175
|
+
// no turn shape. Not for model output; use `parse` for that.
|
|
176
|
+
static parseStatements(input) {
|
|
177
|
+
return PlurnkParser.#run(input, (parser) => parser.statementSeq());
|
|
178
|
+
}
|
|
179
|
+
// Parse a multi-turn LOG - a saved sequence of turns, each a full PLAN-anchored sandwich.
|
|
180
|
+
// Items are flat across turns, in source order; turn
|
|
181
|
+
// boundaries are recoverable from the terminal SENDs. A log is valid (no error items, no
|
|
182
|
+
// unparsedTail) iff every turn in it is a valid turn.
|
|
183
|
+
static parseLog(input) {
|
|
184
|
+
return PlurnkParser.#run(input, (parser) => parser.log());
|
|
185
|
+
}
|
|
186
|
+
// Parse the CLIENT tier - a bare sequence of protocol statements plus the client-only utility
|
|
187
|
+
// ops LOOK and BUFF. The topmost subset (one above Script); never used for model output. The
|
|
188
|
+
// protocol entry points reject LOOK/BUFF, so a client op only parses here.
|
|
189
|
+
static parseClient(input) {
|
|
190
|
+
return PlurnkParser.#run(input, (parser) => parser.clientStatementSeq(), (ctx) => AstBuilder.buildClient(ctx));
|
|
191
|
+
}
|
|
192
|
+
static #run(input, parseFn, buildFn = ((ctx) => AstBuilder.build(ctx))) {
|
|
193
|
+
const lexer = new plurnkLexer(CharStream.fromString(input));
|
|
194
|
+
const errors = [];
|
|
195
|
+
lexer.removeErrorListeners();
|
|
196
|
+
lexer.addErrorListener(new RecordingListener("lexer", errors));
|
|
197
|
+
const tokenStream = new CommonTokenStream(lexer);
|
|
198
|
+
const parser = new plurnkParser(tokenStream);
|
|
199
|
+
parser.removeErrorListeners();
|
|
200
|
+
parser.addErrorListener(new RecordingListener("parser", errors));
|
|
201
|
+
parser.errorHandler = new PlurnkErrorStrategy();
|
|
202
|
+
const tree = parseFn(parser);
|
|
203
|
+
PlurnkParser.#dedupeLexerCascade(errors);
|
|
204
|
+
const unparsedTail = PlurnkParser.#unparsedTail(lexer, input);
|
|
205
|
+
const items = [];
|
|
206
|
+
const consumedErrors = new Set();
|
|
207
|
+
PlurnkParser.#collect(tree, errors, consumedErrors, items, buildFn, unparsedTail?.from);
|
|
208
|
+
for (const err of errors) {
|
|
209
|
+
if (!consumedErrors.has(err)
|
|
210
|
+
&& (unparsedTail === undefined || PlurnkParser.#isBefore(err, unparsedTail.from))) {
|
|
211
|
+
items.push({ kind: "error", error: err });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { items, unparsedTail };
|
|
215
|
+
}
|
|
216
|
+
// Determine the public trust boundary before visiting recovered contexts. The parser may
|
|
217
|
+
// synthesize tree nodes after an unfinished lexer mode, but those nodes have no public AST
|
|
218
|
+
// meaning and can violate AstBuilder's complete-statement precondition. {§unparsed-tail-boundary}
|
|
219
|
+
static #unparsedTail(lexer, input) {
|
|
220
|
+
if (lexer.mode === 0)
|
|
221
|
+
return undefined;
|
|
222
|
+
const openTag = lexer.getOpenTag();
|
|
223
|
+
const from = { line: lexer.getOpenTagLine(), column: lexer.getOpenTagColumn() };
|
|
224
|
+
const modeName = lexer.modeNames[lexer.mode] ?? "";
|
|
225
|
+
const reason = modeName === "BODY"
|
|
226
|
+
? `body of \`<<${openTag}\` opened at line ${from.line} but never closed - add \`:${openTag}\` to terminate${PlurnkParser.#inventedCloser(input, lexer.getBodyStart(), openTag)}`
|
|
227
|
+
: modeName === "SIGNAL_TAGS" || modeName === "SIGNAL_INT" || modeName === "SIGNAL_IDENT"
|
|
228
|
+
? `signal slot of \`<<${openTag}\` opened at line ${from.line} but never closed - add \`]\` to terminate the signal`
|
|
229
|
+
: modeName === "TARGET"
|
|
230
|
+
? `target slot of \`<<${openTag}\` opened at line ${from.line} but never closed - add \`)\` to terminate the target`
|
|
231
|
+
: `statement \`<<${openTag}\` opened at line ${from.line} but never reached its close tag - add \`:${openTag}\` to terminate`;
|
|
232
|
+
return { from, reason };
|
|
233
|
+
}
|
|
234
|
+
// Warn when an unsuffixed PLAN body contains op-shaped text; a suffix deliberately
|
|
235
|
+
// invokes the universal quoting contract. {§plan-body-op-advisory}
|
|
236
|
+
static #flagOpsInPlanBody(items) {
|
|
237
|
+
const additions = [];
|
|
238
|
+
const opener = new RegExp(`<<(${PLURNK_OPS.join("|")})\\b`);
|
|
239
|
+
items.forEach((item, idx) => {
|
|
240
|
+
if (item.kind !== "statement" || item.statement.op !== "PLAN")
|
|
241
|
+
return;
|
|
242
|
+
if (item.statement.suffix.length > 0)
|
|
243
|
+
return;
|
|
244
|
+
const body = item.statement.body ?? "";
|
|
245
|
+
const m = opener.exec(body);
|
|
246
|
+
if (!m)
|
|
247
|
+
return;
|
|
248
|
+
additions.push({
|
|
249
|
+
at: idx,
|
|
250
|
+
item: {
|
|
251
|
+
kind: "error",
|
|
252
|
+
error: new PlurnkParseError(item.statement.position.line, item.statement.position.column, "parser", `PLAN body contains op-shaped text (\`<<${m[1]}\`) - ops belong after the plan closes; did you omit \`:PLAN\`?`, "warning"),
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
for (const { at, item } of additions.reverse())
|
|
257
|
+
items.splice(at + 1, 0, item);
|
|
258
|
+
}
|
|
259
|
+
// Mutating ops that require a `(target)` and carry a `[tags]` string-array signal. A null target
|
|
260
|
+
// on one of these is unambiguously wrong - there is nothing to edit/copy/move.
|
|
261
|
+
static #MUTATING_OPS = new Set(["EDIT", "COPY", "MOVE"]);
|
|
262
|
+
// A null mutation target plus a path-shaped tag is the narrow advisory gate; an
|
|
263
|
+
// ordinary tags-only omission is not redirected. {§misplaced-target-advisory}
|
|
264
|
+
static #flagMisplacedTarget(items) {
|
|
265
|
+
const pathShaped = (s) => s.includes("/") || /[^/]\.[a-zA-Z][a-zA-Z0-9]*$/.test(s);
|
|
266
|
+
const additions = [];
|
|
267
|
+
items.forEach((item, idx) => {
|
|
268
|
+
if (item.kind !== "statement")
|
|
269
|
+
return;
|
|
270
|
+
const st = item.statement;
|
|
271
|
+
if (!PlurnkParser.#MUTATING_OPS.has(st.op) || st.target !== null)
|
|
272
|
+
return;
|
|
273
|
+
if (!Array.isArray(st.signal))
|
|
274
|
+
return;
|
|
275
|
+
const path = st.signal.find(pathShaped);
|
|
276
|
+
if (!path)
|
|
277
|
+
return;
|
|
278
|
+
additions.push({
|
|
279
|
+
at: idx,
|
|
280
|
+
item: {
|
|
281
|
+
kind: "error",
|
|
282
|
+
error: new PlurnkParseError(st.position.line, st.position.column, "parser", `\`<<${st.op}\` has no \`(target)\` - that path sits in the \`[…]\` tag slot; a target goes in \`(…)\`. Try \`${st.op}(${path}):…\``, "warning"),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
for (const { at, item } of additions.reverse())
|
|
287
|
+
items.splice(at + 1, 0, item);
|
|
288
|
+
}
|
|
289
|
+
// Name an ALLCAPS close lookalike only inside a never-closed body; healthy
|
|
290
|
+
// bodies are never scanned by this path. {§invented-closer-advisory}
|
|
291
|
+
static #inventedCloser(input, bodyStart, openTag) {
|
|
292
|
+
const offset = PlurnkParser.#offsetAtPosition(input, bodyStart);
|
|
293
|
+
const body = input.slice(offset);
|
|
294
|
+
const m = /:([A-Z][A-Z0-9_]{2,})\b/.exec(body);
|
|
295
|
+
if (!m || m[1] === openTag.toUpperCase())
|
|
296
|
+
return "";
|
|
297
|
+
return ` (found \`:${m[1]}\`, which is body text - the closer echoes the op's name)`;
|
|
298
|
+
}
|
|
299
|
+
// JavaScript offsets count UTF-16 code units; parser source points count Unicode code
|
|
300
|
+
// points and advance only at LF. Keep that translation inside the parser. {§parser-position}
|
|
301
|
+
static #advancePosition(from, text) {
|
|
302
|
+
let { line, column } = from;
|
|
303
|
+
for (const character of text) {
|
|
304
|
+
if (character === "\n") {
|
|
305
|
+
line++;
|
|
306
|
+
column = 0;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
column++;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return { line, column };
|
|
313
|
+
}
|
|
314
|
+
static #offsetAtPosition(input, target) {
|
|
315
|
+
if (target.line < 1 || target.column < 0) {
|
|
316
|
+
throw new RangeError(`cannot resolve degraded parser position ${target.line}:${target.column}`);
|
|
317
|
+
}
|
|
318
|
+
let position = { line: 1, column: 0 };
|
|
319
|
+
let offset = 0;
|
|
320
|
+
for (const character of input) {
|
|
321
|
+
if (position.line === target.line && position.column === target.column)
|
|
322
|
+
return offset;
|
|
323
|
+
position = PlurnkParser.#advancePosition(position, character);
|
|
324
|
+
offset += character.length;
|
|
325
|
+
}
|
|
326
|
+
if (position.line === target.line && position.column === target.column)
|
|
327
|
+
return offset;
|
|
328
|
+
throw new RangeError(`parser position ${target.line}:${target.column} is outside its source`);
|
|
329
|
+
}
|
|
330
|
+
// Walk a parse tree, appending statement/error/text items in source order. Statement rules
|
|
331
|
+
// are leaves (built directly); container rules (turnContent) are recursed into; TEXT tokens
|
|
332
|
+
// surface as text items. So `document` (one turnContent) and `log` (turnContent+) both
|
|
333
|
+
// flatten to items in order, while a bounded malformed statement surfaces as an error item.
|
|
334
|
+
static #collect(ctx, errors, consumedErrors, items, buildFn, boundary) {
|
|
335
|
+
for (const child of ctx.children ?? []) {
|
|
336
|
+
const c = child;
|
|
337
|
+
const start = c.start ?? c.symbol;
|
|
338
|
+
const stop = c.stop ?? c.symbol;
|
|
339
|
+
if (!start)
|
|
340
|
+
continue;
|
|
341
|
+
if (boundary !== undefined && !PlurnkParser.#isBefore(start, boundary))
|
|
342
|
+
continue;
|
|
343
|
+
if (c.ruleIndex !== undefined && STATEMENT_RULES.has(c.ruleIndex)) {
|
|
344
|
+
const errorsForStatement = errors.filter((e) => !consumedErrors.has(e) && PlurnkParser.#errorInRange(e, start, stop ?? start));
|
|
345
|
+
const errForStatement = errorsForStatement[0];
|
|
346
|
+
if (errForStatement) {
|
|
347
|
+
// One malformed statement projects one hard diagnostic. {§error-shape}
|
|
348
|
+
for (const error of errorsForStatement)
|
|
349
|
+
consumedErrors.add(error);
|
|
350
|
+
items.push({ kind: "error", error: errForStatement });
|
|
351
|
+
}
|
|
352
|
+
else if ((c.getChildCount?.() ?? 0) === 0) {
|
|
353
|
+
// A phantom statement context synthesized during error recovery (e.g. a
|
|
354
|
+
// PLAN slot the parser opened then failed to fill on bare text): zero tokens
|
|
355
|
+
// matched, so its OPEN terminal is null and building it would null-deref.
|
|
356
|
+
// The real failure is already recorded; skip the zero-token recovery node.
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
try {
|
|
360
|
+
items.push({ kind: "statement", statement: buildFn(c) });
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
// A genuine visitor contract violation (e.g. a malformed URI) is a
|
|
364
|
+
// PlurnkParseError - surface it as an error item. Anything else is an
|
|
365
|
+
// internal bug, not a parse error: let it crash rather than masquerade
|
|
366
|
+
// as a model-facing parse-error item.
|
|
367
|
+
if (!(e instanceof PlurnkParseError))
|
|
368
|
+
throw e;
|
|
369
|
+
items.push({ kind: "error", error: e });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else if (c.ruleIndex !== undefined && CONTAINER_RULES.has(c.ruleIndex)) {
|
|
374
|
+
PlurnkParser.#collect(c, errors, consumedErrors, items, buildFn, boundary);
|
|
375
|
+
}
|
|
376
|
+
else if (c.symbol?.type === plurnkLexer.TEXT) {
|
|
377
|
+
const position = { line: start.line, column: start.column };
|
|
378
|
+
items.push({ kind: "text", text: c.symbol.text ?? "", position });
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
static #isBefore(point, boundary) {
|
|
383
|
+
return point.line < boundary.line
|
|
384
|
+
|| (point.line === boundary.line && point.column < boundary.column);
|
|
385
|
+
}
|
|
386
|
+
static #errorInRange(err, start, stop) {
|
|
387
|
+
if (err.line < start.line || err.line > stop.line)
|
|
388
|
+
return false;
|
|
389
|
+
if (err.line === start.line && err.column < start.column)
|
|
390
|
+
return false;
|
|
391
|
+
if (err.line === stop.line && err.column > stop.column)
|
|
392
|
+
return false;
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
//# sourceMappingURL=PlurnkParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlurnkParser.js","sourceRoot":"","sources":["../../src/PlurnkParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAA0B,MAAM,UAAU,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,YAAY,EAA+B,MAAM,6BAA6B,CAAC;AACxF,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,8FAA8F;AAC9F,8FAA8F;AAC9F,4FAA4F;AAC5F,eAAe;AACf,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS;IACpC,YA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,GAAa,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;gBACtE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;YACtE,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAuC,EAAE,QAAkB;QACxE,OAAO,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI;eAC1B,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,CAAC,aAAa,CAChB,GAAqB,EACrB,KAAuC,EACvC,IAAsC;QAEtC,IAAI,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAChE,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACvE,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACrE,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProblemDetails } from "./types.generated.ts";
|
|
2
|
+
export interface ProblemOptions {
|
|
3
|
+
readonly title?: string;
|
|
4
|
+
}
|
|
5
|
+
export default class Problems {
|
|
6
|
+
static create(owner: string, code: string, status: number, detail: string, extensions?: Readonly<Record<string, unknown>>, options?: ProblemOptions): ProblemDetails;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=Problems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Problems.d.ts","sourceRoot":"","sources":["../../src/Problems.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,MAAM,CAAC,MAAM,CACT,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,UAAU,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,EAClD,OAAO,GAAE,cAAmB,GAC7B,cAAc,CAehB;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Validator from "./Validator.js";
|
|
2
|
+
const TYPE_ROOT = "https://problems.plurnk.dev";
|
|
3
|
+
const OWNER = /^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)*$/;
|
|
4
|
+
const CODE = /^[a-z][a-z0-9-]*$/;
|
|
5
|
+
export default class Problems {
|
|
6
|
+
static create(owner, code, status, detail, extensions = {}, options = {}) {
|
|
7
|
+
if (!OWNER.test(owner)) {
|
|
8
|
+
throw new Error(`problem owner must be a colon-delimited lowercase identifier; got ${JSON.stringify(owner)}`);
|
|
9
|
+
}
|
|
10
|
+
if (!CODE.test(code)) {
|
|
11
|
+
throw new Error(`problem code must be a lowercase kebab-case identifier; got ${JSON.stringify(code)}`);
|
|
12
|
+
}
|
|
13
|
+
const title = options.title ?? code.charAt(0).toUpperCase() + code.slice(1).replaceAll("-", " ");
|
|
14
|
+
return Validator.assertProblemDetails({
|
|
15
|
+
...extensions,
|
|
16
|
+
type: `${TYPE_ROOT}/${owner.replaceAll(":", "/")}/${code}`,
|
|
17
|
+
title,
|
|
18
|
+
status,
|
|
19
|
+
detail,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=Problems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Problems.js","sourceRoot":"","sources":["../../src/Problems.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,MAAM,SAAS,GAAG,6BAA6B,CAAC;AAChD,MAAM,KAAK,GAAG,wCAAwC,CAAC;AACvD,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAMjC,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,MAAM,CAAC,MAAM,CACT,KAAa,EACb,IAAY,EACZ,MAAc,EACd,MAAc,EACd,UAAU,GAAsC,EAAE,EAClD,OAAO,GAAmB,EAAE;QAE5B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,qEAAqE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,+DAA+D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3G,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjG,OAAO,SAAS,CAAC,oBAAoB,CAAC;YAClC,GAAG,UAAU;YACb,IAAI,EAAE,GAAG,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;YAC1D,KAAK;YACL,MAAM;YACN,MAAM;SACT,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseErrorListener, type RecognitionException, type Recognizer, type Token } from "antlr4ng";
|
|
2
|
+
import PlurnkParseError from "./PlurnkParseError.ts";
|
|
3
|
+
export default class RecordingListener extends BaseErrorListener {
|
|
4
|
+
readonly errors: PlurnkParseError[];
|
|
5
|
+
readonly source: "lexer" | "parser";
|
|
6
|
+
constructor(source: "lexer" | "parser", errors: PlurnkParseError[]);
|
|
7
|
+
syntaxError(recognizer: Recognizer<any>, _offendingSymbol: Token | null, line: number, column: number, msg: string, _e: RecognitionException | null): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=RecordingListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecordingListener.d.ts","sourceRoot":"","sources":["../../src/RecordingListener.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,KAAK,EACb,MAAM,UAAU,CAAC;AAElB,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AAGrD,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,iBAAiB;IAC5D,QAAQ,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;IAEpC,YAAY,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAIjE;IAEQ,WAAW,CAChB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAC3B,gBAAgB,EAAE,KAAK,GAAG,IAAI,EAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,oBAAoB,GAAG,IAAI,GAChC,IAAI,CAKN;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseErrorListener, } from "antlr4ng";
|
|
2
|
+
import PlurnkParseError from "./PlurnkParseError.js";
|
|
3
|
+
import PlurnkErrorStrategy from "./PlurnkErrorStrategy.js";
|
|
4
|
+
export default class RecordingListener extends BaseErrorListener {
|
|
5
|
+
errors;
|
|
6
|
+
source;
|
|
7
|
+
constructor(source, errors) {
|
|
8
|
+
super();
|
|
9
|
+
this.source = source;
|
|
10
|
+
this.errors = errors;
|
|
11
|
+
}
|
|
12
|
+
syntaxError(recognizer, _offendingSymbol, line, column, msg, _e) {
|
|
13
|
+
const translated = this.source === "lexer"
|
|
14
|
+
? PlurnkErrorStrategy.translateLexerMessage(recognizer, msg)
|
|
15
|
+
: msg;
|
|
16
|
+
this.errors.push(new PlurnkParseError(line, column, this.source, translated));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=RecordingListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecordingListener.js","sourceRoot":"","sources":["../../src/RecordingListener.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,GAIpB,MAAM,UAAU,CAAC;AAElB,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,iBAAiB;IACnD,MAAM,CAAqB;IAC3B,MAAM,CAAqB;IAEpC,YAAY,MAA0B,EAAE,MAA0B;QAC9D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAEQ,WAAW,CAChB,UAA2B,EAC3B,gBAA8B,EAC9B,IAAY,EACZ,MAAc,EACd,GAAW,EACX,EAA+B;QAE/B,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,KAAK,OAAO;YACtC,CAAC,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,UAAyB,EAAE,GAAG,CAAC;YAC3E,CAAC,CAAC,GAAG,CAAC;QACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAClF,CAAC;CACJ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type OutputUnit } from "@cfworker/json-schema";
|
|
2
|
+
import type { ClientDisplayCapabilities, EntryReadResult, LoopFlags, Notice, OperationResult, ProblemDetails, ProposalProjection, TextRegion } from "./types.generated.ts";
|
|
3
|
+
export type ValidationResult = {
|
|
4
|
+
valid: boolean;
|
|
5
|
+
errors: OutputUnit[];
|
|
6
|
+
};
|
|
7
|
+
export declare class InvalidNoticeError extends TypeError {
|
|
8
|
+
}
|
|
9
|
+
export declare class InvalidProblemDetailsError extends TypeError {
|
|
10
|
+
}
|
|
11
|
+
export declare class InvalidOperationResultError extends TypeError {
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidEntryReadResultError extends TypeError {
|
|
14
|
+
}
|
|
15
|
+
export declare class InvalidTextRegionError extends TypeError {
|
|
16
|
+
}
|
|
17
|
+
export declare class InvalidLoopFlagsError extends TypeError {
|
|
18
|
+
}
|
|
19
|
+
export declare class InvalidProposalProjectionError extends TypeError {
|
|
20
|
+
}
|
|
21
|
+
export declare class InvalidClientDisplayCapabilitiesError extends TypeError {
|
|
22
|
+
}
|
|
23
|
+
export default class Validator {
|
|
24
|
+
#private;
|
|
25
|
+
static validatePosition(value: unknown): ValidationResult;
|
|
26
|
+
static validateLineMarker(value: unknown): ValidationResult;
|
|
27
|
+
static validateParsedPath(value: unknown): ValidationResult;
|
|
28
|
+
static validateMatcherBody(value: unknown): ValidationResult;
|
|
29
|
+
static validateSendBody(value: unknown): ValidationResult;
|
|
30
|
+
static validatePlurnkStatement(value: unknown): ValidationResult;
|
|
31
|
+
static validateClientStatement(value: unknown): ValidationResult;
|
|
32
|
+
static validateNotice(value: unknown): ValidationResult;
|
|
33
|
+
static validateProblemDetails(value: unknown): ValidationResult;
|
|
34
|
+
static validateOperationResult(value: unknown): ValidationResult;
|
|
35
|
+
static validateEntryReadResult(value: unknown): ValidationResult;
|
|
36
|
+
static validateTextRegion(value: unknown): ValidationResult;
|
|
37
|
+
static validateLoopFlags(value: unknown): ValidationResult;
|
|
38
|
+
static validateProposalProjection(value: unknown): ValidationResult;
|
|
39
|
+
static validateClientDisplayCapabilities(value: unknown): ValidationResult;
|
|
40
|
+
static assertNotice<T extends Notice>(value: T): T;
|
|
41
|
+
static assertProblemDetails<T extends ProblemDetails>(value: T): T;
|
|
42
|
+
static assertOperationResult<T extends OperationResult>(value: T): T;
|
|
43
|
+
static assertEntryReadResult<T extends EntryReadResult>(value: T): T;
|
|
44
|
+
static assertTextRegion<T extends TextRegion>(value: T): T;
|
|
45
|
+
static assertLoopFlags<T extends LoopFlags>(value: T): T;
|
|
46
|
+
static assertProposalProjection<T extends ProposalProjection>(value: T): T;
|
|
47
|
+
static assertClientDisplayCapabilities<T extends ClientDisplayCapabilities>(value: T): T;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../src/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAe,MAAM,uBAAuB,CAAC;AAkB/F,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE3K,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAExE,qBAAa,kBAAmB,SAAQ,SA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