@comunica/utils-expression-evaluator 4.5.0 → 5.0.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.
Files changed (58) hide show
  1. package/lib/expressions/Aggregate.d.ts +1 -1
  2. package/lib/expressions/Aggregate.js +3 -1
  3. package/lib/expressions/Aggregate.js.map +1 -1
  4. package/lib/expressions/Existence.d.ts +1 -1
  5. package/lib/expressions/Existence.js +2 -1
  6. package/lib/expressions/Existence.js.map +1 -1
  7. package/lib/expressions/Expressions.d.ts +0 -0
  8. package/lib/expressions/Expressions.js +1 -2
  9. package/lib/expressions/Expressions.js.map +1 -1
  10. package/lib/expressions/Operator.d.ts +0 -0
  11. package/lib/expressions/Operator.js +4 -1
  12. package/lib/expressions/Operator.js.map +1 -1
  13. package/lib/expressions/Term.d.ts +9 -1
  14. package/lib/expressions/Term.js +76 -21
  15. package/lib/expressions/Term.js.map +1 -1
  16. package/lib/expressions/Variable.d.ts +0 -0
  17. package/lib/expressions/Variable.js +2 -1
  18. package/lib/expressions/Variable.js.map +1 -1
  19. package/lib/expressions/index.d.ts +0 -0
  20. package/lib/expressions/index.js +0 -0
  21. package/lib/expressions/index.js.map +0 -0
  22. package/lib/functions/Helpers.d.ts +2 -0
  23. package/lib/functions/Helpers.js +20 -11
  24. package/lib/functions/Helpers.js.map +1 -1
  25. package/lib/functions/OverloadTree.d.ts +0 -0
  26. package/lib/functions/OverloadTree.js +8 -0
  27. package/lib/functions/OverloadTree.js.map +1 -1
  28. package/lib/index.d.ts +0 -0
  29. package/lib/index.js +0 -0
  30. package/lib/index.js.map +0 -0
  31. package/lib/transformers/TermTransformer.d.ts +2 -2
  32. package/lib/transformers/TermTransformer.js +7 -3
  33. package/lib/transformers/TermTransformer.js.map +1 -1
  34. package/lib/util/Consts.d.ts +5 -0
  35. package/lib/util/Consts.js +7 -3
  36. package/lib/util/Consts.js.map +1 -1
  37. package/lib/util/Context.d.ts +0 -0
  38. package/lib/util/Context.js +1 -2
  39. package/lib/util/Context.js.map +1 -1
  40. package/lib/util/DateTimeHelpers.d.ts +0 -0
  41. package/lib/util/DateTimeHelpers.js +15 -16
  42. package/lib/util/DateTimeHelpers.js.map +1 -1
  43. package/lib/util/Errors.d.ts +5 -0
  44. package/lib/util/Errors.js +28 -2
  45. package/lib/util/Errors.js.map +1 -1
  46. package/lib/util/Parsing.d.ts +0 -1
  47. package/lib/util/Parsing.js +8 -11
  48. package/lib/util/Parsing.js.map +1 -1
  49. package/lib/util/Serialization.d.ts +0 -0
  50. package/lib/util/Serialization.js +4 -5
  51. package/lib/util/Serialization.js.map +1 -1
  52. package/lib/util/SpecAlgos.d.ts +0 -0
  53. package/lib/util/SpecAlgos.js +3 -4
  54. package/lib/util/SpecAlgos.js.map +1 -1
  55. package/lib/util/TypeHandling.d.ts +0 -0
  56. package/lib/util/TypeHandling.js +11 -10
  57. package/lib/util/TypeHandling.js.map +1 -1
  58. package/package.json +8 -8
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.elapsedDuration = exports.addDurationToDateTime = exports.maximumDayInMonthFor = void 0;
3
+ exports.maximumDayInMonthFor = maximumDayInMonthFor;
4
+ exports.addDurationToDateTime = addDurationToDateTime;
5
+ exports.elapsedDuration = elapsedDuration;
4
6
  const DateTimeHelpers_1 = require("./DateTimeHelpers");
5
7
  function fDiv(arg, high, low = 0) {
6
8
  // Adds the 4 spec functions into one since they are highly related,
@@ -25,7 +27,6 @@ function maximumDayInMonthFor(yearValue, monthValue) {
25
27
  }
26
28
  return 28;
27
29
  }
28
- exports.maximumDayInMonthFor = maximumDayInMonthFor;
29
30
  // https://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes
30
31
  function addDurationToDateTime(date, duration) {
31
32
  // Used to cary over optional fields like timezone
@@ -65,7 +66,6 @@ function addDurationToDateTime(date, duration) {
65
66
  }
66
67
  return newDate;
67
68
  }
68
- exports.addDurationToDateTime = addDurationToDateTime;
69
69
  function elapsedDuration(first, second, defaultTimeZone) {
70
70
  const d1 = (0, DateTimeHelpers_1.toUTCDate)(first, defaultTimeZone);
71
71
  const d2 = (0, DateTimeHelpers_1.toUTCDate)(second, defaultTimeZone);
@@ -77,5 +77,4 @@ function elapsedDuration(first, second, defaultTimeZone) {
77
77
  seconds: diff % (1_000 * 60),
78
78
  };
79
79
  }
