Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 7954c86

Browse files
JSON serialization fixes (#220)
## What is the goal of this PR? We update serialization API from `JSON()` to more canonical `toJSONRecord()`* and update the BDD test steps to reflect the changes in typedb-behaviour (typedb/typedb-behaviour#240). \* We're avoiding `toJSON()` as it is reserved by JavaScript for built-in JSON serialization. Since our JSON representation is lossy, we'd like the user to be explicit in their intent.
1 parent fe7b4ad commit 7954c86

File tree

12 files changed

+59
-30
lines changed

12 files changed

+59
-30
lines changed

BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ filegroup(
6767

6868
behaviour_steps_common = [
6969
"//test/behaviour/connection:ConnectionStepsBase.ts",
70-
"//test/behaviour/concept/serialization:SerializationSteps.ts",
70+
"//test/behaviour/concept/serialization/json:JSONSteps.ts",
7171
"//test/behaviour/concept/thing:ThingSteps.ts",
7272
"//test/behaviour/concept/thing/attribute:AttributeSteps.ts",
7373
"//test/behaviour/concept/thing/entity:EntitySteps.ts",

api/answer/ConceptMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface ConceptMap {
3131

3232
readonly explainables: ConceptMap.Explainables;
3333

34-
JSON(): Record<string, Record<string, boolean | string | number>>;
34+
toJSONRecord(): Record<string, Record<string, boolean | string | number>>;
3535
}
3636

3737
export namespace ConceptMap {

api/concept/Concept.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export interface Concept {
8080

8181
equals(concept: Concept): boolean;
8282

83-
JSON(): Record<string, boolean | string | number>;
83+
toJSONRecord(): Record<string, boolean | string | number>;
8484
}
8585

8686
export namespace Concept {

concept/ConceptImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export abstract class ConceptImpl implements Concept {
127127

128128
abstract equals(concept: Concept): boolean;
129129

130-
abstract JSON(): Record<string, boolean | string | number>;
130+
abstract toJSONRecord(): Record<string, boolean | string | number>;
131131
}
132132

133133
export namespace ConceptImpl {

concept/answer/ConceptMapImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ export class ConceptMapImpl implements ConceptMap {
5353
return this._explainables;
5454
}
5555

56-
JSON(): Record<string, Record<string, boolean | string | number>> {
56+
toJSONRecord(): Record<string, Record<string, boolean | string | number>> {
5757
const object: Record<string, Record<string, boolean | string | number>> = {}
5858
for (const key of this._concepts.keys()) {
59-
object[key] = this._concepts.get(key).JSON();
59+
object[key] = this._concepts.get(key).toJSONRecord();
6060
}
6161
return object;
6262
}

concept/thing/AttributeImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export abstract class AttributeImpl extends ThingImpl implements Attribute {
7979
return this;
8080
}
8181

82-
JSON(): Record<string, boolean | string | number> {
82+
toJSONRecord(): Record<string, boolean | string | number> {
8383
let value;
8484
if (this.value instanceof Date) value = this.value.toISOString().slice(0, -1);
8585
else value = this.value;
@@ -191,7 +191,7 @@ export namespace AttributeImpl {
191191
return this;
192192
}
193193

194-
JSON(): Record<string, boolean | string | number> {
194+
toJSONRecord(): Record<string, boolean | string | number> {
195195
let value;
196196
if (this.value instanceof Date) value = this.value.toISOString().slice(0, -1);
197197
else value = this.value;

concept/thing/ThingImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export abstract class ThingImpl extends ConceptImpl implements Thing {
7777
return this;
7878
}
7979

80-
JSON(): Record<string, boolean | string | number> {
80+
toJSONRecord(): Record<string, boolean | string | number> {
8181
return {type: this.type.label.name};
8282
}
8383
}
@@ -125,7 +125,7 @@ export namespace ThingImpl {
125125
return this;
126126
}
127127

128-
JSON(): Record<string, boolean | string | number> {
128+
toJSONRecord(): Record<string, boolean | string | number> {
129129
return {type: this.type.label.name};
130130
}
131131

concept/type/TypeImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export abstract class TypeImpl extends ConceptImpl implements Type {
6868
return this;
6969
}
7070

71-
JSON(): Record<string, string> {
71+
toJSONRecord(): Record<string, string> {
7272
return {label: this.label.scopedName};
7373
}
7474

@@ -129,7 +129,7 @@ export namespace TypeImpl {
129129
return this;
130130
}
131131

132-
JSON(): Record<string, string> {
132+
toJSONRecord(): Record<string, string> {
133133
return {label: this.label.scopedName};
134134
}
135135

dependencies/vaticle/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def vaticle_typedb_behaviour():
4040
git_repository(
4141
name = "vaticle_typedb_behaviour",
4242
remote = "https://github.com/vaticle/typedb-behaviour",
43-
commit = "46619244d5f1773505eeacf6d5bd0ae71781f8e8" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
43+
commit = "ff4f58b4db2200b907c60b28a2b8ee661449e9c0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
4444
)

test/behaviour/concept/serialization/BUILD

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,8 @@
2222
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
2323
load("//test/behaviour:rules.bzl", "typedb_behaviour_node_test")
2424

25-
exports_files(["SerializationSteps.ts"])
26-
2725
checkstyle_test(
2826
name = "checkstyle",
2927
include = glob(["*"]),
3028
license_type = "apache-header",
3129
)
32-
33-
typedb_behaviour_node_test(
34-
name = "test",
35-
features = ["@vaticle_typedb_behaviour//concept:serialization.feature"],
36-
node_modules = "//:node_modules",
37-
package_json = "//:package.json",
38-
native_typedb_artifact_core = "//test:native-typedb-artifact",
39-
native_typedb_artifact_cluster = "//test:native-typedb-cluster-artifact",
40-
client = "//:client-nodejs-targz",
41-
steps_core = "//test/behaviour:steps-core-targz",
42-
steps_cluster = "//test/behaviour:steps-cluster-targz",
43-
)

0 commit comments

Comments
 (0)