@valbuild/core 0.83.0 → 0.84.0

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.
@@ -53,6 +53,7 @@ export { type SerializedUnionSchema, UnionSchema, type SerializedStringUnionSche
53
53
  export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
54
54
  export { deserializeSchema } from "./schema/deserialize.js";
55
55
  export { type ListRecordRender, type ListArrayRender, type ReifiedRender, } from "./render.js";
56
+ export type { ValRouter, RouteValidationError } from "./router.js";
56
57
  export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
57
58
  export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
58
59
  export declare const DEFAULT_CONTENT_HOST = "https://content.val.build";
@@ -70,6 +71,7 @@ declare const Internal: {
70
71
  safeResolvePath: typeof safeResolvePath;
71
72
  splitModuleFilePathAndModulePath: typeof splitModuleFilePathAndModulePath;
72
73
  joinModuleFilePathAndModulePath: typeof joinModuleFilePathAndModulePath;
74
+ nextAppRouter: import("./router.js").ValRouter;
73
75
  remote: {
74
76
  createRemoteRef: typeof createRemoteRef;
75
77
  getValidationBasis: typeof getValidationBasis;
@@ -0,0 +1,24 @@
1
+ import { ModuleFilePath } from "./val/index.js";
2
+ export type RouteValidationError = {
3
+ error: {
4
+ message: string;
5
+ urlPath: string;
6
+ expectedPath: string | null;
7
+ };
8
+ };
9
+ export declare const nextAppRouter: ValRouter;
10
+ /**
11
+ * Parse Next.js route pattern from file path
12
+ * Support multiple Next.js app directory structures:
13
+ * - /app/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"]
14
+ * - /src/app/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"]
15
+ * - /pages/blogs/[blog].tsx -> ["blogs", "[blog]"] (Pages Router)
16
+ * - /app/(group)/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"] (with groups)
17
+ * - /app/(.)feed/page.val.ts -> ["feed"] (interception route)
18
+ * - /app/(..)(dashboard)/feed/page.val.ts -> ["feed"] (interception route)
19
+ */
20
+ export declare function parseNextJsRoutePattern(moduleFilePath: string): string[];
21
+ export interface ValRouter {
22
+ getRouterId(): string;
23
+ validate(moduleFilePath: ModuleFilePath, urlPaths: string[]): RouteValidationError[];
24
+ }
@@ -40,11 +40,15 @@ export type SchemaAssertResult<Src extends SelectorSource> = {
40
40
  success: false;
41
41
  errors: Record<SourcePath, AssertError[]>;
42
42
  };
43
- export type CustomValidateFunction<Src extends SelectorSource> = (src: Src) => false | string;
43
+ export type CustomValidateFunction<Src extends SelectorSource> = (src: Src, ctx: {
44
+ path: SourcePath;
45
+ }) => false | string;
44
46
  export declare abstract class Schema<Src extends SelectorSource> {
45
47
  /** Validate the value of source content */
46
48
  protected abstract executeValidate(path: SourcePath, src: Src): ValidationErrors;
47
- protected executeCustomValidateFunctions(src: Src, customValidateFunctions: CustomValidateFunction<Src>[]): ValidationError[];
49
+ protected executeCustomValidateFunctions(src: Src, customValidateFunctions: CustomValidateFunction<Src>[], ctx: {
50
+ path: SourcePath;
51
+ }): ValidationError[];
48
52
  /**
49
53
  * Check if the **root** **type** of source is correct.
50
54
  *
@@ -9,18 +9,26 @@ import { ReifiedRender } from "../render.js";
9
9
  export type SerializedKeyOfSchema = {
10
10
  type: "keyOf";
11
11
  path: SourcePath;
12
- schema: SerializedSchema;
12
+ schema?: SerializedRefSchema | undefined;
13
13
  opt: boolean;
14
14
  values: "string" | string[];
15
15
  customValidate?: boolean;
16
16
  };
17
+ type SerializedRefSchema = {
18
+ type: "object";
19
+ keys: string[];
20
+ opt?: boolean | undefined;
21
+ } | {
22
+ type: "record";
23
+ opt?: boolean | undefined;
24
+ };
17
25
  type KeyOfSelector<Sel extends GenericSelector<SourceObject>> = Sel extends GenericSelector<infer S> ? S extends readonly Source[] ? number : S extends SourceObject ? string extends keyof S ? RawString : keyof S : S extends Record<string, Source> ? RawString : never : never;
18
26
  export declare class KeyOfSchema<Sel extends GenericSelector<SourceObject>, Src extends KeyOfSelector<Sel> | null> extends Schema<Src> {
19
27
  private readonly schema?;
20
28
  private readonly sourcePath?;
21
29
  private readonly opt;
22
30
  private readonly customValidateFunctions;
23
- constructor(schema?: SerializedSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
31
+ constructor(schema?: SerializedRefSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
24
32
  validate(validationFunction: (src: Src) => false | string): KeyOfSchema<Sel, Src>;
25
33
  protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
26
34
  protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
@@ -1,5 +1,6 @@
1
1
  import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
2
  import { RenderSelector, ReifiedRender } from "../render.js";
3
+ import { ValRouter } from "../router.js";
3
4
  import { SelectorSource } from "../selector/index.js";
4
5
  import { ImageSource } from "../source/image.js";
5
6
  import { RemoteSource } from "../source/remote.js";
@@ -10,18 +11,22 @@ export type SerializedRecordSchema = {
10
11
  type: "record";
11
12
  item: SerializedSchema;
12
13
  opt: boolean;
14
+ router?: string;
13
15
  customValidate?: boolean;
14
16
  };
15
17
  export declare class RecordSchema<T extends Schema<SelectorSource>, Src extends Record<string, SelectorOfSchema<T>> | null> extends Schema<Src> {
16
18
  private readonly item;
17
19
  private readonly opt;
18
20
  private readonly customValidateFunctions;
19
- constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
21
+ private readonly currentRouter;
22
+ constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], currentRouter?: ValRouter | null);
20
23
  validate(validationFunction: (src: Src) => false | string): RecordSchema<T, Src>;
21
24
  protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
22
25
  protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
23
26
  nullable(): RecordSchema<T, Src | null>;
24
- executeSerialize(): SerializedRecordSchema;
27
+ router(router: ValRouter): RecordSchema<T, Src>;
28
+ private getRouterValidations;
29
+ protected executeSerialize(): SerializedRecordSchema;
25
30
  private renderInput;
26
31
  protected executeRender(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedRender;
27
32
  render(input: {