kristiandupont / kanel

Generate Typescript types from Postgres
https://kristiandupont.github.io/kanel/
MIT License
829 stars 57 forks source link

Inconsistency with introspecting compositeTypes #548

Open gitrojones opened 3 months ago

gitrojones commented 3 months ago

Introspection currently works fine if Kanel runs as a non-owner for enum composite types but will fail to introspect non-enum composite types.

For example:

CREATE TYPE enum_test AS ENUM('foo', 'bar');
CREATE TYPE test AS
(
    foo text,
    bar INT
);

Produces:

/** Represents the enum public.enum_test */
export enum EnumTest {
  foo = 'foo',
  bar = 'bar',
}

/** Represents the compositeType public.test */
export interface Test {}

I would expect that types would resolve as long as usage is allowed on that type. Digging in the source, it looks like a variant of

SELECT
    *,
    ('"' || "attribute_udt_schema" || '"."' || "attribute_udt_name" || '"')::regtype as regtype
FROM information_schema.attributes
WHERE udt_schema = <schema_name>
AND udt_name = <type_name>

used to be used for this, which does correctly resolve columns and types.

Any help on this would be appreciated. Being able to compile types using the runtime role is a useful feature of this tool

kristiandupont commented 3 months ago

Yeah, that simply looks like a bug. Composite types should create interfaces just like tables and views, as you expect.