Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(evaluator): simplified synchronous evaluator #273

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Current Tape Test",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"args": [
"${workspaceFolder}/node_modules/.bin/tap",
"--no-timeout",
"--coverage-report=html",
"--no-browser",
"${file}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "openOnSessionStart"
}
]
}
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
]
},
"dependencies": {
"@portabletext/toolkit": "^2.0.17",
"debug": "^4.3.4"
},
"devDependencies": {
Expand Down
22 changes: 2 additions & 20 deletions src/1.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
export {evaluate} from './evaluator'
export {evaluateQuery as evaluate} from './evaluator'
export type {GroqFunction, GroqFunctionArg, GroqPipeFunction} from './evaluator/functions'
export type {Scope} from './evaluator/scope'
export type {
Context,
DereferenceFunction,
Document,
EvaluateOptions,
Executor,
EvaluateQueryOptions as EvaluateOptions,
} from './evaluator/types'
export * from './nodeTypes'
export {parse} from './parser'
export type {ParseOptions} from './types'
export type {
AnyStaticValue,
ArrayValue,
BooleanValue,
DateTimeValue,
GroqType,
NullValue,
NumberValue,
ObjectValue,
PathValue,
StaticValue,
StreamValue,
StringValue,
Value,
} from './values'
export {DateTime, Path} from './values'

// Type evaluation
export type * from './typeEvaluator'
Expand Down
55 changes: 0 additions & 55 deletions src/evaluator/constantEvaluate.ts

This file was deleted.

22 changes: 11 additions & 11 deletions src/evaluator/equality.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type {Value} from '../values'
import {isIso8601} from './evaluate'

export function isEqual(a: Value, b: Value): boolean {
if (
(a.type === 'string' && b.type === 'string') ||
(a.type === 'boolean' && b.type === 'boolean') ||
(a.type === 'null' && b.type === 'null') ||
(a.type === 'number' && b.type === 'number')
) {
return a.data === b.data
export function isEqual(a: unknown = null, b: unknown = null): boolean {
if (isIso8601(a) && isIso8601(b)) {
return new Date(a).getTime() === new Date(b).getTime()
}

if (a.type === 'datetime' && b.type === 'datetime') {
return a.data.equals(b.data)
if (
(a === null && b === null) ||
(typeof a === 'string' && typeof b === 'string') ||
(typeof a === 'boolean' && typeof b === 'boolean') ||
(typeof a === 'number' && typeof b === 'number')
) {
return a === b
}

return false
Expand Down
Loading
Loading