zitejs 0.3.0 → 0.5.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.
Files changed (51) hide show
  1. package/dist/api/index.d.ts +4 -0
  2. package/dist/api/index.d.ts.map +1 -0
  3. package/dist/api/index.js +20 -0
  4. package/dist/api/index.js.map +1 -0
  5. package/dist/auth/index.d.ts +14 -0
  6. package/dist/auth/index.d.ts.map +1 -0
  7. package/dist/auth/index.js +7 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/backend/index.d.ts +27 -0
  10. package/dist/backend/index.d.ts.map +1 -0
  11. package/dist/backend/index.js +12 -0
  12. package/dist/backend/index.js.map +1 -0
  13. package/dist/db/index.d.ts +17 -0
  14. package/dist/db/index.d.ts.map +1 -0
  15. package/dist/db/index.js +6 -0
  16. package/dist/db/index.js.map +1 -0
  17. package/dist/pdf/index.d.ts +10 -0
  18. package/dist/pdf/index.d.ts.map +1 -0
  19. package/dist/pdf/index.js +6 -0
  20. package/dist/pdf/index.js.map +1 -0
  21. package/dist/schedules/index.d.ts +17 -0
  22. package/dist/schedules/index.d.ts.map +1 -0
  23. package/dist/schedules/index.js +12 -0
  24. package/dist/schedules/index.js.map +1 -0
  25. package/dist/sync/index.d.ts +3 -0
  26. package/dist/sync/index.d.ts.map +1 -0
  27. package/dist/sync/index.js +64 -0
  28. package/dist/sync/index.js.map +1 -0
  29. package/dist/sync/lib.d.ts +26 -0
  30. package/dist/sync/lib.d.ts.map +1 -0
  31. package/dist/sync/lib.js +182 -0
  32. package/dist/sync/lib.js.map +1 -0
  33. package/dist/upload/index.d.ts +7 -0
  34. package/dist/upload/index.d.ts.map +1 -0
  35. package/dist/upload/index.js +4 -0
  36. package/dist/upload/index.js.map +1 -0
  37. package/package.json +40 -23
  38. package/api/index.d.ts +0 -47
  39. package/api/index.js +0 -34
  40. package/auth/index.d.ts +0 -23
  41. package/auth/index.js +0 -8
  42. package/db/index.d.ts +0 -34
  43. package/db/index.js +0 -23
  44. package/pdf/index.d.ts +0 -15
  45. package/pdf/index.js +0 -6
  46. package/schedules/index.d.ts +0 -19
  47. package/schedules/index.js +0 -12
  48. package/sync/index.js +0 -87
  49. package/sync/lib.js +0 -173
  50. package/upload/index.d.ts +0 -11
  51. package/upload/index.js +0 -4
