@membranehq/sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +8370 -1268
- package/dist/bundle.js +2216 -2085
- package/dist/bundle.js.map +1 -1
- package/dist/dts/accessors/connections-accessors.d.ts +57 -1
- package/dist/dts/accessors/integrations-accessors.d.ts +57 -1
- package/dist/dts/api-client.d.ts +1 -0
- package/dist/dts/client.d.ts +1 -0
- package/dist/dts/data-schema/types.d.ts +4 -3
- package/dist/dts/entity-repository.d.ts +87 -20
- package/dist/dts/formulas/dataSchemaRef.d.ts +2 -2
- package/dist/dts/http-requests.d.ts +20 -6
- package/dist/dts/iframe.d.ts +12 -4
- package/dist/dts/index.d.ts +2 -1
- package/dist/dts/sse/index.d.ts +1 -0
- package/dist/dts/sse/workspace-elements.d.ts +9 -0
- package/dist/dts/workspace-elements/api/actions-api.d.ts +702 -40
- package/dist/dts/workspace-elements/api/connections-api.d.ts +702 -41
- package/dist/dts/workspace-elements/api/customers-api.d.ts +56 -13
- package/dist/dts/workspace-elements/api/data-sources-api.d.ts +834 -77
- package/dist/dts/workspace-elements/api/external-events-api.d.ts +440 -6
- package/dist/dts/workspace-elements/api/field-mappings-api.d.ts +586 -6
- package/dist/dts/workspace-elements/api/flow-runs-api.d.ts +1 -1
- package/dist/dts/workspace-elements/api/flows-api.d.ts +2417 -50
- package/dist/dts/workspace-elements/api/integrations-api.d.ts +253 -24
- package/dist/dts/workspace-elements/api/scenarios-api.d.ts +397 -34
- package/dist/dts/workspace-elements/api/screens-api.d.ts +2 -2
- package/dist/dts/workspace-elements/base/action-instances/types.d.ts +61 -14
- package/dist/dts/workspace-elements/base/action-run-log-records/types.d.ts +30 -7
- package/dist/dts/workspace-elements/base/actions/types.d.ts +60 -17
- package/dist/dts/workspace-elements/base/app-data-schema-instances/types.d.ts +42 -7
- package/dist/dts/workspace-elements/base/app-data-schemas/types.d.ts +35 -7
- package/dist/dts/workspace-elements/base/app-event-subscriptions/types.d.ts +78 -9
- package/dist/dts/workspace-elements/base/app-event-types/types.d.ts +70 -7
- package/dist/dts/workspace-elements/base/connections/types.d.ts +76 -20
- package/dist/dts/workspace-elements/base/connectors/types.d.ts +14 -2
- package/dist/dts/workspace-elements/base/customers/index.d.ts +26 -6
- package/dist/dts/workspace-elements/base/data-collections/schemas.d.ts +75 -74
- package/dist/dts/workspace-elements/base/data-link-table-instances/types.d.ts +61 -11
- package/dist/dts/workspace-elements/base/data-link-tables/types.d.ts +26 -4
- package/dist/dts/workspace-elements/base/data-source-instances/types.d.ts +1030 -19
- package/dist/dts/workspace-elements/base/data-sources/types.d.ts +89 -22
- package/dist/dts/workspace-elements/base/external-event-log-records/types.d.ts +31 -8
- package/dist/dts/workspace-elements/base/external-event-pulls/types.d.ts +35 -8
- package/dist/dts/workspace-elements/base/external-event-subscriptions/types.d.ts +199 -23
- package/dist/dts/workspace-elements/base/external-events/types.d.ts +145 -5
- package/dist/dts/workspace-elements/base/field-mapping-instances/types.d.ts +74 -16
- package/dist/dts/workspace-elements/base/field-mappings/types.d.ts +91 -14
- package/dist/dts/workspace-elements/base/flow-instances/schemas.d.ts +39 -39
- package/dist/dts/workspace-elements/base/flow-instances/types.d.ts +155 -24
- package/dist/dts/workspace-elements/base/flow-runs/flow-node-runs.d.ts +20 -20
- package/dist/dts/workspace-elements/base/flow-runs/types.d.ts +114 -19
- package/dist/dts/workspace-elements/base/flows/types.d.ts +220 -26
- package/dist/dts/workspace-elements/base/integrations/types.d.ts +497 -24
- package/dist/dts/workspace-elements/base/scenarios/types.d.ts +723 -23
- package/dist/dts/workspace-elements/base/screens/types.d.ts +40 -6
- package/dist/index.d.ts +12141 -2138
- package/dist/index.js +1555 -522
- package/dist/index.js.map +1 -1
- package/dist/index.module.d.mts +12141 -2138
- package/dist/index.module.mjs +1414 -490
- package/dist/index.module.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -6779,505 +6779,6 @@
|
|
|
6779
6779
|
};
|
|
6780
6780
|
};
|
|
6781
6781
|
|
|
6782
|
-
const POPUP_ELEMENT_ID = '__integration-app-popup';
|
|
6783
|
-
const CONTAINER_ELEMENT_ID = '__integration-app-container';
|
|
6784
|
-
const CONTAINER_ELEMENT_CLASS = '__integration-app-container';
|
|
6785
|
-
const CONTAINER_ELEMENT_CLASS__LOADER = '__integration-app-container__loader';
|
|
6786
|
-
const BODY_CLASS = '__integration-app-open';
|
|
6787
|
-
const STYLES_ELEMENT_ID = '__integration-app-embed-styles';
|
|
6788
|
-
let IFRAME_START_SHOW_LOADER_TIME = 0;
|
|
6789
|
-
let IFRAME_SHOW_LOADER_TIMEOUT_ID;
|
|
6790
|
-
const IFRAME_SHOW_LOADER_MINIMAL_TIME = 500;
|
|
6791
|
-
const IFRAME_LAYOUT_SHIFT_TIME = 300;
|
|
6792
|
-
function showIframeLoader() {
|
|
6793
|
-
const container = getContainer();
|
|
6794
|
-
container === null || container === void 0 ? void 0 : container.classList.add(CONTAINER_ELEMENT_CLASS__LOADER);
|
|
6795
|
-
IFRAME_START_SHOW_LOADER_TIME = Date.now();
|
|
6796
|
-
}
|
|
6797
|
-
function hideIframeLoader(waitLayoutShift = IFRAME_LAYOUT_SHIFT_TIME) {
|
|
6798
|
-
if (IFRAME_SHOW_LOADER_TIMEOUT_ID) {
|
|
6799
|
-
clearTimeout(IFRAME_SHOW_LOADER_TIMEOUT_ID);
|
|
6800
|
-
}
|
|
6801
|
-
const delta = Date.now() - IFRAME_START_SHOW_LOADER_TIME;
|
|
6802
|
-
if (delta >= IFRAME_SHOW_LOADER_MINIMAL_TIME) {
|
|
6803
|
-
setTimeout(() => {
|
|
6804
|
-
const container = getContainer();
|
|
6805
|
-
container === null || container === void 0 ? void 0 : container.classList.remove(CONTAINER_ELEMENT_CLASS__LOADER);
|
|
6806
|
-
IFRAME_START_SHOW_LOADER_TIME = 0;
|
|
6807
|
-
}, waitLayoutShift);
|
|
6808
|
-
return;
|
|
6809
|
-
}
|
|
6810
|
-
else {
|
|
6811
|
-
const waitLayoutShift = delta >= IFRAME_LAYOUT_SHIFT_TIME ? 0 : IFRAME_LAYOUT_SHIFT_TIME - delta;
|
|
6812
|
-
const timeoutTime = IFRAME_SHOW_LOADER_MINIMAL_TIME - delta;
|
|
6813
|
-
IFRAME_SHOW_LOADER_TIMEOUT_ID = setTimeout(() => {
|
|
6814
|
-
hideIframeLoader(waitLayoutShift);
|
|
6815
|
-
}, timeoutTime);
|
|
6816
|
-
return;
|
|
6817
|
-
}
|
|
6818
|
-
}
|
|
6819
|
-
async function openIframe(uri, callbacks = {}, { mountTargetSelector } = {}) {
|
|
6820
|
-
close();
|
|
6821
|
-
init(mountTargetSelector);
|
|
6822
|
-
return new Promise((resolve) => {
|
|
6823
|
-
function complete(callback) {
|
|
6824
|
-
close(callback);
|
|
6825
|
-
resolve();
|
|
6826
|
-
}
|
|
6827
|
-
function doOpen() {
|
|
6828
|
-
const iframe = document.createElement('iframe');
|
|
6829
|
-
iframe.src = uri;
|
|
6830
|
-
iframe.id = POPUP_ELEMENT_ID;
|
|
6831
|
-
iframe.onload = () => {
|
|
6832
|
-
hideIframeLoader();
|
|
6833
|
-
};
|
|
6834
|
-
if (!!getContainer()) {
|
|
6835
|
-
document.body.classList.add(BODY_CLASS);
|
|
6836
|
-
showIframeLoader();
|
|
6837
|
-
appendToContainer(iframe);
|
|
6838
|
-
handleIframeUnmount(iframe);
|
|
6839
|
-
connectToChild({
|
|
6840
|
-
iframe,
|
|
6841
|
-
methods: {
|
|
6842
|
-
...callbacks,
|
|
6843
|
-
handshake: (...args) => {
|
|
6844
|
-
var _a;
|
|
6845
|
-
hideIframeLoader();
|
|
6846
|
-
(_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.handshake) === null || _a === void 0 ? void 0 : _a.call(callbacks, ...args);
|
|
6847
|
-
},
|
|
6848
|
-
close: () => complete(callbacks.onClose),
|
|
6849
|
-
},
|
|
6850
|
-
});
|
|
6851
|
-
}
|
|
6852
|
-
else {
|
|
6853
|
-
throw Error('Membrane container element not found. Was it manually removed?');
|
|
6854
|
-
}
|
|
6855
|
-
}
|
|
6856
|
-
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
6857
|
-
doOpen();
|
|
6858
|
-
}
|
|
6859
|
-
else {
|
|
6860
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
6861
|
-
doOpen();
|
|
6862
|
-
});
|
|
6863
|
-
}
|
|
6864
|
-
});
|
|
6865
|
-
}
|
|
6866
|
-
function close(callback) {
|
|
6867
|
-
document.body.classList.remove(BODY_CLASS);
|
|
6868
|
-
if (!!getContainer()) {
|
|
6869
|
-
deleteContainer();
|
|
6870
|
-
if (callback) {
|
|
6871
|
-
callback();
|
|
6872
|
-
}
|
|
6873
|
-
}
|
|
6874
|
-
}
|
|
6875
|
-
function init(mountTargetSelector) {
|
|
6876
|
-
var _a;
|
|
6877
|
-
injectStyles(mountTargetSelector);
|
|
6878
|
-
if (!!getContainer()) {
|
|
6879
|
-
return;
|
|
6880
|
-
}
|
|
6881
|
-
const container = createContainer();
|
|
6882
|
-
if (mountTargetSelector && document.querySelector(mountTargetSelector)) {
|
|
6883
|
-
(_a = document.querySelector(mountTargetSelector)) === null || _a === void 0 ? void 0 : _a.appendChild(container);
|
|
6884
|
-
}
|
|
6885
|
-
else {
|
|
6886
|
-
document.body.appendChild(container);
|
|
6887
|
-
}
|
|
6888
|
-
}
|
|
6889
|
-
function injectStyles(mountTargetSelector) {
|
|
6890
|
-
const hasCustomMountTarget = Boolean(mountTargetSelector && document.querySelector(mountTargetSelector));
|
|
6891
|
-
const styles = [
|
|
6892
|
-
`.${CONTAINER_ELEMENT_CLASS}:empty {
|
|
6893
|
-
display: none;
|
|
6894
|
-
}`,
|
|
6895
|
-
hasCustomMountTarget
|
|
6896
|
-
? `.${CONTAINER_ELEMENT_CLASS} {
|
|
6897
|
-
inset: 0;
|
|
6898
|
-
background: rgba(0, 0, 0, 0);
|
|
6899
|
-
transition: background 0.2s ease-out;
|
|
6900
|
-
display: flex;
|
|
6901
|
-
justify-content: center;
|
|
6902
|
-
align-items: center;
|
|
6903
|
-
width: 100%;
|
|
6904
|
-
height: 100%;
|
|
6905
|
-
}`
|
|
6906
|
-
: `.${CONTAINER_ELEMENT_CLASS} {
|
|
6907
|
-
position: fixed;
|
|
6908
|
-
inset: 0;
|
|
6909
|
-
z-index: 2147483647;
|
|
6910
|
-
display: flex;
|
|
6911
|
-
justify-content: center;
|
|
6912
|
-
align-items: center;
|
|
6913
|
-
pointer-events: auto;
|
|
6914
|
-
background: rgba(0, 0, 0, 0);
|
|
6915
|
-
transition: background 0.2s ease-out;
|
|
6916
|
-
}`,
|
|
6917
|
-
`.${CONTAINER_ELEMENT_CLASS}.${CONTAINER_ELEMENT_CLASS__LOADER} {
|
|
6918
|
-
background: rgba(0, 0, 0, 0.8);
|
|
6919
|
-
}`,
|
|
6920
|
-
`.${CONTAINER_ELEMENT_CLASS}.${CONTAINER_ELEMENT_CLASS__LOADER}::before {
|
|
6921
|
-
${hasCustomMountTarget ? 'position: absolute;' : ''}
|
|
6922
|
-
content: "";
|
|
6923
|
-
width: 5rem;
|
|
6924
|
-
height: 4rem;
|
|
6925
|
-
background-image: url('data:image/svg+xml,%3Csvg viewBox="0 0 32 22" fill="%23000" xmlns="http://www.w3.org/2000/svg" %3E%3Cdefs%3E%3Cmask id="a"%3E%3Crect width="100%25" height="100%25" fill="%23fff" /%3E%3Cpath d="M11.8 13.12a3 3 0 0 1 0-4.24l7.08-7.07a3 3 0 0 1 4.24 0l7.07 7.07a3 3 0 0 1 0 4.24l-7.07 7.07a3 3 0 0 1-4.24 0l-7.07-7.07Z"%3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 21 11" to="-360 21 11" /%3E%3C/path%3E%3C/mask%3E%3Cmask id="b"%3E%3Crect width="100%25" height="100%25" fill="%23fff"/%3E%3Cpath fill-rule="evenodd" clip-rule="evenodd" d="M1.8 8.88a3 3 0 0 0 0 4.24l7.08 7.07a3 3 0 0 0 4.24 0l7.07-7.07a3 3 0 0 0 0-4.24L13.12 1.8a3 3 0 0 0-4.24 0L1.8 8.88Zm.71.7a2 2 0 0 0 0 2.83L9.6 19.5a2 2 0 0 0 2.82 0l7.08-7.08a2 2 0 0 0 0-2.82l-7.1-7.1a2 2 0 0 0-2.82 0L2.5 9.6Z" %3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 11 11" to="720 11 11" /%3E%3C/path%3E%3C/mask%3E%3C/defs%3E%3Cg mask="url(%23a)"%3E%3Cpath fill-rule="evenodd" clip-rule="evenodd" d="M1.8 8.88a3 3 0 0 0 0 4.24l7.08 7.07a3 3 0 0 0 4.24 0l7.07-7.07a3 3 0 0 0 0-4.24L13.12 1.8a3 3 0 0 0-4.24 0L1.8 8.88Zm.71.7a2 2 0 0 0 0 2.83L9.6 19.5a2 2 0 0 0 2.82 0l7.08-7.08a2 2 0 0 0 0-2.82l-7.1-7.1a2 2 0 0 0-2.82 0L2.5 9.6Z"%0A%3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 11 11" to="720 11 11" /%3E%3C/path%3E%3C/g%3E%3Cg mask="url(%23b)"%3E%3Cpath d="M11.8 13.12a3 3 0 0 1 0-4.24l7.08-7.07a3 3 0 0 1 4.24 0l7.07 7.07a3 3 0 0 1 0 4.24l-7.07 7.07a3 3 0 0 1-4.24 0l-7.07-7.07Z"%3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 21 11" to="-360 21 11" /%3E%3C/path%3E%3C/g%3E%3C/svg%3E');
|
|
6926
|
-
background-size: contain;
|
|
6927
|
-
background-repeat: no-repeat;
|
|
6928
|
-
background-position: center;
|
|
6929
|
-
filter: invert(1);
|
|
6930
|
-
}`,
|
|
6931
|
-
`.${CONTAINER_ELEMENT_CLASS} iframe {
|
|
6932
|
-
${hasCustomMountTarget ? '' : 'position: absolute;'}
|
|
6933
|
-
width: 100%;
|
|
6934
|
-
height: 100%;
|
|
6935
|
-
border-width: 0;
|
|
6936
|
-
|
|
6937
|
-
/* fix transparent bg, because iframe document has light scheme */
|
|
6938
|
-
color-scheme: light;
|
|
6939
|
-
}`,
|
|
6940
|
-
`.${CONTAINER_ELEMENT_CLASS}.${CONTAINER_ELEMENT_CLASS__LOADER} iframe {
|
|
6941
|
-
visibility: hidden;
|
|
6942
|
-
}`,
|
|
6943
|
-
!hasCustomMountTarget
|
|
6944
|
-
? `body.${BODY_CLASS} {
|
|
6945
|
-
overflow: hidden;
|
|
6946
|
-
}`
|
|
6947
|
-
: '',
|
|
6948
|
-
];
|
|
6949
|
-
let styleElement = document.getElementById(STYLES_ELEMENT_ID);
|
|
6950
|
-
if (!styleElement) {
|
|
6951
|
-
styleElement = document.createElement('style');
|
|
6952
|
-
styleElement.id = STYLES_ELEMENT_ID;
|
|
6953
|
-
styleElement.type = 'text/css';
|
|
6954
|
-
document.head.appendChild(styleElement);
|
|
6955
|
-
}
|
|
6956
|
-
styleElement.textContent = styles.join('\n');
|
|
6957
|
-
}
|
|
6958
|
-
function removeInjectedStyles() {
|
|
6959
|
-
const stylesElement = document.getElementById(STYLES_ELEMENT_ID);
|
|
6960
|
-
if (stylesElement) {
|
|
6961
|
-
stylesElement.remove();
|
|
6962
|
-
}
|
|
6963
|
-
}
|
|
6964
|
-
function createContainer() {
|
|
6965
|
-
const container = document.createElement('div');
|
|
6966
|
-
container.id = CONTAINER_ELEMENT_ID;
|
|
6967
|
-
container.classList.add(CONTAINER_ELEMENT_CLASS);
|
|
6968
|
-
return container;
|
|
6969
|
-
}
|
|
6970
|
-
function getContainer() {
|
|
6971
|
-
return document.getElementById(CONTAINER_ELEMENT_ID);
|
|
6972
|
-
}
|
|
6973
|
-
function appendToContainer(el) {
|
|
6974
|
-
const container = getContainer();
|
|
6975
|
-
container === null || container === void 0 ? void 0 : container.appendChild(el);
|
|
6976
|
-
}
|
|
6977
|
-
function deleteContainer() {
|
|
6978
|
-
const container = getContainer();
|
|
6979
|
-
if (container) {
|
|
6980
|
-
container.remove();
|
|
6981
|
-
}
|
|
6982
|
-
removeInjectedStyles();
|
|
6983
|
-
}
|
|
6984
|
-
function handleIframeUnmount(iframe) {
|
|
6985
|
-
const observer = new MutationObserver((mutationsList) => {
|
|
6986
|
-
for (const mutation of mutationsList) {
|
|
6987
|
-
for (const removedNode of mutation.removedNodes) {
|
|
6988
|
-
if (removedNode instanceof HTMLElement && removedNode.id === POPUP_ELEMENT_ID) {
|
|
6989
|
-
observer.disconnect();
|
|
6990
|
-
deleteContainer();
|
|
6991
|
-
return;
|
|
6992
|
-
}
|
|
6993
|
-
}
|
|
6994
|
-
}
|
|
6995
|
-
});
|
|
6996
|
-
const parent = iframe.parentNode;
|
|
6997
|
-
if (parent) {
|
|
6998
|
-
observer.observe(parent, {
|
|
6999
|
-
childList: true,
|
|
7000
|
-
});
|
|
7001
|
-
}
|
|
7002
|
-
else {
|
|
7003
|
-
console.warn(`iframe with ID "${POPUP_ELEMENT_ID}" has no parent node`);
|
|
7004
|
-
}
|
|
7005
|
-
}
|
|
7006
|
-
|
|
7007
|
-
class ConnectionLevelElementAccessor {
|
|
7008
|
-
constructor(client, connectionSelector, selector, elementKey, query) {
|
|
7009
|
-
this.client = client;
|
|
7010
|
-
this.connectionSelector = connectionSelector;
|
|
7011
|
-
this.selector = selector;
|
|
7012
|
-
this.elementKey = elementKey;
|
|
7013
|
-
this.query = query;
|
|
7014
|
-
this.endpoint = `/connections/${this.connectionSelector}/${elementKey}/${selector}`;
|
|
7015
|
-
}
|
|
7016
|
-
uri(path = '', query = {}) {
|
|
7017
|
-
return this.endpoint + path + '?' + qs.stringify({ ...this.query, ...query });
|
|
7018
|
-
}
|
|
7019
|
-
getUniqueIdentifier() {
|
|
7020
|
-
return this.endpoint;
|
|
7021
|
-
}
|
|
7022
|
-
async get(query = {}) {
|
|
7023
|
-
return this.client.get(this.uri('', query));
|
|
7024
|
-
}
|
|
7025
|
-
async create() {
|
|
7026
|
-
return this.client.put(this.uri());
|
|
7027
|
-
}
|
|
7028
|
-
async patch(data) {
|
|
7029
|
-
return this.client.patch(this.uri(), data);
|
|
7030
|
-
}
|
|
7031
|
-
async put(data) {
|
|
7032
|
-
return this.client.put(this.uri(), data);
|
|
7033
|
-
}
|
|
7034
|
-
async archive() {
|
|
7035
|
-
return this.client.delete(this.uri());
|
|
7036
|
-
}
|
|
7037
|
-
async reset() {
|
|
7038
|
-
return this.client.post(this.uri('/reset'));
|
|
7039
|
-
}
|
|
7040
|
-
async setup() {
|
|
7041
|
-
return this.client.post(this.uri('/setup'));
|
|
7042
|
-
}
|
|
7043
|
-
}
|
|
7044
|
-
class ConnectionLevelElementsListAccessor {
|
|
7045
|
-
constructor(client, connectionSelector, elementKey) {
|
|
7046
|
-
this.client = client;
|
|
7047
|
-
this.connectionSelector = connectionSelector;
|
|
7048
|
-
this.elementKey = elementKey;
|
|
7049
|
-
}
|
|
7050
|
-
async list(query) {
|
|
7051
|
-
const endpoint = `/connections/${this.connectionSelector}/${this.elementKey}?${qs.stringify(query !== null && query !== void 0 ? query : {})}`;
|
|
7052
|
-
return this.client.get(endpoint);
|
|
7053
|
-
}
|
|
7054
|
-
}
|
|
7055
|
-
|
|
7056
|
-
class ActionInstancesAccessor extends ElementInstanceListAccessor {
|
|
7057
|
-
constructor(client) {
|
|
7058
|
-
super(client, 'action-instances');
|
|
7059
|
-
}
|
|
7060
|
-
}
|
|
7061
|
-
class ActionInstanceAccessor extends ElementInstanceAccessor {
|
|
7062
|
-
constructor(client, selector) {
|
|
7063
|
-
super({
|
|
7064
|
-
client,
|
|
7065
|
-
instancePath: 'action-instance',
|
|
7066
|
-
selector,
|
|
7067
|
-
});
|
|
7068
|
-
this.client = client;
|
|
7069
|
-
}
|
|
7070
|
-
async setup() {
|
|
7071
|
-
await this.client.post(this.getPath('setup'));
|
|
7072
|
-
}
|
|
7073
|
-
async reset() {
|
|
7074
|
-
await this.client.post(this.getPath('reset'));
|
|
7075
|
-
}
|
|
7076
|
-
async run(input) {
|
|
7077
|
-
return this.client.post(this.getPath('run'), input);
|
|
7078
|
-
}
|
|
7079
|
-
async open({ onClose = () => { } } = {}) {
|
|
7080
|
-
const id = await this.getId();
|
|
7081
|
-
const uri = await this.client.getEmbedUri(`action-instances/${id}/configuration`);
|
|
7082
|
-
return openIframe(uri, { onClose });
|
|
7083
|
-
}
|
|
7084
|
-
}
|
|
7085
|
-
class ConnectionLevelActionAccessor extends ConnectionLevelElementAccessor {
|
|
7086
|
-
constructor(client, connectionSelector, actionSelector, query) {
|
|
7087
|
-
super(client, connectionSelector, actionSelector, 'actions', query);
|
|
7088
|
-
this.client = client;
|
|
7089
|
-
this.connectionSelector = connectionSelector;
|
|
7090
|
-
this.actionSelector = actionSelector;
|
|
7091
|
-
this.query = query;
|
|
7092
|
-
}
|
|
7093
|
-
async run(input) {
|
|
7094
|
-
return this.client.post(this.uri('/run'), input);
|
|
7095
|
-
}
|
|
7096
|
-
}
|
|
7097
|
-
class ConnectionLevelActionsAccessor extends ConnectionLevelElementsListAccessor {
|
|
7098
|
-
constructor(client, connectionSelector) {
|
|
7099
|
-
super(client, connectionSelector, 'actions');
|
|
7100
|
-
this.client = client;
|
|
7101
|
-
this.connectionSelector = connectionSelector;
|
|
7102
|
-
}
|
|
7103
|
-
}
|
|
7104
|
-
|
|
7105
|
-
class DataSourcesAccessor extends ElementListAccessor {
|
|
7106
|
-
constructor(client) {
|
|
7107
|
-
super(client, 'data-sources');
|
|
7108
|
-
}
|
|
7109
|
-
}
|
|
7110
|
-
class DataSourceAccessor extends ElementAccessor {
|
|
7111
|
-
constructor(client, selector) {
|
|
7112
|
-
super({
|
|
7113
|
-
client,
|
|
7114
|
-
selector,
|
|
7115
|
-
path: 'data-source',
|
|
7116
|
-
});
|
|
7117
|
-
}
|
|
7118
|
-
async apply(integrationKeys) {
|
|
7119
|
-
return await this.options.client.post(this.getPath('apply'), {
|
|
7120
|
-
integrationKeys,
|
|
7121
|
-
});
|
|
7122
|
-
}
|
|
7123
|
-
async setup() {
|
|
7124
|
-
await this.options.client.post(this.getPath('setup'));
|
|
7125
|
-
}
|
|
7126
|
-
async reset() {
|
|
7127
|
-
return await this.options.client.post(this.getPath('reset'));
|
|
7128
|
-
}
|
|
7129
|
-
}
|
|
7130
|
-
class DataSourceInstancesAccessor extends ElementInstanceListAccessor {
|
|
7131
|
-
constructor(client) {
|
|
7132
|
-
super(client, 'data-source-instances');
|
|
7133
|
-
}
|
|
7134
|
-
}
|
|
7135
|
-
class DataSourceInstanceAccessor extends ElementInstanceAccessor {
|
|
7136
|
-
constructor(client, selector) {
|
|
7137
|
-
super({
|
|
7138
|
-
client,
|
|
7139
|
-
instancePath: 'data-source-instance',
|
|
7140
|
-
selector,
|
|
7141
|
-
});
|
|
7142
|
-
this.client = client;
|
|
7143
|
-
}
|
|
7144
|
-
async setup() {
|
|
7145
|
-
await this.client.post(this.getPath('setup'));
|
|
7146
|
-
}
|
|
7147
|
-
async reset() {
|
|
7148
|
-
await this.client.post(this.getPath('reset'));
|
|
7149
|
-
}
|
|
7150
|
-
async openConfiguration({ onClose = () => { } } = {}) {
|
|
7151
|
-
const id = await this.getId();
|
|
7152
|
-
const uri = await this.client.getEmbedUri(`data-source-instances/${id}/configuration`);
|
|
7153
|
-
return openIframe(uri, {
|
|
7154
|
-
onClose,
|
|
7155
|
-
});
|
|
7156
|
-
}
|
|
7157
|
-
async unifiedFieldsToNative(unifiedFields) {
|
|
7158
|
-
return this.client.post(this.getPath('unified-fields-to-native'), unifiedFields);
|
|
7159
|
-
}
|
|
7160
|
-
async getCollection() {
|
|
7161
|
-
return this.client.get(this.getPath('collection'));
|
|
7162
|
-
}
|
|
7163
|
-
async listRecords(request = {}) {
|
|
7164
|
-
return this.client.post(this.getPath('collection/list'), request);
|
|
7165
|
-
}
|
|
7166
|
-
async matchRecord(request) {
|
|
7167
|
-
return this.client.post(this.getPath('collection/match'), request);
|
|
7168
|
-
}
|
|
7169
|
-
async searchRecords(request) {
|
|
7170
|
-
return this.client.post(this.getPath('collection/search'), request);
|
|
7171
|
-
}
|
|
7172
|
-
async findRecordById(request) {
|
|
7173
|
-
const data = typeof request === 'string' ? { id: request } : request;
|
|
7174
|
-
return this.client.post(this.getPath('collection/find-by-id'), data);
|
|
7175
|
-
}
|
|
7176
|
-
async createRecord(request) {
|
|
7177
|
-
return this.client.post(this.getPath('collection/create'), request);
|
|
7178
|
-
}
|
|
7179
|
-
async updateRecord(request) {
|
|
7180
|
-
return this.client.post(this.getPath(`collection/update`), request);
|
|
7181
|
-
}
|
|
7182
|
-
async deleteRecord(request) {
|
|
7183
|
-
const data = typeof request === 'string' ? { id: request } : request;
|
|
7184
|
-
return this.client.post(this.getPath(`collection/delete`), data);
|
|
7185
|
-
}
|
|
7186
|
-
async findRecords(request = {}) {
|
|
7187
|
-
return this.client.post(this.getPath('collection/find'), request);
|
|
7188
|
-
}
|
|
7189
|
-
}
|
|
7190
|
-
class IntegrationLevelDataSourceAccessor extends IntegrationLevelElementAccessor {
|
|
7191
|
-
constructor(client, integrationSelector, dataSourceSelector) {
|
|
7192
|
-
super(client, integrationSelector, dataSourceSelector, 'data-sources');
|
|
7193
|
-
this.client = client;
|
|
7194
|
-
this.integrationSelector = integrationSelector;
|
|
7195
|
-
this.dataSourceSelector = dataSourceSelector;
|
|
7196
|
-
}
|
|
7197
|
-
}
|
|
7198
|
-
class IntegrationLevelDataSourcesListAccessor extends IntegrationLevelElementsListAccessor {
|
|
7199
|
-
constructor(client, integrationSelector) {
|
|
7200
|
-
super(client, integrationSelector, 'data-sources');
|
|
7201
|
-
this.client = client;
|
|
7202
|
-
this.integrationSelector = integrationSelector;
|
|
7203
|
-
}
|
|
7204
|
-
}
|
|
7205
|
-
class ConnectionLevelDataSourceAccessor extends ConnectionLevelElementAccessor {
|
|
7206
|
-
constructor(client, connectionSelector, dataSourceSelector, query) {
|
|
7207
|
-
super(client, connectionSelector, dataSourceSelector, 'data-sources', query);
|
|
7208
|
-
this.client = client;
|
|
7209
|
-
this.connectionSelector = connectionSelector;
|
|
7210
|
-
this.dataSourceSelector = dataSourceSelector;
|
|
7211
|
-
this.query = query;
|
|
7212
|
-
}
|
|
7213
|
-
async openConfiguration(options) {
|
|
7214
|
-
var _a;
|
|
7215
|
-
const instance = await this.get({ autoCreate: true });
|
|
7216
|
-
const uri = await this.client.getEmbedUri(`data-source-instances/${instance.id}/configuration`);
|
|
7217
|
-
const onClose = (_a = options === null || options === void 0 ? void 0 : options.onClose) !== null && _a !== void 0 ? _a : (() => { });
|
|
7218
|
-
return openIframe(uri, { onClose });
|
|
7219
|
-
}
|
|
7220
|
-
}
|
|
7221
|
-
class ConnectionLevelDataSourcesAccessor extends ConnectionLevelElementsListAccessor {
|
|
7222
|
-
constructor(client, connectionSelector) {
|
|
7223
|
-
super(client, connectionSelector, 'data-sources');
|
|
7224
|
-
this.client = client;
|
|
7225
|
-
this.connectionSelector = connectionSelector;
|
|
7226
|
-
}
|
|
7227
|
-
}
|
|
7228
|
-
|
|
7229
|
-
class FieldMappingInstancesAccessor extends ElementInstanceListAccessor {
|
|
7230
|
-
constructor(client) {
|
|
7231
|
-
super(client, 'field-mapping-instances');
|
|
7232
|
-
}
|
|
7233
|
-
}
|
|
7234
|
-
class FieldMappingInstanceAccessor extends ElementInstanceAccessor {
|
|
7235
|
-
constructor(client, selector) {
|
|
7236
|
-
super({
|
|
7237
|
-
client,
|
|
7238
|
-
instancePath: 'field-mapping-instance',
|
|
7239
|
-
selector,
|
|
7240
|
-
});
|
|
7241
|
-
this.client = client;
|
|
7242
|
-
}
|
|
7243
|
-
async setup() {
|
|
7244
|
-
const id = await this.getId();
|
|
7245
|
-
return this.client.post(`/field-mapping-instances/${id}/setup`);
|
|
7246
|
-
}
|
|
7247
|
-
async reset() {
|
|
7248
|
-
const id = await this.getId();
|
|
7249
|
-
return this.client.post(`/field-mapping-instances/${id}/reset`);
|
|
7250
|
-
}
|
|
7251
|
-
async openConfiguration({ onClose = () => { } } = {}) {
|
|
7252
|
-
const id = await this.getId();
|
|
7253
|
-
const uri = await this.client.getEmbedUri(`field-mapping-instances/${id}/configuration`);
|
|
7254
|
-
return openIframe(uri, {
|
|
7255
|
-
onClose,
|
|
7256
|
-
});
|
|
7257
|
-
}
|
|
7258
|
-
}
|
|
7259
|
-
class ConnectionLevelFieldMappingAccessor extends ConnectionLevelElementAccessor {
|
|
7260
|
-
constructor(client, connectionSelector, fieldMappingSelector, query) {
|
|
7261
|
-
super(client, connectionSelector, fieldMappingSelector, 'field-mappings', query);
|
|
7262
|
-
this.client = client;
|
|
7263
|
-
this.connectionSelector = connectionSelector;
|
|
7264
|
-
this.fieldMappingSelector = fieldMappingSelector;
|
|
7265
|
-
this.query = query;
|
|
7266
|
-
}
|
|
7267
|
-
async openConfiguration({ onClose } = {}) {
|
|
7268
|
-
const instance = await this.get({ autoCreate: true });
|
|
7269
|
-
const uri = await this.client.getEmbedUri(`field-mapping-instances/${instance.id}/configuration`);
|
|
7270
|
-
return openIframe(uri, { onClose: onClose !== null && onClose !== void 0 ? onClose : (() => { }) });
|
|
7271
|
-
}
|
|
7272
|
-
}
|
|
7273
|
-
class ConnectionLevelFieldMappingsAccessor extends ConnectionLevelElementsListAccessor {
|
|
7274
|
-
constructor(client, connectionSelector) {
|
|
7275
|
-
super(client, connectionSelector, 'field-mappings');
|
|
7276
|
-
this.client = client;
|
|
7277
|
-
this.connectionSelector = connectionSelector;
|
|
7278
|
-
}
|
|
7279
|
-
}
|
|
7280
|
-
|
|
7281
6782
|
var util;
|
|
7282
6783
|
(function (util) {
|
|
7283
6784
|
util.assertEqual = (_) => { };
|
|
@@ -9195,22 +8696,158 @@
|
|
|
9195
8696
|
message: errorUtil.toString(message),
|
|
9196
8697
|
});
|
|
9197
8698
|
}
|
|
9198
|
-
nonnegative(message) {
|
|
8699
|
+
nonnegative(message) {
|
|
8700
|
+
return this._addCheck({
|
|
8701
|
+
kind: "min",
|
|
8702
|
+
value: BigInt(0),
|
|
8703
|
+
inclusive: true,
|
|
8704
|
+
message: errorUtil.toString(message),
|
|
8705
|
+
});
|
|
8706
|
+
}
|
|
8707
|
+
multipleOf(value, message) {
|
|
8708
|
+
return this._addCheck({
|
|
8709
|
+
kind: "multipleOf",
|
|
8710
|
+
value,
|
|
8711
|
+
message: errorUtil.toString(message),
|
|
8712
|
+
});
|
|
8713
|
+
}
|
|
8714
|
+
get minValue() {
|
|
8715
|
+
let min = null;
|
|
8716
|
+
for (const ch of this._def.checks) {
|
|
8717
|
+
if (ch.kind === "min") {
|
|
8718
|
+
if (min === null || ch.value > min)
|
|
8719
|
+
min = ch.value;
|
|
8720
|
+
}
|
|
8721
|
+
}
|
|
8722
|
+
return min;
|
|
8723
|
+
}
|
|
8724
|
+
get maxValue() {
|
|
8725
|
+
let max = null;
|
|
8726
|
+
for (const ch of this._def.checks) {
|
|
8727
|
+
if (ch.kind === "max") {
|
|
8728
|
+
if (max === null || ch.value < max)
|
|
8729
|
+
max = ch.value;
|
|
8730
|
+
}
|
|
8731
|
+
}
|
|
8732
|
+
return max;
|
|
8733
|
+
}
|
|
8734
|
+
}
|
|
8735
|
+
ZodBigInt.create = (params) => {
|
|
8736
|
+
return new ZodBigInt({
|
|
8737
|
+
checks: [],
|
|
8738
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
8739
|
+
coerce: params?.coerce ?? false,
|
|
8740
|
+
...processCreateParams(params),
|
|
8741
|
+
});
|
|
8742
|
+
};
|
|
8743
|
+
class ZodBoolean extends ZodType {
|
|
8744
|
+
_parse(input) {
|
|
8745
|
+
if (this._def.coerce) {
|
|
8746
|
+
input.data = Boolean(input.data);
|
|
8747
|
+
}
|
|
8748
|
+
const parsedType = this._getType(input);
|
|
8749
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
8750
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8751
|
+
addIssueToContext(ctx, {
|
|
8752
|
+
code: ZodIssueCode.invalid_type,
|
|
8753
|
+
expected: ZodParsedType.boolean,
|
|
8754
|
+
received: ctx.parsedType,
|
|
8755
|
+
});
|
|
8756
|
+
return INVALID;
|
|
8757
|
+
}
|
|
8758
|
+
return OK(input.data);
|
|
8759
|
+
}
|
|
8760
|
+
}
|
|
8761
|
+
ZodBoolean.create = (params) => {
|
|
8762
|
+
return new ZodBoolean({
|
|
8763
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
8764
|
+
coerce: params?.coerce || false,
|
|
8765
|
+
...processCreateParams(params),
|
|
8766
|
+
});
|
|
8767
|
+
};
|
|
8768
|
+
class ZodDate extends ZodType {
|
|
8769
|
+
_parse(input) {
|
|
8770
|
+
if (this._def.coerce) {
|
|
8771
|
+
input.data = new Date(input.data);
|
|
8772
|
+
}
|
|
8773
|
+
const parsedType = this._getType(input);
|
|
8774
|
+
if (parsedType !== ZodParsedType.date) {
|
|
8775
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8776
|
+
addIssueToContext(ctx, {
|
|
8777
|
+
code: ZodIssueCode.invalid_type,
|
|
8778
|
+
expected: ZodParsedType.date,
|
|
8779
|
+
received: ctx.parsedType,
|
|
8780
|
+
});
|
|
8781
|
+
return INVALID;
|
|
8782
|
+
}
|
|
8783
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
8784
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8785
|
+
addIssueToContext(ctx, {
|
|
8786
|
+
code: ZodIssueCode.invalid_date,
|
|
8787
|
+
});
|
|
8788
|
+
return INVALID;
|
|
8789
|
+
}
|
|
8790
|
+
const status = new ParseStatus();
|
|
8791
|
+
let ctx = undefined;
|
|
8792
|
+
for (const check of this._def.checks) {
|
|
8793
|
+
if (check.kind === "min") {
|
|
8794
|
+
if (input.data.getTime() < check.value) {
|
|
8795
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
8796
|
+
addIssueToContext(ctx, {
|
|
8797
|
+
code: ZodIssueCode.too_small,
|
|
8798
|
+
message: check.message,
|
|
8799
|
+
inclusive: true,
|
|
8800
|
+
exact: false,
|
|
8801
|
+
minimum: check.value,
|
|
8802
|
+
type: "date",
|
|
8803
|
+
});
|
|
8804
|
+
status.dirty();
|
|
8805
|
+
}
|
|
8806
|
+
}
|
|
8807
|
+
else if (check.kind === "max") {
|
|
8808
|
+
if (input.data.getTime() > check.value) {
|
|
8809
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
8810
|
+
addIssueToContext(ctx, {
|
|
8811
|
+
code: ZodIssueCode.too_big,
|
|
8812
|
+
message: check.message,
|
|
8813
|
+
inclusive: true,
|
|
8814
|
+
exact: false,
|
|
8815
|
+
maximum: check.value,
|
|
8816
|
+
type: "date",
|
|
8817
|
+
});
|
|
8818
|
+
status.dirty();
|
|
8819
|
+
}
|
|
8820
|
+
}
|
|
8821
|
+
else {
|
|
8822
|
+
util.assertNever(check);
|
|
8823
|
+
}
|
|
8824
|
+
}
|
|
8825
|
+
return {
|
|
8826
|
+
status: status.value,
|
|
8827
|
+
value: new Date(input.data.getTime()),
|
|
8828
|
+
};
|
|
8829
|
+
}
|
|
8830
|
+
_addCheck(check) {
|
|
8831
|
+
return new ZodDate({
|
|
8832
|
+
...this._def,
|
|
8833
|
+
checks: [...this._def.checks, check],
|
|
8834
|
+
});
|
|
8835
|
+
}
|
|
8836
|
+
min(minDate, message) {
|
|
9199
8837
|
return this._addCheck({
|
|
9200
8838
|
kind: "min",
|
|
9201
|
-
value:
|
|
9202
|
-
inclusive: true,
|
|
8839
|
+
value: minDate.getTime(),
|
|
9203
8840
|
message: errorUtil.toString(message),
|
|
9204
8841
|
});
|
|
9205
8842
|
}
|
|
9206
|
-
|
|
8843
|
+
max(maxDate, message) {
|
|
9207
8844
|
return this._addCheck({
|
|
9208
|
-
kind: "
|
|
9209
|
-
value,
|
|
8845
|
+
kind: "max",
|
|
8846
|
+
value: maxDate.getTime(),
|
|
9210
8847
|
message: errorUtil.toString(message),
|
|
9211
8848
|
});
|
|
9212
8849
|
}
|
|
9213
|
-
get
|
|
8850
|
+
get minDate() {
|
|
9214
8851
|
let min = null;
|
|
9215
8852
|
for (const ch of this._def.checks) {
|
|
9216
8853
|
if (ch.kind === "min") {
|
|
@@ -9218,9 +8855,9 @@
|
|
|
9218
8855
|
min = ch.value;
|
|
9219
8856
|
}
|
|
9220
8857
|
}
|
|
9221
|
-
return min;
|
|
8858
|
+
return min != null ? new Date(min) : null;
|
|
9222
8859
|
}
|
|
9223
|
-
get
|
|
8860
|
+
get maxDate() {
|
|
9224
8861
|
let max = null;
|
|
9225
8862
|
for (const ch of this._def.checks) {
|
|
9226
8863
|
if (ch.kind === "max") {
|
|
@@ -9228,1838 +8865,2322 @@
|
|
|
9228
8865
|
max = ch.value;
|
|
9229
8866
|
}
|
|
9230
8867
|
}
|
|
9231
|
-
return max;
|
|
8868
|
+
return max != null ? new Date(max) : null;
|
|
9232
8869
|
}
|
|
9233
8870
|
}
|
|
9234
|
-
|
|
9235
|
-
return new
|
|
8871
|
+
ZodDate.create = (params) => {
|
|
8872
|
+
return new ZodDate({
|
|
9236
8873
|
checks: [],
|
|
9237
|
-
|
|
9238
|
-
|
|
8874
|
+
coerce: params?.coerce || false,
|
|
8875
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
8876
|
+
...processCreateParams(params),
|
|
8877
|
+
});
|
|
8878
|
+
};
|
|
8879
|
+
class ZodSymbol extends ZodType {
|
|
8880
|
+
_parse(input) {
|
|
8881
|
+
const parsedType = this._getType(input);
|
|
8882
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
8883
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8884
|
+
addIssueToContext(ctx, {
|
|
8885
|
+
code: ZodIssueCode.invalid_type,
|
|
8886
|
+
expected: ZodParsedType.symbol,
|
|
8887
|
+
received: ctx.parsedType,
|
|
8888
|
+
});
|
|
8889
|
+
return INVALID;
|
|
8890
|
+
}
|
|
8891
|
+
return OK(input.data);
|
|
8892
|
+
}
|
|
8893
|
+
}
|
|
8894
|
+
ZodSymbol.create = (params) => {
|
|
8895
|
+
return new ZodSymbol({
|
|
8896
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
8897
|
+
...processCreateParams(params),
|
|
8898
|
+
});
|
|
8899
|
+
};
|
|
8900
|
+
class ZodUndefined extends ZodType {
|
|
8901
|
+
_parse(input) {
|
|
8902
|
+
const parsedType = this._getType(input);
|
|
8903
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
8904
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8905
|
+
addIssueToContext(ctx, {
|
|
8906
|
+
code: ZodIssueCode.invalid_type,
|
|
8907
|
+
expected: ZodParsedType.undefined,
|
|
8908
|
+
received: ctx.parsedType,
|
|
8909
|
+
});
|
|
8910
|
+
return INVALID;
|
|
8911
|
+
}
|
|
8912
|
+
return OK(input.data);
|
|
8913
|
+
}
|
|
8914
|
+
}
|
|
8915
|
+
ZodUndefined.create = (params) => {
|
|
8916
|
+
return new ZodUndefined({
|
|
8917
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
8918
|
+
...processCreateParams(params),
|
|
8919
|
+
});
|
|
8920
|
+
};
|
|
8921
|
+
class ZodNull extends ZodType {
|
|
8922
|
+
_parse(input) {
|
|
8923
|
+
const parsedType = this._getType(input);
|
|
8924
|
+
if (parsedType !== ZodParsedType.null) {
|
|
8925
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8926
|
+
addIssueToContext(ctx, {
|
|
8927
|
+
code: ZodIssueCode.invalid_type,
|
|
8928
|
+
expected: ZodParsedType.null,
|
|
8929
|
+
received: ctx.parsedType,
|
|
8930
|
+
});
|
|
8931
|
+
return INVALID;
|
|
8932
|
+
}
|
|
8933
|
+
return OK(input.data);
|
|
8934
|
+
}
|
|
8935
|
+
}
|
|
8936
|
+
ZodNull.create = (params) => {
|
|
8937
|
+
return new ZodNull({
|
|
8938
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
8939
|
+
...processCreateParams(params),
|
|
8940
|
+
});
|
|
8941
|
+
};
|
|
8942
|
+
class ZodAny extends ZodType {
|
|
8943
|
+
constructor() {
|
|
8944
|
+
super(...arguments);
|
|
8945
|
+
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
8946
|
+
this._any = true;
|
|
8947
|
+
}
|
|
8948
|
+
_parse(input) {
|
|
8949
|
+
return OK(input.data);
|
|
8950
|
+
}
|
|
8951
|
+
}
|
|
8952
|
+
ZodAny.create = (params) => {
|
|
8953
|
+
return new ZodAny({
|
|
8954
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
8955
|
+
...processCreateParams(params),
|
|
8956
|
+
});
|
|
8957
|
+
};
|
|
8958
|
+
class ZodUnknown extends ZodType {
|
|
8959
|
+
constructor() {
|
|
8960
|
+
super(...arguments);
|
|
8961
|
+
// required
|
|
8962
|
+
this._unknown = true;
|
|
8963
|
+
}
|
|
8964
|
+
_parse(input) {
|
|
8965
|
+
return OK(input.data);
|
|
8966
|
+
}
|
|
8967
|
+
}
|
|
8968
|
+
ZodUnknown.create = (params) => {
|
|
8969
|
+
return new ZodUnknown({
|
|
8970
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
8971
|
+
...processCreateParams(params),
|
|
8972
|
+
});
|
|
8973
|
+
};
|
|
8974
|
+
class ZodNever extends ZodType {
|
|
8975
|
+
_parse(input) {
|
|
8976
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8977
|
+
addIssueToContext(ctx, {
|
|
8978
|
+
code: ZodIssueCode.invalid_type,
|
|
8979
|
+
expected: ZodParsedType.never,
|
|
8980
|
+
received: ctx.parsedType,
|
|
8981
|
+
});
|
|
8982
|
+
return INVALID;
|
|
8983
|
+
}
|
|
8984
|
+
}
|
|
8985
|
+
ZodNever.create = (params) => {
|
|
8986
|
+
return new ZodNever({
|
|
8987
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
8988
|
+
...processCreateParams(params),
|
|
8989
|
+
});
|
|
8990
|
+
};
|
|
8991
|
+
class ZodVoid extends ZodType {
|
|
8992
|
+
_parse(input) {
|
|
8993
|
+
const parsedType = this._getType(input);
|
|
8994
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
8995
|
+
const ctx = this._getOrReturnCtx(input);
|
|
8996
|
+
addIssueToContext(ctx, {
|
|
8997
|
+
code: ZodIssueCode.invalid_type,
|
|
8998
|
+
expected: ZodParsedType.void,
|
|
8999
|
+
received: ctx.parsedType,
|
|
9000
|
+
});
|
|
9001
|
+
return INVALID;
|
|
9002
|
+
}
|
|
9003
|
+
return OK(input.data);
|
|
9004
|
+
}
|
|
9005
|
+
}
|
|
9006
|
+
ZodVoid.create = (params) => {
|
|
9007
|
+
return new ZodVoid({
|
|
9008
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
9009
|
+
...processCreateParams(params),
|
|
9010
|
+
});
|
|
9011
|
+
};
|
|
9012
|
+
class ZodArray extends ZodType {
|
|
9013
|
+
_parse(input) {
|
|
9014
|
+
const { ctx, status } = this._processInputParams(input);
|
|
9015
|
+
const def = this._def;
|
|
9016
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
9017
|
+
addIssueToContext(ctx, {
|
|
9018
|
+
code: ZodIssueCode.invalid_type,
|
|
9019
|
+
expected: ZodParsedType.array,
|
|
9020
|
+
received: ctx.parsedType,
|
|
9021
|
+
});
|
|
9022
|
+
return INVALID;
|
|
9023
|
+
}
|
|
9024
|
+
if (def.exactLength !== null) {
|
|
9025
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
9026
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
9027
|
+
if (tooBig || tooSmall) {
|
|
9028
|
+
addIssueToContext(ctx, {
|
|
9029
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
9030
|
+
minimum: (tooSmall ? def.exactLength.value : undefined),
|
|
9031
|
+
maximum: (tooBig ? def.exactLength.value : undefined),
|
|
9032
|
+
type: "array",
|
|
9033
|
+
inclusive: true,
|
|
9034
|
+
exact: true,
|
|
9035
|
+
message: def.exactLength.message,
|
|
9036
|
+
});
|
|
9037
|
+
status.dirty();
|
|
9038
|
+
}
|
|
9039
|
+
}
|
|
9040
|
+
if (def.minLength !== null) {
|
|
9041
|
+
if (ctx.data.length < def.minLength.value) {
|
|
9042
|
+
addIssueToContext(ctx, {
|
|
9043
|
+
code: ZodIssueCode.too_small,
|
|
9044
|
+
minimum: def.minLength.value,
|
|
9045
|
+
type: "array",
|
|
9046
|
+
inclusive: true,
|
|
9047
|
+
exact: false,
|
|
9048
|
+
message: def.minLength.message,
|
|
9049
|
+
});
|
|
9050
|
+
status.dirty();
|
|
9051
|
+
}
|
|
9052
|
+
}
|
|
9053
|
+
if (def.maxLength !== null) {
|
|
9054
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
9055
|
+
addIssueToContext(ctx, {
|
|
9056
|
+
code: ZodIssueCode.too_big,
|
|
9057
|
+
maximum: def.maxLength.value,
|
|
9058
|
+
type: "array",
|
|
9059
|
+
inclusive: true,
|
|
9060
|
+
exact: false,
|
|
9061
|
+
message: def.maxLength.message,
|
|
9062
|
+
});
|
|
9063
|
+
status.dirty();
|
|
9064
|
+
}
|
|
9065
|
+
}
|
|
9066
|
+
if (ctx.common.async) {
|
|
9067
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
9068
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
9069
|
+
})).then((result) => {
|
|
9070
|
+
return ParseStatus.mergeArray(status, result);
|
|
9071
|
+
});
|
|
9072
|
+
}
|
|
9073
|
+
const result = [...ctx.data].map((item, i) => {
|
|
9074
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
9075
|
+
});
|
|
9076
|
+
return ParseStatus.mergeArray(status, result);
|
|
9077
|
+
}
|
|
9078
|
+
get element() {
|
|
9079
|
+
return this._def.type;
|
|
9080
|
+
}
|
|
9081
|
+
min(minLength, message) {
|
|
9082
|
+
return new ZodArray({
|
|
9083
|
+
...this._def,
|
|
9084
|
+
minLength: { value: minLength, message: errorUtil.toString(message) },
|
|
9085
|
+
});
|
|
9086
|
+
}
|
|
9087
|
+
max(maxLength, message) {
|
|
9088
|
+
return new ZodArray({
|
|
9089
|
+
...this._def,
|
|
9090
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) },
|
|
9091
|
+
});
|
|
9092
|
+
}
|
|
9093
|
+
length(len, message) {
|
|
9094
|
+
return new ZodArray({
|
|
9095
|
+
...this._def,
|
|
9096
|
+
exactLength: { value: len, message: errorUtil.toString(message) },
|
|
9097
|
+
});
|
|
9098
|
+
}
|
|
9099
|
+
nonempty(message) {
|
|
9100
|
+
return this.min(1, message);
|
|
9101
|
+
}
|
|
9102
|
+
}
|
|
9103
|
+
ZodArray.create = (schema, params) => {
|
|
9104
|
+
return new ZodArray({
|
|
9105
|
+
type: schema,
|
|
9106
|
+
minLength: null,
|
|
9107
|
+
maxLength: null,
|
|
9108
|
+
exactLength: null,
|
|
9109
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
9239
9110
|
...processCreateParams(params),
|
|
9240
9111
|
});
|
|
9241
9112
|
};
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
9249
|
-
const ctx = this._getOrReturnCtx(input);
|
|
9250
|
-
addIssueToContext(ctx, {
|
|
9251
|
-
code: ZodIssueCode.invalid_type,
|
|
9252
|
-
expected: ZodParsedType.boolean,
|
|
9253
|
-
received: ctx.parsedType,
|
|
9254
|
-
});
|
|
9255
|
-
return INVALID;
|
|
9113
|
+
function deepPartialify(schema) {
|
|
9114
|
+
if (schema instanceof ZodObject) {
|
|
9115
|
+
const newShape = {};
|
|
9116
|
+
for (const key in schema.shape) {
|
|
9117
|
+
const fieldSchema = schema.shape[key];
|
|
9118
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
9256
9119
|
}
|
|
9257
|
-
return
|
|
9120
|
+
return new ZodObject({
|
|
9121
|
+
...schema._def,
|
|
9122
|
+
shape: () => newShape,
|
|
9123
|
+
});
|
|
9124
|
+
}
|
|
9125
|
+
else if (schema instanceof ZodArray) {
|
|
9126
|
+
return new ZodArray({
|
|
9127
|
+
...schema._def,
|
|
9128
|
+
type: deepPartialify(schema.element),
|
|
9129
|
+
});
|
|
9130
|
+
}
|
|
9131
|
+
else if (schema instanceof ZodOptional) {
|
|
9132
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
9133
|
+
}
|
|
9134
|
+
else if (schema instanceof ZodNullable) {
|
|
9135
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
9136
|
+
}
|
|
9137
|
+
else if (schema instanceof ZodTuple) {
|
|
9138
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
9139
|
+
}
|
|
9140
|
+
else {
|
|
9141
|
+
return schema;
|
|
9258
9142
|
}
|
|
9259
9143
|
}
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9144
|
+
class ZodObject extends ZodType {
|
|
9145
|
+
constructor() {
|
|
9146
|
+
super(...arguments);
|
|
9147
|
+
this._cached = null;
|
|
9148
|
+
/**
|
|
9149
|
+
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
9150
|
+
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
9151
|
+
*/
|
|
9152
|
+
this.nonstrict = this.passthrough;
|
|
9153
|
+
// extend<
|
|
9154
|
+
// Augmentation extends ZodRawShape,
|
|
9155
|
+
// NewOutput extends util.flatten<{
|
|
9156
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
9157
|
+
// ? Augmentation[k]["_output"]
|
|
9158
|
+
// : k extends keyof Output
|
|
9159
|
+
// ? Output[k]
|
|
9160
|
+
// : never;
|
|
9161
|
+
// }>,
|
|
9162
|
+
// NewInput extends util.flatten<{
|
|
9163
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
9164
|
+
// ? Augmentation[k]["_input"]
|
|
9165
|
+
// : k extends keyof Input
|
|
9166
|
+
// ? Input[k]
|
|
9167
|
+
// : never;
|
|
9168
|
+
// }>
|
|
9169
|
+
// >(
|
|
9170
|
+
// augmentation: Augmentation
|
|
9171
|
+
// ): ZodObject<
|
|
9172
|
+
// extendShape<T, Augmentation>,
|
|
9173
|
+
// UnknownKeys,
|
|
9174
|
+
// Catchall,
|
|
9175
|
+
// NewOutput,
|
|
9176
|
+
// NewInput
|
|
9177
|
+
// > {
|
|
9178
|
+
// return new ZodObject({
|
|
9179
|
+
// ...this._def,
|
|
9180
|
+
// shape: () => ({
|
|
9181
|
+
// ...this._def.shape(),
|
|
9182
|
+
// ...augmentation,
|
|
9183
|
+
// }),
|
|
9184
|
+
// }) as any;
|
|
9185
|
+
// }
|
|
9186
|
+
/**
|
|
9187
|
+
* @deprecated Use `.extend` instead
|
|
9188
|
+
* */
|
|
9189
|
+
this.augment = this.extend;
|
|
9190
|
+
}
|
|
9191
|
+
_getCached() {
|
|
9192
|
+
if (this._cached !== null)
|
|
9193
|
+
return this._cached;
|
|
9194
|
+
const shape = this._def.shape();
|
|
9195
|
+
const keys = util.objectKeys(shape);
|
|
9196
|
+
this._cached = { shape, keys };
|
|
9197
|
+
return this._cached;
|
|
9198
|
+
}
|
|
9268
9199
|
_parse(input) {
|
|
9269
|
-
if (this._def.coerce) {
|
|
9270
|
-
input.data = new Date(input.data);
|
|
9271
|
-
}
|
|
9272
9200
|
const parsedType = this._getType(input);
|
|
9273
|
-
if (parsedType !== ZodParsedType.
|
|
9201
|
+
if (parsedType !== ZodParsedType.object) {
|
|
9274
9202
|
const ctx = this._getOrReturnCtx(input);
|
|
9275
9203
|
addIssueToContext(ctx, {
|
|
9276
9204
|
code: ZodIssueCode.invalid_type,
|
|
9277
|
-
expected: ZodParsedType.
|
|
9205
|
+
expected: ZodParsedType.object,
|
|
9278
9206
|
received: ctx.parsedType,
|
|
9279
9207
|
});
|
|
9280
9208
|
return INVALID;
|
|
9281
9209
|
}
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9210
|
+
const { status, ctx } = this._processInputParams(input);
|
|
9211
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
9212
|
+
const extraKeys = [];
|
|
9213
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
9214
|
+
for (const key in ctx.data) {
|
|
9215
|
+
if (!shapeKeys.includes(key)) {
|
|
9216
|
+
extraKeys.push(key);
|
|
9217
|
+
}
|
|
9218
|
+
}
|
|
9219
|
+
}
|
|
9220
|
+
const pairs = [];
|
|
9221
|
+
for (const key of shapeKeys) {
|
|
9222
|
+
const keyValidator = shape[key];
|
|
9223
|
+
const value = ctx.data[key];
|
|
9224
|
+
pairs.push({
|
|
9225
|
+
key: { status: "valid", value: key },
|
|
9226
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
9227
|
+
alwaysSet: key in ctx.data,
|
|
9286
9228
|
});
|
|
9287
|
-
return INVALID;
|
|
9288
9229
|
}
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
code: ZodIssueCode.too_small,
|
|
9297
|
-
message: check.message,
|
|
9298
|
-
inclusive: true,
|
|
9299
|
-
exact: false,
|
|
9300
|
-
minimum: check.value,
|
|
9301
|
-
type: "date",
|
|
9230
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
9231
|
+
const unknownKeys = this._def.unknownKeys;
|
|
9232
|
+
if (unknownKeys === "passthrough") {
|
|
9233
|
+
for (const key of extraKeys) {
|
|
9234
|
+
pairs.push({
|
|
9235
|
+
key: { status: "valid", value: key },
|
|
9236
|
+
value: { status: "valid", value: ctx.data[key] },
|
|
9302
9237
|
});
|
|
9303
|
-
status.dirty();
|
|
9304
9238
|
}
|
|
9305
9239
|
}
|
|
9306
|
-
else if (
|
|
9307
|
-
if (
|
|
9308
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
9240
|
+
else if (unknownKeys === "strict") {
|
|
9241
|
+
if (extraKeys.length > 0) {
|
|
9309
9242
|
addIssueToContext(ctx, {
|
|
9310
|
-
code: ZodIssueCode.
|
|
9311
|
-
|
|
9312
|
-
inclusive: true,
|
|
9313
|
-
exact: false,
|
|
9314
|
-
maximum: check.value,
|
|
9315
|
-
type: "date",
|
|
9243
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
9244
|
+
keys: extraKeys,
|
|
9316
9245
|
});
|
|
9317
9246
|
status.dirty();
|
|
9318
9247
|
}
|
|
9319
9248
|
}
|
|
9249
|
+
else if (unknownKeys === "strip") ;
|
|
9320
9250
|
else {
|
|
9321
|
-
|
|
9251
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
9322
9252
|
}
|
|
9323
9253
|
}
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9254
|
+
else {
|
|
9255
|
+
// run catchall validation
|
|
9256
|
+
const catchall = this._def.catchall;
|
|
9257
|
+
for (const key of extraKeys) {
|
|
9258
|
+
const value = ctx.data[key];
|
|
9259
|
+
pairs.push({
|
|
9260
|
+
key: { status: "valid", value: key },
|
|
9261
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
|
9262
|
+
),
|
|
9263
|
+
alwaysSet: key in ctx.data,
|
|
9264
|
+
});
|
|
9265
|
+
}
|
|
9266
|
+
}
|
|
9267
|
+
if (ctx.common.async) {
|
|
9268
|
+
return Promise.resolve()
|
|
9269
|
+
.then(async () => {
|
|
9270
|
+
const syncPairs = [];
|
|
9271
|
+
for (const pair of pairs) {
|
|
9272
|
+
const key = await pair.key;
|
|
9273
|
+
const value = await pair.value;
|
|
9274
|
+
syncPairs.push({
|
|
9275
|
+
key,
|
|
9276
|
+
value,
|
|
9277
|
+
alwaysSet: pair.alwaysSet,
|
|
9278
|
+
});
|
|
9279
|
+
}
|
|
9280
|
+
return syncPairs;
|
|
9281
|
+
})
|
|
9282
|
+
.then((syncPairs) => {
|
|
9283
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
9284
|
+
});
|
|
9285
|
+
}
|
|
9286
|
+
else {
|
|
9287
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
9288
|
+
}
|
|
9289
|
+
}
|
|
9290
|
+
get shape() {
|
|
9291
|
+
return this._def.shape();
|
|
9292
|
+
}
|
|
9293
|
+
strict(message) {
|
|
9294
|
+
errorUtil.errToObj;
|
|
9295
|
+
return new ZodObject({
|
|
9296
|
+
...this._def,
|
|
9297
|
+
unknownKeys: "strict",
|
|
9298
|
+
...(message !== undefined
|
|
9299
|
+
? {
|
|
9300
|
+
errorMap: (issue, ctx) => {
|
|
9301
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
9302
|
+
if (issue.code === "unrecognized_keys")
|
|
9303
|
+
return {
|
|
9304
|
+
message: errorUtil.errToObj(message).message ?? defaultError,
|
|
9305
|
+
};
|
|
9306
|
+
return {
|
|
9307
|
+
message: defaultError,
|
|
9308
|
+
};
|
|
9309
|
+
},
|
|
9310
|
+
}
|
|
9311
|
+
: {}),
|
|
9312
|
+
});
|
|
9313
|
+
}
|
|
9314
|
+
strip() {
|
|
9315
|
+
return new ZodObject({
|
|
9316
|
+
...this._def,
|
|
9317
|
+
unknownKeys: "strip",
|
|
9318
|
+
});
|
|
9319
|
+
}
|
|
9320
|
+
passthrough() {
|
|
9321
|
+
return new ZodObject({
|
|
9322
|
+
...this._def,
|
|
9323
|
+
unknownKeys: "passthrough",
|
|
9324
|
+
});
|
|
9328
9325
|
}
|
|
9329
|
-
|
|
9330
|
-
|
|
9326
|
+
// const AugmentFactory =
|
|
9327
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
9328
|
+
// <Augmentation extends ZodRawShape>(
|
|
9329
|
+
// augmentation: Augmentation
|
|
9330
|
+
// ): ZodObject<
|
|
9331
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
9332
|
+
// Def["unknownKeys"],
|
|
9333
|
+
// Def["catchall"]
|
|
9334
|
+
// > => {
|
|
9335
|
+
// return new ZodObject({
|
|
9336
|
+
// ...def,
|
|
9337
|
+
// shape: () => ({
|
|
9338
|
+
// ...def.shape(),
|
|
9339
|
+
// ...augmentation,
|
|
9340
|
+
// }),
|
|
9341
|
+
// }) as any;
|
|
9342
|
+
// };
|
|
9343
|
+
extend(augmentation) {
|
|
9344
|
+
return new ZodObject({
|
|
9331
9345
|
...this._def,
|
|
9332
|
-
|
|
9346
|
+
shape: () => ({
|
|
9347
|
+
...this._def.shape(),
|
|
9348
|
+
...augmentation,
|
|
9349
|
+
}),
|
|
9333
9350
|
});
|
|
9334
9351
|
}
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9352
|
+
/**
|
|
9353
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
9354
|
+
* inferred type of merged objects. Please
|
|
9355
|
+
* upgrade if you are experiencing issues.
|
|
9356
|
+
*/
|
|
9357
|
+
merge(merging) {
|
|
9358
|
+
const merged = new ZodObject({
|
|
9359
|
+
unknownKeys: merging._def.unknownKeys,
|
|
9360
|
+
catchall: merging._def.catchall,
|
|
9361
|
+
shape: () => ({
|
|
9362
|
+
...this._def.shape(),
|
|
9363
|
+
...merging._def.shape(),
|
|
9364
|
+
}),
|
|
9365
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9340
9366
|
});
|
|
9367
|
+
return merged;
|
|
9341
9368
|
}
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9369
|
+
// merge<
|
|
9370
|
+
// Incoming extends AnyZodObject,
|
|
9371
|
+
// Augmentation extends Incoming["shape"],
|
|
9372
|
+
// NewOutput extends {
|
|
9373
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
9374
|
+
// ? Augmentation[k]["_output"]
|
|
9375
|
+
// : k extends keyof Output
|
|
9376
|
+
// ? Output[k]
|
|
9377
|
+
// : never;
|
|
9378
|
+
// },
|
|
9379
|
+
// NewInput extends {
|
|
9380
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
9381
|
+
// ? Augmentation[k]["_input"]
|
|
9382
|
+
// : k extends keyof Input
|
|
9383
|
+
// ? Input[k]
|
|
9384
|
+
// : never;
|
|
9385
|
+
// }
|
|
9386
|
+
// >(
|
|
9387
|
+
// merging: Incoming
|
|
9388
|
+
// ): ZodObject<
|
|
9389
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
9390
|
+
// Incoming["_def"]["unknownKeys"],
|
|
9391
|
+
// Incoming["_def"]["catchall"],
|
|
9392
|
+
// NewOutput,
|
|
9393
|
+
// NewInput
|
|
9394
|
+
// > {
|
|
9395
|
+
// const merged: any = new ZodObject({
|
|
9396
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
9397
|
+
// catchall: merging._def.catchall,
|
|
9398
|
+
// shape: () =>
|
|
9399
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
9400
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9401
|
+
// }) as any;
|
|
9402
|
+
// return merged;
|
|
9403
|
+
// }
|
|
9404
|
+
setKey(key, schema) {
|
|
9405
|
+
return this.augment({ [key]: schema });
|
|
9406
|
+
}
|
|
9407
|
+
// merge<Incoming extends AnyZodObject>(
|
|
9408
|
+
// merging: Incoming
|
|
9409
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
9410
|
+
// ZodObject<
|
|
9411
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
9412
|
+
// Incoming["_def"]["unknownKeys"],
|
|
9413
|
+
// Incoming["_def"]["catchall"]
|
|
9414
|
+
// > {
|
|
9415
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
9416
|
+
// // this._def.shape(),
|
|
9417
|
+
// // merging._def.shape()
|
|
9418
|
+
// // );
|
|
9419
|
+
// const merged: any = new ZodObject({
|
|
9420
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
9421
|
+
// catchall: merging._def.catchall,
|
|
9422
|
+
// shape: () =>
|
|
9423
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
9424
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9425
|
+
// }) as any;
|
|
9426
|
+
// return merged;
|
|
9427
|
+
// }
|
|
9428
|
+
catchall(index) {
|
|
9429
|
+
return new ZodObject({
|
|
9430
|
+
...this._def,
|
|
9431
|
+
catchall: index,
|
|
9347
9432
|
});
|
|
9348
9433
|
}
|
|
9349
|
-
|
|
9350
|
-
|
|
9351
|
-
for (const
|
|
9352
|
-
if (
|
|
9353
|
-
|
|
9354
|
-
min = ch.value;
|
|
9434
|
+
pick(mask) {
|
|
9435
|
+
const shape = {};
|
|
9436
|
+
for (const key of util.objectKeys(mask)) {
|
|
9437
|
+
if (mask[key] && this.shape[key]) {
|
|
9438
|
+
shape[key] = this.shape[key];
|
|
9355
9439
|
}
|
|
9356
9440
|
}
|
|
9357
|
-
return
|
|
9441
|
+
return new ZodObject({
|
|
9442
|
+
...this._def,
|
|
9443
|
+
shape: () => shape,
|
|
9444
|
+
});
|
|
9358
9445
|
}
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
for (const
|
|
9362
|
-
if (
|
|
9363
|
-
|
|
9364
|
-
max = ch.value;
|
|
9446
|
+
omit(mask) {
|
|
9447
|
+
const shape = {};
|
|
9448
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
9449
|
+
if (!mask[key]) {
|
|
9450
|
+
shape[key] = this.shape[key];
|
|
9365
9451
|
}
|
|
9366
9452
|
}
|
|
9367
|
-
return
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
return new ZodDate({
|
|
9372
|
-
checks: [],
|
|
9373
|
-
coerce: params?.coerce || false,
|
|
9374
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
9375
|
-
...processCreateParams(params),
|
|
9376
|
-
});
|
|
9377
|
-
};
|
|
9378
|
-
class ZodSymbol extends ZodType {
|
|
9379
|
-
_parse(input) {
|
|
9380
|
-
const parsedType = this._getType(input);
|
|
9381
|
-
if (parsedType !== ZodParsedType.symbol) {
|
|
9382
|
-
const ctx = this._getOrReturnCtx(input);
|
|
9383
|
-
addIssueToContext(ctx, {
|
|
9384
|
-
code: ZodIssueCode.invalid_type,
|
|
9385
|
-
expected: ZodParsedType.symbol,
|
|
9386
|
-
received: ctx.parsedType,
|
|
9387
|
-
});
|
|
9388
|
-
return INVALID;
|
|
9389
|
-
}
|
|
9390
|
-
return OK(input.data);
|
|
9453
|
+
return new ZodObject({
|
|
9454
|
+
...this._def,
|
|
9455
|
+
shape: () => shape,
|
|
9456
|
+
});
|
|
9391
9457
|
}
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
});
|
|
9398
|
-
};
|
|
9399
|
-
class ZodUndefined extends ZodType {
|
|
9400
|
-
_parse(input) {
|
|
9401
|
-
const parsedType = this._getType(input);
|
|
9402
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
9403
|
-
const ctx = this._getOrReturnCtx(input);
|
|
9404
|
-
addIssueToContext(ctx, {
|
|
9405
|
-
code: ZodIssueCode.invalid_type,
|
|
9406
|
-
expected: ZodParsedType.undefined,
|
|
9407
|
-
received: ctx.parsedType,
|
|
9408
|
-
});
|
|
9409
|
-
return INVALID;
|
|
9410
|
-
}
|
|
9411
|
-
return OK(input.data);
|
|
9458
|
+
/**
|
|
9459
|
+
* @deprecated
|
|
9460
|
+
*/
|
|
9461
|
+
deepPartial() {
|
|
9462
|
+
return deepPartialify(this);
|
|
9412
9463
|
}
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
if (parsedType !== ZodParsedType.null) {
|
|
9424
|
-
const ctx = this._getOrReturnCtx(input);
|
|
9425
|
-
addIssueToContext(ctx, {
|
|
9426
|
-
code: ZodIssueCode.invalid_type,
|
|
9427
|
-
expected: ZodParsedType.null,
|
|
9428
|
-
received: ctx.parsedType,
|
|
9429
|
-
});
|
|
9430
|
-
return INVALID;
|
|
9464
|
+
partial(mask) {
|
|
9465
|
+
const newShape = {};
|
|
9466
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
9467
|
+
const fieldSchema = this.shape[key];
|
|
9468
|
+
if (mask && !mask[key]) {
|
|
9469
|
+
newShape[key] = fieldSchema;
|
|
9470
|
+
}
|
|
9471
|
+
else {
|
|
9472
|
+
newShape[key] = fieldSchema.optional();
|
|
9473
|
+
}
|
|
9431
9474
|
}
|
|
9432
|
-
return
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
return new ZodNull({
|
|
9437
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
9438
|
-
...processCreateParams(params),
|
|
9439
|
-
});
|
|
9440
|
-
};
|
|
9441
|
-
class ZodAny extends ZodType {
|
|
9442
|
-
constructor() {
|
|
9443
|
-
super(...arguments);
|
|
9444
|
-
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
9445
|
-
this._any = true;
|
|
9446
|
-
}
|
|
9447
|
-
_parse(input) {
|
|
9448
|
-
return OK(input.data);
|
|
9475
|
+
return new ZodObject({
|
|
9476
|
+
...this._def,
|
|
9477
|
+
shape: () => newShape,
|
|
9478
|
+
});
|
|
9449
9479
|
}
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9480
|
+
required(mask) {
|
|
9481
|
+
const newShape = {};
|
|
9482
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
9483
|
+
if (mask && !mask[key]) {
|
|
9484
|
+
newShape[key] = this.shape[key];
|
|
9485
|
+
}
|
|
9486
|
+
else {
|
|
9487
|
+
const fieldSchema = this.shape[key];
|
|
9488
|
+
let newField = fieldSchema;
|
|
9489
|
+
while (newField instanceof ZodOptional) {
|
|
9490
|
+
newField = newField._def.innerType;
|
|
9491
|
+
}
|
|
9492
|
+
newShape[key] = newField;
|
|
9493
|
+
}
|
|
9494
|
+
}
|
|
9495
|
+
return new ZodObject({
|
|
9496
|
+
...this._def,
|
|
9497
|
+
shape: () => newShape,
|
|
9498
|
+
});
|
|
9462
9499
|
}
|
|
9463
|
-
|
|
9464
|
-
return
|
|
9500
|
+
keyof() {
|
|
9501
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
9465
9502
|
}
|
|
9466
9503
|
}
|
|
9467
|
-
|
|
9468
|
-
return new
|
|
9469
|
-
|
|
9504
|
+
ZodObject.create = (shape, params) => {
|
|
9505
|
+
return new ZodObject({
|
|
9506
|
+
shape: () => shape,
|
|
9507
|
+
unknownKeys: "strip",
|
|
9508
|
+
catchall: ZodNever.create(),
|
|
9509
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9470
9510
|
...processCreateParams(params),
|
|
9471
9511
|
});
|
|
9472
9512
|
};
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
received: ctx.parsedType,
|
|
9480
|
-
});
|
|
9481
|
-
return INVALID;
|
|
9482
|
-
}
|
|
9483
|
-
}
|
|
9484
|
-
ZodNever.create = (params) => {
|
|
9485
|
-
return new ZodNever({
|
|
9486
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
9513
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
9514
|
+
return new ZodObject({
|
|
9515
|
+
shape: () => shape,
|
|
9516
|
+
unknownKeys: "strict",
|
|
9517
|
+
catchall: ZodNever.create(),
|
|
9518
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9487
9519
|
...processCreateParams(params),
|
|
9488
9520
|
});
|
|
9489
9521
|
};
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
code: ZodIssueCode.invalid_type,
|
|
9497
|
-
expected: ZodParsedType.void,
|
|
9498
|
-
received: ctx.parsedType,
|
|
9499
|
-
});
|
|
9500
|
-
return INVALID;
|
|
9501
|
-
}
|
|
9502
|
-
return OK(input.data);
|
|
9503
|
-
}
|
|
9504
|
-
}
|
|
9505
|
-
ZodVoid.create = (params) => {
|
|
9506
|
-
return new ZodVoid({
|
|
9507
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
9522
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
9523
|
+
return new ZodObject({
|
|
9524
|
+
shape,
|
|
9525
|
+
unknownKeys: "strip",
|
|
9526
|
+
catchall: ZodNever.create(),
|
|
9527
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9508
9528
|
...processCreateParams(params),
|
|
9509
9529
|
});
|
|
9510
9530
|
};
|
|
9511
|
-
class
|
|
9531
|
+
class ZodUnion extends ZodType {
|
|
9512
9532
|
_parse(input) {
|
|
9513
|
-
const { ctx
|
|
9514
|
-
const
|
|
9515
|
-
|
|
9533
|
+
const { ctx } = this._processInputParams(input);
|
|
9534
|
+
const options = this._def.options;
|
|
9535
|
+
function handleResults(results) {
|
|
9536
|
+
// return first issue-free validation if it exists
|
|
9537
|
+
for (const result of results) {
|
|
9538
|
+
if (result.result.status === "valid") {
|
|
9539
|
+
return result.result;
|
|
9540
|
+
}
|
|
9541
|
+
}
|
|
9542
|
+
for (const result of results) {
|
|
9543
|
+
if (result.result.status === "dirty") {
|
|
9544
|
+
// add issues from dirty option
|
|
9545
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
9546
|
+
return result.result;
|
|
9547
|
+
}
|
|
9548
|
+
}
|
|
9549
|
+
// return invalid
|
|
9550
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
9516
9551
|
addIssueToContext(ctx, {
|
|
9517
|
-
code: ZodIssueCode.
|
|
9518
|
-
|
|
9519
|
-
received: ctx.parsedType,
|
|
9552
|
+
code: ZodIssueCode.invalid_union,
|
|
9553
|
+
unionErrors,
|
|
9520
9554
|
});
|
|
9521
9555
|
return INVALID;
|
|
9522
9556
|
}
|
|
9523
|
-
if (
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9536
|
-
|
|
9537
|
-
|
|
9557
|
+
if (ctx.common.async) {
|
|
9558
|
+
return Promise.all(options.map(async (option) => {
|
|
9559
|
+
const childCtx = {
|
|
9560
|
+
...ctx,
|
|
9561
|
+
common: {
|
|
9562
|
+
...ctx.common,
|
|
9563
|
+
issues: [],
|
|
9564
|
+
},
|
|
9565
|
+
parent: null,
|
|
9566
|
+
};
|
|
9567
|
+
return {
|
|
9568
|
+
result: await option._parseAsync({
|
|
9569
|
+
data: ctx.data,
|
|
9570
|
+
path: ctx.path,
|
|
9571
|
+
parent: childCtx,
|
|
9572
|
+
}),
|
|
9573
|
+
ctx: childCtx,
|
|
9574
|
+
};
|
|
9575
|
+
})).then(handleResults);
|
|
9538
9576
|
}
|
|
9539
|
-
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9577
|
+
else {
|
|
9578
|
+
let dirty = undefined;
|
|
9579
|
+
const issues = [];
|
|
9580
|
+
for (const option of options) {
|
|
9581
|
+
const childCtx = {
|
|
9582
|
+
...ctx,
|
|
9583
|
+
common: {
|
|
9584
|
+
...ctx.common,
|
|
9585
|
+
issues: [],
|
|
9586
|
+
},
|
|
9587
|
+
parent: null,
|
|
9588
|
+
};
|
|
9589
|
+
const result = option._parseSync({
|
|
9590
|
+
data: ctx.data,
|
|
9591
|
+
path: ctx.path,
|
|
9592
|
+
parent: childCtx,
|
|
9548
9593
|
});
|
|
9549
|
-
status
|
|
9594
|
+
if (result.status === "valid") {
|
|
9595
|
+
return result;
|
|
9596
|
+
}
|
|
9597
|
+
else if (result.status === "dirty" && !dirty) {
|
|
9598
|
+
dirty = { result, ctx: childCtx };
|
|
9599
|
+
}
|
|
9600
|
+
if (childCtx.common.issues.length) {
|
|
9601
|
+
issues.push(childCtx.common.issues);
|
|
9602
|
+
}
|
|
9550
9603
|
}
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
addIssueToContext(ctx, {
|
|
9555
|
-
code: ZodIssueCode.too_big,
|
|
9556
|
-
maximum: def.maxLength.value,
|
|
9557
|
-
type: "array",
|
|
9558
|
-
inclusive: true,
|
|
9559
|
-
exact: false,
|
|
9560
|
-
message: def.maxLength.message,
|
|
9561
|
-
});
|
|
9562
|
-
status.dirty();
|
|
9604
|
+
if (dirty) {
|
|
9605
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
9606
|
+
return dirty.result;
|
|
9563
9607
|
}
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
})).then((result) => {
|
|
9569
|
-
return ParseStatus.mergeArray(status, result);
|
|
9608
|
+
const unionErrors = issues.map((issues) => new ZodError(issues));
|
|
9609
|
+
addIssueToContext(ctx, {
|
|
9610
|
+
code: ZodIssueCode.invalid_union,
|
|
9611
|
+
unionErrors,
|
|
9570
9612
|
});
|
|
9613
|
+
return INVALID;
|
|
9571
9614
|
}
|
|
9572
|
-
const result = [...ctx.data].map((item, i) => {
|
|
9573
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
9574
|
-
});
|
|
9575
|
-
return ParseStatus.mergeArray(status, result);
|
|
9576
|
-
}
|
|
9577
|
-
get element() {
|
|
9578
|
-
return this._def.type;
|
|
9579
|
-
}
|
|
9580
|
-
min(minLength, message) {
|
|
9581
|
-
return new ZodArray({
|
|
9582
|
-
...this._def,
|
|
9583
|
-
minLength: { value: minLength, message: errorUtil.toString(message) },
|
|
9584
|
-
});
|
|
9585
|
-
}
|
|
9586
|
-
max(maxLength, message) {
|
|
9587
|
-
return new ZodArray({
|
|
9588
|
-
...this._def,
|
|
9589
|
-
maxLength: { value: maxLength, message: errorUtil.toString(message) },
|
|
9590
|
-
});
|
|
9591
|
-
}
|
|
9592
|
-
length(len, message) {
|
|
9593
|
-
return new ZodArray({
|
|
9594
|
-
...this._def,
|
|
9595
|
-
exactLength: { value: len, message: errorUtil.toString(message) },
|
|
9596
|
-
});
|
|
9597
9615
|
}
|
|
9598
|
-
|
|
9599
|
-
return this.
|
|
9616
|
+
get options() {
|
|
9617
|
+
return this._def.options;
|
|
9600
9618
|
}
|
|
9601
9619
|
}
|
|
9602
|
-
|
|
9603
|
-
return new
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
maxLength: null,
|
|
9607
|
-
exactLength: null,
|
|
9608
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
9620
|
+
ZodUnion.create = (types, params) => {
|
|
9621
|
+
return new ZodUnion({
|
|
9622
|
+
options: types,
|
|
9623
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
9609
9624
|
...processCreateParams(params),
|
|
9610
9625
|
});
|
|
9611
9626
|
};
|
|
9612
|
-
function
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
9618
|
-
}
|
|
9619
|
-
return new ZodObject({
|
|
9620
|
-
...schema._def,
|
|
9621
|
-
shape: () => newShape,
|
|
9622
|
-
});
|
|
9623
|
-
}
|
|
9624
|
-
else if (schema instanceof ZodArray) {
|
|
9625
|
-
return new ZodArray({
|
|
9626
|
-
...schema._def,
|
|
9627
|
-
type: deepPartialify(schema.element),
|
|
9628
|
-
});
|
|
9627
|
+
function mergeValues(a, b) {
|
|
9628
|
+
const aType = getParsedType(a);
|
|
9629
|
+
const bType = getParsedType(b);
|
|
9630
|
+
if (a === b) {
|
|
9631
|
+
return { valid: true, data: a };
|
|
9629
9632
|
}
|
|
9630
|
-
else if (
|
|
9631
|
-
|
|
9633
|
+
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
9634
|
+
const bKeys = util.objectKeys(b);
|
|
9635
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
9636
|
+
const newObj = { ...a, ...b };
|
|
9637
|
+
for (const key of sharedKeys) {
|
|
9638
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
9639
|
+
if (!sharedValue.valid) {
|
|
9640
|
+
return { valid: false };
|
|
9641
|
+
}
|
|
9642
|
+
newObj[key] = sharedValue.data;
|
|
9643
|
+
}
|
|
9644
|
+
return { valid: true, data: newObj };
|
|
9632
9645
|
}
|
|
9633
|
-
else if (
|
|
9634
|
-
|
|
9646
|
+
else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
9647
|
+
if (a.length !== b.length) {
|
|
9648
|
+
return { valid: false };
|
|
9649
|
+
}
|
|
9650
|
+
const newArray = [];
|
|
9651
|
+
for (let index = 0; index < a.length; index++) {
|
|
9652
|
+
const itemA = a[index];
|
|
9653
|
+
const itemB = b[index];
|
|
9654
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
9655
|
+
if (!sharedValue.valid) {
|
|
9656
|
+
return { valid: false };
|
|
9657
|
+
}
|
|
9658
|
+
newArray.push(sharedValue.data);
|
|
9659
|
+
}
|
|
9660
|
+
return { valid: true, data: newArray };
|
|
9635
9661
|
}
|
|
9636
|
-
else if (
|
|
9637
|
-
return
|
|
9662
|
+
else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
9663
|
+
return { valid: true, data: a };
|
|
9638
9664
|
}
|
|
9639
9665
|
else {
|
|
9640
|
-
return
|
|
9666
|
+
return { valid: false };
|
|
9641
9667
|
}
|
|
9642
9668
|
}
|
|
9643
|
-
class
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
* */
|
|
9688
|
-
this.augment = this.extend;
|
|
9689
|
-
}
|
|
9690
|
-
_getCached() {
|
|
9691
|
-
if (this._cached !== null)
|
|
9692
|
-
return this._cached;
|
|
9693
|
-
const shape = this._def.shape();
|
|
9694
|
-
const keys = util.objectKeys(shape);
|
|
9695
|
-
this._cached = { shape, keys };
|
|
9696
|
-
return this._cached;
|
|
9669
|
+
class ZodIntersection extends ZodType {
|
|
9670
|
+
_parse(input) {
|
|
9671
|
+
const { status, ctx } = this._processInputParams(input);
|
|
9672
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
9673
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
9674
|
+
return INVALID;
|
|
9675
|
+
}
|
|
9676
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
9677
|
+
if (!merged.valid) {
|
|
9678
|
+
addIssueToContext(ctx, {
|
|
9679
|
+
code: ZodIssueCode.invalid_intersection_types,
|
|
9680
|
+
});
|
|
9681
|
+
return INVALID;
|
|
9682
|
+
}
|
|
9683
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
9684
|
+
status.dirty();
|
|
9685
|
+
}
|
|
9686
|
+
return { status: status.value, value: merged.data };
|
|
9687
|
+
};
|
|
9688
|
+
if (ctx.common.async) {
|
|
9689
|
+
return Promise.all([
|
|
9690
|
+
this._def.left._parseAsync({
|
|
9691
|
+
data: ctx.data,
|
|
9692
|
+
path: ctx.path,
|
|
9693
|
+
parent: ctx,
|
|
9694
|
+
}),
|
|
9695
|
+
this._def.right._parseAsync({
|
|
9696
|
+
data: ctx.data,
|
|
9697
|
+
path: ctx.path,
|
|
9698
|
+
parent: ctx,
|
|
9699
|
+
}),
|
|
9700
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
9701
|
+
}
|
|
9702
|
+
else {
|
|
9703
|
+
return handleParsed(this._def.left._parseSync({
|
|
9704
|
+
data: ctx.data,
|
|
9705
|
+
path: ctx.path,
|
|
9706
|
+
parent: ctx,
|
|
9707
|
+
}), this._def.right._parseSync({
|
|
9708
|
+
data: ctx.data,
|
|
9709
|
+
path: ctx.path,
|
|
9710
|
+
parent: ctx,
|
|
9711
|
+
}));
|
|
9712
|
+
}
|
|
9697
9713
|
}
|
|
9714
|
+
}
|
|
9715
|
+
ZodIntersection.create = (left, right, params) => {
|
|
9716
|
+
return new ZodIntersection({
|
|
9717
|
+
left: left,
|
|
9718
|
+
right: right,
|
|
9719
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
9720
|
+
...processCreateParams(params),
|
|
9721
|
+
});
|
|
9722
|
+
};
|
|
9723
|
+
// type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
|
|
9724
|
+
class ZodTuple extends ZodType {
|
|
9698
9725
|
_parse(input) {
|
|
9699
|
-
const
|
|
9700
|
-
if (parsedType !== ZodParsedType.
|
|
9701
|
-
const ctx = this._getOrReturnCtx(input);
|
|
9726
|
+
const { status, ctx } = this._processInputParams(input);
|
|
9727
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
9702
9728
|
addIssueToContext(ctx, {
|
|
9703
9729
|
code: ZodIssueCode.invalid_type,
|
|
9704
|
-
expected: ZodParsedType.
|
|
9730
|
+
expected: ZodParsedType.array,
|
|
9705
9731
|
received: ctx.parsedType,
|
|
9706
9732
|
});
|
|
9707
9733
|
return INVALID;
|
|
9708
9734
|
}
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
}
|
|
9717
|
-
}
|
|
9718
|
-
}
|
|
9719
|
-
const pairs = [];
|
|
9720
|
-
for (const key of shapeKeys) {
|
|
9721
|
-
const keyValidator = shape[key];
|
|
9722
|
-
const value = ctx.data[key];
|
|
9723
|
-
pairs.push({
|
|
9724
|
-
key: { status: "valid", value: key },
|
|
9725
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
9726
|
-
alwaysSet: key in ctx.data,
|
|
9735
|
+
if (ctx.data.length < this._def.items.length) {
|
|
9736
|
+
addIssueToContext(ctx, {
|
|
9737
|
+
code: ZodIssueCode.too_small,
|
|
9738
|
+
minimum: this._def.items.length,
|
|
9739
|
+
inclusive: true,
|
|
9740
|
+
exact: false,
|
|
9741
|
+
type: "array",
|
|
9727
9742
|
});
|
|
9743
|
+
return INVALID;
|
|
9728
9744
|
}
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
else if (unknownKeys === "strict") {
|
|
9740
|
-
if (extraKeys.length > 0) {
|
|
9741
|
-
addIssueToContext(ctx, {
|
|
9742
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
9743
|
-
keys: extraKeys,
|
|
9744
|
-
});
|
|
9745
|
-
status.dirty();
|
|
9746
|
-
}
|
|
9747
|
-
}
|
|
9748
|
-
else if (unknownKeys === "strip") ;
|
|
9749
|
-
else {
|
|
9750
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
9751
|
-
}
|
|
9752
|
-
}
|
|
9753
|
-
else {
|
|
9754
|
-
// run catchall validation
|
|
9755
|
-
const catchall = this._def.catchall;
|
|
9756
|
-
for (const key of extraKeys) {
|
|
9757
|
-
const value = ctx.data[key];
|
|
9758
|
-
pairs.push({
|
|
9759
|
-
key: { status: "valid", value: key },
|
|
9760
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
|
9761
|
-
),
|
|
9762
|
-
alwaysSet: key in ctx.data,
|
|
9763
|
-
});
|
|
9764
|
-
}
|
|
9745
|
+
const rest = this._def.rest;
|
|
9746
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
9747
|
+
addIssueToContext(ctx, {
|
|
9748
|
+
code: ZodIssueCode.too_big,
|
|
9749
|
+
maximum: this._def.items.length,
|
|
9750
|
+
inclusive: true,
|
|
9751
|
+
exact: false,
|
|
9752
|
+
type: "array",
|
|
9753
|
+
});
|
|
9754
|
+
status.dirty();
|
|
9765
9755
|
}
|
|
9756
|
+
const items = [...ctx.data]
|
|
9757
|
+
.map((item, itemIndex) => {
|
|
9758
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
9759
|
+
if (!schema)
|
|
9760
|
+
return null;
|
|
9761
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
9762
|
+
})
|
|
9763
|
+
.filter((x) => !!x); // filter nulls
|
|
9766
9764
|
if (ctx.common.async) {
|
|
9767
|
-
return Promise.
|
|
9768
|
-
.
|
|
9769
|
-
const syncPairs = [];
|
|
9770
|
-
for (const pair of pairs) {
|
|
9771
|
-
const key = await pair.key;
|
|
9772
|
-
const value = await pair.value;
|
|
9773
|
-
syncPairs.push({
|
|
9774
|
-
key,
|
|
9775
|
-
value,
|
|
9776
|
-
alwaysSet: pair.alwaysSet,
|
|
9777
|
-
});
|
|
9778
|
-
}
|
|
9779
|
-
return syncPairs;
|
|
9780
|
-
})
|
|
9781
|
-
.then((syncPairs) => {
|
|
9782
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
9765
|
+
return Promise.all(items).then((results) => {
|
|
9766
|
+
return ParseStatus.mergeArray(status, results);
|
|
9783
9767
|
});
|
|
9784
9768
|
}
|
|
9785
9769
|
else {
|
|
9786
|
-
return ParseStatus.
|
|
9770
|
+
return ParseStatus.mergeArray(status, items);
|
|
9787
9771
|
}
|
|
9788
9772
|
}
|
|
9789
|
-
get
|
|
9790
|
-
return this._def.
|
|
9791
|
-
}
|
|
9792
|
-
strict(message) {
|
|
9793
|
-
errorUtil.errToObj;
|
|
9794
|
-
return new ZodObject({
|
|
9795
|
-
...this._def,
|
|
9796
|
-
unknownKeys: "strict",
|
|
9797
|
-
...(message !== undefined
|
|
9798
|
-
? {
|
|
9799
|
-
errorMap: (issue, ctx) => {
|
|
9800
|
-
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
9801
|
-
if (issue.code === "unrecognized_keys")
|
|
9802
|
-
return {
|
|
9803
|
-
message: errorUtil.errToObj(message).message ?? defaultError,
|
|
9804
|
-
};
|
|
9805
|
-
return {
|
|
9806
|
-
message: defaultError,
|
|
9807
|
-
};
|
|
9808
|
-
},
|
|
9809
|
-
}
|
|
9810
|
-
: {}),
|
|
9811
|
-
});
|
|
9812
|
-
}
|
|
9813
|
-
strip() {
|
|
9814
|
-
return new ZodObject({
|
|
9815
|
-
...this._def,
|
|
9816
|
-
unknownKeys: "strip",
|
|
9817
|
-
});
|
|
9773
|
+
get items() {
|
|
9774
|
+
return this._def.items;
|
|
9818
9775
|
}
|
|
9819
|
-
|
|
9820
|
-
return new
|
|
9776
|
+
rest(rest) {
|
|
9777
|
+
return new ZodTuple({
|
|
9821
9778
|
...this._def,
|
|
9822
|
-
|
|
9779
|
+
rest,
|
|
9823
9780
|
});
|
|
9824
9781
|
}
|
|
9825
|
-
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
// ): ZodObject<
|
|
9830
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
9831
|
-
// Def["unknownKeys"],
|
|
9832
|
-
// Def["catchall"]
|
|
9833
|
-
// > => {
|
|
9834
|
-
// return new ZodObject({
|
|
9835
|
-
// ...def,
|
|
9836
|
-
// shape: () => ({
|
|
9837
|
-
// ...def.shape(),
|
|
9838
|
-
// ...augmentation,
|
|
9839
|
-
// }),
|
|
9840
|
-
// }) as any;
|
|
9841
|
-
// };
|
|
9842
|
-
extend(augmentation) {
|
|
9843
|
-
return new ZodObject({
|
|
9844
|
-
...this._def,
|
|
9845
|
-
shape: () => ({
|
|
9846
|
-
...this._def.shape(),
|
|
9847
|
-
...augmentation,
|
|
9848
|
-
}),
|
|
9849
|
-
});
|
|
9782
|
+
}
|
|
9783
|
+
ZodTuple.create = (schemas, params) => {
|
|
9784
|
+
if (!Array.isArray(schemas)) {
|
|
9785
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
9850
9786
|
}
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
...this._def.shape(),
|
|
9862
|
-
...merging._def.shape(),
|
|
9863
|
-
}),
|
|
9864
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9865
|
-
});
|
|
9866
|
-
return merged;
|
|
9787
|
+
return new ZodTuple({
|
|
9788
|
+
items: schemas,
|
|
9789
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
9790
|
+
rest: null,
|
|
9791
|
+
...processCreateParams(params),
|
|
9792
|
+
});
|
|
9793
|
+
};
|
|
9794
|
+
class ZodMap extends ZodType {
|
|
9795
|
+
get keySchema() {
|
|
9796
|
+
return this._def.keyType;
|
|
9867
9797
|
}
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
// Augmentation extends Incoming["shape"],
|
|
9871
|
-
// NewOutput extends {
|
|
9872
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
9873
|
-
// ? Augmentation[k]["_output"]
|
|
9874
|
-
// : k extends keyof Output
|
|
9875
|
-
// ? Output[k]
|
|
9876
|
-
// : never;
|
|
9877
|
-
// },
|
|
9878
|
-
// NewInput extends {
|
|
9879
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
9880
|
-
// ? Augmentation[k]["_input"]
|
|
9881
|
-
// : k extends keyof Input
|
|
9882
|
-
// ? Input[k]
|
|
9883
|
-
// : never;
|
|
9884
|
-
// }
|
|
9885
|
-
// >(
|
|
9886
|
-
// merging: Incoming
|
|
9887
|
-
// ): ZodObject<
|
|
9888
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
9889
|
-
// Incoming["_def"]["unknownKeys"],
|
|
9890
|
-
// Incoming["_def"]["catchall"],
|
|
9891
|
-
// NewOutput,
|
|
9892
|
-
// NewInput
|
|
9893
|
-
// > {
|
|
9894
|
-
// const merged: any = new ZodObject({
|
|
9895
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
9896
|
-
// catchall: merging._def.catchall,
|
|
9897
|
-
// shape: () =>
|
|
9898
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
9899
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9900
|
-
// }) as any;
|
|
9901
|
-
// return merged;
|
|
9902
|
-
// }
|
|
9903
|
-
setKey(key, schema) {
|
|
9904
|
-
return this.augment({ [key]: schema });
|
|
9798
|
+
get valueSchema() {
|
|
9799
|
+
return this._def.valueType;
|
|
9905
9800
|
}
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
9924
|
-
// }) as any;
|
|
9925
|
-
// return merged;
|
|
9926
|
-
// }
|
|
9927
|
-
catchall(index) {
|
|
9928
|
-
return new ZodObject({
|
|
9929
|
-
...this._def,
|
|
9930
|
-
catchall: index,
|
|
9801
|
+
_parse(input) {
|
|
9802
|
+
const { status, ctx } = this._processInputParams(input);
|
|
9803
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
9804
|
+
addIssueToContext(ctx, {
|
|
9805
|
+
code: ZodIssueCode.invalid_type,
|
|
9806
|
+
expected: ZodParsedType.map,
|
|
9807
|
+
received: ctx.parsedType,
|
|
9808
|
+
});
|
|
9809
|
+
return INVALID;
|
|
9810
|
+
}
|
|
9811
|
+
const keyType = this._def.keyType;
|
|
9812
|
+
const valueType = this._def.valueType;
|
|
9813
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
9814
|
+
return {
|
|
9815
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
9816
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
|
|
9817
|
+
};
|
|
9931
9818
|
});
|
|
9819
|
+
if (ctx.common.async) {
|
|
9820
|
+
const finalMap = new Map();
|
|
9821
|
+
return Promise.resolve().then(async () => {
|
|
9822
|
+
for (const pair of pairs) {
|
|
9823
|
+
const key = await pair.key;
|
|
9824
|
+
const value = await pair.value;
|
|
9825
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
9826
|
+
return INVALID;
|
|
9827
|
+
}
|
|
9828
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
9829
|
+
status.dirty();
|
|
9830
|
+
}
|
|
9831
|
+
finalMap.set(key.value, value.value);
|
|
9832
|
+
}
|
|
9833
|
+
return { status: status.value, value: finalMap };
|
|
9834
|
+
});
|
|
9835
|
+
}
|
|
9836
|
+
else {
|
|
9837
|
+
const finalMap = new Map();
|
|
9838
|
+
for (const pair of pairs) {
|
|
9839
|
+
const key = pair.key;
|
|
9840
|
+
const value = pair.value;
|
|
9841
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
9842
|
+
return INVALID;
|
|
9843
|
+
}
|
|
9844
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
9845
|
+
status.dirty();
|
|
9846
|
+
}
|
|
9847
|
+
finalMap.set(key.value, value.value);
|
|
9848
|
+
}
|
|
9849
|
+
return { status: status.value, value: finalMap };
|
|
9850
|
+
}
|
|
9932
9851
|
}
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9852
|
+
}
|
|
9853
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
9854
|
+
return new ZodMap({
|
|
9855
|
+
valueType,
|
|
9856
|
+
keyType,
|
|
9857
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
9858
|
+
...processCreateParams(params),
|
|
9859
|
+
});
|
|
9860
|
+
};
|
|
9861
|
+
class ZodSet extends ZodType {
|
|
9862
|
+
_parse(input) {
|
|
9863
|
+
const { status, ctx } = this._processInputParams(input);
|
|
9864
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
9865
|
+
addIssueToContext(ctx, {
|
|
9866
|
+
code: ZodIssueCode.invalid_type,
|
|
9867
|
+
expected: ZodParsedType.set,
|
|
9868
|
+
received: ctx.parsedType,
|
|
9869
|
+
});
|
|
9870
|
+
return INVALID;
|
|
9871
|
+
}
|
|
9872
|
+
const def = this._def;
|
|
9873
|
+
if (def.minSize !== null) {
|
|
9874
|
+
if (ctx.data.size < def.minSize.value) {
|
|
9875
|
+
addIssueToContext(ctx, {
|
|
9876
|
+
code: ZodIssueCode.too_small,
|
|
9877
|
+
minimum: def.minSize.value,
|
|
9878
|
+
type: "set",
|
|
9879
|
+
inclusive: true,
|
|
9880
|
+
exact: false,
|
|
9881
|
+
message: def.minSize.message,
|
|
9882
|
+
});
|
|
9883
|
+
status.dirty();
|
|
9884
|
+
}
|
|
9885
|
+
}
|
|
9886
|
+
if (def.maxSize !== null) {
|
|
9887
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
9888
|
+
addIssueToContext(ctx, {
|
|
9889
|
+
code: ZodIssueCode.too_big,
|
|
9890
|
+
maximum: def.maxSize.value,
|
|
9891
|
+
type: "set",
|
|
9892
|
+
inclusive: true,
|
|
9893
|
+
exact: false,
|
|
9894
|
+
message: def.maxSize.message,
|
|
9895
|
+
});
|
|
9896
|
+
status.dirty();
|
|
9938
9897
|
}
|
|
9939
9898
|
}
|
|
9940
|
-
|
|
9899
|
+
const valueType = this._def.valueType;
|
|
9900
|
+
function finalizeSet(elements) {
|
|
9901
|
+
const parsedSet = new Set();
|
|
9902
|
+
for (const element of elements) {
|
|
9903
|
+
if (element.status === "aborted")
|
|
9904
|
+
return INVALID;
|
|
9905
|
+
if (element.status === "dirty")
|
|
9906
|
+
status.dirty();
|
|
9907
|
+
parsedSet.add(element.value);
|
|
9908
|
+
}
|
|
9909
|
+
return { status: status.value, value: parsedSet };
|
|
9910
|
+
}
|
|
9911
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
9912
|
+
if (ctx.common.async) {
|
|
9913
|
+
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
9914
|
+
}
|
|
9915
|
+
else {
|
|
9916
|
+
return finalizeSet(elements);
|
|
9917
|
+
}
|
|
9918
|
+
}
|
|
9919
|
+
min(minSize, message) {
|
|
9920
|
+
return new ZodSet({
|
|
9941
9921
|
...this._def,
|
|
9942
|
-
|
|
9922
|
+
minSize: { value: minSize, message: errorUtil.toString(message) },
|
|
9943
9923
|
});
|
|
9944
9924
|
}
|
|
9945
|
-
|
|
9946
|
-
|
|
9947
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
9948
|
-
if (!mask[key]) {
|
|
9949
|
-
shape[key] = this.shape[key];
|
|
9950
|
-
}
|
|
9951
|
-
}
|
|
9952
|
-
return new ZodObject({
|
|
9925
|
+
max(maxSize, message) {
|
|
9926
|
+
return new ZodSet({
|
|
9953
9927
|
...this._def,
|
|
9954
|
-
|
|
9928
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) },
|
|
9955
9929
|
});
|
|
9956
9930
|
}
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
*/
|
|
9960
|
-
deepPartial() {
|
|
9961
|
-
return deepPartialify(this);
|
|
9931
|
+
size(size, message) {
|
|
9932
|
+
return this.min(size, message).max(size, message);
|
|
9962
9933
|
}
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9934
|
+
nonempty(message) {
|
|
9935
|
+
return this.min(1, message);
|
|
9936
|
+
}
|
|
9937
|
+
}
|
|
9938
|
+
ZodSet.create = (valueType, params) => {
|
|
9939
|
+
return new ZodSet({
|
|
9940
|
+
valueType,
|
|
9941
|
+
minSize: null,
|
|
9942
|
+
maxSize: null,
|
|
9943
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
9944
|
+
...processCreateParams(params),
|
|
9945
|
+
});
|
|
9946
|
+
};
|
|
9947
|
+
class ZodFunction extends ZodType {
|
|
9948
|
+
constructor() {
|
|
9949
|
+
super(...arguments);
|
|
9950
|
+
this.validate = this.implement;
|
|
9951
|
+
}
|
|
9952
|
+
_parse(input) {
|
|
9953
|
+
const { ctx } = this._processInputParams(input);
|
|
9954
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
9955
|
+
addIssueToContext(ctx, {
|
|
9956
|
+
code: ZodIssueCode.invalid_type,
|
|
9957
|
+
expected: ZodParsedType.function,
|
|
9958
|
+
received: ctx.parsedType,
|
|
9959
|
+
});
|
|
9960
|
+
return INVALID;
|
|
9973
9961
|
}
|
|
9974
|
-
|
|
9962
|
+
function makeArgsIssue(args, error) {
|
|
9963
|
+
return makeIssue({
|
|
9964
|
+
data: args,
|
|
9965
|
+
path: ctx.path,
|
|
9966
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap].filter((x) => !!x),
|
|
9967
|
+
issueData: {
|
|
9968
|
+
code: ZodIssueCode.invalid_arguments,
|
|
9969
|
+
argumentsError: error,
|
|
9970
|
+
},
|
|
9971
|
+
});
|
|
9972
|
+
}
|
|
9973
|
+
function makeReturnsIssue(returns, error) {
|
|
9974
|
+
return makeIssue({
|
|
9975
|
+
data: returns,
|
|
9976
|
+
path: ctx.path,
|
|
9977
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap].filter((x) => !!x),
|
|
9978
|
+
issueData: {
|
|
9979
|
+
code: ZodIssueCode.invalid_return_type,
|
|
9980
|
+
returnTypeError: error,
|
|
9981
|
+
},
|
|
9982
|
+
});
|
|
9983
|
+
}
|
|
9984
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
9985
|
+
const fn = ctx.data;
|
|
9986
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
9987
|
+
// Would love a way to avoid disabling this rule, but we need
|
|
9988
|
+
// an alias (using an arrow function was what caused 2651).
|
|
9989
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
9990
|
+
const me = this;
|
|
9991
|
+
return OK(async function (...args) {
|
|
9992
|
+
const error = new ZodError([]);
|
|
9993
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
9994
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
9995
|
+
throw error;
|
|
9996
|
+
});
|
|
9997
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
9998
|
+
const parsedReturns = await me._def.returns._def.type
|
|
9999
|
+
.parseAsync(result, params)
|
|
10000
|
+
.catch((e) => {
|
|
10001
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
10002
|
+
throw error;
|
|
10003
|
+
});
|
|
10004
|
+
return parsedReturns;
|
|
10005
|
+
});
|
|
10006
|
+
}
|
|
10007
|
+
else {
|
|
10008
|
+
// Would love a way to avoid disabling this rule, but we need
|
|
10009
|
+
// an alias (using an arrow function was what caused 2651).
|
|
10010
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
10011
|
+
const me = this;
|
|
10012
|
+
return OK(function (...args) {
|
|
10013
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
10014
|
+
if (!parsedArgs.success) {
|
|
10015
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
10016
|
+
}
|
|
10017
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
10018
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
10019
|
+
if (!parsedReturns.success) {
|
|
10020
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
10021
|
+
}
|
|
10022
|
+
return parsedReturns.data;
|
|
10023
|
+
});
|
|
10024
|
+
}
|
|
10025
|
+
}
|
|
10026
|
+
parameters() {
|
|
10027
|
+
return this._def.args;
|
|
10028
|
+
}
|
|
10029
|
+
returnType() {
|
|
10030
|
+
return this._def.returns;
|
|
10031
|
+
}
|
|
10032
|
+
args(...items) {
|
|
10033
|
+
return new ZodFunction({
|
|
9975
10034
|
...this._def,
|
|
9976
|
-
|
|
10035
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create()),
|
|
9977
10036
|
});
|
|
9978
10037
|
}
|
|
9979
|
-
|
|
9980
|
-
|
|
9981
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
9982
|
-
if (mask && !mask[key]) {
|
|
9983
|
-
newShape[key] = this.shape[key];
|
|
9984
|
-
}
|
|
9985
|
-
else {
|
|
9986
|
-
const fieldSchema = this.shape[key];
|
|
9987
|
-
let newField = fieldSchema;
|
|
9988
|
-
while (newField instanceof ZodOptional) {
|
|
9989
|
-
newField = newField._def.innerType;
|
|
9990
|
-
}
|
|
9991
|
-
newShape[key] = newField;
|
|
9992
|
-
}
|
|
9993
|
-
}
|
|
9994
|
-
return new ZodObject({
|
|
10038
|
+
returns(returnType) {
|
|
10039
|
+
return new ZodFunction({
|
|
9995
10040
|
...this._def,
|
|
9996
|
-
|
|
10041
|
+
returns: returnType,
|
|
9997
10042
|
});
|
|
9998
10043
|
}
|
|
9999
|
-
|
|
10000
|
-
|
|
10044
|
+
implement(func) {
|
|
10045
|
+
const validatedFunc = this.parse(func);
|
|
10046
|
+
return validatedFunc;
|
|
10047
|
+
}
|
|
10048
|
+
strictImplement(func) {
|
|
10049
|
+
const validatedFunc = this.parse(func);
|
|
10050
|
+
return validatedFunc;
|
|
10051
|
+
}
|
|
10052
|
+
static create(args, returns, params) {
|
|
10053
|
+
return new ZodFunction({
|
|
10054
|
+
args: (args ? args : ZodTuple.create([]).rest(ZodUnknown.create())),
|
|
10055
|
+
returns: returns || ZodUnknown.create(),
|
|
10056
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
10057
|
+
...processCreateParams(params),
|
|
10058
|
+
});
|
|
10001
10059
|
}
|
|
10002
10060
|
}
|
|
10003
|
-
|
|
10004
|
-
|
|
10005
|
-
|
|
10006
|
-
|
|
10007
|
-
|
|
10008
|
-
|
|
10061
|
+
class ZodLazy extends ZodType {
|
|
10062
|
+
get schema() {
|
|
10063
|
+
return this._def.getter();
|
|
10064
|
+
}
|
|
10065
|
+
_parse(input) {
|
|
10066
|
+
const { ctx } = this._processInputParams(input);
|
|
10067
|
+
const lazySchema = this._def.getter();
|
|
10068
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
10069
|
+
}
|
|
10070
|
+
}
|
|
10071
|
+
ZodLazy.create = (getter, params) => {
|
|
10072
|
+
return new ZodLazy({
|
|
10073
|
+
getter: getter,
|
|
10074
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
10009
10075
|
...processCreateParams(params),
|
|
10010
10076
|
});
|
|
10011
10077
|
};
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10017
|
-
|
|
10078
|
+
class ZodLiteral extends ZodType {
|
|
10079
|
+
_parse(input) {
|
|
10080
|
+
if (input.data !== this._def.value) {
|
|
10081
|
+
const ctx = this._getOrReturnCtx(input);
|
|
10082
|
+
addIssueToContext(ctx, {
|
|
10083
|
+
received: ctx.data,
|
|
10084
|
+
code: ZodIssueCode.invalid_literal,
|
|
10085
|
+
expected: this._def.value,
|
|
10086
|
+
});
|
|
10087
|
+
return INVALID;
|
|
10088
|
+
}
|
|
10089
|
+
return { status: "valid", value: input.data };
|
|
10090
|
+
}
|
|
10091
|
+
get value() {
|
|
10092
|
+
return this._def.value;
|
|
10093
|
+
}
|
|
10094
|
+
}
|
|
10095
|
+
ZodLiteral.create = (value, params) => {
|
|
10096
|
+
return new ZodLiteral({
|
|
10097
|
+
value: value,
|
|
10098
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
10018
10099
|
...processCreateParams(params),
|
|
10019
10100
|
});
|
|
10020
10101
|
};
|
|
10021
|
-
|
|
10022
|
-
return new
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
catchall: ZodNever.create(),
|
|
10026
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
10102
|
+
function createZodEnum(values, params) {
|
|
10103
|
+
return new ZodEnum({
|
|
10104
|
+
values,
|
|
10105
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
10027
10106
|
...processCreateParams(params),
|
|
10028
10107
|
});
|
|
10029
|
-
}
|
|
10030
|
-
class
|
|
10108
|
+
}
|
|
10109
|
+
class ZodEnum extends ZodType {
|
|
10031
10110
|
_parse(input) {
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10111
|
+
if (typeof input.data !== "string") {
|
|
10112
|
+
const ctx = this._getOrReturnCtx(input);
|
|
10113
|
+
const expectedValues = this._def.values;
|
|
10114
|
+
addIssueToContext(ctx, {
|
|
10115
|
+
expected: util.joinValues(expectedValues),
|
|
10116
|
+
received: ctx.parsedType,
|
|
10117
|
+
code: ZodIssueCode.invalid_type,
|
|
10118
|
+
});
|
|
10119
|
+
return INVALID;
|
|
10120
|
+
}
|
|
10121
|
+
if (!this._cache) {
|
|
10122
|
+
this._cache = new Set(this._def.values);
|
|
10123
|
+
}
|
|
10124
|
+
if (!this._cache.has(input.data)) {
|
|
10125
|
+
const ctx = this._getOrReturnCtx(input);
|
|
10126
|
+
const expectedValues = this._def.values;
|
|
10127
|
+
addIssueToContext(ctx, {
|
|
10128
|
+
received: ctx.data,
|
|
10129
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
10130
|
+
options: expectedValues,
|
|
10131
|
+
});
|
|
10132
|
+
return INVALID;
|
|
10133
|
+
}
|
|
10134
|
+
return OK(input.data);
|
|
10135
|
+
}
|
|
10136
|
+
get options() {
|
|
10137
|
+
return this._def.values;
|
|
10138
|
+
}
|
|
10139
|
+
get enum() {
|
|
10140
|
+
const enumValues = {};
|
|
10141
|
+
for (const val of this._def.values) {
|
|
10142
|
+
enumValues[val] = val;
|
|
10143
|
+
}
|
|
10144
|
+
return enumValues;
|
|
10145
|
+
}
|
|
10146
|
+
get Values() {
|
|
10147
|
+
const enumValues = {};
|
|
10148
|
+
for (const val of this._def.values) {
|
|
10149
|
+
enumValues[val] = val;
|
|
10150
|
+
}
|
|
10151
|
+
return enumValues;
|
|
10152
|
+
}
|
|
10153
|
+
get Enum() {
|
|
10154
|
+
const enumValues = {};
|
|
10155
|
+
for (const val of this._def.values) {
|
|
10156
|
+
enumValues[val] = val;
|
|
10157
|
+
}
|
|
10158
|
+
return enumValues;
|
|
10159
|
+
}
|
|
10160
|
+
extract(values, newDef = this._def) {
|
|
10161
|
+
return ZodEnum.create(values, {
|
|
10162
|
+
...this._def,
|
|
10163
|
+
...newDef,
|
|
10164
|
+
});
|
|
10165
|
+
}
|
|
10166
|
+
exclude(values, newDef = this._def) {
|
|
10167
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
10168
|
+
...this._def,
|
|
10169
|
+
...newDef,
|
|
10170
|
+
});
|
|
10171
|
+
}
|
|
10172
|
+
}
|
|
10173
|
+
ZodEnum.create = createZodEnum;
|
|
10174
|
+
class ZodNativeEnum extends ZodType {
|
|
10175
|
+
_parse(input) {
|
|
10176
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
10177
|
+
const ctx = this._getOrReturnCtx(input);
|
|
10178
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
10179
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
10050
10180
|
addIssueToContext(ctx, {
|
|
10051
|
-
|
|
10052
|
-
|
|
10181
|
+
expected: util.joinValues(expectedValues),
|
|
10182
|
+
received: ctx.parsedType,
|
|
10183
|
+
code: ZodIssueCode.invalid_type,
|
|
10053
10184
|
});
|
|
10054
10185
|
return INVALID;
|
|
10055
10186
|
}
|
|
10056
|
-
if (
|
|
10057
|
-
|
|
10058
|
-
const childCtx = {
|
|
10059
|
-
...ctx,
|
|
10060
|
-
common: {
|
|
10061
|
-
...ctx.common,
|
|
10062
|
-
issues: [],
|
|
10063
|
-
},
|
|
10064
|
-
parent: null,
|
|
10065
|
-
};
|
|
10066
|
-
return {
|
|
10067
|
-
result: await option._parseAsync({
|
|
10068
|
-
data: ctx.data,
|
|
10069
|
-
path: ctx.path,
|
|
10070
|
-
parent: childCtx,
|
|
10071
|
-
}),
|
|
10072
|
-
ctx: childCtx,
|
|
10073
|
-
};
|
|
10074
|
-
})).then(handleResults);
|
|
10187
|
+
if (!this._cache) {
|
|
10188
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
10075
10189
|
}
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
const issues = [];
|
|
10079
|
-
for (const option of options) {
|
|
10080
|
-
const childCtx = {
|
|
10081
|
-
...ctx,
|
|
10082
|
-
common: {
|
|
10083
|
-
...ctx.common,
|
|
10084
|
-
issues: [],
|
|
10085
|
-
},
|
|
10086
|
-
parent: null,
|
|
10087
|
-
};
|
|
10088
|
-
const result = option._parseSync({
|
|
10089
|
-
data: ctx.data,
|
|
10090
|
-
path: ctx.path,
|
|
10091
|
-
parent: childCtx,
|
|
10092
|
-
});
|
|
10093
|
-
if (result.status === "valid") {
|
|
10094
|
-
return result;
|
|
10095
|
-
}
|
|
10096
|
-
else if (result.status === "dirty" && !dirty) {
|
|
10097
|
-
dirty = { result, ctx: childCtx };
|
|
10098
|
-
}
|
|
10099
|
-
if (childCtx.common.issues.length) {
|
|
10100
|
-
issues.push(childCtx.common.issues);
|
|
10101
|
-
}
|
|
10102
|
-
}
|
|
10103
|
-
if (dirty) {
|
|
10104
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
10105
|
-
return dirty.result;
|
|
10106
|
-
}
|
|
10107
|
-
const unionErrors = issues.map((issues) => new ZodError(issues));
|
|
10190
|
+
if (!this._cache.has(input.data)) {
|
|
10191
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
10108
10192
|
addIssueToContext(ctx, {
|
|
10109
|
-
|
|
10110
|
-
|
|
10193
|
+
received: ctx.data,
|
|
10194
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
10195
|
+
options: expectedValues,
|
|
10111
10196
|
});
|
|
10112
10197
|
return INVALID;
|
|
10113
10198
|
}
|
|
10199
|
+
return OK(input.data);
|
|
10114
10200
|
}
|
|
10115
|
-
get
|
|
10116
|
-
return this._def.
|
|
10201
|
+
get enum() {
|
|
10202
|
+
return this._def.values;
|
|
10117
10203
|
}
|
|
10118
10204
|
}
|
|
10119
|
-
|
|
10120
|
-
return new
|
|
10121
|
-
|
|
10122
|
-
typeName: ZodFirstPartyTypeKind.
|
|
10205
|
+
ZodNativeEnum.create = (values, params) => {
|
|
10206
|
+
return new ZodNativeEnum({
|
|
10207
|
+
values: values,
|
|
10208
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
10123
10209
|
...processCreateParams(params),
|
|
10124
10210
|
});
|
|
10125
10211
|
};
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
if (a === b) {
|
|
10130
|
-
return { valid: true, data: a };
|
|
10131
|
-
}
|
|
10132
|
-
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
10133
|
-
const bKeys = util.objectKeys(b);
|
|
10134
|
-
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
10135
|
-
const newObj = { ...a, ...b };
|
|
10136
|
-
for (const key of sharedKeys) {
|
|
10137
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
10138
|
-
if (!sharedValue.valid) {
|
|
10139
|
-
return { valid: false };
|
|
10140
|
-
}
|
|
10141
|
-
newObj[key] = sharedValue.data;
|
|
10142
|
-
}
|
|
10143
|
-
return { valid: true, data: newObj };
|
|
10212
|
+
class ZodPromise extends ZodType {
|
|
10213
|
+
unwrap() {
|
|
10214
|
+
return this._def.type;
|
|
10144
10215
|
}
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
if (!sharedValue.valid) {
|
|
10155
|
-
return { valid: false };
|
|
10156
|
-
}
|
|
10157
|
-
newArray.push(sharedValue.data);
|
|
10216
|
+
_parse(input) {
|
|
10217
|
+
const { ctx } = this._processInputParams(input);
|
|
10218
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
10219
|
+
addIssueToContext(ctx, {
|
|
10220
|
+
code: ZodIssueCode.invalid_type,
|
|
10221
|
+
expected: ZodParsedType.promise,
|
|
10222
|
+
received: ctx.parsedType,
|
|
10223
|
+
});
|
|
10224
|
+
return INVALID;
|
|
10158
10225
|
}
|
|
10159
|
-
|
|
10226
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
10227
|
+
return OK(promisified.then((data) => {
|
|
10228
|
+
return this._def.type.parseAsync(data, {
|
|
10229
|
+
path: ctx.path,
|
|
10230
|
+
errorMap: ctx.common.contextualErrorMap,
|
|
10231
|
+
});
|
|
10232
|
+
}));
|
|
10160
10233
|
}
|
|
10161
|
-
|
|
10162
|
-
|
|
10234
|
+
}
|
|
10235
|
+
ZodPromise.create = (schema, params) => {
|
|
10236
|
+
return new ZodPromise({
|
|
10237
|
+
type: schema,
|
|
10238
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
10239
|
+
...processCreateParams(params),
|
|
10240
|
+
});
|
|
10241
|
+
};
|
|
10242
|
+
class ZodEffects extends ZodType {
|
|
10243
|
+
innerType() {
|
|
10244
|
+
return this._def.schema;
|
|
10163
10245
|
}
|
|
10164
|
-
|
|
10165
|
-
return
|
|
10246
|
+
sourceType() {
|
|
10247
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
|
|
10248
|
+
? this._def.schema.sourceType()
|
|
10249
|
+
: this._def.schema;
|
|
10166
10250
|
}
|
|
10167
|
-
}
|
|
10168
|
-
class ZodIntersection extends ZodType {
|
|
10169
10251
|
_parse(input) {
|
|
10170
10252
|
const { status, ctx } = this._processInputParams(input);
|
|
10171
|
-
const
|
|
10172
|
-
|
|
10173
|
-
|
|
10253
|
+
const effect = this._def.effect || null;
|
|
10254
|
+
const checkCtx = {
|
|
10255
|
+
addIssue: (arg) => {
|
|
10256
|
+
addIssueToContext(ctx, arg);
|
|
10257
|
+
if (arg.fatal) {
|
|
10258
|
+
status.abort();
|
|
10259
|
+
}
|
|
10260
|
+
else {
|
|
10261
|
+
status.dirty();
|
|
10262
|
+
}
|
|
10263
|
+
},
|
|
10264
|
+
get path() {
|
|
10265
|
+
return ctx.path;
|
|
10266
|
+
},
|
|
10267
|
+
};
|
|
10268
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
10269
|
+
if (effect.type === "preprocess") {
|
|
10270
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
10271
|
+
if (ctx.common.async) {
|
|
10272
|
+
return Promise.resolve(processed).then(async (processed) => {
|
|
10273
|
+
if (status.value === "aborted")
|
|
10274
|
+
return INVALID;
|
|
10275
|
+
const result = await this._def.schema._parseAsync({
|
|
10276
|
+
data: processed,
|
|
10277
|
+
path: ctx.path,
|
|
10278
|
+
parent: ctx,
|
|
10279
|
+
});
|
|
10280
|
+
if (result.status === "aborted")
|
|
10281
|
+
return INVALID;
|
|
10282
|
+
if (result.status === "dirty")
|
|
10283
|
+
return DIRTY(result.value);
|
|
10284
|
+
if (status.value === "dirty")
|
|
10285
|
+
return DIRTY(result.value);
|
|
10286
|
+
return result;
|
|
10287
|
+
});
|
|
10174
10288
|
}
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10289
|
+
else {
|
|
10290
|
+
if (status.value === "aborted")
|
|
10291
|
+
return INVALID;
|
|
10292
|
+
const result = this._def.schema._parseSync({
|
|
10293
|
+
data: processed,
|
|
10294
|
+
path: ctx.path,
|
|
10295
|
+
parent: ctx,
|
|
10296
|
+
});
|
|
10297
|
+
if (result.status === "aborted")
|
|
10298
|
+
return INVALID;
|
|
10299
|
+
if (result.status === "dirty")
|
|
10300
|
+
return DIRTY(result.value);
|
|
10301
|
+
if (status.value === "dirty")
|
|
10302
|
+
return DIRTY(result.value);
|
|
10303
|
+
return result;
|
|
10304
|
+
}
|
|
10305
|
+
}
|
|
10306
|
+
if (effect.type === "refinement") {
|
|
10307
|
+
const executeRefinement = (acc) => {
|
|
10308
|
+
const result = effect.refinement(acc, checkCtx);
|
|
10309
|
+
if (ctx.common.async) {
|
|
10310
|
+
return Promise.resolve(result);
|
|
10311
|
+
}
|
|
10312
|
+
if (result instanceof Promise) {
|
|
10313
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
10314
|
+
}
|
|
10315
|
+
return acc;
|
|
10316
|
+
};
|
|
10317
|
+
if (ctx.common.async === false) {
|
|
10318
|
+
const inner = this._def.schema._parseSync({
|
|
10319
|
+
data: ctx.data,
|
|
10320
|
+
path: ctx.path,
|
|
10321
|
+
parent: ctx,
|
|
10322
|
+
});
|
|
10323
|
+
if (inner.status === "aborted")
|
|
10324
|
+
return INVALID;
|
|
10325
|
+
if (inner.status === "dirty")
|
|
10326
|
+
status.dirty();
|
|
10327
|
+
// return value is ignored
|
|
10328
|
+
executeRefinement(inner.value);
|
|
10329
|
+
return { status: status.value, value: inner.value };
|
|
10330
|
+
}
|
|
10331
|
+
else {
|
|
10332
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
10333
|
+
if (inner.status === "aborted")
|
|
10334
|
+
return INVALID;
|
|
10335
|
+
if (inner.status === "dirty")
|
|
10336
|
+
status.dirty();
|
|
10337
|
+
return executeRefinement(inner.value).then(() => {
|
|
10338
|
+
return { status: status.value, value: inner.value };
|
|
10339
|
+
});
|
|
10179
10340
|
});
|
|
10180
|
-
return INVALID;
|
|
10181
|
-
}
|
|
10182
|
-
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
10183
|
-
status.dirty();
|
|
10184
10341
|
}
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
this._def.left._parseAsync({
|
|
10190
|
-
data: ctx.data,
|
|
10191
|
-
path: ctx.path,
|
|
10192
|
-
parent: ctx,
|
|
10193
|
-
}),
|
|
10194
|
-
this._def.right._parseAsync({
|
|
10342
|
+
}
|
|
10343
|
+
if (effect.type === "transform") {
|
|
10344
|
+
if (ctx.common.async === false) {
|
|
10345
|
+
const base = this._def.schema._parseSync({
|
|
10195
10346
|
data: ctx.data,
|
|
10196
10347
|
path: ctx.path,
|
|
10197
10348
|
parent: ctx,
|
|
10198
|
-
})
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
}
|
|
10207
|
-
|
|
10208
|
-
path: ctx.path,
|
|
10209
|
-
|
|
10210
|
-
|
|
10349
|
+
});
|
|
10350
|
+
if (!isValid(base))
|
|
10351
|
+
return INVALID;
|
|
10352
|
+
const result = effect.transform(base.value, checkCtx);
|
|
10353
|
+
if (result instanceof Promise) {
|
|
10354
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
10355
|
+
}
|
|
10356
|
+
return { status: status.value, value: result };
|
|
10357
|
+
}
|
|
10358
|
+
else {
|
|
10359
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
10360
|
+
if (!isValid(base))
|
|
10361
|
+
return INVALID;
|
|
10362
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
10363
|
+
status: status.value,
|
|
10364
|
+
value: result,
|
|
10365
|
+
}));
|
|
10366
|
+
});
|
|
10367
|
+
}
|
|
10211
10368
|
}
|
|
10369
|
+
util.assertNever(effect);
|
|
10212
10370
|
}
|
|
10213
10371
|
}
|
|
10214
|
-
|
|
10215
|
-
return new
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10372
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
10373
|
+
return new ZodEffects({
|
|
10374
|
+
schema,
|
|
10375
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
10376
|
+
effect,
|
|
10219
10377
|
...processCreateParams(params),
|
|
10220
10378
|
});
|
|
10221
10379
|
};
|
|
10222
|
-
|
|
10223
|
-
|
|
10380
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
10381
|
+
return new ZodEffects({
|
|
10382
|
+
schema,
|
|
10383
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
10384
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
10385
|
+
...processCreateParams(params),
|
|
10386
|
+
});
|
|
10387
|
+
};
|
|
10388
|
+
class ZodOptional extends ZodType {
|
|
10224
10389
|
_parse(input) {
|
|
10225
|
-
const
|
|
10226
|
-
if (
|
|
10227
|
-
|
|
10228
|
-
code: ZodIssueCode.invalid_type,
|
|
10229
|
-
expected: ZodParsedType.array,
|
|
10230
|
-
received: ctx.parsedType,
|
|
10231
|
-
});
|
|
10232
|
-
return INVALID;
|
|
10233
|
-
}
|
|
10234
|
-
if (ctx.data.length < this._def.items.length) {
|
|
10235
|
-
addIssueToContext(ctx, {
|
|
10236
|
-
code: ZodIssueCode.too_small,
|
|
10237
|
-
minimum: this._def.items.length,
|
|
10238
|
-
inclusive: true,
|
|
10239
|
-
exact: false,
|
|
10240
|
-
type: "array",
|
|
10241
|
-
});
|
|
10242
|
-
return INVALID;
|
|
10243
|
-
}
|
|
10244
|
-
const rest = this._def.rest;
|
|
10245
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
|
10246
|
-
addIssueToContext(ctx, {
|
|
10247
|
-
code: ZodIssueCode.too_big,
|
|
10248
|
-
maximum: this._def.items.length,
|
|
10249
|
-
inclusive: true,
|
|
10250
|
-
exact: false,
|
|
10251
|
-
type: "array",
|
|
10252
|
-
});
|
|
10253
|
-
status.dirty();
|
|
10254
|
-
}
|
|
10255
|
-
const items = [...ctx.data]
|
|
10256
|
-
.map((item, itemIndex) => {
|
|
10257
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
10258
|
-
if (!schema)
|
|
10259
|
-
return null;
|
|
10260
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
10261
|
-
})
|
|
10262
|
-
.filter((x) => !!x); // filter nulls
|
|
10263
|
-
if (ctx.common.async) {
|
|
10264
|
-
return Promise.all(items).then((results) => {
|
|
10265
|
-
return ParseStatus.mergeArray(status, results);
|
|
10266
|
-
});
|
|
10267
|
-
}
|
|
10268
|
-
else {
|
|
10269
|
-
return ParseStatus.mergeArray(status, items);
|
|
10390
|
+
const parsedType = this._getType(input);
|
|
10391
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
10392
|
+
return OK(undefined);
|
|
10270
10393
|
}
|
|
10394
|
+
return this._def.innerType._parse(input);
|
|
10271
10395
|
}
|
|
10272
|
-
|
|
10273
|
-
return this._def.
|
|
10274
|
-
}
|
|
10275
|
-
rest(rest) {
|
|
10276
|
-
return new ZodTuple({
|
|
10277
|
-
...this._def,
|
|
10278
|
-
rest,
|
|
10279
|
-
});
|
|
10396
|
+
unwrap() {
|
|
10397
|
+
return this._def.innerType;
|
|
10280
10398
|
}
|
|
10281
10399
|
}
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
return new ZodTuple({
|
|
10287
|
-
items: schemas,
|
|
10288
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
10289
|
-
rest: null,
|
|
10400
|
+
ZodOptional.create = (type, params) => {
|
|
10401
|
+
return new ZodOptional({
|
|
10402
|
+
innerType: type,
|
|
10403
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
10290
10404
|
...processCreateParams(params),
|
|
10291
10405
|
});
|
|
10292
10406
|
};
|
|
10293
|
-
class
|
|
10294
|
-
|
|
10295
|
-
|
|
10407
|
+
class ZodNullable extends ZodType {
|
|
10408
|
+
_parse(input) {
|
|
10409
|
+
const parsedType = this._getType(input);
|
|
10410
|
+
if (parsedType === ZodParsedType.null) {
|
|
10411
|
+
return OK(null);
|
|
10412
|
+
}
|
|
10413
|
+
return this._def.innerType._parse(input);
|
|
10296
10414
|
}
|
|
10297
|
-
|
|
10298
|
-
return this._def.
|
|
10415
|
+
unwrap() {
|
|
10416
|
+
return this._def.innerType;
|
|
10299
10417
|
}
|
|
10418
|
+
}
|
|
10419
|
+
ZodNullable.create = (type, params) => {
|
|
10420
|
+
return new ZodNullable({
|
|
10421
|
+
innerType: type,
|
|
10422
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
10423
|
+
...processCreateParams(params),
|
|
10424
|
+
});
|
|
10425
|
+
};
|
|
10426
|
+
class ZodDefault extends ZodType {
|
|
10300
10427
|
_parse(input) {
|
|
10301
|
-
const {
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
expected: ZodParsedType.map,
|
|
10306
|
-
received: ctx.parsedType,
|
|
10307
|
-
});
|
|
10308
|
-
return INVALID;
|
|
10428
|
+
const { ctx } = this._processInputParams(input);
|
|
10429
|
+
let data = ctx.data;
|
|
10430
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
10431
|
+
data = this._def.defaultValue();
|
|
10309
10432
|
}
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
10315
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
|
|
10316
|
-
};
|
|
10433
|
+
return this._def.innerType._parse({
|
|
10434
|
+
data,
|
|
10435
|
+
path: ctx.path,
|
|
10436
|
+
parent: ctx,
|
|
10317
10437
|
});
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
}
|
|
10348
|
-
|
|
10438
|
+
}
|
|
10439
|
+
removeDefault() {
|
|
10440
|
+
return this._def.innerType;
|
|
10441
|
+
}
|
|
10442
|
+
}
|
|
10443
|
+
ZodDefault.create = (type, params) => {
|
|
10444
|
+
return new ZodDefault({
|
|
10445
|
+
innerType: type,
|
|
10446
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
10447
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
10448
|
+
...processCreateParams(params),
|
|
10449
|
+
});
|
|
10450
|
+
};
|
|
10451
|
+
class ZodCatch extends ZodType {
|
|
10452
|
+
_parse(input) {
|
|
10453
|
+
const { ctx } = this._processInputParams(input);
|
|
10454
|
+
// newCtx is used to not collect issues from inner types in ctx
|
|
10455
|
+
const newCtx = {
|
|
10456
|
+
...ctx,
|
|
10457
|
+
common: {
|
|
10458
|
+
...ctx.common,
|
|
10459
|
+
issues: [],
|
|
10460
|
+
},
|
|
10461
|
+
};
|
|
10462
|
+
const result = this._def.innerType._parse({
|
|
10463
|
+
data: newCtx.data,
|
|
10464
|
+
path: newCtx.path,
|
|
10465
|
+
parent: {
|
|
10466
|
+
...newCtx,
|
|
10467
|
+
},
|
|
10468
|
+
});
|
|
10469
|
+
if (isAsync(result)) {
|
|
10470
|
+
return result.then((result) => {
|
|
10471
|
+
return {
|
|
10472
|
+
status: "valid",
|
|
10473
|
+
value: result.status === "valid"
|
|
10474
|
+
? result.value
|
|
10475
|
+
: this._def.catchValue({
|
|
10476
|
+
get error() {
|
|
10477
|
+
return new ZodError(newCtx.common.issues);
|
|
10478
|
+
},
|
|
10479
|
+
input: newCtx.data,
|
|
10480
|
+
}),
|
|
10481
|
+
};
|
|
10482
|
+
});
|
|
10483
|
+
}
|
|
10484
|
+
else {
|
|
10485
|
+
return {
|
|
10486
|
+
status: "valid",
|
|
10487
|
+
value: result.status === "valid"
|
|
10488
|
+
? result.value
|
|
10489
|
+
: this._def.catchValue({
|
|
10490
|
+
get error() {
|
|
10491
|
+
return new ZodError(newCtx.common.issues);
|
|
10492
|
+
},
|
|
10493
|
+
input: newCtx.data,
|
|
10494
|
+
}),
|
|
10495
|
+
};
|
|
10349
10496
|
}
|
|
10350
10497
|
}
|
|
10498
|
+
removeCatch() {
|
|
10499
|
+
return this._def.innerType;
|
|
10500
|
+
}
|
|
10351
10501
|
}
|
|
10352
|
-
|
|
10353
|
-
return new
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10502
|
+
ZodCatch.create = (type, params) => {
|
|
10503
|
+
return new ZodCatch({
|
|
10504
|
+
innerType: type,
|
|
10505
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
10506
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
10357
10507
|
...processCreateParams(params),
|
|
10358
10508
|
});
|
|
10359
10509
|
};
|
|
10360
|
-
class
|
|
10510
|
+
class ZodNaN extends ZodType {
|
|
10361
10511
|
_parse(input) {
|
|
10362
|
-
const
|
|
10363
|
-
if (
|
|
10512
|
+
const parsedType = this._getType(input);
|
|
10513
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
10514
|
+
const ctx = this._getOrReturnCtx(input);
|
|
10364
10515
|
addIssueToContext(ctx, {
|
|
10365
10516
|
code: ZodIssueCode.invalid_type,
|
|
10366
|
-
expected: ZodParsedType.
|
|
10517
|
+
expected: ZodParsedType.nan,
|
|
10367
10518
|
received: ctx.parsedType,
|
|
10368
10519
|
});
|
|
10369
10520
|
return INVALID;
|
|
10370
10521
|
}
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10522
|
+
return { status: "valid", value: input.data };
|
|
10523
|
+
}
|
|
10524
|
+
}
|
|
10525
|
+
ZodNaN.create = (params) => {
|
|
10526
|
+
return new ZodNaN({
|
|
10527
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
10528
|
+
...processCreateParams(params),
|
|
10529
|
+
});
|
|
10530
|
+
};
|
|
10531
|
+
class ZodBranded extends ZodType {
|
|
10532
|
+
_parse(input) {
|
|
10533
|
+
const { ctx } = this._processInputParams(input);
|
|
10534
|
+
const data = ctx.data;
|
|
10535
|
+
return this._def.type._parse({
|
|
10536
|
+
data,
|
|
10537
|
+
path: ctx.path,
|
|
10538
|
+
parent: ctx,
|
|
10539
|
+
});
|
|
10540
|
+
}
|
|
10541
|
+
unwrap() {
|
|
10542
|
+
return this._def.type;
|
|
10543
|
+
}
|
|
10544
|
+
}
|
|
10545
|
+
class ZodPipeline extends ZodType {
|
|
10546
|
+
_parse(input) {
|
|
10547
|
+
const { status, ctx } = this._processInputParams(input);
|
|
10548
|
+
if (ctx.common.async) {
|
|
10549
|
+
const handleAsync = async () => {
|
|
10550
|
+
const inResult = await this._def.in._parseAsync({
|
|
10551
|
+
data: ctx.data,
|
|
10552
|
+
path: ctx.path,
|
|
10553
|
+
parent: ctx,
|
|
10381
10554
|
});
|
|
10555
|
+
if (inResult.status === "aborted")
|
|
10556
|
+
return INVALID;
|
|
10557
|
+
if (inResult.status === "dirty") {
|
|
10558
|
+
status.dirty();
|
|
10559
|
+
return DIRTY(inResult.value);
|
|
10560
|
+
}
|
|
10561
|
+
else {
|
|
10562
|
+
return this._def.out._parseAsync({
|
|
10563
|
+
data: inResult.value,
|
|
10564
|
+
path: ctx.path,
|
|
10565
|
+
parent: ctx,
|
|
10566
|
+
});
|
|
10567
|
+
}
|
|
10568
|
+
};
|
|
10569
|
+
return handleAsync();
|
|
10570
|
+
}
|
|
10571
|
+
else {
|
|
10572
|
+
const inResult = this._def.in._parseSync({
|
|
10573
|
+
data: ctx.data,
|
|
10574
|
+
path: ctx.path,
|
|
10575
|
+
parent: ctx,
|
|
10576
|
+
});
|
|
10577
|
+
if (inResult.status === "aborted")
|
|
10578
|
+
return INVALID;
|
|
10579
|
+
if (inResult.status === "dirty") {
|
|
10382
10580
|
status.dirty();
|
|
10581
|
+
return {
|
|
10582
|
+
status: "dirty",
|
|
10583
|
+
value: inResult.value,
|
|
10584
|
+
};
|
|
10585
|
+
}
|
|
10586
|
+
else {
|
|
10587
|
+
return this._def.out._parseSync({
|
|
10588
|
+
data: inResult.value,
|
|
10589
|
+
path: ctx.path,
|
|
10590
|
+
parent: ctx,
|
|
10591
|
+
});
|
|
10383
10592
|
}
|
|
10384
10593
|
}
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10594
|
+
}
|
|
10595
|
+
static create(a, b) {
|
|
10596
|
+
return new ZodPipeline({
|
|
10597
|
+
in: a,
|
|
10598
|
+
out: b,
|
|
10599
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline,
|
|
10600
|
+
});
|
|
10601
|
+
}
|
|
10602
|
+
}
|
|
10603
|
+
class ZodReadonly extends ZodType {
|
|
10604
|
+
_parse(input) {
|
|
10605
|
+
const result = this._def.innerType._parse(input);
|
|
10606
|
+
const freeze = (data) => {
|
|
10607
|
+
if (isValid(data)) {
|
|
10608
|
+
data.value = Object.freeze(data.value);
|
|
10609
|
+
}
|
|
10610
|
+
return data;
|
|
10611
|
+
};
|
|
10612
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
10613
|
+
}
|
|
10614
|
+
unwrap() {
|
|
10615
|
+
return this._def.innerType;
|
|
10616
|
+
}
|
|
10617
|
+
}
|
|
10618
|
+
ZodReadonly.create = (type, params) => {
|
|
10619
|
+
return new ZodReadonly({
|
|
10620
|
+
innerType: type,
|
|
10621
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
10622
|
+
...processCreateParams(params),
|
|
10623
|
+
});
|
|
10624
|
+
};
|
|
10625
|
+
var ZodFirstPartyTypeKind;
|
|
10626
|
+
(function (ZodFirstPartyTypeKind) {
|
|
10627
|
+
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
10628
|
+
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
10629
|
+
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
10630
|
+
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
10631
|
+
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
10632
|
+
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
10633
|
+
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
10634
|
+
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
10635
|
+
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
10636
|
+
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
10637
|
+
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
10638
|
+
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
10639
|
+
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
10640
|
+
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
10641
|
+
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
10642
|
+
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
10643
|
+
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
10644
|
+
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
10645
|
+
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
10646
|
+
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
10647
|
+
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
10648
|
+
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
10649
|
+
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
10650
|
+
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
10651
|
+
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
10652
|
+
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
10653
|
+
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
10654
|
+
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
10655
|
+
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
10656
|
+
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
10657
|
+
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
10658
|
+
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
10659
|
+
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
10660
|
+
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
10661
|
+
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
10662
|
+
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
10663
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
10664
|
+
const stringType = ZodString.create;
|
|
10665
|
+
const booleanType = ZodBoolean.create;
|
|
10666
|
+
const anyType = ZodAny.create;
|
|
10667
|
+
ZodUnknown.create;
|
|
10668
|
+
ZodNever.create;
|
|
10669
|
+
const arrayType = ZodArray.create;
|
|
10670
|
+
const objectType = ZodObject.create;
|
|
10671
|
+
ZodUnion.create;
|
|
10672
|
+
ZodIntersection.create;
|
|
10673
|
+
ZodTuple.create;
|
|
10674
|
+
const functionType = ZodFunction.create;
|
|
10675
|
+
const lazyType = ZodLazy.create;
|
|
10676
|
+
ZodEnum.create;
|
|
10677
|
+
const nativeEnumType = ZodNativeEnum.create;
|
|
10678
|
+
ZodPromise.create;
|
|
10679
|
+
ZodOptional.create;
|
|
10680
|
+
ZodNullable.create;
|
|
10681
|
+
|
|
10682
|
+
const POPUP_ELEMENT_ID = '__integration-app-popup';
|
|
10683
|
+
const CONTAINER_ELEMENT_ID = '__integration-app-container';
|
|
10684
|
+
const CONTAINER_ELEMENT_CLASS = '__integration-app-container';
|
|
10685
|
+
const CONTAINER_ELEMENT_CLASS__LOADER = '__integration-app-container__loader';
|
|
10686
|
+
const BODY_CLASS = '__integration-app-open';
|
|
10687
|
+
const STYLES_ELEMENT_ID = '__integration-app-embed-styles';
|
|
10688
|
+
objectType({
|
|
10689
|
+
onClose: functionType().optional(),
|
|
10690
|
+
showPoweredBy: booleanType().optional(),
|
|
10691
|
+
});
|
|
10692
|
+
let IFRAME_START_SHOW_LOADER_TIME = 0;
|
|
10693
|
+
let IFRAME_SHOW_LOADER_TIMEOUT_ID;
|
|
10694
|
+
const IFRAME_SHOW_LOADER_MINIMAL_TIME = 500;
|
|
10695
|
+
const IFRAME_LAYOUT_SHIFT_TIME = 300;
|
|
10696
|
+
function showIframeLoader() {
|
|
10697
|
+
const container = getContainer();
|
|
10698
|
+
container === null || container === void 0 ? void 0 : container.classList.add(CONTAINER_ELEMENT_CLASS__LOADER);
|
|
10699
|
+
IFRAME_START_SHOW_LOADER_TIME = Date.now();
|
|
10700
|
+
}
|
|
10701
|
+
function hideIframeLoader(waitLayoutShift = IFRAME_LAYOUT_SHIFT_TIME) {
|
|
10702
|
+
if (IFRAME_SHOW_LOADER_TIMEOUT_ID) {
|
|
10703
|
+
clearTimeout(IFRAME_SHOW_LOADER_TIMEOUT_ID);
|
|
10704
|
+
}
|
|
10705
|
+
const delta = Date.now() - IFRAME_START_SHOW_LOADER_TIME;
|
|
10706
|
+
if (delta >= IFRAME_SHOW_LOADER_MINIMAL_TIME) {
|
|
10707
|
+
setTimeout(() => {
|
|
10708
|
+
const container = getContainer();
|
|
10709
|
+
container === null || container === void 0 ? void 0 : container.classList.remove(CONTAINER_ELEMENT_CLASS__LOADER);
|
|
10710
|
+
IFRAME_START_SHOW_LOADER_TIME = 0;
|
|
10711
|
+
}, waitLayoutShift);
|
|
10712
|
+
return;
|
|
10713
|
+
}
|
|
10714
|
+
else {
|
|
10715
|
+
const waitLayoutShift = delta >= IFRAME_LAYOUT_SHIFT_TIME ? 0 : IFRAME_LAYOUT_SHIFT_TIME - delta;
|
|
10716
|
+
const timeoutTime = IFRAME_SHOW_LOADER_MINIMAL_TIME - delta;
|
|
10717
|
+
IFRAME_SHOW_LOADER_TIMEOUT_ID = setTimeout(() => {
|
|
10718
|
+
hideIframeLoader(waitLayoutShift);
|
|
10719
|
+
}, timeoutTime);
|
|
10720
|
+
return;
|
|
10721
|
+
}
|
|
10722
|
+
}
|
|
10723
|
+
async function openIframe(uri, callbacks = {}, { mountTargetSelector } = {}) {
|
|
10724
|
+
close();
|
|
10725
|
+
init(mountTargetSelector);
|
|
10726
|
+
return new Promise((resolve) => {
|
|
10727
|
+
function complete(callback) {
|
|
10728
|
+
close(callback);
|
|
10729
|
+
resolve();
|
|
10730
|
+
}
|
|
10731
|
+
function doOpen() {
|
|
10732
|
+
const iframe = document.createElement('iframe');
|
|
10733
|
+
iframe.src = uri;
|
|
10734
|
+
iframe.id = POPUP_ELEMENT_ID;
|
|
10735
|
+
iframe.onload = () => {
|
|
10736
|
+
hideIframeLoader();
|
|
10737
|
+
};
|
|
10738
|
+
if (!!getContainer()) {
|
|
10739
|
+
document.body.classList.add(BODY_CLASS);
|
|
10740
|
+
showIframeLoader();
|
|
10741
|
+
appendToContainer(iframe);
|
|
10742
|
+
handleIframeUnmount(iframe);
|
|
10743
|
+
connectToChild({
|
|
10744
|
+
iframe,
|
|
10745
|
+
methods: {
|
|
10746
|
+
...callbacks,
|
|
10747
|
+
handshake: (...args) => {
|
|
10748
|
+
var _a;
|
|
10749
|
+
hideIframeLoader();
|
|
10750
|
+
(_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.handshake) === null || _a === void 0 ? void 0 : _a.call(callbacks, ...args);
|
|
10751
|
+
},
|
|
10752
|
+
close: () => complete(callbacks.onClose),
|
|
10753
|
+
},
|
|
10394
10754
|
});
|
|
10395
|
-
status.dirty();
|
|
10396
10755
|
}
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
function finalizeSet(elements) {
|
|
10400
|
-
const parsedSet = new Set();
|
|
10401
|
-
for (const element of elements) {
|
|
10402
|
-
if (element.status === "aborted")
|
|
10403
|
-
return INVALID;
|
|
10404
|
-
if (element.status === "dirty")
|
|
10405
|
-
status.dirty();
|
|
10406
|
-
parsedSet.add(element.value);
|
|
10756
|
+
else {
|
|
10757
|
+
throw Error('Membrane container element not found. Was it manually removed?');
|
|
10407
10758
|
}
|
|
10408
|
-
return { status: status.value, value: parsedSet };
|
|
10409
10759
|
}
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
10760
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
10761
|
+
doOpen();
|
|
10413
10762
|
}
|
|
10414
10763
|
else {
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
}
|
|
10418
|
-
min(minSize, message) {
|
|
10419
|
-
return new ZodSet({
|
|
10420
|
-
...this._def,
|
|
10421
|
-
minSize: { value: minSize, message: errorUtil.toString(message) },
|
|
10422
|
-
});
|
|
10423
|
-
}
|
|
10424
|
-
max(maxSize, message) {
|
|
10425
|
-
return new ZodSet({
|
|
10426
|
-
...this._def,
|
|
10427
|
-
maxSize: { value: maxSize, message: errorUtil.toString(message) },
|
|
10428
|
-
});
|
|
10429
|
-
}
|
|
10430
|
-
size(size, message) {
|
|
10431
|
-
return this.min(size, message).max(size, message);
|
|
10432
|
-
}
|
|
10433
|
-
nonempty(message) {
|
|
10434
|
-
return this.min(1, message);
|
|
10435
|
-
}
|
|
10436
|
-
}
|
|
10437
|
-
ZodSet.create = (valueType, params) => {
|
|
10438
|
-
return new ZodSet({
|
|
10439
|
-
valueType,
|
|
10440
|
-
minSize: null,
|
|
10441
|
-
maxSize: null,
|
|
10442
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
10443
|
-
...processCreateParams(params),
|
|
10444
|
-
});
|
|
10445
|
-
};
|
|
10446
|
-
class ZodLazy extends ZodType {
|
|
10447
|
-
get schema() {
|
|
10448
|
-
return this._def.getter();
|
|
10449
|
-
}
|
|
10450
|
-
_parse(input) {
|
|
10451
|
-
const { ctx } = this._processInputParams(input);
|
|
10452
|
-
const lazySchema = this._def.getter();
|
|
10453
|
-
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
10454
|
-
}
|
|
10455
|
-
}
|
|
10456
|
-
ZodLazy.create = (getter, params) => {
|
|
10457
|
-
return new ZodLazy({
|
|
10458
|
-
getter: getter,
|
|
10459
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
10460
|
-
...processCreateParams(params),
|
|
10461
|
-
});
|
|
10462
|
-
};
|
|
10463
|
-
class ZodLiteral extends ZodType {
|
|
10464
|
-
_parse(input) {
|
|
10465
|
-
if (input.data !== this._def.value) {
|
|
10466
|
-
const ctx = this._getOrReturnCtx(input);
|
|
10467
|
-
addIssueToContext(ctx, {
|
|
10468
|
-
received: ctx.data,
|
|
10469
|
-
code: ZodIssueCode.invalid_literal,
|
|
10470
|
-
expected: this._def.value,
|
|
10764
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
10765
|
+
doOpen();
|
|
10471
10766
|
});
|
|
10472
|
-
return INVALID;
|
|
10473
10767
|
}
|
|
10474
|
-
return { status: "valid", value: input.data };
|
|
10475
|
-
}
|
|
10476
|
-
get value() {
|
|
10477
|
-
return this._def.value;
|
|
10478
|
-
}
|
|
10479
|
-
}
|
|
10480
|
-
ZodLiteral.create = (value, params) => {
|
|
10481
|
-
return new ZodLiteral({
|
|
10482
|
-
value: value,
|
|
10483
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
10484
|
-
...processCreateParams(params),
|
|
10485
|
-
});
|
|
10486
|
-
};
|
|
10487
|
-
function createZodEnum(values, params) {
|
|
10488
|
-
return new ZodEnum({
|
|
10489
|
-
values,
|
|
10490
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
10491
|
-
...processCreateParams(params),
|
|
10492
10768
|
});
|
|
10493
10769
|
}
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
expected: util.joinValues(expectedValues),
|
|
10501
|
-
received: ctx.parsedType,
|
|
10502
|
-
code: ZodIssueCode.invalid_type,
|
|
10503
|
-
});
|
|
10504
|
-
return INVALID;
|
|
10505
|
-
}
|
|
10506
|
-
if (!this._cache) {
|
|
10507
|
-
this._cache = new Set(this._def.values);
|
|
10508
|
-
}
|
|
10509
|
-
if (!this._cache.has(input.data)) {
|
|
10510
|
-
const ctx = this._getOrReturnCtx(input);
|
|
10511
|
-
const expectedValues = this._def.values;
|
|
10512
|
-
addIssueToContext(ctx, {
|
|
10513
|
-
received: ctx.data,
|
|
10514
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
10515
|
-
options: expectedValues,
|
|
10516
|
-
});
|
|
10517
|
-
return INVALID;
|
|
10518
|
-
}
|
|
10519
|
-
return OK(input.data);
|
|
10520
|
-
}
|
|
10521
|
-
get options() {
|
|
10522
|
-
return this._def.values;
|
|
10523
|
-
}
|
|
10524
|
-
get enum() {
|
|
10525
|
-
const enumValues = {};
|
|
10526
|
-
for (const val of this._def.values) {
|
|
10527
|
-
enumValues[val] = val;
|
|
10770
|
+
function close(callback) {
|
|
10771
|
+
document.body.classList.remove(BODY_CLASS);
|
|
10772
|
+
if (!!getContainer()) {
|
|
10773
|
+
deleteContainer();
|
|
10774
|
+
if (callback) {
|
|
10775
|
+
callback();
|
|
10528
10776
|
}
|
|
10529
|
-
return enumValues;
|
|
10530
10777
|
}
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
return
|
|
10778
|
+
}
|
|
10779
|
+
function init(mountTargetSelector) {
|
|
10780
|
+
var _a;
|
|
10781
|
+
injectStyles(mountTargetSelector);
|
|
10782
|
+
if (!!getContainer()) {
|
|
10783
|
+
return;
|
|
10537
10784
|
}
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
enumValues[val] = val;
|
|
10542
|
-
}
|
|
10543
|
-
return enumValues;
|
|
10785
|
+
const container = createContainer();
|
|
10786
|
+
if (mountTargetSelector && document.querySelector(mountTargetSelector)) {
|
|
10787
|
+
(_a = document.querySelector(mountTargetSelector)) === null || _a === void 0 ? void 0 : _a.appendChild(container);
|
|
10544
10788
|
}
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
...this._def,
|
|
10548
|
-
...newDef,
|
|
10549
|
-
});
|
|
10789
|
+
else {
|
|
10790
|
+
document.body.appendChild(container);
|
|
10550
10791
|
}
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
}
|
|
10792
|
+
}
|
|
10793
|
+
function injectStyles(mountTargetSelector) {
|
|
10794
|
+
const hasCustomMountTarget = Boolean(mountTargetSelector && document.querySelector(mountTargetSelector));
|
|
10795
|
+
const styles = [
|
|
10796
|
+
`.${CONTAINER_ELEMENT_CLASS}:empty {
|
|
10797
|
+
display: none;
|
|
10798
|
+
}`,
|
|
10799
|
+
hasCustomMountTarget
|
|
10800
|
+
? `.${CONTAINER_ELEMENT_CLASS} {
|
|
10801
|
+
inset: 0;
|
|
10802
|
+
background: rgba(0, 0, 0, 0);
|
|
10803
|
+
transition: background 0.2s ease-out;
|
|
10804
|
+
display: flex;
|
|
10805
|
+
justify-content: center;
|
|
10806
|
+
align-items: center;
|
|
10807
|
+
width: 100%;
|
|
10808
|
+
height: 100%;
|
|
10809
|
+
}`
|
|
10810
|
+
: `.${CONTAINER_ELEMENT_CLASS} {
|
|
10811
|
+
position: fixed;
|
|
10812
|
+
inset: 0;
|
|
10813
|
+
z-index: 2147483647;
|
|
10814
|
+
display: flex;
|
|
10815
|
+
justify-content: center;
|
|
10816
|
+
align-items: center;
|
|
10817
|
+
pointer-events: auto;
|
|
10818
|
+
background: rgba(0, 0, 0, 0);
|
|
10819
|
+
transition: background 0.2s ease-out;
|
|
10820
|
+
}`,
|
|
10821
|
+
`.${CONTAINER_ELEMENT_CLASS}.${CONTAINER_ELEMENT_CLASS__LOADER} {
|
|
10822
|
+
background: rgba(0, 0, 0, 0.8);
|
|
10823
|
+
}`,
|
|
10824
|
+
`.${CONTAINER_ELEMENT_CLASS}.${CONTAINER_ELEMENT_CLASS__LOADER}::before {
|
|
10825
|
+
${hasCustomMountTarget ? 'position: absolute;' : ''}
|
|
10826
|
+
content: "";
|
|
10827
|
+
width: 5rem;
|
|
10828
|
+
height: 4rem;
|
|
10829
|
+
background-image: url('data:image/svg+xml,%3Csvg viewBox="0 0 32 22" fill="%23000" xmlns="http://www.w3.org/2000/svg" %3E%3Cdefs%3E%3Cmask id="a"%3E%3Crect width="100%25" height="100%25" fill="%23fff" /%3E%3Cpath d="M11.8 13.12a3 3 0 0 1 0-4.24l7.08-7.07a3 3 0 0 1 4.24 0l7.07 7.07a3 3 0 0 1 0 4.24l-7.07 7.07a3 3 0 0 1-4.24 0l-7.07-7.07Z"%3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 21 11" to="-360 21 11" /%3E%3C/path%3E%3C/mask%3E%3Cmask id="b"%3E%3Crect width="100%25" height="100%25" fill="%23fff"/%3E%3Cpath fill-rule="evenodd" clip-rule="evenodd" d="M1.8 8.88a3 3 0 0 0 0 4.24l7.08 7.07a3 3 0 0 0 4.24 0l7.07-7.07a3 3 0 0 0 0-4.24L13.12 1.8a3 3 0 0 0-4.24 0L1.8 8.88Zm.71.7a2 2 0 0 0 0 2.83L9.6 19.5a2 2 0 0 0 2.82 0l7.08-7.08a2 2 0 0 0 0-2.82l-7.1-7.1a2 2 0 0 0-2.82 0L2.5 9.6Z" %3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 11 11" to="720 11 11" /%3E%3C/path%3E%3C/mask%3E%3C/defs%3E%3Cg mask="url(%23a)"%3E%3Cpath fill-rule="evenodd" clip-rule="evenodd" d="M1.8 8.88a3 3 0 0 0 0 4.24l7.08 7.07a3 3 0 0 0 4.24 0l7.07-7.07a3 3 0 0 0 0-4.24L13.12 1.8a3 3 0 0 0-4.24 0L1.8 8.88Zm.71.7a2 2 0 0 0 0 2.83L9.6 19.5a2 2 0 0 0 2.82 0l7.08-7.08a2 2 0 0 0 0-2.82l-7.1-7.1a2 2 0 0 0-2.82 0L2.5 9.6Z"%0A%3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 11 11" to="720 11 11" /%3E%3C/path%3E%3C/g%3E%3Cg mask="url(%23b)"%3E%3Cpath d="M11.8 13.12a3 3 0 0 1 0-4.24l7.08-7.07a3 3 0 0 1 4.24 0l7.07 7.07a3 3 0 0 1 0 4.24l-7.07 7.07a3 3 0 0 1-4.24 0l-7.07-7.07Z"%3E%3CanimateTransform attributeName="transform" attributeType="XML" type="rotate" repeatCount="indefinite" calcMode="spline" keyTimes="0;1" dur="5s" keySplines="0 0 0.1 1" from="0 21 11" to="-360 21 11" /%3E%3C/path%3E%3C/g%3E%3C/svg%3E');
|
|
10830
|
+
background-size: contain;
|
|
10831
|
+
background-repeat: no-repeat;
|
|
10832
|
+
background-position: center;
|
|
10833
|
+
filter: invert(1);
|
|
10834
|
+
}`,
|
|
10835
|
+
`.${CONTAINER_ELEMENT_CLASS} iframe {
|
|
10836
|
+
${hasCustomMountTarget ? '' : 'position: absolute;'}
|
|
10837
|
+
width: 100%;
|
|
10838
|
+
height: 100%;
|
|
10839
|
+
border-width: 0;
|
|
10840
|
+
|
|
10841
|
+
/* fix transparent bg, because iframe document has light scheme */
|
|
10842
|
+
color-scheme: light;
|
|
10843
|
+
}`,
|
|
10844
|
+
`.${CONTAINER_ELEMENT_CLASS}.${CONTAINER_ELEMENT_CLASS__LOADER} iframe {
|
|
10845
|
+
visibility: hidden;
|
|
10846
|
+
}`,
|
|
10847
|
+
!hasCustomMountTarget
|
|
10848
|
+
? `body.${BODY_CLASS} {
|
|
10849
|
+
overflow: hidden;
|
|
10850
|
+
}`
|
|
10851
|
+
: '',
|
|
10852
|
+
];
|
|
10853
|
+
let styleElement = document.getElementById(STYLES_ELEMENT_ID);
|
|
10854
|
+
if (!styleElement) {
|
|
10855
|
+
styleElement = document.createElement('style');
|
|
10856
|
+
styleElement.id = STYLES_ELEMENT_ID;
|
|
10857
|
+
styleElement.type = 'text/css';
|
|
10858
|
+
document.head.appendChild(styleElement);
|
|
10556
10859
|
}
|
|
10860
|
+
styleElement.textContent = styles.join('\n');
|
|
10557
10861
|
}
|
|
10558
|
-
|
|
10559
|
-
|
|
10560
|
-
|
|
10561
|
-
|
|
10562
|
-
const ctx = this._getOrReturnCtx(input);
|
|
10563
|
-
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
10564
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
10565
|
-
addIssueToContext(ctx, {
|
|
10566
|
-
expected: util.joinValues(expectedValues),
|
|
10567
|
-
received: ctx.parsedType,
|
|
10568
|
-
code: ZodIssueCode.invalid_type,
|
|
10569
|
-
});
|
|
10570
|
-
return INVALID;
|
|
10571
|
-
}
|
|
10572
|
-
if (!this._cache) {
|
|
10573
|
-
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
10574
|
-
}
|
|
10575
|
-
if (!this._cache.has(input.data)) {
|
|
10576
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
10577
|
-
addIssueToContext(ctx, {
|
|
10578
|
-
received: ctx.data,
|
|
10579
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
10580
|
-
options: expectedValues,
|
|
10581
|
-
});
|
|
10582
|
-
return INVALID;
|
|
10583
|
-
}
|
|
10584
|
-
return OK(input.data);
|
|
10862
|
+
function removeInjectedStyles() {
|
|
10863
|
+
const stylesElement = document.getElementById(STYLES_ELEMENT_ID);
|
|
10864
|
+
if (stylesElement) {
|
|
10865
|
+
stylesElement.remove();
|
|
10585
10866
|
}
|
|
10586
|
-
|
|
10587
|
-
|
|
10867
|
+
}
|
|
10868
|
+
function createContainer() {
|
|
10869
|
+
const container = document.createElement('div');
|
|
10870
|
+
container.id = CONTAINER_ELEMENT_ID;
|
|
10871
|
+
container.classList.add(CONTAINER_ELEMENT_CLASS);
|
|
10872
|
+
return container;
|
|
10873
|
+
}
|
|
10874
|
+
function getContainer() {
|
|
10875
|
+
return document.getElementById(CONTAINER_ELEMENT_ID);
|
|
10876
|
+
}
|
|
10877
|
+
function appendToContainer(el) {
|
|
10878
|
+
const container = getContainer();
|
|
10879
|
+
container === null || container === void 0 ? void 0 : container.appendChild(el);
|
|
10880
|
+
}
|
|
10881
|
+
function deleteContainer() {
|
|
10882
|
+
const container = getContainer();
|
|
10883
|
+
if (container) {
|
|
10884
|
+
container.remove();
|
|
10588
10885
|
}
|
|
10886
|
+
removeInjectedStyles();
|
|
10589
10887
|
}
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10888
|
+
function handleIframeUnmount(iframe) {
|
|
10889
|
+
const observer = new MutationObserver((mutationsList) => {
|
|
10890
|
+
for (const mutation of mutationsList) {
|
|
10891
|
+
for (const removedNode of mutation.removedNodes) {
|
|
10892
|
+
if (removedNode instanceof HTMLElement && removedNode.id === POPUP_ELEMENT_ID) {
|
|
10893
|
+
observer.disconnect();
|
|
10894
|
+
deleteContainer();
|
|
10895
|
+
return;
|
|
10896
|
+
}
|
|
10897
|
+
}
|
|
10898
|
+
}
|
|
10595
10899
|
});
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10900
|
+
const parent = iframe.parentNode;
|
|
10901
|
+
if (parent) {
|
|
10902
|
+
observer.observe(parent, {
|
|
10903
|
+
childList: true,
|
|
10904
|
+
});
|
|
10600
10905
|
}
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
10604
|
-
addIssueToContext(ctx, {
|
|
10605
|
-
code: ZodIssueCode.invalid_type,
|
|
10606
|
-
expected: ZodParsedType.promise,
|
|
10607
|
-
received: ctx.parsedType,
|
|
10608
|
-
});
|
|
10609
|
-
return INVALID;
|
|
10610
|
-
}
|
|
10611
|
-
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
10612
|
-
return OK(promisified.then((data) => {
|
|
10613
|
-
return this._def.type.parseAsync(data, {
|
|
10614
|
-
path: ctx.path,
|
|
10615
|
-
errorMap: ctx.common.contextualErrorMap,
|
|
10616
|
-
});
|
|
10617
|
-
}));
|
|
10906
|
+
else {
|
|
10907
|
+
console.warn(`iframe with ID "${POPUP_ELEMENT_ID}" has no parent node`);
|
|
10618
10908
|
}
|
|
10619
10909
|
}
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
return this._def.schema;
|
|
10910
|
+
|
|
10911
|
+
class ConnectionLevelElementAccessor {
|
|
10912
|
+
constructor(client, connectionSelector, selector, elementKey, query) {
|
|
10913
|
+
this.client = client;
|
|
10914
|
+
this.connectionSelector = connectionSelector;
|
|
10915
|
+
this.selector = selector;
|
|
10916
|
+
this.elementKey = elementKey;
|
|
10917
|
+
this.query = query;
|
|
10918
|
+
this.endpoint = `/connections/${this.connectionSelector}/${elementKey}/${selector}`;
|
|
10630
10919
|
}
|
|
10631
|
-
|
|
10632
|
-
return this.
|
|
10633
|
-
? this._def.schema.sourceType()
|
|
10634
|
-
: this._def.schema;
|
|
10920
|
+
uri(path = '', query = {}) {
|
|
10921
|
+
return this.endpoint + path + '?' + qs.stringify({ ...this.query, ...query });
|
|
10635
10922
|
}
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
|
|
10655
|
-
|
|
10656
|
-
|
|
10657
|
-
|
|
10658
|
-
|
|
10659
|
-
return INVALID;
|
|
10660
|
-
const result = await this._def.schema._parseAsync({
|
|
10661
|
-
data: processed,
|
|
10662
|
-
path: ctx.path,
|
|
10663
|
-
parent: ctx,
|
|
10664
|
-
});
|
|
10665
|
-
if (result.status === "aborted")
|
|
10666
|
-
return INVALID;
|
|
10667
|
-
if (result.status === "dirty")
|
|
10668
|
-
return DIRTY(result.value);
|
|
10669
|
-
if (status.value === "dirty")
|
|
10670
|
-
return DIRTY(result.value);
|
|
10671
|
-
return result;
|
|
10672
|
-
});
|
|
10673
|
-
}
|
|
10674
|
-
else {
|
|
10675
|
-
if (status.value === "aborted")
|
|
10676
|
-
return INVALID;
|
|
10677
|
-
const result = this._def.schema._parseSync({
|
|
10678
|
-
data: processed,
|
|
10679
|
-
path: ctx.path,
|
|
10680
|
-
parent: ctx,
|
|
10681
|
-
});
|
|
10682
|
-
if (result.status === "aborted")
|
|
10683
|
-
return INVALID;
|
|
10684
|
-
if (result.status === "dirty")
|
|
10685
|
-
return DIRTY(result.value);
|
|
10686
|
-
if (status.value === "dirty")
|
|
10687
|
-
return DIRTY(result.value);
|
|
10688
|
-
return result;
|
|
10689
|
-
}
|
|
10690
|
-
}
|
|
10691
|
-
if (effect.type === "refinement") {
|
|
10692
|
-
const executeRefinement = (acc) => {
|
|
10693
|
-
const result = effect.refinement(acc, checkCtx);
|
|
10694
|
-
if (ctx.common.async) {
|
|
10695
|
-
return Promise.resolve(result);
|
|
10696
|
-
}
|
|
10697
|
-
if (result instanceof Promise) {
|
|
10698
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
10699
|
-
}
|
|
10700
|
-
return acc;
|
|
10701
|
-
};
|
|
10702
|
-
if (ctx.common.async === false) {
|
|
10703
|
-
const inner = this._def.schema._parseSync({
|
|
10704
|
-
data: ctx.data,
|
|
10705
|
-
path: ctx.path,
|
|
10706
|
-
parent: ctx,
|
|
10707
|
-
});
|
|
10708
|
-
if (inner.status === "aborted")
|
|
10709
|
-
return INVALID;
|
|
10710
|
-
if (inner.status === "dirty")
|
|
10711
|
-
status.dirty();
|
|
10712
|
-
// return value is ignored
|
|
10713
|
-
executeRefinement(inner.value);
|
|
10714
|
-
return { status: status.value, value: inner.value };
|
|
10715
|
-
}
|
|
10716
|
-
else {
|
|
10717
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
10718
|
-
if (inner.status === "aborted")
|
|
10719
|
-
return INVALID;
|
|
10720
|
-
if (inner.status === "dirty")
|
|
10721
|
-
status.dirty();
|
|
10722
|
-
return executeRefinement(inner.value).then(() => {
|
|
10723
|
-
return { status: status.value, value: inner.value };
|
|
10724
|
-
});
|
|
10725
|
-
});
|
|
10726
|
-
}
|
|
10727
|
-
}
|
|
10728
|
-
if (effect.type === "transform") {
|
|
10729
|
-
if (ctx.common.async === false) {
|
|
10730
|
-
const base = this._def.schema._parseSync({
|
|
10731
|
-
data: ctx.data,
|
|
10732
|
-
path: ctx.path,
|
|
10733
|
-
parent: ctx,
|
|
10734
|
-
});
|
|
10735
|
-
if (!isValid(base))
|
|
10736
|
-
return INVALID;
|
|
10737
|
-
const result = effect.transform(base.value, checkCtx);
|
|
10738
|
-
if (result instanceof Promise) {
|
|
10739
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
10740
|
-
}
|
|
10741
|
-
return { status: status.value, value: result };
|
|
10742
|
-
}
|
|
10743
|
-
else {
|
|
10744
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
10745
|
-
if (!isValid(base))
|
|
10746
|
-
return INVALID;
|
|
10747
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
10748
|
-
status: status.value,
|
|
10749
|
-
value: result,
|
|
10750
|
-
}));
|
|
10751
|
-
});
|
|
10752
|
-
}
|
|
10753
|
-
}
|
|
10754
|
-
util.assertNever(effect);
|
|
10923
|
+
getUniqueIdentifier() {
|
|
10924
|
+
return this.endpoint;
|
|
10925
|
+
}
|
|
10926
|
+
async get(query = {}) {
|
|
10927
|
+
return this.client.get(this.uri('', query));
|
|
10928
|
+
}
|
|
10929
|
+
async create() {
|
|
10930
|
+
return this.client.put(this.uri());
|
|
10931
|
+
}
|
|
10932
|
+
async patch(data) {
|
|
10933
|
+
return this.client.patch(this.uri(), data);
|
|
10934
|
+
}
|
|
10935
|
+
async put(data) {
|
|
10936
|
+
return this.client.put(this.uri(), data);
|
|
10937
|
+
}
|
|
10938
|
+
async archive() {
|
|
10939
|
+
return this.client.delete(this.uri());
|
|
10940
|
+
}
|
|
10941
|
+
async reset() {
|
|
10942
|
+
return this.client.post(this.uri('/reset'));
|
|
10943
|
+
}
|
|
10944
|
+
async setup() {
|
|
10945
|
+
return this.client.post(this.uri('/setup'));
|
|
10755
10946
|
}
|
|
10756
10947
|
}
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
...processCreateParams(params),
|
|
10763
|
-
});
|
|
10764
|
-
};
|
|
10765
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
10766
|
-
return new ZodEffects({
|
|
10767
|
-
schema,
|
|
10768
|
-
effect: { type: "preprocess", transform: preprocess },
|
|
10769
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
10770
|
-
...processCreateParams(params),
|
|
10771
|
-
});
|
|
10772
|
-
};
|
|
10773
|
-
class ZodOptional extends ZodType {
|
|
10774
|
-
_parse(input) {
|
|
10775
|
-
const parsedType = this._getType(input);
|
|
10776
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
10777
|
-
return OK(undefined);
|
|
10778
|
-
}
|
|
10779
|
-
return this._def.innerType._parse(input);
|
|
10948
|
+
class ConnectionLevelElementsListAccessor {
|
|
10949
|
+
constructor(client, connectionSelector, elementKey) {
|
|
10950
|
+
this.client = client;
|
|
10951
|
+
this.connectionSelector = connectionSelector;
|
|
10952
|
+
this.elementKey = elementKey;
|
|
10780
10953
|
}
|
|
10781
|
-
|
|
10782
|
-
|
|
10954
|
+
async list(query) {
|
|
10955
|
+
const endpoint = `/connections/${this.connectionSelector}/${this.elementKey}?${qs.stringify(query !== null && query !== void 0 ? query : {})}`;
|
|
10956
|
+
return this.client.get(endpoint);
|
|
10783
10957
|
}
|
|
10784
10958
|
}
|
|
10785
|
-
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
...processCreateParams(params),
|
|
10790
|
-
});
|
|
10791
|
-
};
|
|
10792
|
-
class ZodNullable extends ZodType {
|
|
10793
|
-
_parse(input) {
|
|
10794
|
-
const parsedType = this._getType(input);
|
|
10795
|
-
if (parsedType === ZodParsedType.null) {
|
|
10796
|
-
return OK(null);
|
|
10797
|
-
}
|
|
10798
|
-
return this._def.innerType._parse(input);
|
|
10959
|
+
|
|
10960
|
+
class ActionInstancesAccessor extends ElementInstanceListAccessor {
|
|
10961
|
+
constructor(client) {
|
|
10962
|
+
super(client, 'action-instances');
|
|
10799
10963
|
}
|
|
10800
|
-
|
|
10801
|
-
|
|
10964
|
+
}
|
|
10965
|
+
class ActionInstanceAccessor extends ElementInstanceAccessor {
|
|
10966
|
+
constructor(client, selector) {
|
|
10967
|
+
super({
|
|
10968
|
+
client,
|
|
10969
|
+
instancePath: 'action-instance',
|
|
10970
|
+
selector,
|
|
10971
|
+
});
|
|
10972
|
+
this.client = client;
|
|
10973
|
+
}
|
|
10974
|
+
async setup() {
|
|
10975
|
+
await this.client.post(this.getPath('setup'));
|
|
10976
|
+
}
|
|
10977
|
+
async reset() {
|
|
10978
|
+
await this.client.post(this.getPath('reset'));
|
|
10979
|
+
}
|
|
10980
|
+
async run(input) {
|
|
10981
|
+
return this.client.post(this.getPath('run'), input);
|
|
10982
|
+
}
|
|
10983
|
+
async open({ onClose = () => { } } = {}) {
|
|
10984
|
+
const id = await this.getId();
|
|
10985
|
+
const uri = await this.client.getEmbedUri(`action-instances/${id}/configuration`);
|
|
10986
|
+
return openIframe(uri, { onClose });
|
|
10802
10987
|
}
|
|
10803
10988
|
}
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10989
|
+
class ConnectionLevelActionAccessor extends ConnectionLevelElementAccessor {
|
|
10990
|
+
constructor(client, connectionSelector, actionSelector, query) {
|
|
10991
|
+
super(client, connectionSelector, actionSelector, 'actions', query);
|
|
10992
|
+
this.client = client;
|
|
10993
|
+
this.connectionSelector = connectionSelector;
|
|
10994
|
+
this.actionSelector = actionSelector;
|
|
10995
|
+
this.query = query;
|
|
10996
|
+
}
|
|
10997
|
+
async run(input) {
|
|
10998
|
+
return this.client.post(this.uri('/run'), input);
|
|
10999
|
+
}
|
|
11000
|
+
}
|
|
11001
|
+
class ConnectionLevelActionsAccessor extends ConnectionLevelElementsListAccessor {
|
|
11002
|
+
constructor(client, connectionSelector) {
|
|
11003
|
+
super(client, connectionSelector, 'actions');
|
|
11004
|
+
this.client = client;
|
|
11005
|
+
this.connectionSelector = connectionSelector;
|
|
11006
|
+
}
|
|
11007
|
+
}
|
|
11008
|
+
|
|
11009
|
+
class DataSourcesAccessor extends ElementListAccessor {
|
|
11010
|
+
constructor(client) {
|
|
11011
|
+
super(client, 'data-sources');
|
|
11012
|
+
}
|
|
11013
|
+
}
|
|
11014
|
+
class DataSourceAccessor extends ElementAccessor {
|
|
11015
|
+
constructor(client, selector) {
|
|
11016
|
+
super({
|
|
11017
|
+
client,
|
|
11018
|
+
selector,
|
|
11019
|
+
path: 'data-source',
|
|
10822
11020
|
});
|
|
10823
11021
|
}
|
|
10824
|
-
|
|
10825
|
-
return this.
|
|
11022
|
+
async apply(integrationKeys) {
|
|
11023
|
+
return await this.options.client.post(this.getPath('apply'), {
|
|
11024
|
+
integrationKeys,
|
|
11025
|
+
});
|
|
11026
|
+
}
|
|
11027
|
+
async setup() {
|
|
11028
|
+
await this.options.client.post(this.getPath('setup'));
|
|
11029
|
+
}
|
|
11030
|
+
async reset() {
|
|
11031
|
+
return await this.options.client.post(this.getPath('reset'));
|
|
10826
11032
|
}
|
|
10827
11033
|
}
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
// newCtx is used to not collect issues from inner types in ctx
|
|
10840
|
-
const newCtx = {
|
|
10841
|
-
...ctx,
|
|
10842
|
-
common: {
|
|
10843
|
-
...ctx.common,
|
|
10844
|
-
issues: [],
|
|
10845
|
-
},
|
|
10846
|
-
};
|
|
10847
|
-
const result = this._def.innerType._parse({
|
|
10848
|
-
data: newCtx.data,
|
|
10849
|
-
path: newCtx.path,
|
|
10850
|
-
parent: {
|
|
10851
|
-
...newCtx,
|
|
10852
|
-
},
|
|
11034
|
+
class DataSourceInstancesAccessor extends ElementInstanceListAccessor {
|
|
11035
|
+
constructor(client) {
|
|
11036
|
+
super(client, 'data-source-instances');
|
|
11037
|
+
}
|
|
11038
|
+
}
|
|
11039
|
+
class DataSourceInstanceAccessor extends ElementInstanceAccessor {
|
|
11040
|
+
constructor(client, selector) {
|
|
11041
|
+
super({
|
|
11042
|
+
client,
|
|
11043
|
+
instancePath: 'data-source-instance',
|
|
11044
|
+
selector,
|
|
10853
11045
|
});
|
|
10854
|
-
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
11046
|
+
this.client = client;
|
|
11047
|
+
}
|
|
11048
|
+
async setup() {
|
|
11049
|
+
await this.client.post(this.getPath('setup'));
|
|
11050
|
+
}
|
|
11051
|
+
async reset() {
|
|
11052
|
+
await this.client.post(this.getPath('reset'));
|
|
11053
|
+
}
|
|
11054
|
+
async openConfiguration({ onClose = () => { } } = {}) {
|
|
11055
|
+
const id = await this.getId();
|
|
11056
|
+
const uri = await this.client.getEmbedUri(`data-source-instances/${id}/configuration`);
|
|
11057
|
+
return openIframe(uri, {
|
|
11058
|
+
onClose,
|
|
11059
|
+
});
|
|
11060
|
+
}
|
|
11061
|
+
async unifiedFieldsToNative(unifiedFields) {
|
|
11062
|
+
return this.client.post(this.getPath('unified-fields-to-native'), unifiedFields);
|
|
11063
|
+
}
|
|
11064
|
+
async getCollection() {
|
|
11065
|
+
return this.client.get(this.getPath('collection'));
|
|
11066
|
+
}
|
|
11067
|
+
async listRecords(request = {}) {
|
|
11068
|
+
return this.client.post(this.getPath('collection/list'), request);
|
|
11069
|
+
}
|
|
11070
|
+
async matchRecord(request) {
|
|
11071
|
+
return this.client.post(this.getPath('collection/match'), request);
|
|
11072
|
+
}
|
|
11073
|
+
async searchRecords(request) {
|
|
11074
|
+
return this.client.post(this.getPath('collection/search'), request);
|
|
11075
|
+
}
|
|
11076
|
+
async findRecordById(request) {
|
|
11077
|
+
const data = typeof request === 'string' ? { id: request } : request;
|
|
11078
|
+
return this.client.post(this.getPath('collection/find-by-id'), data);
|
|
11079
|
+
}
|
|
11080
|
+
async createRecord(request) {
|
|
11081
|
+
return this.client.post(this.getPath('collection/create'), request);
|
|
10882
11082
|
}
|
|
10883
|
-
|
|
10884
|
-
return this.
|
|
11083
|
+
async updateRecord(request) {
|
|
11084
|
+
return this.client.post(this.getPath(`collection/update`), request);
|
|
11085
|
+
}
|
|
11086
|
+
async deleteRecord(request) {
|
|
11087
|
+
const data = typeof request === 'string' ? { id: request } : request;
|
|
11088
|
+
return this.client.post(this.getPath(`collection/delete`), data);
|
|
11089
|
+
}
|
|
11090
|
+
async findRecords(request = {}) {
|
|
11091
|
+
return this.client.post(this.getPath('collection/find'), request);
|
|
10885
11092
|
}
|
|
10886
11093
|
}
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
});
|
|
10894
|
-
};
|
|
10895
|
-
class ZodNaN extends ZodType {
|
|
10896
|
-
_parse(input) {
|
|
10897
|
-
const parsedType = this._getType(input);
|
|
10898
|
-
if (parsedType !== ZodParsedType.nan) {
|
|
10899
|
-
const ctx = this._getOrReturnCtx(input);
|
|
10900
|
-
addIssueToContext(ctx, {
|
|
10901
|
-
code: ZodIssueCode.invalid_type,
|
|
10902
|
-
expected: ZodParsedType.nan,
|
|
10903
|
-
received: ctx.parsedType,
|
|
10904
|
-
});
|
|
10905
|
-
return INVALID;
|
|
10906
|
-
}
|
|
10907
|
-
return { status: "valid", value: input.data };
|
|
11094
|
+
class IntegrationLevelDataSourceAccessor extends IntegrationLevelElementAccessor {
|
|
11095
|
+
constructor(client, integrationSelector, dataSourceSelector) {
|
|
11096
|
+
super(client, integrationSelector, dataSourceSelector, 'data-sources');
|
|
11097
|
+
this.client = client;
|
|
11098
|
+
this.integrationSelector = integrationSelector;
|
|
11099
|
+
this.dataSourceSelector = dataSourceSelector;
|
|
10908
11100
|
}
|
|
10909
11101
|
}
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
};
|
|
10916
|
-
class ZodBranded extends ZodType {
|
|
10917
|
-
_parse(input) {
|
|
10918
|
-
const { ctx } = this._processInputParams(input);
|
|
10919
|
-
const data = ctx.data;
|
|
10920
|
-
return this._def.type._parse({
|
|
10921
|
-
data,
|
|
10922
|
-
path: ctx.path,
|
|
10923
|
-
parent: ctx,
|
|
10924
|
-
});
|
|
11102
|
+
class IntegrationLevelDataSourcesListAccessor extends IntegrationLevelElementsListAccessor {
|
|
11103
|
+
constructor(client, integrationSelector) {
|
|
11104
|
+
super(client, integrationSelector, 'data-sources');
|
|
11105
|
+
this.client = client;
|
|
11106
|
+
this.integrationSelector = integrationSelector;
|
|
10925
11107
|
}
|
|
10926
|
-
|
|
10927
|
-
|
|
11108
|
+
}
|
|
11109
|
+
class ConnectionLevelDataSourceAccessor extends ConnectionLevelElementAccessor {
|
|
11110
|
+
constructor(client, connectionSelector, dataSourceSelector, query) {
|
|
11111
|
+
super(client, connectionSelector, dataSourceSelector, 'data-sources', query);
|
|
11112
|
+
this.client = client;
|
|
11113
|
+
this.connectionSelector = connectionSelector;
|
|
11114
|
+
this.dataSourceSelector = dataSourceSelector;
|
|
11115
|
+
this.query = query;
|
|
11116
|
+
}
|
|
11117
|
+
async openConfiguration(options) {
|
|
11118
|
+
var _a;
|
|
11119
|
+
const instance = await this.get({ autoCreate: true });
|
|
11120
|
+
const uri = await this.client.getEmbedUri(`data-source-instances/${instance.id}/configuration`);
|
|
11121
|
+
const onClose = (_a = options === null || options === void 0 ? void 0 : options.onClose) !== null && _a !== void 0 ? _a : (() => { });
|
|
11122
|
+
return openIframe(uri, { onClose });
|
|
10928
11123
|
}
|
|
10929
11124
|
}
|
|
10930
|
-
class
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
const inResult = await this._def.in._parseAsync({
|
|
10936
|
-
data: ctx.data,
|
|
10937
|
-
path: ctx.path,
|
|
10938
|
-
parent: ctx,
|
|
10939
|
-
});
|
|
10940
|
-
if (inResult.status === "aborted")
|
|
10941
|
-
return INVALID;
|
|
10942
|
-
if (inResult.status === "dirty") {
|
|
10943
|
-
status.dirty();
|
|
10944
|
-
return DIRTY(inResult.value);
|
|
10945
|
-
}
|
|
10946
|
-
else {
|
|
10947
|
-
return this._def.out._parseAsync({
|
|
10948
|
-
data: inResult.value,
|
|
10949
|
-
path: ctx.path,
|
|
10950
|
-
parent: ctx,
|
|
10951
|
-
});
|
|
10952
|
-
}
|
|
10953
|
-
};
|
|
10954
|
-
return handleAsync();
|
|
10955
|
-
}
|
|
10956
|
-
else {
|
|
10957
|
-
const inResult = this._def.in._parseSync({
|
|
10958
|
-
data: ctx.data,
|
|
10959
|
-
path: ctx.path,
|
|
10960
|
-
parent: ctx,
|
|
10961
|
-
});
|
|
10962
|
-
if (inResult.status === "aborted")
|
|
10963
|
-
return INVALID;
|
|
10964
|
-
if (inResult.status === "dirty") {
|
|
10965
|
-
status.dirty();
|
|
10966
|
-
return {
|
|
10967
|
-
status: "dirty",
|
|
10968
|
-
value: inResult.value,
|
|
10969
|
-
};
|
|
10970
|
-
}
|
|
10971
|
-
else {
|
|
10972
|
-
return this._def.out._parseSync({
|
|
10973
|
-
data: inResult.value,
|
|
10974
|
-
path: ctx.path,
|
|
10975
|
-
parent: ctx,
|
|
10976
|
-
});
|
|
10977
|
-
}
|
|
10978
|
-
}
|
|
11125
|
+
class ConnectionLevelDataSourcesAccessor extends ConnectionLevelElementsListAccessor {
|
|
11126
|
+
constructor(client, connectionSelector) {
|
|
11127
|
+
super(client, connectionSelector, 'data-sources');
|
|
11128
|
+
this.client = client;
|
|
11129
|
+
this.connectionSelector = connectionSelector;
|
|
10979
11130
|
}
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
11131
|
+
}
|
|
11132
|
+
|
|
11133
|
+
class FieldMappingInstancesAccessor extends ElementInstanceListAccessor {
|
|
11134
|
+
constructor(client) {
|
|
11135
|
+
super(client, 'field-mapping-instances');
|
|
11136
|
+
}
|
|
11137
|
+
}
|
|
11138
|
+
class FieldMappingInstanceAccessor extends ElementInstanceAccessor {
|
|
11139
|
+
constructor(client, selector) {
|
|
11140
|
+
super({
|
|
11141
|
+
client,
|
|
11142
|
+
instancePath: 'field-mapping-instance',
|
|
11143
|
+
selector,
|
|
11144
|
+
});
|
|
11145
|
+
this.client = client;
|
|
11146
|
+
}
|
|
11147
|
+
async setup() {
|
|
11148
|
+
const id = await this.getId();
|
|
11149
|
+
return this.client.post(`/field-mapping-instances/${id}/setup`);
|
|
11150
|
+
}
|
|
11151
|
+
async reset() {
|
|
11152
|
+
const id = await this.getId();
|
|
11153
|
+
return this.client.post(`/field-mapping-instances/${id}/reset`);
|
|
11154
|
+
}
|
|
11155
|
+
async openConfiguration({ onClose = () => { } } = {}) {
|
|
11156
|
+
const id = await this.getId();
|
|
11157
|
+
const uri = await this.client.getEmbedUri(`field-mapping-instances/${id}/configuration`);
|
|
11158
|
+
return openIframe(uri, {
|
|
11159
|
+
onClose,
|
|
10985
11160
|
});
|
|
10986
11161
|
}
|
|
10987
11162
|
}
|
|
10988
|
-
class
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
return data;
|
|
10996
|
-
};
|
|
10997
|
-
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
11163
|
+
class ConnectionLevelFieldMappingAccessor extends ConnectionLevelElementAccessor {
|
|
11164
|
+
constructor(client, connectionSelector, fieldMappingSelector, query) {
|
|
11165
|
+
super(client, connectionSelector, fieldMappingSelector, 'field-mappings', query);
|
|
11166
|
+
this.client = client;
|
|
11167
|
+
this.connectionSelector = connectionSelector;
|
|
11168
|
+
this.fieldMappingSelector = fieldMappingSelector;
|
|
11169
|
+
this.query = query;
|
|
10998
11170
|
}
|
|
10999
|
-
|
|
11000
|
-
|
|
11171
|
+
async openConfiguration({ onClose } = {}) {
|
|
11172
|
+
const instance = await this.get({ autoCreate: true });
|
|
11173
|
+
const uri = await this.client.getEmbedUri(`field-mapping-instances/${instance.id}/configuration`);
|
|
11174
|
+
return openIframe(uri, { onClose: onClose !== null && onClose !== void 0 ? onClose : (() => { }) });
|
|
11175
|
+
}
|
|
11176
|
+
}
|
|
11177
|
+
class ConnectionLevelFieldMappingsAccessor extends ConnectionLevelElementsListAccessor {
|
|
11178
|
+
constructor(client, connectionSelector) {
|
|
11179
|
+
super(client, connectionSelector, 'field-mappings');
|
|
11180
|
+
this.client = client;
|
|
11181
|
+
this.connectionSelector = connectionSelector;
|
|
11001
11182
|
}
|
|
11002
11183
|
}
|
|
11003
|
-
ZodReadonly.create = (type, params) => {
|
|
11004
|
-
return new ZodReadonly({
|
|
11005
|
-
innerType: type,
|
|
11006
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
11007
|
-
...processCreateParams(params),
|
|
11008
|
-
});
|
|
11009
|
-
};
|
|
11010
|
-
var ZodFirstPartyTypeKind;
|
|
11011
|
-
(function (ZodFirstPartyTypeKind) {
|
|
11012
|
-
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
11013
|
-
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
11014
|
-
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
11015
|
-
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
11016
|
-
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
11017
|
-
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
11018
|
-
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
11019
|
-
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
11020
|
-
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
11021
|
-
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
11022
|
-
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
11023
|
-
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
11024
|
-
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
11025
|
-
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
11026
|
-
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
11027
|
-
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
11028
|
-
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
11029
|
-
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
11030
|
-
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
11031
|
-
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
11032
|
-
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
11033
|
-
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
11034
|
-
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
11035
|
-
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
11036
|
-
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
11037
|
-
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
11038
|
-
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
11039
|
-
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
11040
|
-
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
11041
|
-
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
11042
|
-
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
11043
|
-
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
11044
|
-
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
11045
|
-
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
11046
|
-
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
11047
|
-
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
11048
|
-
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
11049
|
-
const stringType = ZodString.create;
|
|
11050
|
-
const anyType = ZodAny.create;
|
|
11051
|
-
ZodNever.create;
|
|
11052
|
-
const arrayType = ZodArray.create;
|
|
11053
|
-
const objectType = ZodObject.create;
|
|
11054
|
-
ZodUnion.create;
|
|
11055
|
-
ZodIntersection.create;
|
|
11056
|
-
ZodTuple.create;
|
|
11057
|
-
const lazyType = ZodLazy.create;
|
|
11058
|
-
ZodEnum.create;
|
|
11059
|
-
const nativeEnumType = ZodNativeEnum.create;
|
|
11060
|
-
ZodPromise.create;
|
|
11061
|
-
ZodOptional.create;
|
|
11062
|
-
ZodNullable.create;
|
|
11063
11184
|
|
|
11064
11185
|
var ErrorType;
|
|
11065
11186
|
(function (ErrorType) {
|
|
@@ -16144,6 +16265,13 @@
|
|
|
16144
16265
|
async delete(uri, data, options) {
|
|
16145
16266
|
return this.makeApiRequest('DELETE', { ...(options !== null && options !== void 0 ? options : {}), url: uri, data });
|
|
16146
16267
|
}
|
|
16268
|
+
async createEventSource(uri, queryParams) {
|
|
16269
|
+
const token = await this.getToken();
|
|
16270
|
+
const allParams = { ...queryParams, token };
|
|
16271
|
+
const queryString = qs.stringify(omitBy(allParams, isEmptyValue));
|
|
16272
|
+
const urlWithToken = `${this.apiUri}/${uri}?${queryString}`;
|
|
16273
|
+
return new EventSource(urlWithToken);
|
|
16274
|
+
}
|
|
16147
16275
|
async getEmbedUri(page, pageParams, options) {
|
|
16148
16276
|
var _a;
|
|
16149
16277
|
const paramsWithToken = {
|
|
@@ -16336,6 +16464,9 @@
|
|
|
16336
16464
|
get scenarios() {
|
|
16337
16465
|
return new ScenariosAccessor(this);
|
|
16338
16466
|
}
|
|
16467
|
+
async createEventSource(uri, queryParams) {
|
|
16468
|
+
return super.createEventSource(uri, queryParams);
|
|
16469
|
+
}
|
|
16339
16470
|
async connectionRequest(connectionId, uri, data) {
|
|
16340
16471
|
return this.post(`connections/${connectionId}/execute-request`, {
|
|
16341
16472
|
key: uri,
|