tywalch/electrodb

Unable to export EntityItem when using CustomAttributeType

rcoundon opened this issue · 7 comments

Describe the bug
I'm trying to use CustomAttributeType to specify a specific string type for an attribute. When I export the EntityItem derived from the schema, I run into an error

Exported variable 'activities' has or is using name 'OpaquePrimitiveSymbol' from external module "file:///node_modules/electrodb/index" but cannot be named.(4023)

ElectroDB Version
2.4.1

ElectroDB Playground Link
ElectroDB Playground

Entity/Service Definitions
Include your entity model (or a model that sufficiently recreates your issue) to help troubleshoot.

const activities = new Entity({
  model: {
    entity: 'Activity',
    version: '1',
    service: 'aa',
  },
  attributes: {
    leadentId: { type: 'string', required: true },
    activityId: { type: 'string', required: true },
    datasetId: { type: 'string', required: true },  
    timezone: { type: CustomAttributeType<DtgTimezone>('string'), required: true },
    
  },
  indexes: {
    byDataSet: {
      pk: { field: 'datasetId', composite: ['datasetId'] },
      sk: { field: 'activityId', composite: ['activityId'] },
    },    
  },
}, { table: "your_table_name" });
export type ActivityRecord = EntityItem<typeof activities>; // Missing from playground as can't get it to update to include this line

Expected behavior
The ability to be able to export the EntityItem type for use by client code

Errors

Exported variable 'activities' has or is using name 'OpaquePrimitiveSymbol' from external module "file:///node_modules/electrodb/index" but cannot be named.(4023)

I am having trouble recreating, but that might be because my configuration differs from yours. Could you include your version of typescript and your tsconfig?

Hi - thanks for taking a look. A couple of the SST crew chipped in, it needed for me to set the following in tsconfig.json

    "declarationMap": false,
    "declaration": false,
    "emitDeclarationOnly": false,

Thanks Ross!

@tywalch while that solves the TS issue, it obviously disables the generation of declaration files, which is still an issue when trying to put electrodb entities in a shared package and you need the declarations to be generated.

I solved this in a different, more interesting way.

export enum FileType {
  CSV = "CSV",
  JSON = "JSON",
  XML = "XML",
  Unknown = "UNKNOWN",
}

const ElectroFileType = Object.values(FileType);

const thing = new Entity({
  model: {
    entity: "...",
    version: "1",
    service: "...",
  },
  attributes: {
    id: {
      type: "string",
      required: true
    },
    file_type: {
      type: ElectroFileType,
      required: false,
    },
    ...
}

I solved this in a different, more interesting way.

export enum FileType {
  CSV = "CSV",
  JSON = "JSON",
  XML = "XML",
  Unknown = "UNKNOWN",
}

const ElectroFileType = Object.values(FileType);

const thing = new Entity({
  model: {
    entity: "...",
    version: "1",
    service: "...",
  },
  attributes: {
    id: {
      type: "string",
      required: true
    },
    file_type: {
      type: ElectroFileType,
      required: false,
    },
    ...
}

Interesting, thanks for sharing