zitejs 0.4.0 → 0.5.1
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/api/index.js +22 -0
- package/dist/cjs/auth/index.js +10 -0
- package/dist/cjs/backend/index.js +16 -0
- package/dist/cjs/db/index.js +8 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pdf/index.js +9 -0
- package/dist/cjs/schedules/index.js +15 -0
- package/dist/cjs/sync/index.js +65 -0
- package/dist/cjs/sync/lib.js +189 -0
- package/dist/cjs/upload/index.js +6 -0
- package/dist/esm/api/index.d.ts +4 -0
- package/dist/esm/api/index.d.ts.map +1 -0
- package/dist/esm/api/index.js +20 -0
- package/dist/esm/api/index.js.map +1 -0
- package/dist/esm/auth/index.d.ts +14 -0
- package/dist/esm/auth/index.d.ts.map +1 -0
- package/dist/esm/auth/index.js +7 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/backend/index.d.ts +27 -0
- package/dist/esm/backend/index.d.ts.map +1 -0
- package/dist/esm/backend/index.js +12 -0
- package/dist/esm/backend/index.js.map +1 -0
- package/dist/esm/db/index.d.ts +17 -0
- package/dist/esm/db/index.d.ts.map +1 -0
- package/dist/esm/db/index.js +6 -0
- package/dist/esm/db/index.js.map +1 -0
- package/dist/esm/pdf/index.d.ts +10 -0
- package/dist/esm/pdf/index.d.ts.map +1 -0
- package/dist/esm/pdf/index.js +6 -0
- package/dist/esm/pdf/index.js.map +1 -0
- package/dist/esm/schedules/index.d.ts +17 -0
- package/dist/esm/schedules/index.d.ts.map +1 -0
- package/dist/esm/schedules/index.js +12 -0
- package/dist/esm/schedules/index.js.map +1 -0
- package/dist/esm/sync/index.d.ts +3 -0
- package/dist/esm/sync/index.d.ts.map +1 -0
- package/dist/esm/sync/index.js +64 -0
- package/dist/esm/sync/index.js.map +1 -0
- package/dist/esm/sync/lib.d.ts +26 -0
- package/dist/esm/sync/lib.d.ts.map +1 -0
- package/dist/esm/sync/lib.js +182 -0
- package/dist/esm/sync/lib.js.map +1 -0
- package/dist/esm/upload/index.d.ts +7 -0
- package/dist/esm/upload/index.d.ts.map +1 -0
- package/dist/esm/upload/index.js +4 -0
- package/dist/esm/upload/index.js.map +1 -0
- package/package.json +39 -25
- package/api/index.d.ts +0 -21
- package/api/index.js +0 -22
- package/auth/index.d.ts +0 -23
- package/auth/index.js +0 -8
- package/backend/index.d.ts +0 -39
- package/backend/index.js +0 -13
- package/db/index.d.ts +0 -34
- package/db/index.js +0 -23
- package/pdf/index.d.ts +0 -15
- package/pdf/index.js +0 -6
- package/schedules/index.d.ts +0 -19
- package/schedules/index.js +0 -12
- package/sync/index.js +0 -87
- package/sync/lib.js +0 -173
- package/upload/index.d.ts +0 -11
- package/upload/index.js +0 -4
package/sync/index.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* zitejs sync — CLI entry point.
|
|
5
|
-
* Fetches database schema, generates .zite/db.ts and .zite/api.ts.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* ZITE_DB_TOKEN=sk_prod_... npx zitejs sync
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync } from 'fs';
|
|
12
|
-
import { join, dirname } from 'path';
|
|
13
|
-
import { generateSchema, generateDbTs, generateApiTs } from './lib.js';
|
|
14
|
-
|
|
15
|
-
const BASE_URL =
|
|
16
|
-
process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';
|
|
17
|
-
const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
|
|
18
|
-
|
|
19
|
-
async function fetchBaseMetadata(baseId) {
|
|
20
|
-
const url = `${BASE_URL}/bases/${encodeURIComponent(baseId)}`;
|
|
21
|
-
const res = await fetch(url, {
|
|
22
|
-
headers: { Authorization: `Bearer ${TOKEN}` },
|
|
23
|
-
});
|
|
24
|
-
if (!res.ok) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
`Failed to fetch base metadata (${res.status}): ${await res.text()}`,
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return res.json();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function main() {
|
|
33
|
-
if (!TOKEN) {
|
|
34
|
-
console.error('Error: ZITE_DB_TOKEN is required.');
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let baseId = process.env.ZITE_BASE_ID;
|
|
39
|
-
if (!baseId) {
|
|
40
|
-
try {
|
|
41
|
-
const config = JSON.parse(readFileSync('zite.config.json', 'utf-8'));
|
|
42
|
-
baseId = config.project?.basePublicIdentifier;
|
|
43
|
-
} catch { /* ignore */ }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!baseId) {
|
|
47
|
-
console.error('Error: Could not determine base ID.');
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(`Syncing database ${baseId}...`);
|
|
52
|
-
|
|
53
|
-
const base = await fetchBaseMetadata(baseId);
|
|
54
|
-
console.log(`Found ${base.tables?.length ?? 0} tables`);
|
|
55
|
-
|
|
56
|
-
const schema = generateSchema(base);
|
|
57
|
-
|
|
58
|
-
writeFileSync('zite.schema.json', JSON.stringify(schema, null, 2));
|
|
59
|
-
console.log('Wrote zite.schema.json');
|
|
60
|
-
|
|
61
|
-
const dbTs = generateDbTs(base, schema, baseId);
|
|
62
|
-
const dbPath = join('.zite', 'db.ts');
|
|
63
|
-
mkdirSync(dirname(dbPath), { recursive: true });
|
|
64
|
-
writeFileSync(dbPath, dbTs);
|
|
65
|
-
console.log(`Wrote ${dbPath}`);
|
|
66
|
-
|
|
67
|
-
// Generate .zite/api.ts from src/api/*.ts
|
|
68
|
-
const apiDir = join('src', 'api');
|
|
69
|
-
if (existsSync(apiDir)) {
|
|
70
|
-
const endpointFiles = readdirSync(apiDir).filter(
|
|
71
|
-
f => f.endsWith('.ts') || f.endsWith('.js'),
|
|
72
|
-
);
|
|
73
|
-
const apiTs = generateApiTs(endpointFiles);
|
|
74
|
-
if (apiTs) {
|
|
75
|
-
const apiPath = join('.zite', 'api.ts');
|
|
76
|
-
writeFileSync(apiPath, apiTs);
|
|
77
|
-
console.log(`Wrote ${apiPath}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log('Done!');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
main().catch(err => {
|
|
85
|
-
console.error('Sync failed:', err.message);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
});
|
package/sync/lib.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* zitejs/sync — pure generator functions.
|
|
3
|
-
*
|
|
4
|
-
* These can be imported as a library (by our backend) or used by the
|
|
5
|
-
* CLI entry point. No fs/network dependencies — just string generation.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Field type → TypeScript type mapping
|
|
9
|
-
const FIELD_TYPE_MAP = {
|
|
10
|
-
single_line_text: 'string',
|
|
11
|
-
long_text: 'string',
|
|
12
|
-
email: 'string',
|
|
13
|
-
url: 'string',
|
|
14
|
-
phone_number: 'string',
|
|
15
|
-
number: 'number',
|
|
16
|
-
currency: 'number',
|
|
17
|
-
percent: 'number',
|
|
18
|
-
rating: 'number',
|
|
19
|
-
duration: 'number',
|
|
20
|
-
single_select: 'string',
|
|
21
|
-
multiple_select: 'string[]',
|
|
22
|
-
checkbox: 'boolean',
|
|
23
|
-
date: 'string',
|
|
24
|
-
datetime: 'string',
|
|
25
|
-
attachments: 'Array<{ url: string; name?: string }>',
|
|
26
|
-
linked_record: 'string[]',
|
|
27
|
-
lookup: 'unknown',
|
|
28
|
-
autonumber: 'number',
|
|
29
|
-
source: 'string',
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export function toPascalCase(name) {
|
|
33
|
-
return name
|
|
34
|
-
.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase())
|
|
35
|
-
.replace(/^(.)/, (_, c) => c.toUpperCase());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function toCamelCase(name) {
|
|
39
|
-
const pascal = toPascalCase(name);
|
|
40
|
-
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function tsTypeForField(field) {
|
|
44
|
-
return FIELD_TYPE_MAP[field.type] ?? 'unknown';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Generate zite.schema.json content from base metadata.
|
|
49
|
-
*/
|
|
50
|
-
export function generateSchema(base) {
|
|
51
|
-
const schema = { tables: {} };
|
|
52
|
-
for (const table of base.tables ?? []) {
|
|
53
|
-
const tableName = toCamelCase(table.name);
|
|
54
|
-
const fields = {};
|
|
55
|
-
for (const field of table.fields ?? []) {
|
|
56
|
-
fields[toCamelCase(field.name)] = { id: field.id };
|
|
57
|
-
}
|
|
58
|
-
schema.tables[tableName] = { id: table.id, fields };
|
|
59
|
-
}
|
|
60
|
-
return schema;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Generate .zite/db.ts content from base metadata + schema.
|
|
65
|
-
*/
|
|
66
|
-
export function generateDbTs(base, schema, baseId) {
|
|
67
|
-
const lines = [];
|
|
68
|
-
|
|
69
|
-
lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
|
|
70
|
-
lines.push('');
|
|
71
|
-
lines.push(`const BASE_URL = process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';`);
|
|
72
|
-
lines.push(`const TOKEN = process.env.ZITE_DB_TOKEN ?? '';`);
|
|
73
|
-
lines.push('');
|
|
74
|
-
lines.push('async function dbFetch(method: string, path: string, body?: unknown) {');
|
|
75
|
-
lines.push(' const res = await fetch(BASE_URL + path, {');
|
|
76
|
-
lines.push(' method,');
|
|
77
|
-
lines.push(' headers: {');
|
|
78
|
-
lines.push(' Authorization: `Bearer ${TOKEN}`,');
|
|
79
|
-
lines.push(" ...(body ? { 'Content-Type': 'application/json' } : {}),");
|
|
80
|
-
lines.push(' },');
|
|
81
|
-
lines.push(' body: body ? JSON.stringify(body) : undefined,');
|
|
82
|
-
lines.push(' });');
|
|
83
|
-
lines.push(' if (!res.ok) {');
|
|
84
|
-
lines.push(" const text = await res.text().catch(() => '');");
|
|
85
|
-
lines.push(' throw new Error(`Zite DB request failed (${res.status}): ${text}`);');
|
|
86
|
-
lines.push(' }');
|
|
87
|
-
lines.push(' return res.json();');
|
|
88
|
-
lines.push('}');
|
|
89
|
-
lines.push('');
|
|
90
|
-
|
|
91
|
-
for (const table of base.tables ?? []) {
|
|
92
|
-
const className = toPascalCase(table.name);
|
|
93
|
-
const recordType = `${className}RecordType`;
|
|
94
|
-
|
|
95
|
-
lines.push(`export type ${recordType} = {`);
|
|
96
|
-
lines.push(' id: string;');
|
|
97
|
-
for (const field of table.fields ?? []) {
|
|
98
|
-
const fieldName = toCamelCase(field.name);
|
|
99
|
-
const tsType = tsTypeForField(field);
|
|
100
|
-
lines.push(` ${fieldName}: ${tsType};`);
|
|
101
|
-
}
|
|
102
|
-
lines.push(' createdAt: string;');
|
|
103
|
-
lines.push(' updatedAt: string;');
|
|
104
|
-
lines.push('};');
|
|
105
|
-
lines.push('');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
lines.push('function createTableClient<T>(baseId: string, tableId: string) {');
|
|
109
|
-
lines.push(' const base = `/bases/${encodeURIComponent(baseId)}/tables/${encodeURIComponent(tableId)}`;');
|
|
110
|
-
lines.push(' return {');
|
|
111
|
-
lines.push(' findMany: (options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }> =>');
|
|
112
|
-
lines.push(' dbFetch("POST", `${base}/records/list`, options),');
|
|
113
|
-
lines.push(' findOne: (recordId: string): Promise<T> =>');
|
|
114
|
-
lines.push(' dbFetch("GET", `${base}/records/${encodeURIComponent(recordId)}`),');
|
|
115
|
-
lines.push(' create: (data: Partial<T>): Promise<T> =>');
|
|
116
|
-
lines.push(' dbFetch("POST", `${base}/records`, { record: data }),');
|
|
117
|
-
lines.push(' update: (recordId: string, data: Partial<T>): Promise<T> =>');
|
|
118
|
-
lines.push(' dbFetch("PATCH", `${base}/records/${encodeURIComponent(recordId)}`, { record: data }),');
|
|
119
|
-
lines.push(' delete: (recordId: string): Promise<{ deleted: true }> =>');
|
|
120
|
-
lines.push(' dbFetch("DELETE", `${base}/records/${encodeURIComponent(recordId)}`),');
|
|
121
|
-
lines.push(' bulkCreate: (records: Partial<T>[]): Promise<T[]> =>');
|
|
122
|
-
lines.push(' dbFetch("POST", `${base}/records/bulk`, { records }),');
|
|
123
|
-
lines.push(' };');
|
|
124
|
-
lines.push('}');
|
|
125
|
-
lines.push('');
|
|
126
|
-
|
|
127
|
-
lines.push(`const BASE_ID = '${baseId}';`);
|
|
128
|
-
lines.push('');
|
|
129
|
-
lines.push('export const zite = {');
|
|
130
|
-
for (const table of base.tables ?? []) {
|
|
131
|
-
const className = toPascalCase(table.name);
|
|
132
|
-
const propName = toCamelCase(table.name);
|
|
133
|
-
const tableId = schema.tables[propName]?.id ?? table.id;
|
|
134
|
-
lines.push(` ${propName}: createTableClient<${className}RecordType>(BASE_ID, '${tableId}'),`);
|
|
135
|
-
}
|
|
136
|
-
lines.push('};');
|
|
137
|
-
lines.push('');
|
|
138
|
-
|
|
139
|
-
return lines.join('\n');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Generate .zite/api.ts content from a list of endpoint file names.
|
|
144
|
-
* @param endpointFiles — array of filenames like ['deleteRecord.ts', 'getRecords.ts']
|
|
145
|
-
*/
|
|
146
|
-
export function generateApiTs(endpointFiles) {
|
|
147
|
-
if (!endpointFiles || endpointFiles.length === 0) return null;
|
|
148
|
-
|
|
149
|
-
const lines = [
|
|
150
|
-
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
151
|
-
'',
|
|
152
|
-
"import { createCaller } from 'zitejs/api';",
|
|
153
|
-
'',
|
|
154
|
-
];
|
|
155
|
-
|
|
156
|
-
const endpointNames = [];
|
|
157
|
-
for (const file of endpointFiles) {
|
|
158
|
-
const name = file.replace(/\.(ts|js)$/, '');
|
|
159
|
-
const camelName = toCamelCase(name);
|
|
160
|
-
lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
|
|
161
|
-
endpointNames.push(camelName);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
lines.push('');
|
|
165
|
-
lines.push('export const api = {');
|
|
166
|
-
for (const name of endpointNames) {
|
|
167
|
-
lines.push(` ${name}: createCaller(${name}Endpoint),`);
|
|
168
|
-
}
|
|
169
|
-
lines.push('};');
|
|
170
|
-
lines.push('');
|
|
171
|
-
|
|
172
|
-
return lines.join('\n');
|
|
173
|
-
}
|
package/upload/index.d.ts
DELETED
package/upload/index.js
DELETED