diff --git a/.env b/.env index abde809e..5eb4267a 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -VERSION="2.8.4" +VERSION="2.8.5" MAJOR=2 MINOR=8 -PATCH=4 \ No newline at end of file +PATCH=5 \ No newline at end of file diff --git a/Core/Generators/TypeScript/TypeScriptGenerator.cs b/Core/Generators/TypeScript/TypeScriptGenerator.cs index 476f75fe..a160dc85 100644 --- a/Core/Generators/TypeScript/TypeScriptGenerator.cs +++ b/Core/Generators/TypeScript/TypeScriptGenerator.cs @@ -315,14 +315,14 @@ public string CompileJsonMethods(Definition definition) { var builder = new IndentedStringBuilder(0); builder.AppendLine(FormatDocumentation("Serializes the current instance into a JSON-Over-Bebop string", string.Empty, 0)); - builder.CodeBlock($"public toJson(): string", indentStep, () => + builder.CodeBlock($"public toJSON(): string", indentStep, () => { - builder.AppendLine($"return {definition.ClassName()}.encodeToJson(this);"); + builder.AppendLine($"return {definition.ClassName()}.encodeToJSON(this);"); }); builder.AppendLine(); builder.AppendLine(FormatDocumentation("Serializes the specified object into a JSON-Over-Bebop string", string.Empty, 0)); - builder.CodeBlock($"public static encodeToJson(record: I{definition.ClassName()}): string", indentStep, () => + builder.CodeBlock($"public static encodeToJSON(record: I{definition.ClassName()}): string", indentStep, () => { if (definition is UnionDefinition) { @@ -365,11 +365,11 @@ public string CompileJsonMethods(Definition definition) }); builder.AppendLine(); builder.AppendLine(FormatDocumentation($"Creates a new {{@link {definition.ClassName()}}} instance from a JSON-Over-Bebop string. Type checking is performed.", string.Empty, 0)); - builder.CodeBlock($"public static fromJson(json: string): {returnType}", indentStep, () => + builder.CodeBlock($"public static fromJSON(json: string): {returnType}", indentStep, () => { builder.CodeBlock("if (typeof json !== 'string' || json.trim().length === 0)", indentStep, () => { - builder.AppendLine($"throw new BebopRuntimeError(`{definition.ClassName()}.fromJson: expected string`);"); + builder.AppendLine($"throw new BebopRuntimeError(`{definition.ClassName()}.fromJSON: expected string`);"); }); builder.AppendLine("const parsed = JSON.parse(json, BebopJson.reviver);"); builder.AppendLine($"{definition.ClassName()}.validateCompatibility(parsed);"); @@ -976,8 +976,8 @@ public override string Compile(Version? languageVersion, TempoServices services builder.AppendLine($"invoke: service.{methodName},"); builder.AppendLine($"serialize: {method.Definition.ReturnDefintion}.encode,"); builder.AppendLine($"deserialize: {method.Definition.RequestDefinition}.decode,"); - builder.AppendLine($"toJson: {method.Definition.ReturnDefintion}.encodeToJson,"); - builder.AppendLine($"fromJson: {method.Definition.RequestDefinition}.fromJson,"); + builder.AppendLine($"toJSON: {method.Definition.ReturnDefintion}.encodeToJSON,"); + builder.AppendLine($"fromJSON: {method.Definition.RequestDefinition}.fromJSON,"); builder.AppendLine($"type: MethodType.{RpcSchema.GetMethodTypeName(methodType)},"); }, close: $"}} as BebopMethod);"); } @@ -1049,8 +1049,8 @@ public override string Compile(Version? languageVersion, TempoServices services builder.AppendLine($"id: {method.Id},"); builder.AppendLine($"serialize: {method.Definition.RequestDefinition}.encode,"); builder.AppendLine($"deserialize: {method.Definition.ReturnDefintion}.decode,"); - builder.AppendLine($"toJson: {method.Definition.RequestDefinition}.encodeToJson,"); - builder.AppendLine($"fromJson: {method.Definition.ReturnDefintion}.fromJson,"); + builder.AppendLine($"toJSON: {method.Definition.RequestDefinition}.encodeToJSON,"); + builder.AppendLine($"fromJSON: {method.Definition.ReturnDefintion}.fromJSON,"); builder.AppendLine($"type: MethodType.{RpcSchema.GetMethodTypeName(methodType)},"); }); diff --git a/Laboratory/TypeScript/benchmark/jsonoverbebop.ts b/Laboratory/TypeScript/benchmark/jsonoverbebop.ts index cca74dbc..5a69302f 100644 --- a/Laboratory/TypeScript/benchmark/jsonoverbebop.ts +++ b/Laboratory/TypeScript/benchmark/jsonoverbebop.ts @@ -13,7 +13,7 @@ const song = new G.Song({ ], }); -const encodedJsonLib = song.toJson(); +const encodedJsonLib = song.toJSON(); const encodedBinaryLib = song.encode(); const standardJson = JSON.stringify(song); console.log(standardJson) @@ -23,7 +23,7 @@ suite.add(`encode binary bebop`, () => { G.Song.encode(song); }); suite.add(`encode json-over-bebop`, function () { - G.Song.encodeToJson(song); + G.Song.encodeToJSON(song); }); suite.add(`encode standard json`, function () { @@ -35,7 +35,7 @@ suite.add(`decode binary bebop`, () => { }); suite.add(`decode json-over-bebop`, function () { - G.Song.fromJson(encodedJsonLib); + G.Song.fromJSON(encodedJsonLib); }); suite.add(`decode standard json`, function () { diff --git a/Laboratory/TypeScript/test/json.ts b/Laboratory/TypeScript/test/json.ts index e182e9c1..af657ac4 100644 --- a/Laboratory/TypeScript/test/json.ts +++ b/Laboratory/TypeScript/test/json.ts @@ -18,7 +18,7 @@ it("Roundtrips a flat object to JSON-Over-Bebop", () => { a_date: new Date(Date.UTC(1996, 1, 7)), }; - const json = G.BasicTypes.encodeToJson(obj); + const json = G.BasicTypes.encodeToJSON(obj); const rawParse = JSON.parse(json); expect(rawParse).toMatchObject({ a_bool: true, @@ -35,7 +35,7 @@ it("Roundtrips a flat object to JSON-Over-Bebop", () => { a_guid: { "#btype": 5, value: "01234567-0123-0123-0123-0123456789ab" }, a_date: { "#btype": 2, value: "629592480000000000" }, }); - expect(() => G.BasicTypes.fromJson(json)).not.toThrow(); + expect(() => G.BasicTypes.fromJSON(json)).not.toThrow(); }); it("Fails to roundtrip a flat object to JSON-Over-Bebop", () => { @@ -58,7 +58,7 @@ it("Fails to roundtrip a flat object to JSON-Over-Bebop", () => { obj, (key, value) => (typeof value === "bigint" ? value.toString() : value) // return everything else unchanged ); - expect(() => G.BasicTypes.fromJson(json)).toThrow(BebopRuntimeError); + expect(() => G.BasicTypes.fromJSON(json)).toThrow(BebopRuntimeError); }); it("Roundtrips a nested map object to JSON-Over-Bebop", () => { @@ -94,8 +94,8 @@ it("Roundtrips a nested map object to JSON-Over-Bebop", () => { ], ]), }; - const json = G.SomeMaps.encodeToJson(obj); - expect(() => G.SomeMaps.fromJson(json)).not.toThrow(); + const json = G.SomeMaps.encodeToJSON(obj); + expect(() => G.SomeMaps.fromJSON(json)).not.toThrow(); }); it("Roundtrips jazz to JSON-Over-Bebop", () => { @@ -117,6 +117,6 @@ it("Roundtrips jazz to JSON-Over-Bebop", () => { ]), }; - const json = G.Library.encodeToJson(lib); - expect(() => G.Library.fromJson(json)).not.toThrow(); + const json = G.Library.encodeToJSON(lib); + expect(() => G.Library.fromJSON(json)).not.toThrow(); });