@omgbase/oqx 0.10.2 → 0.13.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/CHANGELOG.md +192 -0
- package/README.md +138 -32
- package/dist/context.d.ts +21 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +21 -9
- package/dist/context.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +98 -67
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lexer.d.ts.map +1 -1
- package/dist/lexer.js +47 -21
- package/dist/lexer.js.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +356 -163
- package/dist/parser.js.map +1 -1
- package/dist/regex.d.ts +19 -0
- package/dist/regex.d.ts.map +1 -0
- package/dist/regex.js +0 -0
- package/dist/regex.js.map +1 -0
- package/dist/semantics.d.ts +37 -9
- package/dist/semantics.d.ts.map +1 -1
- package/dist/semantics.js +138 -36
- package/dist/semantics.js.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +37 -10
- package/src/engine.ts +98 -65
- package/src/index.ts +7 -1
- package/src/lexer.ts +44 -14
- package/src/parser.ts +340 -119
- package/src/regex.ts +0 -0
- package/src/semantics.ts +128 -31
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,198 @@ All notable changes to `@omgbase/oqx` are recorded here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
5
|
[Semantic Versioning](https://semver.org/) (pre-1.0: a minor bump may break).
|
|
6
6
|
|
|
7
|
+
## [0.13.0] - 2026-09-26
|
|
8
|
+
|
|
9
|
+
Language `0.13` (`spec/oqx/VERSION`; `LANGUAGE_VERSION` is `"0.13"`). One
|
|
10
|
+
scoping rule changed; the spec now has 850 fixtures in 29 files (15 new, in
|
|
11
|
+
`cases/intrinsics.json`; no existing expectation moved).
|
|
12
|
+
|
|
13
|
+
### Changed (breaking) — semantics
|
|
14
|
+
- **Intrinsic names fall through to the row where the scope carries no such
|
|
15
|
+
metadata** (SEMANTICS §2 steps 2–3, §20, §21). `$key` is metadata only in an
|
|
16
|
+
`entries()` scope; `$depth`, `$stop`, `$leaf`, `$frontier`, `$ordinal` only
|
|
17
|
+
on a `follow` occurrence. Anywhere else the six names are ordinary property
|
|
18
|
+
reads of the row (step 5): a plain row `{ "$depth": 3, "$ordinal": 7 }`
|
|
19
|
+
projects `3`/`7` at the top level and inside a nested `collect`; a `where`
|
|
20
|
+
on `$depth` without a `follow` is an ordinary predicate (no seed/post-walk
|
|
21
|
+
split); `order by $ordinal` over rows without the property is unchanged
|
|
22
|
+
(absent sorts last). Inside a nested block within a `follow`, a bare `$depth`
|
|
23
|
+
is now the nested row's own `$depth` property (absent unless the data carries
|
|
24
|
+
one) and `^$depth` is still the occurrence's. Where the metadata exists it
|
|
25
|
+
wins over a same-named row property, so nothing inside a `follow` changes.
|
|
26
|
+
Before, the six names read absent everywhere they were not metadata.
|
|
27
|
+
**Why:** omgbase's blocks carry a `$depth` and `$ordinal` of their own that
|
|
28
|
+
the recursion intrinsics shadowed outside a `follow`; `spec/surface` §9 had
|
|
29
|
+
pinned this as a candidate minor.
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
- `DataContext.get` is documented as the host's error channel: a throw (an
|
|
33
|
+
`OqxError` with stage `"eval"`, or any error) rejects the read and is the
|
|
34
|
+
query's error. The behavior is unchanged; the Rust crate's `DataContext::get`
|
|
35
|
+
now returns `Result<Value>` to match.
|
|
36
|
+
|
|
37
|
+
## [0.12.0] - 2026-09-25
|
|
38
|
+
|
|
39
|
+
**OQX is now a language with a specification and two implementations.** The
|
|
40
|
+
spec lives at `spec/oqx` in the monorepo: `GRAMMAR.md`, `SEMANTICS.md`, and
|
|
41
|
+
835 executable fixtures in 28 files that this package and the Rust
|
|
42
|
+
crate `oqx` both run. **Versioning changed accordingly:** the language version
|
|
43
|
+
is `spec/oqx/VERSION` (`0.12`) and every implementation's version is
|
|
44
|
+
`<language>.<patch>`, so `@omgbase/oqx 0.12.x` and the `oqx` crate `0.12.x`
|
|
45
|
+
both mean "the 0.12 language"; the patch digit is per implementation. The
|
|
46
|
+
package exports `LANGUAGE_VERSION`.
|
|
47
|
+
|
|
48
|
+
Everything below follows one principle, applied without exception: **least
|
|
49
|
+
surprise.** Where the reference behaved by JavaScript accident, it now does
|
|
50
|
+
what a careful user would predict.
|
|
51
|
+
|
|
52
|
+
### Changed (breaking) — semantics
|
|
53
|
+
- **Identity is structural.** `distinct` over unprojected rows and `follow`
|
|
54
|
+
cycle detection/dedup use the `id` property when present, else the row's
|
|
55
|
+
structural value (deep equality, key order ignored). Previously identities
|
|
56
|
+
were stringified, so every id-less object collided as `[object Object]`
|
|
57
|
+
(`count distinct { }` over two different objects gave 1; `follow` over
|
|
58
|
+
id-less nodes marked every successor a cycle) and `1` equalled `"1"`.
|
|
59
|
+
- **No cross-type ordering.** `< <= > >=` and range coverage order only
|
|
60
|
+
number/number and string/string; every other pair, including booleans and
|
|
61
|
+
anything absent, is false. `1 < "2"` and `"3" in 1..5` were true.
|
|
62
|
+
- **Strings order and measure by Unicode code point**, not UTF-16 code unit:
|
|
63
|
+
`"😀".size()` is 1 and astral characters sort after the BMP.
|
|
64
|
+
- **Own enumerable properties only.** Property reads (`name`, `.name`,
|
|
65
|
+
`^name`), `has()`, `in` over an object, and `entries()` never see inherited
|
|
66
|
+
members (`has(toString)` is false). Arrays expose only their integer
|
|
67
|
+
indices — `.length` is absent; use `size()`. Primitives have no properties.
|
|
68
|
+
- **Absent propagates.** Any arithmetic with an absent operand is absent,
|
|
69
|
+
including `"a" + missing` (was `"aundefined"`) and `null + 1` (was `1`).
|
|
70
|
+
`.lower()` / `.upper()` on absent are absent (were `"undefined"` /
|
|
71
|
+
`"NULL"`).
|
|
72
|
+
- **Regex is an OQX concern.** An invalid `matches()` pattern raises
|
|
73
|
+
`OqxError` (`eval`, `invalid regular expression`) instead of a raw
|
|
74
|
+
`SyntaxError`. Lookaround and backreferences are rejected (`not supported in
|
|
75
|
+
OQX`) so the dialect is the portable intersection.
|
|
76
|
+
- **Ranges never appear in results.** Projecting a range value is an error
|
|
77
|
+
(`a range … cannot appear in a result`); no range covers an absent value,
|
|
78
|
+
however open.
|
|
79
|
+
- **`&&` and `||` evaluate strictly left to right** with short-circuit; the
|
|
80
|
+
engine no longer reorders conjuncts by cost, so `false && bogus()` never
|
|
81
|
+
errors and `true && bogus()` always does.
|
|
82
|
+
- **`single` reports the true row count** in its error.
|
|
83
|
+
- **`$ordinal` path components compare as values** (numbers numerically,
|
|
84
|
+
before strings), not as text: `[1, 9, 10]`, not `[1, 10, 9]`.
|
|
85
|
+
- **Bindings out of range** (`run(query, { values })` with fewer values than
|
|
86
|
+
the query references) raise `OqxError` instead of reading `undefined`.
|
|
87
|
+
|
|
88
|
+
### Changed (breaking) — grammar
|
|
89
|
+
- **`!` has one precedence everywhere:** a prefix operator binding tighter
|
|
90
|
+
than comparison, applied to the operand right after it. `where !a == b` is
|
|
91
|
+
`(!a) == b` (it negated the whole comparison before); `!jobs exists { … }`
|
|
92
|
+
and `!(a == b)` work as written.
|
|
93
|
+
- **Parenthesized scalars work in `where`:** `where (a + 1) > 2` was a parse
|
|
94
|
+
error; a group followed by an operator is a scalar.
|
|
95
|
+
- **`follow distinct` requires a relation** (`follow distinct { depth 2 }` no
|
|
96
|
+
longer treats `distinct` as the relation name); `follow ^rel` is a clear
|
|
97
|
+
error.
|
|
98
|
+
- **Open-ended ranges stop at clause words** (`in ..5 order by a`); a range
|
|
99
|
+
with no bound at all is an error.
|
|
100
|
+
- **Duplicate projection names are an error** (`a: 1, a: 2` last-wins is
|
|
101
|
+
gone), including a dotted default key colliding with an alias.
|
|
102
|
+
- **Malformed numerals are lex errors:** `1e`, `1e+`, `1.`, `.5`, `xs.0`.
|
|
103
|
+
`1..5`, `1...5`, `..5`, `1..`, `1.5..2.5` are unchanged.
|
|
104
|
+
- **Top-level `limit ^n` / `offset ^n`** are parse errors (`no enclosing
|
|
105
|
+
scope`); they were always absent and failed at run time.
|
|
106
|
+
- **`true` / `false` / `null` are literals in every position;** as a receiver
|
|
107
|
+
or follow relation they error instead of resolving a root by that name.
|
|
108
|
+
- **Lifts (`^name:`) outside a where-position `collect`** are parse errors
|
|
109
|
+
instead of silently doing nothing.
|
|
110
|
+
- **Chained comparisons** (`a == b == c`) error clearly; **stray tokens** after
|
|
111
|
+
a query or in a block get a located message; clause words without their
|
|
112
|
+
clause (`order age`, bare `follow`, `limit x`) say what they need.
|
|
113
|
+
|
|
114
|
+
### Changed (breaking) — regular expressions
|
|
115
|
+
- **`matches()` compiles the OQX regex baseline, not a JavaScript `RegExp`.**
|
|
116
|
+
The baseline (SEMANTICS §11) is a fixed grammar — literals and escaped
|
|
117
|
+
metacharacters, `\n \t \r \f \v`, `\uXXXX` / `\u{…}`, the classes
|
|
118
|
+
`\d \D \w \W \s \S` with spec-fixed sets (`\d` = `[0-9]`, `\w` =
|
|
119
|
+
`[A-Za-z0-9_]`, `\s` = one listed set), `\b \B` over that `\w`, bracket
|
|
120
|
+
classes, `.`, `^ $`, the quantifiers and their lazy forms, `|`, `(…)`,
|
|
121
|
+
`(?:…)`, `(?<name>…)` — and the pattern is validated and rewritten before
|
|
122
|
+
`RegExp` sees it (`src/regex.ts`). **The line terminator is `\n` alone**
|
|
123
|
+
for `.` and for `m`-mode anchors (`\r`, U+2028, U+2029 are ordinary
|
|
124
|
+
characters), and `.` consumes a code point. Every construct outside the
|
|
125
|
+
grammar is an eval error naming it (`an inline flag (?i) is not supported in
|
|
126
|
+
OQX regular expressions`): lookaround and backreferences (already rejected),
|
|
127
|
+
now also inline flags `(?i)` / `(?i:…)`, `\p{…}`, `\x..`, `\c.`, octal
|
|
128
|
+
escapes, identity escapes of non-metacharacters, possessive quantifiers,
|
|
129
|
+
atomic and comment groups, `(?P<…>)`, `\A \z \Z \G \K \Q \E`, POSIX and
|
|
130
|
+
nested classes, class set operations, `[\b]`. Malformed patterns that
|
|
131
|
+
`RegExp` tolerated (`a{`, a lone `]`, `a**`, `[]`, `[^]`, `(?<n>…)` twice)
|
|
132
|
+
are `invalid regular expression`.
|
|
133
|
+
- **Flags are an explicit second argument**: `matches(pattern, flags)` with
|
|
134
|
+
`flags` a string of distinct letters from `i` (simple case folding, so `é`
|
|
135
|
+
matches `É`), `m`, `s`. Anything else is an eval error: `unknown regex
|
|
136
|
+
flag` (`"g"`, `"I"`, a non-string) or `duplicate regex flag`. There is no
|
|
137
|
+
inline flag syntax.
|
|
138
|
+
- **Engine-native dialects are a host opt-in, not query syntax.**
|
|
139
|
+
`DataContext` gains an optional `regexDialect: "oqx" | "native"` (default
|
|
140
|
+
`"oqx"`); `new DefaultContext(roots, { regexDialect: "native" })` hands
|
|
141
|
+
patterns to `RegExp` unvalidated with the `u` flag plus the given flags —
|
|
142
|
+
implementation-defined, not portable, untested by the spec. `DefaultContext`
|
|
143
|
+
answers `matches` itself so it can read the dialect; `BUILTIN_METHODS.matches`
|
|
144
|
+
stays the baseline, and `semantics.regexMatches(recv, args, dialect)` is the
|
|
145
|
+
helper for custom contexts. `compileRegex(pattern, flags?, dialect?)` and the
|
|
146
|
+
`RegexDialect` / `RegexFlags` types are exported.
|
|
147
|
+
- Fixtures: the `matches` cases moved from `strings.json` to a new
|
|
148
|
+
`regex.json` (21 moved, 98 added), pinning each baseline construct, the
|
|
149
|
+
`\n`-only line terminator, ASCII `\d \w \b`, the `\s` set, code-point `.`,
|
|
150
|
+
flags, and one rejection per construct.
|
|
151
|
+
|
|
152
|
+
### Documentation
|
|
153
|
+
- Integer-like object keys enumerate first in JavaScript before OQX sees the
|
|
154
|
+
object; this is a host fact the reference cannot undo, and fixtures must not
|
|
155
|
+
depend on the relative order of integer-like and other keys.
|
|
156
|
+
|
|
157
|
+
## [0.11.0] - 2026-09-24
|
|
158
|
+
|
|
159
|
+
### Changed (breaking)
|
|
160
|
+
- **Clause order is fixed** (omgbase ADR-020). Within one clause body — the
|
|
161
|
+
top level or any consumer block — clauses appear at most once each, in
|
|
162
|
+
exactly this order: `select … from … where … follow … order by … limit N
|
|
163
|
+
offset N`. Every clause is optional except a top-level `from` (the
|
|
164
|
+
`<receiver> <consumer> { … }` form supplies its own source). A clause out
|
|
165
|
+
of order is a parse error that names the order (`` `select` must come
|
|
166
|
+
before `from` — OQX clause order is select, from, where, follow, order by,
|
|
167
|
+
limit, offset ``); a second `from` in one body is a duplicate. The
|
|
168
|
+
order-flexible grammar (`from ${people} select name where …`, `limit 1 name
|
|
169
|
+
from …`, `offset 1 limit 1`) no longer parses.
|
|
170
|
+
- **Only `select` may drop its keyword, and only when it is the first clause
|
|
171
|
+
written** (`name, age from people`). Every other clause always carries its
|
|
172
|
+
keyword, so a predicate is never implicit: the `looksLikePredicate` shape
|
|
173
|
+
heuristic is gone. **A block now needs `where`** — `jobs exists { where
|
|
174
|
+
!end }` — and a bare comparison in leading position (`exists { age > 50 }`,
|
|
175
|
+
`age > 50 from people`) is a parse error that points at `where`. A bare name
|
|
176
|
+
in leading position projects, as before (`count { active }` selects
|
|
177
|
+
`active`).
|
|
178
|
+
- **The `from docs count` footgun is closed.** A bare run after `from` is an
|
|
179
|
+
error; `from people count` fails at `count` with a hint — write
|
|
180
|
+
`people count { … }` for the whole-query consumer, or `select count from …`
|
|
181
|
+
to project a field named `count`. (Previously it silently projected the
|
|
182
|
+
field.)
|
|
183
|
+
|
|
184
|
+
### Added
|
|
185
|
+
- **`where` may reference the same body's `select` aliases.** Implemented as a
|
|
186
|
+
compile-time inline rewrite (not a second execution pass): after a body is
|
|
187
|
+
parsed, each bare identifier in its `where` that names an alias is replaced
|
|
188
|
+
by the alias's expression, so the engine and any pushdown planner see an
|
|
189
|
+
ordinary predicate. An alias shadows a same-named row field inside `where`;
|
|
190
|
+
an alias's own name inside its own expression is still the field
|
|
191
|
+
(`name: name.upper()` is not recursive); a chain of aliases that returns to
|
|
192
|
+
one being resolved (`a: b, b: a … where a`) is a parse error; an alias whose
|
|
193
|
+
value is a `collect`/`first`/`single { … }` block may stand alone as a
|
|
194
|
+
where leaf (non-empty test) but not inside an expression. Each body rewrites
|
|
195
|
+
only against its own `select` (nested blocks and `follow` blocks are their
|
|
196
|
+
own scopes); `^name` is never an alias. `order by` is unchanged — it reads
|
|
197
|
+
row fields, not aliases.
|
|
198
|
+
|
|
7
199
|
## [0.10.2] - 2026-09-23
|
|
8
200
|
|
|
9
201
|
Moved into the omgbase monorepo (`packages/oqx`, via `git subtree` — full
|
package/README.md
CHANGED
|
@@ -13,6 +13,10 @@ JavaScript tagged template.
|
|
|
13
13
|
> is published independently under its own version line and has **zero runtime
|
|
14
14
|
> dependencies** — it is usable without omgbase, and omgbase code is never
|
|
15
15
|
> imported here (omgbase binds it from the outside via the `DataContext` seam).
|
|
16
|
+
> OQX is a language with more than one implementation; the specification is
|
|
17
|
+
> [`spec/oqx`](https://github.com/omgbase/omgbase/tree/main/spec/oqx). The
|
|
18
|
+
> language version is the package version's `major.minor` (`LANGUAGE_VERSION`,
|
|
19
|
+
> `"0.13"`); the patch digit is this implementation's own.
|
|
16
20
|
> Requirements: Node ≥ 22.13 for `@omgbase/oqx/sqlite`; Node ≥ 22.18 to run the
|
|
17
21
|
> test suite (see [Requirements](#requirements)).
|
|
18
22
|
|
|
@@ -30,7 +34,7 @@ const company = "Globocorp";
|
|
|
30
34
|
const employees = oqx`
|
|
31
35
|
name, id, title
|
|
32
36
|
from ${people}
|
|
33
|
-
where jobs exists { employer == ${company} && !end_date }
|
|
37
|
+
where jobs exists { where employer == ${company} && !end_date }
|
|
34
38
|
`;
|
|
35
39
|
// → [{ name: "Bob", id: 124, title: "Engineer" }, …] (current Globocorp employees)
|
|
36
40
|
```
|
|
@@ -46,18 +50,30 @@ template's identity and re-runs with fresh bindings each call.
|
|
|
46
50
|
|
|
47
51
|
## Language tutorial
|
|
48
52
|
|
|
49
|
-
A query
|
|
50
|
-
|
|
51
|
-
`from`, whichever reads better:
|
|
53
|
+
A query is a list of clauses in a **fixed order**. Each clause appears at most
|
|
54
|
+
once, and every one is optional except `from` at the top level:
|
|
52
55
|
|
|
53
56
|
```
|
|
54
|
-
[ [select] projection ] name, id, title: label
|
|
57
|
+
[ [select] projection ] name, id, title: label (or: select distinct …, … values)
|
|
55
58
|
from <collection> from ${people}
|
|
56
|
-
[ where <predicate> ] where age >= 18 && jobs exists { !end }
|
|
57
|
-
[ order by <expr> … ] order by age desc, name
|
|
59
|
+
[ where <predicate> ] where age >= 18 && jobs exists { where !end }
|
|
58
60
|
[ follow <relation> … ] follow children { depth 4 }
|
|
61
|
+
[ order by <expr> … ] order by age desc, name
|
|
62
|
+
[ limit N ] limit 10
|
|
63
|
+
[ offset N ] offset 20
|
|
59
64
|
```
|
|
60
65
|
|
|
66
|
+
**`select` is the only keyword you may drop, and only when the projection comes
|
|
67
|
+
first** (`name, id from ${people}`). Every other clause always carries its
|
|
68
|
+
keyword — in particular a predicate is never implicit, so a block filters with
|
|
69
|
+
`where` (`jobs exists { where !end }`), and `from ${people} count` is an error
|
|
70
|
+
rather than a projection of a field called `count`. Writing a clause out of
|
|
71
|
+
order is a parse error that names the order (`` `select` must come before
|
|
72
|
+
`from` — OQX clause order is select, from, where, follow, order by, limit,
|
|
73
|
+
offset ``). The same body grammar applies inside every consumer block
|
|
74
|
+
(`collect { … }`, `exists { … }`, …), where `from` is optional because the
|
|
75
|
+
receiver supplies the rows.
|
|
76
|
+
|
|
61
77
|
The examples below all use this dataset:
|
|
62
78
|
|
|
63
79
|
```js
|
|
@@ -113,8 +129,12 @@ An item that is not a plain navigation — a call, arithmetic, a comparison —
|
|
|
113
129
|
no natural key, so it must be aliased (`n: size(jobs)`), unless the projection is
|
|
114
130
|
in `values` mode (next).
|
|
115
131
|
|
|
116
|
-
The `select` keyword
|
|
117
|
-
is identical to `name from
|
|
132
|
+
The `select` keyword may be dropped when the projection is the first clause —
|
|
133
|
+
`select name from …` is identical to `name from …`. The keyword form hosts
|
|
134
|
+
`select distinct` (§6), and is the only way to write a projection whose first
|
|
135
|
+
item would otherwise be misread (there is no other keyword-less clause). The
|
|
136
|
+
projection always comes *before* `from`: `from ${people} select name` is an
|
|
137
|
+
ordering error.
|
|
118
138
|
|
|
119
139
|
**`values` — scalar projection.** Ordinarily every row projects to a record. Add
|
|
120
140
|
`values` after a projection of exactly **one** item to get the value itself:
|
|
@@ -182,8 +202,9 @@ ask for one. As a plain value (not a source) `entries(x)` is an array of
|
|
|
182
202
|
|
|
183
203
|
`where` filters rows. The predicate language has comparisons (`== != < <= > >=`),
|
|
184
204
|
boolean operators (`&& || !`) with grouping `( )`, membership (`in`), arithmetic
|
|
185
|
-
(`+ - * / %`), and bare truthiness. The `where` keyword is
|
|
186
|
-
leading expression is
|
|
205
|
+
(`+ - * / %`), and bare truthiness. The `where` keyword is always written — a
|
|
206
|
+
leading expression without it is a projection, and a bare comparison in that
|
|
207
|
+
position is an error that points you at `where`.
|
|
187
208
|
|
|
188
209
|
```js
|
|
189
210
|
const min = 40;
|
|
@@ -231,6 +252,25 @@ non-range string yields an absent range, so `x in range(bad)` is just false.
|
|
|
231
252
|
**Interpolations are always values, never syntax.** `where name == ${x}` compares
|
|
232
253
|
against the value of `x`; a string in `x` can't inject operators or identifiers.
|
|
233
254
|
|
|
255
|
+
**`where` sees the `select` aliases.** A name defined in the same body's
|
|
256
|
+
projection may be used in its `where`; an alias shadows a same-named field
|
|
257
|
+
there. It is a compile-time rewrite — the alias's expression is substituted
|
|
258
|
+
inline — so it costs nothing at run time and a storage planner still sees an
|
|
259
|
+
ordinary predicate:
|
|
260
|
+
|
|
261
|
+
```js
|
|
262
|
+
oqx`select name, adult: age >= 18 from ${people} where adult`; // ≡ where age >= 18
|
|
263
|
+
oqx`select name, active: age > 50 from ${people} where active`; // the ALIAS, not the field → Alice
|
|
264
|
+
oqx`select name, current: jobs collect { employer where !end } from ${people} where current`;
|
|
265
|
+
// a collect alias in predicate position means "non-empty" → Bob, Carol
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Inside an alias's own expression its name is still the field
|
|
269
|
+
(`name: name.upper()` is not recursive); a chain of aliases that comes back to
|
|
270
|
+
itself (`a: b, b: a … where a`) is a parse error. Each block rewrites only
|
|
271
|
+
against its *own* `select`; `^name` always reads an enclosing row's field, never
|
|
272
|
+
an alias. `order by` is not rewritten — it reads row fields (§8).
|
|
273
|
+
|
|
234
274
|
**Scoping: bare names are local, `^` reaches out.** A bare identifier resolves
|
|
235
275
|
against the **current row only**. If the row lacks that property the value is
|
|
236
276
|
absent — it never falls through to an enclosing row. To correlate with an
|
|
@@ -242,10 +282,10 @@ const accounts = [
|
|
|
242
282
|
{ owner: "x", budget: 100, orders: [{ amount: 50 }, { amount: 150 }] },
|
|
243
283
|
{ owner: "y", budget: 200, orders: [{ amount: 250 }] },
|
|
244
284
|
];
|
|
245
|
-
oqx`owner from ${accounts} where orders exists { amount > ^budget }`;
|
|
285
|
+
oqx`owner from ${accounts} where orders exists { where amount > ^budget }`;
|
|
246
286
|
// [{ owner: "x" }, { owner: "y" }] — `^budget` is the enclosing account's budget
|
|
247
287
|
|
|
248
|
-
oqx`owner from ${accounts} where orders exists { amount > budget }`;
|
|
288
|
+
oqx`owner from ${accounts} where orders exists { where amount > budget }`;
|
|
249
289
|
// [] — a bare `budget` is the ORDER's own budget: absent, so `>` is false
|
|
250
290
|
```
|
|
251
291
|
|
|
@@ -311,13 +351,56 @@ oqx`name from ${people} where tags.contains("admin")`; // array membership
|
|
|
311
351
|
- `.contains(v)` works on strings (substring) **and arrays** (an element equal
|
|
312
352
|
to `v` under OQX's strict equality); on anything else it is false.
|
|
313
353
|
- `.size()` / `size(x)` is the length of a string or array, the key count of
|
|
314
|
-
an object, and 0 for absent
|
|
315
|
-
|
|
354
|
+
an object, and 0 for absent.
|
|
355
|
+
- `.matches(re, flags?)` searches the receiver's text for a regular expression
|
|
356
|
+
written in the **OQX regex baseline** (below), unanchored unless the pattern
|
|
357
|
+
anchors. `flags` is an optional string of `i` (case-insensitive), `m` (`^`/`$`
|
|
358
|
+
also at newlines), `s` (`.` also matches `\n`); an absent receiver is `false`.
|
|
316
359
|
|
|
317
360
|
Anything not in these tables is an **eval error** (`unknown function 'f(…)'` /
|
|
318
361
|
`unknown method '.m(…)'`) — see [custom functions](#custom-functions-and-methods)
|
|
319
362
|
for adding your own.
|
|
320
363
|
|
|
364
|
+
#### The regex baseline
|
|
365
|
+
|
|
366
|
+
OQX is a language with more than one implementation, so `matches()` does not
|
|
367
|
+
expose the host's `RegExp`. It compiles a fixed, portable dialect whose every
|
|
368
|
+
construct has one spec-defined meaning (`spec/oqx/SEMANTICS.md` §11):
|
|
369
|
+
|
|
370
|
+
- literals; escaped metacharacters `\. \* \+ \? \( \) \[ \] \{ \} \| \^ \$ \\ \/ \-`;
|
|
371
|
+
`\n \t \r \f \v`; `\uXXXX` (four hex digits) and `\u{X…}` (any code point);
|
|
372
|
+
- `\d` = `[0-9]`, `\w` = `[A-Za-z0-9_]`, `\s` = JavaScript's white space (one
|
|
373
|
+
listed set), `\D \W \S` their complements, `\b \B` word boundaries over that
|
|
374
|
+
`\w`; bracket classes `[…]` / `[^…]` with ranges;
|
|
375
|
+
- `.` = any code point except `\n` (the line terminator is `\n` alone — `\r`
|
|
376
|
+
is an ordinary character); anchors `^ $`; quantifiers `* + ? {n} {n,} {n,m}`
|
|
377
|
+
and their lazy `?` forms; alternation `|`; groups `(…)`, `(?:…)`, `(?<name>…)`.
|
|
378
|
+
|
|
379
|
+
Everything else — lookaround, backreferences, inline flags `(?i)`, `\p{…}`,
|
|
380
|
+
`\x..`, octal, possessive quantifiers, POSIX classes, `\A \z` … — is an
|
|
381
|
+
`OqxError` (stage `eval`) naming the construct: `an inline flag (?i) is not
|
|
382
|
+
supported in OQX regular expressions`. A pattern that is malformed within the
|
|
383
|
+
baseline is `invalid regular expression …`; a bad flag is `unknown regex flag`
|
|
384
|
+
/ `duplicate regex flag`. The pattern is validated and rewritten before
|
|
385
|
+
`RegExp` sees it (`src/regex.ts`), so JavaScript-only behavior never leaks.
|
|
386
|
+
|
|
387
|
+
```js
|
|
388
|
+
oqx`name from ${people} where title.matches("^(eng|dir)", "i")`; // Bob, Alice
|
|
389
|
+
oqx`x: "a\nb".matches("a.b") from ${one}`; // false: . stops at \n
|
|
390
|
+
oqx`x: "a\nb".matches("a.b", "s") from ${one}`; // true
|
|
391
|
+
oqx`x: "٣".matches(${"\\d"}) from ${one}`; // false: \d is ASCII
|
|
392
|
+
oqx`x: "é".matches(${"^\\u{e9}$"}) from ${one}`; // true
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
A pattern with backslashes is easiest to pass as a binding (`${"\\d"}`): the
|
|
396
|
+
template's own escaping and the OQX string literal's `\<c>` escape would each
|
|
397
|
+
consume one level otherwise (`"\\\\d"` in the template is `\d` to the regex).
|
|
398
|
+
|
|
399
|
+
A host that wants JavaScript's own dialect can opt in per context:
|
|
400
|
+
`new DefaultContext(roots, { regexDialect: "native" })` hands patterns to
|
|
401
|
+
`RegExp` unvalidated (with the `u` flag plus the given flags). That is
|
|
402
|
+
implementation-defined and not portable to the Rust implementation.
|
|
403
|
+
|
|
321
404
|
### 5. Consumers
|
|
322
405
|
|
|
323
406
|
A consumer shapes a result set. There are six:
|
|
@@ -333,8 +416,9 @@ A consumer shapes a result set. There are six:
|
|
|
333
416
|
|
|
334
417
|
The bare `from … ` form is always `collect`. To reduce the **whole** query with a
|
|
335
418
|
different consumer, use the directive form `<source> <consumer> { <body> }` — note
|
|
336
|
-
this is *not* SQL: `count from people`
|
|
337
|
-
|
|
419
|
+
this is *not* SQL: `count from people` projects a field called `count`, and
|
|
420
|
+
`from people count` is a parse error that points at the directive form. A real
|
|
421
|
+
reduction is a directive:
|
|
338
422
|
|
|
339
423
|
```js
|
|
340
424
|
oqx`${people} exists { where active }`; // true
|
|
@@ -342,8 +426,11 @@ oqx`${people} count { where active }`; // 2
|
|
|
342
426
|
oqx`${people} first { name where age > 50 }`; // { name: "Alice" }
|
|
343
427
|
```
|
|
344
428
|
|
|
345
|
-
(
|
|
346
|
-
|
|
429
|
+
(A consumer block follows the same clause grammar as the top level, with `from`
|
|
430
|
+
optional. A leading bare identifier **projects** — `count { active }` selects a
|
|
431
|
+
field named `active`; write `count { where active }` to filter, and always write
|
|
432
|
+
`where` before a predicate: `exists { !end }` is an error, `exists { where !end }`
|
|
433
|
+
is the test.)
|
|
347
434
|
|
|
348
435
|
### 6. Nested collections and relations
|
|
349
436
|
|
|
@@ -354,7 +441,7 @@ In `where`, an `exists { … }` tests non-emptiness and `count { … } <op> N` c
|
|
|
354
441
|
cardinality:
|
|
355
442
|
|
|
356
443
|
```js
|
|
357
|
-
oqx`name from ${people} where jobs exists { !end }`; // has a current job → Bob, Carol
|
|
444
|
+
oqx`name from ${people} where jobs exists { where !end }`; // has a current job → Bob, Carol
|
|
358
445
|
oqx`name from ${people} where jobs count {} >= 2`; // ≥2 jobs → Bob, Alice
|
|
359
446
|
oqx`name from ${people} where jobs none { where end }`; // no past job → Carol
|
|
360
447
|
```
|
|
@@ -384,7 +471,7 @@ counts and collections are over distinct projections rather than raw rows. Spell
|
|
|
384
471
|
it after the consumer (`count distinct { … }`) or inside via `select distinct`:
|
|
385
472
|
|
|
386
473
|
```js
|
|
387
|
-
oqx`from ${jobs}
|
|
474
|
+
oqx`select distinct employer from ${jobs}`; // distinct employers
|
|
388
475
|
oqx`n: jobs collect distinct { select employer } from ${people}`; // per person, unique employers
|
|
389
476
|
oqx`name from ${people} where jobs count distinct { select employer } == 1`; // worked at exactly one employer
|
|
390
477
|
```
|
|
@@ -437,7 +524,9 @@ fully), not a short-circuiting `exists`.
|
|
|
437
524
|
### 8. Ordering
|
|
438
525
|
|
|
439
526
|
`order by <expr> [asc|desc]`, comma-separated for tie-breaks. Absent values sort
|
|
440
|
-
last.
|
|
527
|
+
last. The sort expression reads the row (fields, `$value`, recursion
|
|
528
|
+
intrinsics) — it is not rewritten against the `select` aliases, so
|
|
529
|
+
`order by decade` sorts by a field called `decade`, not by `decade: age / 10`.
|
|
441
530
|
|
|
442
531
|
```js
|
|
443
532
|
oqx`name from ${people} where city == "NYC" order by age desc`;
|
|
@@ -456,7 +545,7 @@ inside `{ … }`; it must be a non-negative integer.
|
|
|
456
545
|
|
|
457
546
|
```js
|
|
458
547
|
oqx`name values from ${people} order by age desc limit 2`; // ["Alice", "Bob"]
|
|
459
|
-
oqx`name values from ${people} order by age desc
|
|
548
|
+
oqx`name values from ${people} order by age desc limit 1 offset 1`; // ["Bob"]
|
|
460
549
|
oqx`name, latest: jobs collect { employer values order by start desc limit 1 } from ${people}`;
|
|
461
550
|
oqx`name from ${people} where jobs exists { offset 1 }`; // has a second job
|
|
462
551
|
```
|
|
@@ -495,8 +584,14 @@ oqx`id, stop: $stop from ${tree} follow children { depth 2 } order by $ordinal`;
|
|
|
495
584
|
```
|
|
496
585
|
|
|
497
586
|
The intrinsics belong to the reached row's own scope like any other name: inside
|
|
498
|
-
a nested block (`kids: children collect { … }`) a bare `$depth` is
|
|
499
|
-
|
|
587
|
+
a nested block (`kids: children collect { … }`) a bare `$depth` is the nested
|
|
588
|
+
row's own `$depth` property (absent unless the data carries one), and the
|
|
589
|
+
occurrence's depth is `^$depth`. The same holds everywhere the metadata is not
|
|
590
|
+
present — outside a `follow`, `$depth`/`$ordinal`/`$stop`/`$leaf`/`$frontier`
|
|
591
|
+
are ordinary property reads (a row `{ "$depth": 3 }` projects `3`), and `$key`
|
|
592
|
+
is likewise an ordinary property read outside an `entries()` scope. Where the
|
|
593
|
+
metadata exists it wins over a same-named property (language 0.13; before, the
|
|
594
|
+
six names read absent everywhere they were not metadata).
|
|
500
595
|
|
|
501
596
|
The walk is **per-path**: a node reached by N distinct paths yields N
|
|
502
597
|
occurrences, and revisiting an identity already on the current path is admitted
|
|
@@ -513,9 +608,11 @@ your relation returns fresh objects rather than shared references.
|
|
|
513
608
|
### Cheat-sheet
|
|
514
609
|
|
|
515
610
|
```
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
611
|
+
select … from … where … follow … order by … limit N offset N the fixed clause order (each at most once)
|
|
612
|
+
name, alias: expr, nested: rel collect { … } projection (`select` may be dropped only here, in first position)
|
|
613
|
+
from ${source} source collection (required at the top level)
|
|
614
|
+
where a == b && rel exists { where … } || !c predicate tree + nested ops (`where` is never implicit)
|
|
615
|
+
where alias `where` may use this body's select aliases (inlined; an alias shadows a field)
|
|
519
616
|
where rel none { … } zero rows (≡ !rel exists { … }; "all" = none over the complement)
|
|
520
617
|
where x in lo..hi / lo...hi / ..hi / lo.. range membership (incl. / excl. / open-ended)
|
|
521
618
|
where x in range(field) coerce a string field to a range, then test coverage
|
|
@@ -699,14 +796,23 @@ adapter lives on the `@omgbase/oqx/sqlite` subpath.
|
|
|
699
796
|
- `InMemoryEngine` — `new InMemoryEngine(context?)`; the reference engine over a
|
|
700
797
|
`DataContext` (tier 1/2).
|
|
701
798
|
- `DataContext` — the tier-2 interface: `root`, `get`, `toRows`, `identity`,
|
|
702
|
-
plus optional `callFunction` / `callMethod` (above)
|
|
799
|
+
plus optional `callFunction` / `callMethod` (above) and an optional
|
|
800
|
+
`regexDialect` (`"oqx"` default | `"native"`). The engine dispatches
|
|
801
|
+
`matches` through `callMethod`, so a custom context that wants the native
|
|
802
|
+
dialect answers `matches` itself with `semantics.regexMatches(recv, args,
|
|
803
|
+
"native")`; `BUILTIN_METHODS.matches` is always the baseline.
|
|
703
804
|
- `CallResult` — `{ handled: boolean; value?: unknown }`, returned by those hooks.
|
|
704
|
-
- `DefaultContext` — `new DefaultContext(roots?)`; plain-object
|
|
705
|
-
identity, and the builtin function/method tables.
|
|
805
|
+
- `DefaultContext` — `new DefaultContext(roots?, options?)`; plain-object
|
|
806
|
+
access, `.id` identity, and the builtin function/method tables. `options`:
|
|
807
|
+
`{ regexDialect?: RegexDialect }` (see the regex baseline, §4).
|
|
808
|
+
- `compileRegex(pattern, flags?, dialect?)` — the `matches()` compiler: a
|
|
809
|
+
`RegExp`, or an `OqxError` for a bad pattern/flag. `RegexDialect` /
|
|
810
|
+
`RegexFlags` are the types.
|
|
706
811
|
- `semantics` — the scalar-contract module (`equals`, `relate`, `arith`,
|
|
707
812
|
`membership`, `truthy`, `compareForSort`, `sizeOf`, `toList`,
|
|
708
813
|
`coerceCollection`, ranges: `makeRange` / `isRange` / `rangeCovers` /
|
|
709
|
-
`parseRangeString`, entries: `makeEntry` / `isEntry` / `entriesOf`,
|
|
814
|
+
`parseRangeString`, entries: `makeEntry` / `isEntry` / `entriesOf`, regex:
|
|
815
|
+
`compileRegex` / `regexMatches` / `parseRegexFlags`, and the
|
|
710
816
|
`BUILTIN_FUNCTIONS` / `BUILTIN_METHODS` tables). A backend reproducing a rule
|
|
711
817
|
natively must match these.
|
|
712
818
|
|
package/dist/context.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RegexDialect } from "./regex.js";
|
|
1
2
|
/** Result of a context-provided function/method call: `handled: false` tells the
|
|
2
3
|
* engine to fall back to the builtin table (or error if none). */
|
|
3
4
|
export interface CallResult {
|
|
@@ -10,7 +11,9 @@ export interface DataContext {
|
|
|
10
11
|
/** Read a property/relation off a row: a bare identifier (`field`), a
|
|
11
12
|
* `.field` segment, or a `^field` outer reference all come through here, each
|
|
12
13
|
* against exactly the row of the scope it names. An absent property is
|
|
13
|
-
* `undefined`; the engine never looks elsewhere for it.
|
|
14
|
+
* `undefined`; the engine never looks elsewhere for it. A context may throw
|
|
15
|
+
* (an `OqxError` with stage `"eval"`, or any error) to reject a read — a
|
|
16
|
+
* reserved name, a failed store read — and the throw is the query's error. */
|
|
14
17
|
get(row: unknown, key: string): unknown;
|
|
15
18
|
/** Coerce a relation/source value into rows (may be lazy). */
|
|
16
19
|
toRows(value: unknown): Iterable<unknown>;
|
|
@@ -20,13 +23,27 @@ export interface DataContext {
|
|
|
20
23
|
callFunction?(name: string, args: unknown[]): CallResult;
|
|
21
24
|
/** Optional custom method; return `{ handled: false }` to defer. */
|
|
22
25
|
callMethod?(name: string, recv: unknown, args: unknown[]): CallResult;
|
|
26
|
+
/** The regex dialect `matches()` compiles against. `"oqx"` (the default when
|
|
27
|
+
* absent) is the portable baseline the spec tests; `"native"` hands the
|
|
28
|
+
* pattern to the host `RegExp` unvalidated — implementation-defined, not
|
|
29
|
+
* portable. Note the engine dispatches `matches` through `callMethod`, so
|
|
30
|
+
* this is read by the context's own `matches` (`DefaultContext` does;
|
|
31
|
+
* `regexMatches(recv, args, dialect)` is the helper). `BUILTIN_METHODS.matches`
|
|
32
|
+
* is always the baseline. */
|
|
33
|
+
readonly regexDialect?: RegexDialect;
|
|
34
|
+
}
|
|
35
|
+
export interface DefaultContextOptions {
|
|
36
|
+
/** See `DataContext.regexDialect`. Default `"oqx"`. */
|
|
37
|
+
regexDialect?: RegexDialect;
|
|
23
38
|
}
|
|
24
39
|
/** The default context: ordinary JavaScript objects. Named roots come from a
|
|
25
|
-
* plain `{ name: collection }` map; properties are
|
|
26
|
-
*
|
|
40
|
+
* plain `{ name: collection }` map; properties are OWN keys only (an array
|
|
41
|
+
* exposes only its integer indices, a primitive has none); identity is `.id`
|
|
42
|
+
* when present, else the row itself (the engine keys it structurally). */
|
|
27
43
|
export declare class DefaultContext implements DataContext {
|
|
28
44
|
private roots;
|
|
29
|
-
|
|
45
|
+
readonly regexDialect: RegexDialect;
|
|
46
|
+
constructor(roots?: Record<string, unknown>, options?: DefaultContextOptions);
|
|
30
47
|
root(name: string): unknown;
|
|
31
48
|
get(row: unknown, key: string): unknown;
|
|
32
49
|
toRows(value: unknown): Iterable<unknown>;
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY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KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IAIzC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO;IAK/B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU;IAKvD,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU;CAKrE"}
|
package/dist/context.js
CHANGED
|
@@ -7,22 +7,32 @@
|
|
|
7
7
|
//
|
|
8
8
|
// (Performant execution over a real store is the tier-3 seam — see planner.ts —
|
|
9
9
|
// which pushes work into the store instead of driving it row-by-row here.)
|
|
10
|
-
import { coerceCollection, BUILTIN_FUNCTIONS, BUILTIN_METHODS } from "./semantics.js";
|
|
10
|
+
import { coerceCollection, regexMatches, BUILTIN_FUNCTIONS, BUILTIN_METHODS } from "./semantics.js";
|
|
11
|
+
// An array's only properties are its integer indices, spelled canonically
|
|
12
|
+
// (`"0"`, `"12"`; never `"01"`, `"length"`, or a method name).
|
|
13
|
+
function isIndexKey(key) {
|
|
14
|
+
return /^(0|[1-9]\d*)$/.test(key);
|
|
15
|
+
}
|
|
11
16
|
/** The default context: ordinary JavaScript objects. Named roots come from a
|
|
12
|
-
* plain `{ name: collection }` map; properties are
|
|
13
|
-
*
|
|
17
|
+
* plain `{ name: collection }` map; properties are OWN keys only (an array
|
|
18
|
+
* exposes only its integer indices, a primitive has none); identity is `.id`
|
|
19
|
+
* when present, else the row itself (the engine keys it structurally). */
|
|
14
20
|
export class DefaultContext {
|
|
15
21
|
roots;
|
|
16
|
-
|
|
22
|
+
regexDialect;
|
|
23
|
+
constructor(roots = {}, options = {}) {
|
|
17
24
|
this.roots = roots;
|
|
25
|
+
this.regexDialect = options.regexDialect ?? "oqx";
|
|
18
26
|
}
|
|
19
27
|
root(name) {
|
|
20
|
-
return this.roots[name];
|
|
28
|
+
return Object.hasOwn(this.roots, name) ? this.roots[name] : undefined;
|
|
21
29
|
}
|
|
22
30
|
get(row, key) {
|
|
23
|
-
if (row == null)
|
|
31
|
+
if (row == null || typeof row !== "object")
|
|
24
32
|
return undefined;
|
|
25
|
-
|
|
33
|
+
if (Array.isArray(row))
|
|
34
|
+
return isIndexKey(key) ? row[Number(key)] : undefined;
|
|
35
|
+
return Object.hasOwn(row, key) ? row[key] : undefined;
|
|
26
36
|
}
|
|
27
37
|
toRows(value) {
|
|
28
38
|
return coerceCollection(value);
|
|
@@ -33,11 +43,13 @@ export class DefaultContext {
|
|
|
33
43
|
return row;
|
|
34
44
|
}
|
|
35
45
|
callFunction(name, args) {
|
|
36
|
-
const fn = BUILTIN_FUNCTIONS[name];
|
|
46
|
+
const fn = Object.hasOwn(BUILTIN_FUNCTIONS, name) ? BUILTIN_FUNCTIONS[name] : undefined;
|
|
37
47
|
return fn ? { handled: true, value: fn(args) } : { handled: false };
|
|
38
48
|
}
|
|
39
49
|
callMethod(name, recv, args) {
|
|
40
|
-
|
|
50
|
+
if (name === "matches")
|
|
51
|
+
return { handled: true, value: regexMatches(recv, args, this.regexDialect) };
|
|
52
|
+
const fn = Object.hasOwn(BUILTIN_METHODS, name) ? BUILTIN_METHODS[name] : undefined;
|
|
41
53
|
return fn ? { handled: true, value: fn(recv, args) } : { handled: false };
|
|
42
54
|
}
|
|
43
55
|
}
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAChF,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,EAAE;AACF,gFAAgF;AAChF,2EAA2E;AAE3E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"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