Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/adapter-next/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
type InferFormFieldTree,
type UseFormOptions,
type UseFormResult,
useForm as createForm,
} from '@holo-js/forms/client'
createFormClient,
} from '@holo-js/forms/internal/client'

export {
type ClientSubmitContext,
Expand All @@ -19,7 +19,7 @@ export {
type UseFormOptions,
type UseFormResult,
type ValidateOnMode,
} from '@holo-js/forms/client'
} from '@holo-js/forms/internal/client'

function isPlainObject(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob)
Expand Down Expand Up @@ -112,13 +112,13 @@ export function useForm<TSchema extends FormSchema, TSuccess = unknown>(
!formRef.current
|| previousSchemaRef.current !== schemaDefinition
) {
formRef.current = createForm(schemaDefinition, resolvedOptions)
formRef.current = createFormClient(schemaDefinition, resolvedOptions)
previousSchemaRef.current = schemaDefinition
previousOptionsRef.current = options
} else {
const previousOptions = previousOptionsRef.current as UseFormOptions<TData, TSuccess>
if (!areOptionsEqual(previousOptions, options)) {
formRef.current = createForm(schemaDefinition, resolvedOptions)
formRef.current = createFormClient(schemaDefinition, resolvedOptions)
previousOptionsRef.current = options
}
}
Expand Down
30 changes: 15 additions & 15 deletions packages/adapter-next/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('@holo-js/adapter-next client', () => {
vi.resetModules()
vi.clearAllMocks()
vi.doUnmock('react')
vi.doUnmock('@holo-js/forms/client')
vi.doUnmock('@holo-js/forms/internal/client')
})

