zitejs 0.9.25 → 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 +16 -7
- package/dist/esm/runtime/index.d.ts +10 -13
- package/dist/esm/runtime/index.js +30 -51
- package/dist/esm/sync/lib.js +16 -7
- 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,7 +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(
|
|
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';");
|
|
68
72
|
lines.push('');
|
|
69
73
|
for (const table of base.tables ?? []) {
|
|
70
74
|
const className = toPascalCase(table.name);
|
|
@@ -87,8 +91,7 @@ function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
87
91
|
const propName = toCamelCase(table.name);
|
|
88
92
|
lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
|
|
89
93
|
}
|
|
90
|
-
lines.push(
|
|
91
|
-
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}'),`);
|
|
92
95
|
lines.push('};');
|
|
93
96
|
lines.push('');
|
|
94
97
|
return lines.join('\n');
|
|
@@ -96,10 +99,16 @@ function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
96
99
|
function generateDbDts(base, schema) {
|
|
97
100
|
const lines = [
|
|
98
101
|
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
99
|
-
'//
|
|
100
|
-
'// See db.ts for the full runtime.',
|
|
102
|
+
'// Type declarations for IDE and LLM context. See db.ts for runtime.',
|
|
101
103
|
'',
|
|
102
|
-
|
|
104
|
+
'interface TableClient<T> {',
|
|
105
|
+
' findAll(options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown; filters?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }>;',
|
|
106
|
+
' findOne(recordId: string | { filters?: unknown; filter?: unknown }): Promise<T>;',
|
|
107
|
+
' create(data: Partial<T>): Promise<T>;',
|
|
108
|
+
' update(id: string, data: Partial<T>): Promise<T>;',
|
|
109
|
+
' delete(id: string): Promise<{ deleted: true }>;',
|
|
110
|
+
' bulkCreate(records: Partial<T>[]): Promise<T[]>;',
|
|
111
|
+
'}',
|
|
103
112
|
'',
|
|
104
113
|
];
|
|
105
114
|
for (const table of base.tables ?? []) {
|
|
@@ -123,7 +132,7 @@ function generateDbDts(base, schema) {
|
|
|
123
132
|
const propName = toCamelCase(table.name);
|
|
124
133
|
lines.push(` ${propName}: TableClient<${className}RecordType>;`);
|
|
125
134
|
}
|
|
126
|
-
lines.push('
|
|
135
|
+
lines.push(' sql: (params: { query?: string; sql?: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
|
|
127
136
|
lines.push('};');
|
|
128
137
|
lines.push('');
|
|
129
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,7 +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(
|
|
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';");
|
|
57
61
|
lines.push('');
|
|
58
62
|
for (const table of base.tables ?? []) {
|
|
59
63
|
const className = toPascalCase(table.name);
|
|
@@ -76,8 +80,7 @@ export function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
76
80
|
const propName = toCamelCase(table.name);
|
|
77
81
|
lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
|
|
78
82
|
}
|
|
79
|
-
lines.push(
|
|
80
|
-
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}'),`);
|
|
81
84
|
lines.push('};');
|
|
82
85
|
lines.push('');
|
|
83
86
|
return lines.join('\n');
|
|
@@ -85,10 +88,16 @@ export function generateDbTs(base, schema, integrationId = 'databases') {
|
|
|
85
88
|
export function generateDbDts(base, schema) {
|
|
86
89
|
const lines = [
|
|
87
90
|
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
88
|
-
'//
|
|
89
|
-
'// See db.ts for the full runtime.',
|
|
91
|
+
'// Type declarations for IDE and LLM context. See db.ts for runtime.',
|
|
90
92
|
'',
|
|
91
|
-
|
|
93
|
+
'interface TableClient<T> {',
|
|
94
|
+
' findAll(options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown; filters?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }>;',
|
|
95
|
+
' findOne(recordId: string | { filters?: unknown; filter?: unknown }): Promise<T>;',
|
|
96
|
+
' create(data: Partial<T>): Promise<T>;',
|
|
97
|
+
' update(id: string, data: Partial<T>): Promise<T>;',
|
|
98
|
+
' delete(id: string): Promise<{ deleted: true }>;',
|
|
99
|
+
' bulkCreate(records: Partial<T>[]): Promise<T[]>;',
|
|
100
|
+
'}',
|
|
92
101
|
'',
|
|
93
102
|
];
|
|
94
103
|
for (const table of base.tables ?? []) {
|
|
@@ -112,7 +121,7 @@ export function generateDbDts(base, schema) {
|
|
|
112
121
|
const propName = toCamelCase(table.name);
|
|
113
122
|
lines.push(` ${propName}: TableClient<${className}RecordType>;`);
|
|
114
123
|
}
|
|
115
|
-
lines.push('
|
|
124
|
+
lines.push(' sql: (params: { query?: string; sql?: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
|
|
116
125
|
lines.push('};');
|
|
117
126
|
lines.push('');
|
|
118
127
|
return lines.join('\n');
|