@cargo-ai/utils 1.0.4 → 1.0.6
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/README.md +52 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -4
- package/build/array.js +0 -52
- package/build/collection.js +0 -155
- package/build/components.js +0 -56
- package/build/cron.js +0 -19
- package/build/delay.js +0 -52
- package/build/hooks/index.js +0 -35
- package/build/hooks/useClickOutside.js +0 -46
- package/build/hooks/useCountAnimation.js +0 -34
- package/build/hooks/useDeviceType.js +0 -54
- package/build/hooks/useEventListener.js +0 -27
- package/build/hooks/useHeight.js +0 -26
- package/build/hooks/usePictureInPicture.js +0 -126
- package/build/hooks/useResizeObserver.js +0 -35
- package/build/hooks/useScrollPosition.js +0 -22
- package/build/hooks/useStepper.js +0 -138
- package/build/hooks/useStorageState.js +0 -110
- package/build/hooks/useVideoPlayer/VideoManager.js +0 -78
- package/build/hooks/useVideoPlayer/index.js +0 -5
- package/build/hooks/useVideoPlayer/useVideoPlayer.js +0 -100
- package/build/hooks/useWillUnmountEffect.js +0 -13
- package/build/index.js +0 -28
- package/build/json.js +0 -81
- package/build/random.js +0 -7
- package/build/src/components.d.ts +0 -4
- package/build/src/components.js +0 -45
- package/build/src/date.d.ts +0 -13
- package/build/src/date.d.ts.map +0 -1
- package/build/src/date.js +0 -14
- package/build/src/expression/jsonSchema.d.ts +0 -4
- package/build/src/expression/jsonSchema.d.ts.map +0 -1
- package/build/src/expression/jsonSchema.js +0 -85
- package/build/src/expression/matchIsExpression.d.ts +0 -2
- package/build/src/expression/matchIsExpression.d.ts.map +0 -1
- package/build/src/expression/matchIsExpression.js +0 -10
- package/build/src/expression/matchIsExpressionObject.d.ts +0 -2
- package/build/src/expression/matchIsExpressionObject.d.ts.map +0 -1
- package/build/src/expression/matchIsExpressionObject.js +0 -10
- package/build/src/expression/matchIsExpressionString.d.ts +0 -2
- package/build/src/expression/matchIsExpressionString.d.ts.map +0 -1
- package/build/src/expression/matchIsExpressionString.js +0 -4
- package/build/src/hooks/index.d.ts +0 -12
- package/build/src/hooks/index.js +0 -12
- package/build/src/hooks/useClickOutside.d.ts +0 -4
- package/build/src/hooks/useClickOutside.js +0 -42
- package/build/src/hooks/useCountAnimation.d.ts +0 -1
- package/build/src/hooks/useCountAnimation.js +0 -30
- package/build/src/hooks/useDeviceType.d.ts +0 -2
- package/build/src/hooks/useDeviceType.js +0 -50
- package/build/src/hooks/useEventListener.d.ts +0 -6
- package/build/src/hooks/useEventListener.js +0 -23
- package/build/src/hooks/useHeight.d.ts +0 -2
- package/build/src/hooks/useHeight.js +0 -20
- package/build/src/hooks/usePictureInPicture.d.ts +0 -9
- package/build/src/hooks/usePictureInPicture.js +0 -60
- package/build/src/hooks/useResizeObserver.d.ts +0 -4
- package/build/src/hooks/useResizeObserver.js +0 -31
- package/build/src/hooks/useScrollPosition.d.ts +0 -5
- package/build/src/hooks/useScrollPosition.js +0 -18
- package/build/src/hooks/useStepper.d.ts +0 -26
- package/build/src/hooks/useStepper.js +0 -136
- package/build/src/hooks/useStorageState.d.ts +0 -12
- package/build/src/hooks/useStorageState.js +0 -53
- package/build/src/hooks/useVideoPlayer/VideoManager.d.ts +0 -18
- package/build/src/hooks/useVideoPlayer/VideoManager.js +0 -72
- package/build/src/hooks/useVideoPlayer/index.d.ts +0 -1
- package/build/src/hooks/useVideoPlayer/index.js +0 -1
- package/build/src/hooks/useVideoPlayer/useVideoPlayer.d.ts +0 -15
- package/build/src/hooks/useVideoPlayer/useVideoPlayer.js +0 -96
- package/build/src/hooks/useWillUnmountEffect.d.ts +0 -1
- package/build/src/hooks/useWillUnmountEffect.js +0 -8
- package/build/src/integration.d.ts +0 -14
- package/build/src/integration.d.ts.map +0 -1
- package/build/src/integration.js +0 -72
- package/build/src/json/cleanJson.d.ts +0 -3
- package/build/src/json/cleanJson.d.ts.map +0 -1
- package/build/src/json/cleanJson.js +0 -18
- package/build/src/json.d.ts +0 -13
- package/build/src/json.d.ts.map +0 -1
- package/build/src/json.js +0 -107
- package/build/src/jsonSchema.d.ts +0 -5
- package/build/src/jsonSchema.d.ts.map +0 -1
- package/build/src/jsonSchema.js +0 -73
- package/build/src/type.d.ts +0 -10
- package/build/src/type.js +0 -1
- package/build/src/vm.d.ts +0 -1
- package/build/src/vm.js +0 -32
- package/build/src/zod.d.ts +0 -8
- package/build/src/zod.d.ts.map +0 -1
- package/build/src/zod.js +0 -89
- package/build/storage.js +0 -285
- package/build/string.js +0 -17
- package/build/type.js +0 -2
- package/build/user.js +0 -12
package/build/src/json.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { getEntries, getKeys } from "./collection.js";
|
|
2
|
-
import { getDate } from "./date/getDate.js";
|
|
3
|
-
export const jsonTypes = [
|
|
4
|
-
"string",
|
|
5
|
-
"number",
|
|
6
|
-
"object",
|
|
7
|
-
"array",
|
|
8
|
-
"date",
|
|
9
|
-
"boolean",
|
|
10
|
-
"any",
|
|
11
|
-
];
|
|
12
|
-
export const isJson = (value) => {
|
|
13
|
-
try {
|
|
14
|
-
JSON.parse(value);
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export const getJsonType = (value) => {
|
|
22
|
-
if (value === null || value === undefined) {
|
|
23
|
-
return "any";
|
|
24
|
-
}
|
|
25
|
-
if (Array.isArray(value) === true) {
|
|
26
|
-
return "array";
|
|
27
|
-
}
|
|
28
|
-
if (value instanceof Date) {
|
|
29
|
-
return "date";
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === "object") {
|
|
32
|
-
return "object";
|
|
33
|
-
}
|
|
34
|
-
if (value === true || value === false) {
|
|
35
|
-
return "boolean";
|
|
36
|
-
}
|
|
37
|
-
if (typeof value === "number") {
|
|
38
|
-
return "number";
|
|
39
|
-
}
|
|
40
|
-
if (typeof value === "string") {
|
|
41
|
-
return "string";
|
|
42
|
-
}
|
|
43
|
-
return "any";
|
|
44
|
-
};
|
|
45
|
-
export const castToJsonType = (value, type, options = {}) => {
|
|
46
|
-
const { timezone = "UTC" } = options;
|
|
47
|
-
try {
|
|
48
|
-
if (value === undefined) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
if (value === null) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
if (type === "array") {
|
|
55
|
-
return Array.isArray(value) ? value : null;
|
|
56
|
-
}
|
|
57
|
-
if (type === "string") {
|
|
58
|
-
return String(value);
|
|
59
|
-
}
|
|
60
|
-
if (type === "boolean") {
|
|
61
|
-
return Boolean(value);
|
|
62
|
-
}
|
|
63
|
-
if (type === "number") {
|
|
64
|
-
const number = Number(value);
|
|
65
|
-
if (isNaN(number)) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return number;
|
|
69
|
-
}
|
|
70
|
-
if (type === "date") {
|
|
71
|
-
return getDate(value, { timezone });
|
|
72
|
-
}
|
|
73
|
-
return value;
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
export const stringifyJson = (value) => {
|
|
80
|
-
if (typeof value === "string") {
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
return JSON.stringify(value);
|
|
84
|
-
};
|
|
85
|
-
export const isJsonSchemaEmpty = (jsonSchema) => {
|
|
86
|
-
return (jsonSchema.type === "object" &&
|
|
87
|
-
jsonSchema.additionalProperties !== true &&
|
|
88
|
-
(jsonSchema.properties === undefined ||
|
|
89
|
-
getKeys(jsonSchema.properties).length === 0));
|
|
90
|
-
};
|
|
91
|
-
export const cleanJson = (jsonSchema, value) => {
|
|
92
|
-
if (jsonSchema.type === "object" &&
|
|
93
|
-
jsonSchema.properties !== undefined &&
|
|
94
|
-
typeof value === "object" &&
|
|
95
|
-
value !== null) {
|
|
96
|
-
return getEntries(jsonSchema.properties).reduce((out, [key, subJsonSchema]) => {
|
|
97
|
-
if (key in value) {
|
|
98
|
-
return {
|
|
99
|
-
...out,
|
|
100
|
-
[key]: cleanJson(subJsonSchema, value[key]),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return out;
|
|
104
|
-
}, {});
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Schema as JsonSchema } from "jsonschema";
|
|
2
|
-
export { JsonSchema };
|
|
3
|
-
export declare const getJsonSchemaFromPath: (schema: JsonSchema, path: string[]) => JsonSchema | undefined;
|
|
4
|
-
export declare const derivePartialJsonSchema: (schema: JsonSchema, paths: string[][]) => JsonSchema;
|
|
5
|
-
//# sourceMappingURL=jsonSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonSchema.d.ts","sourceRoot":"","sources":["../../src/jsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAIvD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,eAAO,MAAM,qBAAqB,WACxB,UAAU,QACZ,MAAM,EAAE,KACb,UAAU,GAAG,SA4Bf,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAC1B,UAAU,SACX,MAAM,EAAE,EAAE,KAChB,UAuEF,CAAC"}
|
package/build/src/jsonSchema.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { getEntries, getValues } from "./collection.js";
|
|
2
|
-
export const getJsonSchemaFromPath = (schema, path) => {
|
|
3
|
-
const [head, ...nested] = path;
|
|
4
|
-
if (head === undefined) {
|
|
5
|
-
return schema;
|
|
6
|
-
}
|
|
7
|
-
if (schema.type === "array" && schema.items !== undefined) {
|
|
8
|
-
const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
9
|
-
if (items === undefined) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return getJsonSchemaFromPath(items, nested);
|
|
13
|
-
}
|
|
14
|
-
if (schema.type === "object" && schema.properties !== undefined) {
|
|
15
|
-
const property = schema.properties[head];
|
|
16
|
-
if (property === undefined) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
return getJsonSchemaFromPath(property, nested);
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
};
|
|
23
|
-
export const derivePartialJsonSchema = (schema, paths) => {
|
|
24
|
-
if (paths.length === 0) {
|
|
25
|
-
return { type: "object", properties: {} };
|
|
26
|
-
}
|
|
27
|
-
const groupedPaths = paths.reduce((acc, [head, ...nested]) => {
|
|
28
|
-
if (head === undefined) {
|
|
29
|
-
return acc;
|
|
30
|
-
}
|
|
31
|
-
const currentPaths = acc[head];
|
|
32
|
-
if (currentPaths === undefined) {
|
|
33
|
-
return { ...acc, [head]: [nested] };
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
...acc,
|
|
37
|
-
[head]: [...currentPaths, nested],
|
|
38
|
-
};
|
|
39
|
-
}, {});
|
|
40
|
-
if (schema.type === "object" && schema.properties !== undefined) {
|
|
41
|
-
const newProperties = getEntries(groupedPaths).reduce((acc, [head, nestedPaths]) => {
|
|
42
|
-
const subSchema = schema.properties?.[head];
|
|
43
|
-
if (subSchema === undefined) {
|
|
44
|
-
return acc;
|
|
45
|
-
}
|
|
46
|
-
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
47
|
-
if (hasEmptyPath === true) {
|
|
48
|
-
return { ...acc, [head]: subSchema };
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
...acc,
|
|
52
|
-
[head]: derivePartialJsonSchema(subSchema, nestedPaths),
|
|
53
|
-
};
|
|
54
|
-
}, {});
|
|
55
|
-
return { type: "object", properties: newProperties };
|
|
56
|
-
}
|
|
57
|
-
if (schema.type === "array" && schema.items !== undefined) {
|
|
58
|
-
const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
59
|
-
if (items === undefined) {
|
|
60
|
-
return schema;
|
|
61
|
-
}
|
|
62
|
-
const allNestedPaths = getValues(groupedPaths).flat();
|
|
63
|
-
const hasEmptyPath = allNestedPaths.some((path) => path.length === 0);
|
|
64
|
-
if (hasEmptyPath === true) {
|
|
65
|
-
return schema;
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
type: "array",
|
|
69
|
-
items: derivePartialJsonSchema(items, allNestedPaths),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return schema;
|
|
73
|
-
};
|
package/build/src/type.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
package/build/src/type.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/src/vm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const runInVm: (script: string, context: Record<string, unknown>) => Promise<unknown>;
|
package/build/src/vm.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
};
|
package/build/src/zod.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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 getZodFromPath: (schema: z.ZodType, path: string[]) => z.ZodType | undefined;
|
|
7
|
-
export declare const derivePartialZod: (schema: z.ZodType, paths: string[][]) => z.ZodType;
|
|
8
|
-
//# sourceMappingURL=zod.d.ts.map
|
package/build/src/zod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/zod.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;AAUF,eAAO,MAAM,cAAc,WACjB,EAAE,OAAO,QACX,MAAM,EAAE,KACb,EAAE,OAAO,GAAG,SAyBd,CAAC;AAEF,eAAO,MAAM,gBAAgB,WACnB,EAAE,OAAO,SACV,MAAM,EAAE,EAAE,KAChB,EAAE,OAmEJ,CAAC"}
|
package/build/src/zod.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
import { getEntries, getValues } 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; // @aureeaubert - to support multiple types, we need to return an array of strings
|
|
19
|
-
};
|
|
20
|
-
const getZodArrayElement = (schema) => {
|
|
21
|
-
return schema.def.element;
|
|
22
|
-
};
|
|
23
|
-
const getZodObjectShape = (schema) => {
|
|
24
|
-
return schema.def.shape;
|
|
25
|
-
};
|
|
26
|
-
export const getZodFromPath = (schema, path) => {
|
|
27
|
-
const [head, ...nested] = path;
|
|
28
|
-
if (head === undefined) {
|
|
29
|
-
return schema;
|
|
30
|
-
}
|
|
31
|
-
const unwrappedSchemaSchema = unwrapZod(schema);
|
|
32
|
-
const typeName = getZodType(unwrappedSchemaSchema);
|
|
33
|
-
if (typeName === "array") {
|
|
34
|
-
return getZodFromPath(getZodArrayElement(unwrappedSchemaSchema), nested);
|
|
35
|
-
}
|
|
36
|
-
if (typeName === "object") {
|
|
37
|
-
const shape = getZodObjectShape(unwrappedSchemaSchema)[head];
|
|
38
|
-
if (shape === undefined) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
return getZodFromPath(shape, nested);
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
};
|
|
45
|
-
export const derivePartialZod = (schema, paths) => {
|
|
46
|
-
if (paths.length === 0) {
|
|
47
|
-
return z.object({});
|
|
48
|
-
}
|
|
49
|
-
const unwrappedSchema = unwrapZod(schema);
|
|
50
|
-
const typeName = getZodType(unwrappedSchema);
|
|
51
|
-
const groupedPaths = paths.reduce((acc, [head, ...nested]) => {
|
|
52
|
-
if (head === undefined) {
|
|
53
|
-
return acc;
|
|
54
|
-
}
|
|
55
|
-
const currentPaths = acc[head];
|
|
56
|
-
if (currentPaths === undefined) {
|
|
57
|
-
return { ...acc, [head]: [nested] };
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
...acc,
|
|
61
|
-
[head]: [...currentPaths, nested],
|
|
62
|
-
};
|
|
63
|
-
}, {});
|
|
64
|
-
if (typeName === "object") {
|
|
65
|
-
const shape = getZodObjectShape(unwrappedSchema);
|
|
66
|
-
const newShape = getEntries(groupedPaths).reduce((acc, [head, nestedPaths]) => {
|
|
67
|
-
const subSchema = shape[head];
|
|
68
|
-
if (subSchema === undefined) {
|
|
69
|
-
return acc;
|
|
70
|
-
}
|
|
71
|
-
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
72
|
-
if (hasEmptyPath === true) {
|
|
73
|
-
return { ...acc, [head]: subSchema };
|
|
74
|
-
}
|
|
75
|
-
return { ...acc, [head]: derivePartialZod(subSchema, nestedPaths) };
|
|
76
|
-
}, {});
|
|
77
|
-
return z.object(newShape);
|
|
78
|
-
}
|
|
79
|
-
if (typeName === "array") {
|
|
80
|
-
const element = getZodArrayElement(unwrappedSchema);
|
|
81
|
-
const allNestedPaths = getValues(groupedPaths).flat();
|
|
82
|
-
const hasEmptyPath = allNestedPaths.some((path) => path.length === 0);
|
|
83
|
-
if (hasEmptyPath === true) {
|
|
84
|
-
return unwrappedSchema;
|
|
85
|
-
}
|
|
86
|
-
return z.array(derivePartialZod(element, allNestedPaths));
|
|
87
|
-
}
|
|
88
|
-
return unwrappedSchema;
|
|
89
|
-
};
|
package/build/storage.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.removeItemFromStorage = exports.setItemInStorage = exports.getItemFromStorage = exports.matchIsIndexedDBSupported = exports.matchIsLocalStorageSupported = void 0;
|
|
40
|
-
var idb_keyval_1 = require("idb-keyval");
|
|
41
|
-
var cachedIsLocalStorageSupported = undefined;
|
|
42
|
-
var cachedIsIndexedDBSupportedPromise = undefined;
|
|
43
|
-
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
|
|
44
|
-
var matchIsLocalStorageSupported = function () {
|
|
45
|
-
if (cachedIsLocalStorageSupported !== undefined) {
|
|
46
|
-
return cachedIsLocalStorageSupported;
|
|
47
|
-
}
|
|
48
|
-
var mod = "modernizr";
|
|
49
|
-
try {
|
|
50
|
-
window.localStorage.setItem(mod, mod);
|
|
51
|
-
window.localStorage.removeItem(mod);
|
|
52
|
-
cachedIsLocalStorageSupported = true;
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
catch (_a) {
|
|
56
|
-
cachedIsLocalStorageSupported = false;
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
exports.matchIsLocalStorageSupported = matchIsLocalStorageSupported;
|
|
61
|
-
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/indexeddb.js
|
|
62
|
-
var matchIsIndexedDBSupported = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var matchIsCreateDatabaseSupported, matchIsDeleteDatabaseSupported, indexeddb, testDBName_1, isSupportedPromise, isSupported, _a;
|
|
64
|
-
return __generator(this, function (_b) {
|
|
65
|
-
switch (_b.label) {
|
|
66
|
-
case 0:
|
|
67
|
-
if (cachedIsIndexedDBSupportedPromise !== undefined) {
|
|
68
|
-
return [2 /*return*/, cachedIsIndexedDBSupportedPromise];
|
|
69
|
-
}
|
|
70
|
-
matchIsCreateDatabaseSupported = function (indexeddb, testDBName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
71
|
-
var isSupported, _a;
|
|
72
|
-
return __generator(this, function (_b) {
|
|
73
|
-
switch (_b.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
_b.trys.push([0, 2, , 3]);
|
|
76
|
-
return [4 /*yield*/, new Promise(function (resolve) {
|
|
77
|
-
var req = indexeddb.open(testDBName);
|
|
78
|
-
req.onsuccess = function () {
|
|
79
|
-
resolve(true);
|
|
80
|
-
};
|
|
81
|
-
req.onerror = function (event) {
|
|
82
|
-
if (req.error &&
|
|
83
|
-
(req.error.name === "InvalidStateError" ||
|
|
84
|
-
req.error.name === "UnknownError")) {
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
resolve(false);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
resolve(true);
|
|
90
|
-
};
|
|
91
|
-
})];
|
|
92
|
-
case 1:
|
|
93
|
-
isSupported = _b.sent();
|
|
94
|
-
return [2 /*return*/, isSupported];
|
|
95
|
-
case 2:
|
|
96
|
-
_a = _b.sent();
|
|
97
|
-
return [2 /*return*/, false];
|
|
98
|
-
case 3: return [2 /*return*/];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}); };
|
|
102
|
-
matchIsDeleteDatabaseSupported = function (indexeddb, testDBName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
103
|
-
var isSupported, _a;
|
|
104
|
-
return __generator(this, function (_b) {
|
|
105
|
-
switch (_b.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
_b.trys.push([0, 2, , 3]);
|
|
108
|
-
return [4 /*yield*/, new Promise(function (resolve) {
|
|
109
|
-
var deleteReq = indexeddb.deleteDatabase(testDBName);
|
|
110
|
-
deleteReq.onsuccess = function () {
|
|
111
|
-
resolve(true);
|
|
112
|
-
};
|
|
113
|
-
deleteReq.onerror = function () {
|
|
114
|
-
resolve(false);
|
|
115
|
-
};
|
|
116
|
-
})];
|
|
117
|
-
case 1:
|
|
118
|
-
isSupported = _b.sent();
|
|
119
|
-
return [2 /*return*/, isSupported];
|
|
120
|
-
case 2:
|
|
121
|
-
_a = _b.sent();
|
|
122
|
-
return [2 /*return*/, false];
|
|
123
|
-
case 3: return [2 /*return*/];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}); };
|
|
127
|
-
indexeddb = null;
|
|
128
|
-
try {
|
|
129
|
-
// Firefox throws a Security Error when cookies are disabled
|
|
130
|
-
indexeddb = window.indexedDB;
|
|
131
|
-
}
|
|
132
|
-
catch (_c) {
|
|
133
|
-
cachedIsIndexedDBSupportedPromise = false;
|
|
134
|
-
return [2 /*return*/, false];
|
|
135
|
-
}
|
|
136
|
-
if (indexeddb === null) {
|
|
137
|
-
cachedIsIndexedDBSupportedPromise = false;
|
|
138
|
-
return [2 /*return*/, false];
|
|
139
|
-
}
|
|
140
|
-
_b.label = 1;
|
|
141
|
-
case 1:
|
|
142
|
-
_b.trys.push([1, 3, , 4]);
|
|
143
|
-
testDBName_1 = "modernizr-".concat(Math.random());
|
|
144
|
-
isSupportedPromise = matchIsCreateDatabaseSupported(indexeddb, testDBName_1).then(function (isCreateDatabaseSupported) {
|
|
145
|
-
if (isCreateDatabaseSupported === false) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
return matchIsDeleteDatabaseSupported(indexeddb, testDBName_1);
|
|
149
|
-
});
|
|
150
|
-
cachedIsIndexedDBSupportedPromise = isSupportedPromise;
|
|
151
|
-
return [4 /*yield*/, isSupportedPromise];
|
|
152
|
-
case 2:
|
|
153
|
-
isSupported = _b.sent();
|
|
154
|
-
cachedIsIndexedDBSupportedPromise = isSupported;
|
|
155
|
-
return [2 /*return*/, isSupported];
|
|
156
|
-
case 3:
|
|
157
|
-
_a = _b.sent();
|
|
158
|
-
cachedIsIndexedDBSupportedPromise = false;
|
|
159
|
-
return [2 /*return*/, false];
|
|
160
|
-
case 4: return [2 /*return*/];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}); };
|
|
164
|
-
exports.matchIsIndexedDBSupported = matchIsIndexedDBSupported;
|
|
165
|
-
var getItemFromStorage = function (key, options) {
|
|
166
|
-
if (options === void 0) { options = {}; }
|
|
167
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
-
var _a, storage, getOnLocalStorage, getOnIndexedDB, isIndexedDBSupported, isLocalStorageSupported;
|
|
169
|
-
return __generator(this, function (_b) {
|
|
170
|
-
switch (_b.label) {
|
|
171
|
-
case 0:
|
|
172
|
-
_a = options.storage, storage = _a === void 0 ? "localStorage" : _a;
|
|
173
|
-
getOnLocalStorage = function () {
|
|
174
|
-
var stringifiedValue = window.localStorage.getItem(key);
|
|
175
|
-
if (!stringifiedValue) {
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
return JSON.parse(stringifiedValue);
|
|
179
|
-
};
|
|
180
|
-
getOnIndexedDB = function () {
|
|
181
|
-
return (0, idb_keyval_1.get)(key);
|
|
182
|
-
};
|
|
183
|
-
if (!(storage === "indexedDB")) return [3 /*break*/, 2];
|
|
184
|
-
return [4 /*yield*/, (0, exports.matchIsIndexedDBSupported)()];
|
|
185
|
-
case 1:
|
|
186
|
-
isIndexedDBSupported = _b.sent();
|
|
187
|
-
if (isIndexedDBSupported === true) {
|
|
188
|
-
return [2 /*return*/, getOnIndexedDB()];
|
|
189
|
-
}
|
|
190
|
-
_b.label = 2;
|
|
191
|
-
case 2:
|
|
192
|
-
isLocalStorageSupported = (0, exports.matchIsLocalStorageSupported)();
|
|
193
|
-
if (isLocalStorageSupported === false) {
|
|
194
|
-
return [2 /*return*/, undefined];
|
|
195
|
-
}
|
|
196
|
-
return [2 /*return*/, getOnLocalStorage()];
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
exports.getItemFromStorage = getItemFromStorage;
|
|
202
|
-
var setItemInStorage = function (key, value, options) {
|
|
203
|
-
if (options === void 0) { options = {}; }
|
|
204
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
205
|
-
var _a, storage, setOnLocalStorage, setOnIndexedDB, isIndexedDBSupported, isLocalStorageSupported;
|
|
206
|
-
return __generator(this, function (_b) {
|
|
207
|
-
switch (_b.label) {
|
|
208
|
-
case 0:
|
|
209
|
-
_a = options.storage, storage = _a === void 0 ? "localStorage" : _a;
|
|
210
|
-
setOnLocalStorage = function () {
|
|
211
|
-
var stringifiedValue = JSON.stringify(value);
|
|
212
|
-
window.localStorage.setItem(key, stringifiedValue);
|
|
213
|
-
return value;
|
|
214
|
-
};
|
|
215
|
-
setOnIndexedDB = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
-
return __generator(this, function (_a) {
|
|
217
|
-
switch (_a.label) {
|
|
218
|
-
case 0: return [4 /*yield*/, (0, idb_keyval_1.set)(key, value)];
|
|
219
|
-
case 1:
|
|
220
|
-
_a.sent();
|
|
221
|
-
return [2 /*return*/, value];
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}); };
|
|
225
|
-
if (!(storage === "indexedDB")) return [3 /*break*/, 2];
|
|
226
|
-
return [4 /*yield*/, (0, exports.matchIsIndexedDBSupported)()];
|
|
227
|
-
case 1:
|
|
228
|
-
isIndexedDBSupported = _b.sent();
|
|
229
|
-
if (isIndexedDBSupported === true) {
|
|
230
|
-
return [2 /*return*/, setOnIndexedDB()];
|
|
231
|
-
}
|
|
232
|
-
_b.label = 2;
|
|
233
|
-
case 2:
|
|
234
|
-
isLocalStorageSupported = (0, exports.matchIsLocalStorageSupported)();
|
|
235
|
-
if (isLocalStorageSupported === false) {
|
|
236
|
-
return [2 /*return*/, value];
|
|
237
|
-
}
|
|
238
|
-
return [2 /*return*/, setOnLocalStorage()];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
exports.setItemInStorage = setItemInStorage;
|
|
244
|
-
var removeItemFromStorage = function (key, options) {
|
|
245
|
-
if (options === void 0) { options = {}; }
|
|
246
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
247
|
-
var _a, storage, removeOnLocalStorage, removeOnIndexedDB, isIndexedDBSupported, isLocalStorageSupported;
|
|
248
|
-
return __generator(this, function (_b) {
|
|
249
|
-
switch (_b.label) {
|
|
250
|
-
case 0:
|
|
251
|
-
_a = options.storage, storage = _a === void 0 ? "localStorage" : _a;
|
|
252
|
-
removeOnLocalStorage = function () {
|
|
253
|
-
window.localStorage.removeItem(key);
|
|
254
|
-
};
|
|
255
|
-
removeOnIndexedDB = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
256
|
-
return __generator(this, function (_a) {
|
|
257
|
-
switch (_a.label) {
|
|
258
|
-
case 0: return [4 /*yield*/, (0, idb_keyval_1.del)(key)];
|
|
259
|
-
case 1:
|
|
260
|
-
_a.sent();
|
|
261
|
-
return [2 /*return*/];
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}); };
|
|
265
|
-
if (!(storage === "indexedDB")) return [3 /*break*/, 3];
|
|
266
|
-
return [4 /*yield*/, (0, exports.matchIsIndexedDBSupported)()];
|
|
267
|
-
case 1:
|
|
268
|
-
isIndexedDBSupported = _b.sent();
|
|
269
|
-
if (!(isIndexedDBSupported === true)) return [3 /*break*/, 3];
|
|
270
|
-
return [4 /*yield*/, removeOnIndexedDB()];
|
|
271
|
-
case 2:
|
|
272
|
-
_b.sent();
|
|
273
|
-
return [2 /*return*/];
|
|
274
|
-
case 3:
|
|
275
|
-
isLocalStorageSupported = (0, exports.matchIsLocalStorageSupported)();
|
|
276
|
-
if (isLocalStorageSupported === false) {
|
|
277
|
-
return [2 /*return*/];
|
|
278
|
-
}
|
|
279
|
-
removeOnLocalStorage();
|
|
280
|
-
return [2 /*return*/];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
exports.removeItemFromStorage = removeItemFromStorage;
|
package/build/string.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHash = exports.capitalizeFirstLetter = void 0;
|
|
4
|
-
var capitalizeFirstLetter = function (string) {
|
|
5
|
-
return "".concat(string.charAt(0).toUpperCase()).concat(string.slice(1));
|
|
6
|
-
};
|
|
7
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
8
|
-
var getHash = function (str) {
|
|
9
|
-
var hash = 0;
|
|
10
|
-
for (var i = 0; i < str.length; i++) {
|
|
11
|
-
var char = str.charCodeAt(i);
|
|
12
|
-
hash = (hash << 5) - hash + char;
|
|
13
|
-
hash |= 0; // Convert to 32bit integer
|
|
14
|
-
}
|
|
15
|
-
return hash;
|
|
16
|
-
};
|
|
17
|
-
exports.getHash = getHash;
|
package/build/type.js
DELETED
package/build/user.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserName = exports.getUserInitials = void 0;
|
|
4
|
-
var getUserInitials = function (firstName, lastName) { var _a, _b; return "".concat((_a = firstName === null || firstName === void 0 ? void 0 : firstName[0]) !== null && _a !== void 0 ? _a : "").concat((_b = lastName === null || lastName === void 0 ? void 0 : lastName[0]) !== null && _b !== void 0 ? _b : "").toUpperCase() || "-"; };
|
|
5
|
-
exports.getUserInitials = getUserInitials;
|
|
6
|
-
var getUserName = function (email, firstName, lastName) {
|
|
7
|
-
if (!firstName || !lastName) {
|
|
8
|
-
return email;
|
|
9
|
-
}
|
|
10
|
-
return "".concat(firstName, " ").concat(lastName);
|
|
11
|
-
};
|
|
12
|
-
exports.getUserName = getUserName;
|