Skip to content

Commit

Permalink
Release v0.0.1-next.2
Browse files Browse the repository at this point in the history
  • Loading branch information
accuser committed Nov 9, 2024
1 parent fd3a1ba commit bf724c7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
67 changes: 61 additions & 6 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,68 @@
declare const schemaField: {
readonly valid: (value: unknown, field: unknown) => boolean;
readonly validate: (value: unknown, field: unknown, path?: string[]) => ValidationError[];
};

interface ArrayField {
readonly type: 'Array';
readonly items: SchemaField;
readonly minItems?: number;
readonly maxItems?: number;
readonly default?: readonly unknown[];
readonly __arrayField: unique symbol;
}

interface BooleanField {
readonly type: 'Boolean';
readonly default?: boolean;
readonly __booleanField: unique symbol;
}

interface DateField {
readonly type: 'Date';
readonly format?: 'ISO-8601';
readonly default?: string;
readonly __dateField: unique symbol;
}

interface NumberField {
readonly type: 'Number';
readonly min?: number;
readonly max?: number;
readonly default?: number;
readonly __numberField: unique symbol;
}

interface ObjectField {
readonly type: 'Object';
readonly properties?: Record<string, SchemaField>;
readonly required?: readonly string[];
readonly default?: Record<string, unknown>;
readonly __objectField: unique symbol;
}

interface StringField {
readonly type: 'String';
readonly pattern?: string;
readonly enum?: readonly string[];
readonly default?: string;
}

interface SchemaFieldMap {
ArrayField: ArrayField;
BooleanField: BooleanField;
DateField: DateField;
NumberField: NumberField;
ObjectField: ObjectField;
StringField: StringField;
}
type SchemaField = SchemaFieldMap[keyof SchemaFieldMap];

declare const VALIDATION_ERROR_NAME = "ValidationError";
interface ValidationError extends Error {
readonly name: typeof VALIDATION_ERROR_NAME;
readonly path: readonly string[];
readonly __validationError: unique symbol;
}

declare const schemaField: {
readonly valid: (value: unknown, field: unknown) => boolean;
readonly validate: (value: unknown, field: unknown, path?: string[]) => ValidationError[];
};

export { type ValidationError, schemaField as default };
export { type SchemaField, type ValidationError, schemaField as default };
4 changes: 3 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typematter/schema",
"version": "0.0.1-next.1",
"version": "0.0.1-next.2",
"description": "Simple schema.",
"private": false,
"type": "module",
Expand Down

0 comments on commit bf724c7

Please sign in to comment.