New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

laravel-precognition-vue

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laravel-precognition-vue - npm Package Compare versions

Comparing version

to
0.4.0

5

dist/index.d.ts

@@ -1,3 +0,4 @@

import { RequestMethod, ValidationConfig } from 'laravel-precognition';
import { RequestMethod, client, ValidationConfig } from 'laravel-precognition';
import { Form } from './types';
export declare const useForm: <Data extends Record<string, unknown>>(method: RequestMethod, url: string, inputs: Data, config?: ValidationConfig) => Data & Form<Data>;
export { client };
export declare const useForm: <Data extends Record<string, unknown>>(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data, config?: ValidationConfig) => Data & Form<Data>;

44

dist/index.js

@@ -1,2 +0,2 @@

import { client, createValidator, toSimpleValidationErrors } from 'laravel-precognition';
import { client, createValidator, toSimpleValidationErrors, resolveUrl, resolveMethod } from 'laravel-precognition';
import { reactive, ref, toRaw } from 'vue';

@@ -7,5 +7,4 @@ import cloneDeep from 'lodash.clonedeep';

import set from 'lodash.set';
export { client };
export const useForm = (method, url, inputs, config = {}) => {
// @ts-expect-error
method = method.toLowerCase();
/**

@@ -30,11 +29,13 @@ * The original data.

*/
const validator = createValidator(client => client[method](url, form.data(), config), originalData)
const validator = createValidator(client => client[resolveMethod(method)](resolveUrl(url), form.data(), config), originalData)
.on('validatingChanged', () => {
form.validating = validator.validating();
})
.on('validatedChanged', () => {
// @ts-expect-error
valid.value = validator.valid();
})
.on('touchedChanged', () => {
// @ts-expect-error
touched.value = validator.touched();
// @ts-expect-error
valid.value = validator.valid();
})

@@ -44,4 +45,2 @@ .on('errorsChanged', () => {

// @ts-expect-error
valid.value = validator.valid();
// @ts-expect-error
form.errors = toSimpleValidationErrors(validator.errors());

@@ -73,3 +72,3 @@ });

*/
const createForm = () => ({
let form = {
...cloneDeep(originalData),

@@ -85,3 +84,4 @@ data() {

Object.keys(data).forEach(input => {
this[input] = data[input];
// @ts-expect-error
form[input] = data[input];
});

@@ -94,6 +94,15 @@ return form;

},
touch(name) {
validator.touch(name);
return form;
},
validate(name) {
// @ts-expect-error
name = resolveName(name);
validator.validate(name, get(this.data(), name));
if (typeof name === 'undefined') {
validator.validate();
}
else {
// @ts-expect-error
name = resolveName(name);
validator.validate(name, get(form.data(), name));
}
return form;

@@ -140,3 +149,3 @@ },

async submit(config = {}) {
return client[method](url, form.data(), resolveSubmitConfig(config));
return client[resolveMethod(method)](resolveUrl(url), form.data(), resolveSubmitConfig(config));
},

@@ -150,8 +159,5 @@ validateFiles() {

},
});
/**
* The form instance.
*/
const form = reactive(createForm());
};
form = reactive(form);
return form;
};

@@ -6,2 +6,3 @@ import { Config, NamedInputEvent, Validator } from 'laravel-precognition';

touched(name: keyof Data): boolean;
touch(name: string | NamedInputEvent | Array<string>): Data & Form<Data>;
data(): Data;

@@ -13,3 +14,3 @@ setData(data: Record<string, unknown>): Data & Form<Data>;

invalid(name: keyof Data): boolean;
validate(name: keyof Data | NamedInputEvent): Data & Form<Data>;
validate(name?: keyof Data | NamedInputEvent): Data & Form<Data>;
setErrors(errors: Partial<Record<keyof Data, string | string[]>>): Data & Form<Data>;

@@ -16,0 +17,0 @@ forgetError(string: keyof Data | NamedInputEvent): Data & Form<Data>;

{
"name": "laravel-precognition-vue",
"version": "0.3.2",
"version": "0.4.0",
"description": "Laravel Precognition (Vue).",

@@ -34,3 +34,3 @@ "keywords": [

"dependencies": {
"laravel-precognition": "0.3.2",
"laravel-precognition": "0.4.0",
"lodash.clonedeep": "^4.5.0",

@@ -37,0 +37,0 @@ "lodash.get": "^4.4.2",