Skip to content

Commit

Permalink
Type Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrich committed Jun 10, 2024
1 parent cd95195 commit ff6eb17
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/custom/schema/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {type SchemaVerifyInit} from '../../schema/verify/init';
/**
* @category Schema – Custom Type
*/
export interface CustomSchemaVerify<DataT = unknown> extends SchemaVerifyInit<DataT> {
export interface CustomSchemaVerify<InputT = unknown, DataT = unknown>
extends SchemaVerifyInit<InputT, DataT> {
typeId: string;
}
7 changes: 3 additions & 4 deletions src/custom/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import {type Resettable} from '@toreda/types';
import {type CustomSchemaType} from './schema/type';
import {Schema} from '../schema';
import {type VerifiedSchema} from '../verified/schema';
import {type VerifiedField} from '../verified/field';
import {VerifiedMap} from '../verified/map';
import {type VerifiedMap} from '../verified/map';

/**
* Registry of a single schema's registered custom types.
Expand Down Expand Up @@ -203,8 +202,8 @@ export class CustomTypes<DataT, InputT extends SchemaData<DataT>, VerifiedT = In
return fate;
}

public async verifyOnly(init: CustomSchemaVerify): Promise<Fate<VerifiedSchema<DataT>>> {
const fate = new Fate<VerifiedSchema<DataT>>();
public async verifyOnly(init: CustomSchemaVerify<InputT, DataT>): Promise<Fate<VerifiedMap<DataT>>> {
const fate = new Fate<VerifiedMap<DataT>>();

const schema = this.getSchema(init.typeId);

Expand Down
17 changes: 8 additions & 9 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {type SchemaVerifyInit} from './schema/verify/init';
import {type SchemaVerifyValue} from './schema/verify/value';
import {type VerifiedField} from './verified/field';
import {type VerifiedMap} from './verified/map';
import {type VerifiedSchema} from './verified/schema';

/**
* @category Schema
Expand Down Expand Up @@ -177,8 +176,8 @@ export class Schema<DataT, InputT extends SchemaData<DataT>, TransformedT = Inpu
value: InputT | SchemaData<InputT>,
tracer: Tracer,
base: Log
): Promise<Fate<VerifiedField<DataT>>> {
const fate = new Fate<VerifiedField<DataT>>();
): Promise<Fate<VerifiedField<DataT> | VerifiedField<DataT>[]>> {
const fate = new Fate<VerifiedField<DataT> | VerifiedField<DataT>[]>();

if (value === null) {
if (field.types.includes('null')) {
Expand Down Expand Up @@ -278,9 +277,9 @@ export class Schema<DataT, InputT extends SchemaData<DataT>, TransformedT = Inpu
* the expected range or format (if any).
*/
public async verifyValue(
init: SchemaVerifyValue<DataT, InputT>
): Promise<Fate<DataT | VerifiedField<DataT>>> {
const fate = new Fate<DataT | VerifiedField<DataT>>();
init: SchemaVerifyValue<InputT, DataT>
): Promise<Fate<DataT | VerifiedMap<DataT>>> {
const fate = new Fate<DataT | VerifiedMap<DataT>>();

if (this.isBuiltIn(init.fieldType)) {
if (this.valueHasBuiltinType(init.fieldType, init.value)) {
Expand Down Expand Up @@ -318,7 +317,7 @@ export class Schema<DataT, InputT extends SchemaData<DataT>, TransformedT = Inpu
);
}

public async verify(init: SchemaVerifyInit): Promise<Fate<TransformedT | null>> {
public async verify(init: SchemaVerifyInit<InputT, DataT>): Promise<Fate<TransformedT | null>> {
const fate = new Fate<TransformedT | null>();

if (!init) {
Expand Down Expand Up @@ -386,8 +385,8 @@ export class Schema<DataT, InputT extends SchemaData<DataT>, TransformedT = Inpu
* Verify provided data object's structure, content, and types against this schema.
* @param init
*/
public async verifyOnly(init: SchemaVerifyInit): Promise<Fate<VerifiedSchema<DataT>>> {
const fate = new Fate<VerifiedSchema<DataT>>();
public async verifyOnly(init: SchemaVerifyInit<InputT, DataT>): Promise<Fate<VerifiedMap<DataT>>> {
const fate = new Fate<VerifiedMap<DataT>>();

const currPath = init.tracer ? init.tracer : new Tracer();
// Root schemas (no parent) use their schema name as the first path item. Child schemas DO NOT
Expand Down
4 changes: 2 additions & 2 deletions src/schema/field/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @category Schema – Field
*/
export type SchemaFieldType<InputT = unknown> =
export type SchemaFieldType<DataT = unknown> =
| 'bigint[]'
| 'bigint'
| 'BigInt'
Expand Down Expand Up @@ -65,4 +65,4 @@ export type SchemaFieldType<InputT = unknown> =
| 'url[]'
| 'time'
| 'time[]'
| Extract<keyof InputT, string>;
| Extract<keyof DataT, string>;
2 changes: 1 addition & 1 deletion src/schema/verify/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {type SchemaData} from '../data';
/**
* @category Schema
*/
export interface SchemaVerifyValue<DataT = unknown, InputT = unknown> {
export interface SchemaVerifyValue<InputT = unknown, DataT = unknown> {
fieldId: string;
fieldType: SchemaFieldType<DataT>;
tracer: Tracer;
Expand Down
2 changes: 1 addition & 1 deletion src/verified/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ import {type VerifiedField} from './field';
*
* @category Schema – Transform Output
*/
export type VerifiedMap<DataT> = Map<string, VerifiedField<DataT> | null>;
export type VerifiedMap<DataT> = Map<string, VerifiedField<DataT> | VerifiedField<DataT>[] | null>;

0 comments on commit ff6eb17

Please sign in to comment.