@cargo-ai/utils 1.0.4
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/build/array.js +52 -0
- package/build/collection.js +155 -0
- package/build/components.js +56 -0
- package/build/cron.js +19 -0
- package/build/delay.js +52 -0
- package/build/hooks/index.js +35 -0
- package/build/hooks/useClickOutside.js +46 -0
- package/build/hooks/useCountAnimation.js +34 -0
- package/build/hooks/useDeviceType.js +54 -0
- package/build/hooks/useEventListener.js +27 -0
- package/build/hooks/useHeight.js +26 -0
- package/build/hooks/usePictureInPicture.js +126 -0
- package/build/hooks/useResizeObserver.js +35 -0
- package/build/hooks/useScrollPosition.js +22 -0
- package/build/hooks/useStepper.js +138 -0
- package/build/hooks/useStorageState.js +110 -0
- package/build/hooks/useVideoPlayer/VideoManager.js +78 -0
- package/build/hooks/useVideoPlayer/index.js +5 -0
- package/build/hooks/useVideoPlayer/useVideoPlayer.js +100 -0
- package/build/hooks/useWillUnmountEffect.js +13 -0
- package/build/index.js +28 -0
- package/build/json.js +81 -0
- package/build/random.js +7 -0
- package/build/src/array.d.ts +16 -0
- package/build/src/array.d.ts.map +1 -0
- package/build/src/array.js +81 -0
- package/build/src/base64.d.ts +3 -0
- package/build/src/base64.d.ts.map +1 -0
- package/build/src/base64.js +6 -0
- package/build/src/bytes.d.ts +7 -0
- package/build/src/bytes.d.ts.map +1 -0
- package/build/src/bytes.js +71 -0
- package/build/src/collection/deepMergeObjects.d.ts +2 -0
- package/build/src/collection/deepMergeObjects.d.ts.map +1 -0
- package/build/src/collection/deepMergeObjects.js +30 -0
- package/build/src/collection/index.d.ts +2 -0
- package/build/src/collection/index.d.ts.map +1 -0
- package/build/src/collection/index.js +1 -0
- package/build/src/collection.d.ts +22 -0
- package/build/src/collection.d.ts.map +1 -0
- package/build/src/collection.js +210 -0
- package/build/src/colors.d.ts +2 -0
- package/build/src/colors.d.ts.map +1 -0
- package/build/src/colors.js +14 -0
- package/build/src/components.d.ts +4 -0
- package/build/src/components.js +45 -0
- package/build/src/credits.d.ts +7 -0
- package/build/src/credits.d.ts.map +1 -0
- package/build/src/credits.js +88 -0
- package/build/src/cron.d.ts +3 -0
- package/build/src/cron.d.ts.map +1 -0
- package/build/src/cron.js +16 -0
- package/build/src/date/getContextTimezone.d.ts +2 -0
- package/build/src/date/getContextTimezone.d.ts.map +1 -0
- package/build/src/date/getContextTimezone.js +3 -0
- package/build/src/date/getDate.d.ts +8 -0
- package/build/src/date/getDate.d.ts.map +1 -0
- package/build/src/date/getDate.js +25 -0
- package/build/src/date/getDateString.d.ts +8 -0
- package/build/src/date/getDateString.d.ts.map +1 -0
- package/build/src/date/getDateString.js +13 -0
- package/build/src/date/getDatesDifferenceString.d.ts +2 -0
- package/build/src/date/getDatesDifferenceString.d.ts.map +1 -0
- package/build/src/date/getDatesDifferenceString.js +17 -0
- package/build/src/date/getTimeFromNowString.d.ts +2 -0
- package/build/src/date/getTimeFromNowString.d.ts.map +1 -0
- package/build/src/date/getTimeFromNowString.js +8 -0
- package/build/src/date/getTimezoneHoursOffset.d.ts +2 -0
- package/build/src/date/getTimezoneHoursOffset.d.ts.map +1 -0
- package/build/src/date/getTimezoneHoursOffset.js +7 -0
- package/build/src/date/getTimezoneOffsetString.d.ts +2 -0
- package/build/src/date/getTimezoneOffsetString.d.ts.map +1 -0
- package/build/src/date/getTimezoneOffsetString.js +8 -0
- package/build/src/date/index.d.ts +8 -0
- package/build/src/date/index.d.ts.map +1 -0
- package/build/src/date/index.js +7 -0
- package/build/src/date.d.ts +13 -0
- package/build/src/date.d.ts.map +1 -0
- package/build/src/date.js +14 -0
- package/build/src/delay.d.ts +7 -0
- package/build/src/delay.d.ts.map +1 -0
- package/build/src/delay.js +19 -0
- package/build/src/expression/getExpressionNodesReferences.d.ts +17 -0
- package/build/src/expression/getExpressionNodesReferences.d.ts.map +1 -0
- package/build/src/expression/getExpressionNodesReferences.js +71 -0
- package/build/src/expression/getObjectAccessKeysBeforeCursor.d.ts +17 -0
- package/build/src/expression/getObjectAccessKeysBeforeCursor.d.ts.map +1 -0
- package/build/src/expression/getObjectAccessKeysBeforeCursor.js +97 -0
- package/build/src/expression/index.d.ts +3 -0
- package/build/src/expression/index.d.ts.map +1 -0
- package/build/src/expression/index.js +2 -0
- package/build/src/expression/jsonSchema.d.ts +4 -0
- package/build/src/expression/jsonSchema.d.ts.map +1 -0
- package/build/src/expression/jsonSchema.js +85 -0
- package/build/src/expression/matchIsExpression.d.ts +2 -0
- package/build/src/expression/matchIsExpression.d.ts.map +1 -0
- package/build/src/expression/matchIsExpression.js +10 -0
- package/build/src/expression/matchIsExpressionObject.d.ts +2 -0
- package/build/src/expression/matchIsExpressionObject.d.ts.map +1 -0
- package/build/src/expression/matchIsExpressionObject.js +10 -0
- package/build/src/expression/matchIsExpressionString.d.ts +2 -0
- package/build/src/expression/matchIsExpressionString.d.ts.map +1 -0
- package/build/src/expression/matchIsExpressionString.js +4 -0
- package/build/src/gclid.d.ts +4 -0
- package/build/src/gclid.d.ts.map +1 -0
- package/build/src/gclid.js +30 -0
- package/build/src/hooks/index.d.ts +12 -0
- package/build/src/hooks/index.js +12 -0
- package/build/src/hooks/useClickOutside.d.ts +4 -0
- package/build/src/hooks/useClickOutside.js +42 -0
- package/build/src/hooks/useCountAnimation.d.ts +1 -0
- package/build/src/hooks/useCountAnimation.js +30 -0
- package/build/src/hooks/useDeviceType.d.ts +2 -0
- package/build/src/hooks/useDeviceType.js +50 -0
- package/build/src/hooks/useEventListener.d.ts +6 -0
- package/build/src/hooks/useEventListener.js +23 -0
- package/build/src/hooks/useHeight.d.ts +2 -0
- package/build/src/hooks/useHeight.js +20 -0
- package/build/src/hooks/usePictureInPicture.d.ts +9 -0
- package/build/src/hooks/usePictureInPicture.js +60 -0
- package/build/src/hooks/useResizeObserver.d.ts +4 -0
- package/build/src/hooks/useResizeObserver.js +31 -0
- package/build/src/hooks/useScrollPosition.d.ts +5 -0
- package/build/src/hooks/useScrollPosition.js +18 -0
- package/build/src/hooks/useStepper.d.ts +26 -0
- package/build/src/hooks/useStepper.js +136 -0
- package/build/src/hooks/useStorageState.d.ts +12 -0
- package/build/src/hooks/useStorageState.js +53 -0
- package/build/src/hooks/useVideoPlayer/VideoManager.d.ts +18 -0
- package/build/src/hooks/useVideoPlayer/VideoManager.js +72 -0
- package/build/src/hooks/useVideoPlayer/index.d.ts +1 -0
- package/build/src/hooks/useVideoPlayer/index.js +1 -0
- package/build/src/hooks/useVideoPlayer/useVideoPlayer.d.ts +15 -0
- package/build/src/hooks/useVideoPlayer/useVideoPlayer.js +96 -0
- package/build/src/hooks/useWillUnmountEffect.d.ts +1 -0
- package/build/src/hooks/useWillUnmountEffect.js +8 -0
- package/build/src/index.d.ts +27 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +26 -0
- package/build/src/integration.d.ts +14 -0
- package/build/src/integration.d.ts.map +1 -0
- package/build/src/integration.js +72 -0
- package/build/src/json/castToJsonType.d.ts +5 -0
- package/build/src/json/castToJsonType.d.ts.map +1 -0
- package/build/src/json/castToJsonType.js +58 -0
- package/build/src/json/cleanJson.d.ts +3 -0
- package/build/src/json/cleanJson.d.ts.map +1 -0
- package/build/src/json/cleanJson.js +18 -0
- package/build/src/json/constants.d.ts +3 -0
- package/build/src/json/constants.d.ts.map +1 -0
- package/build/src/json/constants.js +9 -0
- package/build/src/json/getJsonType.d.ts +3 -0
- package/build/src/json/getJsonType.d.ts.map +1 -0
- package/build/src/json/getJsonType.js +24 -0
- package/build/src/json/index.d.ts +8 -0
- package/build/src/json/index.d.ts.map +1 -0
- package/build/src/json/index.js +7 -0
- package/build/src/json/isJson.d.ts +2 -0
- package/build/src/json/isJson.d.ts.map +1 -0
- package/build/src/json/isJson.js +9 -0
- package/build/src/json/isJsonSchemaEmpty.d.ts +3 -0
- package/build/src/json/isJsonSchemaEmpty.d.ts.map +1 -0
- package/build/src/json/isJsonSchemaEmpty.js +7 -0
- package/build/src/json/stringifyJson.d.ts +2 -0
- package/build/src/json/stringifyJson.d.ts.map +1 -0
- package/build/src/json/stringifyJson.js +6 -0
- package/build/src/json/types.d.ts +2 -0
- package/build/src/json/types.d.ts.map +1 -0
- package/build/src/json/types.js +1 -0
- package/build/src/json.d.ts +13 -0
- package/build/src/json.d.ts.map +1 -0
- package/build/src/json.js +107 -0
- package/build/src/jsonSchema/index.d.ts +10 -0
- package/build/src/jsonSchema/index.d.ts.map +1 -0
- package/build/src/jsonSchema/index.js +198 -0
- package/build/src/jsonSchema.d.ts +5 -0
- package/build/src/jsonSchema.d.ts.map +1 -0
- package/build/src/jsonSchema.js +73 -0
- package/build/src/number/formatCredits.d.ts +2 -0
- package/build/src/number/formatCredits.d.ts.map +1 -0
- package/build/src/number/formatCredits.js +7 -0
- package/build/src/number/formatPrice.d.ts +2 -0
- package/build/src/number/formatPrice.d.ts.map +1 -0
- package/build/src/number/formatPrice.js +8 -0
- package/build/src/number/getNumberWithMaxDecimals.d.ts +2 -0
- package/build/src/number/getNumberWithMaxDecimals.d.ts.map +1 -0
- package/build/src/number/getNumberWithMaxDecimals.js +3 -0
- package/build/src/number/index.d.ts +4 -0
- package/build/src/number/index.d.ts.map +1 -0
- package/build/src/number/index.js +3 -0
- package/build/src/poll.d.ts +5 -0
- package/build/src/poll.d.ts.map +1 -0
- package/build/src/poll.js +30 -0
- package/build/src/random.d.ts +2 -0
- package/build/src/random.d.ts.map +1 -0
- package/build/src/random.js +3 -0
- package/build/src/schema.d.ts +24 -0
- package/build/src/schema.d.ts.map +1 -0
- package/build/src/schema.js +315 -0
- package/build/src/searchInTree.d.ts +46 -0
- package/build/src/searchInTree.d.ts.map +1 -0
- package/build/src/searchInTree.js +67 -0
- package/build/src/storage.d.ts +13 -0
- package/build/src/storage.d.ts.map +1 -0
- package/build/src/storage.js +169 -0
- package/build/src/string/capitalizeFirstLetter.d.ts +2 -0
- package/build/src/string/capitalizeFirstLetter.d.ts.map +1 -0
- package/build/src/string/capitalizeFirstLetter.js +3 -0
- package/build/src/string/findAllIndexOf.d.ts +2 -0
- package/build/src/string/findAllIndexOf.d.ts.map +1 -0
- package/build/src/string/findAllIndexOf.js +13 -0
- package/build/src/string/getHash.d.ts +2 -0
- package/build/src/string/getHash.d.ts.map +1 -0
- package/build/src/string/getHash.js +9 -0
- package/build/src/string/index.d.ts +5 -0
- package/build/src/string/index.d.ts.map +1 -0
- package/build/src/string/index.js +4 -0
- package/build/src/string/sentenceCase.d.ts +2 -0
- package/build/src/string/sentenceCase.d.ts.map +1 -0
- package/build/src/string/sentenceCase.js +38 -0
- package/build/src/string.d.ts +2 -0
- package/build/src/string.d.ts.map +1 -0
- package/build/src/string.js +3 -0
- package/build/src/type.d.ts +10 -0
- package/build/src/type.js +1 -0
- package/build/src/types.d.ts +22 -0
- package/build/src/types.d.ts.map +1 -0
- package/build/src/types.js +1 -0
- package/build/src/user.d.ts +3 -0
- package/build/src/user.d.ts.map +1 -0
- package/build/src/user.js +7 -0
- package/build/src/validation/index.d.ts +2 -0
- package/build/src/validation/index.d.ts.map +1 -0
- package/build/src/validation/index.js +1 -0
- package/build/src/validation/matchIsObjectLike.d.ts +2 -0
- package/build/src/validation/matchIsObjectLike.d.ts.map +1 -0
- package/build/src/validation/matchIsObjectLike.js +4 -0
- package/build/src/vm.d.ts +1 -0
- package/build/src/vm.js +32 -0
- package/build/src/zod/index.d.ts +14 -0
- package/build/src/zod/index.d.ts.map +1 -0
- package/build/src/zod/index.js +210 -0
- package/build/src/zod.d.ts +8 -0
- package/build/src/zod.d.ts.map +1 -0
- package/build/src/zod.js +89 -0
- package/build/storage.js +285 -0
- package/build/string.js +17 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/type.js +2 -0
- package/build/user.js +12 -0
- package/package.json +50 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { del as removeIndexedDB, get as getIndexedDB, set as setIndexedDB, } from "idb-keyval";
|
|
2
|
+
let cachedIsLocalStorageSupported = undefined;
|
|
3
|
+
let cachedIsIndexedDBSupportedPromise = undefined;
|
|
4
|
+
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
|
|
5
|
+
export const matchIsLocalStorageSupported = () => {
|
|
6
|
+
if (cachedIsLocalStorageSupported !== undefined) {
|
|
7
|
+
return cachedIsLocalStorageSupported;
|
|
8
|
+
}
|
|
9
|
+
const mod = "modernizr";
|
|
10
|
+
try {
|
|
11
|
+
window.localStorage.setItem(mod, mod);
|
|
12
|
+
window.localStorage.removeItem(mod);
|
|
13
|
+
cachedIsLocalStorageSupported = true;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
cachedIsLocalStorageSupported = false;
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/indexeddb.js
|
|
22
|
+
export const matchIsIndexedDBSupported = async () => {
|
|
23
|
+
if (cachedIsIndexedDBSupportedPromise !== undefined) {
|
|
24
|
+
return cachedIsIndexedDBSupportedPromise;
|
|
25
|
+
}
|
|
26
|
+
const matchIsCreateDatabaseSupported = async (indexeddb, testDBName) => {
|
|
27
|
+
try {
|
|
28
|
+
const isSupported = await new Promise((resolve) => {
|
|
29
|
+
const req = indexeddb.open(testDBName);
|
|
30
|
+
req.onsuccess = () => {
|
|
31
|
+
resolve(true);
|
|
32
|
+
};
|
|
33
|
+
req.onerror = (event) => {
|
|
34
|
+
if (req.error &&
|
|
35
|
+
(req.error.name === "InvalidStateError" ||
|
|
36
|
+
req.error.name === "UnknownError")) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
resolve(false);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
resolve(true);
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
return isSupported;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const matchIsDeleteDatabaseSupported = async (indexeddb, testDBName) => {
|
|
51
|
+
try {
|
|
52
|
+
const isSupported = await new Promise((resolve) => {
|
|
53
|
+
const deleteReq = indexeddb.deleteDatabase(testDBName);
|
|
54
|
+
deleteReq.onsuccess = () => {
|
|
55
|
+
resolve(true);
|
|
56
|
+
};
|
|
57
|
+
deleteReq.onerror = () => {
|
|
58
|
+
resolve(false);
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
return isSupported;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
let indexeddb = null;
|
|
68
|
+
try {
|
|
69
|
+
// Firefox throws a Security Error when cookies are disabled
|
|
70
|
+
indexeddb = window.indexedDB;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
cachedIsIndexedDBSupportedPromise = false;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (indexeddb === null) {
|
|
77
|
+
cachedIsIndexedDBSupportedPromise = false;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const testDBName = `modernizr-${Math.random()}`;
|
|
82
|
+
const isSupportedPromise = matchIsCreateDatabaseSupported(indexeddb, testDBName).then((isCreateDatabaseSupported) => {
|
|
83
|
+
if (isCreateDatabaseSupported === false) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return matchIsDeleteDatabaseSupported(indexeddb, testDBName);
|
|
87
|
+
});
|
|
88
|
+
cachedIsIndexedDBSupportedPromise = isSupportedPromise;
|
|
89
|
+
const isSupported = await isSupportedPromise;
|
|
90
|
+
cachedIsIndexedDBSupportedPromise = isSupported;
|
|
91
|
+
return isSupported;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
cachedIsIndexedDBSupportedPromise = false;
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export const getItemFromStorage = async (key, options = {}) => {
|
|
99
|
+
const { storage = "localStorage" } = options;
|
|
100
|
+
const getOnLocalStorage = () => {
|
|
101
|
+
const stringifiedValue = window.localStorage.getItem(key);
|
|
102
|
+
if (stringifiedValue === null) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const parsedValue = JSON.parse(stringifiedValue);
|
|
106
|
+
if (parsedValue === null) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return parsedValue;
|
|
110
|
+
};
|
|
111
|
+
const getOnIndexedDB = () => {
|
|
112
|
+
return getIndexedDB(key);
|
|
113
|
+
};
|
|
114
|
+
if (storage === "indexedDB") {
|
|
115
|
+
const isIndexedDBSupported = await matchIsIndexedDBSupported();
|
|
116
|
+
if (isIndexedDBSupported === true) {
|
|
117
|
+
return getOnIndexedDB();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const isLocalStorageSupported = matchIsLocalStorageSupported();
|
|
121
|
+
if (isLocalStorageSupported === false) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
return getOnLocalStorage();
|
|
125
|
+
};
|
|
126
|
+
export const setItemInStorage = async (key, value, options = {}) => {
|
|
127
|
+
const { storage = "localStorage" } = options;
|
|
128
|
+
const setOnLocalStorage = () => {
|
|
129
|
+
const stringifiedValue = JSON.stringify(value === undefined ? null : value);
|
|
130
|
+
window.localStorage.setItem(key, stringifiedValue);
|
|
131
|
+
return value;
|
|
132
|
+
};
|
|
133
|
+
const setOnIndexedDB = async () => {
|
|
134
|
+
await setIndexedDB(key, value);
|
|
135
|
+
return value;
|
|
136
|
+
};
|
|
137
|
+
if (storage === "indexedDB") {
|
|
138
|
+
const isIndexedDBSupported = await matchIsIndexedDBSupported();
|
|
139
|
+
if (isIndexedDBSupported === true) {
|
|
140
|
+
return setOnIndexedDB();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const isLocalStorageSupported = matchIsLocalStorageSupported();
|
|
144
|
+
if (isLocalStorageSupported === false) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
return setOnLocalStorage();
|
|
148
|
+
};
|
|
149
|
+
export const removeItemFromStorage = async (key, options = {}) => {
|
|
150
|
+
const { storage = "localStorage" } = options;
|
|
151
|
+
const removeOnLocalStorage = () => {
|
|
152
|
+
window.localStorage.removeItem(key);
|
|
153
|
+
};
|
|
154
|
+
const removeOnIndexedDB = async () => {
|
|
155
|
+
await removeIndexedDB(key);
|
|
156
|
+
};
|
|
157
|
+
if (storage === "indexedDB") {
|
|
158
|
+
const isIndexedDBSupported = await matchIsIndexedDBSupported();
|
|
159
|
+
if (isIndexedDBSupported === true) {
|
|
160
|
+
await removeOnIndexedDB();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const isLocalStorageSupported = matchIsLocalStorageSupported();
|
|
165
|
+
if (isLocalStorageSupported === false) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
removeOnLocalStorage();
|
|
169
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capitalizeFirstLetter.d.ts","sourceRoot":"","sources":["../../../src/string/capitalizeFirstLetter.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,WAAY,MAAM,KAAG,MAEtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findAllIndexOf.d.ts","sourceRoot":"","sources":["../../../src/string/findAllIndexOf.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,UAAW,MAAM,UAAU,MAAM,KAAG,MAAM,EAkBpE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const findAllIndexOf = (value, search) => {
|
|
2
|
+
const indices = [];
|
|
3
|
+
let startIndex = 0;
|
|
4
|
+
while (startIndex < value.length) {
|
|
5
|
+
const index = value.indexOf(search, startIndex);
|
|
6
|
+
if (index === -1) {
|
|
7
|
+
break;
|
|
8
|
+
}
|
|
9
|
+
indices.push(index);
|
|
10
|
+
startIndex = index + search.length;
|
|
11
|
+
}
|
|
12
|
+
return indices;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHash.d.ts","sourceRoot":"","sources":["../../../src/string/getHash.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,QAAS,MAAM,KAAG,MAUrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentenceCase.d.ts","sourceRoot":"","sources":["../../../src/string/sentenceCase.ts"],"names":[],"mappings":"AAsCA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWlD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
2
|
+
const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
3
|
+
const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
|
|
4
|
+
const SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
5
|
+
const TRIM_NON_ALPHA_RE = /^[^\p{L}]+/u;
|
|
6
|
+
const lowerFactory = (input) => input.toLowerCase();
|
|
7
|
+
const upperFactory = (input) => input.toUpperCase();
|
|
8
|
+
const capitalCaseTransformFactory = (lower, upper) => {
|
|
9
|
+
return (word) => {
|
|
10
|
+
const firstCharacter = word[0];
|
|
11
|
+
if (word.length <= 1 || firstCharacter === undefined) {
|
|
12
|
+
return word;
|
|
13
|
+
}
|
|
14
|
+
return `${upper(firstCharacter)}${lower(word.slice(1))}`;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const split = (input) => {
|
|
18
|
+
let result = input.trim();
|
|
19
|
+
result = result.replace(TRIM_NON_ALPHA_RE, "");
|
|
20
|
+
result = result
|
|
21
|
+
.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)
|
|
22
|
+
.replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
23
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
24
|
+
return result.split(/\0/g);
|
|
25
|
+
};
|
|
26
|
+
export function sentenceCase(input) {
|
|
27
|
+
if (input.length === 0)
|
|
28
|
+
return input;
|
|
29
|
+
const transform = capitalCaseTransformFactory(lowerFactory, upperFactory);
|
|
30
|
+
const result = split(input)
|
|
31
|
+
.map((word, index) => {
|
|
32
|
+
if (index === 0)
|
|
33
|
+
return transform(word);
|
|
34
|
+
return lowerFactory(word);
|
|
35
|
+
})
|
|
36
|
+
.join(" ");
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,SAAU,MAAM,SAAS,MAAM,KAAG,MAEvD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type RecursivePartial<T> = {
|
|
2
|
+
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
3
|
+
};
|
|
4
|
+
export type NonNull<T> = T extends null ? never : T;
|
|
5
|
+
export type RecursiveNonNull<T> = T extends null ? T extends Date | RegExp ? NonNull<T> | undefined : T extends object ? {
|
|
6
|
+
[K in keyof T]: RecursiveNonNull<T[K]>;
|
|
7
|
+
} | undefined : NonNull<T> | undefined : T extends Date | RegExp ? NonNull<T> : T extends object ? {
|
|
8
|
+
[K in keyof T]: RecursiveNonNull<T[K]>;
|
|
9
|
+
} : NonNull<T>;
|
|
10
|
+
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { JsonSchema } from "./jsonSchema/index.js";
|
|
2
|
+
export type RecursivePartial<Type> = {
|
|
3
|
+
[Prop in keyof Type]?: Type[Prop] extends (infer U)[] ? RecursivePartial<U>[] : Type[Prop] extends object | undefined ? RecursivePartial<Type[Prop]> : Type[Prop];
|
|
4
|
+
};
|
|
5
|
+
export type NonNull<T> = T extends null ? never : T;
|
|
6
|
+
export type RecursiveNonNull<T> = T extends null ? T extends Date | RegExp ? NonNull<T> | undefined : T extends object ? {
|
|
7
|
+
[K in keyof T]: RecursiveNonNull<T[K]>;
|
|
8
|
+
} | undefined : NonNull<T> | undefined : T extends Date | RegExp ? NonNull<T> : T extends object ? {
|
|
9
|
+
[K in keyof T]: RecursiveNonNull<T[K]>;
|
|
10
|
+
} : NonNull<T>;
|
|
11
|
+
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
12
|
+
export type EitherOr<T, U> = (T & {
|
|
13
|
+
[K in keyof U]?: never;
|
|
14
|
+
}) | (U & {
|
|
15
|
+
[K in keyof T]?: never;
|
|
16
|
+
});
|
|
17
|
+
export type RecursiveSchemaToJsonSchema<T> = T extends {
|
|
18
|
+
_zod: unknown;
|
|
19
|
+
} ? JsonSchema : T extends Date | RegExp ? T : T extends Array<infer U> ? Array<RecursiveSchemaToJsonSchema<U>> : T extends object ? {
|
|
20
|
+
[K in keyof T]: RecursiveSchemaToJsonSchema<T[K]>;
|
|
21
|
+
} : T;
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,gBAAgB,CAAC,IAAI,IAAI;KAClC,IAAI,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACjD,gBAAgB,CAAC,CAAC,CAAC,EAAE,GACrB,IAAI,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,SAAS,GACnC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAC5B,IAAI,CAAC,IAAI,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;AAEpD,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAC5C,CAAC,SAAS,IAAI,GAAG,MAAM,GACrB,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,GACtB,CAAC,SAAS,MAAM,GAEV;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvC,GACD,SAAS,GACb,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,GAC1B,CAAC,SAAS,IAAI,GAAG,MAAM,GACrB,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvC,GACD,OAAO,CAAC,CAAC,CAAC,CAAC;AAInB,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,CAAC,SAAS,GAAG,GAChE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACV,KAAK,CAAC;AAGV,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IACrB,CAAC,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC,GAChC,CAAC,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC,CAAC;AAGrC,MAAM,MAAM,2BAA2B,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACpE,UAAU,GACV,CAAC,SAAS,IAAI,GAAG,MAAM,GACrB,CAAC,GACD,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,GACrC,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACrD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/user.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eACd,MAAM,aACP,MAAM,KAChB,MACmE,CAAC;AAEvE,eAAO,MAAM,WAAW,UACf,MAAM,cACD,MAAM,aACP,MAAM,KAChB,MAMF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getUserInitials = (firstName, lastName) => `${firstName?.[0] ?? ""}${lastName?.[0] ?? ""}`.toUpperCase() || "?";
|
|
2
|
+
export const getUserName = (email, firstName, lastName) => {
|
|
3
|
+
if (!firstName || !lastName) {
|
|
4
|
+
return email;
|
|
5
|
+
}
|
|
6
|
+
return `${firstName} ${lastName}`;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./matchIsObjectLike.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchIsObjectLike.d.ts","sourceRoot":"","sources":["../../../src/validation/matchIsObjectLike.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runInVm: (script: string, context: Record<string, unknown>) => Promise<unknown>;
|
package/build/src/vm.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import vm from "node:vm";
|
|
3
|
+
const VM_ALLOWED_MODULES = [
|
|
4
|
+
"axios",
|
|
5
|
+
"cheerio",
|
|
6
|
+
"crypto-js",
|
|
7
|
+
"date-fns",
|
|
8
|
+
"jsonschema",
|
|
9
|
+
"knex",
|
|
10
|
+
"lodash",
|
|
11
|
+
"uuid",
|
|
12
|
+
"zod",
|
|
13
|
+
];
|
|
14
|
+
export const runInVm = async (script, context) => {
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const vmContext = vm.createContext({
|
|
17
|
+
require: (moduleName) => {
|
|
18
|
+
if (VM_ALLOWED_MODULES.includes(moduleName) === false) {
|
|
19
|
+
throw new Error(`Module ${moduleName} is not allowed`);
|
|
20
|
+
}
|
|
21
|
+
return require(moduleName);
|
|
22
|
+
},
|
|
23
|
+
...context,
|
|
24
|
+
});
|
|
25
|
+
const vmScript = new vm.Script(`
|
|
26
|
+
(async () => {${script}})();
|
|
27
|
+
`);
|
|
28
|
+
const result = await vmScript.runInContext(vmContext, {
|
|
29
|
+
timeout: 30000, // 30s
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Zod from "zod/v4";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
export declare const zodEnum: <T extends string>(values: T[]) => Zod.ZodEnum<{ [k_1 in T]: k_1; } extends infer T_1 ? { [k in keyof T_1]: { [k_1 in T]: k_1; }[k]; } : never>;
|
|
4
|
+
export declare const unwrapZod: (schema: z.ZodType) => z.ZodType;
|
|
5
|
+
export declare const getZodType: (schema: z.ZodType) => string;
|
|
6
|
+
export declare const getZodObjectShape: (schema: z.ZodType) => Record<string, z.ZodType>;
|
|
7
|
+
export declare const getZodUnionOptions: (schema: z.ZodType) => z.ZodType[];
|
|
8
|
+
export declare const getZodFromPath: (schema: z.ZodType, path: string[]) => z.ZodType | undefined;
|
|
9
|
+
export declare const derivePartialZod: (schema: z.ZodType, paths: string[][]) => z.ZodType;
|
|
10
|
+
export declare const setZodMetaFromPath: (schema: z.ZodType, path: string[], meta: {
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
}) => z.ZodType;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/zod/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAI3B,eAAO,MAAM,OAAO,iJAEnB,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,EAAE,OAAO,KAAG,EAAE,OAe/C,CAAC;AAEF,eAAO,MAAM,UAAU,WAAY,EAAE,OAAO,KAAG,MAE9C,CAAC;AAMF,eAAO,MAAM,iBAAiB,WACpB,EAAE,OAAO,KAChB,OAAO,MAAM,EAAE,EAAE,OAAO,CAE1B,CAAC;AAMF,eAAO,MAAM,kBAAkB,WAAY,EAAE,OAAO,KAAG,EAAE,OAAO,EAE/D,CAAC;AAEF,eAAO,MAAM,cAAc,WACjB,EAAE,OAAO,QACX,MAAM,EAAE,KACb,EAAE,OAAO,GAAG,SAsCd,CAAC;AAEF,eAAO,MAAM,gBAAgB,WACnB,EAAE,OAAO,SACV,MAAM,EAAE,EAAE,KAChB,EAAE,OAyGJ,CAAC;AA8CF,eAAO,MAAM,kBAAkB,WACrB,EAAE,OAAO,QACX,MAAM,EAAE,QACR;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7C,EAAE,OA+FJ,CAAC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { getEntries, getKeys } from "../collection.js";
|
|
3
|
+
export const zodEnum = (values) => {
|
|
4
|
+
return z.enum(values);
|
|
5
|
+
};
|
|
6
|
+
export const unwrapZod = (schema) => {
|
|
7
|
+
const typeName = schema.def.type;
|
|
8
|
+
if (typeName === "optional" ||
|
|
9
|
+
typeName === "nullable" ||
|
|
10
|
+
typeName === "default") {
|
|
11
|
+
const innerSchema = schema.def
|
|
12
|
+
.innerType;
|
|
13
|
+
return unwrapZod(innerSchema);
|
|
14
|
+
}
|
|
15
|
+
return schema;
|
|
16
|
+
};
|
|
17
|
+
export const getZodType = (schema) => {
|
|
18
|
+
return schema.def.type;
|
|
19
|
+
};
|
|
20
|
+
const getZodArrayElement = (schema) => {
|
|
21
|
+
return schema.def.element;
|
|
22
|
+
};
|
|
23
|
+
export const getZodObjectShape = (schema) => {
|
|
24
|
+
return schema.def.shape;
|
|
25
|
+
};
|
|
26
|
+
const getZodTupleElements = (schema) => {
|
|
27
|
+
return schema.def.items;
|
|
28
|
+
};
|
|
29
|
+
export const getZodUnionOptions = (schema) => {
|
|
30
|
+
return schema.def.options;
|
|
31
|
+
};
|
|
32
|
+
export const getZodFromPath = (schema, path) => {
|
|
33
|
+
const [head, ...nested] = path;
|
|
34
|
+
if (head === undefined) {
|
|
35
|
+
return schema;
|
|
36
|
+
}
|
|
37
|
+
const unwrappedSchema = unwrapZod(schema);
|
|
38
|
+
const typeName = getZodType(unwrappedSchema);
|
|
39
|
+
if (typeName === "tuple") {
|
|
40
|
+
const index = Number(head);
|
|
41
|
+
const elements = getZodTupleElements(unwrappedSchema);
|
|
42
|
+
const element = elements[index];
|
|
43
|
+
if (element === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return getZodFromPath(element, nested);
|
|
47
|
+
}
|
|
48
|
+
if (typeName === "array") {
|
|
49
|
+
return getZodFromPath(getZodArrayElement(unwrappedSchema), nested);
|
|
50
|
+
}
|
|
51
|
+
if (typeName === "object") {
|
|
52
|
+
const shape = getZodObjectShape(unwrappedSchema)[head];
|
|
53
|
+
if (shape === undefined) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return getZodFromPath(shape, nested);
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
};
|
|
60
|
+
export const derivePartialZod = (schema, paths) => {
|
|
61
|
+
if (paths.length === 0) {
|
|
62
|
+
return z.object({});
|
|
63
|
+
}
|
|
64
|
+
const unwrappedSchema = unwrapZod(schema);
|
|
65
|
+
const typeName = getZodType(unwrappedSchema);
|
|
66
|
+
const groupedPaths = paths.reduce((acc, [head, ...nested]) => {
|
|
67
|
+
if (head === undefined) {
|
|
68
|
+
return acc;
|
|
69
|
+
}
|
|
70
|
+
const currentPaths = acc[head];
|
|
71
|
+
if (currentPaths === undefined) {
|
|
72
|
+
return { ...acc, [head]: [nested] };
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
...acc,
|
|
76
|
+
[head]: [...currentPaths, nested],
|
|
77
|
+
};
|
|
78
|
+
}, {});
|
|
79
|
+
if (typeName === "object") {
|
|
80
|
+
const shape = getZodObjectShape(unwrappedSchema);
|
|
81
|
+
const newShape = getEntries(groupedPaths).reduce((acc, [head, nestedPaths]) => {
|
|
82
|
+
const subSchema = shape[head];
|
|
83
|
+
if (subSchema === undefined) {
|
|
84
|
+
return acc;
|
|
85
|
+
}
|
|
86
|
+
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
87
|
+
if (hasEmptyPath === true) {
|
|
88
|
+
return { ...acc, [head]: subSchema };
|
|
89
|
+
}
|
|
90
|
+
return { ...acc, [head]: derivePartialZod(subSchema, nestedPaths) };
|
|
91
|
+
}, {});
|
|
92
|
+
return z.object(newShape);
|
|
93
|
+
}
|
|
94
|
+
if (typeName === "array" || typeName === "tuple") {
|
|
95
|
+
const elements = typeName === "array"
|
|
96
|
+
? [getZodArrayElement(unwrappedSchema)]
|
|
97
|
+
: getZodTupleElements(unwrappedSchema);
|
|
98
|
+
const defaultElement = elements.at(-1);
|
|
99
|
+
if (defaultElement === undefined) {
|
|
100
|
+
return z.array(z.never());
|
|
101
|
+
}
|
|
102
|
+
const indices = getKeys(groupedPaths).map(Number);
|
|
103
|
+
const elementsLength = Math.max(...indices.map((index) => index + 1), elements.length);
|
|
104
|
+
const tupleElements = Array.from({ length: elementsLength }, (_, i) => {
|
|
105
|
+
if (indices.includes(i) === false) {
|
|
106
|
+
return z.never();
|
|
107
|
+
}
|
|
108
|
+
const element = elements[i] !== undefined ? elements[i] : defaultElement;
|
|
109
|
+
if (element === undefined) {
|
|
110
|
+
return z.never();
|
|
111
|
+
}
|
|
112
|
+
const nestedPaths = groupedPaths[i];
|
|
113
|
+
if (nestedPaths === undefined) {
|
|
114
|
+
return z.never();
|
|
115
|
+
}
|
|
116
|
+
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
117
|
+
if (hasEmptyPath === true) {
|
|
118
|
+
return element;
|
|
119
|
+
}
|
|
120
|
+
return derivePartialZod(element, nestedPaths);
|
|
121
|
+
});
|
|
122
|
+
if (tupleElements.length === 0) {
|
|
123
|
+
return z.tuple([]);
|
|
124
|
+
}
|
|
125
|
+
// Zod tuple requires at least [head, ...tail]
|
|
126
|
+
return z.tuple(tupleElements);
|
|
127
|
+
}
|
|
128
|
+
return unwrappedSchema;
|
|
129
|
+
};
|
|
130
|
+
const wrapZodWithModifiers = (schema, originalSchema) => {
|
|
131
|
+
const typeName = originalSchema.def.type;
|
|
132
|
+
if (typeName === "optional") {
|
|
133
|
+
const innerType = originalSchema.def.innerType;
|
|
134
|
+
return z.optional(wrapZodWithModifiers(schema, innerType));
|
|
135
|
+
}
|
|
136
|
+
if (typeName === "nullable") {
|
|
137
|
+
const innerType = originalSchema.def.innerType;
|
|
138
|
+
return z.nullable(wrapZodWithModifiers(schema, innerType));
|
|
139
|
+
}
|
|
140
|
+
if (typeName === "default") {
|
|
141
|
+
const innerType = originalSchema.def.innerType;
|
|
142
|
+
const defaultValue = originalSchema.def.defaultValue;
|
|
143
|
+
return wrapZodWithModifiers(schema, innerType).default(defaultValue);
|
|
144
|
+
}
|
|
145
|
+
return schema;
|
|
146
|
+
};
|
|
147
|
+
export const setZodMetaFromPath = (schema, path, meta) => {
|
|
148
|
+
const [head, ...nested] = path;
|
|
149
|
+
if (head === undefined) {
|
|
150
|
+
// Empty path means we're setting meta on the root schema
|
|
151
|
+
return schema.meta(meta);
|
|
152
|
+
}
|
|
153
|
+
const unwrappedSchema = unwrapZod(schema);
|
|
154
|
+
const typeName = getZodType(unwrappedSchema);
|
|
155
|
+
if (typeName === "tuple") {
|
|
156
|
+
const index = Number(head);
|
|
157
|
+
const elements = getZodTupleElements(unwrappedSchema);
|
|
158
|
+
const defaultElement = elements.at(-1);
|
|
159
|
+
if (defaultElement === undefined) {
|
|
160
|
+
return schema;
|
|
161
|
+
}
|
|
162
|
+
const elementsLength = Math.max(index + 1, elements.length);
|
|
163
|
+
const tupleElements = Array.from({ length: elementsLength }, (_, i) => {
|
|
164
|
+
const element = elements[i] !== undefined ? elements[i] : defaultElement;
|
|
165
|
+
if (element === undefined) {
|
|
166
|
+
return z.never();
|
|
167
|
+
}
|
|
168
|
+
if (i === index) {
|
|
169
|
+
return setZodMetaFromPath(element, nested, meta);
|
|
170
|
+
}
|
|
171
|
+
return element;
|
|
172
|
+
});
|
|
173
|
+
if (tupleElements.length === 0) {
|
|
174
|
+
return wrapZodWithModifiers(z.tuple([]), schema);
|
|
175
|
+
}
|
|
176
|
+
return wrapZodWithModifiers(z.tuple(tupleElements), schema);
|
|
177
|
+
}
|
|
178
|
+
if (typeName === "array") {
|
|
179
|
+
const index = Number(head);
|
|
180
|
+
const element = getZodArrayElement(unwrappedSchema);
|
|
181
|
+
if (index === 0) {
|
|
182
|
+
return wrapZodWithModifiers(z.array(setZodMetaFromPath(element, nested, meta)), schema);
|
|
183
|
+
}
|
|
184
|
+
const tupleElements = Array.from({ length: index + 1 }, (_, i) => {
|
|
185
|
+
if (i === index) {
|
|
186
|
+
return setZodMetaFromPath(element, nested, meta);
|
|
187
|
+
}
|
|
188
|
+
return element;
|
|
189
|
+
});
|
|
190
|
+
if (tupleElements.length === 0) {
|
|
191
|
+
return wrapZodWithModifiers(z.tuple([]), schema);
|
|
192
|
+
}
|
|
193
|
+
return wrapZodWithModifiers(z.tuple(tupleElements), schema);
|
|
194
|
+
}
|
|
195
|
+
if (typeName === "object") {
|
|
196
|
+
const shape = getZodObjectShape(unwrappedSchema);
|
|
197
|
+
const subSchema = shape[head];
|
|
198
|
+
if (subSchema === undefined) {
|
|
199
|
+
return schema;
|
|
200
|
+
}
|
|
201
|
+
const updatedSubSchema = setZodMetaFromPath(subSchema, nested, meta);
|
|
202
|
+
const newShape = {
|
|
203
|
+
...shape,
|
|
204
|
+
[head]: updatedSubSchema,
|
|
205
|
+
};
|
|
206
|
+
const updatedObject = z.object(newShape);
|
|
207
|
+
return wrapZodWithModifiers(updatedObject, schema);
|
|
208
|
+
}
|
|
209
|
+
return schema;
|
|
210
|
+
};
|