@ldo/solid-type-index 1.0.0-alpha.51 → 1.0.0-alpha.53
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 +2 -2
- package/dist/_ldo/{profile.context.mjs → profile.context.js} +1 -1
- package/dist/_ldo/profile.context.js.map +1 -0
- package/dist/_ldo/{profile.schema.mjs → profile.schema.js} +1 -1
- package/dist/_ldo/profile.schema.js.map +1 -0
- package/dist/_ldo/{profile.shapeTypes.mjs → profile.shapeTypes.js} +3 -3
- package/dist/_ldo/profile.shapeTypes.js.map +1 -0
- package/dist/_ldo/{profile.typings.d.cts → profile.typings.d.ts} +1 -1
- package/dist/_ldo/profile.typings.d.ts.map +1 -0
- package/dist/_ldo/{typeIndex.context.mjs → typeIndex.context.js} +1 -1
- package/dist/_ldo/typeIndex.context.js.map +1 -0
- package/dist/_ldo/{typeIndex.schema.mjs → typeIndex.schema.js} +1 -1
- package/dist/_ldo/typeIndex.schema.js.map +1 -0
- package/dist/_ldo/{typeIndex.shapeTypes.mjs → typeIndex.shapeTypes.js} +3 -3
- package/dist/_ldo/typeIndex.shapeTypes.js.map +1 -0
- package/dist/_ldo/{typeIndex.typings.d.cts → typeIndex.typings.d.ts} +1 -1
- package/dist/_ldo/typeIndex.typings.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/{getTypeIndex.d.cts → getTypeIndex.d.ts} +5 -5
- package/dist/getTypeIndex.d.ts.map +1 -0
- package/dist/{getTypeIndex.mjs → getTypeIndex.js} +5 -5
- package/dist/getTypeIndex.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +4 -4
- package/dist/{index.mjs → index.js} +4 -4
- package/dist/react/{useInstanceUris.d.mts → useInstanceUris.d.ts} +1 -1
- package/dist/react/useInstanceUris.d.ts.map +1 -0
- package/dist/react/{useInstanceUris.mjs → useInstanceUris.js} +6 -6
- package/dist/react/useInstanceUris.js.map +1 -0
- package/dist/react/{useTypeIndexProfile.d.cts → useTypeIndexProfile.d.ts} +2 -2
- package/dist/react/useTypeIndexProfile.d.ts.map +1 -0
- package/dist/react/{useTypeIndexProfile.mjs → useTypeIndexProfile.js} +2 -2
- package/dist/react/useTypeIndexProfile.js.map +1 -0
- package/dist/react/util/{useSubscribeToUris.mjs → useSubscribeToUris.js} +1 -1
- package/dist/react/util/useSubscribeToUris.js.map +1 -0
- package/dist/{setTypeIndex.d.mts → setTypeIndex.d.ts} +3 -3
- package/dist/setTypeIndex.d.ts.map +1 -0
- package/dist/{setTypeIndex.mjs → setTypeIndex.js} +6 -6
- package/dist/setTypeIndex.js.map +1 -0
- package/dist/util/{Options.d.mts → Options.d.ts} +1 -1
- package/dist/util/Options.d.ts.map +1 -0
- package/dist/util/{Options.mjs → Options.js} +1 -1
- package/dist/util/Options.js.map +1 -0
- package/package.json +15 -19
- package/dist/_ldo/profile.context.cjs +0 -20
- package/dist/_ldo/profile.context.mjs.map +0 -1
- package/dist/_ldo/profile.schema.cjs +0 -50
- package/dist/_ldo/profile.schema.mjs.map +0 -1
- package/dist/_ldo/profile.shapeTypes.cjs +0 -18
- package/dist/_ldo/profile.shapeTypes.mjs.map +0 -1
- package/dist/_ldo/profile.typings.d.cts.map +0 -1
- package/dist/_ldo/profile.typings.d.mts +0 -30
- package/dist/_ldo/profile.typings.d.mts.map +0 -1
- package/dist/_ldo/typeIndex.context.cjs +0 -53
- package/dist/_ldo/typeIndex.context.mjs.map +0 -1
- package/dist/_ldo/typeIndex.schema.cjs +0 -115
- package/dist/_ldo/typeIndex.schema.mjs.map +0 -1
- package/dist/_ldo/typeIndex.shapeTypes.cjs +0 -27
- package/dist/_ldo/typeIndex.shapeTypes.mjs.map +0 -1
- package/dist/_ldo/typeIndex.typings.d.cts.map +0 -1
- package/dist/_ldo/typeIndex.typings.d.mts +0 -37
- package/dist/_ldo/typeIndex.typings.d.mts.map +0 -1
- package/dist/constants.cjs +0 -8
- package/dist/constants.mjs.map +0 -1
- package/dist/getTypeIndex.cjs +0 -52
- package/dist/getTypeIndex.d.cts.map +0 -1
- package/dist/getTypeIndex.d.mts +0 -14
- package/dist/getTypeIndex.d.mts.map +0 -1
- package/dist/getTypeIndex.mjs.map +0 -1
- package/dist/index.cjs +0 -16
- package/dist/index.d.mts +0 -5
- package/dist/react/useInstanceUris.cjs +0 -27
- package/dist/react/useInstanceUris.d.cts +0 -13
- package/dist/react/useInstanceUris.d.cts.map +0 -1
- package/dist/react/useInstanceUris.d.mts.map +0 -1
- package/dist/react/useInstanceUris.mjs.map +0 -1
- package/dist/react/useTypeIndexProfile.cjs +0 -10
- package/dist/react/useTypeIndexProfile.d.cts.map +0 -1
- package/dist/react/useTypeIndexProfile.d.mts +0 -7
- package/dist/react/useTypeIndexProfile.d.mts.map +0 -1
- package/dist/react/useTypeIndexProfile.mjs.map +0 -1
- package/dist/react/util/useSubscribeToUris.cjs +0 -24
- package/dist/react/util/useSubscribeToUris.mjs.map +0 -1
- package/dist/setTypeIndex.cjs +0 -125
- package/dist/setTypeIndex.d.cts +0 -56
- package/dist/setTypeIndex.d.cts.map +0 -1
- package/dist/setTypeIndex.d.mts.map +0 -1
- package/dist/setTypeIndex.mjs.map +0 -1
- package/dist/util/Options.cjs +0 -13
- package/dist/util/Options.d.cts +0 -11
- package/dist/util/Options.d.cts.map +0 -1
- package/dist/util/Options.d.mts.map +0 -1
- package/dist/util/Options.mjs.map +0 -1
package/dist/setTypeIndex.cjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
const require_profile_shapeTypes = require("./_ldo/profile.shapeTypes.cjs");
|
|
2
|
-
const require_typeIndex_shapeTypes = require("./_ldo/typeIndex.shapeTypes.cjs");
|
|
3
|
-
const require_constants = require("./constants.cjs");
|
|
4
|
-
const require_Options = require("./util/Options.cjs");
|
|
5
|
-
const require_getTypeIndex = require("./getTypeIndex.cjs");
|
|
6
|
-
let uuid = require("uuid");
|
|
7
|
-
let _ldo_rdf_utils = require("@ldo/rdf-utils");
|
|
8
|
-
let _ldo_ldo = require("@ldo/ldo");
|
|
9
|
-
//#region src/setTypeIndex.ts
|
|
10
|
-
/**
|
|
11
|
-
* =============================================================================
|
|
12
|
-
* INITIALIZERS
|
|
13
|
-
* =============================================================================
|
|
14
|
-
*/
|
|
15
|
-
async function initTypeIndex(webId, options) {
|
|
16
|
-
const { dataset } = require_Options.guaranteeOptions(options);
|
|
17
|
-
const profile = await require_getTypeIndex.getProfile(webId, options);
|
|
18
|
-
if (!profile.privateTypeIndex?.size || !profile.publicTypeIndex?.size) {
|
|
19
|
-
const profileFolder = await dataset.getResource(webId).getParentContainer();
|
|
20
|
-
if (profileFolder?.isError) throw profileFolder;
|
|
21
|
-
if (!profileFolder) throw new Error("No folder to save the type indexes to.");
|
|
22
|
-
if (!profile.privateTypeIndex?.size) await createIndex(webId, profileFolder, dataset, true);
|
|
23
|
-
if (!profile.publicTypeIndex?.size) await createIndex(webId, profileFolder, dataset, false);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
* @param webId
|
|
29
|
-
* @param profileFolder
|
|
30
|
-
* @param dataset
|
|
31
|
-
*/
|
|
32
|
-
async function createIndex(webId, profileFolder, dataset, isPrivate) {
|
|
33
|
-
const createResult = await profileFolder.createChildAndOverwrite(`${isPrivate ? "private" : "public"}_index_${(0, uuid.v4)()}`);
|
|
34
|
-
if (createResult.isError) throw createResult;
|
|
35
|
-
const indexResource = createResult.resource;
|
|
36
|
-
const wacResult = await indexResource.setWac({
|
|
37
|
-
agent: { [webId]: {
|
|
38
|
-
read: true,
|
|
39
|
-
write: true,
|
|
40
|
-
append: true,
|
|
41
|
-
control: true
|
|
42
|
-
} },
|
|
43
|
-
public: {
|
|
44
|
-
read: isPrivate ? false : true,
|
|
45
|
-
write: true,
|
|
46
|
-
append: true,
|
|
47
|
-
control: true
|
|
48
|
-
},
|
|
49
|
-
authenticated: {
|
|
50
|
-
read: isPrivate ? false : true,
|
|
51
|
-
write: true,
|
|
52
|
-
append: true,
|
|
53
|
-
control: true
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
if (wacResult.isError) throw wacResult;
|
|
57
|
-
const transaction = dataset.startTransaction();
|
|
58
|
-
const cProfile = transaction.usingType(require_profile_shapeTypes.TypeIndexProfileShapeType).write(dataset.getResource(webId).uri).fromSubject(webId);
|
|
59
|
-
if (isPrivate) cProfile.privateTypeIndex?.add({ "@id": indexResource.uri });
|
|
60
|
-
else cProfile.publicTypeIndex?.add({ "@id": indexResource.uri });
|
|
61
|
-
const cTypeIndex = transaction.usingType(require_typeIndex_shapeTypes.TypeIndexDocumentShapeType).write(indexResource.uri).fromSubject(indexResource.uri);
|
|
62
|
-
cTypeIndex.type = (0, _ldo_ldo.set)({ "@id": "ListedDocument" }, { "@id": "TypeIndex" });
|
|
63
|
-
const commitResult = await transaction.commitToRemote();
|
|
64
|
-
if (commitResult.isError) throw commitResult;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Adds an instance to a TypeRegistration
|
|
68
|
-
* @param indexUri The URI of the TypeIndex
|
|
69
|
-
* @param classUri The URI for the class the instance should be added to
|
|
70
|
-
* @param instances Objects representing the instances to add
|
|
71
|
-
* @param options Options
|
|
72
|
-
*/
|
|
73
|
-
function addRegistration(indexUri, classUri, instances, options) {
|
|
74
|
-
const typeRegistration = findAppropriateTypeRegistration(indexUri, classUri, options);
|
|
75
|
-
instances.instance?.forEach((instance) => {
|
|
76
|
-
typeRegistration.instance?.add({ "@id": instance });
|
|
77
|
-
});
|
|
78
|
-
instances.instanceContainer?.forEach((instanceContainer) => {
|
|
79
|
-
typeRegistration.instanceContainer?.add({ "@id": instanceContainer });
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Removes instances from a TypeRegistration
|
|
84
|
-
* @param indexUri The URI of the TypeIndex
|
|
85
|
-
* @param classUri The URI for the class the instance should be removed from
|
|
86
|
-
* @param instances Objects representing the instances to remove
|
|
87
|
-
* @param options Options
|
|
88
|
-
*/
|
|
89
|
-
async function removeRegistration(indexUri, classUri, instances, options) {
|
|
90
|
-
const typeRegistration = findAppropriateTypeRegistration(indexUri, classUri, options);
|
|
91
|
-
instances.instance?.forEach((instanceUri) => {
|
|
92
|
-
typeRegistration.instance?.delete({ "@id": instanceUri });
|
|
93
|
-
});
|
|
94
|
-
instances.instanceContainer?.forEach((instanceContainerUri) => {
|
|
95
|
-
typeRegistration.instanceContainer?.delete({ "@id": instanceContainerUri });
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Finds a TypeRegistration inside of a type index. If it doesn't exist, it
|
|
100
|
-
* creates one.
|
|
101
|
-
* @param indexUri The URI of the typeIndex
|
|
102
|
-
* @param classUri The URI of the class in question for the TypeRegistration
|
|
103
|
-
* @param options
|
|
104
|
-
* @returns The Type Index
|
|
105
|
-
*/
|
|
106
|
-
function findAppropriateTypeRegistration(indexUri, classUri, options) {
|
|
107
|
-
const { dataset } = require_Options.guaranteeOptions(options);
|
|
108
|
-
const existingRegistrationForClassUri = dataset.match(null, (0, _ldo_rdf_utils.namedNode)(require_constants.RDF_TYPE), (0, _ldo_rdf_utils.namedNode)(require_constants.TYPE_REGISTRATION), (0, _ldo_rdf_utils.namedNode)(indexUri)).toArray().map((quad) => quad.subject).find((registrationUri) => {
|
|
109
|
-
return dataset.has((0, _ldo_rdf_utils.quad)(registrationUri, (0, _ldo_rdf_utils.namedNode)(require_constants.FOR_CLASS), (0, _ldo_rdf_utils.namedNode)(classUri), (0, _ldo_rdf_utils.namedNode)(indexUri)));
|
|
110
|
-
})?.value;
|
|
111
|
-
let typeRegistration;
|
|
112
|
-
if (existingRegistrationForClassUri) typeRegistration = dataset.usingType(require_typeIndex_shapeTypes.TypeRegistrationShapeType).write(indexUri).fromSubject(existingRegistrationForClassUri);
|
|
113
|
-
else {
|
|
114
|
-
typeRegistration = dataset.usingType(require_typeIndex_shapeTypes.TypeRegistrationShapeType).write(indexUri).fromSubject(`${indexUri}#${(0, uuid.v4)()}`);
|
|
115
|
-
typeRegistration.type = { "@id": "TypeRegistration" };
|
|
116
|
-
typeRegistration.forClass = { "@id": classUri };
|
|
117
|
-
}
|
|
118
|
-
return typeRegistration;
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
exports.addRegistration = addRegistration;
|
|
122
|
-
exports.createIndex = createIndex;
|
|
123
|
-
exports.findAppropriateTypeRegistration = findAppropriateTypeRegistration;
|
|
124
|
-
exports.initTypeIndex = initTypeIndex;
|
|
125
|
-
exports.removeRegistration = removeRegistration;
|
package/dist/setTypeIndex.d.cts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { TypeRegistration } from "./_ldo/typeIndex.typings.cjs";
|
|
2
|
-
import { Options } from "./util/Options.cjs";
|
|
3
|
-
import { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
4
|
-
import { SolidConnectedPlugin, SolidContainer } from "@ldo/connected-solid";
|
|
5
|
-
|
|
6
|
-
//#region src/setTypeIndex.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* =============================================================================
|
|
9
|
-
* INITIALIZERS
|
|
10
|
-
* =============================================================================
|
|
11
|
-
*/
|
|
12
|
-
declare function initTypeIndex(webId: string, options?: Options): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
* @param webId
|
|
16
|
-
* @param profileFolder
|
|
17
|
-
* @param dataset
|
|
18
|
-
*/
|
|
19
|
-
declare function createIndex(webId: any, profileFolder: SolidContainer, dataset: ConnectedLdoDataset<(SolidConnectedPlugin | ConnectedPlugin<any, any, any, any>)[]>, isPrivate: boolean): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* =============================================================================
|
|
22
|
-
* DATASET MODIFIERS
|
|
23
|
-
* =============================================================================
|
|
24
|
-
*/
|
|
25
|
-
interface Instances {
|
|
26
|
-
instance?: string[];
|
|
27
|
-
instanceContainer?: string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Adds an instance to a TypeRegistration
|
|
31
|
-
* @param indexUri The URI of the TypeIndex
|
|
32
|
-
* @param classUri The URI for the class the instance should be added to
|
|
33
|
-
* @param instances Objects representing the instances to add
|
|
34
|
-
* @param options Options
|
|
35
|
-
*/
|
|
36
|
-
declare function addRegistration(indexUri: string, classUri: string, instances: Instances, options?: Options): void;
|
|
37
|
-
/**
|
|
38
|
-
* Removes instances from a TypeRegistration
|
|
39
|
-
* @param indexUri The URI of the TypeIndex
|
|
40
|
-
* @param classUri The URI for the class the instance should be removed from
|
|
41
|
-
* @param instances Objects representing the instances to remove
|
|
42
|
-
* @param options Options
|
|
43
|
-
*/
|
|
44
|
-
declare function removeRegistration(indexUri: string, classUri: string, instances: Instances, options?: Options): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Finds a TypeRegistration inside of a type index. If it doesn't exist, it
|
|
47
|
-
* creates one.
|
|
48
|
-
* @param indexUri The URI of the typeIndex
|
|
49
|
-
* @param classUri The URI of the class in question for the TypeRegistration
|
|
50
|
-
* @param options
|
|
51
|
-
* @returns The Type Index
|
|
52
|
-
*/
|
|
53
|
-
declare function findAppropriateTypeRegistration(indexUri: string, classUri: string, options?: Options): TypeRegistration;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { addRegistration, createIndex, findAppropriateTypeRegistration, initTypeIndex, removeRegistration };
|
|
56
|
-
//# sourceMappingURL=setTypeIndex.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTypeIndex.d.cts","names":[],"sources":["../src/setTypeIndex.ts"],"mappings":";;;;;;;;AA2BA;;;iBAAsB,aAAA,CACpB,KAAA,UACA,OAAA,GAAU,OAAA,GACT,OAAA;;;;;;;iBAyBmB,WAAA,CACpB,KAAA,OACA,aAAA,EAAe,cAAA,EACf,OAAA,EAAS,mBAAA,EACN,oBAAA,GAAuB,eAAA,0BAE1B,SAAA,YAAkB,OAAA;;;;;;UAmDV,SAAA;EACR,QAAA;EACA,iBAAA;AAAA;;;;;;;;iBAUc,eAAA,CACd,QAAA,UACA,QAAA,UACA,SAAA,EAAW,SAAA,EACX,OAAA,GAAU,OAAA;;;;AAvBX;;;;iBAgDqB,kBAAA,CACpB,QAAA,UACA,QAAA,UACA,SAAA,EAAW,SAAA,EACX,OAAA,GAAU,OAAA,GAAO,OAAA;AAjCnB;;;;;;;;AAAA,iBA2DgB,+BAAA,CACd,QAAA,UACA,QAAA,UACA,OAAA,GAAU,OAAA,GACT,gBAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTypeIndex.d.mts","names":[],"sources":["../src/setTypeIndex.ts"],"mappings":";;;;;;;;AA2BA;;;iBAAsB,aAAA,CACpB,KAAA,UACA,OAAA,GAAU,OAAA,GACT,OAAA;;;;;;;iBAyBmB,WAAA,CACpB,KAAA,OACA,aAAA,EAAe,cAAA,EACf,OAAA,EAAS,mBAAA,EACN,oBAAA,GAAuB,eAAA,0BAE1B,SAAA,YAAkB,OAAA;;;;;;UAmDV,SAAA;EACR,QAAA;EACA,iBAAA;AAAA;;;;;;;;iBAUc,eAAA,CACd,QAAA,UACA,QAAA,UACA,SAAA,EAAW,SAAA,EACX,OAAA,GAAU,OAAA;;;;AAvBX;;;;iBAgDqB,kBAAA,CACpB,QAAA,UACA,QAAA,UACA,SAAA,EAAW,SAAA,EACX,OAAA,GAAU,OAAA,GAAO,OAAA;AAjCnB;;;;;;;;AAAA,iBA2DgB,+BAAA,CACd,QAAA,UACA,QAAA,UACA,OAAA,GAAU,OAAA,GACT,gBAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTypeIndex.mjs","names":[],"sources":["../src/setTypeIndex.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { v4 } from \"uuid\";\nimport { FOR_CLASS, RDF_TYPE, TYPE_REGISTRATION } from \"./constants\";\nimport { guaranteeOptions, type Options } from \"./util/Options\";\nimport { namedNode, quad } from \"@ldo/rdf-utils\";\nimport type { TypeRegistration } from \"./_ldo/typeIndex.typings\";\nimport { getProfile } from \"./getTypeIndex\";\nimport { TypeIndexProfileShapeType } from \"./_ldo/profile.shapeTypes\";\nimport type { NamedNode } from \"@rdfjs/types\";\nimport { set } from \"@ldo/ldo\";\nimport type {\n SolidConnectedPlugin,\n SolidContainer,\n SolidContainerUri,\n SolidLeafUri,\n} from \"@ldo/connected-solid\";\nimport type { ConnectedLdoDataset, ConnectedPlugin } from \"@ldo/connected\";\nimport {\n TypeIndexDocumentShapeType,\n TypeRegistrationShapeType,\n} from \"./_ldo/typeIndex.shapeTypes\";\n\n/**\n * =============================================================================\n * INITIALIZERS\n * =============================================================================\n */\nexport async function initTypeIndex(\n webId: string,\n options?: Options,\n): Promise<void> {\n const { dataset } = guaranteeOptions(options);\n const profile = await getProfile(webId, options);\n if (!profile.privateTypeIndex?.size || !profile.publicTypeIndex?.size) {\n const profileFolder = await dataset\n .getResource(webId as SolidLeafUri | SolidContainerUri)\n .getParentContainer();\n if (profileFolder?.isError) throw profileFolder;\n if (!profileFolder)\n throw new Error(\"No folder to save the type indexes to.\");\n if (!profile.privateTypeIndex?.size) {\n await createIndex(webId, profileFolder, dataset, true);\n }\n if (!profile.publicTypeIndex?.size) {\n await createIndex(webId, profileFolder, dataset, false);\n }\n }\n}\n\n/**\n * @internal\n * @param webId\n * @param profileFolder\n * @param dataset\n */\nexport async function createIndex(\n webId,\n profileFolder: SolidContainer,\n dataset: ConnectedLdoDataset<\n (SolidConnectedPlugin | ConnectedPlugin<any, any, any, any>)[]\n >,\n isPrivate: boolean,\n) {\n // Create a private type index\n const createResult = await profileFolder.createChildAndOverwrite(\n `${isPrivate ? \"private\" : \"public\"}_index_${v4()}`,\n );\n if (createResult.isError) throw createResult;\n const indexResource = createResult.resource;\n const wacResult = await indexResource.setWac({\n agent: {\n [webId]: { read: true, write: true, append: true, control: true },\n },\n public: {\n read: isPrivate ? false : true,\n write: true,\n append: true,\n control: true,\n },\n authenticated: {\n read: isPrivate ? false : true,\n write: true,\n append: true,\n control: true,\n },\n });\n if (wacResult.isError) throw wacResult;\n const transaction = dataset.startTransaction();\n const cProfile = transaction\n .usingType(TypeIndexProfileShapeType)\n .write(dataset.getResource(webId).uri)\n .fromSubject(webId);\n if (isPrivate) {\n cProfile.privateTypeIndex?.add({ \"@id\": indexResource.uri });\n } else {\n cProfile.publicTypeIndex?.add({ \"@id\": indexResource.uri });\n }\n const cTypeIndex = transaction\n .usingType(TypeIndexDocumentShapeType)\n .write(indexResource.uri)\n .fromSubject(indexResource.uri);\n\n cTypeIndex.type = set({ \"@id\": \"ListedDocument\" }, { \"@id\": \"TypeIndex\" });\n const commitResult = await transaction.commitToRemote();\n if (commitResult.isError) throw commitResult;\n}\n\n/**\n * =============================================================================\n * DATASET MODIFIERS\n * =============================================================================\n */\ninterface Instances {\n instance?: string[];\n instanceContainer?: string[];\n}\n\n/**\n * Adds an instance to a TypeRegistration\n * @param indexUri The URI of the TypeIndex\n * @param classUri The URI for the class the instance should be added to\n * @param instances Objects representing the instances to add\n * @param options Options\n */\nexport function addRegistration(\n indexUri: string,\n classUri: string,\n instances: Instances,\n options?: Options,\n): void {\n // Check to see if its already in the index\n const typeRegistration = findAppropriateTypeRegistration(\n indexUri,\n classUri,\n options,\n );\n\n // Add instances to type registration\n instances.instance?.forEach((instance) => {\n typeRegistration.instance?.add({ \"@id\": instance });\n });\n instances.instanceContainer?.forEach((instanceContainer) => {\n typeRegistration.instanceContainer?.add({ \"@id\": instanceContainer });\n });\n}\n\n/**\n * Removes instances from a TypeRegistration\n * @param indexUri The URI of the TypeIndex\n * @param classUri The URI for the class the instance should be removed from\n * @param instances Objects representing the instances to remove\n * @param options Options\n */\nexport async function removeRegistration(\n indexUri: string,\n classUri: string,\n instances: Instances,\n options?: Options,\n) {\n // Check to see if its already in the index\n const typeRegistration = findAppropriateTypeRegistration(\n indexUri,\n classUri,\n options,\n );\n\n // Add instances to type registration\n instances.instance?.forEach((instanceUri) => {\n typeRegistration.instance?.delete({ \"@id\": instanceUri });\n });\n instances.instanceContainer?.forEach((instanceContainerUri) => {\n typeRegistration.instanceContainer?.delete({ \"@id\": instanceContainerUri });\n });\n}\n\n/**\n * Finds a TypeRegistration inside of a type index. If it doesn't exist, it\n * creates one.\n * @param indexUri The URI of the typeIndex\n * @param classUri The URI of the class in question for the TypeRegistration\n * @param options\n * @returns The Type Index\n */\nexport function findAppropriateTypeRegistration(\n indexUri: string,\n classUri: string,\n options?: Options,\n): TypeRegistration {\n const { dataset } = guaranteeOptions(options);\n // Check to see if its already in the index\n const existingRegistrationsUris: NamedNode[] = dataset\n .match(\n null,\n namedNode(RDF_TYPE),\n namedNode(TYPE_REGISTRATION),\n namedNode(indexUri),\n )\n .toArray()\n .map((quad) => quad.subject) as NamedNode[];\n\n const existingRegistrationForClassUri = existingRegistrationsUris.find(\n (registrationUri) => {\n return dataset.has(\n quad(\n registrationUri,\n namedNode(FOR_CLASS),\n namedNode(classUri),\n namedNode(indexUri),\n ),\n );\n },\n )?.value;\n\n let typeRegistration: TypeRegistration;\n if (existingRegistrationForClassUri) {\n typeRegistration = dataset\n .usingType(TypeRegistrationShapeType)\n .write(indexUri)\n .fromSubject(existingRegistrationForClassUri);\n } else {\n typeRegistration = dataset\n .usingType(TypeRegistrationShapeType)\n .write(indexUri)\n .fromSubject(`${indexUri}#${v4()}`);\n typeRegistration.type = { \"@id\": \"TypeRegistration\" };\n typeRegistration.forClass = { \"@id\": classUri };\n }\n return typeRegistration;\n}\n"],"mappings":";;;;;;;;;;;;;;AA2BA,eAAsB,cACpB,OACA,SACe;CACf,MAAM,EAAE,YAAY,iBAAiB,QAAQ;CAC7C,MAAM,UAAU,MAAM,WAAW,OAAO,QAAQ;AAChD,KAAI,CAAC,QAAQ,kBAAkB,QAAQ,CAAC,QAAQ,iBAAiB,MAAM;EACrE,MAAM,gBAAgB,MAAM,QACzB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dist/util/Options.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
let _ldo_connected_solid = require("@ldo/connected-solid");
|
|
2
|
-
//#region src/util/Options.ts
|
|
3
|
-
function guaranteeOptions(options) {
|
|
4
|
-
const fetch = (0, _ldo_connected_solid.guaranteeFetch)(options?.fetch);
|
|
5
|
-
const dataset = options?.solidLdoDataset ?? (0, _ldo_connected_solid.createSolidLdoDataset)();
|
|
6
|
-
dataset.setContext("solid", { fetch });
|
|
7
|
-
return {
|
|
8
|
-
fetch,
|
|
9
|
-
dataset
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
exports.guaranteeOptions = guaranteeOptions;
|
package/dist/util/Options.d.cts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ConnectedLdoDataset, IConnectedLdoDataset } from "@ldo/connected";
|
|
2
|
-
import { SolidConnectedPlugin } from "@ldo/connected-solid";
|
|
3
|
-
|
|
4
|
-
//#region src/util/Options.d.ts
|
|
5
|
-
interface Options {
|
|
6
|
-
solidLdoDataset?: IConnectedLdoDataset<SolidConnectedPlugin[]>;
|
|
7
|
-
fetch?: typeof fetch;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { Options };
|
|
11
|
-
//# sourceMappingURL=Options.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Options.d.cts","names":[],"sources":["../../src/util/Options.ts"],"mappings":";;;;UAKiB,OAAA;EACf,eAAA,GAAkB,oBAAA,CAAqB,oBAAA;EACvC,KAAA,UAAe,KAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Options.d.mts","names":[],"sources":["../../src/util/Options.ts"],"mappings":";;;;UAKiB,OAAA;EACf,eAAA,GAAkB,oBAAA,CAAqB,oBAAA;EACvC,KAAA,UAAe,KAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Options.mjs","names":[],"sources":["../../src/util/Options.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { ConnectedLdoDataset, IConnectedLdoDataset } from \"@ldo/connected\";\nimport type { SolidConnectedPlugin } from \"@ldo/connected-solid\";\nimport { createSolidLdoDataset, guaranteeFetch } from \"@ldo/connected-solid\";\n\nexport interface Options {\n solidLdoDataset?: IConnectedLdoDataset<SolidConnectedPlugin[]>;\n fetch?: typeof fetch;\n}\n\nexport function guaranteeOptions(options?: Options) {\n const fetch = guaranteeFetch(options?.fetch);\n const dataset = (options?.solidLdoDataset ??\n createSolidLdoDataset()) as ConnectedLdoDataset<SolidConnectedPlugin[]>;\n dataset.setContext(\"solid\", { fetch });\n return { fetch, dataset };\n}\n"],"mappings":";;AAUA,SAAgB,iBAAiB,SAAmB;CAClD,MAAM,QAAQ,eAAe,SAAS,MAAM;CAC5C,MAAM,UAAW,SAAS,mBACxB,uBAAuB;AACzB,SAAQ,WAAW,SAAS,EAAE,OAAO,CAAC;AACtC,QAAO;EAAE;EAAO;EAAS"}
|