@comunica/utils-expression-evaluator 3.2.4-alpha.47.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/LICENSE.txt +22 -0
- package/README.md +102 -0
- package/lib/expressions/Aggregate.d.ts +9 -0
- package/lib/expressions/Aggregate.js +13 -0
- package/lib/expressions/Aggregate.js.map +1 -0
- package/lib/expressions/Existence.d.ts +8 -0
- package/lib/expressions/Existence.js +12 -0
- package/lib/expressions/Existence.js.map +1 -0
- package/lib/expressions/Expressions.d.ts +2 -0
- package/lib/expressions/Expressions.js +11 -0
- package/lib/expressions/Expressions.js.map +1 -0
- package/lib/expressions/Operator.d.ts +9 -0
- package/lib/expressions/Operator.js +14 -0
- package/lib/expressions/Operator.js.map +1 -0
- package/lib/expressions/Term.d.ts +180 -0
- package/lib/expressions/Term.js +348 -0
- package/lib/expressions/Term.js.map +1 -0
- package/lib/expressions/Variable.d.ts +7 -0
- package/lib/expressions/Variable.js +12 -0
- package/lib/expressions/Variable.js.map +1 -0
- package/lib/expressions/index.d.ts +6 -0
- package/lib/expressions/index.js +23 -0
- package/lib/expressions/index.js.map +1 -0
- package/lib/functions/Helpers.d.ts +81 -0
- package/lib/functions/Helpers.js +218 -0
- package/lib/functions/Helpers.js.map +1 -0
- package/lib/functions/OverloadTree.d.ts +45 -0
- package/lib/functions/OverloadTree.js +196 -0
- package/lib/functions/OverloadTree.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +99 -0
- package/lib/index.js.map +1 -0
- package/lib/transformers/TermTransformer.d.ts +24 -0
- package/lib/transformers/TermTransformer.js +133 -0
- package/lib/transformers/TermTransformer.js.map +1 -0
- package/lib/util/Consts.d.ts +136 -0
- package/lib/util/Consts.js +171 -0
- package/lib/util/Consts.js.map +1 -0
- package/lib/util/Context.d.ts +2 -0
- package/lib/util/Context.js +32 -0
- package/lib/util/Context.js.map +1 -0
- package/lib/util/DateTimeHelpers.d.ts +19 -0
- package/lib/util/DateTimeHelpers.js +166 -0
- package/lib/util/DateTimeHelpers.js.map +1 -0
- package/lib/util/Errors.d.ts +130 -0
- package/lib/util/Errors.js +194 -0
- package/lib/util/Errors.js.map +1 -0
- package/lib/util/Parsing.d.ts +25 -0
- package/lib/util/Parsing.js +166 -0
- package/lib/util/Parsing.js.map +1 -0
- package/lib/util/Serialization.d.ts +5 -0
- package/lib/util/Serialization.js +54 -0
- package/lib/util/Serialization.js.map +1 -0
- package/lib/util/SpecAlgos.d.ts +4 -0
- package/lib/util/SpecAlgos.js +81 -0
- package/lib/util/SpecAlgos.js.map +1 -0
- package/lib/util/TypeHandling.d.ts +56 -0
- package/lib/util/TypeHandling.js +216 -0
- package/lib/util/TypeHandling.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Consts.js","sourceRoot":"","sources":["Consts.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAI/C,IAAY,SAWX;AAXD,WAAY,SAAS;IACnB,0FAA0F;IAC1F,8CAAiC,CAAA;IACjC;;;;;;OAMG;IACH,gDAAmC,CAAA;AACrC,CAAC,EAXW,SAAS,yBAAT,SAAS,QAWpB;AAED,MAAM,EAAE,GAAG,IAAI,8BAAW,EAAE,CAAC;AAE7B,SAAgB,YAAY,CAAC,KAAa,EAAE,IAAa;IACvD,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/C,CAAC;AAFD,oCAEC;AAED,IAAY,OAyDX;AAzDD,WAAY,OAAO;IACjB,kEAAuD,CAAA;IACvD,iEAAsD,CAAA;IACtD,oFAAyE,CAAA;IAEzE,mEAAwD,CAAA;IAExD,sEAA2D,CAAA;IAC3D,iFAAsE,CAAA;IACtE,6DAAkD,CAAA;IAElD,kEAAuD,CAAA;IACvD,wEAA6D,CAAA;IAC7D,gEAAqD,CAAA;IACrD,2EAAgE,CAAA;IAChE,6D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mB;IACnB,mDAAmD;IACnD,iCAAe,CAAA;IACf,2BAAS,CAAA;IACT,uCAAqB,CAAA;AACvB,CAAC,EA3GW,cAAc,8BAAd,cAAc,QA2GzB","sourcesContent":["import type * as RDF from '@rdfjs/types';\nimport { DataFactory } from 'rdf-data-factory';\n\nexport type KnownLiteralTypes = TypeAlias | TypeURL;\n\nexport enum TypeAlias {\n // Numeric is everything defined in https://www.w3.org/TR/sparql11-query/#operandDataTypes\n SPARQL_NUMERIC = 'SPARQL_NUMERIC',\n /**\n * Stringly is everything defined in https://www.w3.org/TR/sparql11-query/#func-strings\n * In other words it is a simple literal, a plain literal with language tag, or a literal with datatype xsd:string\n * In other words, since utils-expression-evaluator transforms a simple literal to xsd_string.\n * It is RDF_LANG_STRING or XSD_STRING.\n * Reasons for this are mentioned here: w3c/sparql-12#112\n */\n SPARQL_STRINGLY = 'SPARQL_STRINGLY',\n}\n\nconst DF = new DataFactory();\n\nexport function typedLiteral(value: string, type: TypeURL): RDF.Literal {\n return DF.literal(value, DF.namedNode(type));\n}\n\nexport enum TypeURL {\n XSD_ANY_URI = 'http://www.w3.org/2001/XMLSchema#anyURI',\n XSD_STRING = 'http://www.w3.org/2001/XMLSchema#string',\n RDF_LANG_STRING = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString',\n\n XSD_BOOLEAN = 'http://www.w3.org/2001/XMLSchema#boolean',\n\n XSD_DATE_TIME = 'http://www.w3.org/2001/XMLSchema#dateTime',\n XSD_DATE_TIME_STAMP = 'http://www.w3.org/2001/XMLSchema#dateTimeStamp',\n XSD_DATE = 'http://www.w3.org/2001/XMLSchema#date',\n\n XSD_G_MONTH = 'http://www.w3.org/2001/XMLSchema#gMonth',\n XSD_G_MONTHDAY = 'http://www.w3.org/2001/XMLSchema#gMonthDay',\n XSD_G_YEAR = 'http://www.w3.org/2001/XMLSchema#gYear',\n XSD_G_YEAR_MONTH = 'http://www.w3.org/2001/XMLSchema#gYearMonth',\n XSD_TIME = 'http://www.w3.org/2001/XMLSchema#time',\n XSD_G_DAY = 'http://www.w3.org/2001/XMLSchema#gDay',\n\n // Numeric types\n XSD_DECIMAL = 'http://www.w3.org/2001/XMLSchema#decimal',\n XSD_FLOAT = 'http://www.w3.org/2001/XMLSchema#float',\n XSD_DOUBLE = 'http://www.w3.org/2001/XMLSchema#double',\n\n // Derived numeric types\n XSD_INTEGER = 'http://www.w3.org/2001/XMLSchema#integer',\n\n XSD_NON_POSITIVE_INTEGER = 'http://www.w3.org/2001/XMLSchema#nonPositiveInteger',\n XSD_NEGATIVE_INTEGER = 'http://www.w3.org/2001/XMLSchema#negativeInteger',\n\n XSD_LONG = 'http://www.w3.org/2001/XMLSchema#long',\n XSD_INT = 'http://www.w3.org/2001/XMLSchema#int',\n XSD_SHORT = 'http://www.w3.org/2001/XMLSchema#short',\n XSD_BYTE = 'http://www.w3.org/2001/XMLSchema#byte',\n\n XSD_NON_NEGATIVE_INTEGER = 'http://www.w3.org/2001/XMLSchema#nonNegativeInteger',\n XSD_POSITIVE_INTEGER = 'http://www.w3.org/2001/XMLSchema#positiveInteger',\n XSD_UNSIGNED_LONG = 'http://www.w3.org/2001/XMLSchema#unsignedLong',\n XSD_UNSIGNED_INT = 'http://www.w3.org/2001/XMLSchema#unsignedInt',\n XSD_UNSIGNED_SHORT = 'http://www.w3.org/2001/XMLSchema#unsignedShort',\n XSD_UNSIGNED_BYTE = 'http://www.w3.org/2001/XMLSchema#unsignedByte',\n\n // Derived String Type\n XSD_NORMALIZED_STRING = 'http://www.w3.org/2001/XMLSchema#normalizedString',\n XSD_TOKEN = 'http://www.w3.org/2001/XMLSchema#token',\n XSD_LANGUAGE = 'http://www.w3.org/2001/XMLSchema#language',\n XSD_NM_TOKEN = 'http://www.w3.org/2001/XMLSchema#NMTOKEN',\n\n XSD_NAME = 'http://www.w3.org/2001/XMLSchema#name',\n XSD_NC_NAME = 'http://www.w3.org/2001/XMLSchema#NCName',\n XSD_ENTITY = 'http://www.w3.org/2001/XMLSchema#ENTITY',\n XSD_ID = 'http://www.w3.org/2001/XMLSchema#ID',\n XSD_ID_REF = 'http://www.w3.org/2001/XMLSchema#IDREF',\n\n // Other types\n XSD_DURATION = 'http://www.w3.org/2001/XMLSchema#duration',\n XSD_YEAR_MONTH_DURATION = 'http://www.w3.org/2001/XMLSchema#yearMonthDuration',\n XSD_DAY_TIME_DURATION = 'http://www.w3.org/2001/XMLSchema#dayTimeDuration',\n}\n\n// ----------------------------------------------------------------------------\n// Operators\n// ----------------------------------------------------------------------------\n\nexport type GeneralOperator = KnownOperator | string;\n\nexport type KnownOperator = SparqlOperator | NamedOperator;\n\n// TODO: Remove unneeded double typing\nexport enum SparqlOperator {\n // Operator mapping\n // https://www.w3.org/TR/sparql11-query/#OperatorMapping\n NOT = '!',\n UMINUS = 'uminus',\n UPLUS = 'uplus',\n LOGICAL_OR = '||',\n LOGICAL_AND = '&&',\n\n EQUAL = '=',\n NOT_EQUAL = '!=',\n LT = '<',\n GT = '>',\n LTE = '<=',\n GTE = '>=',\n SAME_TERM = 'sameterm',\n IN = 'in',\n NOT_IN = 'notin',\n\n MULTIPLICATION = '*',\n DIVISION = '/',\n ADDITION = '+',\n SUBTRACTION = '-',\n\n // Functional Forms\n // https://www.w3.org/TR/sparql11-query/#func-forms\n // See SpecialOperators\n\n // Functions on RDF Terms\n // https://www.w3.org/TR/sparql11-query/#func-rdfTerms\n IS_IRI = 'isiri',\n IS_URI = 'isuri',\n IS_BLANK = 'isblank',\n IS_LITERAL = 'isliteral',\n IS_NUMERIC = 'isnumeric',\n STR = 'str',\n LANG = 'lang',\n DATATYPE = 'datatype',\n IRI = 'iri',\n URI = 'uri',\n BNODE = 'bnode',\n STRDT = 'strdt',\n STRLANG = 'strlang',\n UUID = 'uuid',\n STRUUID = 'struuid',\n\n // Functions on strings\n // https://www.w3.org/TR/sparql11-query/#func-strings\n STRLEN = 'strlen',\n SUBSTR = 'substr',\n UCASE = 'ucase',\n LCASE = 'lcase',\n STRSTARTS = 'strstarts',\n STRENDS = 'strends',\n CONTAINS = 'contains',\n STRBEFORE = 'strbefore',\n STRAFTER = 'strafter',\n ENCODE_FOR_URI = 'encode_for_uri',\n CONCAT = 'concat',\n LANG_MATCHES = 'langmatches',\n REGEX = 'regex',\n REPLACE = 'replace',\n\n // Functions on numerics\n // https://www.w3.org/TR/sparql11-query/#func-numerics\n ABS = 'abs',\n ROUND = 'round',\n CEIL = 'ceil',\n FLOOR = 'floor',\n RAND = 'rand',\n\n // Functions on Dates and Times\n // https://www.w3.org/TR/sparql11-query/#func-date-time\n NOW = 'now',\n YEAR = 'year',\n MONTH = 'month',\n DAY = 'day',\n HOURS = 'hours',\n MINUTES = 'minutes',\n SECONDS = 'seconds',\n TIMEZONE = 'timezone',\n TZ = 'tz',\n // Hash functions\n // https://www.w3.org/TR/sparql11-query/#func-hash\n MD5 = 'md5',\n SHA1 = 'sha1',\n SHA256 = 'sha256',\n SHA384 = 'sha384',\n SHA512 = 'sha512',\n\n // XPath Constructor functions\n // https://www.w3.org/TR/sparql11-query/#FunctionMapping\n // See Named Operators\n\n // Functions for quoted triples\n // https://w3c.github.io/rdf-star/cg-spec/editors_draft.html#triple-function\n TRIPLE = 'triple',\n SUBJECT = 'subject',\n PREDICATE = 'predicate',\n OBJECT = 'object',\n IS_TRIPLE = 'istriple',\n\n // Functional Forms\n // https://www.w3.org/TR/sparql11-query/#func-forms\n BOUND = 'bound',\n IF = 'if',\n COALESCE = 'coalesce',\n}\n\nexport type NamedOperator =\n // XPath Constructor functions\n // https://www.w3.org/TR/sparql11-query/#FunctionMapping\n TypeURL.XSD_STRING\n | TypeURL.XSD_FLOAT\n | TypeURL.XSD_DOUBLE\n | TypeURL.XSD_DECIMAL\n | TypeURL.XSD_INTEGER\n | TypeURL.XSD_DATE_TIME\n | TypeURL.XSD_DATE\n | TypeURL.XSD_BOOLEAN\n | TypeURL.XSD_TIME\n | TypeURL.XSD_DURATION\n | TypeURL.XSD_DAY_TIME_DURATION\n | TypeURL.XSD_YEAR_MONTH_DURATION;\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareEvaluatorActionContext = void 0;
|
|
4
|
+
const context_entries_1 = require("@comunica/context-entries");
|
|
5
|
+
const lru_cache_1 = require("lru-cache");
|
|
6
|
+
const DateTimeHelpers_1 = require("./DateTimeHelpers");
|
|
7
|
+
function prepareEvaluatorActionContext(orgContext) {
|
|
8
|
+
let context = orgContext;
|
|
9
|
+
// Handle two variants of providing extension functions
|
|
10
|
+
if (context.has(context_entries_1.KeysInitQuery.extensionFunctionCreator) && context.has(context_entries_1.KeysInitQuery.extensionFunctions)) {
|
|
11
|
+
throw new Error('Illegal simultaneous usage of extensionFunctionCreator and extensionFunctions in context');
|
|
12
|
+
}
|
|
13
|
+
if (context.has(context_entries_1.KeysInitQuery.extensionFunctionCreator)) {
|
|
14
|
+
context = context.set(context_entries_1.KeysExpressionEvaluator.extensionFunctionCreator, context.get(context_entries_1.KeysInitQuery.extensionFunctionCreator));
|
|
15
|
+
}
|
|
16
|
+
else if (context.has(context_entries_1.KeysInitQuery.extensionFunctions)) {
|
|
17
|
+
const extensionFunctions = context.getSafe(context_entries_1.KeysInitQuery.extensionFunctions);
|
|
18
|
+
context = context.set(context_entries_1.KeysExpressionEvaluator.extensionFunctionCreator, async (functionNamedNode) => extensionFunctions[functionNamedNode.value]);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
22
|
+
context = context.setDefault(context_entries_1.KeysExpressionEvaluator.extensionFunctionCreator, async () => undefined);
|
|
23
|
+
}
|
|
24
|
+
context = context.setDefault(context_entries_1.KeysExpressionEvaluator.defaultTimeZone, (0, DateTimeHelpers_1.extractTimeZone)(context.getSafe(context_entries_1.KeysInitQuery.queryTimestamp)));
|
|
25
|
+
context = context.setDefault(context_entries_1.KeysExpressionEvaluator.superTypeProvider, {
|
|
26
|
+
cache: new lru_cache_1.LRUCache({ max: 1_000 }),
|
|
27
|
+
discoverer: () => 'term',
|
|
28
|
+
});
|
|
29
|
+
return context;
|
|
30
|
+
}
|
|
31
|
+
exports.prepareEvaluatorActionContext = prepareEvaluatorActionContext;
|
|
32
|
+
//# sourceMappingURL=Context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["Context.ts"],"names":[],"mappings":";;;AAAA,+DAAmF;AAGnF,yCAAqC;AACrC,uDAAoD;AAEpD,SAAgB,6BAA6B,CAAC,UAA0B;IACtE,IAAI,OAAO,GAAG,UAAU,CAAC;IAEzB,uDAAuD;IACvD,IAAI,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,wBAAwB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzG,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAC;IAC9G,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,wBAAwB,CAAC,EAAE,CAAC;QACxD,OAAO,GAAG,OAAO,CAAC,GAAG,CACnB,yCAAuB,CAAC,wBAAwB,EAChD,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,wBAAwB,CAAC,CACpD,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzD,MAAM,kBAAkB,GAA2C,OAAO,CAAC,OAAO,CAChF,+BAAa,CAAC,kBAAkB,CACjC,CAAC;QACF,OAAO,GAAG,OAAO,CAAC,GAAG,CACnB,yCAAuB,CAAC,wBAAwB,EAChD,KAAK,EAAC,iBAAgC,EAAE,EAAE,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CACvF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,wDAAwD;QACxD,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,yCAAuB,CAAC,wBAAwB,EAAE,KAAK,IAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACvG,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,UAAU,CAC1B,yCAAuB,CAAC,eAAe,EACvC,IAAA,iCAAe,EAAC,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,cAAc,CAAC,CAAC,CAC/D,CAAC;IAEF,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,yCAAuB,CAAC,iBAAiB,EAAE;QACtE,KAAK,EAAE,IAAI,oBAAQ,CAA+B,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QACjE,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM;KACzB,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AApCD,sEAoCC","sourcesContent":["import { KeysExpressionEvaluator, KeysInitQuery } from '@comunica/context-entries';\nimport type { AsyncExtensionFunction, GeneralSuperTypeDict, IActionContext } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { LRUCache } from 'lru-cache';\nimport { extractTimeZone } from './DateTimeHelpers';\n\nexport function prepareEvaluatorActionContext(orgContext: IActionContext): IActionContext {\n let context = orgContext;\n\n // Handle two variants of providing extension functions\n if (context.has(KeysInitQuery.extensionFunctionCreator) && context.has(KeysInitQuery.extensionFunctions)) {\n throw new Error('Illegal simultaneous usage of extensionFunctionCreator and extensionFunctions in context');\n }\n if (context.has(KeysInitQuery.extensionFunctionCreator)) {\n context = context.set(\n KeysExpressionEvaluator.extensionFunctionCreator,\n context.get(KeysInitQuery.extensionFunctionCreator),\n );\n } else if (context.has(KeysInitQuery.extensionFunctions)) {\n const extensionFunctions: Record<string, AsyncExtensionFunction> = context.getSafe(\n KeysInitQuery.extensionFunctions,\n );\n context = context.set(\n KeysExpressionEvaluator.extensionFunctionCreator,\n async(functionNamedNode: RDF.NamedNode) => extensionFunctions[functionNamedNode.value],\n );\n } else {\n // eslint-disable-next-line unicorn/no-useless-undefined\n context = context.setDefault(KeysExpressionEvaluator.extensionFunctionCreator, async() => undefined);\n }\n\n context = context.setDefault(\n KeysExpressionEvaluator.defaultTimeZone,\n extractTimeZone(context.getSafe(KeysInitQuery.queryTimestamp)),\n );\n\n context = context.setDefault(KeysExpressionEvaluator.superTypeProvider, {\n cache: new LRUCache<string, GeneralSuperTypeDict>({ max: 1_000 }),\n discoverer: () => 'term',\n });\n\n return context;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IDateTimeRepresentation, IDayTimeDurationRepresentation, IDurationRepresentation, ITimeZoneRepresentation, IYearMonthDurationRepresentation } from '@comunica/types';
|
|
2
|
+
export declare function defaultedDayTimeDurationRepresentation(rep: Partial<IDayTimeDurationRepresentation>): IDayTimeDurationRepresentation;
|
|
3
|
+
export declare function defaultedYearMonthDurationRepresentation(rep: Partial<IYearMonthDurationRepresentation>): IYearMonthDurationRepresentation;
|
|
4
|
+
export declare function defaultedDurationRepresentation(rep: Partial<IDurationRepresentation>): IDurationRepresentation;
|
|
5
|
+
export declare function simplifyDurationRepresentation(rep: Partial<IDurationRepresentation>): Partial<IDurationRepresentation>;
|
|
6
|
+
export declare function defaultedDateTimeRepresentation(rep: Partial<IDateTimeRepresentation>): IDateTimeRepresentation;
|
|
7
|
+
export declare function toDateTimeRepresentation({ date, timeZone }: {
|
|
8
|
+
date: Date;
|
|
9
|
+
timeZone: ITimeZoneRepresentation;
|
|
10
|
+
}): IDateTimeRepresentation;
|
|
11
|
+
export declare function negateDuration(dur: Partial<IDurationRepresentation>): Partial<IDurationRepresentation>;
|
|
12
|
+
export declare function toJSDate(date: IDateTimeRepresentation): Date;
|
|
13
|
+
export declare function toUTCDate(date: Partial<IDateTimeRepresentation>, defaultTimezone: ITimeZoneRepresentation): Date;
|
|
14
|
+
export declare function trimToYearMonthDuration(dur: Partial<IDurationRepresentation>): Partial<IYearMonthDurationRepresentation>;
|
|
15
|
+
export declare function trimToDayTimeDuration(dur: Partial<IDurationRepresentation>): Partial<IDayTimeDurationRepresentation>;
|
|
16
|
+
export declare function yearMonthDurationsToMonths(dur: IYearMonthDurationRepresentation): number;
|
|
17
|
+
export declare function dayTimeDurationsToSeconds(dur: IDayTimeDurationRepresentation): number;
|
|
18
|
+
export declare function extractRawTimeZone(zoneContained: string): string;
|
|
19
|
+
export declare function extractTimeZone(date: Date): ITimeZoneRepresentation;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractTimeZone = exports.extractRawTimeZone = exports.dayTimeDurationsToSeconds = exports.yearMonthDurationsToMonths = exports.trimToDayTimeDuration = exports.trimToYearMonthDuration = exports.toUTCDate = exports.toJSDate = exports.negateDuration = exports.toDateTimeRepresentation = exports.defaultedDateTimeRepresentation = exports.simplifyDurationRepresentation = exports.defaultedDurationRepresentation = exports.defaultedYearMonthDurationRepresentation = exports.defaultedDayTimeDurationRepresentation = void 0;
|
|
4
|
+
// Important is to notice JS and XSD datatypes have different defaulted values
|
|
5
|
+
// | Field | Default in JS | Default in XSD_DayTime | Default in XSD_Duration |
|
|
6
|
+
// | Month | 0 | 1 | 0 |
|
|
7
|
+
// | Day | 1 | 1 | 0 |
|
|
8
|
+
function defaultedDayTimeDurationRepresentation(rep) {
|
|
9
|
+
return {
|
|
10
|
+
day: rep.day ?? 0,
|
|
11
|
+
hours: rep.hours ?? 0,
|
|
12
|
+
minutes: rep.minutes ?? 0,
|
|
13
|
+
seconds: rep.seconds ?? 0,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.defaultedDayTimeDurationRepresentation = defaultedDayTimeDurationRepresentation;
|
|
17
|
+
function defaultedYearMonthDurationRepresentation(rep) {
|
|
18
|
+
return {
|
|
19
|
+
year: rep.year ?? 0,
|
|
20
|
+
month: rep.month ?? 0,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.defaultedYearMonthDurationRepresentation = defaultedYearMonthDurationRepresentation;
|
|
24
|
+
function defaultedDurationRepresentation(rep) {
|
|
25
|
+
return {
|
|
26
|
+
...defaultedDayTimeDurationRepresentation(rep),
|
|
27
|
+
...defaultedYearMonthDurationRepresentation(rep),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.defaultedDurationRepresentation = defaultedDurationRepresentation;
|
|
31
|
+
function simplifyDurationRepresentation(rep) {
|
|
32
|
+
const temp = defaultedDurationRepresentation(rep);
|
|
33
|
+
const res = {};
|
|
34
|
+
// Simplify year part
|
|
35
|
+
const years = temp.year + Math.trunc(temp.month / 12);
|
|
36
|
+
if (years) {
|
|
37
|
+
res.year = years;
|
|
38
|
+
temp.month %= 12;
|
|
39
|
+
}
|
|
40
|
+
if (temp.month) {
|
|
41
|
+
res.month = temp.month;
|
|
42
|
+
}
|
|
43
|
+
// Simplify day part
|
|
44
|
+
const days = temp.day + Math.trunc(temp.hours / 24) +
|
|
45
|
+
Math.trunc(temp.minutes / (24 * 60)) + Math.trunc(temp.seconds / (24 * 60 * 60));
|
|
46
|
+
if (days) {
|
|
47
|
+
res.day = days;
|
|
48
|
+
temp.hours %= 24;
|
|
49
|
+
temp.minutes %= 24 * 60;
|
|
50
|
+
temp.seconds %= 24 * 60 * 60;
|
|
51
|
+
}
|
|
52
|
+
const hours = temp.hours + Math.trunc(temp.minutes / 60) +
|
|
53
|
+
Math.trunc(temp.seconds / (60 * 60));
|
|
54
|
+
if (hours) {
|
|
55
|
+
res.hours = hours;
|
|
56
|
+
temp.minutes %= 60;
|
|
57
|
+
temp.seconds %= 60 * 60;
|
|
58
|
+
}
|
|
59
|
+
const minutes = temp.minutes + Math.trunc(temp.seconds / 60);
|
|
60
|
+
if (minutes) {
|
|
61
|
+
res.minutes = minutes;
|
|
62
|
+
temp.seconds %= 60;
|
|
63
|
+
}
|
|
64
|
+
if (temp.seconds) {
|
|
65
|
+
res.seconds = temp.seconds;
|
|
66
|
+
}
|
|
67
|
+
return res;
|
|
68
|
+
}
|
|
69
|
+
exports.simplifyDurationRepresentation = simplifyDurationRepresentation;
|
|
70
|
+
function defaultedDateTimeRepresentation(rep) {
|
|
71
|
+
return {
|
|
72
|
+
...rep,
|
|
73
|
+
day: rep.day ?? 1,
|
|
74
|
+
hours: rep.hours ?? 0,
|
|
75
|
+
month: rep.month ?? 1,
|
|
76
|
+
year: rep.year ?? 0,
|
|
77
|
+
seconds: rep.seconds ?? 0,
|
|
78
|
+
minutes: rep.minutes ?? 0,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
exports.defaultedDateTimeRepresentation = defaultedDateTimeRepresentation;
|
|
82
|
+
function toDateTimeRepresentation({ date, timeZone }) {
|
|
83
|
+
return {
|
|
84
|
+
year: date.getFullYear(),
|
|
85
|
+
month: date.getMonth() + 1,
|
|
86
|
+
day: date.getDate(),
|
|
87
|
+
hours: date.getHours(),
|
|
88
|
+
minutes: date.getMinutes(),
|
|
89
|
+
seconds: date.getSeconds(),
|
|
90
|
+
zoneHours: timeZone.zoneHours,
|
|
91
|
+
zoneMinutes: timeZone.zoneMinutes,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.toDateTimeRepresentation = toDateTimeRepresentation;
|
|
95
|
+
function negateDuration(dur) {
|
|
96
|
+
return {
|
|
97
|
+
year: dur.year === undefined ? undefined : -1 * dur.year,
|
|
98
|
+
month: dur.month === undefined ? undefined : -1 * dur.month,
|
|
99
|
+
day: dur.day === undefined ? undefined : -1 * dur.day,
|
|
100
|
+
hours: dur.hours === undefined ? undefined : -1 * dur.hours,
|
|
101
|
+
minutes: dur.minutes === undefined ? undefined : -1 * dur.minutes,
|
|
102
|
+
seconds: dur.seconds === undefined ? undefined : -1 * dur.seconds,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
exports.negateDuration = negateDuration;
|
|
106
|
+
function toJSDate(date) {
|
|
107
|
+
// The given hours will be assumed to be local time.
|
|
108
|
+
const res = new Date(date.year, date.month - 1, date.day, date.hours, date.minutes, Math.trunc(date.seconds), (date.seconds % 1) * 1_000);
|
|
109
|
+
if (date.year >= 0 && date.year < 100) {
|
|
110
|
+
// Special rule of date has gone int action:
|
|
111
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#individual_date_and_time_component_values
|
|
112
|
+
const jumpDeltaOfDate = 1_900;
|
|
113
|
+
res.setFullYear(res.getFullYear() - jumpDeltaOfDate);
|
|
114
|
+
}
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
exports.toJSDate = toJSDate;
|
|
118
|
+
function toUTCDate(date, defaultTimezone) {
|
|
119
|
+
const localTime = toJSDate(defaultedDateTimeRepresentation(date));
|
|
120
|
+
// This date has been constructed in machine local time, now we alter it to become UTC and convert to correct timezone
|
|
121
|
+
// Correction needed from local machine timezone to UTC
|
|
122
|
+
const minutesCorrectionLocal = localTime.getTimezoneOffset();
|
|
123
|
+
// Correction needed from UTC to provided timeZone
|
|
124
|
+
const hourCorrectionUTC = date.zoneHours ?? defaultTimezone.zoneHours;
|
|
125
|
+
const minutesCorrectionUTC = date.zoneMinutes ?? defaultTimezone.zoneMinutes;
|
|
126
|
+
return new Date(localTime.getTime() - (minutesCorrectionLocal + hourCorrectionUTC * 60 + minutesCorrectionUTC) * 60 * 1_000);
|
|
127
|
+
}
|
|
128
|
+
exports.toUTCDate = toUTCDate;
|
|
129
|
+
function trimToYearMonthDuration(dur) {
|
|
130
|
+
return {
|
|
131
|
+
year: dur.year,
|
|
132
|
+
month: dur.month,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
exports.trimToYearMonthDuration = trimToYearMonthDuration;
|
|
136
|
+
function trimToDayTimeDuration(dur) {
|
|
137
|
+
return {
|
|
138
|
+
day: dur.day,
|
|
139
|
+
hours: dur.hours,
|
|
140
|
+
minutes: dur.minutes,
|
|
141
|
+
seconds: dur.seconds,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
exports.trimToDayTimeDuration = trimToDayTimeDuration;
|
|
145
|
+
function yearMonthDurationsToMonths(dur) {
|
|
146
|
+
return dur.year * 12 + dur.month;
|
|
147
|
+
}
|
|
148
|
+
exports.yearMonthDurationsToMonths = yearMonthDurationsToMonths;
|
|
149
|
+
function dayTimeDurationsToSeconds(dur) {
|
|
150
|
+
return (((dur.day * 24) + dur.hours) * 60 + dur.minutes) * 60 + dur.seconds;
|
|
151
|
+
}
|
|
152
|
+
exports.dayTimeDurationsToSeconds = dayTimeDurationsToSeconds;
|
|
153
|
+
function extractRawTimeZone(zoneContained) {
|
|
154
|
+
const extraction = /(Z|([+-]\d\d:\d\d))?$/u.exec(zoneContained);
|
|
155
|
+
// It is safe to cast here because the empty string can always match.
|
|
156
|
+
return extraction[0];
|
|
157
|
+
}
|
|
158
|
+
exports.extractRawTimeZone = extractRawTimeZone;
|
|
159
|
+
function extractTimeZone(date) {
|
|
160
|
+
return {
|
|
161
|
+
zoneHours: date.getTimezoneOffset() / 60,
|
|
162
|
+
zoneMinutes: date.getTimezoneOffset() % 60,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
exports.extractTimeZone = extractTimeZone;
|
|
166
|
+
//# sourceMappingURL=DateTimeHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateTimeHelpers.js","sourceRoot":"","sources":["DateTimeHelpers.ts"],"names":[],"mappings":";;;AAQA,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAE/E,SAAgB,sCAAsC,CAAC,GAA4C;IAEjG,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;QACjB,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;QACrB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,CAAC;QACzB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,CAAC;KAC1B,CAAC;AACJ,CAAC;AARD,wFAQC;AAED,SAAgB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C","sourcesContent":["import type {\n IDateTimeRepresentation,\n IDayTimeDurationRepresentation,\n IDurationRepresentation,\n ITimeZoneRepresentation,\n IYearMonthDurationRepresentation,\n} from '@comunica/types';\n\n// Important is to notice JS and XSD datatypes have different defaulted values\n// | Field | Default in JS | Default in XSD_DayTime | Default in XSD_Duration |\n// | Month | 0 | 1 | 0 |\n// | Day | 1 | 1 | 0 |\n\nexport function defaultedDayTimeDurationRepresentation(rep: Partial<IDayTimeDurationRepresentation>):\nIDayTimeDurationRepresentation {\n return {\n day: rep.day ?? 0,\n hours: rep.hours ?? 0,\n minutes: rep.minutes ?? 0,\n seconds: rep.seconds ?? 0,\n };\n}\n\nexport function defaultedYearMonthDurationRepresentation(rep: Partial<IYearMonthDurationRepresentation>):\nIYearMonthDurationRepresentation {\n return {\n year: rep.year ?? 0,\n month: rep.month ?? 0,\n };\n}\n\nexport function defaultedDurationRepresentation(\n rep: Partial<IDurationRepresentation>,\n): IDurationRepresentation {\n return {\n ...defaultedDayTimeDurationRepresentation(rep),\n ...defaultedYearMonthDurationRepresentation(rep),\n };\n}\n\nexport function simplifyDurationRepresentation(rep: Partial<IDurationRepresentation>):\nPartial<IDurationRepresentation> {\n const temp = defaultedDurationRepresentation(rep);\n const res: Partial<IDurationRepresentation> = {};\n\n // Simplify year part\n const years = temp.year + Math.trunc(temp.month / 12);\n if (years) {\n res.year = years;\n temp.month %= 12;\n }\n if (temp.month) {\n res.month = temp.month;\n }\n\n // Simplify day part\n const days = temp.day + Math.trunc(temp.hours / 24) +\n Math.trunc(temp.minutes / (24 * 60)) + Math.trunc(temp.seconds / (24 * 60 * 60));\n if (days) {\n res.day = days;\n temp.hours %= 24;\n temp.minutes %= 24 * 60;\n temp.seconds %= 24 * 60 * 60;\n }\n const hours = temp.hours + Math.trunc(temp.minutes / 60) +\n Math.trunc(temp.seconds / (60 * 60));\n if (hours) {\n res.hours = hours;\n temp.minutes %= 60;\n temp.seconds %= 60 * 60;\n }\n const minutes = temp.minutes + Math.trunc(temp.seconds / 60);\n if (minutes) {\n res.minutes = minutes;\n temp.seconds %= 60;\n }\n if (temp.seconds) {\n res.seconds = temp.seconds;\n }\n return res;\n}\n\nexport function defaultedDateTimeRepresentation(rep: Partial<IDateTimeRepresentation>): IDateTimeRepresentation {\n return {\n ...rep,\n day: rep.day ?? 1,\n hours: rep.hours ?? 0,\n month: rep.month ?? 1,\n year: rep.year ?? 0,\n seconds: rep.seconds ?? 0,\n minutes: rep.minutes ?? 0,\n };\n}\n\nexport function toDateTimeRepresentation({ date, timeZone }:\n{ date: Date; timeZone: ITimeZoneRepresentation }): IDateTimeRepresentation {\n return {\n year: date.getFullYear(),\n month: date.getMonth() + 1,\n day: date.getDate(),\n hours: date.getHours(),\n minutes: date.getMinutes(),\n seconds: date.getSeconds(),\n zoneHours: timeZone.zoneHours,\n zoneMinutes: timeZone.zoneMinutes,\n };\n}\n\nexport function negateDuration(dur: Partial<IDurationRepresentation>): Partial<IDurationRepresentation> {\n return {\n year: dur.year === undefined ? undefined : -1 * dur.year,\n month: dur.month === undefined ? undefined : -1 * dur.month,\n day: dur.day === undefined ? undefined : -1 * dur.day,\n hours: dur.hours === undefined ? undefined : -1 * dur.hours,\n minutes: dur.minutes === undefined ? undefined : -1 * dur.minutes,\n seconds: dur.seconds === undefined ? undefined : -1 * dur.seconds,\n };\n}\n\nexport function toJSDate(date: IDateTimeRepresentation): Date {\n // The given hours will be assumed to be local time.\n const res = new Date(\n date.year,\n date.month - 1,\n date.day,\n date.hours,\n date.minutes,\n Math.trunc(date.seconds),\n (date.seconds % 1) * 1_000,\n );\n if (date.year >= 0 && date.year < 100) {\n // Special rule of date has gone int action:\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#individual_date_and_time_component_values\n\n const jumpDeltaOfDate = 1_900;\n res.setFullYear(res.getFullYear() - jumpDeltaOfDate);\n }\n return res;\n}\n\nexport function toUTCDate(date: Partial<IDateTimeRepresentation>, defaultTimezone: ITimeZoneRepresentation): Date {\n const localTime = toJSDate(defaultedDateTimeRepresentation(date));\n // This date has been constructed in machine local time, now we alter it to become UTC and convert to correct timezone\n\n // Correction needed from local machine timezone to UTC\n const minutesCorrectionLocal = localTime.getTimezoneOffset();\n // Correction needed from UTC to provided timeZone\n const hourCorrectionUTC = date.zoneHours ?? defaultTimezone.zoneHours;\n const minutesCorrectionUTC = date.zoneMinutes ?? defaultTimezone.zoneMinutes;\n return new Date(\n localTime.getTime() - (minutesCorrectionLocal + hourCorrectionUTC * 60 + minutesCorrectionUTC) * 60 * 1_000,\n );\n}\n\nexport function trimToYearMonthDuration(dur: Partial<IDurationRepresentation>):\nPartial<IYearMonthDurationRepresentation> {\n return {\n year: dur.year,\n month: dur.month,\n };\n}\n\nexport function trimToDayTimeDuration(dur: Partial<IDurationRepresentation>): Partial<IDayTimeDurationRepresentation> {\n return {\n day: dur.day,\n hours: dur.hours,\n minutes: dur.minutes,\n seconds: dur.seconds,\n };\n}\n\nexport function yearMonthDurationsToMonths(dur: IYearMonthDurationRepresentation): number {\n return dur.year * 12 + dur.month;\n}\n\nexport function dayTimeDurationsToSeconds(dur: IDayTimeDurationRepresentation): number {\n return (((dur.day * 24) + dur.hours) * 60 + dur.minutes) * 60 + dur.seconds;\n}\n\nexport function extractRawTimeZone(zoneContained: string): string {\n const extraction = /(Z|([+-]\\d\\d:\\d\\d))?$/u.exec(zoneContained);\n // It is safe to cast here because the empty string can always match.\n return extraction![0];\n}\n\nexport function extractTimeZone(date: Date): ITimeZoneRepresentation {\n return {\n zoneHours: date.getTimezoneOffset() / 60,\n zoneMinutes: date.getTimezoneOffset() % 60,\n };\n}\n"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Expression } from '@comunica/types';
|
|
2
|
+
import type * as RDF from '@rdfjs/types';
|
|
3
|
+
import type * as E from '../expressions';
|
|
4
|
+
import type * as C from './Consts';
|
|
5
|
+
/**
|
|
6
|
+
* This class of error will be thrown when an expression errors.
|
|
7
|
+
* Various reasons this could happen are:
|
|
8
|
+
* - invalid types for the given operator
|
|
9
|
+
* - unbound variables
|
|
10
|
+
* - invalid lexical forms
|
|
11
|
+
* - ...
|
|
12
|
+
*
|
|
13
|
+
* The distinction is made so that one can catch this specific type
|
|
14
|
+
* and handle it accordingly to the SPARQL spec (relevant for e.g. FILTER, EXTEND),
|
|
15
|
+
* while others (programming errors) can be re-thrown.
|
|
16
|
+
*
|
|
17
|
+
* @see isExpressionError
|
|
18
|
+
*/
|
|
19
|
+
export declare class ExpressionError extends Error {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether a given error is an {@link ExpressionError}.
|
|
23
|
+
* Also useful for mocking in tests for covering all branches.
|
|
24
|
+
*
|
|
25
|
+
* @see ExpressionError
|
|
26
|
+
*/
|
|
27
|
+
export declare function isExpressionError(error: Error): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* A literal has an invalid lexical form for the datatype it is accompanied by.
|
|
30
|
+
* This error is only thrown when the term is as function argument that requires
|
|
31
|
+
* a valid lexical form.
|
|
32
|
+
*/
|
|
33
|
+
export declare class InvalidLexicalForm extends ExpressionError {
|
|
34
|
+
arg: RDF.Term;
|
|
35
|
+
constructor(arg: RDF.Term);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A variable in the expression was not bound.
|
|
39
|
+
*/
|
|
40
|
+
export declare class UnboundVariableError extends ExpressionError {
|
|
41
|
+
variable: string;
|
|
42
|
+
bindings: RDF.Bindings;
|
|
43
|
+
constructor(variable: string, bindings: RDF.Bindings);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An invalid term was being coerced to an Effective Boolean Value.
|
|
47
|
+
*
|
|
48
|
+
* See the {@link https://www.w3.org/TR/sparql11-query/#ebv | SPARQL docs}
|
|
49
|
+
* on EBVs.
|
|
50
|
+
*/
|
|
51
|
+
export declare class EBVCoercionError extends ExpressionError {
|
|
52
|
+
arg: E.Term;
|
|
53
|
+
constructor(arg: E.Term);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* An equality test was done on literals with unsupported datatypes.
|
|
57
|
+
*
|
|
58
|
+
* See {@link https://www.w3.org/TR/sparql11-query/#func-RDFterm-equal | term equality spec}.
|
|
59
|
+
*/
|
|
60
|
+
export declare class RDFEqualTypeError extends ExpressionError {
|
|
61
|
+
args: Expression[];
|
|
62
|
+
constructor(args: Expression[]);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* All the expressions in a COALESCE call threw errors.
|
|
66
|
+
*/
|
|
67
|
+
export declare class CoalesceError extends ExpressionError {
|
|
68
|
+
errors: Error[];
|
|
69
|
+
constructor(errors: Error[]);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* No arguments to an IN call where equal, and at least one threw an error.
|
|
73
|
+
*/
|
|
74
|
+
export declare class InError extends ExpressionError {
|
|
75
|
+
errors: (Error | false)[];
|
|
76
|
+
constructor(errors: (Error | false)[]);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Literals were passed to an operator that doesn't support their datatypes.
|
|
80
|
+
*/
|
|
81
|
+
export declare class InvalidArgumentTypes extends ExpressionError {
|
|
82
|
+
args: Expression[];
|
|
83
|
+
op: C.GeneralOperator;
|
|
84
|
+
constructor(args: Expression[], op: C.GeneralOperator);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* An invalid typecast happened.
|
|
88
|
+
*/
|
|
89
|
+
export declare class CastError<T> extends ExpressionError {
|
|
90
|
+
arg: T;
|
|
91
|
+
constructor(arg: T, cast: C.TypeURL);
|
|
92
|
+
}
|
|
93
|
+
export declare class InvalidTimezoneCall extends ExpressionError {
|
|
94
|
+
dateString: string;
|
|
95
|
+
constructor(dateString: string);
|
|
96
|
+
}
|
|
97
|
+
export declare class IncompatibleLanguageOperation extends ExpressionError {
|
|
98
|
+
arg1: E.LangStringLiteral;
|
|
99
|
+
arg2: E.LangStringLiteral;
|
|
100
|
+
constructor(arg1: E.LangStringLiteral, arg2: E.LangStringLiteral);
|
|
101
|
+
}
|
|
102
|
+
export declare class EmptyAggregateError extends ExpressionError {
|
|
103
|
+
constructor();
|
|
104
|
+
}
|
|
105
|
+
export declare class ParseError extends ExpressionError {
|
|
106
|
+
constructor(str: string, type: string);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* An error that arises when we detect a 'should-be-impossible' state.
|
|
110
|
+
* Given that this error is thrown, it clearly wasn't impossible, and some
|
|
111
|
+
* mistake has been made.
|
|
112
|
+
*/
|
|
113
|
+
export declare class UnexpectedError<T> extends Error {
|
|
114
|
+
payload?: T | undefined;
|
|
115
|
+
constructor(message: string, payload?: T | undefined);
|
|
116
|
+
}
|
|
117
|
+
export declare class InvalidArity extends Error {
|
|
118
|
+
args: Expression[];
|
|
119
|
+
op: C.GeneralOperator;
|
|
120
|
+
constructor(args: Expression[], op: C.GeneralOperator);
|
|
121
|
+
}
|
|
122
|
+
export declare class InvalidExpression<T> extends Error {
|
|
123
|
+
constructor(expr: T);
|
|
124
|
+
}
|
|
125
|
+
export declare class ExtensionFunctionError extends Error {
|
|
126
|
+
constructor(name: string, functionError: unknown);
|
|
127
|
+
}
|
|
128
|
+
export declare class NoAggregator extends Error {
|
|
129
|
+
constructor(name?: string);
|
|
130
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoAggregator = exports.ExtensionFunctionError = exports.InvalidExpression = exports.InvalidArity = exports.UnexpectedError = exports.ParseError = exports.EmptyAggregateError = exports.IncompatibleLanguageOperation = exports.InvalidTimezoneCall = exports.CastError = exports.InvalidArgumentTypes = exports.InError = exports.CoalesceError = exports.RDFEqualTypeError = exports.EBVCoercionError = exports.UnboundVariableError = exports.InvalidLexicalForm = exports.isExpressionError = exports.ExpressionError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This class of error will be thrown when an expression errors.
|
|
6
|
+
* Various reasons this could happen are:
|
|
7
|
+
* - invalid types for the given operator
|
|
8
|
+
* - unbound variables
|
|
9
|
+
* - invalid lexical forms
|
|
10
|
+
* - ...
|
|
11
|
+
*
|
|
12
|
+
* The distinction is made so that one can catch this specific type
|
|
13
|
+
* and handle it accordingly to the SPARQL spec (relevant for e.g. FILTER, EXTEND),
|
|
14
|
+
* while others (programming errors) can be re-thrown.
|
|
15
|
+
*
|
|
16
|
+
* @see isExpressionError
|
|
17
|
+
*/
|
|
18
|
+
class ExpressionError extends Error {
|
|
19
|
+
}
|
|
20
|
+
exports.ExpressionError = ExpressionError;
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether a given error is an {@link ExpressionError}.
|
|
23
|
+
* Also useful for mocking in tests for covering all branches.
|
|
24
|
+
*
|
|
25
|
+
* @see ExpressionError
|
|
26
|
+
*/
|
|
27
|
+
function isExpressionError(error) {
|
|
28
|
+
return error instanceof ExpressionError;
|
|
29
|
+
}
|
|
30
|
+
exports.isExpressionError = isExpressionError;
|
|
31
|
+
/**
|
|
32
|
+
* A literal has an invalid lexical form for the datatype it is accompanied by.
|
|
33
|
+
* This error is only thrown when the term is as function argument that requires
|
|
34
|
+
* a valid lexical form.
|
|
35
|
+
*/
|
|
36
|
+
class InvalidLexicalForm extends ExpressionError {
|
|
37
|
+
constructor(arg) {
|
|
38
|
+
super(`Invalid lexical form '${pp(arg)}'`);
|
|
39
|
+
this.arg = arg;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.InvalidLexicalForm = InvalidLexicalForm;
|
|
43
|
+
/**
|
|
44
|
+
* A variable in the expression was not bound.
|
|
45
|
+
*/
|
|
46
|
+
class UnboundVariableError extends ExpressionError {
|
|
47
|
+
constructor(variable, bindings) {
|
|
48
|
+
super(`Unbound variable '${pp(variable)}'`);
|
|
49
|
+
this.variable = variable;
|
|
50
|
+
this.bindings = bindings;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.UnboundVariableError = UnboundVariableError;
|
|
54
|
+
/**
|
|
55
|
+
* An invalid term was being coerced to an Effective Boolean Value.
|
|
56
|
+
*
|
|
57
|
+
* See the {@link https://www.w3.org/TR/sparql11-query/#ebv | SPARQL docs}
|
|
58
|
+
* on EBVs.
|
|
59
|
+
*/
|
|
60
|
+
class EBVCoercionError extends ExpressionError {
|
|
61
|
+
constructor(arg) {
|
|
62
|
+
super(`Cannot coerce term to EBV '${pp(arg)}'`);
|
|
63
|
+
this.arg = arg;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.EBVCoercionError = EBVCoercionError;
|
|
67
|
+
/**
|
|
68
|
+
* An equality test was done on literals with unsupported datatypes.
|
|
69
|
+
*
|
|
70
|
+
* See {@link https://www.w3.org/TR/sparql11-query/#func-RDFterm-equal | term equality spec}.
|
|
71
|
+
*/
|
|
72
|
+
class RDFEqualTypeError extends ExpressionError {
|
|
73
|
+
constructor(args) {
|
|
74
|
+
super('Equality test for literals with unsupported datatypes');
|
|
75
|
+
this.args = args;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.RDFEqualTypeError = RDFEqualTypeError;
|
|
79
|
+
/**
|
|
80
|
+
* All the expressions in a COALESCE call threw errors.
|
|
81
|
+
*/
|
|
82
|
+
class CoalesceError extends ExpressionError {
|
|
83
|
+
constructor(errors) {
|
|
84
|
+
super('All COALESCE arguments threw errors');
|
|
85
|
+
this.errors = errors;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.CoalesceError = CoalesceError;
|
|
89
|
+
/**
|
|
90
|
+
* No arguments to an IN call where equal, and at least one threw an error.
|
|
91
|
+
*/
|
|
92
|
+
class InError extends ExpressionError {
|
|
93
|
+
constructor(errors) {
|
|
94
|
+
super(`Some argument to IN errorred and none where equal. ${errors.map(err => `(${err.toString()}) `).join('and ')}`);
|
|
95
|
+
this.errors = errors;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.InError = InError;
|
|
99
|
+
/**
|
|
100
|
+
* Literals were passed to an operator that doesn't support their datatypes.
|
|
101
|
+
*/
|
|
102
|
+
class InvalidArgumentTypes extends ExpressionError {
|
|
103
|
+
constructor(args, op) {
|
|
104
|
+
super(`Argument types not valid for operator: '${pp(op)}' with '${pp(args)}`);
|
|
105
|
+
this.args = args;
|
|
106
|
+
this.op = op;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.InvalidArgumentTypes = InvalidArgumentTypes;
|
|
110
|
+
/**
|
|
111
|
+
* An invalid typecast happened.
|
|
112
|
+
*/
|
|
113
|
+
class CastError extends ExpressionError {
|
|
114
|
+
constructor(arg, cast) {
|
|
115
|
+
super(`Invalid cast: '${pp(arg)}' to '${pp(cast)}'`);
|
|
116
|
+
this.arg = arg;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.CastError = CastError;
|
|
120
|
+
class InvalidTimezoneCall extends ExpressionError {
|
|
121
|
+
constructor(dateString) {
|
|
122
|
+
super(`TIMEZONE call on ${dateString} which has no timezone`);
|
|
123
|
+
this.dateString = dateString;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.InvalidTimezoneCall = InvalidTimezoneCall;
|
|
127
|
+
class IncompatibleLanguageOperation extends ExpressionError {
|
|
128
|
+
constructor(arg1, arg2) {
|
|
129
|
+
super(`Operation on incompatible language literals '${pp(arg1)}' and '${pp(arg2)}'`);
|
|
130
|
+
this.arg1 = arg1;
|
|
131
|
+
this.arg2 = arg2;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.IncompatibleLanguageOperation = IncompatibleLanguageOperation;
|
|
135
|
+
class EmptyAggregateError extends ExpressionError {
|
|
136
|
+
constructor() {
|
|
137
|
+
super('Empty aggregate expression');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.EmptyAggregateError = EmptyAggregateError;
|
|
141
|
+
class ParseError extends ExpressionError {
|
|
142
|
+
constructor(str, type) {
|
|
143
|
+
super(`Failed to parse "${str}" as ${type}.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.ParseError = ParseError;
|
|
147
|
+
// Non Expression Errors ------------------------------------------------------
|
|
148
|
+
/**
|
|
149
|
+
* An error that arises when we detect a 'should-be-impossible' state.
|
|
150
|
+
* Given that this error is thrown, it clearly wasn't impossible, and some
|
|
151
|
+
* mistake has been made.
|
|
152
|
+
*/
|
|
153
|
+
class UnexpectedError extends Error {
|
|
154
|
+
constructor(message, payload) {
|
|
155
|
+
super(`Programmer Error '${message}'`);
|
|
156
|
+
this.payload = payload;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.UnexpectedError = UnexpectedError;
|
|
160
|
+
class InvalidArity extends Error {
|
|
161
|
+
constructor(args, op) {
|
|
162
|
+
super(`The number of args does not match the arity of the operator '${pp(op)}'.`);
|
|
163
|
+
this.args = args;
|
|
164
|
+
this.op = op;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.InvalidArity = InvalidArity;
|
|
168
|
+
class InvalidExpression extends Error {
|
|
169
|
+
constructor(expr) {
|
|
170
|
+
super(`Invalid SPARQL Expression '${pp(expr)}'`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.InvalidExpression = InvalidExpression;
|
|
174
|
+
class ExtensionFunctionError extends Error {
|
|
175
|
+
constructor(name, functionError) {
|
|
176
|
+
if (functionError instanceof Error) {
|
|
177
|
+
super(`Error thrown in ${name}: ${functionError.message}${functionError.stack ? `\n${functionError.stack}` : ''}`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
super(`Error thrown in ${name}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.ExtensionFunctionError = ExtensionFunctionError;
|
|
185
|
+
class NoAggregator extends Error {
|
|
186
|
+
constructor(name) {
|
|
187
|
+
super(`Aggregate expression ${pp(name)} found, but no aggregate hook provided.`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.NoAggregator = NoAggregator;
|
|
191
|
+
function pp(object) {
|
|
192
|
+
return JSON.stringify(object);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=Errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.js","sourceRoot":"","sources":["Errors.ts"],"names":[],"mappings":";;;AAKA;;;;;;;;;;;;;GAaG;AACH,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C;AAE7C;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAY;IAC5C,OAAO,KAAK,YAAY,eAAe,CAAC;AAC1C,CAAC;AAFD,8CAEC;AAED;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,eAAe;IACrD,YAA0B,GAAa;QACrC,KAAK,CAAC,yBAAyB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QADnB,QAAG,GAAH,GAAG,CAAU;IAEvC,CAAC;CACF;AAJD,gDAIC;AAED;;GAEG;AACH,MAAa,oBAAqB,SAAQ,eAAe;IACvD,YAA0B,QAAgB,EAAS,QAAsB;QACvE,KAAK,CAAC,qBAAqB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QADpB,aAAQ,GAAR,QAAQ,CAAQ;QAAS,aAAQ,GAAR,QAAQ,CAAc;IAEzE,CAAC;CACF;AAJD,oDAIC;AAED;;;;;GAKG;AACH,MAAa,gBAAiB,SAAQ,eAAe;IACnD,YAA0B,GAAW;QACnC,KAAK,CAAC,8BAA8B,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QADxB,QAAG,GAAH,GAAG,CAAQ;IAErC,CAAC;CACF;AAJD,4CAIC;AAED;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,eAAe;IACpD,YAA0B,IAAkB;QAC1C,KAAK,CAAC,uDAAuD,CAAC,CAAC;QADvC,SAAI,GAAJ,IAAI,CAAc;IAE5C,CAAC;CACF;AAJD,8CAIC;AAED;;GA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E,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrH,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;CACF;AARD,wDAQC;AAED,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAmB,IAAa;QAC9B,KAAK,CAAC,wBAAwB,EAAE,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;IACnF,CAAC;CACF;AAJD,oCAIC;AAED,SAAS,EAAE,CAAI,MAAS;IACtB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { Expression } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type * as E from '../expressions';\nimport type * as C from './Consts';\n\n/**\n * This class of error will be thrown when an expression errors.\n * Various reasons this could happen are:\n * - invalid types for the given operator\n * - unbound variables\n * - invalid lexical forms\n * - ...\n *\n * The distinction is made so that one can catch this specific type\n * and handle it accordingly to the SPARQL spec (relevant for e.g. FILTER, EXTEND),\n * while others (programming errors) can be re-thrown.\n *\n * @see isExpressionError\n */\nexport class ExpressionError extends Error {}\n\n/**\n * Checks whether a given error is an {@link ExpressionError}.\n * Also useful for mocking in tests for covering all branches.\n *\n * @see ExpressionError\n */\nexport function isExpressionError(error: Error): boolean {\n return error instanceof ExpressionError;\n}\n\n/**\n * A literal has an invalid lexical form for the datatype it is accompanied by.\n * This error is only thrown when the term is as function argument that requires\n * a valid lexical form.\n */\nexport class InvalidLexicalForm extends ExpressionError {\n public constructor(public arg: RDF.Term) {\n super(`Invalid lexical form '${pp(arg)}'`);\n }\n}\n\n/**\n * A variable in the expression was not bound.\n */\nexport class UnboundVariableError extends ExpressionError {\n public constructor(public variable: string, public bindings: RDF.Bindings) {\n super(`Unbound variable '${pp(variable)}'`);\n }\n}\n\n/**\n * An invalid term was being coerced to an Effective Boolean Value.\n *\n * See the {@link https://www.w3.org/TR/sparql11-query/#ebv | SPARQL docs}\n * on EBVs.\n */\nexport class EBVCoercionError extends ExpressionError {\n public constructor(public arg: E.Term) {\n super(`Cannot coerce term to EBV '${pp(arg)}'`);\n }\n}\n\n/**\n * An equality test was done on literals with unsupported datatypes.\n *\n * See {@link https://www.w3.org/TR/sparql11-query/#func-RDFterm-equal | term equality spec}.\n */\nexport class RDFEqualTypeError extends ExpressionError {\n public constructor(public args: Expression[]) {\n super('Equality test for literals with unsupported datatypes');\n }\n}\n\n/**\n * All the expressions in a COALESCE call threw errors.\n */\nexport class CoalesceError extends ExpressionError {\n public constructor(public errors: Error[]) {\n super('All COALESCE arguments threw errors');\n }\n}\n\n/**\n * No arguments to an IN call where equal, and at least one threw an error.\n */\nexport class InError extends ExpressionError {\n public constructor(public errors: (Error | false)[]) {\n super(\n `Some argument to IN errorred and none where equal. ${\n\n errors.map(err => `(${err.toString()}) `).join('and ')}`,\n );\n }\n}\n\n/**\n * Literals were passed to an operator that doesn't support their datatypes.\n */\nexport class InvalidArgumentTypes extends ExpressionError {\n public constructor(public args: Expression[], public op: C.GeneralOperator) {\n super(`Argument types not valid for operator: '${pp(op)}' with '${pp(args)}`);\n }\n}\n\n/**\n * An invalid typecast happened.\n */\nexport class CastError<T> extends ExpressionError {\n public constructor(public arg: T, cast: C.TypeURL) {\n super(`Invalid cast: '${pp(arg)}' to '${pp(cast)}'`);\n }\n}\n\nexport class InvalidTimezoneCall extends ExpressionError {\n public constructor(public dateString: string) {\n super(`TIMEZONE call on ${dateString} which has no timezone`);\n }\n}\n\nexport class IncompatibleLanguageOperation extends ExpressionError {\n public constructor(public arg1: E.LangStringLiteral, public arg2: E.LangStringLiteral) {\n super(`Operation on incompatible language literals '${pp(arg1)}' and '${pp(arg2)}'`);\n }\n}\n\nexport class EmptyAggregateError extends ExpressionError {\n public constructor() {\n super('Empty aggregate expression');\n }\n}\n\nexport class ParseError extends ExpressionError {\n public constructor(str: string, type: string) {\n super(`Failed to parse \"${str}\" as ${type}.`);\n }\n}\n\n// Non Expression Errors ------------------------------------------------------\n\n/**\n * An error that arises when we detect a 'should-be-impossible' state.\n * Given that this error is thrown, it clearly wasn't impossible, and some\n * mistake has been made.\n */\nexport class UnexpectedError<T> extends Error {\n public constructor(message: string, public payload?: T) {\n super(`Programmer Error '${message}'`);\n }\n}\n\nexport class InvalidArity extends Error {\n public constructor(public args: Expression[], public op: C.GeneralOperator) {\n super(`The number of args does not match the arity of the operator '${pp(op)}'.`);\n }\n}\n\nexport class InvalidExpression<T> extends Error {\n public constructor(expr: T) {\n super(`Invalid SPARQL Expression '${pp(expr)}'`);\n }\n}\n\nexport class ExtensionFunctionError extends Error {\n public constructor(name: string, functionError: unknown) {\n if (functionError instanceof Error) {\n super(`Error thrown in ${name}: ${functionError.message}${functionError.stack ? `\\n${functionError.stack}` : ''}`);\n } else {\n super(`Error thrown in ${name}`);\n }\n }\n}\n\nexport class NoAggregator extends Error {\n public constructor(name?: string) {\n super(`Aggregate expression ${pp(name)} found, but no aggregate hook provided.`);\n }\n}\n\nfunction pp<T>(object: T): string {\n return JSON.stringify(object);\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IDateRepresentation, IDateTimeRepresentation, IDayTimeDurationRepresentation, IDurationRepresentation, ITimeRepresentation, IYearMonthDurationRepresentation } from '@comunica/types';
|
|
2
|
+
/**
|
|
3
|
+
* TODO: Fix decently
|
|
4
|
+
* Parses float datatypes (double, float).
|
|
5
|
+
*
|
|
6
|
+
* All invalid lexical values return undefined.
|
|
7
|
+
*
|
|
8
|
+
* @param value the string to interpret as a number
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseXSDFloat(value: string): number | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Parses decimal datatypes (decimal, int, byte, nonPositiveInteger, etc...).
|
|
13
|
+
*
|
|
14
|
+
* All other values, including NaN, INF, and floating point numbers all
|
|
15
|
+
* return undefined;
|
|
16
|
+
*
|
|
17
|
+
* @param value the string to interpret as a number
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseXSDDecimal(value: string): number | undefined;
|
|
20
|
+
export declare function parseDateTime(dateTimeStr: string): IDateTimeRepresentation;
|
|
21
|
+
export declare function parseDate(dateStr: string): IDateRepresentation;
|
|
22
|
+
export declare function parseTime(timeStr: string): ITimeRepresentation;
|
|
23
|
+
export declare function parseDuration(durationStr: string): Partial<IDurationRepresentation>;
|
|
24
|
+
export declare function parseYearMonthDuration(durationStr: string): Partial<IYearMonthDurationRepresentation>;
|
|
25
|
+
export declare function parseDayTimeDuration(durationStr: string): Partial<IDayTimeDurationRepresentation>;
|