zitejs 0.3.0 → 0.4.0

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/api/index.d.ts CHANGED
@@ -1,47 +1,21 @@
1
1
  /**
2
- * zitejs/api — Server-side endpoint definition + typed client caller.
2
+ * zitejs/api — Client-side typed API caller.
3
3
  *
4
- * Server-side (defining endpoints):
5
- * import { createEndpoint, ZiteError } from 'zitejs/api';
6
- * export default createEndpoint({ ... });
4
+ * Used in generated .zite/api.ts files:
5
+ * import { createCaller } from 'zitejs/api';
6
+ * import myEndpoint from '../src/api/myEndpoint';
7
+ * export const api = { myEndpoint: createCaller(myEndpoint) };
7
8
  *
8
- * Client-side (generated by zitejs sync into .zite/api.ts):
9
- * import { api } from './.zite/api';
10
- * await api.getRecords({ table: 'contacts' });
9
+ * Then consumed in app code:
10
+ * import { api } from 'zitejs/api'; // resolved via tsconfig to .zite/api.ts
11
+ * await api.myEndpoint({ ... });
11
12
  */
12
13
 
13
- export interface ZiteRequestContext {
14
- userId?: string;
15
- organizationId?: string;
16
- [key: string]: unknown;
17
- }
18
-
19
- export interface ZiteScheduledContext extends ZiteRequestContext {
20
- scheduledAt: string;
21
- }
22
-
23
- export declare class ZiteError extends Error {
24
- constructor(message: string, options?: { statusCode?: number });
25
- statusCode: number;
26
- }
27
-
28
14
  export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
29
- description?: string;
30
- inputSchema?: unknown;
31
- outputSchema?: unknown;
32
- stream?: boolean;
33
15
  _name?: string;
34
- execute: (params: {
35
- input: TInput;
36
- context: ZiteRequestContext | ZiteScheduledContext;
37
- }) => Promise<TOutput> | TOutput;
16
+ execute: (params: { input: TInput; context: unknown }) => Promise<TOutput> | TOutput;
38
17
  }
39
18
 
40
- export declare function createEndpoint<
41
- TInput = unknown,
42
- TOutput = unknown,
43
- >(config: EndpointConfig<TInput, TOutput>): EndpointConfig<TInput, TOutput>;
44
-
45
19
  export declare function createCaller<TInput, TOutput>(
46
20
  endpoint: EndpointConfig<TInput, TOutput>,
47
21
  ): (input: TInput) => Promise<TOutput>;
package/api/index.js CHANGED
@@ -1,20 +1,8 @@
1
- // zitejs/api — server-side endpoint definition + client caller factory.
1
+ // zitejs/api — client-side typed API caller factory.
2
2
 
3
3
  const BASE_URL = process.env.ZITE_API_URL ?? '';
4
4
  const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
5
5
 
6
- export class ZiteError extends Error {
7
- constructor(message, options) {
8
- super(message);
9
- this.name = 'ZiteError';
10
- this.statusCode = options?.statusCode ?? 500;
11
- }
12
- }
13
-
14
- export function createEndpoint(config) {
15
- return config;
16
- }
17
-
18
6
  export function createCaller(endpoint) {
19
7
  return async (input) => {
20
8
  const res = await fetch(BASE_URL + '/api/' + endpoint._name, {
@@ -27,7 +15,7 @@ export function createCaller(endpoint) {
27
15
  });
28
16
  if (!res.ok) {
29
17
  const text = await res.text().catch(() => '');
30
- throw new ZiteError(`API call failed (${res.status}): ${text}`);
18
+ throw new Error(`API call failed (${res.status}): ${text}`);
31
19
  }
32
20
  return res.json();
33
21
  };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * zitejs/backend — Server-side endpoint definition.
3
+ *
4
+ * Usage:
5
+ * import { createEndpoint, ZiteError } from 'zitejs/backend';
6
+ * export default createEndpoint({ ... });
7
+ */
8
+
9
+ export interface ZiteRequestContext {
10
+ userId?: string;
11
+ organizationId?: string;
12
+ [key: string]: unknown;
13
+ }
14
+
15
+ export interface ZiteScheduledContext extends ZiteRequestContext {
16
+ scheduledAt: string;
17
+ }
18
+
19
+ export declare class ZiteError extends Error {
20
+ constructor(message: string, options?: { statusCode?: number });
21
+ statusCode: number;
22
+ }
23
+
24
+ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
25
+ description?: string;
26
+ inputSchema?: unknown;
27
+ outputSchema?: unknown;
28
+ stream?: boolean;
29
+ _name?: string;
30
+ execute: (params: {
31
+ input: TInput;
32
+ context: ZiteRequestContext | ZiteScheduledContext;
33
+ }) => Promise<TOutput> | TOutput;
34
+ }
35
+
36
+ export declare function createEndpoint<
37
+ TInput = unknown,
38
+ TOutput = unknown,
39
+ >(config: EndpointConfig<TInput, TOutput>): EndpointConfig<TInput, TOutput>;
@@ -0,0 +1,13 @@
1
+ // zitejs/backend — server-side endpoint definition.
2
+
3
+ export class ZiteError extends Error {
4
+ constructor(message, options) {
5
+ super(message);
6
+ this.name = 'ZiteError';
7
+ this.statusCode = options?.statusCode ?? 500;
8
+ }
9
+ }
10
+
11
+ export function createEndpoint(config) {
12
+ return config;
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,6 +15,10 @@
15
15
  "types": "./api/index.d.ts",
16
16
  "default": "./api/index.js"
17
17
  },
18
+ "./backend": {
19
+ "types": "./backend/index.d.ts",
20
+ "default": "./backend/index.js"
21
+ },
18
22
  "./auth": {
19
23
  "types": "./auth/index.d.ts",
20
24
  "default": "./auth/index.js"
@@ -38,6 +42,7 @@
38
42
  "files": [
39
43
  "db",
40
44
  "api",
45
+ "backend",
41
46
  "auth",
42
47
  "upload",
43
48
  "pdf",