@ldo/svelte 1.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/dist/example/src/ldoSvelteMethods.d.ts +2 -0
- package/dist/example/src/ldoSvelteMethods.d.ts.map +1 -0
- package/dist/example/src/main.d.ts +5 -0
- package/dist/example/src/main.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +88 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/methods/useLdo.d.ts +60 -0
- package/dist/src/methods/useLdo.d.ts.map +1 -0
- package/dist/src/methods/useLinkQuery.d.ts +11 -0
- package/dist/src/methods/useLinkQuery.d.ts.map +1 -0
- package/dist/src/methods/useMatchObject.d.ts +11 -0
- package/dist/src/methods/useMatchObject.d.ts.map +1 -0
- package/dist/src/methods/useMatchSubject.d.ts +11 -0
- package/dist/src/methods/useMatchSubject.d.ts.map +1 -0
- package/dist/src/methods/useResource.d.ts +24 -0
- package/dist/src/methods/useResource.d.ts.map +1 -0
- package/dist/src/methods/useSubject.d.ts +17 -0
- package/dist/src/methods/useSubject.d.ts.map +1 -0
- package/dist/src/methods/useSubscribeToResource.d.ts +9 -0
- package/dist/src/methods/useSubscribeToResource.d.ts.map +1 -0
- package/dist/src/util/useTrackingProxy.d.ts +10 -0
- package/dist/src/util/useTrackingProxy.d.ts.map +1 -0
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/dist/vite.config.example.d.ts +3 -0
- package/dist/vite.config.example.d.ts.map +1 -0
- package/package.json +74 -0
- package/src/createLdoSvelteMethods.tsx +77 -0
- package/src/index.ts +9 -0
- package/src/methods/useLdo.ts +147 -0
- package/src/methods/useLinkQuery.ts +34 -0
- package/src/methods/useMatchObject.ts +25 -0
- package/src/methods/useMatchSubject.ts +25 -0
- package/src/methods/useResource.ts +94 -0
- package/src/methods/useSubject.ts +48 -0
- package/src/methods/useSubscribeToResource.ts +17 -0
- package/src/util/useTrackingProxy.ts +44 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jackson Morgan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const dataset: import('@ldo/connected').ConnectedLdoDataset<import('@ldo/connected-solid').SolidConnectedPlugin[]>, useLdo: void, useMatchObject: <Type extends import('@ldo/ldo').LdoBase>(shapeType: import('@ldo/ldo').ShapeType<Type>, subject?: import('@ldo/rdf-utils').QuadMatch[0] | string, predicate?: import('@ldo/rdf-utils').QuadMatch[1] | string, graph?: import('@ldo/rdf-utils').QuadMatch[3] | string) => import('@ldo/jsonld-dataset-proxy').LdSet<Type>, useMatchSubject: <Type extends import('@ldo/ldo').LdoBase>(shapeType: import('@ldo/ldo').ShapeType<Type>, predicate?: import('@ldo/rdf-utils').QuadMatch[1] | string, object?: import('@ldo/rdf-utils').QuadMatch[2] | string, graph?: import('@ldo/rdf-utils').QuadMatch[3] | string) => import('@ldo/jsonld-dataset-proxy').LdSet<Type>, useResource: import('../../src/index.ts').useResourceType<import('@ldo/connected-solid').SolidConnectedPlugin[]>, useSubject: import('../../src/index.ts').useSubjectType, useSubscribeToResource: (...uris: string[]) => void, useLinkQuery: <Type extends import('@ldo/ldo').LdoBase, QueryInput extends Partial<{ [key in Exclude<keyof Type, "@context">]: import('@ldo/connected').LQInputFlattenSet<Type[key]>; }>>(shapeType: import('@ldo/ldo').ShapeType<Type>, startingResource: string, startingSubject: import('@ldo/rdf-utils').SubjectNode | string, linkQuery: QueryInput) => import('@ldo/connected').ExpandDeep<import('@ldo/connected').LQReturn<Type, QueryInput>> | undefined;
|
|
2
|
+
//# sourceMappingURL=ldoSvelteMethods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ldoSvelteMethods.d.ts","sourceRoot":"","sources":["../../../example/src/ldoSvelteMethods.ts"],"names":[],"mappings":"AAGA,eAAO,MACL,OAAO,uGACP,MAAM,QACN,cAAc,6TACd,eAAe,4TACf,WAAW,gGACX,UAAU,wCACV,sBAAsB,+BACtB,YAAY,qbACoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../example/src/main.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAI/B,QAAA,MAAM,GAAG,KAEP,CAAC;AAEH,eAAe,GAAG,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@ldo/connected"),i=require("svelte/store");function d(r){throw new Error("Not Implemented")}function b(r){return function(u,e,t,s){throw new Error("Not Implemented")}}function f(r){return function(u,e,t,s){throw new Error("Not Implemented")}}function l(r){return function(u,e){let t;return u?(t=r.getResource(u),e!=null&&e.suppressInitialRead||(e!=null&&e.reloadOnMount?t.read():t.readIfUnfetched())):t=void 0,{subscribe:i.writable(t,n=>{const o=()=>{n(t)};if(t)return t.on("update",o),()=>{t.off("update",o)}}).subscribe}}}function m(r,c,u){const e={},t=()=>{u.removeListenerFromAllEvents(t);const n=a.createTrackingProxyBuilder(u,r,t),o=c(n);e.ldo=o,e.set&&e.ldo&&e.set(e.ldo)};return t(),{subscribe:i.writable(e.ldo,n=>(e.set=n,()=>{u.removeListenerFromAllEvents(t)})).subscribe}}function h(r){return function(u,e){return m(u,s=>{if(e)return s.fromSubject(e)},r)}}function S(r){return function(...u){throw new Error("Not Implemented")}}function j(r){return function(u,e,t,s){throw new Error("Not Implemented")}}function U(r){const c=a.createConnectedLdoDataset(r);return c.setMaxListeners(1e3),{dataset:c,useLdo:d(),useMatchObject:b(),useMatchSubject:f(),useResource:l(c),useSubject:h(c),useSubscribeToResource:S(),useLinkQuery:j()}}exports.createLdoSvelteMethods=U;exports.createUseLdo=d;exports.createUseLinkQuery=j;exports.createUseMatchObject=b;exports.createUseMatchSubject=f;exports.createUseResource=l;exports.createUseSubject=h;exports.createUseSubscribeToResource=S;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/methods/useLdo.ts","../src/methods/useMatchObject.ts","../src/methods/useMatchSubject.ts","../src/methods/useResource.ts","../src/util/useTrackingProxy.ts","../src/methods/useSubject.ts","../src/methods/useSubscribeToResource.ts","../src/methods/useLinkQuery.ts","../src/createLdoSvelteMethods.tsx"],"sourcesContent":["import {\n // changeData,\n type ConnectedLdoDataset,\n type ConnectedLdoTransactionDataset,\n type ConnectedPlugin,\n} from \"@ldo/connected\";\nimport { type LdoBase, type ShapeType } from \"@ldo/ldo\";\nimport type { SubjectNode } from \"@ldo/rdf-utils\";\n\n/**\n * The methods returned by useLdo\n */\nexport interface UseLdoMethods<Plugins extends ConnectedPlugin[]> {\n /**\n * A ConnectedLdoDataset\n */\n dataset: ConnectedLdoDataset<Plugins>;\n /**\n * Retireves a representation of a Resource at the given URI. This resource\n * represents the current state of the resource: whether it is currently\n * fetched or in the process of fetching as well as some information about it.\n *\n * @param uri - the URI of the resource\n * @param pluginName - optionally, force this function to choose a specific\n * plugin to use rather than perform content negotiation.\n *\n * @returns a Resource\n */\n getResource: ConnectedLdoDataset<Plugins>[\"getResource\"];\n /**\n * Sets conetext for a specific plugin\n *\n * @param pluginName - the name of the plugin\n * @param context - the context for this specific plugin\n */\n setContext: ConnectedLdoDataset<Plugins>[\"setContext\"];\n /**\n * Gets a linked data object based on the subject\n */\n getSubject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject: string | SubjectNode,\n ): Type;\n /**\n * Shorthand for connectedLdoDataset\n * .usingType(shapeType)\n * .write(...resources.map((r) => r.uri))\n * .fromSubject(subject);\n * @param shapeType - The shapetype to represent the data\n * @param subject - A subject URI\n * @param resources - The resources changes to should written to\n */\n createData<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject: string | SubjectNode,\n resource: Plugins[number][\"types\"][\"resource\"],\n ...additionalResources: Plugins[number][\"types\"][\"resource\"][]\n ): Type;\n /**\n * Returns a writable LinkedDataObject given a linked data object\n */\n changeData<Type extends LdoBase>(\n input: Type,\n resource: Plugins[number][\"types\"][\"resource\"],\n ...additionalResources: Plugins[number][\"types\"][\"resource\"][]\n ): Type;\n /**\n * Commits the data of a writable Linke Data Object back to the remote.\n */\n commitData(\n input: LdoBase,\n ): ReturnType<ConnectedLdoTransactionDataset<Plugins>[\"commitToRemote\"]>;\n}\n\n/**\n * @internal\n * Creates the useLdoHook\n */\nexport function createUseLdo<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n throw new Error(\"Not Implemented\");\n // const toReturn = {\n // dataset,\n // /**\n // * Gets a resource\n // */\n // getResource: dataset.getResource.bind(dataset),\n // /**\n // * Set the context\n // */\n // setContext: dataset.setContext.bind(dataset),\n // /**\n // * Returns a Linked Data Object for a subject\n // * @param shapeType The shape type for the data\n // * @param subject Subject Node\n // * @returns A Linked Data Object\n // */\n // getSubject<Type extends LdoBase>(\n // shapeType: ShapeType<Type>,\n // subject: string | SubjectNode,\n // ): Type {\n // return dataset.usingType(shapeType).fromSubject(subject);\n // },\n // /**\n // * Begins tracking changes to eventually commit for a new subject\n // * @param shapeType The shape type that defines the created data\n // * @param subject The RDF subject for a Linked Data Object\n // * @param resources Any number of resources to which this data should be written\n // * @returns A Linked Data Object to modify and commit\n // */\n // createData<Type extends LdoBase>(\n // shapeType: ShapeType<Type>,\n // subject: string | SubjectNode,\n // resource: Plugins[number][\"types\"][\"resource\"],\n // ...additionalResources: Plugins[number][\"types\"][\"resource\"][]\n // ): Type {\n // return dataset.createData(\n // shapeType,\n // subject,\n // resource,\n // ...additionalResources,\n // );\n // },\n // /**\n // * Begins tracking changes to eventually commit\n // * @param input A linked data object to track changes on\n // * @param resources\n // */\n // changeData: changeData,\n // /**\n // * Commits the transaction to the global dataset, syncing all subscribing\n // * components and Solid Pods\n // */\n // commitData(\n // input: LdoBase,\n // ): ReturnType<ConnectedLdoTransactionDataset<Plugins>[\"commitToRemote\"]> {\n // const inputDataset = getDataset(\n // input,\n // ) as ConnectedLdoTransactionDataset<Plugins>;\n // return inputDataset.commitToRemote();\n // },\n // };\n // return function useLdo(): UseLdoMethods<Plugins> {\n // throw new Error(\"Not Implemented\");\n // };\n}\n","import type { LdoBase, LdSet, ShapeType } from \"@ldo/ldo\";\nimport type { QuadMatch } from \"@ldo/rdf-utils\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\n\n/**\n * @internal\n *\n * Creates a useMatchObject function\n */\nexport function createUseMatchObject<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Returns an array of matching items and triggers a rerender when that data\n * is updated.\n */\n return function useMatchObject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: QuadMatch[0] | string,\n predicate?: QuadMatch[1] | string,\n graph?: QuadMatch[3] | string,\n ): LdSet<Type> {\n throw new Error(\"Not Implemented\");\n };\n}\n","import type { LdoBase, LdSet, ShapeType } from \"@ldo/ldo\";\nimport type { QuadMatch } from \"@ldo/rdf-utils\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\n\n/**\n * @internal\n *\n * Creates a useMatchSubject function.\n */\nexport function createUseMatchSubject<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Returns an array of matching linked data objects. Triggers a rerender if\n * the data is updated.\n */\n return function useMatchSubject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n predicate?: QuadMatch[1] | string,\n object?: QuadMatch[2] | string,\n graph?: QuadMatch[3] | string,\n ): LdSet<Type> {\n throw new Error(\"Not Implemented\");\n };\n}\n","import type {\n ConnectedLdoDataset,\n ConnectedPlugin,\n GetResourceReturnType,\n} from \"@ldo/connected\";\nimport { writable, type Readable } from \"svelte/store\";\n\nexport interface UseResourceOptions<Name> {\n pluginName?: Name;\n suppressInitialRead?: boolean;\n reloadOnMount?: boolean;\n subscribe?: boolean;\n}\n\nexport type useResourceType<Plugins extends ConnectedPlugin[]> = {\n <\n Name extends Plugins[number][\"name\"],\n Plugin extends Extract<Plugins[number], { name: Name }>,\n UriType extends string,\n >(\n uri: UriType,\n options?: UseResourceOptions<Name>,\n ): Readable<GetResourceReturnType<Plugin, UriType>>;\n <\n Name extends Plugins[number][\"name\"],\n Plugin extends Extract<Plugins[number], { name: Name }>,\n UriType extends string,\n >(\n uri?: UriType,\n options?: UseResourceOptions<Name>,\n ): Readable<GetResourceReturnType<Plugin, UriType> | undefined>;\n};\n\n/**\n * @internal\n *\n * Creates a useResource function.\n */\nexport function createUseResource<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n): useResourceType<Plugins> {\n /**\n * Returns a resource and triggers a rerender if that resource is updated.\n */\n return function useResource<\n Name extends Plugins[number][\"name\"],\n Plugin extends Extract<Plugins[number], { name: Name }>,\n UriType extends string,\n >(\n uri?: UriType,\n options?: UseResourceOptions<Name>,\n ): Readable<GetResourceReturnType<Plugin, UriType> | undefined> {\n let resource: GetResourceReturnType<Plugin, UriType> | undefined;\n // Get the resource based on incoming data\n if (uri) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resource = dataset.getResource(uri) as any;\n // Run read operations if necissary\n if (!options?.suppressInitialRead) {\n if (options?.reloadOnMount) {\n resource!.read();\n } else {\n resource!.readIfUnfetched();\n }\n }\n } else {\n resource = undefined;\n }\n\n // The Svelte store\n const store = writable<GetResourceReturnType<Plugin, UriType> | undefined>(\n resource,\n (set) => {\n const onResourceUpdate = () => {\n set(resource);\n };\n\n if (resource) {\n resource.on(\"update\", onResourceUpdate);\n\n // TODO: handle subscriptions\n\n return () => {\n resource.off(\"update\", onResourceUpdate);\n };\n }\n },\n );\n\n return {\n subscribe: store.subscribe,\n };\n };\n}\n","import type { LdoBuilder } from \"@ldo/ldo\";\nimport type { LdoBase, LdoDataset, ShapeType } from \"@ldo/ldo\";\nimport { createTrackingProxyBuilder } from \"@ldo/connected\";\nimport { writable, type Readable } from \"svelte/store\";\nimport type { nodeEventListener } from \"@ldo/subscribable-dataset\";\n\n/**\n * @internal\n *\n * A hook for tracking proxies\n */\nexport function useTrackingProxy<Type extends LdoBase, ReturnType>(\n shapeType: ShapeType<Type>,\n createLdo: (builder: LdoBuilder<Type>) => ReturnType,\n dataset: LdoDataset,\n): Readable<ReturnType> {\n const forceUpdateInfo: {\n set?: (item: ReturnType) => void;\n ldo?: ReturnType;\n } = {};\n\n const forceUpdate: nodeEventListener = () => {\n dataset.removeListenerFromAllEvents(forceUpdate);\n const builder = createTrackingProxyBuilder(dataset, shapeType, forceUpdate);\n const linkedDataObject = createLdo(builder);\n forceUpdateInfo.ldo = linkedDataObject;\n if (forceUpdateInfo.set && forceUpdateInfo.ldo)\n forceUpdateInfo.set(forceUpdateInfo.ldo);\n };\n forceUpdate({}, \"\", [undefined, undefined, undefined, undefined]);\n\n // The Svelte store\n const store = writable<ReturnType>(forceUpdateInfo.ldo, (set) => {\n forceUpdateInfo.set = set;\n\n return () => {\n dataset.removeListenerFromAllEvents(forceUpdate);\n };\n });\n\n return {\n subscribe: store.subscribe,\n };\n}\n","import type { SubjectNode } from \"@ldo/rdf-utils\";\nimport type { ShapeType } from \"@ldo/ldo\";\nimport type { LdoBuilder } from \"@ldo/ldo\";\nimport type { LdoBase } from \"@ldo/ldo\";\n\nimport { useTrackingProxy } from \"../util/useTrackingProxy.js\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\nimport type { Readable } from \"svelte/store\";\n\nexport type useSubjectType = {\n <Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject: string | SubjectNode,\n ): Readable<Type>;\n <Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: string | SubjectNode,\n ): Readable<Type | undefined>;\n <Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: string | SubjectNode,\n ): Readable<Type | undefined>;\n};\n\n/**\n * @internal\n *\n * Creates a useSubject function.\n */\nexport function createUseSubject<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n): useSubjectType {\n /**\n * Returns a Linked Data Object based on the provided subject. Triggers a\n * rerender if the data is udpated.\n */\n return function useSubject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: string | SubjectNode,\n ): Readable<Type | undefined> {\n const fromSubject = (builder: LdoBuilder<Type>) => {\n if (!subject) return;\n return builder.fromSubject(subject);\n };\n\n return useTrackingProxy(shapeType, fromSubject, dataset);\n };\n}\n","import type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\n\n/**\n * @internal\n *\n * Creates a useSubscribeToResource function.\n */\nexport function createUseSubscribeToResource<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Starts a subscription to a resource.\n */\n return function useSubscribeToResource(...uris: string[]): void {\n throw new Error(\"Not Implemented\");\n };\n}\n","import type {\n ConnectedLdoDataset,\n ConnectedPlugin,\n ExpandDeep,\n LQInput,\n LQReturn,\n} from \"@ldo/connected\";\nimport type { LdoBase, ShapeType } from \"@ldo/ldo\";\nimport type { SubjectNode } from \"@ldo/rdf-utils\";\n\n/**\n * @internal\n *\n * Creates a useMatchSubject function.\n */\nexport function createUseLinkQuery<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Returns an array of matching linked data objects. Triggers a rerender if\n * the data is updated.\n */\n return function useQueryLink<\n Type extends LdoBase,\n QueryInput extends LQInput<Type>,\n >(\n shapeType: ShapeType<Type>,\n startingResource: string,\n startingSubject: SubjectNode | string,\n linkQuery: QueryInput,\n ): ExpandDeep<LQReturn<Type, QueryInput>> | undefined {\n throw new Error(\"Not Implemented\");\n };\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { createUseLdo } from \"./methods/useLdo.js\";\nimport {\n createConnectedLdoDataset,\n type ConnectedPlugin,\n} from \"@ldo/connected\";\nimport { createUseMatchObject } from \"./methods/useMatchObject.js\";\nimport { createUseMatchSubject } from \"./methods/useMatchSubject.js\";\nimport { createUseResource } from \"./methods/useResource.js\";\nimport { createUseSubject } from \"./methods/useSubject.js\";\nimport { createUseSubscribeToResource } from \"./methods/useSubscribeToResource.js\";\nimport { createUseLinkQuery } from \"./methods/useLinkQuery.js\";\n\n/**\n * A function that creates all common react functions given specific plugin.\n *\n * @example\n * `methods.ts`\n * ```tyepscript\n * import { solidConnectedPlugin } from \"@ldo/connected-solid\";\n * import { nextGraphConnectedPlugin } from \"@ldo/connected-nextgraph\";\n * import { createLdoReactMethods } from \"@ldo/react\";\n *\n * // Export the results to be used in the reset of the application\n * export const {\n * dataset,\n * useLdo,\n * useMatchObject,\n * useMatchSubject,\n * useResource,\n * useSubject,\n * useSubscribeToResource,\n * useLinkQuery,\n * } = createLdoReactMethods([\n * solidConnectedPlugin,\n * nextGraphConnectedPlugin\n * ]);\n * ```\n *\n * `App.tsx`\n * ```typescript\n * import react, { FunctionComponent } from \"react\";\n * import { PostShShapeType } from \"./.ldo/posts.shapeType.ts\";\n * import { useResource, useSubject } from \"./methods.ts\";\n *\n * const UseSubjectTest: FunctionComponent = () => {\n * const resource = useResource(SAMPLE_DATA_URI);\n * const post = useSubject(PostShShapeType, `${SAMPLE_DATA_URI}#Post1`);\n * if (resource.isLoading() || !post) return <p>loading</p>;\n *\n * return (\n * <ul>\n * {post.publisher.map((publisher) => {\n * return <li key={publisher[\"@id\"]}>{publisher[\"@id\"]}</li>;\n * })}\n * </ul>\n * );\n * };\n * ```\n */\nexport function createLdoSvelteMethods<\n Plugins extends ConnectedPlugin<any, any, any, any>[],\n>(plugins: Plugins) {\n const dataset = createConnectedLdoDataset(plugins);\n dataset.setMaxListeners(1000);\n\n return {\n dataset,\n useLdo: createUseLdo(dataset),\n useMatchObject: createUseMatchObject(dataset),\n useMatchSubject: createUseMatchSubject(dataset),\n useResource: createUseResource(dataset),\n useSubject: createUseSubject(dataset),\n useSubscribeToResource: createUseSubscribeToResource(dataset),\n useLinkQuery: createUseLinkQuery(dataset),\n };\n}\n"],"names":["createUseLdo","dataset","createUseMatchObject","shapeType","subject","predicate","graph","createUseMatchSubject","object","createUseResource","uri","options","resource","writable","set","onResourceUpdate","useTrackingProxy","createLdo","forceUpdateInfo","forceUpdate","builder","createTrackingProxyBuilder","linkedDataObject","createUseSubject","createUseSubscribeToResource","uris","createUseLinkQuery","startingResource","startingSubject","linkQuery","createLdoSvelteMethods","plugins","createConnectedLdoDataset"],"mappings":"4IA8EO,SAASA,EACdC,EACA,CACM,MAAA,IAAI,MAAM,iBAAiB,CAiEnC,CCzIO,SAASC,EACdD,EACA,CAKA,OAAO,SACLE,EACAC,EACAC,EACAC,EACa,CACP,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAErC,CCfO,SAASC,EACdN,EACA,CAKA,OAAO,SACLE,EACAE,EACAG,EACAF,EACa,CACP,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAErC,CCcO,SAASG,EACdR,EAC0B,CAInB,OAAA,SAKLS,EACAC,EAC8D,CAC1D,IAAAC,EAEJ,OAAIF,GAESE,EAAAX,EAAQ,YAAYS,CAAG,EAE7BC,GAAA,MAAAA,EAAS,sBACRA,GAAA,MAAAA,EAAS,cACXC,EAAU,KAAK,EAEfA,EAAU,gBAAgB,IAInBA,EAAA,OAuBN,CACL,UApBYC,EAAA,SACZD,EACCE,GAAQ,CACP,MAAMC,EAAmB,IAAM,CAC7BD,EAAIF,CAAQ,CAAA,EAGd,GAAIA,EACO,OAAAA,EAAA,GAAG,SAAUG,CAAgB,EAI/B,IAAM,CACFH,EAAA,IAAI,SAAUG,CAAgB,CAAA,CAG7C,CAAA,EAIiB,SAAA,CACnB,CAEJ,CClFgB,SAAAC,EACdb,EACAc,EACAhB,EACsB,CACtB,MAAMiB,EAGF,CAAA,EAEEC,EAAiC,IAAM,CAC3ClB,EAAQ,4BAA4BkB,CAAW,EAC/C,MAAMC,EAAUC,EAAA,2BAA2BpB,EAASE,EAAWgB,CAAW,EACpEG,EAAmBL,EAAUG,CAAO,EAC1CF,EAAgB,IAAMI,EAClBJ,EAAgB,KAAOA,EAAgB,KACzBA,EAAA,IAAIA,EAAgB,GAAG,CAAA,EAE/B,OAAAC,EAAoD,EAWzD,CACL,UATYN,EAAA,SAAqBK,EAAgB,IAAMJ,IACvDI,EAAgB,IAAMJ,EAEf,IAAM,CACXb,EAAQ,4BAA4BkB,CAAW,CAAA,EAElD,EAGkB,SAAA,CAErB,CCdO,SAASI,EACdtB,EACgB,CAKT,OAAA,SACLE,EACAC,EAC4B,CAMrB,OAAAY,EAAiBb,EALHiB,GAA8B,CACjD,GAAKhB,EACE,OAAAgB,EAAQ,YAAYhB,CAAO,CAAA,EAGYH,CAAO,CAAA,CAE3D,CCxCO,SAASuB,EACdvB,EACA,CAIO,OAAA,YAAmCwB,EAAsB,CACxD,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAErC,CCDO,SAASC,EACdzB,EACA,CAKA,OAAO,SAILE,EACAwB,EACAC,EACAC,EACoD,CAC9C,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAErC,CC2BO,SAASC,EAEdC,EAAkB,CACZ,MAAA9B,EAAU+B,4BAA0BD,CAAO,EACjD,OAAA9B,EAAQ,gBAAgB,GAAI,EAErB,CACL,QAAAA,EACA,OAAQD,EAAoB,EAC5B,eAAgBE,EAA4B,EAC5C,gBAAiBK,EAA6B,EAC9C,YAAaE,EAAkBR,CAAO,EACtC,WAAYsB,EAAiBtB,CAAO,EACpC,uBAAwBuB,EAAoC,EAC5D,aAAcE,EAA0B,CAAA,CAE5C"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/index'
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createTrackingProxyBuilder as i, createConnectedLdoDataset as d } from "@ldo/connected";
|
|
2
|
+
import { writable as a } from "svelte/store";
|
|
3
|
+
function f(r) {
|
|
4
|
+
throw new Error("Not Implemented");
|
|
5
|
+
}
|
|
6
|
+
function b(r) {
|
|
7
|
+
return function(u, e, t, n) {
|
|
8
|
+
throw new Error("Not Implemented");
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function l(r) {
|
|
12
|
+
return function(u, e, t, n) {
|
|
13
|
+
throw new Error("Not Implemented");
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function m(r) {
|
|
17
|
+
return function(u, e) {
|
|
18
|
+
let t;
|
|
19
|
+
return u ? (t = r.getResource(u), e != null && e.suppressInitialRead || (e != null && e.reloadOnMount ? t.read() : t.readIfUnfetched())) : t = void 0, {
|
|
20
|
+
subscribe: a(
|
|
21
|
+
t,
|
|
22
|
+
(s) => {
|
|
23
|
+
const o = () => {
|
|
24
|
+
s(t);
|
|
25
|
+
};
|
|
26
|
+
if (t)
|
|
27
|
+
return t.on("update", o), () => {
|
|
28
|
+
t.off("update", o);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
).subscribe
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function h(r, c, u) {
|
|
36
|
+
const e = {}, t = () => {
|
|
37
|
+
u.removeListenerFromAllEvents(t);
|
|
38
|
+
const s = i(u, r, t), o = c(s);
|
|
39
|
+
e.ldo = o, e.set && e.ldo && e.set(e.ldo);
|
|
40
|
+
};
|
|
41
|
+
return t(), {
|
|
42
|
+
subscribe: a(e.ldo, (s) => (e.set = s, () => {
|
|
43
|
+
u.removeListenerFromAllEvents(t);
|
|
44
|
+
})).subscribe
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function p(r) {
|
|
48
|
+
return function(u, e) {
|
|
49
|
+
return h(u, (n) => {
|
|
50
|
+
if (e)
|
|
51
|
+
return n.fromSubject(e);
|
|
52
|
+
}, r);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function j(r) {
|
|
56
|
+
return function(...u) {
|
|
57
|
+
throw new Error("Not Implemented");
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function S(r) {
|
|
61
|
+
return function(u, e, t, n) {
|
|
62
|
+
throw new Error("Not Implemented");
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function L(r) {
|
|
66
|
+
const c = d(r);
|
|
67
|
+
return c.setMaxListeners(1e3), {
|
|
68
|
+
dataset: c,
|
|
69
|
+
useLdo: f(),
|
|
70
|
+
useMatchObject: b(),
|
|
71
|
+
useMatchSubject: l(),
|
|
72
|
+
useResource: m(c),
|
|
73
|
+
useSubject: p(c),
|
|
74
|
+
useSubscribeToResource: j(),
|
|
75
|
+
useLinkQuery: S()
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
L as createLdoSvelteMethods,
|
|
80
|
+
f as createUseLdo,
|
|
81
|
+
S as createUseLinkQuery,
|
|
82
|
+
b as createUseMatchObject,
|
|
83
|
+
l as createUseMatchSubject,
|
|
84
|
+
m as createUseResource,
|
|
85
|
+
p as createUseSubject,
|
|
86
|
+
j as createUseSubscribeToResource
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/methods/useLdo.ts","../src/methods/useMatchObject.ts","../src/methods/useMatchSubject.ts","../src/methods/useResource.ts","../src/util/useTrackingProxy.ts","../src/methods/useSubject.ts","../src/methods/useSubscribeToResource.ts","../src/methods/useLinkQuery.ts","../src/createLdoSvelteMethods.tsx"],"sourcesContent":["import {\n // changeData,\n type ConnectedLdoDataset,\n type ConnectedLdoTransactionDataset,\n type ConnectedPlugin,\n} from \"@ldo/connected\";\nimport { type LdoBase, type ShapeType } from \"@ldo/ldo\";\nimport type { SubjectNode } from \"@ldo/rdf-utils\";\n\n/**\n * The methods returned by useLdo\n */\nexport interface UseLdoMethods<Plugins extends ConnectedPlugin[]> {\n /**\n * A ConnectedLdoDataset\n */\n dataset: ConnectedLdoDataset<Plugins>;\n /**\n * Retireves a representation of a Resource at the given URI. This resource\n * represents the current state of the resource: whether it is currently\n * fetched or in the process of fetching as well as some information about it.\n *\n * @param uri - the URI of the resource\n * @param pluginName - optionally, force this function to choose a specific\n * plugin to use rather than perform content negotiation.\n *\n * @returns a Resource\n */\n getResource: ConnectedLdoDataset<Plugins>[\"getResource\"];\n /**\n * Sets conetext for a specific plugin\n *\n * @param pluginName - the name of the plugin\n * @param context - the context for this specific plugin\n */\n setContext: ConnectedLdoDataset<Plugins>[\"setContext\"];\n /**\n * Gets a linked data object based on the subject\n */\n getSubject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject: string | SubjectNode,\n ): Type;\n /**\n * Shorthand for connectedLdoDataset\n * .usingType(shapeType)\n * .write(...resources.map((r) => r.uri))\n * .fromSubject(subject);\n * @param shapeType - The shapetype to represent the data\n * @param subject - A subject URI\n * @param resources - The resources changes to should written to\n */\n createData<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject: string | SubjectNode,\n resource: Plugins[number][\"types\"][\"resource\"],\n ...additionalResources: Plugins[number][\"types\"][\"resource\"][]\n ): Type;\n /**\n * Returns a writable LinkedDataObject given a linked data object\n */\n changeData<Type extends LdoBase>(\n input: Type,\n resource: Plugins[number][\"types\"][\"resource\"],\n ...additionalResources: Plugins[number][\"types\"][\"resource\"][]\n ): Type;\n /**\n * Commits the data of a writable Linke Data Object back to the remote.\n */\n commitData(\n input: LdoBase,\n ): ReturnType<ConnectedLdoTransactionDataset<Plugins>[\"commitToRemote\"]>;\n}\n\n/**\n * @internal\n * Creates the useLdoHook\n */\nexport function createUseLdo<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n throw new Error(\"Not Implemented\");\n // const toReturn = {\n // dataset,\n // /**\n // * Gets a resource\n // */\n // getResource: dataset.getResource.bind(dataset),\n // /**\n // * Set the context\n // */\n // setContext: dataset.setContext.bind(dataset),\n // /**\n // * Returns a Linked Data Object for a subject\n // * @param shapeType The shape type for the data\n // * @param subject Subject Node\n // * @returns A Linked Data Object\n // */\n // getSubject<Type extends LdoBase>(\n // shapeType: ShapeType<Type>,\n // subject: string | SubjectNode,\n // ): Type {\n // return dataset.usingType(shapeType).fromSubject(subject);\n // },\n // /**\n // * Begins tracking changes to eventually commit for a new subject\n // * @param shapeType The shape type that defines the created data\n // * @param subject The RDF subject for a Linked Data Object\n // * @param resources Any number of resources to which this data should be written\n // * @returns A Linked Data Object to modify and commit\n // */\n // createData<Type extends LdoBase>(\n // shapeType: ShapeType<Type>,\n // subject: string | SubjectNode,\n // resource: Plugins[number][\"types\"][\"resource\"],\n // ...additionalResources: Plugins[number][\"types\"][\"resource\"][]\n // ): Type {\n // return dataset.createData(\n // shapeType,\n // subject,\n // resource,\n // ...additionalResources,\n // );\n // },\n // /**\n // * Begins tracking changes to eventually commit\n // * @param input A linked data object to track changes on\n // * @param resources\n // */\n // changeData: changeData,\n // /**\n // * Commits the transaction to the global dataset, syncing all subscribing\n // * components and Solid Pods\n // */\n // commitData(\n // input: LdoBase,\n // ): ReturnType<ConnectedLdoTransactionDataset<Plugins>[\"commitToRemote\"]> {\n // const inputDataset = getDataset(\n // input,\n // ) as ConnectedLdoTransactionDataset<Plugins>;\n // return inputDataset.commitToRemote();\n // },\n // };\n // return function useLdo(): UseLdoMethods<Plugins> {\n // throw new Error(\"Not Implemented\");\n // };\n}\n","import type { LdoBase, LdSet, ShapeType } from \"@ldo/ldo\";\nimport type { QuadMatch } from \"@ldo/rdf-utils\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\n\n/**\n * @internal\n *\n * Creates a useMatchObject function\n */\nexport function createUseMatchObject<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Returns an array of matching items and triggers a rerender when that data\n * is updated.\n */\n return function useMatchObject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: QuadMatch[0] | string,\n predicate?: QuadMatch[1] | string,\n graph?: QuadMatch[3] | string,\n ): LdSet<Type> {\n throw new Error(\"Not Implemented\");\n };\n}\n","import type { LdoBase, LdSet, ShapeType } from \"@ldo/ldo\";\nimport type { QuadMatch } from \"@ldo/rdf-utils\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\n\n/**\n * @internal\n *\n * Creates a useMatchSubject function.\n */\nexport function createUseMatchSubject<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Returns an array of matching linked data objects. Triggers a rerender if\n * the data is updated.\n */\n return function useMatchSubject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n predicate?: QuadMatch[1] | string,\n object?: QuadMatch[2] | string,\n graph?: QuadMatch[3] | string,\n ): LdSet<Type> {\n throw new Error(\"Not Implemented\");\n };\n}\n","import type {\n ConnectedLdoDataset,\n ConnectedPlugin,\n GetResourceReturnType,\n} from \"@ldo/connected\";\nimport { writable, type Readable } from \"svelte/store\";\n\nexport interface UseResourceOptions<Name> {\n pluginName?: Name;\n suppressInitialRead?: boolean;\n reloadOnMount?: boolean;\n subscribe?: boolean;\n}\n\nexport type useResourceType<Plugins extends ConnectedPlugin[]> = {\n <\n Name extends Plugins[number][\"name\"],\n Plugin extends Extract<Plugins[number], { name: Name }>,\n UriType extends string,\n >(\n uri: UriType,\n options?: UseResourceOptions<Name>,\n ): Readable<GetResourceReturnType<Plugin, UriType>>;\n <\n Name extends Plugins[number][\"name\"],\n Plugin extends Extract<Plugins[number], { name: Name }>,\n UriType extends string,\n >(\n uri?: UriType,\n options?: UseResourceOptions<Name>,\n ): Readable<GetResourceReturnType<Plugin, UriType> | undefined>;\n};\n\n/**\n * @internal\n *\n * Creates a useResource function.\n */\nexport function createUseResource<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n): useResourceType<Plugins> {\n /**\n * Returns a resource and triggers a rerender if that resource is updated.\n */\n return function useResource<\n Name extends Plugins[number][\"name\"],\n Plugin extends Extract<Plugins[number], { name: Name }>,\n UriType extends string,\n >(\n uri?: UriType,\n options?: UseResourceOptions<Name>,\n ): Readable<GetResourceReturnType<Plugin, UriType> | undefined> {\n let resource: GetResourceReturnType<Plugin, UriType> | undefined;\n // Get the resource based on incoming data\n if (uri) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resource = dataset.getResource(uri) as any;\n // Run read operations if necissary\n if (!options?.suppressInitialRead) {\n if (options?.reloadOnMount) {\n resource!.read();\n } else {\n resource!.readIfUnfetched();\n }\n }\n } else {\n resource = undefined;\n }\n\n // The Svelte store\n const store = writable<GetResourceReturnType<Plugin, UriType> | undefined>(\n resource,\n (set) => {\n const onResourceUpdate = () => {\n set(resource);\n };\n\n if (resource) {\n resource.on(\"update\", onResourceUpdate);\n\n // TODO: handle subscriptions\n\n return () => {\n resource.off(\"update\", onResourceUpdate);\n };\n }\n },\n );\n\n return {\n subscribe: store.subscribe,\n };\n };\n}\n","import type { LdoBuilder } from \"@ldo/ldo\";\nimport type { LdoBase, LdoDataset, ShapeType } from \"@ldo/ldo\";\nimport { createTrackingProxyBuilder } from \"@ldo/connected\";\nimport { writable, type Readable } from \"svelte/store\";\nimport type { nodeEventListener } from \"@ldo/subscribable-dataset\";\n\n/**\n * @internal\n *\n * A hook for tracking proxies\n */\nexport function useTrackingProxy<Type extends LdoBase, ReturnType>(\n shapeType: ShapeType<Type>,\n createLdo: (builder: LdoBuilder<Type>) => ReturnType,\n dataset: LdoDataset,\n): Readable<ReturnType> {\n const forceUpdateInfo: {\n set?: (item: ReturnType) => void;\n ldo?: ReturnType;\n } = {};\n\n const forceUpdate: nodeEventListener = () => {\n dataset.removeListenerFromAllEvents(forceUpdate);\n const builder = createTrackingProxyBuilder(dataset, shapeType, forceUpdate);\n const linkedDataObject = createLdo(builder);\n forceUpdateInfo.ldo = linkedDataObject;\n if (forceUpdateInfo.set && forceUpdateInfo.ldo)\n forceUpdateInfo.set(forceUpdateInfo.ldo);\n };\n forceUpdate({}, \"\", [undefined, undefined, undefined, undefined]);\n\n // The Svelte store\n const store = writable<ReturnType>(forceUpdateInfo.ldo, (set) => {\n forceUpdateInfo.set = set;\n\n return () => {\n dataset.removeListenerFromAllEvents(forceUpdate);\n };\n });\n\n return {\n subscribe: store.subscribe,\n };\n}\n","import type { SubjectNode } from \"@ldo/rdf-utils\";\nimport type { ShapeType } from \"@ldo/ldo\";\nimport type { LdoBuilder } from \"@ldo/ldo\";\nimport type { LdoBase } from \"@ldo/ldo\";\n\nimport { useTrackingProxy } from \"../util/useTrackingProxy.js\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\nimport type { Readable } from \"svelte/store\";\n\nexport type useSubjectType = {\n <Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject: string | SubjectNode,\n ): Readable<Type>;\n <Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: string | SubjectNode,\n ): Readable<Type | undefined>;\n <Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: string | SubjectNode,\n ): Readable<Type | undefined>;\n};\n\n/**\n * @internal\n *\n * Creates a useSubject function.\n */\nexport function createUseSubject<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n): useSubjectType {\n /**\n * Returns a Linked Data Object based on the provided subject. Triggers a\n * rerender if the data is udpated.\n */\n return function useSubject<Type extends LdoBase>(\n shapeType: ShapeType<Type>,\n subject?: string | SubjectNode,\n ): Readable<Type | undefined> {\n const fromSubject = (builder: LdoBuilder<Type>) => {\n if (!subject) return;\n return builder.fromSubject(subject);\n };\n\n return useTrackingProxy(shapeType, fromSubject, dataset);\n };\n}\n","import type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\n\n/**\n * @internal\n *\n * Creates a useSubscribeToResource function.\n */\nexport function createUseSubscribeToResource<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Starts a subscription to a resource.\n */\n return function useSubscribeToResource(...uris: string[]): void {\n throw new Error(\"Not Implemented\");\n };\n}\n","import type {\n ConnectedLdoDataset,\n ConnectedPlugin,\n ExpandDeep,\n LQInput,\n LQReturn,\n} from \"@ldo/connected\";\nimport type { LdoBase, ShapeType } from \"@ldo/ldo\";\nimport type { SubjectNode } from \"@ldo/rdf-utils\";\n\n/**\n * @internal\n *\n * Creates a useMatchSubject function.\n */\nexport function createUseLinkQuery<Plugins extends ConnectedPlugin[]>(\n dataset: ConnectedLdoDataset<Plugins>,\n) {\n /**\n * Returns an array of matching linked data objects. Triggers a rerender if\n * the data is updated.\n */\n return function useQueryLink<\n Type extends LdoBase,\n QueryInput extends LQInput<Type>,\n >(\n shapeType: ShapeType<Type>,\n startingResource: string,\n startingSubject: SubjectNode | string,\n linkQuery: QueryInput,\n ): ExpandDeep<LQReturn<Type, QueryInput>> | undefined {\n throw new Error(\"Not Implemented\");\n };\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { createUseLdo } from \"./methods/useLdo.js\";\nimport {\n createConnectedLdoDataset,\n type ConnectedPlugin,\n} from \"@ldo/connected\";\nimport { createUseMatchObject } from \"./methods/useMatchObject.js\";\nimport { createUseMatchSubject } from \"./methods/useMatchSubject.js\";\nimport { createUseResource } from \"./methods/useResource.js\";\nimport { createUseSubject } from \"./methods/useSubject.js\";\nimport { createUseSubscribeToResource } from \"./methods/useSubscribeToResource.js\";\nimport { createUseLinkQuery } from \"./methods/useLinkQuery.js\";\n\n/**\n * A function that creates all common react functions given specific plugin.\n *\n * @example\n * `methods.ts`\n * ```tyepscript\n * import { solidConnectedPlugin } from \"@ldo/connected-solid\";\n * import { nextGraphConnectedPlugin } from \"@ldo/connected-nextgraph\";\n * import { createLdoReactMethods } from \"@ldo/react\";\n *\n * // Export the results to be used in the reset of the application\n * export const {\n * dataset,\n * useLdo,\n * useMatchObject,\n * useMatchSubject,\n * useResource,\n * useSubject,\n * useSubscribeToResource,\n * useLinkQuery,\n * } = createLdoReactMethods([\n * solidConnectedPlugin,\n * nextGraphConnectedPlugin\n * ]);\n * ```\n *\n * `App.tsx`\n * ```typescript\n * import react, { FunctionComponent } from \"react\";\n * import { PostShShapeType } from \"./.ldo/posts.shapeType.ts\";\n * import { useResource, useSubject } from \"./methods.ts\";\n *\n * const UseSubjectTest: FunctionComponent = () => {\n * const resource = useResource(SAMPLE_DATA_URI);\n * const post = useSubject(PostShShapeType, `${SAMPLE_DATA_URI}#Post1`);\n * if (resource.isLoading() || !post) return <p>loading</p>;\n *\n * return (\n * <ul>\n * {post.publisher.map((publisher) => {\n * return <li key={publisher[\"@id\"]}>{publisher[\"@id\"]}</li>;\n * })}\n * </ul>\n * );\n * };\n * ```\n */\nexport function createLdoSvelteMethods<\n Plugins extends ConnectedPlugin<any, any, any, any>[],\n>(plugins: Plugins) {\n const dataset = createConnectedLdoDataset(plugins);\n dataset.setMaxListeners(1000);\n\n return {\n dataset,\n useLdo: createUseLdo(dataset),\n useMatchObject: createUseMatchObject(dataset),\n useMatchSubject: createUseMatchSubject(dataset),\n useResource: createUseResource(dataset),\n useSubject: createUseSubject(dataset),\n useSubscribeToResource: createUseSubscribeToResource(dataset),\n useLinkQuery: createUseLinkQuery(dataset),\n };\n}\n"],"names":["createUseLdo","dataset","createUseMatchObject","shapeType","subject","predicate","graph","createUseMatchSubject","object","createUseResource","uri","options","resource","writable","set","onResourceUpdate","useTrackingProxy","createLdo","forceUpdateInfo","forceUpdate","builder","createTrackingProxyBuilder","linkedDataObject","createUseSubject","createUseSubscribeToResource","uris","createUseLinkQuery","startingResource","startingSubject","linkQuery","createLdoSvelteMethods","plugins","createConnectedLdoDataset"],"mappings":";;AA8EO,SAASA,EACdC,GACA;AACM,QAAA,IAAI,MAAM,iBAAiB;AAiEnC;ACzIO,SAASC,EACdD,GACA;AAKA,SAAO,SACLE,GACAC,GACAC,GACAC,GACa;AACP,UAAA,IAAI,MAAM,iBAAiB;AAAA,EAAA;AAErC;ACfO,SAASC,EACdN,GACA;AAKA,SAAO,SACLE,GACAE,GACAG,GACAF,GACa;AACP,UAAA,IAAI,MAAM,iBAAiB;AAAA,EAAA;AAErC;ACcO,SAASG,EACdR,GAC0B;AAInB,SAAA,SAKLS,GACAC,GAC8D;AAC1D,QAAAC;AAEJ,WAAIF,KAESE,IAAAX,EAAQ,YAAYS,CAAG,GAE7BC,KAAA,QAAAA,EAAS,wBACRA,KAAA,QAAAA,EAAS,gBACXC,EAAU,KAAK,IAEfA,EAAU,gBAAgB,MAInBA,IAAA,QAuBN;AAAA,MACL,WApBYC;AAAA,QACZD;AAAA,QACA,CAACE,MAAQ;AACP,gBAAMC,IAAmB,MAAM;AAC7B,YAAAD,EAAIF,CAAQ;AAAA,UAAA;AAGd,cAAIA;AACO,mBAAAA,EAAA,GAAG,UAAUG,CAAgB,GAI/B,MAAM;AACF,cAAAH,EAAA,IAAI,UAAUG,CAAgB;AAAA,YAAA;AAAA,QAG7C;AAAA,MAAA,EAIiB;AAAA,IAAA;AAAA,EACnB;AAEJ;AClFgB,SAAAC,EACdb,GACAc,GACAhB,GACsB;AACtB,QAAMiB,IAGF,CAAA,GAEEC,IAAiC,MAAM;AAC3C,IAAAlB,EAAQ,4BAA4BkB,CAAW;AAC/C,UAAMC,IAAUC,EAA2BpB,GAASE,GAAWgB,CAAW,GACpEG,IAAmBL,EAAUG,CAAO;AAC1C,IAAAF,EAAgB,MAAMI,GAClBJ,EAAgB,OAAOA,EAAgB,OACzBA,EAAA,IAAIA,EAAgB,GAAG;AAAA,EAAA;AAE/B,SAAAC,EAAoD,GAWzD;AAAA,IACL,WATYN,EAAqBK,EAAgB,KAAK,CAACJ,OACvDI,EAAgB,MAAMJ,GAEf,MAAM;AACX,MAAAb,EAAQ,4BAA4BkB,CAAW;AAAA,IAAA,EAElD,EAGkB;AAAA,EAAA;AAErB;ACdO,SAASI,EACdtB,GACgB;AAKT,SAAA,SACLE,GACAC,GAC4B;AAMrB,WAAAY,EAAiBb,GALJ,CAACiB,MAA8B;AACjD,UAAKhB;AACE,eAAAgB,EAAQ,YAAYhB,CAAO;AAAA,IAAA,GAGYH,CAAO;AAAA,EAAA;AAE3D;ACxCO,SAASuB,EACdvB,GACA;AAIO,SAAA,YAAmCwB,GAAsB;AACxD,UAAA,IAAI,MAAM,iBAAiB;AAAA,EAAA;AAErC;ACDO,SAASC,EACdzB,GACA;AAKA,SAAO,SAILE,GACAwB,GACAC,GACAC,GACoD;AAC9C,UAAA,IAAI,MAAM,iBAAiB;AAAA,EAAA;AAErC;AC2BO,SAASC,EAEdC,GAAkB;AACZ,QAAA9B,IAAU+B,EAA0BD,CAAO;AACjD,SAAA9B,EAAQ,gBAAgB,GAAI,GAErB;AAAA,IACL,SAAAA;AAAA,IACA,QAAQD,EAAoB;AAAA,IAC5B,gBAAgBE,EAA4B;AAAA,IAC5C,iBAAiBK,EAA6B;AAAA,IAC9C,aAAaE,EAAkBR,CAAO;AAAA,IACtC,YAAYsB,EAAiBtB,CAAO;AAAA,IACpC,wBAAwBuB,EAAoC;AAAA,IAC5D,cAAcE,EAA0B;AAAA,EAAA;AAE5C;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './createLdoSvelteMethods.js';
|
|
2
|
+
export * from './methods/useLdo.js';
|
|
3
|
+
export * from './methods/useMatchObject.js';
|
|
4
|
+
export * from './methods/useMatchSubject.js';
|
|
5
|
+
export * from './methods/useResource.js';
|
|
6
|
+
export * from './methods/useSubject.js';
|
|
7
|
+
export * from './methods/useSubscribeToResource.js';
|
|
8
|
+
export * from './methods/useLinkQuery.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAE5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ConnectedLdoDataset, ConnectedLdoTransactionDataset, ConnectedPlugin } from '@ldo/connected';
|
|
2
|
+
import { LdoBase, ShapeType } from '@ldo/ldo';
|
|
3
|
+
import { SubjectNode } from '@ldo/rdf-utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The methods returned by useLdo
|
|
7
|
+
*/
|
|
8
|
+
export interface UseLdoMethods<Plugins extends ConnectedPlugin[]> {
|
|
9
|
+
/**
|
|
10
|
+
* A ConnectedLdoDataset
|
|
11
|
+
*/
|
|
12
|
+
dataset: ConnectedLdoDataset<Plugins>;
|
|
13
|
+
/**
|
|
14
|
+
* Retireves a representation of a Resource at the given URI. This resource
|
|
15
|
+
* represents the current state of the resource: whether it is currently
|
|
16
|
+
* fetched or in the process of fetching as well as some information about it.
|
|
17
|
+
*
|
|
18
|
+
* @param uri - the URI of the resource
|
|
19
|
+
* @param pluginName - optionally, force this function to choose a specific
|
|
20
|
+
* plugin to use rather than perform content negotiation.
|
|
21
|
+
*
|
|
22
|
+
* @returns a Resource
|
|
23
|
+
*/
|
|
24
|
+
getResource: ConnectedLdoDataset<Plugins>["getResource"];
|
|
25
|
+
/**
|
|
26
|
+
* Sets conetext for a specific plugin
|
|
27
|
+
*
|
|
28
|
+
* @param pluginName - the name of the plugin
|
|
29
|
+
* @param context - the context for this specific plugin
|
|
30
|
+
*/
|
|
31
|
+
setContext: ConnectedLdoDataset<Plugins>["setContext"];
|
|
32
|
+
/**
|
|
33
|
+
* Gets a linked data object based on the subject
|
|
34
|
+
*/
|
|
35
|
+
getSubject<Type extends LdoBase>(shapeType: ShapeType<Type>, subject: string | SubjectNode): Type;
|
|
36
|
+
/**
|
|
37
|
+
* Shorthand for connectedLdoDataset
|
|
38
|
+
* .usingType(shapeType)
|
|
39
|
+
* .write(...resources.map((r) => r.uri))
|
|
40
|
+
* .fromSubject(subject);
|
|
41
|
+
* @param shapeType - The shapetype to represent the data
|
|
42
|
+
* @param subject - A subject URI
|
|
43
|
+
* @param resources - The resources changes to should written to
|
|
44
|
+
*/
|
|
45
|
+
createData<Type extends LdoBase>(shapeType: ShapeType<Type>, subject: string | SubjectNode, resource: Plugins[number]["types"]["resource"], ...additionalResources: Plugins[number]["types"]["resource"][]): Type;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a writable LinkedDataObject given a linked data object
|
|
48
|
+
*/
|
|
49
|
+
changeData<Type extends LdoBase>(input: Type, resource: Plugins[number]["types"]["resource"], ...additionalResources: Plugins[number]["types"]["resource"][]): Type;
|
|
50
|
+
/**
|
|
51
|
+
* Commits the data of a writable Linke Data Object back to the remote.
|
|
52
|
+
*/
|
|
53
|
+
commitData(input: LdoBase): ReturnType<ConnectedLdoTransactionDataset<Plugins>["commitToRemote"]>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
* Creates the useLdoHook
|
|
58
|
+
*/
|
|
59
|
+
export declare function createUseLdo<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): void;
|
|
60
|
+
//# sourceMappingURL=useLdo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLdo.d.ts","sourceRoot":"","sources":["../../../src/methods/useLdo.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACnC,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,OAAO,SAAS,eAAe,EAAE;IAC9D;;OAEG;IACH,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACtC;;;;;;;;;;OAUG;IACH,WAAW,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC;IACzD;;;;;OAKG;IACH,UAAU,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;IACvD;;OAEG;IACH,UAAU,CAAC,IAAI,SAAS,OAAO,EAC7B,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,EAC1B,OAAO,EAAE,MAAM,GAAG,WAAW,GAC5B,IAAI,CAAC;IACR;;;;;;;;OAQG;IACH,UAAU,CAAC,IAAI,SAAS,OAAO,EAC7B,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,EAC1B,OAAO,EAAE,MAAM,GAAG,WAAW,EAC7B,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,EAC9C,GAAG,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,EAAE,GAC7D,IAAI,CAAC;IACR;;OAEG;IACH,UAAU,CAAC,IAAI,SAAS,OAAO,EAC7B,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,EAC9C,GAAG,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,EAAE,GAC7D,IAAI,CAAC;IACR;;OAEG;IACH,UAAU,CACR,KAAK,EAAE,OAAO,GACb,UAAU,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;CAC1E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,eAAe,EAAE,EAC5D,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,QAmEtC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectedLdoDataset, ConnectedPlugin, ExpandDeep, LQInput, LQReturn } from '@ldo/connected';
|
|
2
|
+
import { LdoBase, ShapeType } from '@ldo/ldo';
|
|
3
|
+
import { SubjectNode } from '@ldo/rdf-utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* Creates a useMatchSubject function.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createUseLinkQuery<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): <Type extends LdoBase, QueryInput extends LQInput<Type>>(shapeType: ShapeType<Type>, startingResource: string, startingSubject: SubjectNode | string, linkQuery: QueryInput) => ExpandDeep<LQReturn<Type, QueryInput>> | undefined;
|
|
11
|
+
//# sourceMappingURL=useLinkQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLinkQuery.d.ts","sourceRoot":"","sources":["../../../src/methods/useLinkQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,OAAO,EACP,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,eAAe,EAAE,EAClE,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,IAOnC,IAAI,SAAS,OAAO,EACpB,UAAU,SAAS,OAAO,CAAC,IAAI,CAAC,EAEhC,WAAW,SAAS,CAAC,IAAI,CAAC,EAC1B,kBAAkB,MAAM,EACxB,iBAAiB,WAAW,GAAG,MAAM,EACrC,WAAW,UAAU,KACpB,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,GAAG,SAAS,CAGtD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LdoBase, LdSet, ShapeType } from '@ldo/ldo';
|
|
2
|
+
import { QuadMatch } from '@ldo/rdf-utils';
|
|
3
|
+
import { ConnectedLdoDataset, ConnectedPlugin } from '@ldo/connected';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* Creates a useMatchObject function
|
|
9
|
+
*/
|
|
10
|
+
export declare function createUseMatchObject<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): <Type extends LdoBase>(shapeType: ShapeType<Type>, subject?: QuadMatch[0] | string, predicate?: QuadMatch[1] | string, graph?: QuadMatch[3] | string) => LdSet<Type>;
|
|
11
|
+
//# sourceMappingURL=useMatchObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMatchObject.d.ts","sourceRoot":"","sources":["../../../src/methods/useMatchObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,eAAe,EAAE,EACpE,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,IAMN,IAAI,SAAS,OAAO,EACjD,WAAW,SAAS,CAAC,IAAI,CAAC,EAC1B,UAAU,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,EAC/B,YAAY,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,EACjC,QAAQ,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,KAC5B,KAAK,CAAC,IAAI,CAAC,CAGf"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LdoBase, LdSet, ShapeType } from '@ldo/ldo';
|
|
2
|
+
import { QuadMatch } from '@ldo/rdf-utils';
|
|
3
|
+
import { ConnectedLdoDataset, ConnectedPlugin } from '@ldo/connected';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* Creates a useMatchSubject function.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createUseMatchSubject<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): <Type extends LdoBase>(shapeType: ShapeType<Type>, predicate?: QuadMatch[1] | string, object?: QuadMatch[2] | string, graph?: QuadMatch[3] | string) => LdSet<Type>;
|
|
11
|
+
//# sourceMappingURL=useMatchSubject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMatchSubject.d.ts","sourceRoot":"","sources":["../../../src/methods/useMatchSubject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,eAAe,EAAE,EACrE,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,IAML,IAAI,SAAS,OAAO,EAClD,WAAW,SAAS,CAAC,IAAI,CAAC,EAC1B,YAAY,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,EACjC,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,EAC9B,QAAQ,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,KAC5B,KAAK,CAAC,IAAI,CAAC,CAGf"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ConnectedLdoDataset, ConnectedPlugin, GetResourceReturnType } from '@ldo/connected';
|
|
2
|
+
import { Readable } from 'svelte/store';
|
|
3
|
+
|
|
4
|
+
export interface UseResourceOptions<Name> {
|
|
5
|
+
pluginName?: Name;
|
|
6
|
+
suppressInitialRead?: boolean;
|
|
7
|
+
reloadOnMount?: boolean;
|
|
8
|
+
subscribe?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type useResourceType<Plugins extends ConnectedPlugin[]> = {
|
|
11
|
+
<Name extends Plugins[number]["name"], Plugin extends Extract<Plugins[number], {
|
|
12
|
+
name: Name;
|
|
13
|
+
}>, UriType extends string>(uri: UriType, options?: UseResourceOptions<Name>): Readable<GetResourceReturnType<Plugin, UriType>>;
|
|
14
|
+
<Name extends Plugins[number]["name"], Plugin extends Extract<Plugins[number], {
|
|
15
|
+
name: Name;
|
|
16
|
+
}>, UriType extends string>(uri?: UriType, options?: UseResourceOptions<Name>): Readable<GetResourceReturnType<Plugin, UriType> | undefined>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*
|
|
21
|
+
* Creates a useResource function.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createUseResource<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): useResourceType<Plugins>;
|
|
24
|
+
//# sourceMappingURL=useResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResource.d.ts","sourceRoot":"","sources":["../../../src/methods/useResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,WAAW,kBAAkB,CAAC,IAAI;IACtC,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,eAAe,EAAE,IAAI;IAC/D,CACE,IAAI,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EACpC,MAAM,SAAS,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,EACvD,OAAO,SAAS,MAAM,EAEtB,GAAG,EAAE,OAAO,EACZ,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,GACjC,QAAQ,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,CACE,IAAI,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EACpC,MAAM,SAAS,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,EACvD,OAAO,SAAS,MAAM,EAEtB,GAAG,CAAC,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,GACjC,QAAQ,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CACjE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,eAAe,EAAE,EACjE,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACpC,eAAe,CAAC,OAAO,CAAC,CAqD1B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SubjectNode } from '@ldo/rdf-utils';
|
|
2
|
+
import { ShapeType, LdoBase } from '@ldo/ldo';
|
|
3
|
+
import { ConnectedLdoDataset, ConnectedPlugin } from '@ldo/connected';
|
|
4
|
+
import { Readable } from 'svelte/store';
|
|
5
|
+
|
|
6
|
+
export type useSubjectType = {
|
|
7
|
+
<Type extends LdoBase>(shapeType: ShapeType<Type>, subject: string | SubjectNode): Readable<Type>;
|
|
8
|
+
<Type extends LdoBase>(shapeType: ShapeType<Type>, subject?: string | SubjectNode): Readable<Type | undefined>;
|
|
9
|
+
<Type extends LdoBase>(shapeType: ShapeType<Type>, subject?: string | SubjectNode): Readable<Type | undefined>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
14
|
+
* Creates a useSubject function.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createUseSubject<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): useSubjectType;
|
|
17
|
+
//# sourceMappingURL=useSubject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubject.d.ts","sourceRoot":"","sources":["../../../src/methods/useSubject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,IAAI,SAAS,OAAO,EACnB,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,EAC1B,OAAO,EAAE,MAAM,GAAG,WAAW,GAC5B,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,IAAI,SAAS,OAAO,EACnB,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,EAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAC7B,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAC9B,CAAC,IAAI,SAAS,OAAO,EACnB,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,EAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAC7B,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,eAAe,EAAE,EAChE,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACpC,cAAc,CAgBhB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConnectedLdoDataset, ConnectedPlugin } from '@ldo/connected';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* Creates a useSubscribeToResource function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createUseSubscribeToResource<Plugins extends ConnectedPlugin[]>(dataset: ConnectedLdoDataset<Plugins>): (...uris: string[]) => void;
|
|
9
|
+
//# sourceMappingURL=useSubscribeToResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscribeToResource.d.ts","sourceRoot":"","sources":["../../../src/methods/useSubscribeToResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,SAAS,eAAe,EAAE,EAC5E,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,IAKE,GAAG,MAAM,MAAM,EAAE,KAAG,IAAI,CAGhE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LdoBuilder, LdoBase, LdoDataset, ShapeType } from '@ldo/ldo';
|
|
2
|
+
import { Readable } from 'svelte/store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* A hook for tracking proxies
|
|
8
|
+
*/
|
|
9
|
+
export declare function useTrackingProxy<Type extends LdoBase, ReturnType>(shapeType: ShapeType<Type>, createLdo: (builder: LdoBuilder<Type>) => ReturnType, dataset: LdoDataset): Readable<ReturnType>;
|
|
10
|
+
//# sourceMappingURL=useTrackingProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTrackingProxy.d.ts","sourceRoot":"","sources":["../../../src/util/useTrackingProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGvD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,SAAS,OAAO,EAAE,UAAU,EAC/D,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,EAC1B,SAAS,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,UAAU,EACpD,OAAO,EAAE,UAAU,GAClB,QAAQ,CAAC,UAAU,CAAC,CA4BtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.config.d.ts","sourceRoot":"","sources":["../vite.config.ts"],"names":[],"mappings":";AAkBA,wBAsCG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.config.example.d.ts","sourceRoot":"","sources":["../vite.config.example.ts"],"names":[],"mappings":";AAWA,wBA6CG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ldo/svelte",
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
|
+
"description": "A Svelte library for LDO.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"svelte": "src/index.ts",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "concurrently \"npm run dev:pod\" \"npm run dev:app\"",
|
|
12
|
+
"dev:pod": "tsx ./example/test-server/runServer.ts",
|
|
13
|
+
"dev:app": "vite --config vite.config.example.ts",
|
|
14
|
+
"build": "rimraf dist && vite build",
|
|
15
|
+
"build:example": "vite build --config vite.config.example.ts example",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"test:watch": "jest --watch",
|
|
18
|
+
"lint": "eslint . --ext .js,.ts,.svelte --fix --no-error-on-unmatched-pattern",
|
|
19
|
+
"format": "prettier --write .",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/o-development/ldo.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "Jackson Morgan",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/o-development/ldo/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/o-development/ldo/tree/main/packages/svelte#readme",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@ldo/test-solid-server": "^1.0.0-alpha.11",
|
|
34
|
+
"@sveltejs/vite-plugin-svelte": "^2.5.3",
|
|
35
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
36
|
+
"@testing-library/svelte": "^5.2.7",
|
|
37
|
+
"@tsconfig/svelte": "^5.0.4",
|
|
38
|
+
"@types/jest": "^29.5.14",
|
|
39
|
+
"concurrently": "^9.1.2",
|
|
40
|
+
"eslint-plugin-svelte3": "^4.0.0",
|
|
41
|
+
"identity-obj-proxy": "^3.0.0",
|
|
42
|
+
"jest": "^29.7.0",
|
|
43
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
44
|
+
"rimraf": "^5.0.10",
|
|
45
|
+
"svelte": "^3.59.2",
|
|
46
|
+
"svelte-jester": "^5.0.0",
|
|
47
|
+
"svelte-preprocess": "^5.1.4",
|
|
48
|
+
"ts-jest": "^29.3.2",
|
|
49
|
+
"tslib": "^2.8.1",
|
|
50
|
+
"typescript": "^5.8.3",
|
|
51
|
+
"vite": "^4.5.0",
|
|
52
|
+
"vite-plugin-dts": "^3.8.1"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"svelte": "^3.50.0"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@ldo/connected": "^1.0.0-alpha.11",
|
|
59
|
+
"@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.11",
|
|
60
|
+
"@ldo/ldo": "^1.0.0-alpha.11",
|
|
61
|
+
"@ldo/rdf-utils": "^1.0.0-alpha.11",
|
|
62
|
+
"@ldo/subscribable-dataset": "^1.0.0-alpha.11",
|
|
63
|
+
"@rdfjs/data-model": "^1.2.0",
|
|
64
|
+
"tsx": "^4.19.4"
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"dist",
|
|
68
|
+
"src"
|
|
69
|
+
],
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "84bd3d7cf0a1b28c5e20b019a6451973d69d0198"
|
|
74
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { createUseLdo } from "./methods/useLdo.js";
|
|
3
|
+
import {
|
|
4
|
+
createConnectedLdoDataset,
|
|
5
|
+
type ConnectedPlugin,
|
|
6
|
+
} from "@ldo/connected";
|
|
7
|
+
import { createUseMatchObject } from "./methods/useMatchObject.js";
|
|
8
|
+
import { createUseMatchSubject } from "./methods/useMatchSubject.js";
|
|
9
|
+
import { createUseResource } from "./methods/useResource.js";
|
|
10
|
+
import { createUseSubject } from "./methods/useSubject.js";
|
|
11
|
+
import { createUseSubscribeToResource } from "./methods/useSubscribeToResource.js";
|
|
12
|
+
import { createUseLinkQuery } from "./methods/useLinkQuery.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A function that creates all common react functions given specific plugin.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* `methods.ts`
|
|
19
|
+
* ```tyepscript
|
|
20
|
+
* import { solidConnectedPlugin } from "@ldo/connected-solid";
|
|
21
|
+
* import { nextGraphConnectedPlugin } from "@ldo/connected-nextgraph";
|
|
22
|
+
* import { createLdoReactMethods } from "@ldo/react";
|
|
23
|
+
*
|
|
24
|
+
* // Export the results to be used in the reset of the application
|
|
25
|
+
* export const {
|
|
26
|
+
* dataset,
|
|
27
|
+
* useLdo,
|
|
28
|
+
* useMatchObject,
|
|
29
|
+
* useMatchSubject,
|
|
30
|
+
* useResource,
|
|
31
|
+
* useSubject,
|
|
32
|
+
* useSubscribeToResource,
|
|
33
|
+
* useLinkQuery,
|
|
34
|
+
* } = createLdoReactMethods([
|
|
35
|
+
* solidConnectedPlugin,
|
|
36
|
+
* nextGraphConnectedPlugin
|
|
37
|
+
* ]);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* `App.tsx`
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import react, { FunctionComponent } from "react";
|
|
43
|
+
* import { PostShShapeType } from "./.ldo/posts.shapeType.ts";
|
|
44
|
+
* import { useResource, useSubject } from "./methods.ts";
|
|
45
|
+
*
|
|
46
|
+
* const UseSubjectTest: FunctionComponent = () => {
|
|
47
|
+
* const resource = useResource(SAMPLE_DATA_URI);
|
|
48
|
+
* const post = useSubject(PostShShapeType, `${SAMPLE_DATA_URI}#Post1`);
|
|
49
|
+
* if (resource.isLoading() || !post) return <p>loading</p>;
|
|
50
|
+
*
|
|
51
|
+
* return (
|
|
52
|
+
* <ul>
|
|
53
|
+
* {post.publisher.map((publisher) => {
|
|
54
|
+
* return <li key={publisher["@id"]}>{publisher["@id"]}</li>;
|
|
55
|
+
* })}
|
|
56
|
+
* </ul>
|
|
57
|
+
* );
|
|
58
|
+
* };
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function createLdoSvelteMethods<
|
|
62
|
+
Plugins extends ConnectedPlugin<any, any, any, any>[],
|
|
63
|
+
>(plugins: Plugins) {
|
|
64
|
+
const dataset = createConnectedLdoDataset(plugins);
|
|
65
|
+
dataset.setMaxListeners(1000);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
dataset,
|
|
69
|
+
useLdo: createUseLdo(dataset),
|
|
70
|
+
useMatchObject: createUseMatchObject(dataset),
|
|
71
|
+
useMatchSubject: createUseMatchSubject(dataset),
|
|
72
|
+
useResource: createUseResource(dataset),
|
|
73
|
+
useSubject: createUseSubject(dataset),
|
|
74
|
+
useSubscribeToResource: createUseSubscribeToResource(dataset),
|
|
75
|
+
useLinkQuery: createUseLinkQuery(dataset),
|
|
76
|
+
};
|
|
77
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./createLdoSvelteMethods.js";
|
|
2
|
+
|
|
3
|
+
export * from "./methods/useLdo.js";
|
|
4
|
+
export * from "./methods/useMatchObject.js";
|
|
5
|
+
export * from "./methods/useMatchSubject.js";
|
|
6
|
+
export * from "./methods/useResource.js";
|
|
7
|
+
export * from "./methods/useSubject.js";
|
|
8
|
+
export * from "./methods/useSubscribeToResource.js";
|
|
9
|
+
export * from "./methods/useLinkQuery.js";
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
// changeData,
|
|
3
|
+
type ConnectedLdoDataset,
|
|
4
|
+
type ConnectedLdoTransactionDataset,
|
|
5
|
+
type ConnectedPlugin,
|
|
6
|
+
} from "@ldo/connected";
|
|
7
|
+
import { type LdoBase, type ShapeType } from "@ldo/ldo";
|
|
8
|
+
import type { SubjectNode } from "@ldo/rdf-utils";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The methods returned by useLdo
|
|
12
|
+
*/
|
|
13
|
+
export interface UseLdoMethods<Plugins extends ConnectedPlugin[]> {
|
|
14
|
+
/**
|
|
15
|
+
* A ConnectedLdoDataset
|
|
16
|
+
*/
|
|
17
|
+
dataset: ConnectedLdoDataset<Plugins>;
|
|
18
|
+
/**
|
|
19
|
+
* Retireves a representation of a Resource at the given URI. This resource
|
|
20
|
+
* represents the current state of the resource: whether it is currently
|
|
21
|
+
* fetched or in the process of fetching as well as some information about it.
|
|
22
|
+
*
|
|
23
|
+
* @param uri - the URI of the resource
|
|
24
|
+
* @param pluginName - optionally, force this function to choose a specific
|
|
25
|
+
* plugin to use rather than perform content negotiation.
|
|
26
|
+
*
|
|
27
|
+
* @returns a Resource
|
|
28
|
+
*/
|
|
29
|
+
getResource: ConnectedLdoDataset<Plugins>["getResource"];
|
|
30
|
+
/**
|
|
31
|
+
* Sets conetext for a specific plugin
|
|
32
|
+
*
|
|
33
|
+
* @param pluginName - the name of the plugin
|
|
34
|
+
* @param context - the context for this specific plugin
|
|
35
|
+
*/
|
|
36
|
+
setContext: ConnectedLdoDataset<Plugins>["setContext"];
|
|
37
|
+
/**
|
|
38
|
+
* Gets a linked data object based on the subject
|
|
39
|
+
*/
|
|
40
|
+
getSubject<Type extends LdoBase>(
|
|
41
|
+
shapeType: ShapeType<Type>,
|
|
42
|
+
subject: string | SubjectNode,
|
|
43
|
+
): Type;
|
|
44
|
+
/**
|
|
45
|
+
* Shorthand for connectedLdoDataset
|
|
46
|
+
* .usingType(shapeType)
|
|
47
|
+
* .write(...resources.map((r) => r.uri))
|
|
48
|
+
* .fromSubject(subject);
|
|
49
|
+
* @param shapeType - The shapetype to represent the data
|
|
50
|
+
* @param subject - A subject URI
|
|
51
|
+
* @param resources - The resources changes to should written to
|
|
52
|
+
*/
|
|
53
|
+
createData<Type extends LdoBase>(
|
|
54
|
+
shapeType: ShapeType<Type>,
|
|
55
|
+
subject: string | SubjectNode,
|
|
56
|
+
resource: Plugins[number]["types"]["resource"],
|
|
57
|
+
...additionalResources: Plugins[number]["types"]["resource"][]
|
|
58
|
+
): Type;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a writable LinkedDataObject given a linked data object
|
|
61
|
+
*/
|
|
62
|
+
changeData<Type extends LdoBase>(
|
|
63
|
+
input: Type,
|
|
64
|
+
resource: Plugins[number]["types"]["resource"],
|
|
65
|
+
...additionalResources: Plugins[number]["types"]["resource"][]
|
|
66
|
+
): Type;
|
|
67
|
+
/**
|
|
68
|
+
* Commits the data of a writable Linke Data Object back to the remote.
|
|
69
|
+
*/
|
|
70
|
+
commitData(
|
|
71
|
+
input: LdoBase,
|
|
72
|
+
): ReturnType<ConnectedLdoTransactionDataset<Plugins>["commitToRemote"]>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
* Creates the useLdoHook
|
|
78
|
+
*/
|
|
79
|
+
export function createUseLdo<Plugins extends ConnectedPlugin[]>(
|
|
80
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
81
|
+
) {
|
|
82
|
+
throw new Error("Not Implemented");
|
|
83
|
+
// const toReturn = {
|
|
84
|
+
// dataset,
|
|
85
|
+
// /**
|
|
86
|
+
// * Gets a resource
|
|
87
|
+
// */
|
|
88
|
+
// getResource: dataset.getResource.bind(dataset),
|
|
89
|
+
// /**
|
|
90
|
+
// * Set the context
|
|
91
|
+
// */
|
|
92
|
+
// setContext: dataset.setContext.bind(dataset),
|
|
93
|
+
// /**
|
|
94
|
+
// * Returns a Linked Data Object for a subject
|
|
95
|
+
// * @param shapeType The shape type for the data
|
|
96
|
+
// * @param subject Subject Node
|
|
97
|
+
// * @returns A Linked Data Object
|
|
98
|
+
// */
|
|
99
|
+
// getSubject<Type extends LdoBase>(
|
|
100
|
+
// shapeType: ShapeType<Type>,
|
|
101
|
+
// subject: string | SubjectNode,
|
|
102
|
+
// ): Type {
|
|
103
|
+
// return dataset.usingType(shapeType).fromSubject(subject);
|
|
104
|
+
// },
|
|
105
|
+
// /**
|
|
106
|
+
// * Begins tracking changes to eventually commit for a new subject
|
|
107
|
+
// * @param shapeType The shape type that defines the created data
|
|
108
|
+
// * @param subject The RDF subject for a Linked Data Object
|
|
109
|
+
// * @param resources Any number of resources to which this data should be written
|
|
110
|
+
// * @returns A Linked Data Object to modify and commit
|
|
111
|
+
// */
|
|
112
|
+
// createData<Type extends LdoBase>(
|
|
113
|
+
// shapeType: ShapeType<Type>,
|
|
114
|
+
// subject: string | SubjectNode,
|
|
115
|
+
// resource: Plugins[number]["types"]["resource"],
|
|
116
|
+
// ...additionalResources: Plugins[number]["types"]["resource"][]
|
|
117
|
+
// ): Type {
|
|
118
|
+
// return dataset.createData(
|
|
119
|
+
// shapeType,
|
|
120
|
+
// subject,
|
|
121
|
+
// resource,
|
|
122
|
+
// ...additionalResources,
|
|
123
|
+
// );
|
|
124
|
+
// },
|
|
125
|
+
// /**
|
|
126
|
+
// * Begins tracking changes to eventually commit
|
|
127
|
+
// * @param input A linked data object to track changes on
|
|
128
|
+
// * @param resources
|
|
129
|
+
// */
|
|
130
|
+
// changeData: changeData,
|
|
131
|
+
// /**
|
|
132
|
+
// * Commits the transaction to the global dataset, syncing all subscribing
|
|
133
|
+
// * components and Solid Pods
|
|
134
|
+
// */
|
|
135
|
+
// commitData(
|
|
136
|
+
// input: LdoBase,
|
|
137
|
+
// ): ReturnType<ConnectedLdoTransactionDataset<Plugins>["commitToRemote"]> {
|
|
138
|
+
// const inputDataset = getDataset(
|
|
139
|
+
// input,
|
|
140
|
+
// ) as ConnectedLdoTransactionDataset<Plugins>;
|
|
141
|
+
// return inputDataset.commitToRemote();
|
|
142
|
+
// },
|
|
143
|
+
// };
|
|
144
|
+
// return function useLdo(): UseLdoMethods<Plugins> {
|
|
145
|
+
// throw new Error("Not Implemented");
|
|
146
|
+
// };
|
|
147
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectedLdoDataset,
|
|
3
|
+
ConnectedPlugin,
|
|
4
|
+
ExpandDeep,
|
|
5
|
+
LQInput,
|
|
6
|
+
LQReturn,
|
|
7
|
+
} from "@ldo/connected";
|
|
8
|
+
import type { LdoBase, ShapeType } from "@ldo/ldo";
|
|
9
|
+
import type { SubjectNode } from "@ldo/rdf-utils";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
14
|
+
* Creates a useMatchSubject function.
|
|
15
|
+
*/
|
|
16
|
+
export function createUseLinkQuery<Plugins extends ConnectedPlugin[]>(
|
|
17
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
18
|
+
) {
|
|
19
|
+
/**
|
|
20
|
+
* Returns an array of matching linked data objects. Triggers a rerender if
|
|
21
|
+
* the data is updated.
|
|
22
|
+
*/
|
|
23
|
+
return function useQueryLink<
|
|
24
|
+
Type extends LdoBase,
|
|
25
|
+
QueryInput extends LQInput<Type>,
|
|
26
|
+
>(
|
|
27
|
+
shapeType: ShapeType<Type>,
|
|
28
|
+
startingResource: string,
|
|
29
|
+
startingSubject: SubjectNode | string,
|
|
30
|
+
linkQuery: QueryInput,
|
|
31
|
+
): ExpandDeep<LQReturn<Type, QueryInput>> | undefined {
|
|
32
|
+
throw new Error("Not Implemented");
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LdoBase, LdSet, ShapeType } from "@ldo/ldo";
|
|
2
|
+
import type { QuadMatch } from "@ldo/rdf-utils";
|
|
3
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* Creates a useMatchObject function
|
|
9
|
+
*/
|
|
10
|
+
export function createUseMatchObject<Plugins extends ConnectedPlugin[]>(
|
|
11
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
12
|
+
) {
|
|
13
|
+
/**
|
|
14
|
+
* Returns an array of matching items and triggers a rerender when that data
|
|
15
|
+
* is updated.
|
|
16
|
+
*/
|
|
17
|
+
return function useMatchObject<Type extends LdoBase>(
|
|
18
|
+
shapeType: ShapeType<Type>,
|
|
19
|
+
subject?: QuadMatch[0] | string,
|
|
20
|
+
predicate?: QuadMatch[1] | string,
|
|
21
|
+
graph?: QuadMatch[3] | string,
|
|
22
|
+
): LdSet<Type> {
|
|
23
|
+
throw new Error("Not Implemented");
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LdoBase, LdSet, ShapeType } from "@ldo/ldo";
|
|
2
|
+
import type { QuadMatch } from "@ldo/rdf-utils";
|
|
3
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* Creates a useMatchSubject function.
|
|
9
|
+
*/
|
|
10
|
+
export function createUseMatchSubject<Plugins extends ConnectedPlugin[]>(
|
|
11
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
12
|
+
) {
|
|
13
|
+
/**
|
|
14
|
+
* Returns an array of matching linked data objects. Triggers a rerender if
|
|
15
|
+
* the data is updated.
|
|
16
|
+
*/
|
|
17
|
+
return function useMatchSubject<Type extends LdoBase>(
|
|
18
|
+
shapeType: ShapeType<Type>,
|
|
19
|
+
predicate?: QuadMatch[1] | string,
|
|
20
|
+
object?: QuadMatch[2] | string,
|
|
21
|
+
graph?: QuadMatch[3] | string,
|
|
22
|
+
): LdSet<Type> {
|
|
23
|
+
throw new Error("Not Implemented");
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectedLdoDataset,
|
|
3
|
+
ConnectedPlugin,
|
|
4
|
+
GetResourceReturnType,
|
|
5
|
+
} from "@ldo/connected";
|
|
6
|
+
import { writable, type Readable } from "svelte/store";
|
|
7
|
+
|
|
8
|
+
export interface UseResourceOptions<Name> {
|
|
9
|
+
pluginName?: Name;
|
|
10
|
+
suppressInitialRead?: boolean;
|
|
11
|
+
reloadOnMount?: boolean;
|
|
12
|
+
subscribe?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type useResourceType<Plugins extends ConnectedPlugin[]> = {
|
|
16
|
+
<
|
|
17
|
+
Name extends Plugins[number]["name"],
|
|
18
|
+
Plugin extends Extract<Plugins[number], { name: Name }>,
|
|
19
|
+
UriType extends string,
|
|
20
|
+
>(
|
|
21
|
+
uri: UriType,
|
|
22
|
+
options?: UseResourceOptions<Name>,
|
|
23
|
+
): Readable<GetResourceReturnType<Plugin, UriType>>;
|
|
24
|
+
<
|
|
25
|
+
Name extends Plugins[number]["name"],
|
|
26
|
+
Plugin extends Extract<Plugins[number], { name: Name }>,
|
|
27
|
+
UriType extends string,
|
|
28
|
+
>(
|
|
29
|
+
uri?: UriType,
|
|
30
|
+
options?: UseResourceOptions<Name>,
|
|
31
|
+
): Readable<GetResourceReturnType<Plugin, UriType> | undefined>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*
|
|
37
|
+
* Creates a useResource function.
|
|
38
|
+
*/
|
|
39
|
+
export function createUseResource<Plugins extends ConnectedPlugin[]>(
|
|
40
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
41
|
+
): useResourceType<Plugins> {
|
|
42
|
+
/**
|
|
43
|
+
* Returns a resource and triggers a rerender if that resource is updated.
|
|
44
|
+
*/
|
|
45
|
+
return function useResource<
|
|
46
|
+
Name extends Plugins[number]["name"],
|
|
47
|
+
Plugin extends Extract<Plugins[number], { name: Name }>,
|
|
48
|
+
UriType extends string,
|
|
49
|
+
>(
|
|
50
|
+
uri?: UriType,
|
|
51
|
+
options?: UseResourceOptions<Name>,
|
|
52
|
+
): Readable<GetResourceReturnType<Plugin, UriType> | undefined> {
|
|
53
|
+
let resource: GetResourceReturnType<Plugin, UriType> | undefined;
|
|
54
|
+
// Get the resource based on incoming data
|
|
55
|
+
if (uri) {
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
resource = dataset.getResource(uri) as any;
|
|
58
|
+
// Run read operations if necissary
|
|
59
|
+
if (!options?.suppressInitialRead) {
|
|
60
|
+
if (options?.reloadOnMount) {
|
|
61
|
+
resource!.read();
|
|
62
|
+
} else {
|
|
63
|
+
resource!.readIfUnfetched();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
resource = undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The Svelte store
|
|
71
|
+
const store = writable<GetResourceReturnType<Plugin, UriType> | undefined>(
|
|
72
|
+
resource,
|
|
73
|
+
(set) => {
|
|
74
|
+
const onResourceUpdate = () => {
|
|
75
|
+
set(resource);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (resource) {
|
|
79
|
+
resource.on("update", onResourceUpdate);
|
|
80
|
+
|
|
81
|
+
// TODO: handle subscriptions
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
resource.off("update", onResourceUpdate);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
subscribe: store.subscribe,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SubjectNode } from "@ldo/rdf-utils";
|
|
2
|
+
import type { ShapeType } from "@ldo/ldo";
|
|
3
|
+
import type { LdoBuilder } from "@ldo/ldo";
|
|
4
|
+
import type { LdoBase } from "@ldo/ldo";
|
|
5
|
+
|
|
6
|
+
import { useTrackingProxy } from "../util/useTrackingProxy.js";
|
|
7
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
8
|
+
import type { Readable } from "svelte/store";
|
|
9
|
+
|
|
10
|
+
export type useSubjectType = {
|
|
11
|
+
<Type extends LdoBase>(
|
|
12
|
+
shapeType: ShapeType<Type>,
|
|
13
|
+
subject: string | SubjectNode,
|
|
14
|
+
): Readable<Type>;
|
|
15
|
+
<Type extends LdoBase>(
|
|
16
|
+
shapeType: ShapeType<Type>,
|
|
17
|
+
subject?: string | SubjectNode,
|
|
18
|
+
): Readable<Type | undefined>;
|
|
19
|
+
<Type extends LdoBase>(
|
|
20
|
+
shapeType: ShapeType<Type>,
|
|
21
|
+
subject?: string | SubjectNode,
|
|
22
|
+
): Readable<Type | undefined>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*
|
|
28
|
+
* Creates a useSubject function.
|
|
29
|
+
*/
|
|
30
|
+
export function createUseSubject<Plugins extends ConnectedPlugin[]>(
|
|
31
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
32
|
+
): useSubjectType {
|
|
33
|
+
/**
|
|
34
|
+
* Returns a Linked Data Object based on the provided subject. Triggers a
|
|
35
|
+
* rerender if the data is udpated.
|
|
36
|
+
*/
|
|
37
|
+
return function useSubject<Type extends LdoBase>(
|
|
38
|
+
shapeType: ShapeType<Type>,
|
|
39
|
+
subject?: string | SubjectNode,
|
|
40
|
+
): Readable<Type | undefined> {
|
|
41
|
+
const fromSubject = (builder: LdoBuilder<Type>) => {
|
|
42
|
+
if (!subject) return;
|
|
43
|
+
return builder.fromSubject(subject);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return useTrackingProxy(shapeType, fromSubject, dataset);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* Creates a useSubscribeToResource function.
|
|
7
|
+
*/
|
|
8
|
+
export function createUseSubscribeToResource<Plugins extends ConnectedPlugin[]>(
|
|
9
|
+
dataset: ConnectedLdoDataset<Plugins>,
|
|
10
|
+
) {
|
|
11
|
+
/**
|
|
12
|
+
* Starts a subscription to a resource.
|
|
13
|
+
*/
|
|
14
|
+
return function useSubscribeToResource(...uris: string[]): void {
|
|
15
|
+
throw new Error("Not Implemented");
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LdoBuilder } from "@ldo/ldo";
|
|
2
|
+
import type { LdoBase, LdoDataset, ShapeType } from "@ldo/ldo";
|
|
3
|
+
import { createTrackingProxyBuilder } from "@ldo/connected";
|
|
4
|
+
import { writable, type Readable } from "svelte/store";
|
|
5
|
+
import type { nodeEventListener } from "@ldo/subscribable-dataset";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* A hook for tracking proxies
|
|
11
|
+
*/
|
|
12
|
+
export function useTrackingProxy<Type extends LdoBase, ReturnType>(
|
|
13
|
+
shapeType: ShapeType<Type>,
|
|
14
|
+
createLdo: (builder: LdoBuilder<Type>) => ReturnType,
|
|
15
|
+
dataset: LdoDataset,
|
|
16
|
+
): Readable<ReturnType> {
|
|
17
|
+
const forceUpdateInfo: {
|
|
18
|
+
set?: (item: ReturnType) => void;
|
|
19
|
+
ldo?: ReturnType;
|
|
20
|
+
} = {};
|
|
21
|
+
|
|
22
|
+
const forceUpdate: nodeEventListener = () => {
|
|
23
|
+
dataset.removeListenerFromAllEvents(forceUpdate);
|
|
24
|
+
const builder = createTrackingProxyBuilder(dataset, shapeType, forceUpdate);
|
|
25
|
+
const linkedDataObject = createLdo(builder);
|
|
26
|
+
forceUpdateInfo.ldo = linkedDataObject;
|
|
27
|
+
if (forceUpdateInfo.set && forceUpdateInfo.ldo)
|
|
28
|
+
forceUpdateInfo.set(forceUpdateInfo.ldo);
|
|
29
|
+
};
|
|
30
|
+
forceUpdate({}, "", [undefined, undefined, undefined, undefined]);
|
|
31
|
+
|
|
32
|
+
// The Svelte store
|
|
33
|
+
const store = writable<ReturnType>(forceUpdateInfo.ldo, (set) => {
|
|
34
|
+
forceUpdateInfo.set = set;
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
dataset.removeListenerFromAllEvents(forceUpdate);
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
subscribe: store.subscribe,
|
|
43
|
+
};
|
|
44
|
+
}
|