mean-expert-official / loopback-sdk-builder Goto Github PK
View Code? Open in Web Editor NEWTool for auto-generating Software Development Kits (SDKs) for LoopBack
License: Other
Tool for auto-generating Software Development Kits (SDKs) for LoopBack
License: Other
The current implementation is incorrect and create a wrong query string. Refactor to build a valid query string params
We have issues with custom end points that accept json param instead of data in body. Such params require to be transferred to the body for processing while sending in the request, and would not become part of the search/ url. So following assignment woudl never hit the API correctly:
this.searchParams.setJSON(params);
let request = new Request({
headers : headers,
method : method,
url : requestUrl,
search : this.searchParams.getURLSearchParams(),
body : data ? JSON.stringify(data) : undefined
});
params needs to be parsed and sent in the body I believe.
Also rename again the angular generator to angular 2 and remove the angularjs one.
Reasons:
This builder won't support Angular 1.x, we will not compete with the loopback-sdk-angular
When I use the SDK builder in Loopback 3 the method patchAttributes throws an error. The method is not sending the data passed as second argument.
The URL from User.ts file for the function getCurrent() is missing the api version.
Instead of:
public getCurrent(): any {
let method: string = "GET";
let url: string = LoopBackConfig.getPath() + "/users" + "/:id";
I think it should be:
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/users" + "/:id";
This seems to be the only call that is missing the api version (api.ejs):
public getCurrent(): any {
let method: string = "GET";
let url: string = LoopBackConfig.getPath() + <%-: meta.getPath() | q %> + "/:id";
Hi, any thoughts on what should include the Angular Universal driver?
I have been playing around and the main issue should be with the LoopBackAuth and StorageDriver that uses localStorage (which by definition is not supported in node.js).
Other considerations (things that node.js doesn't support) may be:
But I don't know if the loopback SDK even uses these features.
Anyways, maybe we just need to avoid the LoopBackAuth dependency to get things working for de Angular Universal driver.
Do you see any other pain point or roadblock?
The following files are missing on the angular2 generated files (beta):
import { LoggerService } from './services/logger.service';
import { JSONSearchParams } from './services/search.params';
I see that if the loopback model is public, then the imports refer to it in Title case, whereas if the model is public: false it does not get generated (which creates typing issues in typescript, where the variable types of relational properties is undefined).
And also for such models all imports mention them in lower case (my loopback model names are all lower case) and the property definitions also refer to them in lower case.
here, business model is exporting in lower case, but it is being imported elsewhere in Title case, another model that is private : breview, does not get generated (if i make it public just to carry over the generated model - tmp fix, it would be exported in Title case and I'd need to make all references to change case. It becomes nuance. if a model is private, its service can be skipped, but model is required with new RC.2/3 changes.
import {
Job,
User,
breview
} from '../index';
export interface businessInterface {
brief?: string;
jobs?: Array<Job>;
user?:User;
reviews?: Array<breview>;
}
export class business implements businessInterface {
brief: string;
jobs: Array<Job>;
user:User;
reviews: Array<breview>;
constructor(instance?: business) {
Object.assign(this, instance);
}
}
Angular2 and Nativescript2 are integrating very well together and there are project trying to reuse most of the code for both platforms. (I am also working on such a starter)
Also looking to our current implementation it seams that both generators are very similar apart form two specific point:
I would consider trying to abstract both layers in a way that we could end up with only one template for both platforms.
Would like to know your thought on this.
ISSUE 1: nativescript-socket.io for IOS is WIP
In case loopback-passport-component is used, there is a duplicate property (for relation to UserCredentials) named as credentials, same as the in build User.credentials. This needs to eb avoided.
How i can import angular 2 routes in loopback. thanks
Create common folder for those templates that can be shared.
Implement the possibility to break the sdk into different files as the angular2
Work on this after 2.0.0 stable release
Hi,
I test the new rc2 sdk builder, but i have some bugs :(
First of all, i launch the build:sdk command, everything is ok, but when i launch the typescript compiler, i have these errors :
Error:(20, 1) TS2308: Module './AccessToken' has already exported a member named 'AccessToken'. Consider explicitly re-exporting to resolve the ambiguity.
this is the content of my sdk/models/index.ts :
/* tslint:disable */
export * from './AccessToken';
export * from './Seminaire';
export * from './User';
export * from './UserEvent';
export * from './UserSeminaire';
export * from './Session';
export * from './Feed';
export * from './Like';
export * from './Comment';
export * from './UserSession';
export * from './Intervenant';
export * from './Image';
export * from './Organisateur';
export * from './Notation';
export * from './ACL';
export * from './RoleMapping';
export * from './Role';
export * from './Email';
export * from './BaseModels';
the error come from the last line because a conflict exist with /AccessToken.
Content of sdk/models/AccessToken.ts :
/* tslint:disable */
import {
User
} from '../index';
export interface AccessTokenInterface {
id?:string;
/**
* time to live in seconds (2 weeks by default)
*/
ttl?:number;
created?:any;
userId?:string;
user?:User;
}
export class AccessToken implements AccessTokenInterface {
id:string;
/**
* time to live in seconds (2 weeks by default)
*/
ttl:number;
created:any;
userId:string;
user:User;
constructor(instance?:AccessToken) {
Object.assign(this, instance);
}
}
Content of sdk/models/BaseModels.ts :
/* tslint:disable */
export interface LoopBackFilterInterface {
fields?: any;
include?: any;
limit?: any;
order?: any;
skip?: any;
offset?: any;
where?: any;
}
export class LoopBackFilter implements LoopBackFilterInterface {
fields: any;
include: any;
limit: any;
order: any;
skip: any;
offset: any;
where: any;
}
export interface TokenInterface {
id?: any;
user?: any;
userId?: any;
ttl?: any;
created?: any;
}
export class AccessToken implements TokenInterface {
id: any;
user: any;
userId: any;
ttl: any;
created: any;
}
This is the 1st error, if i rename AccessToken to Token inside BaseModels.ts, my console.log display this error after the application launching :
zone.js:323 Error: (SystemJS) TypeError: Class extends value undefined is not a function or null
at Object.eval (http://localhost:3000/sdk/services/custom/AccessToken.js:27:58)
at eval (http://localhost:3000/sdk/services/custom/AccessToken.js:948:4)
at eval (http://localhost:3000/sdk/services/custom/AccessToken.js:949:3)
at Object.eval (http://localhost:3000/sdk/services/custom/index.js:6:10)
Evaluating http://localhost:3000/sdk/services/custom/AccessToken.js
Evaluating http://localhost:3000/sdk/services/custom/index.js
Evaluating http://localhost:3000/sdk/services/index.js
Evaluating http://localhost:3000/sdk/index.js
Evaluating http://localhost:3000/sdk/services/core/logger.service.js
Evaluating http://localhost:3000/sdk/services/core/index.js
Evaluating http://localhost:3000/sdk/services/custom/Organisateur.js
Evaluating http://localhost:3000/services/auth.service.js
Evaluating http://localhost:3000/app/ui/navbar.component.js
Evaluating http://localhost:3000/app/app.component.js
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js
I don't understand what is the problem... please do you have this bug ? and can you resolve it please ?
Many thanks for your help,
best regards
BM
This is a complement for unsubscribing to events within a component scope
Actually in my project I have a warning (node) warning: possible EventEmitter memory leak detected. 11 authentication listeners added. Use emitter.setMaxListeners() to increase limit.
I thing is good idea add in the manual anything help or instruction for that.
I've followed the instructions for generating the angular2 sdk in the documention and receive the following error when building my project with webpack.
ERROR in ./src/client/app/shared/lb-services/services/api.d.ts
Module build failed: Error: Debug Failure. False expression: Output generation failed
at Object.assert (C:\Users\Josh\Documents\Github\muskoka\node_modules\typescript\lib\typescript.js:2099:23)
at Object.transpileModule (C:\Users\Josh\Documents\Github\muskoka\node_modules\typescript\lib\typescript.js:53173:18)
at State.fastEmit (C:\Users\Josh\Documents\Github\muskoka\node_modules\awesome-typescript-loader\dist.babel\host.js:302:43)
at transform (C:\Users\Josh\Documents\Github\muskoka\node_modules\awesome-typescript-loader\dist.babel\index.js:215:53)
at _callee3$ (C:\Users\Josh\Documents\Github\muskoka\node_modules\awesome-typescript-loader\dist.babel\index.js:265:42)
at tryCatch (C:\Users\Josh\Documents\Github\muskoka\node_modules\regenerator-runtime\runtime.js:62:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\Josh\Documents\Github\muskoka\node_modules\regenerator-runtime\runtime.js:336:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\Josh\Documents\Github\muskoka\node_modules\regenerator-runtime\runtime.js:95:21)
at fulfilled (C:\Users\Josh\Documents\Github\muskoka\node_modules\awesome-typescript-loader\dist.babel\index.js:31:32)
at run (C:\Users\Josh\Documents\Github\muskoka\node_modules\core-js\modules\es6.promise.js:89:22)
at C:\Users\Josh\Documents\Github\muskoka\node_modules\core-js\modules\es6.promise.js:102:28
at flush (C:\Users\Josh\Documents\Github\muskoka\node_modules\core-js\modules\_microtask.js:18:9)
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
@ ./src/client/app/shared/lb-services/index.ts 22:9-36
This should generate an executable in node_modules/.bin/lb-ng to prevent need for global installation and easy CI.
We already have a pretty stable generated SDK but the generator is super messy and out of any standard. Refactor to avoid multiple loops and the huge amount of duplicated code.
This is for release candidate 3 and should be transparent for final usage.
This should improve performance while generating SDK
Although the models and APIs are referred to in Title case, the interface and models are being exported in provided case (in my case lower case). This results in errors in case you have any model name in lower case.
Following two changes correct the Title casing for properties and models: (utils.js)
var name = c.name;
var name = c.name[0].toUpperCase() + c.name.slice(1);
targetClass = targetClass[0].toUpperCase() + targetClass.slice(1);
modelClass.sharedClass.ctor.relations[scopeName].targetClass = targetClass;
On the storage.driver.ts of ng4web the line 10 is setting "null" as string to the localStorage[key]. Then assuming that getCurrentUserId() is null, when I'm doing something like:
if (this.loopbackAuth.getCurrentUserId() !== null) {
//this code will be executed
}
The code will be executed.
Here how I replaced to fix it:
/* tslint:disable */
export class StorageDriver {
static set(key: string, value: string) {
localStorage.setItem(key, value); //instead of localStorage[key] = value;
}
static get(key: string): string {
return localStorage.getItem(key); //instead of localStorage[key];
}
static remove(key: string): any {
localStorage.removeItem(key); //instead of localStorage[key] = null;
}
}
Thank you again!
undefined:25
throw err;
^
TypeError: ejs:9
7| import { ErrorHandler } from './services/errorHandler.service';
8| import {
9| <% models.forEach(function(modelName, i, arr) {
10| var meta = models[modelName];
11| // capitalize the model name
12| modelName = modelName[0].toUpperCase() + modelName.slice(1);
Can you consider use "eofline": true
in your tslint pass conditions?
I can add in a pull request the necesary changes.
In the model function the "data" property is wrongly set from the first param (by ejs), this results in other params being missed, ideally we need to merge the params with data and send in request body:
let result = this.request(method, url, urlParams, params<%=
postData && postData.length > 0 ? ", " + postData[0].arg : '' %>, true)<%
The file index.ts is generating:
export * from './models';
must be:
export * from './services/models.service';
And the "models.service.ts" requires be created.
Thank you!
In the beta15 version the created code have a error with unexpected ; in LoopBackConfig.getApiVersion() + ;
What are your thoughts on including generators for both redux since you want to support react and ngrx for angular2?
I am not sure if we should include these in this project or spin another project specific for it. What do you think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.