nuxt-precognition 0.0.6 → 0.0.7
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 +1 -1
- package/dist/module.d.mts +1 -15
- package/dist/module.d.ts +1 -15
- package/dist/module.json +5 -1
- package/dist/runtime/core.d.ts +2 -2
- package/dist/runtime/{core.mjs → core.js} +6 -6
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/{plugin.mjs → plugin.js} +1 -1
- package/dist/runtime/server/definePrecognitiveEventHandler.d.ts +3 -3
- package/dist/runtime/server/{definePrecognitiveEventHandler.mjs → definePrecognitiveEventHandler.js} +1 -1
- package/dist/runtime/types/eventHandler.d.ts +2 -2
- package/dist/runtime/types/form.d.ts +2 -2
- package/dist/runtime/useForm.d.ts +1 -1
- package/dist/runtime/{useForm.mjs → useForm.js} +2 -2
- package/dist/runtime/validator.d.ts +3 -3
- package/dist/runtime/{validator.mjs → validator.js} +1 -1
- package/dist/types.d.mts +1 -16
- package/dist/types.d.ts +1 -16
- package/package.json +2 -2
- /package/dist/runtime/server/{plugin.mjs → plugin.js} +0 -0
- /package/dist/runtime/types/{config.mjs → config.js} +0 -0
- /package/dist/runtime/types/{core.mjs → core.js} +0 -0
- /package/dist/runtime/types/{eventHandler.mjs → eventHandler.js} +0 -0
- /package/dist/runtime/types/{form.mjs → form.js} +0 -0
- /package/dist/runtime/types/{utils.mjs → utils.js} +0 -0
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ const form = useForm(
|
|
|
33
33
|
|
|
34
34
|
This module comes with native __Nitro__ integration, but will work with other backend as well.
|
|
35
35
|
|
|
36
|
-
Are you using only __Lambda__? You are covered
|
|
36
|
+
Are you using only __Lambda__? You are covered with [Lambda Precognition](https://www.npmjs.com/package/lambda-precognition)!!
|
|
37
37
|
|
|
38
38
|
It supports any validation library (_who said [__Zod__](https://zod.dev/)??_) server or client side. You will need only to configure specific `Error parsers`.
|
|
39
39
|
|
package/dist/module.d.mts
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
interface Config {
|
|
4
|
-
/** base validation timeout, @default 1500 ms */
|
|
5
|
-
validationTimeout: number;
|
|
6
|
-
/** enable backend validation @default false */
|
|
7
|
-
backendValidation: boolean;
|
|
8
|
-
/** precognitive files validation, @default false */
|
|
9
|
-
validateFiles: boolean;
|
|
10
|
-
/** enable Nuxt precognitive error parser client side, @default false */
|
|
11
|
-
enableNuxtClientErrorParser: boolean;
|
|
12
|
-
/** enable Laravel precognitive error parser client side, @default false */
|
|
13
|
-
enableLaravelClientErrorParser: boolean;
|
|
14
|
-
/** enable Laravel precognitive error parsers server side, @default false */
|
|
15
|
-
enableLaravelServerErrorParser: boolean;
|
|
16
|
-
}
|
|
2
|
+
import { Config } from '../dist/runtime/types/config.js';
|
|
17
3
|
|
|
18
4
|
interface ModuleOptions extends Config {
|
|
19
5
|
}
|
package/dist/module.d.ts
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
interface Config {
|
|
4
|
-
/** base validation timeout, @default 1500 ms */
|
|
5
|
-
validationTimeout: number;
|
|
6
|
-
/** enable backend validation @default false */
|
|
7
|
-
backendValidation: boolean;
|
|
8
|
-
/** precognitive files validation, @default false */
|
|
9
|
-
validateFiles: boolean;
|
|
10
|
-
/** enable Nuxt precognitive error parser client side, @default false */
|
|
11
|
-
enableNuxtClientErrorParser: boolean;
|
|
12
|
-
/** enable Laravel precognitive error parser client side, @default false */
|
|
13
|
-
enableLaravelClientErrorParser: boolean;
|
|
14
|
-
/** enable Laravel precognitive error parsers server side, @default false */
|
|
15
|
-
enableLaravelServerErrorParser: boolean;
|
|
16
|
-
}
|
|
2
|
+
import { Config } from '../dist/runtime/types/config.js';
|
|
17
3
|
|
|
18
4
|
interface ModuleOptions extends Config {
|
|
19
5
|
}
|
package/dist/module.json
CHANGED
package/dist/runtime/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ValidationErrorsData, ValidationErrorParser } from './types/core';
|
|
2
|
-
import type { NestedKeyOf } from './types/utils';
|
|
1
|
+
import type { ValidationErrorsData, ValidationErrorParser } from './types/core.js';
|
|
2
|
+
import type { NestedKeyOf } from './types/utils.js';
|
|
3
3
|
export declare function hasResponse(error: Error): error is Error & {
|
|
4
4
|
response: Response;
|
|
5
5
|
};
|
|
@@ -65,12 +65,12 @@ export function assertSuccessfulPrecognitiveResponses(ctx) {
|
|
|
65
65
|
if (new Headers(ctx.options.headers).get("Precognition") !== "true") {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
68
|
+
const { status, headers } = ctx.response;
|
|
69
|
+
const hasPrecognitionHeader = headers.get("Precognition") === "true";
|
|
70
|
+
const hasPrecognitionSuccessHeader = headers.get("Precognition-Success") === "true";
|
|
71
|
+
const isSuccess = hasPrecognitionHeader && hasPrecognitionSuccessHeader && status === 204;
|
|
72
|
+
const isValidationError = hasPrecognitionHeader && status === 422;
|
|
73
|
+
if (!(isSuccess || isValidationError)) {
|
|
74
74
|
throw createError({ message: "Did not receive a Precognition response. Ensure you have the Precognition middleware in place for the route and Precognitive headers have been enabled in config/cors.php.", statusCode: 500 });
|
|
75
75
|
}
|
|
76
76
|
}
|
package/dist/runtime/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EventHandler, EventHandlerObject, EventHandlerRequest, H3Event } from 'h3';
|
|
2
|
-
import type { ValidationErrorParser } from '../types/core';
|
|
3
|
-
import type { ServerStatusHandlers } from '../types/eventHandler';
|
|
4
|
-
import type { ErrorStatusCode } from '../types/utils';
|
|
2
|
+
import type { ValidationErrorParser } from '../types/core.js';
|
|
3
|
+
import type { ServerStatusHandlers } from '../types/eventHandler.js';
|
|
4
|
+
import type { ErrorStatusCode } from '../types/utils.js';
|
|
5
5
|
declare function definePrecognitiveEventHandler<TRequest extends EventHandlerRequest, TResponse>(handler: EventHandlerObject<TRequest, TResponse>, options?: {
|
|
6
6
|
errorParsers?: ValidationErrorParser[];
|
|
7
7
|
statusHandlers?: ServerStatusHandlers;
|
package/dist/runtime/server/{definePrecognitiveEventHandler.mjs → definePrecognitiveEventHandler.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasResponse, makeLaravelValidationErrorParser, resolveValidationErrorData } from "../core.
|
|
1
|
+
import { hasResponse, makeLaravelValidationErrorParser, resolveValidationErrorData } from "../core.js";
|
|
2
2
|
import { useRuntimeConfig, defineEventHandler, setResponseHeader, createError, setResponseStatus } from "#imports";
|
|
3
3
|
function definePrecognitiveEventHandler(handler, options) {
|
|
4
4
|
return defineEventHandler({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { H3Event, EventHandlerRequest } from 'h3';
|
|
2
|
-
import type { ErrorStatusCode } from './utils';
|
|
3
|
-
import type { ValidationErrorParser } from './core';
|
|
2
|
+
import type { ErrorStatusCode } from './utils.js';
|
|
3
|
+
import type { ValidationErrorParser } from './core.js';
|
|
4
4
|
export type ServerStatusHandlers = Partial<Record<ErrorStatusCode, <TRequest extends EventHandlerRequest>(error: Error, event: H3Event<TRequest>) => void | Promise<void>>>;
|
|
5
5
|
export interface PrecognitionEventContext {
|
|
6
6
|
$precognition: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ValidationErrorParser, ValidationErrorsData } from './core';
|
|
2
|
-
import type { NestedKeyOf, ErrorStatusCode } from './utils';
|
|
1
|
+
import type { ValidationErrorParser, ValidationErrorsData } from './core.js';
|
|
2
|
+
import type { NestedKeyOf, ErrorStatusCode } from './utils.js';
|
|
3
3
|
interface SubmitOptions<TData extends object, TResp> {
|
|
4
4
|
headers?: Headers;
|
|
5
5
|
onError?: (error: Error, data: TData) => Promise<void> | void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Form, UseFormOptions } from './types/form';
|
|
1
|
+
import type { Form, UseFormOptions } from './types/form.js';
|
|
2
2
|
export declare function useForm<TData extends object, TResp>(init: TData | (() => TData), cb: (form: TData, precognitiveHeaders: Headers) => Promise<TResp>, options?: UseFormOptions<TData>): TData & Form<TData, TResp>;
|
|
3
3
|
export declare namespace useForm {
|
|
4
4
|
var create: <TData extends object, TResp>(_options?: UseFormOptions<TData> | undefined) => (init: TData | (() => TData), cb: (form: TData, precognitiveHeaders: Headers) => Promise<TResp>, options?: UseFormOptions<TData> | undefined) => TData & Form<TData, TResp>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cloneDeep } from "lodash-es";
|
|
2
|
-
import { getAllNestedKeys, hasResponse, resolveDynamicObject, resolveValidationErrorData } from "./core.
|
|
3
|
-
import { makeValidator } from "./validator.
|
|
2
|
+
import { getAllNestedKeys, hasResponse, resolveDynamicObject, resolveValidationErrorData } from "./core.js";
|
|
3
|
+
import { makeValidator } from "./validator.js";
|
|
4
4
|
import { reactive, toRaw } from "#imports";
|
|
5
5
|
export function useForm(init, cb, options) {
|
|
6
6
|
const keys = Object.keys(resolveDynamicObject(init));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DebouncedFuncLeading } from 'lodash';
|
|
2
|
-
import type { NestedKeyOf } from './types/utils';
|
|
3
|
-
import type { ValidationErrorParser } from './types/core';
|
|
4
|
-
import type { ClientStatusHandlers, Form, UseFormOptions } from './types/form';
|
|
2
|
+
import type { NestedKeyOf } from './types/utils.js';
|
|
3
|
+
import type { ValidationErrorParser } from './types/core.js';
|
|
4
|
+
import type { ClientStatusHandlers, Form, UseFormOptions } from './types/form.js';
|
|
5
5
|
export declare function makeValidator<TData extends object, TResp>(cb: (data: TData, precognitiveHeaders: Headers) => Promise<TResp>, options?: UseFormOptions<TData>): {
|
|
6
6
|
validate: DebouncedFuncLeading<(form: Form<TData, TResp>, ...keys: NestedKeyOf<TData>[]) => Promise<void>>;
|
|
7
7
|
errorParsers: ValidationErrorParser[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { debounce } from "lodash-es";
|
|
2
2
|
import defu from "defu";
|
|
3
|
-
import { isFile, requestPrecognitiveHeaders, resolveValidationErrorData, makeLaravelValidationErrorParser, makeNuxtValidationErrorParser, hasResponse } from "./core.
|
|
3
|
+
import { isFile, requestPrecognitiveHeaders, resolveValidationErrorData, makeLaravelValidationErrorParser, makeNuxtValidationErrorParser, hasResponse } from "./core.js";
|
|
4
4
|
import { useNuxtApp, useRuntimeConfig } from "#imports";
|
|
5
5
|
export function makeValidator(cb, options) {
|
|
6
6
|
const { $precognition } = useNuxtApp();
|
package/dist/types.d.mts
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ModuleOptions } from './module.js'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare module '@nuxt/schema' {
|
|
6
|
-
interface NuxtConfig { ['precognition']?: Partial<ModuleOptions> }
|
|
7
|
-
interface NuxtOptions { ['precognition']?: ModuleOptions }
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module 'nuxt/schema' {
|
|
11
|
-
interface NuxtConfig { ['precognition']?: Partial<ModuleOptions> }
|
|
12
|
-
interface NuxtOptions { ['precognition']?: ModuleOptions }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export type { ModuleOptions, default } from './module.js'
|
|
1
|
+
export { type ModuleOptions, default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ModuleOptions } from './module'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare module '@nuxt/schema' {
|
|
6
|
-
interface NuxtConfig { ['precognition']?: Partial<ModuleOptions> }
|
|
7
|
-
interface NuxtOptions { ['precognition']?: ModuleOptions }
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module 'nuxt/schema' {
|
|
11
|
-
interface NuxtConfig { ['precognition']?: Partial<ModuleOptions> }
|
|
12
|
-
interface NuxtOptions { ['precognition']?: ModuleOptions }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export type { ModuleOptions, default } from './module'
|
|
1
|
+
export { type ModuleOptions, default } from './module'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-precognition",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "Nuxt module implementing Precognition protocol (inspired by official Laravel Precognition) for backend precognitive validation.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "sot1986",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@nuxt/devtools": "latest",
|
|
53
53
|
"@nuxt/eslint-config": "^0.3.12",
|
|
54
|
-
"@nuxt/module-builder": "^0.
|
|
54
|
+
"@nuxt/module-builder": "^0.8.3",
|
|
55
55
|
"@nuxt/schema": "^3.11.2",
|
|
56
56
|
"@nuxt/test-utils": "^3.12.1",
|
|
57
57
|
"@tailwindcss/forms": "^0.5.7",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|