query-builder-for-driveapi
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,21 @@ | ||
import { Collection, FileType, VisibilityLevel } from './constants.js'; | ||
declare enum Collection { | ||
PARENTS = "parents", | ||
OWNERS = "owners", | ||
WRITERS = "writers", | ||
READERS = "readers" | ||
} | ||
declare enum VisibilityLevel { | ||
ANYONE_CAN_FIND = "anyoneCanFind", | ||
ANYONE_WITH_LINK = "anyoneWithLink", | ||
DOMAIN_CAN_FIND = "domainCanFind", | ||
DOMAIN_WITH_LINK = "domainWithLink", | ||
LIMITED = "limited" | ||
} | ||
declare enum FileType { | ||
FOLDER = "application/vnd.google-apps.folder", | ||
DOCUMENT = "application/vnd.google-apps.document", | ||
SPREADSHEET = "application/vnd.google-apps.spreadsheet", | ||
PRESENTATION = "application/vnd.google-apps.presentation", | ||
FORM = "application/vnd.google-apps.form" | ||
} | ||
@@ -3,0 +22,0 @@ declare class QueryBuilder { |
199
lib/index.js
@@ -1,198 +0,1 @@ | ||
import { | ||
Collection, | ||
File, | ||
FileType, | ||
Operator, | ||
QueryType, | ||
VisibilityLevel | ||
} from "./constants.js"; | ||
const QueryTemplate = { | ||
[QueryType.COLLECTION]: ({ field, op, entry }) => `'${entry.value}' ${op} ${field}`, | ||
[QueryType.STRING]: ({ field, op, entry }) => `${field} ${op} '${entry.value}'`, | ||
[QueryType.BOOLEAN]: ({ field, op, entry }) => `${field} ${op} ${entry.value}`, | ||
[QueryType.HASH]: ({ field, op, entry }) => `${field} ${op} { key='${entry?.key}' and value='${entry.value}' }` | ||
}; | ||
class QueryBuilder { | ||
constructor() { | ||
this.queries = []; | ||
this.negateNextTerm = false; | ||
} | ||
addQuery(type, options) { | ||
const { field, op, entry } = options; | ||
let query = ""; | ||
if (this.negateNextTerm) { | ||
this.negateNextTerm = false; | ||
query += `${Operator.NOT} `; | ||
} | ||
const _queries = []; | ||
for (const key in entry) { | ||
const value = entry[key]; | ||
_queries.push( | ||
QueryTemplate[type]({ field, op, entry: { key: `${key}`, value } }) | ||
); | ||
} | ||
query += `(${_queries.join( | ||
` ${Array.isArray(entry) ? Operator.OR : Operator.AND} ` | ||
)})`; | ||
this.queries.push(query); | ||
} | ||
/** | ||
* Negate the immediately following input (query). | ||
*/ | ||
not() { | ||
this.negateNextTerm = true; | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the collection contains the specified value. | ||
*/ | ||
getByCollection(collection, value) { | ||
this.addQuery(QueryType.COLLECTION, { | ||
field: collection, | ||
op: Operator.IN, | ||
entry: Array.isArray(value) ? value : [value] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the file name is equal to the specified file name. | ||
*/ | ||
getByFileName(filename) { | ||
this.addQuery(QueryType.STRING, { | ||
field: File.NAME, | ||
op: Operator.EQUAL, | ||
entry: Array.isArray(filename) ? filename : [filename] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the file name, description, indexableText or | ||
* content text properties or metadata of the file contains the specified value. | ||
*/ | ||
getByContent(value) { | ||
this.addQuery(QueryType.STRING, { | ||
field: File.FULL_TEXT, | ||
op: Operator.CONTAINS, | ||
entry: Array.isArray(value) ? value : [value] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the MIME type of the file is equal to the specified file type. | ||
*/ | ||
getByFileType(filetype) { | ||
this.addQuery(QueryType.STRING, { | ||
field: File.MIME_TYPE, | ||
op: Operator.EQUAL, | ||
entry: Array.isArray(filetype) ? filetype : [filetype] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the creation date of the file is equal to the specified timestamp. | ||
* | ||
* Uses RFC 3339 format, the default timezone is UTC, such as 2011-10-05T14:48:00Z. | ||
*/ | ||
getByCreatedAt(timestamp) { | ||
this.addQuery(QueryType.STRING, { | ||
field: File.CREATED_TIME, | ||
op: Operator.EQUAL, | ||
entry: Array.isArray(timestamp) ? timestamp : [timestamp] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the modified date of the file is equal to the specified timestamp. | ||
* | ||
* Uses RFC 3339 format, the default timezone is UTC, such as 2011-10-05T14:48:00Z. | ||
*/ | ||
getByUpdatedAt(timestamp) { | ||
this.addQuery(QueryType.STRING, { | ||
field: File.MODIFIED_TIME, | ||
op: Operator.EQUAL, | ||
entry: Array.isArray(timestamp) ? timestamp : [timestamp] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the visibility level of the file is equal to the specified visibility level. | ||
* | ||
* Valid values are found in the `VisibilityLevel` enumeration. | ||
*/ | ||
getByVisibility(visibilityLevel) { | ||
this.addQuery(QueryType.STRING, { | ||
field: File.VISIBILITY, | ||
op: Operator.EQUAL, | ||
entry: Array.isArray(visibilityLevel) ? visibilityLevel : [visibilityLevel] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the file has the specified public properties. | ||
*/ | ||
getByPublicProp(properties) { | ||
this.addQuery(QueryType.HASH, { | ||
field: File.PROPERTIES, | ||
op: Operator.HAS, | ||
entry: properties | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the file has the specified private properties. | ||
*/ | ||
getByPrivateProp(properties) { | ||
this.addQuery(QueryType.HASH, { | ||
field: File.APP_PROPERTIES, | ||
op: Operator.HAS, | ||
entry: properties | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the file is in the trash or not. | ||
*/ | ||
isTrashed(value) { | ||
this.addQuery(QueryType.BOOLEAN, { | ||
field: File.TRASHED, | ||
op: Operator.EQUAL, | ||
entry: [`${value}`] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the file is starred or not. | ||
*/ | ||
isStarred(value) { | ||
this.addQuery(QueryType.BOOLEAN, { | ||
field: File.STARRED, | ||
op: Operator.EQUAL, | ||
entry: [`${value}`] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Indicates whether the shared drive is hidden or not. | ||
*/ | ||
isHidden(value) { | ||
this.addQuery(QueryType.BOOLEAN, { | ||
field: File.HIDDEN, | ||
op: Operator.EQUAL, | ||
entry: [`${value}`] | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Joins the inputs into a single string with the `and` operator. | ||
*/ | ||
build() { | ||
return this.queries.join(` ${Operator.AND} `); | ||
} | ||
} | ||
var src_default = QueryBuilder; | ||
export { | ||
Collection, | ||
FileType, | ||
VisibilityLevel, | ||
src_default as default | ||
}; | ||
var A=(i=>(i.PARENTS="parents",i.OWNERS="owners",i.WRITERS="writers",i.READERS="readers",i))(A||{});var E=(r=>(r.ANYONE_CAN_FIND="anyoneCanFind",r.ANYONE_WITH_LINK="anyoneWithLink",r.DOMAIN_CAN_FIND="domainCanFind",r.DOMAIN_WITH_LINK="domainWithLink",r.LIMITED="limited",r))(E||{}),p=(r=>(r.FOLDER="application/vnd.google-apps.folder",r.DOCUMENT="application/vnd.google-apps.document",r.SPREADSHEET="application/vnd.google-apps.spreadsheet",r.PRESENTATION="application/vnd.google-apps.presentation",r.FORM="application/vnd.google-apps.form",r))(p||{});var u={0:({field:n,op:t,entry:e})=>`'${e.value}' ${t} ${n}`,1:({field:n,op:t,entry:e})=>`${n} ${t} '${e.value}'`,2:({field:n,op:t,entry:e})=>`${n} ${t} ${e.value}`,3:({field:n,op:t,entry:e})=>`${n} ${t} { key='${e?.key}' and value='${e.value}' }`},o=class{constructor(){this.queries=[];this.negateNextTerm=!1}addQuery(t,e){let{field:y,op:i,entry:r}=e,s="";this.negateNextTerm&&(this.negateNextTerm=!1,s+="not ");let a=[];for(let d in r){let T=r[d];a.push(u[t]({field:y,op:i,entry:{key:`${d}`,value:T}}))}s+=`(${a.join(` ${Array.isArray(r)?"or":"and"} `)})`,this.queries.push(s)}not(){return this.negateNextTerm=!0,this}getByCollection(t,e){return this.addQuery(0,{field:t,op:"in",entry:Array.isArray(e)?e:[e]}),this}getByFileName(t){return this.addQuery(1,{field:"name",op:"=",entry:Array.isArray(t)?t:[t]}),this}getByContent(t){return this.addQuery(1,{field:"fullText",op:"contains",entry:Array.isArray(t)?t:[t]}),this}getByFileType(t){return this.addQuery(1,{field:"mimeType",op:"=",entry:Array.isArray(t)?t:[t]}),this}getByCreatedAt(t){return this.addQuery(1,{field:"createdTime",op:"=",entry:Array.isArray(t)?t:[t]}),this}getByUpdatedAt(t){return this.addQuery(1,{field:"modifiedTime",op:"=",entry:Array.isArray(t)?t:[t]}),this}getByVisibility(t){return this.addQuery(1,{field:"visibility",op:"=",entry:Array.isArray(t)?t:[t]}),this}getByPublicProp(t){return this.addQuery(3,{field:"properties",op:"has",entry:t}),this}getByPrivateProp(t){return this.addQuery(3,{field:"appProperties",op:"has",entry:t}),this}isTrashed(t){return this.addQuery(2,{field:"trashed",op:"=",entry:[`${t}`]}),this}isStarred(t){return this.addQuery(2,{field:"starred",op:"=",entry:[`${t}`]}),this}isHidden(t){return this.addQuery(2,{field:"hidden",op:"=",entry:[`${t}`]}),this}build(){return this.queries.join(" and ")}};var R=o;export{A as Collection,p as FileType,E as VisibilityLevel,R as default}; |
@@ -5,3 +5,3 @@ { | ||
"description": "Easily generate queries for the Google Drive API.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22120
7
111