Skip to content

Commit

Permalink
Improve crud schema
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Dec 4, 2024
1 parent 20d9b3d commit c44489a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 19 deletions.
16 changes: 12 additions & 4 deletions src/endpoints/create.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import type { AnyZodObject } from "zod";
import { contentJson } from "../contentTypes";
import { InputValidationException } from "../exceptions";
import { OpenAPIRoute } from "../route";
import { type Meta, MetaGenerator, type MetaInput, type O } from "./types";
import { MetaGenerator, type Model, type O } from "./types";

export class CreateEndpoint<HandleArgs extends Array<object> = Array<object>> extends OpenAPIRoute<HandleArgs> {
get model(): MetaInput {
throw new Error("get meta not implemented");
get fields(): AnyZodObject | undefined {
return undefined;
}

get model(): Model {
throw new Error("get model not implemented");
}

get meta() {
return MetaGenerator(this.model);
return MetaGenerator({
model: this.model,
fields: this.fields,
});
}

defaultValues?: Record<string, () => any>; // TODO: move this into model
Expand Down
24 changes: 20 additions & 4 deletions src/endpoints/delete.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import type { AnyZodObject } from "zod";
import { contentJson } from "../contentTypes";
import { NotFoundException } from "../exceptions";
import { OpenAPIRoute } from "../route";
import { type FilterCondition, type Filters, type Meta, MetaGenerator, type MetaInput, type O } from "./types";
import {
type FilterCondition,
type Filters,
type Meta,
MetaGenerator,
type MetaInput,
type Model,
type O,
} from "./types";

export class DeleteEndpoint<HandleArgs extends Array<object> = Array<object>> extends OpenAPIRoute<HandleArgs> {
get model(): MetaInput {
throw new Error("get meta not implemented");
get fields(): AnyZodObject | undefined {
return undefined;
}

get model(): Model {
throw new Error("get model not implemented");
}

get meta() {
return MetaGenerator(this.model);
return MetaGenerator({
model: this.model,
fields: this.fields,
});
}

getSchema() {
Expand Down
24 changes: 20 additions & 4 deletions src/endpoints/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import type { AnyZodObject } from "zod";
import { contentJson } from "../contentTypes";
import { NotFoundException } from "../exceptions";
import { OpenAPIRoute } from "../route";
import { type FilterCondition, type ListFilters, type Meta, MetaGenerator, type MetaInput, type O } from "./types";
import {
type FilterCondition,
type ListFilters,
type Meta,
MetaGenerator,
type MetaInput,
type Model,
type O,
} from "./types";

export class FetchEndpoint<HandleArgs extends Array<object> = Array<object>> extends OpenAPIRoute<HandleArgs> {
get model(): MetaInput {
throw new Error("get meta not implemented");
get fields(): AnyZodObject | undefined {
return undefined;
}

get model(): Model {
throw new Error("get model not implemented");
}

get meta() {
return MetaGenerator(this.model);
return MetaGenerator({
model: this.model,
fields: this.fields,
});
}

getSchema() {
Expand Down
14 changes: 11 additions & 3 deletions src/endpoints/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ import {
type Meta,
MetaGenerator,
type MetaInput,
type Model,
type O,
} from "./types";

export class ListEndpoint<HandleArgs extends Array<object> = Array<object>> extends OpenAPIRoute<HandleArgs> {
get model(): MetaInput {
throw new Error("get meta not implemented");
get fields(): AnyZodObject | undefined {
return undefined;
}

get model(): Model {
throw new Error("get model not implemented");
}

get meta() {
return MetaGenerator(this.model);
return MetaGenerator({
model: this.model,
fields: this.fields,
});
}

filterFields?: Array<string>;
Expand Down
24 changes: 20 additions & 4 deletions src/endpoints/update.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import type { AnyZodObject } from "zod";
import { contentJson } from "../contentTypes";
import { InputValidationException, NotFoundException } from "../exceptions";
import { OpenAPIRoute } from "../route";
import { type FilterCondition, type Meta, MetaGenerator, type MetaInput, type O, type UpdateFilters } from "./types";
import {
type FilterCondition,
type Meta,
MetaGenerator,
type MetaInput,
type Model,
type O,
type UpdateFilters,
} from "./types";

export class UpdateEndpoint<HandleArgs extends Array<object> = Array<object>> extends OpenAPIRoute<HandleArgs> {
get model(): MetaInput {
throw new Error("get meta not implemented");
get fields(): AnyZodObject | undefined {
return undefined;
}

get model(): Model {
throw new Error("get model not implemented");
}

get meta() {
return MetaGenerator(this.model);
return MetaGenerator({
model: this.model,
fields: this.fields,
});
}

getSchema() {
Expand Down

0 comments on commit c44489a

Please sign in to comment.