Skip to content

Commit

Permalink
add datastore bulk apis
Browse files Browse the repository at this point in the history
  • Loading branch information
anabulsi committed Jan 23, 2024
1 parent 43269f5 commit 3b8f6e0
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/typed-method-types/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ export type DatastorePutResponse<
item: DatastoreItem<Schema>;
};

export type DatastoreBulkPutArgs<
Schema extends DatastoreSchema,
> =
& BaseMethodArgs
& {
/**
* @description The name of the datastore
*/
datastore: Schema["name"];
/**
* @description Array of items to store
*/
items: DatastoreItem<Schema>[];
};

export type DatastoreBulkPutResponse<
Schema extends DatastoreSchema,
> =
& BaseResponse
& {
/**
* @description The name of the datastore
*/
datastore: Schema["name"];
/**
* @description Array of items that failed to be inserted
*/
failed_items: DatastoreItem<Schema>[];
};

export type DatastoreUpdateArgs<
Schema extends DatastoreSchema,
> =
Expand Down Expand Up @@ -112,6 +142,41 @@ export type DatastoreGetResponse<
item: DatastoreItem<Schema>;
};

export type DatastoreBulkGetArgs<
Schema extends DatastoreSchema,
> =
& {
/**
* @description Primary keys of the items to retrieve
*/
// deno-lint-ignore no-explicit-any
ids: any[];
/**
* @description The name of the datastore
*/
datastore: Schema["name"];
}
& BaseMethodArgs;

export type DatastoreBulkGetResponse<
Schema extends DatastoreSchema,
> =
& BaseResponse
& {
/**
* @description The name of the datastore
*/
datastore: Schema["name"];
/**
* @description The retreived items
*/
items: DatastoreItem<Schema>[];
/**
* @description Array of items that failed to be retreived
*/
failed_items: DatastoreItem<Schema>[];
};

export type DatastoreQueryArgs<
Schema extends DatastoreSchema,
> =
Expand Down Expand Up @@ -168,16 +233,56 @@ export type DatastoreDeleteResponse<
datastore: Schema["name"];
};

export type DatastoreBulkDeleteArgs<
Schema extends DatastoreSchema,
> =
& {
/**
* @description Primary keys of the items to delete
*/
// deno-lint-ignore no-explicit-any
ids: any[];
/**
* @description The name of the datastore
*/
datastore: Schema["name"];
}
& BaseMethodArgs;

export type DatastoreBulkDeleteResponse<
Schema extends DatastoreSchema,
> = BaseResponse & {
/**
* @description The name of the datastore
*/
datastore: Schema["name"];
/**
* @description Primary keys of the items that failed to be deleted
*/
// deno-lint-ignore no-explicit-any
ids: any[];
};

export type AppsDatastoreGet = {
<Schema extends DatastoreSchema>(
args: DatastoreGetArgs<Schema>,
): Promise<DatastoreGetResponse<Schema>>;
};
export type AppsDatastoreBulkGet = {
<Schema extends DatastoreSchema>(
args: DatastoreBulkGetArgs<Schema>,
): Promise<DatastoreBulkGetResponse<Schema>>;
};
export type AppsDatastorePut = {
<Schema extends DatastoreSchema>(
args: DatastorePutArgs<Schema>,
): Promise<DatastorePutResponse<Schema>>;
};
export type AppsDatastoreBulkPut = {
<Schema extends DatastoreSchema>(
args: DatastoreBulkPutArgs<Schema>,
): Promise<DatastoreBulkPutResponse<Schema>>;
};
export type AppsDatastoreUpdate = {
<Schema extends DatastoreSchema>(
args: DatastoreUpdateArgs<Schema>,
Expand All @@ -193,6 +298,11 @@ export type AppsDatastoreDelete = {
args: DatastoreDeleteArgs<Schema>,
): Promise<DatastoreDeleteResponse<Schema>>;
};
export type AppsDatastoreBulkDelete = {
<Schema extends DatastoreSchema>(
args: DatastoreBulkDeleteArgs<Schema>,
): Promise<DatastoreBulkDeleteResponse<Schema>>;
};

// apps.auth Types

Expand Down Expand Up @@ -253,10 +363,13 @@ export type TypedAppsMethodTypes = {
apps: {
datastore: {
get: AppsDatastoreGet;
bulkGet: AppsDatastoreBulkGet;
put: AppsDatastorePut;
bulkPut: AppsDatastoreBulkPut;
update: AppsDatastoreUpdate;
query: AppsDatastoreQuery;
delete: AppsDatastoreDelete;
bulkDelete: AppsDatastoreBulkDelete;
};
auth: {
external: {
Expand Down
3 changes: 3 additions & 0 deletions src/typed-method-types/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import { TypedWorkflowsMethodTypes } from "./workflows/mod.ts";
*/
export const methodsWithCustomTypes = [
"apps.datastore.delete",
"apps.datastore.bulkDelete",
"apps.datastore.get",
"apps.datastore.bulkGet",
"apps.datastore.put",
"apps.datastore.bulkPut",
"apps.datastore.update",
"apps.datastore.query",
"apps.auth.external.get",
Expand Down
3 changes: 3 additions & 0 deletions src/typed-method-types/typed-method-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Deno.test("Custom Type Methods are valid functions", () => {
const client = SlackAPI("test-token");

assertEquals(typeof client.apps.datastore.delete, "function");
assertEquals(typeof client.apps.datastore.bulkDelete, "function");
assertEquals(typeof client.apps.datastore.get, "function");
assertEquals(typeof client.apps.datastore.bulkGet, "function");
assertEquals(typeof client.apps.datastore.put, "function");
assertEquals(typeof client.apps.datastore.bulkPut, "function");
assertEquals(typeof client.apps.datastore.update, "function");
assertEquals(typeof client.apps.datastore.query, "function");
assertEquals(typeof client.apps.auth.external.get, "function");
Expand Down

0 comments on commit 3b8f6e0

Please sign in to comment.