@lwrjs/shared-utils 0.6.0-alpha.5 → 0.6.0-alpha.9

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.
@@ -67,7 +67,7 @@ async function extractMetadataFromHtml(htmlSource) {
67
67
  ceRefStack.push(ceRef);
68
68
  }
69
69
  }
70
- if (tagName === "img" && sourceCodeLocation.attrs) {
70
+ if ((tagName === "img" || tagName === "script") && sourceCodeLocation.attrs) {
71
71
  if (sourceCodeLocation.attrs.src) {
72
72
  assetReferences.push(parseAssetLocation(htmlSource, tagName, sourceCodeLocation.attrs.src));
73
73
  }
@@ -26,6 +26,7 @@ __exportStar(exports, __toModule(require("./interchangeable-modules.cjs")));
26
26
  __exportStar(exports, __toModule(require("./link.cjs")));
27
27
  __exportStar(exports, __toModule(require("./object.cjs")));
28
28
  __exportStar(exports, __toModule(require("./serialize.cjs")));
29
+ __exportStar(exports, __toModule(require("./tasks.cjs")));
29
30
  __exportStar(exports, __toModule(require("./typescript.cjs")));
30
31
  __exportStar(exports, __toModule(require("./import-metadata.cjs")));
31
32
  __exportStar(exports, __toModule(require("./graph.cjs")));
@@ -0,0 +1,72 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+
8
+ // packages/@lwrjs/shared-utils/src/tasks.ts
9
+ __markAsModule(exports);
10
+ __export(exports, {
11
+ InflightTasks: () => InflightTasks,
12
+ TaskPool: () => TaskPool
13
+ });
14
+ var Task = class {
15
+ constructor(taskFunction, caller, resolve, reject) {
16
+ this.taskFunction = taskFunction;
17
+ this.caller = caller;
18
+ this.resolve = resolve;
19
+ this.reject = reject;
20
+ }
21
+ };
22
+ var TaskPool = class {
23
+ constructor(size) {
24
+ this.queue = [];
25
+ this.running = 0;
26
+ this.size = size || 15;
27
+ }
28
+ async execute(taskFunction, caller) {
29
+ return new Promise((resolve, reject) => {
30
+ const task = new Task(taskFunction, caller || this, resolve, reject);
31
+ if (this.running >= this.size) {
32
+ this.queue.push(task);
33
+ } else {
34
+ this.start(task);
35
+ }
36
+ });
37
+ }
38
+ async start(task) {
39
+ this.running++;
40
+ try {
41
+ const ret = await task.taskFunction.bind(task.caller)();
42
+ task.resolve(ret);
43
+ } catch (err) {
44
+ task.reject(err);
45
+ } finally {
46
+ this.running--;
47
+ this.runNext();
48
+ }
49
+ }
50
+ runNext() {
51
+ const next = this.queue.shift();
52
+ if (next) {
53
+ this.start(next);
54
+ }
55
+ }
56
+ };
57
+ var InflightTasks = class {
58
+ constructor() {
59
+ this.tasks = new Map();
60
+ }
61
+ execute(id, taskCtor, caller) {
62
+ if (this.tasks.has(id)) {
63
+ return this.tasks.get(id);
64
+ } else {
65
+ const job = taskCtor.bind(caller || this)().finally(() => {
66
+ this.tasks.delete(id);
67
+ });
68
+ this.tasks.set(id, job);
69
+ return job;
70
+ }
71
+ }
72
+ };
@@ -46,7 +46,8 @@ export async function extractMetadataFromHtml(htmlSource) {
46
46
  }
47
47
  }
48
48
  // <img src="asset-url"/>
49
- if (tagName === 'img' && sourceCodeLocation.attrs) {
49
+ // <script type="text/javascript" src="asset-url"></script>
50
+ if ((tagName === 'img' || tagName === 'script') && sourceCodeLocation.attrs) {
50
51
  if (sourceCodeLocation.attrs.src) {
51
52
  assetReferences.push(parseAssetLocation(htmlSource, tagName, sourceCodeLocation.attrs.src));
52
53
  }
@@ -5,6 +5,7 @@ export * from './interchangeable-modules.js';
5
5
  export * from './link.js';
6
6
  export * from './object.js';
7
7
  export * from './serialize.js';
8
+ export * from './tasks.js';
8
9
  export * from './typescript.js';
9
10
  export * from './import-metadata.js';
10
11
  export * from './graph.js';
package/build/es/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './interchangeable-modules.js';
5
5
  export * from './link.js';
6
6
  export * from './object.js';
7
7
  export * from './serialize.js';
8
+ export * from './tasks.js';
8
9
  export * from './typescript.js';
9
10
  export * from './import-metadata.js';
10
11
  export * from './graph.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A pool is created of a given size
3
+ * If more tasks than that are asked to execute they are put in a queue until there is space in the pool
4
+ */
5
+ export declare class TaskPool {
6
+ private size;
7
+ private queue;
8
+ private running;
9
+ constructor(size?: number);
10
+ /**
11
+ * Add a function that takes no arguments
12
+ * It will run as soon as there is room in the pool
13
+ *
14
+ * @param taskFunction - Function to run when there is space in the pool
15
+ * @param caller - The closer to use when calling the constructor
16
+ **/
17
+ execute(taskFunction: Function, caller?: any): Promise<any>;
18
+ private start;
19
+ private runNext;
20
+ }
21
+ /**
22
+ * Contains a map of tasks that are in progress
23
+ * Calls to execute with the id of a task in progress returns the running tasks
24
+ * If no task of that id is running a new task is created
25
+ */
26
+ export declare class InflightTasks<Type> {
27
+ private tasks;
28
+ /**
29
+ * Return a promise per id. If one is already in flight return the promise.
30
+ * If not use the constructor to create a new
31
+ *
32
+ * @param id - Unique id for promise in question
33
+ * @param taskCtor - Function that create a promise for the id if needed
34
+ * @param caller - The closer to use when calling the constructor
35
+ */
36
+ execute(id: string, taskCtor: Function, caller?: any): Promise<Type>;
37
+ }
38
+ //# sourceMappingURL=tasks.d.ts.map
@@ -0,0 +1,98 @@
1
+ class Task {
2
+ constructor(taskFunction, caller, resolve, reject) {
3
+ this.taskFunction = taskFunction;
4
+ this.caller = caller;
5
+ this.resolve = resolve;
6
+ this.reject = reject;
7
+ }
8
+ }
9
+ /**
10
+ * A pool is created of a given size
11
+ * If more tasks than that are asked to execute they are put in a queue until there is space in the pool
12
+ */
13
+ export class TaskPool {
14
+ constructor(size) {
15
+ this.queue = [];
16
+ this.running = 0;
17
+ this.size = size || 15;
18
+ }
19
+ /**
20
+ * Add a function that takes no arguments
21
+ * It will run as soon as there is room in the pool
22
+ *
23
+ * @param taskFunction - Function to run when there is space in the pool
24
+ * @param caller - The closer to use when calling the constructor
25
+ **/
26
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
27
+ async execute(taskFunction, caller) {
28
+ return new Promise((resolve, reject) => {
29
+ const task = new Task(taskFunction, caller || this, resolve, reject);
30
+ if (this.running >= this.size) {
31
+ this.queue.push(task);
32
+ // TODO add to profiling
33
+ // console.log('[DEBUG] TaskPool Queue Size: ' + this.queue.length);
34
+ }
35
+ else {
36
+ this.start(task);
37
+ }
38
+ });
39
+ }
40
+ async start(task) {
41
+ // Add run next
42
+ this.running++;
43
+ try {
44
+ const ret = await task.taskFunction.bind(task.caller)();
45
+ task.resolve(ret);
46
+ }
47
+ catch (err) {
48
+ task.reject(err);
49
+ }
50
+ finally {
51
+ this.running--;
52
+ this.runNext();
53
+ }
54
+ }
55
+ runNext() {
56
+ const next = this.queue.shift();
57
+ if (next) {
58
+ // TODO add to profiling
59
+ // console.log('[DEBUG] TaskPool Queue Size: ' + this.queue.length);
60
+ this.start(next);
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * Contains a map of tasks that are in progress
66
+ * Calls to execute with the id of a task in progress returns the running tasks
67
+ * If no task of that id is running a new task is created
68
+ */
69
+ export class InflightTasks {
70
+ constructor() {
71
+ this.tasks = new Map();
72
+ }
73
+ /**
74
+ * Return a promise per id. If one is already in flight return the promise.
75
+ * If not use the constructor to create a new
76
+ *
77
+ * @param id - Unique id for promise in question
78
+ * @param taskCtor - Function that create a promise for the id if needed
79
+ * @param caller - The closer to use when calling the constructor
80
+ */
81
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
82
+ execute(id, taskCtor, caller) {
83
+ if (this.tasks.has(id)) {
84
+ return this.tasks.get(id);
85
+ }
86
+ else {
87
+ const job = taskCtor
88
+ .bind(caller || this)()
89
+ .finally(() => {
90
+ // Once fulfilled remove form active jobs
91
+ this.tasks.delete(id);
92
+ });
93
+ this.tasks.set(id, job);
94
+ return job;
95
+ }
96
+ }
97
+ }
98
+ //# sourceMappingURL=tasks.js.map
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.5",
8
- "homepage": "https://lwr.dev/",
7
+ "version": "0.6.0-alpha.9",
8
+ "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/salesforce/lwr.git",
@@ -43,13 +43,13 @@
43
43
  "slugify": "^1.4.5"
44
44
  },
45
45
  "devDependencies": {
46
- "@lwrjs/diagnostics": "0.6.0-alpha.5",
47
- "@lwrjs/types": "0.6.0-alpha.5",
46
+ "@lwrjs/diagnostics": "0.6.0-alpha.9",
47
+ "@lwrjs/types": "0.6.0-alpha.9",
48
48
  "@types/mime-types": "2.1.1",
49
49
  "@types/path-to-regexp": "^1.7.0"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=14.15.4 <17"
53
53
  },
54
- "gitHead": "56b2b35fd0a2b519c548c0e98c5136b0993ce73f"
54
+ "gitHead": "9cb371a5d01ef345660138a48fe0b3f0119d0799"
55
55
  }