From 86b288dc0767b1e26a2696a7a85ee057ef70cf3b Mon Sep 17 00:00:00 2001 From: Jackson Morgan Date: Mon, 12 May 2025 15:31:38 -0400 Subject: [PATCH] Theoretically made useResource and useSubject for Svelte, but having problems with ESM --- package-lock.json | 581 +++++++++++++- .../test/Solid-Integration.test.tsx | 1 - .../svelte/example/src/.ldo/post.context.ts | 32 + .../svelte/example/src/.ldo/post.schema.ts | 155 ++++ .../example/src/.ldo/post.shapeTypes.ts | 19 + .../svelte/example/src/.ldo/post.typings.ts | 45 ++ .../example/src/.ldo/solidProfile.context.ts | 459 +++++++++++ .../example/src/.ldo/solidProfile.schema.ts | 749 ++++++++++++++++++ .../src/.ldo/solidProfile.shapeTypes.ts | 71 ++ .../example/src/.ldo/solidProfile.typings.ts | 293 +++++++ packages/svelte/example/src/App.svelte | 55 +- .../svelte/example/src/ldoSvelteMethods.ts | 13 + .../unauthenticatedServer.json | 52 ++ .../test-server/configs/solid-css-seed.json | 9 + .../test-server/configs/template/wac/.acl.hbs | 13 + .../template/wac/link-query/main-profile.ttl | 7 + .../template/wac/link-query/other-profile.ttl | 7 + .../template/wac/link-query/third-profile.ttl | 7 + .../configs/template/wac/profile/card.acl.hbs | 19 + .../svelte/example/test-server/runServer.ts | 18 + packages/svelte/package.json | 10 +- .../svelte/src/createLdoSvelteMethods.tsx | 77 ++ packages/svelte/src/index.ts | 14 +- packages/svelte/src/methods/useLdo.ts | 147 ++++ packages/svelte/src/methods/useLinkQuery.ts | 34 + packages/svelte/src/methods/useMatchObject.ts | 25 + .../svelte/src/methods/useMatchSubject.ts | 25 + packages/svelte/src/methods/useResource.ts | 94 +++ packages/svelte/src/methods/useSubject.ts | 48 ++ .../src/methods/useSubscribeToResource.ts | 17 + packages/svelte/src/util/useTrackingProxy.ts | 44 + .../test-solid-server/src/createServer.ts | 4 - .../test-solid-server/src/setupTestServer.ts | 4 + 33 files changed, 3107 insertions(+), 41 deletions(-) create mode 100644 packages/svelte/example/src/.ldo/post.context.ts create mode 100644 packages/svelte/example/src/.ldo/post.schema.ts create mode 100644 packages/svelte/example/src/.ldo/post.shapeTypes.ts create mode 100644 packages/svelte/example/src/.ldo/post.typings.ts create mode 100644 packages/svelte/example/src/.ldo/solidProfile.context.ts create mode 100644 packages/svelte/example/src/.ldo/solidProfile.schema.ts create mode 100644 packages/svelte/example/src/.ldo/solidProfile.shapeTypes.ts create mode 100644 packages/svelte/example/src/.ldo/solidProfile.typings.ts create mode 100644 packages/svelte/example/src/ldoSvelteMethods.ts create mode 100644 packages/svelte/example/test-server/configs/components-config/unauthenticatedServer.json create mode 100644 packages/svelte/example/test-server/configs/solid-css-seed.json create mode 100644 packages/svelte/example/test-server/configs/template/wac/.acl.hbs create mode 100644 packages/svelte/example/test-server/configs/template/wac/link-query/main-profile.ttl create mode 100644 packages/svelte/example/test-server/configs/template/wac/link-query/other-profile.ttl create mode 100644 packages/svelte/example/test-server/configs/template/wac/link-query/third-profile.ttl create mode 100644 packages/svelte/example/test-server/configs/template/wac/profile/card.acl.hbs create mode 100644 packages/svelte/example/test-server/runServer.ts create mode 100644 packages/svelte/src/createLdoSvelteMethods.tsx create mode 100644 packages/svelte/src/methods/useLdo.ts create mode 100644 packages/svelte/src/methods/useLinkQuery.ts create mode 100644 packages/svelte/src/methods/useMatchObject.ts create mode 100644 packages/svelte/src/methods/useMatchSubject.ts create mode 100644 packages/svelte/src/methods/useResource.ts create mode 100644 packages/svelte/src/methods/useSubject.ts create mode 100644 packages/svelte/src/methods/useSubscribeToResource.ts create mode 100644 packages/svelte/src/util/useTrackingProxy.ts diff --git a/package-lock.json b/package-lock.json index b6d3853..a3c74f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4271,6 +4271,22 @@ "node": ">=10.0.0" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.4.tgz", + "integrity": "sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@esbuild/android-arm": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", @@ -4543,6 +4559,22 @@ "node": ">=12" } }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.4.tgz", + "integrity": "sha512-vUnkBYxZW4hL/ie91hSqaSNjulOnYXE1VSLusnvHg2u3jewJBz3YzB9+oCw8DABeVqZGg94t9tyZFoHma8gWZQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@esbuild/netbsd-x64": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz", @@ -4560,6 +4592,22 @@ "node": ">=12" } }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.4.tgz", + "integrity": "sha512-Ct2WcFEANlFDtp1nVAXSNBPDxyU+j7+tId//iHXU2f/lN5AmO4zLyhDcpR5Cz1r08mVxzt3Jpyt4PmXQ1O6+7A==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@esbuild/openbsd-x64": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz", @@ -11404,6 +11452,78 @@ "node": ">= 6" } }, + "node_modules/concurrently": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.1.2.tgz", + "integrity": "sha512-H9MWcoPsYddwbOGM6difjVwVZHl63nwMEwDJG/L7VGtuaJhb12h2caPG2tVPWs7emuYix252iGfqOyrz1GczTQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.1.2", + "lodash": "^4.17.21", + "rxjs": "^7.8.1", + "shell-quote": "^1.8.1", + "supports-color": "^8.1.1", + "tree-kill": "^1.2.2", + "yargs": "^17.7.2" + }, + "bin": { + "conc": "dist/bin/concurrently.js", + "concurrently": "dist/bin/concurrently.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/chalk/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/concurrently/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -14506,6 +14626,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.0.tgz", + "integrity": "sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A==", + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/git-raw-commits": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-3.0.0.tgz", @@ -23635,6 +23767,15 @@ "node": ">=8" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/resolve.exports": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.3.tgz", @@ -24100,6 +24241,19 @@ "node": ">=8" } }, + "node_modules/shell-quote": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.2.tgz", + "integrity": "sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/shex-test": { "version": "0.5.8", "resolved": "https://registry.npmjs.org/shex-test/-/shex-test-0.5.8.tgz", @@ -25808,6 +25962,16 @@ "node": ">=12" } }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "dev": true, + "license": "MIT", + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/trim-newlines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz", @@ -26100,6 +26264,417 @@ "node": ">=0.6.x" } }, + "node_modules/tsx": { + "version": "4.19.4", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.4.tgz", + "integrity": "sha512-gK5GVzDkJK1SI1zwHf32Mqxf2tSJkNx+eYcNly5+nHvWqXUJYUkWBQtKauoESz3ymezAI++ZwT855x5p5eop+Q==", + "license": "MIT", + "dependencies": { + "esbuild": "~0.25.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/tsx/node_modules/@esbuild/android-arm": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.4.tgz", + "integrity": "sha512-QNdQEps7DfFwE3hXiU4BZeOV68HHzYwGd0Nthhd3uCkkEKK7/R6MTgM0P7H7FAs5pU/DIWsviMmEGxEoxIZ+ZQ==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/android-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.4.tgz", + "integrity": "sha512-bBy69pgfhMGtCnwpC/x5QhfxAz/cBgQ9enbtwjf6V9lnPI/hMyT9iWpR1arm0l3kttTr4L0KSLpKmLp/ilKS9A==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/android-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.4.tgz", + "integrity": "sha512-TVhdVtQIFuVpIIR282btcGC2oGQoSfZfmBdTip2anCaVYcqWlZXGcdcKIUklfX2wj0JklNYgz39OBqh2cqXvcQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/darwin-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.4.tgz", + "integrity": "sha512-Y1giCfM4nlHDWEfSckMzeWNdQS31BQGs9/rouw6Ub91tkK79aIMTH3q9xHvzH8d0wDru5Ci0kWB8b3up/nl16g==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/darwin-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.4.tgz", + "integrity": "sha512-CJsry8ZGM5VFVeyUYB3cdKpd/H69PYez4eJh1W/t38vzutdjEjtP7hB6eLKBoOdxcAlCtEYHzQ/PJ/oU9I4u0A==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.4.tgz", + "integrity": "sha512-yYq+39NlTRzU2XmoPW4l5Ifpl9fqSk0nAJYM/V/WUGPEFfek1epLHJIkTQM6bBs1swApjO5nWgvr843g6TjxuQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/freebsd-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.4.tgz", + "integrity": "sha512-0FgvOJ6UUMflsHSPLzdfDnnBBVoCDtBTVyn/MrWloUNvq/5SFmh13l3dvgRPkDihRxb77Y17MbqbCAa2strMQQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-arm": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.4.tgz", + "integrity": "sha512-kro4c0P85GMfFYqW4TWOpvmF8rFShbWGnrLqlzp4X1TNWjRY3JMYUfDCtOxPKOIY8B0WC8HN51hGP4I4hz4AaQ==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.4.tgz", + "integrity": "sha512-+89UsQTfXdmjIvZS6nUnOOLoXnkUTB9hR5QAeLrQdzOSWZvNSAXAtcRDHWtqAUtAmv7ZM1WPOOeSxDzzzMogiQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-ia32": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.4.tgz", + "integrity": "sha512-yTEjoapy8UP3rv8dB0ip3AfMpRbyhSN3+hY8mo/i4QXFeDxmiYbEKp3ZRjBKcOP862Ua4b1PDfwlvbuwY7hIGQ==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-loong64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.4.tgz", + "integrity": "sha512-NeqqYkrcGzFwi6CGRGNMOjWGGSYOpqwCjS9fvaUlX5s3zwOtn1qwg1s2iE2svBe4Q/YOG1q6875lcAoQK/F4VA==", + "cpu": [ + "loong64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-mips64el": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.4.tgz", + "integrity": "sha512-IcvTlF9dtLrfL/M8WgNI/qJYBENP3ekgsHbYUIzEzq5XJzzVEV/fXY9WFPfEEXmu3ck2qJP8LG/p3Q8f7Zc2Xg==", + "cpu": [ + "mips64el" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-ppc64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.4.tgz", + "integrity": "sha512-HOy0aLTJTVtoTeGZh4HSXaO6M95qu4k5lJcH4gxv56iaycfz1S8GO/5Jh6X4Y1YiI0h7cRyLi+HixMR+88swag==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-riscv64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.4.tgz", + "integrity": "sha512-i8JUDAufpz9jOzo4yIShCTcXzS07vEgWzyX3NH2G7LEFVgrLEhjwL3ajFE4fZI3I4ZgiM7JH3GQ7ReObROvSUA==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-s390x": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.4.tgz", + "integrity": "sha512-jFnu+6UbLlzIjPQpWCNh5QtrcNfMLjgIavnwPQAfoGx4q17ocOU9MsQ2QVvFxwQoWpZT8DvTLooTvmOQXkO51g==", + "cpu": [ + "s390x" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/linux-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.4.tgz", + "integrity": "sha512-6e0cvXwzOnVWJHq+mskP8DNSrKBr1bULBvnFLpc1KY+d+irZSgZ02TGse5FsafKS5jg2e4pbvK6TPXaF/A6+CA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/netbsd-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.4.tgz", + "integrity": "sha512-XAg8pIQn5CzhOB8odIcAm42QsOfa98SBeKUdo4xa8OvX8LbMZqEtgeWE9P/Wxt7MlG2QqvjGths+nq48TrUiKw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/openbsd-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.4.tgz", + "integrity": "sha512-xAGGhyOQ9Otm1Xu8NT1ifGLnA6M3sJxZ6ixylb+vIUVzvvd6GOALpwQrYrtlPouMqd/vSbgehz6HaVk4+7Afhw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/sunos-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.4.tgz", + "integrity": "sha512-Mw+tzy4pp6wZEK0+Lwr76pWLjrtjmJyUB23tHKqEDP74R3q95luY/bXqXZeYl4NYlvwOqoRKlInQialgCKy67Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/win32-arm64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.4.tgz", + "integrity": "sha512-AVUP428VQTSddguz9dO9ngb+E5aScyg7nOeJDrF1HPYu555gmza3bDGMPhmVXL8svDSoqPCsCPjb265yG/kLKQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/win32-ia32": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.4.tgz", + "integrity": "sha512-i1sW+1i+oWvQzSgfRcxxG2k4I9n3O9NRqy8U+uugaT2Dy7kLO9Y7wI72haOahxceMX8hZAzgGou1FhndRldxRg==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/@esbuild/win32-x64": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.4.tgz", + "integrity": "sha512-nOT2vZNw6hJ+z43oP1SPea/G/6AbN6X+bGNhNuq8NtRHy4wsMhw765IKLNmnjek7GvjWBYQ8Q5VBoYTFg9y1UQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/tsx/node_modules/esbuild": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.4.tgz", + "integrity": "sha512-8pgjLUcUjcgDg+2Q4NYXnPbo/vncAY4UmyaCm0jZevERqCHZIaWwdJHkf8XQtu4AxSKCdvrUbT0XUr1IdZzI8Q==", + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.4", + "@esbuild/android-arm": "0.25.4", + "@esbuild/android-arm64": "0.25.4", + "@esbuild/android-x64": "0.25.4", + "@esbuild/darwin-arm64": "0.25.4", + "@esbuild/darwin-x64": "0.25.4", + "@esbuild/freebsd-arm64": "0.25.4", + "@esbuild/freebsd-x64": "0.25.4", + "@esbuild/linux-arm": "0.25.4", + "@esbuild/linux-arm64": "0.25.4", + "@esbuild/linux-ia32": "0.25.4", + "@esbuild/linux-loong64": "0.25.4", + "@esbuild/linux-mips64el": "0.25.4", + "@esbuild/linux-ppc64": "0.25.4", + "@esbuild/linux-riscv64": "0.25.4", + "@esbuild/linux-s390x": "0.25.4", + "@esbuild/linux-x64": "0.25.4", + "@esbuild/netbsd-arm64": "0.25.4", + "@esbuild/netbsd-x64": "0.25.4", + "@esbuild/openbsd-arm64": "0.25.4", + "@esbuild/openbsd-x64": "0.25.4", + "@esbuild/sunos-x64": "0.25.4", + "@esbuild/win32-arm64": "0.25.4", + "@esbuild/win32-ia32": "0.25.4", + "@esbuild/win32-x64": "0.25.4" + } + }, "node_modules/tuf-js": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/tuf-js/-/tuf-js-1.1.7.tgz", @@ -28711,14 +29286,17 @@ "@ldo/ldo": "^1.0.0-alpha.9", "@ldo/rdf-utils": "^1.0.0-alpha.9", "@ldo/subscribable-dataset": "^1.0.0-alpha.9", - "@rdfjs/data-model": "^1.2.0" + "@rdfjs/data-model": "^1.2.0", + "tsx": "^4.19.4" }, "devDependencies": { + "@ldo/test-solid-server": "^1.0.0-alpha.9", "@sveltejs/vite-plugin-svelte": "^2.5.3", "@testing-library/jest-dom": "^6.6.3", "@testing-library/svelte": "^5.2.7", "@tsconfig/svelte": "^5.0.4", "@types/jest": "^29.5.14", + "concurrently": "^9.1.2", "eslint-plugin-svelte3": "^4.0.0", "identity-obj-proxy": "^3.0.0", "jest": "^29.7.0", @@ -28728,7 +29306,6 @@ "svelte-jester": "^5.0.0", "svelte-preprocess": "^5.1.4", "ts-jest": "^29.3.2", - "ts-node": "^10.9.2", "tslib": "^2.8.1", "typescript": "^5.8.3", "vite": "^4.5.0", diff --git a/packages/solid-react/test/Solid-Integration.test.tsx b/packages/solid-react/test/Solid-Integration.test.tsx index 95b167d..5cbf36b 100644 --- a/packages/solid-react/test/Solid-Integration.test.tsx +++ b/packages/solid-react/test/Solid-Integration.test.tsx @@ -4,7 +4,6 @@ import { render, screen, fireEvent, act } from "@testing-library/react"; import { MAIN_PROFILE_SUBJECT, MAIN_PROFILE_URI, - OTHER_PROFILE_URI, SAMPLE_BINARY_URI, SAMPLE_DATA_URI, SERVER_DOMAIN, diff --git a/packages/svelte/example/src/.ldo/post.context.ts b/packages/svelte/example/src/.ldo/post.context.ts new file mode 100644 index 0000000..5cb3a91 --- /dev/null +++ b/packages/svelte/example/src/.ldo/post.context.ts @@ -0,0 +1,32 @@ +import { ContextDefinition } from "jsonld"; + +/** + * ============================================================================= + * postContext: JSONLD Context for post + * ============================================================================= + */ +export const postContext: ContextDefinition = { + type: { + "@id": "@type", + }, + SocialMediaPosting: "http://schema.org/SocialMediaPosting", + CreativeWork: "http://schema.org/CreativeWork", + Thing: "http://schema.org/Thing", + articleBody: { + "@id": "http://schema.org/articleBody", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + uploadDate: { + "@id": "http://schema.org/uploadDate", + "@type": "http://www.w3.org/2001/XMLSchema#date", + }, + image: { + "@id": "http://schema.org/image", + "@type": "@id", + }, + publisher: { + "@id": "http://schema.org/publisher", + "@type": "@id", + "@container": "@set", + }, +}; diff --git a/packages/svelte/example/src/.ldo/post.schema.ts b/packages/svelte/example/src/.ldo/post.schema.ts new file mode 100644 index 0000000..39e8b63 --- /dev/null +++ b/packages/svelte/example/src/.ldo/post.schema.ts @@ -0,0 +1,155 @@ +import { Schema } from "shexj"; + +/** + * ============================================================================= + * postSchema: ShexJ Schema for post + * ============================================================================= + */ +export const postSchema: Schema = { + type: "Schema", + shapes: [ + { + id: "https://example.com/PostSh", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + valueExpr: { + type: "NodeConstraint", + values: [ + "http://schema.org/SocialMediaPosting", + "http://schema.org/CreativeWork", + "http://schema.org/Thing", + ], + }, + }, + { + type: "TripleConstraint", + predicate: "http://schema.org/articleBody", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#label", + object: { + value: "articleBody", + }, + }, + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The actual body of the article. ", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://schema.org/uploadDate", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#date", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#label", + object: { + value: "uploadDate", + }, + }, + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "Date when this media object was uploaded to this site.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://schema.org/image", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#label", + object: { + value: "image", + }, + }, + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A media object that encodes this CreativeWork. This property is a synonym for encoding.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://schema.org/publisher", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#label", + object: { + value: "publisher", + }, + }, + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The publisher of the creative work.", + }, + }, + ], + }, + ], + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#label", + object: { + value: "SocialMediaPost", + }, + }, + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A post to a social media platform, including blog posts, tweets, Facebook posts, etc.", + }, + }, + ], + }, + }, + ], +}; diff --git a/packages/svelte/example/src/.ldo/post.shapeTypes.ts b/packages/svelte/example/src/.ldo/post.shapeTypes.ts new file mode 100644 index 0000000..4c50683 --- /dev/null +++ b/packages/svelte/example/src/.ldo/post.shapeTypes.ts @@ -0,0 +1,19 @@ +import { ShapeType } from "@ldo/ldo"; +import { postSchema } from "./post.schema"; +import { postContext } from "./post.context"; +import { PostSh } from "./post.typings"; + +/** + * ============================================================================= + * LDO ShapeTypes post + * ============================================================================= + */ + +/** + * PostSh ShapeType + */ +export const PostShShapeType: ShapeType = { + schema: postSchema, + shape: "https://example.com/PostSh", + context: postContext, +}; diff --git a/packages/svelte/example/src/.ldo/post.typings.ts b/packages/svelte/example/src/.ldo/post.typings.ts new file mode 100644 index 0000000..bf9ac17 --- /dev/null +++ b/packages/svelte/example/src/.ldo/post.typings.ts @@ -0,0 +1,45 @@ +import { LdSet, LdoJsonldContext } from "@ldo/ldo"; + +/** + * ============================================================================= + * Typescript Typings for post + * ============================================================================= + */ + +/** + * PostSh Type + */ +export interface PostSh { + "@id"?: string; + "@context"?: LdoJsonldContext; + type: + | { + "@id": "SocialMediaPosting"; + } + | { + "@id": "CreativeWork"; + } + | { + "@id": "Thing"; + }; + /** + * The actual body of the article. + */ + articleBody?: string; + /** + * Date when this media object was uploaded to this site. + */ + uploadDate: string; + /** + * A media object that encodes this CreativeWork. This property is a synonym for encoding. + */ + image?: { + "@id": string; + }; + /** + * The publisher of the creative work. + */ + publisher: LdSet<{ + "@id": string; + }>; +} diff --git a/packages/svelte/example/src/.ldo/solidProfile.context.ts b/packages/svelte/example/src/.ldo/solidProfile.context.ts new file mode 100644 index 0000000..9fdffc3 --- /dev/null +++ b/packages/svelte/example/src/.ldo/solidProfile.context.ts @@ -0,0 +1,459 @@ +import { LdoJsonldContext } from "@ldo/ldo"; + +/** + * ============================================================================= + * solidProfileContext: JSONLD Context for solidProfile + * ============================================================================= + */ +export const solidProfileContext: LdoJsonldContext = { + type: { + "@id": "@type", + }, + Person: { + "@id": "http://schema.org/Person", + "@context": { + type: { + "@id": "@type", + }, + fn: { + "@id": "http://www.w3.org/2006/vcard/ns#fn", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + name: { + "@id": "http://xmlns.com/foaf/0.1/name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasAddress: { + "@id": "http://www.w3.org/2006/vcard/ns#hasAddress", + "@type": "@id", + "@isCollection": true, + }, + hasEmail: { + "@id": "http://www.w3.org/2006/vcard/ns#hasEmail", + "@type": "@id", + "@isCollection": true, + }, + hasPhoto: { + "@id": "http://www.w3.org/2006/vcard/ns#hasPhoto", + "@type": "@id", + }, + img: { + "@id": "http://xmlns.com/foaf/0.1/img", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasTelephone: { + "@id": "http://www.w3.org/2006/vcard/ns#hasTelephone", + "@type": "@id", + "@isCollection": true, + }, + phone: { + "@id": "http://www.w3.org/2006/vcard/ns#phone", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + organizationName: { + "@id": "http://www.w3.org/2006/vcard/ns#organization-name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + role: { + "@id": "http://www.w3.org/2006/vcard/ns#role", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + trustedApp: { + "@id": "http://www.w3.org/ns/auth/acl#trustedApp", + "@type": "@id", + "@isCollection": true, + }, + key: { + "@id": "http://www.w3.org/ns/auth/cert#key", + "@type": "@id", + "@isCollection": true, + }, + inbox: { + "@id": "http://www.w3.org/ns/ldp#inbox", + "@type": "@id", + }, + preferencesFile: { + "@id": "http://www.w3.org/ns/pim/space#preferencesFile", + "@type": "@id", + }, + storage: { + "@id": "http://www.w3.org/ns/pim/space#storage", + "@type": "@id", + "@isCollection": true, + }, + account: { + "@id": "http://www.w3.org/ns/solid/terms#account", + "@type": "@id", + }, + privateTypeIndex: { + "@id": "http://www.w3.org/ns/solid/terms#privateTypeIndex", + "@type": "@id", + "@isCollection": true, + }, + publicTypeIndex: { + "@id": "http://www.w3.org/ns/solid/terms#publicTypeIndex", + "@type": "@id", + "@isCollection": true, + }, + knows: { + "@id": "http://xmlns.com/foaf/0.1/knows", + "@type": "@id", + "@isCollection": true, + }, + }, + }, + Person2: { + "@id": "http://xmlns.com/foaf/0.1/Person", + "@context": { + type: { + "@id": "@type", + }, + fn: { + "@id": "http://www.w3.org/2006/vcard/ns#fn", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + name: { + "@id": "http://xmlns.com/foaf/0.1/name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasAddress: { + "@id": "http://www.w3.org/2006/vcard/ns#hasAddress", + "@type": "@id", + "@isCollection": true, + }, + hasEmail: { + "@id": "http://www.w3.org/2006/vcard/ns#hasEmail", + "@type": "@id", + "@isCollection": true, + }, + hasPhoto: { + "@id": "http://www.w3.org/2006/vcard/ns#hasPhoto", + "@type": "@id", + }, + img: { + "@id": "http://xmlns.com/foaf/0.1/img", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasTelephone: { + "@id": "http://www.w3.org/2006/vcard/ns#hasTelephone", + "@type": "@id", + "@isCollection": true, + }, + phone: { + "@id": "http://www.w3.org/2006/vcard/ns#phone", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + organizationName: { + "@id": "http://www.w3.org/2006/vcard/ns#organization-name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + role: { + "@id": "http://www.w3.org/2006/vcard/ns#role", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + trustedApp: { + "@id": "http://www.w3.org/ns/auth/acl#trustedApp", + "@type": "@id", + "@isCollection": true, + }, + key: { + "@id": "http://www.w3.org/ns/auth/cert#key", + "@type": "@id", + "@isCollection": true, + }, + inbox: { + "@id": "http://www.w3.org/ns/ldp#inbox", + "@type": "@id", + }, + preferencesFile: { + "@id": "http://www.w3.org/ns/pim/space#preferencesFile", + "@type": "@id", + }, + storage: { + "@id": "http://www.w3.org/ns/pim/space#storage", + "@type": "@id", + "@isCollection": true, + }, + account: { + "@id": "http://www.w3.org/ns/solid/terms#account", + "@type": "@id", + }, + privateTypeIndex: { + "@id": "http://www.w3.org/ns/solid/terms#privateTypeIndex", + "@type": "@id", + "@isCollection": true, + }, + publicTypeIndex: { + "@id": "http://www.w3.org/ns/solid/terms#publicTypeIndex", + "@type": "@id", + "@isCollection": true, + }, + knows: { + "@id": "http://xmlns.com/foaf/0.1/knows", + "@type": "@id", + "@isCollection": true, + }, + }, + }, + fn: { + "@id": "http://www.w3.org/2006/vcard/ns#fn", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + name: { + "@id": "http://xmlns.com/foaf/0.1/name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasAddress: { + "@id": "http://www.w3.org/2006/vcard/ns#hasAddress", + "@type": "@id", + "@isCollection": true, + }, + countryName: { + "@id": "http://www.w3.org/2006/vcard/ns#country-name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + locality: { + "@id": "http://www.w3.org/2006/vcard/ns#locality", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + postalCode: { + "@id": "http://www.w3.org/2006/vcard/ns#postal-code", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + region: { + "@id": "http://www.w3.org/2006/vcard/ns#region", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + streetAddress: { + "@id": "http://www.w3.org/2006/vcard/ns#street-address", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasEmail: { + "@id": "http://www.w3.org/2006/vcard/ns#hasEmail", + "@type": "@id", + "@isCollection": true, + }, + Dom: { + "@id": "http://www.w3.org/2006/vcard/ns#Dom", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Home: { + "@id": "http://www.w3.org/2006/vcard/ns#Home", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + ISDN: { + "@id": "http://www.w3.org/2006/vcard/ns#ISDN", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Internet: { + "@id": "http://www.w3.org/2006/vcard/ns#Internet", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Intl: { + "@id": "http://www.w3.org/2006/vcard/ns#Intl", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Label: { + "@id": "http://www.w3.org/2006/vcard/ns#Label", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Parcel: { + "@id": "http://www.w3.org/2006/vcard/ns#Parcel", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Postal: { + "@id": "http://www.w3.org/2006/vcard/ns#Postal", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Pref: { + "@id": "http://www.w3.org/2006/vcard/ns#Pref", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + Work: { + "@id": "http://www.w3.org/2006/vcard/ns#Work", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + X400: { + "@id": "http://www.w3.org/2006/vcard/ns#X400", + "@context": { + type: { + "@id": "@type", + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + }, + }, + value: { + "@id": "http://www.w3.org/2006/vcard/ns#value", + "@type": "@id", + }, + hasPhoto: { + "@id": "http://www.w3.org/2006/vcard/ns#hasPhoto", + "@type": "@id", + }, + img: { + "@id": "http://xmlns.com/foaf/0.1/img", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + hasTelephone: { + "@id": "http://www.w3.org/2006/vcard/ns#hasTelephone", + "@type": "@id", + "@isCollection": true, + }, + phone: { + "@id": "http://www.w3.org/2006/vcard/ns#phone", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + organizationName: { + "@id": "http://www.w3.org/2006/vcard/ns#organization-name", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + role: { + "@id": "http://www.w3.org/2006/vcard/ns#role", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + trustedApp: { + "@id": "http://www.w3.org/ns/auth/acl#trustedApp", + "@type": "@id", + "@isCollection": true, + }, + mode: { + "@id": "http://www.w3.org/ns/auth/acl#mode", + "@isCollection": true, + }, + Append: "http://www.w3.org/ns/auth/acl#Append", + Control: "http://www.w3.org/ns/auth/acl#Control", + Read: "http://www.w3.org/ns/auth/acl#Read", + Write: "http://www.w3.org/ns/auth/acl#Write", + origin: { + "@id": "http://www.w3.org/ns/auth/acl#origin", + "@type": "@id", + }, + key: { + "@id": "http://www.w3.org/ns/auth/cert#key", + "@type": "@id", + "@isCollection": true, + }, + modulus: { + "@id": "http://www.w3.org/ns/auth/cert#modulus", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + exponent: { + "@id": "http://www.w3.org/ns/auth/cert#exponent", + "@type": "http://www.w3.org/2001/XMLSchema#integer", + }, + inbox: { + "@id": "http://www.w3.org/ns/ldp#inbox", + "@type": "@id", + }, + preferencesFile: { + "@id": "http://www.w3.org/ns/pim/space#preferencesFile", + "@type": "@id", + }, + storage: { + "@id": "http://www.w3.org/ns/pim/space#storage", + "@type": "@id", + "@isCollection": true, + }, + account: { + "@id": "http://www.w3.org/ns/solid/terms#account", + "@type": "@id", + }, + privateTypeIndex: { + "@id": "http://www.w3.org/ns/solid/terms#privateTypeIndex", + "@type": "@id", + "@isCollection": true, + }, + publicTypeIndex: { + "@id": "http://www.w3.org/ns/solid/terms#publicTypeIndex", + "@type": "@id", + "@isCollection": true, + }, + knows: { + "@id": "http://xmlns.com/foaf/0.1/knows", + "@type": "@id", + "@isCollection": true, + }, +}; diff --git a/packages/svelte/example/src/.ldo/solidProfile.schema.ts b/packages/svelte/example/src/.ldo/solidProfile.schema.ts new file mode 100644 index 0000000..69466fc --- /dev/null +++ b/packages/svelte/example/src/.ldo/solidProfile.schema.ts @@ -0,0 +1,749 @@ +import { Schema } from "shexj"; + +/** + * ============================================================================= + * solidProfileSchema: ShexJ Schema for solidProfile + * ============================================================================= + */ +export const solidProfileSchema: Schema = { + type: "Schema", + shapes: [ + { + id: "https://shaperepo.com/schemas/solidProfile#SolidProfileShape", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + valueExpr: { + type: "NodeConstraint", + values: ["http://schema.org/Person"], + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "Defines the node as a Person (from Schema.org)", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + valueExpr: { + type: "NodeConstraint", + values: ["http://xmlns.com/foaf/0.1/Person"], + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "Defines the node as a Person (from foaf)", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#fn", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The formatted name of a person. Example: John Smith", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://xmlns.com/foaf/0.1/name", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "An alternate way to define a person's name.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#hasAddress", + valueExpr: + "https://shaperepo.com/schemas/solidProfile#AddressShape", + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The person's street address.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#hasEmail", + valueExpr: + "https://shaperepo.com/schemas/solidProfile#EmailShape", + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The person's email.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#hasPhoto", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "A link to the person's photo", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://xmlns.com/foaf/0.1/img", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "Photo link but in string form", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#hasTelephone", + valueExpr: + "https://shaperepo.com/schemas/solidProfile#PhoneNumberShape", + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "Person's telephone number", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#phone", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "An alternative way to define a person's telephone number using a string", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#organization-name", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The name of the organization with which the person is affiliated", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#role", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The name of the person's role in their organization", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/auth/acl#trustedApp", + valueExpr: + "https://shaperepo.com/schemas/solidProfile#TrustedAppShape", + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A list of app origins that are trusted by this user", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/auth/cert#key", + valueExpr: + "https://shaperepo.com/schemas/solidProfile#RSAPublicKeyShape", + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A list of RSA public keys that are associated with private keys the user holds.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/ldp#inbox", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The user's LDP inbox to which apps can post notifications", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/pim/space#preferencesFile", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The user's preferences", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/pim/space#storage", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The location of a Solid storage server related to this WebId", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/solid/terms#account", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The user's account", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/solid/terms#privateTypeIndex", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A registry of all types used on the user's Pod (for private access only)", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/solid/terms#publicTypeIndex", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A registry of all types used on the user's Pod (for public access)", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://xmlns.com/foaf/0.1/knows", + valueExpr: + "https://shaperepo.com/schemas/solidProfile#SolidProfileShape", + min: 0, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "A list of WebIds for all the people this user knows.", + }, + }, + ], + }, + ], + }, + extra: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], + }, + }, + { + id: "https://shaperepo.com/schemas/solidProfile#AddressShape", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#country-name", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The name of the user's country of residence", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#locality", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The name of the user's locality (City, Town etc.) of residence", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#postal-code", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The user's postal code", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#region", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The name of the user's region (State, Province etc.) of residence", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#street-address", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The user's street address", + }, + }, + ], + }, + ], + }, + }, + }, + { + id: "https://shaperepo.com/schemas/solidProfile#EmailShape", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + valueExpr: { + type: "NodeConstraint", + values: [ + "http://www.w3.org/2006/vcard/ns#Dom", + "http://www.w3.org/2006/vcard/ns#Home", + "http://www.w3.org/2006/vcard/ns#ISDN", + "http://www.w3.org/2006/vcard/ns#Internet", + "http://www.w3.org/2006/vcard/ns#Intl", + "http://www.w3.org/2006/vcard/ns#Label", + "http://www.w3.org/2006/vcard/ns#Parcel", + "http://www.w3.org/2006/vcard/ns#Postal", + "http://www.w3.org/2006/vcard/ns#Pref", + "http://www.w3.org/2006/vcard/ns#Work", + "http://www.w3.org/2006/vcard/ns#X400", + ], + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The type of email.", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#value", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The value of an email as a mailto link (Example )", + }, + }, + ], + }, + ], + }, + extra: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], + }, + }, + { + id: "https://shaperepo.com/schemas/solidProfile#PhoneNumberShape", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + valueExpr: { + type: "NodeConstraint", + values: [ + "http://www.w3.org/2006/vcard/ns#Dom", + "http://www.w3.org/2006/vcard/ns#Home", + "http://www.w3.org/2006/vcard/ns#ISDN", + "http://www.w3.org/2006/vcard/ns#Internet", + "http://www.w3.org/2006/vcard/ns#Intl", + "http://www.w3.org/2006/vcard/ns#Label", + "http://www.w3.org/2006/vcard/ns#Parcel", + "http://www.w3.org/2006/vcard/ns#Postal", + "http://www.w3.org/2006/vcard/ns#Pref", + "http://www.w3.org/2006/vcard/ns#Work", + "http://www.w3.org/2006/vcard/ns#X400", + ], + }, + min: 0, + max: 1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "They type of Phone Number", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/2006/vcard/ns#value", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: + "The value of a phone number as a tel link (Example )", + }, + }, + ], + }, + ], + }, + extra: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], + }, + }, + { + id: "https://shaperepo.com/schemas/solidProfile#TrustedAppShape", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/auth/acl#mode", + valueExpr: { + type: "NodeConstraint", + values: [ + "http://www.w3.org/ns/auth/acl#Append", + "http://www.w3.org/ns/auth/acl#Control", + "http://www.w3.org/ns/auth/acl#Read", + "http://www.w3.org/ns/auth/acl#Write", + ], + }, + min: 1, + max: -1, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The level of access provided to this origin", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/auth/acl#origin", + valueExpr: { + type: "NodeConstraint", + nodeKind: "iri", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "The app origin the user trusts", + }, + }, + ], + }, + ], + }, + }, + }, + { + id: "https://shaperepo.com/schemas/solidProfile#RSAPublicKeyShape", + type: "ShapeDecl", + shapeExpr: { + type: "Shape", + expression: { + type: "EachOf", + expressions: [ + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/auth/cert#modulus", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#string", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "RSA Modulus", + }, + }, + ], + }, + { + type: "TripleConstraint", + predicate: "http://www.w3.org/ns/auth/cert#exponent", + valueExpr: { + type: "NodeConstraint", + datatype: "http://www.w3.org/2001/XMLSchema#integer", + }, + annotations: [ + { + type: "Annotation", + predicate: "http://www.w3.org/2000/01/rdf-schema#comment", + object: { + value: "RSA Exponent", + }, + }, + ], + }, + ], + }, + }, + }, + ], +}; diff --git a/packages/svelte/example/src/.ldo/solidProfile.shapeTypes.ts b/packages/svelte/example/src/.ldo/solidProfile.shapeTypes.ts new file mode 100644 index 0000000..71426e4 --- /dev/null +++ b/packages/svelte/example/src/.ldo/solidProfile.shapeTypes.ts @@ -0,0 +1,71 @@ +import { ShapeType } from "@ldo/ldo"; +import { solidProfileSchema } from "./solidProfile.schema"; +import { solidProfileContext } from "./solidProfile.context"; +import { + SolidProfileShape, + AddressShape, + EmailShape, + PhoneNumberShape, + TrustedAppShape, + RSAPublicKeyShape, +} from "./solidProfile.typings"; + +/** + * ============================================================================= + * LDO ShapeTypes solidProfile + * ============================================================================= + */ + +/** + * SolidProfileShape ShapeType + */ +export const SolidProfileShapeShapeType: ShapeType = { + schema: solidProfileSchema, + shape: "https://shaperepo.com/schemas/solidProfile#SolidProfileShape", + context: solidProfileContext, +}; + +/** + * AddressShape ShapeType + */ +export const AddressShapeShapeType: ShapeType = { + schema: solidProfileSchema, + shape: "https://shaperepo.com/schemas/solidProfile#AddressShape", + context: solidProfileContext, +}; + +/** + * EmailShape ShapeType + */ +export const EmailShapeShapeType: ShapeType = { + schema: solidProfileSchema, + shape: "https://shaperepo.com/schemas/solidProfile#EmailShape", + context: solidProfileContext, +}; + +/** + * PhoneNumberShape ShapeType + */ +export const PhoneNumberShapeShapeType: ShapeType = { + schema: solidProfileSchema, + shape: "https://shaperepo.com/schemas/solidProfile#PhoneNumberShape", + context: solidProfileContext, +}; + +/** + * TrustedAppShape ShapeType + */ +export const TrustedAppShapeShapeType: ShapeType = { + schema: solidProfileSchema, + shape: "https://shaperepo.com/schemas/solidProfile#TrustedAppShape", + context: solidProfileContext, +}; + +/** + * RSAPublicKeyShape ShapeType + */ +export const RSAPublicKeyShapeShapeType: ShapeType = { + schema: solidProfileSchema, + shape: "https://shaperepo.com/schemas/solidProfile#RSAPublicKeyShape", + context: solidProfileContext, +}; diff --git a/packages/svelte/example/src/.ldo/solidProfile.typings.ts b/packages/svelte/example/src/.ldo/solidProfile.typings.ts new file mode 100644 index 0000000..95dbaef --- /dev/null +++ b/packages/svelte/example/src/.ldo/solidProfile.typings.ts @@ -0,0 +1,293 @@ +import { LdoJsonldContext, LdSet } from "@ldo/ldo"; + +/** + * ============================================================================= + * Typescript Typings for solidProfile + * ============================================================================= + */ + +/** + * SolidProfileShape Type + */ +export interface SolidProfileShape { + "@id"?: string; + "@context"?: LdoJsonldContext; + /** + * Defines the node as a Person (from Schema.org) | Defines the node as a Person (from foaf) + */ + type: LdSet< + | { + "@id": "Person"; + } + | { + "@id": "Person2"; + } + >; + /** + * The formatted name of a person. Example: John Smith + */ + fn?: string; + /** + * An alternate way to define a person's name. + */ + name?: string; + /** + * The person's street address. + */ + hasAddress?: LdSet; + /** + * The person's email. + */ + hasEmail?: LdSet; + /** + * A link to the person's photo + */ + hasPhoto?: { + "@id": string; + }; + /** + * Photo link but in string form + */ + img?: string; + /** + * Person's telephone number + */ + hasTelephone?: LdSet; + /** + * An alternative way to define a person's telephone number using a string + */ + phone?: string; + /** + * The name of the organization with which the person is affiliated + */ + organizationName?: string; + /** + * The name of the person's role in their organization + */ + role?: string; + /** + * A list of app origins that are trusted by this user + */ + trustedApp?: LdSet; + /** + * A list of RSA public keys that are associated with private keys the user holds. + */ + key?: LdSet; + /** + * The user's LDP inbox to which apps can post notifications + */ + inbox: { + "@id": string; + }; + /** + * The user's preferences + */ + preferencesFile?: { + "@id": string; + }; + /** + * The location of a Solid storage server related to this WebId + */ + storage?: LdSet<{ + "@id": string; + }>; + /** + * The user's account + */ + account?: { + "@id": string; + }; + /** + * A registry of all types used on the user's Pod (for private access only) + */ + privateTypeIndex?: LdSet<{ + "@id": string; + }>; + /** + * A registry of all types used on the user's Pod (for public access) + */ + publicTypeIndex?: LdSet<{ + "@id": string; + }>; + /** + * A list of WebIds for all the people this user knows. + */ + knows?: LdSet; +} + +/** + * AddressShape Type + */ +export interface AddressShape { + "@id"?: string; + "@context"?: LdoJsonldContext; + /** + * The name of the user's country of residence + */ + countryName?: string; + /** + * The name of the user's locality (City, Town etc.) of residence + */ + locality?: string; + /** + * The user's postal code + */ + postalCode?: string; + /** + * The name of the user's region (State, Province etc.) of residence + */ + region?: string; + /** + * The user's street address + */ + streetAddress?: string; +} + +/** + * EmailShape Type + */ +export interface EmailShape { + "@id"?: string; + "@context"?: LdoJsonldContext; + /** + * The type of email. + */ + type?: + | { + "@id": "Dom"; + } + | { + "@id": "Home"; + } + | { + "@id": "ISDN"; + } + | { + "@id": "Internet"; + } + | { + "@id": "Intl"; + } + | { + "@id": "Label"; + } + | { + "@id": "Parcel"; + } + | { + "@id": "Postal"; + } + | { + "@id": "Pref"; + } + | { + "@id": "Work"; + } + | { + "@id": "X400"; + }; + /** + * The value of an email as a mailto link (Example ) + */ + value: { + "@id": string; + }; +} + +/** + * PhoneNumberShape Type + */ +export interface PhoneNumberShape { + "@id"?: string; + "@context"?: LdoJsonldContext; + /** + * They type of Phone Number + */ + type?: + | { + "@id": "Dom"; + } + | { + "@id": "Home"; + } + | { + "@id": "ISDN"; + } + | { + "@id": "Internet"; + } + | { + "@id": "Intl"; + } + | { + "@id": "Label"; + } + | { + "@id": "Parcel"; + } + | { + "@id": "Postal"; + } + | { + "@id": "Pref"; + } + | { + "@id": "Work"; + } + | { + "@id": "X400"; + }; + /** + * The value of a phone number as a tel link (Example ) + */ + value: { + "@id": string; + }; +} + +/** + * TrustedAppShape Type + */ +export interface TrustedAppShape { + "@id"?: string; + "@context"?: LdoJsonldContext; + /** + * The level of access provided to this origin + */ + mode: LdSet< + | { + "@id": "Append"; + } + | { + "@id": "Control"; + } + | { + "@id": "Read"; + } + | { + "@id": "Write"; + } + >; + /** + * The app origin the user trusts + */ + origin: { + "@id": string; + }; +} + +/** + * RSAPublicKeyShape Type + */ +export interface RSAPublicKeyShape { + "@id"?: string; + "@context"?: LdoJsonldContext; + /** + * RSA Modulus + */ + modulus: string; + /** + * RSA Exponent + */ + exponent: number; +} diff --git a/packages/svelte/example/src/App.svelte b/packages/svelte/example/src/App.svelte index 5a0a25c..827934b 100644 --- a/packages/svelte/example/src/App.svelte +++ b/packages/svelte/example/src/App.svelte @@ -1,29 +1,34 @@ -
-

