@medplum/core 0.9.35 → 0.9.36
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 +14 -5
- package/dist/cjs/fhirlexer/index.d.ts +2 -0
- package/dist/cjs/fhirlexer/parse.d.ts +31 -0
- package/dist/cjs/fhirlexer/tokenize.d.ts +14 -0
- package/dist/cjs/fhirmapper/atoms.d.ts +67 -0
- package/dist/cjs/fhirmapper/parse.d.ts +7 -0
- package/dist/cjs/fhirmapper/tokenize.d.ts +2 -0
- package/dist/cjs/fhirpath/atoms.d.ts +2 -7
- package/dist/cjs/fhirpath/functions.d.ts +2 -1
- package/dist/cjs/fhirpath/parse.d.ts +8 -5
- package/dist/cjs/fhirpath/tokenize.d.ts +3 -4
- package/dist/cjs/fhirpath/utils.d.ts +1 -1
- package/dist/cjs/index.js +310 -272
- 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/cjs/types.d.ts +4 -0
- package/dist/esm/client.d.ts +14 -5
- package/dist/esm/client.js +58 -45
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/fhirlexer/index.d.ts +2 -0
- package/dist/esm/fhirlexer/parse.d.ts +31 -0
- package/dist/esm/fhirlexer/parse.js +105 -0
- package/dist/esm/fhirlexer/parse.js.map +1 -0
- package/dist/esm/fhirlexer/tokenize.d.ts +14 -0
- package/dist/esm/fhirlexer/tokenize.js +212 -0
- package/dist/esm/fhirlexer/tokenize.js.map +1 -0
- package/dist/esm/fhirmapper/atoms.d.ts +67 -0
- package/dist/esm/fhirmapper/parse.d.ts +7 -0
- package/dist/esm/fhirmapper/tokenize.d.ts +2 -0
- package/dist/esm/fhirpath/atoms.d.ts +2 -7
- package/dist/esm/fhirpath/atoms.js.map +1 -1
- package/dist/esm/fhirpath/functions.d.ts +2 -1
- package/dist/esm/fhirpath/functions.js.map +1 -1
- package/dist/esm/fhirpath/parse.d.ts +8 -5
- package/dist/esm/fhirpath/parse.js +57 -169
- package/dist/esm/fhirpath/parse.js.map +1 -1
- package/dist/esm/fhirpath/tokenize.d.ts +3 -4
- package/dist/esm/fhirpath/tokenize.js +5 -180
- package/dist/esm/fhirpath/tokenize.js.map +1 -1
- package/dist/esm/fhirpath/utils.d.ts +1 -1
- package/dist/esm/fhirpath/utils.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/outcomes.js +1 -1
- package/dist/esm/outcomes.js.map +1 -1
- package/dist/esm/types.d.ts +4 -0
- package/dist/esm/types.js.map +1 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -6244,7 +6244,7 @@
|
|
|
6244
6244
|
|
|
6245
6245
|
// PKCE auth based on:
|
|
6246
6246
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
6247
|
-
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _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,
|
|
6247
|
+
var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _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;
|
|
6248
6248
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
6249
6249
|
const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
|
|
6250
6250
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
@@ -6513,8 +6513,8 @@
|
|
|
6513
6513
|
*/
|
|
6514
6514
|
startNewUser(newUserRequest) {
|
|
6515
6515
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6516
|
-
yield
|
|
6517
|
-
return this.post('auth/newuser', Object.assign(Object.assign({}, newUserRequest), { codeChallengeMethod: 'S256', codeChallenge:
|
|
6516
|
+
yield this.startPkce();
|
|
6517
|
+
return this.post('auth/newuser', Object.assign(Object.assign({}, newUserRequest), { codeChallengeMethod: 'S256', codeChallenge: sessionStorage.getItem('codeChallenge') }));
|
|
6518
6518
|
});
|
|
6519
6519
|
}
|
|
6520
6520
|
/**
|
|
@@ -6552,10 +6552,9 @@
|
|
|
6552
6552
|
startLogin(loginRequest) {
|
|
6553
6553
|
var _a, _b;
|
|
6554
6554
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
return this.post('auth/login', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: (_b = loginRequest.scope) !== null && _b !== void 0 ? _b : DEFAULT_SCOPE, codeChallengeMethod: loginRequest.codeChallengeMethod || 'S256', codeChallenge: loginRequest.codeChallenge || __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge') }));
|
|
6555
|
+
const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
|
|
6556
|
+
return this.post('auth/login', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: (_b = loginRequest.scope) !== null && _b !== void 0 ? _b : DEFAULT_SCOPE, codeChallengeMethod,
|
|
6557
|
+
codeChallenge }));
|
|
6559
6558
|
});
|
|
6560
6559
|
}
|
|
6561
6560
|
/**
|
|
@@ -6569,12 +6568,27 @@
|
|
|
6569
6568
|
startGoogleLogin(loginRequest) {
|
|
6570
6569
|
var _a, _b;
|
|
6571
6570
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
return this.post('auth/google', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: (_b = loginRequest.scope) !== null && _b !== void 0 ? _b : DEFAULT_SCOPE, codeChallengeMethod: loginRequest.codeChallengeMethod || 'S256', codeChallenge: loginRequest.codeChallenge || __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge') }));
|
|
6571
|
+
const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
|
|
6572
|
+
return this.post('auth/google', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: (_b = loginRequest.scope) !== null && _b !== void 0 ? _b : DEFAULT_SCOPE, codeChallengeMethod,
|
|
6573
|
+
codeChallenge }));
|
|
6576
6574
|
});
|
|
6577
6575
|
}
|
|
6576
|
+
getCodeChallenge(loginRequest) {
|
|
6577
|
+
if (loginRequest.codeChallenge) {
|
|
6578
|
+
return {
|
|
6579
|
+
codeChallenge: loginRequest.codeChallenge,
|
|
6580
|
+
codeChallengeMethod: loginRequest.codeChallengeMethod,
|
|
6581
|
+
};
|
|
6582
|
+
}
|
|
6583
|
+
const codeChallenge = sessionStorage.getItem('codeChallenge');
|
|
6584
|
+
if (codeChallenge) {
|
|
6585
|
+
return {
|
|
6586
|
+
codeChallenge,
|
|
6587
|
+
codeChallengeMethod: 'S256',
|
|
6588
|
+
};
|
|
6589
|
+
}
|
|
6590
|
+
return {};
|
|
6591
|
+
}
|
|
6578
6592
|
/**
|
|
6579
6593
|
* Signs out locally.
|
|
6580
6594
|
* Does not invalidate tokens with the server.
|
|
@@ -6804,8 +6818,8 @@
|
|
|
6804
6818
|
* @param id The resource ID.
|
|
6805
6819
|
* @returns The resource if available; undefined otherwise.
|
|
6806
6820
|
*/
|
|
6807
|
-
readResource(resourceType, id) {
|
|
6808
|
-
return this.get(this.fhirUrl(resourceType, id));
|
|
6821
|
+
readResource(resourceType, id, options = {}) {
|
|
6822
|
+
return this.get(this.fhirUrl(resourceType, id), options);
|
|
6809
6823
|
}
|
|
6810
6824
|
/**
|
|
6811
6825
|
* Reads a resource by `Reference`.
|
|
@@ -6826,7 +6840,7 @@
|
|
|
6826
6840
|
* @param reference The FHIR reference object.
|
|
6827
6841
|
* @returns The resource if available; undefined otherwise.
|
|
6828
6842
|
*/
|
|
6829
|
-
readReference(reference) {
|
|
6843
|
+
readReference(reference, options = {}) {
|
|
6830
6844
|
const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
|
|
6831
6845
|
if (!refString) {
|
|
6832
6846
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
@@ -6835,7 +6849,7 @@
|
|
|
6835
6849
|
if (!resourceType || !id) {
|
|
6836
6850
|
return new ReadablePromise(Promise.reject(new Error('Invalid reference')));
|
|
6837
6851
|
}
|
|
6838
|
-
return this.readResource(resourceType, id);
|
|
6852
|
+
return this.readResource(resourceType, id, options);
|
|
6839
6853
|
}
|
|
6840
6854
|
/**
|
|
6841
6855
|
* Returns a cached schema for a resource type.
|
|
@@ -6919,8 +6933,8 @@
|
|
|
6919
6933
|
* @param id The resource ID.
|
|
6920
6934
|
* @returns Promise to the resource history.
|
|
6921
6935
|
*/
|
|
6922
|
-
readHistory(resourceType, id) {
|
|
6923
|
-
return this.get(this.fhirUrl(resourceType, id, '_history'));
|
|
6936
|
+
readHistory(resourceType, id, options = {}) {
|
|
6937
|
+
return this.get(this.fhirUrl(resourceType, id, '_history'), options);
|
|
6924
6938
|
}
|
|
6925
6939
|
/**
|
|
6926
6940
|
* Reads a specific version of a resource by resource type, ID, and version ID.
|
|
@@ -6939,8 +6953,8 @@
|
|
|
6939
6953
|
* @param id The resource ID.
|
|
6940
6954
|
* @returns The resource if available; undefined otherwise.
|
|
6941
6955
|
*/
|
|
6942
|
-
readVersion(resourceType, id, vid) {
|
|
6943
|
-
return this.get(this.fhirUrl(resourceType, id, '_history', vid));
|
|
6956
|
+
readVersion(resourceType, id, vid, options = {}) {
|
|
6957
|
+
return this.get(this.fhirUrl(resourceType, id, '_history', vid), options);
|
|
6944
6958
|
}
|
|
6945
6959
|
/**
|
|
6946
6960
|
*
|
|
@@ -6948,8 +6962,8 @@
|
|
|
6948
6962
|
* @param id The Patient Id
|
|
6949
6963
|
* @returns A Bundle of all Resources related to the Patient
|
|
6950
6964
|
*/
|
|
6951
|
-
readPatientEverything(id) {
|
|
6952
|
-
return this.get(this.fhirUrl('Patient', id, '$everything'));
|
|
6965
|
+
readPatientEverything(id, options = {}) {
|
|
6966
|
+
return this.get(this.fhirUrl('Patient', id, '$everything'), options);
|
|
6953
6967
|
}
|
|
6954
6968
|
/**
|
|
6955
6969
|
* Creates a new FHIR resource.
|
|
@@ -7459,28 +7473,36 @@
|
|
|
7459
7473
|
return response.blob();
|
|
7460
7474
|
});
|
|
7461
7475
|
}
|
|
7476
|
+
/**
|
|
7477
|
+
* Starts a new PKCE flow.
|
|
7478
|
+
* These PKCE values are stateful, and must survive redirects and page refreshes.
|
|
7479
|
+
*/
|
|
7480
|
+
startPkce() {
|
|
7481
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7482
|
+
const pkceState = getRandomString();
|
|
7483
|
+
sessionStorage.setItem('pkceState', pkceState);
|
|
7484
|
+
const codeVerifier = getRandomString();
|
|
7485
|
+
sessionStorage.setItem('codeVerifier', codeVerifier);
|
|
7486
|
+
const arrayHash = yield encryptSHA256(codeVerifier);
|
|
7487
|
+
const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
7488
|
+
sessionStorage.setItem('codeChallenge', codeChallenge);
|
|
7489
|
+
});
|
|
7490
|
+
}
|
|
7462
7491
|
/**
|
|
7463
7492
|
* Processes an OAuth authorization code.
|
|
7464
7493
|
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
|
|
7465
7494
|
* @param code The authorization code received by URL parameter.
|
|
7466
7495
|
*/
|
|
7467
7496
|
processCode(code) {
|
|
7468
|
-
const pkceState = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState');
|
|
7469
|
-
if (!pkceState) {
|
|
7470
|
-
this.clear();
|
|
7471
|
-
throw new Error('Invalid PCKE state');
|
|
7472
|
-
}
|
|
7473
|
-
const codeVerifier = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeVerifier');
|
|
7474
|
-
if (!codeVerifier) {
|
|
7475
|
-
this.clear();
|
|
7476
|
-
throw new Error('Invalid PCKE code verifier');
|
|
7477
|
-
}
|
|
7478
7497
|
const formBody = new URLSearchParams();
|
|
7479
7498
|
formBody.set('grant_type', 'authorization_code');
|
|
7480
7499
|
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
7481
|
-
formBody.set('code_verifier', codeVerifier);
|
|
7482
7500
|
formBody.set('code', code);
|
|
7483
7501
|
formBody.set('redirect_uri', getBaseUrl());
|
|
7502
|
+
const codeVerifier = sessionStorage.getItem('codeVerifier');
|
|
7503
|
+
if (codeVerifier) {
|
|
7504
|
+
formBody.set('code_verifier', codeVerifier);
|
|
7505
|
+
}
|
|
7484
7506
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
7485
7507
|
}
|
|
7486
7508
|
/**
|
|
@@ -7604,27 +7626,17 @@
|
|
|
7604
7626
|
return Promise.reject(error);
|
|
7605
7627
|
});
|
|
7606
7628
|
});
|
|
7607
|
-
}, _MedplumClient_startPkce = function _MedplumClient_startPkce() {
|
|
7608
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
7609
|
-
const pkceState = getRandomString();
|
|
7610
|
-
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('pkceState', pkceState);
|
|
7611
|
-
const codeVerifier = getRandomString();
|
|
7612
|
-
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeVerifier', codeVerifier);
|
|
7613
|
-
const arrayHash = yield encryptSHA256(codeVerifier);
|
|
7614
|
-
const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
7615
|
-
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeChallenge', codeChallenge);
|
|
7616
|
-
});
|
|
7617
7629
|
}, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
|
|
7618
7630
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7619
|
-
yield
|
|
7631
|
+
yield this.startPkce();
|
|
7620
7632
|
const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
|
|
7621
7633
|
url.searchParams.set('response_type', 'code');
|
|
7622
|
-
url.searchParams.set('state',
|
|
7634
|
+
url.searchParams.set('state', sessionStorage.getItem('pkceState'));
|
|
7623
7635
|
url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
7624
7636
|
url.searchParams.set('redirect_uri', getBaseUrl());
|
|
7625
7637
|
url.searchParams.set('scope', DEFAULT_SCOPE);
|
|
7626
7638
|
url.searchParams.set('code_challenge_method', 'S256');
|
|
7627
|
-
url.searchParams.set('code_challenge',
|
|
7639
|
+
url.searchParams.set('code_challenge', sessionStorage.getItem('codeChallenge'));
|
|
7628
7640
|
window.location.assign(url.toString());
|
|
7629
7641
|
});
|
|
7630
7642
|
}, _MedplumClient_refresh = function _MedplumClient_refresh() {
|
|
@@ -7649,6 +7661,7 @@
|
|
|
7649
7661
|
method: 'POST',
|
|
7650
7662
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
7651
7663
|
body: formBody,
|
|
7664
|
+
credentials: 'include',
|
|
7652
7665
|
})
|
|
7653
7666
|
.then((response) => {
|
|
7654
7667
|
if (!response.ok) {
|
|
@@ -9925,10 +9938,108 @@
|
|
|
9925
9938
|
}
|
|
9926
9939
|
}
|
|
9927
9940
|
|
|
9928
|
-
var
|
|
9929
|
-
|
|
9930
|
-
|
|
9941
|
+
var _ParserBuilder_prefixParselets, _ParserBuilder_infixParselets, _Parser_tokens, _Parser_prefixParselets, _Parser_infixParselets;
|
|
9942
|
+
class ParserBuilder {
|
|
9943
|
+
constructor() {
|
|
9944
|
+
_ParserBuilder_prefixParselets.set(this, {});
|
|
9945
|
+
_ParserBuilder_infixParselets.set(this, {});
|
|
9946
|
+
}
|
|
9947
|
+
registerInfix(tokenType, parselet) {
|
|
9948
|
+
__classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
|
|
9949
|
+
return this;
|
|
9950
|
+
}
|
|
9951
|
+
registerPrefix(tokenType, parselet) {
|
|
9952
|
+
__classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
|
|
9953
|
+
return this;
|
|
9954
|
+
}
|
|
9955
|
+
prefix(tokenType, precedence, builder) {
|
|
9956
|
+
return this.registerPrefix(tokenType, {
|
|
9957
|
+
parse(parser, token) {
|
|
9958
|
+
const right = parser.consumeAndParse(precedence);
|
|
9959
|
+
return builder(token, right);
|
|
9960
|
+
},
|
|
9961
|
+
});
|
|
9962
|
+
}
|
|
9963
|
+
infixLeft(tokenType, precedence, builder) {
|
|
9964
|
+
return this.registerInfix(tokenType, {
|
|
9965
|
+
parse(parser, left, token) {
|
|
9966
|
+
const right = parser.consumeAndParse(precedence);
|
|
9967
|
+
return builder(left, token, right);
|
|
9968
|
+
},
|
|
9969
|
+
precedence,
|
|
9970
|
+
});
|
|
9971
|
+
}
|
|
9972
|
+
construct(input) {
|
|
9973
|
+
return new Parser(input, __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
|
|
9974
|
+
}
|
|
9975
|
+
}
|
|
9976
|
+
_ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
|
|
9977
|
+
class Parser {
|
|
9978
|
+
constructor(tokens, prefixParselets, infixParselets) {
|
|
9979
|
+
_Parser_tokens.set(this, void 0);
|
|
9980
|
+
_Parser_prefixParselets.set(this, void 0);
|
|
9981
|
+
_Parser_infixParselets.set(this, void 0);
|
|
9982
|
+
__classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
|
|
9983
|
+
__classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
|
|
9984
|
+
__classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
|
|
9985
|
+
}
|
|
9986
|
+
hasMore() {
|
|
9987
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0;
|
|
9988
|
+
}
|
|
9989
|
+
match(expected) {
|
|
9990
|
+
const token = this.peek();
|
|
9991
|
+
if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
|
|
9992
|
+
return false;
|
|
9993
|
+
}
|
|
9994
|
+
this.consume();
|
|
9995
|
+
return true;
|
|
9996
|
+
}
|
|
9997
|
+
consumeAndParse(precedence = Infinity) {
|
|
9998
|
+
const token = this.consume();
|
|
9999
|
+
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
10000
|
+
if (!prefix) {
|
|
10001
|
+
throw Error(`Parse error at "${token.value}" (line ${token.line}, column ${token.column}). No matching prefix parselet.`);
|
|
10002
|
+
}
|
|
10003
|
+
let left = prefix.parse(this, token);
|
|
10004
|
+
while (precedence > this.getPrecedence()) {
|
|
10005
|
+
const next = this.consume();
|
|
10006
|
+
const infix = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[next.id];
|
|
10007
|
+
left = infix.parse(this, left, next);
|
|
10008
|
+
}
|
|
10009
|
+
return left;
|
|
10010
|
+
}
|
|
10011
|
+
getPrecedence() {
|
|
10012
|
+
const nextToken = this.peek();
|
|
10013
|
+
if (!nextToken) {
|
|
10014
|
+
return Infinity;
|
|
10015
|
+
}
|
|
10016
|
+
const parser = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[nextToken.id];
|
|
10017
|
+
if (parser) {
|
|
10018
|
+
return parser.precedence;
|
|
10019
|
+
}
|
|
10020
|
+
return Infinity;
|
|
10021
|
+
}
|
|
10022
|
+
consume(expected) {
|
|
10023
|
+
var _a;
|
|
10024
|
+
if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
|
|
10025
|
+
throw Error('Cant consume unknown more tokens.');
|
|
10026
|
+
}
|
|
10027
|
+
if (expected && ((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.id) !== expected) {
|
|
10028
|
+
const actual = this.peek();
|
|
10029
|
+
throw Error(`Expected ${expected} but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
|
|
10030
|
+
}
|
|
10031
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
|
|
10032
|
+
}
|
|
10033
|
+
peek() {
|
|
10034
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
|
|
10035
|
+
}
|
|
10036
|
+
removeComments() {
|
|
10037
|
+
__classPrivateFieldSet(this, _Parser_tokens, __classPrivateFieldGet(this, _Parser_tokens, "f").filter((t) => t.id !== 'Comment'), "f");
|
|
10038
|
+
}
|
|
9931
10039
|
}
|
|
10040
|
+
_Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser_infixParselets = new WeakMap();
|
|
10041
|
+
|
|
10042
|
+
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;
|
|
9932
10043
|
const STANDARD_UNITS = [
|
|
9933
10044
|
'year',
|
|
9934
10045
|
'years',
|
|
@@ -9947,30 +10058,35 @@
|
|
|
9947
10058
|
'millisecond',
|
|
9948
10059
|
'milliseconds',
|
|
9949
10060
|
];
|
|
9950
|
-
const TWO_CHAR_OPERATORS = ['!=', '!~', '<=', '>=', '{}'];
|
|
9951
10061
|
class Tokenizer {
|
|
9952
|
-
constructor(str) {
|
|
10062
|
+
constructor(str, keywords, operators) {
|
|
9953
10063
|
_Tokenizer_instances.add(this);
|
|
9954
10064
|
_Tokenizer_str.set(this, void 0);
|
|
9955
|
-
|
|
10065
|
+
_Tokenizer_keywords.set(this, void 0);
|
|
10066
|
+
_Tokenizer_operators.set(this, void 0);
|
|
10067
|
+
_Tokenizer_result.set(this, []);
|
|
10068
|
+
_Tokenizer_pos.set(this, { index: 0, line: 0, column: 0 });
|
|
10069
|
+
_Tokenizer_markStack.set(this, []);
|
|
9956
10070
|
__classPrivateFieldSet(this, _Tokenizer_str, str, "f");
|
|
9957
|
-
__classPrivateFieldSet(this,
|
|
10071
|
+
__classPrivateFieldSet(this, _Tokenizer_keywords, keywords, "f");
|
|
10072
|
+
__classPrivateFieldSet(this, _Tokenizer_operators, operators, "f");
|
|
9958
10073
|
}
|
|
9959
10074
|
tokenize() {
|
|
9960
|
-
|
|
9961
|
-
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f") < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
|
|
10075
|
+
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
|
|
9962
10076
|
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
9963
10077
|
if (token) {
|
|
9964
|
-
|
|
10078
|
+
__classPrivateFieldGet(this, _Tokenizer_result, "f").push(token);
|
|
9965
10079
|
}
|
|
9966
10080
|
}
|
|
9967
|
-
return
|
|
10081
|
+
return __classPrivateFieldGet(this, _Tokenizer_result, "f");
|
|
9968
10082
|
}
|
|
9969
10083
|
}
|
|
9970
|
-
_Tokenizer_str = new WeakMap(), _Tokenizer_pos = new WeakMap(), _Tokenizer_instances = new WeakSet(),
|
|
9971
|
-
|
|
10084
|
+
_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() {
|
|
10085
|
+
return __classPrivateFieldGet(this, _Tokenizer_result, "f").slice(-1)[0];
|
|
10086
|
+
}, _Tokenizer_peekToken = function _Tokenizer_peekToken() {
|
|
10087
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
|
|
9972
10088
|
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
9973
|
-
|
|
10089
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_reset).call(this);
|
|
9974
10090
|
return token;
|
|
9975
10091
|
}, _Tokenizer_consumeToken = function _Tokenizer_consumeToken() {
|
|
9976
10092
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhitespace).call(this);
|
|
@@ -9978,6 +10094,7 @@
|
|
|
9978
10094
|
if (!c) {
|
|
9979
10095
|
return undefined;
|
|
9980
10096
|
}
|
|
10097
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
|
|
9981
10098
|
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
9982
10099
|
if (c === '/' && next === '*') {
|
|
9983
10100
|
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeMultiLineComment).call(this);
|
|
@@ -9985,8 +10102,8 @@
|
|
|
9985
10102
|
if (c === '/' && next === '/') {
|
|
9986
10103
|
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSingleLineComment).call(this);
|
|
9987
10104
|
}
|
|
9988
|
-
if (c === "'") {
|
|
9989
|
-
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeString).call(this);
|
|
10105
|
+
if (c === "'" || c === '"') {
|
|
10106
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeString).call(this, c);
|
|
9990
10107
|
}
|
|
9991
10108
|
if (c === '`') {
|
|
9992
10109
|
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeBacktickSymbol).call(this);
|
|
@@ -10005,54 +10122,51 @@
|
|
|
10005
10122
|
}
|
|
10006
10123
|
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeOperator).call(this);
|
|
10007
10124
|
}, _Tokenizer_consumeWhitespace = function _Tokenizer_consumeWhitespace() {
|
|
10008
|
-
|
|
10125
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\s/));
|
|
10009
10126
|
}, _Tokenizer_consumeMultiLineComment = function _Tokenizer_consumeMultiLineComment() {
|
|
10010
|
-
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
10127
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
10011
10128
|
__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) !== '/');
|
|
10012
|
-
|
|
10013
|
-
|
|
10129
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10130
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10131
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
10014
10132
|
}, _Tokenizer_consumeSingleLineComment = function _Tokenizer_consumeSingleLineComment() {
|
|
10015
|
-
return
|
|
10016
|
-
}, _Tokenizer_consumeString = function _Tokenizer_consumeString() {
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
__classPrivateFieldSet(this, _Tokenizer_pos, (_b = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _b++, _b), "f");
|
|
10133
|
+
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'));
|
|
10134
|
+
}, _Tokenizer_consumeString = function _Tokenizer_consumeString(endChar) {
|
|
10135
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10136
|
+
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));
|
|
10137
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10021
10138
|
return result;
|
|
10022
10139
|
}, _Tokenizer_consumeBacktickSymbol = function _Tokenizer_consumeBacktickSymbol() {
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
__classPrivateFieldSet(this, _Tokenizer_pos, (_b = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _b++, _b), "f");
|
|
10140
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10141
|
+
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) !== '`'));
|
|
10142
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10027
10143
|
return result;
|
|
10028
10144
|
}, _Tokenizer_consumeDateTime = function _Tokenizer_consumeDateTime() {
|
|
10029
|
-
|
|
10030
|
-
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
10031
|
-
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
10145
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this); // Consume "@"
|
|
10146
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
10032
10147
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d-]/));
|
|
10033
10148
|
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'T') {
|
|
10034
|
-
|
|
10149
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10035
10150
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
10036
10151
|
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
10037
|
-
|
|
10038
|
-
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(
|
|
10152
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10153
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
10039
10154
|
}
|
|
10040
10155
|
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'Z') {
|
|
10041
|
-
|
|
10156
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10042
10157
|
}
|
|
10043
10158
|
else if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '+' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '-') {
|
|
10044
|
-
|
|
10159
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10045
10160
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
10046
10161
|
}
|
|
10047
10162
|
}
|
|
10048
|
-
return
|
|
10163
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'DateTime', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
10049
10164
|
}, _Tokenizer_consumeNumber = function _Tokenizer_consumeNumber() {
|
|
10050
|
-
|
|
10051
|
-
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
10165
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
10052
10166
|
let id = 'Number';
|
|
10053
10167
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
10054
10168
|
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
10055
|
-
|
|
10169
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10056
10170
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
10057
10171
|
}
|
|
10058
10172
|
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === ' ') {
|
|
@@ -10061,39 +10175,66 @@
|
|
|
10061
10175
|
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
10062
10176
|
}
|
|
10063
10177
|
}
|
|
10064
|
-
return
|
|
10178
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, id, __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
|
|
10065
10179
|
}, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
|
|
10066
|
-
return buildToken('Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/)));
|
|
10067
|
-
}, _Tokenizer_consumeOperator = function _Tokenizer_consumeOperator() {
|
|
10068
10180
|
var _a;
|
|
10181
|
+
const value = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/));
|
|
10182
|
+
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)) {
|
|
10183
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, value, value);
|
|
10184
|
+
}
|
|
10185
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', value);
|
|
10186
|
+
}, _Tokenizer_consumeOperator = function _Tokenizer_consumeOperator() {
|
|
10069
10187
|
const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
|
|
10070
10188
|
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
10071
10189
|
const twoCharOp = c + next;
|
|
10072
|
-
if (
|
|
10073
|
-
|
|
10074
|
-
|
|
10190
|
+
if (__classPrivateFieldGet(this, _Tokenizer_operators, "f").includes(twoCharOp)) {
|
|
10191
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10192
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10193
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, twoCharOp, twoCharOp);
|
|
10075
10194
|
}
|
|
10076
|
-
|
|
10077
|
-
return
|
|
10195
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10196
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, c, c);
|
|
10078
10197
|
}, _Tokenizer_consumeWhile = function _Tokenizer_consumeWhile(condition) {
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
10198
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
|
|
10199
|
+
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length && condition()) {
|
|
10200
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
|
|
10083
10201
|
}
|
|
10084
|
-
return __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f"));
|
|
10202
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index);
|
|
10085
10203
|
}, _Tokenizer_curr = function _Tokenizer_curr() {
|
|
10086
|
-
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f")];
|
|
10204
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index];
|
|
10087
10205
|
}, _Tokenizer_prev = function _Tokenizer_prev() {
|
|
10088
10206
|
var _a;
|
|
10089
|
-
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f") - 1]) !== null && _a !== void 0 ? _a : '';
|
|
10207
|
+
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1]) !== null && _a !== void 0 ? _a : '';
|
|
10090
10208
|
}, _Tokenizer_peek = function _Tokenizer_peek() {
|
|
10091
10209
|
var _a;
|
|
10092
|
-
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f") + 1]) !== null && _a !== void 0 ? _a : '';
|
|
10210
|
+
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1]) !== null && _a !== void 0 ? _a : '';
|
|
10211
|
+
}, _Tokenizer_mark = function _Tokenizer_mark() {
|
|
10212
|
+
__classPrivateFieldGet(this, _Tokenizer_markStack, "f").push(Object.assign({}, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
|
|
10213
|
+
}, _Tokenizer_reset = function _Tokenizer_reset() {
|
|
10214
|
+
const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
|
|
10215
|
+
if (!mark) {
|
|
10216
|
+
throw new Error('No mark to reset to');
|
|
10217
|
+
}
|
|
10218
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").index = mark.index;
|
|
10219
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").line = mark.line;
|
|
10220
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column = mark.column;
|
|
10221
|
+
}, _Tokenizer_advance = function _Tokenizer_advance() {
|
|
10222
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").index++;
|
|
10223
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '\n') {
|
|
10224
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").line++;
|
|
10225
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column = 0;
|
|
10226
|
+
}
|
|
10227
|
+
else {
|
|
10228
|
+
__classPrivateFieldGet(this, _Tokenizer_pos, "f").column++;
|
|
10229
|
+
}
|
|
10230
|
+
}, _Tokenizer_buildToken = function _Tokenizer_buildToken(id, value) {
|
|
10231
|
+
const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
|
|
10232
|
+
if (!mark) {
|
|
10233
|
+
throw new Error('No mark for token');
|
|
10234
|
+
}
|
|
10235
|
+
return Object.assign({ id,
|
|
10236
|
+
value }, mark);
|
|
10093
10237
|
};
|
|
10094
|
-
function buildToken(id, value) {
|
|
10095
|
-
return { id, value };
|
|
10096
|
-
}
|
|
10097
10238
|
function isUnitToken(token) {
|
|
10098
10239
|
if (token) {
|
|
10099
10240
|
if (token.id === 'String') {
|
|
@@ -10106,93 +10247,12 @@
|
|
|
10106
10247
|
return false;
|
|
10107
10248
|
}
|
|
10108
10249
|
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
_ParserBuilder_infixParselets.set(this, {});
|
|
10114
|
-
}
|
|
10115
|
-
registerInfix(tokenType, parselet) {
|
|
10116
|
-
__classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
|
|
10117
|
-
return this;
|
|
10118
|
-
}
|
|
10119
|
-
registerPrefix(tokenType, parselet) {
|
|
10120
|
-
__classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
|
|
10121
|
-
return this;
|
|
10122
|
-
}
|
|
10123
|
-
prefix(tokenType, precedence, builder) {
|
|
10124
|
-
return this.registerPrefix(tokenType, {
|
|
10125
|
-
parse(parser, token) {
|
|
10126
|
-
const right = parser.consumeAndParse(precedence);
|
|
10127
|
-
return builder(token, right);
|
|
10128
|
-
},
|
|
10129
|
-
});
|
|
10130
|
-
}
|
|
10131
|
-
infixLeft(tokenType, precedence, builder) {
|
|
10132
|
-
return this.registerInfix(tokenType, {
|
|
10133
|
-
parse(parser, left, token) {
|
|
10134
|
-
const right = parser.consumeAndParse(precedence);
|
|
10135
|
-
return builder(left, token, right);
|
|
10136
|
-
},
|
|
10137
|
-
precedence,
|
|
10138
|
-
});
|
|
10139
|
-
}
|
|
10140
|
-
construct(input) {
|
|
10141
|
-
return new Parser(tokenize(input), __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
|
|
10142
|
-
}
|
|
10143
|
-
}
|
|
10144
|
-
_ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
|
|
10145
|
-
class Parser {
|
|
10146
|
-
constructor(tokens, prefixParselets, infixParselets) {
|
|
10147
|
-
_Parser_instances.add(this);
|
|
10148
|
-
_Parser_tokens.set(this, void 0);
|
|
10149
|
-
_Parser_prefixParselets.set(this, void 0);
|
|
10150
|
-
_Parser_infixParselets.set(this, void 0);
|
|
10151
|
-
__classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
|
|
10152
|
-
__classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
|
|
10153
|
-
__classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
|
|
10154
|
-
}
|
|
10155
|
-
match(expected) {
|
|
10156
|
-
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_look).call(this);
|
|
10157
|
-
if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
|
|
10158
|
-
return false;
|
|
10159
|
-
}
|
|
10160
|
-
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
10161
|
-
return true;
|
|
10162
|
-
}
|
|
10163
|
-
consumeAndParse(precedence = 100 /* Precedence.MaximumPrecedence */) {
|
|
10164
|
-
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
10165
|
-
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
10166
|
-
if (!prefix) {
|
|
10167
|
-
throw Error(`Parse error at ${token.value}. No matching prefix parselet.`);
|
|
10168
|
-
}
|
|
10169
|
-
let left = prefix.parse(this, token);
|
|
10170
|
-
while (precedence > __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_getPrecedence).call(this)) {
|
|
10171
|
-
const next = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
10172
|
-
const infix = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[next.id];
|
|
10173
|
-
left = infix.parse(this, left, next);
|
|
10174
|
-
}
|
|
10175
|
-
return left;
|
|
10176
|
-
}
|
|
10250
|
+
const FHIRPATH_KEYWORDS = ['true', 'false', 'and', 'as', 'contains', 'div', 'in', 'is', 'mod', 'or', 'xor'];
|
|
10251
|
+
const FHIRPATH_OPERATORS = ['!=', '!~', '<=', '>=', '{}', '->'];
|
|
10252
|
+
function tokenize(str) {
|
|
10253
|
+
return new Tokenizer(str, FHIRPATH_KEYWORDS, FHIRPATH_OPERATORS).tokenize();
|
|
10177
10254
|
}
|
|
10178
|
-
|
|
10179
|
-
const nextToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_look).call(this);
|
|
10180
|
-
if (!nextToken) {
|
|
10181
|
-
return 100 /* Precedence.MaximumPrecedence */;
|
|
10182
|
-
}
|
|
10183
|
-
const parser = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[nextToken.id];
|
|
10184
|
-
if (parser) {
|
|
10185
|
-
return parser.precedence;
|
|
10186
|
-
}
|
|
10187
|
-
return 100 /* Precedence.MaximumPrecedence */;
|
|
10188
|
-
}, _Parser_consume = function _Parser_consume() {
|
|
10189
|
-
if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
|
|
10190
|
-
throw Error('Cant consume unknown more tokens.');
|
|
10191
|
-
}
|
|
10192
|
-
return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
|
|
10193
|
-
}, _Parser_look = function _Parser_look() {
|
|
10194
|
-
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
|
|
10195
|
-
};
|
|
10255
|
+
|
|
10196
10256
|
const PARENTHESES_PARSELET = {
|
|
10197
10257
|
parse(parser) {
|
|
10198
10258
|
const expr = parser.consumeAndParse();
|
|
@@ -10241,75 +10301,55 @@
|
|
|
10241
10301
|
}
|
|
10242
10302
|
return { value, unit };
|
|
10243
10303
|
}
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
}
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10293
|
-
case 'as':
|
|
10294
|
-
return new AsAtom(left, right);
|
|
10295
|
-
case 'contains':
|
|
10296
|
-
return new ContainsAtom(left, right);
|
|
10297
|
-
case 'div':
|
|
10298
|
-
return new ArithemticOperatorAtom(left, right, (x, y) => (x / y) | 0);
|
|
10299
|
-
case 'in':
|
|
10300
|
-
return new InAtom(left, right);
|
|
10301
|
-
case 'is':
|
|
10302
|
-
return new IsAtom(left, right);
|
|
10303
|
-
case 'mod':
|
|
10304
|
-
return new ArithemticOperatorAtom(left, right, (x, y) => x % y);
|
|
10305
|
-
case 'or':
|
|
10306
|
-
return new OrAtom(left, right);
|
|
10307
|
-
case 'xor':
|
|
10308
|
-
return new XorAtom(left, right);
|
|
10309
|
-
default:
|
|
10310
|
-
throw new Error('Cannot use ' + symbol.value + ' as infix operator');
|
|
10311
|
-
}
|
|
10312
|
-
});
|
|
10304
|
+
function initFhirPathParserBuilder() {
|
|
10305
|
+
return new ParserBuilder()
|
|
10306
|
+
.registerPrefix('String', {
|
|
10307
|
+
parse: (_, token) => new LiteralAtom({ type: exports.PropertyType.string, value: token.value }),
|
|
10308
|
+
})
|
|
10309
|
+
.registerPrefix('DateTime', {
|
|
10310
|
+
parse: (_, token) => new LiteralAtom({ type: exports.PropertyType.dateTime, value: parseDateString(token.value) }),
|
|
10311
|
+
})
|
|
10312
|
+
.registerPrefix('Quantity', {
|
|
10313
|
+
parse: (_, token) => new LiteralAtom({ type: exports.PropertyType.Quantity, value: parseQuantity(token.value) }),
|
|
10314
|
+
})
|
|
10315
|
+
.registerPrefix('Number', {
|
|
10316
|
+
parse: (_, token) => new LiteralAtom({ type: exports.PropertyType.decimal, value: parseFloat(token.value) }),
|
|
10317
|
+
})
|
|
10318
|
+
.registerPrefix('true', { parse: () => new LiteralAtom({ type: exports.PropertyType.boolean, value: true }) })
|
|
10319
|
+
.registerPrefix('false', { parse: () => new LiteralAtom({ type: exports.PropertyType.boolean, value: false }) })
|
|
10320
|
+
.registerPrefix('Symbol', { parse: (_, token) => new SymbolAtom(token.value) })
|
|
10321
|
+
.registerPrefix('{}', { parse: () => new EmptySetAtom() })
|
|
10322
|
+
.registerPrefix('(', PARENTHESES_PARSELET)
|
|
10323
|
+
.registerInfix('[', INDEXER_PARSELET)
|
|
10324
|
+
.registerInfix('(', FUNCTION_CALL_PARSELET)
|
|
10325
|
+
.prefix('+', 3 /* Precedence.UnaryAdd */, (_, right) => new UnaryOperatorAtom(right, (x) => x))
|
|
10326
|
+
.prefix('-', 3 /* Precedence.UnarySubtract */, (_, right) => new ArithemticOperatorAtom(right, right, (_, y) => -y))
|
|
10327
|
+
.infixLeft('.', 1 /* Precedence.Dot */, (left, _, right) => new DotAtom(left, right))
|
|
10328
|
+
.infixLeft('/', 4 /* Precedence.Divide */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x / y))
|
|
10329
|
+
.infixLeft('*', 4 /* Precedence.Multiply */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x * y))
|
|
10330
|
+
.infixLeft('+', 5 /* Precedence.Add */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x + y))
|
|
10331
|
+
.infixLeft('-', 5 /* Precedence.Subtract */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x - y))
|
|
10332
|
+
.infixLeft('|', 7 /* Precedence.Union */, (left, _, right) => new UnionAtom(left, right))
|
|
10333
|
+
.infixLeft('=', 9 /* Precedence.Equals */, (left, _, right) => new EqualsAtom(left, right))
|
|
10334
|
+
.infixLeft('!=', 9 /* Precedence.Equals */, (left, _, right) => new NotEqualsAtom(left, right))
|
|
10335
|
+
.infixLeft('~', 9 /* Precedence.Equivalent */, (left, _, right) => new EquivalentAtom(left, right))
|
|
10336
|
+
.infixLeft('!~', 9 /* Precedence.NotEquivalent */, (left, _, right) => new NotEquivalentAtom(left, right))
|
|
10337
|
+
.infixLeft('<', 8 /* Precedence.LessThan */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x < y))
|
|
10338
|
+
.infixLeft('<=', 8 /* Precedence.LessThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x <= y))
|
|
10339
|
+
.infixLeft('>', 8 /* Precedence.GreaterThan */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x > y))
|
|
10340
|
+
.infixLeft('>=', 8 /* Precedence.GreaterThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x >= y))
|
|
10341
|
+
.infixLeft('&', 5 /* Precedence.Ampersand */, (left, _, right) => new ConcatAtom(left, right))
|
|
10342
|
+
.infixLeft('and', 6 /* Precedence.Is */, (left, _, right) => new AndAtom(left, right))
|
|
10343
|
+
.infixLeft('as', 6 /* Precedence.Is */, (left, _, right) => new AsAtom(left, right))
|
|
10344
|
+
.infixLeft('contains', 6 /* Precedence.Is */, (left, _, right) => new ContainsAtom(left, right))
|
|
10345
|
+
.infixLeft('div', 6 /* Precedence.Is */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => (x / y) | 0))
|
|
10346
|
+
.infixLeft('in', 6 /* Precedence.Is */, (left, _, right) => new InAtom(left, right))
|
|
10347
|
+
.infixLeft('is', 6 /* Precedence.Is */, (left, _, right) => new IsAtom(left, right))
|
|
10348
|
+
.infixLeft('mod', 6 /* Precedence.Is */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x % y))
|
|
10349
|
+
.infixLeft('or', 6 /* Precedence.Is */, (left, _, right) => new OrAtom(left, right))
|
|
10350
|
+
.infixLeft('xor', 6 /* Precedence.Is */, (left, _, right) => new XorAtom(left, right));
|
|
10351
|
+
}
|
|
10352
|
+
const fhirPathParserBuilder = initFhirPathParserBuilder();
|
|
10313
10353
|
/**
|
|
10314
10354
|
* Parses a FHIRPath expression into an AST.
|
|
10315
10355
|
* The result can be used to evaluate the expression against a resource or other object.
|
|
@@ -10319,17 +10359,12 @@
|
|
|
10319
10359
|
* @returns The AST representing the expression.
|
|
10320
10360
|
*/
|
|
10321
10361
|
function parseFhirPath(input) {
|
|
10322
|
-
|
|
10323
|
-
return new FhirPathAtom(input, parserBuilder.construct(input).consumeAndParse());
|
|
10324
|
-
}
|
|
10325
|
-
catch (error) {
|
|
10326
|
-
throw new Error(`FhirPathError on "${input}": ${error}`);
|
|
10327
|
-
}
|
|
10362
|
+
return new FhirPathAtom(input, fhirPathParserBuilder.construct(tokenize(input)).consumeAndParse());
|
|
10328
10363
|
}
|
|
10329
10364
|
/**
|
|
10330
10365
|
* Evaluates a FHIRPath expression against a resource or other object.
|
|
10331
|
-
* @param
|
|
10332
|
-
* @param
|
|
10366
|
+
* @param expression The FHIRPath expression to parse.
|
|
10367
|
+
* @param input The resource or object to evaluate the expression against.
|
|
10333
10368
|
* @returns The result of the FHIRPath expression against the resource or object.
|
|
10334
10369
|
*/
|
|
10335
10370
|
function evalFhirPath(expression, input) {
|
|
@@ -10346,8 +10381,8 @@
|
|
|
10346
10381
|
}
|
|
10347
10382
|
/**
|
|
10348
10383
|
* Evaluates a FHIRPath expression against a resource or other object.
|
|
10349
|
-
* @param
|
|
10350
|
-
* @param
|
|
10384
|
+
* @param expression The FHIRPath expression to parse.
|
|
10385
|
+
* @param input The resource or object to evaluate the expression against.
|
|
10351
10386
|
* @returns The result of the FHIRPath expression against the resource or object.
|
|
10352
10387
|
*/
|
|
10353
10388
|
function evalFhirPathTyped(expression, input) {
|
|
@@ -10553,7 +10588,7 @@
|
|
|
10553
10588
|
issue: [
|
|
10554
10589
|
{
|
|
10555
10590
|
severity: 'error',
|
|
10556
|
-
code: '
|
|
10591
|
+
code: 'deleted',
|
|
10557
10592
|
details: {
|
|
10558
10593
|
text: 'Gone',
|
|
10559
10594
|
},
|
|
@@ -11039,6 +11074,8 @@
|
|
|
11039
11074
|
exports.EmptySetAtom = EmptySetAtom;
|
|
11040
11075
|
exports.EqualsAtom = EqualsAtom;
|
|
11041
11076
|
exports.EquivalentAtom = EquivalentAtom;
|
|
11077
|
+
exports.FHIRPATH_KEYWORDS = FHIRPATH_KEYWORDS;
|
|
11078
|
+
exports.FHIRPATH_OPERATORS = FHIRPATH_OPERATORS;
|
|
11042
11079
|
exports.FIELD_SEPARATOR = FIELD_SEPARATOR;
|
|
11043
11080
|
exports.FhirPathAtom = FhirPathAtom;
|
|
11044
11081
|
exports.FunctionAtom = FunctionAtom;
|
|
@@ -11116,6 +11153,7 @@
|
|
|
11116
11153
|
exports.indexSearchParameter = indexSearchParameter;
|
|
11117
11154
|
exports.indexStructureDefinition = indexStructureDefinition;
|
|
11118
11155
|
exports.indexStructureDefinitionBundle = indexStructureDefinitionBundle;
|
|
11156
|
+
exports.initFhirPathParserBuilder = initFhirPathParserBuilder;
|
|
11119
11157
|
exports.isEmpty = isEmpty;
|
|
11120
11158
|
exports.isGone = isGone;
|
|
11121
11159
|
exports.isLowerCase = isLowerCase;
|