aquinas 0.0.6 → 0.0.8

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 CHANGED
@@ -1 +1 @@
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)};
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 e{constructor(e){this.name=e,this.id=Symbol.for(e),this.toJSON=()=>e}id;__type;toJSON;type(){return new e(this.name)}},r=e=>new n(e);function i(e){return e instanceof n}r.create=e=>new n(e);var o=class{reference;implementation;constructor(e,t){this.reference=e,this.implementation=t}},c=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 o(this.reference,n=>{const r=n.get(this.refs);return e(t(n,r))})}};function s(e){return e instanceof o}var a=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(!d(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(!s(n))throw new t("Invalid injectable","expected an Injectable object but got "+typeof n);this.bindReference(n.reference,n.implementation)}}update(e,n){if(!s(n)&&"function"!=typeof n)throw new t("Invalid update","expected an Injectable or implementation function but got "+typeof n);s(n)?this.update(e,n.implementation):this.bindReference(e,n,{rebind:!0})}delete(e){if(!i(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 r of e){if(!i(r))throw new t("Invalid reference","expected a Reference object but got "+typeof r);try{n.push(this.container.get(r.id))}catch(e){throw new t(`Failed to get reference with name "${r.name}"`,e)}}return n}const n=e[0];if("id"in n){if(!i(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 r={};for(const e in n){const o=n[e];if(!i(o))throw new t(`Invalid reference for key "${e}"`,"expected a Reference object but got "+typeof o);r[e]=this.container.get(o.id)}return r}safeGet(e){if(!i(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 a}function d(e){return e instanceof a}exports.dock=f,exports.injectable=function(e){return new c(e)},exports.reference=r;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,16 @@
1
- declare class Reference<T> {
2
- readonly name: string;
1
+ declare class Reference<T, N extends string = string> {
2
+ readonly name: N;
3
3
  id: symbol;
4
4
  __type: T;
5
5
  toJSON: () => string;
6
- constructor(name: string);
6
+ constructor(name: N);
7
+ type<U>(): Reference<U, N>;
7
8
  }
8
- declare function derivedReference<T>(base: string, ref: Reference<any>): Reference<T>;
9
- declare function reference<T>(name: string): Reference<T>;
9
+ interface ReferenceFn {
10
+ <T>(name: string): Reference<T>;
11
+ create<const N extends string>(name: N): Reference<unknown, N>;
12
+ }
13
+ declare const reference: ReferenceFn;
10
14
 
11
15
  type RefMap = Record<string, Reference<any>>;
12
16
  type ResolveRefs<T extends RefMap> = {
@@ -52,6 +56,5 @@ declare class Dock {
52
56
  find(predicate: (reference: Reference<any>) => boolean): Reference<any>[];
53
57
  }
54
58
  declare function dock(): Dock;
55
- declare function cloneDock(source: Dock): Dock;
56
59
 
57
- export { Dock, Injectable, Reference, cloneDock, derivedReference, dock, injectable, reference };
60
+ export { Dock, Injectable, Reference, dock, injectable, reference };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.0.6",
8
+ "version": "0.0.8",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",