diff --git a/bookmarks/soukai/demo/package-lock.json b/bookmarks/soukai/demo/package-lock.json index eedf3b6..62686c6 100644 --- a/bookmarks/soukai/demo/package-lock.json +++ b/bookmarks/soukai/demo/package-lock.json @@ -21,6 +21,7 @@ "react-dom": "^18.2.0", "recoil": "^0.7.7", "soukai-solid": "^0.5.2", + "soukai-solid-bookmarks": "^0.0.0", "uuid": "^9.0.1" }, "devDependencies": { @@ -1421,6 +1422,17 @@ "react": ">=18" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "http://localhost:4873/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@digitalbazaar/http-client": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@digitalbazaar/http-client/-/http-client-1.2.0.tgz", @@ -2121,6 +2133,28 @@ "node": ">= 10.14.2" } }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "http://localhost:4873/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "http://localhost:4873/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "http://localhost:4873/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2252,7 +2286,7 @@ "version": "1.3.95", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.95.tgz", "integrity": "sha512-PMrNeuqIusq9DPDooV3FfNEbZuTu5jKAc04N3Hm6Uk2Fl49cqElLFQ4xvl4qDmVDz97n3n/C1RE0/f6WyGPEiA==", - "dev": true, + "devOptional": true, "hasInstallScript": true, "dependencies": { "@swc/counter": "^0.1.1", @@ -2450,13 +2484,33 @@ "version": "0.1.2", "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.2.tgz", "integrity": "sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==", - "dev": true + "devOptional": true }, "node_modules/@swc/types": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.5.tgz", "integrity": "sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==", - "dev": true + "devOptional": true + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "http://localhost:4873/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "http://localhost:4873/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "http://localhost:4873/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "http://localhost:4873/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" }, "node_modules/@types/http-link-header": { "version": "1.0.4", @@ -2606,8 +2660,7 @@ "node_modules/@types/webpack-env": { "version": "1.18.3", "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.18.3.tgz", - "integrity": "sha512-v4CH6FLBCftYGFAswDhzFLjKgucXsOkIf5Mzl8ZZhEtC6oye9whFInNPKszNB9AvX7JEZMtpXxWctih6addP+Q==", - "peer": true + "integrity": "sha512-v4CH6FLBCftYGFAswDhzFLjKgucXsOkIf5Mzl8ZZhEtC6oye9whFInNPKszNB9AvX7JEZMtpXxWctih6addP+Q==" }, "node_modules/@types/yargs": { "version": "15.0.17", @@ -2878,6 +2931,14 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.3.0", + "resolved": "http://localhost:4873/acorn-walk/-/acorn-walk-8.3.0.tgz", + "integrity": "sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2916,6 +2977,11 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "http://localhost:4873/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -3158,6 +3224,11 @@ "node": ">=10" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "http://localhost:4873/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, "node_modules/cross-fetch": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", @@ -3250,6 +3321,14 @@ "resolved": "https://registry.npmjs.org/detect-node-es/-/detect-node-es-1.1.0.tgz", "integrity": "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==" }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "http://localhost:4873/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", @@ -3915,8 +3994,7 @@ "node_modules/idb": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/idb/-/idb-5.0.8.tgz", - "integrity": "sha512-K9xInRkVbT3ZsYimD2KVj6B4E93IBvOjEQTryu99WuuN7G+7x3SzA79+yubbX0QRN9V64Gi+L+ulG5QYTVydOg==", - "peer": true + "integrity": "sha512-K9xInRkVbT3ZsYimD2KVj6B4E93IBvOjEQTryu99WuuN7G+7x3SzA79+yubbX0QRN9V64Gi+L+ulG5QYTVydOg==" }, "node_modules/ieee754": { "version": "1.2.1", @@ -4311,6 +4389,11 @@ "node": ">=10" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "http://localhost:4873/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, "node_modules/md5": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz", @@ -5067,7 +5150,6 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/soukai/-/soukai-0.5.1.tgz", "integrity": "sha512-NugJQKA0srEknErcyoTvTvwN14erkRFh6ewNjhPzGSXguVIrTTeVPRxER2F4JGDJM7Y7GCsr3jYVbUMbnCVe7g==", - "peer": true, "dependencies": { "@babel/runtime": "^7.12.18", "@noeldemartin/utils": "^0.4.0", @@ -5096,6 +5178,30 @@ "soukai": "~0.5.1" } }, + "node_modules/soukai-solid-bookmarks": { + "version": "0.0.0", + "resolved": "http://localhost:4873/soukai-solid-bookmarks/-/soukai-solid-bookmarks-0.0.0.tgz", + "integrity": "sha512-QvpVAw5IHgv1KoSdmzCe5VTE83071La3udXTMmakUjr9JBWs83pOd3VJneip3yqffjWBAjtZbl1cbxlvKVuh1Q==", + "dependencies": { + "soukai-solid": "^0.5.2", + "soukai-solid-utils": "^0.0.1", + "ts-node": "^10.9.1", + "uuid": "^9.0.1" + } + }, + "node_modules/soukai-solid-utils": { + "version": "0.0.1", + "resolved": "http://localhost:4873/soukai-solid-utils/-/soukai-solid-utils-0.0.1.tgz", + "integrity": "sha512-GyDdprqPog4/FhOqV74yIQFTMZcPB2wGuI1FO9GM+W7E0+tCeMRwwOKpoHEMie7hA/IIxVEnbPUNjjI2KzdoLQ==", + "dependencies": { + "@noeldemartin/solid-utils": "^0.3.0", + "@noeldemartin/utils": "^0.4.0", + "rdf-js": "^4.0.2", + "soukai": "~0.5.1", + "soukai-solid": "^0.5.2", + "uuid": "^9.0.1" + } + }, "node_modules/source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", @@ -5244,6 +5350,59 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "http://localhost:4873/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/acorn": { + "version": "8.11.2", + "resolved": "http://localhost:4873/acorn/-/acorn-8.11.2.tgz", + "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/tslib": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", @@ -5277,7 +5436,6 @@ "version": "5.2.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -5364,6 +5522,11 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "http://localhost:4873/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" + }, "node_modules/vite": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.0.tgz", @@ -5467,6 +5630,14 @@ "node": ">= 6" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "http://localhost:4873/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/bookmarks/soukai/demo/package.json b/bookmarks/soukai/demo/package.json index ab7500a..b92e7c1 100644 --- a/bookmarks/soukai/demo/package.json +++ b/bookmarks/soukai/demo/package.json @@ -23,6 +23,7 @@ "react-dom": "^18.2.0", "recoil": "^0.7.7", "soukai-solid": "^0.5.2", + "soukai-solid-bookmarks": "^0.0.0", "uuid": "^9.0.1" }, "devDependencies": { diff --git a/bookmarks/soukai/demo/src/components/Bookmarks.tsx b/bookmarks/soukai/demo/src/components/Bookmarks.tsx index 696e798..53702a8 100644 --- a/bookmarks/soukai/demo/src/components/Bookmarks.tsx +++ b/bookmarks/soukai/demo/src/components/Bookmarks.tsx @@ -14,14 +14,14 @@ import { import { Bookmark, BookmarkFactory, -} from "../../../dist/index"; +} from "../soukai-solid-data-modules/modules/Bookmarks"; import { FC, useEffect, useState } from "react"; +import { FieldType } from "soukai"; import { SolidHasManyRelation, SolidModel } from "soukai-solid"; import { useUserSession } from "../atoms/userSession.atom"; -import { FieldType } from "soukai"; -// import Movie from "soukai-solid/src/testing/lib/stubs/Movie" + const Bookmarks: FC = () => { const { userSession } = useUserSession(); const [form, setForm] = useState({ label: "", link: "", topic: "" }); @@ -30,29 +30,18 @@ const Bookmarks: FC = () => { useEffect(() => { (async () => { if (!userSession) return; - // console.log("🚀 ~ file: Bookmarks.tsx:19 ~ userSession:") - const factory = await BookmarkFactory.getInstance( { webId: userSession?.info.webId ?? "", fetch: userSession?.fetch, isPrivate: true, - // baseURL: pod, - // containerUrl: pod + "bookmarks/", - // typeIndexUrl: "https://reza-soltani.solidcommunity.net/settings/privateTypeIndex.ttl", - // forClass: Bookmark.rdfsClasses[0] } - // "bookmarks/" ); const bookmarks = await factory.getAll(); console.log("🚀 ~ file: Bookmarks.tsx:46 ~ bookmarks:", bookmarks.map(x => x.getAttributes())) setBookmarks(bookmarks); - // const res = await Bookmark.findOrFail( - // "https://solid-dm.solidcommunity.net/bookmarks/index.ttl#9a34eeec-01cc-4191-ad13-58c16ccf11f8" - // ); - // console.log("🚀 ~ file: Bookmarks.tsx:37 ~ res:", res.getAttributes()); })(); }, []); diff --git a/bookmarks/soukai/demo/src/soukai-solid-data-modules/modules/Bookmarks.ts b/bookmarks/soukai/demo/src/soukai-solid-data-modules/modules/Bookmarks.ts index f0873bb..2b5c6a8 100644 --- a/bookmarks/soukai/demo/src/soukai-solid-data-modules/modules/Bookmarks.ts +++ b/bookmarks/soukai/demo/src/soukai-solid-data-modules/modules/Bookmarks.ts @@ -14,34 +14,18 @@ import { } from "soukai-solid"; import { ISoukaiDocumentBase } from "../shared/contracts"; import { v4 } from "uuid"; +import { GetInstanceArgs } from "soukai-solid-utils"; + + + export type ICreateBookmark = { topic: string; label: string; link: string; }; -export interface GetInstanceArgs { - webId: string; - fetch?: Fetch; - isPrivate?: boolean; -} - export type IBookmark = ISoukaiDocumentBase & ICreateBookmark; -export const TopicSchema = defineSolidModelSchema({ - rdfContexts: { - bk: "http://www.w3.org/2002/01/bookmark#", - }, - rdfsClasses: ["bk:hasTopic"], - timestamps: false, -}); - -export class Topic extends TopicSchema { - // topicRelationship() { - // return this.belongsToMany(Bookmark, "topic"); - // } -} - export const BookmarkSchema = defineSolidModelSchema({ rdfContexts: { bk: "http://www.w3.org/2002/01/bookmark#", @@ -49,11 +33,11 @@ export const BookmarkSchema = defineSolidModelSchema({ rdfsClasses: ["bk:Bookmark"], - timestamps: false, + timestamps: [TimestampField.CreatedAt, TimestampField.UpdatedAt], fields: { topic: { - type: FieldType.Any, + type: FieldType.String, rdfProperty: "bk:hasTopic", }, label: { @@ -65,22 +49,24 @@ export const BookmarkSchema = defineSolidModelSchema({ rdfProperty: "bk:recalls", }, }, + }); export class Bookmark extends BookmarkSchema { - topicRelationship() { - return this.hasOne(Topic, "topic"); - } - // public relatedTopics!: SolidHasManyRelation; + // protected initialize(attributes: Attributes, exists: boolean): void { + // } + // newInstance({ url: "url" }, true) + // newInstance(this: T, attributes?: Attributes | undefined, exists?: boolean | undefined): T { + // } } -// Bookmark + export class BookmarkFactory { private static instance: BookmarkFactory; private constructor( private containerUrls: string[] = [], private instancesUrls: string[] = [] - ) {} + ) { } public static async getInstance( args?: GetInstanceArgs, @@ -90,9 +76,7 @@ export class BookmarkFactory { try { const baseURL = args?.webId.split("profile")[0]; // https://example.solidcommunity.net/ - defaultContainerUrl = `${baseURL}${ - defaultContainerUrl ?? "bookmarks/" - }`; + defaultContainerUrl = `${baseURL}${defaultContainerUrl ?? "bookmarks/"}`; let _containerUrls: string[] = []; let _instancesUrls: string[] = []; @@ -143,7 +127,7 @@ export class BookmarkFactory { // Create TypeIndex const typeIndexUrl = await createTypeIndex( args?.webId ?? "", - "private", + args?.isPrivate ? "private" : "public", args?.fetch ); _containerUrls.push(defaultContainerUrl); @@ -178,10 +162,6 @@ export class BookmarkFactory { const allPromise = Promise.all([...containerPromises, ...instancePromises]); try { - console.log( - "🚀 ~ file: Bookmarks.ts:197 ~ BookmarkFactory ~ getAll ~ await allPromise:", - await allPromise - ); const values = (await allPromise).flat(); return values; } catch (error) { @@ -212,25 +192,13 @@ export class BookmarkFactory { async create(payload: ICreateBookmark) { const id = v4(); - const { topic, ...rest } = payload; + const bookmark = new Bookmark({ - ...rest, - // id: id, + ...payload, + id: id, url: `${this.containerUrls[0]}${id}`, }); - // bookmark.relatedTopics.create({ topic: "..." }); - bookmark.topicRelationship().create( - Topic.at("https://solid-dm.solidcommunity.net/bookmarks/").create({ - // url: "https://solid-dm.solidcommunity.net/topics/", - title: "soukai-solid", - }) - ); - // .create(new Topic({ - // url: "https://solid-dm.solidcommunity.net/topics/", - // topic: "soukai-solid", - // })); - // bookmark.topic.create({topic:"https://soukai.js.org/guide/defining-models.html#a-word-about-constructors"}) // bookmark.url = `${this.containerUrls[0]}${id}#it` return await bookmark.save();