feat/orm
Laurin Weger 3 weeks ago
parent b8f70f0c47
commit d3c825800e
No known key found for this signature in database
GPG Key ID: 9B372BB0B792770F
  1. 192
      Cargo.lock
  2. 1
      nextgraph/.gitignore
  3. 7
      nextgraph/examples/open.rs
  4. 5
      nextgraph/src/lib.rs
  5. BIN
      nextgraph/src/tests/1-pixel.png
  6. 0
      nextgraph/src/tests/get_or_create_wallet.rs
  7. 11
      nextgraph/src/tests/mod.rs
  8. 186
      nextgraph/src/tests/orm.rs
  9. 14
      ng-broker/Cargo.toml
  10. 70
      ng-net/src/orm.rs
  11. 13
      ng-verifier/Cargo.toml
  12. 1
      ng-verifier/src/lib.rs
  13. 2
      ng-verifier/src/orm.rs
  14. 11
      sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/shapeHandler.ts
  15. 4
      sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/sparql/buildConstruct.ts
  16. 2
      sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/sparql/buildSparqlConstructFromShape.ts
  17. 30
      sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/sparql/testShape.schema.ts
  18. 16
      sdk/ng-sdk-js/examples/multi-framework-signals/src/shapes/ldo/catShape.schema.ts
  19. 14
      sdk/ng-sdk-js/examples/multi-framework-signals/src/shapes/ldo/personShape.schema.ts
  20. 32
      sdk/ng-sdk-js/examples/multi-framework-signals/src/shapes/ldo/testShape.schema.ts
  21. 3
      sdk/ng-sdk-js/ng-shex-orm/src/schema-converter/converter.ts
  22. 18
      sdk/ng-sdk-js/ng-shex-orm/src/schema-converter/transformers/ShexJSchemaTransformer.ts
  23. 10
      sdk/ng-sdk-js/ng-shex-orm/src/types.ts
  24. 7
      sdk/ng-sdk-js/src/lib.rs

192
Cargo.lock generated

