@ldo/solid-react 0.0.1-alpha.32 → 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/README.md +124 -3
- package/dist/{SolidAuthContext.js → cjs/SolidAuthContext.js} +5 -2
- package/dist/cjs/SolidAuthContext.js.map +1 -0
- package/dist/{UnauthenticatedSolidLdoProvider.js → cjs/UnauthenticatedSolidLdoProvider.js} +6 -3
- package/dist/cjs/UnauthenticatedSolidLdoProvider.js.map +1 -0
- package/dist/cjs/createBrowserSolidReactMethods.js +88 -0
- package/dist/cjs/createBrowserSolidReactMethods.js.map +1 -0
- package/dist/cjs/defaultIntance.js +13 -0
- package/dist/cjs/defaultIntance.js.map +1 -0
- package/dist/{index.js → cjs/index.js} +2 -11
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/useRootContainerFor.js +32 -0
- package/dist/cjs/useRootContainerFor.js.map +1 -0
- package/dist/esm/SolidAuthContext.js +9 -0
- package/dist/esm/SolidAuthContext.js.map +1 -0
- package/dist/esm/UnauthenticatedSolidLdoProvider.js +37 -0
- package/dist/esm/UnauthenticatedSolidLdoProvider.js.map +1 -0
- package/dist/esm/createBrowserSolidReactMethods.js +85 -0
- package/dist/esm/createBrowserSolidReactMethods.js.map +1 -0
- package/dist/esm/defaultIntance.js +9 -0
- package/dist/esm/defaultIntance.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/useRootContainerFor.js +29 -0
- package/dist/esm/useRootContainerFor.js.map +1 -0
- package/dist/{SolidAuthContext.d.ts → types/SolidAuthContext.d.ts} +4 -1
- package/dist/types/SolidAuthContext.d.ts.map +1 -0
- package/dist/{UnauthenticatedSolidLdoProvider.d.ts → types/UnauthenticatedSolidLdoProvider.d.ts} +4 -0
- package/dist/types/UnauthenticatedSolidLdoProvider.d.ts.map +1 -0
- package/dist/types/createBrowserSolidReactMethods.d.ts +17 -0
- package/dist/types/createBrowserSolidReactMethods.d.ts.map +1 -0
- package/dist/types/defaultIntance.d.ts +8 -0
- package/dist/types/defaultIntance.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/useRootContainerFor.d.ts +10 -0
- package/dist/types/useRootContainerFor.d.ts.map +1 -0
- package/package.json +31 -26
- package/src/SolidAuthContext.ts +3 -0
- package/src/UnauthenticatedSolidLdoProvider.tsx +6 -4
- package/src/createBrowserSolidReactMethods.tsx +132 -0
- package/src/defaultIntance.ts +20 -0
- package/src/index.ts +2 -12
- package/src/useRootContainerFor.ts +46 -0
- package/dist/BrowserSolidLdoProvider.d.ts +0 -2
- package/dist/BrowserSolidLdoProvider.js +0 -63
- package/dist/BrowserSolidLdoProvider.js.map +0 -1
- package/dist/SolidAuthContext.js.map +0 -1
- package/dist/SolidLdoProvider.d.ts +0 -8
- package/dist/SolidLdoProvider.js +0 -31
- package/dist/SolidLdoProvider.js.map +0 -1
- package/dist/UnauthenticatedSolidLdoProvider.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.js.map +0 -1
- package/dist/useLdoMethods.d.ts +0 -12
- package/dist/useLdoMethods.js +0 -20
- package/dist/useLdoMethods.js.map +0 -1
- package/dist/useMatchObject.d.ts +0 -3
- package/dist/useMatchObject.js +0 -13
- package/dist/useMatchObject.js.map +0 -1
- package/dist/useMatchSubject.d.ts +0 -3
- package/dist/useMatchSubject.js +0 -13
- package/dist/useMatchSubject.js.map +0 -1
- package/dist/useResource.d.ts +0 -12
- package/dist/useResource.js +0 -63
- package/dist/useResource.js.map +0 -1
- package/dist/useRootContainer.d.ts +0 -3
- package/dist/useRootContainer.js +0 -26
- package/dist/useRootContainer.js.map +0 -1
- package/dist/useSubject.d.ts +0 -5
- package/dist/useSubject.js +0 -15
- package/dist/useSubject.js.map +0 -1
- package/dist/useSubscribeToResource.d.ts +0 -1
- package/dist/useSubscribeToResource.js +0 -40
- package/dist/useSubscribeToResource.js.map +0 -1
- package/dist/util/TrackingProxyContext.d.ts +0 -15
- package/dist/util/TrackingProxyContext.js +0 -75
- package/dist/util/TrackingProxyContext.js.map +0 -1
- package/dist/util/useTrackingProxy.d.ts +0 -3
- package/dist/util/useTrackingProxy.js +0 -34
- package/dist/util/useTrackingProxy.js.map +0 -1
- package/src/BrowserSolidLdoProvider.tsx +0 -97
- package/src/SolidLdoProvider.tsx +0 -55
- package/src/useLdoMethods.ts +0 -84
- package/src/useMatchObject.ts +0 -21
- package/src/useMatchSubject.ts +0 -21
- package/src/useResource.ts +0 -114
- package/src/useRootContainer.ts +0 -31
- package/src/useSubject.ts +0 -30
- package/src/useSubscribeToResource.ts +0 -52
- package/src/util/TrackingProxyContext.ts +0 -110
- package/src/util/useTrackingProxy.ts +0 -55
package/dist/useResource.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useResource = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const SolidLdoProvider_1 = require("./SolidLdoProvider");
|
|
6
|
-
function useResource(uri, options) {
|
|
7
|
-
const { getResource } = (0, SolidLdoProvider_1.useLdo)();
|
|
8
|
-
const subscriptionIdRef = (0, react_1.useRef)();
|
|
9
|
-
const resource = (0, react_1.useMemo)(() => {
|
|
10
|
-
if (uri) {
|
|
11
|
-
const resource = getResource(uri);
|
|
12
|
-
if (!options?.suppressInitialRead) {
|
|
13
|
-
if (options?.reloadOnMount) {
|
|
14
|
-
resource.read();
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
resource.readIfUnfetched();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return resource;
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
}, [getResource, uri]);
|
|
24
|
-
const [resourceRepresentation, setResourceRepresentation] = (0, react_1.useState)(resource);
|
|
25
|
-
const pastResource = (0, react_1.useRef)();
|
|
26
|
-
(0, react_1.useEffect)(() => {
|
|
27
|
-
if (options?.subscribe) {
|
|
28
|
-
resource
|
|
29
|
-
?.subscribeToNotifications()
|
|
30
|
-
.then((subscriptionId) => (subscriptionIdRef.current = subscriptionId));
|
|
31
|
-
}
|
|
32
|
-
else if (subscriptionIdRef.current) {
|
|
33
|
-
resource?.unsubscribeFromNotifications(subscriptionIdRef.current);
|
|
34
|
-
}
|
|
35
|
-
return () => {
|
|
36
|
-
if (subscriptionIdRef.current)
|
|
37
|
-
resource?.unsubscribeFromNotifications(subscriptionIdRef.current);
|
|
38
|
-
};
|
|
39
|
-
}, [resource, options?.subscribe]);
|
|
40
|
-
const forceReload = (0, react_1.useCallback)(() => {
|
|
41
|
-
if (resource)
|
|
42
|
-
setResourceRepresentation(new Proxy(resource, {}));
|
|
43
|
-
}, [resource]);
|
|
44
|
-
(0, react_1.useEffect)(() => {
|
|
45
|
-
if (pastResource.current?.resource) {
|
|
46
|
-
pastResource.current.resource.off("update", pastResource.current.callback);
|
|
47
|
-
}
|
|
48
|
-
pastResource.current = { resource, callback: forceReload };
|
|
49
|
-
if (resource) {
|
|
50
|
-
resource.on("update", forceReload);
|
|
51
|
-
setResourceRepresentation(new Proxy(resource, {}));
|
|
52
|
-
return () => {
|
|
53
|
-
resource.off("update", forceReload);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
setResourceRepresentation(undefined);
|
|
58
|
-
}
|
|
59
|
-
}, [resource]);
|
|
60
|
-
return resourceRepresentation;
|
|
61
|
-
}
|
|
62
|
-
exports.useResource = useResource;
|
|
63
|
-
//# sourceMappingURL=useResource.js.map
|
package/dist/useResource.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useResource.js","sourceRoot":"","sources":["../src/useResource.ts"],"names":[],"mappings":";;;AAAA,iCAA0E;AAQ1E,yDAA4C;AA6B5C,SAAgB,WAAW,CACzB,GAAY,EACZ,OAA4B;IAE5B,MA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;IAGnC,MAAM,WAAW,GAAG,IAAA,mBAAW,EAE7B,GAAG,EAAE;QACH,IAAI,QAAQ;YAAE,yBAAyB,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,IAAA,iBAAS,EAAC,GAAG,EAAE;QAEb,IAAI,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE;YAClC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAC/B,QAAQ,EACR,YAAY,CAAC,OAAO,CAAC,QAAQ,CAC9B,CAAC;SACH;QAED,YAAY,CAAC,OAAO,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;QAC3D,IAAI,QAAQ,EAAE;YAEZ,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YACnC,yBAAyB,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;YAGnD,OAAO,GAAG,EAAE;gBACV,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YACtC,CAAC,CAAC;SACH;aAAM;YACL,yBAAyB,CAAC,SAAS,CAAC,CAAC;SACtC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACf,OAAO,sBAAsB,CAAC;AAChC,CAAC;AA5ED,kCA4EC"}
|
package/dist/useRootContainer.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRootContainerFor = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useResource_1 = require("./useResource");
|
|
6
|
-
const SolidLdoProvider_1 = require("./SolidLdoProvider");
|
|
7
|
-
function useRootContainerFor(uri, options) {
|
|
8
|
-
const { getResource } = (0, SolidLdoProvider_1.useLdo)();
|
|
9
|
-
const [rootContainerUri, setRootContainerUri] = (0, react_1.useState)(undefined);
|
|
10
|
-
(0, react_1.useEffect)(() => {
|
|
11
|
-
if (uri) {
|
|
12
|
-
const givenResource = getResource(uri);
|
|
13
|
-
givenResource.getRootContainer().then((result) => {
|
|
14
|
-
if (!result.isError) {
|
|
15
|
-
setRootContainerUri(result.uri);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
setRootContainerUri(undefined);
|
|
21
|
-
}
|
|
22
|
-
}, [uri]);
|
|
23
|
-
return (0, useResource_1.useResource)(rootContainerUri, options);
|
|
24
|
-
}
|
|
25
|
-
exports.useRootContainerFor = useRootContainerFor;
|
|
26
|
-
//# sourceMappingURL=useRootContainer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRootContainer.js","sourceRoot":"","sources":["../src/useRootContainer.ts"],"names":[],"mappings":";;;AACA,iCAA4C;AAE5C,+CAA4C;AAC5C,yDAA4C;AAE5C,SAAgB,mBAAmB,CACjC,GAAY,EACZ,OAA4B;IAE5B,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,yBAAM,GAAE,CAAC;IAEjC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,IAAA,gBAAQ,EAEtD,SAAS,CAAC,CAAC;IAEb,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,GAAG,EAAE;YACP,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;YACvC,aAAa,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC/C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oBACnB,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;iBACjC;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,mBAAmB,CAAC,SAAS,CAAC,CAAC;SAChC;IACH,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,IAAA,yBAAW,EAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAxBD,kDAwBC"}
|
package/dist/useSubject.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { SubjectNode } from "@ldo/rdf-utils";
|
|
2
|
-
import type { ShapeType } from "@ldo/ldo";
|
|
3
|
-
import type { LdoBase } from "@ldo/ldo";
|
|
4
|
-
export declare function useSubject<Type extends LdoBase>(shapeType: ShapeType<Type>, subject: string | SubjectNode): Type;
|
|
5
|
-
export declare function useSubject<Type extends LdoBase>(shapeType: ShapeType<Type>, subject?: string | SubjectNode): Type | undefined;
|
package/dist/useSubject.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSubject = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useTrackingProxy_1 = require("./util/useTrackingProxy");
|
|
6
|
-
function useSubject(shapeType, subject) {
|
|
7
|
-
const fromSubject = (0, react_1.useCallback)((builder) => {
|
|
8
|
-
if (!subject)
|
|
9
|
-
return;
|
|
10
|
-
return builder.fromSubject(subject);
|
|
11
|
-
}, [subject]);
|
|
12
|
-
return (0, useTrackingProxy_1.useTrackingProxy)(shapeType, fromSubject);
|
|
13
|
-
}
|
|
14
|
-
exports.useSubject = useSubject;
|
|
15
|
-
//# sourceMappingURL=useSubject.js.map
|
package/dist/useSubject.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSubject.js","sourceRoot":"","sources":["../src/useSubject.ts"],"names":[],"mappings":";;;AAIA,iCAAoC;AAEpC,8DAA2D;AAU3D,SAAgB,UAAU,CACxB,SAA0B,EAC1B,OAA8B;IAE9B,MAAM,WAAW,GAAG,IAAA,mBAAW,EAC7B,CAAC,OAAyB,EAAE,EAAE;QAC5B,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,IAAA,mCAAgB,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC;AAbD,gCAaC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useSubscribeToResource(...uris: string[]): void;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSubscribeToResource = void 0;
|
|
4
|
-
const SolidLdoProvider_1 = require("./SolidLdoProvider");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
function useSubscribeToResource(...uris) {
|
|
7
|
-
const { dataset } = (0, SolidLdoProvider_1.useLdo)();
|
|
8
|
-
const currentlySubscribed = (0, react_1.useRef)({});
|
|
9
|
-
(0, react_1.useEffect)(() => {
|
|
10
|
-
const resources = uris.map((uri) => dataset.getResource(uri));
|
|
11
|
-
const previousSubscriptions = { ...currentlySubscribed.current };
|
|
12
|
-
Promise.all(resources.map(async (resource) => {
|
|
13
|
-
if (!previousSubscriptions[resource.uri]) {
|
|
14
|
-
currentlySubscribed.current[resource.uri] = "AWAITING";
|
|
15
|
-
await resource.readIfUnfetched();
|
|
16
|
-
currentlySubscribed.current[resource.uri] =
|
|
17
|
-
await resource.subscribeToNotifications();
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
delete previousSubscriptions[resource.uri];
|
|
21
|
-
}
|
|
22
|
-
})).then(async () => {
|
|
23
|
-
await Promise.all(Object.entries(previousSubscriptions).map(async ([resourceUri, subscriptionId]) => {
|
|
24
|
-
delete currentlySubscribed.current[resourceUri];
|
|
25
|
-
const resource = dataset.getResource(resourceUri);
|
|
26
|
-
await resource.unsubscribeFromNotifications(subscriptionId);
|
|
27
|
-
}));
|
|
28
|
-
});
|
|
29
|
-
}, [uris]);
|
|
30
|
-
(0, react_1.useEffect)(() => {
|
|
31
|
-
return () => {
|
|
32
|
-
Promise.all(Object.entries(currentlySubscribed.current).map(async ([resourceUri, subscriptionId]) => {
|
|
33
|
-
const resource = dataset.getResource(resourceUri);
|
|
34
|
-
await resource.unsubscribeFromNotifications(subscriptionId);
|
|
35
|
-
}));
|
|
36
|
-
};
|
|
37
|
-
}, []);
|
|
38
|
-
}
|
|
39
|
-
exports.useSubscribeToResource = useSubscribeToResource;
|
|
40
|
-
//# sourceMappingURL=useSubscribeToResource.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSubscribeToResource.js","sourceRoot":"","sources":["../src/useSubscribeToResource.ts"],"names":[],"mappings":";;;AAAA,yDAA4C;AAC5C,iCAA0C;AAE1C,SAAgB,sBAAsB,CAAC,GAAG,IAAc;IACtD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,yBAAM,GAAE,CAAC;IAC7B,MAAM,mBAAmB,GAAG,IAAA,cAAM,EAAyB,EAAE,CAAC,CAAC;IAC/D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,MAAM,qBAAqB,GAAG,EAAE,GAAG,mBAAmB,CAAC,OAAO,EAAE,CAAC;QACjE,OAAO,CAAC,GAAG,CACT,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAC/B,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAGxC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;gBAEvD,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;gBACjC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,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
3
|
-
import type { SubscribableDataset } from "@ldo/subscribable-dataset";
|
|
4
|
-
import type { Quad } from "@rdfjs/types";
|
|
5
|
-
export interface TrackingProxyContextOptions extends ProxyContextOptions {
|
|
6
|
-
dataset: SubscribableDataset<Quad>;
|
|
7
|
-
}
|
|
8
|
-
export declare class TrackingProxyContext extends ProxyContext {
|
|
9
|
-
private listener;
|
|
10
|
-
private subscribableDataset;
|
|
11
|
-
constructor(options: TrackingProxyContextOptions, listener: () => void);
|
|
12
|
-
private addListener;
|
|
13
|
-
protected createSubjectHandler(): ProxyHandler<SubjectProxyTarget>;
|
|
14
|
-
protected createArrayHandler(): ProxyHandler<ArrayProxyTarget>;
|
|
15
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrackingProxyContext = void 0;
|
|
4
|
-
const jsonld_dataset_proxy_1 = require("@ldo/jsonld-dataset-proxy");
|
|
5
|
-
const data_model_1 = require("@rdfjs/data-model");
|
|
6
|
-
class TrackingProxyContext extends jsonld_dataset_proxy_1.ProxyContext {
|
|
7
|
-
constructor(options, listener) {
|
|
8
|
-
super(options);
|
|
9
|
-
this.subscribableDataset = options.dataset;
|
|
10
|
-
this.listener = listener;
|
|
11
|
-
}
|
|
12
|
-
addListener(eventName) {
|
|
13
|
-
const listeners = this.subscribableDataset.listeners(eventName);
|
|
14
|
-
if (!listeners.includes(this.listener)) {
|
|
15
|
-
this.subscribableDataset.on(eventName, this.listener);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
createSubjectHandler() {
|
|
19
|
-
const baseHandler = super.createSubjectHandler();
|
|
20
|
-
const oldGetFunction = baseHandler.get;
|
|
21
|
-
const newGetFunction = (target, key, receiver) => {
|
|
22
|
-
const subject = target["@id"];
|
|
23
|
-
const rdfTypes = this.getRdfType(subject);
|
|
24
|
-
if (typeof key === "symbol") {
|
|
25
|
-
}
|
|
26
|
-
else if (key === "@id") {
|
|
27
|
-
this.addListener([subject, null, null, null]);
|
|
28
|
-
}
|
|
29
|
-
else if (!this.contextUtil.isArray(key, rdfTypes)) {
|
|
30
|
-
const predicate = (0, data_model_1.namedNode)(this.contextUtil.keyToIri(key, rdfTypes));
|
|
31
|
-
this.addListener([subject, predicate, null, null]);
|
|
32
|
-
}
|
|
33
|
-
return oldGetFunction && oldGetFunction(target, key, receiver);
|
|
34
|
-
};
|
|
35
|
-
baseHandler.get = newGetFunction;
|
|
36
|
-
baseHandler.set = () => {
|
|
37
|
-
console.warn("You've attempted to set a value on a Linked Data Object from the useSubject, useMatchingSubject, or useMatchingObject hooks. These linked data objects should only be used to render data, not modify it. To modify data, use the `changeData` function.");
|
|
38
|
-
return true;
|
|
39
|
-
};
|
|
40
|
-
return baseHandler;
|
|
41
|
-
}
|
|
42
|
-
createArrayHandler() {
|
|
43
|
-
const baseHandler = super.createArrayHandler();
|
|
44
|
-
const oldGetFunction = baseHandler.get;
|
|
45
|
-
const newGetFunction = (target, key, receiver) => {
|
|
46
|
-
if (qualifiedArrayMethods.has(key)) {
|
|
47
|
-
this.addListener([target[0][0], target[0][1], target[0][2], null]);
|
|
48
|
-
}
|
|
49
|
-
return oldGetFunction && oldGetFunction(target, key, receiver);
|
|
50
|
-
};
|
|
51
|
-
baseHandler.get = newGetFunction;
|
|
52
|
-
return baseHandler;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.TrackingProxyContext = TrackingProxyContext;
|
|
56
|
-
const qualifiedArrayMethods = new Set([
|
|
57
|
-
"forEach",
|
|
58
|
-
"map",
|
|
59
|
-
"reduce",
|
|
60
|
-
Symbol.iterator,
|
|
61
|
-
"entries",
|
|
62
|
-
"every",
|
|
63
|
-
"filter",
|
|
64
|
-
"find",
|
|
65
|
-
"findIndex",
|
|
66
|
-
"findLast",
|
|
67
|
-
"findLastIndex",
|
|
68
|
-
"includes, indexOf",
|
|
69
|
-
"keys",
|
|
70
|
-
"lastIndexOf",
|
|
71
|
-
"reduceRight",
|
|
72
|
-
"some",
|
|
73
|
-
"values",
|
|
74
|
-
]);
|
|
75
|
-
//# sourceMappingURL=TrackingProxyContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TrackingProxyContext.js","sourceRoot":"","sources":["../../src/util/TrackingProxyContext.ts"],"names":[],"mappings":";;;AAKA,oEAAyD;AAGzD,kDAA8C;AAiB9C,MAAa,oBAAqB,SAAQ,mCAAY;IAIpD,YAAY,OAAoC,EAAE,QAAoB;QACpE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAGO,WAAW,CAAC,SAAoB;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACtC,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SACvD;IACH,CAAC;IAES,oBAAoB;QAC5B,MAAM,WAAW,GAAG,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjD,MAAM,cAAc,GAAG,WAAW,CAAC,GAAG,CAAC;QACvC,MAAM,cAAc,GAA4C,CAC9D,MAA0B,EAC1B,GAAoB,EACpB,QAAQ,EACR,EAAE;YACF,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;aAE5B;iBAAM,IAAI,GAAG,KAAK,KAAK,EAAE;gBACxB,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,IAA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AAW,CAAC,GAAG,GAAG,cAAc,CAAC;QACjC,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAhED,oDAgEC;AAED,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,SAAS;IACT,KAAK;IACL,QAAQ;IACR,MAAM,CAAC,QAAQ;IACf,SAAS;IACT,OAAO;IACP,QAAQ;IACR,MAAM;IACN,WAAW;IACX,UAAU;IACV,eAAe;IACf,mBAAmB;IACnB,MAAM;IACN,aAAa;IACb,aAAa;IACb,MAAM;IACN,QAAQ;CACT,CAAC,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTrackingProxy = void 0;
|
|
4
|
-
const jsonld_dataset_proxy_1 = require("@ldo/jsonld-dataset-proxy");
|
|
5
|
-
const ldo_1 = require("@ldo/ldo");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const TrackingProxyContext_1 = require("./TrackingProxyContext");
|
|
8
|
-
const data_model_1 = require("@rdfjs/data-model");
|
|
9
|
-
const SolidLdoProvider_1 = require("../SolidLdoProvider");
|
|
10
|
-
function useTrackingProxy(shapeType, createLdo) {
|
|
11
|
-
const { dataset } = (0, SolidLdoProvider_1.useLdo)();
|
|
12
|
-
const [forceUpdateCounter, setForceUpdateCounter] = (0, react_1.useState)(0);
|
|
13
|
-
const forceUpdate = (0, react_1.useCallback)(() => setForceUpdateCounter((val) => val + 1), []);
|
|
14
|
-
const linkedDataObject = (0, react_1.useMemo)(() => {
|
|
15
|
-
dataset.removeListenerFromAllEvents(forceUpdate);
|
|
16
|
-
const contextUtil = new jsonld_dataset_proxy_1.ContextUtil(shapeType.context);
|
|
17
|
-
const proxyContext = new TrackingProxyContext_1.TrackingProxyContext({
|
|
18
|
-
dataset,
|
|
19
|
-
contextUtil,
|
|
20
|
-
writeGraphs: [(0, data_model_1.defaultGraph)()],
|
|
21
|
-
languageOrdering: ["none", "en", "other"],
|
|
22
|
-
}, forceUpdate);
|
|
23
|
-
const builder = new ldo_1.LdoBuilder(new jsonld_dataset_proxy_1.JsonldDatasetProxyBuilder(proxyContext), shapeType);
|
|
24
|
-
return createLdo(builder);
|
|
25
|
-
}, [shapeType, dataset, forceUpdateCounter, forceUpdate, createLdo]);
|
|
26
|
-
(0, react_1.useEffect)(() => {
|
|
27
|
-
return () => {
|
|
28
|
-
dataset.removeListenerFromAllEvents(forceUpdate);
|
|
29
|
-
};
|
|
30
|
-
}, [shapeType]);
|
|
31
|
-
return linkedDataObject;
|
|
32
|
-
}
|
|
33
|
-
exports.useTrackingProxy = useTrackingProxy;
|
|
34
|
-
//# sourceMappingURL=useTrackingProxy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTrackingProxy.js","sourceRoot":"","sources":["../../src/util/useTrackingProxy.ts"],"names":[],"mappings":";;;AAAA,oEAGmC;AACnC,kCAAsC;AAEtC,iCAAkE;AAClE,iEAA8D;AAC9D,kDAAiD;AACjD,0DAA6C;AAE7C,SAAgB,gBAAgB,CAC9B,SAA0B,EAC1B,SAAoD;IAEpD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,yBAAM,GAAE,CAAC;IAE7B,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,IAAA,mBAAW,EAC7B,GAAG,EAAE,CAAC,qBAAqB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,EAC7C,EAAE,CACH,CAAC;IAGF,MAAM,gBAAgB,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAEpC,OAAO,CAAC,2BAA2B,CAAC,WAAW,CAAC,CAAC;QAGjD,MAAM,WAAW,GAAG,IAAI,kCAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACvD,MAAM,YAAY,GAAG,IAAI,2CAAoB,CAC3C;YACE,OAAO;YACP,WAAW;YACX,WAAW,EAAE,CAAC,IAAA,yBAAY,GAAE,CAAC;YAC7B,gBAAgB,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;SAC1C,EACD,WAAW,CACZ,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,gBAAU,CAC5B,IAAI,gDAAyB,CAAC,YAAY,CAAC,EAC3C,SAAS,CACV,CAAC;QACF,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAErE,IAAA,iBAAS,EAAC,GAAG,EAAE;QAEb,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACnD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AA3CD,4CA2CC"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import type { FunctionComponent, PropsWithChildren } from "react";
|
|
3
|
-
import type { LoginOptions, SessionInfo } from "./SolidAuthContext";
|
|
4
|
-
import { SolidAuthContext } from "./SolidAuthContext";
|
|
5
|
-
import {
|
|
6
|
-
getDefaultSession,
|
|
7
|
-
handleIncomingRedirect,
|
|
8
|
-
login as libraryLogin,
|
|
9
|
-
logout as libraryLogout,
|
|
10
|
-
fetch as libraryFetch,
|
|
11
|
-
} from "@inrupt/solid-client-authn-browser";
|
|
12
|
-
import { SolidLdoProvider } from "./SolidLdoProvider";
|
|
13
|
-
|
|
14
|
-
const PRE_REDIRECT_URI = "PRE_REDIRECT_URI";
|
|
15
|
-
|
|
16
|
-
export const BrowserSolidLdoProvider: FunctionComponent<PropsWithChildren> = ({
|
|
17
|
-
children,
|
|
18
|
-
}) => {
|
|
19
|
-
const [session, setSession] = useState<SessionInfo>(getDefaultSession().info);
|
|
20
|
-
const [ranInitialAuthCheck, setRanInitialAuthCheck] = useState(false);
|
|
21
|
-
|
|
22
|
-
const runInitialAuthCheck = useCallback(async () => {
|
|
23
|
-
if (!window.localStorage.getItem(PRE_REDIRECT_URI)) {
|
|
24
|
-
window.localStorage.setItem(PRE_REDIRECT_URI, window.location.href);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
await handleIncomingRedirect({
|
|
28
|
-
restorePreviousSession: true,
|
|
29
|
-
});
|
|
30
|
-
// Set timout to ensure this happens after the redirect
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
setSession({ ...getDefaultSession().info });
|
|
33
|
-
window.history.replaceState(
|
|
34
|
-
{},
|
|
35
|
-
"",
|
|
36
|
-
window.localStorage.getItem(PRE_REDIRECT_URI),
|
|
37
|
-
);
|
|
38
|
-
window.localStorage.removeItem(PRE_REDIRECT_URI);
|
|
39
|
-
|
|
40
|
-
setRanInitialAuthCheck(true);
|
|
41
|
-
}, 0);
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
const login = useCallback(async (issuer: string, options?: LoginOptions) => {
|
|
45
|
-
const cleanUrl = new URL(window.location.href);
|
|
46
|
-
cleanUrl.hash = "";
|
|
47
|
-
cleanUrl.search = "";
|
|
48
|
-
const fullOptions = {
|
|
49
|
-
redirectUrl: cleanUrl.toString(),
|
|
50
|
-
clientName: "Solid App",
|
|
51
|
-
oidcIssuer: issuer,
|
|
52
|
-
...options,
|
|
53
|
-
};
|
|
54
|
-
window.localStorage.setItem(PRE_REDIRECT_URI, window.location.href);
|
|
55
|
-
await libraryLogin(fullOptions);
|
|
56
|
-
setSession({ ...getDefaultSession().info });
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
const logout = useCallback(async () => {
|
|
60
|
-
await libraryLogout();
|
|
61
|
-
setSession({ ...getDefaultSession().info });
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
const signUp = useCallback(
|
|
65
|
-
async (issuer: string, options?: LoginOptions) => {
|
|
66
|
-
// The typings on @inrupt/solid-client-authn-core have not yet been updated
|
|
67
|
-
// TODO: remove this ts-ignore when they are updated.
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
return login(issuer, { ...options, prompt: "create" });
|
|
71
|
-
},
|
|
72
|
-
[login],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
runInitialAuthCheck();
|
|
77
|
-
}, []);
|
|
78
|
-
|
|
79
|
-
const solidAuthFunctions = useMemo(
|
|
80
|
-
() => ({
|
|
81
|
-
runInitialAuthCheck,
|
|
82
|
-
login,
|
|
83
|
-
logout,
|
|
84
|
-
signUp,
|
|
85
|
-
session,
|
|
86
|
-
ranInitialAuthCheck,
|
|
87
|
-
fetch: libraryFetch,
|
|
88
|
-
}),
|
|
89
|
-
[login, logout, ranInitialAuthCheck, runInitialAuthCheck, session, signUp],
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<SolidAuthContext.Provider value={solidAuthFunctions}>
|
|
94
|
-
<SolidLdoProvider>{children}</SolidLdoProvider>
|
|
95
|
-
</SolidAuthContext.Provider>
|
|
96
|
-
);
|
|
97
|
-
};
|
package/src/SolidLdoProvider.tsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext } from "react";
|
|
2
|
-
import {
|
|
3
|
-
useMemo,
|
|
4
|
-
type FunctionComponent,
|
|
5
|
-
type PropsWithChildren,
|
|
6
|
-
useEffect,
|
|
7
|
-
} from "react";
|
|
8
|
-
import { useSolidAuth } from "./SolidAuthContext";
|
|
9
|
-
import type { SolidLdoDataset } from "@ldo/solid";
|
|
10
|
-
import { createSolidLdoDataset } from "@ldo/solid";
|
|
11
|
-
import type { UseLdoMethods } from "./useLdoMethods";
|
|
12
|
-
import { createUseLdoMethods } from "./useLdoMethods";
|
|
13
|
-
|
|
14
|
-
export const SolidLdoReactContext =
|
|
15
|
-
// This will be set in the provider
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
createContext<UseLdoMethods>(undefined);
|
|
19
|
-
|
|
20
|
-
export function useLdo(): UseLdoMethods {
|
|
21
|
-
return useContext(SolidLdoReactContext);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface SolidLdoProviderProps extends PropsWithChildren {}
|
|
25
|
-
|
|
26
|
-
export const SolidLdoProvider: FunctionComponent<SolidLdoProviderProps> = ({
|
|
27
|
-
children,
|
|
28
|
-
}) => {
|
|
29
|
-
const { fetch } = useSolidAuth();
|
|
30
|
-
|
|
31
|
-
// Initialize storeDependencies before render
|
|
32
|
-
const solidLdoDataset: SolidLdoDataset = useMemo(() => {
|
|
33
|
-
const ldoDataset = createSolidLdoDataset({
|
|
34
|
-
fetch,
|
|
35
|
-
});
|
|
36
|
-
ldoDataset.setMaxListeners(1000);
|
|
37
|
-
return ldoDataset;
|
|
38
|
-
}, []);
|
|
39
|
-
|
|
40
|
-
// Keep context in sync with props
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
solidLdoDataset.context.fetch = fetch;
|
|
43
|
-
}, [fetch]);
|
|
44
|
-
|
|
45
|
-
const value: UseLdoMethods = useMemo(
|
|
46
|
-
() => createUseLdoMethods(solidLdoDataset),
|
|
47
|
-
[solidLdoDataset],
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<SolidLdoReactContext.Provider value={value}>
|
|
52
|
-
{children}
|
|
53
|
-
</SolidLdoReactContext.Provider>
|
|
54
|
-
);
|
|
55
|
-
};
|
package/src/useLdoMethods.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { LdoBase, ShapeType } from "@ldo/ldo";
|
|
2
|
-
import type { SubjectNode } from "@ldo/rdf-utils";
|
|
3
|
-
import type {
|
|
4
|
-
Resource,
|
|
5
|
-
SolidLdoDataset,
|
|
6
|
-
SolidLdoTransactionDataset,
|
|
7
|
-
} from "@ldo/solid";
|
|
8
|
-
import { changeData, commitData } from "@ldo/solid";
|
|
9
|
-
|
|
10
|
-
export interface UseLdoMethods {
|
|
11
|
-
dataset: SolidLdoDataset;
|
|
12
|
-
getResource: SolidLdoDataset["getResource"];
|
|
13
|
-
getSubject<Type extends LdoBase>(
|
|
14
|
-
shapeType: ShapeType<Type>,
|
|
15
|
-
subject: string | SubjectNode,
|
|
16
|
-
): Type;
|
|
17
|
-
createData<Type extends LdoBase>(
|
|
18
|
-
shapeType: ShapeType<Type>,
|
|
19
|
-
subject: string | SubjectNode,
|
|
20
|
-
resource: Resource,
|
|
21
|
-
...additionalResources: Resource[]
|
|
22
|
-
): Type;
|
|
23
|
-
changeData<Type extends LdoBase>(
|
|
24
|
-
input: Type,
|
|
25
|
-
resource: Resource,
|
|
26
|
-
...additionalResources: Resource[]
|
|
27
|
-
): Type;
|
|
28
|
-
commitData(
|
|
29
|
-
input: LdoBase,
|
|
30
|
-
): ReturnType<SolidLdoTransactionDataset["commitToPod"]>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function createUseLdoMethods(dataset: SolidLdoDataset): UseLdoMethods {
|
|
34
|
-
return {
|
|
35
|
-
dataset: dataset,
|
|
36
|
-
/**
|
|
37
|
-
* Gets a resource
|
|
38
|
-
*/
|
|
39
|
-
getResource: dataset.getResource.bind(dataset),
|
|
40
|
-
/**
|
|
41
|
-
* Returns a Linked Data Object for a subject
|
|
42
|
-
* @param shapeType The shape type for the data
|
|
43
|
-
* @param subject Subject Node
|
|
44
|
-
* @returns A Linked Data Object
|
|
45
|
-
*/
|
|
46
|
-
getSubject<Type extends LdoBase>(
|
|
47
|
-
shapeType: ShapeType<Type>,
|
|
48
|
-
subject: string | SubjectNode,
|
|
49
|
-
): Type {
|
|
50
|
-
return dataset.usingType(shapeType).fromSubject(subject);
|
|
51
|
-
},
|
|
52
|
-
/**
|
|
53
|
-
* Begins tracking changes to eventually commit for a new subject
|
|
54
|
-
* @param shapeType The shape type that defines the created data
|
|
55
|
-
* @param subject The RDF subject for a Linked Data Object
|
|
56
|
-
* @param resources Any number of resources to which this data should be written
|
|
57
|
-
* @returns A Linked Data Object to modify and commit
|
|
58
|
-
*/
|
|
59
|
-
createData<Type extends LdoBase>(
|
|
60
|
-
shapeType: ShapeType<Type>,
|
|
61
|
-
subject: string | SubjectNode,
|
|
62
|
-
resource: Resource,
|
|
63
|
-
...additionalResources: Resource[]
|
|
64
|
-
): Type {
|
|
65
|
-
return dataset.createData(
|
|
66
|
-
shapeType,
|
|
67
|
-
subject,
|
|
68
|
-
resource,
|
|
69
|
-
...additionalResources,
|
|
70
|
-
);
|
|
71
|
-
},
|
|
72
|
-
/**
|
|
73
|
-
* Begins tracking changes to eventually commit
|
|
74
|
-
* @param input A linked data object to track changes on
|
|
75
|
-
* @param resources
|
|
76
|
-
*/
|
|
77
|
-
changeData: changeData,
|
|
78
|
-
/**
|
|
79
|
-
* Commits the transaction to the global dataset, syncing all subscribing
|
|
80
|
-
* components and Solid Pods
|
|
81
|
-
*/
|
|
82
|
-
commitData: commitData,
|
|
83
|
-
};
|
|
84
|
-
}
|
package/src/useMatchObject.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { LdoBase, ShapeType } from "@ldo/ldo";
|
|
2
|
-
import type { QuadMatch } from "@ldo/rdf-utils";
|
|
3
|
-
import type { LdoBuilder } from "@ldo/ldo";
|
|
4
|
-
import { useCallback } from "react";
|
|
5
|
-
import { useTrackingProxy } from "./util/useTrackingProxy";
|
|
6
|
-
|
|
7
|
-
export function useMatchObject<Type extends LdoBase>(
|
|
8
|
-
shapeType: ShapeType<Type>,
|
|
9
|
-
subject?: QuadMatch[0] | string,
|
|
10
|
-
predicate?: QuadMatch[1] | string,
|
|
11
|
-
graph?: QuadMatch[3] | string,
|
|
12
|
-
): Type[] {
|
|
13
|
-
const matchObject = useCallback(
|
|
14
|
-
(builder: LdoBuilder<Type>) => {
|
|
15
|
-
return builder.matchObject(subject, predicate, graph);
|
|
16
|
-
},
|
|
17
|
-
[subject, predicate, graph],
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return useTrackingProxy(shapeType, matchObject);
|
|
21
|
-
}
|
package/src/useMatchSubject.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { LdoBase, ShapeType } from "@ldo/ldo";
|
|
2
|
-
import type { QuadMatch } from "@ldo/rdf-utils";
|
|
3
|
-
import type { LdoBuilder } from "@ldo/ldo";
|
|
4
|
-
import { useCallback } from "react";
|
|
5
|
-
import { useTrackingProxy } from "./util/useTrackingProxy";
|
|
6
|
-
|
|
7
|
-
export function useMatchSubject<Type extends LdoBase>(
|
|
8
|
-
shapeType: ShapeType<Type>,
|
|
9
|
-
predicate?: QuadMatch[1] | string,
|
|
10
|
-
object?: QuadMatch[2] | string,
|
|
11
|
-
graph?: QuadMatch[3] | string,
|
|
12
|
-
): Type[] {
|
|
13
|
-
const matchSubject = useCallback(
|
|
14
|
-
(builder: LdoBuilder<Type>) => {
|
|
15
|
-
return builder.matchSubject(predicate, object, graph);
|
|
16
|
-
},
|
|
17
|
-
[predicate, object, graph],
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return useTrackingProxy(shapeType, matchSubject);
|
|
21
|
-
}
|