refactor(api)!: align client with canonical HTTP contract
Route all feature requests through business API modules, sync generated DTOs, and add communication tests and architecture documentation. BREAKING CHANGE: migrate the client to plural resource paths, canonical snake_case fields, ISO timestamps, and explicit paginated responses.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
import { format, resolveConfig } from 'prettier'
|
||||
|
||||
const source = resolve(process.env.OPENCLOUD_API_DIR || '../hono-api', 'contracts/api.ts')
|
||||
const target = resolve('src/types/api-contract.ts')
|
||||
const output = await format(await readFile(source, 'utf8'), {
|
||||
...(await resolveConfig(target)),
|
||||
filepath: target,
|
||||
})
|
||||
if (process.argv.includes('--check')) {
|
||||
if ((await readFile(target, 'utf8')) !== output) {
|
||||
throw new Error('API 契约已变化,请先在后端生成,再运行 npm run api:sync')
|
||||
}
|
||||
} else {
|
||||
await writeFile(target, output)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { registerHooks } from 'node:module'
|
||||
import { existsSync } from 'node:fs'
|
||||
|
||||
const source = new URL('../src/', import.meta.url)
|
||||
registerHooks({
|
||||
resolve(specifier, context, nextResolve) {
|
||||
if (specifier.startsWith('@/')) {
|
||||
return nextResolve(new URL(`${specifier.slice(2)}.ts`, source).href, context)
|
||||
}
|
||||
if (specifier.startsWith('.') && context.parentURL?.startsWith(source.href)) {
|
||||
const candidate = new URL(`${specifier}.ts`, context.parentURL)
|
||||
if (existsSync(candidate)) return nextResolve(candidate.href, context)
|
||||
}
|
||||
return nextResolve(specifier, context)
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user