talizen 0.2.9 → 0.2.10
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/README.md +35 -0
- package/func-runtime.d.ts +5 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +5 -1
- package/server-runtime.d.ts +40 -0
- package/server-runtime.js +1 -0
package/README.md
CHANGED
|
@@ -160,6 +160,24 @@ const result = await invoke<{ ok: boolean; id: string }>("booking.create", {
|
|
|
160
160
|
await invoke("booking", { email: "hi@talizen.com" });
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
+
### Server-side page context
|
|
164
|
+
|
|
165
|
+
In `getServerSideProps`, use the injected server context for request metadata
|
|
166
|
+
and cookies. Do not import `talizen/auth` or `talizen/func`, and do not read
|
|
167
|
+
auth state or call Func from server-side page code:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import type { TalizenServerSideContext } from "talizen/server-runtime";
|
|
171
|
+
|
|
172
|
+
export async function getServerSideProps(ctx: TalizenServerSideContext) {
|
|
173
|
+
return { props: { path: ctx.request.path } };
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Server-side context supports `ctx.request` and `ctx.cookies`. It intentionally
|
|
178
|
+
does not expose `ctx.auth`, `ctx.db`, `ctx.cache`, or `ctx.func`; put login UI,
|
|
179
|
+
private business data access, and writes in browser-side SDK/Func/API flows.
|
|
180
|
+
|
|
163
181
|
### Write function runtime code
|
|
164
182
|
|
|
165
183
|
Func code can use TypeScript and import Func authoring types from `talizen/func-runtime`.
|
|
@@ -180,6 +198,22 @@ export function create(input: { title: string }, ctx: TalizenFuncContext) {
|
|
|
180
198
|
}
|
|
181
199
|
```
|
|
182
200
|
|
|
201
|
+
`ctx.db.query(table, query)` returns `{ total, list }`, where `total` is the
|
|
202
|
+
matched record count before pagination and `list` is the current page:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import type { TalizenFuncContext } from "talizen/func-runtime";
|
|
206
|
+
|
|
207
|
+
export function list(input: { offset?: number }, ctx: TalizenFuncContext) {
|
|
208
|
+
const result = ctx.db.query<{ title: string; status: string }>("book", {
|
|
209
|
+
where: { status: "published" },
|
|
210
|
+
limit: 20,
|
|
211
|
+
offset: input.offset || 0,
|
|
212
|
+
});
|
|
213
|
+
return { total: result.total, books: result.list };
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
183
217
|
`ctx.db`, `ctx.cache`, `ctx.auth`, `ctx.request`, and `ctx.cookies` are injected by the Talizen Func runtime. `talizen/func-runtime` is a type-only authoring module; do not import runtime values from it.
|
|
184
218
|
|
|
185
219
|
## Package Layout
|
|
@@ -190,6 +224,7 @@ export function create(input: { title: string }, ctx: TalizenFuncContext) {
|
|
|
190
224
|
- `talizen/form`: form submission helpers and related types.
|
|
191
225
|
- `talizen/func`: custom function invocation helpers such as `invoke`.
|
|
192
226
|
- `talizen/func-runtime`: Func-runtime-only `ctx` capability types.
|
|
227
|
+
- `talizen/server-runtime`: getServerSideProps-only `ctx` capability types.
|
|
193
228
|
|
|
194
229
|
## Publish
|
|
195
230
|
|
package/func-runtime.d.ts
CHANGED
|
@@ -22,9 +22,13 @@ export interface DbQuery {
|
|
|
22
22
|
export type DbRecord<T extends Record<string, unknown> = Record<string, unknown>> = T & {
|
|
23
23
|
id: string;
|
|
24
24
|
};
|
|
25
|
+
export interface DbQueryResult<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
26
|
+
total: number;
|
|
27
|
+
list: Array<DbRecord<T>>;
|
|
28
|
+
}
|
|
25
29
|
export interface FuncDbRuntime {
|
|
26
30
|
get<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string): DbRecord<T> | null;
|
|
27
|
-
query<T extends Record<string, unknown> = Record<string, unknown>>(table: string, query?: DbQuery):
|
|
31
|
+
query<T extends Record<string, unknown> = Record<string, unknown>>(table: string, query?: DbQuery): DbQueryResult<T>;
|
|
28
32
|
insert<T extends Record<string, unknown> = Record<string, unknown>>(table: string, data: T): DbRecord<T>;
|
|
29
33
|
update<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string, data: Partial<T>): {
|
|
30
34
|
ok?: boolean;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "talizen",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Talizen frontend SDK types for cms, form and core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"types": "./func-runtime.d.ts",
|
|
45
45
|
"import": "./func-runtime.js"
|
|
46
46
|
},
|
|
47
|
+
"./server-runtime": {
|
|
48
|
+
"types": "./server-runtime.d.ts",
|
|
49
|
+
"import": "./server-runtime.js"
|
|
50
|
+
},
|
|
47
51
|
"./i18n": {
|
|
48
52
|
"types": "./i18n.d.ts",
|
|
49
53
|
"import": "./i18n.js"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface ServerReadonlyStringMap {
|
|
2
|
+
get(name: string): string | null;
|
|
3
|
+
}
|
|
4
|
+
export interface TalizenServerRequestRuntime {
|
|
5
|
+
host: string;
|
|
6
|
+
ip: string;
|
|
7
|
+
method: string;
|
|
8
|
+
path: string;
|
|
9
|
+
url: string;
|
|
10
|
+
headers: ServerReadonlyStringMap;
|
|
11
|
+
cookies: ServerReadonlyStringMap;
|
|
12
|
+
}
|
|
13
|
+
export interface ServerCookieSetOptions {
|
|
14
|
+
path?: string;
|
|
15
|
+
domain?: string;
|
|
16
|
+
maxAge?: number;
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
sameSite?: "lax" | "strict" | "none";
|
|
20
|
+
}
|
|
21
|
+
export interface TalizenServerCookieRuntime {
|
|
22
|
+
get(name: string): string | null;
|
|
23
|
+
set(name: string, value: string, options?: ServerCookieSetOptions): {
|
|
24
|
+
ok?: boolean;
|
|
25
|
+
};
|
|
26
|
+
delete(name: string, options?: Pick<ServerCookieSetOptions, "path" | "domain">): {
|
|
27
|
+
ok?: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface TalizenServerSideContext {
|
|
31
|
+
query: Record<string, string | string[]>;
|
|
32
|
+
searchParams: Record<string, string | string[]>;
|
|
33
|
+
params: Record<string, string>;
|
|
34
|
+
locale?: string;
|
|
35
|
+
locales?: string[];
|
|
36
|
+
defaultLocale?: string;
|
|
37
|
+
request: TalizenServerRequestRuntime;
|
|
38
|
+
req: TalizenServerRequestRuntime;
|
|
39
|
+
cookies: TalizenServerCookieRuntime;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|