80
- exports.elapsedDuration = elapsedDuration;
81
80
  //# sourceMappingURL=SpecAlgos.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpecAlgos.js","sourceRoot":"","sources":["SpecAlgos.ts"],"names":[],"mappings":";;;AACA,uDAA8C;AAE9C,SAAS,IAAI,CAAC,GAAW,EAAE,IAAY,EAAE,GAAG,GAAG,CAAC;IAC9C,oEAAoE;IACpE,8DAA8D;IAC9D,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IAC1C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AACtD,CAAC;AAED,SAAgB,oBAAoB,CAAC,SAAiB,EAAE,UAAkB;IACxE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,SAAS,GAAG,eAAe,CAAC;IAEzC,IAAI,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAE,CAAC,EAAE,CAAC,EAAE,CAA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K,EAAE,eAAe,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,IAAA,2BAAS,EAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IACzC,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QACtE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;QAC5D,OAAO,EAAE,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;KAC7B,CAAC;AACJ,CAAC;AAdD,0CAcC","sourcesContent":["import type { IDateTimeRepresentation, IDurationRepresentation, ITimeZoneRepresentation } from '@comunica/types';\nimport { toUTCDate } from './DateTimeHelpers';\n\nfunction fDiv(arg: number, high: number, low = 0): { intDiv: number; remainder: number } {\n // Adds the 4 spec functions into one since they are highly related,\n // and fQuotient and modulo are almost always called in pairs.\n const first = arg - low;\n const second = high - low;\n const intDiv = Math.floor(first / second);\n return { intDiv, remainder: arg - intDiv * second };\n}\n\nexport function maximumDayInMonthFor(yearValue: number, monthValue: number): number {\n const { intDiv: additionalYears, remainder: month } = fDiv(monthValue, 13, 1);\n const year = yearValue + additionalYears;\n\n if ([ 1, 3, 5, 7, 8, 10, 12 ].includes(month)) {\n return 31;\n }\n if ([ 4, 6, 9, 11 ].includes(month)) {\n return 30;\n }\n if (month === 2 && (\n fDiv(year, 400).remainder === 0 ||\n (fDiv(year, 100).remainder !== 0 && fDiv(year, 4).remainder === 0))) {\n return 29;\n }\n return 28;\n}\n\n// https://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes\nexport function addDurationToDateTime(date: IDateTimeRepresentation, duration: IDurationRepresentation):\nIDateTimeRepresentation {\n // Used to cary over optional fields like timezone\n const newDate: IDateTimeRepresentation = { ...date };\n\n // Month\n let tempDiv = fDiv(date.month + duration.month, 13, 1);\n newDate.month = tempDiv.remainder;\n // Year\n newDate.year = date.year + duration.year + tempDiv.intDiv;\n // Seconds\n tempDiv = fDiv(date.seconds + duration.seconds, 60);\n newDate.seconds = tempDiv.remainder;\n // Minutes\n tempDiv = fDiv(date.minutes + duration.minutes + tempDiv.intDiv, 60);\n newDate.minutes = tempDiv.remainder;\n // Hours\n tempDiv = fDiv(date.hours + duration.hours + tempDiv.intDiv, 24);\n newDate.hours = tempDiv.remainder;\n\n // We skip a part of the spec code since: Defined spec code can not happen since it would be an invalid literal\n\n newDate.day = date.day + duration.day + tempDiv.intDiv;\n\n while (true) {\n let carry;\n if (newDate.day < 1) {\n newDate.day += maximumDayInMonthFor(newDate.year, newDate.month - 1);\n carry = -1;\n } else if (newDate.day > maximumDayInMonthFor(newDate.year, newDate.month)) {\n newDate.day -= maximumDayInMonthFor(newDate.year, newDate.month);\n carry = 1;\n } else {\n break;\n }\n tempDiv = fDiv(newDate.month + carry, 13, 1);\n newDate.month = tempDiv.remainder;\n newDate.year += tempDiv.intDiv;\n }\n return newDate;\n}\n\nexport function elapsedDuration(\n first: IDateTimeRepresentation,\n second: IDateTimeRepresentation,\n defaultTimeZone: ITimeZoneRepresentation,\n): Partial<IDurationRepresentation> {\n const d1 = toUTCDate(first, defaultTimeZone);\n const d2 = toUTCDate(second, defaultTimeZone);\n const diff = d1.getTime() - d2.getTime();\n return {\n day: Math.floor(diff / (1_000 * 60 * 60 * 24)),\n hours: Math.floor((diff % (1_000 * 60 * 60 * 24)) / (1_000 * 60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,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QACtE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;QAC5D,OAAO,EAAE,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import type { IDateTimeRepresentation, IDurationRepresentation, ITimeZoneRepresentation } from '@comunica/types';\nimport { toUTCDate } from './DateTimeHelpers';\n\nfunction fDiv(arg: number, high: number, low = 0): { intDiv: number; remainder: number } {\n // Adds the 4 spec functions into one since they are highly related,\n // and fQuotient and modulo are almost always called in pairs.\n const first = arg - low;\n const second = high - low;\n const intDiv = Math.floor(first / second);\n return { intDiv, remainder: arg - intDiv * second };\n}\n\nexport function maximumDayInMonthFor(yearValue: number, monthValue: number): number {\n const { intDiv: additionalYears, remainder: month } = fDiv(monthValue, 13, 1);\n const year = yearValue + additionalYears;\n\n if ([ 1, 3, 5, 7, 8, 10, 12 ].includes(month)) {\n return 31;\n }\n if ([ 4, 6, 9, 11 ].includes(month)) {\n return 30;\n }\n if (month === 2 && (\n fDiv(year, 400).remainder === 0 ||\n (fDiv(year, 100).remainder !== 0 && fDiv(year, 4).remainder === 0))) {\n return 29;\n }\n return 28;\n}\n\n// https://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes\nexport function addDurationToDateTime(date: IDateTimeRepresentation, duration: IDurationRepresentation):\nIDateTimeRepresentation {\n // Used to cary over optional fields like timezone\n const newDate: IDateTimeRepresentation = { ...date };\n\n // Month\n let tempDiv = fDiv(date.month + duration.month, 13, 1);\n newDate.month = tempDiv.remainder;\n // Year\n newDate.year = date.year + duration.year + tempDiv.intDiv;\n // Seconds\n tempDiv = fDiv(date.seconds + duration.seconds, 60);\n newDate.seconds = tempDiv.remainder;\n // Minutes\n tempDiv = fDiv(date.minutes + duration.minutes + tempDiv.intDiv, 60);\n newDate.minutes = tempDiv.remainder;\n // Hours\n tempDiv = fDiv(date.hours + duration.hours + tempDiv.intDiv, 24);\n newDate.hours = tempDiv.remainder;\n\n // We skip a part of the spec code since: Defined spec code can not happen since it would be an invalid literal\n\n newDate.day = date.day + duration.day + tempDiv.intDiv;\n\n while (true) {\n let carry;\n if (newDate.day < 1) {\n newDate.day += maximumDayInMonthFor(newDate.year, newDate.month - 1);\n carry = -1;\n } else if (newDate.day > maximumDayInMonthFor(newDate.year, newDate.month)) {\n newDate.day -= maximumDayInMonthFor(newDate.year, newDate.month);\n carry = 1;\n } else {\n break;\n }\n tempDiv = fDiv(newDate.month + carry, 13, 1);\n newDate.month = tempDiv.remainder;\n newDate.year += tempDiv.intDiv;\n }\n return newDate;\n}\n\nexport function elapsedDuration(\n first: IDateTimeRepresentation,\n second: IDateTimeRepresentation,\n defaultTimeZone: ITimeZoneRepresentation,\n): Partial<IDurationRepresentation> {\n const d1 = toUTCDate(first, defaultTimeZone);\n const d2 = toUTCDate(second, defaultTimeZone);\n const diff = d1.getTime() - d2.getTime();\n return {\n day: Math.floor(diff / (1_000 * 60 * 60 * 24)),\n hours: Math.floor((diff % (1_000 * 60 * 60 * 24)) / (1_000 * 60 * 60)),\n minutes: Math.floor(diff % (1_000 * 60 * 60) / (1_000 * 60)),\n seconds: diff % (1_000 * 60),\n };\n}\n"]}
