zitejs 0.9.5 → 0.9.7

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.
@@ -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 tsconfigPath = (0, path_1.join)(appPath, 'tsconfig.json');
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}`, '.');
@@ -44,16 +44,19 @@ async function wrapSdkCall(integrationId, className, methodName, params) {
44
44
  function createTableClient(integrationId, className) {
45
45
  return {
46
46
  findAll: (options) => wrapSdkCall(integrationId, className, 'findAll', options),
47
- findOne: (recordId) => wrapSdkCall(integrationId, className, 'findOne', {
48
- id: recordId,
49
- }),
47
+ findOne: (recordId) => wrapSdkCall(integrationId, className, 'findOne', typeof recordId === 'string' ? { id: recordId } : recordId),
50
48
  create: (data) => wrapSdkCall(integrationId, className, 'create', data),
51
- update: (recordId, data) => wrapSdkCall(integrationId, className, 'update', {
52
- id: recordId,
53
- ...data,
54
- }),
49
+ update: (recordId, data) => {
50
+ if (typeof recordId === 'object') {
51
+ return wrapSdkCall(integrationId, className, 'update', recordId);
52
+ }
53
+ return wrapSdkCall(integrationId, className, 'update', {
54
+ id: recordId,
55
+ ...(data && 'record' in data ? data.record : data),
56
+ });
57
+ },
55
58
  delete: (recordId) => wrapSdkCall(integrationId, className, 'delete', {
56
- id: recordId,
59
+ id: typeof recordId === 'string' ? recordId : recordId.id,
57
60
  }),
58
61
  bulkCreate: (records) => wrapSdkCall(integrationId, className, 'bulkCreate', {
59
62
  records,
@@ -23,7 +23,7 @@ const FIELD_TYPE_MAP = {
23
23
  date: 'string',
24
24
  datetime: 'string',
25
25
  attachments: 'Array<{ url: string; name?: string }>',
26
- linked_record: 'string[]',
26
+ linked_record: 'string | string[]',
27
27
  lookup: 'unknown',
28
28
  autonumber: 'number',
29
29
  source: 'string',
@@ -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
- return FIELD_TYPE_MAP[field.type] ?? 'unknown';
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: {} };
@@ -78,8 +84,8 @@ function generateDbTs(base, schema, integrationId = 'databases') {
78
84
  const propName = toCamelCase(table.name);
79
85
  lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
80
86
  }
81
- lines.push(" executeSql: (params: { query: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }>,");
82
- lines.push(" db: { executeSql: (params: { query: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }> },");
87
+ lines.push(" executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }>,");
88
+ lines.push(" db: { executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }> },");
83
89
  lines.push('};');
84
90
  lines.push('');
85
91
  return lines.join('\n');
@@ -114,7 +120,7 @@ function generateDbDts(base, schema) {
114
120
  const propName = toCamelCase(table.name);
115
121
  lines.push(` ${propName}: TableClient<${className}RecordType>;`);
116
122
  }
117
- lines.push(' executeSql: (params: { query: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
123
+ lines.push(' executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
118
124
  lines.push('};');
119
125
  lines.push('');
120
126
  return lines.join('\n');
@@ -142,6 +148,13 @@ function generateApiTs(endpointFiles, flowId) {
142
148
  lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
143
149
  }
144
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;`);
156
+ }
157
+ lines.push('');
145
158
  // Also export as a single api object
146
159
  lines.push('export const api = {');
