From 58951ec6c98433f3164523b313fc2bc8b4d1bc35 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Jun 2026 11:35:46 +0000 Subject: [PATCH] replace local serialize.ts with @haverstack/wire-types Delete src/lib/serialize.ts and update the four route files that imported from it to pull serializeRecord, serializeType, serializeVersion, and parseDate from the shared package instead. --- package.json | 1 + pnpm-lock.yaml | 10 +++++ src/lib/serialize.ts | 89 ------------------------------------------- src/routes/entity.ts | 2 +- src/routes/records.ts | 2 +- src/routes/tokens.ts | 2 +- src/routes/types.ts | 2 +- 7 files changed, 15 insertions(+), 93 deletions(-) delete mode 100644 src/lib/serialize.ts diff --git a/package.json b/package.json index 127deae..9306186 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "@haverstack/adapter-sqlite": "^0.5.0", "@haverstack/core": "^0.5.0", + "@haverstack/wire-types": "^0.5.0", "@hono/node-server": "^1.13.7", "hono": "^4.6.0", "pino": "^9.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 493ffaa..ad62e70 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@haverstack/core': specifier: ^0.5.0 version: 0.5.0 + '@haverstack/wire-types': + specifier: ^0.5.0 + version: 0.5.0 '@hono/node-server': specifier: ^1.13.7 version: 1.19.14(hono@4.12.26) @@ -404,6 +407,9 @@ packages: '@haverstack/core@0.5.0': resolution: {integrity: sha512-YIAvsWxWyM6VnZeyQhTcsujmj5VH+Oh1LmgpMzeJ4HR2Y60ml/ra+JhUh5Pvys7qm+ir+DVrxN4pZvcboQ9g/w==} + '@haverstack/wire-types@0.5.0': + resolution: {integrity: sha512-LVQz3efDKNWEjNgX6+GH7ZvyhqlRssu6hmIdZgWLj/F8U65Ap0IdX4idwWMrAIu2bzmwF3DotT/58sdRSMkEDw==} + '@hono/node-server@1.19.14': resolution: {integrity: sha512-GwtvgtXxnWsucXvbQXkRgqksiH2Qed37H9xHZocE5sA3N8O8O8/8FA3uclQXxXVzc9XBZuEOMK7+r02FmSpHtw==} engines: {node: '>=18.14.1'} @@ -1498,6 +1504,10 @@ snapshots: '@haverstack/core@0.5.0': {} + '@haverstack/wire-types@0.5.0': + dependencies: + '@haverstack/core': 0.5.0 + '@hono/node-server@1.19.14(hono@4.12.26)': dependencies: hono: 4.12.26 diff --git a/src/lib/serialize.ts b/src/lib/serialize.ts deleted file mode 100644 index 2d912d4..0000000 --- a/src/lib/serialize.ts +++ /dev/null @@ -1,89 +0,0 @@ -import type { - StackRecord, - StackType, - RecordVersion, - Association, - Permission, -} from '@haverstack/core'; - -export type WireRecord = { - id: string; - typeId: string; - createdAt: string; - updatedAt: string; - content: Record; - version: number; - parentId?: string; - entityId?: string; - appId?: string; - deletedAt?: string; - permissions?: Permission[]; - associations?: Association[]; -}; - -export type WireType = { - id: string; - baseId: string; - version: number; - name: string; - schema: Record; - schemaHash: string; - migratesFrom?: string; - createdAt: string; -}; - -export type WireVersion = { - version: number; - content: Record; - updatedAt: string; - entityId?: string; -}; - -export function serializeRecord(r: StackRecord): WireRecord { - const w: WireRecord = { - id: r.id, - typeId: r.typeId, - createdAt: r.createdAt.toISOString(), - updatedAt: r.updatedAt.toISOString(), - content: r.content, - version: r.version, - }; - if (r.parentId !== undefined) w.parentId = r.parentId; - if (r.entityId !== undefined) w.entityId = r.entityId; - if (r.appId !== undefined) w.appId = r.appId; - if (r.deletedAt !== undefined) w.deletedAt = r.deletedAt.toISOString(); - if (r.permissions !== undefined) w.permissions = r.permissions; - if (r.associations !== undefined) w.associations = r.associations; - return w; -} - -export function serializeType(t: StackType): WireType { - const w: WireType = { - id: t.id, - baseId: t.baseId, - version: t.version, - name: t.name, - schema: t.schema as Record, - schemaHash: t.schemaHash, - createdAt: t.createdAt.toISOString(), - }; - if (t.migratesFrom !== undefined) w.migratesFrom = t.migratesFrom; - return w; -} - -export function serializeVersion(v: RecordVersion): WireVersion { - const w: WireVersion = { - version: v.version, - content: v.content, - updatedAt: v.updatedAt.toISOString(), - }; - if (v.entityId !== undefined) w.entityId = v.entityId; - return w; -} - -/** Parse an ISO date string from a wire body, returns undefined if absent or invalid. */ -export function parseDate(val: unknown): Date | undefined { - if (typeof val !== 'string') return undefined; - const d = new Date(val); - return isNaN(d.getTime()) ? undefined : d; -} diff --git a/src/routes/entity.ts b/src/routes/entity.ts index 75a577b..7dd8d57 100644 --- a/src/routes/entity.ts +++ b/src/routes/entity.ts @@ -2,7 +2,7 @@ import { Hono } from 'hono'; import type { AppEnv } from '../types.js'; import type { StackContext } from '../stack.js'; import { requireAuth, requireOwner } from '../middleware/auth.js'; -import { serializeRecord } from '../lib/serialize.js'; +import { serializeRecord } from '@haverstack/wire-types'; export function entityRoutes(ctx: StackContext): Hono { const app = new Hono(); diff --git a/src/routes/records.ts b/src/routes/records.ts index dde1c16..d3c163b 100644 --- a/src/routes/records.ts +++ b/src/routes/records.ts @@ -2,7 +2,7 @@ import { Hono } from 'hono'; import type { AppEnv } from '../types.js'; import type { StackContext } from '../stack.js'; import { requireAuth } from '../middleware/auth.js'; -import { parseDate, serializeRecord, serializeVersion } from '../lib/serialize.js'; +import { parseDate, serializeRecord, serializeVersion } from '@haverstack/wire-types'; import { SYSTEM_TYPES } from '@haverstack/core'; import type { StackQuery, RecordFilter, Association, Permission, TypeId } from '@haverstack/core'; diff --git a/src/routes/tokens.ts b/src/routes/tokens.ts index c76c303..6c6c67e 100644 --- a/src/routes/tokens.ts +++ b/src/routes/tokens.ts @@ -2,7 +2,7 @@ import { Hono } from 'hono'; import type { AppEnv } from '../types.js'; import type { StackContext } from '../stack.js'; import { requireOwner } from '../middleware/auth.js'; -import { parseDate } from '../lib/serialize.js'; +import { parseDate } from '@haverstack/wire-types'; import type { TokenInfo } from '@haverstack/adapter-sqlite'; export function tokenRoutes(ctx: StackContext): Hono { diff --git a/src/routes/types.ts b/src/routes/types.ts index 039d7c1..9e3d424 100644 --- a/src/routes/types.ts +++ b/src/routes/types.ts @@ -2,7 +2,7 @@ import { Hono } from 'hono'; import type { AppEnv } from '../types.js'; import type { StackContext } from '../stack.js'; import { requireOwner } from '../middleware/auth.js'; -import { parseDate, serializeType } from '../lib/serialize.js'; +import { parseDate, serializeType } from '@haverstack/wire-types'; import { hashSchema } from '@haverstack/core'; import type { StackType, TypeSchema } from '@haverstack/core';