Skip to main content

HttpDataSource<T>

Defined in: js-api/src/dapi.ts:321

Common functionality for handling collections of entities stored on the server. Works with Datagrok REST API, allows to get filtered and paginated lists of entities, Can be extended with specific methods. (i.e. UsersDataSource)

The fluent methods (filter, order, page, by, include, ...) are immutable: each returns a new source and leaves this one as it was, so a source can be kept in a variable and reused as a starting point.

Example

const projects = grok.dapi.projects.order('createdOn', true);
const recent = await projects.filter('createdOn > -1w').list({pageSize: 20});
const all = await projects.list(); // still unfiltered

Extended by

Type Parameters

Type Parameter
T

Constructors

Constructor

new HttpDataSource<T>(s, clsName?): HttpDataSource<T>

Defined in: js-api/src/dapi.ts:327

Parameters

ParameterType
sany
clsName?string | null

Returns

HttpDataSource<T>

Properties

PropertyTypeDefined in
clsNamestringjs-api/src/dapi.ts:323
dartanyjs-api/src/dapi.ts:322

Methods

allPackageVersions()

allPackageVersions(): this

Defined in: js-api/src/dapi.ts:404

A source without package version isolation: entities of all package versions, not only the current one.

Returns

this


by()

by(i): this

Defined in: js-api/src/dapi.ts:409

A source that returns at most [i] entities per page. See also page.

Parameters

ParameterType
inumber

Returns

this


count()

count(): Promise<number>

Defined in: js-api/src/dapi.ts:375

Counts entities that satisfy the filtering criteria (see filter). See examples: https://public.datagrok.ai/js/samples/dapi/projects-list Smart filter: https://datagrok.ai/help/datagrok/smart-search

Returns

Promise<number>


delete()

delete(e): Promise<void>

Defined in: js-api/src/dapi.ts:399

Deletes an entity.

Parameters

ParameterType
eEntity

Returns

Promise<void>


filter()

filter(w): this

Defined in: js-api/src/dapi.ts:429

A source filtered by [w]; replaces the filter of this source, if any. Also can be set with list method "options" parameter See example: https://public.datagrok.ai/js/samples/dapi/projects-list Smart filter: https://datagrok.ai/help/datagrok/concepts/objects#entity-search

Parameters

ParameterType
wstring

Returns

this


find()

find(id): Promise<T>

Defined in: js-api/src/dapi.ts:389

Returns an entity with the specified id. Throws an exception if an entity does not exist, or is not accessible in the current context. Sample: https://public.datagrok.ai/js/samples/data-access/save-and-load-df

Parameters

ParameterTypeDescription
idstringGUID of the corresponding object

Returns

Promise<T>

{Promise<object>} - entity.


first()

first(): Promise<T>

Defined in: js-api/src/dapi.ts:380

Returns the first entity that satisfies the filtering criteria (see filter).

Returns

Promise<T>


include()

include(include): this

Defined in: js-api/src/dapi.ts:439

A source that also loads the [include]d properties of every entity (adds to this source's includes).

Parameters

ParameterType
includestring

Returns

this


list()

list(options?): Promise<T[]>

Defined in: js-api/src/dapi.ts:359

Returns all entities that satisfy the filtering criteria (see filter). See examples: https://public.datagrok.ai/js/samples/dapi/projects-list Smart filter: https://datagrok.ai/help/datagrok/smart-search

Parameters

ParameterType
options{ filter?: string; order?: string; pageNumber?: number; pageSize?: number; }
options.filter?string
options.order?string
options.pageNumber?number
options.pageSize?number

Returns

Promise<T[]>


nextPage()

nextPage(): this

Defined in: js-api/src/dapi.ts:421

A source for the page after this one (the first call gives page 1). Reassign to advance: source = source.nextPage(). See examples: https://public.datagrok.ai/js/samples/dapi/projects-list

Returns

this


order()

order(fieldName, desc?): this

Defined in: js-api/src/dapi.ts:434

A source ordered by [fieldName]; replaces the order of this source, if any.

Parameters

ParameterTypeDefault value
fieldNamestringundefined
descbooleanfalse

Returns

this


page()

page(i): this

Defined in: js-api/src/dapi.ts:414

A source restricted to page [i]. See also nextPage.

Parameters

ParameterType
inumber

Returns

this


save()

save(e): Promise<T>

Defined in: js-api/src/dapi.ts:394

Saves an entity; the saved copy comes back with this source's includes loaded.

Parameters

ParameterType
eEntity

Returns

Promise<T>


with()

protected with(patch): this

Defined in: js-api/src/dapi.ts:334

A copy of this source whose query has [patch] applied. The Dart handle is shared; its state is rebuilt from the query right before every request, so the copies never observe each other.

Parameters

ParameterType
patchPartial<DataSourceQuery>

Returns

this