@wazootech/sparql-engine 0.0.0-stage → 0.5.8

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.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Vendored SPARQL parser — maintained by this project.
3
+ *
4
+ * The runtime parser is a pure ESM/TypeScript module (`parser.ts`) generated
5
+ * from the in-repo jison grammar (`sparql.jison`), itself sparqljs 3.7.4's
6
+ * grammar extended with the SPARQL 1.2 surface upstream lacks — the four
7
+ * direction functions below and the RDF 1.2 triple-term/reifier/annotation
8
+ * forms (see README.md):
9
+ *
10
+ * - `LANGDIR(literal)` — arity 1
11
+ * - `hasLang(term)` — arity 1
12
+ * - `hasLangDir(term)` — arity 1
13
+ * - `STRLANGDIR(simpleLiteral, langTag, baseDirection)` — arity 3
14
+ *
15
+ * The grammar patch (see README.md) is in two parts: a lexer whitelist
16
+ * extension for the four direction functions (they join existing
17
+ * `FUNC_ARITYn` alternations, so the generated productions already construct
18
+ * `functionCall` nodes), and grammar productions for `<<( s p o )>>` data
19
+ * triple terms, `~` reifiers, `{| |}` annotated triples, standalone
20
+ * `<< s p o >>` reified-triple patterns, and object-level reifier and
21
+ * annotation clauses (`:s :p :o ~ r {| ... |}`).
22
+ *
23
+ * Term construction uses this project's internal zero-dependency DataFactory
24
+ * (`@/term/data-factory.ts`) instead of upstream's `rdf-data-factory`. The
25
+ * AST shapes are identical to upstream sparqljs — this module is a drop-in
26
+ * replacement for the `sparqljs` `Parser` export.
27
+ */
28
+ import { A as Quads, B as Triple, C as MinusPattern, D as PathElement, E as Ordering, F as SelectQuery, G as ValuePatternRow, H as UnionPattern, I as SelectSubQuery, J as VariableTerm, K as ValuesPattern, L as ServicePattern, M as Query, N as QueryModifiers, O as Pattern, P as ReifiedQuad, R as SparqlQuery, S as MembershipExpression, T as OptionalPattern, U as UpdateOperation, V as TriplePredicate, W as UpdateQuery, Y as Wildcard, _ as GraphRefAll, a as ClearDropOperation, b as InsertDeleteOperation, c as CreateOperation, d as Expression, f as FilterPattern, g as GraphPattern, h as GraphOrDefault, i as BindPattern, j as QuadsPattern, k as PropertyPath, l as DescribeQuery, m as FunctionCallExpression, n as AskQuery, o as ConstructQuery, p as FromClause, q as VariableExpression, r as BgpPattern, s as CopyMoveOperation, t as AggregateExpression, u as ExistsExpression, v as GroupPattern, w as OperationExpression, x as LoadOperation, y as Grouping, z as Term } from "./ast-CIKmrXH9.js";
29
+ import { n as SparqlSyntaxError, t as parseTurtleQuads } from "./turtle-parser-CzWF7KXf.js";
30
+ export interface SparqlParserOptions {
31
+ /** Pre-registered prefixes; the standard `xsd:` prefix is always included. */
32
+ prefixes?: Record<string, string>;
33
+ /** Base IRI for resolving relative IRIs in `IRI()` / triple terms. */
34
+ baseIRI?: string;
35
+ /** Enable RDF-star syntax (quoted triples, TRIPLE()/SUBJECT()/...). */
36
+ sparqlStar?: boolean;
37
+ /** Skip sparqljs validation checks (ungrouped-variable projection, ...). */
38
+ skipValidation?: boolean;
39
+ }
40
+ /**
41
+ * Extended SPARQL parser.
42
+ *
43
+ * Mirrors upstream sparqljs's `Parser` wrapper: each `parse` resets the typed
44
+ * parse context (base, prefixes, factory, SPARQL-star and validation options,
45
+ * see `sparql-context.ts`) before running the generated parser, whose
46
+ * semantic actions read that context.
47
+ */
48
+ export declare class Parser {
49
+ private readonly baseIri;
50
+ private readonly prefixTable;
51
+ private readonly sparqlStar;
52
+ private readonly skipValidation;
53
+ constructor(options?: SparqlParserOptions);
54
+ /**
55
+ * Parse a raw SPARQL query/update string into a sparqljs AST. The optional
56
+ * baseIRI is the base for relative IRIs when the query has no BASE
57
+ * directive (the directive wins when both are present).
58
+ */
59
+ parse(query: string, options?: {
60
+ baseIRI?: string;
61
+ }): SparqlQuery;
62
+ /** Reset the parser's blank-node label counter between parses. */
63
+ _resetBlanks(): void;
64
+ }
65
+ export { type AggregateExpression, type AskQuery, type BgpPattern, type BindPattern, type ClearDropOperation, type ConstructQuery, type CopyMoveOperation, type CreateOperation, type DescribeQuery, type ExistsExpression, type Expression, type FilterPattern, type FromClause, type FunctionCallExpression, type GraphOrDefault, type GraphPattern, type GraphRefAll, type GroupPattern, type Grouping, type InsertDeleteOperation, type LoadOperation, type MembershipExpression, type MinusPattern, type OperationExpression, type OptionalPattern, type Ordering, Parser as SparqlParser, type PathElement, type Pattern, type PropertyPath, type Quads, type QuadsPattern, type Query, type QueryModifiers, type ReifiedQuad, type SelectQuery, type SelectSubQuery, type ServicePattern, type SparqlQuery, SparqlSyntaxError, type Term, type Triple, type TriplePredicate, type UnionPattern, type UpdateOperation, type UpdateQuery, type ValuePatternRow, type ValuesPattern, type VariableExpression, type VariableTerm, type Wildcard, parseTurtleQuads };
package/dist/parser.js ADDED
@@ -0,0 +1 @@
1
+ export { t as Parser, t as SparqlParser, r as SparqlSyntaxError, n as parseTurtleQuads } from "./parser-CTZiNJfu.js";
@@ -0,0 +1,234 @@
1
+ import { l as RdfTerm, n as RdfLiteral } from "./rdf-terms-DGpxNnyn.js";
2
+ import { c as SparqlValue } from "./sparql-engine-interface-Bies9KjE.js";
3
+ import { z as Term } from "./ast-CIKmrXH9.js";
4
+ import * as rdfjs from "@rdfjs/types";
5
+ declare function termKey(term: RdfTerm): string;
6
+ /**
7
+ * sameRdfTerm compares two RDF/JS terms by type, value, and literal
8
+ * language/datatype. RDF-star triple terms are compared structurally on
9
+ * subject, predicate, and object — the graph is a property of the statement,
10
+ * not of the triple term, so it is not part of term identity.
11
+ */
12
+ declare function sameRdfTerm(a: RdfTerm, b: RdfTerm): boolean;
13
+ declare const RDF_LANG_STRING = "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString";
14
+ declare const RDF_DIR_LANG_STRING = "http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString";
15
+ /**
16
+ * sparqlTermToRdfTerm converts a sparqljs AST term to an RDF/JS term.
17
+ */
18
+ declare function sparqlTermToRdfTerm(term: Term): RdfTerm;
19
+ /**
20
+ * rdfTermToSparqlValue converts an RDF/JS term to a SparqlValue, the engine's
21
+ * result wire format. Plain string literals carry no datatype (xsd:string is
22
+ * implicit in SPARQL results); lang-tagged and typed literals carry their
23
+ * language or datatype.
24
+ */
25
+ declare function rdfTermToSparqlValue(term: RdfTerm): SparqlValue;
26
+ /**
27
+ * CanonicalTerm is a serialization-stable projection of an RDF term that is
28
+ * produced identically from Comunica terms, wazoo SparqlValue objects, and
29
+ * other RDF/JS-shaped terms such as Oxigraph's. Two terms canonicalize to the
30
+ * same CanonicalTerm exactly when they are the same RDF term.
31
+ */
32
+ type CanonicalTerm = {
33
+ termType: "NamedNode" | "BlankNode" | "Literal" | "DefaultGraph" | "Quad";
34
+ value: string;
35
+ language?: string;
36
+ direction?: string;
37
+ datatype?: string;
38
+ subject?: CanonicalTerm;
39
+ predicate?: CanonicalTerm;
40
+ object?: CanonicalTerm;
41
+ };
42
+ /**
43
+ * canonicalizeRdfTerm normalizes an RDF/JS-shaped term into a CanonicalTerm.
44
+ * Plain xsd:string literals drop their datatype (it is implicit), and
45
+ * RDF-star triple terms flatten to subject/predicate/object.
46
+ */
47
+ declare function canonicalizeRdfTerm(term: RdfTerm): CanonicalTerm;
48
+ /**
49
+ * canonicalizeSparqlValue normalizes a wazoo SparqlValue into a
50
+ * CanonicalTerm, so wazoo results compare structurally with RDF/JS-shaped
51
+ * results from other engines.
52
+ */
53
+ declare function canonicalizeSparqlValue(value: SparqlValue): CanonicalTerm;
54
+ /**
55
+ * XSD is the XML Schema datatype namespace IRI.
56
+ */
57
+ declare const XSD = "http://www.w3.org/2001/XMLSchema#";
58
+ /** XSD_STRING is the xsd:string datatype IRI. */
59
+ declare const XSD_STRING: string;
60
+ /** XSD_BOOLEAN is the xsd:boolean datatype IRI. */
61
+ declare const XSD_BOOLEAN: string;
62
+ /** XSD_INTEGER is the xsd:integer datatype IRI. */
63
+ declare const XSD_INTEGER: string;
64
+ /** XSD_DECIMAL is the xsd:decimal datatype IRI. */
65
+ declare const XSD_DECIMAL: string;
66
+ /** XSD_FLOAT is the xsd:float datatype IRI. */
67
+ declare const XSD_FLOAT: string;
68
+ /** XSD_DOUBLE is the xsd:double datatype IRI. */
69
+ declare const XSD_DOUBLE: string;
70
+ /** XSD_DATETIME is the xsd:dateTime datatype IRI. */
71
+ declare const XSD_DATETIME: string;
72
+ /** XSD_DAYTIME_DURATION is the xsd:dayTimeDuration datatype IRI. */
73
+ declare const XSD_DAYTIME_DURATION: string;
74
+ /**
75
+ * NUMERIC_DATATYPES is the set of XSD datatypes with numeric value semantics
76
+ * per SPARQL 1.1 §17.1, including the types derived from xsd:integer:
77
+ * comparisons and arithmetic operate on their values rather than their lexical
78
+ * forms.
79
+ */
80
+ declare const NUMERIC_DATATYPES: ReadonlySet<string>;
81
+ /**
82
+ * numberFromText parses a numeric lexical form as a JS number with the
83
+ * ToNumber semantics of `Number(text)`: surrounding whitespace is ignored,
84
+ * blank text is 0, and anything that is not a decimal, infinity, or
85
+ * radix-prefixed form is NaN. Every branch is statically typed, so the native
86
+ * compiler keeps it out of the dynamic tier (scriptc issues #221 and #247).
87
+ */
88
+ declare function numberFromText(text: string): number;
89
+ /**
90
+ * numberFromNumeric converts a numeric value to a JS number. A bigint goes
91
+ * through its exact decimal form, so the result keeps `Number(bigint)`
92
+ * rounding without the dynamic `Number()` constructor.
93
+ */
94
+ declare function numberFromNumeric(value: number | bigint): number;
95
+ /**
96
+ * numericValue extracts the numeric value of a literal, or null when it is
97
+ * not numeric or its lexical form is malformed. xsd:integer and its derived
98
+ * types parse with BigInt for exact arbitrary-precision arithmetic (a derived
99
+ * type's range is not enforced, as in Comunica); other numeric datatypes use JS
100
+ * number parsing.
101
+ */
102
+ declare function numericValue(term: RdfLiteral): number | bigint | null;
103
+ /**
104
+ * compareNumericValues orders two numeric values, comparing BigInt pairs
105
+ * exactly and everything else as Numbers. It returns NaN when either value is
106
+ * NaN, so every ordering operator answers false, as XPath requires.
107
+ */
108
+ declare function compareNumericValues(a: number | bigint, b: number | bigint): number;
109
+ /**
110
+ * numeric-format.ts renders numeric values as lexical forms.
111
+ */
112
+ /**
113
+ * formatNumber renders a numeric value's Number string form. No datatype
114
+ * padding is applied: like Comunica, decimal results use plain JS string
115
+ * forms (6/3 -> "2", not "2.0"). Double and float results keep the Number
116
+ * string form; canonicalDouble (used by the XSD constructors and the
117
+ * aggregates) produces the canonical XPath exponent form instead. Infinity and
118
+ * NaN take their XML Schema spellings.
119
+ */
120
+ declare function formatNumber(value: number, _datatype: string): string;
121
+ /**
122
+ * canonicalDouble renders a number in the canonical XPath double lexical
123
+ * form: a mantissa with at least one decimal digit and an exponent with no
124
+ * leading plus ("3.0E0", "1.5E0", "1.0E21", "INF", "-INF").
125
+ */
126
+ declare function canonicalDouble(n: number): string;
127
+ /**
128
+ * datetime.ts implements the xsd:dateTime value surface the SPARQL date/time
129
+ * functions (YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS, TIMEZONE) need:
130
+ * strict lexical parsing and the xsd:dayTimeDuration lexical form for
131
+ * timezone offsets.
132
+ */
133
+ /**
134
+ * DateTimeParts is the parsed component view of an xsd:dateTime literal.
135
+ */
136
+ interface DateTimeParts {
137
+ /** year is the (possibly negative) calendar year. */
138
+ year: number;
139
+ /** month is 1-12. */
140
+ month: number;
141
+ /** day is 1-31. */
142
+ day: number;
143
+ /** hours is 0-23. */
144
+ hours: number;
145
+ /** minutes is 0-59. */
146
+ minutes: number;
147
+ /** seconds includes any fractional part (13 or 13.815). */
148
+ seconds: number;
149
+ /** hasTimezone is false when the lexical form has no timezone. */
150
+ hasTimezone: boolean;
151
+ /** timezoneMinutes is the signed UTC offset in minutes (0 for Z). */
152
+ timezoneMinutes: number;
153
+ }
154
+ /**
155
+ * parseDateTime parses an xsd:dateTime lexical form into its components, or
156
+ * null when the form is malformed or out of range.
157
+ */
158
+ declare function parseDateTime(lexical: string): DateTimeParts | null;
159
+ /**
160
+ * timezoneDurationLexical renders a signed UTC offset in minutes as the
161
+ * canonical xsd:dayTimeDuration lexical form: "PT0S" for zero, "-PT5H" for
162
+ * -05:00, "PT5H30M" for +05:30.
163
+ */
164
+ declare function timezoneDurationLexical(offsetMinutes: number): string;
165
+ /**
166
+ * md5Hex returns the MD5 digest of the UTF-8 encoding of the input as
167
+ * lowercase hexadecimal.
168
+ */
169
+ declare function md5Hex(input: string): string;
170
+ /**
171
+ * sha1Hex returns the SHA-1 digest of the UTF-8 encoding of the input as
172
+ * lowercase hexadecimal.
173
+ */
174
+ declare function sha1Hex(input: string): string;
175
+ /**
176
+ * sha256Hex returns the SHA-256 digest of the UTF-8 encoding of the input as
177
+ * lowercase hexadecimal.
178
+ */
179
+ declare function sha256Hex(input: string): string;
180
+ /**
181
+ * sha384Hex returns the SHA-384 digest of the UTF-8 encoding of the input as
182
+ * lowercase hexadecimal.
183
+ */
184
+ declare function sha384Hex(input: string): string;
185
+ /**
186
+ * sha512Hex returns the SHA-512 digest of the UTF-8 encoding of the input as
187
+ * lowercase hexadecimal.
188
+ */
189
+ declare function sha512Hex(input: string): string;
190
+ /**
191
+ * compareRdfTerms orders two RDF terms (or undefined for an unbound
192
+ * variable) per SPARQL 1.1 §12.4: unbound sorts lowest, then blank nodes,
193
+ * then IRIs, then literals, then triple terms (per RDF 1.2's total order).
194
+ * Literals order by datatype IRI first (plain literals counting as
195
+ * xsd:string), numerically within the same numeric datatype, then by lexical
196
+ * form. Triple terms order lexicographically by subject, predicate, then
197
+ * object, recursively. Blank-node labels and the relative order of terms the
198
+ * spec leaves undefined are compared deterministically. Returns a negative,
199
+ * zero, or positive number suitable for Array.prototype.sort.
200
+ *
201
+ * Prior art: the ordering rules are SPARQL 1.1 §12.4 (ORDER BY), with the
202
+ * cross-datatype numeric comparisons following the XPath 2.0 value
203
+ * ordering the spec delegates to.
204
+ * @see {@link https://www.w3.org/TR/sparql11-query/ Harris & Seaborne (eds.), "SPARQL 1.1 Query Language," W3C Recommendation, 2013}
205
+ * @see {@link https://www.w3.org/TR/2010/REC-xpath-functions-20101214/ Malhotra, Melton & Walsh (eds.), "XQuery 1.0 and XPath 2.0 Functions and Operators (Second Edition)," W3C Recommendation, 2010}
206
+ */
207
+ declare function compareRdfTerms(a: RdfTerm | undefined, b: RdfTerm | undefined): number;
208
+ /**
209
+ * InternalDataFactory is the public, RDF/JS-typed view of the engine's
210
+ * DataFactory. The engine builds terms with the local term types (the
211
+ * `Rdf*` interfaces in `parser/rdf-terms.ts`), which are structurally
212
+ * identical to `@rdfjs/types`; this module is the type-only boundary that
213
+ * presents them to consumers as `@rdfjs/types` (including the generic
214
+ * `NamedNode<Iri>` and the `fromTerm` overloads). It is the only place where
215
+ * the factory is cast, and nothing inside the engine imports it.
216
+ */
217
+ interface InternalDataFactory extends rdfjs.DataFactory {
218
+ namedNode<Iri extends string = string>(value: Iri): rdfjs.NamedNode<Iri>;
219
+ blankNode(value?: string): rdfjs.BlankNode;
220
+ literal(value: string, languageOrDatatype?: string | rdfjs.NamedNode | rdfjs.DirectionalLanguage): rdfjs.Literal;
221
+ variable(value: string): rdfjs.Variable;
222
+ defaultGraph(): rdfjs.DefaultGraph;
223
+ quad(subject: rdfjs.Term, predicate: rdfjs.Term, object: rdfjs.Term, graph?: rdfjs.Term): rdfjs.Quad;
224
+ fromTerm(original: rdfjs.NamedNode): rdfjs.NamedNode;
225
+ fromTerm(original: rdfjs.BlankNode): rdfjs.BlankNode;
226
+ fromTerm(original: rdfjs.Literal): rdfjs.Literal;
227
+ fromTerm(original: rdfjs.Variable): rdfjs.Variable;
228
+ fromTerm(original: rdfjs.DefaultGraph): rdfjs.DefaultGraph;
229
+ fromTerm(original: rdfjs.BaseQuad): rdfjs.Quad;
230
+ fromQuad(original: rdfjs.Quad): rdfjs.Quad;
231
+ }
232
+ declare const DataFactory: InternalDataFactory;
233
+ declare const dataFactory: InternalDataFactory;
234
+ export { canonicalizeRdfTerm as A, XSD_INTEGER as C, numberFromText as D, numberFromNumeric as E, RDF_LANG_STRING as F, sameRdfTerm as I, termKey as L, rdfTermToSparqlValue as M, sparqlTermToRdfTerm as N, numericValue as O, RDF_DIR_LANG_STRING as P, XSD_FLOAT as S, compareNumericValues as T, XSD_BOOLEAN as _, sha384Hex as a, XSD_DECIMAL as b, sha1Hex as c, parseDateTime as d, timezoneDurationLexical as f, XSD as g, NUMERIC_DATATYPES as h, compareRdfTerms as i, canonicalizeSparqlValue as j, CanonicalTerm as k, md5Hex as l, formatNumber as m, InternalDataFactory as n, sha512Hex as o, canonicalDouble as p, dataFactory as r, sha256Hex as s, DataFactory as t, DateTimeParts as u, XSD_DATETIME as v, XSD_STRING as w, XSD_DOUBLE as x, XSD_DAYTIME_DURATION as y };