@lwrjs/shared-utils 0.9.0-alpha.1 → 0.9.0-alpha.11

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/build/cjs/env.cjs CHANGED
@@ -19,6 +19,7 @@ function getFeatureFlags() {
19
19
  } catch (e) {
20
20
  }
21
21
  return {
22
- LEGACY_LOADER: legacyLoader
22
+ LEGACY_LOADER: legacyLoader,
23
+ SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES === "true" ? true : false
23
24
  };
24
25
  }
package/build/cjs/fs.cjs CHANGED
@@ -44,10 +44,13 @@ var import_chokidar = __toModule(require("chokidar"));
44
44
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
45
45
  var import_mime_types = __toModule(require("mime-types"));
46
46
  var import_logger = __toModule(require("./logger.cjs"));
47
+ var fileCount = 0;
48
+ var files = new Map();
47
49
  function hashContent(source) {
48
50
  return import_crypto.default.createHash("md5").update(source).digest("hex");
49
51
  }
50
52
  function readFile(filePath) {
53
+ logMetrics(filePath);
51
54
  return import_fs.default.readFileSync(filePath, "utf8");
52
55
  }
53
56
  function resolveFileExtension(filePath) {
@@ -125,3 +128,15 @@ function normalizeResourcePath(rawPath, {rootDir, assets, contentDir, layoutsDir
125
128
  return alias;
126
129
  });
127
130
  }
