@epoch32/visage 0.0.0-stage → 0.0.0
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 +373 -0
- package/README.md +110 -2
- package/dist/bundle.dev.js +4875 -0
- package/dist/index.js +9633 -0
- package/dist/src/api/index.js +4002 -0
- package/dist/src/charts/index.js +2717 -0
- package/dist/src/devtools/index.js +4677 -0
- package/dist/src/dom/index.js +1550 -0
- package/dist/src/form/index.js +1415 -0
- package/dist/src/index.js +11826 -0
- package/dist/src/jsx-runtime/index.js +1630 -0
- package/dist/src/query/index.js +2422 -0
- package/dist/src/router/index.js +1856 -0
- package/dist/src/rpc/index.js +3484 -0
- package/dist/src/server/index.js +1173 -0
- package/dist/src/signals/index.js +1077 -0
- package/dist/src/style/index.js +2340 -0
- package/dist/src/template/index.js +1149 -0
- package/dist/src/ui/index.js +4155 -0
- package/dist/src/virtual/index.js +1955 -0
- package/dist/src/vite/index.js +984 -0
- package/dist/vite/index.js +707 -0
- package/package.json +140 -4
- package/src/api/client.ts +371 -0
- package/src/api/file-router.ts +183 -0
- package/src/api/handler.ts +326 -0
- package/src/api/index.ts +71 -0
- package/src/api/middleware.ts +54 -0
- package/src/api/pragma.ts +155 -0
- package/src/api/procedure.ts +172 -0
- package/src/api/types.ts +249 -0
- package/src/charts/Area.tsx +111 -0
- package/src/charts/Axis.tsx +126 -0
- package/src/charts/Bar.tsx +86 -0
- package/src/charts/CartesianGrid.tsx +72 -0
- package/src/charts/Chart.tsx +269 -0
- package/src/charts/Cursor.tsx +42 -0
- package/src/charts/Legend.tsx +56 -0
- package/src/charts/Line.tsx +106 -0
- package/src/charts/Pie.tsx +88 -0
- package/src/charts/Tooltip.tsx +127 -0
- package/src/charts/context.ts +30 -0
- package/src/charts/index.ts +14 -0
- package/src/charts/path.ts +155 -0
- package/src/charts/scale.ts +133 -0
- package/src/charts/types.ts +50 -0
- package/src/devtools/DomTab.tsx +134 -0
- package/src/devtools/GraphInspector.tsx +196 -0
- package/src/devtools/GraphTab.tsx +315 -0
- package/src/devtools/QueryTab.tsx +200 -0
- package/src/devtools/RpcTab.tsx +190 -0
- package/src/devtools/SignalsTab.tsx +129 -0
- package/src/devtools/component.tsx +243 -0
- package/src/devtools/highlighter.ts +134 -0
- package/src/devtools/hub.ts +175 -0
- package/src/devtools/index.ts +20 -0
- package/src/devtools/styles.ts +313 -0
- package/src/devtools/types.ts +45 -0
- package/src/dom/async.ts +232 -0
- package/src/dom/control-flow.ts +353 -0
- package/src/dom/index.ts +32 -0
- package/src/dom/lazy.ts +82 -0
- package/src/dom/render.ts +286 -0
- package/src/dom/resource.ts +120 -0
- package/src/form/form.ts +218 -0
- package/src/form/index.ts +17 -0
- package/src/form/schema.ts +299 -0
- package/src/index.ts +413 -0
- package/src/jsx-dev-runtime/index.ts +1 -0
- package/src/jsx-runtime/index.ts +112 -0
- package/src/jsx-runtime/jsx.d.ts +278 -0
- package/src/query/create-mutation.ts +64 -0
- package/src/query/create-query.ts +426 -0
- package/src/query/focus-manager.ts +68 -0
- package/src/query/index.ts +63 -0
- package/src/query/mutation-cache.ts +138 -0
- package/src/query/online-manager.ts +67 -0
- package/src/query/query-cache.ts +369 -0
- package/src/query/query-client.ts +248 -0
- package/src/query/types.ts +221 -0
- package/src/query/utils.ts +132 -0
- package/src/router/index.ts +19 -0
- package/src/router/router.tsx +352 -0
- package/src/rpc/client.ts +317 -0
- package/src/rpc/error.ts +70 -0
- package/src/rpc/index.ts +52 -0
- package/src/rpc/procedure.ts +88 -0
- package/src/rpc/router.ts +105 -0
- package/src/rpc/server.ts +511 -0
- package/src/rpc/types.ts +328 -0
- package/src/server/hydrate.ts +21 -0
- package/src/server/index.ts +10 -0
- package/src/server/render-to-stream.ts +31 -0
- package/src/server/render-to-string.ts +125 -0
- package/src/signals/computed.ts +217 -0
- package/src/signals/context.ts +89 -0
- package/src/signals/effect.ts +161 -0
- package/src/signals/index.ts +57 -0
- package/src/signals/scope.ts +132 -0
- package/src/signals/signal.ts +203 -0
- package/src/signals/store.ts +163 -0
- package/src/signals/system.ts +124 -0
- package/src/signals/types.ts +64 -0
- package/src/style/component.tsx +122 -0
- package/src/style/create-style.ts +229 -0
- package/src/style/cx.ts +75 -0
- package/src/style/hash.ts +19 -0
- package/src/style/index.ts +8 -0
- package/src/style/layout.tsx +406 -0
- package/src/style/manager.ts +87 -0
- package/src/style/parser.ts +257 -0
- package/src/style/scale.ts +237 -0
- package/src/template/index.ts +4 -0
- package/src/template/template.ts +126 -0
- package/src/ui/accordion.tsx +286 -0
- package/src/ui/command-dialog.tsx +49 -0
- package/src/ui/command.tsx +400 -0
- package/src/ui/data-table.tsx +322 -0
- package/src/ui/dialog.tsx +362 -0
- package/src/ui/dropdown-menu.tsx +381 -0
- package/src/ui/icon.tsx +69 -0
- package/src/ui/index.ts +138 -0
- package/src/ui/layout.tsx +13 -0
- package/src/ui/popover.tsx +249 -0
- package/src/ui/switch.tsx +114 -0
- package/src/ui/tabs.tsx +297 -0
- package/src/ui/toast.tsx +280 -0
- package/src/ui/tooltip.tsx +262 -0
- package/src/ui/utils.ts +110 -0
- package/src/virtual/index.ts +12 -0
- package/src/virtual/virtual-list.tsx +185 -0
- package/src/virtual/virtualizer.ts +274 -0
- package/src/vite/hmr.ts +38 -0
- package/src/vite/index.ts +3 -0
- package/src/vite/lucide.ts +124 -0
- package/src/vite/plugin.ts +102 -0
- package/src/vite/rpc-middleware.ts +82 -0
- package/src/vite/types.ts +65 -0
package/src/rpc/error.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ValidationIssue } from "../form/schema";
|
|
2
|
+
import type { RPCErrorCode } from "./types";
|
|
3
|
+
|
|
4
|
+
export const ERROR_CODE_TO_STATUS: Record<RPCErrorCode, number> = {
|
|
5
|
+
BAD_REQUEST: 400,
|
|
6
|
+
UNAUTHORIZED: 401,
|
|
7
|
+
FORBIDDEN: 403,
|
|
8
|
+
NOT_FOUND: 404,
|
|
9
|
+
METHOD_NOT_ALLOWED: 405,
|
|
10
|
+
TIMEOUT: 408,
|
|
11
|
+
CONFLICT: 409,
|
|
12
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
13
|
+
INTERNAL_SERVER_ERROR: 500
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const STATUS_TO_ERROR_CODE: Record<number, RPCErrorCode> = {
|
|
17
|
+
400: "BAD_REQUEST",
|
|
18
|
+
401: "UNAUTHORIZED",
|
|
19
|
+
403: "FORBIDDEN",
|
|
20
|
+
404: "NOT_FOUND",
|
|
21
|
+
405: "METHOD_NOT_ALLOWED",
|
|
22
|
+
408: "TIMEOUT",
|
|
23
|
+
409: "CONFLICT",
|
|
24
|
+
422: "UNPROCESSABLE_CONTENT",
|
|
25
|
+
500: "INTERNAL_SERVER_ERROR"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export class RPCError extends Error {
|
|
29
|
+
readonly code: RPCErrorCode;
|
|
30
|
+
readonly status: number;
|
|
31
|
+
readonly issues?: ValidationIssue[];
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
codeOrStatusOrOptions:
|
|
35
|
+
| RPCErrorCode
|
|
36
|
+
| number
|
|
37
|
+
| {
|
|
38
|
+
code: RPCErrorCode;
|
|
39
|
+
message?: string;
|
|
40
|
+
issues?: ValidationIssue[];
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
},
|
|
43
|
+
message?: string
|
|
44
|
+
) {
|
|
45
|
+
if (typeof codeOrStatusOrOptions === "number") {
|
|
46
|
+
const code = STATUS_TO_ERROR_CODE[codeOrStatusOrOptions] || "INTERNAL_SERVER_ERROR";
|
|
47
|
+
super(message || code);
|
|
48
|
+
this.name = "RPCError";
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.status = codeOrStatusOrOptions;
|
|
51
|
+
} else if (typeof codeOrStatusOrOptions === "string") {
|
|
52
|
+
super(message || codeOrStatusOrOptions);
|
|
53
|
+
this.name = "RPCError";
|
|
54
|
+
this.code = codeOrStatusOrOptions;
|
|
55
|
+
this.status = ERROR_CODE_TO_STATUS[codeOrStatusOrOptions] || 500;
|
|
56
|
+
} else {
|
|
57
|
+
super(codeOrStatusOrOptions.message ?? codeOrStatusOrOptions.code, {
|
|
58
|
+
cause: codeOrStatusOrOptions.cause
|
|
59
|
+
});
|
|
60
|
+
this.name = "RPCError";
|
|
61
|
+
this.code = codeOrStatusOrOptions.code;
|
|
62
|
+
this.status = ERROR_CODE_TO_STATUS[codeOrStatusOrOptions.code] ?? 500;
|
|
63
|
+
this.issues = codeOrStatusOrOptions.issues;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get statusCode(): number {
|
|
68
|
+
return this.status;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/rpc/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Schema,
|
|
3
|
+
type SchemaLike,
|
|
4
|
+
type StandardSchemaV1,
|
|
5
|
+
type ValidationIssue,
|
|
6
|
+
type ValidationResult,
|
|
7
|
+
v,
|
|
8
|
+
validateWithSchema
|
|
9
|
+
} from "../form/schema";
|
|
10
|
+
export { createClient } from "./client";
|
|
11
|
+
export {
|
|
12
|
+
ERROR_CODE_TO_STATUS,
|
|
13
|
+
RPCError,
|
|
14
|
+
STATUS_TO_ERROR_CODE
|
|
15
|
+
} from "./error";
|
|
16
|
+
export {
|
|
17
|
+
createProcedure,
|
|
18
|
+
executeProcedure
|
|
19
|
+
} from "./procedure";
|
|
20
|
+
export {
|
|
21
|
+
createRouter,
|
|
22
|
+
mutation,
|
|
23
|
+
query,
|
|
24
|
+
RouterImpl,
|
|
25
|
+
subscription
|
|
26
|
+
} from "./router";
|
|
27
|
+
export { createFetchHandler } from "./server";
|
|
28
|
+
export type {
|
|
29
|
+
ClientMutationMethod,
|
|
30
|
+
ClientOptions,
|
|
31
|
+
ClientProcedure,
|
|
32
|
+
ClientQueryMethod,
|
|
33
|
+
ClientRouter,
|
|
34
|
+
ClientSubscriptionMethod,
|
|
35
|
+
CORSOptions,
|
|
36
|
+
FetchHandlerOptions,
|
|
37
|
+
InferProcedureInput,
|
|
38
|
+
InferProcedureOutput,
|
|
39
|
+
MiddlewareFn,
|
|
40
|
+
Procedure,
|
|
41
|
+
ProcedureOptions,
|
|
42
|
+
ProcedureRecord,
|
|
43
|
+
ProcedureType,
|
|
44
|
+
Router,
|
|
45
|
+
Router as RPCRouter,
|
|
46
|
+
RPCErrorCode,
|
|
47
|
+
RPCResponse,
|
|
48
|
+
RPCResponseError,
|
|
49
|
+
RPCResponseSuccess,
|
|
50
|
+
SubscriptionCallbacks,
|
|
51
|
+
SubscriptionHandle
|
|
52
|
+
} from "./types";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { validateWithSchema } from "../form/schema";
|
|
2
|
+
import { RPCError } from "./error";
|
|
3
|
+
import type { MiddlewareFn, Procedure, ProcedureOptions, ProcedureType } from "./types";
|
|
4
|
+
|
|
5
|
+
export function createProcedure<
|
|
6
|
+
TType extends ProcedureType,
|
|
7
|
+
TInput = any,
|
|
8
|
+
TOutput = any,
|
|
9
|
+
TContext = any
|
|
10
|
+
>(
|
|
11
|
+
type: TType,
|
|
12
|
+
options: ProcedureOptions<TInput, TOutput, TContext>,
|
|
13
|
+
middlewares: MiddlewareFn<any, any>[] = []
|
|
14
|
+
): Procedure<TType, TInput, TOutput, TContext> {
|
|
15
|
+
return {
|
|
16
|
+
type,
|
|
17
|
+
inputSchema: options.input,
|
|
18
|
+
outputSchema: options.output,
|
|
19
|
+
middlewares: [...middlewares],
|
|
20
|
+
resolve: options.resolve as any
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function executeProcedure(
|
|
25
|
+
procedure: Procedure<any, any, any, any>,
|
|
26
|
+
opts: {
|
|
27
|
+
rawInput: unknown;
|
|
28
|
+
ctx: any;
|
|
29
|
+
req: Request;
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
}
|
|
32
|
+
): Promise<any> {
|
|
33
|
+
let input = opts.rawInput;
|
|
34
|
+
|
|
35
|
+
if (procedure.inputSchema) {
|
|
36
|
+
const res = validateWithSchema(procedure.inputSchema, opts.rawInput);
|
|
37
|
+
if (!res.success) {
|
|
38
|
+
throw new RPCError({
|
|
39
|
+
code: "BAD_REQUEST",
|
|
40
|
+
message: "Invalid procedure input",
|
|
41
|
+
issues: res.issues
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
input = res.data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Middleware pipeline runner
|
|
48
|
+
let currentIndex = 0;
|
|
49
|
+
let currentContext = opts.ctx;
|
|
50
|
+
|
|
51
|
+
const runPipeline = async (ctx: any): Promise<any> => {
|
|
52
|
+
currentContext = ctx;
|
|
53
|
+
if (currentIndex < procedure.middlewares.length) {
|
|
54
|
+
const mw = procedure.middlewares[currentIndex++]!;
|
|
55
|
+
return mw({
|
|
56
|
+
ctx: currentContext,
|
|
57
|
+
req: opts.req,
|
|
58
|
+
signal: opts.signal,
|
|
59
|
+
next: async (nextOpts) => {
|
|
60
|
+
return runPipeline(nextOpts?.ctx ?? currentContext);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return procedure.resolve({
|
|
66
|
+
input,
|
|
67
|
+
ctx: currentContext,
|
|
68
|
+
req: opts.req,
|
|
69
|
+
signal: opts.signal
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const output = await runPipeline(currentContext);
|
|
74
|
+
|
|
75
|
+
if (procedure.outputSchema && procedure.type !== "subscription") {
|
|
76
|
+
const res = validateWithSchema(procedure.outputSchema, output);
|
|
77
|
+
if (!res.success) {
|
|
78
|
+
throw new RPCError({
|
|
79
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
80
|
+
message: "Invalid procedure output",
|
|
81
|
+
issues: res.issues
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return res.data;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return output;
|
|
88
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createProcedure } from "./procedure";
|
|
2
|
+
import type { MiddlewareFn, Procedure, ProcedureOptions, ProcedureRecord, Router } from "./types";
|
|
3
|
+
|
|
4
|
+
export class RouterImpl<TRecord extends ProcedureRecord = ProcedureRecord, TContext = any>
|
|
5
|
+
implements Router<TRecord, TContext>
|
|
6
|
+
{
|
|
7
|
+
_def: {
|
|
8
|
+
record: TRecord;
|
|
9
|
+
middlewares: MiddlewareFn<any, any>[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
constructor(record: TRecord = {} as TRecord, middlewares: MiddlewareFn<any, any>[] = []) {
|
|
13
|
+
this._def = {
|
|
14
|
+
record: { ...record },
|
|
15
|
+
middlewares: [...middlewares]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
query(name: string, options: any): any {
|
|
20
|
+
const proc = createProcedure("query", options, this._def.middlewares);
|
|
21
|
+
const newRecord = {
|
|
22
|
+
...this._def.record,
|
|
23
|
+
[name]: proc
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return new RouterImpl(newRecord, this._def.middlewares);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
mutation(name: string, options: any): any {
|
|
30
|
+
const proc = createProcedure("mutation", options, this._def.middlewares);
|
|
31
|
+
const newRecord = {
|
|
32
|
+
...this._def.record,
|
|
33
|
+
[name]: proc
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return new RouterImpl(newRecord, this._def.middlewares);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
subscription(name: string, options: any): any {
|
|
40
|
+
const proc = createProcedure("subscription", options, this._def.middlewares);
|
|
41
|
+
const newRecord = {
|
|
42
|
+
...this._def.record,
|
|
43
|
+
[name]: proc
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return new RouterImpl(newRecord, this._def.middlewares);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
use<TNewContext = TContext>(
|
|
50
|
+
middleware: MiddlewareFn<TContext, TNewContext>
|
|
51
|
+
): Router<TRecord, TNewContext> {
|
|
52
|
+
const updatedMiddlewares = [...this._def.middlewares, middleware];
|
|
53
|
+
// Re-bind existing procedures with new middleware
|
|
54
|
+
const updatedRecord: ProcedureRecord = {};
|
|
55
|
+
for (const key in this._def.record) {
|
|
56
|
+
const item = this._def.record[key]!;
|
|
57
|
+
if ("type" in item) {
|
|
58
|
+
updatedRecord[key] = {
|
|
59
|
+
...item,
|
|
60
|
+
middlewares: [...updatedMiddlewares]
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
updatedRecord[key] = item;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return new RouterImpl(updatedRecord as TRecord, updatedMiddlewares);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
merge<TPrefix extends string, TSubRecord extends ProcedureRecord>(
|
|
70
|
+
prefix: TPrefix,
|
|
71
|
+
router: Router<TSubRecord, TContext>
|
|
72
|
+
): Router<TRecord & { [K in TPrefix]: Router<TSubRecord, TContext> }, TContext> {
|
|
73
|
+
const newRecord = {
|
|
74
|
+
...this._def.record,
|
|
75
|
+
[prefix]: router
|
|
76
|
+
} as TRecord & { [K in TPrefix]: Router<TSubRecord, TContext> };
|
|
77
|
+
|
|
78
|
+
return new RouterImpl(newRecord, this._def.middlewares);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createRouter<
|
|
83
|
+
TRecord extends ProcedureRecord = Record<string, never>,
|
|
84
|
+
TContext = any
|
|
85
|
+
>(record?: TRecord): Router<TRecord, TContext> {
|
|
86
|
+
return new RouterImpl<TRecord, TContext>(record ?? ({} as TRecord));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function query<TInput = any, TOutput = any, TContext = any>(
|
|
90
|
+
options: ProcedureOptions<TInput, TOutput, TContext>
|
|
91
|
+
): Procedure<"query", TInput, TOutput, TContext> {
|
|
92
|
+
return createProcedure("query", options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function mutation<TInput = any, TOutput = any, TContext = any>(
|
|
96
|
+
options: ProcedureOptions<TInput, TOutput, TContext>
|
|
97
|
+
): Procedure<"mutation", TInput, TOutput, TContext> {
|
|
98
|
+
return createProcedure("mutation", options);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function subscription<TInput = any, TOutput = any, TContext = any>(
|
|
102
|
+
options: ProcedureOptions<TInput, TOutput, TContext>
|
|
103
|
+
): Procedure<"subscription", TInput, TOutput, TContext> {
|
|
104
|
+
return createProcedure("subscription", options);
|
|
105
|
+
}
|