Skip to content

dx | 1636 | sre and test cases #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>JSDoc: Global</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js" integrity="sha384-hDHlUtmnjnJimeAhT+DpLqjLdp8vFgSFHhZO1zq2EtqpwFsNM7H5cpSUYqT1Uh2E" crossorigin="anonymous"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/global.html#Stack
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>JSDoc: Class: Stack</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>JSDoc: Home</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js" integrity="sha384-hDHlUtmnjnJimeAhT+DpLqjLdp8vFgSFHhZO1zq2EtqpwFsNM7H5cpSUYqT1Uh2E" crossorigin="anonymous"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js" integrity="sha384-hDHlUtmnjnJimeAhT+DpLqjLdp8vFgSFHhZO1zq2EtqpwFsNM7H5cpSUYqT1Uh2E" crossorigin="anonymous"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>JSDoc: Source: index.js</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js" integrity="sha384-hDHlUtmnjnJimeAhT+DpLqjLdp8vFgSFHhZO1zq2EtqpwFsNM7H5cpSUYqT1Uh2E" crossorigin="anonymous"></script>
Expand Down
28 changes: 0 additions & 28 deletions docs/scripts/prettify/prettify.js

This file was deleted.

2 changes: 1 addition & 1 deletion docs/stack.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>JSDoc: Source: stack.js</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js" integrity="sha384-hDHlUtmnjnJimeAhT+DpLqjLdp8vFgSFHhZO1zq2EtqpwFsNM7H5cpSUYqT1Uh2E" crossorigin="anonymous"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const config = {
// http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
options: {
connectTimeoutMS: 15000,
keepAlive: true,
// keepAlive: true, // The keepAlive option was deprecated in the Node.js Driver starting from version 5.3. In version 6.0 of the driver, the keepAlive option is permanently set to true
noDelay: true,
useNewUrlParser: true,
},
Expand Down
36 changes: 35 additions & 1 deletion src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,9 @@ export class Stack {

private async bindLeftoverAssets(queries: IQuery, locale: string, pointerList: IShelf[]) {
// const contents = await readFile(getAssetsPath(locale) + '.json')
if (!this.sanitizeIQuery(queries)) {
throw new Error('Invalid queries provided');
}
const filteredAssets = await this.db.collection(getCollectionName({
content_type_uid: this.types.assets,
locale,
Expand Down Expand Up @@ -2096,6 +2099,9 @@ export class Stack {
}

private async getReferencePath(query, locale, currentInclude) {
if (!this.sanityQueryAny(query)) {
throw new Error('Invalid query provided');
}
const schemas = await this.db.collection(getCollectionName({
content_type_uid: this.types.content_types,
locale,
Expand Down Expand Up @@ -2184,6 +2190,9 @@ export class Stack {

private async fetchEntries(query: IQuery, locale: string, paths: string[], include: string[], includeAll:
boolean = false) {
if (!this.sanitizeIQuery(query)) {
throw new Error('Invalid queries provided');
}
const result = await this.db.collection(getCollectionName({
content_type_uid: 'entries',
locale,
Expand Down Expand Up @@ -2376,5 +2385,30 @@ export class Stack {
paths,
}
}
// tslint:disable-next-line: max-file-line-count

private sanitizeIQuery(query: IQuery): boolean {
if (!query || typeof query !== 'object' || Array.isArray(query)) {
return false;
}
if (!query || !Array.isArray(query.$or)) {
return false;
}
for (const item of query.$or) {
if (
typeof item._content_type_uid !== 'string' ||
typeof item.uid !== 'string' ||
(item._version && typeof item._version.$exists !== 'boolean') ||
(item.locale && typeof item.locale !== 'string')
) {
return false;
}
}
return true;
}
private sanityQueryAny(query: any): boolean {
if (!query || typeof query !== 'object' || Array.isArray(query)) {
return false;
}
return true;
}
}
2 changes: 1 addition & 1 deletion test/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('# Expressional Operators', () => {
test('.regex()', () => {
return Stack.contentType('blog')
.entries()
.regex('title', '/^Blog Two$/', 'g')
.regex('title', '/^Blog Two$/', 'i')
.find()
.then((result: any) => {
checkEntries(result)
Expand Down
1 change: 0 additions & 1 deletion typings/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export declare const config: {
locale: string;
options: {
connectTimeoutMS: number;
keepAlive: boolean;
noDelay: boolean;
useNewUrlParser: boolean;
};
Expand Down
2 changes: 2 additions & 0 deletions typings/stack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,4 +1092,6 @@ export declare class Stack {
private bindReferences;
private includeAllReferencesIteration;
private getAllReferencePaths;
private sanitizeIQuery;
private sanityQueryAny;
}
Loading