talizen 0.2.4 → 0.2.6

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 CHANGED
@@ -7,6 +7,7 @@ Talizen's frontend SDK package. It provides a small runtime client and shared ty
7
7
  - `talizen/cms`
8
8
  - `talizen/form`
9
9
  - `talizen/func`
10
+ - `talizen/func-runtime`
10
11
 
11
12
  The package is designed to hold the platform-level APIs that frontend projects use directly, while project-specific CMS and form schema types can still be generated separately per project.
12
13
 
@@ -137,13 +138,35 @@ const result = await invoke<{ success: boolean }>("user/auth.login", {
137
138
  await invoke("user/auth", { email: "hi@talizen.com" });
138
139
  ```
139
140
 
141
+ ### Write function runtime code
142
+
143
+ Func code can use TypeScript and import runtime-only helpers from `talizen/func-runtime`:
144
+
145
+ ```ts
146
+ import { auth, db, cache } from "talizen/func-runtime";
147
+
148
+ export function create(input: { title: string }) {
149
+ const user = auth.requireUser();
150
+ const row = db.insert("book", {
151
+ title: input.title,
152
+ user_id: user.id,
153
+ status: "draft",
154
+ });
155
+ cache.set(`book:${row.id}`, row, 60);
156
+ return { ok: true, id: row.id };
157
+ }
158
+ ```
159
+
160
+ `db`, `cache`, and Func `auth` are injected by the Talizen Func runtime. They are typed in this package for authoring, but they are not browser/Node general-purpose APIs.
161
+
140
162
  ## Package Layout
141
163
 
142
164
  - `talizen/core`: shared runtime config, request helpers, and base data types.
143
165
  - `talizen/auth`: project user register, login, logout, and current user helpers.
144
166
  - `talizen/cms`: CMS content types and content query APIs.
145
167
  - `talizen/form`: form submission helpers and related types.
146
- - `talizen/func`: custom function invocation helpers.
168
+ - `talizen/func`: custom function invocation helpers such as `invoke`.
169
+ - `talizen/func-runtime`: Func-runtime-only `db`, `cache`, and `auth` types.
147
170
 
148
171
  ## Publish
149
172
 
@@ -0,0 +1,65 @@
1
+ import type { AuthUser } from "./auth.js";
2
+ export type DbOrderBy = string;
3
+ export interface DbFilterCondition {
4
+ field_id?: string;
5
+ fieldId?: string;
6
+ operator: "equal" | "not_equal" | "in";
7
+ value?: unknown;
8
+ values?: unknown[];
9
+ }
10
+ export interface DbFilter {
11
+ match?: "and" | "or";
12
+ conditions?: DbFilterCondition[];
13
+ }
14
+ export interface DbQuery {
15
+ where?: Record<string, unknown>;
16
+ filter?: DbFilter;
17
+ limit?: number;
18
+ offset?: number;
19
+ order_by?: DbOrderBy;
20
+ orderBy?: DbOrderBy;
21
+ }
22
+ export type DbRecord<T extends Record<string, unknown> = Record<string, unknown>> = T & {
23
+ id: string;
24
+ };
25
+ export interface FuncDbRuntime {
26
+ 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): Array<DbRecord<T>>;
28
+ insert<T extends Record<string, unknown> = Record<string, unknown>>(table: string, data: T): DbRecord<T>;
29
+ update<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string, data: Partial<T>): {
30
+ ok?: boolean;
31
+ updated?: boolean;
32
+ } | DbRecord<T>;
33
+ delete(table: string, id: string): {
34
+ ok?: boolean;
35
+ deleted?: boolean;
36
+ };
37
+ }
38
+ export interface FuncAuthRuntime {
39
+ currentUser(): AuthUser | null;
40
+ requireUser(): AuthUser;
41
+ }
42
+ export interface CacheSetOptions {
43
+ ttl?: number;
44
+ ttlSeconds?: number;
45
+ }
46
+ export interface FuncCacheRuntime {
47
+ get<T = unknown>(key: string): T | null;
48
+ set(key: string, value: unknown, ttlSeconds?: number): {
49
+ ok?: boolean;
50
+ };
51
+ set(key: string, value: unknown, options?: CacheSetOptions): {
52
+ ok?: boolean;
53
+ };
54
+ del(key: string): {
55
+ ok?: boolean;
56
+ deleted?: boolean;
57
+ };
58
+ incr(key: string, delta?: number): number;
59
+ expire(key: string, ttlSeconds: number): {
60
+ ok?: boolean;
61
+ };
62
+ }
63
+ export declare const db: FuncDbRuntime;
64
+ export declare const auth: FuncAuthRuntime;
65
+ export declare const cache: FuncCacheRuntime;
@@ -0,0 +1,21 @@
1
+ function unavailable() {
2
+ throw new Error("talizen/func-runtime is only available inside Talizen Func runtime.");
3
+ }
4
+ export const db = {
5
+ get: unavailable,
6
+ query: unavailable,
7
+ insert: unavailable,
8
+ update: unavailable,
9
+ delete: unavailable,
10
+ };
11
+ export const auth = {
12
+ currentUser: unavailable,
13
+ requireUser: unavailable,
14
+ };
15
+ export const cache = {
16
+ get: unavailable,
17
+ set: unavailable,
18
+ del: unavailable,
19
+ incr: unavailable,
20
+ expire: unavailable,
21
+ };
package/index.d.ts CHANGED
@@ -3,7 +3,6 @@ export * from "./auth.js";
3
3
  export * from "./cms.js";
4
4
  export * from "./captcha-ui.js";
5
5
  export * from "./form.js";
6
- export * from "./func.js";
7
6
  export * from "./i18n.js";
8
7
  type OneOrMany<T> = T | Array<T>;
9
8
  export interface MetadataTitle {
package/index.js CHANGED
@@ -3,5 +3,4 @@ export * from "./auth.js";
3
3
  export * from "./cms.js";
4
4
  export * from "./captcha-ui.js";
5
5
  export * from "./form.js";
6
- export * from "./func.js";
7
6
  export * from "./i18n.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talizen",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Talizen frontend SDK types for cms, form and core.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,6 +40,10 @@
40
40
  "types": "./func.d.ts",
41
41
  "import": "./func.js"
42
42
  },
43
+ "./func-runtime": {
44
+ "types": "./func-runtime.d.ts",
45
+ "import": "./func-runtime.js"
46
+ },
43
47
  "./i18n": {
44
48
  "types": "./i18n.d.ts",
45
49
  "import": "./i18n.js"