diff --git a/sdk-core/src/core/query/core-query.ts b/sdk-core/src/core/query/core-query.ts index e4ebfcc..b27bdb9 100644 --- a/sdk-core/src/core/query/core-query.ts +++ b/sdk-core/src/core/query/core-query.ts @@ -2,7 +2,7 @@ import { CoreObject, CoreObjectAttributes } from '../core-object'; import { GlobalObjectPool } from '../global-object-pool'; import { Service } from '../service'; import { CoreError } from './errors/core-error'; -import { QueryContainsOperator, ContainsQuery } from './queries/contains-query'; +import { ContainsQuery } from './queries/contains-query'; import { DeletedQuery } from './queries/deleted-query'; import { FieldsQuery } from './queries/fields-query'; import { FilterQuery, FilterQueryOperator } from './queries/filter-query'; @@ -54,7 +54,11 @@ export abstract class CoreQuery, U extends CoreObjectAtt */ public join(...queries: Array, CoreObjectAttributes>>): this { queries.forEach((query: CoreQuery, CoreObjectAttributes>) => { - this._queries.push(new JoinQuery(query.toString())); + const queryString: string = query.toString(); + + if (queryString !== '') { + this._queries.push(new JoinQuery(queryString)); + } }); return this; @@ -81,36 +85,38 @@ export abstract class CoreQuery, U extends CoreObjectAtt return this; } - public include(...objects: Array<(typeof CoreObject) | Array>): this { - const data: Array> = objects.map>((object: typeof CoreObject | Array) => { + public include(...objects: Array<(typeof CoreObject) | (typeof CoreQuery, CoreObjectAttributes>) | Array>): this { + const data: Array> = objects.map>((object: typeof CoreObject | typeof CoreQuery, CoreObjectAttributes> | Array) => { if (Array.isArray(object)) { return object.map((object: string) => { return `${this.instance.type}.${object}`; }); } - return `${this.instance.type}.${object.type}`; - }); - - const consolidatedData: Array = new Array(); + if (object instanceof CoreQuery) { + this.join(object); - data.forEach((object: string | Array) => { - if (Array.isArray(object)) { - consolidatedData.push(...object); - } - else { - consolidatedData.push(object); + return `${this.instance.type}.${object.instance.type}`; } + + return `${this.instance.type}.${(object).type}`; }); - this._queries.push(new IncludeQuery(consolidatedData)); + this._queries.push(new IncludeQuery(data.flat())); + + return this; + } + + public contains(...objects: Array>): this { + const data: Array = objects.map((object: typeof CoreObject) => object.type); + this._queries.push(new ContainsQuery("==", data)); return this; } - public contains(operation: QueryContainsOperator = '==', ...objects: Array>): this { + public notContains(...objects: Array>): this { const data: Array = objects.map((object: typeof CoreObject) => object.type); - this._queries.push(new ContainsQuery(operation, data)); + this._queries.push(new ContainsQuery("!=", data)); return this; } diff --git a/sdk-core/src/generator/generators/project.ts b/sdk-core/src/generator/generators/project.ts index 747f34e..3014020 100644 --- a/sdk-core/src/generator/generators/project.ts +++ b/sdk-core/src/generator/generators/project.ts @@ -74,7 +74,7 @@ export class Project { let output = `const { CleanWebpackPlugin } = require('clean-webpack-plugin');\n`; output += `const path = require("path");\n\n`; output += `module.exports = {\n`; - output += `\t name: '${vars.name}',\n`; + output += `\t name: '${vars.name}-sdk',\n`; output += `\t mode: 'production',\n`; output += `\t devtool: 'source-map',\n`; output += `\t entry: './dist/index.js',\n`; @@ -97,7 +97,7 @@ export class Project { */ public static generatePackageJson(vars: PackageJsonVars): any { return { - name: `@plattar/${vars.name}`, + name: `@plattar/${vars.name}-sdk`, version: vars.version, description: `Generated using @plattar/sdk-core and used for interfacing with ${vars.name} backend service`, main: 'dist/index.js', @@ -172,14 +172,14 @@ export class Project { } public static generateReadme(vars: PackageJsonVars): string { - let output = `[![NPM](https://img.shields.io/npm/v/@plattar/${vars.name})](https://www.npmjs.com/package/@plattar/${vars.name})\n\n`; + let output = `[![NPM](https://img.shields.io/npm/v/@plattar/${vars.name}-sdk)](https://www.npmjs.com/package/@plattar/${vars.name}-sdk)\n\n`; output += `### About\n\n`; - output += `_${vars.name}_ v${vars.version} is automatically generated using [sdk-core](https://www.npmjs.com/package/@plattar/sdk-core) module\n\n`; + output += `${vars.name}-sdk v${vars.version} is automatically generated using [sdk-core](https://www.npmjs.com/package/@plattar/sdk-core) module\n\n`; output += `### Installation\n\n`; - output += `- Install using [npm](https://www.npmjs.com/package/@plattar/${vars.name})\n\n`; - output += `\`\`\`console\nnpm install @plattar/${vars.name}\n\`\`\`\n\n`; + output += `- Install using [npm](https://www.npmjs.com/package/@plattar/${vars.name}-sdk)\n\n`; + output += `\`\`\`console\nnpm install @plattar/${vars.name}-sdk\n\`\`\`\n\n`; output += `### JSDelivr\n\n`; - output += `- Minified Bundle \`https://cdn.jsdelivr.net/npm/@plattar/${vars.name}/build/bundle.min.js\`\n`; + output += `- Minified Bundle \`https://cdn.jsdelivr.net/npm/@plattar/${vars.name}-sdk/build/bundle.min.js\`\n`; return output; }