diff --git a/engine/verifier/src/orm/handle_backend_update.rs b/engine/verifier/src/orm/handle_backend_update.rs index 1ac9b9f..3d4497b 100644 --- a/engine/verifier/src/orm/handle_backend_update.rs +++ b/engine/verifier/src/orm/handle_backend_update.rs @@ -267,7 +267,7 @@ impl Verifier { patches.push(OrmDiffOp { op: OrmDiffOpType::add, valType: None, - path: format!("{}/id", json_pointer), + path: format!("{}/@id", json_pointer), value: Some(json!(iri)), }); } diff --git a/sdk/js/shex-orm/src/schema-converter/util/annotateReadablePredicates.ts b/sdk/js/shex-orm/src/schema-converter/util/annotateReadablePredicates.ts index b5eb624..763a087 100644 --- a/sdk/js/shex-orm/src/schema-converter/util/annotateReadablePredicates.ts +++ b/sdk/js/shex-orm/src/schema-converter/util/annotateReadablePredicates.ts @@ -33,25 +33,40 @@ export default function annotateReadablePredicates(schema: Schema): void { if (tcs.length > 0) { // Group by local token (last segment of IRI) and set a base readablePredicate for all - const groups = new Map(); - for (const tc of tcs) { - const tokens = splitIriTokens(tc.predicate); - const local = tokens.length - ? tokens[tokens.length - 1] - : tc.predicate; + const readableNameToPredicatesMap = new Map< + string, + TCwReadable[] + >(); + for (const tripleConstraint of tcs) { + // Use the name based on the IRI ending. + let readableName: string; + // Special case rdfs:type => @type + if ( + tripleConstraint.predicate === + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + ) { + readableName = "@type"; + } else { + const tokens = splitIriTokens(tripleConstraint.predicate); + readableName = tokens.length + ? tokens[tokens.length - 1] + : tripleConstraint.predicate; + } // default base name for non-colliders - tc.readablePredicate = local; - const arr = groups.get(local) ?? []; - arr.push(tc); - groups.set(local, arr); + tripleConstraint.readablePredicate = readableName; + const groupMembers = + readableNameToPredicatesMap.get(readableName) ?? []; + groupMembers.push(tripleConstraint); + readableNameToPredicatesMap.set(readableName, groupMembers); } // Resolve each group (rename all in collisions) - for (const [, arr] of groups) { - if (arr.length <= 1) continue; + for (const [, groupMembers] of readableNameToPredicatesMap) { + if (groupMembers.length <= 1) continue; const used = new Set(); const local = - splitIriTokens(arr[0].predicate).slice(-1)[0] ?? ""; - for (const tc of arr) { + splitIriTokens(groupMembers[0].predicate).slice(-1)[0] ?? + ""; + for (const tc of groupMembers) { const tokens = splitIriTokens(tc.predicate); let localIdx = tokens.lastIndexOf(local); if (localIdx === -1) diff --git a/sdk/rust/src/tests/mod.rs b/sdk/rust/src/tests/mod.rs index a389234..c204b56 100644 --- a/sdk/rust/src/tests/mod.rs +++ b/sdk/rust/src/tests/mod.rs @@ -86,14 +86,14 @@ fn sort_arrays(value: &mut Value) { } } -/// Helper to recursively remove nested "id" fields from nested objects, +/// Helper to recursively remove nested "@id" fields from nested objects, /// but only if they are not at the root level. fn remove_id_fields(value: &mut Value) { fn remove_id_fields_inner(value: &mut Value, is_root: bool) { match value { Value::Object(map) => { if !is_root { - map.remove("id"); + map.remove("@id"); } for v in map.values_mut() { remove_id_fields_inner(v, false); diff --git a/sdk/rust/src/tests/orm_create_patches.rs b/sdk/rust/src/tests/orm_create_patches.rs index 6c93847..f25807f 100644 --- a/sdk/rust/src/tests/orm_create_patches.rs +++ b/sdk/rust/src/tests/orm_create_patches.rs @@ -209,7 +209,7 @@ INSERT DATA { { "op": "add", "value": "urn:test:numArrayObj4", - "path": "/urn:test:numArrayObj4/id", + "path": "/urn:test:numArrayObj4/@id", "valType": Value::Null, }, { @@ -575,7 +575,7 @@ INSERT DATA { "op": "add", // "valType": None, "value": "urn:test:multiNested4", - "path": "/urn:test:oj1/multiNest/urn:test:multiNested4/id", + "path": "/urn:test:oj1/multiNest/urn:test:multiNested4/@id", }, { "op": "add", @@ -882,7 +882,7 @@ INSERT DATA { { "op": "add", "value": "urn:test:cat2", - "path": "/urn:test:house1/inhabitants/urn:test:person2/cat/id", + "path": "/urn:test:house1/inhabitants/urn:test:person2/cat/@id", }, { "op": "add", @@ -903,7 +903,7 @@ INSERT DATA { { "op": "add", "value": "urn:test:person3", - "path": "/urn:test:house1/inhabitants/urn:test:person3/id", + "path": "/urn:test:house1/inhabitants/urn:test:person3/@id", }, { "op": "add", @@ -923,7 +923,7 @@ INSERT DATA { { "op": "add", "value": "urn:test:cat3", - "path": "/urn:test:house1/inhabitants/urn:test:person3/cat/id", + "path": "/urn:test:house1/inhabitants/urn:test:person3/cat/@id", }, { "op": "add", diff --git a/sdk/rust/src/tests/orm_creation.rs b/sdk/rust/src/tests/orm_creation.rs index 9d2efec..52d017b 100644 --- a/sdk/rust/src/tests/orm_creation.rs +++ b/sdk/rust/src/tests/orm_creation.rs @@ -448,7 +448,7 @@ INSERT DATA { let mut expected = json!([{ "type":"http://example.org/TestObject", - "id":"urn:test:obj1", + "@id":"urn:test:obj1", "anotherObject":{ "urn:test:id1":{ "prop1":"one", @@ -465,7 +465,7 @@ INSERT DATA { "numOrStr":"either", "numValue":42.0, "objectValue":{ - "id":"urn:test:id3", + "@id":"urn:test:id3", "nestedArray":[5.0,6.0], "nestedNum":7.0, "nestedString":"nested" @@ -473,7 +473,7 @@ INSERT DATA { "stringValue": "hello world", }, { - "id":"urn:test:obj2", + "@id":"urn:test:obj2", "type":"http://example.org/TestObject", "anotherObject": { "urn:test:id4":{ @@ -491,7 +491,7 @@ INSERT DATA { "numOrStr":4.0, "numValue":422.0, "objectValue":{ - "id":"urn:test:id6", + "@id":"urn:test:id6", "nestedArray": [7.0,8.0,9.0], "nestedNum":72.0, "nestedString":"nested2" @@ -602,17 +602,17 @@ INSERT DATA { let mut expected = json!([ { - "id": "urn:test:numArrayObj1", + "@id": "urn:test:numArrayObj1", "type": "http://example.org/TestObject", "numArray": [1.0, 2.0, 3.0] }, { - "id": "urn:test:numArrayObj2", + "@id": "urn:test:numArrayObj2", "type": "http://example.org/TestObject", "numArray": [] }, { - "id": "urn:test:numArrayObj3", + "@id": "urn:test:numArrayObj3", "type": "http://example.org/TestObject", "numArray": [1.0, 2.0] } @@ -689,7 +689,7 @@ INSERT DATA { let mut expected = json!([ { - "id": "urn:test:oj1", + "@id": "urn:test:oj1", "opt": true } ]); @@ -786,12 +786,12 @@ INSERT DATA { let mut expected = json!([ { - "id": "urn:test:oj1", + "@id": "urn:test:oj1", "lit1": ["lit 1"], "lit2": "lit 2" }, { - "id": "urn:test:obj2", + "@id": "urn:test:obj2", "lit1": ["lit 1", "lit 1 extra"], "lit2": "lit 2" } @@ -878,7 +878,7 @@ INSERT DATA { let mut expected = json!([ { - "id": "urn:test:oj1", + "@id": "urn:test:oj1", "strOrNum": ["a string", "another string", 2.0] } ]); @@ -1079,7 +1079,7 @@ INSERT DATA { let mut expected = json!([ { - "id": "urn:test:oj1", + "@id": "urn:test:oj1", "str": "obj1 str", "nestedWithExtra": { "nestedStr": "obj1 nested with extra valid", @@ -1199,7 +1199,7 @@ INSERT DATA { // claire2 is invalid (missing name), so alice2's knows chain is incomplete let mut expected = json!([ { - "id": "urn:test:alice", + "@id": "urn:test:alice", "name": "Alice", "knows": { "urn:test:bob": { @@ -1218,7 +1218,7 @@ INSERT DATA { } }, { - "id": "urn:test:bob", + "@id": "urn:test:bob", "name": "Bob", "knows": { "urn:test:claire": { @@ -1228,7 +1228,7 @@ INSERT DATA { } }, { - "id": "urn:test:claire", + "@id": "urn:test:claire", "name": "Claire", "knows": {} } @@ -1411,7 +1411,7 @@ INSERT DATA { // alice2 is incomplete because claire2 has wrong type let mut expected = json!([ { - "id": "urn:test:alice", + "@id": "urn:test:alice", "type": "http://example.org/Alice", "knows": { "urn:test:bob": { @@ -1538,7 +1538,7 @@ INSERT DATA { let mut expected = json!([ { - "id": "urn:test:alice", + "@id": "urn:test:alice", "type": "http://example.org/Person", "cats": { "urn:test:kitten1": {