@pbinj/pbj
Advanced tools
Comparing version
@@ -1,25 +0,23 @@ | ||
import { c as context, C as Context } from "./context-H3H9WYcD.js"; | ||
import { c as pbjKey } from "./pbjKey-Ci4CnftB.js"; | ||
const env$1 = process.env; | ||
const envPBinJKey = pbjKey("@pbj/env"); | ||
context.register(envPBinJKey, () => env$1); | ||
Context.prototype.env = function env2(envKey, defaultValue) { | ||
import { c as t, C as r } from "./context-N0Pib2IT.mjs"; | ||
import { c as p } from "./pbjKey-CAlNVDQg.mjs"; | ||
const s = process.env, n = p("@pbj/env"); | ||
t.register(n, () => s); | ||
r.prototype.env = function(e, i) { | ||
return this.register( | ||
Symbol.for(`@pbj/env/${envKey}`), | ||
this.pathOf(envPBinJKey, envKey, defaultValue) | ||
Symbol.for(`@pbj/env/${e}`), | ||
this.pathOf(n, e, i) | ||
).proxy; | ||
}; | ||
Context.prototype.envRequired = function envRequired2(envKey) { | ||
r.prototype.envRequired = function(e) { | ||
return this.register( | ||
Symbol.for(`@pbj/env/${envKey}`), | ||
this.pathOf(envPBinJKey, envKey) | ||
).withOptional(false).proxy; | ||
Symbol.for(`@pbj/env/${e}`), | ||
this.pathOf(n, e) | ||
).withOptional(!1).proxy; | ||
}; | ||
const env = context.env.bind(context); | ||
const envRequired = context.envRequired.bind(context); | ||
const f = t.env.bind(t), b = t.envRequired.bind(t); | ||
export { | ||
env, | ||
envPBinJKey, | ||
envRequired | ||
f as env, | ||
n as envPBinJKey, | ||
b as envRequired | ||
}; | ||
//# sourceMappingURL=env.js.map |
@@ -1,32 +0,31 @@ | ||
import { f, d, i, c, e, p, r, a, b, s } from "./pbjKey-Ci4CnftB.js"; | ||
import { c as context, C as Context } from "./context-H3H9WYcD.js"; | ||
import { a as a2, p as p2, s as s2 } from "./context-H3H9WYcD.js"; | ||
import { g as get } from "./logger-DaPImKKe.js"; | ||
Context.prototype.pathOf = function pathOf2(service, path, defaultValue) { | ||
return (ctx = this.pbj(service)) => get(ctx, path, defaultValue); | ||
import { f as x, d as h, i as v, c as j, e as l, p as K, r as S, a as d, b as u, s as O } from "./pbjKey-CAlNVDQg.mjs"; | ||
import { c as r, C as e } from "./context-N0Pib2IT.mjs"; | ||
import { a as C, p as D, s as N } from "./context-N0Pib2IT.mjs"; | ||
import { g as i } from "./logger-DMZuaXXP.mjs"; | ||
e.prototype.pathOf = function(t, s, a) { | ||
return (p = this.pbj(t)) => i(p, s, a); | ||
}; | ||
Context.prototype.transform = function transform2(service, transformer) { | ||
return this.pbj(() => transformer(this.resolve(service))); | ||
e.prototype.transform = function(t, s) { | ||
return this.pbj(() => s(this.resolve(t))); | ||
}; | ||
const transform = context.transform.bind(context); | ||
const pathOf = context.pathOf.bind(context); | ||
const f = r.transform.bind(r), c = r.pathOf.bind(r); | ||
export { | ||
Context, | ||
f as asString, | ||
context, | ||
a2 as createNewContext, | ||
d as destroySymbol, | ||
i as isPBinJKey, | ||
pathOf, | ||
p2 as pbj, | ||
c as pbjKey, | ||
e as pbjKeyName, | ||
p as proxyKey, | ||
r as removeSymbol, | ||
s2 as serviceDescriptor, | ||
a as serviceDescriptorKey, | ||
b as serviceProxySymbol, | ||
s as serviceSymbol, | ||
transform | ||
e as Context, | ||
x as asString, | ||
r as context, | ||
C as createNewContext, | ||
h as destroySymbol, | ||
v as isPBinJKey, | ||
c as pathOf, | ||
D as pbj, | ||
j as pbjKey, | ||
l as pbjKeyName, | ||
K as proxyKey, | ||
S as removeSymbol, | ||
N as serviceDescriptor, | ||
d as serviceDescriptorKey, | ||
u as serviceProxySymbol, | ||
O as serviceSymbol, | ||
f as transform | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,9 @@ | ||
import "./pbjKey-Ci4CnftB.js"; | ||
import { L, b, l, a } from "./logger-DaPImKKe.js"; | ||
import "./pbjKey-CAlNVDQg.mjs"; | ||
import { L as o, b as s, l as g, a as l } from "./logger-DMZuaXXP.mjs"; | ||
export { | ||
L as Logger, | ||
b as formatStr, | ||
l as levels, | ||
a as loggerPBinJKey | ||
o as Logger, | ||
s as formatStr, | ||
g as levels, | ||
l as loggerPBinJKey | ||
}; | ||
//# sourceMappingURL=logger.js.map |
@@ -1,8 +0,8 @@ | ||
import { f, i, c, e } from "./pbjKey-Ci4CnftB.js"; | ||
import { f as s, i, c as p, e as r } from "./pbjKey-CAlNVDQg.mjs"; | ||
export { | ||
f as asString, | ||
s as asString, | ||
i as isPBinJKey, | ||
c as pbjKey, | ||
e as pbjKeyName | ||
p as pbjKey, | ||
r as pbjKeyName | ||
}; | ||
//# sourceMappingURL=pbjKey.js.map |
@@ -1,5 +0,5 @@ | ||
import { h as hasA, g as isSymbol, b as serviceProxySymbol, j as has, k as isFn } from "./pbjKey-Ci4CnftB.js"; | ||
import { C as Context, P as PBinJError, S as ServiceDescriptor } from "./context-H3H9WYcD.js"; | ||
import { k as keyOf } from "./logger-DaPImKKe.js"; | ||
class BrowserAsyncStorage { | ||
import { h as S, g, b as o, j as p, k as l } from "./pbjKey-CAlNVDQg.mjs"; | ||
import { C as m, P as s, S as u } from "./context-N0Pib2IT.mjs"; | ||
import { k as f } from "./logger-DMZuaXXP.mjs"; | ||
class d { | ||
constructor() { | ||
@@ -17,6 +17,6 @@ this.contextStack = []; | ||
*/ | ||
run(store, callback) { | ||
this.contextStack.push(store); | ||
run(e, r) { | ||
this.contextStack.push(e); | ||
try { | ||
return callback(); | ||
return r(); | ||
} finally { | ||
@@ -27,49 +27,38 @@ this.contextStack.pop(); | ||
} | ||
const asyncLocalStorage = new BrowserAsyncStorage(); | ||
const scoped = function(key) { | ||
const serviceDesc = this.register(key); | ||
if (hasA(serviceDesc, serviceProxySymbol, isSymbol) && serviceDesc[serviceProxySymbol] !== keyOf(key)) { | ||
throw new PBinJError( | ||
`key ${String(key)} already registered as '${String(serviceDesc[serviceProxySymbol])}', can not register a key into more than one scope` | ||
const a = new d(), y = function(t) { | ||
const e = this.register(t); | ||
if (S(e, o, g) && e[o] !== f(t)) | ||
throw new s( | ||
`key ${String(t)} already registered as '${String(e[o])}', can not register a key into more than one scope` | ||
); | ||
} | ||
if (has(serviceDesc, asyncLocalSymbol)) { | ||
throw new PBinJError( | ||
`key ${String(key)} already registered as async scoped, can not register a key into more than one scope` | ||
if (p(e, i)) | ||
throw new s( | ||
`key ${String(t)} already registered as async scoped, can not register a key into more than one scope` | ||
); | ||
} | ||
serviceDesc.withInterceptors(() => { | ||
return getServiceDescription(key).invoke(); | ||
}); | ||
serviceDesc[asyncLocalSymbol] = key; | ||
return (next, ...[service, ...args]) => { | ||
const map = asyncLocalStorage.getStore() ?? /* @__PURE__ */ new Map(); | ||
if (!map.has(key)) { | ||
map.set( | ||
key, | ||
new ServiceDescriptor( | ||
key, | ||
service, | ||
args, | ||
false, | ||
isFn(service), | ||
`async scoped pbj '${String(key)}'` | ||
) | ||
); | ||
} | ||
return asyncLocalStorage.run(map, next); | ||
return e.withInterceptors(() => w(t).invoke()), e[i] = t, (r, ...[c, ...h]) => { | ||
const n = a.getStore() ?? /* @__PURE__ */ new Map(); | ||
return n.has(t) || n.set( | ||
t, | ||
new u( | ||
t, | ||
c, | ||
h, | ||
!1, | ||
l(c), | ||
`async scoped pbj '${String(t)}'` | ||
) | ||
), a.run(n, r); | ||
}; | ||
}; | ||
function getServiceDescription(key) { | ||
var _a; | ||
const serviceDesc = (_a = asyncLocalStorage.getStore()) == null ? void 0 : _a.get(key); | ||
if (!serviceDesc) { | ||
throw new PBinJError( | ||
`key ${String(key)} not found in async storage, make sure the callback has been handled.` | ||
function w(t) { | ||
var r; | ||
const e = (r = a.getStore()) == null ? void 0 : r.get(t); | ||
if (!e) | ||
throw new s( | ||
`key ${String(t)} not found in async storage, make sure the callback has been handled.` | ||
); | ||
} | ||
return serviceDesc; | ||
return e; | ||
} | ||
Context.prototype.scoped = scoped; | ||
const asyncLocalSymbol = Symbol(); | ||
m.prototype.scoped = y; | ||
const i = Symbol(); | ||
//# sourceMappingURL=scope.js.map |
{ | ||
"name": "@pbinj/pbj", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"license": "MIT", | ||
"description": "A lightweight Dependency Injection (DI) framework for Node.js, based on proxies.", | ||
"typings": "./dist/esm/index.d.ts", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/esm/index.d.ts", | ||
"import": "./dist/esm/index.js", | ||
"browser": "./dist/browser/index.js", | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js" | ||
@@ -17,4 +16,4 @@ }, | ||
"types": "./dist/esm/env.d.ts", | ||
"import": "./dist/esm/env.js", | ||
"browser": "./dist/browser/env.js", | ||
"import": "./dist/esm/env.js", | ||
"require": "./dist/cjs/env.js" | ||
@@ -66,3 +65,2 @@ }, | ||
"vite": "^6.0.6", | ||
"vite-tsconfig-paths": "^5.1.2", | ||
"vitest": "^2.1.8" | ||
@@ -74,3 +72,3 @@ }, | ||
"dependencies": { | ||
"@pbinj/pbj-guards": "3.0.2" | ||
"@pbinj/pbj-guards": "3.0.3" | ||
}, | ||
@@ -81,3 +79,3 @@ "sideEffects": false, | ||
"test:watch": "vitest watch", | ||
"build-esm": "tsc", | ||
"build-esm": "tsc -p tsconfig.esm.json", | ||
"build-cjs": "tsc -p tsconfig.cjs.json", | ||
@@ -84,0 +82,0 @@ "build-browser": "vite build", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
7
-12.5%284065
-2.62%5469
-6.24%No
NaN+ Added
- Removed
Updated