aquinas 0.0.4 → 0.0.6
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/index.cjs +1 -1
- package/dist/index.d.cts +10 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@owja/ioc"),t=
|
|
1
|
+
"use strict";var e=require("@owja/ioc"),t=class extends Error{constructor(e,t){const n=t?"string"==typeof t?t:t.message:"no additional info";super(n?`${e} - ${n}`:e),this.name="AquinasError"}},n=class{constructor(e){this.name=e,this.id=Symbol.for(e),this.toJSON=()=>e}id;__type;toJSON};function r(e){return e instanceof n}var i=class{reference;implementation;constructor(e,t){this.reference=e,this.implementation=t}},o=class e{constructor(e,t={},n){this.reference=e,this.refs=t,this.stateFactory=n}deps(t){return new e(this.reference,{...this.refs,...t},this.stateFactory)}init(t){return new e(this.reference,this.refs,t)}implements(e){const t=(e,t={})=>({...t,...this.stateFactory?this.stateFactory(t):{},ctx:e??f()});return new i(this.reference,n=>{const r=n.get(this.refs);return e(t(n,r))})}};function c(e){return e instanceof i}var s=class{referenceRegistry;bindingRegistry;container;constructor(){this.container=new e.Container,this.referenceRegistry=new Set,this.bindingRegistry=new Map}bindReference(e,n,r){this.referenceRegistry.add(e),this.bindingRegistry.set(e,n);try{r?.rebind?this.container.rebind(e.id).toFactory(()=>n(this)).inSingletonScope():this.container.bind(e.id).toFactory(()=>n(this)).inSingletonScope()}catch(n){throw new t(`failed to bind reference with name "${e.name}"`,n)}}merge(...e){for(const n of e){if(!a(n))throw new t("Invalid dock","expected a Dock object but got "+typeof n);for(const e of n.referenceRegistry){const r=n.bindingRegistry.get(e);if(!r)throw new t("Missing implementation during merge");this.bindReference(e,r)}}}add(...e){for(const n of e){if(!c(n))throw new t("Invalid injectable","expected an Injectable object but got "+typeof n);this.bindReference(n.reference,n.implementation)}}update(e,n){if(!c(n)&&"function"!=typeof n)throw new t("Invalid update","expected an Injectable or implementation function but got "+typeof n);c(n)?this.update(e,n.implementation):this.bindReference(e,n,{rebind:!0})}delete(e){if(!r(e))throw new t("Invalid reference","expected a Reference object but got "+typeof e);this.referenceRegistry.delete(e),this.bindingRegistry.delete(e),this.container.remove(e.id)}get(...e){if(e.length>1){const n=[];for(const i of e){if(!r(i))throw new t("Invalid reference","expected a Reference object but got "+typeof i);try{n.push(this.container.get(i.id))}catch(e){throw new t(`Failed to get reference with name "${i.name}"`,e)}}return n}const n=e[0];if("id"in n){if(!r(n))throw new t("Invalid reference","expected a Reference object but got "+typeof n);try{return this.container.get(n.id)}catch(e){throw new t(`Failed to get reference with name "${n.name}"`,e)}}const i={};for(const e in n){const o=n[e];if(!r(o))throw new t(`Invalid reference for key "${e}"`,"expected a Reference object but got "+typeof o);i[e]=this.container.get(o.id)}return i}safeGet(e){if(!r(e))throw new t("Invalid reference","expected a Reference object but got "+typeof e);try{return this.container.get(e.id)}catch{return}}find(e){return Array.from(this.referenceRegistry).filter(e)}};function f(){return new s}function a(e){return e instanceof s}exports.cloneDock=function(e){const t=new s;return t.merge(e),t},exports.derivedReference=function(e,t){return new n(`${e}:${t.toJSON()}`)},exports.dock=f,exports.injectable=function(e){return new o(e)},exports.reference=function(e){return new n(e)};
|
package/dist/index.d.cts
CHANGED
|
@@ -38,11 +38,18 @@ declare class Dock {
|
|
|
38
38
|
constructor();
|
|
39
39
|
private bindReference;
|
|
40
40
|
merge(...sources: Dock[]): void;
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
add(...bindables: Injectable[]): void;
|
|
42
|
+
update(reference: Reference<any>, injectableOrImplementation: Injectable | InjectableImplementation<any>): void;
|
|
43
43
|
delete<T>(reference: Reference<T>): void;
|
|
44
|
-
get<
|
|
44
|
+
get<U>(reference: Reference<U>): U;
|
|
45
|
+
get<T extends Record<string, Reference<any>>>(reference: T): {
|
|
46
|
+
[K in keyof T]: T[K] extends Reference<infer V> ? V : never;
|
|
47
|
+
};
|
|
48
|
+
get<T extends readonly Reference<any>[]>(...references: T): {
|
|
49
|
+
[K in keyof T]: T[K] extends Reference<infer V> ? V : never;
|
|
50
|
+
};
|
|
45
51
|
safeGet<T>(reference: Reference<T>): T | undefined;
|
|
52
|
+
find(predicate: (reference: Reference<any>) => boolean): Reference<any>[];
|
|
46
53
|
}
|
|
47
54
|
declare function dock(): Dock;
|
|
48
55
|
declare function cloneDock(source: Dock): Dock;
|