@medplum/core 1.0.4 → 1.0.5
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/dist/cjs/client.d.ts +1 -0
- package/dist/cjs/fhirlexer/parse.d.ts +18 -2
- package/dist/cjs/fhirmapper/parse.d.ts +2 -2
- package/dist/cjs/fhirpath/atoms.d.ts +28 -53
- package/dist/cjs/fhirpath/parse.d.ts +37 -0
- package/dist/cjs/index.js +724 -683
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/client.d.ts +1 -0
- package/dist/esm/client.js +26 -25
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/fhirlexer/parse.d.ts +18 -2
- package/dist/esm/fhirlexer/parse.js +33 -7
- package/dist/esm/fhirlexer/parse.js.map +1 -1
- package/dist/esm/fhirlexer/tokenize.js +1 -1
- package/dist/esm/fhirlexer/tokenize.js.map +1 -1
- package/dist/esm/fhirmapper/parse.d.ts +2 -2
- package/dist/esm/fhirpath/atoms.d.ts +28 -53
- package/dist/esm/fhirpath/atoms.js +70 -52
- package/dist/esm/fhirpath/atoms.js.map +1 -1
- package/dist/esm/fhirpath/parse.d.ts +37 -0
- package/dist/esm/fhirpath/parse.js +31 -34
- package/dist/esm/fhirpath/parse.js.map +1 -1
- package/dist/esm/fhirpath/tokenize.js +1 -1
- package/dist/esm/fhirpath/tokenize.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/fhirmapper/atoms.d.ts +0 -67
- package/dist/esm/fhirmapper/atoms.d.ts +0 -67
package/dist/cjs/index.js
CHANGED
|
@@ -6486,8 +6486,8 @@
|
|
|
6486
6486
|
|
|
6487
6487
|
// PKCE auth based on:
|
|
6488
6488
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
6489
|
-
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl,
|
|
6490
|
-
const MEDPLUM_VERSION = "1.0.
|
|
6489
|
+
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_clientId, _MedplumClient_clientSecret, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
|
|
6490
|
+
const MEDPLUM_VERSION = "1.0.5-53328b63";
|
|
6491
6491
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
6492
6492
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
6493
6493
|
const DEFAULT_CACHE_TIME = 60000; // 60 seconds
|
|
@@ -6557,11 +6557,12 @@
|
|
|
6557
6557
|
_MedplumClient_requestCache.set(this, void 0);
|
|
6558
6558
|
_MedplumClient_cacheTime.set(this, void 0);
|
|
6559
6559
|
_MedplumClient_baseUrl.set(this, void 0);
|
|
6560
|
-
_MedplumClient_clientId.set(this, void 0);
|
|
6561
6560
|
_MedplumClient_authorizeUrl.set(this, void 0);
|
|
6562
6561
|
_MedplumClient_tokenUrl.set(this, void 0);
|
|
6563
6562
|
_MedplumClient_logoutUrl.set(this, void 0);
|
|
6564
6563
|
_MedplumClient_onUnauthenticated.set(this, void 0);
|
|
6564
|
+
_MedplumClient_clientId.set(this, void 0);
|
|
6565
|
+
_MedplumClient_clientSecret.set(this, void 0);
|
|
6565
6566
|
_MedplumClient_accessToken.set(this, void 0);
|
|
6566
6567
|
_MedplumClient_refreshToken.set(this, void 0);
|
|
6567
6568
|
_MedplumClient_refreshPromise.set(this, void 0);
|
|
@@ -7841,6 +7842,8 @@
|
|
|
7841
7842
|
*/
|
|
7842
7843
|
startClientLogin(clientId, clientSecret) {
|
|
7843
7844
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7845
|
+
__classPrivateFieldSet(this, _MedplumClient_clientId, clientId, "f");
|
|
7846
|
+
__classPrivateFieldSet(this, _MedplumClient_clientSecret, clientSecret, "f");
|
|
7844
7847
|
const formBody = new URLSearchParams();
|
|
7845
7848
|
formBody.set('grant_type', 'client_credentials');
|
|
7846
7849
|
formBody.set('client_id', clientId);
|
|
@@ -7849,7 +7852,7 @@
|
|
|
7849
7852
|
});
|
|
7850
7853
|
}
|
|
7851
7854
|
}
|
|
7852
|
-
_MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(),
|
|
7855
|
+
_MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_clientSecret = new WeakMap(), _MedplumClient_accessToken = new WeakMap(), _MedplumClient_refreshToken = new WeakMap(), _MedplumClient_refreshPromise = new WeakMap(), _MedplumClient_profilePromise = new WeakMap(), _MedplumClient_profile = new WeakMap(), _MedplumClient_config = new WeakMap(), _MedplumClient_instances = new WeakSet(), _MedplumClient_addLogin = function _MedplumClient_addLogin(newLogin) {
|
|
7853
7856
|
const logins = this.getLogins().filter((login) => { var _a, _b; return ((_a = login.profile) === null || _a === void 0 ? void 0 : _a.reference) !== ((_b = newLogin.profile) === null || _b === void 0 ? void 0 : _b.reference); });
|
|
7854
7857
|
logins.push(newLogin);
|
|
7855
7858
|
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
|
|
@@ -7941,17 +7944,14 @@
|
|
|
7941
7944
|
options.body = JSON.stringify(data);
|
|
7942
7945
|
}
|
|
7943
7946
|
}, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, options) {
|
|
7944
|
-
|
|
7945
|
-
return __classPrivateFieldGet(this, _MedplumClient_instances, "m",
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
return Promise.reject(error);
|
|
7953
|
-
});
|
|
7954
|
-
});
|
|
7947
|
+
if (__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)) {
|
|
7948
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options);
|
|
7949
|
+
}
|
|
7950
|
+
this.clear();
|
|
7951
|
+
if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
|
|
7952
|
+
__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
|
|
7953
|
+
}
|
|
7954
|
+
return Promise.reject(new Error('Unauthenticated'));
|
|
7955
7955
|
}, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
|
|
7956
7956
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7957
7957
|
yield this.startPkce();
|
|
@@ -7965,21 +7965,22 @@
|
|
|
7965
7965
|
window.location.assign(url.toString());
|
|
7966
7966
|
});
|
|
7967
7967
|
}, _MedplumClient_refresh = function _MedplumClient_refresh() {
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
if (!__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
|
|
7973
|
-
this.clear();
|
|
7974
|
-
throw new Error('Invalid refresh token');
|
|
7975
|
-
}
|
|
7968
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
7969
|
+
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
7970
|
+
}
|
|
7971
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
|
|
7976
7972
|
const formBody = new URLSearchParams();
|
|
7977
7973
|
formBody.set('grant_type', 'refresh_token');
|
|
7978
7974
|
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
7979
7975
|
formBody.set('refresh_token', __classPrivateFieldGet(this, _MedplumClient_refreshToken, "f"));
|
|
7980
7976
|
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody), "f");
|
|
7981
|
-
|
|
7982
|
-
}
|
|
7977
|
+
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
7978
|
+
}
|
|
7979
|
+
if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && __classPrivateFieldGet(this, _MedplumClient_clientSecret, "f")) {
|
|
7980
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, this.startClientLogin(__classPrivateFieldGet(this, _MedplumClient_clientId, "f"), __classPrivateFieldGet(this, _MedplumClient_clientSecret, "f")), "f");
|
|
7981
|
+
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
7982
|
+
}
|
|
7983
|
+
return undefined;
|
|
7983
7984
|
}, _MedplumClient_fetchTokens = function _MedplumClient_fetchTokens(formBody) {
|
|
7984
7985
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7985
7986
|
return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
|
|
@@ -8047,150 +8048,485 @@
|
|
|
8047
8048
|
return url.endsWith('/') ? url : url + '/';
|
|
8048
8049
|
}
|
|
8049
8050
|
|
|
8050
|
-
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
}
|
|
8056
|
-
if (str.length <= 10) {
|
|
8057
|
-
// If a local date (i.e., "2021-01-01"),
|
|
8058
|
-
// then return as-is.
|
|
8059
|
-
return str;
|
|
8060
|
-
}
|
|
8061
|
-
try {
|
|
8062
|
-
// Try to normalize to UTC
|
|
8063
|
-
return new Date(str).toISOString();
|
|
8051
|
+
var _ParserBuilder_prefixParselets, _ParserBuilder_infixParselets, _Parser_tokens, _Parser_prefixParselets, _Parser_infixParselets;
|
|
8052
|
+
class PrefixOperatorAtom {
|
|
8053
|
+
constructor(operator, child) {
|
|
8054
|
+
this.operator = operator;
|
|
8055
|
+
this.child = child;
|
|
8064
8056
|
}
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
// This happens on unsupported time formats such as "2021-01-01T12"
|
|
8068
|
-
return str;
|
|
8057
|
+
toString() {
|
|
8058
|
+
return `${this.operator}(${this.child.toString()})`;
|
|
8069
8059
|
}
|
|
8070
8060
|
}
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
*/
|
|
8077
|
-
function booleanToTypedValue(value) {
|
|
8078
|
-
return [{ type: exports.PropertyType.boolean, value }];
|
|
8079
|
-
}
|
|
8080
|
-
/**
|
|
8081
|
-
* Returns a "best guess" TypedValue for a given value.
|
|
8082
|
-
* @param value The unknown value to check.
|
|
8083
|
-
* @returns A "best guess" TypedValue for the given value.
|
|
8084
|
-
*/
|
|
8085
|
-
function toTypedValue(value) {
|
|
8086
|
-
if (value === null || value === undefined) {
|
|
8087
|
-
return { type: 'undefined', value: undefined };
|
|
8061
|
+
class InfixOperatorAtom {
|
|
8062
|
+
constructor(operator, left, right) {
|
|
8063
|
+
this.operator = operator;
|
|
8064
|
+
this.left = left;
|
|
8065
|
+
this.right = right;
|
|
8088
8066
|
}
|
|
8089
|
-
|
|
8090
|
-
return {
|
|
8067
|
+
toString() {
|
|
8068
|
+
return `${this.left.toString()} ${this.operator} ${this.right.toString()}`;
|
|
8091
8069
|
}
|
|
8092
|
-
|
|
8093
|
-
|
|
8070
|
+
}
|
|
8071
|
+
class ParserBuilder {
|
|
8072
|
+
constructor() {
|
|
8073
|
+
_ParserBuilder_prefixParselets.set(this, {});
|
|
8074
|
+
_ParserBuilder_infixParselets.set(this, {});
|
|
8094
8075
|
}
|
|
8095
|
-
|
|
8096
|
-
|
|
8076
|
+
registerInfix(tokenType, parselet) {
|
|
8077
|
+
__classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
|
|
8078
|
+
return this;
|
|
8097
8079
|
}
|
|
8098
|
-
|
|
8099
|
-
|
|
8080
|
+
registerPrefix(tokenType, parselet) {
|
|
8081
|
+
__classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
|
|
8082
|
+
return this;
|
|
8100
8083
|
}
|
|
8101
|
-
|
|
8102
|
-
return
|
|
8084
|
+
prefix(tokenType, precedence, builder) {
|
|
8085
|
+
return this.registerPrefix(tokenType, {
|
|
8086
|
+
parse(parser, token) {
|
|
8087
|
+
const right = parser.consumeAndParse(precedence);
|
|
8088
|
+
return builder(token, right);
|
|
8089
|
+
},
|
|
8090
|
+
});
|
|
8103
8091
|
}
|
|
8104
|
-
|
|
8105
|
-
return
|
|
8092
|
+
infixLeft(tokenType, precedence, builder) {
|
|
8093
|
+
return this.registerInfix(tokenType, {
|
|
8094
|
+
parse(parser, left, token) {
|
|
8095
|
+
const right = parser.consumeAndParse(precedence);
|
|
8096
|
+
return builder(left, token, right);
|
|
8097
|
+
},
|
|
8098
|
+
precedence,
|
|
8099
|
+
});
|
|
8106
8100
|
}
|
|
8107
|
-
|
|
8108
|
-
return
|
|
8101
|
+
construct(input) {
|
|
8102
|
+
return new Parser(input, __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
|
|
8109
8103
|
}
|
|
8110
8104
|
}
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
}
|
|
8121
|
-
/**
|
|
8122
|
-
* Returns the value of the property and the property type.
|
|
8123
|
-
* Some property definitions support multiple types.
|
|
8124
|
-
* For example, "Observation.value[x]" can be "valueString", "valueInteger", "valueQuantity", etc.
|
|
8125
|
-
* According to the spec, there can only be one property for a given element definition.
|
|
8126
|
-
* This function returns the value and the type.
|
|
8127
|
-
* @param input The base context (FHIR resource or backbone element).
|
|
8128
|
-
* @param path The property path.
|
|
8129
|
-
* @returns The value of the property and the property type.
|
|
8130
|
-
*/
|
|
8131
|
-
function getTypedPropertyValue(input, path) {
|
|
8132
|
-
if (!(input === null || input === void 0 ? void 0 : input.value)) {
|
|
8133
|
-
return undefined;
|
|
8105
|
+
_ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
|
|
8106
|
+
class Parser {
|
|
8107
|
+
constructor(tokens, prefixParselets, infixParselets) {
|
|
8108
|
+
_Parser_tokens.set(this, void 0);
|
|
8109
|
+
_Parser_prefixParselets.set(this, void 0);
|
|
8110
|
+
_Parser_infixParselets.set(this, void 0);
|
|
8111
|
+
__classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
|
|
8112
|
+
__classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
|
|
8113
|
+
__classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
|
|
8134
8114
|
}
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
const typedResult = getTypedPropertyValueWithSchema(input, path, elementDefinition);
|
|
8138
|
-
if (typedResult) {
|
|
8139
|
-
return typedResult;
|
|
8140
|
-
}
|
|
8115
|
+
hasMore() {
|
|
8116
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0;
|
|
8141
8117
|
}
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
* @returns The value of the property and the property type.
|
|
8150
|
-
*/
|
|
8151
|
-
function getTypedPropertyValueWithSchema(input, path, property) {
|
|
8152
|
-
var _a;
|
|
8153
|
-
const types = property.type;
|
|
8154
|
-
if (!types || types.length === 0) {
|
|
8155
|
-
return undefined;
|
|
8118
|
+
match(expected) {
|
|
8119
|
+
const token = this.peek();
|
|
8120
|
+
if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
|
|
8121
|
+
return false;
|
|
8122
|
+
}
|
|
8123
|
+
this.consume();
|
|
8124
|
+
return true;
|
|
8156
8125
|
}
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8126
|
+
consumeAndParse(precedence = Infinity) {
|
|
8127
|
+
const token = this.consume();
|
|
8128
|
+
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
8129
|
+
if (!prefix) {
|
|
8130
|
+
throw Error(`Parse error at "${token.value}" (line ${token.line}, column ${token.column}). No matching prefix parselet.`);
|
|
8131
|
+
}
|
|
8132
|
+
let left = prefix.parse(this, token);
|
|
8133
|
+
while (precedence > this.getPrecedence()) {
|
|
8134
|
+
const next = this.consume();
|
|
8135
|
+
const infix = this.getInfixParselet(next);
|
|
8136
|
+
left = infix.parse(this, left, next);
|
|
8137
|
+
}
|
|
8138
|
+
return left;
|
|
8162
8139
|
}
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
resultValue = input.value[path2];
|
|
8168
|
-
resultType = type.code;
|
|
8169
|
-
break;
|
|
8170
|
-
}
|
|
8140
|
+
getPrecedence() {
|
|
8141
|
+
const nextToken = this.peek();
|
|
8142
|
+
if (!nextToken) {
|
|
8143
|
+
return Infinity;
|
|
8171
8144
|
}
|
|
8145
|
+
const parser = this.getInfixParselet(nextToken);
|
|
8146
|
+
if (parser) {
|
|
8147
|
+
return parser.precedence;
|
|
8148
|
+
}
|
|
8149
|
+
return Infinity;
|
|
8172
8150
|
}
|
|
8173
|
-
|
|
8174
|
-
|
|
8151
|
+
consume(expectedId, expectedValue) {
|
|
8152
|
+
var _a, _b;
|
|
8153
|
+
if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
|
|
8154
|
+
throw Error('Cant consume unknown more tokens.');
|
|
8155
|
+
}
|
|
8156
|
+
if (expectedId && ((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.id) !== expectedId) {
|
|
8157
|
+
const actual = this.peek();
|
|
8158
|
+
throw Error(`Expected ${expectedId} but got "${actual.id}" at line ${actual.line} column ${actual.column}.`);
|
|
8159
|
+
}
|
|
8160
|
+
if (expectedValue && ((_b = this.peek()) === null || _b === void 0 ? void 0 : _b.value) !== expectedValue) {
|
|
8161
|
+
const actual = this.peek();
|
|
8162
|
+
throw Error(`Expected "${expectedValue}" but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
|
|
8163
|
+
}
|
|
8164
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
|
|
8175
8165
|
}
|
|
8176
|
-
|
|
8177
|
-
|
|
8166
|
+
peek() {
|
|
8167
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
|
|
8178
8168
|
}
|
|
8179
|
-
|
|
8180
|
-
|
|
8169
|
+
removeComments() {
|
|
8170
|
+
__classPrivateFieldSet(this, _Parser_tokens, __classPrivateFieldGet(this, _Parser_tokens, "f").filter((t) => t.id !== 'Comment'), "f");
|
|
8181
8171
|
}
|
|
8182
|
-
|
|
8183
|
-
return
|
|
8172
|
+
getInfixParselet(token) {
|
|
8173
|
+
return __classPrivateFieldGet(this, _Parser_infixParselets, "f")[token.id === 'Symbol' ? token.value : token.id];
|
|
8184
8174
|
}
|
|
8185
8175
|
}
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8176
|
+
_Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser_infixParselets = new WeakMap();
|
|
8177
|
+
|
|
8178
|
+
var _Tokenizer_instances, _Tokenizer_str, _Tokenizer_keywords, _Tokenizer_operators, _Tokenizer_result, _Tokenizer_pos, _Tokenizer_markStack, _Tokenizer_prevToken, _Tokenizer_peekToken, _Tokenizer_consumeToken, _Tokenizer_consumeWhitespace, _Tokenizer_consumeMultiLineComment, _Tokenizer_consumeSingleLineComment, _Tokenizer_consumeString, _Tokenizer_consumeBacktickSymbol, _Tokenizer_consumeDateTime, _Tokenizer_consumeNumber, _Tokenizer_consumeSymbol, _Tokenizer_consumeOperator, _Tokenizer_consumeWhile, _Tokenizer_curr, _Tokenizer_prev, _Tokenizer_peek, _Tokenizer_mark, _Tokenizer_reset, _Tokenizer_advance, _Tokenizer_buildToken;
|
|
8179
|
+
const STANDARD_UNITS = [
|
|
8180
|
+
'year',
|
|
8181
|
+
'years',
|
|
8182
|
+
'month',
|
|
8183
|
+
'months',
|
|
8184
|
+
'week',
|
|
8185
|
+
'weeks',
|
|
8186
|
+
'day',
|
|
8187
|
+
'days',
|
|
8188
|
+
'hour',
|
|
8189
|
+
'hours',
|
|
8190
|
+
'minute',
|
|
8191
|
+
'minutes',
|
|
8192
|
+
'second',
|
|
8193
|
+
'seconds',
|
|
8194
|
+
'millisecond',
|
|
8195
|
+
'milliseconds',
|
|
8196
|
+
];
|
|
8197
|
+
class Tokenizer {
|
|
8198
|
+
constructor(str, keywords, operators) {
|
|
8199
|
+
_Tokenizer_instances.add(this);
|
|
8200
|
+
_Tokenizer_str.set(this, void 0);
|
|
8201
|
+
_Tokenizer_keywords.set(this, void 0);
|
|
8202
|
+
_Tokenizer_operators.set(this, void 0);
|
|
8203
|
+
_Tokenizer_result.set(this, []);
|
|
8204
|
+
_Tokenizer_pos.set(this, { index: 0, line: 1, column: 0 });
|
|
8205
|
+
_Tokenizer_markStack.set(this, []);
|
|
8206
|
+
__classPrivateFieldSet(this, _Tokenizer_str, str, "f");
|
|
8207
|
+
__classPrivateFieldSet(this, _Tokenizer_keywords, keywords, "f");
|
|
8208
|
+
__classPrivateFieldSet(this, _Tokenizer_operators, operators, "f");
|
|
8189
8209
|
}
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8210
|
+
tokenize() {
|
|
8211
|
+
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
|
|
8212
|
+
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
8213
|
+
if (token) {
|
|
8214
|
+
__classPrivateFieldGet(this, _Tokenizer_result, "f").push(token);
|
|
8215
|
+
}
|
|
8216
|
+
}
|
|
8217
|
+
return __classPrivateFieldGet(this, _Tokenizer_result, "f");
|
|
8218
|
+
}
|
|
8219
|
+
}
|
|
8220
|
+
_Tokenizer_str = new WeakMap(), _Tokenizer_keywords = new WeakMap(), _Tokenizer_operators = new WeakMap(), _Tokenizer_result = new WeakMap(), _Tokenizer_pos = new WeakMap(), _Tokenizer_markStack = new WeakMap(), _Tokenizer_instances = new WeakSet(), _Tokenizer_prevToken = function _Tokenizer_prevToken() {
|
|
8221
|
+
return __classPrivateFieldGet(this, _Tokenizer_result, "f").slice(-1)[0];
|
|
8222
|
+
}, _Tokenizer_peekToken = function _Tokenizer_peekToken() {
|
|
8223
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
|
|
8224
|
+
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
8225
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_reset).call(this);
|
|
8226
|
+
return token;
|
|
8227
|
+
}, _Tokenizer_consumeToken = function _Tokenizer_consumeToken() {
|
|
8228
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhitespace).call(this);
|
|
8229
|
+
const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
|
|
8230
|
+
if (!c) {
|
|
8231
|
+
return undefined;
|
|
8232
|
+
}
|
|
8233
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
|
|
8234
|
+
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
8235
|
+
if (c === '/' && next === '*') {
|
|
8236
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeMultiLineComment).call(this);
|
|
8237
|
+
}
|
|
8238
|
+
if (c === '/' && next === '/') {
|
|
8239
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSingleLineComment).call(this);
|
|
8240
|
+
}
|
|
8241
|
+
if (c === "'" || c === '"') {
|
|
8242
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeString).call(this, c);
|
|
8243
|
+
}
|
|
8244
|
+
if (c === '`') {
|
|
8245
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeBacktickSymbol).call(this);
|
|
8246
|
+
}
|
|
8247
|
+
if (c === '@') {
|
|
8248
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeDateTime).call(this);
|
|
8249
|
+
}
|
|
8250
|
+
if (c.match(/\d/)) {
|
|
8251
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeNumber).call(this);
|
|
8252
|
+
}
|
|
8253
|
+
if (c.match(/\w/)) {
|
|
8254
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
|
|
8255
|
+
}
|
|
8256
|
+
if (c === '$' && next.match(/\w/)) {
|
|
8257
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
|
|
8258
|
+
}
|
|
8259
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeOperator).call(this);
|
|
8260
|
+
}, _Tokenizer_consumeWhitespace = function _Tokenizer_consumeWhitespace() {
|
|
8261
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\s/));
|
|
8262
|
+
}, _Tokenizer_consumeMultiLineComment = function _Tokenizer_consumeMultiLineComment() {
|
|
8263
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
8264
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '*' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this) !== '/');
|
|
8265
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8266
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8267
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
8268
|
+
}, _Tokenizer_consumeSingleLineComment = function _Tokenizer_consumeSingleLineComment() {
|
|
8269
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '\n'));
|
|
8270
|
+
}, _Tokenizer_consumeString = function _Tokenizer_consumeString(endChar) {
|
|
8271
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8272
|
+
const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'String', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prev).call(this) === '\\' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== endChar));
|
|
8273
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8274
|
+
return result;
|
|
8275
|
+
}, _Tokenizer_consumeBacktickSymbol = function _Tokenizer_consumeBacktickSymbol() {
|
|
8276
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8277
|
+
const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '`'));
|
|
8278
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8279
|
+
return result;
|
|
8280
|
+
}, _Tokenizer_consumeDateTime = function _Tokenizer_consumeDateTime() {
|
|
8281
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this); // Consume "@"
|
|
8282
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
8283
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d-]/));
|
|
8284
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'T') {
|
|
8285
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8286
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
8287
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
8288
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8289
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
8290
|
+
}
|
|
8291
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'Z') {
|
|
8292
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8293
|
+
}
|
|
8294
|
+
else if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '+' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '-') {
|
|
8295
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8296
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
8297
|
+
}
|
|
8298
|
+
}
|
|
8299
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'DateTime', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
8300
|
+
}, _Tokenizer_consumeNumber = function _Tokenizer_consumeNumber() {
|
|
8301
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
8302
|
+
let id = 'Number';
|
|
8303
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
8304
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
8305
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8306
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
8307
|
+
}
|
|
8308
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === ' ') {
|
|
8309
|
+
if (isUnitToken(__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peekToken).call(this))) {
|
|
8310
|
+
id = 'Quantity';
|
|
8311
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
8312
|
+
}
|
|
8313
|
+
}
|
|
8314
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, id, __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
8315
|
+
}, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
|
|
8316
|
+
var _a;
|
|
8317
|
+
const value = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/));
|
|
8318
|
+
if (((_a = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prevToken).call(this)) === null || _a === void 0 ? void 0 : _a.value) !== '.' && __classPrivateFieldGet(this, _Tokenizer_keywords, "f").includes(value)) {
|
|
8319
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, value, value);
|
|
8320
|
+
}
|
|
8321
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', value);
|
|
8322
|
+
}, _Tokenizer_consumeOperator = function _Tokenizer_consumeOperator() {
|
|
8323
|
+
const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
|
|
8324
|
+
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
8325
|
+
const twoCharOp = c + next;
|
|
8326
|
+
if (__classPrivateFieldGet(this, _Tokenizer_operators, "f").includes(twoCharOp)) {
|
|
8327
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8328
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8329
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, twoCharOp, twoCharOp);
|
|
8330
|
+
}
|
|
8331
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8332
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, c, c);
|
|
8333
|
+
}, _Tokenizer_consumeWhile = function _Tokenizer_consumeWhile(condition) {
|
|
8334
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
8335
|
+
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length && condition()) {
|
|
8336
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
8337
|
+
}
|
|
8338
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index);
|
|
8339
|
+
}, _Tokenizer_curr = function _Tokenizer_curr() {
|
|
8340
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index];
|
|
8341
|
+
}, _Tokenizer_prev = function _Tokenizer_prev() {
|
|
8342
|
+
var _a;
|
|
8343
|
+
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1]) !== null && _a !== void 0 ? _a : '';
|
|
8344
|
+
}, _Tokenizer_peek = function _Tokenizer_peek() {
|
|
8345
|
+
var _a;
|
|
8346
|
+
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1]) !== null && _a !== void 0 ? _a : '';
|
|
8347
|
+
}, _Tokenizer_mark = function _Tokenizer_mark() {
|
|
8348
|
+
__classPrivateFieldGet(this, _Tokenizer_markStack, "f").push(Object.assign({}, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
|
|
8349
|
+
}, _Tokenizer_reset = function _Tokenizer_reset() {
|
|
8350
|
+
const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
|
|
8351
|
+
if (!mark) {
|
|
8352
|
+
throw new Error('No mark to reset to');
|
|
8353
|
+
}
|
|
8354
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").index = mark.index;
|
|
8355
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").line = mark.line;
|
|
8356
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column = mark.column;
|
|
8357
|
+
}, _Tokenizer_advance = function _Tokenizer_advance() {
|
|
8358
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").index++;
|
|
8359
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '\n') {
|
|
8360
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").line++;
|
|
8361
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column = 0;
|
|
8362
|
+
}
|
|
8363
|
+
else {
|
|
8364
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column++;
|
|
8365
|
+
}
|
|
8366
|
+
}, _Tokenizer_buildToken = function _Tokenizer_buildToken(id, value) {
|
|
8367
|
+
const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
|
|
8368
|
+
if (!mark) {
|
|
8369
|
+
throw new Error('No mark for token');
|
|
8370
|
+
}
|
|
8371
|
+
return Object.assign({ id,
|
|
8372
|
+
value }, mark);
|
|
8373
|
+
};
|
|
8374
|
+
function isUnitToken(token) {
|
|
8375
|
+
if (token) {
|
|
8376
|
+
if (token.id === 'String') {
|
|
8377
|
+
return true;
|
|
8378
|
+
}
|
|
8379
|
+
if (token.id === 'Symbol' && STANDARD_UNITS.includes(token.value)) {
|
|
8380
|
+
return true;
|
|
8381
|
+
}
|
|
8382
|
+
}
|
|
8383
|
+
return false;
|
|
8384
|
+
}
|
|
8385
|
+
|
|
8386
|
+
function parseDateString(str) {
|
|
8387
|
+
if (str.startsWith('T')) {
|
|
8388
|
+
// If a time string,
|
|
8389
|
+
// then normalize to full length.
|
|
8390
|
+
return str + 'T00:00:00.000Z'.substring(str.length);
|
|
8391
|
+
}
|
|
8392
|
+
if (str.length <= 10) {
|
|
8393
|
+
// If a local date (i.e., "2021-01-01"),
|
|
8394
|
+
// then return as-is.
|
|
8395
|
+
return str;
|
|
8396
|
+
}
|
|
8397
|
+
try {
|
|
8398
|
+
// Try to normalize to UTC
|
|
8399
|
+
return new Date(str).toISOString();
|
|
8400
|
+
}
|
|
8401
|
+
catch (e) {
|
|
8402
|
+
// Fallback to original input
|
|
8403
|
+
// This happens on unsupported time formats such as "2021-01-01T12"
|
|
8404
|
+
return str;
|
|
8405
|
+
}
|
|
8406
|
+
}
|
|
8407
|
+
|
|
8408
|
+
/**
|
|
8409
|
+
* Returns a single element array with a typed boolean value.
|
|
8410
|
+
* @param value The primitive boolean value.
|
|
8411
|
+
* @returns Single element array with a typed boolean value.
|
|
8412
|
+
*/
|
|
8413
|
+
function booleanToTypedValue(value) {
|
|
8414
|
+
return [{ type: exports.PropertyType.boolean, value }];
|
|
8415
|
+
}
|
|
8416
|
+
/**
|
|
8417
|
+
* Returns a "best guess" TypedValue for a given value.
|
|
8418
|
+
* @param value The unknown value to check.
|
|
8419
|
+
* @returns A "best guess" TypedValue for the given value.
|
|
8420
|
+
*/
|
|
8421
|
+
function toTypedValue(value) {
|
|
8422
|
+
if (value === null || value === undefined) {
|
|
8423
|
+
return { type: 'undefined', value: undefined };
|
|
8424
|
+
}
|
|
8425
|
+
else if (Number.isSafeInteger(value)) {
|
|
8426
|
+
return { type: exports.PropertyType.integer, value };
|
|
8427
|
+
}
|
|
8428
|
+
else if (typeof value === 'number') {
|
|
8429
|
+
return { type: exports.PropertyType.decimal, value };
|
|
8430
|
+
}
|
|
8431
|
+
else if (typeof value === 'boolean') {
|
|
8432
|
+
return { type: exports.PropertyType.boolean, value };
|
|
8433
|
+
}
|
|
8434
|
+
else if (typeof value === 'string') {
|
|
8435
|
+
return { type: exports.PropertyType.string, value };
|
|
8436
|
+
}
|
|
8437
|
+
else if (isQuantity(value)) {
|
|
8438
|
+
return { type: exports.PropertyType.Quantity, value };
|
|
8439
|
+
}
|
|
8440
|
+
else if (typeof value === 'object' && 'resourceType' in value) {
|
|
8441
|
+
return { type: value.resourceType, value };
|
|
8442
|
+
}
|
|
8443
|
+
else {
|
|
8444
|
+
return { type: exports.PropertyType.BackboneElement, value };
|
|
8445
|
+
}
|
|
8446
|
+
}
|
|
8447
|
+
/**
|
|
8448
|
+
* Converts unknown object into a JavaScript boolean.
|
|
8449
|
+
* Note that this is different than the FHIRPath "toBoolean",
|
|
8450
|
+
* which has particular semantics around arrays, empty arrays, and type conversions.
|
|
8451
|
+
* @param obj Any value or array of values.
|
|
8452
|
+
* @returns The converted boolean value according to FHIRPath rules.
|
|
8453
|
+
*/
|
|
8454
|
+
function toJsBoolean(obj) {
|
|
8455
|
+
return obj.length === 0 ? false : !!obj[0].value;
|
|
8456
|
+
}
|
|
8457
|
+
/**
|
|
8458
|
+
* Returns the value of the property and the property type.
|
|
8459
|
+
* Some property definitions support multiple types.
|
|
8460
|
+
* For example, "Observation.value[x]" can be "valueString", "valueInteger", "valueQuantity", etc.
|
|
8461
|
+
* According to the spec, there can only be one property for a given element definition.
|
|
8462
|
+
* This function returns the value and the type.
|
|
8463
|
+
* @param input The base context (FHIR resource or backbone element).
|
|
8464
|
+
* @param path The property path.
|
|
8465
|
+
* @returns The value of the property and the property type.
|
|
8466
|
+
*/
|
|
8467
|
+
function getTypedPropertyValue(input, path) {
|
|
8468
|
+
if (!(input === null || input === void 0 ? void 0 : input.value)) {
|
|
8469
|
+
return undefined;
|
|
8470
|
+
}
|
|
8471
|
+
const elementDefinition = getElementDefinition(input.type, path);
|
|
8472
|
+
if (elementDefinition) {
|
|
8473
|
+
const typedResult = getTypedPropertyValueWithSchema(input, path, elementDefinition);
|
|
8474
|
+
if (typedResult) {
|
|
8475
|
+
return typedResult;
|
|
8476
|
+
}
|
|
8477
|
+
}
|
|
8478
|
+
return getTypedPropertyValueWithoutSchema(input, path);
|
|
8479
|
+
}
|
|
8480
|
+
/**
|
|
8481
|
+
* Returns the value of the property and the property type using a type schema.
|
|
8482
|
+
* @param input The base context (FHIR resource or backbone element).
|
|
8483
|
+
* @param path The property path.
|
|
8484
|
+
* @param property The property element definition.
|
|
8485
|
+
* @returns The value of the property and the property type.
|
|
8486
|
+
*/
|
|
8487
|
+
function getTypedPropertyValueWithSchema(input, path, property) {
|
|
8488
|
+
var _a;
|
|
8489
|
+
const types = property.type;
|
|
8490
|
+
if (!types || types.length === 0) {
|
|
8491
|
+
return undefined;
|
|
8492
|
+
}
|
|
8493
|
+
let resultValue = undefined;
|
|
8494
|
+
let resultType = 'undefined';
|
|
8495
|
+
if (types.length === 1) {
|
|
8496
|
+
resultValue = input.value[path];
|
|
8497
|
+
resultType = types[0].code;
|
|
8498
|
+
}
|
|
8499
|
+
else {
|
|
8500
|
+
for (const type of types) {
|
|
8501
|
+
const path2 = path.replace('[x]', '') + capitalize(type.code);
|
|
8502
|
+
if (path2 in input.value) {
|
|
8503
|
+
resultValue = input.value[path2];
|
|
8504
|
+
resultType = type.code;
|
|
8505
|
+
break;
|
|
8506
|
+
}
|
|
8507
|
+
}
|
|
8508
|
+
}
|
|
8509
|
+
if (isEmpty(resultValue)) {
|
|
8510
|
+
return undefined;
|
|
8511
|
+
}
|
|
8512
|
+
if (resultType === 'Element' || resultType === 'BackboneElement') {
|
|
8513
|
+
resultType = buildTypeName((_a = property.path) === null || _a === void 0 ? void 0 : _a.split('.'));
|
|
8514
|
+
}
|
|
8515
|
+
if (Array.isArray(resultValue)) {
|
|
8516
|
+
return resultValue.map((element) => toTypedValueWithType(element, resultType));
|
|
8517
|
+
}
|
|
8518
|
+
else {
|
|
8519
|
+
return toTypedValueWithType(resultValue, resultType);
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8522
|
+
function toTypedValueWithType(value, type) {
|
|
8523
|
+
if (type === 'Resource' && typeof value === 'object' && 'resourceType' in value) {
|
|
8524
|
+
type = value.resourceType;
|
|
8525
|
+
}
|
|
8526
|
+
return { type, value };
|
|
8527
|
+
}
|
|
8528
|
+
/**
|
|
8529
|
+
* Returns the value of the property and the property type using a type schema.
|
|
8194
8530
|
* Note that because the type schema is not available, this function may be inaccurate.
|
|
8195
8531
|
* In some cases, that is the desired behavior.
|
|
8196
8532
|
* @param typedValue The base context (FHIR resource or backbone element).
|
|
@@ -9959,6 +10295,9 @@
|
|
|
9959
10295
|
throw new Error(`FhirPathError on "${this.original}": ${error}`);
|
|
9960
10296
|
}
|
|
9961
10297
|
}
|
|
10298
|
+
toString() {
|
|
10299
|
+
return this.child.toString();
|
|
10300
|
+
}
|
|
9962
10301
|
}
|
|
9963
10302
|
class LiteralAtom {
|
|
9964
10303
|
constructor(value) {
|
|
@@ -9967,6 +10306,13 @@
|
|
|
9967
10306
|
eval() {
|
|
9968
10307
|
return [this.value];
|
|
9969
10308
|
}
|
|
10309
|
+
toString() {
|
|
10310
|
+
const value = this.value.value;
|
|
10311
|
+
if (typeof value === 'string') {
|
|
10312
|
+
return `'${value}'`;
|
|
10313
|
+
}
|
|
10314
|
+
return value.toString();
|
|
10315
|
+
}
|
|
9970
10316
|
}
|
|
9971
10317
|
class SymbolAtom {
|
|
9972
10318
|
constructor(name) {
|
|
@@ -9982,6 +10328,9 @@
|
|
|
9982
10328
|
.flat()
|
|
9983
10329
|
.filter((e) => (e === null || e === void 0 ? void 0 : e.value) !== undefined);
|
|
9984
10330
|
}
|
|
10331
|
+
toString() {
|
|
10332
|
+
return this.name;
|
|
10333
|
+
}
|
|
9985
10334
|
}
|
|
9986
10335
|
_SymbolAtom_instances = new WeakSet(), _SymbolAtom_evalValue = function _SymbolAtom_evalValue(typedValue) {
|
|
9987
10336
|
const input = typedValue.value;
|
|
@@ -9997,582 +10346,276 @@
|
|
|
9997
10346
|
eval() {
|
|
9998
10347
|
return [];
|
|
9999
10348
|
}
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
constructor(child, impl) {
|
|
10003
|
-
this.child = child;
|
|
10004
|
-
this.impl = impl;
|
|
10005
|
-
}
|
|
10006
|
-
eval(context) {
|
|
10007
|
-
return this.impl(this.child.eval(context));
|
|
10008
|
-
}
|
|
10009
|
-
}
|
|
10010
|
-
class AsAtom {
|
|
10011
|
-
constructor(left, right) {
|
|
10012
|
-
this.left = left;
|
|
10013
|
-
this.right = right;
|
|
10014
|
-
}
|
|
10015
|
-
eval(context) {
|
|
10016
|
-
return functions.ofType(this.left.eval(context), this.right);
|
|
10349
|
+
toString() {
|
|
10350
|
+
return '{}';
|
|
10017
10351
|
}
|
|
10018
10352
|
}
|
|
10019
|
-
class
|
|
10020
|
-
constructor(
|
|
10021
|
-
|
|
10022
|
-
this.right = right;
|
|
10353
|
+
class UnaryOperatorAtom extends PrefixOperatorAtom {
|
|
10354
|
+
constructor(operator, child, impl) {
|
|
10355
|
+
super(operator, child);
|
|
10023
10356
|
this.impl = impl;
|
|
10024
10357
|
}
|
|
10025
|
-
eval(context) {
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
const rightEvalResult = this.right.eval(context);
|
|
10031
|
-
if (rightEvalResult.length !== 1) {
|
|
10032
|
-
return [];
|
|
10033
|
-
}
|
|
10034
|
-
const leftValue = leftEvalResult[0].value;
|
|
10035
|
-
const rightValue = rightEvalResult[0].value;
|
|
10036
|
-
const leftNumber = isQuantity(leftValue) ? leftValue.value : leftValue;
|
|
10037
|
-
const rightNumber = isQuantity(rightValue) ? rightValue.value : rightValue;
|
|
10038
|
-
const result = this.impl(leftNumber, rightNumber);
|
|
10039
|
-
if (typeof result === 'boolean') {
|
|
10040
|
-
return booleanToTypedValue(result);
|
|
10041
|
-
}
|
|
10042
|
-
else if (isQuantity(leftValue)) {
|
|
10043
|
-
return [{ type: exports.PropertyType.Quantity, value: Object.assign(Object.assign({}, leftValue), { value: result }) }];
|
|
10044
|
-
}
|
|
10045
|
-
else {
|
|
10046
|
-
return [toTypedValue(result)];
|
|
10047
|
-
}
|
|
10048
|
-
}
|
|
10049
|
-
}
|
|
10050
|
-
class ConcatAtom {
|
|
10051
|
-
constructor(left, right) {
|
|
10052
|
-
this.left = left;
|
|
10053
|
-
this.right = right;
|
|
10054
|
-
}
|
|
10055
|
-
eval(context) {
|
|
10056
|
-
const leftValue = this.left.eval(context);
|
|
10057
|
-
const rightValue = this.right.eval(context);
|
|
10058
|
-
const result = [...leftValue, ...rightValue];
|
|
10059
|
-
if (result.length > 0 && result.every((e) => typeof e.value === 'string')) {
|
|
10060
|
-
return [{ type: exports.PropertyType.string, value: result.map((e) => e.value).join('') }];
|
|
10061
|
-
}
|
|
10062
|
-
return result;
|
|
10063
|
-
}
|
|
10064
|
-
}
|
|
10065
|
-
class ContainsAtom {
|
|
10066
|
-
constructor(left, right) {
|
|
10067
|
-
this.left = left;
|
|
10068
|
-
this.right = right;
|
|
10069
|
-
}
|
|
10070
|
-
eval(context) {
|
|
10071
|
-
const leftValue = this.left.eval(context);
|
|
10072
|
-
const rightValue = this.right.eval(context);
|
|
10073
|
-
return booleanToTypedValue(leftValue.some((e) => e.value === rightValue[0].value));
|
|
10074
|
-
}
|
|
10075
|
-
}
|
|
10076
|
-
class InAtom {
|
|
10077
|
-
constructor(left, right) {
|
|
10078
|
-
this.left = left;
|
|
10079
|
-
this.right = right;
|
|
10080
|
-
}
|
|
10081
|
-
eval(context) {
|
|
10082
|
-
const leftValue = this.left.eval(context);
|
|
10083
|
-
const rightValue = this.right.eval(context);
|
|
10084
|
-
return booleanToTypedValue(rightValue.some((e) => e.value === leftValue[0].value));
|
|
10085
|
-
}
|
|
10086
|
-
}
|
|
10087
|
-
class DotAtom {
|
|
10088
|
-
constructor(left, right) {
|
|
10089
|
-
this.left = left;
|
|
10090
|
-
this.right = right;
|
|
10091
|
-
}
|
|
10092
|
-
eval(context) {
|
|
10093
|
-
return this.right.eval(this.left.eval(context));
|
|
10094
|
-
}
|
|
10095
|
-
}
|
|
10096
|
-
class UnionAtom {
|
|
10097
|
-
constructor(left, right) {
|
|
10098
|
-
this.left = left;
|
|
10099
|
-
this.right = right;
|
|
10100
|
-
}
|
|
10101
|
-
eval(context) {
|
|
10102
|
-
const leftResult = this.left.eval(context);
|
|
10103
|
-
const rightResult = this.right.eval(context);
|
|
10104
|
-
return removeDuplicates([...leftResult, ...rightResult]);
|
|
10105
|
-
}
|
|
10106
|
-
}
|
|
10107
|
-
class EqualsAtom {
|
|
10108
|
-
constructor(left, right) {
|
|
10109
|
-
this.left = left;
|
|
10110
|
-
this.right = right;
|
|
10111
|
-
}
|
|
10112
|
-
eval(context) {
|
|
10113
|
-
const leftValue = this.left.eval(context);
|
|
10114
|
-
const rightValue = this.right.eval(context);
|
|
10115
|
-
return fhirPathArrayEquals(leftValue, rightValue);
|
|
10116
|
-
}
|
|
10117
|
-
}
|
|
10118
|
-
class NotEqualsAtom {
|
|
10119
|
-
constructor(left, right) {
|
|
10120
|
-
this.left = left;
|
|
10121
|
-
this.right = right;
|
|
10122
|
-
}
|
|
10123
|
-
eval(context) {
|
|
10124
|
-
const leftValue = this.left.eval(context);
|
|
10125
|
-
const rightValue = this.right.eval(context);
|
|
10126
|
-
return fhirPathNot(fhirPathArrayEquals(leftValue, rightValue));
|
|
10127
|
-
}
|
|
10128
|
-
}
|
|
10129
|
-
class EquivalentAtom {
|
|
10130
|
-
constructor(left, right) {
|
|
10131
|
-
this.left = left;
|
|
10132
|
-
this.right = right;
|
|
10133
|
-
}
|
|
10134
|
-
eval(context) {
|
|
10135
|
-
const leftValue = this.left.eval(context);
|
|
10136
|
-
const rightValue = this.right.eval(context);
|
|
10137
|
-
return fhirPathArrayEquivalent(leftValue, rightValue);
|
|
10358
|
+
eval(context) {
|
|
10359
|
+
return this.impl(this.child.eval(context));
|
|
10360
|
+
}
|
|
10361
|
+
toString() {
|
|
10362
|
+
return this.child.toString();
|
|
10138
10363
|
}
|
|
10139
10364
|
}
|
|
10140
|
-
class
|
|
10365
|
+
class AsAtom extends InfixOperatorAtom {
|
|
10141
10366
|
constructor(left, right) {
|
|
10142
|
-
|
|
10143
|
-
this.right = right;
|
|
10367
|
+
super('as', left, right);
|
|
10144
10368
|
}
|
|
10145
10369
|
eval(context) {
|
|
10146
|
-
|
|
10147
|
-
const rightValue = this.right.eval(context);
|
|
10148
|
-
return fhirPathNot(fhirPathArrayEquivalent(leftValue, rightValue));
|
|
10370
|
+
return functions.ofType(this.left.eval(context), this.right);
|
|
10149
10371
|
}
|
|
10150
10372
|
}
|
|
10151
|
-
class
|
|
10152
|
-
constructor(left, right) {
|
|
10153
|
-
|
|
10154
|
-
this.
|
|
10373
|
+
class ArithemticOperatorAtom extends InfixOperatorAtom {
|
|
10374
|
+
constructor(operator, left, right, impl) {
|
|
10375
|
+
super(operator, left, right);
|
|
10376
|
+
this.impl = impl;
|
|
10155
10377
|
}
|
|
10156
10378
|
eval(context) {
|
|
10157
|
-
const
|
|
10158
|
-
if (
|
|
10379
|
+
const leftEvalResult = this.left.eval(context);
|
|
10380
|
+
if (leftEvalResult.length !== 1) {
|
|
10159
10381
|
return [];
|
|
10160
10382
|
}
|
|
10161
|
-
const
|
|
10162
|
-
|
|
10383
|
+
const rightEvalResult = this.right.eval(context);
|
|
10384
|
+
if (rightEvalResult.length !== 1) {
|
|
10385
|
+
return [];
|
|
10386
|
+
}
|
|
10387
|
+
const leftValue = leftEvalResult[0].value;
|
|
10388
|
+
const rightValue = rightEvalResult[0].value;
|
|
10389
|
+
const leftNumber = isQuantity(leftValue) ? leftValue.value : leftValue;
|
|
10390
|
+
const rightNumber = isQuantity(rightValue) ? rightValue.value : rightValue;
|
|
10391
|
+
const result = this.impl(leftNumber, rightNumber);
|
|
10392
|
+
if (typeof result === 'boolean') {
|
|
10393
|
+
return booleanToTypedValue(result);
|
|
10394
|
+
}
|
|
10395
|
+
else if (isQuantity(leftValue)) {
|
|
10396
|
+
return [{ type: exports.PropertyType.Quantity, value: Object.assign(Object.assign({}, leftValue), { value: result }) }];
|
|
10397
|
+
}
|
|
10398
|
+
else {
|
|
10399
|
+
return [toTypedValue(result)];
|
|
10400
|
+
}
|
|
10163
10401
|
}
|
|
10164
10402
|
}
|
|
10165
|
-
|
|
10166
|
-
* 6.5.1. and
|
|
10167
|
-
* Returns true if both operands evaluate to true,
|
|
10168
|
-
* false if either operand evaluates to false,
|
|
10169
|
-
* and the empty collection otherwise.
|
|
10170
|
-
*/
|
|
10171
|
-
class AndAtom {
|
|
10403
|
+
class ConcatAtom extends InfixOperatorAtom {
|
|
10172
10404
|
constructor(left, right) {
|
|
10173
|
-
|
|
10174
|
-
this.right = right;
|
|
10405
|
+
super('&', left, right);
|
|
10175
10406
|
}
|
|
10176
10407
|
eval(context) {
|
|
10177
|
-
var _a, _b, _c, _d;
|
|
10178
10408
|
const leftValue = this.left.eval(context);
|
|
10179
10409
|
const rightValue = this.right.eval(context);
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
if (((_c = leftValue[0]) === null || _c === void 0 ? void 0 : _c.value) === false || ((_d = rightValue[0]) === null || _d === void 0 ? void 0 : _d.value) === false) {
|
|
10184
|
-
return booleanToTypedValue(false);
|
|
10410
|
+
const result = [...leftValue, ...rightValue];
|
|
10411
|
+
if (result.length > 0 && result.every((e) => typeof e.value === 'string')) {
|
|
10412
|
+
return [{ type: exports.PropertyType.string, value: result.map((e) => e.value).join('') }];
|
|
10185
10413
|
}
|
|
10186
|
-
return
|
|
10414
|
+
return result;
|
|
10187
10415
|
}
|
|
10188
10416
|
}
|
|
10189
|
-
class
|
|
10417
|
+
class ContainsAtom extends InfixOperatorAtom {
|
|
10190
10418
|
constructor(left, right) {
|
|
10191
|
-
|
|
10192
|
-
this.right = right;
|
|
10419
|
+
super('contains', left, right);
|
|
10193
10420
|
}
|
|
10194
10421
|
eval(context) {
|
|
10195
10422
|
const leftValue = this.left.eval(context);
|
|
10196
|
-
if (toJsBoolean(leftValue)) {
|
|
10197
|
-
return leftValue;
|
|
10198
|
-
}
|
|
10199
10423
|
const rightValue = this.right.eval(context);
|
|
10200
|
-
|
|
10201
|
-
return rightValue;
|
|
10202
|
-
}
|
|
10203
|
-
return [];
|
|
10424
|
+
return booleanToTypedValue(leftValue.some((e) => e.value === rightValue[0].value));
|
|
10204
10425
|
}
|
|
10205
10426
|
}
|
|
10206
|
-
|
|
10207
|
-
* 6.5.4. xor
|
|
10208
|
-
* Returns true if exactly one of the operands evaluates to true,
|
|
10209
|
-
* false if either both operands evaluate to true or both operands evaluate to false,
|
|
10210
|
-
* and the empty collection otherwise.
|
|
10211
|
-
*/
|
|
10212
|
-
class XorAtom {
|
|
10427
|
+
class InAtom extends InfixOperatorAtom {
|
|
10213
10428
|
constructor(left, right) {
|
|
10214
|
-
|
|
10215
|
-
this.right = right;
|
|
10216
|
-
}
|
|
10217
|
-
eval(context) {
|
|
10218
|
-
const leftResult = this.left.eval(context);
|
|
10219
|
-
const rightResult = this.right.eval(context);
|
|
10220
|
-
if (leftResult.length === 0 && rightResult.length === 0) {
|
|
10221
|
-
return [];
|
|
10222
|
-
}
|
|
10223
|
-
const leftValue = leftResult.length === 0 ? null : leftResult[0].value;
|
|
10224
|
-
const rightValue = rightResult.length === 0 ? null : rightResult[0].value;
|
|
10225
|
-
if ((leftValue === true && rightValue !== true) || (leftValue !== true && rightValue === true)) {
|
|
10226
|
-
return booleanToTypedValue(true);
|
|
10227
|
-
}
|
|
10228
|
-
if ((leftValue === true && rightValue === true) || (leftValue === false && rightValue === false)) {
|
|
10229
|
-
return booleanToTypedValue(false);
|
|
10230
|
-
}
|
|
10231
|
-
return [];
|
|
10232
|
-
}
|
|
10233
|
-
}
|
|
10234
|
-
class FunctionAtom {
|
|
10235
|
-
constructor(name, args, impl) {
|
|
10236
|
-
this.name = name;
|
|
10237
|
-
this.args = args;
|
|
10238
|
-
this.impl = impl;
|
|
10429
|
+
super('in', left, right);
|
|
10239
10430
|
}
|
|
10240
10431
|
eval(context) {
|
|
10241
|
-
|
|
10432
|
+
const leftValue = this.left.eval(context);
|
|
10433
|
+
const rightValue = this.right.eval(context);
|
|
10434
|
+
return booleanToTypedValue(rightValue.some((e) => e.value === leftValue[0].value));
|
|
10242
10435
|
}
|
|
10243
10436
|
}
|
|
10244
|
-
class
|
|
10245
|
-
constructor(left,
|
|
10246
|
-
|
|
10247
|
-
this.expr = expr;
|
|
10437
|
+
class DotAtom extends InfixOperatorAtom {
|
|
10438
|
+
constructor(left, right) {
|
|
10439
|
+
super('.', left, right);
|
|
10248
10440
|
}
|
|
10249
10441
|
eval(context) {
|
|
10250
|
-
|
|
10251
|
-
if (evalResult.length !== 1) {
|
|
10252
|
-
return [];
|
|
10253
|
-
}
|
|
10254
|
-
const index = evalResult[0].value;
|
|
10255
|
-
if (typeof index !== 'number') {
|
|
10256
|
-
throw new Error(`Invalid indexer expression: should return integer}`);
|
|
10257
|
-
}
|
|
10258
|
-
const leftResult = this.left.eval(context);
|
|
10259
|
-
if (!(index in leftResult)) {
|
|
10260
|
-
return [];
|
|
10261
|
-
}
|
|
10262
|
-
return [leftResult[index]];
|
|
10263
|
-
}
|
|
10264
|
-
}
|
|
10265
|
-
|
|
10266
|
-
var _ParserBuilder_prefixParselets, _ParserBuilder_infixParselets, _Parser_tokens, _Parser_prefixParselets, _Parser_infixParselets;
|
|
10267
|
-
class ParserBuilder {
|
|
10268
|
-
constructor() {
|
|
10269
|
-
_ParserBuilder_prefixParselets.set(this, {});
|
|
10270
|
-
_ParserBuilder_infixParselets.set(this, {});
|
|
10271
|
-
}
|
|
10272
|
-
registerInfix(tokenType, parselet) {
|
|
10273
|
-
__classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
|
|
10274
|
-
return this;
|
|
10275
|
-
}
|
|
10276
|
-
registerPrefix(tokenType, parselet) {
|
|
10277
|
-
__classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
|
|
10278
|
-
return this;
|
|
10279
|
-
}
|
|
10280
|
-
prefix(tokenType, precedence, builder) {
|
|
10281
|
-
return this.registerPrefix(tokenType, {
|
|
10282
|
-
parse(parser, token) {
|
|
10283
|
-
const right = parser.consumeAndParse(precedence);
|
|
10284
|
-
return builder(token, right);
|
|
10285
|
-
},
|
|
10286
|
-
});
|
|
10287
|
-
}
|
|
10288
|
-
infixLeft(tokenType, precedence, builder) {
|
|
10289
|
-
return this.registerInfix(tokenType, {
|
|
10290
|
-
parse(parser, left, token) {
|
|
10291
|
-
const right = parser.consumeAndParse(precedence);
|
|
10292
|
-
return builder(left, token, right);
|
|
10293
|
-
},
|
|
10294
|
-
precedence,
|
|
10295
|
-
});
|
|
10296
|
-
}
|
|
10297
|
-
construct(input) {
|
|
10298
|
-
return new Parser(input, __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
|
|
10299
|
-
}
|
|
10300
|
-
}
|
|
10301
|
-
_ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
|
|
10302
|
-
class Parser {
|
|
10303
|
-
constructor(tokens, prefixParselets, infixParselets) {
|
|
10304
|
-
_Parser_tokens.set(this, void 0);
|
|
10305
|
-
_Parser_prefixParselets.set(this, void 0);
|
|
10306
|
-
_Parser_infixParselets.set(this, void 0);
|
|
10307
|
-
__classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
|
|
10308
|
-
__classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
|
|
10309
|
-
__classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
|
|
10310
|
-
}
|
|
10311
|
-
hasMore() {
|
|
10312
|
-
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0;
|
|
10313
|
-
}
|
|
10314
|
-
match(expected) {
|
|
10315
|
-
const token = this.peek();
|
|
10316
|
-
if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
|
|
10317
|
-
return false;
|
|
10318
|
-
}
|
|
10319
|
-
this.consume();
|
|
10320
|
-
return true;
|
|
10321
|
-
}
|
|
10322
|
-
consumeAndParse(precedence = Infinity) {
|
|
10323
|
-
const token = this.consume();
|
|
10324
|
-
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
10325
|
-
if (!prefix) {
|
|
10326
|
-
throw Error(`Parse error at "${token.value}" (line ${token.line}, column ${token.column}). No matching prefix parselet.`);
|
|
10327
|
-
}
|
|
10328
|
-
let left = prefix.parse(this, token);
|
|
10329
|
-
while (precedence > this.getPrecedence()) {
|
|
10330
|
-
const next = this.consume();
|
|
10331
|
-
const infix = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[next.id];
|
|
10332
|
-
left = infix.parse(this, left, next);
|
|
10333
|
-
}
|
|
10334
|
-
return left;
|
|
10335
|
-
}
|
|
10336
|
-
getPrecedence() {
|
|
10337
|
-
const nextToken = this.peek();
|
|
10338
|
-
if (!nextToken) {
|
|
10339
|
-
return Infinity;
|
|
10340
|
-
}
|
|
10341
|
-
const parser = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[nextToken.id];
|
|
10342
|
-
if (parser) {
|
|
10343
|
-
return parser.precedence;
|
|
10344
|
-
}
|
|
10345
|
-
return Infinity;
|
|
10346
|
-
}
|
|
10347
|
-
consume(expected) {
|
|
10348
|
-
var _a;
|
|
10349
|
-
if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
|
|
10350
|
-
throw Error('Cant consume unknown more tokens.');
|
|
10351
|
-
}
|
|
10352
|
-
if (expected && ((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.id) !== expected) {
|
|
10353
|
-
const actual = this.peek();
|
|
10354
|
-
throw Error(`Expected ${expected} but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
|
|
10355
|
-
}
|
|
10356
|
-
return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
|
|
10357
|
-
}
|
|
10358
|
-
peek() {
|
|
10359
|
-
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
|
|
10442
|
+
return this.right.eval(this.left.eval(context));
|
|
10360
10443
|
}
|
|
10361
|
-
|
|
10362
|
-
|
|
10444
|
+
toString() {
|
|
10445
|
+
return `${this.left.toString()}.${this.right.toString()}`;
|
|
10363
10446
|
}
|
|
10364
10447
|
}
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
'week',
|
|
10374
|
-
'weeks',
|
|
10375
|
-
'day',
|
|
10376
|
-
'days',
|
|
10377
|
-
'hour',
|
|
10378
|
-
'hours',
|
|
10379
|
-
'minute',
|
|
10380
|
-
'minutes',
|
|
10381
|
-
'second',
|
|
10382
|
-
'seconds',
|
|
10383
|
-
'millisecond',
|
|
10384
|
-
'milliseconds',
|
|
10385
|
-
];
|
|
10386
|
-
class Tokenizer {
|
|
10387
|
-
constructor(str, keywords, operators) {
|
|
10388
|
-
_Tokenizer_instances.add(this);
|
|
10389
|
-
_Tokenizer_str.set(this, void 0);
|
|
10390
|
-
_Tokenizer_keywords.set(this, void 0);
|
|
10391
|
-
_Tokenizer_operators.set(this, void 0);
|
|
10392
|
-
_Tokenizer_result.set(this, []);
|
|
10393
|
-
_Tokenizer_pos.set(this, { index: 0, line: 0, column: 0 });
|
|
10394
|
-
_Tokenizer_markStack.set(this, []);
|
|
10395
|
-
__classPrivateFieldSet(this, _Tokenizer_str, str, "f");
|
|
10396
|
-
__classPrivateFieldSet(this, _Tokenizer_keywords, keywords, "f");
|
|
10397
|
-
__classPrivateFieldSet(this, _Tokenizer_operators, operators, "f");
|
|
10398
|
-
}
|
|
10399
|
-
tokenize() {
|
|
10400
|
-
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
|
|
10401
|
-
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
10402
|
-
if (token) {
|
|
10403
|
-
__classPrivateFieldGet(this, _Tokenizer_result, "f").push(token);
|
|
10404
|
-
}
|
|
10405
|
-
}
|
|
10406
|
-
return __classPrivateFieldGet(this, _Tokenizer_result, "f");
|
|
10448
|
+
class UnionAtom extends InfixOperatorAtom {
|
|
10449
|
+
constructor(left, right) {
|
|
10450
|
+
super('|', left, right);
|
|
10451
|
+
}
|
|
10452
|
+
eval(context) {
|
|
10453
|
+
const leftResult = this.left.eval(context);
|
|
10454
|
+
const rightResult = this.right.eval(context);
|
|
10455
|
+
return removeDuplicates([...leftResult, ...rightResult]);
|
|
10407
10456
|
}
|
|
10408
10457
|
}
|
|
10409
|
-
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
|
|
10413
|
-
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
10414
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_reset).call(this);
|
|
10415
|
-
return token;
|
|
10416
|
-
}, _Tokenizer_consumeToken = function _Tokenizer_consumeToken() {
|
|
10417
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhitespace).call(this);
|
|
10418
|
-
const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
|
|
10419
|
-
if (!c) {
|
|
10420
|
-
return undefined;
|
|
10458
|
+
class EqualsAtom extends InfixOperatorAtom {
|
|
10459
|
+
constructor(left, right) {
|
|
10460
|
+
super('=', left, right);
|
|
10421
10461
|
}
|
|
10422
|
-
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
return
|
|
10462
|
+
eval(context) {
|
|
10463
|
+
const leftValue = this.left.eval(context);
|
|
10464
|
+
const rightValue = this.right.eval(context);
|
|
10465
|
+
return fhirPathArrayEquals(leftValue, rightValue);
|
|
10426
10466
|
}
|
|
10427
|
-
|
|
10428
|
-
|
|
10467
|
+
}
|
|
10468
|
+
class NotEqualsAtom extends InfixOperatorAtom {
|
|
10469
|
+
constructor(left, right) {
|
|
10470
|
+
super('!=', left, right);
|
|
10429
10471
|
}
|
|
10430
|
-
|
|
10431
|
-
|
|
10472
|
+
eval(context) {
|
|
10473
|
+
const leftValue = this.left.eval(context);
|
|
10474
|
+
const rightValue = this.right.eval(context);
|
|
10475
|
+
return fhirPathNot(fhirPathArrayEquals(leftValue, rightValue));
|
|
10432
10476
|
}
|
|
10433
|
-
|
|
10434
|
-
|
|
10477
|
+
}
|
|
10478
|
+
class EquivalentAtom extends InfixOperatorAtom {
|
|
10479
|
+
constructor(left, right) {
|
|
10480
|
+
super('~', left, right);
|
|
10435
10481
|
}
|
|
10436
|
-
|
|
10437
|
-
|
|
10482
|
+
eval(context) {
|
|
10483
|
+
const leftValue = this.left.eval(context);
|
|
10484
|
+
const rightValue = this.right.eval(context);
|
|
10485
|
+
return fhirPathArrayEquivalent(leftValue, rightValue);
|
|
10438
10486
|
}
|
|
10439
|
-
|
|
10440
|
-
|
|
10487
|
+
}
|
|
10488
|
+
class NotEquivalentAtom extends InfixOperatorAtom {
|
|
10489
|
+
constructor(left, right) {
|
|
10490
|
+
super('!~', left, right);
|
|
10441
10491
|
}
|
|
10442
|
-
|
|
10443
|
-
|
|
10492
|
+
eval(context) {
|
|
10493
|
+
const leftValue = this.left.eval(context);
|
|
10494
|
+
const rightValue = this.right.eval(context);
|
|
10495
|
+
return fhirPathNot(fhirPathArrayEquivalent(leftValue, rightValue));
|
|
10444
10496
|
}
|
|
10445
|
-
|
|
10446
|
-
|
|
10497
|
+
}
|
|
10498
|
+
class IsAtom extends InfixOperatorAtom {
|
|
10499
|
+
constructor(left, right) {
|
|
10500
|
+
super('is', left, right);
|
|
10447
10501
|
}
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
|
|
10452
|
-
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
10453
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '*' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this) !== '/');
|
|
10454
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10455
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10456
|
-
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
10457
|
-
}, _Tokenizer_consumeSingleLineComment = function _Tokenizer_consumeSingleLineComment() {
|
|
10458
|
-
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '\n'));
|
|
10459
|
-
}, _Tokenizer_consumeString = function _Tokenizer_consumeString(endChar) {
|
|
10460
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10461
|
-
const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'String', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prev).call(this) === '\\' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== endChar));
|
|
10462
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10463
|
-
return result;
|
|
10464
|
-
}, _Tokenizer_consumeBacktickSymbol = function _Tokenizer_consumeBacktickSymbol() {
|
|
10465
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10466
|
-
const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '`'));
|
|
10467
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10468
|
-
return result;
|
|
10469
|
-
}, _Tokenizer_consumeDateTime = function _Tokenizer_consumeDateTime() {
|
|
10470
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this); // Consume "@"
|
|
10471
|
-
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
10472
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d-]/));
|
|
10473
|
-
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'T') {
|
|
10474
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10475
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
10476
|
-
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
10477
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10478
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
10502
|
+
eval(context) {
|
|
10503
|
+
const leftValue = this.left.eval(context);
|
|
10504
|
+
if (leftValue.length !== 1) {
|
|
10505
|
+
return [];
|
|
10479
10506
|
}
|
|
10480
|
-
|
|
10481
|
-
|
|
10507
|
+
const typeName = this.right.name;
|
|
10508
|
+
return booleanToTypedValue(fhirPathIs(leftValue[0], typeName));
|
|
10509
|
+
}
|
|
10510
|
+
}
|
|
10511
|
+
/**
|
|
10512
|
+
* 6.5.1. and
|
|
10513
|
+
* Returns true if both operands evaluate to true,
|
|
10514
|
+
* false if either operand evaluates to false,
|
|
10515
|
+
* and the empty collection otherwise.
|
|
10516
|
+
*/
|
|
10517
|
+
class AndAtom extends InfixOperatorAtom {
|
|
10518
|
+
constructor(left, right) {
|
|
10519
|
+
super('and', left, right);
|
|
10520
|
+
}
|
|
10521
|
+
eval(context) {
|
|
10522
|
+
var _a, _b, _c, _d;
|
|
10523
|
+
const leftValue = this.left.eval(context);
|
|
10524
|
+
const rightValue = this.right.eval(context);
|
|
10525
|
+
if (((_a = leftValue[0]) === null || _a === void 0 ? void 0 : _a.value) === true && ((_b = rightValue[0]) === null || _b === void 0 ? void 0 : _b.value) === true) {
|
|
10526
|
+
return booleanToTypedValue(true);
|
|
10482
10527
|
}
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
10528
|
+
if (((_c = leftValue[0]) === null || _c === void 0 ? void 0 : _c.value) === false || ((_d = rightValue[0]) === null || _d === void 0 ? void 0 : _d.value) === false) {
|
|
10529
|
+
return booleanToTypedValue(false);
|
|
10486
10530
|
}
|
|
10531
|
+
return [];
|
|
10487
10532
|
}
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
10493
|
-
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
10494
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10495
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
10533
|
+
}
|
|
10534
|
+
class OrAtom extends InfixOperatorAtom {
|
|
10535
|
+
constructor(left, right) {
|
|
10536
|
+
super('or', left, right);
|
|
10496
10537
|
}
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10538
|
+
eval(context) {
|
|
10539
|
+
const leftValue = this.left.eval(context);
|
|
10540
|
+
if (toJsBoolean(leftValue)) {
|
|
10541
|
+
return leftValue;
|
|
10501
10542
|
}
|
|
10543
|
+
const rightValue = this.right.eval(context);
|
|
10544
|
+
if (toJsBoolean(rightValue)) {
|
|
10545
|
+
return rightValue;
|
|
10546
|
+
}
|
|
10547
|
+
return [];
|
|
10502
10548
|
}
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
10514
|
-
const twoCharOp = c + next;
|
|
10515
|
-
if (__classPrivateFieldGet(this, _Tokenizer_operators, "f").includes(twoCharOp)) {
|
|
10516
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10517
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10518
|
-
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, twoCharOp, twoCharOp);
|
|
10549
|
+
}
|
|
10550
|
+
/**
|
|
10551
|
+
* 6.5.4. xor
|
|
10552
|
+
* Returns true if exactly one of the operands evaluates to true,
|
|
10553
|
+
* false if either both operands evaluate to true or both operands evaluate to false,
|
|
10554
|
+
* and the empty collection otherwise.
|
|
10555
|
+
*/
|
|
10556
|
+
class XorAtom extends InfixOperatorAtom {
|
|
10557
|
+
constructor(left, right) {
|
|
10558
|
+
super('xor', left, right);
|
|
10519
10559
|
}
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10560
|
+
eval(context) {
|
|
10561
|
+
const leftResult = this.left.eval(context);
|
|
10562
|
+
const rightResult = this.right.eval(context);
|
|
10563
|
+
if (leftResult.length === 0 && rightResult.length === 0) {
|
|
10564
|
+
return [];
|
|
10565
|
+
}
|
|
10566
|
+
const leftValue = leftResult.length === 0 ? null : leftResult[0].value;
|
|
10567
|
+
const rightValue = rightResult.length === 0 ? null : rightResult[0].value;
|
|
10568
|
+
if ((leftValue === true && rightValue !== true) || (leftValue !== true && rightValue === true)) {
|
|
10569
|
+
return booleanToTypedValue(true);
|
|
10570
|
+
}
|
|
10571
|
+
if ((leftValue === true && rightValue === true) || (leftValue === false && rightValue === false)) {
|
|
10572
|
+
return booleanToTypedValue(false);
|
|
10573
|
+
}
|
|
10574
|
+
return [];
|
|
10526
10575
|
}
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1]) !== null && _a !== void 0 ? _a : '';
|
|
10533
|
-
}, _Tokenizer_peek = function _Tokenizer_peek() {
|
|
10534
|
-
var _a;
|
|
10535
|
-
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1]) !== null && _a !== void 0 ? _a : '';
|
|
10536
|
-
}, _Tokenizer_mark = function _Tokenizer_mark() {
|
|
10537
|
-
__classPrivateFieldGet(this, _Tokenizer_markStack, "f").push(Object.assign({}, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
|
|
10538
|
-
}, _Tokenizer_reset = function _Tokenizer_reset() {
|
|
10539
|
-
const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
|
|
10540
|
-
if (!mark) {
|
|
10541
|
-
throw new Error('No mark to reset to');
|
|
10576
|
+
}
|
|
10577
|
+
class FunctionAtom {
|
|
10578
|
+
constructor(name, args) {
|
|
10579
|
+
this.name = name;
|
|
10580
|
+
this.args = args;
|
|
10542
10581
|
}
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
__classPrivateFieldGet(this, _Tokenizer_pos, "f").line++;
|
|
10550
|
-
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column = 0;
|
|
10582
|
+
eval(context) {
|
|
10583
|
+
const impl = functions[this.name];
|
|
10584
|
+
if (!impl) {
|
|
10585
|
+
throw new Error('Unrecognized function: ' + this.name);
|
|
10586
|
+
}
|
|
10587
|
+
return impl(context, ...this.args);
|
|
10551
10588
|
}
|
|
10552
|
-
|
|
10553
|
-
|
|
10589
|
+
toString() {
|
|
10590
|
+
return `${this.name}(${this.args.map((arg) => arg.toString()).join(', ')})`;
|
|
10554
10591
|
}
|
|
10555
|
-
}
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10592
|
+
}
|
|
10593
|
+
class IndexerAtom {
|
|
10594
|
+
constructor(left, expr) {
|
|
10595
|
+
this.left = left;
|
|
10596
|
+
this.expr = expr;
|
|
10559
10597
|
}
|
|
10560
|
-
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
if (token) {
|
|
10565
|
-
if (token.id === 'String') {
|
|
10566
|
-
return true;
|
|
10598
|
+
eval(context) {
|
|
10599
|
+
const evalResult = this.expr.eval(context);
|
|
10600
|
+
if (evalResult.length !== 1) {
|
|
10601
|
+
return [];
|
|
10567
10602
|
}
|
|
10568
|
-
|
|
10569
|
-
|
|
10603
|
+
const index = evalResult[0].value;
|
|
10604
|
+
if (typeof index !== 'number') {
|
|
10605
|
+
throw new Error(`Invalid indexer expression: should return integer}`);
|
|
10606
|
+
}
|
|
10607
|
+
const leftResult = this.left.eval(context);
|
|
10608
|
+
if (!(index in leftResult)) {
|
|
10609
|
+
return [];
|
|
10570
10610
|
}
|
|
10611
|
+
return [leftResult[index]];
|
|
10612
|
+
}
|
|
10613
|
+
toString() {
|
|
10614
|
+
return `${this.left.toString()}[${this.expr.toString()}]`;
|
|
10571
10615
|
}
|
|
10572
|
-
return false;
|
|
10573
10616
|
}
|
|
10574
10617
|
|
|
10575
|
-
const FHIRPATH_KEYWORDS = ['true', 'false'
|
|
10618
|
+
const FHIRPATH_KEYWORDS = ['true', 'false'];
|
|
10576
10619
|
const FHIRPATH_OPERATORS = ['!=', '!~', '<=', '>=', '{}', '->'];
|
|
10577
10620
|
function tokenize(str) {
|
|
10578
10621
|
return new Tokenizer(str, FHIRPATH_KEYWORDS, FHIRPATH_OPERATORS).tokenize();
|
|
@@ -10580,9 +10623,10 @@
|
|
|
10580
10623
|
|
|
10581
10624
|
const PARENTHESES_PARSELET = {
|
|
10582
10625
|
parse(parser) {
|
|
10626
|
+
var _a;
|
|
10583
10627
|
const expr = parser.consumeAndParse();
|
|
10584
10628
|
if (!parser.match(')')) {
|
|
10585
|
-
throw new Error('Parse error: expected `)`');
|
|
10629
|
+
throw new Error('Parse error: expected `)` got `' + ((_a = parser.peek()) === null || _a === void 0 ? void 0 : _a.value) + '`');
|
|
10586
10630
|
}
|
|
10587
10631
|
return expr;
|
|
10588
10632
|
},
|
|
@@ -10595,24 +10639,21 @@
|
|
|
10595
10639
|
}
|
|
10596
10640
|
return new IndexerAtom(left, expr);
|
|
10597
10641
|
},
|
|
10598
|
-
precedence: 2 /*
|
|
10642
|
+
precedence: 2 /* OperatorPrecedence.Indexer */,
|
|
10599
10643
|
};
|
|
10600
10644
|
const FUNCTION_CALL_PARSELET = {
|
|
10601
10645
|
parse(parser, left) {
|
|
10602
10646
|
if (!(left instanceof SymbolAtom)) {
|
|
10603
10647
|
throw new Error('Unexpected parentheses');
|
|
10604
10648
|
}
|
|
10605
|
-
if (!(left.name in functions)) {
|
|
10606
|
-
throw new Error('Unrecognized function: ' + left.name);
|
|
10607
|
-
}
|
|
10608
10649
|
const args = [];
|
|
10609
10650
|
while (!parser.match(')')) {
|
|
10610
10651
|
args.push(parser.consumeAndParse());
|
|
10611
10652
|
parser.match(',');
|
|
10612
10653
|
}
|
|
10613
|
-
return new FunctionAtom(left.name, args
|
|
10654
|
+
return new FunctionAtom(left.name, args); //, functions[left.name]);
|
|
10614
10655
|
},
|
|
10615
|
-
precedence: 0 /*
|
|
10656
|
+
precedence: 0 /* OperatorPrecedence.FunctionCall */,
|
|
10616
10657
|
};
|
|
10617
10658
|
function parseQuantity(str) {
|
|
10618
10659
|
const parts = str.split(' ');
|
|
@@ -10647,32 +10688,32 @@
|
|
|
10647
10688
|
.registerPrefix('(', PARENTHESES_PARSELET)
|
|
10648
10689
|
.registerInfix('[', INDEXER_PARSELET)
|
|
10649
10690
|
.registerInfix('(', FUNCTION_CALL_PARSELET)
|
|
10650
|
-
.prefix('+', 3 /*
|
|
10651
|
-
.prefix('-', 3 /*
|
|
10652
|
-
.infixLeft('.', 1 /*
|
|
10653
|
-
.infixLeft('/', 4 /*
|
|
10654
|
-
.infixLeft('*', 4 /*
|
|
10655
|
-
.infixLeft('+', 5 /*
|
|
10656
|
-
.infixLeft('-', 5 /*
|
|
10657
|
-
.infixLeft('|', 7 /*
|
|
10658
|
-
.infixLeft('=', 9 /*
|
|
10659
|
-
.infixLeft('!=', 9 /*
|
|
10660
|
-
.infixLeft('~', 9 /*
|
|
10661
|
-
.infixLeft('!~', 9 /*
|
|
10662
|
-
.infixLeft('<', 8 /*
|
|
10663
|
-
.infixLeft('<=', 8 /*
|
|
10664
|
-
.infixLeft('>', 8 /*
|
|
10665
|
-
.infixLeft('>=', 8 /*
|
|
10666
|
-
.infixLeft('&', 5 /*
|
|
10667
|
-
.infixLeft('and', 6 /*
|
|
10668
|
-
.infixLeft('as', 6 /*
|
|
10669
|
-
.infixLeft('contains', 6 /*
|
|
10670
|
-
.infixLeft('div', 6 /*
|
|
10671
|
-
.infixLeft('in', 6 /*
|
|
10672
|
-
.infixLeft('is', 6 /*
|
|
10673
|
-
.infixLeft('mod', 6 /*
|
|
10674
|
-
.infixLeft('or', 6 /*
|
|
10675
|
-
.infixLeft('xor', 6 /*
|
|
10691
|
+
.prefix('+', 3 /* OperatorPrecedence.UnaryAdd */, (_, right) => new UnaryOperatorAtom('+', right, (x) => x))
|
|
10692
|
+
.prefix('-', 3 /* OperatorPrecedence.UnarySubtract */, (_, right) => new ArithemticOperatorAtom('-', right, right, (_, y) => -y))
|
|
10693
|
+
.infixLeft('.', 1 /* OperatorPrecedence.Dot */, (left, _, right) => new DotAtom(left, right))
|
|
10694
|
+
.infixLeft('/', 4 /* OperatorPrecedence.Divide */, (left, _, right) => new ArithemticOperatorAtom('/', left, right, (x, y) => x / y))
|
|
10695
|
+
.infixLeft('*', 4 /* OperatorPrecedence.Multiply */, (left, _, right) => new ArithemticOperatorAtom('*', left, right, (x, y) => x * y))
|
|
10696
|
+
.infixLeft('+', 5 /* OperatorPrecedence.Add */, (left, _, right) => new ArithemticOperatorAtom('+', left, right, (x, y) => x + y))
|
|
10697
|
+
.infixLeft('-', 5 /* OperatorPrecedence.Subtract */, (left, _, right) => new ArithemticOperatorAtom('-', left, right, (x, y) => x - y))
|
|
10698
|
+
.infixLeft('|', 7 /* OperatorPrecedence.Union */, (left, _, right) => new UnionAtom(left, right))
|
|
10699
|
+
.infixLeft('=', 9 /* OperatorPrecedence.Equals */, (left, _, right) => new EqualsAtom(left, right))
|
|
10700
|
+
.infixLeft('!=', 9 /* OperatorPrecedence.Equals */, (left, _, right) => new NotEqualsAtom(left, right))
|
|
10701
|
+
.infixLeft('~', 9 /* OperatorPrecedence.Equivalent */, (left, _, right) => new EquivalentAtom(left, right))
|
|
10702
|
+
.infixLeft('!~', 9 /* OperatorPrecedence.NotEquivalent */, (left, _, right) => new NotEquivalentAtom(left, right))
|
|
10703
|
+
.infixLeft('<', 8 /* OperatorPrecedence.LessThan */, (left, _, right) => new ArithemticOperatorAtom('<', left, right, (x, y) => x < y))
|
|
10704
|
+
.infixLeft('<=', 8 /* OperatorPrecedence.LessThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom('<=', left, right, (x, y) => x <= y))
|
|
10705
|
+
.infixLeft('>', 8 /* OperatorPrecedence.GreaterThan */, (left, _, right) => new ArithemticOperatorAtom('>', left, right, (x, y) => x > y))
|
|
10706
|
+
.infixLeft('>=', 8 /* OperatorPrecedence.GreaterThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom('>=', left, right, (x, y) => x >= y))
|
|
10707
|
+
.infixLeft('&', 5 /* OperatorPrecedence.Ampersand */, (left, _, right) => new ConcatAtom(left, right))
|
|
10708
|
+
.infixLeft('and', 6 /* OperatorPrecedence.Is */, (left, _, right) => new AndAtom(left, right))
|
|
10709
|
+
.infixLeft('as', 6 /* OperatorPrecedence.Is */, (left, _, right) => new AsAtom(left, right))
|
|
10710
|
+
.infixLeft('contains', 6 /* OperatorPrecedence.Is */, (left, _, right) => new ContainsAtom(left, right))
|
|
10711
|
+
.infixLeft('div', 6 /* OperatorPrecedence.Is */, (left, _, right) => new ArithemticOperatorAtom('div', left, right, (x, y) => (x / y) | 0))
|
|
10712
|
+
.infixLeft('in', 6 /* OperatorPrecedence.Is */, (left, _, right) => new InAtom(left, right))
|
|
10713
|
+
.infixLeft('is', 6 /* OperatorPrecedence.Is */, (left, _, right) => new IsAtom(left, right))
|
|
10714
|
+
.infixLeft('mod', 6 /* OperatorPrecedence.Is */, (left, _, right) => new ArithemticOperatorAtom('mod', left, right, (x, y) => x % y))
|
|
10715
|
+
.infixLeft('or', 6 /* OperatorPrecedence.Is */, (left, _, right) => new OrAtom(left, right))
|
|
10716
|
+
.infixLeft('xor', 6 /* OperatorPrecedence.Is */, (left, _, right) => new XorAtom(left, right));
|
|
10676
10717
|
}
|
|
10677
10718
|
const fhirPathParserBuilder = initFhirPathParserBuilder();
|
|
10678
10719
|
/**
|