@tailorkit/app 0.1.0-beta.2 → 0.1.0-beta.21
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/LICENSE.md +201 -0
- package/README.md +3 -0
- package/dist/builder/client-views.d.ts +16 -0
- package/dist/builder/drizzle.d.ts +2 -0
- package/dist/builder/generate-migrations.d.ts +6 -0
- package/dist/builder/index.d.ts +1 -2
- package/dist/builder/instances.d.ts +19 -0
- package/dist/builder/migrations.d.ts +6 -0
- package/dist/builder/schema-check.d.ts +2 -0
- package/dist/builder/server.d.ts +6 -0
- package/dist/builder/upload-manifest.d.ts +13 -3
- package/dist/builder.js +986 -21
- package/dist/chunk-7NOEYJOB.js +197 -0
- package/dist/{chunk-7L6ZZHCK.js → chunk-DEU6RITM.js} +6 -1
- package/dist/chunk-GVB2PAK7.js +28 -0
- package/dist/chunk-IJBQ77AH.js +35 -0
- package/dist/chunk-RHCGWGSG.js +645 -0
- package/dist/client/connection.d.ts +31 -0
- package/dist/client/query-store.d.ts +23 -0
- package/dist/client/reference.d.ts +20 -0
- package/dist/client/session.d.ts +14 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +32 -0
- package/dist/config/config.d.ts +88 -4
- package/dist/config/index.d.ts +0 -1
- package/dist/config/loader.d.ts +0 -1
- package/dist/config-loader.js +2 -2
- package/dist/config.js +1 -1
- package/dist/database/schema.d.ts +78 -0
- package/dist/database/types.d.ts +7 -0
- package/dist/errors.d.ts +6 -0
- package/dist/index.d.ts +2 -72
- package/dist/index.js +81 -76
- package/dist/preact-version.d.ts +0 -1
- package/dist/preact.d.ts +52 -0
- package/dist/protocol.d.ts +74 -0
- package/dist/protocol.js +28 -0
- package/dist/server/builder.d.ts +40 -0
- package/dist/server/bundle.d.ts +17 -0
- package/dist/server/functions.d.ts +89 -0
- package/dist/server/instances.d.ts +16 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +58 -0
- package/dist/views.d.ts +139 -0
- package/package.json +30 -23
- package/LICENSE +0 -674
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/upload-manifest.d.ts.map +0 -1
- package/dist/chunk-AGGRUUWG.js +0 -22
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/loader.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/preact-version.d.ts.map +0 -1
|
@@ -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
|
+
}
|
package/dist/protocol.js
ADDED
|
@@ -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}|_tailorkit)(?:\.[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,89 @@
|
|
|
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
|
+
export 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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AppDefinition, Identity } from "./functions";
|
|
3
|
+
interface InstanceResolver {
|
|
4
|
+
slot: string;
|
|
5
|
+
path: string;
|
|
6
|
+
dataSchema: z.ZodType;
|
|
7
|
+
resolve: (context: {
|
|
8
|
+
context: Record<string, unknown>;
|
|
9
|
+
identity: Identity;
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
queries: unknown;
|
|
12
|
+
}) => unknown;
|
|
13
|
+
}
|
|
14
|
+
/** Build-generated actions run through the existing authenticated action runtime. */
|
|
15
|
+
export declare function withInstanceResolvers(app: AppDefinition, resolvers: readonly InstanceResolver[]): AppDefinition;
|
|
16
|
+
export {};
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { defineServer, query, mutation, action } from "./server/functions";
|
|
2
|
+
export { tk } from "./server/builder";
|
|
3
|
+
export { withInstanceResolvers } from "./server/instances";
|
|
4
|
+
export type { QueryDatabase, MutationDatabase } from "./database/types";
|
|
5
|
+
export type { Identity, FunctionDefinition, AppDefinition, ActionContext, FunctionKind, } from "./server/functions";
|
|
6
|
+
export { table, text, integer, real, boolean, eq, ne, gt, gte, lt, lte, and, or, asc, desc, count, isNull, isNotNull, inArray, } from "./database/schema";
|
|
7
|
+
export { AppError } from "./errors";
|
|
8
|
+
export type { ErrorCode } from "./errors";
|
|
9
|
+
export type { ApplicationModule, RuntimeManifest } from "./server/bundle";
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
withInstanceResolvers
|
|
27
|
+
} from "./chunk-7NOEYJOB.js";
|
|
28
|
+
import {
|
|
29
|
+
AppError
|
|
30
|
+
} from "./chunk-IJBQ77AH.js";
|
|
31
|
+
export {
|
|
32
|
+
AppError,
|
|
33
|
+
action,
|
|
34
|
+
and,
|
|
35
|
+
asc,
|
|
36
|
+
boolean,
|
|
37
|
+
count,
|
|
38
|
+
defineServer,
|
|
39
|
+
desc,
|
|
40
|
+
eq,
|
|
41
|
+
gt,
|
|
42
|
+
gte,
|
|
43
|
+
inArray,
|
|
44
|
+
integer,
|
|
45
|
+
isNotNull,
|
|
46
|
+
isNull,
|
|
47
|
+
lt,
|
|
48
|
+
lte,
|
|
49
|
+
mutation,
|
|
50
|
+
ne,
|
|
51
|
+
or,
|
|
52
|
+
query,
|
|
53
|
+
real,
|
|
54
|
+
table,
|
|
55
|
+
text,
|
|
56
|
+
tk,
|
|
57
|
+
withInstanceResolvers
|
|
58
|
+
};
|
package/dist/views.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { h } from "preact";
|
|
2
|
+
import type { ComponentChild, ComponentChildren, ComponentType, VNode } from "preact";
|
|
3
|
+
import type { z } from "zod";
|
|
4
|
+
import type { FunctionCalls, Identity } from "./server/functions";
|
|
5
|
+
export interface TailorKitViews {
|
|
6
|
+
}
|
|
7
|
+
export interface TailorKitSlots {
|
|
8
|
+
}
|
|
9
|
+
export interface TailorKitServerFunctions {
|
|
10
|
+
}
|
|
11
|
+
export interface ViewInstance<TData = unknown> {
|
|
12
|
+
key: string;
|
|
13
|
+
metadata: Record<string, unknown>;
|
|
14
|
+
data: TData;
|
|
15
|
+
}
|
|
16
|
+
export interface InstanceResolverContext<TPath extends AppViewPath> {
|
|
17
|
+
context: ViewContext<TPath>;
|
|
18
|
+
identity: Identity;
|
|
19
|
+
signal: AbortSignal;
|
|
20
|
+
queries: FunctionCalls<TailorKitServerFunctions, "query">;
|
|
21
|
+
}
|
|
22
|
+
export interface ViewInstances<TPath extends AppViewPath, TSchema extends z.ZodType> {
|
|
23
|
+
dataSchema: TSchema;
|
|
24
|
+
/** Runs on the app server. Only registered queries are available. */
|
|
25
|
+
resolve: (context: InstanceResolverContext<TPath>) => ViewInstance<z.input<TSchema>>[] | Promise<ViewInstance<z.input<TSchema>>[]>;
|
|
26
|
+
}
|
|
27
|
+
export type SlotName = keyof TailorKitSlots & string;
|
|
28
|
+
export type ViewPath = Extract<keyof TailorKitViews & string, `/${string}`>;
|
|
29
|
+
export type AppViewPath = ViewPath;
|
|
30
|
+
export type ViewProps<TPath extends ViewPath> = TailorKitViews[TPath] extends object ? TailorKitViews[TPath] : Record<string, never>;
|
|
31
|
+
export type ViewPropsForPath<TPath extends AppViewPath> = TPath extends ViewPath ? ViewProps<TPath> : never;
|
|
32
|
+
export type ViewContext<TPath extends AppViewPath> = ViewPropsForPath<TPath> extends {
|
|
33
|
+
context: infer TContext;
|
|
34
|
+
} ? TContext : Record<string, never>;
|
|
35
|
+
export type View<TProps extends object = Record<string, never>> = (props: TProps) => ComponentChild;
|
|
36
|
+
export type ViewRuntimeProps<TPath extends AppViewPath, TData = unknown> = {
|
|
37
|
+
context: ViewContext<TPath>;
|
|
38
|
+
view: TPath;
|
|
39
|
+
status: "ready";
|
|
40
|
+
instance?: ViewInstance<TData>;
|
|
41
|
+
} | {
|
|
42
|
+
context?: never;
|
|
43
|
+
view: TPath;
|
|
44
|
+
status: "loading";
|
|
45
|
+
instance?: never;
|
|
46
|
+
} | {
|
|
47
|
+
context?: never;
|
|
48
|
+
view: TPath;
|
|
49
|
+
status: "error";
|
|
50
|
+
instance?: never;
|
|
51
|
+
};
|
|
52
|
+
export interface ViewDefinition<TPath extends AppViewPath = AppViewPath, TData = unknown, TSlot extends SlotName = SlotName> {
|
|
53
|
+
component: View<ViewRuntimeProps<TPath>>;
|
|
54
|
+
path: TPath;
|
|
55
|
+
slot: TSlot;
|
|
56
|
+
useContext: () => ViewContext<TPath>;
|
|
57
|
+
/** The selected instance, with data inferred from instances.dataSchema. */
|
|
58
|
+
useInstance: () => ViewInstance<TData>;
|
|
59
|
+
/** Build-only lookup key connecting this view to its extracted server implementation. */
|
|
60
|
+
instances?: {
|
|
61
|
+
resolver: string;
|
|
62
|
+
};
|
|
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
|
+
export type SlotView<TSlot extends SlotName> = TailorKitSlots[TSlot] extends {
|
|
75
|
+
views: infer TViews;
|
|
76
|
+
} ? Extract<TViews, AppViewPath> : never;
|
|
77
|
+
type SlotInstanceDefinition<TSlot extends SlotName> = TailorKitSlots[TSlot] extends {
|
|
78
|
+
multiple: true;
|
|
79
|
+
} ? {
|
|
80
|
+
instances: {
|
|
81
|
+
resolver: string;
|
|
82
|
+
};
|
|
83
|
+
} : {
|
|
84
|
+
instances?: never;
|
|
85
|
+
};
|
|
86
|
+
type SlotDefinitions = {
|
|
87
|
+
[V in SlotName]?: Partial<{
|
|
88
|
+
[P in SlotView<V>]: (ViewDefinition<P, unknown, V> & SlotInstanceDefinition<V>) | false;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
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
|
+
export interface TailorKitClient<TSlots extends SlotDefinitions = SlotDefinitions> {
|
|
95
|
+
slots: TSlots;
|
|
96
|
+
/** Wrap the app root with providers shared by every view. */
|
|
97
|
+
component?: ComponentType<{
|
|
98
|
+
children?: ComponentChildren;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
101
|
+
export interface TailorKitClientMeta {
|
|
102
|
+
preactVersion: string;
|
|
103
|
+
}
|
|
104
|
+
export interface TailorKitClientRuntime {
|
|
105
|
+
h: typeof h;
|
|
106
|
+
render: (vnode: VNode | null, parent: Element | Document | ShadowRoot | DocumentFragment) => void;
|
|
107
|
+
}
|
|
108
|
+
export type TailorKitClientWithMeta<TViews extends SlotDefinitions = SlotDefinitions> = TailorKitClient<TViews> & {
|
|
109
|
+
$meta: TailorKitClientMeta;
|
|
110
|
+
$runtime: TailorKitClientRuntime;
|
|
111
|
+
};
|
|
112
|
+
type ViewOptions<TPath extends AppViewPath, TSlot extends SlotName, TSchema extends z.ZodType> = {
|
|
113
|
+
[S in TSlot]: {
|
|
114
|
+
slot: S;
|
|
115
|
+
view: TPath;
|
|
116
|
+
component: View<Record<string, never>>;
|
|
117
|
+
} & (TPath extends SlotView<S> ? unknown : {
|
|
118
|
+
readonly __tailorkit_error__: "View is not supported by this slot";
|
|
119
|
+
}) & (TailorKitSlots[S] extends {
|
|
120
|
+
multiple: true;
|
|
121
|
+
} ? {
|
|
122
|
+
instances: ViewInstances<TPath, TSchema>;
|
|
123
|
+
} : {
|
|
124
|
+
instances?: never;
|
|
125
|
+
});
|
|
126
|
+
}[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>;
|
|
133
|
+
export declare const createRemoteComponent: <TProps extends object, TChildren extends boolean = false>(name: string, options?: {
|
|
134
|
+
callbacks?: Record<string, number>;
|
|
135
|
+
children?: TChildren;
|
|
136
|
+
}) => View<TProps & {
|
|
137
|
+
children?: TChildren extends true ? ComponentChildren : never;
|
|
138
|
+
}>;
|
|
139
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,68 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailorkit/app",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"license": "
|
|
3
|
+
"version": "0.1.0-beta.21",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/tailorkit-labs/TailorKit.git",
|
|
8
8
|
"directory": "packages/app"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"imports": {
|
|
15
|
-
"#*": [
|
|
16
|
-
"./src/*",
|
|
17
|
-
"./src/*.ts",
|
|
18
|
-
"./src/*.tsx",
|
|
19
|
-
"./src/*/index.ts",
|
|
20
|
-
"./src/*/index.tsx"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
14
|
"exports": {
|
|
24
15
|
".": {
|
|
25
|
-
"development": "./src/index.ts",
|
|
26
16
|
"types": "./dist/index.d.ts",
|
|
27
17
|
"import": "./dist/index.js"
|
|
28
18
|
},
|
|
29
19
|
"./config": {
|
|
30
|
-
"development": "./src/config/index.ts",
|
|
31
20
|
"types": "./dist/config/index.d.ts",
|
|
32
21
|
"import": "./dist/config.js"
|
|
33
22
|
},
|
|
34
23
|
"./config/loader": {
|
|
35
|
-
"development": "./src/config/loader.ts",
|
|
36
24
|
"types": "./dist/config/loader.d.ts",
|
|
37
25
|
"import": "./dist/config-loader.js"
|
|
38
26
|
},
|
|
39
27
|
"./builder": {
|
|
40
|
-
"development": "./src/builder/index.ts",
|
|
41
28
|
"types": "./dist/builder/index.d.ts",
|
|
42
29
|
"import": "./dist/builder.js"
|
|
30
|
+
},
|
|
31
|
+
"./client": {
|
|
32
|
+
"types": "./dist/client.d.ts",
|
|
33
|
+
"import": "./dist/client.js"
|
|
34
|
+
},
|
|
35
|
+
"./server": {
|
|
36
|
+
"types": "./dist/server.d.ts",
|
|
37
|
+
"import": "./dist/server.js"
|
|
38
|
+
},
|
|
39
|
+
"./protocol": {
|
|
40
|
+
"types": "./dist/protocol.d.ts",
|
|
41
|
+
"import": "./dist/protocol.js"
|
|
43
42
|
}
|
|
44
43
|
},
|
|
45
44
|
"publishConfig": {
|
|
46
45
|
"access": "public"
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
48
|
+
"@orpc/client": "2.0.0-beta.40",
|
|
49
|
+
"@orpc/contract": "2.0.0-beta.40",
|
|
50
|
+
"@tanstack/preact-store": "0.13.4",
|
|
51
|
+
"@tanstack/store": "0.11.2",
|
|
52
|
+
"cosmiconfig": "^10.0.1",
|
|
53
|
+
"drizzle-orm": "1.0.0-rc.4-5d5b77c",
|
|
54
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
|
|
55
|
+
"zod": "^4.6.5"
|
|
53
56
|
},
|
|
54
57
|
"devDependencies": {
|
|
58
|
+
"@tailorkit/asset-delivery": "0.0.0",
|
|
55
59
|
"@tailorkit/config": "0.0.0",
|
|
56
|
-
"@types/node": "26.
|
|
60
|
+
"@types/node": "26.6.4",
|
|
61
|
+
"happy-dom": "^20.14.5",
|
|
57
62
|
"preact": "^10.29.8",
|
|
58
63
|
"tsup": "^8.5.1",
|
|
59
|
-
"typescript": "^7.0.2"
|
|
64
|
+
"typescript": "^7.0.2",
|
|
65
|
+
"vite-plus": "1.0.0"
|
|
60
66
|
},
|
|
61
67
|
"peerDependencies": {
|
|
62
68
|
"preact": "^10.0.0"
|
|
63
69
|
},
|
|
64
70
|
"scripts": {
|
|
65
71
|
"build": "tsup --config tsup.config.ts && tsc -p tsconfig.build.json",
|
|
66
|
-
"check-types": "tsc --noEmit"
|
|
72
|
+
"check-types": "tsc --noEmit",
|
|
73
|
+
"test": "vp test run"
|
|
67
74
|
}
|
|
68
75
|
}
|