mirror of
https://github.com/YuzuZensai/Pien-Studio.git
synced 2026-09-02 14:18:35 +00:00
♻️ refactor!: massive refactor
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@pien-studio/contracts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "^4.4.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DeviceSessionRequestSchema } from "./index";
|
||||
|
||||
describe("api contracts", () => {
|
||||
it("accepts valid device session payload", () => {
|
||||
const result = DeviceSessionRequestSchema.safeParse({
|
||||
deviceId: "abcd1234",
|
||||
locale: "ja",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects unknown locale", () => {
|
||||
const result = DeviceSessionRequestSchema.safeParse({
|
||||
deviceId: "abcd1234",
|
||||
locale: "fr",
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const LocaleSchema = z.enum(["en", "th", "ja"]);
|
||||
|
||||
export const DeviceSessionRequestSchema = z.object({
|
||||
deviceId: z.string().min(4),
|
||||
locale: LocaleSchema,
|
||||
});
|
||||
|
||||
export const DeviceSessionResponseSchema = z.object({
|
||||
token: z.string(),
|
||||
scope: z.literal("local-sync"),
|
||||
});
|
||||
|
||||
export const SyncBootstrapResponseSchema = z.object({
|
||||
replication: z.object({
|
||||
pull: z.string(),
|
||||
push: z.string(),
|
||||
strategy: z.literal("operation-log"),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ApiErrorSchema = z.object({
|
||||
error: z.object({
|
||||
code: z.string(),
|
||||
message: z.string(),
|
||||
requestId: z.string().optional(),
|
||||
details: z.unknown().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type DeviceSessionRequest = z.infer<typeof DeviceSessionRequestSchema>;
|
||||
export type DeviceSessionResponse = z.infer<typeof DeviceSessionResponseSchema>;
|
||||
export type SyncBootstrapResponse = z.infer<typeof SyncBootstrapResponseSchema>;
|
||||
export type ApiError = z.infer<typeof ApiErrorSchema>;
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user