diff --git a/src/server/templates/typescript.ts b/src/server/templates/typescript.ts index 563a2ce4..1d5fa925 100644 --- a/src/server/templates/typescript.ts +++ b/src/server/templates/typescript.ts @@ -31,7 +31,8 @@ export const apply = async ({ .forEach((c) => columnsByTableId[c.table_id].push(c)) let output = ` -export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[] +/** @deprecated Use \`unknown\` instead. \`Json\` will be removed in a future release. */ +export type Json = unknown export type Database = { ${schemas @@ -136,7 +137,12 @@ export type Database = { return `${output}?: never` } - output += `?: ${pgTypeToTsType(column.format, { types, schemas, tables, views })}` + output += `?: ${pgTypeToTsType(column.format, { + types, + schemas, + tables, + views, + })}` if (column.is_nullable) { output += '| null' @@ -201,7 +207,12 @@ export type Database = { return `${output}?: never` } - output += `?: ${pgTypeToTsType(column.format, { types, schemas, tables, views })} | null` + output += `?: ${pgTypeToTsType(column.format, { + types, + schemas, + tables, + views, + })} | null` return output })} @@ -214,7 +225,12 @@ export type Database = { return `${output}?: never` } - output += `?: ${pgTypeToTsType(column.format, { types, schemas, tables, views })} | null` + output += `?: ${pgTypeToTsType(column.format, { + types, + schemas, + tables, + views, + })} | null` return output })} @@ -372,7 +388,12 @@ export type Database = { const type = types.find(({ id }) => id === type_id) let tsType = 'unknown' if (type) { - tsType = `${pgTypeToTsType(type.name, { types, schemas, tables, views })} | null` + tsType = `${pgTypeToTsType(type.name, { + types, + schemas, + tables, + views, + })} | null` } return `${JSON.stringify(name)}: ${tsType}` })} @@ -509,7 +530,7 @@ const pgTypeToTsType = ( ) { return 'string' } else if (['json', 'jsonb'].includes(pgType)) { - return 'Json' + return 'unknown' } else if (pgType === 'void') { return 'undefined' } else if (pgType === 'record') { diff --git a/test/server/typegen.ts b/test/server/typegen.ts index ddf31801..2db304d6 100644 --- a/test/server/typegen.ts +++ b/test/server/typegen.ts @@ -4,13 +4,8 @@ import { app } from './utils' test('typegen', async () => { const { body } = await app.inject({ method: 'GET', path: '/generators/typescript' }) expect(body).toMatchInlineSnapshot(` - "export type Json = - | string - | number - | boolean - | null - | { [key: string]: Json | undefined } - | Json[] + "/** @deprecated Use \`unknown\` instead. \`Json\` will be removed in a future release. */ + export type Json = unknown export type Database = { public: { @@ -41,7 +36,7 @@ test('typegen', async () => { category: number | null created_at: string id: number - metadata: Json | null + metadata: unknown | null name: string status: Database["public"]["Enums"]["meme_status"] | null } @@ -49,7 +44,7 @@ test('typegen', async () => { category?: number | null created_at: string id?: number - metadata?: Json | null + metadata?: unknown | null name: string status?: Database["public"]["Enums"]["meme_status"] | null } @@ -57,7 +52,7 @@ test('typegen', async () => { category?: number | null created_at?: string id?: number - metadata?: Json | null + metadata?: unknown | null name?: string status?: Database["public"]["Enums"]["meme_status"] | null } @@ -183,19 +178,19 @@ test('typegen', async () => { Row: { created_at: string | null id: number - previous_value: Json | null + previous_value: unknown | null user_id: number | null } Insert: { created_at?: string | null id?: number - previous_value?: Json | null + previous_value?: unknown | null user_id?: number | null } Update: { created_at?: string | null id?: number - previous_value?: Json | null + previous_value?: unknown | null user_id?: number | null } Relationships: [] @@ -487,13 +482,8 @@ test('typegen w/ one-to-one relationships', async () => { query: { detect_one_to_one_relationships: 'true' }, }) expect(body).toMatchInlineSnapshot(` - "export type Json = - | string - | number - | boolean - | null - | { [key: string]: Json | undefined } - | Json[] + "/** @deprecated Use \`unknown\` instead. \`Json\` will be removed in a future release. */ + export type Json = unknown export type Database = { public: { @@ -524,7 +514,7 @@ test('typegen w/ one-to-one relationships', async () => { category: number | null created_at: string id: number - metadata: Json | null + metadata: unknown | null name: string status: Database["public"]["Enums"]["meme_status"] | null } @@ -532,7 +522,7 @@ test('typegen w/ one-to-one relationships', async () => { category?: number | null created_at: string id?: number - metadata?: Json | null + metadata?: unknown | null name: string status?: Database["public"]["Enums"]["meme_status"] | null } @@ -540,7 +530,7 @@ test('typegen w/ one-to-one relationships', async () => { category?: number | null created_at?: string id?: number - metadata?: Json | null + metadata?: unknown | null name?: string status?: Database["public"]["Enums"]["meme_status"] | null } @@ -673,19 +663,19 @@ test('typegen w/ one-to-one relationships', async () => { Row: { created_at: string | null id: number - previous_value: Json | null + previous_value: unknown | null user_id: number | null } Insert: { created_at?: string | null id?: number - previous_value?: Json | null + previous_value?: unknown | null user_id?: number | null } Update: { created_at?: string | null id?: number - previous_value?: Json | null + previous_value?: unknown | null user_id?: number | null } Relationships: []
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: