@tailorkit/app 0.1.0-beta.23 → 0.1.0-beta.24

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.
@@ -1,18 +1,21 @@
1
1
  import { z } from "zod";
2
+ import type { AnyRelations, EmptyRelations } from "drizzle-orm/relations";
3
+ import type { DatabaseDefinition } from "../database/definition";
2
4
  import type { MutationDatabase, QueryDatabase } from "../database/types";
3
5
  import type { ActionContext, FunctionKind, Functions, Identity } from "./functions";
4
- type HandlerContext<K extends FunctionKind, A extends z.ZodType, F extends Functions> = {
6
+ type HandlerContext<K extends FunctionKind, A extends z.ZodType, F extends Functions, D extends AnyRelations> = {
5
7
  input: z.output<A>;
6
8
  } & (K extends "action" ? ActionContext<F> : {
7
- db: K extends "query" ? QueryDatabase : MutationDatabase;
9
+ db: K extends "query" ? QueryDatabase<D> : MutationDatabase<D>;
8
10
  identity: Identity;
9
11
  });
10
12
  type OutputInput<R> = R extends z.ZodType ? z.input<R> : unknown;
11
13
  type HandlerOutput<K, O> = K extends "action" ? O | Promise<O> : O & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
12
- type BuiltFunction<K extends FunctionKind, A extends z.ZodType, R, O, F extends Functions> = {
14
+ type BuiltFunction<K extends FunctionKind, A extends z.ZodType, R, O, F extends Functions, D extends AnyRelations> = {
13
15
  readonly kind: K;
14
16
  readonly args: A;
15
- readonly handler: (context: Omit<HandlerContext<K, A, F>, "input"> & {
17
+ readonly database?: DatabaseDefinition<D>;
18
+ readonly handler: (context: Omit<HandlerContext<K, A, F, D>, "input"> & {
16
19
  args: z.output<A>;
17
20
  }) => HandlerOutput<K, O>;
18
21
  } & (R extends z.ZodType ? {
@@ -21,20 +24,22 @@ type BuiltFunction<K extends FunctionKind, A extends z.ZodType, R, O, F extends
21
24
  readonly functions: F;
22
25
  } : unknown);
23
26
  /** Immutable builders preserve the validated input and wire output types at every step. */
24
- declare class FunctionBuilder<K extends FunctionKind, A extends z.ZodType, R extends z.ZodType | undefined = undefined, F extends Functions = Record<never, never>> {
27
+ declare class FunctionBuilder<K extends FunctionKind, A extends z.ZodType, R extends z.ZodType | undefined = undefined, F extends Functions = Record<never, never>, D extends AnyRelations = EmptyRelations> {
25
28
  private readonly kind;
26
29
  private readonly args;
27
30
  private readonly result;
28
31
  private readonly calls;
29
- constructor(kind: K, args: A, result: R, calls: F);
30
- input<S extends z.ZodType>(schema: S): FunctionBuilder<K, S, R, F>;
31
- output<S extends z.ZodType>(schema: S): FunctionBuilder<K, A, S, F>;
32
- functions<const G extends Functions>(this: FunctionBuilder<"action", A, R, F>, functions: G): FunctionBuilder<"action", A, R, G>;
33
- handler<O extends OutputInput<R>>(handler: (context: HandlerContext<K, A, F>) => HandlerOutput<K, O>): BuiltFunction<K, A, R, O, F>;
32
+ private readonly databaseDefinition;
33
+ constructor(kind: K, args: A, result: R, calls: F, database?: DatabaseDefinition<D>);
34
+ input<S extends z.ZodType>(schema: S): FunctionBuilder<K, S, R, F, D>;
35
+ output<S extends z.ZodType>(schema: S): FunctionBuilder<K, A, S, F, D>;
36
+ functions<const G extends Functions>(this: FunctionBuilder<"action", A, R, F, D>, functions: G): FunctionBuilder<"action", A, R, G, D>;
37
+ database<const E extends AnyRelations>(this: FunctionBuilder<K, A, R, F, D> & (K extends "action" ? never : unknown), database: DatabaseDefinition<E>): FunctionBuilder<K, A, R, F, E>;
38
+ handler<O extends OutputInput<R>>(handler: (context: HandlerContext<K, A, F, D>) => HandlerOutput<K, O>): BuiltFunction<K, A, R, O, F, D>;
34
39
  }
35
40
  export declare const tk: Readonly<{
36
- query: FunctionBuilder<"query", z.ZodUndefined, undefined, {}>;
37
- mutation: FunctionBuilder<"mutation", z.ZodUndefined, undefined, {}>;
38
- action: FunctionBuilder<"action", z.ZodUndefined, undefined, {}>;
41
+ query: FunctionBuilder<"query", z.ZodUndefined, undefined, {}, EmptyRelations>;
42
+ mutation: FunctionBuilder<"mutation", z.ZodUndefined, undefined, {}, EmptyRelations>;
43
+ action: FunctionBuilder<"action", z.ZodUndefined, undefined, {}, EmptyRelations>;
39
44
  }>;
40
45
  export {};
@@ -13,5 +13,5 @@ export interface ApplicationModule {
13
13
  /** Emitted by this SDK's builder; breaking interface changes increment apiVersion. */
14
14
  export declare const runtimeManifest: {
15
15
  readonly apiVersion: 1;
16
- readonly requires: readonly ["database", "actions"];
16
+ readonly requires: readonly ["database", "actions", "database-relations"];
17
17
  };
@@ -1,4 +1,6 @@
1
1
  import type { z } from "zod";
2
+ import type { AnyRelations, EmptyRelations } from "drizzle-orm/relations";
3
+ import type { DatabaseDefinition } from "../database/definition";
2
4
  import type { QueryDatabase, MutationDatabase } from "../database/types";
3
5
  export interface Identity {
4
6
  readonly userId: string;
@@ -34,37 +36,41 @@ export interface ActionContext<F extends Functions = Record<never, never>> {
34
36
  readonly queries: FunctionCalls<F, "query">;
35
37
  readonly mutations: FunctionCalls<F, "mutation">;
36
38
  }
37
- export interface FunctionDefinition<K extends FunctionKind, A extends z.ZodType, O, F extends Functions = Record<never, never>> {
39
+ export interface FunctionDefinition<K extends FunctionKind, A extends z.ZodType, O, F extends Functions = Record<never, never>, D extends AnyRelations = EmptyRelations> {
38
40
  readonly kind: K;
39
41
  readonly args: A;
42
+ readonly database?: K extends "action" ? never : DatabaseDefinition<D>;
40
43
  readonly result?: z.ZodType<O>;
41
44
  readonly handler: (context: {
42
45
  args: z.output<A>;
43
46
  } & (K extends "action" ? ActionContext<F> : {
44
- db: K extends "query" ? QueryDatabase : MutationDatabase;
47
+ db: K extends "query" ? QueryDatabase<D> : MutationDatabase<D>;
45
48
  identity: Identity;
46
49
  })) => K extends "action" ? O | Promise<O> : O;
47
50
  }
48
- export declare function query<A extends z.ZodType, O>(definition: Omit<FunctionDefinition<"query", A, O>, "kind"> & {
49
- handler: FunctionDefinition<"query", A, O>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
51
+ export declare function query<A extends z.ZodType, O, const D extends AnyRelations = EmptyRelations>(definition: Omit<FunctionDefinition<"query", A, O, Record<never, never>, D>, "kind"> & {
52
+ handler: FunctionDefinition<"query", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
50
53
  }): Readonly<{
51
54
  args: A;
55
+ database?: DatabaseDefinition<D> | undefined;
52
56
  result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
53
- handler: FunctionDefinition<"query", A, O>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
57
+ handler: FunctionDefinition<"query", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
54
58
  kind: "query";
55
59
  }>;
56
- export declare function mutation<A extends z.ZodType, O>(definition: Omit<FunctionDefinition<"mutation", A, O>, "kind"> & {
57
- handler: FunctionDefinition<"mutation", A, O>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
60
+ export declare function mutation<A extends z.ZodType, O, const D extends AnyRelations = EmptyRelations>(definition: Omit<FunctionDefinition<"mutation", A, O, Record<never, never>, D>, "kind"> & {
61
+ handler: FunctionDefinition<"mutation", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
58
62
  }): Readonly<{
59
63
  args: A;
64
+ database?: DatabaseDefinition<D> | undefined;
60
65
  result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
61
- handler: FunctionDefinition<"mutation", A, O>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
66
+ handler: FunctionDefinition<"mutation", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
62
67
  kind: "mutation";
63
68
  }>;
64
69
  export declare function action<A extends z.ZodType, O, const F extends Functions = Record<never, never>>(definition: Omit<FunctionDefinition<"action", A, O, F>, "kind"> & {
65
70
  functions?: F;
66
71
  }): Readonly<{
67
72
  args: A;
73
+ database?: undefined;
68
74
  result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
69
75
  handler: (context: {
70
76
  args: z.infer<A>;
@@ -78,6 +84,7 @@ export type RegisteredFunction = {
78
84
  result?: z.ZodType;
79
85
  handler: (context: never) => unknown;
80
86
  functions?: Functions;
87
+ database?: DatabaseDefinition;
81
88
  };
82
89
  export interface Functions {
83
90
  readonly [name: string]: RegisteredFunction | Functions;
package/dist/server.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { defineServer, query, mutation, action } from "./server/functions";
2
+ export { defineDatabase } from "./database/definition";
3
+ export type { DatabaseDefinition } from "./database/definition";
2
4
  export { tk } from "./server/builder";
3
5
  export { withInstanceResolvers } from "./server/instances";
4
6
  export type { QueryDatabase, MutationDatabase } from "./database/types";
package/dist/server.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  asc,
5
5
  boolean,
6
6
  count,
7
+ defineDatabase,
7
8
  defineServer,
8
9
  desc,
9
10
  eq,
@@ -24,7 +25,7 @@ import {
24
25
  text,
25
26
  tk,
26
27
  withInstanceResolvers
27
- } from "./chunk-7NOEYJOB.js";
28
+ } from "./chunk-ANTVMHDZ.js";
28
29
  import {
29
30
  AppError
30
31
  } from "./chunk-IJBQ77AH.js";
@@ -35,6 +36,7 @@ export {
35
36
  asc,
36
37
  boolean,
37
38
  count,
39
+ defineDatabase,
38
40
  defineServer,
39
41
  desc,
40
42
  eq,
package/dist/views.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { h } from "preact";
2
- import type { ComponentChild, ComponentChildren, ComponentType, VNode } from "preact";
2
+ import type { ComponentChild, ComponentChildren, VNode } from "preact";
3
3
  import type { z } from "zod";
4
4
  import type { FunctionCalls, Identity } from "./server/functions";
5
5
  export interface TailorKitViews {
@@ -61,16 +61,6 @@ export interface ViewDefinition<TPath extends AppViewPath = AppViewPath, TData =
61
61
  resolver: string;
62
62
  };
63
63
  }
64
- type InvalidViewPath<TViews> = Exclude<keyof TViews & string, AppViewPath>;
65
- type RequireViewPaths<TViews> = InvalidViewPath<TViews> extends never ? unknown : {
66
- readonly __tailorkit_error__: `View paths must be declared by the host. Invalid view: ${InvalidViewPath<TViews>}`;
67
- };
68
- type ViewKeyPathMismatch<TViews> = {
69
- [TPath in keyof TViews & string]: TViews[TPath] extends false ? never : TViews[TPath] extends ViewDefinition<infer TViewPath> ? TViewPath extends TPath ? never : TPath : TPath;
70
- }[keyof TViews & string];
71
- type RequireMatchingViewKeys<TViews> = ViewKeyPathMismatch<TViews> extends never ? unknown : {
72
- readonly __tailorkit_error__: `View key must match defineView path. Invalid view: ${ViewKeyPathMismatch<TViews>}`;
73
- };
74
64
  export type SlotView<TSlot extends SlotName> = TailorKitSlots[TSlot] extends {
75
65
  views: infer TViews;
76
66
  } ? Extract<TViews, AppViewPath> : never;
@@ -88,15 +78,8 @@ type SlotDefinitions = {
88
78
  [P in SlotView<V>]: (ViewDefinition<P, unknown, V> & SlotInstanceDefinition<V>) | false;
89
79
  }>;
90
80
  };
91
- type RequireSlotViews<V, S> = V extends SlotName ? Exclude<keyof S, SlotView<V>> extends never ? unknown : {
92
- readonly __tailorkit_error__: "View is not supported by this slot";
93
- } : never;
94
81
  export interface TailorKitClient<TSlots extends SlotDefinitions = SlotDefinitions> {
95
82
  slots: TSlots;
96
- /** Wrap the app root with providers shared by every view. */
97
- component?: ComponentType<{
98
- children?: ComponentChildren;
99
- }>;
100
83
  }
101
84
  export interface TailorKitClientMeta {
102
85
  preactVersion: string;
@@ -124,12 +107,15 @@ type ViewOptions<TPath extends AppViewPath, TSlot extends SlotName, TSchema exte
124
107
  instances?: never;
125
108
  });
126
109
  }[TSlot];
127
- export declare const defineView: <const TPath extends AppViewPath, const TSlot extends SlotName, TSchema extends z.ZodType>(options: ViewOptions<TPath, TSlot, TSchema>) => ViewDefinition<TPath, z.output<TSchema>, TSlot> & SlotInstanceDefinition<TSlot>;
128
- export declare const defineClient: <const TSlots extends SlotDefinitions>(client: TailorKitClient<TSlots> & {
129
- slots: { [V in keyof TSlots]: TSlots[V] & RequireViewPaths<TSlots[V]> & RequireMatchingViewKeys<TSlots[V]> & RequireSlotViews<V, TSlots[V]>; };
130
- } & (Exclude<keyof TSlots, SlotName> extends never ? unknown : {
131
- __tailorkit_error__: "Unknown slot";
132
- })) => TailorKitClientWithMeta<TSlots>;
110
+ /** In .view.tsx files, the builder supplies the slot and filename-derived path.
111
+ * Keep an explicit view for a custom path and precise host context typing. */
112
+ export declare function defineView<const TPath extends AppViewPath = AppViewPath, TSchema extends z.ZodType = z.ZodType>(options: {
113
+ slot?: never;
114
+ view?: TPath;
115
+ component: View<Record<string, never>>;
116
+ instances?: ViewInstances<TPath, TSchema>;
117
+ }): ViewDefinition<TPath, z.output<TSchema>>;
118
+ export declare function defineView<const TPath extends AppViewPath, const TSlot extends SlotName, TSchema extends z.ZodType>(options: ViewOptions<TPath, TSlot, TSchema>): ViewDefinition<TPath, z.output<TSchema>, TSlot> & SlotInstanceDefinition<TSlot>;
133
119
  export declare const createRemoteComponent: <TProps extends object, TChildren extends boolean = false>(name: string, options?: {
134
120
  callbacks?: Record<string, number>;
135
121
  children?: TChildren;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailorkit/app",
3
- "version": "0.1.0-beta.23",
3
+ "version": "0.1.0-beta.24",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,6 +39,10 @@
39
39
  "./protocol": {
40
40
  "types": "./dist/protocol.d.ts",
41
41
  "import": "./dist/protocol.js"
42
+ },
43
+ "./client/connection": {
44
+ "types": "./dist/client/connection.d.ts",
45
+ "import": "./dist/client-connection.js"
42
46
  }
43
47
  },
44
48
  "publishConfig": {