4190fbcf90
- kbdb-client requireOwner 守衛:漏 owner 插件端即 throw,不再靜默送 owner:'' - owner 一路 thread:persistNodes/ingestEnvelope/entity-crud/triplet-crud 全必填 - 病灶修:POST /triplets/ingest 原本沒傳 owner→加 owner_id query+400 - 寫入 route 缺 owner→400;vitest 23→27 - 註:gloss-bridge 分支的 backfill/gloss-entry 另需套 owner 必填(附說明),不跨支疊改
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi';
|
|
import type { Bindings } from '../types';
|
|
import {
|
|
getPendingAliases,
|
|
confirmPendingAlias,
|
|
rejectPendingAlias,
|
|
} from '../actions/entity-pending';
|
|
import { listTripletEntities } from '../actions/triplet-entities';
|
|
import { makeKbdbClient } from '../lib/kbdb-client';
|
|
|
|
const entityRoutes = new OpenAPIHono<{ Bindings: Bindings }>();
|
|
|
|
// GET / (列出 entities)
|
|
const listEntitiesRoute = createRoute({
|
|
method: 'get',
|
|
path: '/',
|
|
request: {
|
|
query: z.object({
|
|
limit: z.string().optional(),
|
|
offset: z.string().optional(),
|
|
q: z.string().optional(),
|
|
}),
|
|
},
|
|
responses: {
|
|
200: { description: 'List of entities' },
|
|
},
|
|
tags: ['Entities'],
|
|
});
|
|
|
|
entityRoutes.openapi(listEntitiesRoute, async (c) => {
|
|
const limit = parseInt(c.req.query('limit') || '100');
|
|
const offset = parseInt(c.req.query('offset') || '0');
|
|
const q = c.req.query('q') || '';
|
|
|
|
const result = await listTripletEntities(makeKbdbClient(c.env), { limit, offset, q: q || undefined });
|
|
return c.json(result);
|
|
});
|
|
|
|
// GET /pending (列出待確認)
|
|
const listPendingRoute = createRoute({
|
|
method: 'get',
|
|
path: '/pending',
|
|
responses: {
|
|
200: { description: 'List of pending aliases' },
|
|
},
|
|
tags: ['Entities'],
|
|
});
|
|
|
|
entityRoutes.openapi(listPendingRoute, async (c) => {
|
|
const limit = parseInt(c.req.query('limit') || '100');
|
|
const pending = await getPendingAliases(makeKbdbClient(c.env), limit);
|
|
return c.json(pending);
|
|
});
|
|
|
|
entityRoutes.post('/pending/:id/confirm', async (c) => {
|
|
const id = c.req.param('id');
|
|
// owner 必經:confirm 會 addAlias(重建 entity record),缺 owner→400 不寫無主資料。
|
|
const owner = c.req.query('owner_id')?.trim();
|
|
if (!owner) return c.json({ error: 'owner_id query parameter required(資料不可無主)' }, 400);
|
|
await confirmPendingAlias(makeKbdbClient(c.env), id, owner);
|
|
return c.json({ success: true, action: 'confirmed', id });
|
|
});
|
|
|
|
entityRoutes.post('/pending/:id/reject', async (c) => {
|
|
const id = c.req.param('id');
|
|
// owner 必經:reject 會 createEntity,缺 owner→400 不寫無主資料。
|
|
const owner = c.req.query('owner_id')?.trim();
|
|
if (!owner) return c.json({ error: 'owner_id query parameter required(資料不可無主)' }, 400);
|
|
const newEntity = await rejectPendingAlias(makeKbdbClient(c.env), id, owner);
|
|
return c.json({ success: true, action: 'rejected', newEntity });
|
|
});
|
|
|
|
export { entityRoutes };
|