@@ -0,0 +1,4 @@
1
+ import type { EndpointConfig } from '../backend/index.js';
2
+ export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>): (input: TInput) => Promise<TOutput>;
3
+ export type { EndpointConfig };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK1D,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAC1C,QAAQ,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAgBrC;AAED,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ const BASE_URL = process.env.ZITE_API_URL ?? '';
2
+ const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
3
+ export function createCaller(endpoint) {
4
+ return async (input) => {
5
+ const res = await fetch(BASE_URL + '/api/' + endpoint._name, {
6
+ method: 'POST',
7
+ headers: {
8
+ Authorization: `Bearer ${TOKEN}`,
9
+ 'Content-Type': 'application/json',
10
+ },
11
+ body: JSON.stringify(input),
12
+ });
13
+ if (!res.ok) {
14
+ const text = await res.text().catch(() => '');
15
+ throw new Error(`API call failed (${res.status}): ${text}`);
16
+ }
17
+ return res.json();
18
+ };
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;AAChD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC;AAE9C,MAAM,UAAU,YAAY,CAC1B,QAAyC;IAEzC,OAAO,KAAK,EAAE,KAAa,EAAoB,EAAE;QAC/C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE;YAC3D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,EAAsB,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export interface ZiteUser {
2
+ id: string;
3
+ email?: string;
4
+ name?: string;
5
+ [key: string]: unknown;
6
+ }
7
+ export declare function useAuth(): {
8
+ user: ZiteUser | null;
9
+ isLoading: boolean;
10
+ authLoading: boolean;
11
+ logout: () => void;
12
+ };
13
+ export declare function getCurrentUser(): ZiteUser | null;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,OAAO,IAAI;IACzB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAEA;AAED,wBAAgB,cAAc,IAAI,QAAQ,GAAG,IAAI,CAEhD"}
@@ -0,0 +1,7 @@
1
+ export function useAuth() {
2
+ throw new Error('useAuth() is only available in the Zite runtime.');
3
+ }
4
+ export function getCurrentUser() {
5
+ throw new Error('getCurrentUser() is only available in the Zite runtime.');
6
+ }
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,OAAO;IAMrB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,27 @@
1
+ export interface ZiteRequestContext {
2
+ userId?: string;
3
+ organizationId?: string;
4
+ [key: string]: unknown;
5
+ }
6
+ export interface ZiteScheduledContext extends ZiteRequestContext {
7
+ scheduledAt: string;
8
+ }
9
+ export declare class ZiteError extends Error {
10
+ statusCode: number;
11
+ constructor(message: string, options?: {
12
+ statusCode?: number;
13
+ });
14
+ }
15
+ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
16
+ description?: string;
17
+ inputSchema?: unknown;
18
+ outputSchema?: unknown;
19
+ stream?: boolean;
20
+ _name?: string;
21
+ execute: (params: {
22
+ input: TInput;
23
+ context: ZiteRequestContext | ZiteScheduledContext;
24
+ }) => Promise<TOutput> | TOutput;
25
+ }
26
+ export declare function createEndpoint<TInput = unknown, TOutput = unknown>(config: EndpointConfig<TInput, TOutput>): EndpointConfig<TInput, TOutput>;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,UAAU,EAAE,MAAM,CAAC;gBAEP,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;CAK/D;AAED,MAAM,WAAW,cAAc,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,kBAAkB,GAAG,oBAAoB,CAAC;KACpD,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAClC;AAED,wBAAgB,cAAc,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAChE,MAAM,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GACtC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAEjC"}
@@ -0,0 +1,12 @@
1
+ export class ZiteError extends Error {
2
+ statusCode;
3
+ constructor(message, options) {
4
+ super(message);
5
+ this.name = 'ZiteError';
6
+ this.statusCode = options?.statusCode ?? 500;
7
+ }
8
+ }
9
+ export function createEndpoint(config) {
10
+ return config;
11
+ }
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,UAAU,CAAS;IAEnB,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC;IAC/C,CAAC;CACF;AAcD,MAAM,UAAU,cAAc,CAC5B,MAAuC;IAEvC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare const zite: Record<string, {
2
+ findMany(params?: {
3
+ limit?: number;
4
+ offset?: number;
5
+ sort?: unknown[];
6
+ filter?: unknown;
7
+ }): Promise<{
8
+ records: Record<string, unknown>[];
9
+ hasMore: boolean;
10
+ }>;
11
+ findOne(id: string): Promise<Record<string, unknown>>;
12
+ create(data: Record<string, unknown>): Promise<Record<string, unknown>>;
13
+ update(id: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
14
+ delete(id: string): Promise<void>;
15
+ bulkCreate(items: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
16
+ }>;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAE,MAAM,CACvB,MAAM,EACN;IACE,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACtE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,MAAM,CACJ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,UAAU,CACR,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;CACvC,CAOD,CAAC"}
@@ -0,0 +1,6 @@
1
+ export const zite = new Proxy({}, {
2
+ get() {
3
+ throw new Error('zite.* is a stub — run `npx zitejs sync` to generate the real client.');
4
+ },
5
+ });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAoBb,IAAI,KAAK,CAAC,EAAW,EAAE;IACzB,GAAG;QACD,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare class ZitePdf {
2
+ generate(options: {
3
+ html: string;
4
+ [key: string]: unknown;
5
+ }): Promise<{
6
+ url: string;
7
+ [key: string]: unknown;
8
+ }>;
9
+ }
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pdf/index.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IAClB,QAAQ,CAAC,OAAO,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CAGrD"}
@@ -0,0 +1,6 @@
1
+ export class ZitePdf {
2
+ generate(options) {
3
+ throw new Error('ZitePdf is only available in the Zite runtime.');
4
+ }
5
+ }
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,OAAO;IAClB,QAAQ,CAAC,OAGR;QACC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ export declare class ZiteSchedule {
2
+ static create(config: {
3
+ name: string;
4
+ cron: string;
5
+ endpoint: string;
6
+ input?: Record<string, unknown>;
7
+ }): Promise<{
8
+ id: string;
9
+ }>;
10
+ static delete(id: string): Promise<void>;
11
+ static list(): Promise<Array<{
12
+ id: string;
13
+ name: string;
14
+ cron: string;
15
+ }>>;
16
+ }
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3B,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAG1E"}
@@ -0,0 +1,12 @@
1
+ export class ZiteSchedule {
2
+ static create(config) {
3
+ throw new Error('ZiteSchedule is only available in the Zite runtime.');
4
+ }
5
+ static delete(id) {
6
+ throw new Error('ZiteSchedule is only available in the Zite runtime.');
7
+ }
8
+ static list() {
9
+ throw new Error('ZiteSchedule is only available in the Zite runtime.');
10
+ }
11
+ }
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,MAKb;QACC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,EAAU;QACtB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,IAAI;QACT,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, } from 'fs';
3
+ import { join } from 'path';
4
+ import { generateSchema, generateDbTs, generateDbDts, generateApiTs } from './lib.js';
5
+ const BASE_URL = process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';
6
+ const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
7
+ async function fetchBaseMetadata(baseId) {
8
+ const url = `${BASE_URL}/bases/${encodeURIComponent(baseId)}`;
9
+ const res = await fetch(url, {
10
+ headers: { Authorization: `Bearer ${TOKEN}` },
11
+ });
12
+ if (!res.ok) {
13
+ throw new Error(`Failed to fetch base metadata (${res.status}): ${await res.text()}`);
14
+ }
15
+ return res.json();
16
+ }
17
+ async function main() {
18
+ if (!TOKEN) {
19
+ console.error('Error: ZITE_DB_TOKEN is required.');
20
+ process.exit(1);
21
+ }
22
+ let baseId = process.env.ZITE_BASE_ID;
23
+ if (!baseId) {
24
+ try {
25
+ const config = JSON.parse(readFileSync('zite.config.json', 'utf-8'));
26
+ baseId = config.project?.basePublicIdentifier;
27
+ }
28
+ catch {
29
+ /* ignore */
30
+ }
31
+ }
32
+ if (!baseId) {
33
+ console.error('Error: Could not determine base ID.');
34
+ process.exit(1);
35
+ }
36
+ console.log(`Syncing database ${baseId}...`);
37
+ const base = await fetchBaseMetadata(baseId);
38
+ console.log(`Found ${base.tables?.length ?? 0} tables`);
39
+ const schema = generateSchema(base);
40
+ writeFileSync('zite.schema.json', JSON.stringify(schema, null, 2));
41
+ console.log('Wrote zite.schema.json');
42
+ const dbTs = generateDbTs(base, schema, baseId);
43
+ const dbDts = generateDbDts(base, schema);
44
+ const dotZite = '.zite';
45
+ mkdirSync(dotZite, { recursive: true });
46
+ writeFileSync(join(dotZite, 'db.ts'), dbTs);
47
+ writeFileSync(join(dotZite, 'db.d.ts'), dbDts);
48
+ console.log('Wrote .zite/db.ts + .zite/db.d.ts');
49
+ const apiDir = join('src', 'api');
50
+ if (existsSync(apiDir)) {
51
+ const endpointFiles = readdirSync(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
52
+ const apiTs = generateApiTs(endpointFiles);
53
+ if (apiTs) {
54
+ writeFileSync(join(dotZite, 'api.ts'), apiTs);
55
+ console.log('Wrote .zite/api.ts');
56
+ }
57
+ }
58
+ console.log('Done!');
59
+ }
60
+ main().catch((err) => {
61
+ console.error('Sync failed:', err.message);
62
+ process.exit(1);
63
+ });
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":";AAEA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,IAAI,EAAW,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtF,MAAM,QAAQ,GACZ,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,mCAAmC,CAAC;AACjE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC;AAE9C,KAAK,UAAU,iBAAiB,CAAC,MAAc;IAC7C,MAAM,GAAG,GAAG,GAAG,QAAQ,UAAU,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;IAC9D,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3B,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE;KAC9C,CAAC,CAAC;IACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,kCAAkC,GAAG,CAAC,MAAM,MAAM,MAAM,GA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+1,26 @@
1
+ export type BaseMetadata = {
2
+ tables?: Array<{
3
+ id: string;
4
+ name: string;
5
+ fields?: Array<{
6
+ id: string;
7
+ name: string;
8
+ type: string;
9
+ }>;
10
+ }>;
11
+ };
12
+ export type ZiteSchema = {
13
+ tables: Record<string, {
14
+ id: string;
15
+ fields: Record<string, {
16
+ id: string;
17
+ }>;
18
+ }>;
19
+ };
20
+ export declare function toPascalCase(name: string): string;
21
+ export declare function toCamelCase(name: string): string;
22
+ export declare function generateSchema(base: BaseMetadata): ZiteSchema;
23
+ export declare function generateDbTs(base: BaseMetadata, schema: ZiteSchema, baseId: string): string;
24
+ export declare function generateDbDts(base: BaseMetadata, schema: ZiteSchema): string;
25
+ export declare function generateApiTs(endpointFiles: string[]): string | null;
26
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/sync/lib.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,KAAK,CAAC;YACb,EAAE,EAAE,MAAM,CAAC;YACX,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;SACd,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CACZ,MAAM,EACN;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CACvD,CAAC;CACH,CAAC;AAyBF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD;AAMD,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAW7D;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAoGR;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,UAAU,GACjB,MAAM,CA4CR;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CA2BpE"}
@@ -0,0 +1,182 @@
1
+ const FIELD_TYPE_MAP = {
2
+ single_line_text: 'string',
3
+ long_text: 'string',
4
+ email: 'string',
5
+ url: 'string',
6
+ phone_number: 'string',
7
+ number: 'number',
8
+ currency: 'number',
9
+ percent: 'number',
10
+ rating: 'number',
11
+ duration: 'number',
12
+ single_select: 'string',
13
+ multiple_select: 'string[]',
14
+ checkbox: 'boolean',
15
+ date: 'string',
16
+ datetime: 'string',
17
+ attachments: 'Array<{ url: string; name?: string }>',
18
+ linked_record: 'string[]',
19
+ lookup: 'unknown',
20
+ autonumber: 'number',
21
+ source: 'string',
22
+ };
23
+ export function toPascalCase(name) {
24
+ return name
25
+ .replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase())
26
+ .replace(/^(.)/, (_, c) => c.toUpperCase());
27
+ }
28
+ export function toCamelCase(name) {
29
+ const pascal = toPascalCase(name);
30
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
31
+ }
32
+ function tsTypeForField(field) {
33
+ return FIELD_TYPE_MAP[field.type] ?? 'unknown';
34
+ }
35
+ export function generateSchema(base) {
36
+ const schema = { tables: {} };
37
+ for (const table of base.tables ?? []) {
38
+ const tableName = toCamelCase(table.name);
39
+ const fields = {};
40
+ for (const field of table.fields ?? []) {
41
+ fields[toCamelCase(field.name)] = { id: field.id };
42
+ }
43
+ schema.tables[tableName] = { id: table.id, fields };
44
+ }
45
+ return schema;
46
+ }
47
+ export function generateDbTs(base, schema, baseId) {
48
+ const lines = [];
49
+ lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
50
+ lines.push('');
51
+ lines.push("const BASE_URL = process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';");
52
+ lines.push("const TOKEN = process.env.ZITE_DB_TOKEN ?? '';");
53
+ lines.push('');
54
+ lines.push('async function dbFetch(method: string, path: string, body?: unknown) {');
55
+ lines.push(' const res = await fetch(BASE_URL + path, {');
56
+ lines.push(' method,');
57
+ lines.push(' headers: {');
58
+ lines.push(' Authorization: `Bearer ${TOKEN}`,');
59
+ lines.push(" ...(body ? { 'Content-Type': 'application/json' } : {}),");
60
+ lines.push(' },');
61
+ lines.push(' body: body ? JSON.stringify(body) : undefined,');
62
+ lines.push(' });');
63
+ lines.push(' if (!res.ok) {');
64
+ lines.push(" const text = await res.text().catch(() => '');");
65
+ lines.push(' throw new Error(`Zite DB request failed (${res.status}): ${text}`);');
66
+ lines.push(' }');
67
+ lines.push(' return res.json();');
68
+ lines.push('}');
69
+ lines.push('');
70
+ for (const table of base.tables ?? []) {
71
+ const className = toPascalCase(table.name);
72
+ const recordType = `${className}RecordType`;
73
+ lines.push(`export type ${recordType} = {`);
74
+ lines.push(' id: string;');
75
+ for (const field of table.fields ?? []) {
76
+ const fieldName = toCamelCase(field.name);
77
+ const tsType = tsTypeForField(field);
78
+ lines.push(` ${fieldName}: ${tsType};`);
79
+ }
80
+ lines.push(' createdAt: string;');
81
+ lines.push(' updatedAt: string;');
82
+ lines.push('};');
83
+ lines.push('');
84
+ }
85
+ lines.push('function createTableClient<T>(baseId: string, tableId: string) {');
86
+ lines.push(' const base = `/bases/${encodeURIComponent(baseId)}/tables/${encodeURIComponent(tableId)}`;');
87
+ lines.push(' return {');
88
+ lines.push(' findMany: (options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }> =>');
89
+ lines.push(' dbFetch("POST", `${base}/records/list`, options),');
90
+ lines.push(' findOne: (recordId: string): Promise<T> =>');
91
+ lines.push(' dbFetch("GET", `${base}/records/${encodeURIComponent(recordId)}`),');
92
+ lines.push(' create: (data: Partial<T>): Promise<T> =>');
93
+ lines.push(' dbFetch("POST", `${base}/records`, { record: data }),');
94
+ lines.push(' update: (recordId: string, data: Partial<T>): Promise<T> =>');
95
+ lines.push(' dbFetch("PATCH", `${base}/records/${encodeURIComponent(recordId)}`, { record: data }),');
96
+ lines.push(' delete: (recordId: string): Promise<{ deleted: true }> =>');
97
+ lines.push(' dbFetch("DELETE", `${base}/records/${encodeURIComponent(recordId)}`),');
98
+ lines.push(' bulkCreate: (records: Partial<T>[]): Promise<T[]> =>');
99
+ lines.push(' dbFetch("POST", `${base}/records/bulk`, { records }),');
100
+ lines.push(' };');
101
+ lines.push('}');
102
+ lines.push('');
103
+ lines.push(`const BASE_ID = '${baseId}';`);
104
+ lines.push('');
105
+ lines.push('export const zite = {');
106
+ for (const table of base.tables ?? []) {
107
+ const className = toPascalCase(table.name);
108
+ const propName = toCamelCase(table.name);
109
+ const tableId = schema.tables[propName]?.id ?? table.id;
110
+ lines.push(` ${propName}: createTableClient<${className}RecordType>(BASE_ID, '${tableId}'),`);
111
+ }
112
+ lines.push('};');
113
+ lines.push('');
114
+ return lines.join('\n');
115
+ }
116
+ export function generateDbDts(base, schema) {
117
+ const lines = [
118
+ '// Auto-generated by zitejs sync. Do not edit manually.',
119
+ '// This file contains only type declarations for LLM context.',
120
+ '// See db.ts for the full runtime implementation.',
121
+ '',
122
+ 'interface TableClient<T> {',
123
+ ' findMany(options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }>;',
124
+ ' findOne(recordId: string): Promise<T>;',
125
+ ' create(data: Partial<T>): Promise<T>;',
126
+ ' update(recordId: string, data: Partial<T>): Promise<T>;',
127
+ ' delete(recordId: string): Promise<{ deleted: true }>;',
128
+ ' bulkCreate(records: Partial<T>[]): Promise<T[]>;',
129
+ '}',
130
+ '',
131
+ ];
132
+ for (const table of base.tables ?? []) {
133
+ const className = toPascalCase(table.name);
134
+ const recordType = `${className}RecordType`;
135
+ lines.push(`export type ${recordType} = {`);
136
+ lines.push(' id: string;');
137
+ for (const field of table.fields ?? []) {
138
+ const fieldName = toCamelCase(field.name);
139
+ const tsType = tsTypeForField(field);
140
+ lines.push(` ${fieldName}: ${tsType};`);
141
+ }
142
+ lines.push(' createdAt: string;');
143
+ lines.push(' updatedAt: string;');
144
+ lines.push('};');
145
+ lines.push('');
146
+ }
147
+ lines.push('export declare const zite: {');
148
+ for (const table of base.tables ?? []) {
149
+ const className = toPascalCase(table.name);
150
+ const propName = toCamelCase(table.name);
151
+ lines.push(` ${propName}: TableClient<${className}RecordType>;`);
152
+ }
153
+ lines.push('};');
154
+ lines.push('');
155
+ return lines.join('\n');
156
+ }
157
+ export function generateApiTs(endpointFiles) {
158
+ if (!endpointFiles || endpointFiles.length === 0)
159
+ return null;
160
+ const lines = [
161
+ '// Auto-generated by zitejs sync. Do not edit manually.',
162
+ '',
163
+ "import { createCaller } from 'zitejs/api';",
164
+ '',
165
+ ];
166
+ const endpointNames = [];
167
+ for (const file of endpointFiles) {
168
+ const name = file.replace(/\.(ts|js)$/, '');
169
+ const camelName = toCamelCase(name);
170
+ lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
171
+ endpointNames.push(camelName);
172
+ }
173
+ lines.push('');
174
+ lines.push('export const api = {');
175
+ for (const name of endpointNames) {
176
+ lines.push(` ${name}: createCaller(${name}Endpoint),`);
177
+ }
178
+ lines.push('};');
179
+ lines.push('');
180
+ return lines.join('\n');
181
+ }
182
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/sync/lib.ts"],"names":[],"mappings":"AAmBA,MAAM,cAAc,GAA2B;IAC7C,gBAAgB,EAAE,QAAQ;IAC1B,SAAS,EAAE,QAAQ;IACnB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I,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,kBAAkB,IAAI,YAAY,CAAC,CAAC;IAC1D,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare function useUpload(): {
2
+ upload: (file: File) => Promise<{
3
+ url: string;
4
+ }>;
5
+ isUploading: boolean;
6
+ };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,IAAI;IAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjD,WAAW,EAAE,OAAO,CAAC;CACtB,CAEA"}
@@ -0,0 +1,4 @@
1
+ export function useUpload() {
2
+ throw new Error('useUpload() is only available in the Zite runtime.');
3
+ }
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS;IAIvB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC"}
package/package.json CHANGED
@@ -1,50 +1,67 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "bin": {
7
- "zitejs": "./sync/index.js"
7
+ "zitejs": "./dist/sync/index.js"
8
8
  },
9
9
  "exports": {
10
10
  "./db": {
11
- "types": "./db/index.d.ts",
12
- "default": "./db/index.js"
11
+ "types": "./dist/db/index.d.ts",
12
+ "default": "./dist/db/index.js"
13
13
  },
14
14
  "./api": {
15
- "types": "./api/index.d.ts",
16
- "default": "./api/index.js"
15
+ "types": "./dist/api/index.d.ts",
16
+ "default": "./dist/api/index.js"
17
+ },
18
+ "./backend": {
19
+ "types": "./dist/backend/index.d.ts",
20
+ "default": "./dist/backend/index.js"
17
21
  },
18
22
  "./auth": {
19
- "types": "./auth/index.d.ts",
20
- "default": "./auth/index.js"
23
+ "types": "./dist/auth/index.d.ts",
24
+ "default": "./dist/auth/index.js"
21
25
  },
22
26
  "./upload": {
23
- "types": "./upload/index.d.ts",
24
- "default": "./upload/index.js"
27
+ "types": "./dist/upload/index.d.ts",
28
+ "default": "./dist/upload/index.js"
25
29
  },
26
30
  "./pdf": {
27
- "types": "./pdf/index.d.ts",
28
- "default": "./pdf/index.js"
31
+ "types": "./dist/pdf/index.d.ts",
32
+ "default": "./dist/pdf/index.js"
29
33
  },
30
34
  "./schedules": {
31
- "types": "./schedules/index.d.ts",
32
- "default": "./schedules/index.js"
35
+ "types": "./dist/schedules/index.d.ts",
36
+ "default": "./dist/schedules/index.js"
33
37
  },
34
38
  "./sync": {
35
- "default": "./sync/lib.js"
39
+ "types": "./dist/sync/lib.d.ts",
40
+ "default": "./dist/sync/lib.js"
36
41
  }
37
42
  },
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "typecheck": "tsc --noEmit",
48
+ "prepublishOnly": "npm run build"
49
+ },
38
50
  "files": [
39
- "db",
40
- "api",
41
- "auth",
42
- "upload",
43
- "pdf",
44
- "schedules",
45
- "sync"
51
+ "dist"
52
+ ],
53
+ "devDependencies": {
54
+ "@types/node": "^25.9.1",
55
+ "typescript": "^5.4.0",
56
+ "vitest": "^3.0.0"
57
+ },
58
+ "keywords": [
59
+ "zite",
60
+ "zitejs",
61
+ "framework",
62
+ "database",
63
+ "vibe-coding"
46
64
  ],
