@bcts/envelope-pattern 1.0.0-alpha.16 → 1.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +485 -485
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -29
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +93 -29
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +485 -485
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +504 -504
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/format.ts +9 -9
- package/src/parse/token.ts +55 -55
- package/src/pattern/leaf/array-pattern.ts +25 -25
- package/src/pattern/leaf/bool-pattern.ts +11 -11
- package/src/pattern/leaf/byte-string-pattern.ts +14 -14
- package/src/pattern/leaf/cbor-pattern.ts +29 -29
- package/src/pattern/leaf/date-pattern.ts +8 -8
- package/src/pattern/leaf/known-value-pattern.ts +17 -17
- package/src/pattern/leaf/map-pattern.ts +13 -13
- package/src/pattern/leaf/null-pattern.ts +7 -7
- package/src/pattern/leaf/number-pattern.ts +19 -19
- package/src/pattern/leaf/tagged-pattern.ts +20 -20
- package/src/pattern/leaf/text-pattern.ts +13 -13
- package/src/pattern/meta/and-pattern.ts +11 -11
- package/src/pattern/meta/capture-pattern.ts +14 -14
- package/src/pattern/meta/group-pattern.ts +13 -13
- package/src/pattern/meta/not-pattern.ts +7 -7
- package/src/pattern/meta/or-pattern.ts +15 -15
- package/src/pattern/meta/search-pattern.ts +15 -15
- package/src/pattern/meta/traverse-pattern.ts +15 -15
- package/src/pattern/structure/assertions-pattern.ts +28 -28
- package/src/pattern/structure/digest-pattern.ts +23 -23
- package/src/pattern/structure/node-pattern.ts +17 -17
- package/src/pattern/structure/object-pattern.ts +13 -13
- package/src/pattern/structure/obscured-pattern.ts +7 -7
- package/src/pattern/structure/predicate-pattern.ts +13 -13
- package/src/pattern/structure/subject-pattern.ts +15 -15
- package/src/pattern/structure/wrapped-pattern.ts +15 -15
|
@@ -39,10 +39,10 @@ export function registerByteStringPatternFactory(
|
|
|
39
39
|
* Corresponds to the Rust `ByteStringPattern` struct in byte_string_pattern.rs
|
|
40
40
|
*/
|
|
41
41
|
export class ByteStringPattern implements Matcher {
|
|
42
|
-
readonly
|
|
42
|
+
private readonly _inner: DCBORByteStringPattern;
|
|
43
43
|
|
|
44
44
|
private constructor(inner: DCBORByteStringPattern) {
|
|
45
|
-
this
|
|
45
|
+
this._inner = inner;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -77,7 +77,7 @@ export class ByteStringPattern implements Matcher {
|
|
|
77
77
|
* Gets the underlying dcbor-pattern ByteStringPattern.
|
|
78
78
|
*/
|
|
79
79
|
get inner(): DCBORByteStringPattern {
|
|
80
|
-
return this
|
|
80
|
+
return this._inner;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
@@ -85,7 +85,7 @@ export class ByteStringPattern implements Matcher {
|
|
|
85
85
|
const cbor = haystack.asLeaf();
|
|
86
86
|
if (cbor !== undefined) {
|
|
87
87
|
// Delegate to dcbor-pattern for CBOR matching
|
|
88
|
-
const dcborPaths = dcborByteStringPatternPaths(this
|
|
88
|
+
const dcborPaths = dcborByteStringPatternPaths(this._inner, cbor);
|
|
89
89
|
|
|
90
90
|
// For simple leaf patterns, if dcbor-pattern found matches, return the envelope
|
|
91
91
|
if (dcborPaths.length > 0) {
|
|
@@ -117,22 +117,22 @@ export class ByteStringPattern implements Matcher {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
toString(): string {
|
|
120
|
-
return byteStringPatternDisplay(this
|
|
120
|
+
return byteStringPatternDisplay(this._inner);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* Equality comparison.
|
|
125
125
|
*/
|
|
126
126
|
equals(other: ByteStringPattern): boolean {
|
|
127
|
-
if (this
|
|
127
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
-
switch (this
|
|
130
|
+
switch (this._inner.variant) {
|
|
131
131
|
case "Any":
|
|
132
132
|
return true;
|
|
133
133
|
case "Value": {
|
|
134
|
-
const a = (this
|
|
135
|
-
const b = (other
|
|
134
|
+
const a = (this._inner as { value: Uint8Array }).value;
|
|
135
|
+
const b = (other._inner as { value: Uint8Array }).value;
|
|
136
136
|
if (a.length !== b.length) return false;
|
|
137
137
|
for (let i = 0; i < a.length; i++) {
|
|
138
138
|
if (a[i] !== b[i]) return false;
|
|
@@ -141,8 +141,8 @@ export class ByteStringPattern implements Matcher {
|
|
|
141
141
|
}
|
|
142
142
|
case "BinaryRegex":
|
|
143
143
|
return (
|
|
144
|
-
(this
|
|
145
|
-
(other
|
|
144
|
+
(this._inner as { pattern: RegExp }).pattern.source ===
|
|
145
|
+
(other._inner as { pattern: RegExp }).pattern.source
|
|
146
146
|
);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -152,19 +152,19 @@ export class ByteStringPattern implements Matcher {
|
|
|
152
152
|
*/
|
|
153
153
|
hashCode(): number {
|
|
154
154
|
let hash = 0;
|
|
155
|
-
switch (this
|
|
155
|
+
switch (this._inner.variant) {
|
|
156
156
|
case "Any":
|
|
157
157
|
hash = 1;
|
|
158
158
|
break;
|
|
159
159
|
case "Value": {
|
|
160
|
-
const val = (this
|
|
160
|
+
const val = (this._inner as { value: Uint8Array }).value;
|
|
161
161
|
for (const byte of val) {
|
|
162
162
|
hash = hash * 31 + byte;
|
|
163
163
|
}
|
|
164
164
|
break;
|
|
165
165
|
}
|
|
166
166
|
case "BinaryRegex":
|
|
167
|
-
hash = 3 * 31 + (this
|
|
167
|
+
hash = 3 * 31 + (this._inner as { pattern: RegExp }).pattern.source.length;
|
|
168
168
|
break;
|
|
169
169
|
}
|
|
170
170
|
return hash;
|
|
@@ -43,10 +43,10 @@ export type CBORPatternType =
|
|
|
43
43
|
* Corresponds to the Rust `CBORPattern` enum in cbor_pattern.rs
|
|
44
44
|
*/
|
|
45
45
|
export class CBORPattern implements Matcher {
|
|
46
|
-
readonly
|
|
46
|
+
private readonly _pattern: CBORPatternType;
|
|
47
47
|
|
|
48
48
|
private constructor(pattern: CBORPatternType) {
|
|
49
|
-
this
|
|
49
|
+
this._pattern = pattern;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -81,13 +81,13 @@ export class CBORPattern implements Matcher {
|
|
|
81
81
|
* Gets the pattern type.
|
|
82
82
|
*/
|
|
83
83
|
get pattern(): CBORPatternType {
|
|
84
|
-
return this
|
|
84
|
+
return this._pattern;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Convert dcbor captures to envelope captures.
|
|
89
89
|
*/
|
|
90
|
-
|
|
90
|
+
private _convertDcborCapturesToEnvelopeCaptures(
|
|
91
91
|
dcborCaptures: Map<string, Cbor[][]>,
|
|
92
92
|
baseEnvelope: Envelope,
|
|
93
93
|
baseCbor: Cbor,
|
|
@@ -96,7 +96,7 @@ export class CBORPattern implements Matcher {
|
|
|
96
96
|
|
|
97
97
|
for (const [captureName, dcborCapturePaths] of dcborCaptures) {
|
|
98
98
|
const envelopeCapturePaths: Path[] = dcborCapturePaths.map((dcborPath) =>
|
|
99
|
-
this
|
|
99
|
+
this._convertDcborPathToEnvelopePath(dcborPath, baseEnvelope, baseCbor),
|
|
100
100
|
);
|
|
101
101
|
envelopeCaptures.set(captureName, envelopeCapturePaths);
|
|
102
102
|
}
|
|
@@ -107,7 +107,7 @@ export class CBORPattern implements Matcher {
|
|
|
107
107
|
/**
|
|
108
108
|
* Convert a single dcbor path to an envelope path.
|
|
109
109
|
*/
|
|
110
|
-
|
|
110
|
+
private _convertDcborPathToEnvelopePath(
|
|
111
111
|
dcborPath: Cbor[],
|
|
112
112
|
baseEnvelope: Envelope,
|
|
113
113
|
baseCbor: Cbor,
|
|
@@ -131,7 +131,7 @@ export class CBORPattern implements Matcher {
|
|
|
131
131
|
/**
|
|
132
132
|
* Collect capture names from a dcbor pattern.
|
|
133
133
|
*/
|
|
134
|
-
|
|
134
|
+
private _collectDcborCaptureNames(dcborPattern: DCBORPattern, names: string[]): void {
|
|
135
135
|
// Parse the pattern string to extract capture names
|
|
136
136
|
const patternStr = dcborPatternDisplay(dcborPattern);
|
|
137
137
|
|
|
@@ -163,19 +163,19 @@ export class CBORPattern implements Matcher {
|
|
|
163
163
|
const knownValue = envCase.value;
|
|
164
164
|
const knownValueCbor = knownValue.taggedCbor();
|
|
165
165
|
|
|
166
|
-
switch (this
|
|
166
|
+
switch (this._pattern.type) {
|
|
167
167
|
case "Any":
|
|
168
168
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
169
169
|
case "Value": {
|
|
170
170
|
// Compare using diagnostic representation
|
|
171
|
-
if (knownValueCbor.toDiagnostic() === this
|
|
171
|
+
if (knownValueCbor.toDiagnostic() === this._pattern.cbor.toDiagnostic()) {
|
|
172
172
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
173
173
|
}
|
|
174
174
|
return [[], new Map<string, Path[]>()];
|
|
175
175
|
}
|
|
176
176
|
case "Pattern": {
|
|
177
177
|
const { paths: dcborPaths, captures: dcborCaptures } = dcborPatternPathsWithCaptures(
|
|
178
|
-
this
|
|
178
|
+
this._pattern.pattern,
|
|
179
179
|
knownValueCbor,
|
|
180
180
|
);
|
|
181
181
|
|
|
@@ -193,7 +193,7 @@ export class CBORPattern implements Matcher {
|
|
|
193
193
|
return extendedPath;
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
-
const envelopeCaptures = this
|
|
196
|
+
const envelopeCaptures = this._convertDcborCapturesToEnvelopeCaptures(
|
|
197
197
|
dcborCaptures,
|
|
198
198
|
haystack,
|
|
199
199
|
knownValueCbor,
|
|
@@ -211,20 +211,20 @@ export class CBORPattern implements Matcher {
|
|
|
211
211
|
return [[], new Map<string, Path[]>()];
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
switch (this
|
|
214
|
+
switch (this._pattern.type) {
|
|
215
215
|
case "Any":
|
|
216
216
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
217
217
|
|
|
218
218
|
case "Value":
|
|
219
219
|
// Compare using diagnostic representation
|
|
220
|
-
if (leafCbor.toDiagnostic() === this
|
|
220
|
+
if (leafCbor.toDiagnostic() === this._pattern.cbor.toDiagnostic()) {
|
|
221
221
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
222
222
|
}
|
|
223
223
|
return [[], new Map<string, Path[]>()];
|
|
224
224
|
|
|
225
225
|
case "Pattern": {
|
|
226
226
|
const { paths: dcborPaths, captures: dcborCaptures } = dcborPatternPathsWithCaptures(
|
|
227
|
-
this
|
|
227
|
+
this._pattern.pattern,
|
|
228
228
|
leafCbor,
|
|
229
229
|
);
|
|
230
230
|
|
|
@@ -245,7 +245,7 @@ export class CBORPattern implements Matcher {
|
|
|
245
245
|
return extendedPath;
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
-
const envelopeCaptures = this
|
|
248
|
+
const envelopeCaptures = this._convertDcborCapturesToEnvelopeCaptures(
|
|
249
249
|
dcborCaptures,
|
|
250
250
|
haystack,
|
|
251
251
|
leafCbor,
|
|
@@ -267,9 +267,9 @@ export class CBORPattern implements Matcher {
|
|
|
267
267
|
|
|
268
268
|
compile(code: Instr[], literals: Pattern[], captures: string[]): void {
|
|
269
269
|
// Register any capture names from this CBOR pattern
|
|
270
|
-
if (this
|
|
270
|
+
if (this._pattern.type === "Pattern") {
|
|
271
271
|
const captureNames: string[] = [];
|
|
272
|
-
this
|
|
272
|
+
this._collectDcborCaptureNames(this._pattern.pattern, captureNames);
|
|
273
273
|
for (const name of captureNames) {
|
|
274
274
|
if (!captures.includes(name)) {
|
|
275
275
|
captures.push(name);
|
|
@@ -288,13 +288,13 @@ export class CBORPattern implements Matcher {
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
toString(): string {
|
|
291
|
-
switch (this
|
|
291
|
+
switch (this._pattern.type) {
|
|
292
292
|
case "Any":
|
|
293
293
|
return "cbor";
|
|
294
294
|
case "Value":
|
|
295
|
-
return `cbor(${this
|
|
295
|
+
return `cbor(${this._pattern.cbor.toDiagnostic()})`;
|
|
296
296
|
case "Pattern":
|
|
297
|
-
return `cbor(/${dcborPatternDisplay(this
|
|
297
|
+
return `cbor(/${dcborPatternDisplay(this._pattern.pattern)}/)`;
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -302,24 +302,24 @@ export class CBORPattern implements Matcher {
|
|
|
302
302
|
* Equality comparison.
|
|
303
303
|
*/
|
|
304
304
|
equals(other: CBORPattern): boolean {
|
|
305
|
-
if (this
|
|
305
|
+
if (this._pattern.type !== other._pattern.type) {
|
|
306
306
|
return false;
|
|
307
307
|
}
|
|
308
|
-
switch (this
|
|
308
|
+
switch (this._pattern.type) {
|
|
309
309
|
case "Any":
|
|
310
310
|
return true;
|
|
311
311
|
case "Value":
|
|
312
312
|
// Compare using diagnostic representation
|
|
313
313
|
return (
|
|
314
|
-
this
|
|
315
|
-
(other
|
|
314
|
+
this._pattern.cbor.toDiagnostic() ===
|
|
315
|
+
(other._pattern as { type: "Value"; cbor: Cbor }).cbor.toDiagnostic()
|
|
316
316
|
);
|
|
317
317
|
case "Pattern":
|
|
318
318
|
// Compare using display representation
|
|
319
319
|
return (
|
|
320
|
-
dcborPatternDisplay(this
|
|
320
|
+
dcborPatternDisplay(this._pattern.pattern) ===
|
|
321
321
|
dcborPatternDisplay(
|
|
322
|
-
(other
|
|
322
|
+
(other._pattern as { type: "Pattern"; pattern: DCBORPattern }).pattern,
|
|
323
323
|
)
|
|
324
324
|
);
|
|
325
325
|
}
|
|
@@ -329,15 +329,15 @@ export class CBORPattern implements Matcher {
|
|
|
329
329
|
* Hash code for use in Maps/Sets.
|
|
330
330
|
*/
|
|
331
331
|
hashCode(): number {
|
|
332
|
-
switch (this
|
|
332
|
+
switch (this._pattern.type) {
|
|
333
333
|
case "Any":
|
|
334
334
|
return 0;
|
|
335
335
|
case "Value":
|
|
336
336
|
// Simple hash based on diagnostic string
|
|
337
|
-
return simpleStringHash(this
|
|
337
|
+
return simpleStringHash(this._pattern.cbor.toDiagnostic());
|
|
338
338
|
case "Pattern":
|
|
339
339
|
// Simple hash based on display string
|
|
340
|
-
return simpleStringHash(dcborPatternDisplay(this
|
|
340
|
+
return simpleStringHash(dcborPatternDisplay(this._pattern.pattern));
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
}
|
|
@@ -42,10 +42,10 @@ export function registerDatePatternFactory(factory: (pattern: DatePattern) => Pa
|
|
|
42
42
|
* Corresponds to the Rust `DatePattern` struct in date_pattern.rs
|
|
43
43
|
*/
|
|
44
44
|
export class DatePattern implements Matcher {
|
|
45
|
-
readonly
|
|
45
|
+
private readonly _inner: DCBORDatePattern;
|
|
46
46
|
|
|
47
47
|
private constructor(inner: DCBORDatePattern) {
|
|
48
|
-
this
|
|
48
|
+
this._inner = inner;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
@@ -109,7 +109,7 @@ export class DatePattern implements Matcher {
|
|
|
109
109
|
* Gets the underlying dcbor-pattern DatePattern.
|
|
110
110
|
*/
|
|
111
111
|
get inner(): DCBORDatePattern {
|
|
112
|
-
return this
|
|
112
|
+
return this._inner;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
@@ -117,7 +117,7 @@ export class DatePattern implements Matcher {
|
|
|
117
117
|
const cbor = haystack.asLeaf();
|
|
118
118
|
if (cbor !== undefined) {
|
|
119
119
|
// Delegate to dcbor-pattern for CBOR matching
|
|
120
|
-
const dcborPaths = dcborDatePatternPaths(this
|
|
120
|
+
const dcborPaths = dcborDatePatternPaths(this._inner, cbor);
|
|
121
121
|
|
|
122
122
|
// For simple leaf patterns, if dcbor-pattern found matches, return the envelope
|
|
123
123
|
if (dcborPaths.length > 0) {
|
|
@@ -149,18 +149,18 @@ export class DatePattern implements Matcher {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
toString(): string {
|
|
152
|
-
return datePatternDisplay(this
|
|
152
|
+
return datePatternDisplay(this._inner);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* Equality comparison.
|
|
157
157
|
*/
|
|
158
158
|
equals(other: DatePattern): boolean {
|
|
159
|
-
if (this
|
|
159
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
160
160
|
return false;
|
|
161
161
|
}
|
|
162
162
|
// Simplified equality - compare variant names
|
|
163
|
-
return JSON.stringify(this
|
|
163
|
+
return JSON.stringify(this._inner) === JSON.stringify(other._inner);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -169,7 +169,7 @@ export class DatePattern implements Matcher {
|
|
|
169
169
|
hashCode(): number {
|
|
170
170
|
// Simple hash based on variant
|
|
171
171
|
let hash = 0;
|
|
172
|
-
const str = this
|
|
172
|
+
const str = this._inner.variant;
|
|
173
173
|
for (let i = 0; i < str.length; i++) {
|
|
174
174
|
hash = hash * 31 + str.charCodeAt(i);
|
|
175
175
|
}
|
|
@@ -41,10 +41,10 @@ export function registerKnownValuePatternFactory(
|
|
|
41
41
|
* Corresponds to the Rust `KnownValuePattern` struct in known_value_pattern.rs
|
|
42
42
|
*/
|
|
43
43
|
export class KnownValuePattern implements Matcher {
|
|
44
|
-
readonly
|
|
44
|
+
private readonly _inner: DCBORKnownValuePattern;
|
|
45
45
|
|
|
46
46
|
private constructor(inner: DCBORKnownValuePattern) {
|
|
47
|
-
this
|
|
47
|
+
this._inner = inner;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -86,7 +86,7 @@ export class KnownValuePattern implements Matcher {
|
|
|
86
86
|
* Gets the underlying dcbor-pattern KnownValuePattern.
|
|
87
87
|
*/
|
|
88
88
|
get inner(): DCBORKnownValuePattern {
|
|
89
|
-
return this
|
|
89
|
+
return this._inner;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
@@ -96,7 +96,7 @@ export class KnownValuePattern implements Matcher {
|
|
|
96
96
|
if (envCase.type === "knownValue") {
|
|
97
97
|
// Get the KnownValue and create CBOR for pattern matching
|
|
98
98
|
const knownValueCbor = envCase.value.taggedCbor();
|
|
99
|
-
if (knownValuePatternMatches(this
|
|
99
|
+
if (knownValuePatternMatches(this._inner, knownValueCbor)) {
|
|
100
100
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -104,7 +104,7 @@ export class KnownValuePattern implements Matcher {
|
|
|
104
104
|
// Also try matching as a leaf (for tagged CBOR containing known values)
|
|
105
105
|
const leafCbor = haystack.asLeaf();
|
|
106
106
|
if (leafCbor !== undefined) {
|
|
107
|
-
if (knownValuePatternMatches(this
|
|
107
|
+
if (knownValuePatternMatches(this._inner, leafCbor)) {
|
|
108
108
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -132,7 +132,7 @@ export class KnownValuePattern implements Matcher {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
toString(): string {
|
|
135
|
-
return knownValuePatternDisplay(this
|
|
135
|
+
return knownValuePatternDisplay(this._inner);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
/**
|
|
@@ -140,23 +140,23 @@ export class KnownValuePattern implements Matcher {
|
|
|
140
140
|
*/
|
|
141
141
|
equals(other: KnownValuePattern): boolean {
|
|
142
142
|
// Compare by variant type and values
|
|
143
|
-
if (this
|
|
143
|
+
if (this._inner.variant !== other._inner.variant) {
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
146
|
-
switch (this
|
|
146
|
+
switch (this._inner.variant) {
|
|
147
147
|
case "Any":
|
|
148
148
|
return true;
|
|
149
149
|
case "Value":
|
|
150
150
|
return (
|
|
151
|
-
this
|
|
152
|
-
(other
|
|
151
|
+
this._inner.value.valueBigInt() ===
|
|
152
|
+
(other._inner as { variant: "Value"; value: KnownValue }).value.valueBigInt()
|
|
153
153
|
);
|
|
154
154
|
case "Named":
|
|
155
|
-
return this
|
|
155
|
+
return this._inner.name === (other._inner as { variant: "Named"; name: string }).name;
|
|
156
156
|
case "Regex":
|
|
157
157
|
return (
|
|
158
|
-
this
|
|
159
|
-
(other
|
|
158
|
+
this._inner.pattern.source ===
|
|
159
|
+
(other._inner as { variant: "Regex"; pattern: RegExp }).pattern.source
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -165,15 +165,15 @@ export class KnownValuePattern implements Matcher {
|
|
|
165
165
|
* Hash code for use in Maps/Sets.
|
|
166
166
|
*/
|
|
167
167
|
hashCode(): number {
|
|
168
|
-
switch (this
|
|
168
|
+
switch (this._inner.variant) {
|
|
169
169
|
case "Any":
|
|
170
170
|
return 0;
|
|
171
171
|
case "Value":
|
|
172
|
-
return Number(this
|
|
172
|
+
return Number(this._inner.value.valueBigInt() & BigInt(0xffffffff));
|
|
173
173
|
case "Named":
|
|
174
|
-
return simpleStringHash(this
|
|
174
|
+
return simpleStringHash(this._inner.name);
|
|
175
175
|
case "Regex":
|
|
176
|
-
return simpleStringHash(this
|
|
176
|
+
return simpleStringHash(this._inner.pattern.source);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
}
|
|
@@ -37,10 +37,10 @@ export type MapPatternType =
|
|
|
37
37
|
* Corresponds to the Rust `MapPattern` struct in map_pattern.rs
|
|
38
38
|
*/
|
|
39
39
|
export class MapPattern implements Matcher {
|
|
40
|
-
readonly
|
|
40
|
+
private readonly _pattern: MapPatternType;
|
|
41
41
|
|
|
42
42
|
private constructor(pattern: MapPatternType) {
|
|
43
|
-
this
|
|
43
|
+
this._pattern = pattern;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -62,7 +62,7 @@ export class MapPattern implements Matcher {
|
|
|
62
62
|
* Gets the pattern type.
|
|
63
63
|
*/
|
|
64
64
|
get pattern(): MapPatternType {
|
|
65
|
-
return this
|
|
65
|
+
return this._pattern;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
@@ -78,13 +78,13 @@ export class MapPattern implements Matcher {
|
|
|
78
78
|
return [[], new Map<string, Path[]>()];
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
switch (this
|
|
81
|
+
switch (this._pattern.type) {
|
|
82
82
|
case "Any":
|
|
83
83
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
84
84
|
|
|
85
85
|
case "Interval": {
|
|
86
86
|
const size = map.size;
|
|
87
|
-
if (this
|
|
87
|
+
if (this._pattern.interval.contains(size)) {
|
|
88
88
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
89
89
|
}
|
|
90
90
|
return [[], new Map<string, Path[]>()];
|
|
@@ -112,11 +112,11 @@ export class MapPattern implements Matcher {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
toString(): string {
|
|
115
|
-
switch (this
|
|
115
|
+
switch (this._pattern.type) {
|
|
116
116
|
case "Any":
|
|
117
117
|
return "{*}";
|
|
118
118
|
case "Interval":
|
|
119
|
-
return `{{${this
|
|
119
|
+
return `{{${this._pattern.interval.toString()}}}`;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -124,15 +124,15 @@ export class MapPattern implements Matcher {
|
|
|
124
124
|
* Equality comparison.
|
|
125
125
|
*/
|
|
126
126
|
equals(other: MapPattern): boolean {
|
|
127
|
-
if (this
|
|
127
|
+
if (this._pattern.type !== other._pattern.type) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
-
switch (this
|
|
130
|
+
switch (this._pattern.type) {
|
|
131
131
|
case "Any":
|
|
132
132
|
return true;
|
|
133
133
|
case "Interval":
|
|
134
|
-
return this
|
|
135
|
-
(other
|
|
134
|
+
return this._pattern.interval.equals(
|
|
135
|
+
(other._pattern as { type: "Interval"; interval: Interval }).interval,
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -141,12 +141,12 @@ export class MapPattern implements Matcher {
|
|
|
141
141
|
* Hash code for use in Maps/Sets.
|
|
142
142
|
*/
|
|
143
143
|
hashCode(): number {
|
|
144
|
-
switch (this
|
|
144
|
+
switch (this._pattern.type) {
|
|
145
145
|
case "Any":
|
|
146
146
|
return 0;
|
|
147
147
|
case "Interval":
|
|
148
148
|
// Simple hash based on interval min/max
|
|
149
|
-
return this
|
|
149
|
+
return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -34,26 +34,26 @@ export function registerNullPatternFactory(factory: (pattern: NullPattern) => Pa
|
|
|
34
34
|
* Corresponds to the Rust `NullPattern` struct in null_pattern.rs
|
|
35
35
|
*/
|
|
36
36
|
export class NullPattern implements Matcher {
|
|
37
|
-
readonly
|
|
38
|
-
static readonly
|
|
37
|
+
private readonly _inner: DCBORNullPattern;
|
|
38
|
+
private static readonly _instance = new NullPattern();
|
|
39
39
|
|
|
40
40
|
private constructor() {
|
|
41
41
|
// Create the NullPattern directly - it's just { variant: "Null" }
|
|
42
|
-
this
|
|
42
|
+
this._inner = { variant: "Null" };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates a new NullPattern (returns singleton).
|
|
47
47
|
*/
|
|
48
48
|
static new(): NullPattern {
|
|
49
|
-
return NullPattern
|
|
49
|
+
return NullPattern._instance;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Gets the underlying dcbor-pattern NullPattern.
|
|
54
54
|
*/
|
|
55
55
|
get inner(): DCBORNullPattern {
|
|
56
|
-
return this
|
|
56
|
+
return this._inner;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
pathsWithCaptures(haystack: Envelope): [Path[], Map<string, Path[]>] {
|
|
@@ -61,7 +61,7 @@ export class NullPattern implements Matcher {
|
|
|
61
61
|
const cbor = haystack.asLeaf();
|
|
62
62
|
if (cbor !== undefined) {
|
|
63
63
|
// Delegate to dcbor-pattern for CBOR matching
|
|
64
|
-
const dcborPaths = dcborNullPatternPaths(this
|
|
64
|
+
const dcborPaths = dcborNullPatternPaths(this._inner, cbor);
|
|
65
65
|
|
|
66
66
|
if (dcborPaths.length > 0) {
|
|
67
67
|
return [[[haystack]], new Map<string, Path[]>()];
|
|
@@ -91,7 +91,7 @@ export class NullPattern implements Matcher {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
toString(): string {
|
|
94
|
-
return nullPatternDisplay(this
|
|
94
|
+
return nullPatternDisplay(this._inner);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|