@lwrjs/shared-utils 0.24.2 → 0.24.4

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