@pyreon/feature 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -1,9 +1,21 @@
1
- import type { FormState, SchemaValidateFn } from '@pyreon/form'
2
- import type { QueryKey, UseMutationResult, UseQueryResult } from '@pyreon/query'
3
- import type { Computed, Signal } from '@pyreon/reactivity'
4
- import type { StoreApi } from '@pyreon/store'
5
- import type { SortingState } from '@pyreon/table'
6
- import type { FieldInfo } from './schema'
1
+ import type { FormState, SchemaValidateFn } from "@pyreon/form"
2
+ import type { QueryKey, UseMutationResult, UseQueryResult } from "@pyreon/query"
3
+ import type { Computed, Signal } from "@pyreon/reactivity"
4
+ import type { StoreApi } from "@pyreon/store"
5
+ import type { SortingState } from "@pyreon/table"
6
+ import type { FieldInfo } from "./schema"
7
+
8
+ /**
9
+ * Duck-typed schema inference. Matches Zod (`_output`), Valibot, ArkType
10
+ * without importing their types. Allows TypeScript to infer TValues from schema.
11
+ */
12
+ export type InferSchemaValues<TSchema> = TSchema extends {
13
+ _output: infer T extends Record<string, unknown>
14
+ }
15
+ ? T // Zod v3/v4: z.ZodType has _output
16
+ : TSchema extends { infer: infer T extends Record<string, unknown> }
17
+ ? T // ArkType
18
+ : Record<string, unknown>
7
19
 
8
20
  /**
9
21
  * Configuration for defining a feature.
@@ -11,8 +23,9 @@ import type { FieldInfo } from './schema'
11
23
  export interface FeatureConfig<TValues extends Record<string, unknown>> {
12
24
  /** Unique feature name — used for store ID and query key namespace. */
13
25
  name: string
14
- /** Validation schema (Zod, Valibot, or ArkType). Duck-typed — must have `safeParseAsync` for auto-validation. */
15
- schema: unknown
26
+ /** Validation schema (Zod, Valibot, or ArkType). Duck-typed — must have `safeParseAsync` for auto-validation.
27
+ * Zod schemas carry `_output` for automatic TValues inference. */
28
+ schema: { _output?: TValues } & Record<never, never>
16
29
  /** Custom schema-level validation function. If provided, overrides auto-detection from schema. */
17
30
  validate?: SchemaValidateFn<TValues>
18
31
  /** API base path (e.g., '/api/users'). */
@@ -44,13 +57,13 @@ export interface ListOptions {
44
57
  */
45
58
  export interface FeatureFormOptions<TValues extends Record<string, unknown>> {
46
59
  /** 'create' (default) or 'edit'. Edit mode uses PUT instead of POST. */
47
- mode?: 'create' | 'edit'
60
+ mode?: "create" | "edit"
48
61
  /** Item ID — required when mode is 'edit'. Used to PUT to api/:id and auto-fetch data. */
49
62
  id?: string | number
50
63
  /** Override initial values (merged with feature defaults). */
51
64
  initialValues?: Partial<TValues>
52
65
  /** When to validate: 'blur' (default), 'change', or 'submit'. */
53
- validateOn?: 'blur' | 'change' | 'submit'
66
+ validateOn?: "blur" | "change" | "submit"
54
67
  /** Callback after successful create/update. */
55
68
  onSuccess?: (result: unknown) => void
56
69
  /** Callback on submit error. */
@@ -64,9 +77,7 @@ export interface FeatureTableOptions<TValues extends Record<string, unknown>> {
64
77
  /** Subset of schema fields to show as columns. If not provided, all fields are shown. */
65
78
  columns?: (keyof TValues & string)[]
66
79
  /** Per-column overrides (header text, cell renderer, size, etc.). */
67
- columnOverrides?: Partial<
68
- Record<keyof TValues & string, Record<string, unknown>>
69
- >
80
+ columnOverrides?: Partial<Record<keyof TValues & string, Record<string, unknown>>>
70
81
  /** Page size for pagination. If not provided, pagination is disabled. */
71
82
  pageSize?: number
72
83
  }
@@ -76,7 +87,7 @@ export interface FeatureTableOptions<TValues extends Record<string, unknown>> {
76
87
  */
77
88
  export interface FeatureTableResult<TValues extends Record<string, unknown>> {
78
89
  /** The reactive TanStack Table instance. */
79
- table: Computed<import('@pyreon/table').Table<TValues>>
90
+ table: Computed<import("@pyreon/table").Table<TValues>>
80
91
  /** Sorting state signal — bind to UI controls. */
81
92
  sorting: Signal<SortingState>
82
93
  /** Global filter signal — bind to search input. */