slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno

Home Page:https://api.slack.com/automation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUERY] Problem storing an object containing an array to a datastore

markfoden opened this issue · comments

I am having a problem storing an object containing an array to a datastore.

Below I've posted:

  • The datastore type definition
  • The essential parts of the function that creates the datastore item
  • Output from "slack datastore get" after creating the item

My test item saves to the datastore but the "partner_names" array is empty and (in the datastore get output) seems to be showing as an object rather than an array

I see from https://api.slack.com/automation/types/custom#define-type that arrays within objects need to be defined. I think I've done that and now I'm stuck.

Can you help please?

Mark

TYPE DEFINITION

export const ArrayOfNames = DefineType({
    name: "ArrayOfNames",
    type: Schema.types.array,
    items: {type: Schema.types.string }
  });
  
  export const TestType  = DefineType({
    name: "TestType",
    type: Schema.types.object,
    properties: {
      deal_name: { type: Schema.types.string },
      partner_names: { type: ArrayOfNames }
  }});

  export default DefineDatastore({
    name: "test-data",
    primary_key: "id",
    attributes: {
      id: {
        type: Schema.types.string,
      },
      test_field: {
        type: TestType,
      },
  }});

FUNCTION

const testObject = {
    deal_name: "test name",
    partner_names: ["name1","name2"]
    };

const putResponse = await client.apps.datastore.put({
    datastore: "test-data",
    item: { 
    id: "1",
    test_field: testObject,
    }
});

OUTPUT

  {
    "id": "1",
    "test_field": {
      "deal_name": "test name",
      "partner_names": {}
    }
  }

I can reproduce this bug. I will investigate and engage the datastore team.

FYI I set up a repro case here using a modified branch of the deno-hello-world sample: https://github.com/filmaj/deno-hello-world/tree/datastore-test