@pod-os/core 0.22.1-rc.f2eaee2.0 → 0.23.1-rc.11e4e07.0

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/dist/index.js CHANGED
@@ -4492,11 +4492,11 @@ var FileFetcher = class {
4492
4492
  }
4493
4493
  };
4494
4494
 
4495
- // src/modules/contacts.ts
4496
- async function loadContactsModule(store) {
4497
- const module2 = await import("./dist-O5YU2L4C.js");
4498
- return store.loadModule(module2);
4499
- }
4495
+ // src/namespaces/index.ts
4496
+ var rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#");
4497
+ var pim = Namespace("http://www.w3.org/ns/pim/space#");
4498
+ var schema = Namespace("https://schema.org/");
4499
+ var flow = Namespace("http://www.w3.org/2005/01/wf/flow#");
4500
4500
 
4501
4501
  // src/thing/accumulateSubjects.ts
4502
4502
  var accumulateSubjects = (accumulator, current3) => {
@@ -4720,6 +4720,19 @@ var Thing = class {
4720
4720
  label: labelForType(uri6)
4721
4721
  }));
4722
4722
  }
4723
+ /**
4724
+ * Returns all attachments linked to this thing
4725
+ */
4726
+ attachments() {
4727
+ const statements = this.store.statementsMatching(
4728
+ namedNode(this.uri),
4729
+ flow("attachment")
4730
+ );
4731
+ return statements.filter((it) => isNamedNode(it.object)).map((statement2) => ({
4732
+ uri: statement2.object.value,
4733
+ label: labelFromUri(statement2.object.value)
4734
+ }));
4735
+ }
4723
4736
  /**
4724
4737
  * Call this method to switch to a more specific subclass of Thing.
4725
4738
  *
@@ -4762,16 +4775,15 @@ var LdpContainer = class extends Thing {
4762
4775
  }
4763
4776
  };
4764
4777
 
4765
- // src/picture/createPictureLinkOperation.ts
4766
- var SCHEMA_IMAGE = "http://schema.org/image";
4767
- function createPictureLinkOperation(thing, file2) {
4778
+ // src/files/createFileLinkOperation.ts
4779
+ function createFileLinkOperation(thing, predicateUri, file2) {
4768
4780
  return {
4769
4781
  deletions: [],
4770
4782
  filesToCreate: [],
4771
4783
  insertions: [
4772
4784
  st(
4773
4785
  namedNode(thing.uri),
4774
- namedNode(SCHEMA_IMAGE),
4786
+ namedNode(predicateUri),
4775
4787
  namedNode(file2.url),
4776
4788
  namedNode(thing.uri).doc()
4777
4789
  )
@@ -4779,32 +4791,33 @@ function createPictureLinkOperation(thing, file2) {
4779
4791
  };
4780
4792
  }
4781
4793
 
4782
- // src/picture/PictureGateway.ts
4783
- var PictureGateway = class {
4794
+ // src/files/FileGateway.ts
4795
+ var FileGateway = class {
4784
4796
  constructor(store, fileFetcher) {
4785
4797
  this.store = store;
4786
4798
  this.fileFetcher = fileFetcher;
4787
4799
  }
4788
4800
  /**
4789
- * Uploads a picture file and associates it with a thing.
4801
+ * Uploads a file and associates it with a thing.
4790
4802
  * The container is automatically derived from the thing's URI.
4791
4803
  * Uses schema:image as the predicate.
4792
4804
  *
4793
- * @param thing - The thing to add the picture to
4794
- * @param pictureFile - The picture file to upload
4795
- * @returns Result with the uploaded picture metadata (url, name, contentType) or error
4805
+ * @param thing - The thing to add the file to
4806
+ * @param predicateUri - The URI of the predicate to use
4807
+ * @param fileToUpload - The file to upload
4808
+ * @returns Result with the uploaded metadata (url, name, contentType) or error
4796
4809
  */
