Upsert a C3Type file via the Console


#1

I have a C3 Type file contents.
How can I create a type from it and upsert via Console (not via tools)?


#2

You can use TagMetadataStore.upsertType, it does the job but it’s a manual process.
For example, to create the following type from console:

type {
  a: int
}

Do the following:

TagMetadataStore.upsertType(Type.make({
  "name":"Test",
  "extends":null,
  "fields":[{
    "type":"FieldType",
    "name":"a",
    "valueType":{"type":"PrimitiveType","name":"int"}
  }]
}))

Create c3Typ dynamically
#3

Is there a way to upsert related .js functions as well?


#4

Once you’ve upserted your type as above:

function myFunc() {
  // function body
}
//see the path of the *c3typ and update the following accordingly
var path = 'meta://customer/..../src/TypeName.js';
var content = myFunc.toString();
MetadataFile.fromUrlOrPath(path).writeString(content);

You shouldn’t have to insert your type and JS implementation like this, you have to provision your code instead.


#5

Thanks! Completely agreed. NOT best practice.