@pod-os/core 0.12.1-eee70d1.0 → 0.12.1-facecbd.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
@@ -13642,6 +13642,30 @@ function labelForType(typeUri) {
13642
13642
  }
13643
13643
  }
13644
13644
 
13645
+ // src/thing/labelFromUri.ts
13646
+ function labelFromUri(uri6) {
13647
+ const url7 = new URL(uri6);
13648
+ if (isTooGeneric(url7.hash)) {
13649
+ return (getFilename(url7) || url7.host + url7.pathname) + url7.hash;
13650
+ }
13651
+ return labelFromFragment(url7.hash) || getFilename(url7) || url7.host;
13652
+ }
13653
+ function labelFromFragment(fragment) {
13654
+ return fragment ? fragment.split("#")[1] : null;
13655
+ }
13656
+ function isTooGeneric(fragment) {
13657
+ const genericFragments = ["#it", "#this", "#me", "#i"];
13658
+ return genericFragments.includes(fragment);
13659
+ }
13660
+ function getFilename(url7) {
13661
+ if (url7.pathname.endsWith("/")) {
13662
+ const containerName = url7.pathname.split("/").at(-2);
13663
+ return containerName ? containerName + "/" : null;
13664
+ } else {
13665
+ return url7.pathname.split("/").pop();
13666
+ }
13667
+ }
13668
+
13645
13669
  // src/thing/Thing.ts
