brustjs 0.1.50-alpha → 0.1.52-alpha

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.
Files changed (90) hide show
  1. package/package.json +39 -15
  2. package/runtime/cache-sync.ts +291 -0
  3. package/runtime/cache.ts +4 -0
  4. package/runtime/cli/dev.ts +7 -0
  5. package/runtime/cli/native-routes-emit.ts +147 -1
  6. package/runtime/config.ts +42 -0
  7. package/runtime/index.d.ts +63 -0
  8. package/runtime/index.js +57 -52
  9. package/runtime/index.ts +108 -9
  10. package/runtime/native/runtime.ts +220 -7
  11. package/runtime/render/fragment.ts +87 -0
  12. package/runtime/routes.ts +225 -48
  13. package/runtime/templates.ts +47 -0
  14. package/runtime/treaty.ts +24 -1
  15. package/types/action-error.d.ts +18 -0
  16. package/types/cache-sync.d.ts +42 -0
  17. package/types/cache.d.ts +20 -0
  18. package/types/cli/help.d.ts +28 -0
  19. package/types/cli/jinja-staleness.d.ts +14 -0
  20. package/types/cli/native-routes-emit.d.ts +217 -0
  21. package/types/cli/new.d.ts +30 -0
  22. package/types/cli/templates.d.ts +39 -0
  23. package/types/client/index.d.ts +14 -0
  24. package/types/config.d.ts +42 -0
  25. package/types/cookies.d.ts +25 -0
  26. package/types/create.d.ts +1 -0
  27. package/types/css/build.d.ts +11 -0
  28. package/types/css/component-build.d.ts +17 -0
  29. package/types/css/component-loader.d.ts +8 -0
  30. package/types/css/manifest.d.ts +21 -0
  31. package/types/css/process-modules.d.ts +31 -0
  32. package/types/css/route-deps.d.ts +20 -0
  33. package/types/css/scan-imports.d.ts +13 -0
  34. package/types/css.d.ts +16 -0
  35. package/types/define-actions.d.ts +133 -0
  36. package/types/dev/client.d.ts +8 -0
  37. package/types/dev/coordinator.d.ts +33 -0
  38. package/types/dev/inject.d.ts +6 -0
  39. package/types/dev/jinja-reload.d.ts +7 -0
  40. package/types/dev/tui.d.ts +35 -0
  41. package/types/dev/watcher.d.ts +34 -0
  42. package/types/dev/worker-registry.d.ts +17 -0
  43. package/types/dev/ws-channel.d.ts +39 -0
  44. package/types/generator.d.ts +23 -0
  45. package/types/index.d.ts +222 -0
  46. package/types/islands/brust-page.d.ts +74 -0
  47. package/types/islands/build.d.ts +49 -0
  48. package/types/islands/chunk-id.d.ts +10 -0
  49. package/types/islands/importmap.d.ts +2 -0
  50. package/types/islands/island.d.ts +65 -0
  51. package/types/islands/isr-jsx.d.ts +31 -0
  52. package/types/islands/native-render.d.ts +89 -0
  53. package/types/loader-cache.d.ts +18 -0
  54. package/types/mcp/extractor.d.ts +14 -0
  55. package/types/mcp/manifest.d.ts +23 -0
  56. package/types/mcp/schema.d.ts +19 -0
  57. package/types/mcp/server.d.ts +15 -0
  58. package/types/md/emit.d.ts +72 -0
  59. package/types/md/render.d.ts +80 -0
  60. package/types/md/routes.d.ts +119 -0
  61. package/types/md/scan.d.ts +34 -0
  62. package/types/md/slug.d.ts +1 -0
  63. package/types/native/build.d.ts +30 -0
  64. package/types/native/index.d.ts +2 -0
  65. package/types/native/runtime.d.ts +52 -0
  66. package/types/navigation/active-nav.d.ts +2 -0
  67. package/types/navigation/index.d.ts +5 -0
  68. package/types/navigation/navigate.d.ts +14 -0
  69. package/types/navigation/react.d.ts +15 -0
  70. package/types/navigation/store.d.ts +44 -0
  71. package/types/render/fragment.d.ts +20 -0
  72. package/types/render/inject-action-prefix.d.ts +9 -0
  73. package/types/render/inject-css-link.d.ts +8 -0
  74. package/types/render/inject-dev-client.d.ts +6 -0
  75. package/types/render/inject-generator.d.ts +7 -0
  76. package/types/render/inject-store.d.ts +9 -0
  77. package/types/render/stream.d.ts +45 -0
  78. package/types/request-context.d.ts +16 -0
  79. package/types/routes.d.ts +506 -0
  80. package/types/sse/handler.d.ts +22 -0
  81. package/types/standard-schema.d.ts +31 -0
  82. package/types/store/define-store.d.ts +31 -0
  83. package/types/store/index.d.ts +5 -0
  84. package/types/store/react.d.ts +2 -0
  85. package/types/store/serialize.d.ts +5 -0
  86. package/types/store/server-context.d.ts +4 -0
  87. package/types/store/signal.d.ts +18 -0
  88. package/types/templates.d.ts +18 -0
  89. package/types/treaty.d.ts +70 -0
  90. package/types/ws/handler.d.ts +26 -0
@@ -0,0 +1,70 @@
1
+ import type { ActionsBuilder, EndpointEntry } from './define-actions.ts';
2
+ export interface TreatyResponse<Data = unknown, Err = unknown> {
3
+ data: Data | null;
4
+ error: {
5
+ status: number;
6
+ value: Err;
7
+ } | null;
8
+ status: number;
9
+ headers: Record<string, string>;
10
+ response: Response | null;
11
+ }
12
+ export interface ClientOptions {
13
+ prefix?: string;
14
+ /** Absolute origin of ANOTHER brust deployment to target, e.g.
15
+ * `https://api.example.com` (a path suffix like `/v2` composes by
16
+ * concatenation). Must match `^https?://`; a trailing slash is stripped.
17
+ * When set, the action prefix is `prefix ?? '/_brust/action'` — the global
18
+ * `__BRUST_ACTION_PREFIX__` belongs to the SERVING app and is never
19
+ * consulted. Cross-origin cookies: pass a `fetch` override that sets
20
+ * `credentials: 'include'` (and configure `cors.credentials` server-side). */
21
+ baseUrl?: string;
22
+ headers?: Record<string, string> | (() => Record<string, string>);
23
+ fetch?: typeof fetch;
24
+ }
25
+ export type PermissiveProxy = {
26
+ (arg?: any): PermissiveProxy;
27
+ [key: string]: PermissiveProxy;
28
+ } & {
29
+ get: (options?: any) => Promise<TreatyResponse<any, any>>;
30
+ post: (body?: any, options?: any) => Promise<TreatyResponse<any, any>>;
31
+ put: (body?: any, options?: any) => Promise<TreatyResponse<any, any>>;
32
+ patch: (body?: any, options?: any) => Promise<TreatyResponse<any, any>>;
33
+ delete: (body?: any, options?: any) => Promise<TreatyResponse<any, any>>;
34
+ head: (options?: any) => Promise<TreatyResponse<any, any>>;
35
+ };
36
+ /** Per-method client signatures for one endpoint-entry map (the `{ GET, POST, … }`
37
+ * object for a single path). Bodyless methods (GET/HEAD) take only options. */
38
+ type Methods<E> = {
39
+ [M in keyof E & string as Lowercase<M>]: M extends 'GET' | 'HEAD' ? E[M] extends EndpointEntry ? (o?: {
40
+ query?: Record<string, string>;
41
+ headers?: Record<string, string>;
42
+ }) => Promise<TreatyResponse<E[M]['output'], E[M]['error']>> : never : E[M] extends EndpointEntry ? (b?: E[M]['input'], o?: {
43
+ headers?: Record<string, string>;
44
+ }) => Promise<TreatyResponse<E[M]['output'], E[M]['error']>> : never;
45
+ };
46
+ /** A path is static iff it contains no `{param}` segment. */
47
+ type IsStatic<K extends string> = K extends `${string}{${string}}${string}` ? false : true;
48
+ /** Keep only the static path keys of the accumulator. */
49
+ type StaticAcc<Acc> = {
50
+ [K in keyof Acc as K extends string ? (IsStatic<K> extends true ? K : never) : never]: Acc[K];
51
+ };
52
+ /** Given a path key `K` and the accumulated prefix `P`, the next segment after `P`. */
53
+ type Tail<K extends string, P extends string> = K extends `${P}/${infer Rest}` ? Rest extends `${infer H}/${string}` ? H : Rest : never;
54
+ /** All immediate child segments under prefix `P`. */
55
+ type ChildSegs<SA, P extends string> = {
56
+ [K in keyof SA]: Tail<K & string, P>;
57
+ }[keyof SA];
58
+ /** The entry map for the exact path `P`, if one exists. */
59
+ type ExactEntry<SA, P extends string> = P extends keyof SA ? SA[P] : {};
60
+ /** A treaty node: methods of the exact path + child segment nodes + permissive fallback. */
61
+ type TNode<SA, P extends string> = Methods<ExactEntry<SA, P>> & {
62
+ [Seg in ChildSegs<SA, P> & string]: TNode<SA, `${P}/${Seg}`>;
63
+ } & PermissiveProxy;
64
+ export type Treaty<App> = App extends ActionsBuilder<infer Acc> ? TNode<StaticAcc<Acc>, ''> : PermissiveProxy;
65
+ /** Build a treaty proxy. Static segments accumulate as a path; a function call
66
+ * with an object fills the next {param}(s) positionally (in insertion order); a
67
+ * terminal method key (.get/.post/…) performs the request. URL is composed from
68
+ * the literal accumulated segments — never from any inferred type. */
69
+ export declare function client<App = unknown>(opts?: ClientOptions): Treaty<App>;
70
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { Route, RouteCall } from '../routes.ts';
2
+ export type WsCall = Extract<RouteCall, {
3
+ kind: 'ws';
4
+ }>;
5
+ /** NAPI surface — Rust provides these. Tests use a mock. */
6
+ export interface WsNapi {
7
+ send(conn_id: bigint, data: Uint8Array, isBinary: boolean): Promise<void>;
8
+ close(conn_id: bigint, code: number, reason: string): void;
9
+ signalOpen(conn_id: bigint, status: number, body: string, contentType: string, subprotocol: string): void;
10
+ registerHandlers(conn_id: bigint, onMessage: (data: Uint8Array, isBinary: boolean) => void, onClose: (code: number, reason: string) => void): void;
11
+ }
12
+ /** Pick the first subprotocol from `routeList` that the client also requested.
13
+ * Returns null when there's no overlap or routeList is empty/undefined. */
14
+ export declare function pickSubprotocol(clientList: string[], routeList: string[] | undefined): string | null;
15
+ /**
16
+ * Per-connection JS driver for WebSocket routes. Caller (wsBranch) is
17
+ * responsible for running middleware FIRST and only invoking this on a 101
18
+ * verdict — the signalOpen call here is always 101.
19
+ *
20
+ * Ordering note: handlers.open is *called* before any message can fire,
21
+ * but if open is async it is NOT guaranteed to *complete* before the first
22
+ * message arrives. Handlers that initialise per-connection state in open
23
+ * and read it in message should await any setup synchronously inside open,
24
+ * or guard reads in message against missing state.
25
+ */
26
+ export declare function handleWsConn(call: WsCall, route: Route, napi: WsNapi): Promise<void>;