Skip to content
On this page

Scale JS / @scale-codec/definition-compiler

Module: @scale-codec/definition-compiler

Tool to define complex SCALE-type namespaces and compile them to TypeScript

Table of contents

Interfaces

Type Aliases

Functions

Type Aliases

DefAlias

Ƭ DefAlias: Object

Just an alias to the inner type

Type declaration

NameType
refTypeRef

Defined in

packages/definition-compiler/src/types.ts:61


DefArray

Ƭ DefArray: Object

Fixed-length array

Type declaration

NameTypeDescription
itemTypeRefInner type name
lennumber-

Defined in

packages/definition-compiler/src/types.ts:68


DefBytesArray

Ƭ DefBytesArray: Object

It's like DefArray but for bytes (u8). Use it for bytes for better performance.

Type declaration

NameType
lennumber

Defined in

packages/definition-compiler/src/types.ts:79


DefEnum

Ƭ DefEnum: Object

Enum definition

Type declaration

NameTypeDescription
variantsDefEnumVariant[]Remarks Order of variants doesn't matter, but variants should not contain collisions between their names and discriminants

Defined in

packages/definition-compiler/src/types.ts:143


DefEnumVariant

Ƭ DefEnumVariant: Object

Type declaration

NameTypeDescription
discriminantnumber-
namestring-
ref?TypeRef | nullNo ref/null ref means that this variant is empty

Defined in

packages/definition-compiler/src/types.ts:152


DefImport

Ƭ DefImport: Object

External type definition - import codec from external module

Remarks

Provides a possibility to define external types, e.g. to use some complex structure from another compiled namespace OR to define your own custom low-level codec for type that is not included into the SCALE codec spec by default.

Note that the import should be of FragmentBuilder type.

Type declaration

NameTypeDescription
modulestringWhere to import from, path Example ts import { ... } from '<here is the module name>'
nameInModule?stringName of the type inside of the module. If this field is omitted, the own type name will be used Todo define custom name for each import?

Defined in

packages/definition-compiler/src/types.ts:185


DefMap

Ƭ DefMap: Object

Map definition (e.g. HashMap, BTreeMap)

Type declaration

NameType
keyTypeRef
valueTypeRef

Defined in

packages/definition-compiler/src/types.ts:128


DefOption

Ƭ DefOption: Object

Option enum definition

Type declaration

NameType
someTypeRef

Defined in

packages/definition-compiler/src/types.ts:164


DefResult

Ƭ DefResult: Object

Result enum definition

Type declaration

NameType
errTypeRef
okTypeRef

Defined in

packages/definition-compiler/src/types.ts:171


DefSet

Ƭ DefSet: Object

Set definition (e.g. HashSet, BTreeSet)

Type declaration

NameType
entryTypeRef

Defined in

packages/definition-compiler/src/types.ts:136


DefStruct

Ƭ DefStruct: Object

Structure definition

Type declaration

NameTypeDescription
fieldsDefStructField[]Remarks note: order of fields matters!

Defined in

packages/definition-compiler/src/types.ts:106


DefStructField

Ƭ DefStructField: Object

Type declaration

NameTypeDescription
namestringName of the struct field
refTypeRefReference to the type

Defined in

packages/definition-compiler/src/types.ts:114


DefTuple

Ƭ DefTuple: Object

Tuple definition

Type declaration

NameTypeDescription
itemsTypeRef[]Array of inner types

Defined in

packages/definition-compiler/src/types.ts:96


DefVec

Ƭ DefVec: Object

Vec<T> definition

Type declaration

NameTypeDescription
itemTypeRefInner vec type name

Defined in

packages/definition-compiler/src/types.ts:86


NamespaceDefinition

Ƭ NamespaceDefinition: Record<string, TypeDef>

The main map with all the definitions

Remarks

Name of type should be a valid JavaScript identifier name, because it will be compiled to an identifier.

Example

ts
const definition: NamespaceDefinition = {
  Person: {
    t: 'struct',
    fields: [
      { name: 'name', ref: 'str' },
      { name: 'age', ref: 'u8' }
    ]
  },
  VecPerson: { t: 'vec', item: 'Person' }
}

Defined in

packages/definition-compiler/src/types.ts:54


TypeDef

Ƭ TypeDef: WithTMark<DefAlias, "alias"> | WithTMark<DefArray, "array"> | WithTMark<DefBytesArray, "bytes-array"> | WithTMark<DefVec, "vec"> | WithTMark<DefTuple, "tuple"> | WithTMark<DefStruct, "struct"> | WithTMark<DefMap, "map"> | WithTMark<DefSet, "set"> | WithTMark<DefEnum, "enum"> | WithTMark<DefOption, "option"> | WithTMark<DefResult, "result"> | WithTMark<DefImport, "import">

Defined in

packages/definition-compiler/src/types.ts:207


TypeRef

Ƭ TypeRef: string

Defined in

packages/definition-compiler/src/types.ts:56

Functions

renderNamespaceDefinition

renderNamespaceDefinition(definition, params?): string

Renders provided definition into a valid TypeScript code.

Parameters

NameType
definitionNamespaceDefinition
params?RenderNamespaceDefinitionParams

Returns

string

Defined in

packages/definition-compiler/src/render/index.ts:317