147
160
  for (const name of endpointNames) {
@@ -21,6 +21,7 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
21
21
  inputSchema?: SchemaLike<TInput>;
22
22
  outputSchema?: SchemaLike<TOutput>;
23
23
  stream?: boolean;
24
+ authenticated?: boolean;
24
25
  execute: (params: {
25
26
  input: TInput;
26
27
  context: ZiteRequestContext | ZiteScheduledContext;
@@ -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 tsconfigPath = join(appPath, 'tsconfig.json');
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}`, '.');
@@ -5,15 +5,28 @@ 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;
11
12
  hasMore: boolean;
12
13
  }>;
13
- findOne(recordId: string): Promise<T>;
14
- create(data: Partial<T>): Promise<T>;
15
- update(recordId: string, data: Partial<T>): Promise<T>;
16
- delete(recordId: string): Promise<{
14
+ findOne(recordId: string | {
15
+ filters?: unknown;
16
+ filter?: unknown;
17
+ }): Promise<T>;
18
+ create(data: Partial<T> | {
19
+ record: Partial<T>;
20
+ }): Promise<T>;
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
30
  deleted: true;
18
31
  }>;
19
32
  bulkCreate(records: Partial<T>[]): Promise<T[]>;
@@ -39,16 +39,19 @@ export async function wrapSdkCall(integrationId, className, methodName, params)
39
39
  export function createTableClient(integrationId, className) {
40
40
  return {
41
41
  findAll: (options) => wrapSdkCall(integrationId, className, 'findAll', options),
42
- findOne: (recordId) => wrapSdkCall(integrationId, className, 'findOne', {
43
- id: recordId,
44
- }),
42
+ findOne: (recordId) => wrapSdkCall(integrationId, className, 'findOne', typeof recordId === 'string' ? { id: recordId } : recordId),
45
43
  create: (data) => wrapSdkCall(integrationId, className, 'create', data),
46
- update: (recordId, data) => wrapSdkCall(integrationId, className, 'update', {
47
- id: recordId,
48
- ...data,
49
- }),
44
+ update: (recordId, data) => {
45
+ if (typeof recordId === 'object') {
46
+ return wrapSdkCall(integrationId, className, 'update', recordId);
47
+ }
48
+ return wrapSdkCall(integrationId, className, 'update', {
49
+ id: recordId,
50
+ ...(data && 'record' in data ? data.record : data),
51
+ });
52
+ },
50
53
  delete: (recordId) => wrapSdkCall(integrationId, className, 'delete', {
51
- id: recordId,
54
+ id: typeof recordId === 'string' ? recordId : recordId.id,
52
55
  }),
53
56
  bulkCreate: (records) => wrapSdkCall(integrationId, className, 'bulkCreate', {
54
57
  records,
@@ -15,7 +15,7 @@ const FIELD_TYPE_MAP = {
15
15
  date: 'string',
16
16
  datetime: 'string',
17
17
  attachments: 'Array<{ url: string; name?: string }>',
18
- linked_record: 'string[]',
18
+ linked_record: 'string | string[]',
19
19
  lookup: 'unknown',
20
20
  autonumber: 'number',
21
21
  source: 'string',
@@ -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
- return FIELD_TYPE_MAP[field.type] ?? 'unknown';
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: {} };
@@ -70,8 +76,8 @@ export function generateDbTs(base, schema, integrationId = 'databases') {
70
76
  const propName = toCamelCase(table.name);
71
77
  lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
72
78
  }
73
- lines.push(" executeSql: (params: { query: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }>,");
74
- lines.push(" db: { executeSql: (params: { query: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }> },");
79
+ lines.push(" executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }>,");
80
+ lines.push(" db: { executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => wrapSdkCall('databases', 'Db', 'executeSql', params) as Promise<{ rows: Record<string, unknown>[] }> },");
75
81
  lines.push('};');
76
82
  lines.push('');
77
83
  return lines.join('\n');
@@ -106,7 +112,7 @@ export function generateDbDts(base, schema) {
106
112
  const propName = toCamelCase(table.name);
107
113
  lines.push(` ${propName}: TableClient<${className}RecordType>;`);
108
114
  }
109
- lines.push(' executeSql: (params: { query: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
115
+ lines.push(' executeSql: (params: { query?: string; sql?: string; params?: unknown[] }) => Promise<{ rows: Record<string, unknown>[] }>;');
110
116
  lines.push('};');
111
117
  lines.push('');
112
118
  return lines.join('\n');
@@ -134,6 +140,13 @@ export function generateApiTs(endpointFiles, flowId) {
134
140
  lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
135
141
  }
136
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;`);
148
+ }
149
+ lines.push('');
137
150
  // Also export as a single api object
138
151
  lines.push('export const api = {');
139
152
  for (const name of endpointNames) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",