@medplum/core 0.9.27 → 0.9.28
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/index.js +182 -16
- 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.js +14 -9
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/fhirpath/utils.js +12 -3
- package/dist/esm/fhirpath/utils.js.map +1 -1
- package/dist/esm/format.d.ts +7 -1
- package/dist/esm/format.js +108 -1
- package/dist/esm/format.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.d.ts +7 -0
- package/dist/esm/outcomes.js +44 -5
- package/dist/esm/outcomes.js.map +1 -1
- package/package.json +3 -3
- package/stats.html +4034 -0
package/dist/esm/outcomes.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const notModified: OperationOutcome;
|
|
|
5
5
|
export declare const notFound: OperationOutcome;
|
|
6
6
|
export declare const gone: OperationOutcome;
|
|
7
7
|
export declare const accessDenied: OperationOutcome;
|
|
8
|
+
export declare const tooManyRequests: OperationOutcome;
|
|
8
9
|
export declare function badRequest(details: string, expression?: string): OperationOutcome;
|
|
9
10
|
export declare function isOk(outcome: OperationOutcome): boolean;
|
|
10
11
|
export declare function isNotFound(outcome: OperationOutcome): boolean;
|
|
@@ -20,3 +21,9 @@ export declare class OperationOutcomeError extends Error {
|
|
|
20
21
|
readonly outcome: OperationOutcome;
|
|
21
22
|
constructor(outcome: OperationOutcome);
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Normalizes an error object into a displayable error string.
|
|
26
|
+
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
|
27
|
+
* @returns A display string for the error.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeErrorString(error: unknown): string;
|
package/dist/esm/outcomes.js
CHANGED
|
@@ -3,7 +3,8 @@ const CREATED_ID = 'created';
|
|
|
3
3
|
const GONE_ID = 'gone';
|
|
4
4
|
const NOT_MODIFIED_ID = 'not-modified';
|
|
5
5
|
const NOT_FOUND_ID = 'not-found';
|
|
6
|
-
const
|
|
6
|
+
const ACCESS_DENIED_ID = 'access-denied';
|
|
7
|
+
const TOO_MANY_REQUESTS_ID = 'too-many-requests';
|
|
7
8
|
const allOk = {
|
|
8
9
|
resourceType: 'OperationOutcome',
|
|
9
10
|
id: OK_ID,
|
|
@@ -71,17 +72,30 @@ const gone = {
|
|
|
71
72
|
};
|
|
72
73
|
const accessDenied = {
|
|
73
74
|
resourceType: 'OperationOutcome',
|
|
74
|
-
id:
|
|
75
|
+
id: ACCESS_DENIED_ID,
|
|
75
76
|
issue: [
|
|
76
77
|
{
|
|
77
78
|
severity: 'error',
|
|
78
|
-
code: '
|
|
79
|
+
code: 'forbidden',
|
|
79
80
|
details: {
|
|
80
81
|
text: 'Access Denied',
|
|
81
82
|
},
|
|
82
83
|
},
|
|
83
84
|
],
|
|
84
85
|
};
|
|
86
|
+
const tooManyRequests = {
|
|
87
|
+
resourceType: 'OperationOutcome',
|
|
88
|
+
id: TOO_MANY_REQUESTS_ID,
|
|
89
|
+
issue: [
|
|
90
|
+
{
|
|
91
|
+
severity: 'error',
|
|
92
|
+
code: 'throttled',
|
|
93
|
+
details: {
|
|
94
|
+
text: 'Too Many Requests',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
};
|
|
85
99
|
function badRequest(details, expression) {
|
|
86
100
|
return {
|
|
87
101
|
resourceType: 'OperationOutcome',
|
|
@@ -116,7 +130,7 @@ function getStatus(outcome) {
|
|
|
116
130
|
else if (outcome.id === NOT_MODIFIED_ID) {
|
|
117
131
|
return 304;
|
|
118
132
|
}
|
|
119
|
-
else if (outcome.id ===
|
|
133
|
+
else if (outcome.id === ACCESS_DENIED_ID) {
|
|
120
134
|
return 403;
|
|
121
135
|
}
|
|
122
136
|
else if (outcome.id === NOT_FOUND_ID) {
|
|
@@ -125,6 +139,9 @@ function getStatus(outcome) {
|
|
|
125
139
|
else if (outcome.id === GONE_ID) {
|
|
126
140
|
return 410;
|
|
127
141
|
}
|
|
142
|
+
else if (outcome.id === TOO_MANY_REQUESTS_ID) {
|
|
143
|
+
return 429;
|
|
144
|
+
}
|
|
128
145
|
else {
|
|
129
146
|
return 400;
|
|
130
147
|
}
|
|
@@ -146,6 +163,28 @@ class OperationOutcomeError extends Error {
|
|
|
146
163
|
this.outcome = outcome;
|
|
147
164
|
}
|
|
148
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Normalizes an error object into a displayable error string.
|
|
168
|
+
* @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
|
|
169
|
+
* @returns A display string for the error.
|
|
170
|
+
*/
|
|
171
|
+
function normalizeErrorString(error) {
|
|
172
|
+
var _a, _b, _c, _d;
|
|
173
|
+
if (!error) {
|
|
174
|
+
return 'Unknown error';
|
|
175
|
+
}
|
|
176
|
+
if (typeof error === 'string') {
|
|
177
|
+
return error;
|
|
178
|
+
}
|
|
179
|
+
if (error instanceof Error) {
|
|
180
|
+
return error.message;
|
|
181
|
+
}
|
|
182
|
+
if (typeof error === 'object' && 'resourceType' in error) {
|
|
183
|
+
const outcome = error;
|
|
184
|
+
return (_d = (_c = (_b = (_a = outcome.issue) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.details) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'Unknown error';
|
|
185
|
+
}
|
|
186
|
+
return JSON.stringify(error);
|
|
187
|
+
}
|
|
149
188
|
|
|
150
|
-
export { OperationOutcomeError, accessDenied, allOk, assertOk, badRequest, created, getStatus, gone, isGone, isNotFound, isOk, notFound, notModified };
|
|
189
|
+
export { OperationOutcomeError, accessDenied, allOk, assertOk, badRequest, created, getStatus, gone, isGone, isNotFound, isOk, normalizeErrorString, notFound, notModified, tooManyRequests };
|
|
151
190
|
//# sourceMappingURL=outcomes.js.map
|
package/dist/esm/outcomes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcomes.js","sources":["../../src/outcomes.ts"],"sourcesContent":["import { OperationOutcome } from '@medplum/fhirtypes';\n\nconst OK_ID = 'ok';\nconst CREATED_ID = 'created';\nconst GONE_ID = 'gone';\nconst NOT_MODIFIED_ID = 'not-modified';\nconst NOT_FOUND_ID = 'not-found';\nconst
|
|
1
|
+
{"version":3,"file":"outcomes.js","sources":["../../src/outcomes.ts"],"sourcesContent":["import { OperationOutcome } from '@medplum/fhirtypes';\n\nconst OK_ID = 'ok';\nconst CREATED_ID = 'created';\nconst GONE_ID = 'gone';\nconst NOT_MODIFIED_ID = 'not-modified';\nconst NOT_FOUND_ID = 'not-found';\nconst ACCESS_DENIED_ID = 'access-denied';\nconst TOO_MANY_REQUESTS_ID = 'too-many-requests';\n\nexport const allOk: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: OK_ID,\n issue: [\n {\n severity: 'information',\n code: 'information',\n details: {\n text: 'All OK',\n },\n },\n ],\n};\n\nexport const created: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: CREATED_ID,\n issue: [\n {\n severity: 'information',\n code: 'information',\n details: {\n text: 'Created',\n },\n },\n ],\n};\n\nexport const notModified: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: NOT_MODIFIED_ID,\n issue: [\n {\n severity: 'information',\n code: 'information',\n details: {\n text: 'Not Modified',\n },\n },\n ],\n};\n\nexport const notFound: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: NOT_FOUND_ID,\n issue: [\n {\n severity: 'error',\n code: 'not-found',\n details: {\n text: 'Not found',\n },\n },\n ],\n};\n\nexport const gone: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: GONE_ID,\n issue: [\n {\n severity: 'error',\n code: 'gone',\n details: {\n text: 'Gone',\n },\n },\n ],\n};\n\nexport const accessDenied: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: ACCESS_DENIED_ID,\n issue: [\n {\n severity: 'error',\n code: 'forbidden',\n details: {\n text: 'Access Denied',\n },\n },\n ],\n};\n\nexport const tooManyRequests: OperationOutcome = {\n resourceType: 'OperationOutcome',\n id: TOO_MANY_REQUESTS_ID,\n issue: [\n {\n severity: 'error',\n code: 'throttled',\n details: {\n text: 'Too Many Requests',\n },\n },\n ],\n};\n\nexport function badRequest(details: string, expression?: string): OperationOutcome {\n return {\n resourceType: 'OperationOutcome',\n issue: [\n {\n severity: 'error',\n code: 'invalid',\n details: {\n text: details,\n },\n expression: expression ? [expression] : undefined,\n },\n ],\n };\n}\n\nexport function isOk(outcome: OperationOutcome): boolean {\n return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;\n}\n\nexport function isNotFound(outcome: OperationOutcome): boolean {\n return outcome.id === NOT_FOUND_ID;\n}\n\nexport function isGone(outcome: OperationOutcome): boolean {\n return outcome.id === GONE_ID;\n}\n\nexport function getStatus(outcome: OperationOutcome): number {\n if (outcome.id === OK_ID) {\n return 200;\n } else if (outcome.id === CREATED_ID) {\n return 201;\n } else if (outcome.id === NOT_MODIFIED_ID) {\n return 304;\n } else if (outcome.id === ACCESS_DENIED_ID) {\n return 403;\n } else if (outcome.id === NOT_FOUND_ID) {\n return 404;\n } else if (outcome.id === GONE_ID) {\n return 410;\n } else if (outcome.id === TOO_MANY_REQUESTS_ID) {\n return 429;\n } else {\n return 400;\n }\n}\n\n/**\n * Asserts that the operation completed successfully and that the resource is defined.\n * @param outcome The operation outcome.\n * @param resource The resource that may or may not have been returned.\n */\nexport function assertOk<T>(outcome: OperationOutcome, resource: T | undefined): asserts resource is T {\n if (!isOk(outcome) || resource === undefined) {\n throw new OperationOutcomeError(outcome);\n }\n}\n\nexport class OperationOutcomeError extends Error {\n readonly outcome: OperationOutcome;\n\n constructor(outcome: OperationOutcome) {\n super(outcome?.issue?.[0].details?.text);\n this.outcome = outcome;\n }\n}\n\n/**\n * Normalizes an error object into a displayable error string.\n * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.\n * @returns A display string for the error.\n */\nexport function normalizeErrorString(error: unknown): string {\n if (!error) {\n return 'Unknown error';\n }\n if (typeof error === 'string') {\n return error;\n }\n if (error instanceof Error) {\n return error.message;\n }\n if (typeof error === 'object' && 'resourceType' in error) {\n const outcome = error as OperationOutcome;\n return outcome.issue?.[0]?.details?.text ?? 'Unknown error';\n }\n return JSON.stringify(error);\n}\n"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AACzC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEpC,MAAA,KAAK,GAAqB;AACrC,IAAA,YAAY,EAAE,kBAAkB;AAChC,IAAA,EAAE,EAAE,KAAK;AACT,IAAA,KAAK,EAAE;AACL,QAAA;AACE,YAAA,QAAQ,EAAE,aAAa;AACvB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE;AACP,gBAAA,IAAI,EAAE,QAAQ;AACf,aAAA;AACF,SAAA;AACF,KAAA;EACD;AAEW,MAAA,OAAO,GAAqB;AACvC,IAAA,YAAY,EAAE,kBAAkB;AAChC,IAAA,EAAE,EAAE,UAAU;AACd,IAAA,KAAK,EAAE;AACL,QAAA;AACE,YAAA,QAAQ,EAAE,aAAa;AACvB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE;AACP,gBAAA,IAAI,EAAE,SAAS;AAChB,aAAA;AACF,SAAA;AACF,KAAA;EACD;AAEW,MAAA,WAAW,GAAqB;AAC3C,IAAA,YAAY,EAAE,kBAAkB;AAChC,IAAA,E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ACd,KAAA;IACD,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,OAAO,KAAK,CAAC,OAAO,CAAC;AACtB,KAAA;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,IAAI,KAAK,EAAE;QACxD,MAAM,OAAO,GAAG,KAAyB,CAAC;AAC1C,QAAA,OAAO,MAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,OAAO,CAAC,KAAK,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAG,CAAC,CAAC,0CAAE,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,IAAI,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,eAAe,CAAC;AAC7D,KAAA;AACD,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medplum/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.28",
|
|
4
4
|
"description": "Medplum TS/JS Library",
|
|
5
5
|
"author": "Medplum <hello@medplum.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"test": "jest"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@medplum/definitions": "0.9.
|
|
21
|
-
"@medplum/fhirtypes": "0.9.
|
|
20
|
+
"@medplum/definitions": "0.9.28",
|
|
21
|
+
"@medplum/fhirtypes": "0.9.28"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"pdfmake": "0.2.5"
|