Add initial project files

This commit is contained in:
Igor Martyniuk
2026-09-01 13:03:41 +03:00
parent 22e111bb44
commit 74cb5b6176
1841 changed files with 242819 additions and 30 deletions
@@ -0,0 +1,26 @@
import vine from '@vinejs/vine'
function isValidJsonValue(value: any): boolean {
if (value === null) return true
if (['string', 'number', 'boolean'].includes(typeof value)) return true
if (Array.isArray(value)) {
return value.every(isValidJsonValue)
}
if (typeof value === 'object' && Object.prototype.toString.call(value) === '[object Object]') {
return Object.values(value).every(isValidJsonValue)
}
return false
}
export const anyJsonRule = vine.createRule((value, _options, field) => {
if (value === undefined || value === null) {
return
}
if (!isValidJsonValue(value)) {
field.report('Not valid JSON in {{ field }}', 'anyJson', field)
}
})
@@ -0,0 +1,23 @@
import { VineMultipartFile } from '@adonisjs/core/vine'
import { OptionalModifier } from '@vinejs/vine/schema/base/literal'
import vine from '@vinejs/vine'
/**
* Creates a reusable upload file schema that requires either:
* - `ref` (reference to an existing file), or
* - `file` (new uploaded file).
*
* At least one field must be present. When `ref` is missing, `file`
* becomes required. When `file` is missing, `ref` becomes required.
*
* @param fileScheme Custom optional file validation schema.
* @returns Vine object schema with mutually dependent `ref` and `file` fields.
*/
export default function createFileInputSchema(
fileScheme: OptionalModifier<VineMultipartFile> = vine.file({ size: '5mb' }).optional()
) {
return vine.object({
ref: vine.string().optional().requiredIfMissing('file'),
file: fileScheme.requiredIfMissing('ref'),
})
}
@@ -0,0 +1,13 @@
import vine from '@vinejs/vine'
export type JsonValue =
| string
| number
| boolean
| null
| JsonValue[]
| { [key: string]: JsonValue }
export type JsonObject = Record<string, JsonValue>
export const jsonObjectSchema = vine.object({}).allowUnknownProperties<JsonValue>()