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
- DefAlias
- DefArray
- DefBytesArray
- DefEnum
- DefEnumVariant
- DefImport
- DefMap
- DefOption
- DefResult
- DefSet
- DefStruct
- DefStructField
- DefTuple
- DefVec
- NamespaceDefinition
- TypeDef
- TypeRef
Functions
Type Aliases
DefAlias
Ƭ DefAlias: Object
Just an alias to the inner type
Type declaration
| Name | Type |
|---|---|
ref | TypeRef |
Defined in
packages/definition-compiler/src/types.ts:61
DefArray
Ƭ DefArray: Object
Fixed-length array
Type declaration
| Name | Type | Description |
|---|---|---|
item | TypeRef | Inner type name |
len | number | - |
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
| Name | Type |
|---|---|
len | number |
Defined in
packages/definition-compiler/src/types.ts:79
DefEnum
Ƭ DefEnum: Object
Enum definition
Type declaration
| Name | Type | Description |
|---|---|---|
variants | DefEnumVariant[] | 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
| Name | Type | Description |
|---|---|---|
discriminant | number | - |
name | string | - |
ref? | TypeRef | null | No 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
| Name | Type | Description |
|---|---|---|
module | string | Where to import from, path Example ts import { ... } from '<here is the module name>' |
nameInModule? | string | Name 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
| Name | Type |
|---|---|
key | TypeRef |
value | TypeRef |
Defined in
packages/definition-compiler/src/types.ts:128
DefOption
Ƭ DefOption: Object
Option enum definition
Type declaration
| Name | Type |
|---|---|
some | TypeRef |
Defined in
packages/definition-compiler/src/types.ts:164
DefResult
Ƭ DefResult: Object
Result enum definition
Type declaration
| Name | Type |
|---|---|
err | TypeRef |
ok | TypeRef |
Defined in
packages/definition-compiler/src/types.ts:171
DefSet
Ƭ DefSet: Object
Set definition (e.g. HashSet, BTreeSet)
Type declaration
| Name | Type |
|---|---|
entry | TypeRef |
Defined in
packages/definition-compiler/src/types.ts:136
DefStruct
Ƭ DefStruct: Object
Structure definition
Type declaration
| Name | Type | Description |
|---|---|---|
fields | DefStructField[] | Remarks note: order of fields matters! |
Defined in
packages/definition-compiler/src/types.ts:106
DefStructField
Ƭ DefStructField: Object
Type declaration
| Name | Type | Description |
|---|---|---|
name | string | Name of the struct field |
ref | TypeRef | Reference to the type |
Defined in
packages/definition-compiler/src/types.ts:114
DefTuple
Ƭ DefTuple: Object
Tuple definition
Type declaration
| Name | Type | Description |
|---|---|---|
items | TypeRef[] | Array of inner types |
Defined in
packages/definition-compiler/src/types.ts:96
DefVec
Ƭ DefVec: Object
Vec<T> definition
Type declaration
| Name | Type | Description |
|---|---|---|
item | TypeRef | Inner 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
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
| Name | Type |
|---|---|
definition | NamespaceDefinition |
params? | RenderNamespaceDefinitionParams |
Returns
string