Skip to content

Commit d088284

Browse files
committed
fix type exports
1 parent 1f79576 commit d088284

File tree

8 files changed

+47
-47
lines changed

8 files changed

+47
-47
lines changed

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"": {
55
"name": "filterql",
66
"devDependencies": {
7-
"@adamhl8/configs": "^0.11.0",
7+
"@adamhl8/configs": "^0.11.1",
88
"@biomejs/biome": "^2.2.0",
99
"@types/bun": "^1.2.20",
1010
"markdown-toc": "^1.2.0",
@@ -15,7 +15,7 @@
1515
},
1616
},
1717
"packages": {
18-
"@adamhl8/configs": ["@adamhl8/configs@0.11.0", "", { "dependencies": { "@prettier/plugin-xml": "^3.4.2", "prettier-plugin-astro": "^0.14.1", "prettier-plugin-sh": "^0.18.0", "prettier-plugin-tailwindcss": "^0.6.14", "prettier-plugin-toml": "^2.0.6" } }, "sha512-qWjpS1SN9cyLRh/rJWHp4pvV+qBAl3l5vUieFPfoeAcWnk107NkJtmP2n2MynQus/NJ5LDfdr2nOuQ4yy2p2lQ=="],
18+
"@adamhl8/configs": ["@adamhl8/configs@0.11.1", "", { "dependencies": { "@prettier/plugin-xml": "^3.4.2", "prettier-plugin-astro": "^0.14.1", "prettier-plugin-sh": "^0.18.0", "prettier-plugin-tailwindcss": "^0.6.14", "prettier-plugin-toml": "^2.0.6" } }, "sha512-gIZI+yPNVnl6U4sWLeTmNSsgLiPcvJpn55mvTvYKURNXLVrUqwqu0/ep8H4Q2u2uTHyCHcbvbL24xVuja10bVg=="],
1919

2020
"@astrojs/compiler": ["@astrojs/compiler@2.12.2", "", {}, "sha512-w2zfvhjNCkNMmMMOn5b0J8+OmUaBL1o40ipMvqcG6NRpdC+lKxmTi48DT8Xw0SzJ3AfmeFLB45zXZXtmbsjcgw=="],
2121

bunfig.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[test]
2-
preload = ["./src/setup.test.ts"]
2+
preload = ["./src/test-setup.ts"]

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "filterql",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"type": "module",
55
"description": "A tiny query language for filtering structured data",
66
"repository": {
@@ -20,7 +20,7 @@
2020
"exports": {
2121
".": {
2222
"import": "./dist/index.js",
23-
"types": "./dist/types/index.d.ts"
23+
"types": "./dist/index.d.ts"
2424
}
2525
},
2626
"files": ["dist/"],
@@ -32,7 +32,7 @@
3232
"prepublishOnly": "bun bundle"
3333
},
3434
"devDependencies": {
35-
"@adamhl8/configs": "^0.11.0",
35+
"@adamhl8/configs": "^0.11.1",
3636
"@biomejs/biome": "^2.2.0",
3737
"@types/bun": "^1.2.20",
3838
"markdown-toc": "^1.2.0",

src/filterql.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Evaluator } from "~/evaluator/evaluator.js"
2+
import type { Data, EvaluatorOptions, Schema } from "~/evaluator/types.js"
3+
import { Lexer } from "~/lexer/lexer.js"
4+
import { Parser } from "~/parser/parser.js"
5+
import type { ASTNode } from "~/parser/types.js"
6+
7+
export interface FilterQLOptions extends EvaluatorOptions {}
8+
9+
const DEFAULT_OPTIONS: FilterQLOptions = { ignoreUnknownFields: false }
10+
11+
export class FilterQL {
12+
private readonly options: FilterQLOptions
13+
private readonly evaluator: Evaluator
14+
15+
public constructor(schema: Schema, options?: FilterQLOptions) {
16+
this.options = { ...DEFAULT_OPTIONS, ...options }
17+
this.evaluator = new Evaluator(schema, this.options)
18+
}
19+
20+
/**
21+
* Parse a query string into an AST
22+
*/
23+
private parseQuery(query: string): ASTNode {
24+
const lexer = new Lexer(query)
25+
const tokens = lexer.tokenize()
26+
const parser = new Parser(tokens)
27+
return parser.parse()
28+
}
29+
30+
/**
31+
* Filter an array of objects based on a query
32+
*/
33+
public filter<T extends Data>(data: T[], query: string): T[] {
34+
if (!query.trim()) return data
35+
36+
const ast = this.parseQuery(query)
37+
return data.filter((item) => this.evaluator.evaluate(ast, item))
38+
}
39+
}

src/index.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,5 @@
1-
import { Evaluator } from "~/evaluator/evaluator.js"
2-
import type { Data, EvaluatorOptions, Schema } from "~/evaluator/types.js"
3-
import { Lexer } from "~/lexer/lexer.js"
4-
import { Parser } from "~/parser/parser.js"
5-
import type { ASTNode } from "~/parser/types.js"
6-
7-
export interface FilterQLOptions extends EvaluatorOptions {}
8-
9-
const DEFAULT_OPTIONS: FilterQLOptions = { ignoreUnknownFields: false }
10-
11-
export class FilterQL {
12-
private readonly options: FilterQLOptions
13-
private readonly evaluator: Evaluator
14-
15-
public constructor(schema: Schema, options?: FilterQLOptions) {
16-
this.options = { ...DEFAULT_OPTIONS, ...options }
17-
this.evaluator = new Evaluator(schema, this.options)
18-
}
19-
20-
/**
21-
* Parse a query string into an AST
22-
*/
23-
private parseQuery(query: string): ASTNode {
24-
const lexer = new Lexer(query)
25-
const tokens = lexer.tokenize()
26-
const parser = new Parser(tokens)
27-
return parser.parse()
28-
}
29-
30-
/**
31-
* Filter an array of objects based on a query
32-
*/
33-
public filter<T extends Data>(data: T[], query: string): T[] {
34-
if (!query.trim()) return data
35-
36-
const ast = this.parseQuery(query)
37-
return data.filter((item) => this.evaluator.evaluate(ast, item))
38-
}
39-
}
40-
411
export { Evaluator } from "~/evaluator/evaluator.js"
422
export type { Schema } from "~/evaluator/types.js"
3+
export { FilterQL, type FilterQLOptions } from "~/filterql.js"
434
export { Lexer } from "~/lexer/lexer.js"
445
export { Parser } from "~/parser/parser.js"
File renamed without changes.
File renamed without changes.

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["**/*.test.ts", "**/*.test.d.ts"]
3+
"exclude": ["**/*.test.ts", "**/test-*.ts"]
44
}

0 commit comments

Comments
 (0)