File without changes
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typePromotion = exports.isSubTypeOf = exports.getSuperTypeDict = exports.isInternalSubType = exports.asGeneralType = exports.asOverrideType = exports.asKnownLiteralType = exports.asTypeAlias = exports.typeAliasCheck = exports.extensionTableInit = exports.getSuperTypes = exports.superTypeDictTable = exports.extensionTableInput = void 0;
3
+ exports.typePromotion = exports.typeAliasCheck = exports.superTypeDictTable = exports.extensionTableInput = void 0;
4
+ exports.getSuperTypes = getSuperTypes;
5
+ exports.extensionTableInit = extensionTableInit;
6
+ exports.asTypeAlias = asTypeAlias;
7
+ exports.asKnownLiteralType = asKnownLiteralType;
8
+ exports.asOverrideType = asOverrideType;
9
+ exports.asGeneralType = asGeneralType;
10
+ exports.isInternalSubType = isInternalSubType;
11
+ exports.getSuperTypeDict = getSuperTypeDict;
12
+ exports.isSubTypeOf = isSubTypeOf;
4
13
  const expressions_1 = require("../expressions");
5
14
  const Helpers_1 = require("../functions/Helpers");
6
15
  const Consts_1 = require("./Consts");
@@ -19,6 +28,7 @@ exports.extensionTableInput = {
19
28
  [Consts_1.TypeURL.XSD_YEAR_MONTH_DURATION]: Consts_1.TypeURL.XSD_DURATION,
20
29
  // Stringly types
21
30
  [Consts_1.TypeURL.RDF_LANG_STRING]: Consts_1.TypeAlias.SPARQL_STRINGLY,
31
+ [Consts_1.TypeURL.RDF_DIR_LANG_STRING]: Consts_1.TypeAlias.SPARQL_STRINGLY,
22
32
  [Consts_1.TypeURL.XSD_STRING]: Consts_1.TypeAlias.SPARQL_STRINGLY,
23
33
  // String types
24
34
  [Consts_1.TypeURL.XSD_NORMALIZED_STRING]: Consts_1.TypeURL.XSD_STRING,
@@ -105,7 +115,6 @@ function getSuperTypes(type, openWorldType) {
105
115
  openWorldType.cache.set(type, subExtension);
106
116
  return subExtension;
107
117
  }
108
- exports.getSuperTypes = getSuperTypes;
109
118
  // No circular structure allowed! & No other keys allowed!
110
119
  function extensionTableInit() {
111
120
  for (const [_key, value] of Object.entries(exports.extensionTableInput)) {
@@ -116,7 +125,6 @@ function extensionTableInit() {
116
125
  extensionTableBuilderInitKey(key, value, exports.superTypeDictTable);
117
126
  }
118
127
  }
119
- exports.extensionTableInit = extensionTableInit;
120
128
  extensionTableInit();
121
129
  function extensionTableBuilderInitKey(key, value, res) {
122
130
  if (value === 'term' || value === undefined) {
@@ -144,28 +152,24 @@ function asTypeAlias(type) {
144
152
  }
145
153
  return undefined;
146
154
  }
147
- exports.asTypeAlias = asTypeAlias;
148
155
  function asKnownLiteralType(type) {
149
156
  if (type in exports.superTypeDictTable) {
150
157
  return type;
151
158
  }
152
159
  return undefined;
153
160
  }
154
- exports.asKnownLiteralType = asKnownLiteralType;
155
161
  function asOverrideType(type) {
156
162
  if (asKnownLiteralType(type) ?? type === 'term') {
157
163
  return type;
158
164
  }
159
165
  return undefined;
160
166
  }
161
- exports.asOverrideType = asOverrideType;
162
167
  function asGeneralType(type) {
163
168
  if (type === 'term' || (0, expressions_1.asTermType)(type)) {
164
169
  return type;
165
170
  }
166
171
  return undefined;
167
172
  }
168
- exports.asGeneralType = asGeneralType;
169
173
  /**
170
174
  * Internal type of @see isSubTypeOf This only takes knownTypes but doesn't need an enabler
171
175
  */
@@ -173,7 +177,6 @@ function isInternalSubType(baseType, argumentType) {
173
177
  return baseType !== 'term' &&
174
178
  (exports.superTypeDictTable[baseType] && exports.superTypeDictTable[baseType][argumentType] !== undefined);
175
179
  }
176
- exports.isInternalSubType = isInternalSubType;
177
180
  /**
178
181
  * This function can be used to check the base type is a restriction on a type in the dict.
179
182
  * If we want to check if type x is a restriction on string we do this by calling:
@@ -190,7 +193,6 @@ function getSuperTypeDict(baseType, superTypeProvider) {
190
193
  // Datatype is a custom datatype
191
194
  return getSuperTypes(baseType, superTypeProvider);
192
195
  }
193
- exports.getSuperTypeDict = getSuperTypeDict;
194
196
  /**
195
197
  * This function needs to be O(1)! The execution time of this function is vital!
196
198
  * We define typeA isSubtypeOf typeA as true.
@@ -205,7 +207,6 @@ function isSubTypeOf(baseType, argumentType, superTypeProvider) {
205
207
  }
206
208
  return getSuperTypeDict(baseType, superTypeProvider)[argumentType] !== undefined;
207
209
  }
208
- exports.isSubTypeOf = isSubTypeOf;
209
210
  // Defined by https://www.w3.org/TR/xpath-31/#promotion .
210
211
  // e.g. When a function takes a string, it can also accept a XSD_ANY_URI if it's cast first.
211
212
  exports.typePromotion = {
@@ -1 +1 @@
1
- {"version":3,"file":"TypeHandling.js","sourceRoot":"","sources":["TypeHandling.ts"],"names":[],"mappings":";;;AAEA,gDAA4C;AAC5C,kDAA6D;AAG7D,qCAA8C;AAI9C;;;;;;GAMG;AACU,QAAA,mBAAmB,GAA4C;IAC1E,iBAAiB;IACjB,CAAC,gBAAO,CAAC,mBAAmB,CAAC,EAAE,gBAAO,CAAC,aAAa;IAEpD,iBAAiB;IACjB,CAAC,gBAAO,CAAC,qBAAqB,CAAC,EAAE,gBAAO,CAAC,YAAY;IACrD,CAAC,gBAAO,CAAC,uBAAuB,CAAC,EAAE,gBAAO,CAAC,YAAY;IAEvD,iBAAiB;IACjB,CAAC,gBAAO,CAAC,eAAe,CAAC,EAAE,kBAAS,CAAC,eAAe;IACpD,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE,kBAAS,CAAC,eAAe;IAE/C,eAAe;IACf,CAAC,gBAAO,CAAC,qBAAqB,CAAC,EAAE,gBAAO,CAAC,UAAU;IACnD,CAAC,gBAAO,CAAC,SAAS,CAAC,EAAE,gBAAO,CAAC,qBAAqB;IAClD,CAAC,gBAAO,CAAC,YAAY,CAAC,EAAE,gBAAO,CAAC,SAAS;IACzC,CAAC,gBAAO,CAAC,YAAY,CAAC,EAAE,gBAAO,CAAC,SAAS;IACzC,CAAC,gBAAO,CAAC,QAAQ,CAAC,EAAE,gBAAO,CAAC,SAAS;IACrC,CAAC,gBAAO,CAAC,WAAW,CAAC,EAAE,gBAAO,CAAC,QAAQ;IACvC,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE,gBAAO,CAAC,WAAW;IACzC,CAAC,gBAAO,CAAC,MAAM,CAAC,EAAE,gBAAO,CAAC,WAAW;IACrC,CAAC,gBAAO,CAAC,U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AAU,CAAC,EAAE;QACpB,EAAE,aAAa,EAAE,gBAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,gBAAM,EAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE;KACrF;IACD,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE;QACpB,EAAE,aAAa,EAAE,gBAAO,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,gBAAM,EAAoB,GAAI,CAAC,UAAU,CAAC,EAAE;QAC3G,oDAAoD;QACpD,EAAE,aAAa,EAAE,gBAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,gBAAM,EAAoB,GAAI,CAAC,UAAU,CAAC,EAAE;KAC9G;IACD,CAAC,gBAAO,CAAC,SAAS,CAAC,EAAE;QACnB,oDAAoD;QACpD,EAAE,aAAa,EAAE,gBAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,eAAK,EAAoB,GAAI,CAAC,UAAU,CAAC,EAAE;KAC7G;CACF,CAAC","sourcesContent":["import type { GeneralSuperTypeDict, ISuperTypeProvider, TermExpression, TermType } from '@comunica/types';\nimport type * as E from '../expressions';\nimport { asTermType } from '../expressions';\nimport { double, float, string } from '../functions/Helpers';\nimport type { ArgumentType } from '../functions/OverloadTree';\nimport type { KnownLiteralTypes } from './Consts';\nimport { TypeAlias, TypeURL } from './Consts';\n\nexport type OverrideType = KnownLiteralTypes | 'term';\n\n/**\n * Types that are not mentioned just map to 'term'.\n * When editing this, make sure type promotion and substitution don't start interfering.\n * e.g. when saying something like string -> stringly -> anyUri -> term.\n * This would make substitution on types that promote to each other possible. We and the specs don't want that!\n * A DAG will be created based on this. Make sure it doesn't have any cycles!\n */\nexport const extensionTableInput: Record<KnownLiteralTypes, OverrideType> = {\n // Datetime types\n [TypeURL.XSD_DATE_TIME_STAMP]: TypeURL.XSD_DATE_TIME,\n\n // Duration types\n [TypeURL.XSD_DAY_TIME_DURATION]: TypeURL.XSD_DURATION,\n [TypeURL.XSD_YEAR_MONTH_DURATION]: TypeURL.XSD_DURATION,\n\n // Stringly types\n [TypeURL.RDF_LANG_STRING]: TypeAlias.SPARQL_STRINGLY,\n [TypeURL.XSD_STRING]: TypeAlias.SPARQL_STRINGLY,\n\n // String types\n [TypeURL.XSD_NORMALIZED_STRING]: TypeURL.XSD_STRING,\n [TypeURL.XSD_TOKEN]: TypeURL.XSD_NORMALIZED_STRING,\n [TypeURL.XSD_LANGUAGE]: TypeURL.XSD_TOKEN,\n [TypeURL.XSD_NM_TOKEN]: TypeURL.XSD_TOKEN,\n [TypeURL.XSD_NAME]: TypeURL.XSD_TOKEN,\n [TypeURL.XSD_NC_NAME]: TypeURL.XSD_NAME,\n [TypeURL.XSD_ENTITY]: TypeURL.XSD_NC_NAME,\n [TypeURL.XSD_ID]: TypeURL.XSD_NC_NAME,\n [TypeURL.XSD_ID_REF]: TypeURL.XSD_NC_NAME,\n // https://www.w3.org/TR/xpath-31/#dt-function-conversion\n // \"Each item in the atomic sequence that is of type xs:untypedAtomic is cast\n // to the expected generalized atomic type.\"\n // So then I looked in the specs for something about casting:\n // https://www.w3.org/TR/xpath-functions-31/#casting-from-strings\n // \"If the value is xs:untypedAtomic, it is treated in exactly the same way as a string\n // containing the same sequence of characters.\"\n // So it's not really a subtype by definition, but it works this way.\n [TypeURL.XSD_UNTYPED_ATOMIC]: TypeURL.XSD_STRING,\n\n // Numeric types\n // https://www.w3.org/TR/sparql11-query/#operandDataTypes\n // > numeric denotes typed literals with datatypes xsd:integer, xsd:decimal, xsd:float, and xsd:double\n [TypeURL.XSD_DOUBLE]: TypeAlias.SPARQL_NUMERIC,\n [TypeURL.XSD_FLOAT]: TypeAlias.SPARQL_NUMERIC,\n [TypeURL.XSD_DECIMAL]: TypeAlias.SPARQL_NUMERIC,\n\n // Decimal types\n [TypeURL.XSD_INTEGER]: TypeURL.XSD_DECIMAL,\n\n [TypeURL.XSD_NON_POSITIVE_INTEGER]: TypeURL.XSD_INTEGER,\n [TypeURL.XSD_NEGATIVE_INTEGER]: TypeURL.XSD_NON_POSITIVE_INTEGER,\n\n [TypeURL.XSD_LONG]: TypeURL.XSD_INTEGER,\n [TypeURL.XSD_INT]: TypeURL.XSD_LONG,\n [TypeURL.XSD_SHORT]: TypeURL.XSD_INT,\n [TypeURL.XSD_BYTE]: TypeURL.XSD_SHORT,\n\n [TypeURL.XSD_NON_NEGATIVE_INTEGER]: TypeURL.XSD_INTEGER,\n [TypeURL.XSD_POSITIVE_INTEGER]: TypeURL.XSD_NON_NEGATIVE_INTEGER,\n [TypeURL.XSD_UNSIGNED_LONG]: TypeURL.XSD_NON_NEGATIVE_INTEGER,\n [TypeURL.XSD_UNSIGNED_INT]: TypeURL.XSD_UNSIGNED_LONG,\n [TypeURL.XSD_UNSIGNED_SHORT]: TypeURL.XSD_UNSIGNED_INT,\n [TypeURL.XSD_UNSIGNED_BYTE]: TypeURL.XSD_UNSIGNED_SHORT,\n\n [TypeURL.XSD_DATE_TIME]: 'term',\n [TypeURL.XSD_BOOLEAN]: 'term',\n [TypeURL.XSD_DATE]: 'term',\n [TypeURL.XSD_G_MONTH]: 'term',\n [TypeURL.XSD_G_MONTHDAY]: 'term',\n [TypeURL.XSD_G_YEAR]: 'term',\n [TypeURL.XSD_G_YEAR_MONTH]: 'term',\n [TypeURL.XSD_TIME]: 'term',\n [TypeURL.XSD_G_DAY]: 'term',\n [TypeURL.XSD_DURATION]: 'term',\n [TypeAlias.SPARQL_NUMERIC]: 'term',\n [TypeAlias.SPARQL_STRINGLY]: 'term',\n [TypeURL.XSD_ANY_URI]: 'term',\n};\ntype SuperTypeDict = Record<KnownLiteralTypes, number> & { __depth: number };\ntype SuperTypeDictTable = Record<KnownLiteralTypes, SuperTypeDict>;\nexport const superTypeDictTable: SuperTypeDictTable = Object.create(null);\n\n/**\n * This will return the super types of a type and cache them.\n * @param type IRI we will decide the super types of.\n * @param openWorldType the enabler that provides a way to find super types.\n */\nexport function getSuperTypes(type: string, openWorldType: ISuperTypeProvider): GeneralSuperTypeDict {\n const cached = openWorldType.cache.get(type);\n if (cached) {\n return cached;\n }\n const value = openWorldType.discoverer(type);\n if (value === 'term') {\n const res: GeneralSuperTypeDict = Object.create(null);\n res.__depth = 0;\n res[type] = 0;\n openWorldType.cache.set(type, res);\n return res;\n }\n let subExtension: GeneralSuperTypeDict;\n const knownValue = asKnownLiteralType(value);\n if (knownValue) {\n subExtension = { ...superTypeDictTable[knownValue] };\n } else {\n subExtension = { ...getSuperTypes(value, openWorldType) };\n }\n subExtension.__depth++;\n subExtension[type] = subExtension.__depth;\n openWorldType.cache.set(type, subExtension);\n return subExtension;\n}\n\n// No circular structure allowed! & No other keys allowed!\nexport function extensionTableInit(): void {\n for (const [ _key, value ] of Object.entries(extensionTableInput)) {\n const key = <KnownLiteralTypes>_key;\n if (superTypeDictTable[key]) {\n continue;\n }\n extensionTableBuilderInitKey(key, value, superTypeDictTable);\n }\n}\nextensionTableInit();\n\nfunction extensionTableBuilderInitKey(key: KnownLiteralTypes, value: OverrideType, res: SuperTypeDictTable): void {\n if (value === 'term' || value === undefined) {\n const baseRes: SuperTypeDict = Object.create(null);\n baseRes.__depth = 0;\n baseRes[key] = 0;\n res[key] = baseRes;\n return;\n }\n if (!res[value]) {\n extensionTableBuilderInitKey(value, extensionTableInput[value], res);\n }\n res[key] = { ...res[value], [key]: res[value].__depth + 1, __depth: res[value].__depth + 1 };\n}\n\nexport const typeAliasCheck: Record<TypeAlias, boolean> = Object.create(null);\nfunction initTypeAliasCheck(): void {\n for (const val of Object.values(TypeAlias)) {\n typeAliasCheck[val] = true;\n }\n}\ninitTypeAliasCheck();\n\nexport function asTypeAlias(type: string): TypeAlias | undefined {\n if (type in typeAliasCheck) {\n return <TypeAlias> type;\n }\n return undefined;\n}\n\nexport function asKnownLiteralType(type: string): KnownLiteralTypes | undefined {\n if (type in superTypeDictTable) {\n return <KnownLiteralTypes> type;\n }\n return undefined;\n}\n\nexport function asOverrideType(type: string): OverrideType | undefined {\n if (asKnownLiteralType(type) ?? type === 'term') {\n return <OverrideType> type;\n }\n return undefined;\n}\n\nexport function asGeneralType(type: string): 'term' | TermType | undefined {\n if (type === 'term' || asTermType(type)) {\n return <'term' | TermType> type;\n }\n return undefined;\n}\n\n/**\n * Internal type of @see isSubTypeOf This only takes knownTypes but doesn't need an enabler\n */\nexport function isInternalSubType(baseType: OverrideType, argumentType: KnownLiteralTypes): boolean {\n return baseType !== 'term' &&\n (superTypeDictTable[baseType] && superTypeDictTable[baseType][argumentType] !== undefined);\n}\n\n/**\n * This function can be used to check the base type is a restriction on a type in the dict.\n * If we want to check if type x is a restriction on string we do this by calling:\n * 'http://www.w3.org/2001/XMLSchema#string' in getSuperTypeDict(X, superTypeProvider)\n * @param baseType\n * @param superTypeProvider\n */\nexport function getSuperTypeDict(baseType: string, superTypeProvider: ISuperTypeProvider): GeneralSuperTypeDict {\n const concreteType: KnownLiteralTypes | undefined = asKnownLiteralType(baseType);\n if (concreteType) {\n // Concrete dataType is known by utils-expression-evaluator.\n return superTypeDictTable[concreteType];\n }\n // Datatype is a custom datatype\n return getSuperTypes(baseType, superTypeProvider);\n}\n\n/**\n * This function needs to be O(1)! The execution time of this function is vital!\n * We define typeA isSubtypeOf typeA as true.\n * If you find yourself using this function a lot (e.g. in a case) please use getSuperTypeDict instead.\n * @param baseType type you want to provide.\n * @param argumentType type you want to provide @param baseType to.\n * @param superTypeProvider the enabler to discover super types of unknown types.\n */\nexport function isSubTypeOf(\n baseType: string,\n argumentType: KnownLiteralTypes,\n superTypeProvider: ISuperTypeProvider,\n): boolean {\n if (baseType === 'term') {\n return false;\n }\n return getSuperTypeDict(baseType, superTypeProvider)[argumentType] !== undefined;\n}\n\n// Defined by https://www.w3.org/TR/xpath-31/#promotion .\n// e.g. When a function takes a string, it can also accept a XSD_ANY_URI if it's cast first.\nexport const typePromotion: Partial<Record<ArgumentType, {\n typeToPromote: KnownLiteralTypes;\n conversionFunction: (arg: TermExpression) => TermExpression;\n}[]>> = {\n [TypeURL.XSD_STRING]: [\n { typeToPromote: TypeURL.XSD_ANY_URI, conversionFunction: arg => string(arg.str()) },\n ],\n [TypeURL.XSD_DOUBLE]: [\n { typeToPromote: TypeURL.XSD_FLOAT, conversionFunction: arg => double((<E.NumericLiteral>arg).typedValue) },\n // TODO: in case of decimal a round needs to happen.\n { typeToPromote: TypeURL.XSD_DECIMAL, conversionFunction: arg => double((<E.NumericLiteral>arg).typedValue) },\n ],\n [TypeURL.XSD_FLOAT]: [\n // TODO: in case of decimal a round needs to happen.\n { typeToPromote: TypeURL.XSD_DECIMAL, conversionFunction: arg => float((<E.NumericLiteral>arg).typedValue) },\n ],\n};\n"]}
1
+ {"version":3,"file":"TypeHandling.js","sourceRoot":"","sources":["TypeHandling.ts"],"names":[],"mappings":";;;AAkGA,sCAwBC;AAGD,gDAQC;AAyBD,kCAKC;AAED,gDAKC;AAED,wCAKC;AAED,sCAKC;AAKD,8CAGC;AASD,4CAQC;AAUD,kCASC;AAlOD,gDAA4C;AAC5C,kDAA6D;AAG7D,qCAA8C;AAI9C;;;;;;GAMG;AACU,QAAA,mBAAmB,GAA4C;IAC1E,iBAAiB;IACjB,CAAC,gBAAO,CAAC,mBAAmB,CAAC,EAAE,gBAAO,CAAC,aAAa;IAEpD,iBAAiB;IACjB,CAAC,gBAAO,CAAC,qBAAqB,CAAC,EAAE,gBAAO,CAAC,YAAY;IACrD,CAAC,gBAAO,CAAC,uBAAuB,CAAC,EAAE,gBAAO,CAAC,YAAY;IAEvD,iBAAiB;IACjB,CAAC,gBAAO,CAAC,eAAe,CAAC,EAAE,kBAAS,CAAC,eAAe;IACpD,CAAC,gBAAO,CAAC,mBAAmB,CAAC,EAAE,kBAAS,CAAC,eAAe;IACxD,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE,kBAAS,CAAC,eAAe;IAE/C,eAAe;IACf,CAA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AAgC;IAChC,OAAO,aAAa,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,WAAW,CACzB,QAAgB,EAChB,YAA+B,EAC/B,iBAAqC;IAErC,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,YAAY,CAAC,KAAK,SAAS,CAAC;AACnF,CAAC;AAED,yDAAyD;AACzD,4FAA4F;AAC/E,QAAA,aAAa,GAGlB;IACN,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE;QACpB,EAAE,aAAa,EAAE,gBAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,gBAAM,EAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE;KACrF;IACD,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE;QACpB,EAAE,aAAa,EAAE,gBAAO,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,gBAAM,EAAoB,GAAI,CAAC,UAAU,CAAC,EAAE;QAC3G,oDAAoD;QACpD,EAAE,aAAa,EAAE,gBAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,gBAAM,EAAoB,GAAI,CAAC,UAAU,CAAC,EAAE;KAC9G;IACD,CAAC,gBAAO,CAAC,SAAS,CAAC,EAAE;QACnB,oDAAoD;QACpD,EAAE,aAAa,EAAE,gBAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,IAAA,eAAK,EAAoB,GAAI,CAAC,UAAU,CAAC,EAAE;KAC7G;CACF,CAAC","sourcesContent":["import type { GeneralSuperTypeDict, ISuperTypeProvider, TermExpression, TermType } from '@comunica/types';\nimport type * as E from '../expressions';\nimport { asTermType } from '../expressions';\nimport { double, float, string } from '../functions/Helpers';\nimport type { ArgumentType } from '../functions/OverloadTree';\nimport type { KnownLiteralTypes } from './Consts';\nimport { TypeAlias, TypeURL } from './Consts';\n\nexport type OverrideType = KnownLiteralTypes | 'term';\n\n/**\n * Types that are not mentioned just map to 'term'.\n * When editing this, make sure type promotion and substitution don't start interfering.\n * e.g. when saying something like string -> stringly -> anyUri -> term.\n * This would make substitution on types that promote to each other possible. We and the specs don't want that!\n * A DAG will be created based on this. Make sure it doesn't have any cycles!\n */\nexport const extensionTableInput: Record<KnownLiteralTypes, OverrideType> = {\n // Datetime types\n [TypeURL.XSD_DATE_TIME_STAMP]: TypeURL.XSD_DATE_TIME,\n\n // Duration types\n [TypeURL.XSD_DAY_TIME_DURATION]: TypeURL.XSD_DURATION,\n [TypeURL.XSD_YEAR_MONTH_DURATION]: TypeURL.XSD_DURATION,\n\n // Stringly types\n [TypeURL.RDF_LANG_STRING]: TypeAlias.SPARQL_STRINGLY,\n [TypeURL.RDF_DIR_LANG_STRING]: TypeAlias.SPARQL_STRINGLY,\n [TypeURL.XSD_STRING]: TypeAlias.SPARQL_STRINGLY,\n\n // String types\n [TypeURL.XSD_NORMALIZED_STRING]: TypeURL.XSD_STRING,\n [TypeURL.XSD_TOKEN]: TypeURL.XSD_NORMALIZED_STRING,\n [TypeURL.XSD_LANGUAGE]: TypeURL.XSD_TOKEN,\n [TypeURL.XSD_NM_TOKEN]: TypeURL.XSD_TOKEN,\n [TypeURL.XSD_NAME]: TypeURL.XSD_TOKEN,\n [TypeURL.XSD_NC_NAME]: TypeURL.XSD_NAME,\n [TypeURL.XSD_ENTITY]: TypeURL.XSD_NC_NAME,\n [TypeURL.XSD_ID]: TypeURL.XSD_NC_NAME,\n [TypeURL.XSD_ID_REF]: TypeURL.XSD_NC_NAME,\n // https://www.w3.org/TR/xpath-31/#dt-function-conversion\n // \"Each item in the atomic sequence that is of type xs:untypedAtomic is cast\n // to the expected generalized atomic type.\"\n // So then I looked in the specs for something about casting:\n // https://www.w3.org/TR/xpath-functions-31/#casting-from-strings\n // \"If the value is xs:untypedAtomic, it is treated in exactly the same way as a string\n // containing the same sequence of characters.\"\n // So it's not really a subtype by definition, but it works this way.\n [TypeURL.XSD_UNTYPED_ATOMIC]: TypeURL.XSD_STRING,\n\n // Numeric types\n // https://www.w3.org/TR/sparql11-query/#operandDataTypes\n // > numeric denotes typed literals with datatypes xsd:integer, xsd:decimal, xsd:float, and xsd:double\n [TypeURL.XSD_DOUBLE]: TypeAlias.SPARQL_NUMERIC,\n [TypeURL.XSD_FLOAT]: TypeAlias.SPARQL_NUMERIC,\n [TypeURL.XSD_DECIMAL]: TypeAlias.SPARQL_NUMERIC,\n\n // Decimal types\n [TypeURL.XSD_INTEGER]: TypeURL.XSD_DECIMAL,\n\n [TypeURL.XSD_NON_POSITIVE_INTEGER]: TypeURL.XSD_INTEGER,\n [TypeURL.XSD_NEGATIVE_INTEGER]: TypeURL.XSD_NON_POSITIVE_INTEGER,\n\n [TypeURL.XSD_LONG]: TypeURL.XSD_INTEGER,\n [TypeURL.XSD_INT]: TypeURL.XSD_LONG,\n [TypeURL.XSD_SHORT]: TypeURL.XSD_INT,\n [TypeURL.XSD_BYTE]: TypeURL.XSD_SHORT,\n\n [TypeURL.XSD_NON_NEGATIVE_INTEGER]: TypeURL.XSD_INTEGER,\n [TypeURL.XSD_POSITIVE_INTEGER]: TypeURL.XSD_NON_NEGATIVE_INTEGER,\n [TypeURL.XSD_UNSIGNED_LONG]: TypeURL.XSD_NON_NEGATIVE_INTEGER,\n [TypeURL.XSD_UNSIGNED_INT]: TypeURL.XSD_UNSIGNED_LONG,\n [TypeURL.XSD_UNSIGNED_SHORT]: TypeURL.XSD_UNSIGNED_INT,\n [TypeURL.XSD_UNSIGNED_BYTE]: TypeURL.XSD_UNSIGNED_SHORT,\n\n [TypeURL.XSD_DATE_TIME]: 'term',\n [TypeURL.XSD_BOOLEAN]: 'term',\n [TypeURL.XSD_DATE]: 'term',\n [TypeURL.XSD_G_MONTH]: 'term',\n [TypeURL.XSD_G_MONTHDAY]: 'term',\n [TypeURL.XSD_G_YEAR]: 'term',\n [TypeURL.XSD_G_YEAR_MONTH]: 'term',\n [TypeURL.XSD_TIME]: 'term',\n [TypeURL.XSD_G_DAY]: 'term',\n [TypeURL.XSD_DURATION]: 'term',\n [TypeAlias.SPARQL_NUMERIC]: 'term',\n [TypeAlias.SPARQL_STRINGLY]: 'term',\n [TypeURL.XSD_ANY_URI]: 'term',\n};\ntype SuperTypeDict = Record<KnownLiteralTypes, number> & { __depth: number };\ntype SuperTypeDictTable = Record<KnownLiteralTypes, SuperTypeDict>;\nexport const superTypeDictTable: SuperTypeDictTable = Object.create(null);\n\n/**\n * This will return the super types of a type and cache them.\n * @param type IRI we will decide the super types of.\n * @param openWorldType the enabler that provides a way to find super types.\n */\nexport function getSuperTypes(type: string, openWorldType: ISuperTypeProvider): GeneralSuperTypeDict {\n const cached = openWorldType.cache.get(type);\n if (cached) {\n return cached;\n }\n const value = openWorldType.discoverer(type);\n if (value === 'term') {\n const res: GeneralSuperTypeDict = Object.create(null);\n res.__depth = 0;\n res[type] = 0;\n openWorldType.cache.set(type, res);\n return res;\n }\n let subExtension: GeneralSuperTypeDict;\n const knownValue = asKnownLiteralType(value);\n if (knownValue) {\n subExtension = { ...superTypeDictTable[knownValue] };\n } else {\n subExtension = { ...getSuperTypes(value, openWorldType) };\n }\n subExtension.__depth++;\n subExtension[type] = subExtension.__depth;\n openWorldType.cache.set(type, subExtension);\n return subExtension;\n}\n\n// No circular structure allowed! & No other keys allowed!\nexport function extensionTableInit(): void {\n for (const [ _key, value ] of Object.entries(extensionTableInput)) {\n const key = <KnownLiteralTypes>_key;\n if (superTypeDictTable[key]) {\n continue;\n }\n extensionTableBuilderInitKey(key, value, superTypeDictTable);\n }\n}\nextensionTableInit();\n\nfunction extensionTableBuilderInitKey(key: KnownLiteralTypes, value: OverrideType, res: SuperTypeDictTable): void {\n if (value === 'term' || value === undefined) {\n const baseRes: SuperTypeDict = Object.create(null);\n baseRes.__depth = 0;\n baseRes[key] = 0;\n res[key] = baseRes;\n return;\n }\n if (!res[value]) {\n extensionTableBuilderInitKey(value, extensionTableInput[value], res);\n }\n res[key] = { ...res[value], [key]: res[value].__depth + 1, __depth: res[value].__depth + 1 };\n}\n\nexport const typeAliasCheck: Record<TypeAlias, boolean> = Object.create(null);\nfunction initTypeAliasCheck(): void {\n for (const val of Object.values(TypeAlias)) {\n typeAliasCheck[val] = true;\n }\n}\ninitTypeAliasCheck();\n\nexport function asTypeAlias(type: string): TypeAlias | undefined {\n if (type in typeAliasCheck) {\n return <TypeAlias> type;\n }\n return undefined;\n}\n\nexport function asKnownLiteralType(type: string): KnownLiteralTypes | undefined {\n if (type in superTypeDictTable) {\n return <KnownLiteralTypes> type;\n }\n return undefined;\n}\n\nexport function asOverrideType(type: string): OverrideType | undefined {\n if (asKnownLiteralType(type) ?? type === 'term') {\n return <OverrideType> type;\n }\n return undefined;\n}\n\nexport function asGeneralType(type: string): 'term' | TermType | undefined {\n if (type === 'term' || asTermType(type)) {\n return <'term' | TermType> type;\n }\n return undefined;\n}\n\n/**\n * Internal type of @see isSubTypeOf This only takes knownTypes but doesn't need an enabler\n */\nexport function isInternalSubType(baseType: OverrideType, argumentType: KnownLiteralTypes): boolean {\n return baseType !== 'term' &&\n (superTypeDictTable[baseType] && superTypeDictTable[baseType][argumentType] !== undefined);\n}\n\n/**\n * This function can be used to check the base type is a restriction on a type in the dict.\n * If we want to check if type x is a restriction on string we do this by calling:\n * 'http://www.w3.org/2001/XMLSchema#string' in getSuperTypeDict(X, superTypeProvider)\n * @param baseType\n * @param superTypeProvider\n */\nexport function getSuperTypeDict(baseType: string, superTypeProvider: ISuperTypeProvider): GeneralSuperTypeDict {\n const concreteType: KnownLiteralTypes | undefined = asKnownLiteralType(baseType);\n if (concreteType) {\n // Concrete dataType is known by utils-expression-evaluator.\n return superTypeDictTable[concreteType];\n }\n // Datatype is a custom datatype\n return getSuperTypes(baseType, superTypeProvider);\n}\n\n/**\n * This function needs to be O(1)! The execution time of this function is vital!\n * We define typeA isSubtypeOf typeA as true.\n * If you find yourself using this function a lot (e.g. in a case) please use getSuperTypeDict instead.\n * @param baseType type you want to provide.\n * @param argumentType type you want to provide @param baseType to.\n * @param superTypeProvider the enabler to discover super types of unknown types.\n */\nexport function isSubTypeOf(\n baseType: string,\n argumentType: KnownLiteralTypes,\n superTypeProvider: ISuperTypeProvider,\n): boolean {\n if (baseType === 'term') {\n return false;\n }\n return getSuperTypeDict(baseType, superTypeProvider)[argumentType] !== undefined;\n}\n\n// Defined by https://www.w3.org/TR/xpath-31/#promotion .\n// e.g. When a function takes a string, it can also accept a XSD_ANY_URI if it's cast first.\nexport const typePromotion: Partial<Record<ArgumentType, {\n typeToPromote: KnownLiteralTypes;\n conversionFunction: (arg: TermExpression) => TermExpression;\n}[]>> = {\n [TypeURL.XSD_STRING]: [\n { typeToPromote: TypeURL.XSD_ANY_URI, conversionFunction: arg => string(arg.str()) },\n ],\n [TypeURL.XSD_DOUBLE]: [\n { typeToPromote: TypeURL.XSD_FLOAT, conversionFunction: arg => double((<E.NumericLiteral>arg).typedValue) },\n // TODO: in case of decimal a round needs to happen.\n { typeToPromote: TypeURL.XSD_DECIMAL, conversionFunction: arg => double((<E.NumericLiteral>arg).typedValue) },\n ],\n [TypeURL.XSD_FLOAT]: [\n // TODO: in case of decimal a round needs to happen.\n { typeToPromote: TypeURL.XSD_DECIMAL, conversionFunction: arg => float((<E.NumericLiteral>arg).typedValue) },\n ],\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/utils-expression-evaluator",
3
- "version": "4.5.0",
3
+ "version": "5.0.0",
4
4
  "description": "A simple SPARQL expression evaluator",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -38,13 +38,13 @@
38
38
  "build": "node \"../../node_modules/typescript/bin/tsc\""
39
39
  },
40
40
  "dependencies": {
41
- "@comunica/context-entries": "^4.5.0",
42
- "@comunica/types": "^4.5.0",
41
+ "@comunica/context-entries": "^5.0.0",
42
+ "@comunica/types": "^5.0.0",
43
+ "@comunica/utils-algebra": "^5.0.0",
43
44
  "@rdfjs/types": "*",
44
- "lru-cache": "^10.0.0",
45
- "rdf-data-factory": "^1.1.2",
46
- "rdf-string": "^1.6.3",
47
- "sparqlalgebrajs": "^5.0.2"
45
+ "lru-cache": "^11.2.2",
46
+ "rdf-data-factory": "^2.0.0",
47
+ "rdf-string": "^2.0.1"
48
48
  },
49
- "gitHead": "2bcd98c387a021fc5c08d375793c205ca3d1bf0d"
49
+ "gitHead": "0b1756fdb9bef014133432489627c1bd71779bd0"
50
50
  }