mancku / strapi-plugin-schemas-to-ts

Strapi Plugin Schemas to TS is a plugin for Strapi v4 that automatically converts your Strapi schemas into Typescript interfaces.
MIT License
65 stars 20 forks source link

Exclude Schema #58

Open Leviathan91 opened 4 months ago

Leviathan91 commented 4 months ago

Hey, first of all thank you for this amazing plugin. It works great!

Now here is my issue.

I added the mux-video-uploader plugin to my strapi instance. The point of is that I can directly upload my video to MUX. My collection type is Watch, which looks like this:

export interface Watch {
  id: number;
  attributes: {
    createdAt: Date;    updatedAt: Date;    publishedAt?: Date;    Name: string;
    Description?: any;
    CoverImage: { data: Media };
    CarouselImages?: { data: Media[] };
    video?: { data: Media };
    Price: number;
    Slug: string;
    mux_video?: { data: MuxAsset };
  };
}

I added the MuxAssest as a relation to my watch, but this MuxAsset type does not exist

src/api/watch/content-types/watch/watch.ts:4:26 - error TS2307: Cannot find module '<PROJECTPATH>/src/api/watch/content-types/watch' or its corresponding type declarations.

4 import { MuxAsset } from '<PROJECTPATH>/src/api/watch/content-types/watch';
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/watch/content-types/watch/watch.ts:6:32 - error TS2307: Cannot find module '<PROJECTPATH>/src/api/watch/content-types/watch' or its corresponding type declarations.

and now I cant start Strapi anymore.

So two questions 1) Can I somehow tell the plugin to ignore the mux_video type (and not add it?) (easiest fix I guess) 2) How would I solve this? I mean I dont even know what the MuxAsset looks like. Would love to learn how to tackle this tho

All I could gather for the Mux type is this, but I dont see how that helps

export interface PluginMuxVideoUploaderMuxAsset extends Schema.CollectionType {
  collectionName: 'muxassets';
  info: {
    name: 'mux-asset';
    description: 'Represents a Mux Asset item, including upload and playback details';
    displayName: 'Mux Asset';
    singularName: 'mux-asset';
    pluralName: 'mux-assets';
  };
  options: {
    increments: true;
    timestamps: true;
  };
  pluginOptions: {
    'content-manager': {
      visible: true;
    };
    'content-type-builder': {
      visible: true;
    };
  };
  attributes: {
    title: Attribute.String &
      Attribute.Required &
      Attribute.SetMinMaxLength<{
        minLength: 3;
        maxLength: 255;
      }>;
    upload_id: Attribute.String &
      Attribute.SetMinMaxLength<{
        maxLength: 255;
      }>;
    asset_id: Attribute.String &
      Attribute.SetMinMaxLength<{
        maxLength: 255;
      }>;
    playback_id: Attribute.String &
      Attribute.SetMinMaxLength<{
        maxLength: 255;
      }>;
    signed: Attribute.Boolean & Attribute.Required & Attribute.DefaultTo<false>;
    error_message: Attribute.String &
      Attribute.SetMinMaxLength<{
        maxLength: 255;
      }>;
    isReady: Attribute.Boolean & Attribute.DefaultTo<false>;
    duration: Attribute.Decimal;
    aspect_ratio: Attribute.String;
    asset_data: Attribute.JSON;
    createdAt: Attribute.DateTime;
    updatedAt: Attribute.DateTime;
    createdBy: Attribute.Relation<
      'plugin::mux-video-uploader.mux-asset',
      'oneToOne',
      'admin::user'
    > &
      Attribute.Private;
    updatedBy: Attribute.Relation<
      'plugin::mux-video-uploader.mux-asset',
      'oneToOne',
      'admin::user'
    > &
      Attribute.Private;
  };
}
export interface PluginMuxVideoUploaderMuxTextTrack
  extends Schema.CollectionType {
  collectionName: 'muxtexttracks';
  info: {
    name: 'mux-text-track';
    description: 'Temporary storage for user-defined subtitles & captions sent to Mux during video uploads';
    displayName: 'Mux Text Track';
    singularName: 'mux-text-track';
    pluralName: 'mux-text-tracks';
  };
  options: {
    increments: true;
    timestamps: true;
  };
  pluginOptions: {
    'content-manager': {
      visible: false;
    };
    'content-type-builder': {
      visible: false;
    };
  };
  attributes: {
    name: Attribute.String & Attribute.Required;
    language_code: Attribute.String & Attribute.Required;
    closed_captions: Attribute.Boolean & Attribute.Required;
    file: Attribute.JSON & Attribute.Required;
    createdAt: Attribute.DateTime;
    updatedAt: Attribute.DateTime;
    createdBy: Attribute.Relation<
      'plugin::mux-video-uploader.mux-text-track',
      'oneToOne',
      'admin::user'
    > &
      Attribute.Private;
    updatedBy: Attribute.Relation<
      'plugin::mux-video-uploader.mux-text-track',
      'oneToOne',
      'admin::user'
    > &
      Attribute.Private;
  };
}
Leviathan91 commented 4 months ago

So it seems that instead of taking the generated content type for the MuxAsset, PluginMuxVideoUploaderMuxAsset (for example), your library assumes that the collection added to the watch should be part of the watch, which makes no sense to me. Also, I could manually swap them out for the correct type, but since these files are auto generated they are just overwritten. So for now, i just swap enabled to false as workaround and cant use it anymore.

Btw, this is the response I get when I query a watch on strapi, e.g. localhost:1337/api/watches/universe

"mux_video" : {
"id": 2,
"title": "Universe",
"upload_id": "Q00102l5X00NNzpri7GdbBuArL7YLP6N9RLxlvPGRTlFB4",
"asset_id": "9ZCcj7xTmJBp9hdtxelgq7ZVlF1MICEnLcss1aWU44k",
"playback_id": "cwpyqp4dEarBWMBRht91r01zHPKEhoImBLVs4tVytisU",
"signed": false,
"error_message": null,
"isReady": true,
"duration": 11.061056,
"aspect_ratio": "16:9",
["asset_data"](http://localhost:1337/api/watches/universe): {
"upload_id": "Q00102l5X00NNzpri7GdbBuArL7YLP6N9RLxlvPGRTlFB4",
["tracks"](http://localhost:1337/api/watches/universe): [
{
"type": "audio",
"primary": true,
"max_channels": 2,
"max_channel_layout": "stereo",
"id": "CxAY3Oi018xOSrbjOMeXIKjxOYXa2Ed3zTCWXX6k90244",
"duration": 11.061063
},
{
"type": "video",
"max_width": 2048,
"max_height": 1152,
"max_frame_rate": 59.94,
"id": "WRv67kG02rOIa3cDWyRVzxf00IbhLUuJ00ZRnaukHVtpJk",
"duration": 11.06105
}
],
"status": "ready",
"resolution_tier": "1080p",
["playback_ids"](http://localhost:1337/api/watches/universe): [
{
"policy": "public",
"id": "cwpyqp4dEarBWMBRht91r01zHPKEhoImBLVs4tVytisU"
}
],
["non_standard_input_reasons"](http://localhost:1337/api/watches/universe): {
"video_resolution": "3840x2160"
},
"mp4_support": "none",
"max_stored_resolution": "UHD",
"max_stored_frame_rate": 59.94,
"max_resolution_tier": "1080p",
"master_access": "none",
"ingest_type": "on_demand_direct_upload",
"id": "9ZCcj7xTmJBp9hdtxelgq7ZVlF1MICEnLcss1aWU44k",
"encoding_tier": "smart",
"duration": 11.061056,
"created_at": 1719221022,
"aspect_ratio": "16:9"
},
"createdAt": "2024-06-24T09:23:23.711Z",
"updatedAt": "2024-06-24T09:23:58.125Z"
},

so it is available in strapi, but somehow it still doesnt create a type for it