@lwrjs/shared-utils 0.24.1 → 0.24.3

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,29 +1,35 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
6
  var __getProtoOf = Object.getPrototypeOf;
4
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
8
  var __export = (target, all) => {
9
9
  for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
17
  }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
18
+ return to;
22
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
29
 
24
30
  // packages/@lwrjs/shared-utils/src/serialize.ts
25
- __markAsModule(exports);
26
- __export(exports, {
31
+ var serialize_exports = {};
32
+ __export(serialize_exports, {
27
33
  addHeadMarkup: () => addHeadMarkup,
28
34
  addToHead: () => addToHead,
29
35
  createHeadMarkup: () => createHeadMarkup,
@@ -32,12 +38,13 @@ __export(exports, {
32
38
  serializeModuleToJson: () => serializeModuleToJson,
33
39
  shortestTtl: () => shortestTtl
34
40
  });
35
- var import_ms = __toModule(require("ms"));
36
- var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
41
+ module.exports = __toCommonJS(serialize_exports);
42
+ var import_ms = __toESM(require("ms"), 1);
43
+ var import_diagnostics = require("@lwrjs/diagnostics");
37
44
  async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
38
45
  const {
39
46
  ownHash,
40
- moduleEntry: {version}
47
+ moduleEntry: { version }
41
48
  } = await moduleRegistry.getModule(moduleId, runtimeParams);
42
49
  return {
43
50
  specifier: moduleId.specifier,
@@ -53,11 +60,13 @@ async function serializeModuleToJson(code = "", {
53
60
  version,
54
61
  ownHash,
55
62
  runtimeEnvironment,
56
- linkedConfig: {minified},
57
- moduleRecord: {imports = []}
63
+ linkedConfig: { minified },
64
+ moduleRecord: { imports = [] }
58
65
  }, moduleRegistry, runtimeParams) {
59
- const {format} = runtimeEnvironment;
60
- const dependencies = imports.map((dep) => createJsonModule(dep, moduleRegistry, runtimeEnvironment, runtimeParams));
66
+ const { format } = runtimeEnvironment;
67
+ const dependencies = imports.map(
68
+ (dep) => createJsonModule(dep, moduleRegistry, runtimeEnvironment, runtimeParams)
69
+ );
61
70
  return {
62
71
  specifier,
63
72
  version,
@@ -76,14 +85,16 @@ var SCRIPT_UNSAFE_ESCAPES = {
76
85
  };
77
86
  var SCRIPT_UNSAFE_CHARS_RE = /[<>\u2028\u2029]/g;
78
87
  function serializeForScript(value) {
79
- return JSON.stringify(value).replace(SCRIPT_UNSAFE_CHARS_RE, (char) => SCRIPT_UNSAFE_ESCAPES[char.charCodeAt(0)]);
88
+ return JSON.stringify(value).replace(
89
+ SCRIPT_UNSAFE_CHARS_RE,
90
+ (char) => SCRIPT_UNSAFE_ESCAPES[char.charCodeAt(0)]
91
+ );
80
92
  }
81
- function replaceStringFromLocation(src, {startOffset, endOffset}, replaceValue) {
93
+ function replaceStringFromLocation(src, { startOffset, endOffset }, replaceValue) {
82
94
  return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length);
83
95
  }
84
96
  function shortestTtl(newTtl, oldTtl, maxTtl) {
85
- if (newTtl === void 0 && oldTtl === void 0)
86
- return void 0;
97
+ if (newTtl === void 0 && oldTtl === void 0) return void 0;
87
98
  const newSeconds = typeof newTtl === "string" ? (0, import_ms.default)(newTtl) / 1e3 : newTtl;
88
99
  const oldSeconds = typeof oldTtl === "string" ? (0, import_ms.default)(oldTtl) / 1e3 : oldTtl;
89
100
  const maxSeconds = typeof maxTtl === "string" ? (0, import_ms.default)(maxTtl) / 1e3 : maxTtl;
@@ -100,27 +111,32 @@ function shortestTtl(newTtl, oldTtl, maxTtl) {
100
111
  return shortest;
101
112
  }
102
113
  function createMetaTags(meta) {
103
- return meta.reduce((metaStr, {name, content, httpEquiv, property, itemprop}) => {
104
- if (!name && !content && !httpEquiv && !property && !itemprop)
105
- return metaStr;
114
+ return meta.reduce((metaStr, { name, content, httpEquiv, property, itemprop }) => {
115
+ if (!name && !content && !httpEquiv && !property && !itemprop) return metaStr;
106
116
  const nameStr = name ? ` name="${name}"` : "", httpEquivStr = httpEquiv ? ` http-equiv="${httpEquiv}"` : "", propertyStr = property ? ` property="${property}"` : "", itempropStr = itemprop ? ` itemprop="${itemprop}"` : "", contentStr = content ? ` content="${content}"` : "";
107
117
  return metaStr + `<meta${nameStr}${httpEquivStr}${propertyStr}${itempropStr}${contentStr}>
108
118
  `;
109
119
  }, "");
110
120
  }
111
121
  function createScriptTags(scripts) {
112
- return scripts.reduce((scriptStr, {body}) => scriptStr + `<script type="application/ld+json">${body}</script>
113
- `, "");
122
+ return scripts.reduce(
123
+ (scriptStr, { body }) => scriptStr + `<script type="application/ld+json">${body}<\/script>
124
+ `,
125
+ ""
126
+ );
114
127
  }
115
128
  function createLinkTags(links) {
116
- return links.reduce((linkStr, {href, rel, as, fetchpriority, type, sizes, hreflang, media, crossorigin}) => {
117
- const relStr = rel ? ` rel="${rel}"` : "", asStr = as ? ` as="${as}"` : "", fetchStr = fetchpriority ? ` fetchpriority="${fetchpriority}"` : "", typeStr = type ? ` type="${type}"` : "", sizesStr = sizes ? ` sizes="${sizes}"` : "", hreflangStr = hreflang ? ` hreflang="${hreflang}"` : "", mediaStr = media ? ` media="${media}"` : "", crossoriginStr = crossorigin !== void 0 ? ` crossorigin="${crossorigin}"` : "";
118
- return linkStr + `<link href="${href}"${relStr}${asStr}${fetchStr}${typeStr}${sizesStr}${hreflangStr}${mediaStr}${crossoriginStr}>
129
+ return links.reduce(
130
+ (linkStr, { href, rel, as, fetchpriority, type, sizes, hreflang, media, crossorigin }) => {
131
+ const relStr = rel ? ` rel="${rel}"` : "", asStr = as ? ` as="${as}"` : "", fetchStr = fetchpriority ? ` fetchpriority="${fetchpriority}"` : "", typeStr = type ? ` type="${type}"` : "", sizesStr = sizes ? ` sizes="${sizes}"` : "", hreflangStr = hreflang ? ` hreflang="${hreflang}"` : "", mediaStr = media ? ` media="${media}"` : "", crossoriginStr = crossorigin !== void 0 ? ` crossorigin="${crossorigin}"` : "";
132
+ return linkStr + `<link href="${href}"${relStr}${asStr}${fetchStr}${typeStr}${sizesStr}${hreflangStr}${mediaStr}${crossoriginStr}>
119
133
  `;
120
- }, "");
134
+ },
135
+ ""
136
+ );
121
137
  }
122
138
  function createStyleTags(styles) {
123
- return styles.reduce((styleStr, {body, id}) => {
139
+ return styles.reduce((styleStr, { body, id }) => {
124
140
  const idStr = id ? ` id="${id}"` : "";
125
141
  return styleStr + `<style type="text/css"${idStr}>${body}</style>
126
142
  `;
@@ -128,7 +144,7 @@ function createStyleTags(styles) {
128
144
  }
129
145
  function createHeadMarkup(markup) {
130
146
  let hasTitle = false;
131
- return markup.reduce((str, {title, scripts = [], meta = [], links = [], styles = []} = {}) => {
147
+ return markup.reduce((str, { title, scripts = [], meta = [], links = [], styles = [] } = {}) => {
132
148
  if (title && !hasTitle) {
133
149
  hasTitle = true;
134
150
  str += `<title>${title}</title>
@@ -1,16 +1,29 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
6
  var __export = (target, all) => {
4
7
  for (var name in all)
5
- __defProp(target, name, {get: all[name], enumerable: true});
8
+ __defProp(target, name, { get: all[name], enumerable: true });
6
9
  };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
7
19
 
8
20
  // packages/@lwrjs/shared-utils/src/tasks.ts
9
- __markAsModule(exports);
10
- __export(exports, {
21
+ var tasks_exports = {};
22
+ __export(tasks_exports, {
11
23
  InflightTasks: () => InflightTasks,
12
24
  TaskPool: () => TaskPool
13
25
  });
26
+ module.exports = __toCommonJS(tasks_exports);
14
27
  var Task = class {
15
28
  constructor(taskFunction, caller, resolve, reject) {
16
29
  this.taskFunction = taskFunction;
@@ -25,6 +38,14 @@ var TaskPool = class {
25
38
  this.running = 0;
26
39
  this.size = size || 15;
27
40
  }
41
+ /**
42
+ * Add a function that takes no arguments
43
+ * It will run as soon as there is room in the pool
44
+ *
45
+ * @param taskFunction - Function to run when there is space in the pool
46
+ * @param caller - The closer to use when calling the constructor
47
+ **/
48
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
28
49
  async execute(taskFunction, caller) {
29
50
  return new Promise((resolve, reject) => {
30
51
  const task = new Task(taskFunction, caller || this, resolve, reject);
@@ -56,8 +77,15 @@ var TaskPool = class {
56
77
  };
57
78
  var InflightTasks = class {
58
79
  constructor() {
59
- this.tasks = new Map();
80
+ this.tasks = /* @__PURE__ */ new Map();
60
81
  }
82
+ /**
83
+ * Return a promise per id. If one is already in flight return the promise.
84
+ * If not use the constructor to create a new
85
+ *
86
+ * @param id - Unique id for promise in question
87
+ * @param fn - Function that create a promise for the id if needed
88
+ */
61
89
  execute(id, fn) {
62
90
  let promise = this.tasks.get(id);
63
91
  if (!promise) {
@@ -1,29 +1,35 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
6
  var __getProtoOf = Object.getPrototypeOf;
4
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
8
  var __export = (target, all) => {
9
9
  for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
17
  }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
18
+ return to;
22
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
29
 
24
30
  // packages/@lwrjs/shared-utils/src/urls.ts
25
- __markAsModule(exports);
26
- __export(exports, {
31
+ var urls_exports = {};
32
+ __export(urls_exports, {
27
33
  crossEnvFileURL: () => crossEnvFileURL,
28
34
  decodeViewPath: () => decodeViewPath,
29
35
  extractRequestParams: () => extractRequestParams,
@@ -36,16 +42,21 @@ __export(exports, {
36
42
  removeClientBootstrapConfigurationSuffix: () => removeClientBootstrapConfigurationSuffix,
37
43
  toHostname: () => toHostname
38
44
  });
39
- var import_path_to_regexp = __toModule(require("path-to-regexp"));
40
- var import_os = __toModule(require("os"));
41
- var import_url = __toModule(require("url"));
42
- var import_fs = __toModule(require("./fs.cjs"));
45
+ module.exports = __toCommonJS(urls_exports);
46
+ var import_path_to_regexp = require("path-to-regexp");
47
+ var import_os = __toESM(require("os"), 1);
48
+ var import_url = require("url");
49
+ var import_fs = require("./fs.cjs");
43
50
  var CONFIG_SUFFIX = "/config.js";
44
51
  var SIGNATURE_SIGIL = "s";
45
52
  function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
46
53
  const url = routeInfo.url + sortedQueryParamString(routeInfo.query);
47
54
  const encodeUrl = `-${encodeURIComponent(url)}-`;
48
- const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
55
+ const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(
56
+ routeInfo,
57
+ runtimeEnvironment,
58
+ runtimeParams
59
+ );
49
60
  const signatureSegment = signature ? `/${SIGNATURE_SIGIL}/${signature}` : "";
50
61
  return `${configUrlPrefix}/${encodeUrl}${signatureSegment}${CONFIG_SUFFIX}`;
51
62
  }
@@ -57,8 +68,8 @@ function decodeViewPath(encodedViewPath) {
57
68
  return decodePath;
58
69
  }
59
70
  function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
60
- const {apiVersion, format, basePath} = runtimeEnvironment;
61
- const {id} = routeInfo;
71
+ const { apiVersion, format, basePath } = runtimeEnvironment;
72
+ const { id } = routeInfo;
62
73
  const locale = runtimeParams?.locale;
63
74
  const environment = runtimeParams?.environment;
64
75
  if (locale && environment) {
@@ -84,6 +95,7 @@ function getClientBootstrapConfigurationRoutes() {
84
95
  `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
85
96
  `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
86
97
  `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
98
+ // with signature
87
99
  `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
88
100
  `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
89
101
  `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.24.1",
7
+ "version": "0.24.3",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "build/**/*.d.ts"
38
38
  ],
39
39
  "dependencies": {
40
- "@lwrjs/diagnostics": "0.24.1",
40
+ "@lwrjs/diagnostics": "0.24.3",
41
41
  "es-module-lexer": "^1.5.4",
42
42
  "fast-json-stable-stringify": "^2.1.0",
43
43
  "magic-string": "^0.30.9",
@@ -50,7 +50,7 @@
50
50
  "slugify": "^1.4.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@lwrjs/types": "0.24.1",
53
+ "@lwrjs/types": "0.24.3",
54
54
  "@types/mime-types": "2.1.4",
55
55
  "@types/path-to-regexp": "^1.7.0",
56
56
  "memfs": "^4.13.0"
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=22.0.0"
60
60
  },
61
- "gitHead": "ebc0aaa310f5ebd008732d0203a15a1c51f77e5e"
61
+ "gitHead": "ed415a8f04d5558cac756fbc2a0e454a373e31c1"
62
62
  }