@pdftron/collab-db-postgresql
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.9
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CollabPostgres=t():e.CollabPostgres=t()}(global,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.setupLogger=t.LogLevels=t.Tags=void 0;var i=o(n(4)),u=n(8);!function(e){e.STANDARD="STANDARD",e.ENTITY="ENTITY",e.QUERY="QUERY",e.RESPONSE="RESPONSE"}(t.Tags||(t.Tags={})),t.LogLevels={ERROR:"error",WARN:"warn",INFO:"info",HTTP:"http",VERBOSE:"verbose",DEBUG:"debug",SILLY:"silly",NONE:"none"};var s=i.default.createLogger({format:i.format.combine(i.format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}))});t.setupLogger=function(e,n){e===t.LogLevels.NONE?s.silent=!0:(u.addConsoleTransport(s,e),n&&n.length&&u.addTransports(s,n))},t.default=s},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getQuery=t.toUnixTimestampSelector=t.toUnixTimestamp=t.camelToSnake=t.keysToCamel=t.valueIn=t.getFilterQuery=t.whereAnd=t.Command=void 0;var a=r(n(2)),o=n(3);!function(e){e.Insert="INSERT",e.Update="UPDATE",e.Delete="DELETE"}(t.Command||(t.Command={}));t.whereAnd=function(e){var t=e.filter((function(e){return!!e}));return t.reduce((function(e,n,r){return e+" "+n+" "+(r===t.length-1?"":"AND")}),"WHERE ")};t.getFilterQuery=function(e){return[e.createdBefore&&t.toUnixTimestampSelector("created_at")+" < "+e.createdBefore,e.createdAfter&&t.toUnixTimestampSelector("created_at")+" > "+e.createdAfter,e.updatedBefore&&t.toUnixTimestampSelector("updated_at")+" < "+e.updatedBefore,e.updatedAfter&&t.toUnixTimestampSelector("updated_at")+" > "+e.updatedAfter]};t.valueIn=function(e,t){return e+" IN ("+t.reduce((function(e,n,r){var a=r===t.length-1?"":",";return"string"==typeof n?e+"'"+n+"'"+a:e+""+n+a}),"")+")"};var i=function(e){return Array.isArray(e)},u=function(e){return e===Object(e)&&!i(e)&&"function"!=typeof e&&!function(e){return e instanceof Date}(e)};t.keysToCamel=function(e){if(u(e)){var n={};return Object.keys(e).forEach((function(r){var a;n[(a=r,a.replace(/([-_][a-z])/gi,(function(e){return e.toUpperCase().replace("-","").replace("_","")})))]=t.keysToCamel(e[r])})),n}return i(e)?e.map((function(e){return t.keysToCamel(e)})):e};t.camelToSnake=function(e){return e.replace(/[\w]([A-Z])/g,(function(e){return e[0]+"_"+e[1]})).toLowerCase()};t.toUnixTimestamp=function(e){return"EXTRACT(epoch FROM date_trunc('milliseconds', "+e+")) * 1000 AS "+e};t.toUnixTimestampSelector=function(e){return"EXTRACT(epoch FROM date_trunc('milliseconds', "+e+")) * 1000"};t.getQuery=function(e){var n=e.type,r=e.id,i=e.table,u=e.params,s=Object.keys(u),c=[],d=[],l=[],f=[],m=1;s.forEach((function(e){var r=u[e];if(void 0!==r){if(o.TimestampProperties.includes(e))if(o.NowTimestampProperties.includes(e))f.push(a.default.getNow());else try{var i=new Date(r);f.push(i.toISOString())}catch(t){throw new Error('Failed to parse date for "'+e+'" - tried to convert '+JSON.stringify(r)+" to a date but could not.")}else f.push(r);c.push(t.camelToSnake(e)),"INSERT"===n&&l.push("$"+m),d.push(t.camelToSnake(e)+" = $"+m),m+=1}}));var p=null;switch(n){case"INSERT":p="INSERT INTO "+i+" ("+c.join(", ")+") VALUES("+l.join(", ")+") RETURNING *;";break;case"UPDATE":p="UPDATE "+i+" SET "+d.join(", ")+" WHERE id = '"+r+"' RETURNING *;";break;case"DELETE":p="DELETE FROM "+i+" WHERE "+d.join(" AND ")+" RETURNING id;"}return{text:p,values:f}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.indicator="NOW",this._current=function(){return"CURRENT_TIMESTAMP"}}return e.prototype.set=function(e){this._current=e},e.prototype.getNow=function(){return this._current()},e}();t.default=new r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NowTimestampProperties=t.TimestampProperties=void 0,t.TimestampProperties=["createdAt","updatedAt","lastRead","annotationCreatedAt"],t.NowTimestampProperties=["createdAt","updatedAt","lastRead"]},function(e,t){e.exports=require("winston")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.QueryType=t.UserTypes=t.UserStatus=void 0,function(e){e.Active="ACTIVE",e.Inactive="INACTIVE"}(t.UserStatus||(t.UserStatus={})),function(e){e.Anonymous="ANONYMOUS",e.Standard="STANDARD"}(t.UserTypes||(t.UserTypes={})),function(e){e.Single="SINGLE",e.Multiple="MULTIPLE"}(t.QueryType||(t.QueryType={}))},function(e,t,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},a=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&a(t,e,n);return o(t,e),t},u=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{s(r.next(e))}catch(e){o(e)}}function u(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}s((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},c=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i},d=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,a=e.length;n<r;n++,a++)e[a]=t[n];return e},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.UserTypes=void 0;var f=n(1),m=l(n(7)).default.Client,p=i(n(0)),v=n(9),h=n(10),y=n(1),b=n(5),g=l(n(2)),_=n(3),T=function(){function e(e){var t=e.username,n=e.dbName,r=e.password,a=e.port,o=e.host,i=e.connectionString,u=e.ssl,s=e.statementTimeout,c=e.queryTimeout,d=void 0===c?5e3:c,l=e.idleInTransactionSessionTimeout,f=e.logLevel,v=e.logTransports;p.setupLogger(f,v),p.default.info("CollabPostgresDB version 2.0.0-alpha.3"),g.default.set((function(){return"NOW()"})),this.dbClient=new m({user:t,database:n,password:r,port:a,host:o,connectionString:i,ssl:u,statement_timeout:s,query_timeout:d,idle_in_transaction_session_timeout:l}),this.dbConnected=!1}return e.prototype.setServer=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.warn("collabDB.setServer() is no longer required. You may remove this function call from your code.")},e.prototype.connectDB=function(){return u(this,void 0,void 0,(function(){var e;return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.dbClient.connect()];case 1:return t.sent(),this.dbConnected=!0,p.default.info("--\x3e Database connected"),[2];case 2:return e=t.sent(),p.default.error("--\x3e Database connection error",{meta:e.stack}),[3,3];case 3:return[2]}}))}))},e.prototype.disconnectDB=function(){return u(this,void 0,void 0,(function(){var e;return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.dbClient.end()];case 1:return t.sent(),this.dbConnected=!1,p.default.info("--\x3e Database disconnected"),[2];case 2:return e=t.sent(),p.default.error("--\x3e Database disconnection error",{meta:e.stack}),[3,3];case 3:return[2]}}))}))},e.prototype.getQueryResponse=function(e,t){var n,r=t.text;return null===(n=t.values)||void 0===n||n.forEach((function(e,t){var n=new RegExp("\\$"+(t+1),"g");r=r.replace(n,e)})),p.default.debug("["+e+"]",{tag:p.Tags.QUERY,meta:r}),this.dbConnected||v.throwError("Database Query","Database not connected, please do db.connectDB() first."),this.dbClient.query(t).then((function(t){var n=y.keysToCamel(t.rows);return p.default.debug("["+e+"]",{tag:p.Tags.RESPONSE,meta:JSON.stringify(n)}),n.forEach((function(e){e.id&&(e.id=""+e.id),e.authorId&&(e.authorId=""+e.authorId),e.documentId&&(e.documentId=""+e.documentId),e.userId&&(e.userId=""+e.userId),e.annotationId&&(e.annotationId=""+e.annotationId),e.inReplyTo&&(e.inReplyTo=""+e.inReplyTo),Object.keys(e).forEach((function(t){_.TimestampProperties.includes(t)&&(e[t]=new Date(e[t]).getTime())}))})),n}))},e.prototype.getUser=function(e){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return v.validateParams("getUser(id)",{id:[e,"string"]}),t={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+" FROM users WHERE id = $1 LIMIT 1",values:[e]},[4,this.getQueryResponse("getUser",t)];case 1:return[2,n.sent()[0]||null]}}))}))},e.prototype.getUserByEmail=function(e){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return v.validateParams("getUserByEmail(email)",{email:[e,"string"]}),t={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at")+" FROM users WHERE email = $1 LIMIT 1",values:[e]},[4,this.getQueryResponse("getUserByEmail",t)];case 1:return[2,n.sent()[0]||null]}}))}))},e.prototype.getUserByUsername=function(e){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return v.validateParams("getUserByUsername(userName)",{userName:[e,"string"]}),t={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at")+" FROM users WHERE user_name = $1 LIMIT 1",values:[e]},[4,this.getQueryResponse("getUserByUsername",t)];case 1:return[2,n.sent()[0]||null]}}))}))},e.prototype.getUsers=function(e){return u(this,void 0,void 0,(function(){var t,n;return s(this,(function(r){switch(r.label){case 0:return v.validateParams("getUsers(ids)",{ids:[e,"array"]}),t=e.map((function(e,t){return"$"+(t+1)})).join(","),n={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at")+" FROM users WHERE id in ("+t+")",values:e},[4,this.getQueryResponse("getUsers",n)];case 1:return[2,r.sent()]}}))}))},e.prototype.createUser=function(e){return u(this,void 0,void 0,(function(){var t,n,a,o,i;return s(this,(function(u){switch(u.label){case 0:return v.validateParams("createUser(user)",{user:[e,"object"],"user.email":[e.email,"string"],"user.password":[e.password,"string"],"user.userName":[e.userName,"string",!1]}),t=Date.now(),[4,h.generateId()];case 1:n=u.sent(),u.label=2;case 2:return u.trys.push([2,4,,5]),a=r({id:n,type:b.UserTypes.Standard,createdAt:t,updatedAt:t},e),o=y.getQuery({type:y.Command.Insert,table:"users",params:a}),[4,this.getQueryResponse("createUser",o)];case 3:return u.sent(),[2,a];case 4:return i=u.sent(),v.throwError("db.createUser","Fail to generate id: "+i),[3,5];case 5:return[2]}}))}))},e.prototype.editUser=function(e){return u(this,void 0,void 0,(function(){var t,n;return s(this,(function(a){switch(a.label){case 0:return v.validateParams("editUser(user)",{user:[e,"object"],"user.id":[e.id,"string"],"user.email":[e.email,"string",!1],"user.password":[e.password,"string",!1],"user.userName":[e.userName,"string",!1]}),t=Date.now(),n=y.getQuery({type:y.Command.Update,id:e.id,table:"users",params:r(r({},e),{updatedAt:e.updatedAt||t})}),[4,this.getQueryResponse("editUser",n)];case 1:return[2,a.sent()[0]||null]}}))}))},e.prototype.deactivateUser=function(e){return u(this,void 0,void 0,(function(){var t,n;return s(this,(function(a){switch(a.label){case 0:v.validateParams("deactivateUser(id)",{id:[e,"string"]}),t=y.getQuery({type:y.Command.Update,id:e,table:"users",params:{status:b.UserStatus.Inactive}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("deactivateUser",t)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:e,successful:!1}];case 4:return[2]}}))}))},e.prototype.getResolvers=function(){var e=this,t="id, user_name, email, type, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),n="id, xfdf, annot_contents, author_id, annotation_id, document_id, page_number, in_reply_to, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),a="id, author_id, is_public, name, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),o="id, user_id, document_id, annotation_id, "+y.toUnixTimestamp("last_read")+", "+y.toUnixTimestamp("updated_at")+", "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("annotation_created_at"),i="id, user_id, document_id, "+y.toUnixTimestamp("last_read")+", "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),l="id, user_id, annotation_id, document_id, read_before_mention, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at");return{Query:{user:function(n){return u(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e={text:"SELECT "+t+" FROM users WHERE id = $1 LIMIT 1",values:[n]},[4,this.getQueryResponse("Query.user",e)];case 1:return[2,r.sent()[0]||null]}}))}))},userWithEmail:function(n){return u(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e={text:"SELECT "+t+" FROM users WHERE email = $1 LIMIT 1",values:[n]},[4,this.getQueryResponse("Query.userWithEmail",e)];case 1:return[2,r.sent()[0]||null]}}))}))},annotations:function(t){return u(e,void 0,void 0,(function(){var e,r,a,o,i,u,l,m,p,v,h,b,g;return s(this,(function(s){switch(s.label){case 0:return e=t.ids,r=t.documentId,a=t.annotationIds,o=t.filters,i=void 0===o?{}:o,u=t.inReplyTo,l=t.pageNumbers,m=i.limit,p=i.orderBy,v=i.orderDirection,h=void 0===v?"DESC":v,b="\n SELECT "+n+"\n FROM annotations\n "+f.whereAnd(d([e&&e.length&&f.valueIn("id",e),a&&a&&f.valueIn("annotation_id",a),r&&"document_id = '"+r+"'",u&&"in_reply_to = '"+u+"'",l&&l.length&&f.valueIn("page_number",l)],c(f.getFilterQuery(i))))+"\n ",p&&(b+=" ORDER BY "+y.camelToSnake(p)+" "+h),m&&(b+=" LIMIT "+m),g={text:b},[4,this.getQueryResponse("Query.annotations",g)];case 1:return[2,s.sent()]}}))}))},documents:function(t){return u(e,void 0,void 0,(function(){var e,n,r,o,i,u,l,m,p,v;return s(this,(function(s){switch(s.label){case 0:return e=t.ids,n=t.userId,r=t.filters,i=(o=void 0===r?{}:r).limit,u=o.orderBy,l=o.orderDirection,m=void 0===l?"DESC":l,p="\n SELECT "+a+"\n FROM documents\n "+f.whereAnd(d([e&&e.length&&f.valueIn("id",e),n&&"id in (SELECT document_id FROM document_members WHERE user_id = '"+n+"')"],c(f.getFilterQuery(o))))+"\n ",u&&(p+=" ORDER BY "+y.camelToSnake(u)+" "+m),i&&(p+=" LIMIT "+i),v={text:p},[4,this.getQueryResponse("Query.documents",v)];case 1:return[2,s.sent()]}}))}))},annotationMembers:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,i,u,l,m,p,v,h;return s(this,(function(s){switch(s.label){case 0:return e=t.annotationId,n=t.ids,r=t.userId,a=t.filters,u=(i=void 0===a?{}:a).limit,l=i.orderBy,m=i.orderDirection,p=void 0===m?"DESC":m,v="\n SELECT "+o+"\n FROM annotation_members\n "+f.whereAnd(d([n&&n.length&&f.valueIn("id",n),e&&"annotation_id = '"+e+"'",r&&"user_id = '"+r+"'"],c(f.getFilterQuery(i))))+"\n ",l&&(v+=" ORDER BY "+y.camelToSnake(l)+" "+p),u&&(v+=" LIMIT "+u),h={text:v},[4,this.getQueryResponse("Query.annotationMembers",h)];case 1:return[2,s.sent()]}}))}))},documentMembers:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,u,l,m,p,v,h;return s(this,(function(s){switch(s.label){case 0:return e=t.documentId,n=t.userId,r=t.ids,a=t.filters,u=(o=void 0===a?{}:a).limit,l=o.orderBy,m=o.orderDirection,p=void 0===m?"DESC":m,v="\n SELECT "+i+"\n FROM document_members\n "+f.whereAnd(d([r&&r.length&&f.valueIn("id",r),e&&"document_id = '"+e+"'",n&&"user_id = '"+n+"'"],c(f.getFilterQuery(o))))+"\n ",l&&(v+=" ORDER BY "+y.camelToSnake(l)+" "+p),u&&(v+=" LIMIT "+u),h={text:v},[4,this.getQueryResponse("Query.documentMembers",h)];case 1:return[2,s.sent()]}}))}))},mentions:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,m,p,v,h;return s(this,(function(s){switch(s.label){case 0:return e=t.annotationId,n=t.userId,r=t.documentId,a=t.ids,o=t.filters,u=(i=void 0===o?{}:o).limit,m=i.orderBy,p=i.orderDirection,v="\n SELECT "+l+"\n FROM mentions\n "+f.whereAnd(d([a&&a.length&&f.valueIn("id",a),r&&"document_id = '"+r+"'",e&&"annotation_id = '"+e+"'",n&&"user_id = '"+n+"'"],c(f.getFilterQuery(i))))+"\n ",m&&(v+=" ORDER BY "+y.camelToSnake(m)+" "+p),u&&(v+=" LIMIT "+u),h={text:v},[4,this.getQueryResponse("Query.mentions",h)];case 1:return[2,s.sent()]}}))}))},annotationCount:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a;return s(this,(function(o){switch(o.label){case 0:return e=t.since,n=t.documentId,r={text:"SELECT COUNT(DISTINCT id) FROM annotations WHERE document_id = $1 AND "+f.toUnixTimestampSelector("created_at")+" > $2",values:[n,e]},[4,this.getQueryResponse("Query.annotationCount",r)];case 1:return a=o.sent(),[2,Number(a[0].count||0)]}}))}))},annotationMemberCount:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o;return s(this,(function(i){switch(i.label){case 0:return e=t.userId,n=t.documentId,r=t.since,a={text:"SELECT COUNT(DISTINCT id) FROM annotation_members WHERE document_id = $1 AND user_id = $2 AND "+f.toUnixTimestampSelector("annotation_created_at")+" > $3",values:[n,e,r]},[4,this.getQueryResponse("Query.annotationMemberCount",a)];case 1:return o=i.sent(),[2,Number(o[0].count||0)]}}))}))}},Mutation:{addUser:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:return t.id?[3,2]:(e=t,[4,h.generateId()]);case 1:e.id=r.sent(),r.label=2;case 2:return n=y.getQuery({type:y.Command.Insert,table:"users",params:t}),[4,this.getQueryResponse("Mutation.addUser",n)];case 3:return[2,r.sent()[0]||null]}}))}))},addAnnotation:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d,l,f,m,p;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return m=s.sent(),[3,3];case 2:m=e,s.label=3;case 3:return n=m,r=t.xfdf,a=t.annotationId,o=t.documentId,i=t.pageNumber,u=t.createdAt,c=t.inReplyTo,d=t.authorId,l=t.updatedAt,f=t.annotContents,p=y.getQuery({type:y.Command.Insert,table:"annotations",params:{id:n,xfdf:r,annotContents:f,authorId:d,annotationId:a,documentId:o,pageNumber:i,createdAt:u,inReplyTo:c,updatedAt:l}}),[4,this.getQueryResponse("Mutation.addAnnotation",p)];case 4:return[2,s.sent()[0]||null]}}))}))},editAnnotation:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a,o,i;return s(this,(function(u){switch(u.label){case 0:return e=n.xfdf,r=n.pageNumber,a=n.updatedAt,o=n.annotContents,i=y.getQuery({type:y.Command.Update,id:t,table:"annotations",params:{xfdf:e,annotContents:o,pageNumber:r,updatedAt:a}}),[4,this.getQueryResponse("Mutation.editAnnotation",i)];case 1:return[2,u.sent()[0]||null]}}))}))},deleteAnnotation:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"annotations",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteAnnotation",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addDocument:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return c=s.sent(),[3,3];case 2:c=e,s.label=3;case 3:return n=c,r=t.authorId,a=t.isPublic,o=t.name,i=t.createdAt,u=t.updatedAt,d=y.getQuery({type:y.Command.Insert,table:"documents",params:{id:n,authorId:r,isPublic:a,name:o,createdAt:i,updatedAt:u}}),[4,this.getQueryResponse("Mutation.addDocument",d)];case 4:return[2,s.sent()[0]||null]}}))}))},editDocument:function(t,n){return u(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e=y.getQuery({type:y.Command.Update,id:t,table:"documents",params:n}),[4,this.getQueryResponse("Mutation.editDocument",e)];case 1:return[2,r.sent()[0]||null]}}))}))},deleteDocument:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"documents",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteDocument",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addDocumentMember:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return c=s.sent(),[3,3];case 2:c=e,s.label=3;case 3:return n=c,r=t.userId,a=t.documentId,o=t.lastRead,i=t.createdAt,u=t.updatedAt,d=y.getQuery({type:y.Command.Insert,table:"document_members",params:{id:n,userId:r,documentId:a,lastRead:o,createdAt:i,updatedAt:u}}),[4,this.getQueryResponse("Mutation.addDocumentMember",d)];case 4:return[2,s.sent()[0]||null]}}))}))},editDocumentMember:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a;return s(this,(function(o){switch(o.label){case 0:return e=n.lastRead,r=n.updatedAt,a=y.getQuery({type:y.Command.Update,id:t,table:"document_members",params:{lastRead:e,updatedAt:r}}),[4,this.getQueryResponse("Mutation.editDocumentMember",a)];case 1:return[2,o.sent()[0]||null]}}))}))},deleteDocumentMember:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"document_members",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteDocumentMember",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addAnnotationMember:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d,l,f;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return l=s.sent(),[3,3];case 2:l=e,s.label=3;case 3:return n=l,r=t.userId,a=t.documentId,o=t.annotationId,i=t.lastRead,u=t.annotationCreatedAt,c=t.createdAt,d=t.updatedAt,f=y.getQuery({type:y.Command.Insert,table:"annotation_members",params:{id:n,userId:r,documentId:a,annotationId:o,lastRead:i,annotationCreatedAt:u,createdAt:c,updatedAt:d}}),[4,this.getQueryResponse("Mutation.addAnnotationMember",f)];case 4:return[2,s.sent()[0]||null]}}))}))},editAnnotationMember:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a;return s(this,(function(o){switch(o.label){case 0:return e=n.lastRead,r=n.updatedAt,a=y.getQuery({type:y.Command.Update,id:t,table:"annotation_members",params:{lastRead:e,updatedAt:r}}),[4,this.getQueryResponse("Mutation.editAnnotationMember",a)];case 1:return[2,o.sent()[0]||null]}}))}))},deleteAnnotationMember:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"annotation_members",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteAnnotationMember",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addMention:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return c=s.sent(),[3,3];case 2:c=e,s.label=3;case 3:return n=c,r=t.userId,a=t.documentId,o=t.annotationId,i=t.createdAt,u=t.updatedAt,d=y.getQuery({type:y.Command.Insert,table:"mentions",params:{id:n,userId:r,documentId:a,annotationId:o,createdAt:i,updatedAt:u}}),[4,this.getQueryResponse("Mutation.addMention",d)];case 4:return[2,s.sent()[0]||null]}}))}))},editMention:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a;return s(this,(function(o){switch(o.label){case 0:return e=n.readBeforeMention,r=n.updatedAt,a=y.getQuery({type:y.Command.Update,id:t,table:"mentions",params:{readBeforeMention:e,updatedAt:r}}),[4,this.getQueryResponse("Mutation.editMention",a)];case 1:return[2,o.sent()[0]||null]}}))}))},deleteMention:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"mentions",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteMention",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))}}}},e.LogLevels=p.LogLevels,e}();t.default=T;var E=n(5);Object.defineProperty(t,"UserTypes",{enumerable:!0,get:function(){return E.UserTypes}})},function(e,t){e.exports=require("pg")},function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.addTransports=t.addConsoleTransport=void 0;var i=o(n(4)),u=n(0);t.addConsoleTransport=function(e,t){void 0===t&&(t=u.LogLevels.INFO),e.add(new i.default.transports.Console({level:t,format:i.format.combine(i.format.colorize(),i.format.printf((function(e){var t=s(e.message),n=e.tag?" ["+e.tag+"]":"",r=s(e.meta);return e.timestamp+" "+e.level+n+":"+t+" "+r})),i.format.metadata({fillExcept:["message","level","timestamp","label"]}))}))};t.addTransports=function(e,t){t.forEach((function(t){return e.add(t)}))};var s=function(e){var t=e||"";return"object"==typeof e&&null!==e&&(t=JSON.stringify(e,null,2)),t}},function(e,t,n){"use strict";var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.validateParams=t.throwError=void 0;var o=a(n(0));t.throwError=function(e,t,n){var r=e+" - "+t;throw o.default.error(r),n?new n(r):new Error(r)};t.validateParams=function(e,t){var n,a=function(t){var n=e+' - Paramater "'+t+'" is required';throw o.default.error(n),new Error(n)},i=function(t,n,r){var a=e+' - Paramater "'+t+'" expected type "'+r+'" but got "'+n+'"';throw o.default.error(a),new Error(a)};for(var u in t){var s=r(t[u],3),c=s[0],d=s[1],l=void 0===d?"any":d,f=s[2],m=void 0===f||f;if(null!=c&&""!==c){if("any"!==l){var p=typeof c;if("string"!==l){if("number"!==l){if("array"!==l){if("blob"!==l){if("boolean"!==l){if("object"!==l){if("function"!==l);else if(!(n=c)||"[object Function]"!=={}.toString.call(n))return i(u,p,l)}else if("object"!==p)return i(u,p,l)}else if("boolean"!==p)return i(u,p,l)}else if(!(c instanceof Blob))return i(u,p,l)}else if(!Array.isArray(c))return i(u,p,l)}else if("number"!==p)return i(u,p,l)}else if("string"!==p)return i(u,p,l)}}else if(m)return a(u)}}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{s(r.next(e))}catch(e){o(e)}}function u(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}s((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.generateId=t.setGenerator=void 0;var o=n(11),i=function(){return o.v4()};t.setGenerator=function(e){i=e};t.generateId=function(){return r(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent()]}}))}))}},function(e,t){e.exports=require("uuid")}]).default})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CollabPostgres=t():e.CollabPostgres=t()}(global,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.setupLogger=t.LogLevels=t.Tags=void 0;var i=o(n(4)),u=n(8);!function(e){e.STANDARD="STANDARD",e.ENTITY="ENTITY",e.QUERY="QUERY",e.RESPONSE="RESPONSE",e.AUTH="AUTH"}(t.Tags||(t.Tags={})),t.LogLevels={ERROR:"error",WARN:"warn",INFO:"info",HTTP:"http",VERBOSE:"verbose",DEBUG:"debug",SILLY:"silly",NONE:"none"};var s=i.default.createLogger({format:i.format.combine(i.format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}))});t.setupLogger=function(e,n,r){e===t.LogLevels.NONE?s.silent=!0:(u.addConsoleTransport(s,e,r),n&&n.length&&u.addTransports(s,n))},t.default=s},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getQuery=t.toUnixTimestampSelector=t.toUnixTimestamp=t.camelToSnake=t.keysToCamel=t.valueIn=t.getFilterQuery=t.whereAnd=t.Command=void 0;var a=r(n(2)),o=n(3);!function(e){e.Insert="INSERT",e.Update="UPDATE",e.Delete="DELETE"}(t.Command||(t.Command={}));t.whereAnd=function(e){var t=e.filter((function(e){return!!e}));return t.reduce((function(e,n,r){return e+" "+n+" "+(r===t.length-1?"":"AND")}),"WHERE ")};t.getFilterQuery=function(e){return[e.createdBefore&&t.toUnixTimestampSelector("created_at")+" < "+e.createdBefore,e.createdAfter&&t.toUnixTimestampSelector("created_at")+" > "+e.createdAfter,e.updatedBefore&&t.toUnixTimestampSelector("updated_at")+" < "+e.updatedBefore,e.updatedAfter&&t.toUnixTimestampSelector("updated_at")+" > "+e.updatedAfter]};t.valueIn=function(e,t){return e+" IN ("+t.reduce((function(e,n,r){var a=r===t.length-1?"":",";return"string"==typeof n?e+"'"+n+"'"+a:e+""+n+a}),"")+")"};var i=function(e){return Array.isArray(e)},u=function(e){return e===Object(e)&&!i(e)&&"function"!=typeof e&&!function(e){return e instanceof Date}(e)};t.keysToCamel=function(e){if(u(e)){var n={};return Object.keys(e).forEach((function(r){var a;n[(a=r,a.replace(/([-_][a-z])/gi,(function(e){return e.toUpperCase().replace("-","").replace("_","")})))]=t.keysToCamel(e[r])})),n}return i(e)?e.map((function(e){return t.keysToCamel(e)})):e};t.camelToSnake=function(e){return e.replace(/[\w]([A-Z])/g,(function(e){return e[0]+"_"+e[1]})).toLowerCase()};t.toUnixTimestamp=function(e){return"EXTRACT(epoch FROM date_trunc('milliseconds', "+e+")) * 1000 AS "+e};t.toUnixTimestampSelector=function(e){return"EXTRACT(epoch FROM date_trunc('milliseconds', "+e+")) * 1000"};t.getQuery=function(e){var n=e.type,r=e.id,i=e.table,u=e.params,s=Object.keys(u),c=[],d=[],l=[],f=[],m=1;s.forEach((function(e){var r=u[e];if(void 0!==r){if(o.TimestampProperties.includes(e))if(o.NowTimestampProperties.includes(e))f.push(a.default.getNow());else try{var i=new Date(r);f.push(i.toISOString())}catch(t){throw new Error('Failed to parse date for "'+e+'" - tried to convert '+JSON.stringify(r)+" to a date but could not.")}else f.push(r);c.push(t.camelToSnake(e)),"INSERT"===n&&l.push("$"+m),d.push(t.camelToSnake(e)+" = $"+m),m+=1}}));var p=null;switch(n){case"INSERT":p="INSERT INTO "+i+" ("+c.join(", ")+") VALUES("+l.join(", ")+") RETURNING *;";break;case"UPDATE":p="UPDATE "+i+" SET "+d.join(", ")+" WHERE id = '"+r+"' RETURNING *;";break;case"DELETE":p="DELETE FROM "+i+" WHERE "+d.join(" AND ")+" RETURNING id;"}return{text:p,values:f}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.indicator="NOW",this._current=function(){return"CURRENT_TIMESTAMP"}}return e.prototype.set=function(e){this._current=e},e.prototype.getNow=function(){return this._current()},e}();t.default=new r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NowTimestampProperties=t.TimestampProperties=void 0,t.TimestampProperties=["createdAt","updatedAt","lastRead","annotationCreatedAt"],t.NowTimestampProperties=["createdAt","updatedAt","lastRead"]},function(e,t){e.exports=require("winston")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.QueryType=t.UserTypes=t.UserStatus=void 0,function(e){e.Active="ACTIVE",e.Inactive="INACTIVE"}(t.UserStatus||(t.UserStatus={})),function(e){e.Anonymous="ANONYMOUS",e.Standard="STANDARD"}(t.UserTypes||(t.UserTypes={})),function(e){e.Single="SINGLE",e.Multiple="MULTIPLE"}(t.QueryType||(t.QueryType={}))},function(e,t,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},a=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&a(t,e,n);return o(t,e),t},u=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{s(r.next(e))}catch(e){o(e)}}function u(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}s((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},c=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i},d=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,a=e.length;n<r;n++,a++)e[a]=t[n];return e},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.UserTypes=void 0;var f=n(1),m=l(n(7)).default.Client,p=i(n(0)),v=n(9),h=n(10),y=n(1),b=n(5),g=l(n(2)),_=n(3),T=function(){function e(e){var t=e.username,n=e.dbName,r=e.password,a=e.port,o=e.host,i=e.connectionString,u=e.ssl,s=e.statementTimeout,c=e.queryTimeout,d=void 0===c?5e3:c,l=e.idleInTransactionSessionTimeout,f=e.logLevel,v=e.logTransports;p.setupLogger(f,v),p.default.info("CollabPostgresDB version 2.0.0-alpha.9"),g.default.set((function(){return"NOW()"})),this.dbClient=new m({user:t,database:n,password:r,port:a,host:o,connectionString:i,ssl:u,statement_timeout:s,query_timeout:d,idle_in_transaction_session_timeout:l}),this.dbConnected=!1}return e.prototype.setServer=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.warn("collabDB.setServer() is no longer required. You may remove this function call from your code.")},e.prototype.connectDB=function(){return u(this,void 0,void 0,(function(){var e;return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.dbClient.connect()];case 1:return t.sent(),this.dbConnected=!0,p.default.info("--\x3e Database connected"),[2];case 2:return e=t.sent(),p.default.error("--\x3e Database connection error",{meta:e.stack}),[3,3];case 3:return[2]}}))}))},e.prototype.disconnectDB=function(){return u(this,void 0,void 0,(function(){var e;return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.dbClient.end()];case 1:return t.sent(),this.dbConnected=!1,p.default.info("--\x3e Database disconnected"),[2];case 2:return e=t.sent(),p.default.error("--\x3e Database disconnection error",{meta:e.stack}),[3,3];case 3:return[2]}}))}))},e.prototype.getQueryResponse=function(e,t){var n,r=t.text;return null===(n=t.values)||void 0===n||n.forEach((function(e,t){var n=new RegExp("\\$"+(t+1),"g");r=r.replace(n,e)})),p.default.debug("["+e+"]",{tag:p.Tags.QUERY,meta:r}),this.dbConnected||v.throwError("Database Query","Database not connected, please do db.connectDB() first."),this.dbClient.query(t).then((function(t){var n=y.keysToCamel(t.rows);return p.default.debug("["+e+"]",{tag:p.Tags.RESPONSE,meta:JSON.stringify(n)}),n.forEach((function(e){e.id&&(e.id=""+e.id),e.authorId&&(e.authorId=""+e.authorId),e.documentId&&(e.documentId=""+e.documentId),e.userId&&(e.userId=""+e.userId),e.annotationId&&(e.annotationId=""+e.annotationId),e.inReplyTo&&(e.inReplyTo=""+e.inReplyTo),Object.keys(e).forEach((function(t){_.TimestampProperties.includes(t)&&(e[t]=new Date(e[t]).getTime())}))})),n}))},e.prototype.getUser=function(e){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return v.validateParams("getUser(id)",{id:[e,"string"]}),t={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+" FROM users WHERE id = $1 LIMIT 1",values:[e]},[4,this.getQueryResponse("getUser",t)];case 1:return[2,n.sent()[0]||null]}}))}))},e.prototype.getUserByEmail=function(e){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return v.validateParams("getUserByEmail(email)",{email:[e,"string"]}),t={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at")+" FROM users WHERE email = $1 LIMIT 1",values:[e]},[4,this.getQueryResponse("getUserByEmail",t)];case 1:return[2,n.sent()[0]||null]}}))}))},e.prototype.getUserByUsername=function(e){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return v.validateParams("getUserByUsername(userName)",{userName:[e,"string"]}),t={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at")+" FROM users WHERE user_name = $1 LIMIT 1",values:[e]},[4,this.getQueryResponse("getUserByUsername",t)];case 1:return[2,n.sent()[0]||null]}}))}))},e.prototype.getUsers=function(e){return u(this,void 0,void 0,(function(){var t,n;return s(this,(function(r){switch(r.label){case 0:return v.validateParams("getUsers(ids)",{ids:[e,"array"]}),t=e.map((function(e,t){return"$"+(t+1)})).join(","),n={text:"SELECT id, user_name, email, password, status, type, custom_data, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at")+" FROM users WHERE id in ("+t+")",values:e},[4,this.getQueryResponse("getUsers",n)];case 1:return[2,r.sent()]}}))}))},e.prototype.createUser=function(e){return u(this,void 0,void 0,(function(){var t,n,a,o,i;return s(this,(function(u){switch(u.label){case 0:return v.validateParams("createUser(user)",{user:[e,"object"],"user.email":[e.email,"string"],"user.password":[e.password,"string"],"user.userName":[e.userName,"string",!1]}),t=Date.now(),[4,h.generateId()];case 1:n=u.sent(),u.label=2;case 2:return u.trys.push([2,4,,5]),a=r({id:n,type:b.UserTypes.Standard,createdAt:t,updatedAt:t},e),o=y.getQuery({type:y.Command.Insert,table:"users",params:a}),[4,this.getQueryResponse("createUser",o)];case 3:return u.sent(),[2,a];case 4:return i=u.sent(),v.throwError("db.createUser","Fail to generate id: "+i),[3,5];case 5:return[2]}}))}))},e.prototype.editUser=function(e){return u(this,void 0,void 0,(function(){var t,n;return s(this,(function(a){switch(a.label){case 0:return v.validateParams("editUser(user)",{user:[e,"object"],"user.id":[e.id,"string"],"user.email":[e.email,"string",!1],"user.password":[e.password,"string",!1],"user.userName":[e.userName,"string",!1]}),t=Date.now(),n=y.getQuery({type:y.Command.Update,id:e.id,table:"users",params:r(r({},e),{updatedAt:e.updatedAt||t})}),[4,this.getQueryResponse("editUser",n)];case 1:return[2,a.sent()[0]||null]}}))}))},e.prototype.deactivateUser=function(e){return u(this,void 0,void 0,(function(){var t,n;return s(this,(function(a){switch(a.label){case 0:v.validateParams("deactivateUser(id)",{id:[e,"string"]}),t=y.getQuery({type:y.Command.Update,id:e,table:"users",params:{status:b.UserStatus.Inactive}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("deactivateUser",t)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:e,successful:!1}];case 4:return[2]}}))}))},e.prototype.getResolvers=function(){var e=this,t="id, user_name, email, type, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),n="id, xfdf, annot_contents, author_id, annotation_id, document_id, page_number, in_reply_to, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),a="id, author_id, is_public, name, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),o="id, user_id, document_id, annotation_id, "+y.toUnixTimestamp("last_read")+", "+y.toUnixTimestamp("updated_at")+", "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("annotation_created_at"),i="id, user_id, document_id, "+y.toUnixTimestamp("last_read")+", "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at"),l="id, user_id, annotation_id, document_id, read_before_mention, "+y.toUnixTimestamp("created_at")+", "+y.toUnixTimestamp("updated_at");return{Query:{user:function(n){return u(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e={text:"SELECT "+t+" FROM users WHERE id = $1 LIMIT 1",values:[n]},[4,this.getQueryResponse("Query.user",e)];case 1:return[2,r.sent()[0]||null]}}))}))},userWithEmail:function(n){return u(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e={text:"SELECT "+t+" FROM users WHERE email = $1 LIMIT 1",values:[n]},[4,this.getQueryResponse("Query.userWithEmail",e)];case 1:return[2,r.sent()[0]||null]}}))}))},annotations:function(t){return u(e,void 0,void 0,(function(){var e,r,a,o,i,u,l,m,p,v,h,b,g;return s(this,(function(s){switch(s.label){case 0:return e=t.ids,r=t.documentId,a=t.annotationIds,o=t.filters,i=void 0===o?{}:o,u=t.inReplyTo,l=t.pageNumbers,m=i.limit,p=i.orderBy,v=i.orderDirection,h=void 0===v?"DESC":v,b="\n SELECT "+n+"\n FROM annotations\n "+f.whereAnd(d([e&&e.length&&f.valueIn("id",e),a&&a&&f.valueIn("annotation_id",a),r&&"document_id = '"+r+"'",u&&"in_reply_to = '"+u+"'",l&&l.length&&f.valueIn("page_number",l)],c(f.getFilterQuery(i))))+"\n ",p&&(b+=" ORDER BY "+y.camelToSnake(p)+" "+h),m&&(b+=" LIMIT "+m),g={text:b},[4,this.getQueryResponse("Query.annotations",g)];case 1:return[2,s.sent()]}}))}))},documents:function(t){return u(e,void 0,void 0,(function(){var e,n,r,o,i,u,l,m,p,v;return s(this,(function(s){switch(s.label){case 0:return e=t.ids,n=t.userId,r=t.filters,i=(o=void 0===r?{}:r).limit,u=o.orderBy,l=o.orderDirection,m=void 0===l?"DESC":l,p="\n SELECT "+a+"\n FROM documents\n "+f.whereAnd(d([e&&e.length&&f.valueIn("id",e),n&&"id in (SELECT document_id FROM document_members WHERE user_id = '"+n+"')"],c(f.getFilterQuery(o))))+"\n ",u&&(p+=" ORDER BY "+y.camelToSnake(u)+" "+m),i&&(p+=" LIMIT "+i),v={text:p},[4,this.getQueryResponse("Query.documents",v)];case 1:return[2,s.sent()]}}))}))},annotationMembers:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,i,u,l,m,p,v,h;return s(this,(function(s){switch(s.label){case 0:return e=t.annotationId,n=t.ids,r=t.userId,a=t.filters,u=(i=void 0===a?{}:a).limit,l=i.orderBy,m=i.orderDirection,p=void 0===m?"DESC":m,v="\n SELECT "+o+"\n FROM annotation_members\n "+f.whereAnd(d([n&&n.length&&f.valueIn("id",n),e&&"annotation_id = '"+e+"'",r&&"user_id = '"+r+"'"],c(f.getFilterQuery(i))))+"\n ",l&&(v+=" ORDER BY "+y.camelToSnake(l)+" "+p),u&&(v+=" LIMIT "+u),h={text:v},[4,this.getQueryResponse("Query.annotationMembers",h)];case 1:return[2,s.sent()]}}))}))},documentMembers:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,u,l,m,p,v,h;return s(this,(function(s){switch(s.label){case 0:return e=t.documentId,n=t.userId,r=t.ids,a=t.filters,u=(o=void 0===a?{}:a).limit,l=o.orderBy,m=o.orderDirection,p=void 0===m?"DESC":m,v="\n SELECT "+i+"\n FROM document_members\n "+f.whereAnd(d([r&&r.length&&f.valueIn("id",r),e&&"document_id = '"+e+"'",n&&"user_id = '"+n+"'"],c(f.getFilterQuery(o))))+"\n ",l&&(v+=" ORDER BY "+y.camelToSnake(l)+" "+p),u&&(v+=" LIMIT "+u),h={text:v},[4,this.getQueryResponse("Query.documentMembers",h)];case 1:return[2,s.sent()]}}))}))},mentions:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,m,p,v,h;return s(this,(function(s){switch(s.label){case 0:return e=t.annotationId,n=t.userId,r=t.documentId,a=t.ids,o=t.filters,u=(i=void 0===o?{}:o).limit,m=i.orderBy,p=i.orderDirection,v="\n SELECT "+l+"\n FROM mentions\n "+f.whereAnd(d([a&&a.length&&f.valueIn("id",a),r&&"document_id = '"+r+"'",e&&"annotation_id = '"+e+"'",n&&"user_id = '"+n+"'"],c(f.getFilterQuery(i))))+"\n ",m&&(v+=" ORDER BY "+y.camelToSnake(m)+" "+p),u&&(v+=" LIMIT "+u),h={text:v},[4,this.getQueryResponse("Query.mentions",h)];case 1:return[2,s.sent()]}}))}))},annotationCount:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a;return s(this,(function(o){switch(o.label){case 0:return e=t.since,n=t.documentId,r={text:"SELECT COUNT(DISTINCT id) FROM annotations WHERE document_id = $1 AND "+f.toUnixTimestampSelector("created_at")+" > $2",values:[n,e]},[4,this.getQueryResponse("Query.annotationCount",r)];case 1:return a=o.sent(),[2,Number(a[0].count||0)]}}))}))},annotationMemberCount:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o;return s(this,(function(i){switch(i.label){case 0:return e=t.userId,n=t.documentId,r=t.since,a={text:"SELECT COUNT(DISTINCT id) FROM annotation_members WHERE document_id = $1 AND user_id = $2 AND "+f.toUnixTimestampSelector("annotation_created_at")+" > $3",values:[n,e,r]},[4,this.getQueryResponse("Query.annotationMemberCount",a)];case 1:return o=i.sent(),[2,Number(o[0].count||0)]}}))}))}},Mutation:{addUser:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:return t.id?[3,2]:(e=t,[4,h.generateId()]);case 1:e.id=r.sent(),r.label=2;case 2:return n=y.getQuery({type:y.Command.Insert,table:"users",params:t}),[4,this.getQueryResponse("Mutation.addUser",n)];case 3:return[2,r.sent()[0]||null]}}))}))},addAnnotation:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d,l,f,m,p;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return m=s.sent(),[3,3];case 2:m=e,s.label=3;case 3:return n=m,r=t.xfdf,a=t.annotationId,o=t.documentId,i=t.pageNumber,u=t.createdAt,c=t.inReplyTo,d=t.authorId,l=t.updatedAt,f=t.annotContents,p=y.getQuery({type:y.Command.Insert,table:"annotations",params:{id:n,xfdf:r,annotContents:f,authorId:d,annotationId:a,documentId:o,pageNumber:i,createdAt:u,inReplyTo:c,updatedAt:l}}),[4,this.getQueryResponse("Mutation.addAnnotation",p)];case 4:return[2,s.sent()[0]||null]}}))}))},editAnnotation:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a,o,i;return s(this,(function(u){switch(u.label){case 0:return e=n.xfdf,r=n.pageNumber,a=n.updatedAt,o=n.annotContents,i=y.getQuery({type:y.Command.Update,id:t,table:"annotations",params:{xfdf:e,annotContents:o,pageNumber:r,updatedAt:a}}),[4,this.getQueryResponse("Mutation.editAnnotation",i)];case 1:return[2,u.sent()[0]||null]}}))}))},deleteAnnotation:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"annotations",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteAnnotation",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addDocument:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return c=s.sent(),[3,3];case 2:c=e,s.label=3;case 3:return n=c,r=t.authorId,a=t.isPublic,o=t.name,i=t.createdAt,u=t.updatedAt,d=y.getQuery({type:y.Command.Insert,table:"documents",params:{id:n,authorId:r,isPublic:a,name:o,createdAt:i,updatedAt:u}}),[4,this.getQueryResponse("Mutation.addDocument",d)];case 4:return[2,s.sent()[0]||null]}}))}))},editDocument:function(t,n){return u(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e=y.getQuery({type:y.Command.Update,id:t,table:"documents",params:n}),[4,this.getQueryResponse("Mutation.editDocument",e)];case 1:return[2,r.sent()[0]||null]}}))}))},deleteDocument:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"documents",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteDocument",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addDocumentMember:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return c=s.sent(),[3,3];case 2:c=e,s.label=3;case 3:return n=c,r=t.userId,a=t.documentId,o=t.lastRead,i=t.createdAt,u=t.updatedAt,d=y.getQuery({type:y.Command.Insert,table:"document_members",params:{id:n,userId:r,documentId:a,lastRead:o,createdAt:i,updatedAt:u}}),[4,this.getQueryResponse("Mutation.addDocumentMember",d)];case 4:return[2,s.sent()[0]||null]}}))}))},editDocumentMember:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a;return s(this,(function(o){switch(o.label){case 0:return e=n.lastRead,r=n.updatedAt,a=y.getQuery({type:y.Command.Update,id:t,table:"document_members",params:{lastRead:e,updatedAt:r}}),[4,this.getQueryResponse("Mutation.editDocumentMember",a)];case 1:return[2,o.sent()[0]||null]}}))}))},deleteDocumentMember:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"document_members",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteDocumentMember",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addAnnotationMember:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d,l,f;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return l=s.sent(),[3,3];case 2:l=e,s.label=3;case 3:return n=l,r=t.userId,a=t.documentId,o=t.annotationId,i=t.lastRead,u=t.annotationCreatedAt,c=t.createdAt,d=t.updatedAt,f=y.getQuery({type:y.Command.Insert,table:"annotation_members",params:{id:n,userId:r,documentId:a,annotationId:o,lastRead:i,annotationCreatedAt:u,createdAt:c,updatedAt:d}}),[4,this.getQueryResponse("Mutation.addAnnotationMember",f)];case 4:return[2,s.sent()[0]||null]}}))}))},editAnnotationMember:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a;return s(this,(function(o){switch(o.label){case 0:return e=n.lastRead,r=n.updatedAt,a=y.getQuery({type:y.Command.Update,id:t,table:"annotation_members",params:{lastRead:e,updatedAt:r}}),[4,this.getQueryResponse("Mutation.editAnnotationMember",a)];case 1:return[2,o.sent()[0]||null]}}))}))},deleteAnnotationMember:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"annotation_members",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteAnnotationMember",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))},addMention:function(t){return u(e,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,d;return s(this,(function(s){switch(s.label){case 0:return void 0!==(e=t.id)?[3,2]:[4,h.generateId()];case 1:return c=s.sent(),[3,3];case 2:c=e,s.label=3;case 3:return n=c,r=t.userId,a=t.documentId,o=t.annotationId,i=t.createdAt,u=t.updatedAt,d=y.getQuery({type:y.Command.Insert,table:"mentions",params:{id:n,userId:r,documentId:a,annotationId:o,createdAt:i,updatedAt:u}}),[4,this.getQueryResponse("Mutation.addMention",d)];case 4:return[2,s.sent()[0]||null]}}))}))},editMention:function(t,n){return u(e,void 0,void 0,(function(){var e,r,a;return s(this,(function(o){switch(o.label){case 0:return e=n.readBeforeMention,r=n.updatedAt,a=y.getQuery({type:y.Command.Update,id:t,table:"mentions",params:{readBeforeMention:e,updatedAt:r}}),[4,this.getQueryResponse("Mutation.editMention",a)];case 1:return[2,o.sent()[0]||null]}}))}))},deleteMention:function(t){return u(e,void 0,void 0,(function(){var e,n;return s(this,(function(a){switch(a.label){case 0:e=y.getQuery({type:y.Command.Delete,table:"mentions",params:{id:t}}),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.getQueryResponse("Mutation.deleteMention",e)];case 2:return n=a.sent(),[2,r(r({},n[0]),{successful:!0})];case 3:return a.sent(),[2,{id:t,successful:!1}];case 4:return[2]}}))}))}}}},e.LogLevels=p.LogLevels,e}();t.default=T;var E=n(5);Object.defineProperty(t,"UserTypes",{enumerable:!0,get:function(){return E.UserTypes}})},function(e,t){e.exports=require("pg")},function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.addTransports=t.addConsoleTransport=void 0;var i=o(n(4)),u=n(0);t.addConsoleTransport=function(e,t,n){void 0===t&&(t=u.LogLevels.INFO),e.add(new i.default.transports.Console({level:t,format:i.format.combine(i.format((function(e){return(!n||e.tag===n)&&e}))(),i.format.colorize(),i.format.printf((function(e){var t=s(e.message),n=e.tag?" ["+e.tag+"]":"",r=s(e.meta);return e.timestamp+" "+e.level+n+": "+t+" "+r})),i.format.metadata({fillExcept:["message","level","timestamp","label"]}))}))};t.addTransports=function(e,t){t.forEach((function(t){return e.add(t)}))};var s=function(e){var t=e||"";return"object"==typeof e&&null!==e&&(t=JSON.stringify(e,null,2)),t}},function(e,t,n){"use strict";var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.validateParams=t.throwError=void 0;var o=a(n(0));t.throwError=function(e,t,n){var r=e+" - "+t;throw o.default.error(r),n?new n(r):new Error(r)};t.validateParams=function(e,t){var n,a=function(t){var n=e+' - Paramater "'+t+'" is required';throw o.default.error(n),new Error(n)},i=function(t,n,r){var a=e+' - Paramater "'+t+'" expected type "'+r+'" but got "'+n+'"';throw o.default.error(a),new Error(a)};for(var u in t){var s=r(t[u],3),c=s[0],d=s[1],l=void 0===d?"any":d,f=s[2],m=void 0===f||f;if(null!=c&&""!==c){if("any"!==l){var p=typeof c;if("string"!==l){if("number"!==l){if("array"!==l){if("blob"!==l){if("boolean"!==l){if("object"!==l){if("function"!==l);else if(!(n=c)||"[object Function]"!=={}.toString.call(n))return i(u,p,l)}else if("object"!==p)return i(u,p,l)}else if("boolean"!==p)return i(u,p,l)}else if(!(c instanceof Blob))return i(u,p,l)}else if(!Array.isArray(c))return i(u,p,l)}else if("number"!==p)return i(u,p,l)}else if("string"!==p)return i(u,p,l)}}else if(m)return a(u)}}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{s(r.next(e))}catch(e){o(e)}}function u(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}s((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.generateId=t.setGenerator=void 0;var o=n(11),i=function(){return o.v4()};t.setGenerator=function(e){i=e};t.generateId=function(){return r(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent()]}}))}))}},function(e,t){e.exports=require("uuid")}]).default})); |
@@ -6,3 +6,3 @@ { | ||
"types": "types/packages/collab-db-postgresql/src/index.d.ts", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.9", | ||
"scripts": { | ||
@@ -33,3 +33,3 @@ "start-local-db": "node dist/scripts/start-local-db.js", | ||
}, | ||
"gitHead": "841b4c9221e1cc1a5dd164b9a3380dfc1b427628" | ||
"gitHead": "be43d839181faf826acf5055db7766babd823459" | ||
} |
@@ -1,6 +0,6 @@ | ||
import { PubSub } from 'apollo-server'; | ||
import { PubSub } from 'graphql-subscriptions'; | ||
import { ApolloDatabaseAnnotation } from './../resolvers'; | ||
import { User } from './User'; | ||
import { Mention } from './Mention'; | ||
import { NewAnnotationInput, Annotation as ApolloAnnotation } from './../../../../types/resolvers-types'; | ||
import { NewAnnotationInput, Annotation as ApolloAnnotation, AnnotationSubscriptionEvent, ChangeEventTypes } from './../../../../types/resolvers-types'; | ||
import { Base } from './Base'; | ||
@@ -11,2 +11,3 @@ import { AnnotationMember } from './AnnotationMember'; | ||
import { RequestedFields } from '../util/getRequestedFields'; | ||
import { EntityPermissions } from '../util/permission'; | ||
export declare type AnnotationPublishEventOptions = { | ||
@@ -18,2 +19,6 @@ onlyFireForUserId?: string; | ||
}; | ||
export declare type AnnotationChangedPayload = { | ||
annotationChanged: AnnotationSubscriptionEvent; | ||
userId: string; | ||
}; | ||
export declare class Annotation extends Base<ApolloDatabaseAnnotation, ApolloAnnotation, { | ||
@@ -26,4 +31,4 @@ membership: AnnotationMember; | ||
getAnnotationForUser(userId: string, requestedFields: RequestedFields, skipMembership?: boolean): Annotation; | ||
publishEvent(pubsub: PubSub, action: 'INVITE' | 'EDIT' | 'ADD' | 'DELETE', options?: AnnotationPublishEventOptions): Promise<void>; | ||
checkPermission(authMethods: Array<AuthMethod> | AuthMethod, context: Context): Promise<boolean>; | ||
publishEvent(pubsub: PubSub, action: ChangeEventTypes, options?: AnnotationPublishEventOptions): Promise<void>; | ||
static checkPermission(annotation: ApolloDatabaseAnnotation, authMethods: Array<AuthMethod> | AuthMethod, context: Context): Promise<boolean>; | ||
addMember(user: { | ||
@@ -35,2 +40,3 @@ id: string; | ||
static buildFromId(id: string, userId: string, from: string, context: Context): Promise<Annotation>; | ||
static addAnnotationCheckPermission(annotation: ApolloDatabaseAnnotation, permission: Omit<EntityPermissions, 'invite'>, context: Context): Promise<void>; | ||
/** | ||
@@ -37,0 +43,0 @@ * Creates a new annotation and saves it in the database |
@@ -1,4 +0,4 @@ | ||
import { PubSub } from 'apollo-server'; | ||
import { PubSub } from 'graphql-subscriptions'; | ||
import { ApolloDatabaseDocument, ApolloDatabaseDocumentMember, ApolloDatabaseUser } from './../resolvers'; | ||
import { Document as ApolloDocument, InvitedUserInput, NewDocumentInput, NewAnnotationInput } from './../../../../types/resolvers-types'; | ||
import { Document as ApolloDocument, InvitedUserInput, NewDocumentInput, NewAnnotationInput, ChangeEventTypes, DocumentSubscriptionEvent } from './../../../../types/resolvers-types'; | ||
import { Base } from './Base'; | ||
@@ -8,3 +8,3 @@ import { Annotation } from './Annotation'; | ||
import { DocumentMember } from './DocumentMember'; | ||
import { AuthMethod } from '../util/permission'; | ||
import { Actions, AuthMethod } from '../util/permission'; | ||
import { RequestedFields } from '../util/getRequestedFields'; | ||
@@ -14,2 +14,6 @@ export declare type DocumentPublishEventOptions = { | ||
}; | ||
export declare type DocumentChangedPayload = { | ||
documentChanged: DocumentSubscriptionEvent; | ||
userId: string; | ||
}; | ||
export declare class Document extends Base<ApolloDatabaseDocument, ApolloDocument, { | ||
@@ -21,3 +25,3 @@ members: DocumentMember[]; | ||
constructor(document: ApolloDatabaseDocument, userId: string, from: string, context: Context); | ||
publishEvent(pubsub: PubSub, action: 'INVITE' | 'EDIT' | 'ADD' | 'DELETE', options?: DocumentPublishEventOptions): Promise<void>; | ||
publishEvent(pubsub: PubSub, action: ChangeEventTypes, options?: DocumentPublishEventOptions): Promise<void>; | ||
getResolvedMembers(): Promise<(ApolloDatabaseDocumentMember & { | ||
@@ -32,3 +36,3 @@ user: ApolloDatabaseUser; | ||
getDocumentForUser(userId: any, requestedFields: RequestedFields): Promise<Document>; | ||
checkPermission(authMethods: Array<AuthMethod> | AuthMethod, context: Context): Promise<boolean>; | ||
static checkPermission(document: ApolloDatabaseDocument, authMethods: Array<AuthMethod> | AuthMethod, action: Actions, context: Context): Promise<boolean>; | ||
addUsers(usersInvited: InvitedUserInput[], currentUserId?: string): Promise<{ | ||
@@ -35,0 +39,0 @@ isSelfInvite: boolean; |
@@ -0,1 +1,2 @@ | ||
import { PubSub } from 'graphql-subscriptions'; | ||
import { ApolloDatabaseMention } from './../resolvers'; | ||
@@ -6,3 +7,2 @@ import { User } from './User'; | ||
import { Base } from './Base'; | ||
import { PubSub } from 'apollo-server'; | ||
export declare class Mention extends Base<ApolloDatabaseMention, ApolloMention, { | ||
@@ -9,0 +9,0 @@ mentionedUser: User; |
@@ -0,15 +1,20 @@ | ||
/// <reference types="cors" /> | ||
/// <reference types="node" /> | ||
import { Tags } from './../../../shared/log/logger'; | ||
import { Response } from 'express'; | ||
import { PubSub } from 'graphql-subscriptions'; | ||
import { TimestampGetter } from './util/TimestampManager'; | ||
import ConnectedUserMap from './util/ConnectedUserMap'; | ||
import { UserResolvers, CustomContext } from './resolvers'; | ||
import { CorsOptions, PubSub } from 'apollo-server'; | ||
import type winston from 'winston'; | ||
import type { CookieOptions } from 'express'; | ||
import { Logging } from '../../../shared/log/logger'; | ||
import { PermissionSetting, UserPermissionSetting } from './util/permission'; | ||
import { InvitedUserInput, XfdfTypes } from '../../../types/resolvers-types'; | ||
import { Response } from 'express'; | ||
import { EmailManager } from './email/EmailManager'; | ||
import ContextCache from './cache/ContextCache'; | ||
import { PermissionSetting, UserPermissionSetting } from './util/permission'; | ||
import RequestStats from './util/RequestStats'; | ||
import { RequestedFields } from './util/getRequestedFields'; | ||
import type { Server as HttpServer } from 'http'; | ||
import type { CorsOptions } from 'apollo-server-express'; | ||
import type winston from 'winston'; | ||
import type { CookieOptions } from 'express'; | ||
import { InvitedUserInput, XfdfTypes } from '../../../types/resolvers-types'; | ||
export declare type UserAuth = { | ||
@@ -29,3 +34,2 @@ id: string; | ||
cookieOptions: CookieOptions; | ||
jwtCookieName: string; | ||
cache: ContextCache; | ||
@@ -41,6 +45,5 @@ resolvers: UserResolvers; | ||
subscriptionFields: Record<string, RequestedFields>; | ||
customContextCookieName: string; | ||
customContextJWT: string | null; | ||
customContext: Record<any, any>; | ||
customContext: CustomContext; | ||
xfdfFormat?: XfdfTypes; | ||
cookies: Record<any, any>; | ||
}; | ||
@@ -58,3 +61,3 @@ /** | ||
*/ | ||
export declare type GetUserFromToken = (token: string, context: CustomContext) => Promise<UserAuth> | UserAuth; | ||
export declare type GetUserFromToken = (token: string, context: CustomContext, cookies: Record<any, any>) => Promise<UserAuth> | UserAuth; | ||
/** | ||
@@ -111,2 +114,3 @@ * @ignore | ||
logLevel?: Logging; | ||
filterLogsByTag?: Tags; | ||
logTransports?: Array<winston.transport>; | ||
@@ -117,3 +121,2 @@ customQueries?: CollabServerCustomQueriesOptions; | ||
getUserFromToken?: GetUserFromToken; | ||
jwtCookieName?: string; | ||
cookieOptions?: CookieOptions; | ||
@@ -125,2 +128,6 @@ permissions?: UserPermissionSetting; | ||
private server; | ||
private subscriptionServer; | ||
private httpServer; | ||
private corsOption; | ||
private app; | ||
constructor(options: CollabServerOptions); | ||
@@ -137,2 +144,3 @@ static LogLevels: { | ||
}; | ||
static LogTags: typeof Tags; | ||
static sendGridEmailHandler: (emailServiceOptions: import("./email/sendGridEmailHandler").EmailServiceOptions) => EmailFunction; | ||
@@ -158,4 +166,4 @@ static Permissions: { | ||
}; | ||
start(port?: number): Promise<void>; | ||
stop(): Promise<void>; | ||
start(port?: number): Promise<HttpServer>; | ||
stop(): void; | ||
} | ||
@@ -162,0 +170,0 @@ export default CollabServer; |
import { Context } from './../../index'; | ||
import { NewAnnotationInput } from '../../../../../types/resolvers-types'; | ||
declare const _default: { | ||
addAnnotation: (p: any, args: any, context: Context) => Promise<import("./../../index").ApolloAnnotation>; | ||
addAnnotation: (p: any, args: { | ||
input: NewAnnotationInput; | ||
}, context: Context) => Promise<import("./../../index").ApolloAnnotation>; | ||
editAnnotation: (p: any, args: any, context: Context) => Promise<import("./../../index").ApolloAnnotation>; | ||
@@ -5,0 +8,0 @@ deleteAnnotation: (p: any, args: any, context: Context) => Promise<import("./../../index").DeleteResult | { |
@@ -1,11 +0,7 @@ | ||
import { MutationSetContextArgs, MutationUpdateContextArgs } from './../../../../../types/resolvers-types'; | ||
import { Context } from '../..'; | ||
export declare const readContext: (jwtString?: string) => Promise<unknown>; | ||
declare const _default: { | ||
setContext: (_: any, args: MutationSetContextArgs, context: Context) => any; | ||
updateContext: (_: any, args: MutationUpdateContextArgs, context: Context) => Promise<{ | ||
data: any; | ||
encodeContext: (p: any, args: any, context: Context) => Promise<{ | ||
token: string; | ||
}>; | ||
deleteContext: (_: any, __: any, context: Context) => boolean; | ||
}; | ||
export default _default; |
declare const Mutation: { | ||
setContext: (_: any, args: import("../../../../../types/resolvers-types").MutationSetContextArgs, context: import("../..").Context) => any; | ||
updateContext: (_: any, args: import("../../../../../types/resolvers-types").MutationUpdateContextArgs, context: import("../..").Context) => Promise<{ | ||
data: any; | ||
encodeContext: (p: any, args: any, context: import("../..").Context) => Promise<{ | ||
token: string; | ||
}>; | ||
deleteContext: (_: any, __: any, context: import("../..").Context) => boolean; | ||
editScrollSync: (p: any, args: any, context: import("../..").Context) => { | ||
@@ -44,3 +42,5 @@ position: any; | ||
deleteAnnotationMember: (p: any, args: any, context: import("../..").Context) => Promise<import("../..").DeleteResult>; | ||
addAnnotation: (p: any, args: any, context: import("../..").Context) => Promise<import("../..").ApolloAnnotation>; | ||
addAnnotation: (p: any, args: { | ||
input: import("../../../../../types/resolvers-types").NewAnnotationInput; | ||
}, context: import("../..").Context) => Promise<import("../..").ApolloAnnotation>; | ||
editAnnotation: (p: any, args: any, context: import("../..").Context) => Promise<import("../..").ApolloAnnotation>; | ||
@@ -55,8 +55,9 @@ deleteAnnotation: (p: any, args: any, context: import("../..").Context) => Promise<import("../..").DeleteResult | { | ||
user: import("../..").ApolloUser; | ||
token: string; | ||
}>; | ||
login: (p: any, args: any, context: import("../..").Context) => Promise<{ | ||
user: import("../..").ApolloDatabaseUser; | ||
token: string; | ||
}>; | ||
endSession: (p: any, args: any, context: import("../..").Context) => Promise<boolean>; | ||
}; | ||
export default Mutation; |
@@ -6,8 +6,9 @@ import { Context } from './../../index'; | ||
user: import("./../../index").ApolloUser; | ||
token: string; | ||
}>; | ||
login: (p: any, args: any, context: Context) => Promise<{ | ||
user: import("../../resolvers").ApolloDatabaseUser; | ||
token: string; | ||
}>; | ||
endSession: (p: any, args: any, context: Context) => Promise<boolean>; | ||
}; | ||
export default _default; |
@@ -0,18 +1,23 @@ | ||
import type { AnnotationChangedPayload } from '../entities/Annotation'; | ||
import type { DocumentChangedPayload } from '../entities/Document'; | ||
import { SubscriptionAnnotationChangedArgs, SubscriptionDocumentChangedArgs } from '../../../../types/resolvers-types'; | ||
declare const _default: { | ||
annotationChanged: { | ||
subscribe: import("apollo-server").ResolverFn; | ||
resolve: (payload: AnnotationChangedPayload, variables: SubscriptionAnnotationChangedArgs) => import("../../../../types/resolvers-types").AnnotationSubscriptionEvent; | ||
subscribe: import("graphql-subscriptions").ResolverFn; | ||
}; | ||
documentChanged: { | ||
subscribe: import("apollo-server").ResolverFn; | ||
resolve: (payload: DocumentChangedPayload, variables: SubscriptionDocumentChangedArgs) => import("../../../../types/resolvers-types").DocumentSubscriptionEvent; | ||
subscribe: import("graphql-subscriptions").ResolverFn; | ||
}; | ||
scrollPositionChanged: { | ||
subscribe: import("apollo-server").ResolverFn; | ||
subscribe: import("graphql-subscriptions").ResolverFn; | ||
}; | ||
connectedDocUsersChanged: { | ||
subscribe: import("apollo-server").ResolverFn; | ||
subscribe: import("graphql-subscriptions").ResolverFn; | ||
}; | ||
mentionChanged: { | ||
subscribe: import("apollo-server").ResolverFn; | ||
subscribe: import("graphql-subscriptions").ResolverFn; | ||
}; | ||
}; | ||
export default _default; |
import ConnectedUserMap from '../util/ConnectedUserMap'; | ||
import type { PubSub } from 'apollo-server'; | ||
import type { PubSub } from 'graphql-subscriptions'; | ||
export declare const leaveScrollSyncEvent: (disconnectedUserId: string, pubsub: PubSub, connectedUsers: ConnectedUserMap) => void; | ||
export declare const leaveConnectedDocUsersMap: (disconnectedUserId: string, pubsub: PubSub, connectedUsers: ConnectedUserMap) => void; |
@@ -1,2 +0,2 @@ | ||
import type { ApolloUser, CustomContext } from './../resolvers'; | ||
import type { CustomContext } from './../resolvers'; | ||
export declare const Entities: { | ||
@@ -38,3 +38,3 @@ readonly DOCUMENT: "document"; | ||
}; | ||
export declare type AuthorizeFunction = (entity: any, user: Pick<ApolloUser, "id" | "createdAt" | "email" | "type">, context: CustomContext) => Promise<boolean>; | ||
export declare type AuthorizeFunction = (entity: any, userId: string, context: CustomContext) => Promise<boolean>; | ||
export declare const setPermissions: (setting?: UserPermissionSetting) => PermissionSetting; | ||
@@ -41,0 +41,0 @@ declare const permissionConstants: { |
@@ -1,1 +0,1 @@ | ||
export declare const retrieveCookie: (cookieStr: string, jwtCookieName: string) => string; | ||
export declare const retrieveCookie: (cookieStr: string, cookieName: string) => string; |
@@ -6,3 +6,4 @@ import winston from 'winston'; | ||
QUERY = "QUERY", | ||
RESPONSE = "RESPONSE" | ||
RESPONSE = "RESPONSE", | ||
AUTH = "AUTH" | ||
} | ||
@@ -21,3 +22,3 @@ export declare type Logging = 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly' | 'none'; | ||
declare const logger: winston.Logger; | ||
export declare const setupLogger: (logLevel: Logging, logTransports: Array<winston.transport>) => void; | ||
export declare const setupLogger: (logLevel: Logging, logTransports: Array<winston.transport>, filterByTag?: Tags) => void; | ||
export default logger; |
import winston from 'winston'; | ||
import { Logging } from './logger'; | ||
export declare const addConsoleTransport: (logger: winston.Logger, level?: Logging) => void; | ||
import { Logging, Tags } from './logger'; | ||
export declare const addConsoleTransport: (logger: winston.Logger, level?: Logging, filterByTag?: Tags) => void; | ||
export declare const addTransports: (logger: winston.Logger, transports: Array<winston.transport>) => void; |
@@ -7,2 +7,6 @@ export declare enum ChangeEventTypes { | ||
} | ||
export declare enum EncodeContextActions { | ||
MERGE = "MERGE", | ||
SET = "SET" | ||
} | ||
export declare enum OrderDirections { | ||
@@ -20,2 +24,8 @@ ASC = "ASC", | ||
} | ||
export declare enum XFDFTypes { | ||
COMMAND_ADD = "COMMAND_ADD", | ||
COMMAND_ALL = "COMMAND_ALL", | ||
COMMAND_MODIFY = "COMMAND_MODIFY", | ||
RAW = "RAW" | ||
} | ||
export interface DeleteAnnotationMemberInput { | ||
@@ -112,1 +122,4 @@ memberId?: string | null; | ||
} | ||
export interface QuerySettings { | ||
xfdfFormat?: XFDFTypes | null; | ||
} |
@@ -48,3 +48,4 @@ import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'; | ||
CommandAdd = "COMMAND_ADD", | ||
CommandModify = "COMMAND_MODIFY" | ||
CommandModify = "COMMAND_MODIFY", | ||
CommandAll = "COMMAND_ALL" | ||
} | ||
@@ -108,2 +109,6 @@ export declare type Member = { | ||
}; | ||
export declare type ContextResult = { | ||
__typename?: 'ContextResult'; | ||
token: Scalars['String']; | ||
}; | ||
export declare type ConnectResult = { | ||
@@ -323,3 +328,2 @@ __typename?: 'ConnectResult'; | ||
loginAnonymous: AuthPayload; | ||
endSession?: Maybe<Scalars['Boolean']>; | ||
addMention: Mention; | ||
@@ -334,5 +338,3 @@ editMention: Mention; | ||
deleteConnectedDocUser: DeleteResult; | ||
setContext: ContextResult; | ||
updateContext: ContextResult; | ||
deleteContext: Scalars['Boolean']; | ||
encodeContext: ContextResult; | ||
}; | ||
@@ -444,12 +446,10 @@ export declare type MutationAddAnnotationArgs = { | ||
}; | ||
export declare type MutationSetContextArgs = { | ||
data?: Maybe<Scalars['JSON']>; | ||
export declare type MutationEncodeContextArgs = { | ||
context: Scalars['String']; | ||
action: EncodeContextActions; | ||
}; | ||
export declare type MutationUpdateContextArgs = { | ||
data: Scalars['JSON']; | ||
}; | ||
export declare type ContextResult = { | ||
__typename?: 'ContextResult'; | ||
data?: Maybe<Scalars['JSON']>; | ||
}; | ||
export declare enum EncodeContextActions { | ||
Set = "SET", | ||
Merge = "MERGE" | ||
} | ||
export declare enum ChangeEventTypes { | ||
@@ -519,2 +519,3 @@ Add = "ADD", | ||
user?: Maybe<User>; | ||
token?: Maybe<Scalars['String']>; | ||
}; | ||
@@ -585,2 +586,3 @@ export declare type IgnoreMembership = { | ||
DeleteResult: ResolverTypeWrapper<DeleteResult>; | ||
ContextResult: ResolverTypeWrapper<ContextResult>; | ||
ConnectResult: ResolverTypeWrapper<ConnectResult>; | ||
@@ -613,3 +615,3 @@ Mention: ResolverTypeWrapper<Mention>; | ||
Mutation: ResolverTypeWrapper<{}>; | ||
ContextResult: ResolverTypeWrapper<ContextResult>; | ||
EncodeContextActions: EncodeContextActions; | ||
ChangeEventTypes: ChangeEventTypes; | ||
@@ -642,2 +644,3 @@ AnnotationSubscriptionEvent: ResolverTypeWrapper<AnnotationSubscriptionEvent>; | ||
DeleteResult: DeleteResult; | ||
ContextResult: ContextResult; | ||
ConnectResult: ConnectResult; | ||
@@ -670,3 +673,2 @@ Mention: Mention; | ||
Mutation: {}; | ||
ContextResult: ContextResult; | ||
AnnotationSubscriptionEvent: AnnotationSubscriptionEvent; | ||
@@ -757,2 +759,6 @@ DocumentSubscriptionEvent: DocumentSubscriptionEvent; | ||
}>; | ||
export declare type ContextResultResolvers<ContextType = any, ParentType extends ResolversParentTypes['ContextResult'] = ResolversParentTypes['ContextResult']> = ResolversObject<{ | ||
token?: Resolver<ResolversTypes['String'], ParentType, ContextType>; | ||
__isTypeOf?: IsTypeOfResolverFn<ParentType>; | ||
}>; | ||
export declare type ConnectResultResolvers<ContextType = any, ParentType extends ResolversParentTypes['ConnectResult'] = ResolversParentTypes['ConnectResult']> = ResolversObject<{ | ||
@@ -824,3 +830,2 @@ userId?: Resolver<Maybe<ResolversTypes['ID']>, ParentType, ContextType>; | ||
loginAnonymous?: Resolver<ResolversTypes['AuthPayload'], ParentType, ContextType, RequireFields<MutationLoginAnonymousArgs, never>>; | ||
endSession?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType>; | ||
addMention?: Resolver<ResolversTypes['Mention'], ParentType, ContextType, RequireFields<MutationAddMentionArgs, never>>; | ||
@@ -835,10 +840,4 @@ editMention?: Resolver<ResolversTypes['Mention'], ParentType, ContextType, RequireFields<MutationEditMentionArgs, 'userId' | 'annotationId'>>; | ||
deleteConnectedDocUser?: Resolver<ResolversTypes['DeleteResult'], ParentType, ContextType, RequireFields<MutationDeleteConnectedDocUserArgs, 'input'>>; | ||
setContext?: Resolver<ResolversTypes['ContextResult'], ParentType, ContextType, RequireFields<MutationSetContextArgs, never>>; | ||
updateContext?: Resolver<ResolversTypes['ContextResult'], ParentType, ContextType, RequireFields<MutationUpdateContextArgs, 'data'>>; | ||
deleteContext?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>; | ||
encodeContext?: Resolver<ResolversTypes['ContextResult'], ParentType, ContextType, RequireFields<MutationEncodeContextArgs, 'context' | 'action'>>; | ||
}>; | ||
export declare type ContextResultResolvers<ContextType = any, ParentType extends ResolversParentTypes['ContextResult'] = ResolversParentTypes['ContextResult']> = ResolversObject<{ | ||
data?: Resolver<Maybe<ResolversTypes['JSON']>, ParentType, ContextType>; | ||
__isTypeOf?: IsTypeOfResolverFn<ParentType>; | ||
}>; | ||
export declare type AnnotationSubscriptionEventResolvers<ContextType = any, ParentType extends ResolversParentTypes['AnnotationSubscriptionEvent'] = ResolversParentTypes['AnnotationSubscriptionEvent']> = ResolversObject<{ | ||
@@ -883,2 +882,3 @@ annotation?: Resolver<ResolversTypes['Annotation'], ParentType, ContextType>; | ||
user?: Resolver<Maybe<ResolversTypes['User']>, ParentType, ContextType>; | ||
token?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>; | ||
__isTypeOf?: IsTypeOfResolverFn<ParentType>; | ||
@@ -909,2 +909,3 @@ }>; | ||
DeleteResult?: DeleteResultResolvers<ContextType>; | ||
ContextResult?: ContextResultResolvers<ContextType>; | ||
ConnectResult?: ConnectResultResolvers<ContextType>; | ||
@@ -918,3 +919,2 @@ Mention?: MentionResolvers<ContextType>; | ||
Mutation?: MutationResolvers<ContextType>; | ||
ContextResult?: ContextResultResolvers<ContextType>; | ||
AnnotationSubscriptionEvent?: AnnotationSubscriptionEventResolvers<ContextType>; | ||
@@ -921,0 +921,0 @@ DocumentSubscriptionEvent?: DocumentSubscriptionEventResolvers<ContextType>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
163066
68
2809