@plattar/sdk-core
Advanced tools
Comparing version
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
include(...objects: Array<(typeof CoreObject<CoreObjectAttributes>) | string>): Array<string>; | ||
static include(...objects: Array<(typeof CoreObject<CoreObjectAttributes>) | Array<string>>): Array<string>; | ||
/** | ||
@@ -25,0 +25,0 @@ * Re-fills tis object instance with data from the api |
@@ -40,9 +40,21 @@ "use strict"; | ||
*/ | ||
include(...objects) { | ||
return objects.map((object) => { | ||
if (typeof object === 'string' || object instanceof String) { | ||
return object; | ||
static include(...objects) { | ||
const data = objects.map((object) => { | ||
if (Array.isArray(object)) { | ||
return object.map((object) => { | ||
return `${this.type}.${object}`; | ||
}); | ||
} | ||
return `${this.type}.${object.type}`; | ||
}); | ||
const consolidatedData = new Array(); | ||
data.forEach((object) => { | ||
if (Array.isArray(object)) { | ||
consolidatedData.push(...object); | ||
} | ||
else { | ||
consolidatedData.push(object); | ||
} | ||
}); | ||
return consolidatedData; | ||
} | ||
@@ -49,0 +61,0 @@ /** |
@@ -23,3 +23,3 @@ import { CoreObject, CoreObjectAttributes } from '../core-object'; | ||
fields(...fields: Array<keyof U>): this; | ||
include(...objects: Array<(typeof CoreObject<CoreObjectAttributes>) | string>): this; | ||
include(...objects: Array<(typeof CoreObject<CoreObjectAttributes>) | Array<string>>): this; | ||
contains(operation?: QueryContainsOperator, ...objects: Array<typeof CoreObject<CoreObjectAttributes>>): this; | ||
@@ -30,2 +30,6 @@ deleted(...objects: Array<typeof CoreObject<CoreObjectAttributes>>): this; | ||
protected _Fetch(url: string, type: QueryFetchType): Promise<Array<T>>; | ||
/** | ||
* Generates the url sequence of all queries and returns | ||
*/ | ||
toString(): string; | ||
} |
@@ -50,8 +50,19 @@ "use strict"; | ||
const data = objects.map((object) => { | ||
if (typeof object === 'string' || object instanceof String) { | ||
return object; | ||
if (Array.isArray(object)) { | ||
return object.map((object) => { | ||
return `${this.instance.type}.${object}`; | ||
}); | ||
} | ||
return `${this.instance.type}.${object.type}`; | ||
}); | ||
this._queries.push(new include_query_1.IncludeQuery(data)); | ||
const consolidatedData = new Array(); | ||
data.forEach((object) => { | ||
if (Array.isArray(object)) { | ||
consolidatedData.push(...object); | ||
} | ||
else { | ||
consolidatedData.push(object); | ||
} | ||
}); | ||
this._queries.push(new include_query_1.IncludeQuery(consolidatedData)); | ||
return this; | ||
@@ -79,16 +90,4 @@ } | ||
const results = new Array(); | ||
const queries = this._queries; | ||
// generate all the query parameters to the final URL (if any) | ||
// some requests (like POST) will ignore certain queries as they are | ||
// not processable in the provided context | ||
if (queries.length > 0) { | ||
url += '?'; | ||
queries.forEach((query) => { | ||
url += `${query.toString()}&`; | ||
}); | ||
// remove the last & keyword | ||
url = url.slice(0, -1); | ||
} | ||
// encode the full url to safely escape all characters (like whitespaces) | ||
const encodedURL = encodeURI(url); | ||
const encodedURL = encodeURI(url + this.toString()); | ||
// proceed with generating the request - for anything other than GET we need to generate a payload | ||
@@ -100,3 +99,18 @@ // this payload is generated from non-null values of the object attributes | ||
} | ||
/** | ||
* Generates the url sequence of all queries and returns | ||
*/ | ||
toString() { | ||
const queries = this._queries; | ||
if (queries.length <= 0) { | ||
return ''; | ||
} | ||
let url = '?'; | ||
queries.forEach((query) => { | ||
url += `${query.toString()}&`; | ||
}); | ||
// remove the last & keyword | ||
return url.slice(0, -1); | ||
} | ||
} | ||
exports.CoreQuery = CoreQuery; |
@@ -42,3 +42,4 @@ "use strict"; | ||
static generateIndexFile(schemas) { | ||
let output = ''; | ||
let output = '/*\n * Warning: Do Not Edit - Auto Generated via @plattar/sdk-core\n */\n\n'; | ||
output += 'export { Service, ServiceConfig, ServiceAuth } from "@plattar/sdk-core";\n'; | ||
schemas.forEach((schema) => { | ||
@@ -45,0 +46,0 @@ output += `export * from "./schemas/${schema.name}";\n`; |
@@ -1,2 +0,2 @@ | ||
declare const _default: "1.163.5"; | ||
declare const _default: "1.163.6"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = "1.163.5"; | ||
exports.default = "1.163.6"; |
{ | ||
"name": "@plattar/sdk-core", | ||
"version": "1.163.5", | ||
"version": "1.163.6", | ||
"description": "Core SDK Module for Generative SDK using API Core", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
48158
2.02%1205
2.64%