Skip to main content

ResourceListForClient

Hierarchy

Index

Constructors

constructor

  • ResourceListForClient will handle resource query related tasks, such as query file by label or ID, query file by URL set and file description.

    This class will also handle resource fallback from different CDN and resource convert related task.


    Parameters

    Returns ResourceListForClient

Properties

readonlyfilesById

filesById: Map<string, IResourceFile | IResourceFileForClient> = ...

readonlyfilesByLabel

filesByLabel: Map<string, IResourceFile | IResourceFileForClient> = ...

readonlygroupsById

groupsById: Map<string, IResourceGroup | IResourceGroupForClient> = ...

readonlygroupsByLabel

groupsByLabel: Map<string, IResourceGroup | IResourceGroupForClient> = ...

readonlyitems

readonlyitemsById

itemsById: Map<string, IDetailedResourceItemForClient> = ...

readonlyitemsByLabel

itemsByLabel: Map<string, IDetailedResourceItemForClient> = ...

publicreadonlyrawResourceList

rawResourceList: IResourceItemForClient[]

readonlyresourceFiles

resourceFiles: Set<IResourceFile | IResourceFileForClient> = ...

readonlyresourceGroups

resourceGroups: Set<IResourceGroup | IResourceGroupForClient> = ...

Methods

add

  • add(x: T, sync?: boolean): void
  • Parameters

    • x: T
    • sync: boolean = true

    Returns void

getResourceById

  • getResourceById<Result, PostProcess>(id: string, envConfig?: Record<string, string>, weights?: Record<string, number>, postProcess?: PostProcess, resourceType?: group | file, useSlowQueue?: boolean, taskId?: string): Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>
  • Get resource by resource ID.


    Type parameters

    Parameters

    • id: string

      The ID for the resource.

    • envConfig: Record<string, string> = null

      Environment variable, this value will be used if the resource is a group, smart-resource will pick one file from the group by the configuration.

    • optionalweights: Record<string, number>

      Weight of each configuration.

    • optionalpostProcess: PostProcess

      Post process function, will convert the resource URL to whatever you want. If the callback is not provided, this method will return a URL, otherwise it will return the result of the callback.

    • optionalresourceType: group | file

      The resource is a group or file, if not provided, a guessing strategy will be used.

    • useSlowQueue: boolean = false
    • taskId: string = ...

      Task ID for debug purpose, will only be shown in the debug log.

    Returns Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>

    A promise that resolves to the resource URL or post processed resource.

getResourceByLabel

  • getResourceByLabel<Result, PostProcess>(label: string, envConfig?: Record<string, string>, weights?: Record<string, number>, postProcess?: PostProcess, resourceType?: group | file, useSlowQueue?: boolean, taskId?: string): Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>
  • Get resource by resource label.


    Type parameters

    Parameters

    • label: string

      The label for the resource.

    • envConfig: Record<string, string> = null

      Environment variable, this value will be used if the resource is a group, smart-resource will pick one file from the group by the configuration.

    • optionalweights: Record<string, number>

      Weight of each configuration.

    • optionalpostProcess: PostProcess

      Post process function, will convert the resource URL to whatever you want. If the callback is not provided, this method will return a URL, otherwise it will return the result of the callback.

    • optionalresourceType: group | file

      The resource is a group or file, if not provided, a guessing strategy will be used.

    • useSlowQueue: boolean = false
    • taskId: string = ...

      Task ID for debug purpose, will only be shown in the debug log.

    Returns Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>

    A promise that resolves to the resource URL or post processed resource.

getResourceByQuery

  • getResourceByQuery<Result, PostProcess>(query: string, queryType: id | label, envConfig?: Record<string, string>, weights?: Record<string, number>, postProcess?: PostProcess, resourceType?: group | file, useSlowQueue?: boolean, taskId?: string): Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>
  • Get resource by resource query.


    Type parameters

    Parameters

    • query: string
    • queryType: id | label
    • envConfig: Record<string, string> = null

      Environment variable, this value will be used if the resource is a group, smart-resource will pick one file from the group by the configuration.

    • optionalweights: Record<string, number>

      Weight of each configuration.

    • optionalpostProcess: PostProcess

      Post process function, will convert the resource URL to whatever you want. If the callback is not provided, this method will return a URL, otherwise it will return the result of the callback.

    • optionalresourceType: group | file

      The resource is a group or file, if not provided, a guessing strategy will be used.

    • useSlowQueue: boolean = false
    • taskId: string = ...

      Task ID for debug purpose, will only be shown in the debug log.

    Returns Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>

    A promise that resolves to the resource URL or post processed resource.

getResourceByResourceDescription

  • getResourceByResourceDescription<Result, PostProcess>(resource: IDetailedResourceItemForClient, envConfig?: Record<string, string>, weights?: Record<string, number>, postProcess?: PostProcess, useSlowQueue?: boolean, taskId?: string): Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>
  • Get resource by a resource description.


    Type parameters

    Parameters

    • resource: IDetailedResourceItemForClient

      The resource description generated by Studio.

    • envConfig: Record<string, string> = null

      Environment variable, this value will be used if the resource is a group, smart-resource will pick one file from the group by the configuration.

    • optionalweights: Record<string, number>

      Weight of each configuration.

    • optionalpostProcess: PostProcess

      Post process function, will convert the resource URL to whatever you want. If the callback is not provided, this method will return a URL, otherwise it will return the result of the callback.

    • useSlowQueue: boolean = false
    • taskId: string = 'client-query'

      Task ID for debug purpose, will only be shown in the debug log.

    Returns Promise<PostProcess extends Metadata ? IDetailedResourceItemForClient : Result>

    A promise that resolves to the resource URL or post processed resource.

getResourceByUrlMap

  • getResourceByUrlMap<Result, PostProcess, AdditionalData>(urlMap: Record<string, string>, postProcess?: PostProcess, additionalData?: AdditionalData, taskId?: string, addToGlobalCache?: boolean, useSlowQueue?: boolean): Promise<Result>
  • Get resource by a URL map.


    Type parameters

    Parameters

    • urlMap: Record<string, string>

      The key is the ID of the CDN or data source, the value is a URL.

    • optionalpostProcess: PostProcess

      Post process function, will convert the resource URL to whatever you want. If the callback is not provided, this method will return a URL, otherwise it will return the result of the callback.

    • optionaladditionalData: AdditionalData
    • taskId: string = 'client-side-selector-url-map'

      Task ID for debug purpose, will only be shown in the debug log.

    • addToGlobalCache: boolean = false
    • useSlowQueue: boolean = false

    Returns Promise<Result>

    A promise that resolves to the resource URL or post processed resource.

remove

  • remove(x: T): void
  • Parameters

    • x: T

    Returns void