@vitnode/core 1.2.0-canary.60 → 1.2.0-canary.62
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/scripts/get-config.js +15 -0
- package/dist/scripts/plugin.js +188 -0
- package/dist/scripts/prepare-database.js +177 -0
- package/dist/scripts/prepare-plugins-files.js +134 -0
- package/dist/scripts/run-interactive-shell-command.js +21 -0
- package/dist/scripts/scripts.js +39 -13
- package/dist/scripts/shared/file-utils.js +203 -0
- package/dist/src/api/adapters/sso/discord.js +1 -77
- package/dist/src/api/adapters/sso/facebook.js +1 -76
- package/dist/src/api/adapters/sso/google.js +1 -87
- package/dist/src/api/config.js +1 -67
- package/dist/src/api/lib/check-plugin-id.js +1 -43
- package/dist/src/api/lib/cron.js +1 -22
- package/dist/src/api/lib/logger-middleware.js +1 -35
- package/dist/src/api/lib/module.js +1 -22
- package/dist/src/api/lib/plugin.js +1 -22
- package/dist/src/api/lib/route.js +1 -27
- package/dist/src/api/lib/with-pagination.js +1 -83
- package/dist/src/api/middlewares/captcha.middleware.js +1 -63
- package/dist/src/api/middlewares/cron-auth.middleware.js +1 -19
- package/dist/src/api/middlewares/global.middleware.js +1 -93
- package/dist/src/api/middlewares/rate-limiter.middleware.js +1 -32
- package/dist/src/api/models/device.js +1 -61
- package/dist/src/api/models/email.js +1 -76
- package/dist/src/api/models/password.js +1 -36
- package/dist/src/api/models/session-admin.js +1 -106
- package/dist/src/api/models/session.js +1 -85
- package/dist/src/api/models/sso.js +1 -120
- package/dist/src/api/models/user/get-user-by-id.js +1 -19
- package/dist/src/api/models/user/sign-in-with-passwords.js +1 -22
- package/dist/src/api/models/user/sign-up.js +1 -73
- package/dist/src/api/models/user.js +1 -8
- package/dist/src/api/modules/admin/admin.module.js +1 -19
- package/dist/src/api/modules/admin/advanced/advanced.admin.module.js +1 -11
- package/dist/src/api/modules/admin/advanced/cron/cron.admin.module.js +1 -12
- package/dist/src/api/modules/admin/advanced/cron/routes/get.route.js +1 -66
- package/dist/src/api/modules/admin/advanced/cron/routes/run.route.js +1 -95
- package/dist/src/api/modules/admin/debug/debug.admin.module.js +1 -10
- package/dist/src/api/modules/admin/debug/routes/logs.route.js +1 -94
- package/dist/src/api/modules/admin/routes/session.route.js +1 -47
- package/dist/src/api/modules/admin/users/routes/list.route.js +1 -79
- package/dist/src/api/modules/admin/users/routes/users.route.js +1 -84
- package/dist/src/api/modules/admin/users/users.admin.module.js +1 -10
- package/dist/src/api/modules/cron/cron/clean.cron.js +1 -24
- package/dist/src/api/modules/cron/cron.module.js +1 -14
- package/dist/src/api/modules/cron/helpers/process-cron-jobs.d.ts.map +1 -1
- package/dist/src/api/modules/cron/helpers/process-cron-jobs.js +1 -76
- package/dist/src/api/modules/cron/routes/cron.route.js +1 -101
- package/dist/src/api/modules/middleware/middleware.module.js +1 -10
- package/dist/src/api/modules/middleware/route.js +1 -49
- package/dist/src/api/modules/users/avatar-color.js +1 -43
- package/dist/src/api/modules/users/routes/change-password.route.js +1 -58
- package/dist/src/api/modules/users/routes/reset-passowrd.route.js +1 -91
- package/dist/src/api/modules/users/routes/session.route.js +1 -46
- package/dist/src/api/modules/users/routes/sign-in.route.js +1 -71
- package/dist/src/api/modules/users/routes/sign-out.route.js +1 -43
- package/dist/src/api/modules/users/routes/sign-up.route.js +1 -77
- package/dist/src/api/modules/users/routes/test.route.js +1 -33
- package/dist/src/api/modules/users/sso/routes/callback.route.js +1 -52
- package/dist/src/api/modules/users/sso/routes/create-url.route.js +1 -36
- package/dist/src/api/modules/users/sso/sso.module.js +1 -12
- package/dist/src/api/modules/users/users.module.js +1 -26
- package/dist/src/api/plugin.js +1 -15
- package/dist/src/app/login/page.js +1 -16
- package/dist/src/app/login/reset-password/page.js +1 -18
- package/dist/src/app/login/sso/[providerId]/page.js +1 -10
- package/dist/src/app/register/page.js +1 -16
- package/dist/src/app_admin/core/advanced/cron/page.js +1 -42
- package/dist/src/app_admin/core/debug/page.js +1 -45
- package/dist/src/app_admin/core/page.js +1 -5
- package/dist/src/app_admin/core/test/page.js +1 -5
- package/dist/src/app_admin/core/users/page.js +1 -38
- package/dist/src/components/avatar.js +1 -14
- package/dist/src/components/confirm-action/confirm-action-alert-dialog.js +1 -42
- package/dist/src/components/confirm-action/content.js +1 -31
- package/dist/src/components/date-format.js +1 -41
- package/dist/src/components/form/auto-form.js +1 -103
- package/dist/src/components/form/common/desc.js +1 -9
- package/dist/src/components/form/common/label.js +1 -18
- package/dist/src/components/form/fields/checkbox.js +1 -37
- package/dist/src/components/form/fields/combobox-async.js +1 -123
- package/dist/src/components/form/fields/combobox.js +1 -87
- package/dist/src/components/form/fields/input.js +1 -39
- package/dist/src/components/form/fields/radio-group.js +1 -50
- package/dist/src/components/form/fields/select.js +1 -58
- package/dist/src/components/form/fields/switch.js +1 -36
- package/dist/src/components/form/fields/textarea.js +1 -36
- package/dist/src/components/i18n-provider.js +1 -43
- package/dist/src/components/logo-vitnode.js +1 -119
- package/dist/src/components/switchers/langs/language-switcher.js +1 -47
- package/dist/src/components/switchers/themes/theme-switcher.js +1 -28
- package/dist/src/components/table/content.js +1 -81
- package/dist/src/components/table/data-table.js +1 -68
- package/dist/src/components/table/order-table-head.js +1 -50
- package/dist/src/components/table/pagination.js +1 -122
- package/dist/src/components/tiptap/extension.js +1 -33
- package/dist/src/components/tiptap/toolbar/actions/alignment-action.js +1 -91
- package/dist/src/components/tiptap/toolbar/actions/bold-action.js +1 -39
- package/dist/src/components/tiptap/toolbar/actions/headings-action.js +1 -93
- package/dist/src/components/tiptap/toolbar/actions/italic-action.js +1 -38
- package/dist/src/components/tiptap/toolbar/actions/list-action.js +1 -61
- package/dist/src/components/tiptap/toolbar/actions/text-format-more/text-format-more.js +1 -59
- package/dist/src/components/tiptap/toolbar/actions/underline-action.js +1 -38
- package/dist/src/components/tiptap/toolbar/actions/undo-redo-actions.js +1 -63
- package/dist/src/components/tiptap/toolbar/actions/utils/tooltip-shortcut.js +1 -11
- package/dist/src/components/tiptap/toolbar/tiptap-toolbar.js +1 -55
- package/dist/src/components/tiptap/toolbar/use-toolbar-editor.js +1 -5
- package/dist/src/components/ui/accordion.js +1 -46
- package/dist/src/components/ui/alert-dialog.js +1 -123
- package/dist/src/components/ui/alert.js +1 -39
- package/dist/src/components/ui/badge.js +1 -28
- package/dist/src/components/ui/button-client.js +1 -57
- package/dist/src/components/ui/button.js +1 -32
- package/dist/src/components/ui/card.js +1 -52
- package/dist/src/components/ui/checkbox.js +1 -20
- package/dist/src/components/ui/collapsible.js +1 -22
- package/dist/src/components/ui/command.js +1 -98
- package/dist/src/components/ui/context-menu.js +1 -140
- package/dist/src/components/ui/dialog.js +1 -189
- package/dist/src/components/ui/drawer.js +1 -83
- package/dist/src/components/ui/dropdown-menu.js +1 -141
- package/dist/src/components/ui/editor-content.js +1 -10
- package/dist/src/components/ui/editor.js +1 -35
- package/dist/src/components/ui/form.js +1 -148
- package/dist/src/components/ui/header-content.js +1 -30
- package/dist/src/components/ui/hover-card.js +1 -29
- package/dist/src/components/ui/input-otp.js +1 -48
- package/dist/src/components/ui/input.js +1 -11
- package/dist/src/components/ui/label.js +1 -12
- package/dist/src/components/ui/loader.js +1 -16
- package/dist/src/components/ui/menubar.js +1 -151
- package/dist/src/components/ui/navigation-menu.js +1 -82
- package/dist/src/components/ui/popover.js +1 -35
- package/dist/src/components/ui/progress.js +1 -19
- package/dist/src/components/ui/radio-group.js +1 -27
- package/dist/src/components/ui/scroll-area.js +1 -33
- package/dist/src/components/ui/select.js +1 -113
- package/dist/src/components/ui/separator.js +1 -14
- package/dist/src/components/ui/sheet.js +1 -92
- package/dist/src/components/ui/sidebar.js +1 -433
- package/dist/src/components/ui/skeleton.js +1 -10
- package/dist/src/components/ui/slider.js +1 -50
- package/dist/src/components/ui/sonner.js +1 -26
- package/dist/src/components/ui/switch.js +1 -16
- package/dist/src/components/ui/table.js +1 -63
- package/dist/src/components/ui/tabs.js +1 -33
- package/dist/src/components/ui/textarea.js +1 -10
- package/dist/src/components/ui/toggle-group.js +1 -45
- package/dist/src/components/ui/toggle.js +1 -34
- package/dist/src/components/ui/tooltip.js +1 -57
- package/dist/src/config.js +1 -4
- package/dist/src/database/admins.js +1 -74
- package/dist/src/database/cron.js +1 -22
- package/dist/src/database/languages.js +1 -52
- package/dist/src/database/logs.js +1 -34
- package/dist/src/database/moderators.js +1 -37
- package/dist/src/database/roles.js +1 -13
- package/dist/src/database/sessions.js +1 -60
- package/dist/src/database/users.js +1 -145
- package/dist/src/drizzle.config.js +1 -67
- package/dist/src/emails/default-template.js +1 -99
- package/dist/src/emails/reset-password.js +1 -132
- package/dist/src/emails/ui/button.js +1 -36
- package/dist/src/emails/ui/card.js +1 -39
- package/dist/src/hooks/use-before-unload.js +1 -30
- package/dist/src/hooks/use-captcha.js +1 -122
- package/dist/src/hooks/use-mobile.js +1 -16
- package/dist/src/lib/api/get-middleware-api.js +1 -13
- package/dist/src/lib/api/get-next-cron-run-date.js +1 -14
- package/dist/src/lib/api/get-next-cron-run-date.test.js +1 -55
- package/dist/src/lib/api/get-session-admin-api.js +1 -19
- package/dist/src/lib/api/get-session-api.js +1 -14
- package/dist/src/lib/api/should-cron-job-run.js +1 -16
- package/dist/src/lib/api/should-cron-job-run.test.js +1 -213
- package/dist/src/lib/api/validate-cron-schedule.d.ts +2 -0
- package/dist/src/lib/api/validate-cron-schedule.d.ts.map +1 -0
- package/dist/src/lib/api/validate-cron-schedule.js +1 -0
- package/dist/src/lib/api/validate-cron-schedule.test.d.ts +2 -0
- package/dist/src/lib/api/validate-cron-schedule.test.d.ts.map +1 -0
- package/dist/src/lib/api/validate-cron-schedule.test.js +1 -0
- package/dist/src/lib/colors.js +1 -140
- package/dist/src/lib/colors.test.js +1 -173
- package/dist/src/lib/config.js +1 -14
- package/dist/src/lib/ctrl-or-command-character.js +1 -5
- package/dist/src/lib/fetcher/cookie-from-string-to-object.js +1 -12
- package/dist/src/lib/fetcher/cookie-from-string-to-object.test.js +1 -78
- package/dist/src/lib/fetcher/core.js +3 -48
- package/dist/src/lib/fetcher/helpers-server.js +1 -18
- package/dist/src/lib/fetcher/helpers.js +1 -16
- package/dist/src/lib/fetcher/helpers.test.js +1 -37
- package/dist/src/lib/fetcher/types.js +1 -1
- package/dist/src/lib/fetcher-client.js +1 -17
- package/dist/src/lib/fetcher.js +1 -33
- package/dist/src/lib/helpers/auto-form.js +1 -98
- package/dist/src/lib/helpers/auto-form.test.js +1 -336
- package/dist/src/lib/navigation.js +1 -11
- package/dist/src/lib/plugin.js +1 -3
- package/dist/src/lib/special-characters.js +1 -4
- package/dist/src/lib/special-characters.test.js +1 -56
- package/dist/src/lib/utils.js +1 -5
- package/dist/src/locales/en.json +308 -0
- package/dist/src/tests/setup.js +1 -6
- package/dist/src/views/admin/layouts/admin-layout.js +1 -73
- package/dist/src/views/admin/layouts/sidebar/nav/item.js +1 -98
- package/dist/src/views/admin/layouts/sidebar/nav/nav.js +1 -60
- package/dist/src/views/admin/layouts/sidebar/sidebar.js +1 -28
- package/dist/src/views/admin/layouts/sidebar/sign-out.js +1 -14
- package/dist/src/views/admin/layouts/user-bar/client.js +1 -69
- package/dist/src/views/admin/layouts/user-bar/user-bar.js +1 -32
- package/dist/src/views/admin/sign-in/sign-in-admin-view.js +1 -27
- package/dist/src/views/admin/views/core/advanced/cron/cron-table-view.js +1 -97
- package/dist/src/views/admin/views/core/advanced/cron/run-action/mutation-api.js +1 -23
- package/dist/src/views/admin/views/core/advanced/cron/run-action/run-action.js +1 -38
- package/dist/src/views/admin/views/core/dashboard/dashboard-admin-view.js +1 -44
- package/dist/src/views/admin/views/core/debug/actions/clear-cache/clear-cache.js +1 -35
- package/dist/src/views/admin/views/core/debug/actions/clear-cache/mutation-api.js +1 -5
- package/dist/src/views/admin/views/core/debug/system-logs/actions/more/content.js +1 -281
- package/dist/src/views/admin/views/core/debug/system-logs/actions/more/more.js +1 -67
- package/dist/src/views/admin/views/core/debug/system-logs/badges/badge-status.js +1 -14
- package/dist/src/views/admin/views/core/debug/system-logs/badges/badge-type-log.js +1 -30
- package/dist/src/views/admin/views/core/debug/system-logs/system-logs-view.js +1 -96
- package/dist/src/views/admin/views/core/test.js +1 -161
- package/dist/src/views/admin/views/core/users/users-admin-view.js +1 -89
- package/dist/src/views/auth/password-reset/change-password-form/form.js +1 -48
- package/dist/src/views/auth/password-reset/change-password-form/mutation-api.js +1 -22
- package/dist/src/views/auth/password-reset/change-password-form/use-form.js +1 -36
- package/dist/src/views/auth/password-reset/form/form.js +1 -104
- package/dist/src/views/auth/password-reset/form/mutation-api.js +1 -21
- package/dist/src/views/auth/password-reset/form/use-form.js +1 -33
- package/dist/src/views/auth/password-reset/password-reset-view.js +1 -37
- package/dist/src/views/auth/sign-in/form/form.js +1 -64
- package/dist/src/views/auth/sign-in/form/mutation-api.js +1 -33
- package/dist/src/views/auth/sign-in/form/use-form.js +1 -38
- package/dist/src/views/auth/sign-in/sign-in-view.js +1 -61
- package/dist/src/views/auth/sign-up/components/password-input.js +1 -96
- package/dist/src/views/auth/sign-up/email-confirmation-view.js +1 -55
- package/dist/src/views/auth/sign-up/form/form.js +1 -89
- package/dist/src/views/auth/sign-up/form/mutation-api.js +1 -30
- package/dist/src/views/auth/sign-up/form/use-form.js +1 -70
- package/dist/src/views/auth/sign-up/sign-up-view.js +1 -65
- package/dist/src/views/auth/sign-up/wrapper.js +1 -22
- package/dist/src/views/auth/sso/buttons/client.js +1 -22
- package/dist/src/views/auth/sso/buttons/mutation-api.js +1 -24
- package/dist/src/views/auth/sso/buttons/sso-buttons.js +1 -56
- package/dist/src/views/auth/sso/callback/callback-sso-view.js +1 -32
- package/dist/src/views/auth/sso/callback/client/client.js +1 -68
- package/dist/src/views/auth/sso/callback/client/mutation-api.js +1 -32
- package/dist/src/views/error/back-button.js +1 -14
- package/dist/src/views/error/error-view.js +1 -58
- package/dist/src/views/error/global-error-view.js +1 -50
- package/dist/src/views/layouts/provider.js +1 -44
- package/dist/src/views/layouts/root-layout.js +1 -25
- package/dist/src/views/layouts/theme/header/header.js +1 -38
- package/dist/src/views/layouts/theme/header/user/auth/auth.js +1 -33
- package/dist/src/views/layouts/theme/header/user/auth/client.js +1 -47
- package/dist/src/views/layouts/theme/header/user/auth/log-out-mutation-api.js +1 -27
- package/dist/src/views/layouts/theme/header/user/user.js +1 -32
- package/dist/src/views/layouts/theme/layout.js +1 -16
- package/dist/src/vitnode.config.js +1 -42
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsup.config.js +18 -0
- package/dist/vitest.config.d.ts.map +1 -1
- package/dist/vitest.config.js +49 -0
- package/eslint.config.mjs +2 -0
- package/package.json +6 -10
- package/dist/src/api/adapters/cron/node-cron.adapter.d.ts +0 -3
- package/dist/src/api/adapters/cron/node-cron.adapter.d.ts.map +0 -1
- package/dist/src/api/adapters/cron/node-cron.adapter.js +0 -11
- package/dist/src/api/adapters/email/nodemailer.d.ts +0 -10
- package/dist/src/api/adapters/email/nodemailer.d.ts.map +0 -1
- package/dist/src/api/adapters/email/nodemailer.js +0 -30
- package/dist/src/api/adapters/email/resend.d.ts +0 -6
- package/dist/src/api/adapters/email/resend.d.ts.map +0 -1
- package/dist/src/api/adapters/email/resend.js +0 -21
|
@@ -1,98 +1 @@
|
|
|
1
|
-
export function getDefaults(jsonSchema) {
|
|
2
|
-
if (!jsonSchema?.properties) {
|
|
3
|
-
return {};
|
|
4
|
-
}
|
|
5
|
-
const defaultValues = {};
|
|
6
|
-
// Iterate over each property in the schema
|
|
7
|
-
for(const key in jsonSchema.properties){
|
|
8
|
-
const prop = jsonSchema.properties[key];
|
|
9
|
-
// Case 1: The property has a 'default' key.
|
|
10
|
-
if (prop.default !== undefined) {
|
|
11
|
-
defaultValues[key] = prop.default;
|
|
12
|
-
continue; // Move to the next property
|
|
13
|
-
}
|
|
14
|
-
// Case 2: The property is a nested object. Recurse into it.
|
|
15
|
-
if (prop.type === "object" && prop.properties) {
|
|
16
|
-
const nestedDefaults = getDefaults(prop);
|
|
17
|
-
// Only add the nested object if it contains default values.
|
|
18
|
-
if (Object.keys(nestedDefaults).length > 0) {
|
|
19
|
-
defaultValues[key] = nestedDefaults;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return defaultValues;
|
|
24
|
-
}
|
|
25
|
-
export function getZodInputParams(jsonSchema, parentRequired = []) {
|
|
26
|
-
// Base case: If there's no schema or properties, return an empty object.
|
|
27
|
-
if (!jsonSchema?.properties) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
const extractedParams = {};
|
|
31
|
-
const requiredFields = new Set(jsonSchema.required ?? parentRequired);
|
|
32
|
-
// Iterate over each property in the current schema level.
|
|
33
|
-
for(const key in jsonSchema.properties){
|
|
34
|
-
const prop = jsonSchema.properties[key];
|
|
35
|
-
const fieldParams = {};
|
|
36
|
-
// 1. Handle 'required' status
|
|
37
|
-
if (requiredFields.has(key)) {
|
|
38
|
-
fieldParams.required = true;
|
|
39
|
-
}
|
|
40
|
-
// 2. Handle standard string constraints
|
|
41
|
-
if (prop.minLength !== undefined) {
|
|
42
|
-
fieldParams.minLength = prop.minLength;
|
|
43
|
-
}
|
|
44
|
-
if (prop.maxLength !== undefined) {
|
|
45
|
-
fieldParams.maxLength = prop.maxLength;
|
|
46
|
-
}
|
|
47
|
-
if (prop.pattern !== undefined) {
|
|
48
|
-
fieldParams.pattern = prop.pattern;
|
|
49
|
-
}
|
|
50
|
-
if (prop.enum) {
|
|
51
|
-
fieldParams.enum = prop.enum;
|
|
52
|
-
}
|
|
53
|
-
// 3. Handle complex patterns from `allOf` (used for password)
|
|
54
|
-
if (prop.allOf) {
|
|
55
|
-
fieldParams.patterns = prop.allOf.map((p)=>p.pattern).filter(Boolean); // Filter out any undefined patterns
|
|
56
|
-
}
|
|
57
|
-
if (prop.description) {
|
|
58
|
-
fieldParams.description = prop.description;
|
|
59
|
-
}
|
|
60
|
-
// 4. Determine the input type based on schema type and format
|
|
61
|
-
switch(prop.type){
|
|
62
|
-
case "boolean":
|
|
63
|
-
fieldParams.type = "checkbox";
|
|
64
|
-
break;
|
|
65
|
-
case "integer":
|
|
66
|
-
case "number":
|
|
67
|
-
fieldParams.type = "number";
|
|
68
|
-
break;
|
|
69
|
-
case "string":
|
|
70
|
-
// Check format for special string types
|
|
71
|
-
if (prop.format === "email") {
|
|
72
|
-
fieldParams.type = "email";
|
|
73
|
-
} else if (key.toLowerCase().includes("password")) {
|
|
74
|
-
// Infer password type by key name for better UX
|
|
75
|
-
fieldParams.type = "password";
|
|
76
|
-
} else {
|
|
77
|
-
fieldParams.type = "text";
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
// 5. Handle nested objects by making a recursive call
|
|
82
|
-
if (prop.type === "object") {
|
|
83
|
-
// Pass the 'required' array from the nested object itself.
|
|
84
|
-
extractedParams[key] = getZodInputParams(prop, prop.required);
|
|
85
|
-
} else {
|
|
86
|
-
extractedParams[key] = fieldParams;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return extractedParams;
|
|
90
|
-
}
|
|
91
|
-
export function getNestedParam(obj, path) {
|
|
92
|
-
return path.split(".").reduce((acc, key)=>{
|
|
93
|
-
if (acc && typeof acc === "object" && !Array.isArray(acc) && key in acc) {
|
|
94
|
-
return acc[key];
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
}, obj);
|
|
98
|
-
}
|
|
1
|
+
export function getDefaults(jsonSchema){if(!jsonSchema?.properties){return{}}const defaultValues={};for(const key in jsonSchema.properties){const prop=jsonSchema.properties[key];if(prop.default!==undefined){defaultValues[key]=prop.default;continue}if(prop.type==="object"&&prop.properties){const nestedDefaults=getDefaults(prop);if(Object.keys(nestedDefaults).length>0){defaultValues[key]=nestedDefaults}}}return defaultValues}export function getZodInputParams(jsonSchema,parentRequired=[]){if(!jsonSchema?.properties){return{}}const extractedParams={};const requiredFields=new Set(jsonSchema.required??parentRequired);for(const key in jsonSchema.properties){const prop=jsonSchema.properties[key];const fieldParams={};if(requiredFields.has(key)){fieldParams.required=true}if(prop.minLength!==undefined){fieldParams.minLength=prop.minLength}if(prop.maxLength!==undefined){fieldParams.maxLength=prop.maxLength}if(prop.pattern!==undefined){fieldParams.pattern=prop.pattern}if(prop.enum){fieldParams.enum=prop.enum}if(prop.allOf){fieldParams.patterns=prop.allOf.map(p=>p.pattern).filter(Boolean)}if(prop.description){fieldParams.description=prop.description}switch(prop.type){case"boolean":fieldParams.type="checkbox";break;case"integer":case"number":fieldParams.type="number";break;case"string":if(prop.format==="email"){fieldParams.type="email"}else if(key.toLowerCase().includes("password")){fieldParams.type="password"}else{fieldParams.type="text"}break}if(prop.type==="object"){extractedParams[key]=getZodInputParams(prop,prop.required)}else{extractedParams[key]=fieldParams}}return extractedParams}export function getNestedParam(obj,path){return path.split(".").reduce((acc,key)=>{if(acc&&typeof acc==="object"&&!Array.isArray(acc)&&key in acc){return acc[key]}return undefined},obj)}
|
|
@@ -1,336 +1 @@
|
|
|
1
|
-
import { describe, expect, it } from "
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { getDefaults, getNestedParam, getZodInputParams } from "./auto-form.js";
|
|
4
|
-
describe("auto-form helpers", ()=>{
|
|
5
|
-
describe("getDefaults", ()=>{
|
|
6
|
-
it("should return empty object when no schema provided", ()=>{
|
|
7
|
-
expect(getDefaults()).toEqual({});
|
|
8
|
-
});
|
|
9
|
-
it("should return empty object when schema has no properties", ()=>{
|
|
10
|
-
const schema = {};
|
|
11
|
-
expect(getDefaults(schema)).toEqual({});
|
|
12
|
-
});
|
|
13
|
-
it("should extract default values from simple Zod schema", ()=>{
|
|
14
|
-
const zodSchema = z.object({
|
|
15
|
-
name: z.string().default("John Doe"),
|
|
16
|
-
age: z.number().default(25),
|
|
17
|
-
active: z.boolean().default(true)
|
|
18
|
-
});
|
|
19
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
20
|
-
const result = getDefaults(jsonSchema);
|
|
21
|
-
expect(result).toEqual({
|
|
22
|
-
name: "John Doe",
|
|
23
|
-
age: 25,
|
|
24
|
-
active: true
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
it("should handle nested Zod objects with defaults", ()=>{
|
|
28
|
-
const zodSchema = z.object({
|
|
29
|
-
user: z.object({
|
|
30
|
-
name: z.string().default("Jane"),
|
|
31
|
-
settings: z.object({
|
|
32
|
-
theme: z.string().default("dark"),
|
|
33
|
-
notifications: z.boolean().default(false)
|
|
34
|
-
})
|
|
35
|
-
}),
|
|
36
|
-
title: z.string().default("Hello")
|
|
37
|
-
});
|
|
38
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
39
|
-
const result = getDefaults(jsonSchema);
|
|
40
|
-
expect(result).toEqual({
|
|
41
|
-
user: {
|
|
42
|
-
name: "Jane",
|
|
43
|
-
settings: {
|
|
44
|
-
theme: "dark",
|
|
45
|
-
notifications: false
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
title: "Hello"
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
it("should skip nested objects with no default values", ()=>{
|
|
52
|
-
const zodSchema = z.object({
|
|
53
|
-
user: z.object({
|
|
54
|
-
name: z.string(),
|
|
55
|
-
email: z.string()
|
|
56
|
-
}),
|
|
57
|
-
title: z.string().default("Hello")
|
|
58
|
-
});
|
|
59
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
60
|
-
const result = getDefaults(jsonSchema);
|
|
61
|
-
expect(result).toEqual({
|
|
62
|
-
title: "Hello"
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it("should handle mixed properties with and without defaults", ()=>{
|
|
66
|
-
const zodSchema = z.object({
|
|
67
|
-
name: z.string().default("Test"),
|
|
68
|
-
email: z.string(),
|
|
69
|
-
age: z.number().default(30),
|
|
70
|
-
bio: z.string()
|
|
71
|
-
});
|
|
72
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
73
|
-
const result = getDefaults(jsonSchema);
|
|
74
|
-
expect(result).toEqual({
|
|
75
|
-
name: "Test",
|
|
76
|
-
age: 30
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe("getZodInputParams", ()=>{
|
|
81
|
-
it("should return empty object when no schema provided", ()=>{
|
|
82
|
-
expect(getZodInputParams()).toEqual({});
|
|
83
|
-
});
|
|
84
|
-
it("should return empty object when schema has no properties", ()=>{
|
|
85
|
-
const schema = {};
|
|
86
|
-
expect(getZodInputParams(schema)).toEqual({});
|
|
87
|
-
});
|
|
88
|
-
it("should extract basic string field parameters from Zod schema", ()=>{
|
|
89
|
-
const zodSchema = z.object({
|
|
90
|
-
name: z.string().min(2).max(50).regex(/^[a-zA-Z]+$/).describe("User name")
|
|
91
|
-
});
|
|
92
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
93
|
-
const result = getZodInputParams(jsonSchema, [
|
|
94
|
-
"name"
|
|
95
|
-
]);
|
|
96
|
-
expect(result).toEqual({
|
|
97
|
-
name: {
|
|
98
|
-
type: "text",
|
|
99
|
-
minLength: 2,
|
|
100
|
-
maxLength: 50,
|
|
101
|
-
pattern: "^[a-zA-Z]+$",
|
|
102
|
-
description: "User name",
|
|
103
|
-
required: true
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
it("should handle email format from Zod schema", ()=>{
|
|
108
|
-
const zodSchema = z.object({
|
|
109
|
-
email: z.email().describe("Email address")
|
|
110
|
-
});
|
|
111
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
112
|
-
const result = getZodInputParams(jsonSchema, [
|
|
113
|
-
"email"
|
|
114
|
-
]);
|
|
115
|
-
expect(result.email).toHaveProperty("type", "email");
|
|
116
|
-
expect(result.email).toHaveProperty("description", "Email address");
|
|
117
|
-
expect(result.email).toHaveProperty("required", true);
|
|
118
|
-
expect(result.email).toHaveProperty("pattern"); // Email pattern is generated
|
|
119
|
-
});
|
|
120
|
-
it("should infer password type from field name", ()=>{
|
|
121
|
-
const zodSchema = z.object({
|
|
122
|
-
password: z.string(),
|
|
123
|
-
confirmPassword: z.string(),
|
|
124
|
-
userPassword: z.string()
|
|
125
|
-
});
|
|
126
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
127
|
-
const result = getZodInputParams(jsonSchema);
|
|
128
|
-
expect(result.password).toHaveProperty("type", "password");
|
|
129
|
-
expect(result.password).toHaveProperty("required", true);
|
|
130
|
-
expect(result.confirmPassword).toHaveProperty("type", "password");
|
|
131
|
-
expect(result.confirmPassword).toHaveProperty("required", true);
|
|
132
|
-
expect(result.userPassword).toHaveProperty("type", "password");
|
|
133
|
-
expect(result.userPassword).toHaveProperty("required", true);
|
|
134
|
-
});
|
|
135
|
-
it("should handle number and boolean types from Zod schema", ()=>{
|
|
136
|
-
const zodSchema = z.object({
|
|
137
|
-
age: z.number(),
|
|
138
|
-
count: z.number().int(),
|
|
139
|
-
active: z.boolean()
|
|
140
|
-
});
|
|
141
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
142
|
-
const result = getZodInputParams(jsonSchema);
|
|
143
|
-
expect(result.age).toHaveProperty("type", "number");
|
|
144
|
-
expect(result.age).toHaveProperty("required", true);
|
|
145
|
-
expect(result.count).toHaveProperty("type", "number");
|
|
146
|
-
expect(result.count).toHaveProperty("required", true);
|
|
147
|
-
expect(result.active).toHaveProperty("type", "checkbox");
|
|
148
|
-
expect(result.active).toHaveProperty("required", true);
|
|
149
|
-
});
|
|
150
|
-
it("should handle enum values from Zod schema", ()=>{
|
|
151
|
-
const zodSchema = z.object({
|
|
152
|
-
role: z.enum([
|
|
153
|
-
"admin",
|
|
154
|
-
"user",
|
|
155
|
-
"guest"
|
|
156
|
-
])
|
|
157
|
-
});
|
|
158
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
159
|
-
const result = getZodInputParams(jsonSchema);
|
|
160
|
-
expect(result.role).toHaveProperty("type", "text");
|
|
161
|
-
expect(result.role).toHaveProperty("enum", [
|
|
162
|
-
"admin",
|
|
163
|
-
"user",
|
|
164
|
-
"guest"
|
|
165
|
-
]);
|
|
166
|
-
expect(result.role).toHaveProperty("required", true);
|
|
167
|
-
});
|
|
168
|
-
it("should handle complex password validation", ()=>{
|
|
169
|
-
const zodSchema = z.object({
|
|
170
|
-
password: z.string().min(8).regex(/(?=.*[a-z])/, "Must contain lowercase").regex(/(?=.*[A-Z])/, "Must contain uppercase").regex(/(?=.*\d)/, "Must contain number")
|
|
171
|
-
});
|
|
172
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
173
|
-
const result = getZodInputParams(jsonSchema);
|
|
174
|
-
expect(result.password).toHaveProperty("type", "password");
|
|
175
|
-
expect(result.password).toHaveProperty("minLength", 8);
|
|
176
|
-
});
|
|
177
|
-
it("should handle nested objects from Zod schema", ()=>{
|
|
178
|
-
const zodSchema = z.object({
|
|
179
|
-
user: z.object({
|
|
180
|
-
name: z.string(),
|
|
181
|
-
email: z.email()
|
|
182
|
-
}),
|
|
183
|
-
settings: z.object({
|
|
184
|
-
theme: z.enum([
|
|
185
|
-
"light",
|
|
186
|
-
"dark"
|
|
187
|
-
]),
|
|
188
|
-
notifications: z.boolean()
|
|
189
|
-
})
|
|
190
|
-
});
|
|
191
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
192
|
-
const result = getZodInputParams(jsonSchema, [
|
|
193
|
-
"user"
|
|
194
|
-
]);
|
|
195
|
-
expect(result.user).toHaveProperty("name");
|
|
196
|
-
expect(result.user).toHaveProperty("email");
|
|
197
|
-
expect(result.settings).toHaveProperty("theme");
|
|
198
|
-
expect(result.settings).toHaveProperty("notifications");
|
|
199
|
-
});
|
|
200
|
-
it("should handle required fields from Zod schema", ()=>{
|
|
201
|
-
const zodSchema = z.object({
|
|
202
|
-
name: z.string(),
|
|
203
|
-
email: z.string(),
|
|
204
|
-
age: z.number().optional()
|
|
205
|
-
});
|
|
206
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
207
|
-
const result = getZodInputParams(jsonSchema, [
|
|
208
|
-
"name",
|
|
209
|
-
"email"
|
|
210
|
-
]);
|
|
211
|
-
expect(result.name).toHaveProperty("required", true);
|
|
212
|
-
expect(result.email).toHaveProperty("required", true);
|
|
213
|
-
expect(result.age).not.toHaveProperty("required");
|
|
214
|
-
});
|
|
215
|
-
it("should handle optional fields from Zod schema", ()=>{
|
|
216
|
-
const zodSchema = z.object({
|
|
217
|
-
name: z.string(),
|
|
218
|
-
email: z.string().optional(),
|
|
219
|
-
age: z.number().optional()
|
|
220
|
-
});
|
|
221
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
222
|
-
const result = getZodInputParams(jsonSchema, [
|
|
223
|
-
"name"
|
|
224
|
-
]);
|
|
225
|
-
expect(result.name).toHaveProperty("required", true);
|
|
226
|
-
expect(result.email).not.toHaveProperty("required");
|
|
227
|
-
expect(result.age).not.toHaveProperty("required");
|
|
228
|
-
});
|
|
229
|
-
it("should handle union types from Zod schema", ()=>{
|
|
230
|
-
const zodSchema = z.object({
|
|
231
|
-
status: z.union([
|
|
232
|
-
z.literal("active"),
|
|
233
|
-
z.literal("inactive")
|
|
234
|
-
]),
|
|
235
|
-
priority: z.number().or(z.string())
|
|
236
|
-
});
|
|
237
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
238
|
-
const result = getZodInputParams(jsonSchema);
|
|
239
|
-
expect(result).toHaveProperty("status");
|
|
240
|
-
expect(result).toHaveProperty("priority");
|
|
241
|
-
});
|
|
242
|
-
it("should handle array types from Zod schema", ()=>{
|
|
243
|
-
const zodSchema = z.object({
|
|
244
|
-
tags: z.array(z.string()),
|
|
245
|
-
numbers: z.array(z.number())
|
|
246
|
-
});
|
|
247
|
-
const jsonSchema = z.toJSONSchema(zodSchema);
|
|
248
|
-
const result = getZodInputParams(jsonSchema);
|
|
249
|
-
expect(result).toHaveProperty("tags");
|
|
250
|
-
expect(result).toHaveProperty("numbers");
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
describe("getNestedParam", ()=>{
|
|
254
|
-
const testObj = {
|
|
255
|
-
user: {
|
|
256
|
-
name: {
|
|
257
|
-
type: "text",
|
|
258
|
-
required: true
|
|
259
|
-
},
|
|
260
|
-
email: {
|
|
261
|
-
type: "email"
|
|
262
|
-
},
|
|
263
|
-
settings: {
|
|
264
|
-
theme: {
|
|
265
|
-
type: "text",
|
|
266
|
-
enum: [
|
|
267
|
-
"light",
|
|
268
|
-
"dark"
|
|
269
|
-
]
|
|
270
|
-
},
|
|
271
|
-
notifications: {
|
|
272
|
-
type: "checkbox"
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
title: {
|
|
277
|
-
type: "text",
|
|
278
|
-
default: "Hello"
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
it("should get top-level properties", ()=>{
|
|
282
|
-
const result = getNestedParam(testObj, "title");
|
|
283
|
-
expect(result).toEqual({
|
|
284
|
-
type: "text",
|
|
285
|
-
default: "Hello"
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
it("should get nested properties", ()=>{
|
|
289
|
-
const result = getNestedParam(testObj, "user.name");
|
|
290
|
-
expect(result).toEqual({
|
|
291
|
-
type: "text",
|
|
292
|
-
required: true
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
it("should get deeply nested properties", ()=>{
|
|
296
|
-
const result = getNestedParam(testObj, "user.settings.theme");
|
|
297
|
-
expect(result).toEqual({
|
|
298
|
-
type: "text",
|
|
299
|
-
enum: [
|
|
300
|
-
"light",
|
|
301
|
-
"dark"
|
|
302
|
-
]
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
it("should return undefined for non-existent paths", ()=>{
|
|
306
|
-
expect(getNestedParam(testObj, "nonexistent")).toBeUndefined();
|
|
307
|
-
expect(getNestedParam(testObj, "user.nonexistent")).toBeUndefined();
|
|
308
|
-
expect(getNestedParam(testObj, "user.settings.nonexistent")).toBeUndefined();
|
|
309
|
-
});
|
|
310
|
-
it("should return undefined for invalid paths", ()=>{
|
|
311
|
-
expect(getNestedParam(testObj, "title.invalid")).toBeUndefined();
|
|
312
|
-
expect(getNestedParam(testObj, "user.name.invalid")).toBeUndefined();
|
|
313
|
-
});
|
|
314
|
-
it("should handle empty path", ()=>{
|
|
315
|
-
const result = getNestedParam(testObj, "");
|
|
316
|
-
expect(result).toBeUndefined(); // Empty string path returns undefined
|
|
317
|
-
});
|
|
318
|
-
it("should handle paths with array values safely", ()=>{
|
|
319
|
-
const objWithArray = {
|
|
320
|
-
items: {
|
|
321
|
-
enum: [
|
|
322
|
-
"a",
|
|
323
|
-
"b",
|
|
324
|
-
"c"
|
|
325
|
-
]
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
const result = getNestedParam(objWithArray, "items.enum");
|
|
329
|
-
expect(result).toEqual([
|
|
330
|
-
"a",
|
|
331
|
-
"b",
|
|
332
|
-
"c"
|
|
333
|
-
]); // Arrays are accessible as normal properties
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
});
|
|
1
|
+
import{describe,expect,it}from"vitest";import{z}from"zod";import{getDefaults,getNestedParam,getZodInputParams}from"./auto-form.js";describe("auto-form helpers",()=>{describe("getDefaults",()=>{it("should return empty object when no schema provided",()=>{expect(getDefaults()).toEqual({})});it("should return empty object when schema has no properties",()=>{const schema={};expect(getDefaults(schema)).toEqual({})});it("should extract default values from simple Zod schema",()=>{const zodSchema=z.object({name:z.string().default("John Doe"),age:z.number().default(25),active:z.boolean().default(true)});const jsonSchema=z.toJSONSchema(zodSchema);const result=getDefaults(jsonSchema);expect(result).toEqual({name:"John Doe",age:25,active:true})});it("should handle nested Zod objects with defaults",()=>{const zodSchema=z.object({user:z.object({name:z.string().default("Jane"),settings:z.object({theme:z.string().default("dark"),notifications:z.boolean().default(false)})}),title:z.string().default("Hello")});const jsonSchema=z.toJSONSchema(zodSchema);const result=getDefaults(jsonSchema);expect(result).toEqual({user:{name:"Jane",settings:{theme:"dark",notifications:false}},title:"Hello"})});it("should skip nested objects with no default values",()=>{const zodSchema=z.object({user:z.object({name:z.string(),email:z.string()}),title:z.string().default("Hello")});const jsonSchema=z.toJSONSchema(zodSchema);const result=getDefaults(jsonSchema);expect(result).toEqual({title:"Hello"})});it("should handle mixed properties with and without defaults",()=>{const zodSchema=z.object({name:z.string().default("Test"),email:z.string(),age:z.number().default(30),bio:z.string()});const jsonSchema=z.toJSONSchema(zodSchema);const result=getDefaults(jsonSchema);expect(result).toEqual({name:"Test",age:30})})});describe("getZodInputParams",()=>{it("should return empty object when no schema provided",()=>{expect(getZodInputParams()).toEqual({})});it("should return empty object when schema has no properties",()=>{const schema={};expect(getZodInputParams(schema)).toEqual({})});it("should extract basic string field parameters from Zod schema",()=>{const zodSchema=z.object({name:z.string().min(2).max(50).regex(/^[a-zA-Z]+$/).describe("User name")});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema,["name"]);expect(result).toEqual({name:{type:"text",minLength:2,maxLength:50,pattern:"^[a-zA-Z]+$",description:"User name",required:true}})});it("should handle email format from Zod schema",()=>{const zodSchema=z.object({email:z.email().describe("Email address")});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema,["email"]);expect(result.email).toHaveProperty("type","email");expect(result.email).toHaveProperty("description","Email address");expect(result.email).toHaveProperty("required",true);expect(result.email).toHaveProperty("pattern")});it("should infer password type from field name",()=>{const zodSchema=z.object({password:z.string(),confirmPassword:z.string(),userPassword:z.string()});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema);expect(result.password).toHaveProperty("type","password");expect(result.password).toHaveProperty("required",true);expect(result.confirmPassword).toHaveProperty("type","password");expect(result.confirmPassword).toHaveProperty("required",true);expect(result.userPassword).toHaveProperty("type","password");expect(result.userPassword).toHaveProperty("required",true)});it("should handle number and boolean types from Zod schema",()=>{const zodSchema=z.object({age:z.number(),count:z.number().int(),active:z.boolean()});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema);expect(result.age).toHaveProperty("type","number");expect(result.age).toHaveProperty("required",true);expect(result.count).toHaveProperty("type","number");expect(result.count).toHaveProperty("required",true);expect(result.active).toHaveProperty("type","checkbox");expect(result.active).toHaveProperty("required",true)});it("should handle enum values from Zod schema",()=>{const zodSchema=z.object({role:z.enum(["admin","user","guest"])});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema);expect(result.role).toHaveProperty("type","text");expect(result.role).toHaveProperty("enum",["admin","user","guest"]);expect(result.role).toHaveProperty("required",true)});it("should handle complex password validation",()=>{const zodSchema=z.object({password:z.string().min(8).regex(/(?=.*[a-z])/,"Must contain lowercase").regex(/(?=.*[A-Z])/,"Must contain uppercase").regex(/(?=.*\d)/,"Must contain number")});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema);expect(result.password).toHaveProperty("type","password");expect(result.password).toHaveProperty("minLength",8)});it("should handle nested objects from Zod schema",()=>{const zodSchema=z.object({user:z.object({name:z.string(),email:z.email()}),settings:z.object({theme:z.enum(["light","dark"]),notifications:z.boolean()})});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema,["user"]);expect(result.user).toHaveProperty("name");expect(result.user).toHaveProperty("email");expect(result.settings).toHaveProperty("theme");expect(result.settings).toHaveProperty("notifications")});it("should handle required fields from Zod schema",()=>{const zodSchema=z.object({name:z.string(),email:z.string(),age:z.number().optional()});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema,["name","email"]);expect(result.name).toHaveProperty("required",true);expect(result.email).toHaveProperty("required",true);expect(result.age).not.toHaveProperty("required")});it("should handle optional fields from Zod schema",()=>{const zodSchema=z.object({name:z.string(),email:z.string().optional(),age:z.number().optional()});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema,["name"]);expect(result.name).toHaveProperty("required",true);expect(result.email).not.toHaveProperty("required");expect(result.age).not.toHaveProperty("required")});it("should handle union types from Zod schema",()=>{const zodSchema=z.object({status:z.union([z.literal("active"),z.literal("inactive")]),priority:z.number().or(z.string())});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema);expect(result).toHaveProperty("status");expect(result).toHaveProperty("priority")});it("should handle array types from Zod schema",()=>{const zodSchema=z.object({tags:z.array(z.string()),numbers:z.array(z.number())});const jsonSchema=z.toJSONSchema(zodSchema);const result=getZodInputParams(jsonSchema);expect(result).toHaveProperty("tags");expect(result).toHaveProperty("numbers")})});describe("getNestedParam",()=>{const testObj={user:{name:{type:"text",required:true},email:{type:"email"},settings:{theme:{type:"text",enum:["light","dark"]},notifications:{type:"checkbox"}}},title:{type:"text",default:"Hello"}};it("should get top-level properties",()=>{const result=getNestedParam(testObj,"title");expect(result).toEqual({type:"text",default:"Hello"})});it("should get nested properties",()=>{const result=getNestedParam(testObj,"user.name");expect(result).toEqual({type:"text",required:true})});it("should get deeply nested properties",()=>{const result=getNestedParam(testObj,"user.settings.theme");expect(result).toEqual({type:"text",enum:["light","dark"]})});it("should return undefined for non-existent paths",()=>{expect(getNestedParam(testObj,"nonexistent")).toBeUndefined();expect(getNestedParam(testObj,"user.nonexistent")).toBeUndefined();expect(getNestedParam(testObj,"user.settings.nonexistent")).toBeUndefined()});it("should return undefined for invalid paths",()=>{expect(getNestedParam(testObj,"title.invalid")).toBeUndefined();expect(getNestedParam(testObj,"user.name.invalid")).toBeUndefined()});it("should handle empty path",()=>{const result=getNestedParam(testObj,"");expect(result).toBeUndefined()});it("should handle paths with array values safely",()=>{const objWithArray={items:{enum:["a","b","c"]}};const result=getNestedParam(objWithArray,"items.enum");expect(result).toEqual(["a","b","c"])})})});
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getLocale } from "next-intl/server";
|
|
3
|
-
const { Link, redirect: redirectFromImport, usePathname, useRouter, getPathname } = createNavigation();
|
|
4
|
-
const redirect = async (href, type)=>{
|
|
5
|
-
const locale = await getLocale();
|
|
6
|
-
redirectFromImport({
|
|
7
|
-
href,
|
|
8
|
-
locale
|
|
9
|
-
}, type);
|
|
10
|
-
};
|
|
11
|
-
export { getPathname, Link, redirect, usePathname, useRouter };
|
|
1
|
+
import{createNavigation}from"next-intl/navigation";import{getLocale}from"next-intl/server";const{Link,redirect:redirectFromImport,usePathname,useRouter,getPathname}=createNavigation();const redirect=async(href,type)=>{const locale=await getLocale();redirectFromImport({href,locale},type)};export{getPathname,Link,redirect,usePathname,useRouter};
|
package/dist/src/lib/plugin.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export const removeSpecialCharacters
|
|
2
|
-
export const checkSpecialCharacters = (text)=>{
|
|
3
|
-
return /^[a-z0-9-]+$/i.test(text);
|
|
4
|
-
};
|
|
1
|
+
export const removeSpecialCharacters=(text,replaceSpace=true)=>text.trimStart().trimEnd().replace(/\s/g,replaceSpace?"-":" ").normalize("NFD").replace(/\p{Diacritic}/gu,"").replace(/[#%&?^|'{}\\/]/g,"").replace(/ł/gi,"l").replace(/@/g,"-at-").replace(/\./g,"-").replace(/-+/g,"-").trim();export const checkSpecialCharacters=text=>{return/^[a-z0-9-]+$/i.test(text)};
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { checkSpecialCharacters, removeSpecialCharacters } from "./special-characters.js";
|
|
3
|
-
describe("removeSpecialCharacters", ()=>{
|
|
4
|
-
it("should remove diacritics and replace spaces with hyphens", ()=>{
|
|
5
|
-
expect(removeSpecialCharacters("héllo wörld")).toBe("hello-world");
|
|
6
|
-
});
|
|
7
|
-
it("should keep spaces when replaceSpace is false", ()=>{
|
|
8
|
-
expect(removeSpecialCharacters("hello world", false)).toBe("hello world");
|
|
9
|
-
});
|
|
10
|
-
it("should remove special characters", ()=>{
|
|
11
|
-
expect(removeSpecialCharacters("hello#world%123")).toBe("helloworld123");
|
|
12
|
-
});
|
|
13
|
-
it("should replace @ with -at-", ()=>{
|
|
14
|
-
expect(removeSpecialCharacters("user@example.com")).toBe("user-at-example-com");
|
|
15
|
-
});
|
|
16
|
-
it("should replace dots with hyphens", ()=>{
|
|
17
|
-
expect(removeSpecialCharacters("file.name.txt")).toBe("file-name-txt");
|
|
18
|
-
});
|
|
19
|
-
it("should replace Polish ł with l", ()=>{
|
|
20
|
-
expect(removeSpecialCharacters("Łódź")).toBe("lodz");
|
|
21
|
-
});
|
|
22
|
-
it("should trim whitespace from start and end", ()=>{
|
|
23
|
-
expect(removeSpecialCharacters(" hello world ")).toBe("hello-world");
|
|
24
|
-
});
|
|
25
|
-
it("should handle empty string", ()=>{
|
|
26
|
-
expect(removeSpecialCharacters("")).toBe("");
|
|
27
|
-
});
|
|
28
|
-
it("should handle multiple special characters and spaces", ()=>{
|
|
29
|
-
expect(removeSpecialCharacters("Hello & World #123 {test}")).toBe("Hello-World-123-test");
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
describe("checkSpecialCharacters", ()=>{
|
|
33
|
-
it("should return true for alphanumeric characters and hyphens", ()=>{
|
|
34
|
-
expect(checkSpecialCharacters("hello-world-123")).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it("should return false for special characters", ()=>{
|
|
37
|
-
expect(checkSpecialCharacters("hello@world")).toBe(false);
|
|
38
|
-
});
|
|
39
|
-
it("should return false for spaces", ()=>{
|
|
40
|
-
expect(checkSpecialCharacters("hello world")).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
it("should return true for uppercase letters", ()=>{
|
|
43
|
-
expect(checkSpecialCharacters("HelloWorld")).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
it("should return true for numbers only", ()=>{
|
|
46
|
-
expect(checkSpecialCharacters("123")).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
it("should return true for hyphens only", ()=>{
|
|
49
|
-
expect(checkSpecialCharacters("-")).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
it("should return false for other special characters", ()=>{
|
|
52
|
-
expect(checkSpecialCharacters("hello#world")).toBe(false);
|
|
53
|
-
expect(checkSpecialCharacters("test.com")).toBe(false);
|
|
54
|
-
expect(checkSpecialCharacters("user&name")).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
1
|
+
import{describe,expect,it}from"vitest";import{checkSpecialCharacters,removeSpecialCharacters}from"./special-characters.js";describe("removeSpecialCharacters",()=>{it("should remove diacritics and replace spaces with hyphens",()=>{expect(removeSpecialCharacters("héllo wörld")).toBe("hello-world")});it("should keep spaces when replaceSpace is false",()=>{expect(removeSpecialCharacters("hello world",false)).toBe("hello world")});it("should remove special characters",()=>{expect(removeSpecialCharacters("hello#world%123")).toBe("helloworld123")});it("should replace @ with -at-",()=>{expect(removeSpecialCharacters("user@example.com")).toBe("user-at-example-com")});it("should replace dots with hyphens",()=>{expect(removeSpecialCharacters("file.name.txt")).toBe("file-name-txt")});it("should replace Polish ł with l",()=>{expect(removeSpecialCharacters("Łódź")).toBe("lodz")});it("should trim whitespace from start and end",()=>{expect(removeSpecialCharacters(" hello world ")).toBe("hello-world")});it("should handle empty string",()=>{expect(removeSpecialCharacters("")).toBe("")});it("should handle multiple special characters and spaces",()=>{expect(removeSpecialCharacters("Hello & World #123 {test}")).toBe("Hello-World-123-test")})});describe("checkSpecialCharacters",()=>{it("should return true for alphanumeric characters and hyphens",()=>{expect(checkSpecialCharacters("hello-world-123")).toBe(true)});it("should return false for special characters",()=>{expect(checkSpecialCharacters("hello@world")).toBe(false)});it("should return false for spaces",()=>{expect(checkSpecialCharacters("hello world")).toBe(false)});it("should return true for uppercase letters",()=>{expect(checkSpecialCharacters("HelloWorld")).toBe(true)});it("should return true for numbers only",()=>{expect(checkSpecialCharacters("123")).toBe(true)});it("should return true for hyphens only",()=>{expect(checkSpecialCharacters("-")).toBe(true)});it("should return false for other special characters",()=>{expect(checkSpecialCharacters("hello#world")).toBe(false);expect(checkSpecialCharacters("test.com")).toBe(false);expect(checkSpecialCharacters("user&name")).toBe(false)})});
|
package/dist/src/lib/utils.js
CHANGED