From 34e07fc68c8835e1876d402d851acfdc43073f74 Mon Sep 17 00:00:00 2001 From: Andrej Adamcik Date: Mon, 20 May 2024 16:30:47 +0200 Subject: [PATCH] feat: export modifiers (#48) --- package.json | 3 ++- src/schema/base/literal.ts | 10 +++++++--- src/schema/base/main.ts | 8 ++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ba03b19..ec748ac 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ ".": "./build/index.js", "./defaults": "./build/src/defaults.js", "./factories": "./build/factories/main.js", - "./types": "./build/src/types.js" + "./types": "./build/src/types.js", + "./schema/base/*": "./build/src/schema/base/*.js" }, "scripts": { "pretest": "npm run lint", diff --git a/src/schema/base/literal.ts b/src/schema/base/literal.ts index 83aced8..efade13 100644 --- a/src/schema/base/literal.ts +++ b/src/schema/base/literal.ts @@ -91,7 +91,9 @@ abstract class BaseModifiersType /** * Modifies the schema type to allow null values */ -class NullableModifier> extends BaseModifiersType< +export class NullableModifier< + Schema extends BaseModifiersType, +> extends BaseModifiersType< Schema[typeof ITYPE] | null, Schema[typeof OTYPE] | null, Schema[typeof COTYPE] | null @@ -124,7 +126,9 @@ class NullableModifier> extends /** * Modifies the schema type to allow undefined values */ -class OptionalModifier> extends BaseModifiersType< +export class OptionalModifier< + Schema extends BaseModifiersType, +> extends BaseModifiersType< Schema[typeof ITYPE] | undefined | null, Schema[typeof OTYPE] | undefined, Schema[typeof COTYPE] | undefined @@ -334,7 +338,7 @@ class OptionalModifier> extends /** * Modifies the schema type to allow custom transformed values */ -class TransformModifier< +export class TransformModifier< Schema extends BaseModifiersType, Output, > extends BaseModifiersType { diff --git a/src/schema/base/main.ts b/src/schema/base/main.ts index 48a21b3..63c1129 100644 --- a/src/schema/base/main.ts +++ b/src/schema/base/main.ts @@ -73,7 +73,9 @@ export abstract class BaseModifiersType /** * Modifies the schema type to allow null values */ -class NullableModifier> extends BaseModifiersType< +export class NullableModifier< + Schema extends BaseModifiersType, +> extends BaseModifiersType< Schema[typeof ITYPE] | null, Schema[typeof OTYPE] | null, Schema[typeof COTYPE] | null @@ -108,7 +110,9 @@ class NullableModifier> extends /** * Modifies the schema type to allow undefined values */ -class OptionalModifier> extends BaseModifiersType< +export class OptionalModifier< + Schema extends BaseModifiersType, +> extends BaseModifiersType< Schema[typeof ITYPE] | undefined | null, Schema[typeof OTYPE] | undefined, Schema[typeof COTYPE] | undefined