byu-oit / uapi-ts

TypeScript Definitions for UAPI elements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

University API Typescript Definitions

npm (scoped) Deployment

Home of the official TypeScript definitions for UAPI Specification elements.

Install

Note: Only GitHub Package Manager support offered for versions >= 2.2.0 as these type definitions are intended for internal use. See the GitHub Docs for Installing a package from GitHub.

npm install --save-dev @byu-oit/uapi-ts

Usage

Define your models as types (not interfaces) and pass them into the Simple or Collection UAPI Response types. Interfaces tend to cause problems because of how they interact with index types in typescript.

interface MyModel extends UAPI.PropertyDictionary {
    id: UAPI.Scalar.String
}
type MyUAPICollectionResponse = UAPI.Response.Collection<MyModel>
type MyUAPISimpleResponse = UAPI.Response.Simple<MyModel>

For organizational purposes, you can use namespaces to organize the different endpoints you wish to group together:

namespace MyNamespace {
    export type MultipleModelsEndpointResponse = UAPI.Response.Collection<MultipleModels>
    
    export type FirstEndpointResponse = UAPI.Response.Simple<FirstModel>
    
    export type SecondEndpointResponse = UAPI.Response.Simple<SecondModel>
    
    type FirstModel = {
        foo: UAPI.Scalar.String
    }
    
    type SecondModel = {
        bar: UAPI.Scalar.String
    }
    
    type MultipleModels = {
        first: UAPI.Object<FirstModel>
        second: UAPI.Object<SecondModel>
    }
}

UAPI Lite Support

UAPI Lite is not an official part of the UAPI Specification (yet) but these types provide UAPI Lite support as an experimental feature. Use it the same way you would the other UAPI types but prefix the types with UAPI.Lite. instead of UAPI. For example:

type MyModel = {
    id: UAPI.Lite.Scalar.String
}

Contributing

Please open a Pull Request or submit an Issue.

About

TypeScript Definitions for UAPI elements

License:Apache License 2.0


Languages

Language:TypeScript 100.0%