Skip to content

Commit b7fdf7f

Browse files
authored
refactor: ablate redundant abstractions across packages (#352)
1 parent c9ac453 commit b7fdf7f

74 files changed

Lines changed: 166 additions & 710 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

alias.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ export const alias = {
7474
'@devframes/json-render/hub': r('json-render/src/hub.ts'),
7575
'@devframes/json-render/node': r('json-render/src/node/index.ts'),
7676
'@devframes/json-render': r('json-render/src/index.ts'),
77-
'@devframes/json-render-ui/components': r('json-render-ui/src/components/index.ts'),
7877
'@devframes/json-render-ui/hub': r('json-render-ui/src/hub.ts'),
7978
'@devframes/json-render-ui/spa': r('json-render-ui/src/spa.ts'),
80-
'@devframes/json-render-ui': r('json-render-ui/src/index.ts'),
8179
'json-render/dashboard': fileURLToPath(new URL('./examples/json-render/src/node/dashboard.ts', import.meta.url)),
8280
'@devframes/plugin-code-server/node': p('code-server/src/node/setup.ts'),
8381
'@devframes/plugin-code-server/constants': p('code-server/src/node/constants.ts'),

knip.jsonc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@
180180
// Published node-safe entries are `spa.ts`/`hub.ts`; the browser
181181
// renderer ships only as self-contained Vite bundles (the standalone
182182
// SPA and the prebuilt renderer module, consumed at runtime via the
183-
// hub's renderer manifest). `src/index.ts` stays as the source barrel
184-
// those Vite/Storybook builds resolve, so it's declared as an entry too.
185-
"entry": ["src/{index,spa,hub}.ts", "src/renderer-module/index.ts"],
183+
// hub's renderer manifest).
184+
"entry": ["src/{spa,hub}.ts", "src/renderer-module/index.ts"],
186185
// The standalone SPA's own Vite config (`src/spa/vite.config.ts`)
187186
// mounts `unocss/vite` with no explicit config path, so UnoCSS
188187
// discovers this nested `uno.config.ts` by directory proximity to

packages/devframe/src/adapters/mcp/__tests__/to-json-schema.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ function withJsonSchema(json: Record<string, unknown>): StandardSchemaV1 {
2222

2323
describe('argsToJsonSchema', () => {
2424
it('returns an empty object schema when no args', () => {
25-
const { schema, unwrapped } = argsToJsonSchema(undefined)
26-
expect(unwrapped).toBe(false)
25+
const schema = argsToJsonSchema(undefined)
2726
expect(schema).toEqual({ type: 'object', properties: {} })
2827
})
2928

3029
it('uses the schema\'s own Standard JSON Schema converter when present', () => {
31-
const { schema } = argsToJsonSchema([withJsonSchema({ type: 'string' })])
30+
const schema = argsToJsonSchema([withJsonSchema({ type: 'string' })])
3231
expect((schema as any).properties.arg0).toEqual({ type: 'string' })
3332
})
3433

3534
it('falls back to a permissive object for validators without a native converter (valibot)', () => {
36-
const { schema } = argsToJsonSchema([v.string(), v.number()])
35+
const schema = argsToJsonSchema([v.string(), v.number()])
3736
expect((schema as any).properties.arg0).toEqual(PERMISSIVE)
3837
expect((schema as any).properties.arg1).toEqual(PERMISSIVE)
3938
expect(schema).toMatchObject({ type: 'object', required: ['arg0', 'arg1'], additionalProperties: false })

packages/devframe/src/adapters/mcp/build-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,14 @@ function projectTool(name: string, tool: AgentTool, ctx: DevframeNodeContext): T
428428

429429
function computeInputSchema(tool: AgentTool, ctx: DevframeNodeContext): unknown {
430430
if (tool.kind === 'tool')
431-
return argsToJsonSchema(tool.args).schema
431+
return argsToJsonSchema(tool.args)
432432
if (tool.kind !== 'rpc' || !tool.rpcName)
433433
return { type: 'object', properties: {} }
434434
const def = ctx.rpc.definitions.get(tool.rpcName) as RpcFunctionDefinitionAnyWithContext<DevframeNodeContext> | undefined
435435
if (!def)
436436
return { type: 'object', properties: {} }
437437
const args = def.args as readonly StandardSchemaV1[] | undefined
438-
return argsToJsonSchema(args).schema
438+
return argsToJsonSchema(args)
439439
}
440440

441441
function computeOutputSchema(tool: AgentTool, ctx: DevframeNodeContext): unknown {

packages/devframe/src/adapters/mcp/to-json-schema.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export function returnToJsonSchema(schema: StandardSchemaV1 | undefined): unknow
4848
*/
4949
export function argsToJsonSchema(
5050
args: readonly StandardSchemaV1[] | undefined,
51-
): { schema: unknown, unwrapped: boolean } {
51+
): unknown {
5252
if (!args || args.length === 0)
53-
return { schema: { type: 'object', properties: {} }, unwrapped: false }
53+
return { type: 'object', properties: {} }
5454

5555
const properties: Record<string, unknown> = {}
5656
const required: string[] = []
@@ -61,12 +61,9 @@ export function argsToJsonSchema(
6161
}
6262

6363
return {
64-
schema: {
65-
type: 'object',
66-
properties,
67-
required,
68-
additionalProperties: false,
69-
},
70-
unwrapped: false,
64+
type: 'object',
65+
properties,
66+
required,
67+
additionalProperties: false,
7168
}
7269
}

packages/devframe/src/client/rpc-live.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { DevframeConnectionStatus } from './connection'
44
import type { DevframeClientRpcHost, DevframeRpcClientMode, DevframeRpcClientOptions, RpcClientEvents } from './rpc'
55
import { createRpcClient } from 'devframe/rpc/client'
66
import { DEVFRAME_EVENTS } from '../events'
7-
import { promiseWithResolver } from '../utils/promise'
87
import { DevframeConnectionError } from './connection'
98

109
/** What a live transport's channel factory receives from the shared mode. */
@@ -53,7 +52,7 @@ export function createLiveRpcClientMode(
5352
let isTrusted = false
5453
let status: DevframeConnectionStatus = 'connecting'
5554
let connectionError: Error | null = null
56-
const trustedPromise = promiseWithResolver<boolean>()
55+
const trustedPromise = Promise.withResolvers<boolean>()
5756

5857
// ── connection status ────────────────────────────────────────────────────
5958

packages/devframe/src/client/settings.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { DevframeSettings, DevframeSettingsStore } from 'devframe/types'
22
import type { SharedState } from 'devframe/utils/shared-state'
33
import type { DevframeRpcClient } from './rpc'
4+
import { createSettingsStore } from '../settings-store'
45

56
function createClientSettingsStore<T extends Record<string, any>>(
67
rpc: DevframeRpcClient,
@@ -21,27 +22,7 @@ function createClientSettingsStore<T extends Record<string, any>>(
2122
return statePromise
2223
}
2324

24-
return {
25-
async get(key) {
26-
return ((await store()).value() as T)[key]
27-
},
28-
async set(key, value) {
29-
;(await store()).mutate((draft) => {
30-
;(draft as T)[key] = value
31-
})
32-
},
33-
async delete(key) {
34-
;(await store()).mutate((draft) => {
35-
delete (draft as T)[key]
36-
})
37-
},
38-
async all() {
39-
return (await store()).value() as Readonly<T>
40-
},
41-
async onChange(fn) {
42-
return (await store()).on('updated', full => fn(full as Readonly<T>))
43-
},
44-
}
25+
return createSettingsStore<T>(store)
4526
}
4627

4728
/**

packages/devframe/src/node/settings.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { DevframeNodeContext, DevframeRpcSharedStates, DevframeSettings, DevframeSettingsStore } from 'devframe/types'
22
import type { SharedState } from 'devframe/utils/shared-state'
33
import { join } from 'pathe'
4+
import { createSettingsStore } from '../settings-store'
45
import { createStorage } from './storage'
56

67
// Map a settings scope to the host storage scope it persists under.
@@ -32,27 +33,7 @@ function createNodeSettingsStore<T extends Record<string, any>>(
3233
return statePromise
3334
}
3435

35-
return {
36-
async get(key) {
37-
return ((await store()).value() as T)[key]
38-
},
39-
async set(key, value) {
40-
;(await store()).mutate((draft) => {
41-
;(draft as T)[key] = value
42-
})
43-
},
44-
async delete(key) {
45-
;(await store()).mutate((draft) => {
46-
delete (draft as T)[key]
47-
})
48-
},
49-
async all() {
50-
return (await store()).value() as Readonly<T>
51-
},
52-
async onChange(fn) {
53-
return (await store()).on('updated', full => fn(full as Readonly<T>))
54-
},
55-
}
36+
return createSettingsStore<T>(store)
5637
}
5738

5839
/**

packages/devframe/src/rpc/types.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import type {
44
RpcDefinitionsToFunctions,
55
RpcFunctionDefinitionToFunction,
66
} from '.'
7-
import type { AssertEqual } from './utils'
87
import * as v from 'valibot'
98
import { describe, it } from 'vitest'
109
import { defineRpcFunction } from '.'
1110

11+
/** Type-level assertion that two types are equal. */
12+
type AssertEqual<X, Y>
13+
= (<T>() => T extends X ? 1 : 2) extends
14+
(<T>() => T extends Y ? 1 : 2) ? true : never
15+
1216
/** Fake a typed Standard Schema from a non-valibot vendor. */
1317
function schema<Input, Output = Input>(): StandardSchemaV1<Input, Output> {
1418
return {

packages/devframe/src/rpc/utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { StandardSchemaV1 } from '@standard-schema/spec'
22
import type { RpcArgsSchema, RpcReturnSchema } from './types'
33

4-
/** Type-level assertion that two types are equal */
5-
export type AssertEqual<X, Y>
6-
= (<T>() => T extends X ? 1 : 2) extends
7-
(<T>() => T extends Y ? 1 : 2) ? true : never
8-
94
/** Infers a TypeScript argument tuple from a Standard Schema array */
105
export type InferArgsType<S extends RpcArgsSchema | undefined>
116
= S extends readonly [] ? []

0 commit comments

Comments
 (0)