Skip to content

Commit 8b87377

Browse files
committed
Fix types gen
1 parent da0cc09 commit 8b87377

6 files changed

Lines changed: 16 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openworkers-api",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"license": "MIT",
55
"module": "src/index.ts",
66
"type": "module",

scripts/generate-types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,19 @@ async function generateTypes() {
102102
};
103103

104104
console.log(' 📋 First pass: building types map...');
105+
// Map from name to type string (not type string to name, to avoid collision issues)
106+
const nameToTypeStr = new Map<string, string>();
105107
for (const { schema, name } of schemas) {
106108
try {
107109
const { node } = zodToTs(schema, { auxiliaryTypeStore });
108110
let typeStr = printNode(node);
109111
// Normalize whitespace for better matching
110112
typeStr = typeStr.replace(/\s+/g, ' ').trim();
111-
typesMap.set(typeStr, name);
113+
nameToTypeStr.set(name, typeStr);
114+
// Only add to typesMap if not already present (first wins for deduplication)
115+
if (!typesMap.has(typeStr)) {
116+
typesMap.set(typeStr, name);
117+
}
112118
} catch (error) {
113119
console.error(`❌ Failed to generate type for ${name}:`, error);
114120
}
@@ -121,7 +127,7 @@ async function generateTypes() {
121127
// Sort types by length (longest first) for better matching
122128
const sortedTypes = Array.from(typesMap.entries()).sort(([a], [b]) => b.length - a.length);
123129

124-
for (const [typeStr, name] of typesMap) {
130+
for (const [name, typeStr] of nameToTypeStr) {
125131
let updatedTypeStr = typeStr;
126132

127133
// Replace all occurrences of other types with their names (with I prefix)

src/services/databases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export class DatabasesService {
1818
* Token is created later via POST /databases/:id/token
1919
*/
2020
async create(userId: string, input: IDatabaseCreateInput): Promise<IDatabase> {
21-
const { name, desc, max_rows } = input;
21+
const { name, desc, maxRows } = input;
2222

2323
// Create tenant database using PL/pgSQL function (creates schema + entry)
2424
// Pass random name to postgate - user's display name stays in openworkers only
2525
const postgateResult = await adminSql<PostgateDatabaseRow>(
2626
`SELECT id FROM create_tenant_database($1, $2::integer)`,
27-
[crypto.randomUUID(), max_rows || 1000]
27+
[crypto.randomUUID(), maxRows || 1000]
2828
);
2929

3030
if (postgateResult.length === 0) {

src/types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export interface JWTPayload {
1313
}
1414

1515
// Types-only exports (no Zod runtime, lightweight for frontend)
16-
export type { Timestamps, Resource } from './schemas/base.schema';
16+
export type { IResource } from './schemas/base.schema';
17+
export type { ITimestamps } from './schemas/base.schema';
1718

1819
export { LoginResponseSchema } from './schemas/auth.schema';
1920
export type { ILoginResponse } from './schemas/auth.schema';

src/types/schemas/base.schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export const ResourceSchema = TimestampsSchema.extend({
1414
});
1515

1616
// Types
17-
export type Timestamps = z.infer<typeof TimestampsSchema>;
18-
export type Resource = z.infer<typeof ResourceSchema>;
17+
export type ITimestamps = z.infer<typeof TimestampsSchema>;
18+
export type IResource = z.infer<typeof ResourceSchema>;

src/types/schemas/database.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const DatabaseSchema = ResourceSchema;
99
export const DatabaseCreateInputSchema = z.object({
1010
name: z.string().min(1).max(100).trim(),
1111
desc: z.string().max(255).trim().nullable().optional(),
12-
max_rows: z.number().int().positive().max(10000).optional()
12+
maxRows: z.number().int().positive().max(10000).optional()
1313
});
1414

1515
// Types

0 commit comments

Comments
 (0)