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AO,EAAK,IAC3B,OAAO,GACC,QAAQ,OAAO,EAAE,KAAK,EAAE,CAAC,MAAM,EAAG,QAAQ,EAAE,YAGzD,EAAY,EAAE,EAAM,KAAc,EACpC,MACA,KACA,CAAC,aAAc,GAAO,OAAO,EAAa,CAAC,MAAM,IAAe,KAEpE,MAAO,CACH,KAAK,CAAC,EAAM,EAAW,CAAC,IAAI,EAAY,CAAC,CAAC,GAAO,IAEjD,KAAK,CAAC,EAAM,EAAI,EAAW,CAAC,IAAI,EAAY,EAAI,CAAC,CAAC,EAAM,OAAO,IAAM,GAAY,CAAC,CAAC,KACnF,OAAO,CAAC,EAAM,IAAO,EAAO,OAAO,EAAK,CAAC,UAAU,IACnD,OAAO,CAAC,EAAM,EAAS,IAAO,EAAO,MAAM,EAAK,CAAC,UAAU,EAAM,OAAO,KACxE,OAAO,CAAC,EAAM,IAAW,EAAO,SAAS,KAAK,CAAC,UAAU,EAAM,OAAO,KACtE,SAAS,CAAC,EAAS,IAAW,EAAO,OAAQ,CAAC,WAAS,YAAU,CAAC,aAClE,MAAM,CAAC,EAAS,IAAW,EAAO,OAAQ,CAAC,WAAS,YAAU,CAAC,UAC/D,OAAO,IAAI,EAAO,OAAO,CAAC,EAAE,CAAC,WAC7B,SAAS,CAAC,EAAU,EAAU,IAAc,EAAO,OAAO,CAAC,WAAU,WAAU,eAAa,CAAC,aAC7F,GAAG,IAAI,EAAO,MAAM,KAAK,CAAC,OAE7B","file":"/npm/js-crud-api@0.4.1/esm/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/js-crud-api@0.4.1/esm/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// todo : encodeURIComponent usage?\r\n// todo : https://github.com/Swizec/better-fetch implemntation\r\nconst castArray=a=>Array.isArray(a)?a:[a];\r\nconst prefix=p=>s=>p+s;\r\nconst join=(d=',')=>a=>castArray(a).join(d);\r\nconst mapN=a=>(...f)=>f.reduce((acc,v)=>acc.map(v),a);\r\nconst pca_join=(key,a)=>mapN(castArray(a))(join(),prefix(key+'='));\r\nconst push=(a,...v)=>{a.push(...v);return a;}\r\nconst query=(conditions) => '?'+Object.keys(conditions)\r\n    .reduce((acc,key)=>\r\n        push(acc,...dispatch(key,castArray(conditions[key])))\r\n    ,[]).join('&');\r\nconst nonMultipleConditions=['include','exclude','page','size'];\r\nconst dispatch=(key, a)=>key==='join'\r\n    ? pca_join(key,a)\r\n    : nonMultipleConditions.indexOf(key)!==-1\r\n        ? [key+\"=\"+a.join(',')]\r\n        : a.map(v=>{ // todo : should list the cases (first need to implement error system)\r\n            return key+'='+(Array.isArray(v)?v.join(','):v)\r\n        });\r\nexport default (baseUrl, config={})=>{\r\n    // todo headers Content-Type? application/json vs multipart/form-data ...\r\n    const headers = {};\r\n    const _config = (method, body)=>{\r\n        let c= {\r\n            method: method,\r\n            ...config,\r\n            headers: {\r\n                ...headers,\r\n                ...config.headers,\r\n            }\r\n        };\r\n        // todo do manage array of FormData?\r\n        if (body) c.body=body instanceof FormData ? body :JSON.stringify(body);\r\n        return c;\r\n    };\r\n    const url=(parts)=>[baseUrl,...parts].join('/');\r\n    const _fetch=(method,body, parts)=> {\r\n        return fetch(url(parts), _config(method, body))\r\n            .then(async response =>{\r\n                const data=await response.json();\r\n                return (response.status === 200 || response.ok)\r\n                    ? Promise.resolve(data)\r\n                    : Promise.reject(data);\r\n            }).catch (e=>{\r\n                return Promise.reject(e.code?e:{code:-1, message:e.message})\r\n            });\r\n    };\r\n    const _readOrList=([part1,conditions])=>_fetch(\r\n        'GET',\r\n        null,\r\n        ['records', ...part1].concat(conditions ? [query(conditions)] : [])\r\n    );\r\n    return {\r\n        list:(table,conditions={})=>_readOrList([[table],conditions]),\r\n        // todo : a read method without ids will be considered as a list operation by php-crud-api. JS error?\r\n        read:(table,ids,conditions={})=>_readOrList(ids?[[table,join()(ids)],conditions]:[[table]]),\r\n        create:(table,data)=>_fetch('POST',data,['records',table]),\r\n        update:(table,idOrList,data)=>_fetch('PUT',data,['records',table,join()(idOrList)]),\r\n        delete:(table,idOrList)=>_fetch('DELETE',null,['records',table,join()(idOrList)]),\r\n        register:(username,password)=>_fetch('POST', {username,password},['register']),\r\n        login:(username,password)=>_fetch('POST', {username,password},['login']),\r\n        logout:()=>_fetch('POST',{},['logout']),\r\n        password:(username, password, newPassword)=>_fetch('POST',{username, password, newPassword},['password']),\r\n        me:()=>_fetch('GET',null,['me'])\r\n        //,openapi:()=>_fetch('GET',null,['openapi'])\r\n    };\r\n};\r\n"]}