diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts index c8037e8545..1591b78e61 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts @@ -50,13 +50,14 @@ export const toWasmInit: MustacheFn = () => { type = type.substring(0, type.length - 1); } else { const nullType = toWasm()(value, render); - const nullable = "Nullable"; + const nullable = "Option"; const nullOptional = "| null"; if (nullType.endsWith(nullOptional)) { return "null"; } else if (nullType.startsWith(nullable)) { - return `new ${nullType}()`; + type = nullType.substring(6); + return `Option.None${type}()`; } } @@ -227,7 +228,7 @@ const applyNullable = ( ) { return `${type} | null`; } else { - return `Nullable<${type}>`; + return `Option<${type}>`; } } else { return type; diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache index 25ce5f5664..390ae595c0 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache @@ -8,19 +8,19 @@ if (reader.isNextString()) { } {{/required}} {{^required}} -let value: Nullable; +let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.get{{type}}Value(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitize{{type}}Value(value.value); + Types.sanitize{{type}}Value(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } {{/required}} diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache index 1b2b569b9a..af1dfb53fa 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache @@ -1,7 +1,7 @@ import { wrap_subinvoke, wrap_subinvokeImplementation, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache index cbeab27539..842613e064 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache @@ -70,7 +70,7 @@ export function write{{name}}Args( } export function deserialize{{name}}Result(buffer: ArrayBuffer): {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}} { - const context: Context = new Context("Deserializing imported module-type: {{name}}"); + const context: Context = new Context("Deserializing imported module-type: {{name}}"); const reader = new ReadDecoder(buffer, context); {{#return}} diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache index ab841d2923..260f1f14f1 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache index e4ff00abd7..f4a4b0c88e 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache @@ -9,7 +9,7 @@ export class Input_{{name}} { } export function deserialize{{name}}Args(argsBuf: ArrayBuffer): Input_{{name}} { - const context: Context = new Context("Deserializing module-type: {{name}}"); + const context: Context = new Context("Deserializing module-type: {{name}}"); {{#arguments.length}} const reader = new ReadDecoder(argsBuf, context); let numFields = reader.readMapLength(); diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache index 9bdd689ad6..37031594f6 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache index 8aeb5aa792..9ded19f5d4 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts index cd97ce73c5..66c4600c3c 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts index f29e52aad3..ed4fbeff94 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts index 0edc7a7894..c6b44c7fda 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -21,7 +21,7 @@ export class CustomType { str: string; optStr: string | null; u: u32; - optU: Nullable; + optU: Option; m_u8: u8; m_u16: u16; m_u32: u32; @@ -38,13 +38,13 @@ export class CustomType { bytes: ArrayBuffer; optBytes: ArrayBuffer | null; m_boolean: bool; - optBoolean: Nullable; + optBoolean: Option; uArray: Array; uOptArray: Array | null; - optUOptArray: Array> | null; + optUOptArray: Array> | null; optStrOptArray: Array | null; uArrayArray: Array>; - uOptArrayOptArray: Array> | null>; + uOptArrayOptArray: Array> | null>; uArrayOptArrayArray: Array> | null>; crazyArray: Array | null>> | null> | null; object: Types.AnotherType; @@ -52,9 +52,9 @@ export class CustomType { objectArray: Array; optObjectArray: Array | null; en: Types.CustomEnum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; static toBuffer(type: CustomType): ArrayBuffer { return serializeCustomType(type); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts index 2529b4cb63..5b8a71d97a 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -38,7 +38,7 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeString("u"); writer.writeUInt32(type.u); writer.context().pop(); - writer.context().push("optU", "Nullable", "writing property"); + writer.context().push("optU", "Option", "writing property"); writer.writeString("optU"); writer.writeNullableUInt32(type.optU); writer.context().pop(); @@ -106,7 +106,7 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeString("boolean"); writer.writeBool(type.m_boolean); writer.context().pop(); - writer.context().push("optBoolean", "Nullable", "writing property"); + writer.context().push("optBoolean", "Option", "writing property"); writer.writeString("optBoolean"); writer.writeNullableBool(type.optBoolean); writer.context().pop(); @@ -122,9 +122,9 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeUInt32(item); }); writer.context().pop(); - writer.context().push("optUOptArray", "Array> | null", "writing property"); + writer.context().push("optUOptArray", "Array> | null", "writing property"); writer.writeString("optUOptArray"); - writer.writeNullableArray(type.optUOptArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(type.optUOptArray, (writer: Write, item: Option): void => { writer.writeNullableUInt32(item); }); writer.context().pop(); @@ -142,10 +142,10 @@ export function writeCustomType(writer: Write, type: CustomType): void { }); }); writer.context().pop(); - writer.context().push("uOptArrayOptArray", "Array> | null>", "writing property"); + writer.context().push("uOptArrayOptArray", "Array> | null>", "writing property"); writer.writeString("uOptArrayOptArray"); - writer.writeArray(type.uOptArrayOptArray, (writer: Write, item: Array> | null): void => { - writer.writeNullableArray(item, (writer: Write, item: Nullable): void => { + writer.writeArray(type.uOptArrayOptArray, (writer: Write, item: Array> | null): void => { + writer.writeNullableArray(item, (writer: Write, item: Option): void => { writer.writeNullableUInt32(item); }); }); @@ -204,7 +204,7 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeString("en"); writer.writeInt32(type.en); writer.context().pop(); - writer.context().push("optEnum", "Nullable", "writing property"); + writer.context().push("optEnum", "Option", "writing property"); writer.writeString("optEnum"); writer.writeNullableInt32(type.optEnum); writer.context().pop(); @@ -214,9 +214,9 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeInt32(item); }); writer.context().pop(); - writer.context().push("optEnumArray", "Array> | null", "writing property"); + writer.context().push("optEnumArray", "Array> | null", "writing property"); writer.writeString("optEnumArray"); - writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Option): void => { writer.writeNullableInt32(item); }); writer.context().pop(); @@ -236,7 +236,7 @@ export function readCustomType(reader: Read): CustomType { let _optStr: string | null = null; let _u: u32 = 0; let _uSet: bool = false; - let _optU: Nullable = new Nullable(); + let _optU: Option = Option.None(); let _u8: u8 = 0; let _u8Set: bool = false; let _u16: u16 = 0; @@ -265,15 +265,15 @@ export function readCustomType(reader: Read): CustomType { let _optBytes: ArrayBuffer | null = null; let _boolean: bool = false; let _booleanSet: bool = false; - let _optBoolean: Nullable = new Nullable(); + let _optBoolean: Option = Option.None(); let _uArray: Array = []; let _uArraySet: bool = false; let _uOptArray: Array | null = null; - let _optUOptArray: Array> | null = null; + let _optUOptArray: Array> | null = null; let _optStrOptArray: Array | null = null; let _uArrayArray: Array> = []; let _uArrayArraySet: bool = false; - let _uOptArrayOptArray: Array> | null> = []; + let _uOptArrayOptArray: Array> | null> = []; let _uOptArrayOptArraySet: bool = false; let _uArrayOptArrayArray: Array> | null> = []; let _uArrayOptArrayArraySet: bool = false; @@ -286,10 +286,10 @@ export function readCustomType(reader: Read): CustomType { let _optObjectArray: Array | null = null; let _en: Types.CustomEnum = 0; let _enSet: bool = false; - let _optEnum: Nullable = new Nullable(); + let _optEnum: Option = Option.None(); let _enumArray: Array = []; let _enumArraySet: bool = false; - let _optEnumArray: Array> | null = null; + let _optEnumArray: Array> | null = null; while (numFields > 0) { numFields--; @@ -314,7 +314,7 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optU") { - reader.context().push(field, "Nullable", "type found, reading property"); + reader.context().push(field, "Option", "type found, reading property"); _optU = reader.readNullableUInt32(); reader.context().pop(); } @@ -411,7 +411,7 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optBoolean") { - reader.context().push(field, "Nullable", "type found, reading property"); + reader.context().push(field, "Option", "type found, reading property"); _optBoolean = reader.readNullableBool(); reader.context().pop(); } @@ -431,8 +431,8 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optUOptArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optUOptArray = reader.readNullableArray((reader: Read): Nullable => { + reader.context().push(field, "Array> | null", "type found, reading property"); + _optUOptArray = reader.readNullableArray((reader: Read): Option => { return reader.readNullableUInt32(); }); reader.context().pop(); @@ -455,9 +455,9 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "uOptArrayOptArray") { - reader.context().push(field, "Array> | null>", "type found, reading property"); - _uOptArrayOptArray = reader.readArray((reader: Read): Array> | null => { - return reader.readNullableArray((reader: Read): Nullable => { + reader.context().push(field, "Array> | null>", "type found, reading property"); + _uOptArrayOptArray = reader.readArray((reader: Read): Array> | null => { + return reader.readNullableArray((reader: Read): Option => { return reader.readNullableUInt32(); }); }); @@ -539,21 +539,21 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optEnum") { - reader.context().push(field, "Nullable", "type found, reading property"); - let value: Nullable; + reader.context().push(field, "Option", "type found, reading property"); + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } _optEnum = value; reader.context().pop(); @@ -574,22 +574,22 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optEnumArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optEnumArray = reader.readNullableArray((reader: Read): Nullable => { - let value: Nullable; + reader.context().push(field, "Array> | null", "type found, reading property"); + _optEnumArray = reader.readNullableArray((reader: Read): Option => { + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } return value; }); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts index 09dee2ac73..904a3bdb79 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -20,7 +20,7 @@ import * as Types from ".."; export class Env { prop: string; optProp: string | null; - optMap: Map> | null; + optMap: Map> | null; static toBuffer(type: Env): ArrayBuffer { return serializeEnv(type); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts index 601434c3e0..e83f1c9ca1 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -34,11 +34,11 @@ export function writeEnv(writer: Write, type: Env): void { writer.writeString("optProp"); writer.writeNullableString(type.optProp); writer.context().pop(); - writer.context().push("optMap", "Map> | null", "writing property"); + writer.context().push("optMap", "Map> | null", "writing property"); writer.writeString("optMap"); writer.writeNullableExtGenericMap(type.optMap, (writer: Write, key: string) => { writer.writeString(key); - }, (writer: Write, value: Nullable): void => { + }, (writer: Write, value: Option): void => { writer.writeNullableInt32(value); }); writer.context().pop(); @@ -56,7 +56,7 @@ export function readEnv(reader: Read): Env { let _prop: string = ""; let _propSet: bool = false; let _optProp: string | null = null; - let _optMap: Map> | null = null; + let _optMap: Map> | null = null; while (numFields > 0) { numFields--; @@ -75,10 +75,10 @@ export function readEnv(reader: Read): Env { reader.context().pop(); } else if (field == "optMap") { - reader.context().push(field, "Map> | null", "type found, reading property"); + reader.context().push(field, "Map> | null", "type found, reading property"); _optMap = reader.readNullableExtGenericMap((reader: Read): string => { return reader.readString(); - }, (reader: Read): Nullable => { + }, (reader: Read): Option => { return reader.readNullableInt32(); }); reader.context().pop(); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts index 6ee48d0a3e..f214d2abae 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -16,14 +16,14 @@ export class Input_moduleMethod { str: string; optStr: string | null; en: Types.CustomEnum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; map: Map; } export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleMethod { - const context: Context = new Context("Deserializing module-type: moduleMethod"); + const context: Context = new Context("Deserializing module-type: moduleMethod"); const reader = new ReadDecoder(argsBuf, context); let numFields = reader.readMapLength(); @@ -32,10 +32,10 @@ export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleM let _optStr: string | null = null; let _en: Types.CustomEnum = 0; let _enSet: bool = false; - let _optEnum: Nullable = new Nullable(); + let _optEnum: Option = Option.None(); let _enumArray: Array = []; let _enumArraySet: bool = false; - let _optEnumArray: Array> | null = null; + let _optEnumArray: Array> | null = null; let _map: Map = new Map(); let _mapSet: bool = false; @@ -69,21 +69,21 @@ export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleM reader.context().pop(); } else if (field == "optEnum") { - reader.context().push(field, "Nullable", "type found, reading property"); - let value: Nullable; + reader.context().push(field, "Option", "type found, reading property"); + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } _optEnum = value; reader.context().pop(); @@ -104,22 +104,22 @@ export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleM reader.context().pop(); } else if (field == "optEnumArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optEnumArray = reader.readNullableArray((reader: Read): Nullable => { - let value: Nullable; + reader.context().push(field, "Array> | null", "type found, reading property"); + _optEnumArray = reader.readNullableArray((reader: Read): Option => { + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } return value; }); @@ -187,7 +187,7 @@ export class Input_objectMethod { } export function deserializeobjectMethodArgs(argsBuf: ArrayBuffer): Input_objectMethod { - const context: Context = new Context("Deserializing module-type: objectMethod"); + const context: Context = new Context("Deserializing module-type: objectMethod"); const reader = new ReadDecoder(argsBuf, context); let numFields = reader.readMapLength(); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts index 6a52f417bb..2b53e96219 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts index cfbe766951..98b67d08ff 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts index 5246bae2bd..859818f55b 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts @@ -1,7 +1,7 @@ import { wrap_subinvoke, wrap_subinvokeImplementation, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts index 65a08566f7..d1bb72d7e5 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -16,16 +16,16 @@ export class Input_importedMethod { str: string; optStr: string | null; u: u32; - optU: Nullable; - uArrayArray: Array> | null>; + optU: Option; + uArrayArray: Array> | null>; object: Types.TestImport_Object; optObject: Types.TestImport_Object | null; objectArray: Array; optObjectArray: Array | null; en: Types.TestImport_Enum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; } export function serializeimportedMethodArgs(input: Input_importedMethod): ArrayBuffer { @@ -56,14 +56,14 @@ export function writeimportedMethodArgs( writer.writeString("u"); writer.writeUInt32(input.u); writer.context().pop(); - writer.context().push("optU", "Nullable", "writing property"); + writer.context().push("optU", "Option", "writing property"); writer.writeString("optU"); writer.writeNullableUInt32(input.optU); writer.context().pop(); - writer.context().push("uArrayArray", "Array> | null>", "writing property"); + writer.context().push("uArrayArray", "Array> | null>", "writing property"); writer.writeString("uArrayArray"); - writer.writeArray(input.uArrayArray, (writer: Write, item: Array> | null): void => { - writer.writeNullableArray(item, (writer: Write, item: Nullable): void => { + writer.writeArray(input.uArrayArray, (writer: Write, item: Array> | null): void => { + writer.writeNullableArray(item, (writer: Write, item: Option): void => { writer.writeNullableUInt32(item); }); }); @@ -100,7 +100,7 @@ export function writeimportedMethodArgs( writer.writeString("en"); writer.writeInt32(input.en); writer.context().pop(); - writer.context().push("optEnum", "Nullable", "writing property"); + writer.context().push("optEnum", "Option", "writing property"); writer.writeString("optEnum"); writer.writeNullableInt32(input.optEnum); writer.context().pop(); @@ -110,16 +110,16 @@ export function writeimportedMethodArgs( writer.writeInt32(item); }); writer.context().pop(); - writer.context().push("optEnumArray", "Array> | null", "writing property"); + writer.context().push("optEnumArray", "Array> | null", "writing property"); writer.writeString("optEnumArray"); - writer.writeNullableArray(input.optEnumArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(input.optEnumArray, (writer: Write, item: Option): void => { writer.writeNullableInt32(item); }); writer.context().pop(); } export function deserializeimportedMethodResult(buffer: ArrayBuffer): Types.TestImport_Object | null { - const context: Context = new Context("Deserializing imported module-type: importedMethod"); + const context: Context = new Context("Deserializing imported module-type: importedMethod"); const reader = new ReadDecoder(buffer, context); reader.context().push("importedMethod", "Types.TestImport_Object | null", "reading function output"); @@ -162,7 +162,7 @@ export function writeanotherMethodArgs( } export function deserializeanotherMethodResult(buffer: ArrayBuffer): i32 { - const context: Context = new Context("Deserializing imported module-type: anotherMethod"); + const context: Context = new Context("Deserializing imported module-type: anotherMethod"); const reader = new ReadDecoder(buffer, context); reader.context().push("anotherMethod", "i32", "reading function output"); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts index fc03152ed8..192e0901cc 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts @@ -1,7 +1,7 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -26,9 +26,9 @@ export class TestImport_Object { objectArray: Array; optObjectArray: Array | null; en: Types.TestImport_Enum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; static toBuffer(type: TestImport_Object): ArrayBuffer { return serializeTestImport_Object(type); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts index 623dcdc2d5..9b588e9ca7 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -58,7 +58,7 @@ export function writeTestImport_Object(writer: Write, type: TestImport_Object): writer.writeString("en"); writer.writeInt32(type.en); writer.context().pop(); - writer.context().push("optEnum", "Nullable", "writing property"); + writer.context().push("optEnum", "Option", "writing property"); writer.writeString("optEnum"); writer.writeNullableInt32(type.optEnum); writer.context().pop(); @@ -68,9 +68,9 @@ export function writeTestImport_Object(writer: Write, type: TestImport_Object): writer.writeInt32(item); }); writer.context().pop(); - writer.context().push("optEnumArray", "Array> | null", "writing property"); + writer.context().push("optEnumArray", "Array> | null", "writing property"); writer.writeString("optEnumArray"); - writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Option): void => { writer.writeNullableInt32(item); }); writer.context().pop(); @@ -93,10 +93,10 @@ export function readTestImport_Object(reader: Read): TestImport_Object { let _optObjectArray: Array | null = null; let _en: Types.TestImport_Enum = 0; let _enSet: bool = false; - let _optEnum: Nullable = new Nullable(); + let _optEnum: Option = Option.None(); let _enumArray: Array = []; let _enumArraySet: bool = false; - let _optEnumArray: Array> | null = null; + let _optEnumArray: Array> | null = null; while (numFields > 0) { numFields--; @@ -153,21 +153,21 @@ export function readTestImport_Object(reader: Read): TestImport_Object { reader.context().pop(); } else if (field == "optEnum") { - reader.context().push(field, "Nullable", "type found, reading property"); - let value: Nullable; + reader.context().push(field, "Option", "type found, reading property"); + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getTestImport_EnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeTestImport_EnumValue(value.value); + Types.sanitizeTestImport_EnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } _optEnum = value; reader.context().pop(); @@ -188,22 +188,22 @@ export function readTestImport_Object(reader: Read): TestImport_Object { reader.context().pop(); } else if (field == "optEnumArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optEnumArray = reader.readNullableArray((reader: Read): Nullable => { - let value: Nullable; + reader.context().push(field, "Array> | null", "type found, reading property"); + _optEnumArray = reader.readNullableArray((reader: Read): Option => { + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getTestImport_EnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeTestImport_EnumValue(value.value); + Types.sanitizeTestImport_EnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } return value; }); diff --git a/packages/wasm/as/assembly/__tests__/msgpack.spec.ts b/packages/wasm/as/assembly/__tests__/msgpack.spec.ts index 44ccfdbcc7..e63ef0a802 100644 --- a/packages/wasm/as/assembly/__tests__/msgpack.spec.ts +++ b/packages/wasm/as/assembly/__tests__/msgpack.spec.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-inferrable-types */ import { - Nullable, Read, ReadDecoder, Write, @@ -11,6 +10,7 @@ import { BigInt, BigNumber, } from "../"; +import { Option } from "as-container"; class Sanity { nil: string | null = "null"; @@ -21,8 +21,8 @@ class Sanity { uint16: u16; uint32: u32; boolean: bool; - optUint32: Nullable = new Nullable(); - optBool: Nullable = new Nullable(); + optUint32: Option = Option.None(); + optBool: Option = Option.None(); float32: f32; float64: f64; str: string = ""; @@ -49,8 +49,8 @@ class Sanity { this.uint16 = 65535; this.uint32 = 4294967295; this.boolean = true; - this.optUint32 = Nullable.fromValue(234234234); - this.optBool = Nullable.fromValue(true); + this.optUint32 = Option.Some(234234234); + this.optBool = Option.Some(true); this.float32 = 3.40282344818115234375; this.float64 = 3124124512.598273468017578125; this.str = "Hello, world!"; diff --git a/packages/wasm/as/assembly/__tests__/nullable.spec.ts b/packages/wasm/as/assembly/__tests__/nullable.spec.ts deleted file mode 100644 index 424731136b..0000000000 --- a/packages/wasm/as/assembly/__tests__/nullable.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Nullable } from "../msgpack/Nullable"; - -describe("Nullable: Sanity", () => { - it("Works", () => { - const value = Nullable.fromValue(500); - const other = Nullable.fromNull(); - - expect(value.value).toBe(500); - expect(other).not.toBe(value); - - expect(value == other).toBe(false); - expect(value != other).toBe(true); - - const sameValue = Nullable.fromValue(value.value); - expect(sameValue == value).toBe(true); - }); -}); diff --git a/packages/wasm/as/assembly/index.ts b/packages/wasm/as/assembly/index.ts index ffacda0174..372b974bd4 100644 --- a/packages/wasm/as/assembly/index.ts +++ b/packages/wasm/as/assembly/index.ts @@ -1,11 +1,5 @@ -export { - Read, - ReadDecoder, - Write, - WriteEncoder, - WriteSizer, - Nullable, -} from "./msgpack"; +export { Option } from "as-container"; +export { Read, ReadDecoder, Write, WriteEncoder, WriteSizer } from "./msgpack"; export * from "./json"; export * from "./math"; export * from "./containers"; diff --git a/packages/wasm/as/assembly/msgpack/Nullable.ts b/packages/wasm/as/assembly/msgpack/Nullable.ts deleted file mode 100644 index 3165d50f07..0000000000 --- a/packages/wasm/as/assembly/msgpack/Nullable.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Only class and string types can be -// "nullable" using the `| null` notation. -// Nullable is used for nullable value types. -// https://www.assemblyscript.org/types.html#type-rules -export class Nullable { - private _value: T; - private _nil: bool; - - constructor() { - this.toNull(); - } - - static fromValue(value: T): Nullable { - const nullable = new Nullable(); - nullable.value = value; - return nullable; - } - - static fromNull(): Nullable { - return new Nullable(); - } - - get value(): T { - return this._value; - } - - set value(arg: T) { - this._value = arg; - this._nil = false; - } - - get isNull(): bool { - return this._nil; - } - - toNull(): void { - this._nil = true; - } - - @inline - @operator("==") - protected eq(rhs: Nullable): bool { - if (this._nil) { - return this._nil == rhs._nil; - } else { - return !(rhs._nil || this._value != rhs._value); - } - } - - @inline - @operator("!=") - protected neq(rhs: Nullable): bool { - return !this.eq(rhs); - } -} diff --git a/packages/wasm/as/assembly/msgpack/Read.ts b/packages/wasm/as/assembly/msgpack/Read.ts index 09517b9f0e..317623afbc 100644 --- a/packages/wasm/as/assembly/msgpack/Read.ts +++ b/packages/wasm/as/assembly/msgpack/Read.ts @@ -1,8 +1,9 @@ -import { Nullable } from "./Nullable"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export abstract class Read { abstract readBool(): bool; abstract readInt8(): i8; @@ -32,15 +33,15 @@ export abstract class Read { value_fn: (reader: Read) => V ): Map; - abstract readNullableBool(): Nullable; - abstract readNullableInt8(): Nullable; - abstract readNullableInt16(): Nullable; - abstract readNullableInt32(): Nullable; - abstract readNullableUInt8(): Nullable; - abstract readNullableUInt16(): Nullable; - abstract readNullableUInt32(): Nullable; - abstract readNullableFloat32(): Nullable; - abstract readNullableFloat64(): Nullable; + abstract readNullableBool(): Option; + abstract readNullableInt8(): Option; + abstract readNullableInt16(): Option; + abstract readNullableInt32(): Option; + abstract readNullableUInt8(): Option; + abstract readNullableUInt16(): Option; + abstract readNullableUInt32(): Option; + abstract readNullableFloat32(): Option; + abstract readNullableFloat64(): Option; abstract readNullableString(): string | null; abstract readNullableBytes(): ArrayBuffer | null; abstract readNullableBigInt(): BigInt | null; diff --git a/packages/wasm/as/assembly/msgpack/ReadDecoder.ts b/packages/wasm/as/assembly/msgpack/ReadDecoder.ts index f276810161..3a902eb81e 100644 --- a/packages/wasm/as/assembly/msgpack/ReadDecoder.ts +++ b/packages/wasm/as/assembly/msgpack/ReadDecoder.ts @@ -9,13 +9,14 @@ import { isFixedArray, isFixedString, } from "./Format"; -import { Nullable } from "./Nullable"; import { Read } from "./Read"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; import { ExtensionType } from "./ExtensionType"; +import { Option } from "as-container"; + export class ReadDecoder extends Read { private readonly _context: Context; private _view: DataView; @@ -363,67 +364,67 @@ export class ReadDecoder extends Read { return this.readMap(key_fn, value_fn); } - readNullableBool(): Nullable { + readNullableBool(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readBool()); + return Option.Some(this.readBool()); } - readNullableInt8(): Nullable { + readNullableInt8(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readInt8()); + return Option.Some(this.readInt8()); } - readNullableInt16(): Nullable { + readNullableInt16(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readInt16()); + return Option.Some(this.readInt16()); } - readNullableInt32(): Nullable { + readNullableInt32(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readInt32()); + return Option.Some(this.readInt32()); } - readNullableUInt8(): Nullable { + readNullableUInt8(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readUInt8()); + return Option.Some(this.readUInt8()); } - readNullableUInt16(): Nullable { + readNullableUInt16(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readUInt16()); + return Option.Some(this.readUInt16()); } - readNullableUInt32(): Nullable { + readNullableUInt32(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readUInt32()); + return Option.Some(this.readUInt32()); } - readNullableFloat32(): Nullable { + readNullableFloat32(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readFloat32()); + return Option.Some(this.readFloat32()); } - readNullableFloat64(): Nullable { + readNullableFloat64(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readFloat64()); + return Option.Some(this.readFloat64()); } readNullableString(): string | null { diff --git a/packages/wasm/as/assembly/msgpack/Write.ts b/packages/wasm/as/assembly/msgpack/Write.ts index b02a9ebbbf..f7ff982686 100644 --- a/packages/wasm/as/assembly/msgpack/Write.ts +++ b/packages/wasm/as/assembly/msgpack/Write.ts @@ -1,8 +1,9 @@ -import { Nullable } from "./Nullable"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export abstract class Write { abstract writeNil(): void; abstract writeBool(value: bool): void; @@ -38,15 +39,15 @@ export abstract class Write { value_fn: (writer: Write, value: V) => void ): void; - abstract writeNullableBool(value: Nullable): void; - abstract writeNullableInt8(value: Nullable): void; - abstract writeNullableInt16(value: Nullable): void; - abstract writeNullableInt32(value: Nullable): void; - abstract writeNullableUInt8(value: Nullable): void; - abstract writeNullableUInt16(value: Nullable): void; - abstract writeNullableUInt32(value: Nullable): void; - abstract writeNullableFloat32(value: Nullable): void; - abstract writeNullableFloat64(value: Nullable): void; + abstract writeNullableBool(value: Option): void; + abstract writeNullableInt8(value: Option): void; + abstract writeNullableInt16(value: Option): void; + abstract writeNullableInt32(value: Option): void; + abstract writeNullableUInt8(value: Option): void; + abstract writeNullableUInt16(value: Option): void; + abstract writeNullableUInt32(value: Option): void; + abstract writeNullableFloat32(value: Option): void; + abstract writeNullableFloat64(value: Option): void; abstract writeNullableString(value: string | null): void; abstract writeNullableBytes(value: ArrayBuffer | null): void; abstract writeNullableBigInt(value: BigInt | null): void; diff --git a/packages/wasm/as/assembly/msgpack/WriteEncoder.ts b/packages/wasm/as/assembly/msgpack/WriteEncoder.ts index 8763a348ed..02140973b5 100644 --- a/packages/wasm/as/assembly/msgpack/WriteEncoder.ts +++ b/packages/wasm/as/assembly/msgpack/WriteEncoder.ts @@ -2,13 +2,14 @@ import { DataView } from "./DataView"; import { WriteSizer } from "./WriteSizer"; import { Format } from "./Format"; import { ExtensionType } from "./ExtensionType"; -import { Nullable } from "./Nullable"; import { Write } from "./Write"; import { throwArrayIndexOutOfRange } from "./utils"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export class WriteEncoder extends Write { private readonly _context: Context; private _view: DataView; @@ -234,85 +235,85 @@ export class WriteEncoder extends Write { this.writeMap(m, key_fn, value_fn); } - writeNullableBool(value: Nullable): void { - if (value.isNull) { + writeNullableBool(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeBool(value.value); + this.writeBool(value.unwrap()); } - writeNullableInt8(value: Nullable): void { - if (value.isNull) { + writeNullableInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt8(value.value); + this.writeInt8(value.unwrap()); } - writeNullableInt16(value: Nullable): void { - if (value.isNull) { + writeNullableInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt16(value.value); + this.writeInt16(value.unwrap()); } - writeNullableInt32(value: Nullable): void { - if (value.isNull) { + writeNullableInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt32(value.value); + this.writeInt32(value.unwrap()); } - writeNullableUInt8(value: Nullable): void { - if (value.isNull) { + writeNullableUInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt8(value.value); + this.writeUInt8(value.unwrap()); } - writeNullableUInt16(value: Nullable): void { - if (value.isNull) { + writeNullableUInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt16(value.value); + this.writeUInt16(value.unwrap()); } - writeNullableUInt32(value: Nullable): void { - if (value.isNull) { + writeNullableUInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt32(value.value); + this.writeUInt32(value.unwrap()); } - writeNullableFloat32(value: Nullable): void { - if (value.isNull) { + writeNullableFloat32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat32(value.value); + this.writeFloat32(value.unwrap()); } - writeNullableFloat64(value: Nullable): void { - if (value.isNull) { + writeNullableFloat64(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat64(value.value); + this.writeFloat64(value.unwrap()); } writeNullableString(value: string | null): void { diff --git a/packages/wasm/as/assembly/msgpack/WriteSizer.ts b/packages/wasm/as/assembly/msgpack/WriteSizer.ts index f88aaf639f..4b32fd07c9 100644 --- a/packages/wasm/as/assembly/msgpack/WriteSizer.ts +++ b/packages/wasm/as/assembly/msgpack/WriteSizer.ts @@ -1,9 +1,10 @@ import { Write } from "./Write"; -import { Nullable } from "./Nullable"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export class WriteSizer extends Write { length: i32; extByteLengths: Array; @@ -194,85 +195,85 @@ export class WriteSizer extends Write { this.extByteLengths.push(byteLength); } - writeNullableBool(value: Nullable): void { - if (value.isNull) { + writeNullableBool(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeBool(value.value); + this.writeBool(value.unwrap()); } - writeNullableInt8(value: Nullable): void { - if (value.isNull) { + writeNullableInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt8(value.value); + this.writeInt8(value.unwrap()); } - writeNullableInt16(value: Nullable): void { - if (value.isNull) { + writeNullableInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt16(value.value); + this.writeInt16(value.unwrap()); } - writeNullableInt32(value: Nullable): void { - if (value.isNull) { + writeNullableInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt32(value.value); + this.writeInt32(value.unwrap()); } - writeNullableUInt8(value: Nullable): void { - if (value.isNull) { + writeNullableUInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt8(value.value); + this.writeUInt8(value.unwrap()); } - writeNullableUInt16(value: Nullable): void { - if (value.isNull) { + writeNullableUInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt16(value.value); + this.writeUInt16(value.unwrap()); } - writeNullableUInt32(value: Nullable): void { - if (value.isNull) { + writeNullableUInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt32(value.value); + this.writeUInt32(value.unwrap()); } - writeNullableFloat32(value: Nullable): void { - if (value.isNull) { + writeNullableFloat32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat32(value.value); + this.writeFloat32(value.unwrap()); } - writeNullableFloat64(value: Nullable): void { - if (value.isNull) { + writeNullableFloat64(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat64(value.value); + this.writeFloat64(value.unwrap()); } writeNullableString(value: string | null): void { diff --git a/packages/wasm/as/assembly/msgpack/index.ts b/packages/wasm/as/assembly/msgpack/index.ts index 1ed14b50e4..0f7d2c3630 100644 --- a/packages/wasm/as/assembly/msgpack/index.ts +++ b/packages/wasm/as/assembly/msgpack/index.ts @@ -3,4 +3,3 @@ export * from "./ReadDecoder"; export * from "./Write"; export * from "./WriteEncoder"; export * from "./WriteSizer"; -export * from "./Nullable";