@tailorkit/app 0.1.0-beta.14 → 0.1.0-beta.16

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/dist/index.js CHANGED
@@ -1,73 +1,82 @@
1
- // src/index.ts
2
- import { createContext, h, render } from "preact";
3
- import { useContext } from "preact/hooks";
4
- var preactVersion = "10.29.8";
5
- var createView = (path, options) => {
6
- const Context = createContext(null);
7
- const View = (props) => {
8
- if (props.status === "loading") {
9
- return options.loading ? h(options.loading, {}) : null;
10
- }
11
- if (props.status === "error") {
12
- return options.error ? h(options.error, {}) : null;
13
- }
14
- return h(
15
- Context.Provider,
16
- { value: props.context },
17
- h(options.component, {})
18
- );
19
- };
20
- return {
21
- component: View,
22
- path,
23
- useContext: () => {
24
- const context = useContext(Context);
25
- if (context === null) {
26
- throw new Error(`View context is only available while rendering "${path}".`);
27
- }
28
- return context;
29
- }
30
- };
31
- };
32
- var defineClient = (client) => ({
33
- ...client,
34
- $meta: { preactVersion },
35
- $runtime: { h, render }
36
- });
37
- var componentTagPrefix = "tailorkit-";
38
- var toComponentTagName = (name) => `${componentTagPrefix}${name.replaceAll(/([a-z0-9])([A-Z])/gu, "$1-$2").replaceAll(/[\s_]+/gu, "-").toLowerCase()}`;
39
- var toCallbackEventName = (name) => `tailorkitcallback${name.replaceAll(/[^A-Za-z0-9_$]/gu, "").toLowerCase()}`;
40
- var toEventProp = (event) => `on${event}`;
41
- var createRemoteComponent = (name, options = {}) => {
42
- const tagName = toComponentTagName(name);
43
- const callbacks = options.callbacks ?? {};
44
- return function RemoteComponent({ children, ...props }) {
45
- const nextProps = { ...props };
46
- const callbackMap = {};
47
- for (const [key, inputCount] of Object.entries(callbacks)) {
48
- const callback = nextProps[key];
49
- Reflect.deleteProperty(nextProps, key);
50
- if (typeof callback !== "function") {
51
- continue;
52
- }
53
- const eventName = toCallbackEventName(key);
54
- callbackMap[eventName] = { callback: key, inputCount };
55
- nextProps[toEventProp(eventName)] = (event) => {
56
- callback(...(event.detail ?? []).slice(0, inputCount));
57
- };
58
- }
59
- const serializedProps = Object.fromEntries(
60
- Object.entries(nextProps).filter(([, value]) => typeof value !== "function")
61
- );
62
- nextProps["data-tailorkit-props"] = JSON.stringify(serializedProps);
63
- if (Object.keys(callbackMap).length > 0) {
64
- nextProps["data-tailorkit-callbacks"] = JSON.stringify(callbackMap);
65
- }
66
- return h(tagName, nextProps, options.children ? children : void 0);
67
- };
68
- };
1
+ import {
2
+ ClientProvider,
3
+ createApi,
4
+ createClient,
5
+ createRemoteComponent,
6
+ createSessionProvider,
7
+ createView,
8
+ defineClient,
9
+ reference,
10
+ useAction,
11
+ useMutation,
12
+ useQuery
13
+ } from "./chunk-3XA36UOQ.js";
14
+ import {
15
+ action,
16
+ and,
17
+ asc,
18
+ boolean,
19
+ count,
20
+ defineServer,
21
+ desc,
22
+ eq,
23
+ gt,
24
+ gte,
25
+ inArray,
26
+ integer,
27
+ isNotNull,
28
+ isNull,
29
+ lt,
30
+ lte,
31
+ mutation,
32
+ ne,
33
+ or,
34
+ query,
35
+ real,
36
+ table,
37
+ text,
38
+ tk
39
+ } from "./chunk-46CTW3XJ.js";
40
+ import {
41
+ AppError,
42
+ appError
43
+ } from "./chunk-IJBQ77AH.js";
69
44
  export {
45
+ AppError,
46
+ ClientProvider,
47
+ action,
48
+ and,
49
+ appError,
50
+ asc,
51
+ boolean,
52
+ count,
53
+ createApi,
54
+ createClient,
70
55
  createRemoteComponent,
56
+ createSessionProvider,
71
57
  createView,
72
- defineClient
58
+ defineClient,
59
+ defineServer,
60
+ desc,
61
+ eq,
62
+ gt,
63
+ gte,
64
+ inArray,
65
+ integer,
66
+ isNotNull,
67
+ isNull,
68
+ lt,
69
+ lte,
70
+ mutation,
71
+ ne,
72
+ or,
73
+ query,
74
+ real,
75
+ reference,
76
+ table,
77
+ text,
78
+ tk,
79
+ useAction,
80
+ useMutation,
81
+ useQuery
73
82
  };