it('wraps the shared form client with a React subscription bridge', async () => {
Expand All @@ -54,8 +54,8 @@ describe('@holo-js/adapter-next client', () => {
},
}

vi.doMock('@holo-js/forms/client', () => ({
useForm: vi.fn(() => fakeForm),
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: vi.fn(() => fakeForm),
}))

vi.doMock('react', () => createReactMock({
Expand Down Expand Up @@ -115,8 +115,8 @@ describe('@holo-js/adapter-next client', () => {
hookValues: [],
}

vi.doMock('@holo-js/forms/client', () => ({
useForm: vi.fn((_schema, options: { initialValues?: { email?: string } }) => ({
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: vi.fn((_schema, options: { initialValues?: { email?: string } }) => ({
subscribe() {
return () => {}
},
Expand Down Expand Up @@ -217,8 +217,8 @@ describe('@holo-js/adapter-next client', () => {
},
}))

vi.doMock('@holo-js/forms/client', () => ({
useForm: createForm,
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: createForm,
}))

vi.doMock('react', () => createReactMock({
Expand Down Expand Up @@ -306,8 +306,8 @@ describe('@holo-js/adapter-next client', () => {
},
}))

vi.doMock('@holo-js/forms/client', () => ({
useForm: createForm,
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: createForm,
}))

vi.doMock('react', () => createReactMock({
Expand Down Expand Up @@ -418,8 +418,8 @@ describe('@holo-js/adapter-next client', () => {
},
}))

vi.doMock('@holo-js/forms/client', () => ({
useForm: createForm,
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: createForm,
}))

vi.doMock('react', () => createReactMock({
Expand Down Expand Up @@ -514,8 +514,8 @@ describe('@holo-js/adapter-next client', () => {
}
})

vi.doMock('@holo-js/forms/client', () => ({
useForm: createForm,
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: createForm,
}))

vi.doMock('react', () => createReactMock({
Expand Down Expand Up @@ -606,8 +606,8 @@ describe('@holo-js/adapter-next client', () => {
},
}))

vi.doMock('@holo-js/forms/client', () => ({
useForm: createForm,
vi.doMock('@holo-js/forms/internal/client', () => ({
createFormClient: createForm,
}))

vi.doMock('react', () => createReactMock({
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-next/tests/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('@holo-js/adapter-next package boundaries', () => {
const runtimeEntry = await readFile(runtimeEntryPath, 'utf8')

expect(indexEntry).not.toContain("@holo-js/forms")
expect(clientEntry).toContain("@holo-js/forms/client")
expect(clientEntry).toContain("@holo-js/forms/internal/client")
expect(clientEntry).not.toContain("@holo-js/auth")
expect(runtimeEntry).not.toContain("@holo-js/forms")
expect(runtimeEntry).not.toContain("@holo-js/auth")
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-next/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@holo-js/config": ["../config/src/index.ts"],
"@holo-js/core": ["../core/src/index.ts"],
"@holo-js/forms": ["../forms/src/index.ts"],
"@holo-js/forms/client": ["../forms/src/client.ts"],
"@holo-js/forms/internal/client": ["../forms/src/internal/client.ts"],
"@holo-js/security": ["../security/src/index.ts"],
"@holo-js/security/client": ["../security/src/client.ts"],
"@holo-js/session": ["../session/src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-next/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineConfig({
'@holo-js/db-postgres': resolve(__dirname, '../db-postgres/src/index.ts'),
'@holo-js/db-sqlite': resolve(__dirname, '../db-sqlite/src/index.ts'),
'@holo-js/events': resolve(__dirname, '../events/src/index.ts'),
'@holo-js/forms/client': resolve(__dirname, '../forms/src/client.ts'),
'@holo-js/forms/internal/client': resolve(__dirname, '../forms/src/internal/client.ts'),
'@holo-js/forms': resolve(__dirname, '../forms/src/index.ts'),
'@holo-js/queue': resolve(__dirname, '../queue/src/index.ts'),
'@holo-js/queue-redis': resolve(__dirname, '../queue-redis/src/index.ts'),
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-nuxt/src/runtime/composables/forms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export type {
UseFormOptions,
UseFormResult,
ValidateOnMode,
} from '@holo-js/forms/client'
} from '@holo-js/forms/internal/client'

export declare const useForm: typeof import('@holo-js/forms/client').useForm
export declare const useForm: typeof import('@holo-js/forms/internal/client').createFormClient
10 changes: 5 additions & 5 deletions packages/adapter-nuxt/src/runtime/composables/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
type InferFormFieldTree,
type UseFormOptions,
type UseFormResult,
useForm as createForm,
} from '@holo-js/forms/client'
createFormClient,
} from '@holo-js/forms/internal/client'

export {
type ClientSubmitContext,
Expand All @@ -15,7 +15,7 @@ export {
type UseFormOptions,
type UseFormResult,
type ValidateOnMode,
} from '@holo-js/forms/client'
} from '@holo-js/forms/internal/client'

type FormValuesBridge = {
readonly values: unknown
Expand Down Expand Up @@ -221,7 +221,7 @@ export function useForm<TSchema extends FormSchema, TSuccess = unknown>(
schemaDefinition: TSchema,
options: UseFormOptions<InferFormData<TSchema>, TSuccess> = {},
): UseFormResult<InferFormData<TSchema>, TSuccess, InferFormFieldTree<TSchema>> {
const form = shallowRef(createForm(schemaDefinition, options))
const form = shallowRef(createFormClient(schemaDefinition, options))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
const version = shallowRef(0)
let versionCounter = 0
const rawValues: Record<string, unknown> = {}
Expand All @@ -239,7 +239,7 @@ export function useForm<TSchema extends FormSchema, TSuccess = unknown>(
}

const stopWatching = watchEffect((onCleanup) => {
form.value = createForm(schemaDefinition, options)
form.value = createFormClient(schemaDefinition, options)
syncValuesFromForm()
version.value = ++versionCounter

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt/tests/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('@holo-js/adapter-nuxt package boundaries', () => {
expect(runtimeEntry).not.toMatch(/@holo-js\/forms/)
expect(runtimeEntry).not.toMatch(/@holo-js\/storage\/runtime/)
expect(storageEntry).toMatch(/@holo-js\/storage\/runtime/)
expect(clientEntry).toMatch(/@holo-js\/forms\/client/)
expect(clientEntry).toMatch(/@holo-js\/forms\/internal\/client/)
expect(storagePlugin).toMatch(/@holo-js\/storage\/runtime/)
expect(storageRoute).toMatch(/@holo-js\/storage/)
expect(s3Driver).toMatch(/@holo-js\/storage-s3/)
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"nitropack/runtime/plugin": ["./src/runtime/shims.d.ts"],
"nitropack/runtime/storage": ["./src/runtime/shims.d.ts"],
"@holo-js/forms": ["../forms/src/index.ts"],
"@holo-js/forms/client": ["../forms/src/client.ts"],
"@holo-js/forms/internal/client": ["../forms/src/internal/client.ts"],
"@holo-js/security": ["../security/src/index.ts"],
"@holo-js/security/client": ["../security/src/client.ts"],
"@holo-js/validation": ["../validation/src/index.ts"]
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
'@holo-js/db-mysql': resolve(__dirname, '../db-mysql/src/index.ts'),
'@holo-js/db-postgres': resolve(__dirname, '../db-postgres/src/index.ts'),
'@holo-js/db-sqlite': resolve(__dirname, '../db-sqlite/src/index.ts'),
'@holo-js/forms/client': resolve(__dirname, '../forms/src/client.ts'),
'@holo-js/forms/internal/client': resolve(__dirname, '../forms/src/internal/client.ts'),
'@holo-js/forms': resolve(__dirname, '../forms/src/index.ts'),
'@holo-js/queue': resolve(__dirname, '../queue/src/index.ts'),
'@holo-js/queue-redis': resolve(__dirname, '../queue-redis/src/index.ts'),
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-sveltekit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
type InferFormFieldTree,
type UseFormOptions,
type UseFormResult,
useForm as createForm,
} from '@holo-js/forms/client'
createFormClient,
} from '@holo-js/forms/internal/client'

export {
type ClientSubmitContext,
Expand All @@ -15,7 +15,7 @@ export {
type UseFormOptions,
type UseFormResult,
type ValidateOnMode,
} from '@holo-js/forms/client'
} from '@holo-js/forms/internal/client'

function isPlainObject(value: unknown): value is Record<string, unknown> {
return !!value
Expand Down Expand Up @@ -87,7 +87,7 @@ export function useForm<TSchema extends FormSchema, TSuccess = unknown>(
): UseFormResult<InferFormData<TSchema>, TSuccess, InferFormFieldTree<TSchema>> {
type TData = InferFormData<TSchema>

const form = createForm(schemaDefinition, options)
const form = createFormClient(schemaDefinition, options)
const subscribe = createSubscriber((update) => form.subscribe(update))
const cache = new WeakMap<object, object>()

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sveltekit/tests/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('@holo-js/adapter-sveltekit package boundaries', () => {
const transportEntry = await readFile(transportEntryPath, 'utf8')

expect(indexEntry).not.toContain("@holo-js/forms")
expect(clientEntry).toContain("@holo-js/forms/client")
expect(clientEntry).toContain("@holo-js/forms/internal/client")
expect(clientEntry).not.toContain("@holo-js/auth")
expect(transportEntry).not.toContain("@holo-js/forms")
expect(transportEntry).not.toContain("@holo-js/auth")
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sveltekit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@holo-js/config": ["../config/src/index.ts"],
"@holo-js/core": ["../core/src/index.ts"],
"@holo-js/forms": ["../forms/src/index.ts"],
"@holo-js/forms/client": ["../forms/src/client.ts"],
"@holo-js/forms/internal/client": ["../forms/src/internal/client.ts"],
"@holo-js/security": ["../security/src/index.ts"],
"@holo-js/security/client": ["../security/src/client.ts"],
"@holo-js/session": ["../session/src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sveltekit/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
'@holo-js/db-mysql': resolve(__dirname, '../db-mysql/src/index.ts'),
'@holo-js/db-postgres': resolve(__dirname, '../db-postgres/src/index.ts'),
'@holo-js/db-sqlite': resolve(__dirname, '../db-sqlite/src/index.ts'),
'@holo-js/forms/client': resolve(__dirname, '../forms/src/client.ts'),
'@holo-js/forms/internal/client': resolve(__dirname, '../forms/src/internal/client.ts'),
'@holo-js/forms': resolve(__dirname, '../forms/src/index.ts'),
'@holo-js/queue': resolve(__dirname, '../queue/src/index.ts'),
'@holo-js/queue-redis': resolve(__dirname, '../queue-redis/src/index.ts'),
Expand Down
8 changes: 4 additions & 4 deletions packages/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"import": "./dist/schema.mjs",
"default": "./dist/schema.mjs"
},
"./client": {
"types": "./dist/client.d.ts",
"import": "./dist/client.mjs",
"default": "./dist/client.mjs"
"./internal/client": {
"types": "./dist/internal/client.d.ts",
"import": "./dist/internal/client.mjs",
"default": "./dist/internal/client.mjs"
}
},
"main": "./dist/index.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import type {
FormSuccessPayload,
SerializedFormSubmission as SerializedSubmissionState,
SerializedFormSubmission,
} from './contracts'
} from '../contracts'
import {
normalizeFailureErrors,
normalizeFailureInput,
normalizeStatus,
} from './failure'
import { clearSensitiveInputValues, sanitizeFlashedInput } from './sensitiveInput'
} from '../failure'
import { clearSensitiveInputValues, sanitizeFlashedInput } from '../sensitiveInput'
import {
type FormLikeValidationInput,
createErrorBag,
Expand All @@ -25,7 +25,7 @@ import {
type WebFileLike,
validate as validateInput,
} from '@holo-js/validation'
import { getClientCsrfField } from './client-security'
import { getClientCsrfField } from '../client-security'

type PrimitiveLike = string | number | boolean | bigint | symbol | null | undefined | Date | Blob | WebFileLike

Expand Down Expand Up @@ -698,7 +698,10 @@ function isSafeMethod(method: string): boolean {
|| normalized === 'TRACE'
}

export function useForm<TSchema extends FormSchema, TSuccess = unknown>(
/**
* @internal Shared headless form runtime for framework adapters.
*/
export function createFormClient<TSchema extends FormSchema, TSuccess = unknown>(
schemaDefinition: TSchema,
options: UseFormOptions<InferFormData<TSchema>, TSuccess> = {},
): UseFormResult<InferFormData<TSchema>, TSuccess, InferFormFieldTree<TSchema>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/tests/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { createFailedSubmission, createSuccessfulSubmission, field, schema } from '../src'
import { useForm } from '../src/client'
import { createFormClient as useForm } from '../src/internal/client'

const browserGlobal = globalThis as typeof globalThis & { document?: Document }
const originalFetch = globalThis.fetch
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/tests/client.type.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'vitest'
import { field, schema } from '../src'
import { type ClientSubmitResult, type FormFieldState, type UseFormResult, useForm } from '../src/client'
import { type ClientSubmitResult, createFormClient as useForm, type FormFieldState, type UseFormResult } from '../src/internal/client'

describe('@holo-js/forms client typing', () => {
it('preserves typed fields, values, and nested field access', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/forms/tests/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,20 @@ describe('@holo-js/forms contracts', () => {
const packageJson = JSON.parse(await import('node:fs/promises').then(module => module.readFile(
new URL('../package.json', import.meta.url),
'utf8',
))) as { version?: string; dependencies?: Record<string, string>; devDependencies?: Record<string, string>; peerDependencies?: Record<string, string>; peerDependenciesMeta?: Record<string, { optional?: boolean }> }
))) as {
version?: string
exports?: Record<string, unknown>
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
peerDependencies?: Record<string, string>
peerDependenciesMeta?: Record<string, { optional?: boolean }>
}

expect(Object.keys(packageJson.dependencies ?? {})).not.toContain('@holo-js/adapter-next')
expect(Object.keys(packageJson.dependencies ?? {})).not.toContain('@holo-js/adapter-nuxt')
expect(Object.keys(packageJson.dependencies ?? {})).not.toContain('@holo-js/adapter-sveltekit')
expect(packageJson.exports).not.toHaveProperty('./client')
expect(packageJson.exports).toHaveProperty('./internal/client')
expect(Object.keys(packageJson.devDependencies ?? {})).not.toContain('next')
expect(Object.keys(packageJson.devDependencies ?? {})).not.toContain('nuxt')
expect(packageJson.peerDependencies?.['@holo-js/security']).toBe(`^${packageJson.version}`)
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/tests/docs-examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { field, schema, validate } from '../src'
import { useForm } from '../src/client'
import { createFormClient as useForm } from '../src/internal/client'

describe('@holo-js/forms documented examples', () => {
it('covers the documented registration and password reset server flows', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
entry: {
index: 'src/index.ts',
schema: 'src/schema.ts',
client: 'src/client.ts',
'internal/client': 'src/internal/client.ts',
},
format: ['esm'],
dts: true,
Expand Down