talizen 0.2.5 → 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
 
@@ -139,10 +140,10 @@ await invoke("user/auth", { email: "hi@talizen.com" });
139
140
 
140
141
  ### Write function runtime code
141
142
 
142
- Func code can use TypeScript and import runtime-only helpers from `talizen/func`:
143
+ Func code can use TypeScript and import runtime-only helpers from `talizen/func-runtime`:
143
144
 
144
145
  ```ts
145
- import { auth, db, cache } from "talizen/func";
146
+ import { auth, db, cache } from "talizen/func-runtime";
146
147
 
147
148
  export function create(input: { title: string }) {
148
149
  const user = auth.requireUser();
@@ -164,7 +165,8 @@ export function create(input: { title: string }) {
164
165
  - `talizen/auth`: project user register, login, logout, and current user helpers.
165
166
  - `talizen/cms`: CMS content types and content query APIs.
166
167
  - `talizen/form`: form submission helpers and related types.
167
- - `talizen/func`: custom function invocation helpers and Func-runtime-only `db`, `cache`, `auth` types.
168
+ - `talizen/func`: custom function invocation helpers such as `invoke`.
169
+ - `talizen/func-runtime`: Func-runtime-only `db`, `cache`, and `auth` types.
168
170
 
169
171
  ## Publish
170
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/func.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { type TalizenRequestOptions } from "./core.js";
2
- import type { AuthUser } from "./auth.js";
3
2
  export interface FuncLogEntry {
4
3
  level: string;
5
4
  text: string;
@@ -10,70 +9,6 @@ export interface FuncRunResponse<T = unknown> {
10
9
  logs?: FuncLogEntry[];
11
10
  error?: string;
12
11
  }
13
- export type DbOrderBy = string;
14
- export interface DbFilterCondition {
15
- field_id?: string;
16
- fieldId?: string;
17
- operator: "equal" | "not_equal" | "in";
18
- value?: unknown;
19
- values?: unknown[];
20
- }
21
- export interface DbFilter {
22
- match?: "and" | "or";
23
- conditions?: DbFilterCondition[];
24
- }
25
- export interface DbQuery {
26
- where?: Record<string, unknown>;
27
- filter?: DbFilter;
28
- limit?: number;
29
- offset?: number;
30
- order_by?: DbOrderBy;
31
- orderBy?: DbOrderBy;
32
- }
33
- export type DbRecord<T extends Record<string, unknown> = Record<string, unknown>> = T & {
34
- id: string;
35
- };
36
- export interface FuncDbRuntime {
37
- get<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string): DbRecord<T> | null;
38
- query<T extends Record<string, unknown> = Record<string, unknown>>(table: string, query?: DbQuery): Array<DbRecord<T>>;
39
- insert<T extends Record<string, unknown> = Record<string, unknown>>(table: string, data: T): DbRecord<T>;
40
- update<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string, data: Partial<T>): {
41
- ok?: boolean;
42
- updated?: boolean;
43
- } | DbRecord<T>;
44
- delete(table: string, id: string): {
45
- ok?: boolean;
46
- deleted?: boolean;
47
- };
48
- }
49
- export interface FuncAuthRuntime {
50
- currentUser(): AuthUser | null;
51
- requireUser(): AuthUser;
52
- }
53
- export interface CacheSetOptions {
54
- ttl?: number;
55
- ttlSeconds?: number;
56
- }
57
- export interface FuncCacheRuntime {
58
- get<T = unknown>(key: string): T | null;
59
- set(key: string, value: unknown, ttlSeconds?: number): {
60
- ok?: boolean;
61
- };
62
- set(key: string, value: unknown, options?: CacheSetOptions): {
63
- ok?: boolean;
64
- };
65
- del(key: string): {
66
- ok?: boolean;
67
- deleted?: boolean;
68
- };
69
- incr(key: string, delta?: number): number;
70
- expire(key: string, ttlSeconds: number): {
71
- ok?: boolean;
72
- };
73
- }
74
- export declare const db: FuncDbRuntime;
75
- export declare const auth: FuncAuthRuntime;
76
- export declare const cache: FuncCacheRuntime;
77
12
  export declare class TalizenFuncError extends Error {
78
13
  readonly key: string;
79
14
  readonly method: string;
package/func.js CHANGED
@@ -1,25 +1,4 @@
1
1
  import { requestJson, } from "./core.js";
2
- function funcRuntimeUnavailable() {
3
- throw new Error("talizen/func db/cache/auth are only available inside Talizen Func runtime.");
4
- }
5
- export const db = {
6
- get: funcRuntimeUnavailable,
7
- query: funcRuntimeUnavailable,
8
- insert: funcRuntimeUnavailable,
9
- update: funcRuntimeUnavailable,
10
- delete: funcRuntimeUnavailable,
11
- };
12
- export const auth = {
13
- currentUser: funcRuntimeUnavailable,
14
- requireUser: funcRuntimeUnavailable,
15
- };
16
- export const cache = {
17
- get: funcRuntimeUnavailable,
18
- set: funcRuntimeUnavailable,
19
- del: funcRuntimeUnavailable,
20
- incr: funcRuntimeUnavailable,
21
- expire: funcRuntimeUnavailable,
22
- };
23
2
  export class TalizenFuncError extends Error {
24
3
  key;
25
4
  method;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talizen",
3
- "version": "0.2.5",
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"