@tailorkit/app 0.1.0-beta.3 → 0.1.0-beta.32
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 +74 -0
- package/README.md +115 -0
- package/dist/chunk-7ZQPXG7O.js +34 -0
- package/dist/chunk-PJBDA2RU.js +415 -0
- package/dist/chunk-UDXPIO6D.js +618 -0
- package/dist/chunk-YX3JURMG.js +262 -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 +41 -0
- package/dist/client/tools.d.ts +16 -0
- package/dist/client-connection.js +16 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +40 -0
- package/dist/database/definition.d.ts +8 -0
- package/dist/database/schema.d.ts +78 -0
- package/dist/database/types.d.ts +8 -0
- package/dist/errors.d.ts +6 -0
- package/dist/index.d.ts +2 -72
- package/dist/index.js +91 -76
- package/dist/preact.d.ts +52 -0
- package/dist/protocol.d.ts +74 -0
- package/dist/protocol.js +30 -0
- package/dist/routing.d.ts +34 -0
- package/dist/server/builder.d.ts +45 -0
- package/dist/server/bundle.d.ts +12 -0
- package/dist/server/functions.d.ts +105 -0
- package/dist/server/instances.d.ts +17 -0
- package/dist/server.d.ts +11 -0
- package/dist/server.js +60 -0
- package/dist/views.d.ts +126 -0
- package/package.json +56 -34
- package/LICENSE +0 -674
- package/dist/builder/index.d.ts +0 -11
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/upload-manifest.d.ts +0 -10
- package/dist/builder/upload-manifest.d.ts.map +0 -1
- package/dist/builder.js +0 -135
- package/dist/chunk-7L6ZZHCK.js +0 -26
- package/dist/chunk-AGGRUUWG.js +0 -22
- package/dist/config/config.d.ts +0 -17
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/index.d.ts +0 -2
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/loader.d.ts +0 -8
- package/dist/config/loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config.js +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/preact-version.d.ts +0 -8
- package/dist/preact-version.d.ts.map +0 -1
- package/src/builder/index.ts +0 -116
- package/src/builder/upload-manifest.ts +0 -18
- package/src/config/config.ts +0 -24
- package/src/config/index.ts +0 -1
- package/src/config/loader.ts +0 -35
- package/src/index.ts +0 -206
- package/src/preact-version.ts +0 -31
package/dist/index.js
CHANGED
|
@@ -1,79 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return h(tagName, props, children);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return function RemoteComponent({ children, ...props }) {
|
|
55
|
-
const nextProps = { ...props };
|
|
56
|
-
const callbackMap = {};
|
|
57
|
-
for (const [key, inputCount] of Object.entries(callbacks)) {
|
|
58
|
-
const callback = nextProps[key];
|
|
59
|
-
Reflect.deleteProperty(nextProps, key);
|
|
60
|
-
if (typeof callback !== "function") {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const eventName = toCallbackEventName(key);
|
|
64
|
-
callbackMap[eventName] = { callback: key, inputCount };
|
|
65
|
-
nextProps[toEventProp(eventName)] = (event) => {
|
|
66
|
-
callback(...(event.detail ?? []).slice(0, inputCount));
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (Object.keys(callbackMap).length > 0) {
|
|
70
|
-
nextProps["data-tailorkit-callbacks"] = JSON.stringify(callbackMap);
|
|
71
|
-
}
|
|
72
|
-
return h(tagName, nextProps, children);
|
|
73
|
-
};
|
|
74
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
ClientProvider,
|
|
3
|
+
Route,
|
|
4
|
+
callTool,
|
|
5
|
+
createFileClient,
|
|
6
|
+
createRemoteComponent,
|
|
7
|
+
defineRoute,
|
|
8
|
+
defineView,
|
|
9
|
+
useAction,
|
|
10
|
+
useMutation,
|
|
11
|
+
useQuery
|
|
12
|
+
} from "./chunk-UDXPIO6D.js";
|
|
13
|
+
import {
|
|
14
|
+
createApi,
|
|
15
|
+
createClient,
|
|
16
|
+
createSessionProvider,
|
|
17
|
+
reference
|
|
18
|
+
} from "./chunk-PJBDA2RU.js";
|
|
19
|
+
import {
|
|
20
|
+
action,
|
|
21
|
+
and,
|
|
22
|
+
asc,
|
|
23
|
+
boolean,
|
|
24
|
+
count,
|
|
25
|
+
defineDatabase,
|
|
26
|
+
defineServer,
|
|
27
|
+
desc,
|
|
28
|
+
eq,
|
|
29
|
+
fn,
|
|
30
|
+
gt,
|
|
31
|
+
gte,
|
|
32
|
+
inArray,
|
|
33
|
+
integer,
|
|
34
|
+
isNotNull,
|
|
35
|
+
isNull,
|
|
36
|
+
lt,
|
|
37
|
+
lte,
|
|
38
|
+
mutation,
|
|
39
|
+
ne,
|
|
40
|
+
or,
|
|
41
|
+
query,
|
|
42
|
+
real,
|
|
43
|
+
table,
|
|
44
|
+
text,
|
|
45
|
+
withInstanceResolvers
|
|
46
|
+
} from "./chunk-YX3JURMG.js";
|
|
47
|
+
import {
|
|
48
|
+
AppError,
|
|
49
|
+
appError
|
|
50
|
+
} from "./chunk-7ZQPXG7O.js";
|
|
75
51
|
export {
|
|
52
|
+
AppError,
|
|
53
|
+
ClientProvider,
|
|
54
|
+
Route,
|
|
55
|
+
action,
|
|
56
|
+
and,
|
|
57
|
+
appError,
|
|
58
|
+
asc,
|
|
59
|
+
boolean,
|
|
60
|
+
callTool,
|
|
61
|
+
count,
|
|
62
|
+
createApi,
|
|
63
|
+
createClient,
|
|
64
|
+
createFileClient,
|
|
76
65
|
createRemoteComponent,
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
createSessionProvider,
|
|
67
|
+
defineDatabase,
|
|
68
|
+
defineRoute,
|
|
69
|
+
defineServer,
|
|
70
|
+
defineView,
|
|
71
|
+
desc,
|
|
72
|
+
eq,
|
|
73
|
+
fn,
|
|
74
|
+
gt,
|
|
75
|
+
gte,
|
|
76
|
+
inArray,
|
|
77
|
+
integer,
|
|
78
|
+
isNotNull,
|
|
79
|
+
isNull,
|
|
80
|
+
lt,
|
|
81
|
+
lte,
|
|
82
|
+
mutation,
|
|
83
|
+
ne,
|
|
84
|
+
or,
|
|
85
|
+
query,
|
|
86
|
+
real,
|
|
87
|
+
reference,
|
|
88
|
+
table,
|
|
89
|
+
text,
|
|
90
|
+
useAction,
|
|
91
|
+
useMutation,
|
|
92
|
+
useQuery,
|
|
93
|
+
withInstanceResolvers
|
|
79
94
|
};
|
package/dist/preact.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ComponentChildren } from "preact";
|
|
2
|
+
import type { Client } from "./client/connection";
|
|
3
|
+
import { QueryStore } from "./client/query-store";
|
|
4
|
+
import type { QueryState } from "./client/query-store";
|
|
5
|
+
import type { Reference } from "./client/reference";
|
|
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 const 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 const 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 const 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 const 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
|
+
args: z.ZodOptional<z.ZodUnknown>;
|
|
5
|
+
name: z.ZodString;
|
|
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
|
+
actions: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
|
|
14
|
+
args: z.ZodOptional<z.ZodUnknown>;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
}, z.core.$strict>, import("@orpc/contract").Schema<unknown, unknown>, {
|
|
17
|
+
BAD_REQUEST: {};
|
|
18
|
+
CONFLICT: {};
|
|
19
|
+
FORBIDDEN: {};
|
|
20
|
+
INCOMPATIBLE_VERSION: {};
|
|
21
|
+
INTERNAL_SERVER_ERROR: {};
|
|
22
|
+
NOT_FOUND: {};
|
|
23
|
+
UNAUTHORIZED: {};
|
|
24
|
+
UNAVAILABLE: {};
|
|
25
|
+
}>;
|
|
26
|
+
mutations: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
|
|
27
|
+
args: z.ZodOptional<z.ZodUnknown>;
|
|
28
|
+
name: z.ZodString;
|
|
29
|
+
requestId: z.ZodUUID;
|
|
30
|
+
}, z.core.$strict>, import("@orpc/contract").Schema<unknown, unknown>, {
|
|
31
|
+
BAD_REQUEST: {};
|
|
32
|
+
CONFLICT: {};
|
|
33
|
+
FORBIDDEN: {};
|
|
34
|
+
INCOMPATIBLE_VERSION: {};
|
|
35
|
+
INTERNAL_SERVER_ERROR: {};
|
|
36
|
+
NOT_FOUND: {};
|
|
37
|
+
UNAUTHORIZED: {};
|
|
38
|
+
UNAVAILABLE: {};
|
|
39
|
+
}>;
|
|
40
|
+
queries: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
|
|
41
|
+
args: z.ZodOptional<z.ZodUnknown>;
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
}, z.core.$strict>, import("@orpc/contract").Schema<unknown, unknown>, {
|
|
44
|
+
BAD_REQUEST: {};
|
|
45
|
+
CONFLICT: {};
|
|
46
|
+
FORBIDDEN: {};
|
|
47
|
+
INCOMPATIBLE_VERSION: {};
|
|
48
|
+
INTERNAL_SERVER_ERROR: {};
|
|
49
|
+
NOT_FOUND: {};
|
|
50
|
+
UNAUTHORIZED: {};
|
|
51
|
+
UNAVAILABLE: {};
|
|
52
|
+
}>;
|
|
53
|
+
subscribe: import("@orpc/contract").ProcedureContractBuilderWithInputOutput<z.ZodObject<{
|
|
54
|
+
args: z.ZodOptional<z.ZodUnknown>;
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
}, z.core.$strict>, import("@orpc/contract").Schema<AsyncIterableIterator<unknown>, AsyncIterableIterator<unknown>>, {
|
|
57
|
+
BAD_REQUEST: {};
|
|
58
|
+
CONFLICT: {};
|
|
59
|
+
FORBIDDEN: {};
|
|
60
|
+
INCOMPATIBLE_VERSION: {};
|
|
61
|
+
INTERNAL_SERVER_ERROR: {};
|
|
62
|
+
NOT_FOUND: {};
|
|
63
|
+
UNAUTHORIZED: {};
|
|
64
|
+
UNAVAILABLE: {};
|
|
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,30 @@
|
|
|
1
|
+
// src/protocol.ts
|
|
2
|
+
import { oc, type } from "@orpc/contract";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var invocationSchema = z.strictObject({
|
|
5
|
+
args: z.unknown().optional(),
|
|
6
|
+
name: z.string().max(512).regex(
|
|
7
|
+
/^(?:[a-zA-Z][a-zA-Z0-9_]{0,63}|_tailorkit)(?:\.[a-zA-Z][a-zA-Z0-9_]{0,63})*$/u
|
|
8
|
+
)
|
|
9
|
+
});
|
|
10
|
+
var procedure = oc.errors({
|
|
11
|
+
BAD_REQUEST: {},
|
|
12
|
+
CONFLICT: {},
|
|
13
|
+
FORBIDDEN: {},
|
|
14
|
+
INCOMPATIBLE_VERSION: {},
|
|
15
|
+
INTERNAL_SERVER_ERROR: {},
|
|
16
|
+
NOT_FOUND: {},
|
|
17
|
+
UNAUTHORIZED: {},
|
|
18
|
+
UNAVAILABLE: {}
|
|
19
|
+
});
|
|
20
|
+
var appContract = {
|
|
21
|
+
actions: procedure.input(invocationSchema).output(type()),
|
|
22
|
+
mutations: procedure.input(invocationSchema.extend({ requestId: z.uuid() })).output(type()),
|
|
23
|
+
queries: procedure.input(invocationSchema).output(type()),
|
|
24
|
+
// A pass-through type schema preserves the private hibernation iterator instance.
|
|
25
|
+
subscribe: procedure.input(invocationSchema).output(type())
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
appContract,
|
|
29
|
+
invocationSchema
|
|
30
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ComponentChildren, ComponentType } from "preact";
|
|
2
|
+
import type { TailorKitClientWithMeta } from "./views";
|
|
3
|
+
export interface ShellProps {
|
|
4
|
+
children?: ComponentChildren;
|
|
5
|
+
}
|
|
6
|
+
export interface RouteDefinition {
|
|
7
|
+
readonly shellComponent: ComponentType<ShellProps>;
|
|
8
|
+
}
|
|
9
|
+
/** Define the shell in an app or slot root.tsx. */
|
|
10
|
+
export declare const defineRoute: (options: RouteDefinition) => RouteDefinition;
|
|
11
|
+
/** Render the next layout or selected view inside a root shell or layout. */
|
|
12
|
+
export declare const Route: () => string | number | bigint | boolean | object | import("preact").ComponentChild[] | import("preact").VNode<any> | null;
|
|
13
|
+
export interface RouteModule {
|
|
14
|
+
filename: string;
|
|
15
|
+
definition: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface FileViewModule extends RouteModule {
|
|
18
|
+
slot: string;
|
|
19
|
+
}
|
|
20
|
+
export interface FileLayoutModule extends RouteModule {
|
|
21
|
+
slot: string;
|
|
22
|
+
path: string;
|
|
23
|
+
}
|
|
24
|
+
/** The app builder generates this registration; apps only export their files.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare const createFileClient: (options: {
|
|
28
|
+
root?: RouteModule;
|
|
29
|
+
roots: (RouteModule & {
|
|
30
|
+
slot: string;
|
|
31
|
+
})[];
|
|
32
|
+
layouts: FileLayoutModule[];
|
|
33
|
+
views: FileViewModule[];
|
|
34
|
+
}) => TailorKitClientWithMeta;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AnyRelations, EmptyRelations } from "drizzle-orm/relations";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { DatabaseDefinition } from "#database/definition";
|
|
4
|
+
import type { MutationDatabase, QueryDatabase } from "#database/types";
|
|
5
|
+
import type { ActionContext, FunctionKind, Functions, Identity } from "./functions";
|
|
6
|
+
type HandlerContext<K extends FunctionKind, A extends z.ZodType, F extends Functions, D extends AnyRelations> = {
|
|
7
|
+
input: z.output<A>;
|
|
8
|
+
} & (K extends "action" ? ActionContext<F> : {
|
|
9
|
+
db: K extends "query" ? QueryDatabase<D> : MutationDatabase<D>;
|
|
10
|
+
identity: Identity;
|
|
11
|
+
});
|
|
12
|
+
type OutputInput<R> = R extends z.ZodType ? z.input<R> : unknown;
|
|
13
|
+
type HandlerOutput<K, O> = K extends "action" ? O | Promise<O> : O & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
|
|
14
|
+
type BuiltFunction<K extends FunctionKind, A extends z.ZodType, R, O, F extends Functions, D extends AnyRelations> = {
|
|
15
|
+
readonly kind: K;
|
|
16
|
+
readonly args: A;
|
|
17
|
+
readonly database?: DatabaseDefinition<D>;
|
|
18
|
+
readonly handler: (context: Omit<HandlerContext<K, A, F, D>, "input"> & {
|
|
19
|
+
args: z.output<A>;
|
|
20
|
+
}) => HandlerOutput<K, O>;
|
|
21
|
+
} & (R extends z.ZodType ? {
|
|
22
|
+
readonly result: R;
|
|
23
|
+
} : unknown) & (K extends "action" ? {
|
|
24
|
+
readonly functions: F;
|
|
25
|
+
} : unknown);
|
|
26
|
+
/** Immutable builders preserve the validated input and wire output types at every step. */
|
|
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> {
|
|
28
|
+
private readonly kind;
|
|
29
|
+
private readonly args;
|
|
30
|
+
private readonly result;
|
|
31
|
+
private readonly calls;
|
|
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>;
|
|
39
|
+
}
|
|
40
|
+
export declare const fn: Readonly<{
|
|
41
|
+
action: FunctionBuilder<"action", z.ZodUndefined, undefined, {}, EmptyRelations>;
|
|
42
|
+
mutation: FunctionBuilder<"mutation", z.ZodUndefined, undefined, {}, EmptyRelations>;
|
|
43
|
+
query: FunctionBuilder<"query", z.ZodUndefined, undefined, {}, EmptyRelations>;
|
|
44
|
+
}>;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AppMigration } from "#protocol";
|
|
2
|
+
import type { AppDefinition } from "./functions";
|
|
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
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { AnyRelations, EmptyRelations } from "drizzle-orm/relations";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { TailorKitServerTools } from "#client/tools";
|
|
4
|
+
import type { DatabaseDefinition } from "#database/definition";
|
|
5
|
+
import type { QueryDatabase, MutationDatabase } from "#database/types";
|
|
6
|
+
export interface Identity {
|
|
7
|
+
readonly subjectId?: string;
|
|
8
|
+
readonly scope: {
|
|
9
|
+
name: string;
|
|
10
|
+
value: Record<string, z.output<ReturnType<typeof z.json>>>;
|
|
11
|
+
};
|
|
12
|
+
readonly toolUrl: string;
|
|
13
|
+
readonly projectId: string;
|
|
14
|
+
readonly appId: string;
|
|
15
|
+
readonly installationId: string;
|
|
16
|
+
readonly deploymentId: string;
|
|
17
|
+
readonly expiresAt: number;
|
|
18
|
+
}
|
|
19
|
+
export type FunctionKind = "query" | "mutation" | "action";
|
|
20
|
+
export type FunctionResult<D> = D extends {
|
|
21
|
+
result: infer R extends z.ZodType;
|
|
22
|
+
} ? z.output<R> : D extends {
|
|
23
|
+
handler: (context: never) => infer O;
|
|
24
|
+
} ? Awaited<O> : never;
|
|
25
|
+
export type FunctionCalls<F, K extends "query" | "mutation"> = {
|
|
26
|
+
readonly [N in keyof F as F[N] extends {
|
|
27
|
+
kind: FunctionKind;
|
|
28
|
+
} ? F[N] extends {
|
|
29
|
+
kind: K;
|
|
30
|
+
} ? N : never : N]: F[N] extends {
|
|
31
|
+
args: infer A extends z.ZodType;
|
|
32
|
+
handler: (context: never) => infer _Output;
|
|
33
|
+
} ? K extends "mutation" ? (...args: undefined extends z.input<A> ? [args?: z.input<A>, options?: {
|
|
34
|
+
requestId?: string;
|
|
35
|
+
}] : [args: z.input<A>, options?: {
|
|
36
|
+
requestId?: string;
|
|
37
|
+
}]) => 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;
|
|
38
|
+
};
|
|
39
|
+
export interface ActionContext<F extends Functions = Record<never, never>> {
|
|
40
|
+
readonly identity: Identity;
|
|
41
|
+
readonly tools: TailorKitServerTools;
|
|
42
|
+
readonly requestId: string;
|
|
43
|
+
readonly scope: Identity["scope"];
|
|
44
|
+
readonly signal: AbortSignal;
|
|
45
|
+
readonly queries: FunctionCalls<F, "query">;
|
|
46
|
+
readonly mutations: FunctionCalls<F, "mutation">;
|
|
47
|
+
}
|
|
48
|
+
export interface FunctionDefinition<K extends FunctionKind, A extends z.ZodType, O, F extends Functions = Record<never, never>, D extends AnyRelations = EmptyRelations> {
|
|
49
|
+
readonly kind: K;
|
|
50
|
+
readonly args: A;
|
|
51
|
+
readonly database?: K extends "action" ? never : DatabaseDefinition<D>;
|
|
52
|
+
readonly result?: z.ZodType<O>;
|
|
53
|
+
readonly handler: (context: {
|
|
54
|
+
args: z.output<A>;
|
|
55
|
+
} & (K extends "action" ? ActionContext<F> : {
|
|
56
|
+
db: K extends "query" ? QueryDatabase<D> : MutationDatabase<D>;
|
|
57
|
+
identity: Identity;
|
|
58
|
+
})) => K extends "action" ? O | Promise<O> : O;
|
|
59
|
+
}
|
|
60
|
+
export declare const query: <A extends z.ZodType, O, const D extends AnyRelations = EmptyRelations>(definition: Omit<FunctionDefinition<"query", A, O, Record<never, never>, D>, "kind"> & {
|
|
61
|
+
handler: FunctionDefinition<"query", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
|
|
62
|
+
}) => Readonly<{
|
|
63
|
+
args: A;
|
|
64
|
+
database?: DatabaseDefinition<D> | undefined;
|
|
65
|
+
result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
|
|
66
|
+
handler: FunctionDefinition<"query", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
|
|
67
|
+
kind: "query";
|
|
68
|
+
}>;
|
|
69
|
+
export declare const mutation: <A extends z.ZodType, O, const D extends AnyRelations = EmptyRelations>(definition: Omit<FunctionDefinition<"mutation", A, O, Record<never, never>, D>, "kind"> & {
|
|
70
|
+
handler: FunctionDefinition<"mutation", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
|
|
71
|
+
}) => Readonly<{
|
|
72
|
+
args: A;
|
|
73
|
+
database?: DatabaseDefinition<D> | undefined;
|
|
74
|
+
result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
|
|
75
|
+
handler: FunctionDefinition<"mutation", A, O, Record<never, never>, D>["handler"] & ([O] extends [never] ? unknown : O extends PromiseLike<unknown> ? never : unknown);
|
|
76
|
+
kind: "mutation";
|
|
77
|
+
}>;
|
|
78
|
+
export declare const action: <A extends z.ZodType, O, const F extends Functions = Record<never, never>>(definition: Omit<FunctionDefinition<"action", A, O, F>, "kind"> & {
|
|
79
|
+
functions?: F;
|
|
80
|
+
}) => Readonly<{
|
|
81
|
+
args: A;
|
|
82
|
+
database?: undefined;
|
|
83
|
+
result?: z.ZodType<O, unknown, z.core.$ZodTypeInternals<O, unknown>> | undefined;
|
|
84
|
+
handler: (context: {
|
|
85
|
+
args: z.infer<A>;
|
|
86
|
+
} & ActionContext<F>) => O | Promise<O>;
|
|
87
|
+
functions?: F;
|
|
88
|
+
kind: "action";
|
|
89
|
+
}>;
|
|
90
|
+
export interface RegisteredFunction<TOutput = unknown> {
|
|
91
|
+
kind: FunctionKind;
|
|
92
|
+
args: z.ZodType;
|
|
93
|
+
result?: z.ZodType;
|
|
94
|
+
handler: (context: never) => TOutput;
|
|
95
|
+
functions?: Functions;
|
|
96
|
+
database?: DatabaseDefinition;
|
|
97
|
+
}
|
|
98
|
+
export interface Functions {
|
|
99
|
+
readonly [name: string]: RegisteredFunction | Functions;
|
|
100
|
+
}
|
|
101
|
+
export declare const isFunction: (value: RegisteredFunction | Functions) => value is RegisteredFunction;
|
|
102
|
+
export declare const defineServer: <const F extends Functions>(functions: F) => Readonly<{
|
|
103
|
+
functions: F;
|
|
104
|
+
}>;
|
|
105
|
+
export type AppDefinition = ReturnType<typeof defineServer>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ViewDataFields } from "#views";
|
|
3
|
+
import type { AppDefinition, Identity } from "./functions";
|
|
4
|
+
interface InstanceResolver<TOutput = unknown> {
|
|
5
|
+
slot: string;
|
|
6
|
+
path: string;
|
|
7
|
+
dataSchema: z.ZodType;
|
|
8
|
+
resolve: (context: {
|
|
9
|
+
context: ViewDataFields;
|
|
10
|
+
identity: Identity;
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
queries: unknown;
|
|
13
|
+
}) => TOutput;
|
|
14
|
+
}
|
|
15
|
+
/** Build-generated actions run through the existing authenticated action runtime. */
|
|
16
|
+
export declare const withInstanceResolvers: (app: AppDefinition, resolvers: readonly InstanceResolver[]) => AppDefinition;
|
|
17
|
+
export {};
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { defineServer, query, mutation, action } from "./server/functions";
|
|
2
|
+
export { defineDatabase } from "./database/definition";
|
|
3
|
+
export type { DatabaseDefinition } from "./database/definition";
|
|
4
|
+
export { fn } from "./server/builder";
|
|
5
|
+
export { withInstanceResolvers } from "./server/instances";
|
|
6
|
+
export type { QueryDatabase, MutationDatabase } from "./database/types";
|
|
7
|
+
export type { Identity, FunctionDefinition, AppDefinition, ActionContext, FunctionKind, } from "./server/functions";
|
|
8
|
+
export { table, text, integer, real, boolean, eq, ne, gt, gte, lt, lte, and, or, asc, desc, count, isNull, isNotNull, inArray, } from "./database/schema";
|
|
9
|
+
export { AppError } from "./errors";
|
|
10
|
+
export type { ErrorCode } from "./errors";
|
|
11
|
+
export type { ApplicationModule, RuntimeManifest } from "./server/bundle";
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
action,
|
|
3
|
+
and,
|
|
4
|
+
asc,
|
|
5
|
+
boolean,
|
|
6
|
+
count,
|
|
7
|
+
defineDatabase,
|
|
8
|
+
defineServer,
|
|
9
|
+
desc,
|
|
10
|
+
eq,
|
|
11
|
+
fn,
|
|
12
|
+
gt,
|
|
13
|
+
gte,
|
|
14
|
+
inArray,
|
|
15
|
+
integer,
|
|
16
|
+
isNotNull,
|
|
17
|
+
isNull,
|
|
18
|
+
lt,
|
|
19
|
+
lte,
|
|
20
|
+
mutation,
|
|
21
|
+
ne,
|
|
22
|
+
or,
|
|
23
|
+
query,
|
|
24
|
+
real,
|
|
25
|
+
table,
|
|
26
|
+
text,
|
|
27
|
+
withInstanceResolvers
|
|
28
|
+
} from "./chunk-YX3JURMG.js";
|
|
29
|
+
import {
|
|
30
|
+
AppError
|
|
31
|
+
} from "./chunk-7ZQPXG7O.js";
|
|
32
|
+
export {
|
|
33
|
+
AppError,
|
|
34
|
+
action,
|
|
35
|
+
and,
|
|
36
|
+
asc,
|
|
37
|
+
boolean,
|
|
38
|
+
count,
|
|
39
|
+
defineDatabase,
|
|
40
|
+
defineServer,
|
|
41
|
+
desc,
|
|
42
|
+
eq,
|
|
43
|
+
fn,
|
|
44
|
+
gt,
|
|
45
|
+
gte,
|
|
46
|
+
inArray,
|
|
47
|
+
integer,
|
|
48
|
+
isNotNull,
|
|
49
|
+
isNull,
|
|
50
|
+
lt,
|
|
51
|
+
lte,
|
|
52
|
+
mutation,
|
|
53
|
+
ne,
|
|
54
|
+
or,
|
|
55
|
+
query,
|
|
56
|
+
real,
|
|
57
|
+
table,
|
|
58
|
+
text,
|
|
59
|
+
withInstanceResolvers
|
|
60
|
+
};
|