@ -97,9 +97,9 @@ checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
[[package]]
name = "anyhow"
version = "1.0.99"
version = "1.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
[[package]]
name = "arc-swap"
@ -604,9 +604,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
version = "1.2.37"
version = "1.2.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65193589c6404eb80b450d618eaf9a2cafaaafd57ecce47370519ef674a7bd44"
checksum = "80f41ae168f955c12fb8960b057d70d0ca153fb83182b57d86380443527be7e9"
dependencies = [
"find-msvc-tools",
"jobserver",
@ -704,18 +704,18 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.47"
version = "4.5.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931"
checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.47"
version = "4.5.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6"
checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9"
dependencies = [
"anstyle",
"clap_lex",
@ -1205,9 +1205,9 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
[[package]]
name = "find-msvc-tools"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959"
[[package]]
name = "flate2"
@ -1410,7 +1410,7 @@ dependencies = [
"js-sys",
"libc",
"r-efi",
"wasi 0.14.5+wasi-0.2.4",
"wasi 0.14.7+wasi-0.2.4",
"wasm-bindgen",
]
@ -1522,9 +1522,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.15.5"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
[[package]]
name = "heapless"
@ -1775,9 +1775,9 @@ checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284"
[[package]]
name = "indexmap"
version = "2.11.1"
version = "2.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206a8042aec68fa4a62e8d3f7aa4ceb508177d9324faf261e1959e495b7a1921"
checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5"
dependencies = [
"equivalent",
"hashbrown",
@ -1865,9 +1865,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.78"
version = "0.3.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c0b063578492ceec17683ef2f8c5e89121fbd0b172cbc280635ab7567db2738"
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305"
dependencies = [
"once_cell",
"wasm-bindgen",
@ -1925,18 +1925,18 @@ checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8"
[[package]]
name = "libc"
version = "0.2.175"
version = "0.2.176"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174"
[[package]]
name = "libloading"
version = "0.8.8"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
dependencies = [
"cfg-if",
"windows-targets 0.53.3",
"windows-link",
]
[[package]]
@ -2420,6 +2420,7 @@ dependencies = [
"ng-oxigraph",
"ng-repo",
"ng-storage-rocksdb",
"once_cell",
"qrcode",
"rand 0.7.3",
"sbbf-rs-safe",
@ -2839,9 +2840,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "plist"
version = "1.7.4"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1"
checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07"
dependencies = [
"base64 0.22.1",
"indexmap",
@ -3407,9 +3408,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
[[package]]
name = "serde"
version = "1.0.222"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aab69e3f5be1836a1fe0aca0b286e5a5b38f262d6c9e8acd2247818751fcc8fb"
checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd"
dependencies = [
"serde_core",
"serde_derive",
@ -3446,9 +3447,9 @@ dependencies = [
[[package]]
name = "serde_bytes"
version = "0.11.18"
version = "0.11.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe07b5d88710e3b807c16a06ccbc9dfecd5fff6a4d2745c59e3e26774f10de6a"
checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8"
dependencies = [
"serde",
"serde_core",
@ -3456,18 +3457,18 @@ dependencies = [
[[package]]
name = "serde_core"
version = "1.0.222"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f8ebec5eea07db7df9342aa712db2138f019d9ab3454a60a680579a6f841b80"
checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.222"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5f61630fe26d0ff555e6c37dc445ab2f15871c8a11ace3cf471b3195d3e4f49"
checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33"
dependencies = [
"proc-macro2",
"quote",
@ -3790,9 +3791,9 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.22.0"
version = "3.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84fa4d11fadde498443cca10fd3ac23c951f0dc59e080e9f4b93d4df4e4eea53"
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
dependencies = [
"fastrand",
"getrandom 0.3.3",
@ -4204,18 +4205,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasi"
version = "0.14.5+wasi-0.2.4"
version = "0.14.7+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4494f6290a82f5fe584817a676a34b9d6763e8d9d18204009fb31dceca98fd4"
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
dependencies = [
"wasip2",
]
[[package]]
name = "wasip2"
version = "1.0.0+wasi-0.2.4"
version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03fa2761397e5bd52002cd7e73110c71af2109aca4e521a9f40473fe685b0a24"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
dependencies = [
"wit-bindgen",
]
@ -4228,9 +4229,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
[[package]]
name = "wasm-bindgen"
version = "0.2.101"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e14915cadd45b529bb8d1f343c4ed0ac1de926144b746e2710f9cd05df6603b"
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d"
dependencies = [
"cfg-if",
"once_cell",
@ -4243,9 +4244,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.101"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28d1ba982ca7923fd01448d5c30c6864d0a14109560296a162f80f305fb93bb"
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
dependencies = [
"bumpalo",
"log",
@ -4257,9 +4258,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.51"
version = "0.4.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca85039a9b469b38336411d6d6ced91f3fc87109a2a27b0c197663f5144dffe"
checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c"
dependencies = [
"cfg-if",
"js-sys",
@ -4270,9 +4271,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.101"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c3d463ae3eff775b0c45df9da45d68837702ac35af998361e2c84e7c5ec1b0d"
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -4280,9 +4281,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.101"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bb4ce89b08211f923caf51d527662b75bdc9c9c7aab40f86dcb9fb85ac552aa"
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7"
dependencies = [
"proc-macro2",
"quote",
@ -4293,18 +4294,18 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.101"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f143854a3b13752c6950862c906306adb27c7e839f7414cec8fea35beab624c1"
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1"
dependencies = [
"unicode-ident",
]
[[package]]
name = "wasm-bindgen-test"
version = "0.3.51"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80cc7f8a4114fdaa0c58383caf973fc126cf004eba25c9dc639bccd3880d55ad"
checksum = "4e381134e148c1062f965a42ed1f5ee933eef2927c3f70d1812158f711d39865"
dependencies = [
"js-sys",
"minicov",
@ -4315,9 +4316,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.3.51"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5ada2ab788d46d4bda04c9d567702a79c8ced14f51f221646a16ed39d0e6a5d"
checksum = "b673bca3298fe582aeef8352330ecbad91849f85090805582400850f8270a2e8"
dependencies = [
"proc-macro2",
"quote",
@ -4326,9 +4327,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.78"
version = "0.3.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77e4b637749ff0d92b8fad63aa1f7cff3cbe125fd49c175cd6345e7272638b12"
checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -4412,12 +4413,6 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-link"
version = "0.2.0"
@ -4466,7 +4461,7 @@ version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa"
dependencies = [
"windows-link 0.2.0",
"windows-link",
]
[[package]]
@ -4493,30 +4488,13 @@ dependencies = [
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm 0.52.6",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
name = "windows-targets"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link 0.1.3",
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
"windows_i686_gnullvm 0.53.0",
"windows_i686_msvc 0.53.0",
"windows_x86_64_gnu 0.53.0",
"windows_x86_64_gnullvm 0.53.0",
"windows_x86_64_msvc 0.53.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
@ -4529,12 +4507,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
@ -4547,12 +4519,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
@ -4565,24 +4531,12 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
@ -4595,12 +4549,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_i686_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
@ -4613,12 +4561,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
@ -4631,12 +4573,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
@ -4649,12 +4585,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]]
name = "winnow"
version = "0.5.40"
@ -4676,9 +4606,9 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.45.1"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "writeable"

@ -1,2 +1 @@
tests
local_broker_dev_env_peer_id.rs

@ -32,7 +32,10 @@ async fn main() -> std::io::Result<()> {
}))
.await;
let wallet_name = "9ivXl3TpgcQlDKTmR9NOipjhPWxQw6Yg5jkWBTlJuXw".to_string();
let wallet_name = "Cd4ZEobTMItCai1mQIJ__nyZ1LS0b1a1C6NATo0IDMMA".to_string();
let a = 32;
a = "";
// as we have previously saved the wallet,
// we can retrieve it, display the security phrase and image to the user, ask for the pazzle or mnemonic, and then open the wallet
@ -43,7 +46,7 @@ async fn main() -> std::io::Result<()> {
// now let's open the wallet, by providing the pazzle and PIN code
let opened_wallet = wallet_open_with_pazzle(
&wallet,
vec![110, 139, 115, 94, 9, 40, 74, 25, 52],
vec![3, 57, 142, 91, 118, 78, 108, 27, 35],
[2, 3, 2, 3],
)?;

@ -130,7 +130,7 @@ pub fn get_device_name() -> String {
}
#[cfg(target_arch = "wasm32")]
if let Ok(distro) = whoami::fallible::distro() {
list.push(distro.replace("Unknown ",""));
list.push(distro.replace("Unknown ", ""));
}
list.join(" ")
@ -138,3 +138,6 @@ pub fn get_device_name() -> String {
#[cfg(debug_assertions)]
mod local_broker_dev_env;
#[cfg(test)]
mod tests;

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

@ -0,0 +1,11 @@
// Copyright (c) 2022-2025 Niko Bonnieure, Par le Peuple, NextGraph.org developers
// All rights reserved.
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
#[doc(hidden)]
pub mod orm;

@ -0,0 +1,186 @@
// Copyright (c) 2022-2025 Niko Bonnieure, Par le Peuple, NextGraph.org developers
// All rights reserved.
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
use std::env::current_dir;
use std::error::Error;
use std::fs::{self, create_dir_all, read, File};
use std::io::{Read, Write};
use std::path::PathBuf;
use crate::local_broker::{
doc_sparql_update, init_local_broker, session_start, session_stop, user_connect,
user_disconnect, wallet_close, wallet_create_v0, wallet_get, wallet_get_file,
wallet_open_with_mnemonic_words, wallet_read_file, wallet_was_opened, LocalBrokerConfig,
SessionConfig,
};
use ng_net::types::BootstrapContentV0;
use ng_repo::types::PubKey;
use ng_wallet::display_mnemonic; // to persist mnemonic as words
use ng_wallet::types::{CreateWalletV0, SensitiveWallet, SensitiveWalletV0};
use once_cell::sync::OnceCell;
static WALLET_PIN: [u8; 4] = [2, 3, 2, 3];
// Persistent test assets (wallet base path + stored credentials)
fn test_base_path() -> PathBuf {
let mut current_path = current_dir().expect("current_dir");
current_path.push(".ng");
create_dir_all(current_path.clone()).expect("create test base path");
current_path
}
fn build_wallet_and_creds_paths() -> (PathBuf, PathBuf) {
let mut current_path = current_dir().expect("current_dir");
current_path.push(".ng");
create_dir_all(current_path.clone()).expect("create test base path");
return (
current_path.join("test_wallet.ngw"),
current_path.join("wallet_creds.txt"),
);
}
static INIT: OnceCell<()> = OnceCell::new();
async fn init_broker() {
if INIT.get().is_none() {
let base = test_base_path();
fs::create_dir_all(&base).expect("create base path");
init_local_broker(Box::new(move || LocalBrokerConfig::BasePath(base.clone()))).await;
let _ = INIT.set(());
}
}
async fn create_or_open_wallet() -> (SensitiveWallet, u64) {
init_broker().await;
let wallet;
let session_id: u64;
let (wallet_path, creds_path) = build_wallet_and_creds_paths();
if wallet_path.exists() {
let wallet_file = read("./.ng/test-wallet.ngw").expect("read wallet file");
// load stored wallet_name + mnemonic
let mut s = String::new();
File::open(creds_path)
.expect("open creds")
.read_to_string(&mut s)
.expect("read creds");
let mut lines = s.lines();
let mnemonic_line = lines.next().expect("missing mnemonic").to_string();
let mnemonic_words: Vec<String> = mnemonic_line
.split_whitespace()
.map(|s| s.to_string())
.collect();
let read_wallet = wallet_read_file(wallet_file).await.unwrap();
wallet =
wallet_open_with_mnemonic_words(&read_wallet, &mnemonic_words, WALLET_PIN).unwrap();
let session = session_start(SessionConfig::new_in_memory(
&wallet.personal_identity(),
&read_wallet.name(),
))
.await
.unwrap();
session_id = session.session_id;
} else {
// first run: create wallet
// Load a real security image from the nextgraph examples to satisfy validation
let security_img = read("./1-pixel.png").unwrap();
// .or_else(|_| read("../nextgraph/examples/wallet-security-image-white.png"))
// .expect("security image");
let peer_id_of_server_broker = PubKey::nil();
let result = wallet_create_v0(CreateWalletV0 {
security_img,
security_txt: "know yourself".to_string(),
pin: WALLET_PIN,
pazzle_length: 9,
send_bootstrap: false,
send_wallet: false,
result_with_wallet_file: false,
local_save: true,
core_bootstrap: BootstrapContentV0::new_localhost(peer_id_of_server_broker),
core_registration: None,
additional_bootstrap: None,
pdf: false,
device_name: "test".to_string(),
})
.await
.expect("wallet_create_v0");
// Save wallet to file.
let wallet_file_bin = wallet_get_file(&result.wallet_name).await.unwrap();
let mut creds_file = File::create(creds_path).expect("create creds file");
let mut wallet_file = File::create(wallet_path).expect("create wallet file");
// Use the mnemonic_str already provided (list of words) to avoid mistakes
let mnemonic_words: Vec<String> = result.mnemonic_str.clone();
writeln!(creds_file, "{}", mnemonic_words.join(" ")).expect("write mnemonic to creds file");
wallet = wallet_open_with_mnemonic_words(&result.wallet, &mnemonic_words, WALLET_PIN)
.expect("open wallet");
session_id = result.session_id;
}
return (wallet, session_id);
}
fn build_insert_sparql() -> String {
// Data conforms to testShape.shex
// Shape requires: a ex:TestObject + required fields.
r#"
PREFIX ex: <http://example.org/>
INSERT DATA {
GRAPH <urn:ng:testShapeGraph> {
<urn:test:obj1> a ex:TestObject ;
ex:stringValue "hello world" ;
ex:numValue 42 ;
ex:boolValue true ;
ex:arrayValue 1,2,3 ;
ex:objectValue [
ex:nestedString "nested" ;
ex:nestedNum 7 ;
ex:nestedArray 5,6
] ;
ex:anotherObject [
ex:prop1 "one" ;
ex:prop2 1
], [
ex:prop1 "two" ;
ex:prop2 2
] ;
ex:numOrStr "either" ;
ex:lit1Or2 "lit1" .
}
}
"#
.trim()
.to_string()
}
#[async_std::test]
async fn test_wallet_and_sparql_insert() {
let (wallet, session_id) = create_or_open_wallet().await;
let sparql = build_insert_sparql();
let doc_id = "urn:ng:testShapeGraph".to_string();
let result = doc_sparql_update(session_id, doc_id.clone(), Some(sparql.clone())).await;
assert!(result.is_ok(), "SPARQL update failed: {:?}", result.err());
// Optional: a second idempotent insert should not duplicate (implementation dependent)
let second = doc_sparql_update(session_id, doc_id, Some(sparql)).await;
assert!(second.is_ok());
user_disconnect(&wallet.personal_identity());
session_stop(&wallet.personal_identity()).await.ok();
wallet_close(&wallet.name());
}

@ -7,7 +7,7 @@ license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
keywords = ["crdt","e2ee","local-first","p2p","pubsub"]
keywords = ["crdt", "e2ee", "local-first", "p2p", "pubsub"]
documentation.workspace = true
rust-version.workspace = true
@ -20,13 +20,15 @@ serde_bare = "0.5.0"
serde_json = "1.0.96"
futures = "0.3.24"
once_cell = "1.17.1"
either = { version = "1.8.1", features=["serde"] }
async-std = { version = "1.12.0", features = ["attributes"] }
either = { version = "1.8.1", features = ["serde"] }
async-std = { version = "1.12.0", features = ["attributes"] }
async-trait = "0.1.64"
rust-embed= { version = "6.7.0", features=["include-exclude"] }
rust-embed = { version = "6.7.0", features = ["include-exclude"] }
urlencoding = "2.1.3"
blake3 = "1.3.1"
ng-async-tungstenite = { version = "0.22.2", git = "https://git.nextgraph.org/NextGraph/async-tungstenite.git", branch = "nextgraph", features = ["async-std-runtime"] }
ng-async-tungstenite = { version = "0.22.2", git = "https://git.nextgraph.org/NextGraph/async-tungstenite.git", branch = "nextgraph", features = [
"async-std-runtime",
] }
ng-repo = { path = "../ng-repo", version = "0.1.2" }
ng-net = { path = "../ng-net", version = "0.1.2" }
ng-client-ws = { path = "../ng-client-ws", version = "0.1.2" }
@ -42,4 +44,4 @@ getrandom = "0.3.3"
netdev = "0.26"
[dev-dependencies]
tempfile = "3"
tempfile = "3"

@ -11,13 +11,16 @@
#![allow(non_snake_case)]
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OrmShapeType {
pub iri: String,
pub schema: OrmSchema,
pub shape: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
@ -43,3 +46,68 @@ pub struct OrmDiffOp {
}
pub type OrmDiff = Vec<OrmDiffOp>;
type OrmSchema = HashMap<String, OrmSchemaShape>;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OrmSchemaShape {
pub iri: String,
pub predicates: Vec<OrmSchemaPredicate>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum OrmSchemaLiteralType {
number,
string,
boolean,
iri,
literal,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum OrmSchemaPredicateType {
number,
string,
boolean,
iri,
literal,
nested,
eitherOf,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrmLiterals {
Bool(bool),
NumArray(Vec<f64>),
StrArray(Vec<String>),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OrmSchemaDataType {
pub valType: OrmSchemaLiteralType,
pub literals: Option<OrmLiterals>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OrmSchemaPredicate {
pub valType: OrmSchemaPredicateType,
pub iri: String,
pub readablePredicate: String,
pub literalValue: Option<Value>, // Strictly speaking, no objects.
pub nestedShape: Option<String>, // Only by reference.
pub maxCardinality: i64, // -1 for infinity
pub minCardinality: i64,
pub eitherOf: Option<Vec<OrmSchemaEitherOfOption>>, // Shape references or multi type.
pub extra: Option<bool>,
}
// TODO: Will this be serialized correctly?
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrmSchemaEitherOfOption {
ShapeRef(String),
DataType(OrmSchemaDataType),
}

@ -7,7 +7,7 @@ license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
keywords = ["crdt","e2ee","local-first","p2p","eventual-consistency"]
keywords = ["crdt", "e2ee", "local-first", "p2p", "eventual-consistency"]
documentation.workspace = true
rust-version.workspace = true
build = "build.rs"
@ -23,14 +23,14 @@ serde = { version = "1.0", features = ["derive"] }
serde_bare = "0.5.0"
serde_bytes = "0.11.7"
serde_json = "1.0"
rand = { version = "0.7", features = ["getrandom"] }
rand = { version = "0.7", features = ["getrandom"] }
web-time = "0.2.0"
either = "1.8.1"
futures = "0.3.24"
lazy_static = "1.4.0"
async-trait = "0.1.64"
base64-url = "2.0.0"
async-std = { version = "1.12.0", features = [ "attributes", "unstable" ] }
async-std = { version = "1.12.0", features = ["attributes", "unstable"] }
automerge = "0.5.11"
yrs = "0.19.2"
qrcode = { version = "0.14.1", default-features = false, features = ["svg"] }
@ -38,9 +38,12 @@ sbbf-rs-safe = "0.3.2"
ng-repo = { path = "../ng-repo", version = "0.1.2" }
ng-net = { path = "../ng-net", version = "0.1.2" }
ng-oxigraph = { path = "../ng-oxigraph", version = "0.4.0-alpha.8-ngalpha" }
once_cell = "1.17.1"
[target.'cfg(target_family = "wasm")'.dependencies]
ng-oxigraph = { path = "../ng-oxigraph", version = "0.4.0-alpha.8-ngalpha", features = ["js"] }
ng-oxigraph = { path = "../ng-oxigraph", version = "0.4.0-alpha.8-ngalpha", features = [
"js",
] }
[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom]
version = "0.3.3"
@ -51,4 +54,4 @@ ng-storage-rocksdb = { path = "../ng-storage-rocksdb", version = "0.1.2" }
getrandom = "0.3.3"
[dev-dependencies]
ng-repo = { path = "../ng-repo", version = "0.1.2", features = ["testing"] }
ng-repo = { path = "../ng-repo", version = "0.1.2", features = ["testing"] }

@ -89,5 +89,6 @@ pub fn prepare_app_response_for_js(mut app_response: AppResponse) -> Result<AppR
*graph = Some(graph_patch);
};
}
Ok(app_response)
}

@ -146,7 +146,7 @@ impl Verifier {
self.orm_subscriptions.insert(
nuri.clone(),
HashMap::from([(
schema.iri.clone(),
schema.shape.clone(),
HashMap::from([(session_id, tx.clone())]),
)]),
);

@ -6,6 +6,8 @@ import type { Person } from "../../shapes/ldo/personShape.typings";
import type { Cat } from "../../shapes/ldo/catShape.typings";
import type { TestObject } from "../../shapes/ldo/testShape.typings";
import updateShape from "./updateShape";
import { testShapeSchema } from "../../shapes/ldo/testShape.schema";
import { TestObjectShapeType } from "../../shapes/ldo/testShape.shapeTypes";
// Messages exchanged over the BroadcastChannel("shape-manager")
interface WasmMessage {
@ -165,9 +167,6 @@ communicationChannel.addEventListener(
}
);
ng.orm_update(
"",
"",
[{ op: "add", valType: "set", value: 1, path: "/foo/bar" }],
1
).catch((err) => console.error(err));
ng.orm_start("", TestObjectShapeType, 12, (...params: any) => {
console.log("updates received with params", params);
}).catch((err) => console.error(err));

@ -82,7 +82,7 @@ function addConstructPattern(
(pred.minCardinality ?? 0) === 0 &&
(options?.includeOptionalForMinZero ?? true);
if (pred.type === "nested" && pred.nestedShape) {
if (pred.valType === "nested" && pred.nestedShape) {
template.push(triple);
const nestedBody: string[] = [triple];
const nestedPreds = pred.nestedShape.predicates;
@ -108,7 +108,7 @@ function addConstructPattern(
template.push(triple);
const blockLines: string[] = [triple];
if (pred.type === "literal" && pred.literalValue !== undefined) {
if (pred.valType === "literal" && pred.literalValue !== undefined) {
if (Array.isArray(pred.literalValue)) {
valuesBlocks.push(valuesBlock(objVar, pred.literalValue as any[]));
} else {

@ -35,7 +35,7 @@ export const buildConstructQuery = ({
for (const pred of predicates) {
const subjectVarName = getVarNameFor(shapeId);
if (pred.type === "nested") {
if (pred.valType === "nested") {
if (typeof pred.nestedShape !== "string")
throw new Error("Nested shapes must be by reference");

@ -10,7 +10,7 @@ export const testShapeSchema: Schema = {
iri: "http://example.org/TestObject",
predicates: [
{
type: "literal",
valType: "literal",
literalValue: ["TestObject"],
maxCardinality: 1,
minCardinality: 1,
@ -19,35 +19,35 @@ export const testShapeSchema: Schema = {
extra: true,
},
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/stringValue",
readablePredicate: "stringValue",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/numValue",
readablePredicate: "numValue",
},
{
type: "boolean",
valType: "boolean",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/boolValue",
readablePredicate: "boolValue",
},
{
type: "number",
valType: "number",
maxCardinality: -1,
minCardinality: 0,
iri: "http://example.org/arrayValue",
readablePredicate: "arrayValue",
},
{
type: "nested",
valType: "nested",
nestedShape:
"http://example.org/TestObject||http://example.org/objectValue",
maxCardinality: 1,
@ -56,7 +56,7 @@ export const testShapeSchema: Schema = {
readablePredicate: "objectValue",
},
{
type: "nested",
valType: "nested",
nestedShape:
"http://example.org/TestObject||http://example.org/anotherObject",
maxCardinality: -1,
@ -65,13 +65,13 @@ export const testShapeSchema: Schema = {
readablePredicate: "anotherObject",
},
{
type: "eitherOf",
valType: "eitherOf",
eitherOf: [
{
type: "string",
valType: "string",
},
{
type: "number",
valType: "number",
},
],
maxCardinality: 1,
@ -85,21 +85,21 @@ export const testShapeSchema: Schema = {
iri: "http://example.org/TestObject||http://example.org/objectValue",
predicates: [
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/nestedString",
readablePredicate: "nestedString",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/nestedNum",
readablePredicate: "nestedNum",
},
{
type: "number",
valType: "number",
maxCardinality: -1,
minCardinality: 0,
iri: "http://example.org/nestedArray",
@ -111,14 +111,14 @@ export const testShapeSchema: Schema = {
iri: "http://example.org/TestObject||http://example.org/anotherObject",
predicates: [
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/prop1",
readablePredicate: "prop1",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/prop2",

@ -10,7 +10,7 @@ export const catShapeSchema: Schema = {
iri: "http://example.org/Cat",
predicates: [
{
type: "literal",
valType: "literal",
literalValue: ["http://example.org/Cat"],
maxCardinality: 1,
minCardinality: 1,
@ -18,28 +18,28 @@ export const catShapeSchema: Schema = {
readablePredicate: "type",
},
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/name",
readablePredicate: "name",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/age",
readablePredicate: "age",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/numberOfHomes",
readablePredicate: "numberOfHomes",
},
{
type: "nested",
valType: "nested",
nestedShape:
"http://example.org/Cat||http://example.org/address",
maxCardinality: 1,
@ -53,21 +53,21 @@ export const catShapeSchema: Schema = {
iri: "http://example.org/Cat||http://example.org/address",
predicates: [
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/street",
readablePredicate: "street",
},
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/houseNumber",
readablePredicate: "houseNumber",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/floor",

@ -10,7 +10,7 @@ export const personShapeSchema: Schema = {
iri: "http://example.org/Person",
predicates: [
{
type: "literal",
valType: "literal",
literalValue: ["http://example.org/Person"],
maxCardinality: 1,
minCardinality: 1,
@ -18,14 +18,14 @@ export const personShapeSchema: Schema = {
readablePredicate: "type",
},
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/name",
readablePredicate: "name",
},
{
type: "nested",
valType: "nested",
nestedShape:
"http://example.org/Person||http://example.org/address",
maxCardinality: 1,
@ -34,14 +34,14 @@ export const personShapeSchema: Schema = {
readablePredicate: "address",
},
{
type: "boolean",
valType: "boolean",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/hasChildren",
readablePredicate: "hasChildren",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/numberOfHouses",
@ -53,14 +53,14 @@ export const personShapeSchema: Schema = {
iri: "http://example.org/Person||http://example.org/address",
predicates: [
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/street",
readablePredicate: "street",
},
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/houseNumber",

@ -10,7 +10,7 @@ export const testShapeSchema: Schema = {
iri: "http://example.org/TestObject",
predicates: [
{
type: "literal",
valType: "literal",
literalValue: ["http://example.org/TestObject"],
maxCardinality: 1,
minCardinality: 1,
@ -19,35 +19,35 @@ export const testShapeSchema: Schema = {
extra: true,
},
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/stringValue",
readablePredicate: "stringValue",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/numValue",
readablePredicate: "numValue",
},
{
type: "boolean",
valType: "boolean",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/boolValue",
readablePredicate: "boolValue",
},
{
type: "number",
valType: "number",
maxCardinality: -1,
minCardinality: 0,
iri: "http://example.org/arrayValue",
readablePredicate: "arrayValue",
},
{
type: "nested",
valType: "nested",
nestedShape:
"http://example.org/TestObject||http://example.org/objectValue",
maxCardinality: 1,
@ -56,7 +56,7 @@ export const testShapeSchema: Schema = {
readablePredicate: "objectValue",
},
{
type: "nested",
valType: "nested",
nestedShape:
"http://example.org/TestObject||http://example.org/anotherObject",
maxCardinality: -1,
@ -65,13 +65,13 @@ export const testShapeSchema: Schema = {
readablePredicate: "anotherObject",
},
{
type: "eitherOf",
valType: "eitherOf",
eitherOf: [
{
type: "string",
valType: "string",
},
{
type: "number",
valType: "number",
},
],
maxCardinality: 1,
@ -80,7 +80,7 @@ export const testShapeSchema: Schema = {
readablePredicate: "numOrStr",
},
{
type: "literal",
valType: "literal",
literalValue: ["lit1", "lit2"],
maxCardinality: 1,
minCardinality: 1,
@ -93,21 +93,21 @@ export const testShapeSchema: Schema = {
iri: "http://example.org/TestObject||http://example.org/objectValue",
predicates: [
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/nestedString",
readablePredicate: "nestedString",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/nestedNum",
readablePredicate: "nestedNum",
},
{
type: "number",
valType: "number",
maxCardinality: -1,
minCardinality: 0,
iri: "http://example.org/nestedArray",
@ -119,14 +119,14 @@ export const testShapeSchema: Schema = {
iri: "http://example.org/TestObject||http://example.org/anotherObject",
predicates: [
{
type: "string",
valType: "string",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/prop1",
readablePredicate: "prop1",
},
{
type: "number",
valType: "number",
maxCardinality: 1,
minCardinality: 1,
iri: "http://example.org/prop2",

@ -80,7 +80,8 @@ function flattenSchema(shapes: Shape[]): ShapeSchema {
// Find nested, unflattened (i.e. anonymous) schemas in properties.
const nestedSchemaPredicates = shape.predicates.filter(
(pred) =>
pred.type === "nested" && typeof pred.nestedShape === "object"
pred.valType === "nested" &&
typeof pred.nestedShape === "object"
);
for (const pred of nestedSchemaPredicates) {

@ -135,15 +135,15 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer<
const commonProperties = {
maxCardinality: tripleConstraint.max ?? 1,
minCardinality: tripleConstraint.min ?? 1,
predicateUri: tripleConstraint.predicate,
iri: tripleConstraint.predicate,
// @ts-expect-error The ldo library does not have our modded readablePredicate property.
readablePredicate: tripleConstraint.readablePredicate,
};
} satisfies Partial<Predicate>;
// Make property based on object type which is either a parsed schema, literal or type.
if (typeof transformedChildren.valueExpr === "string") {
// Reference to nested object
return {
type: "nested",
valType: "nested",
nestedShape: transformedChildren.valueExpr,
...commonProperties,
} satisfies Predicate;
@ -153,13 +153,13 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer<
) {
// Nested object
return {
type: "nested",
valType: "nested",
nestedShape: transformedChildren.valueExpr as Shape,
...commonProperties,
} satisfies Predicate;
} else if (Array.isArray(transformedChildren.valueExpr)) {
return {
type: "eitherOf",
valType: "eitherOf",
eitherOf: transformedChildren.valueExpr,
...commonProperties,
};
@ -168,7 +168,7 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer<
const nodeConstraint =
transformedChildren.valueExpr as DataType;
return {
type: nodeConstraint.type,
valType: nodeConstraint.valType,
literalValue: nodeConstraint.literals,
...commonProperties,
} satisfies Predicate;
@ -180,16 +180,16 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer<
transformer: async (nodeConstraint) => {
if (nodeConstraint.datatype) {
return {
type: rdfDataTypeToBasic(nodeConstraint.datatype),
valType: rdfDataTypeToBasic(nodeConstraint.datatype),
};
}
if (nodeConstraint.nodeKind) {
// Something reference-like.
return { type: "iri" };
return { valType: "iri" };
}
if (nodeConstraint.values) {
return {
type: "literal",
valType: "literal",
literals: nodeConstraint.values.map(
// TODO: We do not convert them to number or boolean or lang tag.
(valueRecord) => valueRecord.value || valueRecord.id

@ -18,26 +18,26 @@ export interface Shape {
export type DataType = {
literals?: number[] | string[] | boolean;
type: "number" | "string" | "boolean" | "iri" | "literal";
valType: "number" | "string" | "boolean" | "iri" | "literal";
};
export interface Predicate {
/** Type of property. */
type: DataType["type"] | "nested" | "eitherOf";
valType: DataType["valType"] | "nested" | "eitherOf";
/** The RDF predicate URI. */
iri: string;
/** The alias of the `predicateUri` when serialized to a JSON object. */
readablePredicate: string;
/** The required literal value(s), if type is `literal`. Others are allowed, if `extra` is true. */
literalValue?: number | string | boolean | number[] | string[];
literalValue?: number | string | boolean | number[] | string[]; // TODO: We could live without this and use eitherOf instead...
/** If type is `nested`, the shape or its IRI. */
nestedShape?: string | Shape;
nestedShape?: string | Shape; // TODO: Only allow Shape while parsing from traverser. We flatten afterwards.
/** Maximum allowed number of values. `-1` means infinite. */
maxCardinality: number;
/** Minimum required number of values */
minCardinality: number;
/** If type is `eitherOf`, specifies multiple allowed types (CompactSchemaValue, shapes, or shape IRI). */
eitherOf?: (DataType | Shape | string)[];
eitherOf?: (DataType | Shape | string)[]; // TODO: Shape is going to be by reference.
/** If other (additional) values are permitted. Useful for literals. */
extra?: boolean;
}

@ -1815,13 +1815,14 @@ pub async fn orm_start(
session_id: JsValue,
callback: &js_sys::Function,
) -> Result<JsValue, String> {
let shape_type: OrmShapeType = serde_wasm_bindgen::from_value::<OrmShapeType>(shapeType)
.map_err(|e| format!("Deserialization error of shapeType {e}"))?;
log_info!("frontend_orm_start {:?}", shape_type);
let session_id: u64 = serde_wasm_bindgen::from_value::<u64>(session_id)
.map_err(|_| "Deserialization error of session_id".to_string())?;
let scope: NuriV0 = serde_wasm_bindgen::from_value::<NuriV0>(scope)
.map_err(|_| "Deserialization error of scope".to_string())?;
let shapeType: OrmShapeType = serde_wasm_bindgen::from_value::<OrmShapeType>(shapeType)
.map_err(|e| format!("Deserialization error of shapeType {e}"))?;
let mut request = AppRequest::new_orm_start(scope, shapeType);
let mut request = AppRequest::new_orm_start(scope, shape_type);
request.set_session_id(session_id);
app_request_stream_(request, callback).await
}

Loading…
Cancel
Save