13646
13670
  var Thing = class {
13647
13671
  constructor(uri6, store, editable = false) {
@@ -13663,13 +13687,17 @@ var Thing = class {
13663
13687
  "http://schema.org/caption",
13664
13688
  "https://schema.org/caption"
13665
13689
  );
13666
- return value6 ?? this.uri;
13690
+ if (value6) {
13691
+ return value6;
13692
+ }
13693
+ return labelFromUri(this.uri);
13667
13694
  }
13668
13695
  literals() {
13669
13696
  const statements = this.store.statementsMatching(namedNode(this.uri));
13670
13697
  const values = statements.filter((it) => isLiteral(it.object)).reduce(accumulateValues, {});
13671
13698
  return Object.keys(values).map((predicate2) => ({
13672
13699
  predicate: predicate2,
13700
+ label: labelFromUri(predicate2),
13673
13701
  values: values[predicate2]
13674
13702
  }));
13675
13703
  }
@@ -13678,6 +13706,7 @@ var Thing = class {
13678
13706
  const values = statements.filter((it) => isNamedNode(it.object) && !isRdfType(it.predicate)).reduce(accumulateValues, {});
13679
13707
  return Object.keys(values).map((predicate2) => ({
13680
13708
  predicate: predicate2,
13709
+ label: labelFromUri(predicate2),
13681
13710
  uris: values[predicate2]
13682
13711
  }));
13683
13712
  }
@@ -13690,6 +13719,7 @@ var Thing = class {
13690
13719
  const values = statements.reduce(accumulateSubjects, {});
13691
13720
  return Object.keys(values).map((predicate2) => ({
13692
13721
  predicate: predicate2,
13722
+ label: labelFromUri(predicate2),
13693
13723
  uris: values[predicate2]
13694
13724
  }));
13695
13725
  }
@@ -34457,7 +34487,8 @@ export {
34457
34487
  RdfDocument,
34458
34488
  SearchIndex,
34459
34489
  Thing,
34460
- WebIdProfile
34490
+ WebIdProfile,
34491
+ labelFromUri
34461
34492
  };
34462
34493
  /*! Bundled license information:
34463
34494
 
package/lib/index.js CHANGED
@@ -44280,7 +44280,8 @@ var PodOS = (() => {
44280
44280
  RdfDocument: () => RdfDocument,
44281
44281
  SearchIndex: () => SearchIndex,
44282
44282
  Thing: () => Thing,
44283
- WebIdProfile: () => WebIdProfile
44283
+ WebIdProfile: () => WebIdProfile,
44284
+ labelFromUri: () => labelFromUri
44284
44285
  });
44285
44286
 
44286
44287
  // ../node_modules/tslib/tslib.es6.mjs
@@ -49447,6 +49448,30 @@ var PodOS = (() => {
49447
49448
  }
49448
49449
  }
49449
49450
 
49451
+ // src/thing/labelFromUri.ts
49452
+ function labelFromUri(uri6) {
49453
+ const url7 = new URL(uri6);
49454
+ if (isTooGeneric(url7.hash)) {
49455
+ return (getFilename(url7) || url7.host + url7.pathname) + url7.hash;
49456
+ }
49457
+ return labelFromFragment(url7.hash) || getFilename(url7) || url7.host;
49458
+ }
49459
+ function labelFromFragment(fragment) {
49460
+ return fragment ? fragment.split("#")[1] : null;
49461
+ }
49462
+ function isTooGeneric(fragment) {
49463
+ const genericFragments = ["#it", "#this", "#me", "#i"];
49464
+ return genericFragments.includes(fragment);
49465
+ }
49466
+ function getFilename(url7) {
49467
+ if (url7.pathname.endsWith("/")) {
49468
+ const containerName = url7.pathname.split("/").at(-2);
49469
+ return containerName ? containerName + "/" : null;
49470
+ } else {
49471
+ return url7.pathname.split("/").pop();
49472
+ }
49473
+ }
49474
+
49450
49475
  // src/thing/Thing.ts
49451
49476
  var Thing = class {
49452
49477
  constructor(uri6, store, editable = false) {
@@ -49468,13 +49493,17 @@ var PodOS = (() => {
49468
49493
  "http://schema.org/caption",
49469
49494
  "https://schema.org/caption"
49470
49495
  );
49471
- return value6 ?? this.uri;
49496
+ if (value6) {
49497
+ return value6;
49498
+ }
49499
+ return labelFromUri(this.uri);
49472
49500
  }
49473
49501
  literals() {
49474
49502
  const statements = this.store.statementsMatching(namedNode2(this.uri));
49475
49503
  const values = statements.filter((it) => isLiteral(it.object)).reduce(accumulateValues, {});
49476
49504
  return Object.keys(values).map((predicate2) => ({
49477
49505
  predicate: predicate2,
49506
+ label: labelFromUri(predicate2),
49478
49507
  values: values[predicate2]
49479
49508
  }));
49480
49509
  }
@@ -49483,6 +49512,7 @@ var PodOS = (() => {
49483
49512
  const values = statements.filter((it) => isNamedNode(it.object) && !isRdfType(it.predicate)).reduce(accumulateValues, {});
49484
49513
  return Object.keys(values).map((predicate2) => ({
49485
49514
  predicate: predicate2,
49515
+ label: labelFromUri(predicate2),
49486
49516
  uris: values[predicate2]
49487
49517
  }));
49488
49518
  }
@@ -49495,6 +49525,7 @@ var PodOS = (() => {
49495
49525
  const values = statements.reduce(accumulateSubjects, {});
49496
49526
  return Object.keys(values).map((predicate2) => ({
49497
49527
  predicate: predicate2,
49528
+ label: labelFromUri(predicate2),
49498
49529
  uris: values[predicate2]
49499
49530
  }));
49500
49531
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pod-os/core",
3
- "version": "0.12.1-eee70d1.0",
3
+ "version": "0.12.1-facecbd.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./types/index.d.ts",
6
6
  "files": [
@@ -1,10 +1,12 @@
1
1
  import { IndexedFormula } from "rdflib";
2
2
  export interface Literal {
3
3
  predicate: string;
4
+ label: string;
4
5
  values: string[];
5
6
  }
6
7
  export interface Relation {
7
8
  predicate: string;
9
+ label: string;
8
10
  uris: string[];
9
11
  }
10
12
  export interface RdfType {
@@ -1 +1,2 @@
1
1
  export * from "./Thing";
2
+ export { labelFromUri } from "./labelFromUri";
@@ -0,0 +1 @@
1
+ export declare function labelFromUri(uri: string): string;
@@ -0,0 +1 @@
1
+ export {};