zitejs 0.9.26 → 0.9.27
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/dist/cjs/runtime/index.js +31 -52
- package/dist/cjs/sync/lib.js +11 -14
- package/dist/esm/runtime/index.d.ts +10 -13
- package/dist/esm/runtime/index.js +30 -51
- package/dist/esm/sync/lib.js +11 -14
- package/package.json +1 -1
|
@@ -1,67 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCaller = void 0;
|
|
4
|
-
exports.wrapSdkCall = wrapSdkCall;
|
|
5
4
|
exports.createTableClient = createTableClient;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
function getExecutionConfig() {
|
|
13
|
-
return globalThis.__ZITE_EXECUTION_CONFIG__;
|
|
14
|
-
}
|
|
15
|
-
function getRunnerUrl() {
|
|
16
|
-
const config = getExecutionConfig();
|
|
17
|
-
if (config?.workflowRunnerUrl)
|
|
18
|
-
return config.workflowRunnerUrl;
|
|
19
|
-
const env = (0, env_js_1.getEnv)('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
|
|
20
|
-
return (0, env_js_1.getEnv)('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
21
|
-
}
|
|
22
|
-
function getToken() {
|
|
23
|
-
const config = getExecutionConfig();
|
|
24
|
-
if (config?.token)
|
|
25
|
-
return config.token;
|
|
26
|
-
return (0, env_js_1.getEnv)('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
27
|
-
}
|
|
28
|
-
async function wrapSdkCall(integrationId, className, methodName, params) {
|
|
29
|
-
const mergedParams = { tableId: className, ...params };
|
|
30
|
-
const res = await fetch(`${getRunnerUrl()}/sdk/execute`, {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: `Bearer ${getToken()}`,
|
|
34
|
-
'Content-Type': 'application/json',
|
|
35
|
-
},
|
|
36
|
-
body: JSON.stringify({ integrationId, methodName, params: mergedParams }),
|
|
37
|
-
});
|
|
38
|
-
if (!res.ok) {
|
|
39
|
-
const text = await res.text().catch(() => '');
|
|
40
|
-
throw new Error(`SDK call failed (${res.status}): ${text}`);
|
|
5
|
+
exports.createSqlClient = createSqlClient;
|
|
6
|
+
function getSdkCall() {
|
|
7
|
+
const fn = globalThis.__wrapSdkCall;
|
|
8
|
+
if (!fn) {
|
|
9
|
+
throw new Error('Zite SDK runtime not initialized. Endpoints must run inside the Zite worker.');
|
|
41
10
|
}
|
|
42
|
-
return
|
|
11
|
+
return fn;
|
|
43
12
|
}
|
|
44
13
|
function createTableClient(integrationId, className) {
|
|
45
14
|
return {
|
|
46
|
-
findAll: (options) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return wrapSdkCall(integrationId, className, 'update', {
|
|
54
|
-
id: recordId,
|
|
55
|
-
...(data && 'record' in data ? data.record : data),
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
delete: (recordId) => wrapSdkCall(integrationId, className, 'delete', {
|
|
59
|
-
id: typeof recordId === 'string' ? recordId : recordId.id,
|
|
15
|
+
findAll: (options) => getSdkCall()(integrationId, className, 'findAll', {
|
|
16
|
+
tableId: className,
|
|
17
|
+
...options,
|
|
18
|
+
}),
|
|
19
|
+
findOne: (recordId) => getSdkCall()(integrationId, className, 'findOne', {
|
|
20
|
+
tableId: className,
|
|
21
|
+
...(typeof recordId === 'string' ? { id: recordId } : recordId),
|
|
60
22
|
}),
|
|
61
|
-
|
|
23
|
+
create: (data) => getSdkCall()(integrationId, className, 'create', {
|
|
24
|
+
tableId: className,
|
|
25
|
+
record: data,
|
|
26
|
+
}),
|
|
27
|
+
update: (id, data) => getSdkCall()(integrationId, className, 'update', {
|
|
28
|
+
tableId: className,
|
|
29
|
+
id,
|
|
30
|
+
record: data,
|
|
31
|
+
}),
|
|
32
|
+
delete: (id) => getSdkCall()(integrationId, className, 'delete', {
|
|
33
|
+
tableId: className,
|
|
34
|
+
id,
|
|
35
|
+
}),
|
|
36
|
+
bulkCreate: (records) => getSdkCall()(integrationId, className, 'bulkCreate', {
|
|
37
|
+
tableId: className,
|
|
62
38
|
records,
|
|
63
39
|
}),
|
|
64
40
|
};
|
|
65
41
|
}
|
|
42
|
+
function createSqlClient(integrationId) {
|
|
43
|
+
return (params) => getSdkCall()(integrationId, 'Db', 'executeSql', params);
|
|
44
|
+
}
|
|
66
45
|
var index_js_1 = require("../caller/index.js");
|
|
67
46
|
Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -64,12 +64,11 @@ function generateSchema(base) {
|
|
|
64
64
|
function generateDbTs(base, schema, integrationId = 'databases') {
|
|
65
65
|
const lines = [];
|
|
66
66
|
lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
|
|
67
|
-
lines.push('//
|
|
68
|
-
lines.push('// .
|
|
69
|
-
lines.push('// .
|
|
70
|
-
lines.push('//
|
|
71
|
-
lines.push(
|
|
72
|
-
lines.push("import { createTableClient, wrapSdkCall } from 'zitejs/runtime';");
|
|
67
|
+
lines.push('// Table methods: .findAll(opts?) → { records: T[], total, hasMore }');
|
|
68
|
+
lines.push('// .findOne(id) → T | .create(data) → T | .update(id, data) → T');
|
|
69
|
+
lines.push('// .delete(id) → { deleted: true } | .bulkCreate(records) → T[]');
|
|
70
|
+
lines.push('// Raw SQL: zite.sql({ query: "SELECT..." }) → { rows: Record<string, unknown>[] }');
|
|
71
|
+
lines.push("import { createTableClient, createSqlClient } from 'zitejs/runtime';");
|
|
73
72
|
lines.push('');
|
|
74
73
|
for (const table of base.tables ?? []) {
|
|
75
74
|
const className = toPascalCase(table.name);
|
|
@@ -92,8 +91,7 @@ function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
92
91
|
const propName = toCamelCase(table.name);
|
|
93
92
|
lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
|
|
94
93
|
}
|
|
95
|
-
lines.push(
|
|
96
|
-
lines.push(" db: { executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }> },");
|
|
94
|
+
lines.push(` sql: createSqlClient('${integrationId}'),`);
|
|
97
95
|
lines.push('};');
|
|
98
96
|
lines.push('');
|
|
99
97
|
return lines.join('\n');
|
|
@@ -101,15 +99,14 @@ function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
101
99
|
function generateDbDts(base, schema) {
|
|
102
100
|
const lines = [
|
|
103
101
|
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
104
|
-
'//
|
|
105
|
-
'// See db.ts for the full runtime.',
|
|
102
|
+
'// Type declarations for IDE and LLM context. See db.ts for runtime.',
|
|
106
103
|
'',
|
|
107
104
|
'interface TableClient<T> {',
|
|
108
105
|
' findAll(options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown; filters?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }>;',
|
|
109
106
|
' findOne(recordId: string | { filters?: unknown; filter?: unknown }): Promise<T>;',
|
|
110
|
-
' create(data: Partial<T>
|
|
111
|
-
' update(
|
|
112
|
-
' delete(
|
|
107
|
+
' create(data: Partial<T>): Promise<T>;',
|
|
108
|
+
' update(id: string, data: Partial<T>): Promise<T>;',
|
|
109
|
+
' delete(id: string): Promise<{ deleted: true }>;',
|
|
113
110
|
' bulkCreate(records: Partial<T>[]): Promise<T[]>;',
|
|
114
111
|
'}',
|
|
115
112
|
'',
|
|
@@ -135,7 +132,7 @@ function generateDbDts(base, schema) {
|
|
|
135
132
|
const propName = toCamelCase(table.name);
|
|
136
133
|
lines.push(` ${propName}: TableClient<${className}RecordType>;`);
|
|
137
134
|
}
|
|
138
|
-
lines.push('
|
|
135
|
+
lines.push(' sql: (params: { query?: string; sql?: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
|
|
139
136
|
lines.push('};');
|
|
140
137
|
lines.push('');
|
|
141
138
|
return lines.join('\n');
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function wrapSdkCall(integrationId: string, className: string, methodName: string, params?: unknown): Promise<unknown>;
|
|
2
1
|
export interface TableClient<T> {
|
|
3
2
|
findAll(options?: {
|
|
4
3
|
limit?: number;
|
|
@@ -15,22 +14,20 @@ export interface TableClient<T> {
|
|
|
15
14
|
filters?: unknown;
|
|
16
15
|
filter?: unknown;
|
|
17
16
|
}): Promise<T>;
|
|
18
|
-
create(data: Partial<T>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
update(recordId: string | {
|
|
22
|
-
id: string;
|
|
23
|
-
record?: Partial<T>;
|
|
24
|
-
}, data?: Partial<T> | {
|
|
25
|
-
record: Partial<T>;
|
|
26
|
-
}): Promise<T>;
|
|
27
|
-
delete(recordId: string | {
|
|
28
|
-
id: string;
|
|
29
|
-
}): Promise<{
|
|
17
|
+
create(data: Partial<T>): Promise<T>;
|
|
18
|
+
update(id: string, data: Partial<T>): Promise<T>;
|
|
19
|
+
delete(id: string): Promise<{
|
|
30
20
|
deleted: true;
|
|
31
21
|
}>;
|
|
32
22
|
bulkCreate(records: Partial<T>[]): Promise<T[]>;
|
|
33
23
|
}
|
|
34
24
|
export declare function createTableClient<T>(integrationId: string, className: string): TableClient<T>;
|
|
25
|
+
export declare function createSqlClient(integrationId: string): (params: {
|
|
26
|
+
query?: string;
|
|
27
|
+
sql?: string;
|
|
28
|
+
params?: unknown[];
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
rows: Record<string, unknown>[];
|
|
31
|
+
}>;
|
|
35
32
|
export { createCaller } from '../caller/index.js';
|
|
36
33
|
export type { EndpointConfig } from '../caller/index.js';
|
|
@@ -1,61 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
local: 'http://localhost:2506',
|
|
6
|
-
};
|
|
7
|
-
function getExecutionConfig() {
|
|
8
|
-
return globalThis.__ZITE_EXECUTION_CONFIG__;
|
|
9
|
-
}
|
|
10
|
-
function getRunnerUrl() {
|
|
11
|
-
const config = getExecutionConfig();
|
|
12
|
-
if (config?.workflowRunnerUrl)
|
|
13
|
-
return config.workflowRunnerUrl;
|
|
14
|
-
const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
|
|
15
|
-
return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
16
|
-
}
|
|
17
|
-
function getToken() {
|
|
18
|
-
const config = getExecutionConfig();
|
|
19
|
-
if (config?.token)
|
|
20
|
-
return config.token;
|
|
21
|
-
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
22
|
-
}
|
|
23
|
-
export async function wrapSdkCall(integrationId, className, methodName, params) {
|
|
24
|
-
const mergedParams = { tableId: className, ...params };
|
|
25
|
-
const res = await fetch(`${getRunnerUrl()}/sdk/execute`, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers: {
|
|
28
|
-
Authorization: `Bearer ${getToken()}`,
|
|
29
|
-
'Content-Type': 'application/json',
|
|
30
|
-
},
|
|
31
|
-
body: JSON.stringify({ integrationId, methodName, params: mergedParams }),
|
|
32
|
-
});
|
|
33
|
-
if (!res.ok) {
|
|
34
|
-
const text = await res.text().catch(() => '');
|
|
35
|
-
throw new Error(`SDK call failed (${res.status}): ${text}`);
|
|
1
|
+
function getSdkCall() {
|
|
2
|
+
const fn = globalThis.__wrapSdkCall;
|
|
3
|
+
if (!fn) {
|
|
4
|
+
throw new Error('Zite SDK runtime not initialized. Endpoints must run inside the Zite worker.');
|
|
36
5
|
}
|
|
37
|
-
return
|
|
6
|
+
return fn;
|
|
38
7
|
}
|
|
39
8
|
export function createTableClient(integrationId, className) {
|
|
40
9
|
return {
|
|
41
|
-
findAll: (options) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
return wrapSdkCall(integrationId, className, 'update', {
|
|
49
|
-
id: recordId,
|
|
50
|
-
...(data && 'record' in data ? data.record : data),
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
delete: (recordId) => wrapSdkCall(integrationId, className, 'delete', {
|
|
54
|
-
id: typeof recordId === 'string' ? recordId : recordId.id,
|
|
10
|
+
findAll: (options) => getSdkCall()(integrationId, className, 'findAll', {
|
|
11
|
+
tableId: className,
|
|
12
|
+
...options,
|
|
13
|
+
}),
|
|
14
|
+
findOne: (recordId) => getSdkCall()(integrationId, className, 'findOne', {
|
|
15
|
+
tableId: className,
|
|
16
|
+
...(typeof recordId === 'string' ? { id: recordId } : recordId),
|
|
55
17
|
}),
|
|
56
|
-
|
|
18
|
+
create: (data) => getSdkCall()(integrationId, className, 'create', {
|
|
19
|
+
tableId: className,
|
|
20
|
+
record: data,
|
|
21
|
+
}),
|
|
22
|
+
update: (id, data) => getSdkCall()(integrationId, className, 'update', {
|
|
23
|
+
tableId: className,
|
|
24
|
+
id,
|
|
25
|
+
record: data,
|
|
26
|
+
}),
|
|
27
|
+
delete: (id) => getSdkCall()(integrationId, className, 'delete', {
|
|
28
|
+
tableId: className,
|
|
29
|
+
id,
|
|
30
|
+
}),
|
|
31
|
+
bulkCreate: (records) => getSdkCall()(integrationId, className, 'bulkCreate', {
|
|
32
|
+
tableId: className,
|
|
57
33
|
records,
|
|
58
34
|
}),
|
|
59
35
|
};
|
|
60
36
|
}
|
|
37
|
+
export function createSqlClient(integrationId) {
|
|
38
|
+
return (params) => getSdkCall()(integrationId, 'Db', 'executeSql', params);
|
|
39
|
+
}
|
|
61
40
|
export { createCaller } from '../caller/index.js';
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -53,12 +53,11 @@ export function generateSchema(base) {
|
|
|
53
53
|
export function generateDbTs(base, schema, integrationId = 'databases') {
|
|
54
54
|
const lines = [];
|
|
55
55
|
lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
|
|
56
|
-
lines.push('//
|
|
57
|
-
lines.push('// .
|
|
58
|
-
lines.push('// .
|
|
59
|
-
lines.push('//
|
|
60
|
-
lines.push(
|
|
61
|
-
lines.push("import { createTableClient, wrapSdkCall } from 'zitejs/runtime';");
|
|
56
|
+
lines.push('// Table methods: .findAll(opts?) → { records: T[], total, hasMore }');
|
|
57
|
+
lines.push('// .findOne(id) → T | .create(data) → T | .update(id, data) → T');
|
|
58
|
+
lines.push('// .delete(id) → { deleted: true } | .bulkCreate(records) → T[]');
|
|
59
|
+
lines.push('// Raw SQL: zite.sql({ query: "SELECT..." }) → { rows: Record<string, unknown>[] }');
|
|
60
|
+
lines.push("import { createTableClient, createSqlClient } from 'zitejs/runtime';");
|
|
62
61
|
lines.push('');
|
|
63
62
|
for (const table of base.tables ?? []) {
|
|
64
63
|
const className = toPascalCase(table.name);
|
|
@@ -81,8 +80,7 @@ export function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
81
80
|
const propName = toCamelCase(table.name);
|
|
82
81
|
lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
|
|
83
82
|
}
|
|
84
|
-
lines.push(
|
|
85
|
-
lines.push(" db: { executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }> },");
|
|
83
|
+
lines.push(` sql: createSqlClient('${integrationId}'),`);
|
|
86
84
|
lines.push('};');
|
|
87
85
|
lines.push('');
|
|
88
86
|
return lines.join('\n');
|
|
@@ -90,15 +88,14 @@ export function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
90
88
|
export function generateDbDts(base, schema) {
|
|
91
89
|
const lines = [
|
|
92
90
|
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
93
|
-
'//
|
|
94
|
-
'// See db.ts for the full runtime.',
|
|
91
|
+
'// Type declarations for IDE and LLM context. See db.ts for runtime.',
|
|
95
92
|
'',
|
|
96
93
|
'interface TableClient<T> {',
|
|
97
94
|
' findAll(options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown; filters?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }>;',
|
|
98
95
|
' findOne(recordId: string | { filters?: unknown; filter?: unknown }): Promise<T>;',
|
|
99
|
-
' create(data: Partial<T>
|
|
100
|
-
' update(
|
|
101
|
-
' delete(
|
|
96
|
+
' create(data: Partial<T>): Promise<T>;',
|
|
97
|
+
' update(id: string, data: Partial<T>): Promise<T>;',
|
|
98
|
+
' delete(id: string): Promise<{ deleted: true }>;',
|
|
102
99
|
' bulkCreate(records: Partial<T>[]): Promise<T[]>;',
|
|
103
100
|
'}',
|
|
104
101
|
'',
|
|
@@ -124,7 +121,7 @@ export function generateDbDts(base, schema) {
|
|
|
124
121
|
const propName = toCamelCase(table.name);
|
|
125
122
|
lines.push(` ${propName}: TableClient<${className}RecordType>;`);
|
|
126
123
|
}
|
|
127
|
-
lines.push('
|
|
124
|
+
lines.push(' sql: (params: { query?: string; sql?: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
|
|
128
125
|
lines.push('};');
|
|
129
126
|
lines.push('');
|
|
130
127
|
return lines.join('\n');
|