candidhealth 0.24.0-2a6d412 → 0.24.1
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/Client.d.ts +3 -0
- package/README.md +134 -6
- package/api/resources/auth/client/Client.d.ts +3 -0
- package/api/resources/auth/resources/v2/client/Client.d.ts +4 -1
- package/api/resources/auth/resources/v2/client/Client.js +6 -7
- package/api/resources/billingNotes/client/Client.d.ts +3 -0
- package/api/resources/billingNotes/resources/v2/client/Client.d.ts +4 -1
- package/api/resources/billingNotes/resources/v2/client/Client.js +5 -4
- package/api/resources/contracts/client/Client.d.ts +3 -0
- package/api/resources/contracts/resources/v2/client/Client.d.ts +8 -5
- package/api/resources/contracts/resources/v2/client/Client.js +27 -26
- package/api/resources/eligibility/client/Client.d.ts +3 -0
- package/api/resources/eligibility/resources/v2/client/Client.d.ts +6 -3
- package/api/resources/eligibility/resources/v2/client/Client.js +12 -9
- package/api/resources/encounters/client/Client.d.ts +3 -0
- package/api/resources/encounters/resources/v4/client/Client.d.ts +7 -19
- package/api/resources/encounters/resources/v4/client/Client.js +22 -37
- package/api/resources/encounters/resources/v4/client/requests/EncounterCreate.d.ts +0 -21
- package/api/resources/encounters/resources/v4/types/Encounter.d.ts +0 -1
- package/api/resources/expectedNetworkStatus/client/Client.d.ts +3 -0
- package/api/resources/expectedNetworkStatus/resources/v1/client/Client.d.ts +4 -1
- package/api/resources/expectedNetworkStatus/resources/v1/client/Client.js +5 -4
- package/api/resources/expectedNetworkStatus/resources/v2/client/Client.d.ts +5 -2
- package/api/resources/expectedNetworkStatus/resources/v2/client/Client.js +13 -11
- package/api/resources/exports/client/Client.d.ts +3 -0
- package/api/resources/exports/resources/v3/client/Client.d.ts +4 -1
- package/api/resources/exports/resources/v3/client/Client.js +5 -4
- package/api/resources/externalPaymentAccountConfig/client/Client.d.ts +3 -0
- package/api/resources/externalPaymentAccountConfig/resources/v1/client/Client.d.ts +4 -1
- package/api/resources/externalPaymentAccountConfig/resources/v1/client/Client.js +4 -3
- package/api/resources/feeSchedules/client/Client.d.ts +3 -0
- package/api/resources/feeSchedules/resources/v3/client/Client.d.ts +13 -10
- package/api/resources/feeSchedules/resources/v3/client/Client.js +52 -44
- package/api/resources/guarantor/client/Client.d.ts +3 -0
- package/api/resources/guarantor/resources/v1/client/Client.d.ts +6 -3
- package/api/resources/guarantor/resources/v1/client/Client.js +18 -19
- package/api/resources/importInvoice/client/Client.d.ts +3 -0
- package/api/resources/importInvoice/resources/v1/client/Client.d.ts +7 -4
- package/api/resources/importInvoice/resources/v1/client/Client.js +22 -18
- package/api/resources/insuranceAdjudications/client/Client.d.ts +3 -0
- package/api/resources/insuranceAdjudications/resources/v1/client/Client.d.ts +6 -3
- package/api/resources/insuranceAdjudications/resources/v1/client/Client.js +15 -12
- package/api/resources/insurancePayments/client/Client.d.ts +3 -0
- package/api/resources/insurancePayments/resources/v1/client/Client.d.ts +8 -5
- package/api/resources/insurancePayments/resources/v1/client/Client.js +29 -24
- package/api/resources/insuranceRefunds/client/Client.d.ts +3 -0
- package/api/resources/insuranceRefunds/resources/v1/client/Client.d.ts +8 -5
- package/api/resources/insuranceRefunds/resources/v1/client/Client.js +29 -24
- package/api/resources/organizationProviders/client/Client.d.ts +3 -0
- package/api/resources/organizationProviders/resources/v3/client/Client.d.ts +7 -4
- package/api/resources/organizationProviders/resources/v3/client/Client.js +23 -19
- package/api/resources/organizationServiceFacilities/client/Client.d.ts +3 -0
- package/api/resources/organizationServiceFacilities/resources/v2/client/Client.d.ts +8 -5
- package/api/resources/organizationServiceFacilities/resources/v2/client/Client.js +32 -23
- package/api/resources/patientPayments/client/Client.d.ts +3 -0
- package/api/resources/patientPayments/resources/v4/client/Client.d.ts +8 -5
- package/api/resources/patientPayments/resources/v4/client/Client.js +29 -24
- package/api/resources/patientRefunds/client/Client.d.ts +3 -0
- package/api/resources/patientRefunds/resources/v1/client/Client.d.ts +8 -5
- package/api/resources/patientRefunds/resources/v1/client/Client.js +29 -24
- package/api/resources/payers/client/Client.d.ts +3 -0
- package/api/resources/payers/resources/v3/client/Client.d.ts +5 -2
- package/api/resources/payers/resources/v3/client/Client.js +9 -7
- package/api/resources/preEncounter/client/Client.d.ts +3 -0
- package/api/resources/preEncounter/resources/coverages/client/Client.d.ts +3 -0
- package/api/resources/preEncounter/resources/coverages/resources/v1/client/Client.d.ts +3 -0
- package/api/resources/preEncounter/resources/coverages/resources/v1/resources/coverages/client/Client.d.ts +9 -6
- package/api/resources/preEncounter/resources/coverages/resources/v1/resources/coverages/client/Client.js +31 -25
- package/api/resources/preEncounter/resources/patients/client/Client.d.ts +3 -0
- package/api/resources/preEncounter/resources/patients/resources/v1/client/Client.d.ts +3 -0
- package/api/resources/preEncounter/resources/patients/resources/v1/resources/patients/client/Client.d.ts +10 -7
- package/api/resources/preEncounter/resources/patients/resources/v1/resources/patients/client/Client.js +38 -31
- package/api/resources/serviceFacility/client/Client.d.ts +4 -1
- package/api/resources/serviceFacility/client/Client.js +6 -7
- package/api/resources/tasks/client/Client.d.ts +3 -0
- package/api/resources/tasks/resources/v3/client/Client.d.ts +8 -5
- package/api/resources/tasks/resources/v3/client/Client.js +28 -23
- package/api/resources/writeOffs/client/Client.d.ts +3 -0
- package/api/resources/writeOffs/resources/v1/client/Client.d.ts +7 -4
- package/api/resources/writeOffs/resources/v1/client/Client.js +19 -15
- package/core/fetcher/Fetcher.d.ts +3 -0
- package/core/fetcher/Fetcher.js +22 -153
- package/core/fetcher/createRequestUrl.d.ts +1 -0
- package/core/fetcher/createRequestUrl.js +13 -0
- package/core/fetcher/getFetchFn.d.ts +4 -0
- package/core/fetcher/getFetchFn.js +59 -0
- package/core/fetcher/getRequestBody.d.ts +7 -0
- package/core/fetcher/getRequestBody.js +23 -0
- package/core/fetcher/getResponseBody.d.ts +1 -0
- package/core/fetcher/getResponseBody.js +48 -0
- package/core/fetcher/makeRequest.d.ts +1 -0
- package/core/fetcher/makeRequest.js +42 -0
- package/core/fetcher/requestWithRetries.d.ts +1 -0
- package/core/fetcher/requestWithRetries.js +32 -0
- package/core/fetcher/signals.d.ts +12 -0
- package/core/fetcher/signals.js +37 -0
- package/core/runtime/runtime.d.ts +2 -1
- package/core/runtime/runtime.js +12 -1
- package/core/schemas/Schema.d.ts +7 -4
- package/core/schemas/builders/lazy/lazy.d.ts +2 -2
- package/core/schemas/builders/lazy/lazy.js +8 -19
- package/core/schemas/builders/lazy/lazyObject.js +1 -10
- package/core/schemas/builders/list/list.js +31 -44
- package/core/schemas/builders/object/object.js +90 -111
- package/core/schemas/builders/object/types.d.ts +2 -2
- package/core/schemas/builders/object-like/getObjectLikeUtils.js +3 -12
- package/core/schemas/builders/record/record.js +49 -60
- package/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +2 -2
- package/core/schemas/builders/schema-utils/getSchemaUtils.js +18 -21
- package/core/schemas/builders/set/set.js +6 -15
- package/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +21 -32
- package/core/schemas/builders/union/union.js +51 -62
- package/core/schemas/utils/maybeSkipValidation.js +3 -12
- package/dist/Client.d.ts +3 -0
- package/dist/api/resources/auth/client/Client.d.ts +3 -0
- package/dist/api/resources/auth/resources/v2/client/Client.d.ts +4 -1
- package/dist/api/resources/auth/resources/v2/client/Client.js +6 -7
- package/dist/api/resources/billingNotes/client/Client.d.ts +3 -0
- package/dist/api/resources/billingNotes/resources/v2/client/Client.d.ts +4 -1
- package/dist/api/resources/billingNotes/resources/v2/client/Client.js +5 -4
- package/dist/api/resources/contracts/client/Client.d.ts +3 -0
- package/dist/api/resources/contracts/resources/v2/client/Client.d.ts +8 -5
- package/dist/api/resources/contracts/resources/v2/client/Client.js +27 -26
- package/dist/api/resources/eligibility/client/Client.d.ts +3 -0
- package/dist/api/resources/eligibility/resources/v2/client/Client.d.ts +6 -3
- package/dist/api/resources/eligibility/resources/v2/client/Client.js +12 -9
- package/dist/api/resources/encounters/client/Client.d.ts +3 -0
- package/dist/api/resources/encounters/resources/v4/client/Client.d.ts +7 -19
- package/dist/api/resources/encounters/resources/v4/client/Client.js +22 -37
- package/dist/api/resources/encounters/resources/v4/client/requests/EncounterCreate.d.ts +0 -21
- package/dist/api/resources/encounters/resources/v4/types/Encounter.d.ts +0 -1
- package/dist/api/resources/expectedNetworkStatus/client/Client.d.ts +3 -0
- package/dist/api/resources/expectedNetworkStatus/resources/v1/client/Client.d.ts +4 -1
- package/dist/api/resources/expectedNetworkStatus/resources/v1/client/Client.js +5 -4
- package/dist/api/resources/expectedNetworkStatus/resources/v2/client/Client.d.ts +5 -2
- package/dist/api/resources/expectedNetworkStatus/resources/v2/client/Client.js +13 -11
- package/dist/api/resources/exports/client/Client.d.ts +3 -0
- package/dist/api/resources/exports/resources/v3/client/Client.d.ts +4 -1
- package/dist/api/resources/exports/resources/v3/client/Client.js +5 -4
- package/dist/api/resources/externalPaymentAccountConfig/client/Client.d.ts +3 -0
- package/dist/api/resources/externalPaymentAccountConfig/resources/v1/client/Client.d.ts +4 -1
- package/dist/api/resources/externalPaymentAccountConfig/resources/v1/client/Client.js +4 -3
- package/dist/api/resources/feeSchedules/client/Client.d.ts +3 -0
- package/dist/api/resources/feeSchedules/resources/v3/client/Client.d.ts +13 -10
- package/dist/api/resources/feeSchedules/resources/v3/client/Client.js +52 -44
- package/dist/api/resources/guarantor/client/Client.d.ts +3 -0
- package/dist/api/resources/guarantor/resources/v1/client/Client.d.ts +6 -3
- package/dist/api/resources/guarantor/resources/v1/client/Client.js +18 -19
- package/dist/api/resources/importInvoice/client/Client.d.ts +3 -0
- package/dist/api/resources/importInvoice/resources/v1/client/Client.d.ts +7 -4
- package/dist/api/resources/importInvoice/resources/v1/client/Client.js +22 -18
- package/dist/api/resources/insuranceAdjudications/client/Client.d.ts +3 -0
- package/dist/api/resources/insuranceAdjudications/resources/v1/client/Client.d.ts +6 -3
- package/dist/api/resources/insuranceAdjudications/resources/v1/client/Client.js +15 -12
- package/dist/api/resources/insurancePayments/client/Client.d.ts +3 -0
- package/dist/api/resources/insurancePayments/resources/v1/client/Client.d.ts +8 -5
- package/dist/api/resources/insurancePayments/resources/v1/client/Client.js +29 -24
- package/dist/api/resources/insuranceRefunds/client/Client.d.ts +3 -0
- package/dist/api/resources/insuranceRefunds/resources/v1/client/Client.d.ts +8 -5
- package/dist/api/resources/insuranceRefunds/resources/v1/client/Client.js +29 -24
- package/dist/api/resources/organizationProviders/client/Client.d.ts +3 -0
- package/dist/api/resources/organizationProviders/resources/v3/client/Client.d.ts +7 -4
- package/dist/api/resources/organizationProviders/resources/v3/client/Client.js +23 -19
- package/dist/api/resources/organizationServiceFacilities/client/Client.d.ts +3 -0
- package/dist/api/resources/organizationServiceFacilities/resources/v2/client/Client.d.ts +8 -5
- package/dist/api/resources/organizationServiceFacilities/resources/v2/client/Client.js +32 -23
- package/dist/api/resources/patientPayments/client/Client.d.ts +3 -0
- package/dist/api/resources/patientPayments/resources/v4/client/Client.d.ts +8 -5
- package/dist/api/resources/patientPayments/resources/v4/client/Client.js +29 -24
- package/dist/api/resources/patientRefunds/client/Client.d.ts +3 -0
- package/dist/api/resources/patientRefunds/resources/v1/client/Client.d.ts +8 -5
- package/dist/api/resources/patientRefunds/resources/v1/client/Client.js +29 -24
- package/dist/api/resources/payers/client/Client.d.ts +3 -0
- package/dist/api/resources/payers/resources/v3/client/Client.d.ts +5 -2
- package/dist/api/resources/payers/resources/v3/client/Client.js +9 -7
- package/dist/api/resources/preEncounter/client/Client.d.ts +3 -0
- package/dist/api/resources/preEncounter/resources/coverages/client/Client.d.ts +3 -0
- package/dist/api/resources/preEncounter/resources/coverages/resources/v1/client/Client.d.ts +3 -0
- package/dist/api/resources/preEncounter/resources/coverages/resources/v1/resources/coverages/client/Client.d.ts +9 -6
- package/dist/api/resources/preEncounter/resources/coverages/resources/v1/resources/coverages/client/Client.js +31 -25
- package/dist/api/resources/preEncounter/resources/patients/client/Client.d.ts +3 -0
- package/dist/api/resources/preEncounter/resources/patients/resources/v1/client/Client.d.ts +3 -0
- package/dist/api/resources/preEncounter/resources/patients/resources/v1/resources/patients/client/Client.d.ts +10 -7
- package/dist/api/resources/preEncounter/resources/patients/resources/v1/resources/patients/client/Client.js +38 -31
- package/dist/api/resources/serviceFacility/client/Client.d.ts +4 -1
- package/dist/api/resources/serviceFacility/client/Client.js +6 -7
- package/dist/api/resources/tasks/client/Client.d.ts +3 -0
- package/dist/api/resources/tasks/resources/v3/client/Client.d.ts +8 -5
- package/dist/api/resources/tasks/resources/v3/client/Client.js +28 -23
- package/dist/api/resources/writeOffs/client/Client.d.ts +3 -0
- package/dist/api/resources/writeOffs/resources/v1/client/Client.d.ts +7 -4
- package/dist/api/resources/writeOffs/resources/v1/client/Client.js +19 -15
- package/dist/core/fetcher/Fetcher.d.ts +3 -0
- package/dist/core/fetcher/Fetcher.js +22 -153
- package/dist/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/core/fetcher/createRequestUrl.js +13 -0
- package/dist/core/fetcher/getFetchFn.d.ts +4 -0
- package/dist/core/fetcher/getFetchFn.js +59 -0
- package/dist/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/core/fetcher/getRequestBody.js +23 -0
- package/dist/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/core/fetcher/getResponseBody.js +48 -0
- package/dist/core/fetcher/makeRequest.d.ts +1 -0
- package/dist/core/fetcher/makeRequest.js +42 -0
- package/dist/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/core/fetcher/requestWithRetries.js +32 -0
- package/dist/core/fetcher/signals.d.ts +12 -0
- package/dist/core/fetcher/signals.js +37 -0
- package/dist/core/runtime/runtime.d.ts +2 -1
- package/dist/core/runtime/runtime.js +12 -1
- package/dist/core/schemas/Schema.d.ts +7 -4
- package/dist/core/schemas/builders/lazy/lazy.d.ts +2 -2
- package/dist/core/schemas/builders/lazy/lazy.js +8 -19
- package/dist/core/schemas/builders/lazy/lazyObject.js +1 -10
- package/dist/core/schemas/builders/list/list.js +31 -44
- package/dist/core/schemas/builders/object/object.js +90 -111
- package/dist/core/schemas/builders/object/types.d.ts +2 -2
- package/dist/core/schemas/builders/object-like/getObjectLikeUtils.js +3 -12
- package/dist/core/schemas/builders/record/record.js +49 -60
- package/dist/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +2 -2
- package/dist/core/schemas/builders/schema-utils/getSchemaUtils.js +18 -21
- package/dist/core/schemas/builders/set/set.js +6 -15
- package/dist/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +21 -32
- package/dist/core/schemas/builders/union/union.js +51 -62
- package/dist/core/schemas/utils/maybeSkipValidation.js +3 -12
- package/dist/serialization/resources/encounters/resources/v4/client/requests/EncounterCreate.d.ts +0 -2
- package/dist/serialization/resources/encounters/resources/v4/client/requests/EncounterCreate.js +0 -2
- package/dist/serialization/resources/encounters/resources/v4/types/Encounter.d.ts +0 -1
- package/dist/serialization/resources/encounters/resources/v4/types/Encounter.js +0 -1
- package/package.json +7 -2
- package/reference.md +7177 -0
- package/serialization/resources/encounters/resources/v4/client/requests/EncounterCreate.d.ts +0 -2
- package/serialization/resources/encounters/resources/v4/client/requests/EncounterCreate.js +0 -2
- package/serialization/resources/encounters/resources/v4/types/Encounter.d.ts +0 -1
- package/serialization/resources/encounters/resources/v4/types/Encounter.js +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.requestWithRetries = void 0;
|
|
13
|
+
const INITIAL_RETRY_DELAY = 1;
|
|
14
|
+
const MAX_RETRY_DELAY = 60;
|
|
15
|
+
const DEFAULT_MAX_RETRIES = 2;
|
|
16
|
+
function requestWithRetries(requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
let response = yield requestFn();
|
|
19
|
+
for (let i = 0; i < maxRetries; ++i) {
|
|
20
|
+
if ([408, 409, 429].includes(response.status) || response.status >= 500) {
|
|
21
|
+
const delay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
|
|
22
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
23
|
+
response = yield requestFn();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return response;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.requestWithRetries = requestWithRetries;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function getTimeoutSignal(timeoutMs: number): {
|
|
3
|
+
signal: AbortSignal;
|
|
4
|
+
abortId: NodeJS.Timeout;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns an abort signal that is getting aborted when
|
|
8
|
+
* at least one of the specified abort signals is aborted.
|
|
9
|
+
*
|
|
10
|
+
* Requires at least node.js 18.
|
|
11
|
+
*/
|
|
12
|
+
export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.anySignal = exports.getTimeoutSignal = void 0;
|
|
4
|
+
const TIMEOUT = "timeout";
|
|
5
|
+
function getTimeoutSignal(timeoutMs) {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
|
|
8
|
+
return { signal: controller.signal, abortId };
|
|
9
|
+
}
|
|
10
|
+
exports.getTimeoutSignal = getTimeoutSignal;
|
|
11
|
+
/**
|
|
12
|
+
* Returns an abort signal that is getting aborted when
|
|
13
|
+
* at least one of the specified abort signals is aborted.
|
|
14
|
+
*
|
|
15
|
+
* Requires at least node.js 18.
|
|
16
|
+
*/
|
|
17
|
+
function anySignal(...args) {
|
|
18
|
+
// Allowing signals to be passed either as array
|
|
19
|
+
// of signals or as multiple arguments.
|
|
20
|
+
const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
for (const signal of signals) {
|
|
23
|
+
if (signal.aborted) {
|
|
24
|
+
// Exiting early if one of the signals
|
|
25
|
+
// is already aborted.
|
|
26
|
+
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
// Listening for signals and removing the listeners
|
|
30
|
+
// when at least one symbol is aborted.
|
|
31
|
+
signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
|
|
32
|
+
signal: controller.signal,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return controller.signal;
|
|
36
|
+
}
|
|
37
|
+
exports.anySignal = anySignal;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare const RUNTIME: Runtime;
|
|
5
5
|
export interface Runtime {
|
|
6
|
-
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown";
|
|
6
|
+
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd";
|
|
7
7
|
version?: string;
|
|
8
|
+
parsedVersion?: number;
|
|
8
9
|
}
|
package/core/runtime/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b, _c, _d;
|
|
2
|
+
var _a, _b, _c, _d, _e;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.RUNTIME = void 0;
|
|
5
5
|
/**
|
|
@@ -37,6 +37,11 @@ const isNode = typeof process !== "undefined" &&
|
|
|
37
37
|
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
38
38
|
*/
|
|
39
39
|
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
40
|
+
/**
|
|
41
|
+
* A constant that indicates whether the environment the code is running is Cloudflare.
|
|
42
|
+
* https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent
|
|
43
|
+
*/
|
|
44
|
+
const isCloudflare = typeof globalThis !== "undefined" && ((_e = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _e === void 0 ? void 0 : _e.userAgent) === "Cloudflare-Workers";
|
|
40
45
|
/**
|
|
41
46
|
* A constant that indicates which environment and version the SDK is running in.
|
|
42
47
|
*/
|
|
@@ -48,6 +53,11 @@ function evaluateRuntime() {
|
|
|
48
53
|
version: window.navigator.userAgent,
|
|
49
54
|
};
|
|
50
55
|
}
|
|
56
|
+
if (isCloudflare) {
|
|
57
|
+
return {
|
|
58
|
+
type: "workerd",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
51
61
|
if (isWebWorker) {
|
|
52
62
|
return {
|
|
53
63
|
type: "web-worker",
|
|
@@ -69,6 +79,7 @@ function evaluateRuntime() {
|
|
|
69
79
|
return {
|
|
70
80
|
type: "node",
|
|
71
81
|
version: process.versions.node,
|
|
82
|
+
parsedVersion: Number(process.versions.node.split(".")[0]),
|
|
72
83
|
};
|
|
73
84
|
}
|
|
74
85
|
if (isReactNative) {
|
package/core/schemas/Schema.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { SchemaUtils } from "./builders";
|
|
2
|
-
import { MaybePromise } from "./utils/MaybePromise";
|
|
3
2
|
export declare type Schema<Raw = unknown, Parsed = unknown> = BaseSchema<Raw, Parsed> & SchemaUtils<Raw, Parsed>;
|
|
4
3
|
export declare type inferRaw<S extends Schema> = S extends Schema<infer Raw, any> ? Raw : never;
|
|
5
4
|
export declare type inferParsed<S extends Schema> = S extends Schema<any, infer Parsed> ? Parsed : never;
|
|
6
5
|
export interface BaseSchema<Raw, Parsed> {
|
|
7
|
-
parse: (raw: unknown, opts?: SchemaOptions) =>
|
|
8
|
-
json: (parsed: unknown, opts?: SchemaOptions) =>
|
|
9
|
-
getType: () => SchemaType |
|
|
6
|
+
parse: (raw: unknown, opts?: SchemaOptions) => MaybeValid<Parsed>;
|
|
7
|
+
json: (parsed: unknown, opts?: SchemaOptions) => MaybeValid<Raw>;
|
|
8
|
+
getType: () => SchemaType | SchemaType;
|
|
10
9
|
}
|
|
11
10
|
export declare const SchemaType: {
|
|
12
11
|
readonly DATE: "date";
|
|
@@ -78,4 +77,8 @@ export interface SchemaOptions {
|
|
|
78
77
|
* helpful for zurg's internal debug logging.
|
|
79
78
|
*/
|
|
80
79
|
breadcrumbsPrefix?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* whether to send 'null' for optional properties explicitly set to 'undefined'.
|
|
82
|
+
*/
|
|
83
|
+
omitUndefined?: boolean;
|
|
81
84
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseSchema, Schema } from "../../Schema";
|
|
2
|
-
export declare type SchemaGetter<SchemaType extends Schema<any, any>> = () => SchemaType
|
|
2
|
+
export declare type SchemaGetter<SchemaType extends Schema<any, any>> = () => SchemaType;
|
|
3
3
|
export declare function lazy<Raw, Parsed>(getter: SchemaGetter<Schema<Raw, Parsed>>): Schema<Raw, Parsed>;
|
|
4
4
|
export declare function constructLazyBaseSchema<Raw, Parsed>(getter: SchemaGetter<Schema<Raw, Parsed>>): BaseSchema<Raw, Parsed>;
|
|
5
|
-
export declare function getMemoizedSchema<SchemaType extends Schema<any, any>>(getter: SchemaGetter<SchemaType>):
|
|
5
|
+
export declare function getMemoizedSchema<SchemaType extends Schema<any, any>>(getter: SchemaGetter<SchemaType>): SchemaType;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getMemoizedSchema = exports.constructLazyBaseSchema = exports.lazy = void 0;
|
|
13
4
|
const schema_utils_1 = require("../schema-utils");
|
|
@@ -18,19 +9,17 @@ function lazy(getter) {
|
|
|
18
9
|
exports.lazy = lazy;
|
|
19
10
|
function constructLazyBaseSchema(getter) {
|
|
20
11
|
return {
|
|
21
|
-
parse: (raw, opts) =>
|
|
22
|
-
json: (parsed, opts) =>
|
|
23
|
-
getType: () =>
|
|
12
|
+
parse: (raw, opts) => getMemoizedSchema(getter).parse(raw, opts),
|
|
13
|
+
json: (parsed, opts) => getMemoizedSchema(getter).json(parsed, opts),
|
|
14
|
+
getType: () => getMemoizedSchema(getter).getType(),
|
|
24
15
|
};
|
|
25
16
|
}
|
|
26
17
|
exports.constructLazyBaseSchema = constructLazyBaseSchema;
|
|
27
18
|
function getMemoizedSchema(getter) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return castedGetter.__zurg_memoized;
|
|
34
|
-
});
|
|
19
|
+
const castedGetter = getter;
|
|
20
|
+
if (castedGetter.__zurg_memoized == null) {
|
|
21
|
+
castedGetter.__zurg_memoized = getter();
|
|
22
|
+
}
|
|
23
|
+
return castedGetter.__zurg_memoized;
|
|
35
24
|
}
|
|
36
25
|
exports.getMemoizedSchema = getMemoizedSchema;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.lazyObject = void 0;
|
|
13
4
|
const object_1 = require("../object");
|
|
@@ -15,7 +6,7 @@ const object_like_1 = require("../object-like");
|
|
|
15
6
|
const schema_utils_1 = require("../schema-utils");
|
|
16
7
|
const lazy_1 = require("./lazy");
|
|
17
8
|
function lazyObject(getter) {
|
|
18
|
-
const baseSchema = Object.assign(Object.assign({}, (0, lazy_1.constructLazyBaseSchema)(getter)), { _getRawProperties: () =>
|
|
9
|
+
const baseSchema = Object.assign(Object.assign({}, (0, lazy_1.constructLazyBaseSchema)(getter)), { _getRawProperties: () => (0, lazy_1.getMemoizedSchema)(getter)._getRawProperties(), _getParsedProperties: () => (0, lazy_1.getMemoizedSchema)(getter)._getParsedProperties() });
|
|
19
10
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseSchema), (0, schema_utils_1.getSchemaUtils)(baseSchema)), (0, object_like_1.getObjectLikeUtils)(baseSchema)), (0, object_1.getObjectUtils)(baseSchema));
|
|
20
11
|
}
|
|
21
12
|
exports.lazyObject = lazyObject;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.list = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -16,11 +7,9 @@ const maybeSkipValidation_1 = require("../../utils/maybeSkipValidation");
|
|
|
16
7
|
const schema_utils_1 = require("../schema-utils");
|
|
17
8
|
function list(schema) {
|
|
18
9
|
const baseSchema = {
|
|
19
|
-
parse: (raw, opts) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return schema.parse(item, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `[${index}]`] }));
|
|
23
|
-
});
|
|
10
|
+
parse: (raw, opts) => validateAndTransformArray(raw, (item, index) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return schema.parse(item, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), `[${index}]`] }));
|
|
24
13
|
}),
|
|
25
14
|
json: (parsed, opts) => validateAndTransformArray(parsed, (item, index) => {
|
|
26
15
|
var _a;
|
|
@@ -32,37 +21,35 @@ function list(schema) {
|
|
|
32
21
|
}
|
|
33
22
|
exports.list = list;
|
|
34
23
|
function validateAndTransformArray(value, transformItem) {
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
if (!Array.isArray(value)) {
|
|
25
|
+
return {
|
|
26
|
+
ok: false,
|
|
27
|
+
errors: [
|
|
28
|
+
{
|
|
29
|
+
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "list"),
|
|
30
|
+
path: [],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const maybeValidItems = value.map((item, index) => transformItem(item, index));
|
|
36
|
+
return maybeValidItems.reduce((acc, item) => {
|
|
37
|
+
if (acc.ok && item.ok) {
|
|
37
38
|
return {
|
|
38
|
-
ok:
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "list"),
|
|
42
|
-
path: [],
|
|
43
|
-
},
|
|
44
|
-
],
|
|
39
|
+
ok: true,
|
|
40
|
+
value: [...acc.value, item.value],
|
|
45
41
|
};
|
|
46
42
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!item.ok) {
|
|
60
|
-
errors.push(...item.errors);
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
ok: false,
|
|
64
|
-
errors,
|
|
65
|
-
};
|
|
66
|
-
}, { ok: true, value: [] });
|
|
67
|
-
});
|
|
43
|
+
const errors = [];
|
|
44
|
+
if (!acc.ok) {
|
|
45
|
+
errors.push(...acc.errors);
|
|
46
|
+
}
|
|
47
|
+
if (!item.ok) {
|
|
48
|
+
errors.push(...item.errors);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
errors,
|
|
53
|
+
};
|
|
54
|
+
}, { ok: true, value: [] });
|
|
68
55
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getObjectUtils = exports.object = void 0;
|
|
13
4
|
const Schema_1 = require("../../Schema");
|
|
@@ -23,9 +14,9 @@ const schema_utils_1 = require("../schema-utils");
|
|
|
23
14
|
const property_1 = require("./property");
|
|
24
15
|
function object(schemas) {
|
|
25
16
|
const baseSchema = {
|
|
26
|
-
_getRawProperties: () =>
|
|
27
|
-
_getParsedProperties: () =>
|
|
28
|
-
parse: (raw, opts) =>
|
|
17
|
+
_getRawProperties: () => Object.entries(schemas).map(([parsedKey, propertySchema]) => (0, property_1.isProperty)(propertySchema) ? propertySchema.rawKey : parsedKey),
|
|
18
|
+
_getParsedProperties: () => (0, keys_1.keys)(schemas),
|
|
19
|
+
parse: (raw, opts) => {
|
|
29
20
|
const rawKeyToProperty = {};
|
|
30
21
|
const requiredKeys = [];
|
|
31
22
|
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_1.entries)(schemas)) {
|
|
@@ -62,9 +53,10 @@ function object(schemas) {
|
|
|
62
53
|
unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
|
|
63
54
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
64
55
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
56
|
+
omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
|
|
65
57
|
});
|
|
66
|
-
}
|
|
67
|
-
json: (parsed, opts) =>
|
|
58
|
+
},
|
|
59
|
+
json: (parsed, opts) => {
|
|
68
60
|
const requiredKeys = [];
|
|
69
61
|
for (const [parsedKey, schemaOrObjectProperty] of (0, entries_1.entries)(schemas)) {
|
|
70
62
|
const valueSchema = (0, property_1.isProperty)(schemaOrObjectProperty)
|
|
@@ -105,110 +97,99 @@ function object(schemas) {
|
|
|
105
97
|
unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
|
|
106
98
|
skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
|
|
107
99
|
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
100
|
+
omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
|
|
108
101
|
});
|
|
109
|
-
}
|
|
102
|
+
},
|
|
110
103
|
getType: () => Schema_1.SchemaType.OBJECT,
|
|
111
104
|
};
|
|
112
105
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, (0, maybeSkipValidation_1.maybeSkipValidation)(baseSchema)), (0, schema_utils_1.getSchemaUtils)(baseSchema)), (0, object_like_1.getObjectLikeUtils)(baseSchema)), getObjectUtils(baseSchema));
|
|
113
106
|
}
|
|
114
107
|
exports.object = object;
|
|
115
108
|
function validateAndTransformObject({ value, requiredKeys, getProperty, unrecognizedObjectKeys = "fail", skipValidation = false, breadcrumbsPrefix = [], }) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
transformed[property.transformedKey] = value.value;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
transformed[preTransformedKey] = preTransformedItemValue;
|
|
141
|
-
errors.push(...value.errors);
|
|
142
|
-
}
|
|
109
|
+
if (!(0, isPlainObject_1.isPlainObject)(value)) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
errors: [
|
|
113
|
+
{
|
|
114
|
+
path: breadcrumbsPrefix,
|
|
115
|
+
message: (0, getErrorMessageForIncorrectType_1.getErrorMessageForIncorrectType)(value, "object"),
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const missingRequiredKeys = new Set(requiredKeys);
|
|
121
|
+
const errors = [];
|
|
122
|
+
const transformed = {};
|
|
123
|
+
for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
|
|
124
|
+
const property = getProperty(preTransformedKey);
|
|
125
|
+
if (property != null) {
|
|
126
|
+
missingRequiredKeys.delete(preTransformedKey);
|
|
127
|
+
const value = property.transform(preTransformedItemValue);
|
|
128
|
+
if (value.ok) {
|
|
129
|
+
transformed[property.transformedKey] = value.value;
|
|
143
130
|
}
|
|
144
131
|
else {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
errors.push({
|
|
148
|
-
path: [...breadcrumbsPrefix, preTransformedKey],
|
|
149
|
-
message: `Unexpected key "${preTransformedKey}"`,
|
|
150
|
-
});
|
|
151
|
-
break;
|
|
152
|
-
case "strip":
|
|
153
|
-
break;
|
|
154
|
-
case "passthrough":
|
|
155
|
-
transformed[preTransformedKey] = preTransformedItemValue;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
132
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
133
|
+
errors.push(...value.errors);
|
|
158
134
|
}
|
|
159
135
|
}
|
|
160
|
-
errors.push(...requiredKeys
|
|
161
|
-
.filter((key) => missingRequiredKeys.has(key))
|
|
162
|
-
.map((key) => ({
|
|
163
|
-
path: breadcrumbsPrefix,
|
|
164
|
-
message: `Missing required key "${key}"`,
|
|
165
|
-
})));
|
|
166
|
-
if (errors.length === 0 || skipValidation) {
|
|
167
|
-
return {
|
|
168
|
-
ok: true,
|
|
169
|
-
value: transformed,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
136
|
else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
137
|
+
switch (unrecognizedObjectKeys) {
|
|
138
|
+
case "fail":
|
|
139
|
+
errors.push({
|
|
140
|
+
path: [...breadcrumbsPrefix, preTransformedKey],
|
|
141
|
+
message: `Unexpected key "${preTransformedKey}"`,
|
|
142
|
+
});
|
|
143
|
+
break;
|
|
144
|
+
case "strip":
|
|
145
|
+
break;
|
|
146
|
+
case "passthrough":
|
|
147
|
+
transformed[preTransformedKey] = preTransformedItemValue;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
177
150
|
}
|
|
178
|
-
}
|
|
151
|
+
}
|
|
152
|
+
errors.push(...requiredKeys
|
|
153
|
+
.filter((key) => missingRequiredKeys.has(key))
|
|
154
|
+
.map((key) => ({
|
|
155
|
+
path: breadcrumbsPrefix,
|
|
156
|
+
message: `Missing required key "${key}"`,
|
|
157
|
+
})));
|
|
158
|
+
if (errors.length === 0 || skipValidation) {
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
value: transformed,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return {
|
|
166
|
+
ok: false,
|
|
167
|
+
errors,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
179
170
|
}
|
|
180
171
|
function getObjectUtils(schema) {
|
|
181
172
|
return {
|
|
182
173
|
extend: (extension) => {
|
|
183
174
|
const baseSchema = {
|
|
184
|
-
_getParsedProperties: () =>
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
...(yield extension._getParsedProperties()),
|
|
188
|
-
];
|
|
189
|
-
}),
|
|
190
|
-
_getRawProperties: () => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
return [
|
|
192
|
-
...(yield schema._getRawProperties()),
|
|
193
|
-
...(yield extension._getRawProperties()),
|
|
194
|
-
];
|
|
195
|
-
}),
|
|
196
|
-
parse: (raw, opts) => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
_getParsedProperties: () => [...schema._getParsedProperties(), ...extension._getParsedProperties()],
|
|
176
|
+
_getRawProperties: () => [...schema._getRawProperties(), ...extension._getRawProperties()],
|
|
177
|
+
parse: (raw, opts) => {
|
|
197
178
|
return validateAndTransformExtendedObject({
|
|
198
|
-
extensionKeys:
|
|
179
|
+
extensionKeys: extension._getRawProperties(),
|
|
199
180
|
value: raw,
|
|
200
181
|
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
201
182
|
transformExtension: (rawExtension) => extension.parse(rawExtension, opts),
|
|
202
183
|
});
|
|
203
|
-
}
|
|
204
|
-
json: (parsed, opts) =>
|
|
184
|
+
},
|
|
185
|
+
json: (parsed, opts) => {
|
|
205
186
|
return validateAndTransformExtendedObject({
|
|
206
|
-
extensionKeys:
|
|
187
|
+
extensionKeys: extension._getParsedProperties(),
|
|
207
188
|
value: parsed,
|
|
208
189
|
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
209
190
|
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts),
|
|
210
191
|
});
|
|
211
|
-
}
|
|
192
|
+
},
|
|
212
193
|
getType: () => Schema_1.SchemaType.OBJECT,
|
|
213
194
|
};
|
|
214
195
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseSchema), (0, schema_utils_1.getSchemaUtils)(baseSchema)), (0, object_like_1.getObjectLikeUtils)(baseSchema)), getObjectUtils(baseSchema));
|
|
@@ -217,27 +198,25 @@ function getObjectUtils(schema) {
|
|
|
217
198
|
}
|
|
218
199
|
exports.getObjectUtils = getObjectUtils;
|
|
219
200
|
function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, transformExtension, }) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
});
|
|
201
|
+
const extensionPropertiesSet = new Set(extensionKeys);
|
|
202
|
+
const [extensionProperties, baseProperties] = (0, partition_1.partition)((0, keys_1.keys)(value), (key) => extensionPropertiesSet.has(key));
|
|
203
|
+
const transformedBase = transformBase((0, filterObject_1.filterObject)(value, baseProperties));
|
|
204
|
+
const transformedExtension = transformExtension((0, filterObject_1.filterObject)(value, extensionProperties));
|
|
205
|
+
if (transformedBase.ok && transformedExtension.ok) {
|
|
206
|
+
return {
|
|
207
|
+
ok: true,
|
|
208
|
+
value: Object.assign(Object.assign({}, transformedBase.value), transformedExtension.value),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return {
|
|
213
|
+
ok: false,
|
|
214
|
+
errors: [
|
|
215
|
+
...(transformedBase.ok ? [] : transformedBase.errors),
|
|
216
|
+
...(transformedExtension.ok ? [] : transformedExtension.errors),
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
241
220
|
}
|
|
242
221
|
function isSchemaRequired(schema) {
|
|
243
222
|
return !isSchemaOptional(schema);
|
|
@@ -5,8 +5,8 @@ import { SchemaUtils } from "../schema-utils";
|
|
|
5
5
|
import { Property } from "./property";
|
|
6
6
|
export declare type ObjectSchema<Raw, Parsed> = BaseObjectSchema<Raw, Parsed> & ObjectLikeUtils<Raw, Parsed> & ObjectUtils<Raw, Parsed> & SchemaUtils<Raw, Parsed>;
|
|
7
7
|
export interface BaseObjectSchema<Raw, Parsed> extends BaseSchema<Raw, Parsed> {
|
|
8
|
-
_getRawProperties: () =>
|
|
9
|
-
_getParsedProperties: () =>
|
|
8
|
+
_getRawProperties: () => (keyof Raw)[];
|
|
9
|
+
_getParsedProperties: () => (keyof Parsed)[];
|
|
10
10
|
}
|
|
11
11
|
export interface ObjectUtils<Raw, Parsed> {
|
|
12
12
|
extend: <RawExtension, ParsedExtension>(schemas: ObjectSchema<RawExtension, ParsedExtension>) => ObjectSchema<Raw & RawExtension, Parsed & ParsedExtension>;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.withParsedProperties = exports.getObjectLikeUtils = void 0;
|
|
13
4
|
const filterObject_1 = require("../../utils/filterObject");
|
|
@@ -25,8 +16,8 @@ exports.getObjectLikeUtils = getObjectLikeUtils;
|
|
|
25
16
|
*/
|
|
26
17
|
function withParsedProperties(objectLike, properties) {
|
|
27
18
|
const objectSchema = {
|
|
28
|
-
parse: (raw, opts) =>
|
|
29
|
-
const parsedObject =
|
|
19
|
+
parse: (raw, opts) => {
|
|
20
|
+
const parsedObject = objectLike.parse(raw, opts);
|
|
30
21
|
if (!parsedObject.ok) {
|
|
31
22
|
return parsedObject;
|
|
32
23
|
}
|
|
@@ -37,7 +28,7 @@ function withParsedProperties(objectLike, properties) {
|
|
|
37
28
|
ok: true,
|
|
38
29
|
value: Object.assign(Object.assign({}, parsedObject.value), additionalProperties),
|
|
39
30
|
};
|
|
40
|
-
}
|
|
31
|
+
},
|
|
41
32
|
json: (parsed, opts) => {
|
|
42
33
|
var _a;
|
|
43
34
|
if (!(0, isPlainObject_1.isPlainObject)(parsed)) {
|