zitejs 0.9.9 → 0.9.11
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/sync/lib.js +89 -0
- package/dist/esm/backend/index.d.ts +5 -0
- package/dist/esm/sync/lib.d.ts +6 -0
- package/dist/esm/sync/lib.js +86 -0
- package/package.json +11 -1
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -6,6 +6,9 @@ exports.generateSchema = generateSchema;
|
|
|
6
6
|
exports.generateDbTs = generateDbTs;
|
|
7
7
|
exports.generateDbDts = generateDbDts;
|
|
8
8
|
exports.generateApiTs = generateApiTs;
|
|
9
|
+
exports.generateUserTs = generateUserTs;
|
|
10
|
+
exports.generateAuthWrapperTs = generateAuthWrapperTs;
|
|
11
|
+
exports.generateBackendWrapperTs = generateBackendWrapperTs;
|
|
9
12
|
const FIELD_TYPE_MAP = {
|
|
10
13
|
single_line_text: 'string',
|
|
11
14
|
long_text: 'string',
|
|
@@ -164,3 +167,89 @@ function generateApiTs(endpointFiles, flowId) {
|
|
|
164
167
|
lines.push('');
|
|
165
168
|
return lines.join('\n');
|
|
166
169
|
}
|
|
170
|
+
function generateUserTs(usersTableFields) {
|
|
171
|
+
const lines = [
|
|
172
|
+
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
173
|
+
'',
|
|
174
|
+
];
|
|
175
|
+
if (usersTableFields && usersTableFields.length > 0) {
|
|
176
|
+
lines.push('export type User = {');
|
|
177
|
+
lines.push(' id: string;');
|
|
178
|
+
lines.push(' email: string;');
|
|
179
|
+
for (const field of usersTableFields) {
|
|
180
|
+
if (field.name.toLowerCase() === 'id')
|
|
181
|
+
continue;
|
|
182
|
+
const fieldName = toCamelCase(field.name);
|
|
183
|
+
const tsType = tsTypeForField(field);
|
|
184
|
+
lines.push(` ${fieldName}: ${tsType};`);
|
|
185
|
+
}
|
|
186
|
+
lines.push(' [key: string]: unknown;');
|
|
187
|
+
lines.push('};');
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
lines.push('export type User = {');
|
|
191
|
+
lines.push(' id: string;');
|
|
192
|
+
lines.push(' email: string;');
|
|
193
|
+
lines.push(' firstName?: string;');
|
|
194
|
+
lines.push(' lastName?: string;');
|
|
195
|
+
lines.push(' [key: string]: unknown;');
|
|
196
|
+
lines.push('};');
|
|
197
|
+
}
|
|
198
|
+
lines.push('');
|
|
199
|
+
return lines.join('\n');
|
|
200
|
+
}
|
|
201
|
+
function generateAuthWrapperTs() {
|
|
202
|
+
return [
|
|
203
|
+
'// Auto-generated type-narrowing wrapper. Do not edit manually.',
|
|
204
|
+
'// The real auth logic lives in the zitejs npm package (zitejs/auth).',
|
|
205
|
+
'',
|
|
206
|
+
"import { useAuth as _useAuth } from 'zitejs/auth/base';",
|
|
207
|
+
"import type { User } from './user';",
|
|
208
|
+
'',
|
|
209
|
+
'export type { User };',
|
|
210
|
+
'',
|
|
211
|
+
'export function useAuth() {',
|
|
212
|
+
' return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };',
|
|
213
|
+
'}',
|
|
214
|
+
'',
|
|
215
|
+
].join('\n');
|
|
216
|
+
}
|
|
217
|
+
function generateBackendWrapperTs() {
|
|
218
|
+
return [
|
|
219
|
+
'// Auto-generated type-narrowing wrapper. Do not edit manually.',
|
|
220
|
+
'// Re-exports createEndpoint with context.user typed to the app User.',
|
|
221
|
+
'',
|
|
222
|
+
"import { ZiteError } from 'zitejs/backend/base';",
|
|
223
|
+
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext as _ZiteScheduledContext } from 'zitejs/backend/base';",
|
|
224
|
+
"import type { User } from './user';",
|
|
225
|
+
'',
|
|
226
|
+
'export { ZiteError };',
|
|
227
|
+
'',
|
|
228
|
+
'export interface ZiteRequestContext extends Omit<_ZiteRequestContext, "user"> {',
|
|
229
|
+
' user: User;',
|
|
230
|
+
'}',
|
|
231
|
+
'',
|
|
232
|
+
'export interface ZiteScheduledContext extends Omit<_ZiteScheduledContext, "user"> {',
|
|
233
|
+
' user: User;',
|
|
234
|
+
' scheduledAt: string;',
|
|
235
|
+
'}',
|
|
236
|
+
'',
|
|
237
|
+
"type SchemaLike<T> = { _output: T; parse: (data: unknown) => T };",
|
|
238
|
+
'',
|
|
239
|
+
'export interface EndpointConfig<TInput = unknown, TOutput = unknown> {',
|
|
240
|
+
' description?: string;',
|
|
241
|
+
' inputSchema?: SchemaLike<TInput>;',
|
|
242
|
+
' outputSchema?: SchemaLike<TOutput>;',
|
|
243
|
+
' stream?: boolean;',
|
|
244
|
+
' authenticated?: boolean;',
|
|
245
|
+
' execute: (params: { input: TInput; context: ZiteRequestContext | ZiteScheduledContext }) => Promise<TOutput> | TOutput;',
|
|
246
|
+
'}',
|
|
247
|
+
'',
|
|
248
|
+
'export function createEndpoint<TInput = unknown, TOutput = unknown>(',
|
|
249
|
+
' config: EndpointConfig<TInput, TOutput>,',
|
|
250
|
+
'): EndpointConfig<TInput, TOutput> {',
|
|
251
|
+
' return config;',
|
|
252
|
+
'}',
|
|
253
|
+
'',
|
|
254
|
+
].join('\n');
|
|
255
|
+
}
|
package/dist/esm/sync/lib.d.ts
CHANGED
|
@@ -23,3 +23,9 @@ 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
25
|
export declare function generateApiTs(endpointFiles: string[], flowId?: string): string | null;
|
|
26
|
+
export declare function generateUserTs(usersTableFields?: Array<{
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}>): string;
|
|
30
|
+
export declare function generateAuthWrapperTs(): string;
|
|
31
|
+
export declare function generateBackendWrapperTs(): string;
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -156,3 +156,89 @@ export function generateApiTs(endpointFiles, flowId) {
|
|
|
156
156
|
lines.push('');
|
|
157
157
|
return lines.join('\n');
|
|
158
158
|
}
|
|
159
|
+
export function generateUserTs(usersTableFields) {
|
|
160
|
+
const lines = [
|
|
161
|
+
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
162
|
+
'',
|
|
163
|
+
];
|
|
164
|
+
if (usersTableFields && usersTableFields.length > 0) {
|
|
165
|
+
lines.push('export type User = {');
|
|
166
|
+
lines.push(' id: string;');
|
|
167
|
+
lines.push(' email: string;');
|
|
168
|
+
for (const field of usersTableFields) {
|
|
169
|
+
if (field.name.toLowerCase() === 'id')
|
|
170
|
+
continue;
|
|
171
|
+
const fieldName = toCamelCase(field.name);
|
|
172
|
+
const tsType = tsTypeForField(field);
|
|
173
|
+
lines.push(` ${fieldName}: ${tsType};`);
|
|
174
|
+
}
|
|
175
|
+
lines.push(' [key: string]: unknown;');
|
|
176
|
+
lines.push('};');
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
lines.push('export type User = {');
|
|
180
|
+
lines.push(' id: string;');
|
|
181
|
+
lines.push(' email: string;');
|
|
182
|
+
lines.push(' firstName?: string;');
|
|
183
|
+
lines.push(' lastName?: string;');
|
|
184
|
+
lines.push(' [key: string]: unknown;');
|
|
185
|
+
lines.push('};');
|
|
186
|
+
}
|
|
187
|
+
lines.push('');
|
|
188
|
+
return lines.join('\n');
|
|
189
|
+
}
|
|
190
|
+
export function generateAuthWrapperTs() {
|
|
191
|
+
return [
|
|
192
|
+
'// Auto-generated type-narrowing wrapper. Do not edit manually.',
|
|
193
|
+
'// The real auth logic lives in the zitejs npm package (zitejs/auth).',
|
|
194
|
+
'',
|
|
195
|
+
"import { useAuth as _useAuth } from 'zitejs/auth/base';",
|
|
196
|
+
"import type { User } from './user';",
|
|
197
|
+
'',
|
|
198
|
+
'export type { User };',
|
|
199
|
+
'',
|
|
200
|
+
'export function useAuth() {',
|
|
201
|
+
' return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };',
|
|
202
|
+
'}',
|
|
203
|
+
'',
|
|
204
|
+
].join('\n');
|
|
205
|
+
}
|
|
206
|
+
export function generateBackendWrapperTs() {
|
|
207
|
+
return [
|
|
208
|
+
'// Auto-generated type-narrowing wrapper. Do not edit manually.',
|
|
209
|
+
'// Re-exports createEndpoint with context.user typed to the app User.',
|
|
210
|
+
'',
|
|
211
|
+
"import { ZiteError } from 'zitejs/backend/base';",
|
|
212
|
+
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext as _ZiteScheduledContext } from 'zitejs/backend/base';",
|
|
213
|
+
"import type { User } from './user';",
|
|
214
|
+
'',
|
|
215
|
+
'export { ZiteError };',
|
|
216
|
+
'',
|
|
217
|
+
'export interface ZiteRequestContext extends Omit<_ZiteRequestContext, "user"> {',
|
|
218
|
+
' user: User;',
|
|
219
|
+
'}',
|
|
220
|
+
'',
|
|
221
|
+
'export interface ZiteScheduledContext extends Omit<_ZiteScheduledContext, "user"> {',
|
|
222
|
+
' user: User;',
|
|
223
|
+
' scheduledAt: string;',
|
|
224
|
+
'}',
|
|
225
|
+
'',
|
|
226
|
+
"type SchemaLike<T> = { _output: T; parse: (data: unknown) => T };",
|
|
227
|
+
'',
|
|
228
|
+
'export interface EndpointConfig<TInput = unknown, TOutput = unknown> {',
|
|
229
|
+
' description?: string;',
|
|
230
|
+
' inputSchema?: SchemaLike<TInput>;',
|
|
231
|
+
' outputSchema?: SchemaLike<TOutput>;',
|
|
232
|
+
' stream?: boolean;',
|
|
233
|
+
' authenticated?: boolean;',
|
|
234
|
+
' execute: (params: { input: TInput; context: ZiteRequestContext | ZiteScheduledContext }) => Promise<TOutput> | TOutput;',
|
|
235
|
+
'}',
|
|
236
|
+
'',
|
|
237
|
+
'export function createEndpoint<TInput = unknown, TOutput = unknown>(',
|
|
238
|
+
' config: EndpointConfig<TInput, TOutput>,',
|
|
239
|
+
'): EndpointConfig<TInput, TOutput> {',
|
|
240
|
+
' return config;',
|
|
241
|
+
'}',
|
|
242
|
+
'',
|
|
243
|
+
].join('\n');
|
|
244
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/runtime/index.js",
|
|
@@ -37,6 +37,16 @@
|
|
|
37
37
|
"import": "./dist/esm/backend/index.js",
|
|
38
38
|
"require": "./dist/cjs/backend/index.js"
|
|
39
39
|
},
|
|
40
|
+
"./backend/base": {
|
|
41
|
+
"types": "./dist/esm/backend/index.d.ts",
|
|
42
|
+
"import": "./dist/esm/backend/index.js",
|
|
43
|
+
"require": "./dist/cjs/backend/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./auth/base": {
|
|
46
|
+
"types": "./dist/esm/auth/index.d.ts",
|
|
47
|
+
"import": "./dist/esm/auth/index.js",
|
|
48
|
+
"require": "./dist/cjs/auth/index.js"
|
|
49
|
+
},
|
|
40
50
|
"./upload": {
|
|
41
51
|
"types": "./dist/esm/upload/index.d.ts",
|
|
42
52
|
"import": "./dist/esm/upload/index.js",
|