@arpproject/recrate 0.1.44 → 0.1.45

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.
@@ -1,5 +1,6 @@
1
1
  import { UnverifiedEntityDefinition, NormalisedEntityDefinition } from '../types.js';
2
2
  export declare const urlProtocols: string[];
3
+ export declare function shouldGenerateEntityName(value: unknown): boolean;
3
4
  /**
4
5
  *
5
6
  * @param {string} value - string to check as a URL: checks 'http','https','ftp', 'arcp'
@@ -73945,6 +73945,14 @@ function validateId({ id: id2, type: type4 }) {
73945
73945
  };
73946
73946
  }
73947
73947
  const urlProtocols = ["http", "https", "ftp", "ftps"];
73948
+ function shouldGenerateEntityName(value) {
73949
+ if (!value) return true;
73950
+ if (isString(value)) return value.trim().length === 0;
73951
+ if (isArray(value)) {
73952
+ return value.map((entry) => String(entry ?? "")).join(" ").trim().length === 0;
73953
+ }
73954
+ return false;
73955
+ }
73948
73956
  function isURL(value) {
73949
73957
  if (!value) return false;
73950
73958
  if (isNumber(value)) return false;
@@ -73986,7 +73994,7 @@ function normalise(entity, i) {
73986
73994
  if (!isValid && message === "The identifier is not valid according to the RO Crate spec nor is it a valid IRI.") {
73987
73995
  normalisedEntity["@id"] = `#${normalisedEntity["@id"]}`;
73988
73996
  }
73989
- normalisedEntity.name = entity.name ? entity.name : normalisedEntity["@id"].replace(/^#/, "");
73997
+ normalisedEntity.name = shouldGenerateEntityName(entity.name) ? normalisedEntity["@id"].replace(/^#/, "") : entity.name;
73990
73998
  if (isArray(normalisedEntity.name)) normalisedEntity.name = normalisedEntity.name.join(" ");
73991
73999
  for (let property of Object.keys(entity)) {
73992
74000
  if (["@id", "@type", "name", "@reverse"].includes(property)) continue;
@@ -126837,6 +126845,12 @@ class CrateManager {
126837
126845
  crate["@graph"][i],
126838
126846
  i
126839
126847
  );
126848
+ if (shouldGenerateEntityName(crate["@graph"][i].name)) {
126849
+ this.__setWarning(
126850
+ "init",
126851
+ `Entity '${normalisedEntity["@id"]}' did not have a name. Recrate generated '${normalisedEntity.name}' from its identifier.`
126852
+ );
126853
+ }
126840
126854
  idMap[crate["@graph"][i]["@id"]] = normalisedEntity["@id"];
126841
126855
  if (normalisedEntity["@id"].match(/^_:/)) {
126842
126856
  this.blankNodes.push(normalisedEntity["@id"]);
@@ -135232,7 +135246,7 @@ var EmotionCacheContext = /* @__PURE__ */ React.createContext(
135232
135246
  }) : null
135233
135247
  );
135234
135248
  var CacheProvider = EmotionCacheContext.Provider;
135235
- const version = "0.1.44";
135249
+ const version = "0.1.45";
135236
135250
  const pkg = {
135237
135251
  version
135238
135252
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arpproject/recrate",
3
- "version": "0.1.44",
3
+ "version": "0.1.45",
4
4
  "type": "module",
5
5
  "main": "./dist/recrate.es.js",
6
6
  "module": "./dist/recrate.es.js",