@ldo/svelte Example App

-

{message}

-
+{#if $resource.isLoading() || !$profile} +

loading

+{:else} +
+ {#if firstFriendId} +

{firstFriendId}

+ {:else} +

No friend found or friend has no @id.

+ {/if} + +
    + {#each friendArray as friend (friend["@id"])} +
  • {friend["@id"]}
  • + {:else} +
  • No friends listed.
  • + {/each} +
+
+{/if} diff --git a/packages/svelte/example/src/ldoSvelteMethods.ts b/packages/svelte/example/src/ldoSvelteMethods.ts new file mode 100644 index 0000000..bb5d03b --- /dev/null +++ b/packages/svelte/example/src/ldoSvelteMethods.ts @@ -0,0 +1,13 @@ +import { createLdoSvelteMethods } from "@ldo/svelte"; +import { solidConnectedPlugin } from "@ldo/connected-solid"; + +export const { + dataset, + useLdo, + useMatchObject, + useMatchSubject, + useResource, + useSubject, + useSubscribeToResource, + useLinkQuery, +} = createLdoSvelteMethods([solidConnectedPlugin]); diff --git a/packages/svelte/example/test-server/configs/components-config/unauthenticatedServer.json b/packages/svelte/example/test-server/configs/components-config/unauthenticatedServer.json new file mode 100644 index 0000000..0036761 --- /dev/null +++ b/packages/svelte/example/test-server/configs/components-config/unauthenticatedServer.json @@ -0,0 +1,52 @@ +{ + "@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld", + "import": [ + "css:config/app/init/initialize-intro.json", + "css:config/app/main/default.json", + "css:config/app/variables/default.json", + "css:config/http/handler/default.json", + "css:config/http/middleware/default.json", + "css:config/http/notifications/all.json", + "css:config/http/server-factory/http.json", + "css:config/http/static/default.json", + "css:config/identity/access/public.json", + "css:config/identity/email/default.json", + "css:config/identity/handler/default.json", + "css:config/identity/oidc/default.json", + "css:config/identity/ownership/token.json", + "css:config/identity/pod/static.json", + "css:config/ldp/authentication/dpop-bearer.json", + "css:config/ldp/authorization/webacl.json", + "css:config/ldp/handler/default.json", + "css:config/ldp/metadata-parser/default.json", + "css:config/ldp/metadata-writer/default.json", + "css:config/ldp/modes/default.json", + "css:config/storage/backend/memory.json", + "css:config/storage/key-value/resource-store.json", + "css:config/storage/location/root.json", + "css:config/storage/middleware/default.json", + "css:config/util/auxiliary/acl.json", + "css:config/util/identifiers/suffix.json", + "css:config/util/index/default.json", + "css:config/util/logging/winston.json", + "css:config/util/representation-conversion/default.json", + "css:config/util/resource-locker/memory.json", + "css:config/util/variables/default.json" + ], + "@graph": [ + { + "comment": "A Solid server that stores its resources in memory and uses WAC for authorization." + }, + { + "comment": "The location of the new pod templates folder.", + "@type": "Override", + "overrideInstance": { + "@id": "urn:solid-server:default:PodResourcesGenerator" + }, + "overrideParameters": { + "@type": "StaticFolderGenerator", + "templateFolder": "./example/test-server/configs/template" + } + } + ] +} \ No newline at end of file diff --git a/packages/svelte/example/test-server/configs/solid-css-seed.json b/packages/svelte/example/test-server/configs/solid-css-seed.json new file mode 100644 index 0000000..5894d0d --- /dev/null +++ b/packages/svelte/example/test-server/configs/solid-css-seed.json @@ -0,0 +1,9 @@ +[ + { + "email": "hello@example.com", + "password": "abc123", + "pods": [ + { "name": "example" } + ] + } +] \ No newline at end of file diff --git a/packages/svelte/example/test-server/configs/template/wac/.acl.hbs b/packages/svelte/example/test-server/configs/template/wac/.acl.hbs new file mode 100644 index 0000000..48fd101 --- /dev/null +++ b/packages/svelte/example/test-server/configs/template/wac/.acl.hbs @@ -0,0 +1,13 @@ +@prefix : <#>. +@prefix acl: . +@prefix foaf: . +@prefix eve: <./>. +@prefix c: <./profile/card#>. + +:ControlReadWrite + a acl:Authorization; + acl:accessTo eve:; + acl:agent c:me, ; + acl:agentClass foaf:Agent; + acl:default eve:; + acl:mode acl:Control, acl:Read, acl:Write. \ No newline at end of file diff --git a/packages/svelte/example/test-server/configs/template/wac/link-query/main-profile.ttl b/packages/svelte/example/test-server/configs/template/wac/link-query/main-profile.ttl new file mode 100644 index 0000000..5a1891b --- /dev/null +++ b/packages/svelte/example/test-server/configs/template/wac/link-query/main-profile.ttl @@ -0,0 +1,7 @@ +@prefix foaf: . +@prefix : <#> . + +:me a foaf:Person ; + foaf:name "Main User" ; + foaf:mbox ; + foaf:knows . \ No newline at end of file diff --git a/packages/svelte/example/test-server/configs/template/wac/link-query/other-profile.ttl b/packages/svelte/example/test-server/configs/template/wac/link-query/other-profile.ttl new file mode 100644 index 0000000..bf3b3b8 --- /dev/null +++ b/packages/svelte/example/test-server/configs/template/wac/link-query/other-profile.ttl @@ -0,0 +1,7 @@ +@prefix foaf: . +@prefix : <#> . + +:me a foaf:Person ; + foaf:name "Other User" ; + foaf:mbox ; + foaf:knows . \ No newline at end of file diff --git a/packages/svelte/example/test-server/configs/template/wac/link-query/third-profile.ttl b/packages/svelte/example/test-server/configs/template/wac/link-query/third-profile.ttl new file mode 100644 index 0000000..e6dc8ce --- /dev/null +++ b/packages/svelte/example/test-server/configs/template/wac/link-query/third-profile.ttl @@ -0,0 +1,7 @@ +@prefix foaf: . +@prefix : <#> . + +:me a foaf:Person ; + foaf:name "Third User" ; + foaf:mbox ; + foaf:knows . \ No newline at end of file diff --git a/packages/svelte/example/test-server/configs/template/wac/profile/card.acl.hbs b/packages/svelte/example/test-server/configs/template/wac/profile/card.acl.hbs new file mode 100644 index 0000000..ea7c2a8 --- /dev/null +++ b/packages/svelte/example/test-server/configs/template/wac/profile/card.acl.hbs @@ -0,0 +1,19 @@ +# ACL resource for the WebID profile document +@prefix acl: . +@prefix foaf: . + +# The WebID profile is readable by the public. +# This is required for discovery and verification, +# e.g. when checking identity providers. +<#public> + a acl:Authorization; + acl:agentClass foaf:Agent; + acl:accessTo <./card>; + acl:mode acl:Read. + +# The owner has full access to the profile +<#owner> + a acl:Authorization; + acl:agent <{{webId}}>; + acl:accessTo <./card>; + acl:mode acl:Read, acl:Write, acl:Control. \ No newline at end of file diff --git a/packages/svelte/example/test-server/runServer.ts b/packages/svelte/example/test-server/runServer.ts new file mode 100644 index 0000000..6f1140a --- /dev/null +++ b/packages/svelte/example/test-server/runServer.ts @@ -0,0 +1,18 @@ +import { createApp } from "@ldo/test-solid-server/dist/createServer"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +async function run() { + const app = await createApp( + 3004, + path.join( + __dirname, + "./configs/components-config/unauthenticatedServer.json", + ), + ); + await app.start(); +} +run(); diff --git a/packages/svelte/package.json b/packages/svelte/package.json index 1353efa..de87a5f 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -8,7 +8,9 @@ "types": "dist/index.d.ts", "type": "module", "scripts": { - "dev": "vite --config vite.config.example.ts", + "dev": "concurrently \"npm run dev:pod\" \"npm run dev:app\"", + "dev:pod": "tsx ./example/test-server/runServer.ts", + "dev:app": "vite --config vite.config.example.ts", "build": "rimraf dist && vite build", "build:example": "vite build --config vite.config.example.ts example", "test": "jest", @@ -28,11 +30,13 @@ }, "homepage": "https://github.com/o-development/ldo/tree/main/packages/svelte#readme", "devDependencies": { + "@ldo/test-solid-server": "^1.0.0-alpha.9", "@sveltejs/vite-plugin-svelte": "^2.5.3", "@testing-library/jest-dom": "^6.6.3", "@testing-library/svelte": "^5.2.7", "@tsconfig/svelte": "^5.0.4", "@types/jest": "^29.5.14", + "concurrently": "^9.1.2", "eslint-plugin-svelte3": "^4.0.0", "identity-obj-proxy": "^3.0.0", "jest": "^29.7.0", @@ -42,7 +46,6 @@ "svelte-jester": "^5.0.0", "svelte-preprocess": "^5.1.4", "ts-jest": "^29.3.2", - "ts-node": "^10.9.2", "tslib": "^2.8.1", "typescript": "^5.8.3", "vite": "^4.5.0", @@ -57,7 +60,8 @@ "@ldo/ldo": "^1.0.0-alpha.9", "@ldo/rdf-utils": "^1.0.0-alpha.9", "@ldo/subscribable-dataset": "^1.0.0-alpha.9", - "@rdfjs/data-model": "^1.2.0" + "@rdfjs/data-model": "^1.2.0", + "tsx": "^4.19.4" }, "files": [ "dist", diff --git a/packages/svelte/src/createLdoSvelteMethods.tsx b/packages/svelte/src/createLdoSvelteMethods.tsx new file mode 100644 index 0000000..95c01d6 --- /dev/null +++ b/packages/svelte/src/createLdoSvelteMethods.tsx @@ -0,0 +1,77 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { createUseLdo } from "./methods/useLdo"; +import { + createConnectedLdoDataset, + type ConnectedPlugin, +} from "@ldo/connected"; +import { createUseMatchObject } from "./methods/useMatchObject"; +import { createUseMatchSubject } from "./methods/useMatchSubject"; +import { createUseResource } from "./methods/useResource"; +import { createUseSubject } from "./methods/useSubject"; +import { createUseSubscribeToResource } from "./methods/useSubscribeToResource"; +import { createUseLinkQuery } from "./methods/useLinkQuery"; + +/** + * A function that creates all common react functions given specific plugin. + * + * @example + * `methods.ts` + * ```tyepscript + * import { solidConnectedPlugin } from "@ldo/connected-solid"; + * import { nextGraphConnectedPlugin } from "@ldo/connected-nextgraph"; + * import { createLdoReactMethods } from "@ldo/react"; + * + * // Export the results to be used in the reset of the application + * export const { + * dataset, + * useLdo, + * useMatchObject, + * useMatchSubject, + * useResource, + * useSubject, + * useSubscribeToResource, + * useLinkQuery, + * } = createLdoReactMethods([ + * solidConnectedPlugin, + * nextGraphConnectedPlugin + * ]); + * ``` + * + * `App.tsx` + * ```typescript + * import react, { FunctionComponent } from "react"; + * import { PostShShapeType } from "./.ldo/posts.shapeType.ts"; + * import { useResource, useSubject } from "./methods.ts"; + * + * const UseSubjectTest: FunctionComponent = () => { + * const resource = useResource(SAMPLE_DATA_URI); + * const post = useSubject(PostShShapeType, `${SAMPLE_DATA_URI}#Post1`); + * if (resource.isLoading() || !post) return

loading

; + * + * return ( + *
    + * {post.publisher.map((publisher) => { + * return
  • {publisher["@id"]}
  • ; + * })} + *
+ * ); + * }; + * ``` + */ +export function createLdoSvelteMethods< + Plugins extends ConnectedPlugin[], +>(plugins: Plugins) { + const dataset = createConnectedLdoDataset(plugins); + dataset.setMaxListeners(1000); + + return { + dataset, + useLdo: createUseLdo(dataset), + useMatchObject: createUseMatchObject(dataset), + useMatchSubject: createUseMatchSubject(dataset), + useResource: createUseResource(dataset), + useSubject: createUseSubject(dataset), + useSubscribeToResource: createUseSubscribeToResource(dataset), + useLinkQuery: createUseLinkQuery(dataset), + }; +} diff --git a/packages/svelte/src/index.ts b/packages/svelte/src/index.ts index e9622f6..a9b5431 100644 --- a/packages/svelte/src/index.ts +++ b/packages/svelte/src/index.ts @@ -1,7 +1,9 @@ -export function myExampleFunction() { - console.log("Hello Example Function"); -} +export * from "./createLdoSvelteMethods"; -export function myReactiveStore() { - console.log("Hello Example Store"); -} +export * from "./methods/useLdo"; +export * from "./methods/useMatchObject"; +export * from "./methods/useMatchSubject"; +export * from "./methods/useResource"; +export * from "./methods/useSubject"; +export * from "./methods/useSubscribeToResource"; +export * from "./methods/useLinkQuery"; diff --git a/packages/svelte/src/methods/useLdo.ts b/packages/svelte/src/methods/useLdo.ts new file mode 100644 index 0000000..ef554f1 --- /dev/null +++ b/packages/svelte/src/methods/useLdo.ts @@ -0,0 +1,147 @@ +import { + // changeData, + type ConnectedLdoDataset, + type ConnectedLdoTransactionDataset, + type ConnectedPlugin, +} from "@ldo/connected"; +import { type LdoBase, type ShapeType } from "@ldo/ldo"; +import type { SubjectNode } from "@ldo/rdf-utils"; + +/** + * The methods returned by useLdo + */ +export interface UseLdoMethods { + /** + * A ConnectedLdoDataset + */ + dataset: ConnectedLdoDataset; + /** + * Retireves a representation of a Resource at the given URI. This resource + * represents the current state of the resource: whether it is currently + * fetched or in the process of fetching as well as some information about it. + * + * @param uri - the URI of the resource + * @param pluginName - optionally, force this function to choose a specific + * plugin to use rather than perform content negotiation. + * + * @returns a Resource + */ + getResource: ConnectedLdoDataset["getResource"]; + /** + * Sets conetext for a specific plugin + * + * @param pluginName - the name of the plugin + * @param context - the context for this specific plugin + */ + setContext: ConnectedLdoDataset["setContext"]; + /** + * Gets a linked data object based on the subject + */ + getSubject( + shapeType: ShapeType, + subject: string | SubjectNode, + ): Type; + /** + * Shorthand for connectedLdoDataset + * .usingType(shapeType) + * .write(...resources.map((r) => r.uri)) + * .fromSubject(subject); + * @param shapeType - The shapetype to represent the data + * @param subject - A subject URI + * @param resources - The resources changes to should written to + */ + createData( + shapeType: ShapeType, + subject: string | SubjectNode, + resource: Plugins[number]["types"]["resource"], + ...additionalResources: Plugins[number]["types"]["resource"][] + ): Type; + /** + * Returns a writable LinkedDataObject given a linked data object + */ + changeData( + input: Type, + resource: Plugins[number]["types"]["resource"], + ...additionalResources: Plugins[number]["types"]["resource"][] + ): Type; + /** + * Commits the data of a writable Linke Data Object back to the remote. + */ + commitData( + input: LdoBase, + ): ReturnType["commitToRemote"]>; +} + +/** + * @internal + * Creates the useLdoHook + */ +export function createUseLdo( + dataset: ConnectedLdoDataset, +) { + throw new Error("Not Implemented"); + // const toReturn = { + // dataset, + // /** + // * Gets a resource + // */ + // getResource: dataset.getResource.bind(dataset), + // /** + // * Set the context + // */ + // setContext: dataset.setContext.bind(dataset), + // /** + // * Returns a Linked Data Object for a subject + // * @param shapeType The shape type for the data + // * @param subject Subject Node + // * @returns A Linked Data Object + // */ + // getSubject( + // shapeType: ShapeType, + // subject: string | SubjectNode, + // ): Type { + // return dataset.usingType(shapeType).fromSubject(subject); + // }, + // /** + // * Begins tracking changes to eventually commit for a new subject + // * @param shapeType The shape type that defines the created data + // * @param subject The RDF subject for a Linked Data Object + // * @param resources Any number of resources to which this data should be written + // * @returns A Linked Data Object to modify and commit + // */ + // createData( + // shapeType: ShapeType, + // subject: string | SubjectNode, + // resource: Plugins[number]["types"]["resource"], + // ...additionalResources: Plugins[number]["types"]["resource"][] + // ): Type { + // return dataset.createData( + // shapeType, + // subject, + // resource, + // ...additionalResources, + // ); + // }, + // /** + // * Begins tracking changes to eventually commit + // * @param input A linked data object to track changes on + // * @param resources + // */ + // changeData: changeData, + // /** + // * Commits the transaction to the global dataset, syncing all subscribing + // * components and Solid Pods + // */ + // commitData( + // input: LdoBase, + // ): ReturnType["commitToRemote"]> { + // const inputDataset = getDataset( + // input, + // ) as ConnectedLdoTransactionDataset; + // return inputDataset.commitToRemote(); + // }, + // }; + // return function useLdo(): UseLdoMethods { + // throw new Error("Not Implemented"); + // }; +} diff --git a/packages/svelte/src/methods/useLinkQuery.ts b/packages/svelte/src/methods/useLinkQuery.ts new file mode 100644 index 0000000..8f8c88d --- /dev/null +++ b/packages/svelte/src/methods/useLinkQuery.ts @@ -0,0 +1,34 @@ +import type { + ConnectedLdoDataset, + ConnectedPlugin, + ExpandDeep, + LQInput, + LQReturn, +} from "@ldo/connected"; +import type { LdoBase, ShapeType } from "@ldo/ldo"; +import type { SubjectNode } from "@ldo/rdf-utils"; + +/** + * @internal + * + * Creates a useMatchSubject function. + */ +export function createUseLinkQuery( + dataset: ConnectedLdoDataset, +) { + /** + * Returns an array of matching linked data objects. Triggers a rerender if + * the data is updated. + */ + return function useQueryLink< + Type extends LdoBase, + QueryInput extends LQInput, + >( + shapeType: ShapeType, + startingResource: string, + startingSubject: SubjectNode | string, + linkQuery: QueryInput, + ): ExpandDeep> | undefined { + throw new Error("Not Implemented"); + }; +} diff --git a/packages/svelte/src/methods/useMatchObject.ts b/packages/svelte/src/methods/useMatchObject.ts new file mode 100644 index 0000000..d598197 --- /dev/null +++ b/packages/svelte/src/methods/useMatchObject.ts @@ -0,0 +1,25 @@ +import type { LdoBase, LdSet, ShapeType } from "@ldo/ldo"; +import type { QuadMatch } from "@ldo/rdf-utils"; +import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; + +/** + * @internal + * + * Creates a useMatchObject function + */ +export function createUseMatchObject( + dataset: ConnectedLdoDataset, +) { + /** + * Returns an array of matching items and triggers a rerender when that data + * is updated. + */ + return function useMatchObject( + shapeType: ShapeType, + subject?: QuadMatch[0] | string, + predicate?: QuadMatch[1] | string, + graph?: QuadMatch[3] | string, + ): LdSet { + throw new Error("Not Implemented"); + }; +} diff --git a/packages/svelte/src/methods/useMatchSubject.ts b/packages/svelte/src/methods/useMatchSubject.ts new file mode 100644 index 0000000..11a7331 --- /dev/null +++ b/packages/svelte/src/methods/useMatchSubject.ts @@ -0,0 +1,25 @@ +import type { LdoBase, LdSet, ShapeType } from "@ldo/ldo"; +import type { QuadMatch } from "@ldo/rdf-utils"; +import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; + +/** + * @internal + * + * Creates a useMatchSubject function. + */ +export function createUseMatchSubject( + dataset: ConnectedLdoDataset, +) { + /** + * Returns an array of matching linked data objects. Triggers a rerender if + * the data is updated. + */ + return function useMatchSubject( + shapeType: ShapeType, + predicate?: QuadMatch[1] | string, + object?: QuadMatch[2] | string, + graph?: QuadMatch[3] | string, + ): LdSet { + throw new Error("Not Implemented"); + }; +} diff --git a/packages/svelte/src/methods/useResource.ts b/packages/svelte/src/methods/useResource.ts new file mode 100644 index 0000000..c50b471 --- /dev/null +++ b/packages/svelte/src/methods/useResource.ts @@ -0,0 +1,94 @@ +import type { + ConnectedLdoDataset, + ConnectedPlugin, + GetResourceReturnType, +} from "@ldo/connected"; +import { writable, type Readable } from "svelte/store"; + +export interface UseResourceOptions { + pluginName?: Name; + suppressInitialRead?: boolean; + reloadOnMount?: boolean; + subscribe?: boolean; +} + +export type useResourceType = { + < + Name extends Plugins[number]["name"], + Plugin extends Extract, + UriType extends string, + >( + uri: UriType, + options?: UseResourceOptions, + ): Readable>; + < + Name extends Plugins[number]["name"], + Plugin extends Extract, + UriType extends string, + >( + uri?: UriType, + options?: UseResourceOptions, + ): Readable | undefined>; +}; + +/** + * @internal + * + * Creates a useResource function. + */ +export function createUseResource( + dataset: ConnectedLdoDataset, +): useResourceType { + /** + * Returns a resource and triggers a rerender if that resource is updated. + */ + return function useResource< + Name extends Plugins[number]["name"], + Plugin extends Extract, + UriType extends string, + >( + uri?: UriType, + options?: UseResourceOptions, + ): Readable | undefined> { + let resource: GetResourceReturnType | undefined; + // Get the resource based on incoming data + if (uri) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + resource = dataset.getResource(uri) as any; + // Run read operations if necissary + if (!options?.suppressInitialRead) { + if (options?.reloadOnMount) { + resource!.read(); + } else { + resource!.readIfUnfetched(); + } + } + } else { + resource = undefined; + } + + // The Svelte store + const store = writable | undefined>( + resource, + (set) => { + const onResourceUpdate = () => { + set(resource); + }; + + if (resource) { + resource.on("update", onResourceUpdate); + + // TODO: handle subscriptions + + return () => { + resource.off("update", onResourceUpdate); + }; + } + }, + ); + + return { + subscribe: store.subscribe, + }; + }; +} diff --git a/packages/svelte/src/methods/useSubject.ts b/packages/svelte/src/methods/useSubject.ts new file mode 100644 index 0000000..9b81519 --- /dev/null +++ b/packages/svelte/src/methods/useSubject.ts @@ -0,0 +1,48 @@ +import type { SubjectNode } from "@ldo/rdf-utils"; +import type { ShapeType } from "@ldo/ldo"; +import type { LdoBuilder } from "@ldo/ldo"; +import type { LdoBase } from "@ldo/ldo"; + +import { useTrackingProxy } from "../util/useTrackingProxy"; +import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; +import type { Readable } from "svelte/store"; + +export type useSubjectType = { + ( + shapeType: ShapeType, + subject: string | SubjectNode, + ): Readable; + ( + shapeType: ShapeType, + subject?: string | SubjectNode, + ): Readable; + ( + shapeType: ShapeType, + subject?: string | SubjectNode, + ): Readable; +}; + +/** + * @internal + * + * Creates a useSubject function. + */ +export function createUseSubject( + dataset: ConnectedLdoDataset, +): useSubjectType { + /** + * Returns a Linked Data Object based on the provided subject. Triggers a + * rerender if the data is udpated. + */ + return function useSubject( + shapeType: ShapeType, + subject?: string | SubjectNode, + ): Readable { + const fromSubject = (builder: LdoBuilder) => { + if (!subject) return; + return builder.fromSubject(subject); + }; + + return useTrackingProxy(shapeType, fromSubject, dataset); + }; +} diff --git a/packages/svelte/src/methods/useSubscribeToResource.ts b/packages/svelte/src/methods/useSubscribeToResource.ts new file mode 100644 index 0000000..a75f1f6 --- /dev/null +++ b/packages/svelte/src/methods/useSubscribeToResource.ts @@ -0,0 +1,17 @@ +import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; + +/** + * @internal + * + * Creates a useSubscribeToResource function. + */ +export function createUseSubscribeToResource( + dataset: ConnectedLdoDataset, +) { + /** + * Starts a subscription to a resource. + */ + return function useSubscribeToResource(...uris: string[]): void { + throw new Error("Not Implemented"); + }; +} diff --git a/packages/svelte/src/util/useTrackingProxy.ts b/packages/svelte/src/util/useTrackingProxy.ts new file mode 100644 index 0000000..0417562 --- /dev/null +++ b/packages/svelte/src/util/useTrackingProxy.ts @@ -0,0 +1,44 @@ +import type { LdoBuilder } from "@ldo/ldo"; +import type { LdoBase, LdoDataset, ShapeType } from "@ldo/ldo"; +import { createTrackingProxyBuilder } from "@ldo/connected"; +import { writable, type Readable } from "svelte/store"; +import type { nodeEventListener } from "@ldo/subscribable-dataset"; + +/** + * @internal + * + * A hook for tracking proxies + */ +export function useTrackingProxy( + shapeType: ShapeType, + createLdo: (builder: LdoBuilder) => ReturnType, + dataset: LdoDataset, +): Readable { + const forceUpdateInfo: { + set?: (item: ReturnType) => void; + ldo?: ReturnType; + } = {}; + + const forceUpdate: nodeEventListener = () => { + dataset.removeListenerFromAllEvents(forceUpdate); + const builder = createTrackingProxyBuilder(dataset, shapeType, forceUpdate); + const linkedDataObject = createLdo(builder); + forceUpdateInfo.ldo = linkedDataObject; + if (forceUpdateInfo.set && forceUpdateInfo.ldo) + forceUpdateInfo.set(forceUpdateInfo.ldo); + }; + forceUpdate({}, "", [undefined, undefined, undefined, undefined]); + + // The Svelte store + const store = writable(forceUpdateInfo.ldo, (set) => { + forceUpdateInfo.set = set; + + return () => { + dataset.removeListenerFromAllEvents(forceUpdate); + }; + }); + + return { + subscribe: store.subscribe, + }; +} diff --git a/packages/test-solid-server/src/createServer.ts b/packages/test-solid-server/src/createServer.ts index 19c8e3d..ceffcaf 100644 --- a/packages/test-solid-server/src/createServer.ts +++ b/packages/test-solid-server/src/createServer.ts @@ -3,10 +3,6 @@ import * as path from "path"; import type { App } from "@solid/community-server"; import { AppRunner, resolveModulePath } from "@solid/community-server"; -import "jest-rdf"; - -// Use an increased timeout, since the CSS server takes too much setup time. -jest.setTimeout(40_000); export async function createApp( port: number, diff --git a/packages/test-solid-server/src/setupTestServer.ts b/packages/test-solid-server/src/setupTestServer.ts index ccbf7da..86f4948 100644 --- a/packages/test-solid-server/src/setupTestServer.ts +++ b/packages/test-solid-server/src/setupTestServer.ts @@ -6,6 +6,10 @@ import type { ResourceInfo } from "./resourceUtils"; import { cleanResources, initResources } from "./resourceUtils"; import { generateAuthFetch } from "./authFetch"; import fs from "fs/promises"; +import "jest-rdf"; + +// Use an increased timeout, since the CSS server takes too much setup time. +jest.setTimeout(40_000); export function setupServer( port: number,