Skip to content

Commit 28d65cf

Browse files
committed
Rename classes to match terminology from the spec
1 parent 8010c0e commit 28d65cf

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

src/path/environment.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FilterExpressionLiteral,
55
FunctionExtension,
66
InfixExpression,
7-
JSONPathQuery,
7+
FilterQuery,
88
} from "./expression";
99
import { Count as CountFilterFunction } from "./functions/count";
1010
import { FilterFunction, FunctionExpressionType } from "./functions/function";
@@ -15,7 +15,7 @@ import { Value as ValueFilterFunction } from "./functions/value";
1515
import { tokenize } from "./lex";
1616
import { JSONPathNode, JSONPathNodeList } from "./node";
1717
import { Parser } from "./parse";
18-
import { JSONPath } from "./path";
18+
import { JSONPathQuery } from "./path";
1919
import { Token, TokenStream } from "./token";
2020
import { JSONValue } from "../types";
2121
import { CurrentKey } from "./extra/expression";
@@ -140,10 +140,10 @@ export class JSONPathEnvironment {
140140

141141
/**
142142
* @param path - A JSONPath query to parse.
143-
* @returns A new {@link JSONPath} object, bound to this environment.
143+
* @returns A new {@link JSONPathQuery} object, bound to this environment.
144144
*/
145-
public compile(path: string): JSONPath {
146-
return new JSONPath(
145+
public compile(path: string): JSONPathQuery {
146+
return new JSONPathQuery(
147147
this,
148148
this.parser.parse(new TokenStream(tokenize(this, path))),
149149
);
@@ -252,7 +252,7 @@ export class JSONPathEnvironment {
252252
!(
253253
arg instanceof FilterExpressionLiteral ||
254254
arg instanceof CurrentKey ||
255-
(arg instanceof JSONPathQuery && arg.path.singularQuery()) ||
255+
(arg instanceof FilterQuery && arg.path.singularQuery()) ||
256256
(arg instanceof FunctionExtension &&
257257
this.functionRegister.get(arg.name)?.returnType ===
258258
FunctionExpressionType.ValueType)
@@ -265,9 +265,7 @@ export class JSONPathEnvironment {
265265
}
266266
break;
267267
case FunctionExpressionType.LogicalType:
268-
if (
269-
!(arg instanceof JSONPathQuery || arg instanceof InfixExpression)
270-
) {
268+
if (!(arg instanceof FilterQuery || arg instanceof InfixExpression)) {
271269
throw new JSONPathTypeError(
272270
`${token.value}() argument ${idx} must be of LogicalType`,
273271
arg.token,
@@ -277,7 +275,7 @@ export class JSONPathEnvironment {
277275
case FunctionExpressionType.NodesType:
278276
if (
279277
!(
280-
arg instanceof JSONPathQuery ||
278+
arg instanceof FilterQuery ||
281279
(arg instanceof FunctionExtension &&
282280
this.functionRegister.get(arg.name)?.returnType ===
283281
FunctionExpressionType.NodesType)

src/path/expression.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { deepEquals } from "../deep_equals";
22
import { JSONPathTypeError, UndefinedFilterFunctionError } from "./errors";
33
import { FunctionExpressionType } from "./functions/function";
44
import { JSONPathNodeList } from "./node";
5-
import { JSONPath } from "./path";
5+
import { JSONPathQuery } from "./path";
66
import { Token } from "./token";
77
import { FilterContext, Nothing } from "./types";
88
import { isNumber, isString } from "../types";
@@ -190,16 +190,16 @@ export class LogicalExpression extends FilterExpression {
190190
/**
191191
* Base class for relative and absolute JSONPath query expressions.
192192
*/
193-
export abstract class JSONPathQuery extends FilterExpression {
193+
export abstract class FilterQuery extends FilterExpression {
194194
constructor(
195195
readonly token: Token,
196-
readonly path: JSONPath,
196+
readonly path: JSONPathQuery,
197197
) {
198198
super(token);
199199
}
200200
}
201201

202-
export class RelativeQuery extends JSONPathQuery {
202+
export class RelativeQuery extends FilterQuery {
203203
public evaluate(context: FilterContext): JSONPathNodeList {
204204
return context.lazy
205205
? new JSONPathNodeList(
@@ -213,7 +213,7 @@ export class RelativeQuery extends JSONPathQuery {
213213
}
214214
}
215215

216-
export class RootQuery extends JSONPathQuery {
216+
export class RootQuery extends FilterQuery {
217217
public evaluate(context: FilterContext): JSONPathNodeList {
218218
return context.lazy
219219
? new JSONPathNodeList(Array.from(this.path.lazyQuery(context.rootValue)))

src/path/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { JSONValue } from "../types";
22
import { JSONPathEnvironment } from "./environment";
33
import { JSONPathNode, JSONPathNodeList } from "./node";
4-
import { JSONPath } from "./path";
4+
import { JSONPathQuery } from "./path";
55

66
export { JSONPathEnvironment } from "./environment";
77
export type { JSONPathEnvironmentOptions } from "./environment";
88

9-
export { JSONPath } from "./path";
9+
export { JSONPathQuery } from "./path";
1010
export { JSONPathNodeList, JSONPathNode } from "./node";
1111
export { Token, TokenKind } from "./token";
1212

@@ -85,7 +85,7 @@ export function lazyQuery(
8585
* If filter function arguments are invalid, or filter expression are
8686
* used in an invalid way.
8787
*/
88-
export function compile(path: string): JSONPath {
88+
export function compile(path: string): JSONPathQuery {
8989
return DEFAULT_ENVIRONMENT.compile(path);
9090
}
9191

src/path/parse.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
StringLiteral,
1616
} from "./expression";
1717
import { FunctionExpressionType } from "./functions/function";
18-
import { JSONPath } from "./path";
18+
import { JSONPathQuery } from "./path";
1919
import {
2020
FilterSelector,
2121
IndexSelector,
@@ -24,11 +24,7 @@ import {
2424
SliceSelector,
2525
WildcardSelector,
2626
} from "./selectors";
27-
import {
28-
RecursiveDescentSegment,
29-
ChildSegment,
30-
JSONPathSegment,
31-
} from "./segments";
27+
import { DescendantSegment, ChildSegment, JSONPathSegment } from "./segments";
3228
import { Token, TokenKind, TokenStream } from "./token";
3329
import { CurrentKey } from "./extra/expression";
3430
import {
@@ -115,7 +111,7 @@ export class Parser {
115111
const token = stream.next();
116112
const selectors = this.parseSelectors(stream);
117113
segments.push(
118-
new RecursiveDescentSegment(this.environment, token, selectors),
114+
new DescendantSegment(this.environment, token, selectors),
119115
);
120116
break;
121117
}
@@ -453,15 +449,15 @@ export class Parser {
453449
const tok = stream.next();
454450
return new RootQuery(
455451
tok,
456-
new JSONPath(this.environment, this.parseQuery(stream, true)),
452+
new JSONPathQuery(this.environment, this.parseQuery(stream, true)),
457453
);
458454
}
459455

460456
protected parseRelativeQuery(stream: TokenStream): RelativeQuery {
461457
const tok = stream.next();
462458
return new RelativeQuery(
463459
tok,
464-
new JSONPath(this.environment, this.parseQuery(stream, true)),
460+
new JSONPathQuery(this.environment, this.parseQuery(stream, true)),
465461
);
466462
}
467463

src/path/path.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { JSONPathEnvironment } from "./environment";
22
import { JSONPathNode, JSONPathNodeList } from "./node";
33
import { IndexSelector, NameSelector } from "./selectors";
44
import { JSONValue } from "../types";
5-
import { JSONPathSegment, RecursiveDescentSegment } from "./segments";
5+
import { JSONPathSegment, DescendantSegment } from "./segments";
66

77
/**
88
*
99
*/
10-
export class JSONPath {
10+
export class JSONPathQuery {
1111
/**
1212
*
1313
* @param environment -
@@ -70,7 +70,7 @@ export class JSONPath {
7070

7171
public singularQuery(): boolean {
7272
for (const segment of this.segments) {
73-
if (segment instanceof RecursiveDescentSegment) return false;
73+
if (segment instanceof DescendantSegment) return false;
7474

7575
if (
7676
segment.selectors.length === 1 &&

src/path/segments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ChildSegment extends JSONPathSegment {
5757
}
5858

5959
/** The recursive descent segment. */
60-
export class RecursiveDescentSegment extends JSONPathSegment {
60+
export class DescendantSegment extends JSONPathSegment {
6161
public resolve(nodes: JSONPathNode[]): JSONPathNode[] {
6262
const rv: JSONPathNode[] = [];
6363

0 commit comments

Comments
 (0)