4797
- uploadAndAddPicture(thing, pictureFile) {
4810
+ uploadAndLinkFile(thing, predicateUri, fileToUpload) {
4798
4811
  const container2 = this.getContainerFromThing(thing);
4799
- return this.fileFetcher.createNewFile(container2, pictureFile).andThen((file2) => this.linkPictureToThing(thing, file2));
4812
+ return this.fileFetcher.createNewFile(container2, fileToUpload).andThen((file2) => this.linkFileToThing(thing, predicateUri, file2));
4800
4813
  }
4801
- linkPictureToThing(thing, file2) {
4802
- const operation3 = createPictureLinkOperation(thing, file2);
4814
+ linkFileToThing(thing, predicateUri, file2) {
4815
+ const operation3 = createFileLinkOperation(thing, predicateUri, file2);
4803
4816
  return ResultAsync.fromPromise(
4804
4817
  this.store.executeUpdate(operation3).then(() => file2),
4805
4818
  () => ({
4806
4819
  type: "network",
4807
- title: "Failed to link picture to thing"
4820
+ title: "Failed to link file to thing"
4808
4821
  })
4809
4822
  );
4810
4823
  }
@@ -4813,6 +4826,129 @@ var PictureGateway = class {
4813
4826
  }
4814
4827
  };
4815
4828
 
4829
+ // src/modules/contacts.ts
4830
+ async function loadContactsModule(store) {
4831
+ const module2 = await import("./dist-O5YU2L4C.js");
4832
+ return store.loadModule(module2);
4833
+ }
4834
+
4835
+ // src/attachments/AttachmentGateway.ts
4836
+ var AttachmentGateway = class {
4837
+ constructor(fileGateway) {
4838
+ this.fileGateway = fileGateway;
4839
+ }
4840
+ /**
4841
+ * Uploads an attachment file and associates it with a thing.
4842
+ * The container is automatically derived from the thing's URI.
4843
+ * Uses flow:attachment as the predicate.
4844
+ *
4845
+ * @param thing - The thing to add the attachment to
4846
+ * @param attachmentFile - The attachment file to upload
4847
+ * @returns Result with the uploaded attachment metadata (url, name, contentType) or error
4848
+ */
4849
+ uploadAndAddAttachment(thing, attachmentFile) {
4850
+ return this.fileGateway.uploadAndLinkFile(
4851
+ thing,
4852
+ "http://www.w3.org/2005/01/wf/flow#attachment",
4853
+ attachmentFile
4854
+ );
4855
+ }
4856
+ };
4857
+
4858
+ // src/picture/PictureGateway.ts
4859
+ var PictureGateway = class {
4860
+ constructor(attachmentGateway) {
4861
+ this.attachmentGateway = attachmentGateway;
4862
+ }
4863
+ /**
4864
+ * Uploads a picture file and associates it with a thing.
4865
+ * The container is automatically derived from the thing's URI.
4866
+ * Uses schema:image as the predicate.
4867
+ *
4868
+ * @param thing - The thing to add the picture to
4869
+ * @param pictureFile - The picture file to upload
4870
+ * @returns Result with the uploaded picture metadata (url, name, contentType) or error
4871
+ */
4872
+ uploadAndAddPicture(thing, pictureFile) {
4873
+ return this.attachmentGateway.uploadAndLinkFile(
4874
+ thing,
4875
+ "http://schema.org/image",
4876
+ pictureFile
4877
+ );
4878
+ }
4879
+ };
4880
+
4881
+ // node_modules/@solid-data-modules/rdflib-utils/dist/web-operations/executeUpdate.js
4882
+ async function executeUpdate(fetcher, updater, operation3) {
4883
+ await updater.updateMany(operation3.deletions, operation3.insertions);
4884
+ operation3.filesToCreate.map((file2) => {
4885
+ createEmptyTurtleFile(fetcher, file2.url);
4886
+ });
4887
+ }
4888
+ function createEmptyTurtleFile(fetcher, url7) {
4889
+ return fetcher.webOperation("PUT", url7, {
4890
+ contentType: "text/turtle"
4891
+ });
4892
+ }
4893
+
4894
+ // node_modules/@solid-data-modules/rdflib-utils/dist/namespaces/index.js
4895
+ var rdf = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
4896
+ var solid = Namespace("http://www.w3.org/ns/solid/terms#");
4897
+ var pim2 = Namespace("http://www.w3.org/ns/pim/space#");
4898
+ var ldp = Namespace("http://www.w3.org/ns/ldp#");
4899
+
4900
+ // node_modules/@solid-data-modules/rdflib-utils/dist/queries/PreferencesQuery.js
4901
+ var PreferencesQuery = class {
4902
+ constructor(store, webIdNode, preferencesDoc) {
4903
+ this.store = store;
4904
+ this.webIdNode = webIdNode;
4905
+ this.preferencesDoc = preferencesDoc;
4906
+ }
4907
+ /**
4908
+ * Look up the private type index. Returns null if none is found or if the predicated does not link to a proper named node
4909
+ */
4910
+ queryPrivateTypeIndex() {
4911
+ const node3 = this.store.any(this.webIdNode, solid("privateTypeIndex"), null, this.preferencesDoc);
4912
+ if (isNamedNode(node3)) {
4913
+ return node3;
4914
+ }
4915
+ return null;
4916
+ }
4917
+ };
4918
+
4919
+ // node_modules/@solid-data-modules/rdflib-utils/dist/queries/ProfileQuery.js
4920
+ var ProfileQuery = class {
4921
+ constructor(webIdNode, store) {
4922
+ this.webIdNode = webIdNode;
4923
+ this.store = store;
4924
+ }
4925
+ /**
4926
+ * Look up the public type index. Returns null if none is found or if the predicated does not link to a proper named node
4927
+ */
4928
+ queryPublicTypeIndex() {
4929
+ const predicate4 = solid("publicTypeIndex");
4930
+ return this.queryNamedNode(predicate4);
4931
+ }
4932
+ /**
4933
+ * Look up the preferences file. Returns null if none is found or if the predicated does not link to a proper named node
4934
+ */
4935
+ queryPreferencesFile() {
4936
+ const predicate4 = pim2("preferencesFile");
4937
+ return this.queryNamedNode(predicate4);
4938
+ }
4939
+ queryNamedNode(predicate4) {
4940
+ const node3 = this.store.any(this.webIdNode, predicate4, null, this.webIdNode.doc());
4941
+ if (isNamedNode(node3)) {
4942
+ return node3;
4943
+ }
4944
+ return null;
4945
+ }
4946
+ };
4947
+
4948
+ // node_modules/@solid-data-modules/rdflib-utils/dist/identifier/generate-id.js
4949
+ var import_short_unique_id = __toESM(require_short_unique_id(), 1);
4950
+ var uid = new import_short_unique_id.default({ length: 10 });
4951
+
4816
4952
  // src/profile/WebIdProfile.ts
4817
4953
  var WebIdProfile = class extends Thing {
4818
4954
  constructor(webId, store, editable = false) {
@@ -4820,17 +4956,32 @@ var WebIdProfile = class extends Thing {
4820
4956
  this.webId = webId;
4821
4957
  this.store = store;
4822
4958
  this.editable = editable;
4959
+ this.profileQuery = new ProfileQuery(namedNode(this.webId), this.store);
4823
4960
  }
4824
4961
  /**
4825
- * Returns te URI of the preferences document
4962
+ * Returns the URI of the preferences document
4826
4963
  */
4827
4964
  getPreferencesFile() {
4828
- return this.store.anyValue(
4965
+ return this.profileQuery.queryPreferencesFile()?.value;
4966
+ }
4967
+ /**
4968
+ * Returns the URI of the public type index document
4969
+ */
4970
+ getPublicTypeIndex() {
4971
+ return this.profileQuery.queryPublicTypeIndex()?.value;
4972
+ }
4973
+ /**
4974
+ * Returns the URI of the private type index document
4975
+ */
4976
+ getPrivateTypeIndex() {
4977
+ const preferences = this.profileQuery.queryPreferencesFile();
4978
+ if (!preferences) return void 0;
4979
+ const query4 = new PreferencesQuery(
4980
+ this.store,
4829
4981
  namedNode(this.webId),
4830
- namedNode("http://www.w3.org/ns/pim/space#preferencesFile"),
4831
- void 0,
4832
- namedNode(this.webId).doc()
4982
+ preferences
4833
4983
  );
4984
+ return query4.queryPrivateTypeIndex()?.value;
4834
4985
  }
4835
4986
  /**
4836
4987
  * Returns the URIs of the private label indexes
@@ -4857,6 +5008,27 @@ var WebIdProfile = class extends Thing {
4857
5008
  }
4858
5009
  };
4859
5010
 
5011
+ // src/profile/ProfileGateway.ts
5012
+ var ProfileGateway = class {
5013
+ constructor(store) {
5014
+ this.store = store;
5015
+ }
5016
+ async fetchProfile(webId) {
5017
+ await this.store.fetch(webId);
5018
+ const profile2 = this.store.get(webId).assume(WebIdProfile);
5019
+ const preferences = profile2.getPreferencesFile();
5020
+ if (preferences) {
5021
+ await this.store.fetch(preferences);
5022
+ }
5023
+ const publicTypeIndex2 = profile2.getPublicTypeIndex();
5024
+ const privateTypeIndex2 = profile2.getPrivateTypeIndex();
5025
+ await this.store.fetchAll(
5026
+ [privateTypeIndex2, publicTypeIndex2].filter((it) => it !== void 0)
5027
+ );
5028
+ return profile2;
5029
+ }
5030
+ };
5031
+
4860
5032
  // src/search/SearchIndex.ts
4861
5033
  var import_lunr = __toESM(require_lunr(), 1);
4862
5034
  var SearchIndex = class {
@@ -4936,10 +5108,6 @@ var RdfDocument = class extends Thing {
4936
5108
  }
4937
5109
  };
4938
5110
 
4939
- // src/namespaces/index.ts
4940
- var rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#");
4941
- var pim = Namespace("http://www.w3.org/ns/pim/space#");
4942
-
4943
5111
  // src/search/LabelIndex.ts
4944
5112
  var LabelIndex = class extends RdfDocument {
4945
5113
  constructor(uri6, store, editable = false) {
@@ -4970,29 +5138,6 @@ var LabelIndex = class extends RdfDocument {
4970
5138
  }
4971
5139
  };
4972
5140
 
4973
- // node_modules/@solid-data-modules/rdflib-utils/dist/web-operations/executeUpdate.js
4974
- async function executeUpdate(fetcher, updater, operation3) {
4975
- await updater.updateMany(operation3.deletions, operation3.insertions);
4976
- operation3.filesToCreate.map((file2) => {
4977
- createEmptyTurtleFile(fetcher, file2.url);
4978
- });
4979
- }
4980
- function createEmptyTurtleFile(fetcher, url7) {
4981
- return fetcher.webOperation("PUT", url7, {
4982
- contentType: "text/turtle"
4983
- });
4984
- }
4985
-
4986
- // node_modules/@solid-data-modules/rdflib-utils/dist/namespaces/index.js
4987
- var rdf = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
4988
- var solid = Namespace("http://www.w3.org/ns/solid/terms#");
4989
- var pim2 = Namespace("http://www.w3.org/ns/pim/space#");
4990
- var ldp = Namespace("http://www.w3.org/ns/ldp#");
4991
-
4992
- // node_modules/@solid-data-modules/rdflib-utils/dist/identifier/generate-id.js
4993
- var import_short_unique_id = __toESM(require_short_unique_id(), 1);
4994
- var uid = new import_short_unique_id.default({ length: 10 });
4995
-
4996
5141
  // src/search/createDefaultLabelIndex.ts
4997
5142
  function createDefaultLabelIndex(profile2) {
4998
5143
  const webId = namedNode(profile2.webId);
@@ -5302,7 +5447,7 @@ __export(index_es_exports, {
5302
5447
  rdf: () => rdf2,
5303
5448
  rdfs: () => rdfs2,
5304
5449
  sched: () => sched,
5305
- schema: () => schema,
5450
+ schema: () => schema2,
5306
5451
  schema_https: () => schema_https,
5307
5452
  sec: () => sec,
5308
5453
  shacl: () => shacl,
@@ -26556,7 +26701,7 @@ var trip3 = tripImport;
26556
26701
  var rdf2 = rdfImport;
26557
26702
  var rdfs2 = rdfsImport;
26558
26703
  var sched = schedImport;
26559
- var schema = schemaImport;
26704
+ var schema2 = schemaImport;
26560
26705
  var schema_https = schema_httpsImport;
26561
26706
  var sec = secImport;
26562
26707
  var shacl = shaclImport;
@@ -26628,6 +26773,52 @@ var AnonymousSession = class {
26628
26773
  }
26629
26774
  };
26630
26775
 
26776
+ // src/type-index/TypeIndex.ts
26777
+ var TypeIndex2 = class extends Thing {
26778
+ constructor(uri6, store, editable = false) {
26779
+ super(uri6, store, editable);
26780
+ this.uri = uri6;
26781
+ this.store = store;
26782
+ this.editable = editable;
26783
+ }
26784
+ listAll() {
26785
+ const forClassStatements = this.store.statementsMatching(
26786
+ null,
26787
+ solid("forClass"),
26788
+ null,
26789
+ namedNode(this.uri)
26790
+ );
26791
+ return forClassStatements.map((statement2) => {
26792
+ const subject8 = statement2.subject;
26793
+ const instanceContainerStatements = this.store.statementsMatching(
26794
+ subject8,
26795
+ solid("instanceContainer"),
26796
+ null,
26797
+ namedNode(this.uri)
26798
+ );
26799
+ const instanceStatements = this.store.statementsMatching(
26800
+ subject8,
26801
+ solid("instance"),
26802
+ null,
26803
+ namedNode(this.uri)
26804
+ );
26805
+ const instances2 = instanceStatements.map((it) => ({
26806
+ type: "instance",
26807
+ uri: it.object.value
26808
+ }));
26809
+ const instanceContainers = instanceContainerStatements.map((it) => ({
26810
+ type: "container",
26811
+ uri: it.object.value
26812
+ }));
26813
+ return {
26814
+ targets: [...instanceContainers, ...instances2],
26815
+ forClass: statement2.object.value,
26816
+ label: labelForType(statement2.object.value)
26817
+ };
26818
+ });
26819
+ }
26820
+ };
26821
+
26631
26822
  // src/index.ts
26632
26823
  var PodOS = class {
26633
26824
  constructor({
@@ -26646,9 +26837,12 @@ var PodOS = class {
26646
26837
  );
26647
26838
  this.searchGateway = new SearchGateway(this.store);
26648
26839
  this.fileFetcher = new FileFetcher(this.session);
26649
- this.pictureGateway = new PictureGateway(this.store, this.fileFetcher);
26840
+ this.fileGateway = new FileGateway(this.store, this.fileFetcher);
26841
+ this.attachmentGateway = new AttachmentGateway(this.fileGateway);
26842
+ this.pictureGateway = new PictureGateway(this.fileGateway);
26650
26843
  this.flagAuthorizationMetaDataOnSessionChange();
26651
26844
  this.uriService = new UriService(this.store);
26845
+ this.profileGateway = new ProfileGateway(this.store);
26652
26846
  }
26653
26847
  /*
26654
26848
  Flagging authorization metadata is necessary every time the user
@@ -26708,13 +26902,7 @@ var PodOS = class {
26708
26902
  * @param webId
26709
26903
  */
26710
26904
  async fetchProfile(webId) {
26711
- await this.fetch(webId);
26712
- const profile2 = this.store.get(webId).assume(WebIdProfile);
26713
- const preferences = profile2.getPreferencesFile();
26714
- if (preferences) {
26715
- await this.fetch(preferences);
26716
- }
26717
- return profile2;
26905
+ return this.profileGateway.fetchProfile(webId);
26718
26906
  }
26719
26907
  /**
26720
26908
  * Fetch the private label index for the given profile and build a search index from it
@@ -26761,13 +26949,22 @@ var PodOS = class {
26761
26949
  uploadAndAddPicture(thing, pictureFile) {
26762
26950
  return this.pictureGateway.uploadAndAddPicture(thing, pictureFile);
26763
26951
  }
26952
+ /**
26953
+ * Provides access to attachment operations such as uploading and linking attachments to things
26954
+ * @returns {AttachmentGateway} An instance of AttachmentGateway that handles attachment operations
26955
+ */
26956
+ attachments() {
26957
+ return this.attachmentGateway;
26958
+ }
26764
26959
  };
26765
26960
  export {
26766
26961
  AnonymousSession,
26767
26962
  AssumeAlwaysOnline,
26963
+ AttachmentGateway,
26768
26964
  BinaryFile,
26769
26965
  BrokenFile,
26770
26966
  FileFetcher,
26967
+ FileGateway,
26771
26968
  HttpStatus,
26772
26969
  LabelIndex,
26773
26970
  LdpContainer,
@@ -26775,14 +26972,15 @@ export {
26775
26972
  OfflineCapableFetcher,
26776
26973
  PictureGateway,
26777
26974
  PodOS,
26975
+ ProfileGateway,
26778
26976
  RdfDocument,
26779
26977
  SearchGateway,
26780
26978
  SearchIndex,
26781
26979
  Store,
26782
26980
  Thing,
26981
+ TypeIndex2 as TypeIndex,
26783
26982
  UriService,
26784
26983
  WebIdProfile,
26785
- createPictureLinkOperation,
26786
26984
  httpProblem,
26787
26985
  labelFromUri,
26788
26986
  listKnownTerms,