@@ -0,0 +1,52 @@
1
+ import type { ComponentChildren } from "preact";
2
+ import type { Client } from "./client/connection";
3
+ import type { Reference } from "./client/reference";
4
+ import { QueryStore } from "./client/query-store";
5
+ import type { QueryState } from "./client/query-store";
6
+ import type { AppError } from "./errors";
7
+ export interface ClientProviderProps {
8
+ children?: ComponentChildren;
9
+ /** Supply a client for custom transport configuration. Caller-owned clients are not closed. */
10
+ client?: Client;
11
+ onError?: (error: AppError) => void;
12
+ }
13
+ export declare function ClientProvider({ children, client, onError }: ClientProviderProps): import("preact").VNode<import("preact").Attributes & {
14
+ value: QueryStore | null;
15
+ children?: ComponentChildren;
16
+ }>;
17
+ export interface QueryOptions {
18
+ enabled?: boolean;
19
+ }
20
+ type InputArguments<I> = undefined extends I ? [input?: I] : [input: I];
21
+ type QueryArguments<I> = undefined extends I ? [input?: I, options?: QueryOptions] : [input: I, options?: QueryOptions];
22
+ export interface QueryResult<T> extends QueryState<T> {
23
+ isPending: boolean;
24
+ isLoading: boolean;
25
+ isSuccess: boolean;
26
+ isError: boolean;
27
+ }
28
+ export declare function useQuery<I, O>(ref: Reference<"query", I, O>, ...[input, options]: QueryArguments<NoInfer<I>>): QueryResult<O>;
29
+ export interface CallOptions<I, O> {
30
+ onSuccess?: (data: O, input: I) => void;
31
+ onError?: (error: AppError, input: I) => void;
32
+ }
33
+ export interface CallState<T> {
34
+ data: T | undefined;
35
+ error: AppError | null;
36
+ status: "idle" | "pending" | "success" | "error";
37
+ isPending: boolean;
38
+ isSuccess: boolean;
39
+ isError: boolean;
40
+ reset: () => void;
41
+ }
42
+ export interface MutationResult<I, O> extends CallState<O> {
43
+ mutate: (...args: InputArguments<I>) => void;
44
+ mutateAsync: (...args: InputArguments<I>) => Promise<O>;
45
+ }
46
+ export declare function useMutation<I, O>(ref: Reference<"mutation", I, O>, options?: CallOptions<I, O>): MutationResult<I, O>;
47
+ export interface ActionResult<I, O> extends CallState<O> {
48
+ execute: (...args: InputArguments<I>) => void;
49
+ executeAsync: (...args: InputArguments<I>) => Promise<O>;
50
+ }
51
+ export declare function useAction<I, O>(ref: Reference<"action", I, O>, options?: CallOptions<I, O>): ActionResult<I, O>;
52
+ export {};
@@ -0,0 +1,74 @@
1
+ import type { ContractRouterClient } from "@orpc/contract";
2
+ import { z } from "zod";
3
+ export declare const invocationSchema: z.ZodObject<{
4
+ name: z.ZodString;
5
+ args: z.ZodOptional<z.ZodUnknown>;
6
+ }, z.core.$strict>;
7
+ export type Invocation = z.infer<typeof invocationSchema>;
8
+ export type MutationInvocation = Invocation & {
9
+ requestId: string;
10
+ };
11
+ /** Public wire contract; implementations and clients both depend on this definition. */
12
+ export declare const appContract: {
13
+ queries: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
14
+ name: z.ZodString;
15
+ args: z.ZodOptional<z.ZodUnknown>;
16
+ }, z.core.$strict>, import("@orpc/contract").Schema<unknown, unknown>, {
17
+ BAD_REQUEST: {};
18
+ UNAUTHORIZED: {};
19
+ FORBIDDEN: {};
20
+ NOT_FOUND: {};
21
+ CONFLICT: {};
22
+ INCOMPATIBLE_VERSION: {};
23
+ UNAVAILABLE: {};
24
+ INTERNAL_SERVER_ERROR: {};
25
+ }>;
26
+ mutations: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
27
+ name: z.ZodString;
28
+ args: z.ZodOptional<z.ZodUnknown>;
29
+ requestId: z.ZodUUID;
30
+ }, z.core.$strict>, import("@orpc/contract").Schema<unknown, unknown>, {
31
+ BAD_REQUEST: {};
32
+ UNAUTHORIZED: {};
33
+ FORBIDDEN: {};
34
+ NOT_FOUND: {};
35
+ CONFLICT: {};
36
+ INCOMPATIBLE_VERSION: {};
37
+ UNAVAILABLE: {};
38
+ INTERNAL_SERVER_ERROR: {};
39
+ }>;
40
+ actions: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
41
+ name: z.ZodString;
42
+ args: z.ZodOptional<z.ZodUnknown>;
43
+ }, z.core.$strict>, import("@orpc/contract").Schema<unknown, unknown>, {
44
+ BAD_REQUEST: {};
45
+ UNAUTHORIZED: {};
46
+ FORBIDDEN: {};
47
+ NOT_FOUND: {};
48
+ CONFLICT: {};
49
+ INCOMPATIBLE_VERSION: {};
50
+ UNAVAILABLE: {};
51
+ INTERNAL_SERVER_ERROR: {};
52
+ }>;
53
+ subscribe: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
54
+ name: z.ZodString;
55
+ args: z.ZodOptional<z.ZodUnknown>;
56
+ }, z.core.$strict>, import("@orpc/contract").Schema<AsyncIterableIterator<unknown>, AsyncIterableIterator<unknown>>, {
57
+ BAD_REQUEST: {};
58
+ UNAUTHORIZED: {};
59
+ FORBIDDEN: {};
60
+ NOT_FOUND: {};
61
+ CONFLICT: {};
62
+ INCOMPATIBLE_VERSION: {};
63
+ UNAVAILABLE: {};
64
+ INTERNAL_SERVER_ERROR: {};
65
+ }>;
66
+ };
67
+ export type PlatformClient = ContractRouterClient<typeof appContract>;
68
+ export type SubscriptionClient = Pick<PlatformClient, "subscribe">;
69
+ /** Drizzle-generated SQL exported by application bundles. */
70
+ export interface AppMigration {
71
+ id: string;
72
+ hash: string;
73
+ statements: string[];
74
+ }
@@ -0,0 +1,28 @@
1
+ // src/protocol.ts
2
+ import { oc, type } from "@orpc/contract";
3
+ import { z } from "zod";
4
+ var invocationSchema = z.strictObject({
5
+ name: z.string().max(512).regex(/^[a-zA-Z][a-zA-Z0-9_]{0,63}(?:\.[a-zA-Z][a-zA-Z0-9_]{0,63})*$/u),
6
+ args: z.unknown().optional()
7
+ });
8
+ var procedure = oc.errors({
9
+ BAD_REQUEST: {},
10
+ UNAUTHORIZED: {},
11
+ FORBIDDEN: {},
12
+ NOT_FOUND: {},
13
+ CONFLICT: {},
14
+ INCOMPATIBLE_VERSION: {},
15
+ UNAVAILABLE: {},
16
+ INTERNAL_SERVER_ERROR: {}
17
+ });
18
+ var appContract = {
19
+ queries: procedure.input(invocationSchema).output(type()),
20
+ mutations: procedure.input(invocationSchema.extend({ requestId: z.uuid() })).output(type()),
21
+ actions: procedure.input(invocationSchema).output(type()),
22
+ // A pass-through type schema preserves the private hibernation iterator instance.
23
+ subscribe: procedure.input(invocationSchema).output(type())
24
+ };
25
+ export {
26
+ appContract,
27
+ invocationSchema
28
+ };
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ import type { MutationDatabase, QueryDatabase } from "../database/types";
3
+ import type { ActionContext, FunctionKind, Functions, Identity } from "./functions";
4
+ type HandlerContext<K extends FunctionKind, A extends z.ZodType, F extends Functions> = {
5
+ input: z.output<A>;
6
+ } & (K extends "action" ? ActionContext<F> : {
7
+ db: K extends "query" ? QueryDatabase : MutationDatabase;
8
+ identity: Identity;
9
+ });
10
+ type OutputInput<R> = R extends z.ZodType ? z.input<R> : unknown;
11
+ 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> = {
13
+ readonly kind: K;
14
+ readonly args: A;
15
+ readonly handler: (context: Omit<HandlerContext<K, A, F>, "input"> & {
16
+ args: z.output<A>;
17
+ }) => HandlerOutput<K, O>;
18
+ } & (R extends z.ZodType ? {
19
+ readonly result: R;
20
+ } : unknown) & (K extends "action" ? {
21
+ readonly functions: F;
22
+ } : unknown);
23
+ /** 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>> {
25
+ private readonly kind;
26
+ private readonly args;
27
+ private readonly result;
28
+ 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>;
34
+ }
35
+ 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, {}>;
39
+ }>;
40
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { AppDefinition } from "./functions";
2
+ import type { AppMigration } from "../protocol";
3
+ /** Interface between an uploaded application module and the server runtime. */
4
+ export interface RuntimeManifest {
5
+ apiVersion: number;
6
+ requires: readonly string[];
7
+ }
8
+ export interface ApplicationModule {
9
+ default: AppDefinition;
10
+ migrations: readonly AppMigration[];
11
+ runtimeManifest: RuntimeManifest;
12
+ }
13
+ /** Emitted by this SDK's builder; breaking interface changes increment apiVersion. */
14
+ export declare const runtimeManifest: {
15
+ readonly apiVersion: 1;
16
+ readonly requires: readonly ["database", "actions"];
17
+ };
@@ -0,0 +1,90 @@
1
+ import type { z } from "zod";
2
+ import type { QueryDatabase, MutationDatabase } from "../database/types";
3
+ export interface Identity {
4
+ readonly userId: string;
5
+ readonly projectId: string;
6
+ readonly appId: string;
7
+ readonly installationId: string;
8
+ readonly deploymentId: string;
9
+ readonly expiresAt: number;
10
+ }
11
+ export type FunctionKind = "query" | "mutation" | "action";
12
+ export type FunctionResult<D> = D extends {
13
+ result: infer R extends z.ZodType;
14
+ } ? z.output<R> : D extends {
15
+ handler: (context: never) => infer O;
16
+ } ? Awaited<O> : never;
17
+ type FunctionCalls<F, K extends "query" | "mutation"> = {
18
+ readonly [N in keyof F as F[N] extends {
19
+ kind: FunctionKind;
20
+ } ? (F[N] extends {
21
+ kind: K;
22
+ } ? N : never) : N]: F[N] extends {
23
+ args: infer A extends z.ZodType;
24
+ handler: (context: never) => unknown;
25
+ } ? K extends "mutation" ? (...args: undefined extends z.input<A> ? [args?: z.input<A>, options?: {
26
+ requestId?: string;
27
+ }] : [args: z.input<A>, options?: {
28
+ requestId?: string;
29
+ }]) => Promise<FunctionResult<F[N]>> : (...args: undefined extends z.input<A> ? [args?: z.input<A>] : [args: z.input<A>]) => Promise<FunctionResult<F[N]>> : F[N] extends Functions ? FunctionCalls<F[N], K> : never;
30
+ };
31
+ export interface ActionContext<F extends Functions = Record<never, never>> {
32
+ readonly identity: Identity;
33
+ readonly signal: AbortSignal;
34
+ readonly queries: FunctionCalls<F, "query">;
35
+ readonly mutations: FunctionCalls<F, "mutation">;
36
+ }
37
+ export interface FunctionDefinition<K extends FunctionKind, A extends z.ZodType, O, F extends Functions = Record<never, never>> {
38
+ readonly kind: K;
39
+ readonly args: A;
40
+ readonly result?: z.ZodType<O>;
41
+ readonly handler: (context: {
42
+ args: z.output<A>;
43
+ } & (K extends "action" ? ActionContext<F> : {
44
+ db: K extends "query" ? QueryDatabase : MutationDatabase;
45
+ identity: Identity;
46
+ })) => K extends "action" ? O | Promise<O> : O;
47
+ }
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);
50
+ }): Readonly<{
51
+ args: A;
52
+ 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);
54
+ kind: "query";
55
+ }>;
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);
58
+ }): Readonly<{
59
+ args: A;
60
+ 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);
62
+ kind: "mutation";
63
+ }>;
64
+ 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
+ functions?: F;
66
+ }): Readonly<{
67
+ args: A;
68
+ result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
69
+ handler: (context: {
70
+ args: z.infer<A>;
71
+ } & ActionContext<F>) => O | Promise<O>;
72
+ functions?: F;
73
+ kind: "action";
74
+ }>;
75
+ export type RegisteredFunction = {
76
+ kind: FunctionKind;
77
+ args: z.ZodType;
78
+ result?: z.ZodType;
79
+ handler: (context: never) => unknown;
80
+ functions?: Functions;
81
+ };
82
+ export interface Functions {
83
+ readonly [name: string]: RegisteredFunction | Functions;
84
+ }
85
+ export declare function isFunction(value: RegisteredFunction | Functions): value is RegisteredFunction;
86
+ export declare function defineServer<const F extends Functions>(functions: F): Readonly<{
87
+ functions: F;
88
+ }>;
89
+ export type AppDefinition = ReturnType<typeof defineServer>;
90
+ export {};
@@ -0,0 +1,8 @@
1
+ export { defineServer, query, mutation, action } from "./server/functions";
2
+ export { tk } from "./server/builder";
3
+ export type { QueryDatabase, MutationDatabase } from "./database/types";
4
+ export type { Identity, FunctionDefinition, AppDefinition, ActionContext, FunctionKind, } from "./server/functions";
5
+ export { table, text, integer, real, boolean, eq, ne, gt, gte, lt, lte, and, or, asc, desc, count, isNull, isNotNull, inArray, } from "./database/schema";
6
+ export { AppError } from "./errors";
7
+ export type { ErrorCode } from "./errors";
8
+ export type { ApplicationModule, RuntimeManifest } from "./server/bundle";
package/dist/server.js ADDED
@@ -0,0 +1,56 @@
1
+ import {
2
+ action,
3
+ and,
4
+ asc,
5
+ boolean,
6
+ count,
7
+ defineServer,
8
+ desc,
9
+ eq,
10
+ gt,
11
+ gte,
12
+ inArray,
13
+ integer,
14
+ isNotNull,
15
+ isNull,
16
+ lt,
17
+ lte,
18
+ mutation,
19
+ ne,
20
+ or,
21
+ query,
22
+ real,
23
+ table,
24
+ text,
25
+ tk
26
+ } from "./chunk-46CTW3XJ.js";
27
+ import {
28
+ AppError
29
+ } from "./chunk-IJBQ77AH.js";
30
+ export {
31
+ AppError,
32
+ action,
33
+ and,
34
+ asc,
35
+ boolean,
36
+ count,
37
+ defineServer,
38
+ desc,
39
+ eq,
40
+ gt,
41
+ gte,
42
+ inArray,
43
+ integer,
44
+ isNotNull,
45
+ isNull,
46
+ lt,
47
+ lte,
48
+ mutation,
49
+ ne,
50
+ or,
51
+ query,
52
+ real,
53
+ table,
54
+ text,
55
+ tk
56
+ };
@@ -0,0 +1,89 @@
1
+ import { h } from "preact";
2
+ import type { ComponentChild, ComponentChildren, ComponentType, VNode } from "preact";
3
+ export interface TailorKitViews {
4
+ }
5
+ export interface TailorKitSlots {
6
+ }
7
+ export type SlotName = keyof TailorKitSlots & string;
8
+ export type ViewPath = Extract<keyof TailorKitViews & string, `/${string}`>;
9
+ export type AppViewPath = ViewPath;
10
+ export type ViewProps<TPath extends ViewPath> = TailorKitViews[TPath] extends object ? TailorKitViews[TPath] : Record<string, never>;
11
+ export type ViewPropsForPath<TPath extends AppViewPath> = TPath extends ViewPath ? ViewProps<TPath> : never;
12
+ export type ViewContext<TPath extends AppViewPath> = ViewPropsForPath<TPath> extends {
13
+ context: infer TContext;
14
+ } ? TContext : Record<string, never>;
15
+ export type View<TProps extends object = Record<string, never>> = (props: TProps) => ComponentChild;
16
+ export type ViewRuntimeProps<TPath extends AppViewPath> = {
17
+ context: ViewContext<TPath>;
18
+ view: TPath;
19
+ status: "ready";
20
+ } | {
21
+ context?: never;
22
+ view: TPath;
23
+ status: "loading";
24
+ } | {
25
+ context?: never;
26
+ view: TPath;
27
+ status: "error";
28
+ };
29
+ export interface ViewDefinition<TPath extends AppViewPath = AppViewPath> {
30
+ component: View<ViewRuntimeProps<TPath>>;
31
+ path: TPath;
32
+ useContext: () => ViewContext<TPath>;
33
+ }
34
+ type RegisteredViews = {
35
+ [TPath in AppViewPath]: ViewDefinition<TPath>;
36
+ };
37
+ type ViewDefinitions = Partial<{
38
+ [P in AppViewPath]: RegisteredViews[P] | false;
39
+ }>;
40
+ type InvalidViewPath<TViews> = Exclude<keyof TViews & string, AppViewPath>;
41
+ type RequireViewPaths<TViews> = InvalidViewPath<TViews> extends never ? unknown : {
42
+ readonly __tailorkit_error__: `View paths must be declared by the host. Invalid view: ${InvalidViewPath<TViews>}`;
43
+ };
44
+ type ViewKeyPathMismatch<TViews> = {
45
+ [TPath in keyof TViews & string]: TViews[TPath] extends false ? never : TViews[TPath] extends ViewDefinition<infer TViewPath> ? TViewPath extends TPath ? never : TPath : TPath;
46
+ }[keyof TViews & string];
47
+ type RequireMatchingViewKeys<TViews> = ViewKeyPathMismatch<TViews> extends never ? unknown : {
48
+ readonly __tailorkit_error__: `View key must match createView path. Invalid view: ${ViewKeyPathMismatch<TViews>}`;
49
+ };
50
+ export type SlotView<TSlot extends SlotName> = Extract<TailorKitSlots[TSlot], AppViewPath>;
51
+ type SlotDefinitions = {
52
+ [V in SlotName]?: Pick<ViewDefinitions, SlotView<V>>;
53
+ };
54
+ type RequireSlotViews<V, S> = V extends SlotName ? Exclude<keyof S, SlotView<V>> extends never ? unknown : {
55
+ readonly __tailorkit_error__: "View is not supported by this slot";
56
+ } : never;
57
+ export interface TailorKitClient<TSlots extends SlotDefinitions = SlotDefinitions> {
58
+ slots: TSlots;
59
+ /** Wrap the app root with providers shared by every view. */
60
+ component?: ComponentType<{
61
+ children?: ComponentChildren;
62
+ }>;
63
+ }
64
+ export interface TailorKitClientMeta {
65
+ preactVersion: string;
66
+ }
67
+ export interface TailorKitClientRuntime {
68
+ h: typeof h;
69
+ render: (vnode: VNode | null, parent: Element | Document | ShadowRoot | DocumentFragment) => void;
70
+ }
71
+ export type TailorKitClientWithMeta<TViews extends SlotDefinitions = SlotDefinitions> = TailorKitClient<TViews> & {
72
+ $meta: TailorKitClientMeta;
73
+ $runtime: TailorKitClientRuntime;
74
+ };
75
+ export declare const createView: <const TPath extends AppViewPath>(path: TPath, options: {
76
+ component: View<Record<string, never>>;
77
+ }) => ViewDefinition<TPath>;
78
+ export declare const defineClient: <const TSlots extends SlotDefinitions>(client: TailorKitClient<TSlots> & {
79
+ slots: { [V in keyof TSlots]: TSlots[V] & RequireViewPaths<TSlots[V]> & RequireMatchingViewKeys<TSlots[V]> & RequireSlotViews<V, TSlots[V]>; };
80
+ } & (Exclude<keyof TSlots, SlotName> extends never ? unknown : {
81
+ __tailorkit_error__: "Unknown slot";
82
+ })) => TailorKitClientWithMeta<TSlots>;
83
+ export declare const createRemoteComponent: <TProps extends object, TChildren extends boolean = false>(name: string, options?: {
84
+ callbacks?: Record<string, number>;
85
+ children?: TChildren;
86
+ }) => View<TProps & {
87
+ children?: TChildren extends true ? ComponentChildren : never;
88
+ }>;
89
+ export {};