orm id and type > @id, @type

feat/orm-diffs
Laurin Weger 1 day ago
parent 1282b9e006
commit d45ebc340f
No known key found for this signature in database
GPG Key ID: 9B372BB0B792770F
  1. 2
      engine/verifier/src/orm/handle_backend_update.rs
  2. 41
      sdk/js/shex-orm/src/schema-converter/util/annotateReadablePredicates.ts
  3. 4
      sdk/rust/src/tests/mod.rs
  4. 10
      sdk/rust/src/tests/orm_create_patches.rs
  5. 34
      sdk/rust/src/tests/orm_creation.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)),
});
}

@ -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<string, TCwReadable[]>();
for (const tc of tcs) {
const tokens = splitIriTokens(tc.predicate);
const local = tokens.length
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]
: tc.predicate;
: 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<string>();
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)

@ -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);

@ -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",

@ -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": {

Loading…
Cancel
Save