♻️ refactor!: massive refactor

This commit is contained in:
2026-05-31 03:04:30 +07:00
parent c1f12c7201
commit df3c944547
86 changed files with 3691 additions and 1129 deletions
+18
View File
@@ -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"
}
}
+20
View File
@@ -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);
});
});
+35
View File
@@ -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>;
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src"]
}