New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sylviejs

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sylviejs - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

.github/dependabot.yml

4

.release-it.json
{
"buildCommand": "npm run build",
"git": {

@@ -7,3 +8,6 @@ "commitMessage": "chore: release v${version}"

"release": true
},
"dist": {
"baseDir": "dist"
}
}

36

dist/modules/sylvie.d.ts

@@ -68,19 +68,5 @@ import { FsAdapter } from "../storage-adapter/fs-adapter";

/**
* Loki: The main database class
* @constructor Loki
* @implements SylvieEventEmitter
* @param {string} filename - name of the file to be saved to
* @param {object=} options - (Optional) config options object
* @param {string} options.env - override environment detection as 'NODEJS', 'BROWSER', 'CORDOVA'
* @param {boolean} [options.verbose=false] - enable console output
* @param {boolean} [options.autosave=false] - enables autosave
* @param {int} [options.autosaveInterval=5000] - time interval (in milliseconds) between saves (if dirty)
* @param {boolean} [options.autoload=false] - enables autoload on loki instantiation
* @param {function} options.autoloadCallback - user callback called after database load
* @param {adapter} options.adapter - an instance of a loki persistence adapter
* @param {string} [options.serializationMethod='normal'] - ['normal', 'pretty', 'destructured']
* @param {string} options.destructureDelimiter - string delimiter used for destructured serialization
* @param {boolean} [options.throttledSaves=true] - debounces multiple calls to to saveDatabase reducing number of disk I/O operations
and guaranteeing proper serialization of the calls.
*/
* Sylvie: The main database class
* @implements SylvieEventEmitter
*/
export default class Sylvie extends SylvieEventEmitter {

@@ -167,2 +153,18 @@ filename: string;

toJson: (options?: Partial<ConfigOptions>) => any;
/**
* Create a instance of the SylvieJS database.
* @param {string} filename - name of the file to be saved to
* @param {object=} options - (Optional) config options object
* @param {string} options.env - override environment detection as 'NODEJS', 'BROWSER', 'CORDOVA'
* @param {boolean} [options.verbose=false] - enable console output
* @param {boolean} [options.autosave=false] - enables autosave
* @param {int} [options.autosaveInterval=5000] - time interval (in milliseconds) between saves (if dirty)
* @param {boolean} [options.autoload=false] - enables autoload on loki instantiation
* @param {function} options.autoloadCallback - user callback called after database load
* @param {adapter} options.adapter - an instance of a loki persistence adapter
* @param {string} [options.serializationMethod='normal'] - ['normal', 'pretty', 'destructured']
* @param {string} options.destructureDelimiter - string delimiter used for destructured serialization
* @param {boolean} [options.throttledSaves=true] - debounces multiple calls to to saveDatabase reducing number of disk I/O operations
* and guaranteeing proper serialization of the calls.
*/
constructor(filename?: string, options?: Partial<ConfigOptions & ConstructorOptions>);

@@ -169,0 +171,0 @@ getIndexedAdapter(): any;

import { IDBCatalog } from "./crypted-indexeddb-adapter/idb-catalog";
import { AsyncPersistenceAdapter, NormalSyncPersistenceAdapter } from "./persistence-adapter";
interface CryptedIndexedAdapterOptions {
interface CryptedIndexedDBAdapterOptions {
appname: string;

@@ -20,8 +20,2 @@ closeAfterSave: boolean;

*
* @constructor SylvieIndexedAdapter
*
* @param {CryptedIndexedAdapterOptions} options Configuration options for the adapter
* @param {string} options.appname - (Optional) Application name context can be used to distinguish subdomains, 'sylvie' by default
* @param {boolean} options.closeAfterSave Whether the indexedDB database should be closed after saving.
* @param {boolean} options.secret The password to encrypt with.
*/

@@ -32,7 +26,14 @@ export declare class CryptedIndexedDBAdapter implements NormalSyncPersistenceAdapter, AsyncPersistenceAdapter {

app: string;
options: Partial<CryptedIndexedAdapterOptions>;
options: Partial<CryptedIndexedDBAdapterOptions>;
catalog: IDBCatalog;
mode: "normal";
constructor(options?: Partial<CryptedIndexedAdapterOptions>);
/**
* Create a CryptedIndexedDBAdapter.
* @param {CryptedIndexedDBAdapterOptions} options Configuration options for the adapter
* @param {string} options.appname - (Optional) Application name context can be used to distinguish subdomains, 'sylvie' by default
* @param {boolean} options.closeAfterSave Whether the indexedDB database should be closed after saving.
* @param {boolean} options.secret The password to encrypt with.
*/
constructor(options?: Partial<CryptedIndexedDBAdapterOptions>);
/**
* Sets a password for use on future load and save of the database.

@@ -167,5 +168,5 @@ * Note that this does not re-encrypt the database with the new password. Use changePassword() for that.

*/
getDatabaseList: (callback: (_: any) => any) => void;
getDatabaseList: (callback: (_: string[] | Error) => void) => void;
getDatabaseListAsync: () => Promise<string[]>;
}
export {};

@@ -1,2 +0,2 @@

var L=Object.defineProperty;var l=(r,t)=>L(r,"name",{value:t,configurable:!0});var C=(r,t,e)=>{if(!t.has(r))throw TypeError("Cannot "+e)};var A=(r,t,e)=>(C(r,t,"read from private field"),e?e.call(r):t.get(r)),D=(r,t,e)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,e)},m=(r,t,e,s)=>(C(r,t,"write to private field"),s?s.call(r,e):t.set(r,e),e);var E=(r,t,e)=>(C(r,t,"access private method"),e);var u=(r,t,e)=>new Promise((s,o)=>{var n=c=>{try{i(e.next(c))}catch(d){o(d)}},a=c=>{try{i(e.throw(c))}catch(d){o(d)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,a);i((e=e.apply(r,t)).next())});function q(r){if(r.length%4!==0)throw new Error("Unable to parse base64 string (invalid length).");let t=r.indexOf("=");if(t!==-1&&t<r.length-2)throw new Error("Unable to parse base64 string (octets).");let e=r.endsWith("==")?2:r.endsWith("=")?1:0,s=r.length,o=new Uint8Array(3*(s/4)),n;for(let a=0,i=0;a<s;a+=4,i+=3)n=B(r.charCodeAt(a))<<18|B(r.charCodeAt(a+1))<<12|B(r.charCodeAt(a+2))<<6|B(r.charCodeAt(a+3)),o[i]=n>>16,o[i+1]=n>>8&255,o[i+2]=n&255;return o.subarray(0,o.length-e)}l(q,"base64ToBytes");var f=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","_","-"],T=(()=>{let t=new Uint8Array(256);for(let e=0;e<256;++e)t[e]=255;return f.forEach((e,s)=>{t[e.charCodeAt(0)]=s}),t["=".charCodeAt(0)]=0,t})();function B(r){if(r>=T.length)throw new Error("Unable to parse base64 string (code beyond length).");let t=T[r];if(t===255)throw new Error("Unable to parse base64 string (invalid code).");return t}l(B,"getBase64Code");function G(r){let t="",e,s=r.length;for(e=2;e<s;e+=3)t+=f[r[e-2]>>2],t+=f[(r[e-2]&3)<<4|r[e-1]>>4],t+=f[(r[e-1]&15)<<2|r[e]>>6],t+=f[r[e]&63];return e===s+1&&(t+=f[r[e-2]>>2],t+=f[(r[e-2]&3)<<4],t+="=="),e===s&&(t+=f[r[e-2]>>2],t+=f[(r[e-2]&3)<<4|r[e-1]>>4],t+=f[(r[e-1]&15)<<2],t+="="),t}l(G,"bytesToBase64");var V=l(r=>{let t=new TextEncoder;return window.crypto.subtle.importKey("raw",t.encode(r),"PBKDF2",!1,["deriveKey"])},"getPasswordKey"),U=l((r,t,e)=>window.crypto.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:25e4,hash:"SHA-256"},r,{name:"AES-GCM",length:256},!1,e),"deriveKey");function S(r,t){return u(this,null,function*(){try{let e=window.crypto.getRandomValues(new Uint8Array(16)),s=window.crypto.getRandomValues(new Uint8Array(12)),o=yield V(t),n=yield U(o,e,["encrypt"]),a=yield window.crypto.subtle.encrypt({name:"AES-GCM",iv:s},n,new TextEncoder().encode(r)),i=new Uint8Array(a),c=new Uint8Array(e.byteLength+s.byteLength+i.byteLength);return c.set(e,0),c.set(s,e.byteLength),c.set(i,e.byteLength+s.byteLength),G(c)}catch(e){throw console.log(`Encryption Error - ${e}`),e}})}l(S,"encryptData");function R(r,t){return u(this,null,function*(){try{let e=q(r),s=e.slice(0,16),o=e.slice(16,16+12),n=e.slice(16+12),a=yield V(t),i=yield U(a,s,["decrypt"]),c=yield window.crypto.subtle.decrypt({name:"AES-GCM",iv:o},i,n);return new TextDecoder().decode(c)}catch(e){throw console.log(`Decryption Error - ${e}`),e}})}l(R,"decryptData");var P,$,p=class{constructor(){D(this,P);this.db=null}initialize(){return new Promise((t,e)=>{E(this,P,$).call(this).then(s=>{t(s)}).catch(s=>{console.log(s),e(s)})})}openCatalog(){let t=indexedDB.open("IDBCatalog",1);return t.onupgradeneeded=({target:e})=>{let s=e.result;if(s.objectStoreNames.contains("IDBAKV")&&s.deleteObjectStore("IDBAKV"),!s.objectStoreNames.contains("IDBAKV")){let o=s.createObjectStore("IDBAKV",{keyPath:"id",autoIncrement:!0});o.createIndex("app","app",{unique:!1}),o.createIndex("key","key",{unique:!1}),o.createIndex("appkey","appkey",{unique:!0})}},t}getAppKeyAsync(t,e){return u(this,null,function*(){let n=this.db.transaction(["IDBAKV"],"readonly").objectStore("IDBAKV").index("appkey"),a=`${t},${e}`,i=n.get(a);return new Promise((c,d)=>{i.onsuccess=({target:g})=>{let y=g.result;(y===null||typeof y=="undefined")&&(y={id:0,success:!1}),c(y)},i.onerror=g=>{d(g)}})})}setAppKeyAsync(t,e,s){return u(this,null,function*(){let n=this.db.transaction(["IDBAKV"],"readwrite").objectStore("IDBAKV"),a=n.index("appkey"),i=`${t},${e}`,c=a.get(i);return new Promise((d,g)=>{c.onsuccess=({target:y})=>{let b=y.result;b==null?b={app:t,key:e,appkey:`${t},${e}`,val:s}:b.val=s;let I=n.put(b);I.onerror=()=>{g({success:!1,error:I.error}),console.error("IDBCatalog.setAppKey (set) onerror"),console.error(c.error)},I.onsuccess=()=>{d({success:!0})}},c.onerror=()=>{g({success:!1,error:c.error}),console.error("IDBCatalog.setAppKey (get) onerror"),console.error(c.error)}})})}deleteAppKeyAsync(t){let o=this.db.transaction(["IDBAKV"],"readwrite").objectStore("IDBAKV").delete(t);return new Promise((n,a)=>{o.onsuccess=()=>{n({success:!0})},o.onerror=i=>{a({success:!1,error:i}),console.error("IDBCatalog.deleteAppKey raised onerror"),console.error(o.error)}})}getAppKeys(t,e){let n=this.db.transaction(["IDBAKV"],"readonly").objectStore("IDBAKV").index("app"),a=IDBKeyRange.only(t),i=n.openCursor(a),c=[];i.onsuccess=((d,g)=>()=>{let y=i.result;if(y){let b=y.value;d.push(b),y.continue()}else typeof g=="function"?g(d):console.log(d)})(c,e),i.onerror=(d=>g=>{typeof d=="function"?d(null):(console.error("IDBCatalog.getAppKeys raised onerror"),console.error(g))})(e)}getAllKeys(t){let o=this.db.transaction(["IDBAKV"],"readonly").objectStore("IDBAKV").openCursor(),n=[];o.onsuccess=((a,i)=>()=>{let c=o.result;if(c){let d=c.value;a.push(d),c.continue()}else typeof i=="function"?i(a):console.log(a)})(n,t),o.onerror=(a=>i=>{typeof a=="function"&&a(null)})(t)}};l(p,"IDBCatalog"),P=new WeakSet,$=l(function(){return u(this,null,function*(){let t=this,e=this.openCatalog();return new Promise((s,o)=>{e.onsuccess=({target:n})=>{t.db=n.result,s(t)},e.onerror=n=>{o(n)}})})},"#initializeCatalog");var w=typeof window!="undefined"&&!!window.__loki_idb_debug;w&&console.log("DEBUG: Running crypted-indexeddb-adapter in DEBUG mode");if(!window.crypto.subtle)throw alert("Required crypto lib is not availible, are you using SSL?"),new Error("Required crypto lib is not availible");var h,K,v,z,x=class{constructor(t){D(this,v);D(this,h,void 0);D(this,K,l(()=>{this.catalog&&this.catalog.db&&(this.catalog.db.close(),this.catalog.db=null)},"#closeDatabase"));this.loadDatabase=l((t,e)=>{if(w&&console.debug("loading database"),this.catalog===null||this.catalog.db===null){new p().initialize().then(s=>{this.catalog=s,this.loadDatabase(t,e)});return}this.catalog.getAppKeyAsync(this.app,t).then(s=>{let{success:o}=s;if(o===!1)e(null);else{let{val:n}=s;R(n,A(this,h)).then(a=>{w&&console.debug(`DECRYPTED STRING: ${a}`),e(a)}).catch(a=>{console.error(a),e(a)})}}).catch(s=>{console.error(s),e(s)})},"loadDatabase");this.loadDatabaseAsync=l(t=>u(this,null,function*(){return w&&console.debug("loading database"),new Promise((e,s)=>{let o=l(()=>this.catalog.getAppKeyAsync(this.app,t).then(n=>{let{success:a}=n;if(a===!1)s(null);else{let{val:i}=n;R(i,A(this,h)).then(d=>{w&&console.debug(`DECRYPTED STRING: ${d}`),e(d)}).catch(d=>{s(d)})}}),"doLoad");this.catalog===null||this.catalog.db===null?new p().initialize().then(n=>{this.catalog=n,o()}).catch(n=>{s(n)}):o()})}),"loadDatabaseAsync");this.saveDatabase=l((t,e,s)=>{w&&console.debug(`in saveDatabase(${t}, ${e}, ${s})`);let o=l(()=>S(e,A(this,h)).then(n=>{w&&console.debug(`ENCRYPTED STRING: ${n}`),this.catalog.setAppKeyAsync(this.app,t,n).then(a=>{s(a)}).catch(a=>{s(a)})}).catch(n=>{s(n)}),"doSave");this.catalog===null||this.catalog.db===null?new p().initialize().then(n=>{this.catalog=n,this.saveDatabaseAsync(t,e).then(()=>{s(void 0)}).catch(a=>{s(new Error("Error saving database: "+a))}).finally(()=>{this.options.closeAfterSave===!0&&A(this,K).call(this)})}).catch(n=>{s(new Error("Error saving database: "+n))}):o()},"saveDatabase");this.deleteDatabase=l((t,e)=>{if(this.catalog===null||this.catalog.db===null){new p().initialize().then(s=>{this.catalog=s,this.deleteDatabase(t,e)}).catch(s=>{e(new Error("Error deleting database: "+s))});return}this.catalog.getAppKeyAsync(this.app,t).then(s=>{let o=s.id;o!==0&&this.catalog.deleteAppKeyAsync(o).then(n=>{typeof e=="function"&&e(n)}).catch(n=>{typeof e=="function"&&e({success:!1,error:n})})}).catch(s=>{typeof e=="function"&&e({success:!1,error:s})})},"deleteDatabase");this.deleteDatabasePartitions=l(t=>{this.getDatabaseList(e=>{e.forEach(s=>{s.startsWith(t)&&this.deleteDatabase(s)})})},"deleteDatabasePartitions");this.getDatabaseList=l(t=>{if(this.catalog===null||this.catalog.db===null){new p().initialize().then(e=>{this.catalog=e,this.getDatabaseList(t)}).catch(e=>{t(new Error("Error getting database list: "+e))});return}this.catalog.getAppKeys(this.app,e=>{let s=[];for(let o=0;o<e.length;o++)s.push(e[o].key);typeof t=="function"?t(s):s.forEach(o=>{console.log(o)})})},"getDatabaseList");this.getDatabaseListAsync=l(()=>new Promise((t,e)=>{this.catalog===null||this.catalog.db===null?new p().initialize().then(s=>{this.catalog=s,this.catalog.getAppKeys(this.app,o=>{let n=o.map(a=>a.key);t(n)})}).catch(s=>{e(s)}):this.catalog.getAppKeys(this.app,s=>{let o=s.map(n=>n.key);t(o)})}),"getDatabaseListAsync");if(w&&console.log("Initialized crypted-indexeddb-adapter"),this.app="sylvie",this.options=t||{},typeof(t==null?void 0:t.appname)!="undefined"&&(this.app=t==null?void 0:t.appname),this.catalog=null,!E(this,v,z).call(this))throw new Error("IndexedDB does not seem to be supported for your environment");t.secret&&m(this,h,t.secret)}usePassword(t){m(this,h,t)}saveDatabaseAsync(t,e){return u(this,null,function*(){return new Promise((s,o)=>{let n=l(()=>S(e,A(this,h)).then(a=>{w&&console.debug(`ENCRYPTED STRING: ${a}`),this.catalog.setAppKeyAsync(this.app,t,a).then(i=>{i.success===!0?s():o(i)}).catch(i=>{o(i)})}).catch(a=>{o(a)}),"doSave");this.catalog===null||this.catalog.db===null?new p().initialize().then(a=>{this.catalog=a,this.saveDatabaseAsync(t,e).then(s).catch(i=>{o(new Error("Error saving database: "+i))}).finally(()=>{this.options.closeAfterSave===!0&&A(this,K).call(this)})}).catch(a=>{o(a)}):n()})})}deleteDatabaseAsync(t){return u(this,null,function*(){return new Promise((e,s)=>{let o=l(()=>this.catalog.getAppKeyAsync(this.app,t).then(n=>{let a=n.id;a!==0&&this.catalog.deleteAppKeyAsync(a).then(i=>{i.success===!0?e():s(i)}).catch(i=>{s(i)})}).catch(n=>{s(n)}),"doDelete");this.catalog===null||this.catalog.db===null?new p().initialize().then(n=>{this.catalog=n,o()}).catch(n=>{s(n)}):o()})})}changePassword(t,e){return u(this,null,function*(){return new Promise((s,o)=>{this.loadDatabase(t,n=>{let a=A(this,h);m(this,h,e),this.saveDatabase(t,n,i=>{i&&(m(this,h,a),i.success===!0?s():o(i)),s()})})})})}};l(x,"CryptedIndexedDBAdapter"),h=new WeakMap,K=new WeakMap,v=new WeakSet,z=l(function(){return!!(typeof indexedDB!="undefined"&&indexedDB)},"#checkIDBAvailability");typeof window!="undefined"&&Object.assign(window,{IndexedDBAdapter:x,CryptedIndexedDBAdapter:x});export{x as CryptedIndexedDBAdapter};
var L=Object.defineProperty;var l=(r,t)=>L(r,"name",{value:t,configurable:!0});var C=(r,t,e)=>{if(!t.has(r))throw TypeError("Cannot "+e)};var A=(r,t,e)=>(C(r,t,"read from private field"),e?e.call(r):t.get(r)),D=(r,t,e)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,e)},m=(r,t,e,s)=>(C(r,t,"write to private field"),s?s.call(r,e):t.set(r,e),e);var x=(r,t,e)=>(C(r,t,"access private method"),e);var h=(r,t,e)=>new Promise((s,o)=>{var n=c=>{try{i(e.next(c))}catch(d){o(d)}},a=c=>{try{i(e.throw(c))}catch(d){o(d)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,a);i((e=e.apply(r,t)).next())});function q(r){if(r.length%4!==0)throw new Error("Unable to parse base64 string (invalid length).");let t=r.indexOf("=");if(t!==-1&&t<r.length-2)throw new Error("Unable to parse base64 string (octets).");let e=r.endsWith("==")?2:r.endsWith("=")?1:0,s=r.length,o=new Uint8Array(3*(s/4)),n;for(let a=0,i=0;a<s;a+=4,i+=3)n=E(r.charCodeAt(a))<<18|E(r.charCodeAt(a+1))<<12|E(r.charCodeAt(a+2))<<6|E(r.charCodeAt(a+3)),o[i]=n>>16,o[i+1]=n>>8&255,o[i+2]=n&255;return o.subarray(0,o.length-e)}l(q,"base64ToBytes");var f=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","_","-"],T=(()=>{let t=new Uint8Array(256);for(let e=0;e<256;++e)t[e]=255;return f.forEach((e,s)=>{t[e.charCodeAt(0)]=s}),t["=".charCodeAt(0)]=0,t})();function E(r){if(r>=T.length)throw new Error("Unable to parse base64 string (code beyond length).");let t=T[r];if(t===255)throw new Error("Unable to parse base64 string (invalid code).");return t}l(E,"getBase64Code");function G(r){let t="",e,s=r.length;for(e=2;e<s;e+=3)t+=f[r[e-2]>>2],t+=f[(r[e-2]&3)<<4|r[e-1]>>4],t+=f[(r[e-1]&15)<<2|r[e]>>6],t+=f[r[e]&63];return e===s+1&&(t+=f[r[e-2]>>2],t+=f[(r[e-2]&3)<<4],t+="=="),e===s&&(t+=f[r[e-2]>>2],t+=f[(r[e-2]&3)<<4|r[e-1]>>4],t+=f[(r[e-1]&15)<<2],t+="="),t}l(G,"bytesToBase64");var V=l(r=>{let t=new TextEncoder;return window.crypto.subtle.importKey("raw",t.encode(r),"PBKDF2",!1,["deriveKey"])},"getPasswordKey"),U=l((r,t,e)=>window.crypto.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:25e4,hash:"SHA-256"},r,{name:"AES-GCM",length:256},!1,e),"deriveKey");function R(r,t){return h(this,null,function*(){try{let e=window.crypto.getRandomValues(new Uint8Array(16)),s=window.crypto.getRandomValues(new Uint8Array(12)),o=yield V(t),n=yield U(o,e,["encrypt"]),a=yield window.crypto.subtle.encrypt({name:"AES-GCM",iv:s},n,new TextEncoder().encode(r)),i=new Uint8Array(a),c=new Uint8Array(e.byteLength+s.byteLength+i.byteLength);return c.set(e,0),c.set(s,e.byteLength),c.set(i,e.byteLength+s.byteLength),G(c)}catch(e){throw console.log(`Encryption Error - ${e}`),e}})}l(R,"encryptData");function S(r,t){return h(this,null,function*(){try{let e=q(r),s=e.slice(0,16),o=e.slice(16,16+12),n=e.slice(16+12),a=yield V(t),i=yield U(a,s,["decrypt"]),c=yield window.crypto.subtle.decrypt({name:"AES-GCM",iv:o},i,n);return new TextDecoder().decode(c)}catch(e){throw console.log(`Decryption Error - ${e}`),e}})}l(S,"decryptData");var B,$,g=class{constructor(){D(this,B);this.db=null}initialize(){return new Promise((t,e)=>{x(this,B,$).call(this).then(s=>{t(s)}).catch(s=>{console.log(s),e(s)})})}openCatalog(){let t=indexedDB.open("IDBCatalog",1);return t.onupgradeneeded=({target:e})=>{let s=e.result;if(s.objectStoreNames.contains("IDBAKV")&&s.deleteObjectStore("IDBAKV"),!s.objectStoreNames.contains("IDBAKV")){let o=s.createObjectStore("IDBAKV",{keyPath:"id",autoIncrement:!0});o.createIndex("app","app",{unique:!1}),o.createIndex("key","key",{unique:!1}),o.createIndex("appkey","appkey",{unique:!0})}},t}getAppKeyAsync(t,e){return h(this,null,function*(){let n=this.db.transaction(["IDBAKV"],"readonly").objectStore("IDBAKV").index("appkey"),a=`${t},${e}`,i=n.get(a);return new Promise((c,d)=>{i.onsuccess=({target:u})=>{let p=u.result;(p===null||typeof p=="undefined")&&(p={id:0,success:!1}),c(p)},i.onerror=u=>{d(u)}})})}setAppKeyAsync(t,e,s){return h(this,null,function*(){let n=this.db.transaction(["IDBAKV"],"readwrite").objectStore("IDBAKV"),a=n.index("appkey"),i=`${t},${e}`,c=a.get(i);return new Promise((d,u)=>{c.onsuccess=({target:p})=>{let b=p.result;b==null?b={app:t,key:e,appkey:`${t},${e}`,val:s}:b.val=s;let I=n.put(b);I.onerror=()=>{u({success:!1,error:I.error}),console.error("IDBCatalog.setAppKey (set) onerror"),console.error(c.error)},I.onsuccess=()=>{d({success:!0})}},c.onerror=()=>{u({success:!1,error:c.error}),console.error("IDBCatalog.setAppKey (get) onerror"),console.error(c.error)}})})}deleteAppKeyAsync(t){let o=this.db.transaction(["IDBAKV"],"readwrite").objectStore("IDBAKV").delete(t);return new Promise((n,a)=>{o.onsuccess=()=>{n({success:!0})},o.onerror=i=>{a({success:!1,error:i}),console.error("IDBCatalog.deleteAppKey raised onerror"),console.error(o.error)}})}getAppKeysAsync(t){return h(this,null,function*(){let o=this.db.transaction(["IDBAKV"],"readonly").objectStore("IDBAKV").index("app"),n=IDBKeyRange.only(t),a=o.openCursor(n),i=[];return new Promise((c,d)=>{a.onsuccess=()=>{let u=a.result;if(u){let p=u.value;i.push(p),u.continue()}else c(i)},a.onerror=u=>{d(u)}})})}getAppKeys(t,e){let n=this.db.transaction(["IDBAKV"],"readonly").objectStore("IDBAKV").index("app"),a=IDBKeyRange.only(t),i=n.openCursor(a),c=[];i.onsuccess=((d,u)=>()=>{let p=i.result;if(p){let b=p.value;d.push(b),p.continue()}else typeof u=="function"?u(d):console.log(d)})(c,e),i.onerror=(d=>u=>{typeof d=="function"?d(null):(console.error("IDBCatalog.getAppKeys raised onerror"),console.error(u))})(e)}};l(g,"IDBCatalog"),B=new WeakSet,$=l(function(){return h(this,null,function*(){let t=this,e=this.openCatalog();return new Promise((s,o)=>{e.onsuccess=({target:n})=>{t.db=n.result,s(t)},e.onerror=n=>{o(n)}})})},"#initializeCatalog");var w=typeof window!="undefined"&&!!window.__loki_idb_debug;w&&console.log("DEBUG: Running crypted-indexeddb-adapter in DEBUG mode");if(!window.crypto.subtle)throw alert("Required crypto lib is not available, are you using SSL?"),new Error("Required crypto lib is not available");var y,K,v,z,P=class{constructor(t){D(this,v);D(this,y,void 0);D(this,K,l(()=>{this.catalog&&this.catalog.db&&(this.catalog.db.close(),this.catalog.db=null)},"#closeDatabase"));this.loadDatabase=l((t,e)=>{if(w&&console.debug("loading database"),this.catalog===null||this.catalog.db===null){new g().initialize().then(s=>{this.catalog=s,this.loadDatabase(t,e)});return}this.catalog.getAppKeyAsync(this.app,t).then(s=>{let{success:o}=s;if(o===!1)e(null);else{let{val:n}=s;S(n,A(this,y)).then(a=>{w&&console.debug(`DECRYPTED STRING: ${a}`),e(a)}).catch(a=>{console.error(a),e(a)})}}).catch(s=>{console.error(s),e(s)})},"loadDatabase");this.loadDatabaseAsync=l(t=>h(this,null,function*(){return w&&console.debug("loading database"),new Promise((e,s)=>{let o=l(()=>this.catalog.getAppKeyAsync(this.app,t).then(n=>{let{success:a}=n;if(a===!1)s(null);else{let{val:i}=n;S(i,A(this,y)).then(d=>{w&&console.debug(`DECRYPTED STRING: ${d}`),e(d)}).catch(d=>{s(d)})}}),"doLoad");this.catalog===null||this.catalog.db===null?new g().initialize().then(n=>{this.catalog=n,o()}).catch(n=>{s(n)}):o()})}),"loadDatabaseAsync");this.saveDatabase=l((t,e,s)=>{w&&console.debug(`in saveDatabase(${t}, ${e}, ${s})`);let o=l(()=>R(e,A(this,y)).then(n=>{w&&console.debug(`ENCRYPTED STRING: ${n}`),this.catalog.setAppKeyAsync(this.app,t,n).then(a=>{s(a)}).catch(a=>{s(a)})}).catch(n=>{s(n)}),"doSave");this.catalog===null||this.catalog.db===null?new g().initialize().then(n=>{this.catalog=n,this.saveDatabaseAsync(t,e).then(()=>{s(void 0)}).catch(a=>{s(new Error("Error saving database: "+a))}).finally(()=>{this.options.closeAfterSave===!0&&A(this,K).call(this)})}).catch(n=>{s(new Error("Error saving database: "+n))}):o()},"saveDatabase");this.deleteDatabase=l((t,e)=>{if(this.catalog===null||this.catalog.db===null){new g().initialize().then(s=>{this.catalog=s,this.deleteDatabase(t,e)}).catch(s=>{e(new Error("Error deleting database: "+s))});return}this.catalog.getAppKeyAsync(this.app,t).then(s=>{let o=s.id;o!==0&&this.catalog.deleteAppKeyAsync(o).then(n=>{typeof e=="function"&&e(n)}).catch(n=>{typeof e=="function"&&e({success:!1,error:n})})}).catch(s=>{typeof e=="function"&&e({success:!1,error:s})})},"deleteDatabase");this.deleteDatabasePartitions=l(t=>{this.getDatabaseList(e=>{if(e instanceof Error)throw e;e.forEach(s=>{s.startsWith(t)&&this.deleteDatabase(s)})})},"deleteDatabasePartitions");this.getDatabaseList=l(t=>{if(this.catalog===null||this.catalog.db===null){new g().initialize().then(e=>{this.catalog=e,this.getDatabaseList(t)}).catch(e=>{t(new Error("Error getting database list: "+e))});return}this.catalog.getAppKeys(this.app,e=>{let s=[];for(let o=0;o<e.length;o++)s.push(e[o].key);typeof t=="function"?t(s):s.forEach(o=>{console.log(o)})})},"getDatabaseList");this.getDatabaseListAsync=l(()=>new Promise((t,e)=>{this.catalog===null||this.catalog.db===null?new g().initialize().then(s=>{this.catalog=s,this.catalog.getAppKeysAsync(this.app).then(o=>{let n=o.map(a=>a.key);t(n)}).catch(o=>{e(o)})}).catch(s=>{e(s)}):this.catalog.getAppKeysAsync(this.app).then(s=>{let o=s.map(n=>n.key);t(o)}).catch(s=>{e(s)})}),"getDatabaseListAsync");if(w&&console.log("Initialized crypted-indexeddb-adapter"),this.app="sylvie",this.options=t||{},typeof(t==null?void 0:t.appname)!="undefined"&&(this.app=t==null?void 0:t.appname),this.catalog=null,!x(this,v,z).call(this))throw new Error("IndexedDB does not seem to be supported for your environment");t.secret&&m(this,y,t.secret)}usePassword(t){m(this,y,t)}saveDatabaseAsync(t,e){return h(this,null,function*(){return new Promise((s,o)=>{let n=l(()=>R(e,A(this,y)).then(a=>{w&&console.debug(`ENCRYPTED STRING: ${a}`),this.catalog.setAppKeyAsync(this.app,t,a).then(i=>{i.success===!0?s():o(i)}).catch(i=>{o(i)})}).catch(a=>{o(a)}),"doSave");this.catalog===null||this.catalog.db===null?new g().initialize().then(a=>{this.catalog=a,this.saveDatabaseAsync(t,e).then(s).catch(i=>{o(new Error("Error saving database: "+i))}).finally(()=>{this.options.closeAfterSave===!0&&A(this,K).call(this)})}).catch(a=>{o(a)}):n()})})}deleteDatabaseAsync(t){return h(this,null,function*(){return new Promise((e,s)=>{let o=l(()=>this.catalog.getAppKeyAsync(this.app,t).then(n=>{let a=n.id;a!==0&&this.catalog.deleteAppKeyAsync(a).then(i=>{i.success===!0?e():s(i)}).catch(i=>{s(i)})}).catch(n=>{s(n)}),"doDelete");this.catalog===null||this.catalog.db===null?new g().initialize().then(n=>{this.catalog=n,o()}).catch(n=>{s(n)}):o()})})}changePassword(t,e){return h(this,null,function*(){return new Promise((s,o)=>{this.loadDatabase(t,n=>{let a=A(this,y);m(this,y,e),this.saveDatabase(t,n,i=>{i&&(m(this,y,a),i.success===!0?s():o(i)),s()})})})})}};l(P,"CryptedIndexedDBAdapter"),y=new WeakMap,K=new WeakMap,v=new WeakSet,z=l(function(){return!!(typeof indexedDB!="undefined"&&indexedDB)},"#checkIDBAvailability");typeof window!="undefined"&&Object.assign(window,{CryptedIndexedDBAdapter:P});export{P as CryptedIndexedDBAdapter};
//# sourceMappingURL=crypted-indexeddb-adapter.js.map

@@ -16,3 +16,3 @@ export type SuccessResultType = {

#private;
db: IDBDatabase;
db?: IDBDatabase;
constructor();

@@ -36,4 +36,6 @@ /**

deleteAppKeyAsync(id: any): Promise<ResultType>;
getAppKeysAsync(app: any): Promise<{
key: string;
}[]>;
getAppKeys(app: any, callback: any): void;
getAllKeys(callback: any): void;
}

@@ -23,3 +23,3 @@ export declare var Comparators: {

export declare function gtHelper(prop1: number | boolean | string, prop2: number | boolean | string, equal: boolean): boolean;
export declare function sortHelper(prop1: string | number | boolean, prop2: string | number | boolean, desc: boolean): 1 | 0 | -1;
export declare function sortHelper(prop1: string | number | boolean, prop2: string | number | boolean, desc: boolean): 0 | 1 | -1;
/**

@@ -26,0 +26,0 @@ * compoundeval() - helper function for compoundsort(), performing individual object comparisons

@@ -1,12 +0,13 @@

# LokiJS
# SylvieJS
[LokiJS.org web site](http://lokijs.org) |
[LokiJS GitHub page](https://github.com/techfort/LokiJS) |
[Sandbox / Playground](https://rawgit.com/techfort/LokiJS/master/examples/sandbox/LokiSandbox.htm)
[SylvieJS GitHub page](https://github.com/cfu288/SylvieJS)
## Documentation Overview
This is an early effort to provide a more accurate and up-to-date version of LokiJS documentation by using jsdoc. Since modifications arise from various contributors, this should allow distributed effort toward
maintaining this documentation.
SylvieJS is a document oriented database written in javascript, published under MIT License.
Its purpose is to store javascript objects as documents in a nosql fashion and retrieve them with a similar mechanism.
Runs in node and the browser.
SylvieJS is a fork of [LokiJS repository](https://github.com/techfort/LokiJS). SylvieJS aims to be a drop-in replacement for LokiJS while maintaining more modern APIs.
## Getting Started

@@ -17,3 +18,7 @@

```javascript
var db = new loki('example.db');
/**
* Note: Sylvie exports loki as well for backwards compatibility.
* let db = new loki("example.db");
*/
let db = new Sylvie("example.db");
```

@@ -24,3 +29,3 @@

```javascript
var users = db.addCollection('users');
let users = db.addCollection("users");
```

@@ -32,9 +37,12 @@

users.insert({
name: 'Odin',
age: 50,
address: 'Asgard'
name: "Odin",
age: 50,
address: "Asgard",
});
// alternatively, insert array of documents
users.insert([{ name: 'Thor', age: 35}, { name: 'Loki', age: 30}]);
users.insert([
{ name: "Thor", age: 35 },
{ name: "Loki", age: 30 },
]);
```

@@ -45,5 +53,5 @@

```javascript
var results = users.find({ age: {'$gte': 35} });
let results = users.find({ age: { $gte: 35 } });
var odin = users.findOne({ name:'Odin' });
let odin = users.findOne({ name: "Odin" });
```

@@ -54,4 +62,4 @@

```javascript
var results = users.where(function(obj) {
return (obj.age >= 35);
let results = users.where(function (obj) {
return obj.age >= 35;
});

@@ -63,3 +71,7 @@ ```

```javascript
var results = users.chain().find({ age: {'$gte': 35} }).simplesort('name').data();
let results = users
.chain()
.find({ age: { $gte: 35 } })
.simplesort("name")
.data();
```

@@ -70,12 +82,12 @@

```javascript
users.addTransform('progeny', [
users.addTransform("progeny", [
{
type: 'find',
type: "find",
value: {
'age': {'$lte': 40}
}
}
age: { $lte: 40 },
},
},
]);
var results = users.chain('progeny').data();
let results = users.chain("progeny").data();
```

@@ -86,11 +98,11 @@

```javascript
var pview = users.addDynamicView('progeny');
let pview = users.addDynamicView("progeny");
pview.applyFind({
'age': {'$lte': 40}
age: { $lte: 40 },
});
pview.applySimpleSort('name');
pview.applySimpleSort("name");
var results = pview.data();
```
let results = pview.data();
```
{
"name": "sylviejs",
"version": "0.0.5",
"version": "0.0.6",
"description": "SylvieJS: Fast document oriented javascript in-memory database",

@@ -40,3 +40,3 @@ "homepage": "https://techfort.github.io/LokiJS/",

"pour:beer": "echo New npm version published, one beer for you !",
"jsdoc": "./node_modules/.bin/jsdoc -c jsdoc-conf.json",
"typedoc": "npx typedoc",
"benchmark": "jest --projects jest-bench.config.ts && mv benchmarks/result.txt benchmark/result.txt && rm -rf benchmarks/",

@@ -64,2 +64,3 @@ "benchmark:incrementalidb": "npm run clean && npm run build:only && mkdir -p benchmark/benchmark_incrementalidb/dist/ && cp dist/storage-adapter/incremental-indexeddb-adapter.js benchmark/benchmark_incrementalidb/dist && cp -r dist/ benchmark/benchmark_incrementalidb/dist && serve benchmark/benchmark_incrementalidb",

"devDependencies": {
"@knodes/typedoc-plugin-pages": "^0.23.4",
"@types/jasmine": "^4.3.2",

@@ -83,3 +84,3 @@ "@types/jest": "^29.5.1",

"jsdoc": "^3.5.5",
"prettier": "^2.8.8",
"prettier": "^3.0.2",
"puppeteer": "^20.4.0",

@@ -92,4 +93,5 @@ "release-it": "^16.1.5",

"ts-node": "^10.9.1",
"typedoc": "^0.23.28",
"typescript": "^5.0.4"
}
}

@@ -5,5 +5,7 @@ # SylvieJS

See our [Documentation](https://cfu288.github.io/SylvieJS/).
**This repo is a fork of the original [LokiJS repository](https://github.com/techfort/LokiJS)**
The objectives of this fork are to modernize the API and the codebase:
SylvieJS aims to be a drop-in replacement for LokiJS. The objectives of this fork are to modernize the API and the codebase:

@@ -24,2 +26,3 @@ - Migrate codebase to ES6

Runs in node and the browser.
SylvieJS is ideal for the following scenarios:

@@ -58,6 +61,4 @@

This fork is undergoing a rework and has not been released on npm yet.
This fork is currently undergoing a rework.
As SylvieJS is written in JavaScript it can be run on any environment supporting JavaScript such as browsers, node.js/node-webkit, nativescript mobile framework and hybrid mobile apps (such as phonegap/cordova).
Currently maintained by cfu288. Originally made by [@techfort](http://twitter.com/tech_fort), with the precious help of Dave Easterday.

@@ -64,0 +65,0 @@

@@ -37,3 +37,3 @@ /* eslint-disable @typescript-eslint/no-this-alias */

export class DynamicView<
DT extends Partial<CollectionDocument>
DT extends Partial<CollectionDocument>,
> extends SylvieEventEmitter {

@@ -72,3 +72,3 @@ collection: Collection<DT>;

name: string,
options?: Partial<DynamicViewOptions>
options?: Partial<DynamicViewOptions>,
) {

@@ -345,3 +345,3 @@ super();

useJavascriptSorting: boolean;
}>
}>,
) {

@@ -709,3 +709,3 @@ this.sortCriteriaSimple = {

this.sortCriteriaSimple.propname,
this.sortCriteriaSimple.options
this.sortCriteriaSimple.options,
);

@@ -881,3 +881,3 @@ }

this.resultset.filteredrows = this.resultset.filteredrows.filter(
(di, idx) => !fxo[idx]
(di, idx) => !fxo[idx],
);

@@ -884,0 +884,0 @@ // if persistent...

@@ -159,3 +159,3 @@ /* eslint-disable no-var */

transform: ChainTransform,
parameters?: Record<string, any>
parameters?: Record<string, any>,
): ResultSet<RST> | any {

@@ -216,3 +216,3 @@ let idx;

step.mapFun,
step.dataOptions
step.dataOptions,
);

@@ -292,3 +292,3 @@ break;

}>
| boolean
| boolean,
): ResultSet<RST> {

@@ -301,3 +301,3 @@ let eff;

this.collection.binaryIndices,
propname
propname,
);

@@ -430,3 +430,3 @@

throw new Error(
"Invalid call to compoundsort, need at least one property"
"Invalid call to compoundsort, need at least one property",
);

@@ -767,3 +767,3 @@ }

Utils.getIn(t[index.values[i]], property, usingDotNotation),
value
value,
)

@@ -960,3 +960,3 @@ ) {

mapFunction: (value: RST, index: number, array: RST[]) => U,
reduceFunction: (_: U[]) => U
reduceFunction: (_: U[]) => U,
) {

@@ -1023,3 +1023,3 @@ return reduceFunction(this.data().map(mapFunction));

forceCloneMethod: CloneMethods;
}
},
): ResultSet<RST> {

@@ -1191,3 +1191,3 @@ let leftData = [];

mapFun: (value: RST, index: number, array: RST[]) => U,
dataOptions?: Partial<ResultSetDataOptions>
dataOptions?: Partial<ResultSetDataOptions>,
) {

@@ -1194,0 +1194,0 @@ const data = this.data(dataOptions).map(mapFun);

@@ -25,3 +25,3 @@ /* eslint-disable @typescript-eslint/no-this-alias */

eventName: string | string[],
listener: F
listener: F,
): F {

@@ -95,3 +95,3 @@ let event;

eventName: string | string[],
listener: (...args: any[]) => any
listener: (...args: any[]) => any,
): void {

@@ -98,0 +98,0 @@ if (Array.isArray(eventName)) {

@@ -1,11 +0,3 @@

/* eslint-disable @typescript-eslint/no-empty-interface */
/* eslint-disable @typescript-eslint/no-this-alias */
/*
/**
Sylvie IndexedDb Adapter (need to include this script to use it)
Console Usage can be used for management/diagnostic, here are a few examples :
adapter.getDatabaseList(); // with no callback passed, this method will log results to console
adapter.saveDatabase('UserDatabase', JSON.stringify(myDb));
adapter.loadDatabase('UserDatabase'); // will log the serialized db to console
adapter.deleteDatabase('UserDatabase');
*/

@@ -16,10 +8,8 @@ import {

} from "./crypted-indexeddb-adapter/string-encryption-utils";
import { IDBCatalog } from "./crypted-indexeddb-adapter/idb-catalog";
import {
IDBCatalog,
SuccessResultType,
} from "./crypted-indexeddb-adapter/idb-catalog";
import {
AsyncPersistenceAdapter,
NormalSyncPersistenceAdapter,
} from "./persistence-adapter";
// @ts-ignore

@@ -33,7 +23,7 @@ const DEBUG = typeof window !== "undefined" && !!window.__loki_idb_debug;

if (!window.crypto.subtle) {
alert("Required crypto lib is not availible, are you using SSL?");
throw new Error("Required crypto lib is not availible");
alert("Required crypto lib is not available, are you using SSL?");
throw new Error("Required crypto lib is not available");
}
interface CryptedIndexedAdapterOptions {
interface CryptedIndexedDBAdapterOptions {
appname: string;

@@ -43,2 +33,3 @@ closeAfterSave: boolean;

}
/**

@@ -56,8 +47,2 @@ * Loki/Sylvie encrypted persistence adapter class for indexedDb.

*
* @constructor SylvieIndexedAdapter
*
* @param {CryptedIndexedAdapterOptions} options Configuration options for the adapter
* @param {string} options.appname - (Optional) Application name context can be used to distinguish subdomains, 'sylvie' by default
* @param {boolean} options.closeAfterSave Whether the indexedDB database should be closed after saving.
* @param {boolean} options.secret The password to encrypt with.
*/

@@ -69,3 +54,3 @@ export class CryptedIndexedDBAdapter

app: string;
options: Partial<CryptedIndexedAdapterOptions>;
options: Partial<CryptedIndexedDBAdapterOptions>;
catalog: IDBCatalog;

@@ -75,3 +60,10 @@ mode: "normal";

constructor(options?: Partial<CryptedIndexedAdapterOptions>) {
/**
* Create a CryptedIndexedDBAdapter.
* @param {CryptedIndexedDBAdapterOptions} options Configuration options for the adapter
* @param {string} options.appname - (Optional) Application name context can be used to distinguish subdomains, 'sylvie' by default
* @param {boolean} options.closeAfterSave Whether the indexedDB database should be closed after saving.
* @param {boolean} options.secret The password to encrypt with.
*/
constructor(options?: Partial<CryptedIndexedDBAdapterOptions>) {
DEBUG && console.log("Initialized crypted-indexeddb-adapter");

@@ -90,3 +82,3 @@ this.app = "sylvie";

throw new Error(
"IndexedDB does not seem to be supported for your environment"
"IndexedDB does not seem to be supported for your environment",
);

@@ -274,4 +266,4 @@ }

callback?: (
err: Error | { success: true } | { success: false; error: Error }
) => void
err: Error | { success: true } | { success: false; error: Error },
) => void,
) => {

@@ -398,4 +390,4 @@ DEBUG &&

callback?: (
_: Error | { success: true } | { success: false; error: Error }
) => any
_: Error | { success: true } | { success: false; error: Error },
) => any,
) => {

@@ -530,2 +522,5 @@ // lazy open/create db reference and pass callback ahead

this.getDatabaseList((result) => {
if (result instanceof Error) {
throw result;
}
result.forEach((str) => {

@@ -553,3 +548,3 @@ if (str.startsWith(dbname)) {

*/
getDatabaseList = (callback: (_: any) => any) => {
getDatabaseList = (callback: (_: string[] | Error) => void) => {
// lazy open/create db reference so dont -need- callback in constructor

@@ -598,6 +593,11 @@ if (this.catalog === null || this.catalog.db === null) {

this.catalog = catalog;
this.catalog.getAppKeys(this.app, (results) => {
const names: string[] = results.map((result) => result.key);
resolve(names);
});
this.catalog
.getAppKeysAsync(this.app)
.then((results) => {
const names: string[] = results.map((result) => result.key);
resolve(names);
})
.catch((err) => {
reject(err);
});
})

@@ -610,6 +610,11 @@ .catch((err) => {

// get all keys for current appName, and transpose results so just string array
this.catalog.getAppKeys(this.app, (results) => {
const names: string[] = results.map((result) => result.key);
resolve(names);
});
this.catalog
.getAppKeysAsync(this.app)
.then((results) => {
const names: string[] = results.map((result) => result.key);
resolve(names);
})
.catch((err) => {
reject(err);
});
}

@@ -622,5 +627,4 @@ });

Object.assign(window, {
IndexedDBAdapter: CryptedIndexedDBAdapter,
CryptedIndexedDBAdapter: CryptedIndexedDBAdapter,
});
}

@@ -10,3 +10,3 @@ export type SuccessResultType = { success: true };

export class IDBCatalog {
db: IDBDatabase;
db?: IDBDatabase;
constructor() {

@@ -174,3 +174,3 @@ this.db = null;

getAppKeys(app, callback) {
async getAppKeysAsync(app): Promise<{ key: string }[]> {
const transaction = this.db.transaction(["IDBAKV"], "readonly");

@@ -190,35 +190,35 @@ const store = transaction.objectStore("IDBAKV");

cursor.onsuccess = ((data, callback) => () => {
const cur = cursor.result;
if (cur) {
const currObject = cur.value;
return new Promise((resolve, reject) => {
cursor.onsuccess = () => {
const cur = cursor.result;
if (cur) {
const currObject = cur.value;
data.push(currObject);
localdata.push(currObject);
cur.continue();
} else {
if (typeof callback === "function") {
callback(data);
cur.continue();
} else {
console.log(data);
resolve(localdata);
}
}
})(localdata, callback);
};
cursor.onerror = ((usercallback) => (e) => {
if (typeof usercallback === "function") {
usercallback(null);
} else {
console.error("IDBCatalog.getAppKeys raised onerror");
console.error(e);
}
})(callback);
cursor.onerror = (e) => {
reject(e);
};
});
}
// Hide 'cursoring' and return array of { id: id, key: key }
getAllKeys(callback) {
getAppKeys(app, callback) {
const transaction = this.db.transaction(["IDBAKV"], "readonly");
const store = transaction.objectStore("IDBAKV");
const cursor = store.openCursor();
const index = store.index("app");
// We want cursor to all values matching our (single) app param
const singleKeyRange = IDBKeyRange.only(app);
// To use one of the key ranges, pass it in as the first argument of openCursor()/openKeyCursor()
const cursor = index.openCursor(singleKeyRange);
// cursor internally, pushing results into this.data[] and return
// this.data[] when done (similar to service)
const localdata = [];

@@ -244,5 +244,10 @@

cursor.onerror = ((usercallback) => (e) => {
if (typeof usercallback === "function") usercallback(null);
if (typeof usercallback === "function") {
usercallback(null);
} else {
console.error("IDBCatalog.getAppKeys raised onerror");
console.error(e);
}
})(callback);
}
}

@@ -44,3 +44,3 @@ /* eslint-disable @typescript-eslint/no-this-alias */

}
}
},
);

@@ -47,0 +47,0 @@ } else {

@@ -148,3 +148,3 @@ // @ts-nocheck

firstDataPosition,
lastDataPosition + 1
lastDataPosition + 1,
);

@@ -186,3 +186,3 @@

throw new Error(
"Error while saving to database - another operation is already in progress. Please use throttledSaves=true option on Loki object"
"Error while saving to database - another operation is already in progress. Please use throttledSaves=true option on Loki object",
);

@@ -207,3 +207,3 @@ }

console.error(
"Unexpected successful tx - cannot update previous version ids"
"Unexpected successful tx - cannot update previous version ids",
);

@@ -239,3 +239,3 @@ };

incremental,
maxChunkIds
maxChunkIds,
);

@@ -278,3 +278,3 @@ // Update last seen version IDs, but only after the transaction is successful

tx.abort();
}
},
);

@@ -292,3 +292,3 @@ };

console.warn(
"Another writer changed Loki IDB, using slow path..."
"Another writer changed Loki IDB, using slow path...",
);

@@ -302,3 +302,3 @@ didOverwrite = true;

tx.abort();
}
},
);

@@ -427,3 +427,3 @@ };

throw new Error(
"Error while loading database - another operation is already in progress. Please use throttledSaves=true option on Loki object"
"Error while loading database - another operation is already in progress. Please use throttledSaves=true option on Loki object",
);

@@ -465,3 +465,3 @@ }

that.options.deserializeChunk,
that.lazyCollections
that.lazyCollections,
);

@@ -492,3 +492,3 @@ chunks = null; // gc

throw new Error(
"Cannot open IndexedDB because open is already in progress"
"Cannot open IndexedDB because open is already in progress",
);

@@ -510,3 +510,3 @@ }

throw new Error(
`Invalid old version ${oldVersion} for IndexedDB upgrade`
`Invalid old version ${oldVersion} for IndexedDB upgrade`,
);

@@ -631,3 +631,3 @@ }

callback(e);
}
},
);

@@ -653,3 +653,3 @@ }

callback(e);
}
},
);

@@ -675,3 +675,3 @@ }

callback(e);
}
},
);

@@ -704,3 +704,3 @@

throw new Error(
"Error while deleting database - another operation is already in progress. Please use throttledSaves=true option on Loki object"
"Error while deleting database - another operation is already in progress. Please use throttledSaves=true option on Loki object",
);

@@ -742,3 +742,3 @@ }

"Deleting database failed because it's blocked by another connection",
e
e,
);

@@ -826,3 +826,3 @@ };

deserializeChunk,
lazyCollections
lazyCollections,
) {

@@ -835,3 +835,3 @@ collections.forEach(function populateCollection(collectionStub, i) {

throw new Error(
`Corrupted database - missing metadata chunk for ${name}`
`Corrupted database - missing metadata chunk for ${name}`,
);

@@ -838,0 +838,0 @@ }

@@ -66,3 +66,3 @@ /* eslint-disable @typescript-eslint/no-empty-interface */

throw new Error(
"IndexedDB does not seem to be supported for your environment"
"IndexedDB does not seem to be supported for your environment",
);

@@ -153,3 +153,3 @@ }

dbstring: string,
callback?: (err: Error) => void
callback?: (err: Error) => void,
) {

@@ -156,0 +156,0 @@ const appName = this.app;

@@ -32,3 +32,3 @@ /* eslint-disable @typescript-eslint/no-this-alias */

adapter,
options?: Partial<PartitioningAdapterOptions>
options?: Partial<PartitioningAdapterOptions>,
) {

@@ -46,3 +46,3 @@ this.mode = "reference";

throw new Error(
"LokiPartitioningAdapter cannot be instantiated with a reference mode adapter"
"LokiPartitioningAdapter cannot be instantiated with a reference mode adapter",
);

@@ -54,3 +54,3 @@ } else {

throw new Error(
"LokiPartitioningAdapter requires a (non-reference mode) adapter on construction"
"LokiPartitioningAdapter requires a (non-reference mode) adapter on construction",
);

@@ -100,4 +100,4 @@ }

new Error(
"LokiPartitioningAdapter received an unexpected response from inner adapter loadDatabase()"
)
"LokiPartitioningAdapter received an unexpected response from inner adapter loadDatabase()",
),
);

@@ -135,3 +135,3 @@ }

partition,
callback
callback,
) {

@@ -199,3 +199,3 @@ var keyname = this.dbname + "." + partition;

self.dbref.collections[self.pageIterator.collection].data.push(
JSON.parse(data[idx])
JSON.parse(data[idx]),
);

@@ -234,3 +234,3 @@ data[idx] = null;

dbref,
callback
callback,
) {

@@ -312,3 +312,3 @@ var idx,

PartitioningAdapter.prototype.saveNextPage = function (
callback: (err?: Error) => void
callback: (err?: Error) => void,
): void {

@@ -315,0 +315,0 @@ var self = this;

@@ -17,4 +17,4 @@ import Sylvie from "../modules/sylvie";

callback: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -25,4 +25,4 @@ saveDatabase(

callback?: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -37,4 +37,4 @@ }

callback: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -45,4 +45,4 @@ saveDatabase(

callback?: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -57,4 +57,4 @@ }

callback: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -65,4 +65,4 @@ saveDatabase(

callback?: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -73,4 +73,4 @@ exportDatabase(

callback?: (
result: Error | { success: true } | { success: false; error: Error }
) => void
result: Error | { success: true } | { success: false; error: Error },
) => void,
): void;

@@ -77,0 +77,0 @@ }

@@ -21,3 +21,3 @@ /* eslint-disable no-prototype-builtins */

extra,
poffset?: number
poffset?: number,
) {

@@ -43,3 +43,3 @@ const pathOffset = poffset || 0;

extra,
pathOffset + 1
pathOffset + 1,
);

@@ -46,0 +46,0 @@ if (valueFound === true) {

@@ -160,3 +160,3 @@ /* eslint-disable no-prototype-builtins */

b[property],
item
item,
);

@@ -163,0 +163,0 @@ }

@@ -23,3 +23,3 @@ /* eslint-disable no-prototype-builtins */

prop1: boolean | string | number,
prop2: boolean | string | number
prop2: boolean | string | number,
) {

@@ -112,3 +112,3 @@ var cv1, cv2, t1, t2;

prop2: number | boolean | string,
equal: boolean
equal: boolean,
): boolean {

@@ -216,3 +216,3 @@ var cv1, cv2, t1, t2;

prop2: number | boolean | string,
equal: boolean
equal: boolean,
): boolean {

@@ -323,3 +323,3 @@ var cv1, cv2, t1, t2;

prop2: string | number | boolean,
desc: boolean
desc: boolean,
) {

@@ -351,3 +351,3 @@ if (Comparators.aeq(prop1, prop2)) return 0;

obj1: object,
obj2: object
obj2: object,
): number {

@@ -354,0 +354,0 @@ var res = 0;

@@ -15,3 +15,3 @@ import { clone } from "./clone";

params,
depth?: number
depth?: number,
) {

@@ -84,3 +84,3 @@ var prop, pname;

path: string | string[],
usingDotNotation?: boolean
usingDotNotation?: boolean,
) {

@@ -87,0 +87,0 @@ if (object == null) {

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

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 too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc