rosetack 0.0.0 → 0.1.1

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.
@@ -0,0 +1,142 @@
1
+ /**
2
+ * rosetack - the globals a `.rose` <script> block can call.
3
+ *
4
+ * This file is the framework's public script surface, declared once so an
5
+ * editor and `rosetack check` (which runs the project's own TypeScript over
6
+ * every extracted script block) both see the same truth the runtime
7
+ * implements. The signatures mirror src/runtime/index.ts exactly - when one
8
+ * changes, this file changes with it.
9
+ *
10
+ * It ships with the package. A project picks it up with a `rosetack-env.d.ts`
11
+ * holding `/// <reference types="rosetack" />` (what `rosetack new` writes for
12
+ * you); `rosetack check` references it by path, so it works in a source
13
+ * checkout too. No imports, no exports: every declaration here is global,
14
+ * because that is exactly how a `.rose` script sees them.
15
+ */
16
+ /// <reference lib="dom" />
17
+
18
+ /**
19
+ * A reactive getter. The compiler turns `let count = $state(0)` into a
20
+ * getter/setter pair named after your declaration, so in a `.rose` script
21
+ * the name you wrote IS this function - `count()` reads it, and
22
+ * `$setState('count', v)` (or the generated setter) writes it.
23
+ */
24
+ type Getter<T> = () => T;
25
+
26
+ /** A store shared by every request in this process (and, with a transport, every worker). */
27
+ interface Store<T> {
28
+ get(): T;
29
+ set(v: T): void;
30
+ update(fn: (v: T) => T): void;
31
+ }
32
+
33
+ /** Declare reactive state. Server-rendered into the document, resumed by the client with zero hydration. */
34
+ declare function $state<T>(initial: T): Getter<T>;
35
+
36
+ /** Write reactive state by key - the same write the generated setter performs. */
37
+ declare function $setState<T>(key: string, value: T): void;
38
+
39
+ /**
40
+ * Server data. The body runs on the server per request (and ships to the
41
+ * client, where it re-runs on a client-side navigation), the result lands in
42
+ * the same state map as `$state` - so `post()` is a getter like any other.
43
+ * The await is the compiler's, not yours.
44
+ */
45
+ declare function $data<T>(fn: () => T | Promise<T>): Getter<T>;
46
+
47
+ /** The per-request bag filled by `pages/_middleware.rose` (auth, db, cache). */
48
+ declare function getContext<T = Record<string, unknown>>(): T;
49
+
50
+ /**
51
+ * Translate a key from src/locales/<lang>.json.
52
+ *
53
+ * Values are either plain strings with `{name}` holes or ICU MessageFormat:
54
+ * `{count, plural, one {# item} other {# items}}`, `{n, selectordinal, ...}`,
55
+ * `{who, select, ...}` - so `vars` carries numbers for counts and strings for
56
+ * names and select arms. A missing key renders the key itself.
57
+ */
58
+ declare function $t(key: string, vars?: Record<string, string | number>): string;
59
+
60
+ /** 'rtl' for a right-to-left locale (ar, he, fa, ur, ...), 'ltr' otherwise. */
61
+ declare function localeDir(lang: string): string;
62
+
63
+ /**
64
+ * Resolve once a locale's dictionary is present: immediately for a baked one,
65
+ * after one fetch of /locales/<lang>.json for a runtime pack (a locale the
66
+ * build left out of the bundle via i18n.preload). The client router awaits
67
+ * this on every navigation, so a page rarely needs to call it directly.
68
+ */
69
+ declare function ensureLocale(lang: string): Promise<void>;
70
+
71
+ /** Merge a dictionary that arrived at runtime (a fetched pack, or your own import()). */
72
+ declare function loadLocale(lang: string, dict: Record<string, string>): void;
73
+
74
+ /** A named, process-wide store. Values must be JSON-serializable. */
75
+ declare function $store<T>(name: string, initial: T): Store<T>;
76
+
77
+ /** Parse the request's cookies (server) or this document's (client). */
78
+ declare function $cookies(request?: Request): Record<string, string>;
79
+
80
+ /** Build a Set-Cookie value with the safe defaults: HttpOnly, SameSite=Lax, Path=/, 7 days. */
81
+ declare function $sessionCookie(
82
+ name: string,
83
+ value: string,
84
+ opts?: { path?: string; maxAge?: number; sameSite?: 'Strict' | 'Lax' | 'None'; secure?: boolean; httpOnly?: boolean }
85
+ ): string;
86
+
87
+ /** Run once after the client has adopted the server's DOM. */
88
+ declare function onMount(fn: () => void): void;
89
+
90
+ /** Register a teardown for the next navigation. */
91
+ declare function onCleanup(fn: () => void): void;
92
+
93
+ /** Re-render the current route in place - `$data` re-runs, zero requests. */
94
+ declare function refresh(): Promise<void>;
95
+
96
+ /** HTML-escape a value into a string (the same escape the template markers use). */
97
+ declare function esc(v: unknown): string;
98
+
99
+ /** Call a server action by name; the response is adopted in place. */
100
+ declare function $action(name: string, e?: Event): Promise<void>;
101
+
102
+ /**
103
+ * The standardized failure a server action throws for a BUSINESS error (bad
104
+ * input, not signed in, a duplicate) - as opposed to a bug, which still goes
105
+ * to the 500 page. `code` becomes the response status; `field` names the
106
+ * offending form input.
107
+ */
108
+ declare class ActionError extends Error {
109
+ code: number;
110
+ field?: string;
111
+ constructor(message: string, code?: number, field?: string);
112
+ }
113
+
114
+ /** What the dispatch seeds into state when an action fails (what `$actionError()` returns). */
115
+ interface ActionErrorInfo {
116
+ action: string;
117
+ message: string;
118
+ code: number;
119
+ field?: string;
120
+ }
121
+
122
+ /**
123
+ * The failure of the action that produced the response being rendered, or
124
+ * null. Render it (`{#if $actionError()}<p>{$actionError().message}</p>{/if}`)
125
+ * or contain it with a `{#boundary}` around the action's widget.
126
+ */
127
+ declare function $actionError(): ActionErrorInfo | null;
128
+
129
+ /**
130
+ * An incremental patch: an action's return value may map a state key to an
131
+ * OPERATION instead of a whole replacement, so growing a large list costs one
132
+ * row rather than a second copy of the list.
133
+ */
134
+ declare function $append(value: unknown): unknown;
135
+ declare function $prepend(value: unknown): unknown;
136
+ declare function $merge(value: Record<string, unknown>): unknown;
137
+
138
+ /** Whether a state key already holds a value (what `$data` checks before fetching). */
139
+ declare function hasState(key: string): boolean;
140
+
141
+ /** The best dictionary for an Accept-Language header (null when none matches). */
142
+ declare function bestLocale(header: string | null | undefined): string | null;
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- ## License
2
-
3
- MIT
package/index.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * rosetack
3
- * @version 0.0.0
4
- * @license MIT
5
- * @repository https://github.com/neodunli/rosetack
6
- */
7
-
8
- 'use strict';
9
-
10
- module.exports = {
11
- version: '0.0.0',
12
- };