47
- "keywords": ["zite", "zitejs", "framework", "database", "vibe-coding"],
48
65
  "license": "MIT",
49
66
  "repository": {
50
67
  "type": "git",
package/api/index.d.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * zitejs/api — Server-side endpoint definition + typed client caller.
3
- *
4
- * Server-side (defining endpoints):
5
- * import { createEndpoint, ZiteError } from 'zitejs/api';
6
- * export default createEndpoint({ ... });
7
- *
8
- * Client-side (generated by zitejs sync into .zite/api.ts):
9
- * import { api } from './.zite/api';
10
- * await api.getRecords({ table: 'contacts' });
11
- */
12
-
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
- export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
29
- description?: string;
30
- inputSchema?: unknown;
31
- outputSchema?: unknown;
32
- stream?: boolean;
33
- _name?: string;
34
- execute: (params: {
35
- input: TInput;
36
- context: ZiteRequestContext | ZiteScheduledContext;
37
- }) => Promise<TOutput> | TOutput;
38
- }
39
-
40
- export declare function createEndpoint<
41
- TInput = unknown,
42
- TOutput = unknown,
43
- >(config: EndpointConfig<TInput, TOutput>): EndpointConfig<TInput, TOutput>;
44
-
45
- export declare function createCaller<TInput, TOutput>(
46
- endpoint: EndpointConfig<TInput, TOutput>,
47
- ): (input: TInput) => Promise<TOutput>;
package/api/index.js DELETED
@@ -1,34 +0,0 @@
1
- // zitejs/api — server-side endpoint definition + client caller factory.
2
-
3
- const BASE_URL = process.env.ZITE_API_URL ?? '';
4
- const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
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
- export function createCaller(endpoint) {
19
- return async (input) => {
20
- const res = await fetch(BASE_URL + '/api/' + endpoint._name, {
21
- method: 'POST',
22
- headers: {
23
- Authorization: `Bearer ${TOKEN}`,
24
- 'Content-Type': 'application/json',
25
- },
26
- body: JSON.stringify(input),
27
- });
28
- if (!res.ok) {
29
- const text = await res.text().catch(() => '');
30
- throw new ZiteError(`API call failed (${res.status}): ${text}`);
31
- }
32
- return res.json();
33
- };
34
- }
package/auth/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * zitejs/auth — Authentication helpers.
3
- *
4
- * Usage:
5
- * import { useAuth } from 'zitejs/auth';
6
- * const { user, isLoading } = useAuth();
7
- */
8
-
9
- export interface ZiteUser {
10
- id: string;
11
- email?: string;
12
- name?: string;
13
- [key: string]: unknown;
14
- }
15
-
16
- export declare function useAuth(): {
17
- user: ZiteUser | null;
18
- isLoading: boolean;
19
- authLoading: boolean;
20
- logout: () => void;
21
- };
22
-
23
- export declare function getCurrentUser(): ZiteUser | null;
package/auth/index.js DELETED
@@ -1,8 +0,0 @@
1
- // zitejs/auth — runtime stub.
2
- export function useAuth() {
3
- return { user: null, isLoading: true, authLoading: true, logout: () => {} };
4
- }
5
-
6
- export function getCurrentUser() {
7
- return null;
8
- }
package/db/index.d.ts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * zitejs/db — The database client.
3
- *
4
- * The `zite` object is generated per-project by `zite sync` and provides
5
- * typed access to your Zite Database tables.
6
- *
7
- * Usage:
8
- * import { zite } from 'zitejs/db';
9
- * const users = await zite.users.findMany();
10
- *
11
- * The actual `zite` object is generated into `.zite/db.ts` in your project.
12
- * This module re-exports it. If you see type errors, run `zite sync` to
13
- * regenerate the client.
14
- */
15
-
16
- export declare const zite: Record<
17
- string,
18
- {
19
- findMany(params?: Record<string, unknown>): Promise<{
20
- records: Record<string, unknown>[];
21
- hasMore: boolean;
22
- }>;
23
- findOne(id: string): Promise<Record<string, unknown>>;
24
- create(data: Record<string, unknown>): Promise<Record<string, unknown>>;
25
- update(
26
- id: string,
27
- data: Record<string, unknown>,
28
- ): Promise<Record<string, unknown>>;
29
- delete(id: string): Promise<void>;
30
- bulkCreate(
31
- items: Record<string, unknown>[],
32
- ): Promise<Record<string, unknown>[]>;
33
- }
34
- >;
package/db/index.js DELETED
@@ -1,23 +0,0 @@
1
- // zitejs/db — runtime stub.
2
- // The actual `zite` object is generated by `zite sync` into .zite/db.ts.
3
- // This stub exists so the package resolves; the generated code overrides it.
4
- export const zite = new Proxy(
5
- {},
6
- {
7
- get(_, tableName) {
8
- const notGenerated = () => {
9
- throw new Error(
10
- `zite.${String(tableName)} is not available. Run \`zite sync\` to generate the database client.`,
11
- );
12
- };
13
- return {
14
- findMany: notGenerated,
15
- findOne: notGenerated,
16
- create: notGenerated,
17
- update: notGenerated,
18
- delete: notGenerated,
19
- bulkCreate: notGenerated,
20
- };
21
- },
22
- },
23
- );
package/pdf/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * zitejs/pdf — PDF generation.
3
- *
4
- * Usage:
5
- * import { ZitePdf } from 'zitejs/pdf';
6
- * const pdf = new ZitePdf();
7
- * const result = await pdf.generate({ html: '<h1>Hello</h1>' });
8
- */
9
-
10
- export declare class ZitePdf {
11
- generate(options: { html: string; [key: string]: unknown }): Promise<{
12
- url: string;
13
- [key: string]: unknown;
14
- }>;
15
- }
package/pdf/index.js DELETED
@@ -1,6 +0,0 @@
1
- // zitejs/pdf — runtime stub.
2
- export class ZitePdf {
3
- async generate() {
4
- throw new Error('ZitePdf is not available outside the Zite sandbox.');
5
- }
6
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * zitejs/schedules — Scheduled task helpers.
3
- *
4
- * Usage:
5
- * import { ZiteSchedule } from 'zitejs/schedules';
6
- */
7
-
8
- export declare class ZiteSchedule {
9
- static create(config: {
10
- name: string;
11
- cron: string;
12
- endpoint: string;
13
- input?: Record<string, unknown>;
14
- }): Promise<{ id: string }>;
15
-
16
- static delete(id: string): Promise<void>;
17
-
18
- static list(): Promise<Array<{ id: string; name: string; cron: string }>>;
19
- }
@@ -1,12 +0,0 @@
1
- // zitejs/schedules — runtime stub.
2
- export class ZiteSchedule {
3
- static async create() {
4
- throw new Error('ZiteSchedule is not available outside the Zite sandbox.');
5
- }
6
- static async delete() {
7
- throw new Error('ZiteSchedule is not available outside the Zite sandbox.');
8
- }
9
- static async list() {
10
- throw new Error('ZiteSchedule is not available outside the Zite sandbox.');
11
- }
12
- }
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
@@ -1,11 +0,0 @@
1
- /**
2
- * zitejs/upload — File upload helpers.
3
- *
4
- * Usage:
5
- * import { useUpload } from 'zitejs/upload';
6
- */
7
-
8
- export declare function useUpload(): {
9
- upload: (file: File) => Promise<{ url: string }>;
10
- isUploading: boolean;
11
- };
package/upload/index.js DELETED
@@ -1,4 +0,0 @@
1
- // zitejs/upload — runtime stub.
2
- export function useUpload() {
3
- return { upload: async () => ({ url: '' }), isUploading: false };
4
- }