131
+ function logMetrics(filePath) {
132
+ if (import_logger.logger.currentLevel == import_logger.DEBUG || import_logger.logger.currentLevel == import_logger.VERBOSE) {
133
+ let count = files.get(filePath) || 0;
134
+ if (++count % 100 === 0) {
135
+ import_logger.logger.debug(`[${count}] Repeat Read ${filePath}`);
136
+ }
137
+ files.set(filePath, count);
138
+ if (++fileCount % 1e3 === 0) {
139
+ import_logger.logger.debug(`Open file count [${fileCount}]`);
140
+ }
141
+ }
142
+ }
@@ -37,14 +37,10 @@ __export(exports, {
37
37
  VERSION_SIGIL: () => VERSION_SIGIL,
38
38
  explodeSpecifier: () => explodeSpecifier,
39
39
  explodeSpecifiers: () => explodeSpecifiers,
40
- getAssetIdentity: () => getAssetIdentity,
41
40
  getCacheKeyFromJson: () => import_fast_json_stable_stringify.default,
42
- getMappingIdentity: () => getMappingIdentity,
43
41
  getMappingUriPrefix: () => getMappingUriPrefix,
44
- getModuleIdentity: () => getModuleIdentity,
45
42
  getModuleUriPrefix: () => getModuleUriPrefix,
46
43
  getPropFromAttrName: () => getPropFromAttrName,
47
- getResourceIdentity: () => getResourceIdentity,
48
44
  getSpecifier: () => getSpecifier,
49
45
  getVersionedModuleId: () => getVersionedModuleId,
50
46
  getVersionedSpecifier: () => getVersionedSpecifier,
@@ -132,12 +128,12 @@ async function getVersionedSpecifier(rawSpecifier, moduleRegistry) {
132
128
  return getSpecifier({namespace, name, version: normalizeVersionToUri(moduleEntry.version)});
133
129
  }
134
130
  async function getVersionedModuleId(rawSpecifier, moduleRegistry) {
135
- const {specifier, version} = explodeSpecifier(rawSpecifier);
136
- if (version) {
137
- return {specifier, version: normalizeVersionFromUri(version)};
131
+ const moduleId = explodeSpecifier(rawSpecifier);
132
+ if (moduleId.version) {
133
+ return {...moduleId, version: normalizeVersionFromUri(moduleId.version)};
138
134
  }
139
- const moduleEntry = await moduleRegistry.getModuleEntry({specifier});
140
- return {specifier, version: moduleEntry.version};
135
+ const moduleEntry = await moduleRegistry.getModuleEntry(moduleId);
136
+ return {...moduleId, version: moduleEntry.version};
141
137
  }
142
138
  var RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
143
139
  var RE_NORMAL = /^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
@@ -212,52 +208,3 @@ function isExternalUrl(url) {
212
208
  function isBundleDefinition(definition) {
213
209
  return definition.bundleRecord !== void 0;
214
210
  }
215
- function validateSpecifier(specifer) {
216
- return specifer.indexOf("../") < 0;
217
- }
218
- function getModuleIdentity(req) {
219
- const {specifier, signature = LATEST_SIGNATURE} = req.params;
220
- if (validateSpecifier(specifier) === false) {
221
- throw new Error("dot-dot-slash is not allowed for module specifier");
222
- }
223
- const moduleId = explodeSpecifier(specifier);
224
- return {
225
- moduleId,
226
- signature
227
- };
228
- }
229
- function getMappingIdentity(req) {
230
- const {specifiers} = req.params;
231
- const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
232
- ...obj,
233
- importer: req.query.importer
234
- }));
235
- return {
236
- moduleIds
237
- };
238
- }
239
- function getResourceIdentity(req) {
240
- const {specifier, signature = LATEST_SIGNATURE} = req.params;
241
- if (validateSpecifier(specifier) === false) {
242
- throw new Error("dot-dot-slash is not allowed for resource specifier");
243
- }
244
- const resourceId = explodeSpecifier(specifier);
245
- return {
246
- resourceId,
247
- signature
248
- };
249
- }
250
- function getAssetIdentity(req) {
251
- const {signature = LATEST_SIGNATURE, assetType: type} = req.params;
252
- const [specifier] = req.originalUrl.split("?");
253
- if (validateSpecifier(specifier) === false) {
254
- throw new Error("dot-dot-slash is not allowed for asset specifier");
255
- }
256
- return {
257
- assetId: {
258
- specifier,
259
- type
260
- },
261
- signature
262
- };
263
- }
@@ -42,10 +42,13 @@ var NoLwcModuleError = class extends Error {
42
42
  function isNpmModuleRecord(module2) {
43
43
  return module2.npm !== void 0;
44
44
  }
45
- function discoverInterchangeableModules(modules, interchangeableModules) {
45
+ function discoverInterchangeableModules(modules, interchangeableModules, visitedModules) {
46
46
  if (!interchangeableModules) {
47
47
  interchangeableModules = new Map();
48
48
  }
49
+ if (!visitedModules) {
50
+ visitedModules = new Set();
51
+ }
49
52
  if (modules.length === 0) {
50
53
  return interchangeableModules;
51
54
  }
@@ -54,6 +57,10 @@ function discoverInterchangeableModules(modules, interchangeableModules) {
54
57
  if (!isNpmModuleRecord(module2)) {
55
58
  continue;
56
59
  }
60
+ if (visitedModules?.has(module2.npm)) {
61
+ continue;
62
+ }
63
+ visitedModules.add(module2.npm);
57
64
  const packageJsonPath = import_resolve.default.sync(`${module2.npm}/package.json`);
58
65
  const packageJson = JSON.parse((0, import_fs2.readFile)(packageJsonPath));
59
66
  let lwcConfig = packageJson.lwc;
@@ -68,7 +75,7 @@ function discoverInterchangeableModules(modules, interchangeableModules) {
68
75
  interchangeableModules = normalizeInterchangeableModuleConfig(lwcConfig.interchangeableModules, interchangeableModules);
69
76
  }
70
77
  }
71
- return discoverInterchangeableModules(nestedModules, interchangeableModules);
78
+ return discoverInterchangeableModules(nestedModules, interchangeableModules, visitedModules);
72
79
  }
73
80
  function resolveCustomLWCMetadata(dir) {
74
81
  for (const configFile of CONFIG_FILES) {
@@ -23,7 +23,8 @@ function _deepFreeze(obj, maxDepth, depth) {
23
23
  }
24
24
  }
25
25
  function deepFreeze(obj, maxDepth = 5) {
26
- return _deepFreeze(obj, maxDepth, 0);
26
+ const objClone = JSON.parse(JSON.stringify(obj));
27
+ return _deepFreeze(objClone, maxDepth, 0);
27
28
  }
28
29
  var debounce = (func, waitFor) => {
29
30
  const timeouts = new Map();
@@ -1,16 +1,34 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2
7
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
8
  var __export = (target, all) => {
4
9
  for (var name in all)
5
10
  __defProp(target, name, {get: all[name], enumerable: true});
6
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});
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);
22
+ };
7
23
 
8
24
  // packages/@lwrjs/shared-utils/src/serialize.ts
9
25
  __markAsModule(exports);
10
26
  __export(exports, {
11
27
  replaceStringFromLocation: () => replaceStringFromLocation,
12
- serializeModuleToJson: () => serializeModuleToJson
28
+ serializeModuleToJson: () => serializeModuleToJson,
29
+ shortestTtl: () => shortestTtl
13
30
  });
31
+ var import_ms = __toModule(require("ms"));
14
32
  async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
15
33
  const {
16
34
  ownHash,
@@ -48,3 +66,14 @@ async function serializeModuleToJson(code = "", {
48
66
  function replaceStringFromLocation(src, {startOffset, endOffset}, replaceValue) {
49
67
  return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length);
50
68
  }
69
+ function shortestTtl(newTtl, oldTtl) {
70
+ if (!newTtl && !oldTtl)
71
+ return void 0;
72
+ const newSeconds = typeof newTtl === "string" ? (0, import_ms.default)(newTtl) / 1e3 : newTtl;
73
+ const oldSeconds = typeof oldTtl === "string" ? (0, import_ms.default)(oldTtl) / 1e3 : oldTtl;
74
+ if (!newSeconds)
75
+ return oldSeconds;
76
+ if (!oldSeconds)
77
+ return newSeconds;
78
+ return newSeconds < oldSeconds ? newSeconds : oldSeconds;
79
+ }
package/build/es/env.js CHANGED
@@ -12,6 +12,10 @@ export function getFeatureFlags() {
12
12
  return {
13
13
  // DEFAULT LEGACY_LOADER = false;
14
14
  LEGACY_LOADER: legacyLoader,
15
+ // SSR should concatenate bundles, default = false
16
+ SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined && process.env.SSR_STATIC_BUNDLES === 'true'
17
+ ? true
18
+ : false,
15
19
  };
16
20
  }
17
21
  //# sourceMappingURL=env.js.map
package/build/es/fs.js CHANGED
@@ -6,7 +6,9 @@ import { debounce } from './object.js';
6
6
  import chokidar from 'chokidar';
7
7
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
8
8
  import { lookup } from 'mime-types';
9
- import { logger } from './logger.js';
9
+ import { DEBUG, logger, VERBOSE } from './logger.js';
10
+ let fileCount = 0;
11
+ const files = new Map();
10
12
  /**
11
13
  * Create a hash string for a source
12
14
  * @param source
@@ -19,6 +21,7 @@ export function hashContent(source) {
19
21
  * @param filePath
20
22
  */
21
23
  export function readFile(filePath) {
24
+ logMetrics(filePath);
22
25
  return fs.readFileSync(filePath, 'utf8');
23
26
  }
24
27
  /**
@@ -138,4 +141,16 @@ export function normalizeResourcePath(rawPath, { rootDir, assets, contentDir, la
138
141
  });
139
142
  }
140
143
  export { lookup as mimeLookup };
144
+ function logMetrics(filePath) {
145
+ if (logger.currentLevel == DEBUG || logger.currentLevel == VERBOSE) {
146
+ let count = files.get(filePath) || 0;
147
+ if (++count % 100 === 0) {
148
+ logger.debug(`[${count}] Repeat Read ${filePath}`);
149
+ }
150
+ files.set(filePath, count);
151
+ if (++fileCount % 1000 === 0) {
152
+ logger.debug(`Open file count [${fileCount}]`);
153
+ }
154
+ }
155
+ }
141
156
  //# sourceMappingURL=fs.js.map
@@ -1,5 +1,5 @@
1
1
  import getCacheKeyFromJson from 'fast-json-stable-stringify';
2
- import { AbstractModuleId, AssetIdentity, BundleDefinition, MappingIdentity, MiddlewareRequest, ModuleDefinition, ModuleId, ModuleIdentity, PublicModuleRegistry, ResourceIdentity, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
+ import { AbstractModuleId, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
3
3
  export declare const VERSION_SIGIL = "/v/";
4
4
  export declare const LOCALE_SIGIL = "l";
5
5
  export declare const ENVIRONMENT_SIGIL = "e";
@@ -13,14 +13,7 @@ export declare const DEFAULT_LWR_LOCKER_CONFIG: {
13
13
  enabled: boolean;
14
14
  trustedComponents: string[];
15
15
  };
16
- export declare const DEFAULT_LWR_BOOTSTRAP_CONFIG: {
17
- autoBoot: boolean;
18
- syntheticShadow: boolean;
19
- workers: {};
20
- services: never[];
21
- configAsSrc: boolean;
22
- ssr: boolean;
23
- };
16
+ export declare const DEFAULT_LWR_BOOTSTRAP_CONFIG: NormalizedLwrAppBootstrapConfig;
24
17
  declare type ModuleIdentifierPartial = Partial<AbstractModuleId>;
25
18
  /**
26
19
  * Turn the dots in a version into underscores
@@ -87,6 +80,9 @@ export declare function getSpecifier({ specifier, namespace, name, version }: Mo
87
80
  * @example - 'c/form/v/0.0.2' => 'c/form/v/0_0_2'
88
81
  */
89
82
  export declare function getVersionedSpecifier(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<string>;
83
+ interface VersionedAbstractModuleId extends AbstractModuleId {
84
+ version: string;
85
+ }
90
86
  /**
91
87
  * Create a AbstractModuleId using the module registry to resolve the version
92
88
  * if a version is not provided in the `rawSpecifier`
@@ -107,7 +103,7 @@ export declare function getVersionedSpecifier(rawSpecifier: string, moduleRegist
107
103
  * @example - 'c/form/v/0.0.2' => {specifier: "c/form", version: "0.0.2"}
108
104
  * @example - 'c/form/v/0_0_2' => {specifier: "c/form", version: "0.0.2"}
109
105
  */
110
- export declare function getVersionedModuleId(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<Required<Pick<ModuleId, 'specifier' | 'version'>>>;
106
+ export declare function getVersionedModuleId(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<VersionedAbstractModuleId>;
111
107
  interface PackageIdentity {
112
108
  scope?: string;
113
109
  packageName: string;
@@ -165,8 +161,4 @@ export declare function getMappingUriPrefix({ apiVersion, bundle, format, compat
165
161
  export { getCacheKeyFromJson };
166
162
  export declare function isExternalUrl(url: string): boolean;
167
163
  export declare function isBundleDefinition(definition: ModuleDefinition | BundleDefinition): definition is BundleDefinition;
168
- export declare function getModuleIdentity(req: MiddlewareRequest): ModuleIdentity;
169
- export declare function getMappingIdentity(req: MiddlewareRequest): MappingIdentity;
170
- export declare function getResourceIdentity(req: MiddlewareRequest): ResourceIdentity;
171
- export declare function getAssetIdentity(req: MiddlewareRequest): AssetIdentity;
172
164
  //# sourceMappingURL=identity.d.ts.map
@@ -148,13 +148,13 @@ export async function getVersionedSpecifier(rawSpecifier, moduleRegistry) {
148
148
  * @example - 'c/form/v/0_0_2' => {specifier: "c/form", version: "0.0.2"}
149
149
  */
150
150
  export async function getVersionedModuleId(rawSpecifier, moduleRegistry) {
151
- const { specifier, version } = explodeSpecifier(rawSpecifier);
152
- if (version) {
153
- return { specifier, version: normalizeVersionFromUri(version) };
151
+ const moduleId = explodeSpecifier(rawSpecifier);
152
+ if (moduleId.version) {
153
+ return { ...moduleId, version: normalizeVersionFromUri(moduleId.version) };
154
154
  }
155
155
  // Get version from Module Registry
156
- const moduleEntry = await moduleRegistry.getModuleEntry({ specifier });
157
- return { specifier, version: moduleEntry.version };
156
+ const moduleEntry = await moduleRegistry.getModuleEntry(moduleId);
157
+ return { ...moduleId, version: moduleEntry.version };
158
158
  }
159
159
  const RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
160
160
  const RE_NORMAL = /^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
@@ -279,53 +279,4 @@ export function isExternalUrl(url) {
279
279
  export function isBundleDefinition(definition) {
280
280
  return definition.bundleRecord !== undefined;
281
281
  }
282
- function validateSpecifier(specifer) {
283
- return specifer.indexOf('../') < 0;
284
- }
285
- export function getModuleIdentity(req) {
286
- const { specifier, signature = LATEST_SIGNATURE } = req.params;
287
- if (validateSpecifier(specifier) === false) {
288
- throw new Error('dot-dot-slash is not allowed for module specifier');
289
- }
290
- const moduleId = explodeSpecifier(specifier);
291
- return {
292
- moduleId,
293
- signature,
294
- };
295
- }
296
- export function getMappingIdentity(req) {
297
- const { specifiers } = req.params;
298
- const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
299
- ...obj,
300
- importer: req.query.importer,
301
- }));
302
- return {
303
- moduleIds,
304
- };
305
- }
306
- export function getResourceIdentity(req) {
307
- const { specifier, signature = LATEST_SIGNATURE } = req.params;
308
- if (validateSpecifier(specifier) === false) {
309
- throw new Error('dot-dot-slash is not allowed for resource specifier');
310
- }
311
- const resourceId = explodeSpecifier(specifier);
312
- return {
313
- resourceId,
314
- signature,
315
- };
316
- }
317
- export function getAssetIdentity(req) {
318
- const { signature = LATEST_SIGNATURE, assetType: type } = req.params;
319
- const [specifier] = req.originalUrl.split('?');
320
- if (validateSpecifier(specifier) === false) {
321
- throw new Error('dot-dot-slash is not allowed for asset specifier');
322
- }
323
- return {
324
- assetId: {
325
- specifier,
326
- type,
327
- },
328
- signature,
329
- };
330
- }
331
282
  //# sourceMappingURL=identity.js.map
@@ -11,7 +11,7 @@ import { InterchangeableModuleRecord, LwcConfig, ResolverModuleRecord, Interchan
11
11
  * @returns {map} a map of all possible interchangeable modules
12
12
  *
13
13
  */
14
- export declare function discoverInterchangeableModules(modules: ResolverModuleRecord[], interchangeableModules?: InterchangeableModuleMap): InterchangeableModuleMap;
14
+ export declare function discoverInterchangeableModules(modules: ResolverModuleRecord[], interchangeableModules?: InterchangeableModuleMap, visitedModules?: Set<string>): InterchangeableModuleMap;
15
15
  /**
16
16
  * Locate the LWC config for the package and resolve custom properties
17
17
  *
@@ -24,10 +24,13 @@ function isNpmModuleRecord(module) {
24
24
  * @returns {map} a map of all possible interchangeable modules
25
25
  *
26
26
  */
27
- export function discoverInterchangeableModules(modules, interchangeableModules) {
27
+ export function discoverInterchangeableModules(modules, interchangeableModules, visitedModules) {
28
28
  if (!interchangeableModules) {
29
29
  interchangeableModules = new Map();
30
30
  }
31
+ if (!visitedModules) {
32
+ visitedModules = new Set();
33
+ }
31
34
  if (modules.length === 0) {
32
35
  return interchangeableModules;
33
36
  }
@@ -37,6 +40,10 @@ export function discoverInterchangeableModules(modules, interchangeableModules)
37
40
  if (!isNpmModuleRecord(module)) {
38
41
  continue;
39
42
  }
43
+ if (visitedModules?.has(module.npm)) {
44
+ continue;
45
+ }
46
+ visitedModules.add(module.npm);
40
47
  // resolve module path and package.json
41
48
  const packageJsonPath = resolve.sync(`${module.npm}/package.json`);
42
49
  const packageJson = JSON.parse(readFile(packageJsonPath));
@@ -55,7 +62,7 @@ export function discoverInterchangeableModules(modules, interchangeableModules)
55
62
  interchangeableModules = normalizeInterchangeableModuleConfig(lwcConfig.interchangeableModules, interchangeableModules);
56
63
  }
57
64
  }
58
- return discoverInterchangeableModules(nestedModules, interchangeableModules);
65
+ return discoverInterchangeableModules(nestedModules, interchangeableModules, visitedModules);
59
66
  }
60
67
  /**
61
68
  * Locate the LWC config for the package and resolve custom properties
@@ -18,7 +18,8 @@ function _deepFreeze(obj, maxDepth, depth) {
18
18
  */
19
19
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
20
20
  export function deepFreeze(obj, maxDepth = 5) {
21
- return _deepFreeze(obj, maxDepth, 0);
21
+ const objClone = JSON.parse(JSON.stringify(obj));
22
+ return _deepFreeze(objClone, maxDepth, 0);
22
23
  }
23
24
  /**
24
25
  * Returns a function which debounces when the input function is called with the same first argument
@@ -1,4 +1,4 @@
1
- import { LinkedModuleDefinition, ModuleJsonDefinition, ModuleRegistry, RuntimeParams } from '@lwrjs/types';
1
+ import type { LinkedModuleDefinition, ModuleJsonDefinition, ModuleRegistry, RuntimeParams } from '@lwrjs/types';
2
2
  /**
3
3
  * Take a Module Definition and return its JSON serialization
4
4
  *
@@ -19,4 +19,11 @@ export declare function replaceStringFromLocation(src: string, { startOffset, en
19
19
  startOffset: number;
20
20
  endOffset: number;
21
21
  }, replaceValue: string): string;
22
+ /**
23
+ * Given two TTLs, return the shortest one
24
+ * @param newTtl - time-to-live: time string or number of seconds
25
+ * @param oldTtl - the current shortest TTL (if it exists)
26
+ * @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
27
+ */
28
+ export declare function shortestTtl(newTtl?: string | number, oldTtl?: string | number): number | undefined;
22
29
  //# sourceMappingURL=serialize.d.ts.map
@@ -1,3 +1,4 @@
1
+ import ms from 'ms';
1
2
  // Given a Module Identifier, return a JSON entry
2
3
  async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
3
4
  const { ownHash, moduleEntry: { version }, } = await moduleRegistry.getModule(moduleId, runtimeParams);
@@ -42,4 +43,21 @@ export async function serializeModuleToJson(code = '', { specifier, version, own
42
43
  export function replaceStringFromLocation(src, { startOffset, endOffset }, replaceValue) {
43
44
  return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length);
44
45
  }
46
+ /**
47
+ * Given two TTLs, return the shortest one
48
+ * @param newTtl - time-to-live: time string or number of seconds
49
+ * @param oldTtl - the current shortest TTL (if it exists)
50
+ * @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
51
+ */
52
+ export function shortestTtl(newTtl, oldTtl) {
53
+ if (!newTtl && !oldTtl)
54
+ return undefined;
55
+ const newSeconds = typeof newTtl === 'string' ? ms(newTtl) / 1000 : newTtl;
56
+ const oldSeconds = typeof oldTtl === 'string' ? ms(oldTtl) / 1000 : oldTtl;
57
+ if (!newSeconds)
58
+ return oldSeconds;
59
+ if (!oldSeconds)
60
+ return newSeconds;
61
+ return newSeconds < oldSeconds ? newSeconds : oldSeconds;
62
+ }
45
63
  //# sourceMappingURL=serialize.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.1",
7
+ "version": "0.9.0-alpha.11",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -39,19 +39,19 @@
39
39
  "fast-json-stable-stringify": "^2.1.0",
40
40
  "magic-string": "^0.25.7",
41
41
  "mime-types": "^2.1.33",
42
+ "ms": "^2.1.3",
42
43
  "parse5-sax-parser": "^6.0.1",
43
44
  "path-to-regexp": "^6.2.0",
44
- "slugify": "^1.4.5",
45
- "winston": "^3.7.2"
45
+ "slugify": "^1.4.5"
46
46
  },
47
47
  "devDependencies": {
48
- "@lwrjs/diagnostics": "0.9.0-alpha.1",
49
- "@lwrjs/types": "0.9.0-alpha.1",
48
+ "@lwrjs/diagnostics": "0.9.0-alpha.11",
49
+ "@lwrjs/types": "0.9.0-alpha.11",
50
50
  "@types/mime-types": "2.1.1",
51
51
  "@types/path-to-regexp": "^1.7.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=14.15.4 <19"
55
55
  },
56
- "gitHead": "7a32c273de67d937fcbcd42293d9e251ed01f123"
56
+ "gitHead": "3cb1275b364ae7373c1868c79e6082a122dbef9c"
57
57
  }