Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add datastore bulk apis #92

Merged
merged 1 commit into from
Feb 12, 2024
Merged

add datastore bulk apis #92

merged 1 commit into from
Feb 12, 2024

Conversation

anabulsi
Copy link
Contributor

DO NOT MERGE YET

Summary

Add support for the experimental bulk APIs

testing

Create an app with a datastore, then use the new bulk APIs to get, put and delete items in bulk

Special notes

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've ran deno task test after making the changes.

@anabulsi anabulsi requested a review from a team as a code owner January 23, 2024 16:03
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7476afc) 100.00% compared to head (3b8f6e0) 100.00%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #92   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           36        36           
  Lines         1091      1091           
  Branches        13        16    +3     
=========================================
  Hits          1091      1091           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@WilliamBergamin WilliamBergamin added enhancement New feature or request semver:minor requires a minor version number bump labels Jan 23, 2024
@WilliamBergamin
Copy link
Contributor

I was able to test these features out with the following, seems like everything works 💯

// record_datastore.ts
import { DefineDatastore, Schema } from "deno-slack-sdk/mod.ts";

export const RecordSchema = {
  id: {
    type: Schema.types.string,
    description: "Datastore record id of the survey",
  },
};

export default DefineDatastore({
  name: "data",
  primary_key: "id",
  attributes: RecordSchema,
});
// in a tests function
import RecordDataStore from "./datastores/data.ts";

    const records = [{ id: crypto.randomUUID() }, { id: crypto.randomUUID() }];

    const putResp = await client.apps.datastore.bulkPut<
      typeof RecordDataStore.definition
    >({
      datastore: RecordDataStore.name,
      items: records,
    });

    if (!putResp.ok) {
      return { error: `Failed to bulk put the record error: ${putResp.error}` };
    }

    const getResp = await client.apps.datastore.bulkGet<
      typeof RecordDataStore.definition
    >({
      datastore: RecordDataStore.name,
      ids: records.map((r) => r.id),
    });

    if (!getResp.ok) {
      return {
        error: `Failed to bulk get the record error: ${getResp.error}`,
      };
    }

    const deletedResp = await client.apps.datastore.bulkDelete<
      typeof RecordDataStore.definition
    >({
      datastore: RecordDataStore.name,
      ids: records.map((r) => r.id),
    });

    if (!deletedResp.ok) {
      return {
        error: `Failed to bulk delete the records error: ${deletedResp.error}`,
      };
    }
// manifest.ts
import { Manifest } from "deno-slack-sdk/mod.ts";
import { PostIssueMessage } from "./functions/post_issue_message.ts";
import SubmitIssueWorkflow from "./workflows/submit_issue.ts";
import RecordDataStore from "./datastores/data.ts";

export default Manifest({
  name: "gallant-mole-238",
  description: "A basic sample that demonstrates issue submission to channel",
  icon: "assets/default_new_app_icon.png",
  workflows: [SubmitIssueWorkflow],
  functions: [PostIssueMessage],
  datastores: [RecordDataStore],
  outgoingDomains: ["raw.githubusercontent.com"],
  botScopes: [
    "commands",
    "chat:write",
    "chat:write.public",
    "datastore:read",
    "datastore:write",
  ],
});
// import_map.json
{
  "imports": {
    "deno-slack-sdk/": "https://deno.land/x/[email protected]/",
    "deno-slack-api/": "https://raw.githubusercontent.com/slackapi/deno-slack-api/anablsi-datastore-bulk-apis/src/"
  },
  "scopes": {
    "https://deno.land/x/[email protected]/": {
      "https://deno.land/x/[email protected]/": "https://raw.githubusercontent.com/slackapi/deno-slack-api/anablsi-datastore-bulk-apis/src/"
    }
  }
}

Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯 should be good to merge whenever

@anabulsi anabulsi merged commit fcb40ae into main Feb 12, 2024
11 checks passed
@anabulsi anabulsi deleted the anablsi-datastore-bulk-apis branch February 12, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver:minor requires a minor version number bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants