1- import fetch from 'node-fetch'
1+ import fetch from 'node-fetch' ;
22
3- import headers from '../utils/headers.js'
4- import constants from '../utils/constants.js'
3+ import headers from '../utils/headers.js' ;
4+ import constants from '../utils/constants.js' ;
55
6- function _hash ( value , salt ) {
7- let hash = crypto . createHmac ( 'sha512' , salt ) ;
8- hash . update ( value ) ;
9- let result = hash . digest ( 'hex' ) ;
10- return {
11- salt : salt ,
12- hashedpassword : result
13- } ;
6+ function hash ( value , salt ) {
7+ const hash = crypto . createHmac ( 'sha512' , salt ) ;
8+ hash . update ( value ) ;
9+ const result = hash . digest ( 'hex' ) ;
10+ return {
11+ salt,
12+ hashedpassword : result ,
13+ } ;
1414}
1515
16- function _compare ( value , hashData ) {
17- let resultData = _hash ( value , hashData . salt ) ;
18- if ( resultData . hashedpassword === hashData . hashedpassword ) {
19- return true ;
20- }
21- return false ;
16+ function compare ( value , hashData ) {
17+ const resultData = _hash ( value , hashData . salt ) ;
18+ if ( resultData . hashedpassword === hashData . hashedpassword ) {
19+ return true ;
20+ }
21+ return false ;
2222}
2323
24- export default class Database {
25- constructor ( replitdbtoken , salt , options ) {
26- this . replitdbtoken = replitdbtoken || process . env . REPLIT_DB_URL . split ( '/' ) [ 4 ] ;
27- this . salt = salt ;
28- this . options = options ;
29- }
24+ let exportable ;
3025
31- async set ( key , value ) {
32- let info = await fetch ( `https://kv.replit.com/v0/ ${ this . replitdbtoken } ` , {
33- method : 'POST' ,
34- headers ,
35- body : encodeURIComponent ( key ) + '=' + encodeURIComponent ( JSON . stringify ( value ) )
36- } ) . then ( res => res . json ( ) ) ;
37- }
26+ if ( global . initVariables . experimentalFeatures ) {
27+ let exportable = class Database {
28+ constructor ( replitdbtoken , salt , options ) {
29+ this . replitdbtoken = replitdbtoken || process . env . REPLIT_DB_URL . split ( '/' ) [ 4 ] ;
30+ this . salt = salt ;
31+ this . options = options ;
32+ }
3833
39- async get ( key , ) {
40- let info = await fetch ( `https://kv.replit.com/v0/${ this . replitdbtoken } /${ key } ` , {
41- method : 'GET' ,
42- headers
43- } ) . then ( res => {
44- res . json ( )
45- } ) ;
46- }
47-
48- async delete ( key ) {
49- let info = await fetch ( `https://kv.replit.com/v0/${ this . replitdbtoken } /${ key } ` , {
50- method : 'GET' ,
51- headers
52- } ) . then ( res => {
53- res . json ( )
54- } ) ;
55- }
56- }
34+ async set ( key , value ) {
35+ const info = await fetch ( `https://kv.replit.com/v0/${ this . replitdbtoken } ` , {
36+ method : 'POST' ,
37+ headers,
38+ body : `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( JSON . stringify ( value ) ) } ` ,
39+ } ) . then ( ( res ) => res . json ( ) ) ;
40+ }
41+
42+ async get ( key ) {
43+ const info = await fetch ( `https://kv.replit.com/v0/${ this . replitdbtoken } /${ key } ` , {
44+ method : 'GET' ,
45+ headers,
46+ } ) . then ( ( res ) => {
47+ res . json ( ) ;
48+ } ) ;
49+ }
50+
51+ async delete ( key ) {
52+ const info = await fetch ( `https://kv.replit.com/v0/${ this . replitdbtoken } /${ key } ` , {
53+ method : 'GET' ,
54+ headers,
55+ } ) . then ( ( res ) => {
56+ res . json ( ) ;
57+ } ) ;
58+ }
59+ }
60+ } else {
61+ exportable = function noExperimentalFeatures ( ) {
62+ console . log ( 'Experimental Features are not enabled. To use learn more about experimental features please visit the documentation.' ) ;
63+ } ;
64+ }
65+
66+ export default exportable ;
0 commit comments