"Fossies" - the Fresh Open Source Software Archive

Member "Rocket.Chat-4.7.2/packages/rest-typings/README.md" (20 May 2022, 2395 Bytes) of package /linux/www/Rocket.Chat-4.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

@rocket.chat/rest-typings

Package containing all Rocket.Chat rest endpoint definitions

Contributing

Contributions are always welcome! However we have some recommendations.

Good examples of what not to do:

If you have an endpoint that accepts name or id, both are not optional, one of them is required

    
    type EndPointTestGetParams = { name?: string; id?: string; } // WRONG!

    type EndPointTestGetParams = { name: string; } | { id: string; } // Better :)

If you have an endpoint that accepts name or id, both are not optional, one of them is required

    export const isEndPointTestGetParams = (props: any) is EndPointTestGetParams => 'name' in prop || 'id' in prop; // WRONG!

    // .... Better
    
    
    import Ajv from 'ajv';

    const ajv = new Ajv();
    const endPointTestGetParams = {
        oneOf: [
            {
                type: 'object',
                properties: {
                    name: {
                        type: 'string',
                    },
                },
                required: ['name'],
                additionalProperties: false,
            },
            {
                type: 'object',
                properties: {
                    id: {
                        type: 'string',
                    },
                },
                required: ['id'],
                additionalProperties: false,
            },
        ],
    };

    export const isEndPointTestGetParams = ajv.compile<EndPointTestGetParams>(endPointTestGetParams);

Optimizations

we use interfaces to register endpoints, so if you use a custom version, or miss an endpoint, you don't necessarily need to recompile the code, you can do it in your own code

    declare module '@rocket.chat/rest-typings' {
        interface Endpoints {
            'custom/endpoint': {
                GET: (params: PaginatedRequest<{ query: string }>) => PaginatedResult<{
                    some: string[];
                }>;
            };
        }
    }

License

MIT