Socket
Socket
Sign inDemoInstall

gitlab-repo-db

Package Overview
Dependencies
10
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

2

lib/index.js

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

"use strict";var t=require("gitlab-api-v4"),e=require("mingo"),i=require("uuid");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(t),a=n(e);class s{constructor(t){this.options=t,this.gitLabApi=new r.default({api:t.url,privateToken:t.token})}createFile(t,e){return this.gitLabApi.repositoryFile.create({id:this.options.projectID,file_path:encodeURIComponent(t)+".json",branch:"master",commit_message:"create file",content:e})}async getFileContent(t){const e=await this.gitLabApi.repositoryFile.get({id:this.options.projectID,file_path:encodeURIComponent(t)+".json",ref:"master"});if(e.content)try{const t=Buffer.from(e.content,"base64").toString();return JSON.parse(t)}catch(t){return[]}return(e.message||e.error).startsWith("404")?(await this.createFile(t,"[]"),[]):Promise.reject(e)}async writeFileContent(t,e){let i=await this.gitLabApi.repositoryFile.update({id:this.options.projectID,file_path:encodeURIComponent(t)+".json",branch:"master",commit_message:"update file",content:e});const n=i.message||i.error;return(n.includes("doesn't exist")||n.startsWith("404"))&&(i=await this.createFile(t,e)),i}}const o=t=>({...t,_id:i.v1().replace(/-/g,"")});class c{constructor(t,e){this.dbName=t,this.gitlab=e}async _getFileContent(){return await this.gitlab.getFileContent(this.dbName)}_writeFileContent(t){return this.gitlab.writeFileContent(this.dbName,JSON.stringify(t))}async find(t={}){const e=await this._getFileContent();return new a.default.Query(t).find(e).all()}async findOne(t={}){const e=await this._getFileContent();return new a.default.Query(t).find(e).next()}async insert(t){const e=(Array.isArray(t)?t:[t]).map((t=>o(t))),i=(await this._getFileContent()).concat(e);return await this._writeFileContent(i),e.length>1?e:e[0]}async remove(t={}){const e=await this._getFileContent(),i=new a.default.Query(t).remove(e);return await this._writeFileContent(i),i.length}async update(t={},e={},i={}){e._id&&delete e._id;const n=await this._getFileContent();let r=t;const s=await this.find(r);let c=[];!i.multi&&s.length?(r={_id:s[0]._id},c.push({...s[0],...e})):c=s.map((t=>({...t,...e})));const l=new a.default.Query(r).remove(n),u=c.concat(l);let h=c.length;return!h&&i.upsert&&(u.push(o(e)),h=1),await this._writeFileContent(u),h}}module.exports=class{constructor(t){this.gitlab=new s(t)}collection(t){return new c(t,this.gitlab)}};
"use strict";var t=require("gitlab-api-v4"),e=require("mingo"),i=require("uuid");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(t),a=n(e);class s{constructor(t){this.options=t,this.gitLabApi=new r.default({api:t.url,privateToken:t.token})}createFile(t,e){return this.gitLabApi.repositoryFile.create({id:this.options.projectID,file_path:encodeURIComponent(t)+".json",branch:"master",commit_message:"create file",content:e})}async getFileContent(t){const e=await this.gitLabApi.repositoryFile.get({id:this.options.projectID,file_path:encodeURIComponent(t)+".json",ref:"master"});if(e.content)try{const t=Buffer.from(e.content,"base64").toString();return JSON.parse(t)}catch(t){return[]}const i=e.message||e.error;return i&&i.startsWith("404")?(await this.createFile(t,"[]"),[]):Promise.reject(e)}async writeFileContent(t,e){let i=await this.gitLabApi.repositoryFile.update({id:this.options.projectID,file_path:encodeURIComponent(t)+".json",branch:"master",commit_message:"update file",content:e});const n=i.message||i.error;return n&&(n.includes("doesn't exist")||n.startsWith("404"))&&(i=await this.createFile(t,e)),i}}const o=t=>({...t,_id:i.v1().replace(/-/g,"")});class c{constructor(t,e){this.dbName=t,this.gitlab=e}async _getFileContent(){return await this.gitlab.getFileContent(this.dbName)}_writeFileContent(t){return this.gitlab.writeFileContent(this.dbName,JSON.stringify(t))}async find(t={}){const e=await this._getFileContent();return new a.default.Query(t).find(e).all()}async findOne(t={}){const e=await this._getFileContent();return new a.default.Query(t).find(e).next()}async insert(t){const e=(Array.isArray(t)?t:[t]).map((t=>o(t))),i=(await this._getFileContent()).concat(e);return await this._writeFileContent(i),e.length>1?e:e[0]}async remove(t={}){const e=await this._getFileContent(),i=new a.default.Query(t).remove(e);return await this._writeFileContent(i),i.length}async update(t={},e={},i={}){e._id&&delete e._id;const n=await this._getFileContent();let r=t;const s=await this.find(r);let c=[];!i.multi&&s.length?(r={_id:s[0]._id},c.push({...s[0],...e})):c=s.map((t=>({...t,...e})));const l=new a.default.Query(r).remove(n),u=c.concat(l);let h=c.length;return!h&&i.upsert&&(u.push(o(e)),h=1),await this._writeFileContent(u),h}}module.exports=class{constructor(t){this.gitlab=new s(t)}collection(t){return new c(t,this.gitlab)}};
{
"name": "gitlab-repo-db",
"version": "0.1.4",
"version": "0.1.5",
"description": "A database based on gitlab files",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc