@workglow/task-graph 0.2.3 → 0.2.5

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/dist/browser.js CHANGED
@@ -294,16 +294,32 @@ function entitlementCovers(granted, required) {
294
294
  function resourcePatternMatches(grantPattern, requiredResource) {
295
295
  if (grantPattern === requiredResource)
296
296
  return true;
297
- const starIdx = grantPattern.indexOf("*");
298
- if (starIdx === -1)
297
+ if (!grantPattern.includes("*"))
299
298
  return false;
300
- const prefix = grantPattern.slice(0, starIdx);
301
- const suffix = grantPattern.slice(starIdx + 1);
302
- if (!requiredResource.startsWith(prefix))
299
+ const parts = grantPattern.split("*");
300
+ const first = parts[0];
301
+ const last = parts[parts.length - 1];
302
+ if (!requiredResource.startsWith(first))
303
303
  return false;
304
- if (!requiredResource.endsWith(suffix))
304
+ if (!requiredResource.endsWith(last))
305
305
  return false;
306
- return requiredResource.length >= prefix.length + suffix.length;
306
+ let fixedLength = 0;
307
+ for (const p of parts)
308
+ fixedLength += p.length;
309
+ if (requiredResource.length < fixedLength)
310
+ return false;
311
+ let searchStart = first.length;
312
+ const searchEnd = requiredResource.length - last.length;
313
+ for (let i = 1;i < parts.length - 1; i++) {
314
+ const part = parts[i];
315
+ if (part.length === 0)
316
+ continue;
317
+ const idx = requiredResource.indexOf(part, searchStart);
318
+ if (idx === -1 || idx + part.length > searchEnd)
319
+ return false;
320
+ searchStart = idx + part.length;
321
+ }
322
+ return true;
307
323
  }
308
324
  function grantCoversResources(grant, required) {
309
325
  if (grant.resources === undefined)
@@ -1371,6 +1387,9 @@ class TaskRunner {
1371
1387
  signal: this.abortController?.signal
1372
1388
  });
1373
1389
  }
1390
+ if (this.task.constructor.hasDynamicEntitlements) {
1391
+ this.task.emit("entitlementChange", this.task.entitlements());
1392
+ }
1374
1393
  return i;
1375
1394
  }
1376
1395
  async executeTask(input) {
@@ -3551,6 +3570,73 @@ class GraphAsTask extends Task {
3551
3570
  this.events.emit("regenerate");
3552
3571
  this.emitEntitlementChange();
3553
3572
  }
3573
+ _entitlementUnsub;
3574
+ _subscribingEntitlements = false;
3575
+ _subscribeToSubGraphEntitlements(graph) {
3576
+ this._entitlementUnsub?.();
3577
+ this._entitlementUnsub = undefined;
3578
+ this._subscribingEntitlements = true;
3579
+ try {
3580
+ this._entitlementUnsub = graph.subscribeToTaskEntitlements(() => {
3581
+ this.emitEntitlementChange();
3582
+ });
3583
+ } finally {
3584
+ this._subscribingEntitlements = false;
3585
+ }
3586
+ }
3587
+ _syncSubGraphEntitlementSubscription(graph = this._subGraph) {
3588
+ if (this._subscribingEntitlements)
3589
+ return;
3590
+ if ((this._events?.listenerCount("entitlementChange") ?? 0) === 0) {
3591
+ this._entitlementUnsub?.();
3592
+ this._entitlementUnsub = undefined;
3593
+ return;
3594
+ }
3595
+ if (!graph || this._entitlementUnsub) {
3596
+ return;
3597
+ }
3598
+ this._subscribeToSubGraphEntitlements(graph);
3599
+ }
3600
+ subscribe(name, fn) {
3601
+ const unsub = super.subscribe(name, fn);
3602
+ if (name !== "entitlementChange") {
3603
+ return unsub;
3604
+ }
3605
+ this._syncSubGraphEntitlementSubscription();
3606
+ return () => {
3607
+ unsub();
3608
+ this._syncSubGraphEntitlementSubscription();
3609
+ };
3610
+ }
3611
+ on(name, fn) {
3612
+ super.on(name, fn);
3613
+ if (name === "entitlementChange") {
3614
+ this._syncSubGraphEntitlementSubscription();
3615
+ }
3616
+ }
3617
+ off(name, fn) {
3618
+ super.off(name, fn);
3619
+ if (name === "entitlementChange") {
3620
+ this._syncSubGraphEntitlementSubscription();
3621
+ }
3622
+ }
3623
+ once(name, fn) {
3624
+ super.once(name, fn);
3625
+ if (name === "entitlementChange") {
3626
+ this._syncSubGraphEntitlementSubscription();
3627
+ }
3628
+ }
3629
+ set subGraph(subGraph) {
3630
+ this._entitlementUnsub?.();
3631
+ this._entitlementUnsub = undefined;
3632
+ super.subGraph = subGraph;
3633
+ this._syncSubGraphEntitlementSubscription(subGraph);
3634
+ }
3635
+ get subGraph() {
3636
+ const graph = super.subGraph;
3637
+ this._syncSubGraphEntitlementSubscription(graph);
3638
+ return graph;
3639
+ }
3554
3640
  toJSON(options) {
3555
3641
  let json = super.toJSON(options);
3556
3642
  const hasChildren = this.hasChildren();
@@ -8122,4 +8208,4 @@ export {
8122
8208
  BROWSER_GRANTS
8123
8209
  };
8124
8210
 
8125
- //# debugId=B6E689E8C44EE76C64756E2164756E21
8211
+ //# debugId=7A0EA069F263434964756E2164756E21