export RepoQueryIn from client

This commit is contained in:
dswbx
2025-02-18 12:54:13 +01:00
parent dec382b49d
commit 7994eabe7d
4 changed files with 62 additions and 3 deletions

View File

@@ -1,10 +1,10 @@
import type { DB } from "core";
import type { EntityData, RepoQuery, RepoQueryIn, RepositoryResponse } from "data";
import type { EntityData, RepoQueryIn, RepositoryResponse } from "data";
import { type BaseModuleApiOptions, ModuleApi, type PrimaryFieldType } from "modules";
export type DataApiOptions = BaseModuleApiOptions & {
queryLengthLimit: number;
defaultQuery: Partial<RepoQuery>;
defaultQuery: Partial<RepoQueryIn>;
};
export class DataApi extends ModuleApi<DataApiOptions> {
@@ -78,7 +78,7 @@ export class DataApi extends ModuleApi<DataApiOptions> {
return this.delete<RepositoryResponse<Data>>(["entity", entity as any, id]);
}
count<E extends keyof DB | string>(entity: E, where: RepoQuery["where"] = {}) {
count<E extends keyof DB | string>(entity: E, where: RepoQueryIn["where"] = {}) {
return this.post<RepositoryResponse<{ entity: E; count: number }>>(
["entity", entity as any, "fn", "count"],
where

View File

@@ -165,6 +165,34 @@ export class DataController extends Controller {
// entity endpoints
hono.route("/entity", this.getEntityRoutes());
/**
* Info endpoints
*/
hono.get("/info/:entity", async (c) => {
const { entity } = c.req.param();
if (!this.entityExists(entity)) {
return c.notFound();
}
const _entity = this.em.entity(entity);
const fields = _entity.fields.map((f) => f.name);
const $rels = (r: any) =>
r.map((r: any) => ({
entity: r.other(_entity).entity.name,
ref: r.other(_entity).reference
}));
return c.json({
name: _entity.name,
fields,
relations: {
all: $rels(this.em.relations.relationsOf(_entity)),
listable: $rels(this.em.relations.listableRelationsOf(_entity)),
source: $rels(this.em.relations.sourceRelationsOf(_entity)),
target: $rels(this.em.relations.targetRelationsOf(_entity))
}
});
});
return hono.all("*", (c) => c.notFound());
}