@potonz/shortlinks-manager 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20,4 +20,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
  */
23
- function S(A=4){let H="";for(let D=0;D<A;D++)H+="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Math.floor(Math.random()*62));return H}function _(A,H){let D=new Set,C=0;while(D.size<A&&C<A*100)D.add(S(H)),C++;return Array.from(D)}async function B({backend:A,caches:H=[],shortIdLength:D,onShortIdLengthUpdated:C,waitUntil:O,options:y}){return await A.init?.(),{async createShortLink(E){let m="";for(let f=0;f<3;f++){let W=_(50,D),z=await A.checkShortIdsExist(W),M=W.find((x)=>!z.includes(x));if(!M){++D;let x=C(D);if(O&&x instanceof Promise)O(x);else await x}else{m=M;break}}if(!m)throw Error("Unable to create a shortlink, potentially ran out");return await A.createShortLink(m,E),m},async getTargetUrl(E){let m=null;for(let f of H){if(!f.initialised)await f.init?.(),f.initialised=!0;if(m=await f.get(E),m)break}if(!m)m=await A.getTargetUrl(E);if(m){if(y?.shouldUpdateLastAccessOnGet??!0){let f=A.updateShortLinkLastAccessTime(E);if(O&&f instanceof Promise)O(f);else await f}for(let f of H){let W=async function(){if(!f.initialised)await f.init?.(),f.initialised=!0;await f.set(E,m)}();if(O)O(W);else await W}}return m},async updateShortLinkLastAccessTime(E){return await A.updateShortLinkLastAccessTime(E)},async cleanUnusedLinks(E){await A.cleanUnusedLinks(E)}}}export{B as createManager};
23
+ function C(m=4){let f="";for(let O=0;O<m;O++)f+="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Math.floor(Math.random()*62));return f}function j(m,f){let O=new Set,S=0;while(O.size<m&&S<m*100)O.add(C(f)),S++;return Array.from(O)}async function H({backend:m,caches:f=[],shortIdLength:O,onShortIdLengthUpdated:S,waitUntil:M,options:B}){return await m.init?.(),{async createShortLink(W){let D="";for(let _=0;_<3;_++){let A=j(50,O),E=await m.checkShortIdsExist(A),y=A.find((z)=>!E.includes(z));if(!y){++O;let z=S(O);if(M&&z instanceof Promise)M(z);else await z}else{D=y;break}}if(!D)throw Error("Unable to create a shortlink, potentially ran out");return await m.createShortLink(D,W),D},async getTargetUrl(W){let D=null,_=-1;for(let A=0;A<f.length;A++){if(!f[A].initialised)await f[A].init?.(),f[A].initialised=!0;if(D=await f[A].get(W),D){_=A;break}}if(!D)D=await m.getTargetUrl(W);if(D){if(B?.shouldUpdateLastAccessOnGet??!0){let E=m.updateShortLinkLastAccessTime(W);if(M&&E instanceof Promise)M(E);else await E}let A=f.length;if(_>=0)A=_;for(let E=0;E<A;E++){let y=async function(){if(!f[E].initialised)await f[E].init?.(),f[E].initialised=!0;await f[E].set(W,D)}();if(M)M(y);else await y}}return D},async updateShortLinkLastAccessTime(W){return await m.updateShortLinkLastAccessTime(W)},async cleanUnusedLinks(W){await m.cleanUnusedLinks(W)}}}export{H as createManager};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "directory": "packages/shortlinks-manager"
13
13
  },
14
- "version": "0.2.1",
14
+ "version": "0.2.2",
15
15
  "type": "module",
16
16
  "license": "MIT",
17
17
  "main": "./dist/index.js",