wardens 0.5.1-2025-02-04.4ddf455 → 0.5.1-2025-02-09.00bcd63

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/wardens.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var B=Object.defineProperty;var j=e=>{throw TypeError(e)};var M=(e,t,r)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var f=(e,t,r)=>M(e,typeof t!="symbol"?t+"":t,r),k=(e,t,r)=>t.has(e)||j("Cannot "+r);var s=(e,t,r)=>(k(e,t,"read from private field"),r?r.call(e):t.get(e)),d=(e,t,r)=>t.has(e)?j("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),h=(e,t,r,o)=>(k(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function A(e){const t=new WeakMap;return new Proxy(e,{get(r,o){const n=Reflect.get(r,o,r);if(typeof n=="function"){if(t.has(n)===!1){const a=n.bind(r);Object.defineProperties(a,Object.getOwnPropertyDescriptors(n)),t.set(n,a)}return t.get(n)}return n},set(r,o,n){return Reflect.set(r,o,n,r)}})}const g=new WeakMap,E=new WeakSet,P=new WeakSet;function T(e){return Proxy.revocable(e,{})}var C,w;class x{constructor(t){d(this,C,Symbol("Context ID"));d(this,w);h(this,w,t)}static getId(t){return s(t,C)}static getDefaultValue(t){var r;return s(r=t,w).call(r)}}C=new WeakMap,w=new WeakMap;const V=e=>new x(e);var y,l,p,i;class H{constructor(t,r,o){d(this,y,new WeakSet);d(this,l);d(this,p);d(this,i);f(this,"create",async(t,...r)=>{if(s(this,p).enforced)throw new Error("Cannot create new resources after teardown.");const o=Object.create(s(this,i)),n=await D(o,t,...r);return s(this,l).add(n),n});f(this,"destroy",async t=>{if(s(this,y).has(t))throw new Error("Resource already destroyed.");if(!s(this,l).has(t))throw new Error("You do not own this resource.");s(this,l).delete(t),s(this,y).add(t),await m(t)});f(this,"setContext",(t,r)=>(s(this,i)[x.getId(t)]=r,r));f(this,"getContext",t=>{const r=x.getId(t);return r in s(this,i)?s(this,i)[r]:x.getDefaultValue(t)});h(this,i,t),h(this,l,r),h(this,p,o)}}y=new WeakMap,l=new WeakMap,p=new WeakMap,i=new WeakMap;const D=async(e,t,...r)=>{const o={enforced:!1},n=new Set,a=new H(e,n,o);let c;try{c=await t(a,...r)}catch(S){const R=Array.from(n).reverse(),v=(await Promise.allSettled(R.map(u=>a.destroy(u)))).filter(u=>u.status==="rejected");throw v.length?W(v.map(u=>u.reason),{cause:S}):S}const I=c.value,{proxy:b,revoke:O}=T(I);return E.add(b),g.set(b,{curfew:o,resource:c,children:n,revoke:O}),b},m=async e=>{if(!E.has(e))throw new Error("Cannot destroy object. It is not a resource.");const t=g.get(e);if(t){g.delete(e),t.revoke();let r={status:"fulfilled",value:void 0};if(t.resource.destroy)try{await t.resource.destroy()}catch(c){r={status:"rejected",reason:c}}t.curfew.enforced=!0;const o=Array.from(t.children).reverse().map(m),n=await Promise.allSettled(o),a=[r].concat(n).filter(c=>c.status==="rejected");if(a.length)throw W(a.map(c=>c.reason))}},W=(e,t)=>e.length===1?e[0]:new U(e,t);class U extends Error{constructor(t,r){super("Some resources could not be destroyed. See the `failures` property for details.",r),this.failures=t}}const Y=async(e,...t)=>{const o=await D(Object.create(null),e,...t);return P.add(o),o},q=async e=>{if(g.has(e)&&!P.has(e))throw new Error("Cannot destroy child resource. It is owned by another scope.");return m(e)};exports.bindContext=A;exports.create=Y;exports.createContext=V;exports.destroy=q;
1
+ "use strict";var B=Object.defineProperty;var v=t=>{throw TypeError(t)};var M=(t,e,r)=>e in t?B(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var f=(t,e,r)=>M(t,typeof e!="symbol"?e+"":e,r),k=(t,e,r)=>e.has(t)||v("Cannot "+r);var s=(t,e,r)=>(k(t,e,"read from private field"),r?r.call(t):e.get(t)),d=(t,e,r)=>e.has(t)?v("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),h=(t,e,r,o)=>(k(t,e,"write to private field"),o?o.call(t,r):e.set(t,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function A(t){const e=new WeakMap;return new Proxy(t,{get(r,o){const n=Reflect.get(r,o,r);if(typeof n=="function"){if(e.has(n)===!1){const a=n.bind(r);Object.defineProperties(a,Object.getOwnPropertyDescriptors(n)),e.set(n,a)}return e.get(n)}return n},set(r,o,n){return Reflect.set(r,o,n,r)}})}const g=new WeakMap,E=new WeakSet,P=new WeakSet;function T(t){return Proxy.revocable(t,{})}var C,w;class x{constructor(e){d(this,C,Symbol("Context ID"));d(this,w);h(this,w,e)}static getId(e){return s(e,C)}static getDefaultValue(e){var r;return s(r=e,w).call(r)}}C=new WeakMap,w=new WeakMap;const V=t=>new x(t);var y,u,p,i;class H{constructor(e,r,o){d(this,y,new WeakSet);d(this,u);d(this,p);d(this,i);f(this,"create",async(e,...r)=>{if(s(this,p).enforced)throw new Error("Cannot create new resources after teardown.");const o=Object.create(s(this,i)),n=await D(o,e,...r);return s(this,u).add(n),n});f(this,"destroy",async e=>{if(s(this,y).has(e))throw new Error("Resource already destroyed.");if(!s(this,u).has(e))throw new Error("You do not own this resource.");s(this,u).delete(e),s(this,y).add(e),await m(e)});f(this,"setContext",(e,r)=>(s(this,i)[x.getId(e)]=r,r));f(this,"getContext",e=>{const r=x.getId(e);return r in s(this,i)?s(this,i)[r]:x.getDefaultValue(e)});h(this,i,e),h(this,u,r),h(this,p,o)}}y=new WeakMap,u=new WeakMap,p=new WeakMap,i=new WeakMap;const D=async(t,e,...r)=>{const o={enforced:!1},n=new Set,a=new H(t,n,o);let c;try{c=await e(a,...r)}catch(S){const R=Array.from(n).reverse(),j=(await Promise.allSettled(R.map(l=>a.destroy(l)))).filter(l=>l.status==="rejected");throw j.length?W(j.map(l=>l.reason),{cause:S}):S}const I=c.value,{proxy:b,revoke:O}=T(I);return E.add(b),g.set(b,{curfew:o,resource:c,children:n,revoke:O}),b},m=async t=>{if(!E.has(t))throw new Error("Cannot destroy object. It is not a resource.");const e=g.get(t);if(e){g.delete(t),e.revoke();let r={status:"fulfilled",value:void 0};if(e.resource.destroy)try{await e.resource.destroy()}catch(c){r={status:"rejected",reason:c}}e.curfew.enforced=!0;const o=Array.from(e.children).reverse().map(m),n=await Promise.allSettled(o),a=[r].concat(n).filter(c=>c.status==="rejected");if(a.length)throw W(a.map(c=>c.reason))}},W=(t,e)=>t.length===1?t[0]:new U(t,e);class U extends Error{constructor(e,r){super("Some resources could not be destroyed. See the `failures` property for details.",r),this.failures=e}}const Y=async(t,...e)=>{const o=await D(Object.create(null),t,...e);return P.add(o),o},q=async t=>{if(g.has(t)&&!P.has(t))throw new Error("Cannot destroy child resource. It is owned by another scope.");return m(t)};exports.bindContext=A;exports.create=Y;exports.createContext=V;exports.destroy=q;
package/dist/wardens.js CHANGED
@@ -1,24 +1,24 @@
1
1
  var B = Object.defineProperty;
2
- var j = (e) => {
3
- throw TypeError(e);
2
+ var k = (t) => {
3
+ throw TypeError(t);
4
4
  };
5
- var A = (e, t, r) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
6
- var h = (e, t, r) => A(e, typeof t != "symbol" ? t + "" : t, r), k = (e, t, r) => t.has(e) || j("Cannot " + r);
7
- var n = (e, t, r) => (k(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? j("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), f = (e, t, r, o) => (k(e, t, "write to private field"), o ? o.call(e, r) : t.set(e, r), r);
8
- function Y(e) {
9
- const t = /* @__PURE__ */ new WeakMap();
10
- return new Proxy(e, {
5
+ var A = (t, e, r) => e in t ? B(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
6
+ var f = (t, e, r) => A(t, typeof e != "symbol" ? e + "" : e, r), v = (t, e, r) => e.has(t) || k("Cannot " + r);
7
+ var n = (t, e, r) => (v(t, e, "read from private field"), r ? r.call(t) : e.get(t)), d = (t, e, r) => e.has(t) ? k("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), h = (t, e, r, o) => (v(t, e, "write to private field"), o ? o.call(t, r) : e.set(t, r), r);
8
+ function Y(t) {
9
+ const e = /* @__PURE__ */ new WeakMap();
10
+ return new Proxy(t, {
11
11
  get(r, o) {
12
12
  const s = Reflect.get(r, o, r);
13
13
  if (typeof s == "function") {
14
- if (t.has(s) === !1) {
14
+ if (e.has(s) === !1) {
15
15
  const a = s.bind(r);
16
16
  Object.defineProperties(
17
17
  a,
18
18
  Object.getOwnPropertyDescriptors(s)
19
- ), t.set(s, a);
19
+ ), e.set(s, a);
20
20
  }
21
- return t.get(s);
21
+ return e.get(s);
22
22
  }
23
23
  return s;
24
24
  },
@@ -28,75 +28,75 @@ function Y(e) {
28
28
  });
29
29
  }
30
30
  const g = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakSet(), D = /* @__PURE__ */ new WeakSet();
31
- function M(e) {
32
- return Proxy.revocable(e, {});
31
+ function M(t) {
32
+ return Proxy.revocable(t, {});
33
33
  }
34
34
  var m, w;
35
35
  class x {
36
- constructor(t) {
36
+ constructor(e) {
37
37
  d(this, m, Symbol("Context ID"));
38
38
  d(this, w);
39
- f(this, w, t);
39
+ h(this, w, e);
40
40
  }
41
- static getId(t) {
42
- return n(t, m);
41
+ static getId(e) {
42
+ return n(e, m);
43
43
  }
44
- static getDefaultValue(t) {
44
+ static getDefaultValue(e) {
45
45
  var r;
46
- return n(r = t, w).call(r);
46
+ return n(r = e, w).call(r);
47
47
  }
48
48
  }
49
49
  m = new WeakMap(), w = new WeakMap();
50
- const q = (e) => new x(e);
51
- var y, l, p, i;
50
+ const q = (t) => new x(t);
51
+ var y, u, p, i;
52
52
  class V {
53
- constructor(t, r, o) {
53
+ constructor(e, r, o) {
54
54
  d(this, y, /* @__PURE__ */ new WeakSet());
55
- d(this, l);
55
+ d(this, u);
56
56
  d(this, p);
57
57
  d(this, i);
58
58
  /** Provision an owned resource and make sure it doesn't outlive us. */
59
- h(this, "create", async (t, ...r) => {
59
+ f(this, "create", async (e, ...r) => {
60
60
  if (n(this, p).enforced)
61
61
  throw new Error("Cannot create new resources after teardown.");
62
- const o = Object.create(n(this, i)), s = await P(o, t, ...r);
63
- return n(this, l).add(s), s;
62
+ const o = Object.create(n(this, i)), s = await P(o, e, ...r);
63
+ return n(this, u).add(s), s;
64
64
  });
65
65
  /**
66
66
  * Tear down a resource. Happens automatically when resource owners are
67
67
  * deallocated.
68
68
  */
69
- h(this, "destroy", async (t) => {
70
- if (n(this, y).has(t))
69
+ f(this, "destroy", async (e) => {
70
+ if (n(this, y).has(e))
71
71
  throw new Error("Resource already destroyed.");
72
- if (!n(this, l).has(t))
72
+ if (!n(this, u).has(e))
73
73
  throw new Error("You do not own this resource.");
74
- n(this, l).delete(t), n(this, y).add(t), await b(t);
74
+ n(this, u).delete(e), n(this, y).add(e), await b(e);
75
75
  });
76
76
  /** Store a value in context. Anything down the chain can read it. */
77
- h(this, "setContext", (t, r) => (n(this, i)[x.getId(t)] = r, r));
77
+ f(this, "setContext", (e, r) => (n(this, i)[x.getId(e)] = r, r));
78
78
  /** Retrieve a value from context, or a default if it is unset. */
79
- h(this, "getContext", (t) => {
80
- const r = x.getId(t);
81
- return r in n(this, i) ? n(this, i)[r] : x.getDefaultValue(t);
79
+ f(this, "getContext", (e) => {
80
+ const r = x.getId(e);
81
+ return r in n(this, i) ? n(this, i)[r] : x.getDefaultValue(e);
82
82
  });
83
- f(this, i, t), f(this, l, r), f(this, p, o);
83
+ h(this, i, e), h(this, u, r), h(this, p, o);
84
84
  }
85
85
  }
86
- y = new WeakMap(), l = new WeakMap(), p = new WeakMap(), i = new WeakMap();
87
- const P = async (e, t, ...r) => {
88
- const o = { enforced: !1 }, s = /* @__PURE__ */ new Set(), a = new V(e, s, o);
86
+ y = new WeakMap(), u = new WeakMap(), p = new WeakMap(), i = new WeakMap();
87
+ const P = async (t, e, ...r) => {
88
+ const o = { enforced: !1 }, s = /* @__PURE__ */ new Set(), a = new V(t, s, o);
89
89
  let c;
90
90
  try {
91
- c = await t(a, ...r);
91
+ c = await e(a, ...r);
92
92
  } catch (S) {
93
- const O = Array.from(s).reverse(), v = (await Promise.allSettled(
94
- O.map((u) => a.destroy(u))
93
+ const O = Array.from(s).reverse(), j = (await Promise.allSettled(
94
+ O.map((l) => a.destroy(l))
95
95
  )).filter(
96
- (u) => u.status === "rejected"
96
+ (l) => l.status === "rejected"
97
97
  );
98
- throw v.length ? W(
99
- v.map((u) => u.reason),
98
+ throw j.length ? W(
99
+ j.map((l) => l.reason),
100
100
  { cause: S }
101
101
  ) : S;
102
102
  }
@@ -107,47 +107,47 @@ const P = async (e, t, ...r) => {
107
107
  children: s,
108
108
  revoke: R
109
109
  }), C;
110
- }, b = async (e) => {
111
- if (!E.has(e))
110
+ }, b = async (t) => {
111
+ if (!E.has(t))
112
112
  throw new Error("Cannot destroy object. It is not a resource.");
113
- const t = g.get(e);
114
- if (t) {
115
- g.delete(e), t.revoke();
113
+ const e = g.get(t);
114
+ if (e) {
115
+ g.delete(t), e.revoke();
116
116
  let r = {
117
117
  status: "fulfilled",
118
118
  value: void 0
119
119
  };
120
- if (t.resource.destroy)
120
+ if (e.resource.destroy)
121
121
  try {
122
- await t.resource.destroy();
122
+ await e.resource.destroy();
123
123
  } catch (c) {
124
124
  r = { status: "rejected", reason: c };
125
125
  }
126
- t.curfew.enforced = !0;
127
- const o = Array.from(t.children).reverse().map(b), s = await Promise.allSettled(o), a = [r].concat(s).filter(
126
+ e.curfew.enforced = !0;
127
+ const o = Array.from(e.children).reverse().map(b), s = await Promise.allSettled(o), a = [r].concat(s).filter(
128
128
  (c) => c.status === "rejected"
129
129
  );
130
130
  if (a.length)
131
131
  throw W(a.map((c) => c.reason));
132
132
  }
133
- }, W = (e, t) => e.length === 1 ? e[0] : new H(e, t);
133
+ }, W = (t, e) => t.length === 1 ? t[0] : new H(t, e);
134
134
  class H extends Error {
135
- constructor(t, r) {
135
+ constructor(e, r) {
136
136
  super(
137
137
  "Some resources could not be destroyed. See the `failures` property for details.",
138
138
  r
139
- ), this.failures = t;
139
+ ), this.failures = e;
140
140
  }
141
141
  }
142
- const z = async (e, ...t) => {
143
- const o = await P(/* @__PURE__ */ Object.create(null), e, ...t);
142
+ const z = async (t, ...e) => {
143
+ const o = await P(/* @__PURE__ */ Object.create(null), t, ...e);
144
144
  return D.add(o), o;
145
- }, F = async (e) => {
146
- if (g.has(e) && !D.has(e))
145
+ }, F = async (t) => {
146
+ if (g.has(t) && !D.has(t))
147
147
  throw new Error(
148
148
  "Cannot destroy child resource. It is owned by another scope."
149
149
  );
150
- return b(e);
150
+ return b(t);
151
151
  };
152
152
  export {
153
153
  Y as bindContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wardens",
3
- "version": "0.5.1-2025-02-04.4ddf455",
3
+ "version": "0.5.1-2025-02-09.00bcd63",
4
4
  "description": "A framework for resource management",
5
5
  "type": "module",
6
6
  "main": "./dist/wardens.cjs",