zitejs 0.9.4 → 0.9.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/dist/cjs/caller/index.js +4 -3
- package/dist/cjs/check/index.js +2 -1
- package/dist/cjs/dev/index.js +12 -1
- package/dist/cjs/runtime/index.js +1 -1
- package/dist/cjs/sync/lib.js +17 -3
- package/dist/esm/caller/index.d.ts +1 -1
- package/dist/esm/caller/index.js +4 -3
- package/dist/esm/check/index.js +2 -1
- package/dist/esm/dev/index.js +13 -2
- package/dist/esm/runtime/index.d.ts +4 -1
- package/dist/esm/runtime/index.js +1 -1
- package/dist/esm/sync/lib.d.ts +1 -1
- package/dist/esm/sync/lib.js +17 -3
- package/package.json +1 -1
package/dist/cjs/caller/index.js
CHANGED
|
@@ -24,15 +24,16 @@ function getRunnerUrl() {
|
|
|
24
24
|
function getToken() {
|
|
25
25
|
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
26
26
|
}
|
|
27
|
-
function createCaller(endpoint, name) {
|
|
27
|
+
function createCaller(endpoint, name, flowId) {
|
|
28
28
|
return async (input) => {
|
|
29
|
-
const
|
|
29
|
+
const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
|
|
30
|
+
const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
|
|
30
31
|
method: 'POST',
|
|
31
32
|
headers: {
|
|
32
33
|
Authorization: `Bearer ${getToken()}`,
|
|
33
34
|
'Content-Type': 'application/json',
|
|
34
35
|
},
|
|
35
|
-
body: JSON.stringify(input),
|
|
36
|
+
body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
|
|
36
37
|
});
|
|
37
38
|
if (!res.ok) {
|
|
38
39
|
const text = await res.text().catch(() => '');
|
package/dist/cjs/check/index.js
CHANGED
|
@@ -36,7 +36,8 @@ async function runCheck() {
|
|
|
36
36
|
for (const app of appDirs) {
|
|
37
37
|
const appPath = (0, path_1.join)('apps', app);
|
|
38
38
|
console.log(`\n── ${app} ──`);
|
|
39
|
-
const
|
|
39
|
+
const tsconfigAppPath = (0, path_1.join)(appPath, 'tsconfig.app.json');
|
|
40
|
+
const tsconfigPath = (0, fs_1.existsSync)(tsconfigAppPath) ? tsconfigAppPath : (0, path_1.join)(appPath, 'tsconfig.json');
|
|
40
41
|
if ((0, fs_1.existsSync)(tsconfigPath)) {
|
|
41
42
|
process.stdout.write(' tsc --noEmit ... ');
|
|
42
43
|
const tsc = run(`npx tsc --noEmit -p ${tsconfigPath}`, '.');
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -21,12 +21,23 @@ function findAppDirs() {
|
|
|
21
21
|
.filter(d => d.isDirectory())
|
|
22
22
|
.map(d => d.name);
|
|
23
23
|
}
|
|
24
|
+
function getFlowId(appDir) {
|
|
25
|
+
try {
|
|
26
|
+
const configPath = (0, path_1.join)('apps', appDir, 'zite.config.json');
|
|
27
|
+
if ((0, fs_2.existsSync)(configPath)) {
|
|
28
|
+
const config = JSON.parse((0, fs_2.readFileSync)(configPath, 'utf-8'));
|
|
29
|
+
return config.id;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
24
35
|
function regenerateAppApiTs(appDir) {
|
|
25
36
|
const apiDir = (0, path_1.join)('apps', appDir, 'src', 'api');
|
|
26
37
|
if (!(0, fs_2.existsSync)(apiDir))
|
|
27
38
|
return;
|
|
28
39
|
const endpointFiles = (0, fs_2.readdirSync)(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
|
|
29
|
-
const content = (0, lib_js_1.generateApiTs)(endpointFiles);
|
|
40
|
+
const content = (0, lib_js_1.generateApiTs)(endpointFiles, getFlowId(appDir));
|
|
30
41
|
if (content) {
|
|
31
42
|
const outDir = (0, path_1.join)('apps', appDir, '.zite');
|
|
32
43
|
(0, fs_2.mkdirSync)(outDir, { recursive: true });
|
|
@@ -53,7 +53,7 @@ function createTableClient(integrationId, className) {
|
|
|
53
53
|
...data,
|
|
54
54
|
}),
|
|
55
55
|
delete: (recordId) => wrapSdkCall(integrationId, className, 'delete', {
|
|
56
|
-
id: recordId,
|
|
56
|
+
id: typeof recordId === 'string' ? recordId : recordId.id,
|
|
57
57
|
}),
|
|
58
58
|
bulkCreate: (records) => wrapSdkCall(integrationId, className, 'bulkCreate', {
|
|
59
59
|
records,
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -38,7 +38,13 @@ function toCamelCase(name) {
|
|
|
38
38
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
39
39
|
}
|
|
40
40
|
function tsTypeForField(field) {
|
|
41
|
-
|
|
41
|
+
if (FIELD_TYPE_MAP[field.type])
|
|
42
|
+
return FIELD_TYPE_MAP[field.type];
|
|
43
|
+
const lowerName = field.name?.toLowerCase() ?? '';
|
|
44
|
+
if (lowerName === 'createdat' || lowerName === 'created_at' || lowerName === 'updatedat' || lowerName === 'updated_at') {
|
|
45
|
+
return 'string';
|
|
46
|
+
}
|
|
47
|
+
return 'string';
|
|
42
48
|
}
|
|
43
49
|
function generateSchema(base) {
|
|
44
50
|
const schema = { tables: {} };
|
|
@@ -119,7 +125,7 @@ function generateDbDts(base, schema) {
|
|
|
119
125
|
lines.push('');
|
|
120
126
|
return lines.join('\n');
|
|
121
127
|
}
|
|
122
|
-
function generateApiTs(endpointFiles) {
|
|
128
|
+
function generateApiTs(endpointFiles, flowId) {
|
|
123
129
|
if (!endpointFiles || endpointFiles.length === 0)
|
|
124
130
|
return null;
|
|
125
131
|
const lines = [
|
|
@@ -135,10 +141,18 @@ function generateApiTs(endpointFiles) {
|
|
|
135
141
|
lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
|
|
136
142
|
endpointNames.push(camelName);
|
|
137
143
|
}
|
|
144
|
+
const flowIdArg = flowId ? `, '${flowId}'` : '';
|
|
138
145
|
lines.push('');
|
|
139
146
|
// Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
|
|
140
147
|
for (const name of endpointNames) {
|
|
141
|
-
lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
|
|
148
|
+
lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
|
|
149
|
+
}
|
|
150
|
+
lines.push('');
|
|
151
|
+
// Inferred input/output types per endpoint (e.g. GetDashboardInputType, GetDashboardOutputType)
|
|
152
|
+
for (const name of endpointNames) {
|
|
153
|
+
const pascal = toPascalCase(name);
|
|
154
|
+
lines.push(`export type ${pascal}InputType = typeof ${name}Endpoint extends { inputSchema: { _output: infer T } } ? T : unknown;`);
|
|
155
|
+
lines.push(`export type ${pascal}OutputType = typeof ${name}Endpoint extends { outputSchema: { _output: infer T } } ? T : unknown;`);
|
|
142
156
|
}
|
|
143
157
|
lines.push('');
|
|
144
158
|
// Also export as a single api object
|
|
@@ -4,4 +4,4 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
|
4
4
|
context: unknown;
|
|
5
5
|
}) => Promise<TOutput> | TOutput;
|
|
6
6
|
}
|
|
7
|
-
export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string): (input: TInput) => Promise<TOutput>;
|
|
7
|
+
export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
package/dist/esm/caller/index.js
CHANGED
|
@@ -21,15 +21,16 @@ function getRunnerUrl() {
|
|
|
21
21
|
function getToken() {
|
|
22
22
|
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
23
23
|
}
|
|
24
|
-
export function createCaller(endpoint, name) {
|
|
24
|
+
export function createCaller(endpoint, name, flowId) {
|
|
25
25
|
return async (input) => {
|
|
26
|
-
const
|
|
26
|
+
const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
|
|
27
|
+
const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
|
|
27
28
|
method: 'POST',
|
|
28
29
|
headers: {
|
|
29
30
|
Authorization: `Bearer ${getToken()}`,
|
|
30
31
|
'Content-Type': 'application/json',
|
|
31
32
|
},
|
|
32
|
-
body: JSON.stringify(input),
|
|
33
|
+
body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
|
|
33
34
|
});
|
|
34
35
|
if (!res.ok) {
|
|
35
36
|
const text = await res.text().catch(() => '');
|
package/dist/esm/check/index.js
CHANGED
|
@@ -33,7 +33,8 @@ export async function runCheck() {
|
|
|
33
33
|
for (const app of appDirs) {
|
|
34
34
|
const appPath = join('apps', app);
|
|
35
35
|
console.log(`\n── ${app} ──`);
|
|
36
|
-
const
|
|
36
|
+
const tsconfigAppPath = join(appPath, 'tsconfig.app.json');
|
|
37
|
+
const tsconfigPath = existsSync(tsconfigAppPath) ? tsconfigAppPath : join(appPath, 'tsconfig.json');
|
|
37
38
|
if (existsSync(tsconfigPath)) {
|
|
38
39
|
process.stdout.write(' tsc --noEmit ... ');
|
|
39
40
|
const tsc = run(`npx tsc --noEmit -p ${tsconfigPath}`, '.');
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { watch } from 'fs';
|
|
2
|
-
import { existsSync, readdirSync, writeFileSync, mkdirSync, } from 'fs';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, } from 'fs';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { runSync } from '../sync/index.js';
|
|
5
5
|
import { generateApiTs } from '../sync/lib.js';
|
|
@@ -18,12 +18,23 @@ function findAppDirs() {
|
|
|
18
18
|
.filter(d => d.isDirectory())
|
|
19
19
|
.map(d => d.name);
|
|
20
20
|
}
|
|
21
|
+
function getFlowId(appDir) {
|
|
22
|
+
try {
|
|
23
|
+
const configPath = join('apps', appDir, 'zite.config.json');
|
|
24
|
+
if (existsSync(configPath)) {
|
|
25
|
+
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
26
|
+
return config.id;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch { }
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
21
32
|
function regenerateAppApiTs(appDir) {
|
|
22
33
|
const apiDir = join('apps', appDir, 'src', 'api');
|
|
23
34
|
if (!existsSync(apiDir))
|
|
24
35
|
return;
|
|
25
36
|
const endpointFiles = readdirSync(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
|
|
26
|
-
const content = generateApiTs(endpointFiles);
|
|
37
|
+
const content = generateApiTs(endpointFiles, getFlowId(appDir));
|
|
27
38
|
if (content) {
|
|
28
39
|
const outDir = join('apps', appDir, '.zite');
|
|
29
40
|
mkdirSync(outDir, { recursive: true });
|
|
@@ -5,6 +5,7 @@ export interface TableClient<T> {
|
|
|
5
5
|
offset?: number;
|
|
6
6
|
sort?: unknown[];
|
|
7
7
|
filter?: unknown;
|
|
8
|
+
filters?: unknown;
|
|
8
9
|
}): Promise<{
|
|
9
10
|
records: T[];
|
|
10
11
|
total: number;
|
|
@@ -13,7 +14,9 @@ export interface TableClient<T> {
|
|
|
13
14
|
findOne(recordId: string): Promise<T>;
|
|
14
15
|
create(data: Partial<T>): Promise<T>;
|
|
15
16
|
update(recordId: string, data: Partial<T>): Promise<T>;
|
|
16
|
-
delete(recordId: string
|
|
17
|
+
delete(recordId: string | {
|
|
18
|
+
id: string;
|
|
19
|
+
}): Promise<{
|
|
17
20
|
deleted: true;
|
|
18
21
|
}>;
|
|
19
22
|
bulkCreate(records: Partial<T>[]): Promise<T[]>;
|
|
@@ -48,7 +48,7 @@ export function createTableClient(integrationId, className) {
|
|
|
48
48
|
...data,
|
|
49
49
|
}),
|
|
50
50
|
delete: (recordId) => wrapSdkCall(integrationId, className, 'delete', {
|
|
51
|
-
id: recordId,
|
|
51
|
+
id: typeof recordId === 'string' ? recordId : recordId.id,
|
|
52
52
|
}),
|
|
53
53
|
bulkCreate: (records) => wrapSdkCall(integrationId, className, 'bulkCreate', {
|
|
54
54
|
records,
|
package/dist/esm/sync/lib.d.ts
CHANGED
|
@@ -22,4 +22,4 @@ export declare function toCamelCase(name: string): string;
|
|
|
22
22
|
export declare function generateSchema(base: BaseMetadata): ZiteSchema;
|
|
23
23
|
export declare function generateDbTs(base: BaseMetadata, schema: ZiteSchema, integrationId?: string): string;
|
|
24
24
|
export declare function generateDbDts(base: BaseMetadata, schema: ZiteSchema): string;
|
|
25
|
-
export declare function generateApiTs(endpointFiles: string[]): string | null;
|
|
25
|
+
export declare function generateApiTs(endpointFiles: string[], flowId?: string): string | null;
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -30,7 +30,13 @@ export function toCamelCase(name) {
|
|
|
30
30
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
31
31
|
}
|
|
32
32
|
function tsTypeForField(field) {
|
|
33
|
-
|
|
33
|
+
if (FIELD_TYPE_MAP[field.type])
|
|
34
|
+
return FIELD_TYPE_MAP[field.type];
|
|
35
|
+
const lowerName = field.name?.toLowerCase() ?? '';
|
|
36
|
+
if (lowerName === 'createdat' || lowerName === 'created_at' || lowerName === 'updatedat' || lowerName === 'updated_at') {
|
|
37
|
+
return 'string';
|
|
38
|
+
}
|
|
39
|
+
return 'string';
|
|
34
40
|
}
|
|
35
41
|
export function generateSchema(base) {
|
|
36
42
|
const schema = { tables: {} };
|
|
@@ -111,7 +117,7 @@ export function generateDbDts(base, schema) {
|
|
|
111
117
|
lines.push('');
|
|
112
118
|
return lines.join('\n');
|
|
113
119
|
}
|
|
114
|
-
export function generateApiTs(endpointFiles) {
|
|
120
|
+
export function generateApiTs(endpointFiles, flowId) {
|
|
115
121
|
if (!endpointFiles || endpointFiles.length === 0)
|
|
116
122
|
return null;
|
|
117
123
|
const lines = [
|
|
@@ -127,10 +133,18 @@ export function generateApiTs(endpointFiles) {
|
|
|
127
133
|
lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
|
|
128
134
|
endpointNames.push(camelName);
|
|
129
135
|
}
|
|
136
|
+
const flowIdArg = flowId ? `, '${flowId}'` : '';
|
|
130
137
|
lines.push('');
|
|
131
138
|
// Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
|
|
132
139
|
for (const name of endpointNames) {
|
|
133
|
-
lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
|
|
140
|
+
lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
|
|
141
|
+
}
|
|
142
|
+
lines.push('');
|
|
143
|
+
// Inferred input/output types per endpoint (e.g. GetDashboardInputType, GetDashboardOutputType)
|
|
144
|
+
for (const name of endpointNames) {
|
|
145
|
+
const pascal = toPascalCase(name);
|
|
146
|
+
lines.push(`export type ${pascal}InputType = typeof ${name}Endpoint extends { inputSchema: { _output: infer T } } ? T : unknown;`);
|
|
147
|
+
lines.push(`export type ${pascal}OutputType = typeof ${name}Endpoint extends { outputSchema: { _output: infer T } } ? T : unknown;`);
|
|
134
148
|
}
|
|
135
149
|
lines.push('');
|
|
136
150
|
// Also export as a single api object
|